1. Victor Kotseruba
  2. FlSock

Commits

Victor Kotseruba  committed 4ae32bd

rooms moved to dispatcher, global variables ain't cool

  • Participants
  • Parent commits 07f9624
  • Branches default

Comments (0)

Files changed (1)

File FlSock.py

View file
  • Ignore whitespace
                   help='allowed domains comma separated, default *')
 
 
-rooms = {}
-
-
 class FlSockChannel(asynchat.async_chat):
     
     ac_in_buffer_size = 1024
         elif self.state == 'message':
             self.state = 'mode'
             if self.room:
-                for channel in rooms[self.room]:
+                for channel in self.server.rooms[self.room]:
                     if channel is not self:
                         channel.push(self.data + chr(1))
             self.data = ''
         self.data = ''
 
     def join_room(self):
-        if self.room not in rooms:
-            rooms[self.room] = []
-        rooms[self.room].append(self)
+        if self.room not in self.server.rooms:
+            self.server.rooms[self.room] = []
+        self.server.rooms[self.room].append(self)
     
     def leave_room(self):
         if self.room:
-            rooms[self.room].remove(self)
-            if not rooms[self.room]:
-                del rooms[self.room]
+            self.server.rooms[self.room].remove(self)
+            if not self.server.rooms[self.room]:
+                del self.server.rooms[self.room]
     
     def handle_close(self):
         self.leave_room()
     def __init__(self, opts):
         asyncore.dispatcher.__init__(self)
         self.opts = opts
+        self.rooms = {}
         self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         self.set_reuse_addr()
         self.bind((opts.host, opts.port))