Browse Source

initial character create test

pbs
andy 5 years ago
parent
commit
8e8f21403f
  1. 57
      src/login/character.rs

57
src/login/character.rs

@ -131,6 +131,7 @@ fn generate_param_data(path: &str) -> (ParamDataHeader, Vec<u8>) {
}, buffer)
}
#[derive(Clone)]
struct ClientState {
param_index: usize,
user: Option<UserAccount>,
@ -464,8 +465,9 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
mod test {
use super::*;
use crate::entity::account::UserSettings;
use libpso::character::settings;
use libpso::character::{settings, character};
use std::time::SystemTime;
use crate::entity::gateway::{InMemoryGateway};
#[test]
fn test_option_send() {
@ -521,4 +523,57 @@ mod test {
let bytes = send[0].1.as_bytes();
assert!(bytes == [0xC, 0, 0xE8, 0x02, 0,0,0,0, 1,0,0,0]);
}
#[test]
fn test_character_create() {
let TestData = InMemoryGateway::new();
let mut fake_user = ClientState::new();
fake_user.user = Some(UserAccount {
id: 3,
username: "hi3".to_string(),
password: bcrypt::hash("qwer", 5).unwrap(),
guildcard: Some(3u32),
team_id: None,
banned: false,
muted_until: SystemTime::now(),
created_at: SystemTime::now(),
flags: 0,
});
let mut server = CharacterServerState::new(TestData.clone());
server.clients.insert(ClientId(1), fake_user.clone());
let mut send = server.handle(ClientId(1), &RecvCharacterPacket::SetFlag(SetFlag {flags: 1})).unwrap().collect::<Vec<_>>();
send = server.handle(ClientId(1), &RecvCharacterPacket::CharacterPreview(CharacterPreview {slot: 1, character: character::SelectScreenCharacter {
exp: 0,
level: 0,
guildcard: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
_unknown: [0, 0],
name_color: 4294967295,
model: 0,
_unused: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
name_color_checksum: 0,
section_id: 4,
ch_class: 2,
v2flags: 0,
version: 3,
v1flags: 49,
costume: 0,
skin: 4,
face: 0,
head: 0,
hair: 0,
hair_r: 0,
hair_g: 0,
hair_b: 0,
prop_x: 0.33333334,
prop_y: 0.0,
name: [9, 69, 116, 101, 115, 116, 32, 110, 97, 109, 101, 0, 0, 0, 0, 0], // "\tEtest name"
play_time: 0,
} })).unwrap().collect::<Vec<_>>();
assert!(send.len() == 2);
let chars = TestData.get_characters_by_user(&fake_user.user.clone().unwrap());
assert!(chars[1].unwrap().character.name == [9, 69, 116, 101, 115, 116, 32, 110, 97, 109, 101, 0, 0, 0, 0, 0]);
assert!(chars[0].is_none());
}
}
Loading…
Cancel
Save