Commit 44af3105 authored by Ralf's avatar Ralf

convert to tabs

parent 070c2e4a
__pycache__
.kateconfig
......@@ -3,36 +3,36 @@ import selectors
import socket
class Game:
def __init__(self):
self.players = []
self.sock = socket.socket()
self.sock.bind(('0.0.0.0', 1234))
self.sock.listen(100)
self.sel = selectors.DefaultSelector()
self.sel.register(self.sock, selectors.EVENT_READ, self.accept)
def accept(self, sock, mask):
assert sock == self.sock
conn, addr = sock.accept() # Should be ready
player = Player(self, conn)
self.players.append(player)
self.sel.register(conn, selectors.EVENT_READ, player.read)
def removePlayer(self, player):
assert player in self.players
player.close()
self.players.remove(player)
assert player not in self.players # this ensure the player was in only once
def close(self):
for player in self.players:
player.close()
self.players.clear()
self.sock.close()
def run(self):
while True:
events = self.sel.select()
for key, mask in events:
callback = key.data
callback(key.fileobj, mask)
def __init__(self):
self.players = []
self.sock = socket.socket()
self.sock.bind(('0.0.0.0', 1234))
self.sock.listen(100)
self.sel = selectors.DefaultSelector()
self.sel.register(self.sock, selectors.EVENT_READ, self.accept)
def accept(self, sock, mask):
assert sock == self.sock
conn, addr = sock.accept() # Should be ready
player = Player(self, conn)
self.players.append(player)
self.sel.register(conn, selectors.EVENT_READ, player.read)
def removePlayer(self, player):
assert player in self.players
player.close()
self.players.remove(player)
assert player not in self.players # this ensure the player was in only once
def close(self):
for player in self.players:
player.close()
self.players.clear()
self.sock.close()
def run(self):
while True:
events = self.sel.select()
for key, mask in events:
callback = key.data
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