Commit 44af3105 authored by Ralf's avatar Ralf
Browse files

convert to tabs

parent 070c2e4a
__pycache__ __pycache__
...@@ -3,36 +3,36 @@ import selectors ...@@ -3,36 +3,36 @@ import selectors
import socket import socket
class Game: class Game:
def __init__(self): def __init__(self):
self.players = [] self.players = []
self.sock = socket.socket() self.sock = socket.socket()
self.sock.bind(('', 1234)) self.sock.bind(('', 1234))
self.sock.listen(100) self.sock.listen(100)
self.sel = selectors.DefaultSelector() self.sel = selectors.DefaultSelector()
self.sel.register(self.sock, selectors.EVENT_READ, self.accept) self.sel.register(self.sock, selectors.EVENT_READ, self.accept)
def accept(self, sock, mask): def accept(self, sock, mask):
assert sock == self.sock assert sock == self.sock
conn, addr = sock.accept() # Should be ready conn, addr = sock.accept() # Should be ready
player = Player(self, conn) player = Player(self, conn)
self.players.append(player) self.players.append(player)
self.sel.register(conn, selectors.EVENT_READ, self.sel.register(conn, selectors.EVENT_READ,
def removePlayer(self, player): def removePlayer(self, player):
assert player in self.players assert player in self.players
player.close() player.close()
self.players.remove(player) self.players.remove(player)
assert player not in self.players # this ensure the player was in only once assert player not in self.players # this ensure the player was in only once
def close(self): def close(self):
for player in self.players: for player in self.players:
player.close() player.close()
self.players.clear() self.players.clear()
self.sock.close() self.sock.close()
def run(self): def run(self):
while True: while True:
events = events =
for key, mask in events: for key, mask in events:
callback = callback =
callback(key.fileobj, mask) callback(key.fileobj, mask)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment