jake
4 years ago
48 changed files with 916 additions and 643 deletions
-
3Cargo.toml
-
49src/bin/login.rs
-
113src/bin/main.rs
-
16src/bin/patch.rs
-
52src/bin/ship.rs
-
104src/common/mainloop/client.rs
-
40src/common/mainloop/interserver.rs
-
4src/common/serverstate.rs
-
32src/entity/account.rs
-
49src/entity/gateway/entitygateway.rs
-
73src/entity/gateway/inmemory.rs
-
2src/entity/gateway/mod.rs
-
11src/entity/gateway/postgres/migrations/V0001__initial.sql
-
21src/entity/gateway/postgres/models.rs
-
195src/entity/gateway/postgres/postgres.rs
-
6src/entity/item/armor.rs
-
6src/entity/item/esweapon.rs
-
6src/entity/item/mag.rs
-
5src/entity/item/mod.rs
-
4src/entity/item/shield.rs
-
2src/entity/item/tech.rs
-
4src/entity/item/tool.rs
-
4src/entity/item/unit.rs
-
14src/entity/item/weapon.rs
-
77src/login/character.rs
-
110src/login/login.rs
-
31src/patch/patch.rs
-
2src/ship/drops/rare_drop_table.rs
-
72src/ship/items/manager.rs
-
30src/ship/items/use_tool.rs
-
16src/ship/packet/handler/auth.rs
-
2src/ship/packet/handler/communication.rs
-
8src/ship/packet/handler/direct_message.rs
-
2src/ship/packet/handler/lobby.rs
-
8src/ship/packet/handler/message.rs
-
6src/ship/packet/handler/settings.rs
-
31src/ship/ship.rs
-
4src/ship/shops/armor.rs
-
31src/ship/shops/tool.rs
-
8tests/common.rs
-
126tests/test_bank.rs
-
4tests/test_character.rs
-
2tests/test_exp_gain.rs
-
6tests/test_item_equip.rs
-
72tests/test_item_pickup.rs
-
22tests/test_item_use.rs
-
20tests/test_mags.rs
-
54tests/test_shops.rs
@ -0,0 +1,49 @@ |
|||
use log::{info};
|
|||
use elseware::entity::gateway::postgres::PostgresGateway;
|
|||
use elseware::login::login::LoginServerState;
|
|||
use elseware::login::character::CharacterServerState;
|
|||
use elseware::common::mainloop::{login_mainloop, character_mainloop};
|
|||
|
|||
fn main() {
|
|||
let colors = fern::colors::ColoredLevelConfig::new()
|
|||
.error(fern::colors::Color::Red)
|
|||
.warn(fern::colors::Color::Yellow)
|
|||
.info(fern::colors::Color::Green)
|
|||
.debug(fern::colors::Color::White)
|
|||
.trace(fern::colors::Color::BrightBlack);
|
|||
let stdio = fern::Dispatch::new()
|
|||
.level(log::LevelFilter::Debug)
|
|||
.format(move |out, message, record| {
|
|||
out.finish(format_args!(
|
|||
"\x1B[{}m[{}][{}][{}] {}\x1B[0m",
|
|||
colors.get_color(&record.level()).to_fg_str(),
|
|||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
|
|||
record.target(),
|
|||
record.level(),
|
|||
message,
|
|||
))
|
|||
})
|
|||
.chain(std::io::stdout());
|
|||
fern::Dispatch::new()
|
|||
.chain(stdio)
|
|||
.apply().unwrap();
|
|||
|
|||
let db_host = std::env::var("DB_HOST").unwrap();
|
|||
let db_username = std::env::var("DB_USERNAME").unwrap();
|
|||
let db_password = std::env::var("DB_PASSWORD").unwrap();
|
|||
let db_dbname = std::env::var("DB_DBNAME").unwrap();
|
|||
let charserv_ip = std::env::var("CHARSERV_IP").unwrap().parse().unwrap();
|
|||
let entity_gateway = PostgresGateway::new(&db_host, &db_dbname, &db_username, &db_password);
|
|||
|
|||
let thread_entity_gateway = entity_gateway.clone();
|
|||
let login_state = LoginServerState::new(thread_entity_gateway, charserv_ip);
|
|||
let login_loop = login_mainloop(login_state, elseware::login::login::LOGIN_PORT);
|
|||
|
|||
let char_state = CharacterServerState::new(entity_gateway);
|
|||
let character_loop = character_mainloop(char_state, elseware::login::character::CHARACTER_PORT, elseware::login::login::COMMUNICATION_PORT);
|
|||
|
|||
info!("[auth/character] starting server");
|
|||
async_std::task::block_on(async move {
|
|||
futures::future::join_all(vec![login_loop, character_loop]).await
|
|||
});
|
|||
}
|
@ -0,0 +1,16 @@ |
|||
use elseware::patch::patch::{PatchServerState, generate_patch_tree, load_config_env, load_motd};
|
|||
use log::{info};
|
|||
use elseware::common::mainloop::patch_mainloop;
|
|||
|
|||
fn main() {
|
|||
info!("[patch] starting server");
|
|||
let patch_config = load_config_env();
|
|||
let patch_motd = load_motd();
|
|||
let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str());
|
|||
let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd);
|
|||
let patch_loop = patch_mainloop(patch_state, patch_config.port);
|
|||
|
|||
async_std::task::block_on(async move {
|
|||
patch_loop.await
|
|||
});
|
|||
}
|
@ -0,0 +1,52 @@ |
|||
use log::{info};
|
|||
use elseware::entity::gateway::postgres::PostgresGateway;
|
|||
use elseware::ship::ship::ShipServerStateBuilder;
|
|||
use elseware::common::mainloop::ship_mainloop;
|
|||
|
|||
fn main() {
|
|||
let colors = fern::colors::ColoredLevelConfig::new()
|
|||
.error(fern::colors::Color::Red)
|
|||
.warn(fern::colors::Color::Yellow)
|
|||
.info(fern::colors::Color::Green)
|
|||
.debug(fern::colors::Color::White)
|
|||
.trace(fern::colors::Color::BrightBlack);
|
|||
let stdio = fern::Dispatch::new()
|
|||
.level(log::LevelFilter::Debug)
|
|||
.format(move |out, message, record| {
|
|||
out.finish(format_args!(
|
|||
"\x1B[{}m[{}][{}][{}] {}\x1B[0m",
|
|||
colors.get_color(&record.level()).to_fg_str(),
|
|||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
|
|||
record.target(),
|
|||
record.level(),
|
|||
message,
|
|||
))
|
|||
})
|
|||
.chain(std::io::stdout());
|
|||
fern::Dispatch::new()
|
|||
.chain(stdio)
|
|||
.apply().unwrap();
|
|||
|
|||
let db_host = std::env::var("DB_HOST").unwrap();
|
|||
let db_username = std::env::var("DB_USERNAME").unwrap();
|
|||
let db_password = std::env::var("DB_PASSWORD").unwrap();
|
|||
let db_dbname = std::env::var("DB_DBNAME").unwrap();
|
|||
let entity_gateway = PostgresGateway::new(&db_host, &db_dbname, &db_username, &db_password);
|
|||
|
|||
let ship_name = std::env::var("SHIP_NAME").unwrap().parse().unwrap();
|
|||
let ip = std::env::var("SELF_IP").unwrap().parse().unwrap();
|
|||
let ship_state = ShipServerStateBuilder::new()
|
|||
.name(ship_name)
|
|||
.ip(ip)
|
|||
.port(elseware::ship::ship::SHIP_PORT)
|
|||
.gateway(entity_gateway)
|
|||
.build();
|
|||
|
|||
let shipgate_ip = std::env::var("SHIPGATE_IP").unwrap().parse().unwrap();
|
|||
let ship_loop = ship_mainloop(ship_state, elseware::ship::ship::SHIP_PORT, shipgate_ip, elseware::login::login::COMMUNICATION_PORT);
|
|||
|
|||
info!("[auth/character] starting server");
|
|||
async_std::task::block_on(async move {
|
|||
ship_loop.await
|
|||
});
|
|||
}
|
@ -1,80 +1,91 @@ |
|||
use thiserror::Error;
|
|||
|
|||
use crate::entity::account::*;
|
|||
use crate::entity::character::*;
|
|||
use crate::entity::item::*;
|
|||
|
|||
// TODO: all these Options should be Results
|
|||
|
|||
// TODO: better granularity?
|
|||
//#[derive(Error, Debug)]
|
|||
#[derive(Error, Debug)]
|
|||
#[error("")]
|
|||
pub enum GatewayError {
|
|||
Error,
|
|||
PgError(#[from] sqlx::Error)
|
|||
}
|
|||
|
|||
#[async_trait::async_trait]
|
|||
pub trait EntityGateway: Send + Sync + Clone {
|
|||
async fn create_user(&mut self, _user: NewUserAccountEntity) -> Option<UserAccountEntity> {
|
|||
async fn create_user(&mut self, _user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError> {
|
|||
unimplemented!()
|
|||
}
|
|||
|
|||
async fn get_user_by_id(&self, _id: UserAccountId) -> Option<UserAccountEntity> {
|
|||
async fn get_user_by_id(&self, _id: UserAccountId) -> Result<UserAccountEntity, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn get_user_by_name(&self, _username: String) -> Option<UserAccountEntity> {
|
|||
async fn get_user_by_name(&self, _username: String) -> Result<UserAccountEntity, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn save_user(&mut self, _user: &UserAccountEntity) {
|
|||
async fn save_user(&mut self, _user: &UserAccountEntity) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn create_user_settings(&mut self, _settings: NewUserSettingsEntity) -> Option<UserSettingsEntity> {
|
|||
async fn create_user_settings(&mut self, _settings: NewUserSettingsEntity) -> Result<UserSettingsEntity, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn get_user_settings_by_user(&self, _user: &UserAccountEntity) -> Option<UserSettingsEntity> {
|
|||
async fn get_user_settings_by_user(&self, _user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn save_user_settings(&mut self, _settings: &UserSettingsEntity) {
|
|||
async fn save_user_settings(&mut self, _settings: &UserSettingsEntity) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn create_character(&mut self, _char: NewCharacterEntity) -> Option<CharacterEntity> {
|
|||
async fn create_character(&mut self, _char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
// TODO: just make this a vec sorted by slot order?
|
|||
async fn get_characters_by_user(&self, _user: &UserAccountEntity) -> [Option<CharacterEntity>; 4] {
|
|||
async fn get_characters_by_user(&self, _user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn save_character(&mut self, _char: &CharacterEntity) {
|
|||
async fn save_character(&mut self, _char: &CharacterEntity) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn get_guild_card_data_by_user(&self, _user: &UserAccountEntity) -> GuildCardDataEntity {
|
|||
async fn get_guild_card_data_by_user(&self, _user: &UserAccountEntity) -> Result<GuildCardDataEntity, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn create_item(&mut self, _item: NewItemEntity) -> Option<ItemEntity> {
|
|||
async fn create_item(&mut self, _item: NewItemEntity) -> Result<ItemEntity, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn save_item(&mut self, _item: &ItemEntity) {
|
|||
async fn save_item(&mut self, _item: &ItemEntity) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn change_item_location(&mut self, _item_id: &ItemEntityId, _item_location: ItemLocation) {
|
|||
async fn change_item_location(&mut self, _item_id: &ItemEntityId, _item_location: ItemLocation) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn feed_mag(&mut self, _mag_item_id: &ItemEntityId, _tool_item_id: &ItemEntityId) {
|
|||
async fn feed_mag(&mut self, _mag_item_id: &ItemEntityId, _tool_item_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn change_mag_owner(&mut self, _mag_item_id: &ItemEntityId, _character: &CharacterEntity) {
|
|||
async fn change_mag_owner(&mut self, _mag_item_id: &ItemEntityId, _character: &CharacterEntity) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn use_mag_cell(&mut self, _mag_item_id: &ItemEntityId, _mag_cell_id: &ItemEntityId) {
|
|||
async fn use_mag_cell(&mut self, _mag_item_id: &ItemEntityId, _mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
|
|||
async fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<ItemEntity> {
|
|||
async fn get_items_by_character(&self, _char_id: &CharacterEntityId) -> Result<Vec<ItemEntity>, GatewayError> {
|
|||
unimplemented!();
|
|||
}
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue