Skip to content

Commit 828edcc

Browse files
committed
fixup mp room
player now have 2 ways of fixing mp room: - by creating another match - by rejoining its existing match player who created more than 2 rooms at same time is untested, but due to this fix it shouldn't be possible anymore.
1 parent 01b8071 commit 828edcc

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

app/api/domains/cho.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,18 +1395,7 @@ async def handle(self, player: Player) -> None:
13951395

13961396
if player.match:
13971397
player.enqueue(app.packets.match_join_fail())
1398-
player.send_bot("You're already in a match. We will try removing you from it.")
1399-
1400-
async def next_tick():
1401-
player.leave_match()
1402-
player.enqueue(
1403-
app.packets.notification(
1404-
"You can try again. Please report to staff if you keep getting this error."
1405-
)
1406-
)
1407-
1408-
asyncio.create_task(next_tick(), name="remove-duplicated-user")
1409-
return
1398+
player.leave_match()
14101399

14111400
# create the channel and add it
14121401
# to the global channel list as

app/objects/player.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,29 @@ async def unsilence(self, admin: Player, reason: str) -> None:
572572

573573
log(f"Unsilenced {self}.", Ansi.LCYAN)
574574

575+
def _special_case_disconnected_rejoin(self, match: Match, passwd: str) -> bool:
576+
"""This method will allow user to rejoin a match they were disconnected from. If everything's working properly, this method should never be called."""
577+
578+
reverse_slot_search = match.get_slot(self)
579+
lobby = app.state.sessions.channels.get_by_name("#lobby")
580+
if reverse_slot_search is None:
581+
# recoverable, reset user state before perform normal join.
582+
self.match = None
583+
self.leave_channel(match.chat)
584+
self.join_channel(lobby) if lobby else None
585+
return self.join_match(match, passwd)
586+
587+
# user is in the match, but was disconnected.
588+
self.join_channel(match.chat)
589+
self.leave_channel(lobby) if lobby else None
590+
self.enqueue(app.packets.match_join_success(match))
591+
return True
592+
575593
def join_match(self, match: Match, passwd: str) -> bool:
576594
"""Attempt to add `self` to `match`."""
577595
if self.match:
596+
if (self.match.id == match.id):
597+
return self._special_case_disconnected_rejoin(match, passwd)
578598
log(f"{self} tried to join multiple matches?")
579599
self.enqueue(app.packets.match_join_fail())
580600
return False

0 commit comments

Comments
 (0)