208 pub fn client(&self, client_id: ClientId) -> &HwClient { |
222 pub fn client(&self, client_id: ClientId) -> &HwClient { |
209 &self.clients[client_id] |
223 &self.clients[client_id] |
210 } |
224 } |
211 |
225 |
212 #[inline] |
226 #[inline] |
213 pub fn client_mut(&mut self, client_id: ClientId) -> &mut HwClient { |
227 fn client_mut(&mut self, client_id: ClientId) -> &mut HwClient { |
214 &mut self.clients[client_id] |
228 &mut self.clients[client_id] |
215 } |
229 } |
216 |
230 |
217 #[inline] |
231 #[inline] |
218 pub fn room(&self, room_id: RoomId) -> &HwRoom { |
232 pub fn room(&self, room_id: RoomId) -> &HwRoom { |
528 } else { |
542 } else { |
529 unreachable!() |
543 unreachable!() |
530 } |
544 } |
531 } |
545 } |
532 |
546 |
|
547 pub fn enable_super_power(&mut self, client_id: ClientId) -> bool { |
|
548 let client = &mut self.clients[client_id]; |
|
549 if client.is_admin() { |
|
550 client.set_has_super_power(true); |
|
551 } |
|
552 client.is_admin() |
|
553 } |
|
554 |
|
555 pub fn set_room_name( |
|
556 &mut self, |
|
557 client_id: ClientId, |
|
558 room_id: RoomId, |
|
559 mut name: String, |
|
560 ) -> Result<String, ModifyRoomNameError> { |
|
561 let room_exists = self.has_room(&name); |
|
562 let room = &mut self.rooms[room_id]; |
|
563 if room.is_fixed() || room.master_id != Some(client_id) { |
|
564 Err(ModifyRoomNameError::AccessDenied) |
|
565 } else if utils::is_name_illegal(&name) { |
|
566 Err(ModifyRoomNameError::InvalidName) |
|
567 } else if room_exists { |
|
568 Err(ModifyRoomNameError::DuplicateName) |
|
569 } else { |
|
570 std::mem::swap(&mut room.name, &mut name); |
|
571 Ok(name) |
|
572 } |
|
573 } |
|
574 |
|
575 pub fn add_team(&mut self, client_id: ClientId) {} |
|
576 |
|
577 pub fn set_team_color( |
|
578 &mut self, |
|
579 client_id: ClientId, |
|
580 room_id: RoomId, |
|
581 team_name: &str, |
|
582 color: u8, |
|
583 ) -> Result<(), ModifyTeamError> { |
|
584 let client = &self.clients[client_id]; |
|
585 let room = &mut self.rooms[room_id]; |
|
586 if let Some((owner, team)) = room.find_team_and_owner_mut(|t| t.name == team_name) { |
|
587 if !client.is_master() { |
|
588 Err(ModifyTeamError::NotMaster) |
|
589 } else { |
|
590 team.color = color; |
|
591 self.clients[owner].clan = Some(color); |
|
592 Ok(()) |
|
593 } |
|
594 } else { |
|
595 Err(ModifyTeamError::NoTeam) |
|
596 } |
|
597 } |
|
598 |
|
599 pub fn toggle_ready(&mut self, client_id: ClientId) -> bool { |
|
600 let client = &mut self.clients[client_id]; |
|
601 if let Some(room_id) = client.room_id { |
|
602 let room = &mut self.rooms[room_id]; |
|
603 |
|
604 client.set_is_ready(!client.is_ready()); |
|
605 if client.is_ready() { |
|
606 room.ready_players_number += 1; |
|
607 } else { |
|
608 room.ready_players_number -= 1; |
|
609 } |
|
610 } |
|
611 client.is_ready() |
|
612 } |
|
613 |
533 #[inline] |
614 #[inline] |
534 pub fn set_var(&mut self, client_id: ClientId, var: ServerVar) -> Result<(), AccessError> { |
615 pub fn set_var(&mut self, client_id: ClientId, var: ServerVar) -> Result<(), AccessError> { |
535 if self.clients[client_id].is_admin() { |
616 if self.clients[client_id].is_admin() { |
536 match var { |
617 match var { |
537 ServerVar::MOTDNew(msg) => self.greetings.for_latest_protocol = msg, |
618 ServerVar::MOTDNew(msg) => self.greetings.for_latest_protocol = msg, |