2016-05-18 17:12:46 +00:00
|
|
|
from objects import glob
|
|
|
|
from constants import clientPackets
|
|
|
|
from constants import serverPackets
|
|
|
|
from helpers import userHelper
|
2016-06-04 10:44:54 +00:00
|
|
|
from helpers import logHelper as log
|
2016-06-15 09:49:06 +00:00
|
|
|
from constants import actions
|
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-09-02 15:45:10 +00:00
|
|
|
if userHelper.isBanned(userID):
|
2016-05-04 21:41:33 +00:00
|
|
|
userToken.enqueue(serverPackets.loginBanned())
|
|
|
|
return
|
|
|
|
|
2016-07-03 18:51:19 +00:00
|
|
|
# Send restricted message if needed
|
2016-09-02 15:45:10 +00:00
|
|
|
if not userToken.restricted:
|
|
|
|
if userHelper.isRestricted(userID):
|
2016-07-03 18:51:19 +00:00
|
|
|
userToken.setRestricted()
|
|
|
|
|
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
|
|
|
|
#if userToken.spectating != 0 and userToken.actionID != actions.watching and userToken.actionID != actions.idle and userToken.actionID != actions.afk:
|
|
|
|
# userToken.stopSpectating()
|
|
|
|
|
|
|
|
# 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-06-16 11:38:17 +00:00
|
|
|
# Update cached stats if our pp changedm if we've just submitted a score or we've changed gameMode
|
2016-09-02 15:16:22 +00:00
|
|
|
if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userHelper.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):
|
2016-06-16 11:38:17 +00:00
|
|
|
# Always update game mode, or we'll cache stats from the wrong game mode if we've changed it
|
|
|
|
userToken.gameMode = packetData["gameMode"]
|
|
|
|
userToken.updateCachedStats()
|
|
|
|
|
|
|
|
# Always update action id, text and md5
|
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-06-16 11:38:17 +00:00
|
|
|
|
|
|
|
# Enqueue our new user panel and stats to us and our spectators
|
|
|
|
recipients = [userID]
|
|
|
|
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)
|
|
|
|
|
2016-09-02 15:45:10 +00:00
|
|
|
if token is not None:
|
2016-07-04 16:58:10 +00:00
|
|
|
# Force our own packet
|
|
|
|
force = True if token.userID == userID else False
|
|
|
|
token.enqueue(serverPackets.userPanel(userID, force))
|
|
|
|
token.enqueue(serverPackets.userStats(userID, force))
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Console output
|
2016-06-04 10:44:54 +00:00
|
|
|
log.info("{} changed action: {} [{}][{}]".format(username, str(userToken.actionID), userToken.actionText, userToken.actionMd5))
|