1. Szymon Wróblewski
  2. pygnetic

Commits

Szymon Wróblewski  committed 252264d

added connections and receivers iterators to server, PacketManager hash includes serializing lib name

  • Participants
  • Parent commits c47457f
  • Branches default

Comments (0)

Files changed (2)

File pygame_network/packet.py

View file
  • Ignore whitespace
 from weakref import WeakKeyDictionary, WeakValueDictionary
 import enet
 try:
-    import msgpack
-    _packer = msgpack.Packer()
-    _unpacker = msgpack.Unpacker()
+    import msgpack as s_lib
+    _packer = s_lib.Packer()
+    _unpacker = s_lib.Unpacker()
     _pack = _packer.pack
     _unpack = lambda data: _unpacker.feed(data) or _unpacker.unpack()
 except ImportError:
-    import json
-    _packer = json.JSONEncoder()
-    _unpacker = json.JSONDecoder()
+    import json as s_lib
+    _packer = s_lib.JSONEncoder()
+    _unpacker = s_lib.JSONDecoder()
     _pack = _packer.encode
     _unpack = _unpacker.decode
 
                 ids = cls._packet_types.keys()
                 ids.sort()
                 l = list()
+                l.append(s_lib.__name__)
                 for i in ids:
                     p = cls._packet_types[i]
                     l.append((i, p.__name__, p._fields))

File pygame_network/server.py

View file
  • Ignore whitespace
 import logging
 from weakref import proxy
+from functools import partial
 import enet
 from receiver import Receiver
 from packet import PacketManager
                 _logger.info('Received data from %s', event.peer.address)
                 self.peers[event.peer.data]._receive(event.packet.data, event.channelID)
             event = host.check_events()
+
+    def connections(self, exclude=None):
+        if exclude is None:
+            return self.peers.itervalues()
+        else:
+            return (c for c in self.peers.itervalues() if c not in exclude)
+
+    def receivers(self, exclude=None):
+        return (c._receivers[0] for c in self.peers.itervalues() if c not in exclude)