pep.py/events/spectateFramesEvent.py

32 lines
1.0 KiB
Python
Raw Normal View History

2016-05-18 17:12:46 +00:00
from objects import glob
from constants import serverPackets
from constants import exceptions
2016-04-19 17:40:59 +00:00
def handle(userToken, packetData):
# get token data
userID = userToken.userID
# Send spectator frames to every spectator
glob.streams.broadcast("spect/{}".format(userID), serverPackets.spectatorFrames(packetData[7:]))
'''for i in userToken.spectators:
2016-04-19 17:40:59 +00:00
# Send to every user but host
if i != userID:
try:
# Get spectator token object
spectatorToken = glob.tokens.getTokenFromUserID(i)
# Make sure the token exists
2016-09-02 15:45:10 +00:00
if spectatorToken is None:
2016-04-19 17:40:59 +00:00
raise exceptions.stopSpectating
# Make sure this user is spectating us
if spectatorToken.spectating != userID:
raise exceptions.stopSpectating
# Everything seems fine, send spectator frames to this spectator
spectatorToken.enqueue(serverPackets.spectatorFrames(packetData[7:]))
except exceptions.stopSpectating:
# Remove this user from spectators
userToken.removeSpectator(i)
userToken.enqueue(serverPackets.removeSpectator(i))'''