Browse Source

pkt E2, player settings

pbs
Jake Probst 5 years ago
parent
commit
92ef648c48
  1. 64
      src/login/character.rs

64
src/login/character.rs

@ -89,8 +89,18 @@ impl<DA: DataAccess> CharacterServerState<DA> {
}
}
fn get_settings(&mut self) -> Box<PktVec> {
pktvec![]
fn get_settings(&mut self) -> Vec<SendCharacterPacket> {
let user = self.user.as_ref().unwrap();
let settings = match self.shared_state.data_access.get_user_settings_by_user(&user) {
Some(settings) => settings,
None => self.shared_state.data_access.create_user_settings_by_user(&user),
};
let pkt = SendKeyAndTeamSettings::new(settings.settings.key_config,
settings.settings.joystick_config, 0, 0);
let pkt = SendCharacterPacket::SendKeyAndTeamSettings(pkt);
vec![pkt]
}
}
@ -134,3 +144,53 @@ pub fn new_client<DA: DataAccess + 'static>(socket: mio::tcp::TcpStream, shared_
let client = Client::new(socket, Box::new(state));
client.io_loop();
}
#[cfg(test)]
mod test {
use super::*;
use crate::models::{EUserSettings, UserSettings};
use libpso::character::settings;
use std::time::SystemTime;
#[test]
fn test_login() {
}
#[test]
fn test_option_send() {
struct TestData {
}
impl DataAccess for TestData {
fn get_user_settings_by_user(&self, _user: &UserAccount) -> Option<UserSettings> {
Some(UserSettings {
id: 0,
user_id: 0,
settings: EUserSettings(settings::UserSettings::default())
})
}
}
let shared = SharedLoginState::new(TestData {});
let mut server = CharacterServerState::new(shared);
server.user = Some(UserAccount {
id: 1,
username: "testuser".to_owned(),
password: bcrypt::hash("mypassword", 5).unwrap(),
guildcard: None,
team_id: None,
banned: false,
muted_until: SystemTime::now(),
created_at: SystemTime::now(),
});
let send = server.handle(&RecvCharacterPacket::RequestSettings(RequestSettings {flag: 0})).collect::<Vec<_>>();
assert!(send.len() == 1);
let bytes = send[0].as_bytes();
assert!(bytes[2] == 0xE2);
assert!(bytes.len() == 0xAFC);
}
}
Loading…
Cancel
Save