diff -r 16d3c9acd715 -r 24f692e791d3 rust/hedgewars-server/src/core/server.rs --- a/rust/hedgewars-server/src/core/server.rs Tue Dec 24 20:57:58 2019 +0300 +++ b/rust/hedgewars-server/src/core/server.rs Tue Dec 24 21:45:26 2019 +0300 @@ -161,9 +161,9 @@ pub struct HwServer { clients: IndexSlab, rooms: Slab, - pub latest_protocol: u16, - pub flags: ServerFlags, - pub greetings: ServerGreetings, + latest_protocol: u16, + flags: ServerFlags, + greetings: ServerGreetings, } impl HwServer { @@ -205,7 +205,7 @@ } #[inline] - pub fn get_room_mut(&mut self, room_id: RoomId) -> Option<&mut HwRoom> { + fn get_room_mut(&mut self, room_id: RoomId) -> Option<&mut HwRoom> { self.rooms.get_mut(room_id) } @@ -404,7 +404,7 @@ .find_map(|(_, r)| Some(r).filter(|r| r.name == name)) } - pub fn find_room_mut(&mut self, name: &str) -> Option<&mut HwRoom> { + fn find_room_mut(&mut self, name: &str) -> Option<&mut HwRoom> { self.rooms .iter_mut() .find_map(|(_, r)| Some(r).filter(|r| r.name == name)) @@ -416,13 +416,13 @@ .find_map(|(_, c)| Some(c).filter(|c| c.nick == nick)) } - pub fn find_client_mut(&mut self, nick: &str) -> Option<&mut HwClient> { + fn find_client_mut(&mut self, nick: &str) -> Option<&mut HwClient> { self.clients .iter_mut() .find_map(|(_, c)| Some(c).filter(|c| c.nick == nick)) } - pub fn all_clients(&self) -> impl Iterator + '_ { + pub fn iter_client_ids(&self) -> impl Iterator + '_ { self.clients.iter().map(|(id, _)| id) } @@ -440,7 +440,7 @@ self.rooms.iter().filter(f).map(|(_, c)| c.id) } - pub fn collect_clients(&self, f: F) -> Vec + pub fn collect_client_ids(&self, f: F) -> Vec where F: Fn(&(usize, &HwClient)) -> bool, { @@ -458,25 +458,25 @@ .collect() } - pub fn lobby_clients(&self) -> impl Iterator + '_ { + pub fn lobby_client_ids(&self) -> impl Iterator + '_ { self.filter_clients(|(_, c)| c.room_id == None) } - pub fn room_clients(&self, room_id: RoomId) -> impl Iterator + '_ { + pub fn room_client_ids(&self, room_id: RoomId) -> impl Iterator + '_ { self.filter_clients(move |(_, c)| c.room_id == Some(room_id)) } - pub fn protocol_clients(&self, protocol: u16) -> impl Iterator + '_ { + pub fn protocol_client_ids(&self, protocol: u16) -> impl Iterator + '_ { self.filter_clients(move |(_, c)| c.protocol_number == protocol) } - pub fn protocol_rooms(&self, protocol: u16) -> impl Iterator + '_ { + pub fn protocol_room_ids(&self, protocol: u16) -> impl Iterator + '_ { self.filter_rooms(move |(_, r)| r.protocol_number == protocol) } - pub fn other_clients_in_room(&self, self_id: ClientId) -> Vec { + pub fn other_client_ids_in_room(&self, self_id: ClientId) -> Vec { let room_id = self.clients[self_id].room_id; - self.collect_clients(|(id, c)| *id != self_id && c.room_id == room_id) + self.collect_client_ids(|(id, c)| *id != self_id && c.room_id == room_id) } pub fn is_registered_only(&self) -> bool { @@ -486,6 +486,14 @@ pub fn set_is_registered_only(&mut self, value: bool) { self.flags.set(ServerFlags::REGISTERED_ONLY, value) } + + pub fn set_room_saves(&mut self, room_id: RoomId, text: &str) -> Result<(), serde_yaml::Error> { + if let Some(room) = self.rooms.get_mut(room_id) { + room.set_saves(text) + } else { + Ok(()) + } + } } pub struct HwRoomControl<'a> { @@ -590,7 +598,7 @@ self.server.rooms.remove(self.room_id); } else if room.master_id == None { let protocol_number = room.protocol_number; - let new_master_id = self.server.room_clients(self.room_id).next(); + let new_master_id = self.server.room_client_ids(self.room_id).next(); if let Some(new_master_id) = new_master_id { let room = self.room_mut(); @@ -672,7 +680,7 @@ match self.room().voting { Some(_) => Err(VotingInProgress), None => { - let voting = Voting::new(kind, self.server.room_clients(self.room_id).collect()); + let voting = Voting::new(kind, self.server.room_client_ids(self.room_id).collect()); self.room_mut().voting = Some(voting); Ok(()) }