rust/hedgewars-server/src/server/handlers.rs
changeset 14786 8ecdb5c6bb2a
parent 14785 a1077e8d26f4
child 14788 6dea1ca64992
equal deleted inserted replaced
14785:a1077e8d26f4 14786:8ecdb5c6bb2a
   220                         common::remove_client(server, response, "User quit: ".to_string() + &msg);
   220                         common::remove_client(server, response, "User quit: ".to_string() + &msg);
   221                     }
   221                     }
   222                     HWProtocolMessage::Quit(None) => {
   222                     HWProtocolMessage::Quit(None) => {
   223                         common::remove_client(server, response, "User quit".to_string());
   223                         common::remove_client(server, response, "User quit".to_string());
   224                     }
   224                     }
       
   225                     HWProtocolMessage::Info(nick) => {
       
   226                         if let Some(client) = server.find_client(&nick) {
       
   227                             let admin_sign = if client.is_admin() { "@" } else { "" };
       
   228                             let master_sign = if client.is_master() { "+" } else { "" };
       
   229                             let room_info = match client.room_id {
       
   230                                 Some(room_id) => {
       
   231                                     let room = &server.rooms[room_id];
       
   232                                     let status = match room.game_info {
       
   233                                         Some(_) if client.teams_in_game == 0 => "(spectating)",
       
   234                                         Some(_) => "(playing)",
       
   235                                         None => "",
       
   236                                     };
       
   237                                     format!(
       
   238                                         "[{}{}room {}]{}",
       
   239                                         admin_sign, master_sign, room.name, status
       
   240                                     )
       
   241                                 }
       
   242                                 None => format!("[{}lobby]", admin_sign),
       
   243                             };
       
   244 
       
   245                             let info = vec![
       
   246                                 client.nick.clone(),
       
   247                                 utils::protocol_version_string(client.protocol_number).to_string(),
       
   248                                 room_info,
       
   249                             ];
       
   250                             Info(info);
       
   251                         } else {
       
   252                             response
       
   253                                 .add(server_chat("Player is not online.".to_string()).send_self())
       
   254                         }
       
   255                     }
       
   256                     HWProtocolMessage::ToggleServerRegisteredOnly => {
       
   257                         if !server.clients[client_id].is_admin() {
       
   258                             response.add(Warning("Access denied.".to_string()).send_self());
       
   259                         } else {
       
   260                             server.set_is_registered_only(server.is_registered_only());
       
   261                             let msg = if server.is_registered_only() {
       
   262                                 "This server no longer allows unregistered players to join."
       
   263                             } else {
       
   264                                 "This server now allows unregistered players to join."
       
   265                             };
       
   266                             response.add(server_chat(msg.to_string()).send_all());
       
   267                         }
       
   268                     }
   225                     HWProtocolMessage::Global(msg) => {
   269                     HWProtocolMessage::Global(msg) => {
   226                         if !server.clients[client_id].is_admin() {
   270                         if !server.clients[client_id].is_admin() {
   227                             response.add(Warning("Access denied.".to_string()).send_self());
   271                             response.add(Warning("Access denied.".to_string()).send_self());
   228                         } else {
   272                         } else {
   229                             response.add(global_chat(msg).send_all())
   273                             response.add(global_chat(msg).send_all())
       
   274                         }
       
   275                     }
       
   276                     HWProtocolMessage::SuperPower => {
       
   277                         if !server.clients[client_id].is_admin() {
       
   278                             response.add(Warning("Access denied.".to_string()).send_self());
       
   279                         } else {
       
   280                             server.clients[client_id].set_has_super_power(true);
       
   281                             response
       
   282                                 .add(server_chat("Super power activated.".to_string()).send_self())
   230                         }
   283                         }
   231                     }
   284                     }
   232                     HWProtocolMessage::Watch(id) => {
   285                     HWProtocolMessage::Watch(id) => {
   233                         #[cfg(feature = "official-server")]
   286                         #[cfg(feature = "official-server")]
   234                         {
   287                         {
   276     response: &mut Response,
   329     response: &mut Response,
   277     io_result: IoResult,
   330     io_result: IoResult,
   278 ) {
   331 ) {
   279     match io_result {
   332     match io_result {
   280         IoResult::Account(Some(info)) => {
   333         IoResult::Account(Some(info)) => {
   281             response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
   334             if !info.is_registered && server.is_registered_only() {
   282             if let Some(client) = server.anteroom.remove_client(client_id) {
   335                 response.add(
   283                 server.add_client(client_id, client);
   336                     Bye("This server only allows registered users to join.".to_string())
   284                 let client = &mut server.clients[client_id];
   337                         .send_self(),
   285                 client.set_is_admin(info.is_admin);
   338                 );
   286                 client.set_is_contributor(info.is_admin)
   339                 response.remove_client(client_id);
       
   340             } else {
       
   341                 response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
       
   342                 if let Some(client) = server.anteroom.remove_client(client_id) {
       
   343                     server.add_client(client_id, client);
       
   344                     let client = &mut server.clients[client_id];
       
   345                     client.set_is_admin(info.is_admin);
       
   346                     client.set_is_contributor(info.is_admin)
       
   347                 }
   287             }
   348             }
   288         }
   349         }
   289         IoResult::Account(None) => {
   350         IoResult::Account(None) => {
   290             response.add(Error("Authentication failed.".to_string()).send_self());
   351             response.add(Error("Authentication failed.".to_string()).send_self());
   291             response.remove_client(client_id);
   352             response.remove_client(client_id);