rust/hedgewars-server/src/server/actions.rs
changeset 14696 dfe652c53470
parent 14694 08a8605bafaf
child 14704 932ff7683653
equal deleted inserted replaced
14695:b87c71ccd17d 14696:dfe652c53470
   115     Send(PendingMessage),
   115     Send(PendingMessage),
   116     CheckRegistered,
   116     CheckRegistered,
   117     JoinLobby,
   117     JoinLobby,
   118     RemoveRoom(RoomId),
   118     RemoveRoom(RoomId),
   119     MoveToRoom(RoomId),
   119     MoveToRoom(RoomId),
   120     MoveToLobby(String),
       
   121     ChangeMaster(RoomId, Option<ClientId>),
   120     ChangeMaster(RoomId, Option<ClientId>),
   122     RemoveTeam(String),
       
   123     RemoveClientTeams,
       
   124     SendRoomUpdate(Option<String>),
   121     SendRoomUpdate(Option<String>),
   125     StartRoomGame(RoomId),
   122     StartRoomGame(RoomId),
   126     SendTeamRemovalMessage(String),
   123     SendTeamRemovalMessage(String),
   127     FinishRoomGame(RoomId),
   124     FinishRoomGame(RoomId),
   128     SendRoomData {
   125     SendRoomData {
   448                 VoteType::Kick(nick) => {
   445                 VoteType::Kick(nick) => {
   449                     if let Some(c) = server.find_client(&nick) {
   446                     if let Some(c) = server.find_client(&nick) {
   450                         if c.room_id == Some(room_id) {
   447                         if c.room_id == Some(room_id) {
   451                             id = c.id;
   448                             id = c.id;
   452                             actions.push(Kicked.send_self().action());
   449                             actions.push(Kicked.send_self().action());
   453                             actions.push(MoveToLobby("kicked".to_string()));
   450                             //actions.push(MoveToLobby("kicked".to_string()));
   454                         }
   451                         }
   455                     }
   452                     }
   456                 }
   453                 }
   457                 VoteType::Map(None) => (),
   454                 VoteType::Map(None) => (),
   458                 VoteType::Map(Some(name)) => {
   455                 VoteType::Map(Some(name)) => {
   509                             .action()
   506                             .action()
   510                     }));
   507                     }));
   511                 }
   508                 }
   512             }
   509             }
   513             server.react(id, actions);
   510             server.react(id, actions);
   514         }
       
   515         MoveToLobby(msg) => {
       
   516             let mut actions = Vec::new();
       
   517             let lobby_id = server.lobby_id;
       
   518             if let (c, Some(r)) = server.client_and_room(client_id) {
       
   519                 r.players_number -= 1;
       
   520                 if c.is_ready() && r.ready_players_number > 0 {
       
   521                     r.ready_players_number -= 1;
       
   522                 }
       
   523                 if c.is_master() && (r.players_number > 0 || r.is_fixed()) {
       
   524                     actions.push(ChangeMaster(r.id, None));
       
   525                 }
       
   526                 actions.push(
       
   527                     ClientFlags("-i".to_string(), vec![c.nick.clone()])
       
   528                         .send_all()
       
   529                         .action(),
       
   530                 );
       
   531             }
       
   532             server.react(client_id, actions);
       
   533             actions = Vec::new();
       
   534 
       
   535             if let (c, Some(r)) = server.client_and_room(client_id) {
       
   536                 c.room_id = Some(lobby_id);
       
   537                 if r.players_number == 0 && !r.is_fixed() {
       
   538                     actions.push(RemoveRoom(r.id));
       
   539                 } else {
       
   540                     actions.push(RemoveClientTeams);
       
   541                     actions.push(
       
   542                         RoomLeft(c.nick.clone(), msg)
       
   543                             .send_all()
       
   544                             .in_room(r.id)
       
   545                             .but_self()
       
   546                             .action(),
       
   547                     );
       
   548                     actions.push(SendRoomUpdate(Some(r.name.clone())));
       
   549                 }
       
   550             }
       
   551             server.react(client_id, actions)
       
   552         }
   511         }
   553         ChangeMaster(room_id, new_id) => {
   512         ChangeMaster(room_id, new_id) => {
   554             let mut actions = Vec::new();
   513             let mut actions = Vec::new();
   555             let room_client_ids = server.room_clients(room_id);
   514             let room_client_ids = server.room_clients(room_id);
   556             let new_id = if server
   515             let new_id = if server
   599             }
   558             }
   600             if let Some(id) = new_id {
   559             if let Some(id) = new_id {
   601                 server.clients[id].set_is_master(true)
   560                 server.clients[id].set_is_master(true)
   602             }
   561             }
   603             server.react(client_id, actions);
   562             server.react(client_id, actions);
   604         }
       
   605         RemoveTeam(name) => {
       
   606             let mut actions = Vec::new();
       
   607             if let (c, Some(r)) = server.client_and_room(client_id) {
       
   608                 r.remove_team(&name);
       
   609                 if let Some(ref mut info) = r.game_info {
       
   610                     info.left_teams.push(name.clone());
       
   611                 }
       
   612                 actions.push(TeamRemove(name.clone()).send_all().in_room(r.id).action());
       
   613                 actions.push(SendRoomUpdate(None));
       
   614                 if r.game_info.is_some() && c.is_in_game() {
       
   615                     actions.push(SendTeamRemovalMessage(name));
       
   616                 }
       
   617             }
       
   618             server.react(client_id, actions);
       
   619         }
       
   620         RemoveClientTeams => {
       
   621             if let (c, Some(r)) = server.client_and_room(client_id) {
       
   622                 let actions = r
       
   623                     .client_teams(c.id)
       
   624                     .map(|t| RemoveTeam(t.name.clone()))
       
   625                     .collect();
       
   626                 server.react(client_id, actions);
       
   627             }
       
   628         }
   563         }
   629         SendRoomUpdate(old_name) => {
   564         SendRoomUpdate(old_name) => {
   630             if let (c, Some(r)) = server.client_and_room(client_id) {
   565             if let (c, Some(r)) = server.client_and_room(client_id) {
   631                 let name = old_name.unwrap_or_else(|| r.name.clone());
   566                 let name = old_name.unwrap_or_else(|| r.name.clone());
   632                 let actions = vec![RoomUpdated(name, r.info(Some(&c)))
   567                 let actions = vec![RoomUpdated(name, r.info(Some(&c)))