rust/hedgewars-server/src/server/actions.rs
changeset 14708 5122c584804e
parent 14707 9f98086de1b6
child 14709 4569d8d50286
equal deleted inserted replaced
14707:9f98086de1b6 14708:5122c584804e
   110         to: ClientId,
   110         to: ClientId,
   111         teams: bool,
   111         teams: bool,
   112         config: bool,
   112         config: bool,
   113         flags: bool,
   113         flags: bool,
   114     },
   114     },
   115     ApplyVoting(VoteType, RoomId),
       
   116 }
   115 }
   117 
   116 
   118 use self::Action::*;
   117 use self::Action::*;
   119 
   118 
   120 pub fn run_action(server: &mut HWServer, client_id: usize, action: Action) {
   119 pub fn run_action(server: &mut HWServer, client_id: usize, action: Action) {
   178 ;
   177 ;
   179                     }
   178                     }
   180                 }
   179                 }
   181             }
   180             }
   182         }
   181         }
   183         ApplyVoting(kind, room_id) => {
       
   184             let mut actions = Vec::new();
       
   185             let mut id = client_id;
       
   186             match kind {
       
   187                 VoteType::Kick(nick) => {
       
   188                     if let Some(c) = server.find_client(&nick) {
       
   189                         if c.room_id == Some(room_id) {
       
   190                             id = c.id;
       
   191                             //actions.push(Kicked.send_self().action());
       
   192                             //actions.push(MoveToLobby("kicked".to_string()));
       
   193                         }
       
   194                     }
       
   195                 }
       
   196                 VoteType::Map(None) => (),
       
   197                 VoteType::Map(Some(name)) => {
       
   198                     if let Some(location) = server.rooms[room_id].load_config(&name) {
       
   199                         /*actions.push(
       
   200                             server_chat(location.to_string())
       
   201                                 .send_all()
       
   202                                 .in_room(room_id)
       
   203                                 .action(),
       
   204                         );*/
       
   205                         //actions.push(SendRoomUpdate(None));
       
   206                         for (_, c) in server.clients.iter() {
       
   207                             if c.room_id == Some(room_id) {
       
   208                                 actions.push(SendRoomData {
       
   209                                     to: c.id,
       
   210                                     teams: false,
       
   211                                     config: true,
       
   212                                     flags: false,
       
   213                                 })
       
   214                             }
       
   215                         }
       
   216                     }
       
   217                 }
       
   218                 VoteType::Pause => {
       
   219                     if let Some(ref mut info) = server.rooms[room_id].game_info {
       
   220                         info.is_paused = !info.is_paused;
       
   221                         /*actions.push(
       
   222                             server_chat("Pause toggled.".to_string())
       
   223                                 .send_all()
       
   224                                 .in_room(room_id)
       
   225                                 .action(),
       
   226                         );*/
       
   227                         /*actions.push(
       
   228                             ForwardEngineMessage(vec![to_engine_msg(once(b'I'))])
       
   229                                 .send_all()
       
   230                                 .in_room(room_id)
       
   231                                 .action(),
       
   232                         );*/
       
   233                     }
       
   234                 }
       
   235                 VoteType::NewSeed => {
       
   236                     let seed = thread_rng().gen_range(0, 1_000_000_000).to_string();
       
   237                     let cfg = GameCfg::Seed(seed);
       
   238                     /*actions.push(cfg.to_server_msg().send_all().in_room(room_id).action());*/
       
   239                     server.rooms[room_id].set_config(cfg);
       
   240                 }
       
   241                 VoteType::HedgehogsPerTeam(number) => {
       
   242                     let r = &mut server.rooms[room_id];
       
   243                     let nicks = r.set_hedgehogs_number(number);
       
   244                     /*actions.extend(nicks.into_iter().map(|n| {
       
   245                         HedgehogsNumber(n, number)
       
   246                             .send_all()
       
   247                             .in_room(room_id)
       
   248                             .action()
       
   249                     }));*/
       
   250                 }
       
   251             }
       
   252         }
       
   253         ChangeMaster(room_id, new_id) => {
   182         ChangeMaster(room_id, new_id) => {
   254             let room_client_ids = server.room_clients(room_id);
   183             let room_client_ids = server.room_clients(room_id);
   255             let new_id = if server
   184             let new_id = if server
   256                 .room(client_id)
   185                 .room(client_id)
   257                 .map(|r| r.is_fixed())
   186                 .map(|r| r.is_fixed())