Notifications for Tournament Multiplayer Rooms #23

Closed
opened 2017-09-09 12:34:09 +00:00 by howl · 0 comments
howl commented 2017-09-09 12:34:09 +00:00 (Migrated from zxq.co)

I am making a pull request because I do not trust myself to write Python code anywhere near being good.

The following are mostly utilities for myself, since I will probably be the only referee today in the tournament and I will need to do everything from IRC.

With these changes, if a room is a tournament room, a notification is sent in the following cases:

  • A user joined or left the match, or they toggled the ready status.
    • In this case, a notification is sent saying how many users in the match are ready.
  • A game in the match has finished.
    • In this case, well, a notification is sent to say that the current game being played has terminated.

pls merge asap kthx

Original pull request patch:

From 3ed837dc96734324e913c9cef486fab4d8e0c214 Mon Sep 17 00:00:00 2001
From: Morgan Bazalgette <the@howl.moe>
Date: Sat, 9 Sep 2017 12:25:51 +0200
Subject: [PATCH 1/3] In tourney rooms, send a message in the chat when the
 ready status changes.

---
 events/matchReadyEvent.py |  5 +++++
 objects/match.py          | 35 ++++++++++++++++++++++++++++++++++-
 objects/osuToken.py       | 12 ++++++++++--
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/events/matchReadyEvent.py b/events/matchReadyEvent.py
index eb24ced..91f9e3f 100644
--- a/events/matchReadyEvent.py
+++ b/events/matchReadyEvent.py
@@ -14,3 +14,8 @@ def handle(userToken, _):
 	slotID = match.getUserSlotID(userID)
 	if slotID is not None:
 		match.toggleSlotReady(slotID)
+
+	# If this is a tournament match, we should send the current status of ready
+	# players.
+	if match.isTourney:
+		match.sendReadyStatus(match)
diff --git a/objects/match.py b/objects/match.py
index 3de20ba..29bd2f5 100644
--- a/objects/match.py
+++ b/objects/match.py
@@ -814,4 +814,37 @@ class match:
 	def resetReady(self):
 		for _slot in self.slots:
 			if _slot.status == slotStatuses.READY:
-				_slot.status = slotStatuses.NOT_READY
\ No newline at end of file
+				_slot.status = slotStatuses.NOT_READY
+
+	def sendReadyStatus(self):
+		chanName = "#multi_{}".format(self.matchID)
+
+		# Make sure match exists before attempting to do anything else
+		if chanName not in glob.channels.channels:
+			return
+
+		totalUsers = 0
+		readyUsers = 0
+
+		for slot in match.slots:
+			# Make sure there is a user in this slot
+			if slot.user is None:
+				continue
+
+			# In this slot there is a user, so we increase the amount of total users
+			# in this multi room.
+			totalUsers += 1
+
+			if slot.status == slotStatuses.READY:
+				readyUsers += 1
+
+		message = "{} users ready out of {}.".format(readyUsers, totalUsers)
+
+		if totalUsers == readyUsers:
+			message += " All users ready!"
+
+		# Check whether there is anyone left in this match.
+		if totalUsers == 0:
+			message = "The match is now empty."
+
+		chat.sendMessage("FokaBot", chanName, message)
diff --git a/objects/osuToken.py b/objects/osuToken.py
index 9135edf..0ecb052 100644
--- a/objects/osuToken.py
+++ b/objects/osuToken.py
@@ -321,9 +321,12 @@ class token:
 		chat.joinChannel(token=self, channel="#multi_{}".format(self.matchID))
 		self.enqueue(serverPackets.matchJoinSuccess(matchID))
 
-		# Alert the user if we have just joined a tourney match
 		if match.isTourney:
+			# Alert the user if we have just joined a tourney match
 			self.enqueue(serverPackets.notification("You are now in a tournament match."))
+			# If an user joins, then the ready status of the match changes and
+			# maybe not all users are ready.
+			match.sendReadyStatus(match)
 
 	def leaveMatch(self):
 		"""
@@ -354,10 +357,15 @@ class token:
 		# Set slot to free
 		match.userLeft(self)
 
+		if match.isTourney:
+			# If an user leaves, then the ready status of the match changes and
+			# maybe all users are ready. Or maybe nobody is in the match anymore
+			match.sendReadyStatus(match)
+
 	def kick(self, message="You have been kicked from the server. Please login again.", reason="kick"):
 		"""
 		Kick this user from the server
-		
+
 		:param message: Notification message to send to this user.
 						Default: "You have been kicked from the server. Please login again."
 		:param reason: Kick reason, used in logs. Default: "kick"
-- 
2.20.1


