fixed error with nonexisting player views

This commit is contained in:
troido 2019-01-20 18:45:24 +01:00
parent a23533980f
commit 015d9a12bc
2 changed files with 4 additions and 5 deletions

View File

@ -31,9 +31,9 @@ class GameServer:
def sendState(self, view):
for connection, name in list(self.connections.items()):
if not view.hasPlayer(name):
continue
data = view.playerView(name)
if data is None:
continue
databytes = bytes(json.dumps(data), 'utf-8')
self.serv.send(connection, databytes)

View File

@ -41,6 +41,8 @@ class View:
def playerView(self, playerName):
player = self.world.getPlayer(playerName)
if player is None:
return None
data = []
for message in player.readMessages():
@ -67,7 +69,4 @@ class View:
data.append(["changecells", list(changedCells.items())])
return data
def hasPlayer(self, name):
return self.world.hasPlayer(name)