rust/hedgewars-server/src/server/handlers/inroom.rs
changeset 14709 4569d8d50286
parent 14708 5122c584804e
child 14710 aae29ba56aec
equal deleted inserted replaced
14708:5122c584804e 14709:4569d8d50286
   153             }
   153             }
   154         }
   154         }
   155         RoomName(new_name) => {
   155         RoomName(new_name) => {
   156             if is_name_illegal(&new_name) {
   156             if is_name_illegal(&new_name) {
   157                 response.add(Warning("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()).send_self());
   157                 response.add(Warning("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()).send_self());
   158             } else if server.rooms[room_id].is_fixed() {
       
   159                 response.add(Warning("Access denied.".to_string()).send_self());
       
   160             } else if server.has_room(&new_name) {
   158             } else if server.has_room(&new_name) {
   161                 response.add(
   159                 response.add(
   162                     Warning("A room with the same name already exists.".to_string()).send_self(),
   160                     Warning("A room with the same name already exists.".to_string()).send_self(),
   163                 );
   161                 );
   164             } else {
   162             } else {
   165                 let mut old_name = new_name.clone();
       
   166                 let client = &server.clients[client_id];
       
   167                 let room = &mut server.rooms[room_id];
   163                 let room = &mut server.rooms[room_id];
   168                 swap(&mut room.name, &mut old_name);
   164                 if room.is_fixed() || room.master_id != Some(client_id) {
   169                 super::common::get_room_update(Some(old_name), room, Some(&client), response);
   165                     response.add(Warning("Access denied.".to_string()).send_self());
   170             };
   166                 } else {
       
   167                     let mut old_name = new_name.clone();
       
   168                     let client = &server.clients[client_id];
       
   169                     swap(&mut room.name, &mut old_name);
       
   170                     super::common::get_room_update(Some(old_name), room, Some(&client), response);
       
   171                 }
       
   172             }
   171         }
   173         }
   172         ToggleReady => {
   174         ToggleReady => {
   173             if let (client, Some(room)) = server.client_and_room(client_id) {
   175             if let (client, Some(room)) = server.client_and_room(client_id) {
   174                 let flags = if client.is_ready() {
   176                 let flags = if client.is_ready() {
   175                     room.ready_players_number -= 1;
   177                     room.ready_players_number -= 1;
   191 
   193 
   192                 client.set_is_ready(!client.is_ready());
   194                 client.set_is_ready(!client.is_ready());
   193             }
   195             }
   194         }
   196         }
   195         AddTeam(info) => {
   197         AddTeam(info) => {
   196             if let (client, Some(room)) = server.client_and_room(client_id) {
   198             let client = &mut server.clients[client_id];
   197                 if room.teams.len() >= room.team_limit as usize {
   199             let room = &mut server.rooms[room_id];
   198                     response.add(Warning("Too many teams!".to_string()).send_self());
   200             if room.teams.len() >= room.team_limit as usize {
   199                 } else if room.addable_hedgehogs() == 0 {
   201                 response.add(Warning("Too many teams!".to_string()).send_self());
   200                     response.add(Warning("Too many hedgehogs!".to_string()).send_self());
   202             } else if room.addable_hedgehogs() == 0 {
   201                 } else if room.find_team(|t| t.name == info.name) != None {
   203                 response.add(Warning("Too many hedgehogs!".to_string()).send_self());
   202                     response.add(
   204             } else if room.find_team(|t| t.name == info.name) != None {
   203                         Warning("There's already a team with same name in the list.".to_string())
   205                 response.add(
   204                             .send_self(),
   206                     Warning("There's already a team with same name in the list.".to_string())
   205                     );
   207                         .send_self(),
   206                 } else if room.game_info.is_some() {
   208                 );
   207                     response.add(
   209             } else if room.game_info.is_some() {
   208                         Warning("Joining not possible: Round is in progress.".to_string())
   210                 response.add(
   209                             .send_self(),
   211                     Warning("Joining not possible: Round is in progress.".to_string()).send_self(),
   210                     );
   212                 );
   211                 } else if room.is_team_add_restricted() {
   213             } else if room.is_team_add_restricted() {
   212                     response.add(
   214                 response.add(
   213                         Warning("This room currently does not allow adding new teams.".to_string())
   215                     Warning("This room currently does not allow adding new teams.".to_string())
   214                             .send_self(),
   216                         .send_self(),
   215                     );
   217                 );
   216                 } else {
   218             } else {
   217                     let team = room.add_team(client.id, *info, client.protocol_number < 42);
   219                 let team = room.add_team(client.id, *info, client.protocol_number < 42);
   218                     client.teams_in_game += 1;
   220                 client.teams_in_game += 1;
   219                     client.clan = Some(team.color);
   221                 client.clan = Some(team.color);
   220                     response.add(TeamAccepted(team.name.clone()).send_self());
   222                 response.add(TeamAccepted(team.name.clone()).send_self());
   221                     response.add(
   223                 response.add(
   222                         TeamAdd(HWRoom::team_info(&client, team))
   224                     TeamAdd(HWRoom::team_info(&client, team))
   223                             .send_all()
   225                         .send_all()
   224                             .in_room(room_id)
   226                         .in_room(room_id)
   225                             .but_self(),
   227                         .but_self(),
   226                     );
   228                 );
   227                     response.add(
   229                 response.add(
   228                         TeamColor(team.name.clone(), team.color)
   230                     TeamColor(team.name.clone(), team.color)
   229                             .send_all()
   231                         .send_all()
   230                             .in_room(room_id),
   232                         .in_room(room_id),
   231                     );
   233                 );
   232                     response.add(
   234                 response.add(
   233                         HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
   235                     HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
   234                             .send_all()
   236                         .send_all()
   235                             .in_room(room_id),
   237                         .in_room(room_id),
   236                     );
   238                 );
   237 
   239 
   238                     super::common::get_room_update(None, room, Some(&client), response);
   240                 let room_master = if let Some(id) = room.master_id {
   239                 }
   241                     Some(&server.clients[id])
       
   242                 } else {
       
   243                     None
       
   244                 };
       
   245                 super::common::get_room_update(None, room, room_master, response);
   240             }
   246             }
   241         }
   247         }
   242         RemoveTeam(name) => {
   248         RemoveTeam(name) => {
   243             if let (client, Some(room)) = server.client_and_room(client_id) {
   249             if let (client, Some(room)) = server.client_and_room(client_id) {
   244                 match room.find_team_owner(&name) {
   250                 match room.find_team_owner(&name) {