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.
112 lines
3.0 KiB
112 lines
3.0 KiB
#![feature(const_generics)]
|
|
|
|
mod common;
|
|
mod login;
|
|
mod entity;
|
|
|
|
use std::thread;
|
|
use std::collections::HashMap;
|
|
|
|
use bcrypt;
|
|
|
|
use libpso::character::settings;
|
|
use libpso::character::character as pso_character;
|
|
use libpso::character::guildcard;
|
|
use libpso::{utf8_to_array, utf8_to_utf16_array};
|
|
|
|
use entity::gateway::EntityGateway;
|
|
use entity::account::{UserAccount, UserSettings, GuildCardData};
|
|
use entity::character::Character;
|
|
|
|
use login::login::LoginServerState;
|
|
use login::character::CharacterServerState;
|
|
|
|
use std::time::SystemTime;
|
|
|
|
#[derive(Clone)]
|
|
struct LoginStubData {
|
|
users: HashMap<String, UserAccount>,
|
|
characters: [Option<Character> ;4],
|
|
}
|
|
|
|
impl LoginStubData {
|
|
fn new() -> LoginStubData {
|
|
let mut c = pso_character::Character::default();
|
|
c.name = utf8_to_utf16_array!("Test Char", 16);
|
|
|
|
let mut users = HashMap::new();
|
|
users.insert("hi".to_string(), UserAccount {
|
|
id: 1,
|
|
username: "hi".to_owned(),
|
|
password: bcrypt::hash("qwer", 5).unwrap(),
|
|
guildcard: None,
|
|
team_id: None,
|
|
banned: false,
|
|
muted_until: SystemTime::now(),
|
|
created_at: SystemTime::now(),
|
|
flags: 0,
|
|
});
|
|
|
|
LoginStubData {
|
|
users: users,
|
|
|
|
characters: [Some(Character {
|
|
id: 1,
|
|
slot: 0,
|
|
user_id: 1,
|
|
character: c,
|
|
}),
|
|
None, None, None]
|
|
}
|
|
}
|
|
}
|
|
|
|
impl EntityGateway for LoginStubData {
|
|
fn get_user_by_name(&self, username: String) -> Option<UserAccount> {
|
|
self.users.get(&username).map(|user| user.clone())
|
|
}
|
|
|
|
fn get_user_settings_by_user(&self, user: &UserAccount) -> Option<UserSettings> {
|
|
Some(UserSettings {
|
|
id: 0,
|
|
user_id: user.id,
|
|
settings: settings::UserSettings::default()
|
|
})
|
|
}
|
|
|
|
fn set_user(&mut self, user: &UserAccount) {
|
|
self.users.insert(user.username.clone(), user.clone());
|
|
}
|
|
|
|
fn get_characters_by_user(&self, _user: &UserAccount) -> [Option<Character>; 4] {
|
|
self.characters
|
|
}
|
|
|
|
fn set_character(&mut self, char: &Character) {
|
|
self.characters[char.slot as usize] = Some(char.clone());
|
|
}
|
|
|
|
fn get_guild_card_data_by_user(&self, user: &UserAccount) -> GuildCardData {
|
|
GuildCardData {
|
|
id: 1,
|
|
user_id: user.id,
|
|
guildcard: guildcard::GuildCardData::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
println!("[login+character] starting server");
|
|
|
|
let auth_thread = thread::spawn(|| {
|
|
let auth_state = LoginServerState::new(LoginStubData::new());
|
|
common::mainloop::mainloop(auth_state, login::login::LOGIN_PORT);
|
|
});
|
|
let char_thread = thread::spawn(|| {
|
|
let char_state = CharacterServerState::new(LoginStubData::new());
|
|
common::mainloop::mainloop(char_state, login::character::CHARACTER_PORT);
|
|
});
|
|
|
|
auth_thread.join().unwrap();
|
|
char_thread.join().unwrap();
|
|
}
|