225 |
225 |
226 let mut v = vec![ |
226 let mut v = vec![ |
227 RoomJoined(vec![c.nick.clone()]).send_all().in_room(room_id).action(), |
227 RoomJoined(vec![c.nick.clone()]).send_all().in_room(room_id).action(), |
228 ClientFlags("+i".to_string(), vec![c.nick.clone()]).send_all().action(), |
228 ClientFlags("+i".to_string(), vec![c.nick.clone()]).send_all().action(), |
229 SendRoomUpdate(None)]; |
229 SendRoomUpdate(None)]; |
|
230 if !r.greeting.is_empty() { |
|
231 v.push(ChatMsg {nick: "[greeting]".to_string(), msg: r.greeting.clone()} |
|
232 .send_self().action()); |
|
233 } |
230 if !c.is_master { |
234 if !c.is_master { |
231 let team_names: Vec<_>; |
235 let team_names: Vec<_>; |
232 if let Some(ref mut info) = r.game_info { |
236 if let Some(ref mut info) = r.game_info { |
233 c.is_in_game = true; |
237 c.is_in_game = true; |
234 c.is_joined_mid_game = true; |
238 c.is_joined_mid_game = true; |
326 if let (c, Some(r)) = server.client_and_room(client_id) { |
330 if let (c, Some(r)) = server.client_and_room(client_id) { |
327 r.players_number -= 1; |
331 r.players_number -= 1; |
328 if c.is_ready && r.ready_players_number > 0 { |
332 if c.is_ready && r.ready_players_number > 0 { |
329 r.ready_players_number -= 1; |
333 r.ready_players_number -= 1; |
330 } |
334 } |
331 if r.players_number > 0 && c.is_master { |
335 if c.is_master && (r.players_number > 0 || r.is_fixed) { |
332 actions.push(ChangeMaster(r.id, None)); |
336 actions.push(ChangeMaster(r.id, None)); |
333 } |
337 } |
334 actions.push(RemoveClientTeams); |
|
335 actions.push(RoomLeft(c.nick.clone(), msg) |
|
336 .send_all().in_room(r.id).but_self().action()); |
|
337 actions.push(ClientFlags("-i".to_string(), vec![c.nick.clone()]) |
338 actions.push(ClientFlags("-i".to_string(), vec![c.nick.clone()]) |
338 .send_all().action()); |
339 .send_all().action()); |
339 actions.push(SendRoomUpdate(Some(r.name.clone()))); |
|
340 } |
340 } |
341 server.react(client_id, actions); |
341 server.react(client_id, actions); |
342 actions = Vec::new(); |
342 actions = Vec::new(); |
343 |
343 |
344 if let (c, Some(r)) = server.client_and_room(client_id) { |
344 if let (c, Some(r)) = server.client_and_room(client_id) { |
345 c.room_id = Some(lobby_id); |
345 c.room_id = Some(lobby_id); |
346 if r.players_number == 0 { |
346 if r.players_number == 0 && !r.is_fixed { |
347 actions.push(RemoveRoom(r.id)); |
347 actions.push(RemoveRoom(r.id)); |
|
348 } else { |
|
349 actions.push(RemoveClientTeams); |
|
350 actions.push(RoomLeft(c.nick.clone(), msg) |
|
351 .send_all().in_room(r.id).but_self().action()); |
|
352 actions.push(SendRoomUpdate(Some(r.name.clone()))); |
348 } |
353 } |
349 } |
354 } |
350 server.react(client_id, actions) |
355 server.react(client_id, actions) |
351 } |
356 } |
352 ChangeMaster(room_id, new_id) => { |
357 ChangeMaster(room_id, new_id) => { |
353 let mut actions = Vec::new(); |
358 let mut actions = Vec::new(); |
354 let room_client_ids = server.room_clients(room_id); |
359 let room_client_ids = server.room_clients(room_id); |
355 let new_id = new_id.or_else(|| |
360 let new_id = if server.room(client_id).map(|r| r.is_fixed).unwrap_or(false) { |
356 room_client_ids.iter().find(|id| **id != client_id).map(|id| *id)); |
361 new_id |
|
362 } else { |
|
363 new_id.or_else(|| |
|
364 room_client_ids.iter().find(|id| **id != client_id).map(|id| *id)) |
|
365 }; |
357 let new_nick = new_id.map(|id| server.clients[id].nick.clone()); |
366 let new_nick = new_id.map(|id| server.clients[id].nick.clone()); |
358 |
367 |
359 if let (c, Some(r)) = server.client_and_room(client_id) { |
368 if let (c, Some(r)) = server.client_and_room(client_id) { |
360 match r.master_id { |
369 match r.master_id { |
361 Some(id) if id == c.id => { |
370 Some(id) if id == c.id => { |