gameServer2/src/server/network.rs
changeset 13416 cdf69667593b
parent 13415 0eedc17055a0
child 13419 81e0ed105f5d
--- a/gameServer2/src/server/network.rs	Thu Jun 14 16:44:27 2018 -0400
+++ b/gameServer2/src/server/network.rs	Mon Jun 18 09:22:53 2018 -0400
@@ -55,7 +55,7 @@
         let result = loop {
             match self.decoder.read_from(&mut self.socket) {
                 Ok(bytes) => {
-                    debug!("Read {} bytes", bytes);
+                    debug!("Client {}: read {} bytes", self.id, bytes);
                     bytes_read += bytes;
                     if bytes == 0 {
                         let result = if bytes_read == 0 {
@@ -167,9 +167,17 @@
     fn flush_server_messages(&mut self) {
         debug!("{} pending server messages", self.server.output.len());
         for PendingMessage(destination, msg) in self.server.output.drain(..) {
+            debug!("Message {:?} to {:?}", msg, destination);
             match destination {
+                Destination::ToAll => {
+                    let msg_string = msg.to_raw_protocol();
+                    for (client_id, client) in self.clients.iter_mut() {
+                        client.send_string(&msg_string);
+                        self.pending.insert((client_id, NetworkClientState::NeedsWrite));
+                    }
+                },
                 Destination::ToSelf(id)  => {
-                    if let Some(ref mut client) = self.clients.get_mut(id) {
+                    if let Some(client) = self.clients.get_mut(id) {
                         client.send_msg(msg);
                         self.pending.insert((id, NetworkClientState::NeedsWrite));
                     }
@@ -182,6 +190,15 @@
                             self.pending.insert((client_id, NetworkClientState::NeedsWrite));
                         }
                     }
+                },
+                Destination::ToSelected(client_ids) => {
+                    let msg_string = msg.to_raw_protocol();
+                    for id in client_ids {
+                        if let Some(client) = self.clients.get_mut(id) {
+                            client.send_string(&msg_string);
+                            self.pending.insert((id, NetworkClientState::NeedsWrite));
+                        }
+                    }
                 }
             }
         }