You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
6.5 KiB
186 lines
6.5 KiB
#![allow(incomplete_features)]
|
|
#![feature(const_generics)]
|
|
#![feature(maybe_uninit_extra)]
|
|
#![feature(const_in_array_repeat_expressions)]
|
|
|
|
|
|
|
|
mod common;
|
|
mod entity;
|
|
mod patch;
|
|
mod login;
|
|
mod ship;
|
|
|
|
use std::thread;
|
|
use std::time::SystemTime;
|
|
use log::{info};
|
|
|
|
use patch::patch::{PatchServerState, generate_patch_tree, load_config, load_motd};
|
|
use login::login::LoginServerState;
|
|
use login::character::CharacterServerState;
|
|
use ship::ship::ShipServerState;
|
|
use entity::account::{UserAccount, UserSettings};
|
|
use entity::gateway::{EntityGateway, InMemoryGateway};
|
|
use entity::item::ItemLocation;
|
|
use libpso::{utf8_to_array, utf8_to_utf16_array};
|
|
//use crate::utf8_to_utf16_array;
|
|
|
|
use libpso::item::*;
|
|
|
|
fn setup_logger() {
|
|
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());
|
|
let fileout = fern::Dispatch::new()
|
|
.level(log::LevelFilter::Trace)
|
|
.chain(fern::log_file(format!("elseware-{}.log", chrono::Local::now().format("%Y-%m-%d_%H:%M:%S"))).unwrap());
|
|
fern::Dispatch::new()
|
|
.chain(stdio)
|
|
.chain(fileout)
|
|
.apply().unwrap();
|
|
}
|
|
|
|
|
|
fn main() {
|
|
setup_logger();
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
let fake_user = UserAccount {
|
|
id: 1,
|
|
username: "hi".to_string(),
|
|
password: bcrypt::hash("qwer", 5).unwrap(),
|
|
guildcard: Some(1),
|
|
team_id: None,
|
|
banned: false,
|
|
muted_until: SystemTime::now(),
|
|
created_at: SystemTime::now(),
|
|
flags: 0,
|
|
};
|
|
entity_gateway.set_user(&fake_user);
|
|
entity_gateway.create_user_settings_by_user(&fake_user);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user);
|
|
character.name = "Test Char 1".into();
|
|
entity_gateway.set_character(&character);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user);
|
|
character.slot = 2;
|
|
character.name = "\tE12345678".into();
|
|
character.exp = 80000000;
|
|
entity_gateway.set_character(&character);
|
|
|
|
let fake_user2 = UserAccount {
|
|
id: 2,
|
|
username: "hi2".to_string(),
|
|
password: bcrypt::hash("qwer", 5).unwrap(),
|
|
guildcard: Some(2),
|
|
team_id: None,
|
|
banned: false,
|
|
muted_until: SystemTime::now(),
|
|
created_at: SystemTime::now(),
|
|
flags: 0,
|
|
};
|
|
entity_gateway.set_user(&fake_user2);
|
|
entity_gateway.create_user_settings_by_user(&fake_user2);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user2);
|
|
character.name = "Test Char 3".into();
|
|
entity_gateway.set_character(&character);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user2);
|
|
character.slot = 2;
|
|
character.name = "Test Char 4".into();
|
|
entity_gateway.set_character(&character);
|
|
|
|
let fake_user3 = UserAccount {
|
|
id: 3,
|
|
username: "hi3".to_string(),
|
|
password: bcrypt::hash("qwer", 5).unwrap(),
|
|
guildcard: Some(3),
|
|
team_id: None,
|
|
banned: false,
|
|
muted_until: SystemTime::now(),
|
|
created_at: SystemTime::now(),
|
|
flags: 0,
|
|
};
|
|
entity_gateway.set_user(&fake_user3);
|
|
entity_gateway.create_user_settings_by_user(&fake_user3);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user3);
|
|
character.name = "Test Char 5".into();
|
|
entity_gateway.set_character(&character);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user3);
|
|
character.slot = 2;
|
|
character.name = "Test Char 6".into();
|
|
entity_gateway.set_character(&character);
|
|
|
|
let fake_user4 = UserAccount {
|
|
id: 4,
|
|
username: "hi4".to_string(),
|
|
password: bcrypt::hash("qwer", 5).unwrap(),
|
|
guildcard: Some(4),
|
|
team_id: None,
|
|
banned: false,
|
|
muted_until: SystemTime::now(),
|
|
created_at: SystemTime::now(),
|
|
flags: 0,
|
|
};
|
|
entity_gateway.set_user(&fake_user4);
|
|
entity_gateway.create_user_settings_by_user(&fake_user4);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user4);
|
|
character.name = "Test Char 7".into();
|
|
entity_gateway.set_character(&character);
|
|
let mut character = entity_gateway.new_character_by_user(&fake_user4);
|
|
character.slot = 2;
|
|
character.name = "Test Char 8".into();
|
|
entity_gateway.set_character(&character);
|
|
|
|
async_std::task::block_on(async move {
|
|
let thread_entity_gateway = entity_gateway.clone();
|
|
let patch = async_std::task::spawn(async {
|
|
info!("[patch] starting server");
|
|
let patch_config = load_config();
|
|
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);
|
|
|
|
crate::common::mainloop::mainloop_async(patch_state, patch_config.port).await;
|
|
});
|
|
|
|
let thread_entity_gateway = entity_gateway.clone();
|
|
let auth = async_std::task::spawn(async {
|
|
info!("[auth] starting server");
|
|
let auth_state = LoginServerState::new(thread_entity_gateway);
|
|
|
|
common::mainloop::mainloop_async(auth_state, login::login::LOGIN_PORT).await;
|
|
});
|
|
|
|
let thread_entity_gateway = entity_gateway.clone();
|
|
let character = async_std::task::spawn(async {
|
|
info!("[character] starting server");
|
|
let char_state = CharacterServerState::new(thread_entity_gateway);
|
|
|
|
common::mainloop::mainloop_async(char_state, login::character::CHARACTER_PORT).await;
|
|
});
|
|
|
|
let thread_entity_gateway = entity_gateway.clone();
|
|
let ship = async_std::task::spawn(async {
|
|
info!("[ship] starting server");
|
|
let ship_state = ShipServerState::new(thread_entity_gateway);
|
|
common::mainloop::mainloop_async(ship_state, ship::ship::SHIP_PORT).await;
|
|
});
|
|
|
|
futures::join!(patch, auth, character, ship);
|
|
});
|
|
}
|