src/Network/Session.hh
changeset 431 c6d7272a164b
parent 400 d64bf28c4340
child 448 34bdf0783874
--- a/src/Network/Session.hh	Mon Jan 26 19:52:52 2009 +0200
+++ b/src/Network/Session.hh	Mon Jan 26 23:03:47 2009 +0200
@@ -14,14 +14,6 @@
 class NetworkSession;
 
 /**
- * A NetworkSession puts each packet onto a specific channel, which can the be used to run multiple different modules
- * on top of a single session.
- *
- * NetworkChannelID zero is reserved for internal NetworkSession use
- */
-typedef uint16_t NetworkChannelID;
-
-/**
  * Size of a NetworkSession's packet header:
  *  uint16      channel_id
  */
@@ -30,6 +22,9 @@
 #include "TCP.hh"
 #include "UDP.hh"
 #include "Node.hh"
+#include "Group.hh"
+#include "Packet.hh"
+#include "Channel.hh"
 
 /**
  * A NetworkSession provides TCP/UDP Server and Client functionality, representing remote NetworkSessions with
@@ -65,7 +60,12 @@
          * A map of NetworkAddress -> NetworkNode, manipulated when TCP connections are established/broken down,
          * and used to map UDP packets to their NetworkNode
          */
-        std::map<NetworkAddress, NetworkNode*> nodes;
+        std::map<NetworkAddress, NetworkNode*> node_map;
+
+        /**
+         * A plain list of connected NetworkNode's
+         */
+        std::list<NetworkNode*> node_list;
 
         /**
          * A map of NetworkChannelID -> signal, used to signal our users when we receieve packets
@@ -146,21 +146,32 @@
 
     public:
         /**
-         * Send the given NetworkPacket to all our nodes using the given NetworkChannelID, using TCP if reliable, UDP otherwise.
-         *
-         * @param channel_id the NetworkChannelID to use
-         * @param pkt the NetworkPacket to send
-         * @param reliable Whether to use TCP or UDP
+         * Get a NetworkGroup containing all connected nodes
          */
-        void send_all (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable = true);
+        NetworkGroup all_nodes (void) {
+            return NetworkGroup(node_list.begin(), node_list.end(), NULL);
+        }
 
         /**
-         * Like send_all, but do not send the packet to the specified node. If node is NULL, this behaves like
-         * send_all.
+         * Get a NetworkGroup containing all connected nodes, but excluding the given one
+         */
+        NetworkGroup all_nodes_except (NetworkNode &node) {
+            return NetworkGroup(node_list.begin(), node_list.end(), &node);
+        }
+
+        /**
+         * Write the appropriate NetworkSession header to the given packet. Can be used to prepare packets for use with
+         * NetworkTarget::send_raw(). The size of the header is equal to NETWORK_SESSION_HEADER_SIZE
          *
-         * @see send_all
+         * XXX: this interface needs fixing to be less procedural
+         *
+         * @param pkt the packet to write the header to
+         * @param channel_id the NetworkChannelID to use
+         *
+         * @see NetworkTarget::send_raw()
+         * @see NETWORK_SESSION_HEADER_SIZE
          */
-        void send_all_except (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, const NetworkNode *node, bool reliable = true);
+        void write_packet_header (NetworkPacketOutput &pkt, NetworkChannelID channel_id);
 
         /**
          * A new node has connected to us