Browse Source

security_data -> session

pbs
jake 5 years ago
parent
commit
8b8e4af0f3
  1. 27
      src/login/character.rs
  2. 45
      src/login/login.rs

27
src/login/character.rs

@ -135,7 +135,7 @@ struct ClientState {
user: Option<UserAccount>,
characters: Option<[Option<Character>; 4]>,
guildcard_data_buffer: Option<Vec<u8>>,
security_data: [u8; 40],
session: Session,
}
impl ClientState {
@ -145,7 +145,7 @@ impl ClientState {
user: None,
characters: None,
guildcard_data_buffer: None,
security_data: [0; 40],
session: Session::new(),
}
}
}
@ -197,15 +197,15 @@ impl<EG: EntityGateway> CharacterServerState<EG> {
let client = self.clients.get_mut(&id).ok_or(CharacterError::ClientNotFound(id))?;
Ok(match get_login_status(&self.entity_gateway, pkt) {
Ok(user) => {
let mut response = LoginResponse::by_status(AccountStatus::Ok, [0; 40]);
let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::new());
response.guildcard = user.guildcard.map_or(0, |gc| gc) as u32;
response.team_id = user.team_id.map_or(0, |ti| ti) as u32;
client.user = Some(user);
client.security_data = pkt.security_data;
client.session = pkt.session;
vec![SendCharacterPacket::LoginResponse(response)]
},
Err(err) => {
vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(err, [0; 40]))]
vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(err, Session::new()))]
}
})
}
@ -264,12 +264,11 @@ impl<EG: EntityGateway> CharacterServerState<EG> {
}
else {
let user = client.user.as_ref().unwrap();
client.security_data[0..4].clone_from_slice(&[1,3,3,7]);
client.security_data[4] = select.slot as u8;
client.security_data[5] = 1;
client.session.action = SessionAction::SelectCharacter;
client.session.character_slot = select.slot as u8;
Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_char_select(user.guildcard.unwrap_or(0),
user.team_id.unwrap_or(1),
client.security_data)),
client.session)),
SendCharacterPacket::CharAck(CharAck {
slot: select.slot,
code: 1,
@ -348,7 +347,7 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
-> Result<Box<dyn Iterator<Item = (ClientId, SendCharacterPacket)>>, CharacterError> {
Ok(match pkt {
RecvCharacterPacket::Login(login) => {
if login.security_data[0..4] == [1,3,3,7] {
if login.session.action == SessionAction::SelectCharacter {
Box::new(self.send_ship_list(id, login)?.into_iter().map(move |pkt| (id, pkt)))
}
else {
@ -398,6 +397,7 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
}
)].into_iter().map(move |pkt| (id, pkt)))
},
// TODO: move USERFLAGS over to SessionAction
RecvCharacterPacket::CharacterPreview(preview) => {
let client = self.clients.get_mut(&id).ok_or(CharacterError::ClientNotFound(id))?;
let mut user = client.user.as_mut().unwrap();
@ -417,14 +417,13 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
// TODO: dressing room stuff
}
client.security_data[0..4].clone_from_slice(&[1,3,3,7]);
client.security_data[4] = preview.slot as u8;
client.security_data[5] = 1;
client.session.action = SessionAction::SelectCharacter;
client.session.character_slot = preview.slot as u8;
user.flags = 0;
self.entity_gateway.set_user(&user);
Box::new(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_char_select(user.guildcard.unwrap_or(0),
user.team_id.unwrap_or(1),
client.security_data)),
client.session)),
SendCharacterPacket::CharAck(CharAck {
slot: preview.slot,
code: 0

45
src/login/login.rs

@ -82,14 +82,14 @@ impl<EG: EntityGateway> LoginServerState<EG> {
fn validate_login(&mut self, pkt: &Login) -> Vec<SendLoginPacket> {
match get_login_status(&self.entity_gateway, pkt) {
Ok(_user) => {
let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.security_data));
let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.session));
let ip = net::Ipv4Addr::new(127,0,0,1);
let ip = u32::from_ne_bytes(ip.octets());
vec![response,
SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::login::character::CHARACTER_PORT))]
},
Err(err) => {
vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.security_data))]
vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.session))]
}
}
}
@ -134,7 +134,6 @@ mod test {
use super::*;
const LOGIN_PACKET: RecvLoginPacket = RecvLoginPacket::Login(Login {
flag: 0,
tag: 65536,
guildcard: 0,
version: 65,
@ -148,8 +147,14 @@ mod test {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0],
hwinfo: [129, 1, 1, 1, 1, 1, 1, 1],
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session: Session {
version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session_id: 0,
interserver_checksum: 0,
action: SessionAction::None,
character_slot: 0,
}
});
#[test]
@ -183,8 +188,14 @@ mod test {
tag: 65536,
guildcard: 0,
team_id: 0,
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session: Session {
version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session_id: 0,
interserver_checksum: 0,
action: SessionAction::None,
character_slot: 0,
},
caps: 258
})),
(ClientId(1), SendLoginPacket::RedirectClient(RedirectClient {
@ -214,8 +225,14 @@ mod test {
tag: 65536,
guildcard: 0,
team_id: 0,
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session: Session {
version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session_id: 0,
interserver_checksum: 0,
action: SessionAction::None,
character_slot: 0,
},
caps: 258
}))])
}
@ -251,8 +268,14 @@ mod test {
tag: 65536,
guildcard: 0,
team_id: 0,
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session: Session {
version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session_id: 0,
interserver_checksum: 0,
action: SessionAction::None,
character_slot: 0,
},
caps: 258
}))])
}

Loading…
Cancel
Save