INNER CODE UNIT · Python
add
TheXTech/TheXTech · resources/_dev_scripts/xserver.py:421
def add(self, client):
# find an ID and slot for the client
if self.freed_clients:
new_id = min(self.freed_clients)
self.freed_clients.discard(new_id)
else:
new_id = len(self.clients)
self.clients.append(None)
# add the client to the room
client.set_room(self, new_id)
self.clients[new_id] = client
# create join event and add to queue
serialized_event = bytes([MESSAGE_ADD_CLIENT, 255, 0, new_id])
heapq.heappush(self.event_queue, (self.frame_no, serialized_event))
# tell the client who they are, what the current time is, and the room's key (may throw)