rust/hedgewars-server/src/handlers.rs
changeset 15103 823052e66611
parent 15102 80ff12edf5e6
child 15113 7d6e519a88c5
equal deleted inserted replaced
15102:80ff12edf5e6 15103:823052e66611
    55     pub is_contributor: bool,
    55     pub is_contributor: bool,
    56     pub server_hash: Sha1Digest,
    56     pub server_hash: Sha1Digest,
    57 }
    57 }
    58 
    58 
    59 pub enum IoTask {
    59 pub enum IoTask {
       
    60     CheckRegistered {
       
    61         nick: String,
       
    62     },
    60     GetAccount {
    63     GetAccount {
    61         nick: String,
    64         nick: String,
    62         protocol: u16,
    65         protocol: u16,
    63         password_hash: String,
    66         password_hash: String,
    64         client_salt: String,
    67         client_salt: String,
    78     },
    81     },
    79 }
    82 }
    80 
    83 
    81 #[derive(Debug)]
    84 #[derive(Debug)]
    82 pub enum IoResult {
    85 pub enum IoResult {
       
    86     AccountRegistered(bool),
    83     Account(Option<AccountInfo>),
    87     Account(Option<AccountInfo>),
    84     Replay(Option<Replay>),
    88     Replay(Option<Replay>),
    85     SaveRoom(RoomId, bool),
    89     SaveRoom(RoomId, bool),
    86     LoadRoom(RoomId, Option<String>),
    90     LoadRoom(RoomId, Option<String>),
    87 }
    91 }
   326     client_id: ClientId,
   330     client_id: ClientId,
   327     response: &mut Response,
   331     response: &mut Response,
   328     io_result: IoResult,
   332     io_result: IoResult,
   329 ) {
   333 ) {
   330     match io_result {
   334     match io_result {
   331         IoResult::Account(Some(info)) => {
   335         IoResult::AccountRegistered(is_registered) => {
   332             if !info.is_registered && server.is_registered_only() {
   336             if !is_registered && server.is_registered_only() {
   333                 response.add(
   337                 response.add(
   334                     Bye("This server only allows registered users to join.".to_string())
   338                     Bye("This server only allows registered users to join.".to_string())
   335                         .send_self(),
   339                         .send_self(),
   336                 );
   340                 );
   337                 response.remove_client(client_id);
   341                 response.remove_client(client_id);
   338             } else {
   342             } else if is_registered {
   339                 response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
   343                 let salt = server.anteroom.clients[client_id].server_salt.clone();
   340                 if let Some(client) = server.anteroom.remove_client(client_id) {
   344                 response.add(AskPassword(salt).send_self());
   341                     server.add_client(client_id, client);
   345             } else if let Some(client) = server.anteroom.remove_client(client_id) {
   342                     let client = &mut server.clients[client_id];
   346                 server.add_client(client_id, client);
   343                     client.set_is_registered(info.is_registered);
   347                 common::join_lobby(server, response);
   344                     client.set_is_admin(info.is_admin);
   348             }
   345                     client.set_is_contributor(info.is_admin)
   349         }
   346                 }
   350         IoResult::Account(Some(info)) => {
       
   351             response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
       
   352             if let Some(client) = server.anteroom.remove_client(client_id) {
       
   353                 server.add_client(client_id, client);
       
   354                 let client = &mut server.clients[client_id];
       
   355                 client.set_is_registered(info.is_registered);
       
   356                 client.set_is_admin(info.is_admin);
       
   357                 client.set_is_contributor(info.is_contributor);
       
   358                 common::join_lobby(server, response);
   347             }
   359             }
   348         }
   360         }
   349         IoResult::Account(None) => {
   361         IoResult::Account(None) => {
   350             response.add(Error("Authentication failed.".to_string()).send_self());
   362             response.add(Error("Authentication failed.".to_string()).send_self());
   351             response.remove_client(client_id);
   363             response.remove_client(client_id);