2016-05-18 17:12:46 +00:00
|
|
|
from objects import glob
|
|
|
|
from constants import serverPackets
|
|
|
|
from constants import exceptions
|
2016-06-04 10:44:54 +00:00
|
|
|
from helpers import logHelper as log
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def handle(userToken, _):
|
|
|
|
try:
|
|
|
|
# get user token data
|
|
|
|
userID = userToken.userID
|
|
|
|
username = userToken.username
|
|
|
|
|
|
|
|
# Remove our userID from host's spectators
|
|
|
|
target = userToken.spectating
|
|
|
|
targetToken = glob.tokens.getTokenFromUserID(target)
|
|
|
|
if targetToken == None:
|
|
|
|
raise exceptions.tokenNotFoundException
|
|
|
|
targetToken.removeSpectator(userID)
|
|
|
|
|
|
|
|
# Send the spectator left packet to host
|
|
|
|
targetToken.enqueue(serverPackets.removeSpectator(userID))
|
2016-06-08 15:26:31 +00:00
|
|
|
for c in targetToken.spectators:
|
|
|
|
spec = glob.tokens.getTokenFromUserID(c)
|
|
|
|
spec.enqueue(serverPackets.fellowSpectatorLeft(userID))
|
|
|
|
|
2016-06-08 18:27:59 +00:00
|
|
|
#targetToken.enqueue(serverPackets.fellowSpectatorLeft(userID))
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Console output
|
|
|
|
# TODO: Move messages in stop spectating
|
2016-06-04 10:44:54 +00:00
|
|
|
log.info("{} are no longer spectating whoever they were spectating".format(username))
|
2016-04-19 17:40:59 +00:00
|
|
|
except exceptions.tokenNotFoundException:
|
2016-06-04 10:44:54 +00:00
|
|
|
log.warning("Spectator stop: token not found")
|
2016-04-19 17:40:59 +00:00
|
|
|
finally:
|
|
|
|
# Set our spectating user to 0
|
|
|
|
userToken.stopSpectating()
|