From e3e46a34ec367a40ca4a3977635e781959c89dbb Mon Sep 17 00:00:00 2001
From: Morgan Bazalgette <the@howl.moe>
Date: Sat, 9 Sep 2017 12:30:25 +0200
Subject: [PATCH 2/3] Notify the chat when the match has been completed.

---
 objects/match.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/objects/match.py b/objects/match.py
index 29bd2f5..da9c496 100644
--- a/objects/match.py
+++ b/objects/match.py
@@ -427,6 +427,12 @@ class match:
 		# Console output
 		log.info("MPROOM{}: Match completed".format(self.matchID))
 
+		# If this is a tournament match, then we send a notification in the chat
+		# saying that the match has completed.
+		chanName = "#multi_{}".format(self.matchID)
+		if self.isTourney and (chanName in glob.channels.channels):
+			chat.sendMessage("FokaBot", chanName, "Match has just finished.")
+
 	def resetSlots(self):
 		for i in range(0,16):
 			if self.slots[i].user is not None and self.slots[i].status == slotStatuses.PLAYING:
@@ -826,7 +832,7 @@ class match:
 		totalUsers = 0
 		readyUsers = 0
 
-		for slot in match.slots:
+		for slot in self.slots:
 			# Make sure there is a user in this slot
 			if slot.user is None:
 				continue
-- 
2.20.1


From c4123eb636fe764fa20433dc3fb87152cc39a2e9 Mon Sep 17 00:00:00 2001
From: Morgan Bazalgette <the@howl.moe>
Date: Sat, 9 Sep 2017 12:42:49 +0200
Subject: [PATCH 3/3] fix positional argument exception meme

---
 events/matchReadyEvent.py | 2 +-
 objects/osuToken.py       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/events/matchReadyEvent.py b/events/matchReadyEvent.py
index 91f9e3f..05e731e 100644
--- a/events/matchReadyEvent.py
+++ b/events/matchReadyEvent.py
@@ -18,4 +18,4 @@ def handle(userToken, _):
 	# If this is a tournament match, we should send the current status of ready
 	# players.
 	if match.isTourney:
-		match.sendReadyStatus(match)
+		match.sendReadyStatus()
diff --git a/objects/osuToken.py b/objects/osuToken.py
index 0ecb052..a4b0a43 100644
--- a/objects/osuToken.py
+++ b/objects/osuToken.py
@@ -326,7 +326,7 @@ class token:
 			self.enqueue(serverPackets.notification("You are now in a tournament match."))
 			# If an user joins, then the ready status of the match changes and
 			# maybe not all users are ready.
-			match.sendReadyStatus(match)
+			match.sendReadyStatus()
 
 	def leaveMatch(self):
 		"""
@@ -360,7 +360,7 @@ class token:
 		if match.isTourney:
 			# If an user leaves, then the ready status of the match changes and
 			# maybe all users are ready. Or maybe nobody is in the match anymore
-			match.sendReadyStatus(match)
+			match.sendReadyStatus()
 
 	def kick(self, message="You have been kicked from the server. Please login again.", reason="kick"):
 		"""
-- 
2.20.1


