.BANCHO. Implemented packet streams for spectator and lobby
This commit is contained in:
@@ -48,22 +48,16 @@ if userToken.matchID != -1 and userToken.actionID != actions.MULTIPLAYING and us
|
||||
userToken.beatmapID = packetData["beatmapID"]
|
||||
|
||||
# Enqueue our new user panel and stats to us and our spectators
|
||||
recipients = [userID]
|
||||
recipients = [userToken]
|
||||
if len(userToken.spectators) > 0:
|
||||
recipients += userToken.spectators
|
||||
|
||||
for i in recipients:
|
||||
if i == userID:
|
||||
# Save some loops
|
||||
token = userToken
|
||||
else:
|
||||
token = glob.tokens.getTokenFromUserID(i)
|
||||
|
||||
if token is not None:
|
||||
if i is not None:
|
||||
# Force our own packet
|
||||
force = True if token.userID == userID else False
|
||||
token.enqueue(serverPackets.userPanel(userID, force))
|
||||
token.enqueue(serverPackets.userStats(userID, force))
|
||||
force = True if i == userToken else False
|
||||
i.enqueue(serverPackets.userPanel(userID, force))
|
||||
i.enqueue(serverPackets.userStats(userID, force))
|
||||
|
||||
# Console output
|
||||
log.info("{} changed action: {} [{}][{}][{}]".format(username, str(userToken.actionID), userToken.actionText, userToken.actionMd5, userToken.beatmapID))
|
||||
|
@@ -32,11 +32,7 @@ def handle(userToken, packetData):
|
||||
match.setHost(userID)
|
||||
|
||||
# Send match create packet to everyone in lobby
|
||||
for i in glob.matches.usersInLobby:
|
||||
# Make sure this user is still connected
|
||||
token = glob.tokens.getTokenFromUserID(i)
|
||||
if token is not None:
|
||||
token.enqueue(serverPackets.createMatch(matchID))
|
||||
glob.streams.broadcast("lobby", serverPackets.createMatch(matchID))
|
||||
|
||||
# Console output
|
||||
log.info("MPROOM{}: Room created!".format(matchID))
|
||||
|
@@ -6,10 +6,9 @@ from objects import glob
|
||||
def handle(userToken, _):
|
||||
# Get userToken data
|
||||
username = userToken.username
|
||||
userID = userToken.userID
|
||||
|
||||
# Add user to users in lobby
|
||||
glob.matches.lobbyUserJoin(userID)
|
||||
userToken.joinStream("lobby")
|
||||
|
||||
# Send matches data
|
||||
for key, _ in glob.matches.matches.items():
|
||||
|
@@ -9,7 +9,7 @@ def handle(userToken, _):
|
||||
username = userToken.username
|
||||
|
||||
# Remove user from users in lobby
|
||||
glob.matches.lobbyUserPart(userID)
|
||||
userToken.leaveStream("lobby")
|
||||
|
||||
# Part lobby channel
|
||||
chat.partChannel(channel="#lobby", token=userToken, kick=True)
|
||||
|
@@ -7,7 +7,8 @@ def handle(userToken, packetData):
|
||||
userID = userToken.userID
|
||||
|
||||
# Send spectator frames to every spectator
|
||||
for i in userToken.spectators:
|
||||
glob.streams.broadcast("spect/{}".format(userID), serverPackets.spectatorFrames(packetData[7:]))
|
||||
'''for i in userToken.spectators:
|
||||
# Send to every user but host
|
||||
if i != userID:
|
||||
try:
|
||||
@@ -27,4 +28,4 @@ def handle(userToken, packetData):
|
||||
except exceptions.stopSpectating:
|
||||
# Remove this user from spectators
|
||||
userToken.removeSpectator(i)
|
||||
userToken.enqueue(serverPackets.removeSpectator(i))
|
||||
userToken.enqueue(serverPackets.removeSpectator(i))'''
|
||||
|
@@ -1,57 +1,20 @@
|
||||
from common.log import logUtils as log
|
||||
from common.ripple import userUtils
|
||||
from constants import clientPackets
|
||||
from constants import exceptions
|
||||
from constants import serverPackets
|
||||
from helpers import chatHelper as chat
|
||||
from objects import glob
|
||||
|
||||
|
||||
def handle(userToken, packetData):
|
||||
try:
|
||||
# Get usertoken data
|
||||
userID = userToken.userID
|
||||
username = userToken.username
|
||||
|
||||
# Start spectating packet
|
||||
packetData = clientPackets.startSpectating(packetData)
|
||||
|
||||
# Stop spectating old user if needed
|
||||
if userToken.spectating != 0:
|
||||
oldTargetToken = glob.tokens.getTokenFromUserID(userToken.spectating)
|
||||
oldTargetToken.enqueue(serverPackets.removeSpectator(userID))
|
||||
userToken.stopSpectating()
|
||||
|
||||
# Start spectating new user
|
||||
userToken.startSpectating(packetData["userID"])
|
||||
|
||||
# Get host token
|
||||
targetToken = glob.tokens.getTokenFromUserID(packetData["userID"])
|
||||
if targetToken is None:
|
||||
raise exceptions.tokenNotFoundException
|
||||
|
||||
# Add us to host's spectators
|
||||
targetToken.addSpectator(userID)
|
||||
|
||||
# Send spectator join packet to host
|
||||
targetToken.enqueue(serverPackets.addSpectator(userID))
|
||||
|
||||
# Create and join #spectator (#spect_userid) channel
|
||||
glob.channels.addTempChannel("#spect_{}".format(targetToken.userID))
|
||||
chat.joinChannel(token=userToken, channel="#spect_{}".format(targetToken.userID))
|
||||
if len(targetToken.spectators) == 1:
|
||||
# First spectator, send #spectator join to host too
|
||||
chat.joinChannel(token=targetToken, channel="#spect_{}".format(targetToken.userID))
|
||||
|
||||
# send fellowSpectatorJoined to all spectators
|
||||
for spec in targetToken.spectators:
|
||||
if spec is not userID:
|
||||
c = glob.tokens.getTokenFromUserID(spec)
|
||||
userToken.enqueue(serverPackets.fellowSpectatorJoined(c.userID))
|
||||
c.enqueue(serverPackets.fellowSpectatorJoined(userID))
|
||||
|
||||
# Console output
|
||||
log.info("{} are spectating {}".format(username, userUtils.getUsername(packetData["userID"])))
|
||||
# Start spectating new user
|
||||
userToken.startSpectating(targetToken)
|
||||
except exceptions.tokenNotFoundException:
|
||||
# Stop spectating if token not found
|
||||
log.warning("Spectator start: token not found")
|
||||
|
Reference in New Issue
Block a user