From 3f9bad3d21a01e2db9f9602855405e819d4e5152 Mon Sep 17 00:00:00 2001 From: russelg Date: Wed, 8 Jun 2016 23:26:31 +0800 Subject: [PATCH] .BANCHO. Add spectator list --- constants/serverPackets.py | 6 ++++++ events/startSpectatingEvent.py | 7 +++++++ events/stopSpectatingEvent.py | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/constants/serverPackets.py b/constants/serverPackets.py index 1fc30d8..e546801 100644 --- a/constants/serverPackets.py +++ b/constants/serverPackets.py @@ -188,6 +188,12 @@ def spectatorFrames(data): def noSongSpectator(userID): return packetHelper.buildPacket(packetIDs.server_spectatorCantSpectate, [[userID, dataTypes.sInt32]]) +def fellowSpectatorJoined(userID): + return packetHelper.buildPacket(packetIDs.server_fellowSpectatorJoined, [[userID, dataTypes.sInt32]]) + +def fellowSpectatorLeft(userID): + return packetHelper.buildPacket(packetIDs.server_fellowSpectatorLeft, [[userID, dataTypes.sInt32]]) + """ Multiplayer Packets """ def createMatch(matchID): diff --git a/events/startSpectatingEvent.py b/events/startSpectatingEvent.py index 028238a..c9b998d 100644 --- a/events/startSpectatingEvent.py +++ b/events/startSpectatingEvent.py @@ -41,6 +41,13 @@ def handle(userToken, packetData): # First spectator, send #spectator join to host too targetToken.enqueue(serverPackets.channelJoinSuccess(userID, "#spectator")) + # send fellowSpectatorJoined to all spectators + for c in targetToken.spectators: + if c is not userID: + targetToken.enqueue(serverPackets.fellowSpectatorJoined(c)) + specToken = glob.tokens.getTokenFromUserID(c) + specToken.enqueue(serverPackets.fellowSpectatorJoined(userID)) + # Console output log.info("{} are spectating {}".format(username, userHelper.getUsername(packetData["userID"]))) except exceptions.tokenNotFoundException: diff --git a/events/stopSpectatingEvent.py b/events/stopSpectatingEvent.py index 729876b..d333e84 100644 --- a/events/stopSpectatingEvent.py +++ b/events/stopSpectatingEvent.py @@ -18,6 +18,11 @@ def handle(userToken, _): # Send the spectator left packet to host targetToken.enqueue(serverPackets.removeSpectator(userID)) + for c in targetToken.spectators: + spec = glob.tokens.getTokenFromUserID(c) + spec.enqueue(serverPackets.fellowSpectatorLeft(userID)) + + targetToken.enqueue(serverPackets.fellowSpectatorLeft(userID)) # Console output # TODO: Move messages in stop spectating