164 entry.insert(client); |
164 entry.insert(client); |
165 } |
165 } |
166 |
166 |
167 fn flush_server_messages(&mut self) { |
167 fn flush_server_messages(&mut self) { |
168 debug!("{} pending server messages", self.server.output.len()); |
168 debug!("{} pending server messages", self.server.output.len()); |
169 for PendingMessage(destination, msg) in self.server.output.drain(..) { |
169 for (clients, message) in self.server.output.drain(..) { |
170 debug!("Message {:?} to {:?}", msg, destination); |
170 debug!("Message {:?} to {:?}", message, clients); |
171 match destination { |
171 let msg_string = message.to_raw_protocol(); |
172 Destination::ToAll => { |
172 for client_id in clients { |
173 let msg_string = msg.to_raw_protocol(); |
173 if let Some(client) = self.clients.get_mut(client_id) { |
174 for (client_id, client) in self.clients.iter_mut() { |
174 client.send_string(&msg_string); |
175 client.send_string(&msg_string); |
175 self.pending.insert((client_id, NetworkClientState::NeedsWrite)); |
176 self.pending.insert((client_id, NetworkClientState::NeedsWrite)); |
|
177 } |
|
178 }, |
|
179 Destination::ToSelf(id) => { |
|
180 if let Some(client) = self.clients.get_mut(id) { |
|
181 client.send_msg(msg); |
|
182 self.pending.insert((id, NetworkClientState::NeedsWrite)); |
|
183 } |
|
184 } |
|
185 Destination::ToOthers(id) => { |
|
186 let msg_string = msg.to_raw_protocol(); |
|
187 for (client_id, client) in self.clients.iter_mut() { |
|
188 if client_id != id { |
|
189 client.send_string(&msg_string); |
|
190 self.pending.insert((client_id, NetworkClientState::NeedsWrite)); |
|
191 } |
|
192 } |
|
193 }, |
|
194 Destination::ToSelected(client_ids) => { |
|
195 let msg_string = msg.to_raw_protocol(); |
|
196 for id in client_ids { |
|
197 if let Some(client) = self.clients.get_mut(id) { |
|
198 client.send_string(&msg_string); |
|
199 self.pending.insert((id, NetworkClientState::NeedsWrite)); |
|
200 } |
|
201 } |
|
202 } |
176 } |
203 } |
177 } |
204 } |
178 } |
205 } |
179 } |
206 |
180 |