gameServer2/src/server/handlers/inroom.rs
changeset 13477 f748a72432f2
parent 13445 d3c86ade3d4d
child 13478 d79795acaa73
equal deleted inserted replaced
13446:dd2e51f7303d 13477:f748a72432f2
    87                     Vec::new()
    87                     Vec::new()
    88                 }
    88                 }
    89             };
    89             };
    90             server.react(client_id, actions);
    90             server.react(client_id, actions);
    91         },
    91         },
       
    92         Fix => {
       
    93             if let (c, Some(r)) = server.client_and_room(client_id) {
       
    94                 if c.is_admin { r.is_fixed = true }
       
    95             }
       
    96         }
       
    97         Unfix => {
       
    98             if let (c, Some(r)) = server.client_and_room(client_id) {
       
    99                 if c.is_admin { r.is_fixed = false }
       
   100             }
       
   101         }
       
   102         Greeting(text) => {
       
   103             if let (c, Some(r)) = server.client_and_room(client_id) {
       
   104                 if c.is_admin || c.is_master && !r.is_fixed {
       
   105                     r.greeting = text
       
   106                 }
       
   107             }
       
   108         }
    92         RoomName(new_name) => {
   109         RoomName(new_name) => {
    93             let actions =
   110             let actions =
    94                 if is_name_illegal(&new_name) {
   111                 if is_name_illegal(&new_name) {
    95                     vec![Warn("Illegal room name! A room name must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}".to_string())]
   112                     vec![Warn("Illegal room name! A room name must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}".to_string())]
       
   113                 } else if server.room(client_id).map(|r| r.is_fixed).unwrap_or(false) {
       
   114                     vec![Warn("Access denied.".to_string())]
    96                 } else if server.has_room(&new_name) {
   115                 } else if server.has_room(&new_name) {
    97                     vec![Warn("A room with the same name already exists.".to_string())]
   116                     vec![Warn("A room with the same name already exists.".to_string())]
    98                 } else {
   117                 } else {
    99                     let mut old_name = new_name.clone();
   118                     let mut old_name = new_name.clone();
   100                     if let (_, Some(r)) = server.client_and_room(client_id) {
   119                     if let (_, Some(r)) = server.client_and_room(client_id) {
   114                 } else {
   133                 } else {
   115                     r.ready_players_number += 1;
   134                     r.ready_players_number += 1;
   116                     "+r"
   135                     "+r"
   117                 };
   136                 };
   118                 c.is_ready = !c.is_ready;
   137                 c.is_ready = !c.is_ready;
   119                 vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
   138                 let mut v =
   120                     .send_all().in_room(r.id).action()]
   139                     vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
       
   140                         .send_all().in_room(r.id).action()];
       
   141                 if r.is_fixed && r.ready_players_number as u32 == r.players_number {
       
   142                     v.push(StartRoomGame(r.id))
       
   143                 }
       
   144                 v
   121             } else {
   145             } else {
   122                 Vec::new()
   146                 Vec::new()
   123             };
   147             };
   124             server.react(client_id, actions);
   148             server.react(client_id, actions);
   125         }
   149         }
   221 
   245 
   222             server.react(client_id, actions);
   246             server.react(client_id, actions);
   223         },
   247         },
   224         Cfg(cfg) => {
   248         Cfg(cfg) => {
   225             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   249             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   226                 if !c.is_master {
   250                 if r.is_fixed {
       
   251                     vec![Warn("Access denied.".to_string())]
       
   252                 } else if !c.is_master {
   227                     vec![ProtocolError("You're not the room master!".to_string())]
   253                     vec![ProtocolError("You're not the room master!".to_string())]
   228                 } else {
   254                 } else {
   229                     let v = vec![cfg.to_server_msg()
   255                     let v = vec![cfg.to_server_msg()
   230                         .send_all().in_room(r.id).but_self().action()];
   256                         .send_all().in_room(r.id).but_self().action()];
   231                     r.set_config(cfg);
   257                     r.set_config(cfg);