91 #[inline] |
91 #[inline] |
92 pub fn move_to_room(&mut self, client_id: ClientId, room_id: RoomId) { |
92 pub fn move_to_room(&mut self, client_id: ClientId, room_id: RoomId) { |
93 move_to_room(&mut self.clients[client_id], &mut self.rooms[room_id]) |
93 move_to_room(&mut self.clients[client_id], &mut self.rooms[room_id]) |
94 } |
94 } |
95 |
95 |
96 fn get_recipients(&self, client_id: ClientId, destination: &Destination) -> Vec<ClientId> { |
|
97 let mut ids = match *destination { |
|
98 Destination::ToSelf => vec![client_id], |
|
99 Destination::ToId(id) => vec![id], |
|
100 Destination::ToAll { |
|
101 room_id: Some(id), .. |
|
102 } => self.room_clients(id), |
|
103 Destination::ToAll { |
|
104 protocol: Some(proto), |
|
105 .. |
|
106 } => self.protocol_clients(proto), |
|
107 Destination::ToAll { .. } => self.clients.iter().map(|(id, _)| id).collect::<Vec<_>>(), |
|
108 }; |
|
109 if let Destination::ToAll { |
|
110 skip_self: true, .. |
|
111 } = destination |
|
112 { |
|
113 if let Some(index) = ids.iter().position(|id| *id == client_id) { |
|
114 ids.remove(index); |
|
115 } |
|
116 } |
|
117 ids |
|
118 } |
|
119 |
|
120 pub fn send( |
96 pub fn send( |
121 &mut self, |
97 &mut self, |
122 client_id: ClientId, |
98 client_id: ClientId, |
123 destination: &Destination, |
99 destination: &Destination, |
124 message: HWServerMessage, |
100 message: HWServerMessage, |
125 ) { |
101 ) { |
126 let ids = self.get_recipients(client_id, &destination); |
102 |
127 self.output.push((ids, message)); |
|
128 } |
103 } |
129 |
104 |
130 pub fn send_msg(&mut self, client_id: ClientId, message: PendingMessage) { |
105 pub fn send_msg(&mut self, client_id: ClientId, message: PendingMessage) { |
131 self.send(client_id, &message.destination, message.message) |
106 self.send(client_id, &message.destination, message.message) |
132 } |
107 } |