I am making a pull request because I do not trust myself to write Python code anywhere near being good. The following are mostly utilities for myself, since I will probably be the only referee today in the tournament and I will need to do everything from IRC. With these changes, if a room is a tournament room, a notification is sent in the following cases: * A user joined or left the match, or they toggled the ready status. * In this case, a notification is sent saying how many users in the match are ready. * A game in the match has finished. * In this case, well, a notification is sent to say that the current game being played has terminated. pls merge asap kthx _Original pull request patch:_ ``` From 3ed837dc96734324e913c9cef486fab4d8e0c214 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette <the@howl.moe> Date: Sat, 9 Sep 2017 12:25:51 +0200 Subject: [PATCH 1/3] In tourney rooms, send a message in the chat when the ready status changes. --- events/matchReadyEvent.py | 5 +++++ objects/match.py | 35 ++++++++++++++++++++++++++++++++++- objects/osuToken.py | 12 ++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/events/matchReadyEvent.py b/events/matchReadyEvent.py index eb24ced..91f9e3f 100644 --- a/events/matchReadyEvent.py +++ b/events/matchReadyEvent.py @@ -14,3 +14,8 @@ def handle(userToken, _): slotID = match.getUserSlotID(userID) if slotID is not None: match.toggleSlotReady(slotID) + + # If this is a tournament match, we should send the current status of ready + # players. + if match.isTourney: + match.sendReadyStatus(match) diff --git a/objects/match.py b/objects/match.py index 3de20ba..29bd2f5 100644 --- a/objects/match.py +++ b/objects/match.py @@ -814,4 +814,37 @@ class match: def resetReady(self): for _slot in self.slots: if _slot.status == slotStatuses.READY: - _slot.status = slotStatuses.NOT_READY \ No newline at end of file + _slot.status = slotStatuses.NOT_READY + + def sendReadyStatus(self): + chanName = "#multi_{}".format(self.matchID) + + # Make sure match exists before attempting to do anything else + if chanName not in glob.channels.channels: + return + + totalUsers = 0 + readyUsers = 0 + + for slot in match.slots: + # Make sure there is a user in this slot + if slot.user is None: + continue + + # In this slot there is a user, so we increase the amount of total users + # in this multi room. + totalUsers += 1 + + if slot.status == slotStatuses.READY: + readyUsers += 1 + + message = "{} users ready out of {}.".format(readyUsers, totalUsers) + + if totalUsers == readyUsers: + message += " All users ready!" + + # Check whether there is anyone left in this match. + if totalUsers == 0: + message = "The match is now empty." + + chat.sendMessage("FokaBot", chanName, message) diff --git a/objects/osuToken.py b/objects/osuToken.py index 9135edf..0ecb052 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -321,9 +321,12 @@ class token: chat.joinChannel(token=self, channel="#multi_{}".format(self.matchID)) self.enqueue(serverPackets.matchJoinSuccess(matchID)) - # Alert the user if we have just joined a tourney match if match.isTourney: + # Alert the user if we have just joined a tourney match self.enqueue(serverPackets.notification("You are now in a tournament match.")) + # If an user joins, then the ready status of the match changes and + # maybe not all users are ready. + match.sendReadyStatus(match) def leaveMatch(self): """ @@ -354,10 +357,15 @@ class token: # Set slot to free match.userLeft(self) + if match.isTourney: + # If an user leaves, then the ready status of the match changes and + # maybe all users are ready. Or maybe nobody is in the match anymore + match.sendReadyStatus(match) + def kick(self, message="You have been kicked from the server. Please login again.", reason="kick"): """ Kick this user from the server - + :param message: Notification message to send to this user. Default: "You have been kicked from the server. Please login again." :param reason: Kick reason, used in logs. Default: "kick" -- 2.20.1 From e3e46a34ec367a40ca4a3977635e781959c89dbb Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette <the@howl.moe> Date: Sat, 9 Sep 2017 12:30:25 +0200 Subject: [PATCH 2/3] Notify the chat when the match has been completed. --- objects/match.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/objects/match.py b/objects/match.py index 29bd2f5..da9c496 100644 --- a/objects/match.py +++ b/objects/match.py @@ -427,6 +427,12 @@ class match: # Console output log.info("MPROOM{}: Match completed".format(self.matchID)) + # If this is a tournament match, then we send a notification in the chat + # saying that the match has completed. + chanName = "#multi_{}".format(self.matchID) + if self.isTourney and (chanName in glob.channels.channels): + chat.sendMessage("FokaBot", chanName, "Match has just finished.") + def resetSlots(self): for i in range(0,16): if self.slots[i].user is not None and self.slots[i].status == slotStatuses.PLAYING: @@ -826,7 +832,7 @@ class match: totalUsers = 0 readyUsers = 0 - for slot in match.slots: + for slot in self.slots: # Make sure there is a user in this slot if slot.user is None: continue -- 2.20.1 From c4123eb636fe764fa20433dc3fb87152cc39a2e9 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette <the@howl.moe> Date: Sat, 9 Sep 2017 12:42:49 +0200 Subject: [PATCH 3/3] fix positional argument exception meme --- events/matchReadyEvent.py | 2 +- objects/osuToken.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/events/matchReadyEvent.py b/events/matchReadyEvent.py index 91f9e3f..05e731e 100644 --- a/events/matchReadyEvent.py +++ b/events/matchReadyEvent.py @@ -18,4 +18,4 @@ def handle(userToken, _): # If this is a tournament match, we should send the current status of ready # players. if match.isTourney: - match.sendReadyStatus(match) + match.sendReadyStatus() diff --git a/objects/osuToken.py b/objects/osuToken.py index 0ecb052..a4b0a43 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -326,7 +326,7 @@ class token: self.enqueue(serverPackets.notification("You are now in a tournament match.")) # If an user joins, then the ready status of the match changes and # maybe not all users are ready. - match.sendReadyStatus(match) + match.sendReadyStatus() def leaveMatch(self): """ @@ -360,7 +360,7 @@ class token: if match.isTourney: # If an user leaves, then the ready status of the match changes and # maybe all users are ready. Or maybe nobody is in the match anymore - match.sendReadyStatus(match) + match.sendReadyStatus() def kick(self, message="You have been kicked from the server. Please login again.", reason="kick"): """ -- 2.20.1 ```
Nyo (Migrated from zxq.co) closed this issue 2020-11-26 16:53:52 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ripple/pep.py#23
No description provided.