rust/hedgewars-server/src/handlers.rs
changeset 15831 7d0f747afcb8
parent 15810 ee84e417d8d0
child 16002 e915ed28726e
equal deleted inserted replaced
15830:ea459da15b30 15831:7d0f747afcb8
   357                             response.add(server_chat(SUPER_POWER.to_string()).send_self())
   357                             response.add(server_chat(SUPER_POWER.to_string()).send_self())
   358                         } else {
   358                         } else {
   359                             response.warn(ACCESS_DENIED);
   359                             response.warn(ACCESS_DENIED);
   360                         }
   360                         }
   361                     }
   361                     }
       
   362                     #[allow(unused_variables)]
   362                     HwProtocolMessage::Watch(id) => {
   363                     HwProtocolMessage::Watch(id) => {
   363                         #[cfg(feature = "official-server")]
   364                         #[cfg(feature = "official-server")]
   364                         {
   365                         {
   365                             response.request_io(IoTask::GetReplay { id })
   366                             response.request_io(IoTask::GetReplay { id })
   366                         }
   367                         }
   384     state: &mut ServerState,
   385     state: &mut ServerState,
   385     client_id: ClientId,
   386     client_id: ClientId,
   386     response: &mut Response,
   387     response: &mut Response,
   387     addr: [u8; 4],
   388     addr: [u8; 4],
   388     is_local: bool,
   389     is_local: bool,
   389 ) {
   390 ) -> bool {
   390     let ban_reason = Some(addr)
   391     let ban_reason = Some(addr)
   391         .filter(|_| !is_local)
   392         .filter(|_| !is_local)
   392         .and_then(|a| state.anteroom.find_ip_ban(a));
   393         .and_then(|a| state.anteroom.find_ip_ban(a));
   393     if let Some(reason) = ban_reason {
   394     if let Some(reason) = ban_reason {
   394         response.add(HwServerMessage::Bye(reason).send_self());
   395         response.add(HwServerMessage::Bye(reason).send_self());
   395         response.remove_client(client_id);
   396         response.remove_client(client_id);
       
   397         false
   396     } else {
   398     } else {
   397         let mut salt = [0u8; 18];
   399         let mut salt = [0u8; 18];
   398         thread_rng().fill_bytes(&mut salt);
   400         thread_rng().fill_bytes(&mut salt);
   399 
   401 
   400         state
   402         state
   401             .anteroom
   403             .anteroom
   402             .add_client(client_id, encode(&salt), is_local);
   404             .add_client(client_id, encode(&salt), is_local);
   403 
   405 
   404         response.add(HwServerMessage::Connected(utils::SERVER_MESSAGE.to_owned(), utils::SERVER_VERSION).send_self());
   406         response.add(
       
   407             HwServerMessage::Connected(utils::SERVER_MESSAGE.to_owned(), utils::SERVER_VERSION)
       
   408                 .send_self(),
       
   409         );
       
   410         true
   405     }
   411     }
   406 }
   412 }
   407 
   413 
   408 pub fn handle_client_loss(state: &mut ServerState, client_id: ClientId, response: &mut Response) {
   414 pub fn handle_client_loss(state: &mut ServerState, client_id: ClientId, response: &mut Response) {
   409     if state.anteroom.remove_client(client_id).is_none() {
   415     if state.anteroom.remove_client(client_id).is_none() {