Ejemplo n.º 1
0
 def create_room(self, conn):
     if socks[conn].get_status() > 1:
         conn.send(self.generator.create_room_fail("Status error"))
         return
     if len(available_ids) == 0:
         new_id = len(rooms) + 1
     else:
         new_id = heapq.heappop(available_ids)
     room = Games.Room(new_id, self.resolver.get_id(), socks[conn].get_name())  # no password version
     rooms[new_id] = room
     socks[conn].in_room(new_id)
     socks[conn].ready()
     # user status changes, need broadcast
     conn.send(self.generator.create_room_suc(new_id))
     fr_li = socks[conn].get_friend_list()
     for i in fr_li:
         if fr_li[i][1] == 1:
             try:
                 socks[users[names[i]]].friend_in_room(socks[conn].get_name())
                 users[names[i]].send(self.generator.friend_in_room(socks[conn].get_name()))
             except:
                 pass
     # room list changes, need broadcast
     for user in users:
         try:
             users[user].send(self.generator.new_room(new_id, socks[conn].get_name()))
         except:
             # user outline
             pass