|
|
@ -323,10 +323,13 @@ impl<EG: EntityGateway> CharacterServerState<EG> { |
|
|
|
Ok(user) => {
|
|
|
|
if let Some(connected_client) = self.connected_clients.get(&user.id) {
|
|
|
|
if let Some(expires) = connected_client.expires {
|
|
|
|
if expires < chrono::Utc::now() {
|
|
|
|
if expires > chrono::Utc::now() {
|
|
|
|
return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::new()))]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::new()))]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::new());
|
|
|
@ -337,7 +340,7 @@ impl<EG: EntityGateway> CharacterServerState<EG> { |
|
|
|
|
|
|
|
self.connected_clients.insert(user.id.clone(), ConnectedClient {
|
|
|
|
ship_id: None,
|
|
|
|
expires: Some(chrono::Utc::now() + chrono::Duration::minutes(1)),
|
|
|
|
expires: None, //Some(chrono::Utc::now() + chrono::Duration::minutes(1)),
|
|
|
|
});
|
|
|
|
|
|
|
|
client.user = Some(user);
|
|
|
@ -509,11 +512,19 @@ impl<EG: EntityGateway> CharacterServerState<EG> { |
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn select_ship(&mut self, menuselect: &MenuSelect) -> Result<Vec<SendCharacterPacket>, anyhow::Error> {
|
|
|
|
fn select_ship(&mut self, id: ClientId, menuselect: &MenuSelect) -> Result<Vec<SendCharacterPacket>, anyhow::Error> {
|
|
|
|
if menuselect.menu != SHIP_MENU_ID {
|
|
|
|
Err(CharacterError::InvalidMenuSelection(menuselect.menu, menuselect.item))?;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(client) = self.clients.get(&id) {
|
|
|
|
if let Some(user) = &client.user {
|
|
|
|
if let Some(cc) = self.connected_clients.get_mut(&user.id) {
|
|
|
|
cc.ship_id = Some(ServerId(menuselect.item as usize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let ship = self.ships.get(&ServerId(menuselect.item as usize))
|
|
|
|
.ok_or(CharacterError::InvalidMenuSelection(menuselect.menu, menuselect.item))?;
|
|
|
|
Ok(vec![SendCharacterPacket::RedirectClient(RedirectClient::new(u32::from_le_bytes(ship.ip.octets()), ship.port))])
|
|
|
@ -604,9 +615,8 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> { |
|
|
|
|
|
|
|
async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, SendCharacterPacket)>, anyhow::Error> {
|
|
|
|
if let Some(client) = self.clients.remove(&id) {
|
|
|
|
if let Some(mut user) = client.user {
|
|
|
|
user.at_character= false;
|
|
|
|
self.entity_gateway.save_user(&user).await;
|
|
|
|
if let Some(user) = client.user {
|
|
|
|
self.connected_clients.remove(&user.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(Vec::new())
|
|
|
|