pep.py/events/startSpectatingEvent.py

27 lines
797 B
Python
Raw Normal View History

2016-10-02 20:48:14 +00:00
from common.log import logUtils as log
2016-05-18 17:12:46 +00:00
from constants import clientPackets
from constants import exceptions
2016-10-02 20:48:14 +00:00
from objects import glob
2016-04-19 17:40:59 +00:00
def handle(userToken, packetData):
try:
# Start spectating packet
packetData = clientPackets.startSpectating(packetData)
2017-08-10 22:45:44 +00:00
# If the user id is less than 0, treat this as a stop spectating packet
if packetData["userID"] < 0:
userToken.stopSpectating()
return
2017-08-10 22:45:44 +00:00
2016-04-19 17:40:59 +00:00
# Get host token
targetToken = glob.tokens.getTokenFromUserID(packetData["userID"])
2016-09-02 15:45:10 +00:00
if targetToken is None:
2016-04-19 17:40:59 +00:00
raise exceptions.tokenNotFoundException
# Start spectating new user
userToken.startSpectating(targetToken)
2016-04-19 17:40:59 +00:00
except exceptions.tokenNotFoundException:
# Stop spectating if token not found
log.warning("Spectator start: token not found")
2016-04-19 17:40:59 +00:00
userToken.stopSpectating()