gameServer2/src/server/handlers/inroom.rs
changeset 13486 1ee192f13456
parent 13460 fb37745c5bca
child 13492 ba5211dddb21
equal deleted inserted replaced
13485:c85b324c4c2d 13486:1ee192f13456
   100             };
   100             };
   101             server.react(client_id, actions);
   101             server.react(client_id, actions);
   102         },
   102         },
   103         Fix => {
   103         Fix => {
   104             if let (c, Some(r)) = server.client_and_room(client_id) {
   104             if let (c, Some(r)) = server.client_and_room(client_id) {
   105                 if c.is_admin { r.is_fixed = true }
   105                 if c.is_admin() { r.is_fixed = true }
   106             }
   106             }
   107         }
   107         }
   108         Unfix => {
   108         Unfix => {
   109             if let (c, Some(r)) = server.client_and_room(client_id) {
   109             if let (c, Some(r)) = server.client_and_room(client_id) {
   110                 if c.is_admin { r.is_fixed = false }
   110                 if c.is_admin() { r.is_fixed = false }
   111             }
   111             }
   112         }
   112         }
   113         Greeting(text) => {
   113         Greeting(text) => {
   114             if let (c, Some(r)) = server.client_and_room(client_id) {
   114             if let (c, Some(r)) = server.client_and_room(client_id) {
   115                 if c.is_admin || c.is_master && !r.is_fixed {
   115                 if c.is_admin() || c.is_master() && !r.is_fixed {
   116                     r.greeting = text
   116                     r.greeting = text
   117                 }
   117                 }
   118             }
   118             }
   119         }
   119         }
   120         RoomName(new_name) => {
   120         RoomName(new_name) => {
   136                 };
   136                 };
   137             server.react(client_id, actions);
   137             server.react(client_id, actions);
   138         },
   138         },
   139         ToggleReady => {
   139         ToggleReady => {
   140             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   140             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   141                 let flags = if c.is_ready {
   141                 let flags = if c.is_ready() {
   142                     r.ready_players_number -= 1;
   142                     r.ready_players_number -= 1;
   143                     "-r"
   143                     "-r"
   144                 } else {
   144                 } else {
   145                     r.ready_players_number += 1;
   145                     r.ready_players_number += 1;
   146                     "+r"
   146                     "+r"
   147                 };
   147                 };
   148                 c.is_ready = !c.is_ready;
   148                 let is_ready = !c.is_ready();
       
   149                 c.set_is_ready(is_ready);
   149                 let mut v =
   150                 let mut v =
   150                     vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
   151                     vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
   151                         .send_all().in_room(r.id).action()];
   152                         .send_all().in_room(r.id).action()];
   152                 if r.is_fixed && r.ready_players_number as u32 == r.players_number {
   153                 if r.is_fixed && r.ready_players_number as u32 == r.players_number {
   153                     v.push(StartRoomGame(r.id))
   154                     v.push(StartRoomGame(r.id))
   207         SetHedgehogsNumber(team_name, number) => {
   208         SetHedgehogsNumber(team_name, number) => {
   208             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   209             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   209                 let room_id = r.id;
   210                 let room_id = r.id;
   210                 let addable_hedgehogs = r.addable_hedgehogs();
   211                 let addable_hedgehogs = r.addable_hedgehogs();
   211                 if let Some((_, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
   212                 if let Some((_, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
   212                     if !c.is_master {
   213                     if !c.is_master() {
   213                         vec![ProtocolError("You're not the room master!".to_string())]
   214                         vec![ProtocolError("You're not the room master!".to_string())]
   214                     } else if number < 1 || number > 8
   215                     } else if number < 1 || number > 8
   215                            || number > addable_hedgehogs + team.hedgehogs_number {
   216                            || number > addable_hedgehogs + team.hedgehogs_number {
   216                         vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
   217                         vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
   217                             .send_self().action()]
   218                             .send_self().action()]
   231         SetTeamColor(team_name, color) => {
   232         SetTeamColor(team_name, color) => {
   232             let mut owner_id = None;
   233             let mut owner_id = None;
   233             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   234             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   234                 let room_id = r.id;
   235                 let room_id = r.id;
   235                 if let Some((owner, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
   236                 if let Some((owner, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
   236                     if !c.is_master {
   237                     if !c.is_master() {
   237                         vec![ProtocolError("You're not the room master!".to_string())]
   238                         vec![ProtocolError("You're not the room master!".to_string())]
   238                     } else if false  {
   239                     } else if false  {
   239                         Vec::new()
   240                         Vec::new()
   240                     } else {
   241                     } else {
   241                         owner_id = Some(owner);
   242                         owner_id = Some(owner);
   258         },
   259         },
   259         Cfg(cfg) => {
   260         Cfg(cfg) => {
   260             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   261             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   261                 if r.is_fixed {
   262                 if r.is_fixed {
   262                     vec![Warn("Access denied.".to_string())]
   263                     vec![Warn("Access denied.".to_string())]
   263                 } else if !c.is_master {
   264                 } else if !c.is_master() {
   264                     vec![ProtocolError("You're not the room master!".to_string())]
   265                     vec![ProtocolError("You're not the room master!".to_string())]
   265                 } else {
   266                 } else {
   266                     let v = vec![cfg.to_server_msg()
   267                     let v = vec![cfg.to_server_msg()
   267                         .send_all().in_room(r.id).but_self().action()];
   268                         .send_all().in_room(r.id).but_self().action()];
   268                     r.set_config(cfg);
   269                     r.set_config(cfg);
   335             };
   336             };
   336             server.react(client_id, actions);
   337             server.react(client_id, actions);
   337         }
   338         }
   338         ForceVote(vote) => {
   339         ForceVote(vote) => {
   339             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   340             let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
   340                 vec![AddVote{ vote, is_forced: c.is_admin} ]
   341                 vec![AddVote{ vote, is_forced: c.is_admin()} ]
   341             } else {
   342             } else {
   342                 Vec::new()
   343                 Vec::new()
   343             };
   344             };
   344             server.react(client_id, actions);
   345             server.react(client_id, actions);
   345         }
   346         }
   381             server.react(client_id, actions)
   382             server.react(client_id, actions)
   382         }
   383         }
   383         RoundFinished => {
   384         RoundFinished => {
   384             let mut actions = Vec::new();
   385             let mut actions = Vec::new();
   385             if let (c, Some(r)) = server.client_and_room(client_id) {
   386             if let (c, Some(r)) = server.client_and_room(client_id) {
   386                 if c.is_in_game {
   387                 if c.is_in_game() {
   387                     c.is_in_game = false;
   388                     c.set_is_in_game(false);
   388                     actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]).
   389                     actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]).
   389                         send_all().in_room(r.id).action());
   390                         send_all().in_room(r.id).action());
   390                     if r.game_info.is_some() {
   391                     if r.game_info.is_some() {
   391                         for team in r.client_teams(c.id) {
   392                         for team in r.client_teams(c.id) {
   392                             actions.push(SendTeamRemovalMessage(team.name.clone()));
   393                             actions.push(SendTeamRemovalMessage(team.name.clone()));