Skip to content

Commit

Permalink
bugfix: 試合中のdisconnectに対応することで、roomに再接続した際のバグを解決しました。
Browse files Browse the repository at this point in the history
  • Loading branch information
massahito committed Aug 1, 2024
1 parent d70ec32 commit dab89b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pong/realtime_pong_game/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def receive(self, text_data=None, bytes_data=None):
await self.room_manager.on_receive_user_message(self.user, text_data)

async def disconnect(self, close_code):
if self.room_manager is not None
if hasattr(self, "room_manager"):
await self.room_manager.on_user_disconnected(self.user)
await self.channel_layer.group_discard(self.room_name, self.channel_name)

Expand Down
10 changes: 2 additions & 8 deletions pong/realtime_pong_game/roommanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ async def on_user_disconnected(self, user):
with self.instance_lock:
# TODO send message when RoomState is ready

if self.room_state == RoomState.In_Game:
return
self.participants.remove(user)
if len(self.participants) == 0:
self.__class__.remove_instance(self.room_name)
Expand Down Expand Up @@ -124,12 +122,8 @@ async def user_became_ready_for_game(self, participant, message_json):
"send_room_information",
{"sender": "room-manager", "type": "all-participants-ready"},
)
self.participants_state[self.participants[0]] = (
ParticipantState.Player1
)
self.participants_state[self.participants[1]] = (
ParticipantState.Player1
)
self.participants_state[self.participants[0]] = ParticipantState.Player1
self.participants_state[self.participants[1]] = ParticipantState.Player2
asyncio.new_event_loop().run_in_executor(
None,
self.game_dispatcher,
Expand Down

0 comments on commit dab89b7

Please sign in to comment.