rust/hedgewars-server/src/handlers.rs
changeset 15532 f1205f33bf5b
parent 15526 24f692e791d3
child 15534 bb93e9642b5b
equal deleted inserted replaced
15531:ede5f4ec48f3 15532:f1205f33bf5b
   113         protocol: u16,
   113         protocol: u16,
   114         password_hash: String,
   114         password_hash: String,
   115         client_salt: String,
   115         client_salt: String,
   116         server_salt: String,
   116         server_salt: String,
   117     },
   117     },
       
   118     GetCheckerAccount {
       
   119         nick: String,
       
   120         password: String,
       
   121     },
   118     GetReplay {
   122     GetReplay {
   119         id: u32,
   123         id: u32,
   120     },
   124     },
   121     SaveRoom {
   125     SaveRoom {
   122         room_id: RoomId,
   126         room_id: RoomId,
   131 
   135 
   132 #[derive(Debug)]
   136 #[derive(Debug)]
   133 pub enum IoResult {
   137 pub enum IoResult {
   134     AccountRegistered(bool),
   138     AccountRegistered(bool),
   135     Account(Option<AccountInfo>),
   139     Account(Option<AccountInfo>),
       
   140     CheckerAccount { is_registered: bool },
   136     Replay(Option<Replay>),
   141     Replay(Option<Replay>),
   137     SaveRoom(RoomId, bool),
   142     SaveRoom(RoomId, bool),
   138     LoadRoom(RoomId, Option<String>),
   143     LoadRoom(RoomId, Option<String>),
   139 }
   144 }
   140 
   145 
   408         IoResult::AccountRegistered(is_registered) => {
   413         IoResult::AccountRegistered(is_registered) => {
   409             if !is_registered && state.server.is_registered_only() {
   414             if !is_registered && state.server.is_registered_only() {
   410                 response.add(Bye(REGISTRATION_REQUIRED.to_string()).send_self());
   415                 response.add(Bye(REGISTRATION_REQUIRED.to_string()).send_self());
   411                 response.remove_client(client_id);
   416                 response.remove_client(client_id);
   412             } else if is_registered {
   417             } else if is_registered {
   413                 let salt = state.anteroom.clients[client_id].server_salt.clone();
   418                 let client = &state.anteroom.clients[client_id];
   414                 response.add(AskPassword(salt).send_self());
   419                 response.add(AskPassword(client.server_salt.clone()).send_self());
   415             } else if let Some(client) = state.anteroom.remove_client(client_id) {
   420             } else if let Some(client) = state.anteroom.remove_client(client_id) {
   416                 state.server.add_client(client_id, client);
   421                 state.server.add_client(client_id, client);
   417                 common::get_lobby_join_data(&state.server, response);
   422                 common::get_lobby_join_data(&state.server, response);
   418             }
   423             }
       
   424         }
       
   425         IoResult::Account(None) => {
       
   426             response.add(Bye(AUTHENTICATION_FAILED.to_string()).send_self());
       
   427             response.remove_client(client_id);
   419         }
   428         }
   420         IoResult::Account(Some(info)) => {
   429         IoResult::Account(Some(info)) => {
   421             response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
   430             response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
   422             if let Some(mut client) = state.anteroom.remove_client(client_id) {
   431             if let Some(mut client) = state.anteroom.remove_client(client_id) {
   423                 client.is_registered = info.is_registered;
   432                 client.is_registered = info.is_registered;
   425                 client.is_contributor = info.is_contributor;
   434                 client.is_contributor = info.is_contributor;
   426                 state.server.add_client(client_id, client);
   435                 state.server.add_client(client_id, client);
   427                 common::get_lobby_join_data(&state.server, response);
   436                 common::get_lobby_join_data(&state.server, response);
   428             }
   437             }
   429         }
   438         }
   430         IoResult::Account(None) => {
   439         IoResult::CheckerAccount { is_registered } => {
   431             response.error(AUTHENTICATION_FAILED);
   440             if is_registered {
   432             response.remove_client(client_id);
   441                 if let Some(client) = state.anteroom.remove_client(client_id) {
       
   442                     state.server.add_client(client_id, client);
       
   443                     response.add(LogonPassed.send_self());
       
   444                 }
       
   445             } else {
       
   446                 response.add(Bye(NO_CHECKER_RIGHTS.to_string()).send_self());
       
   447                 response.remove_client(client_id);
       
   448             }
   433         }
   449         }
   434         IoResult::Replay(Some(replay)) => {
   450         IoResult::Replay(Some(replay)) => {
   435             let client = state.server.client(client_id);
   451             let client = state.server.client(client_id);
   436             let protocol = client.protocol_number;
   452             let protocol = client.protocol_number;
   437             let start_msg = if protocol < 58 {
   453             let start_msg = if protocol < 58 {