rust/hedgewars-server/src/server/handlers/lobby.rs
changeset 14810 18240b308505
parent 14808 0e64acbc3f8b
child 14818 ce2268ae261f
equal deleted inserted replaced
14809:6dea1ca64992 14810:18240b308505
     1 use mio;
     1 use mio;
     2 
     2 
     3 use super::common::rnd_reply;
     3 use super::common::rnd_reply;
     4 use crate::{
     4 use crate::{
     5     protocol::messages::{
     5     protocol::messages::{
     6         add_flags, remove_flags, HWProtocolMessage, HWServerMessage::*, ProtocolFlags as Flags,
     6         add_flags, remove_flags, server_chat, HWProtocolMessage, HWServerMessage::*,
       
     7         ProtocolFlags as Flags,
     7     },
     8     },
     8     server::{
     9     server::{
     9         client::HWClient,
    10         client::HWClient,
    10         core::HWServer,
    11         core::HWServer,
    11         coretypes::{ClientId, ServerVar},
    12         coretypes::{ClientId, ServerVar},
    12     },
    13     },
    13     utils::is_name_illegal,
    14     utils::is_name_illegal,
    14 };
    15 };
    15 use log::*;
    16 use log::*;
       
    17 use std::{collections::HashSet, convert::identity};
    16 
    18 
    17 pub fn handle(
    19 pub fn handle(
    18     server: &mut HWServer,
    20     server: &mut HWServer,
    19     client_id: ClientId,
    21     client_id: ClientId,
    20     response: &mut super::Response,
    22     response: &mut super::Response,
   128             }
   130             }
   129         }
   131         }
   130         Rnd(v) => {
   132         Rnd(v) => {
   131             response.add(rnd_reply(&v).send_self());
   133             response.add(rnd_reply(&v).send_self());
   132         }
   134         }
       
   135         Stats => {
       
   136             let mut protocols: HashSet<_> = server
       
   137                 .clients
       
   138                 .iter()
       
   139                 .map(|(_, c)| c.protocol_number)
       
   140                 .chain(server.rooms.iter().map(|(_, r)| r.protocol_number))
       
   141                 .collect();
       
   142             let mut protocols: Vec<_> = protocols.drain().collect();
       
   143             protocols.sort();
       
   144 
       
   145             let mut html = Vec::with_capacity(protocols.len() + 2);
       
   146 
       
   147             html.push("<table>".to_string());
       
   148             for protocol in protocols {
       
   149                 html.push(format!(
       
   150                     "<tr><td>{}</td><td>{}</td><td>{}</td></tr>",
       
   151                     super::utils::protocol_version_string(protocol),
       
   152                     server.protocol_clients(protocol).count(),
       
   153                     server.protocol_rooms(protocol).count()
       
   154                 ));
       
   155             }
       
   156             html.push("</table>".to_string());
       
   157 
       
   158             response.add(Warning(html.join("")).send_self());
       
   159         }
   133         List => warn!("Deprecated LIST message received"),
   160         List => warn!("Deprecated LIST message received"),
   134         _ => warn!("Incorrect command in lobby state"),
   161         _ => warn!("Incorrect command in lobby state"),
   135     }
   162     }
   136 }
   163 }