Skip to content

Commit

Permalink
Fix gameserver spawning bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mzsawicki committed Jun 3, 2023
1 parent 856389b commit 1f2ce93
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion superego/application/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class GameServer(metaclass=ABCMeta):
@abstractmethod
def run(self) -> None:
async def run(self) -> None:
raise NotImplemented

@abstractmethod
Expand Down
2 changes: 2 additions & 0 deletions superego/application/usecases.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def __call__(self, player_guids: List[UUID]) -> GameServer:
lobby_members = [LobbyMember(name, guid) for name, guid in people.items()]
game_settings = GameSettings(deck, 1)
lobby = Lobby(lobby_members[0], game_settings)
for member in lobby_members:
lobby.add_member(member)
game_server = self._creator.create(lobby)
return game_server

Expand Down
2 changes: 2 additions & 0 deletions superego/infrastructure/http/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import json
from uuid import UUID

Expand Down Expand Up @@ -109,6 +110,7 @@ async def start_game(request):

game_server = start_game_(player_guids)
request.app['game_server_pool'].store(game_server)
asyncio.create_task(game_server.run())
return web.Response(status=200)

async def ongoing_game(request):
Expand Down
4 changes: 2 additions & 2 deletions superego/infrastructure/websockets/gameserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def __init__(
self._stopped: asyncio.Future = self._loop.create_future()
self._loop.add_signal_handler(signal.SIGINT, self.stop)

def run(self) -> None:
self._loop.run_until_complete(self._serve())
async def run(self) -> None:
await self._serve()

def stop(self) -> None:
self._stopped.set_result(True)
Expand Down
4 changes: 2 additions & 2 deletions tests/subscribe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def listen(uri):
async with connect(uri) as websocket:
dict_ = {
'action': 'SUBSCRIBE',
'issuer': 'a7da476f-c81b-4bc7-ac17-e7e675ccc95f'
'issuer': '55ae1d15-3aa1-4277-90e1-fd711aad6d0d'
}
message = json.dumps(dict_)
data = message.encode(ENCODING)
Expand All @@ -22,7 +22,7 @@ async def listen(uri):
print(response)
dict_ = {
'action': 'READ',
'issuer': 'a7da476f-c81b-4bc7-ac17-e7e675ccc95f'
'issuer': '55ae1d15-3aa1-4277-90e1-fd711aad6d0d'
}
message = json.dumps(dict_)
data = message.encode(ENCODING)
Expand Down

0 comments on commit 1f2ce93

Please sign in to comment.