.BANCHO. .FIX. Add user stats cache and user stats request packet
This commit is contained in:
@@ -18,12 +18,38 @@ def handle(userToken, packetData):
|
||||
# Change action packet
|
||||
packetData = clientPackets.userActionChange(packetData)
|
||||
|
||||
# Update our action id, text and md5
|
||||
# Update cached stats if our pp changedm if we've just submitted a score or we've changed gameMode
|
||||
if (userToken.actionID == actions.playing or userToken.actionID == actions.multiplaying) or (userToken.pp != userHelper.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):
|
||||
log.debug("!!!! UPDATING CACHED STATS !!!!")
|
||||
# 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
|
||||
userToken.actionID = packetData["actionID"]
|
||||
userToken.actionText = packetData["actionText"]
|
||||
userToken.actionMd5 = packetData["actionMd5"]
|
||||
userToken.actionMods = packetData["actionMods"]
|
||||
userToken.gameMode = packetData["gameMode"]
|
||||
|
||||
# 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)
|
||||
|
||||
if token != None:
|
||||
token.enqueue(serverPackets.userPanel(userID))
|
||||
token.enqueue(serverPackets.userStats(userID))
|
||||
|
||||
# TODO: Enqueue all if we've changed game mode, (maybe not needed because it's cached)
|
||||
#glob.tokens.enqueueAll(serverPackets.userPanel(userID))
|
||||
#glob.tokens.enqueueAll(serverPackets.userStats(userID))
|
||||
|
||||
# Send osu!direct alert if needed
|
||||
# NOTE: Remove this when osu!direct will be fixed
|
||||
@@ -31,9 +57,6 @@ def handle(userToken, packetData):
|
||||
userToken.osuDirectAlert = True
|
||||
userToken.enqueue(serverPackets.sendMessage("FokaBot", userToken.username, "Sup! osu!direct works, kinda. To download a beatmap, you have to click the \"View listing\" button (the last one) instead of \"Download\". However, if you are on the stable (fallback) branch, it should work also with the \"Download\" button. We'll fix that bug as soon as possibleTM."))
|
||||
|
||||
# Enqueue our new user panel and stats to everyone
|
||||
glob.tokens.enqueueAll(serverPackets.userPanel(userID))
|
||||
glob.tokens.enqueueAll(serverPackets.userStats(userID))
|
||||
|
||||
# Console output
|
||||
log.info("{} changed action: {} [{}][{}]".format(username, str(userToken.actionID), userToken.actionText, userToken.actionMd5))
|
||||
|
@@ -101,7 +101,6 @@ def handle(tornadoRequest):
|
||||
|
||||
# Channel info end (before starting!?! wtf bancho?)
|
||||
responseToken.enqueue(serverPackets.channelInfoEnd())
|
||||
|
||||
# Default opened channels
|
||||
# TODO: Configurable default channels
|
||||
channelJoinEvent.joinChannel(responseToken, "#osu")
|
||||
@@ -125,9 +124,9 @@ def handle(tornadoRequest):
|
||||
|
||||
# Get everyone else userpanel
|
||||
# TODO: Better online users handling
|
||||
for key, value in glob.tokens.tokens.items():
|
||||
responseToken.enqueue(serverPackets.userPanel(value.userID))
|
||||
responseToken.enqueue(serverPackets.userStats(value.userID))
|
||||
#for key, value in glob.tokens.tokens.items():
|
||||
# responseToken.enqueue(serverPackets.userPanel(value.userID))
|
||||
# responseToken.enqueue(serverPackets.userStats(value.userID))
|
||||
|
||||
# Send online users IDs array
|
||||
responseToken.enqueue(serverPackets.onlineUsers())
|
||||
|
11
events/requestStatusUpdateEvent.py
Normal file
11
events/requestStatusUpdateEvent.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from constants import clientPackets
|
||||
from constants import serverPackets
|
||||
from helpers import userHelper
|
||||
from helpers import logHelper as log
|
||||
|
||||
def handle(userToken, packetData):
|
||||
log.debug("Requested status update")
|
||||
|
||||
# Update cache and send new stats
|
||||
userToken.updateCachedStats()
|
||||
userToken.enqueue(serverPackets.userStats(userToken.userID))
|
22
events/userStatsRequestEvent.py
Normal file
22
events/userStatsRequestEvent.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from constants import clientPackets
|
||||
from constants import serverPackets
|
||||
from helpers import logHelper as log
|
||||
|
||||
def handle(userToken, packetData):
|
||||
# Read userIDs list
|
||||
packetData = clientPackets.userStatsRequest(packetData)
|
||||
|
||||
# Process lists with length <= 32
|
||||
if len(packetData) > 32:
|
||||
log.warning("Received userStatsRequest with length > 32")
|
||||
return
|
||||
|
||||
for i in packetData["users"]:
|
||||
log.debug("Sending stats for user {}".format(i))
|
||||
|
||||
# Skip our stats
|
||||
if i == userToken.userID:
|
||||
continue
|
||||
|
||||
# Enqueue stats packets relative to this user
|
||||
userToken.enqueue(serverPackets.userStats(i))
|
Reference in New Issue
Block a user