101 } |
101 } |
102 } |
102 } |
103 |
103 |
104 pub enum Action { |
104 pub enum Action { |
105 ChangeMaster(RoomId, Option<ClientId>), |
105 ChangeMaster(RoomId, Option<ClientId>), |
106 SendTeamRemovalMessage(String), |
|
107 SendRoomData { |
|
108 to: ClientId, |
|
109 teams: bool, |
|
110 config: bool, |
|
111 flags: bool, |
|
112 }, |
|
113 } |
106 } |
114 |
107 |
115 use self::Action::*; |
108 use self::Action::*; |
116 |
109 |
117 pub fn run_action(server: &mut HWServer, client_id: usize, action: Action) { |
110 pub fn run_action(server: &mut HWServer, client_id: usize, action: Action) { |
118 match action { |
111 match action { |
119 SendRoomData { |
|
120 to, |
|
121 teams, |
|
122 config, |
|
123 flags, |
|
124 } => { |
|
125 let room_id = server.clients[client_id].room_id; |
|
126 if let Some(r) = room_id.and_then(|id| server.rooms.get(id)) { |
|
127 if config { |
|
128 /* actions.push( |
|
129 ConfigEntry("FULLMAPCONFIG".to_string(), r.map_config()) |
|
130 .send(to) |
|
131 .action(), |
|
132 )*/ |
|
133 ; |
|
134 for cfg in r.game_config() { |
|
135 //actions.push(cfg.to_server_msg().send(to).action()); |
|
136 } |
|
137 } |
|
138 if teams { |
|
139 let current_teams = match r.game_info { |
|
140 Some(ref info) => &info.teams_at_start, |
|
141 None => &r.teams, |
|
142 }; |
|
143 for (owner_id, team) in current_teams.iter() { |
|
144 /*actions.push( |
|
145 TeamAdd(HWRoom::team_info(&server.clients[*owner_id], &team)) |
|
146 .send(to) |
|
147 .action(), |
|
148 ); |
|
149 actions.push(TeamColor(team.name.clone(), team.color).send(to).action()); |
|
150 actions.push( |
|
151 HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
|
152 .send(to) |
|
153 .action(), |
|
154 );*/ |
|
155 } |
|
156 } |
|
157 if flags { |
|
158 if let Some(id) = r.master_id { |
|
159 /* |
|
160 actions.push( |
|
161 ClientFlags("+h".to_string(), vec![server.clients[id].nick.clone()]) |
|
162 .send(to) |
|
163 .action(), |
|
164 ); |
|
165 */ |
|
166 } |
|
167 let nicks: Vec<_> = server |
|
168 .clients |
|
169 .iter() |
|
170 .filter(|(_, c)| c.room_id == Some(r.id) && c.is_ready()) |
|
171 .map(|(_, c)| c.nick.clone()) |
|
172 .collect(); |
|
173 if !nicks.is_empty() { |
|
174 /*actions.push(ClientFlags("+r".to_string(), nicks).send(to).action())*/ |
|
175 ; |
|
176 } |
|
177 } |
|
178 } |
|
179 } |
|
180 ChangeMaster(room_id, new_id) => { |
112 ChangeMaster(room_id, new_id) => { |
181 let room_client_ids = server.room_clients(room_id); |
113 let room_client_ids = server.room_clients(room_id); |
182 let new_id = if server |
114 let new_id = if server |
183 .room(client_id) |
115 .room(client_id) |
184 .map(|r| r.is_fixed()) |
116 .map(|r| r.is_fixed()) |
225 } |
157 } |
226 if let Some(id) = new_id { |
158 if let Some(id) = new_id { |
227 server.clients[id].set_is_master(true) |
159 server.clients[id].set_is_master(true) |
228 } |
160 } |
229 } |
161 } |
230 SendTeamRemovalMessage(team_name) => { |
|
231 if let Some(r) = server.room(client_id) { |
|
232 if let Some(ref mut info) = r.game_info { |
|
233 let msg = once(b'F').chain(team_name.bytes()); |
|
234 /*actions.push( |
|
235 ForwardEngineMessage(vec![to_engine_msg(msg)]) |
|
236 .send_all() |
|
237 .in_room(r.id) |
|
238 .but_self() |
|
239 .action(), |
|
240 );*/ |
|
241 info.teams_in_game -= 1; |
|
242 if info.teams_in_game == 0 { |
|
243 //actions.push(FinishRoomGame(r.id)); |
|
244 } |
|
245 let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
|
246 if let Some(m) = &info.sync_msg { |
|
247 info.msg_log.push(m.clone()); |
|
248 } |
|
249 if info.sync_msg.is_some() { |
|
250 info.sync_msg = None |
|
251 } |
|
252 info.msg_log.push(remove_msg.clone()); |
|
253 /*actions.push( |
|
254 ForwardEngineMessage(vec![remove_msg]) |
|
255 .send_all() |
|
256 .in_room(r.id) |
|
257 .but_self() |
|
258 .action(), |
|
259 );*/ |
|
260 } |
|
261 } |
|
262 } |
|
263 } |
162 } |
264 } |
163 } |