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 serverPackets
|
2016-10-02 20:48:14 +00:00
|
|
|
from objects import glob
|
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
def handle(userToken, packetData):
|
|
|
|
# Get usertoken data
|
|
|
|
userID = userToken.userID
|
|
|
|
username = userToken.username
|
|
|
|
|
2016-05-04 21:41:33 +00:00
|
|
|
# Make sure we are not banned
|
2016-11-20 10:31:51 +00:00
|
|
|
#if userUtils.isBanned(userID):
|
|
|
|
# userToken.enqueue(serverPackets.loginBanned())
|
|
|
|
# return
|
2016-05-04 21:41:33 +00:00
|
|
|
|
2016-07-03 18:51:19 +00:00
|
|
|
# Send restricted message if needed
|
2016-11-20 10:31:51 +00:00
|
|
|
#if userToken.restricted:
|
|
|
|
# userToken.checkRestricted(True)
|
2016-07-03 18:51:19 +00:00
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
# Change action packet
|
|
|
|
packetData = clientPackets.userActionChange(packetData)
|
|
|
|
|
2016-09-02 10:41:19 +00:00
|
|
|
# If we are not in spectate status but we're spectating someone, stop spectating
|
2016-09-04 15:26:58 +00:00
|
|
|
'''
|
|
|
|
if userToken.spectating != 0 and userToken.actionID != actions.WATCHING and userToken.actionID != actions.IDLE and userToken.actionID != actions.AFK:
|
|
|
|
userToken.stopSpectating()
|
2016-09-02 10:41:19 +00:00
|
|
|
|
2016-09-04 15:26:58 +00:00
|
|
|
# If we are not in multiplayer but we are in a match, part match
|
|
|
|
if userToken.matchID != -1 and userToken.actionID != actions.MULTIPLAYING and userToken.actionID != actions.MULTIPLAYER and userToken.actionID != actions.AFK:
|
|
|
|
userToken.partMatch()
|
|
|
|
'''
|
2016-09-02 10:41:19 +00:00
|
|
|
|
2016-10-08 20:37:10 +00:00
|
|
|
# Update cached stats if our pp changed if we've just submitted a score or we've changed gameMode
|
2016-11-20 10:31:51 +00:00
|
|
|
#if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userUtils.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):
|
|
|
|
|
|
|
|
# Update cached stats if we've changed gamemode
|
|
|
|
if userToken.gameMode != packetData["gameMode"]:
|
2016-06-16 11:38:17 +00:00
|
|
|
userToken.gameMode = packetData["gameMode"]
|
|
|
|
userToken.updateCachedStats()
|
|
|
|
|
2016-09-13 09:56:53 +00:00
|
|
|
# Always update action id, text, md5 and beatmapID
|
2016-04-19 17:40:59 +00:00
|
|
|
userToken.actionID = packetData["actionID"]
|
|
|
|
userToken.actionText = packetData["actionText"]
|
|
|
|
userToken.actionMd5 = packetData["actionMd5"]
|
|
|
|
userToken.actionMods = packetData["actionMods"]
|
2016-09-13 09:56:53 +00:00
|
|
|
userToken.beatmapID = packetData["beatmapID"]
|
2016-06-16 11:38:17 +00:00
|
|
|
|
|
|
|
# Enqueue our new user panel and stats to us and our spectators
|
2016-10-04 20:10:07 +00:00
|
|
|
recipients = [userToken]
|
2016-06-16 11:38:17 +00:00
|
|
|
if len(userToken.spectators) > 0:
|
2016-10-07 10:42:02 +00:00
|
|
|
for i in userToken.spectators:
|
|
|
|
if i in glob.tokens.tokens:
|
|
|
|
recipients.append(glob.tokens.tokens[i])
|
2016-06-16 11:38:17 +00:00
|
|
|
|
|
|
|
for i in recipients:
|
2016-10-04 20:10:07 +00:00
|
|
|
if i is not None:
|
2016-07-04 16:58:10 +00:00
|
|
|
# Force our own packet
|
2016-10-04 20:10:07 +00:00
|
|
|
force = True if i == userToken else False
|
|
|
|
i.enqueue(serverPackets.userPanel(userID, force))
|
|
|
|
i.enqueue(serverPackets.userStats(userID, force))
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Console output
|
2016-09-13 09:56:53 +00:00
|
|
|
log.info("{} changed action: {} [{}][{}][{}]".format(username, str(userToken.actionID), userToken.actionText, userToken.actionMd5, userToken.beatmapID))
|