Send the api some data when a multiplayer match ends
This commit is contained in:
parent
8c3fc6842d
commit
2cf1cdf1fd
|
@ -143,6 +143,26 @@ def transferHost(stream):
|
|||
def matchInvite(stream):
|
||||
return packetHelper.readPacketData(stream, [["userID", dataTypes.UINT32]])
|
||||
|
||||
def matchFrames(stream):
|
||||
return packetHelper.readPacketData(stream,
|
||||
[
|
||||
["time", dataTypes.SINT32],
|
||||
["id", dataTypes.BYTE],
|
||||
["count300", dataTypes.UINT16],
|
||||
["count100", dataTypes.UINT16],
|
||||
["count50", dataTypes.UINT16],
|
||||
["countGeki", dataTypes.UINT16],
|
||||
["countKatu", dataTypes.UINT16],
|
||||
["countMiss", dataTypes.UINT16],
|
||||
["totalScore", dataTypes.SINT32],
|
||||
["maxCombo", dataTypes.UINT16],
|
||||
["currentCombo", dataTypes.UINT16],
|
||||
["perfect", dataTypes.BYTE],
|
||||
["currentHp", dataTypes.BYTE],
|
||||
["tagByte", dataTypes.BYTE],
|
||||
["usingScoreV2", dataTypes.BYTE]
|
||||
])
|
||||
|
||||
def tournamentMatchInfoRequest(stream):
|
||||
return packetHelper.readPacketData(stream, [["matchID", dataTypes.UINT32]])
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from objects import glob
|
||||
from constants import serverPackets
|
||||
from constants import serverPackets, clientPackets
|
||||
|
||||
def handle(userToken, packetData):
|
||||
# Get usertoken data
|
||||
|
@ -22,5 +22,11 @@ def handle(userToken, packetData):
|
|||
# Change slot id in packetData
|
||||
slotID = match.getUserSlotID(userID)
|
||||
|
||||
# Parse the data
|
||||
data = clientPackets.matchFrames(packetData)
|
||||
|
||||
# Update the score
|
||||
match.updateScore(slotID, data["totalScore"])
|
||||
|
||||
# Enqueue frames to who's playing
|
||||
glob.streams.broadcast(match.playingStreamName, serverPackets.matchFrames(slotID, packetData))
|
|
@ -1,4 +1,5 @@
|
|||
import copy
|
||||
import json
|
||||
from common.log import logUtils as log
|
||||
from constants import dataTypes
|
||||
from constants import matchModModes
|
||||
|
@ -21,6 +22,7 @@ class slot:
|
|||
self.loaded = False
|
||||
self.skip = False
|
||||
self.complete = False
|
||||
self.score = 0
|
||||
|
||||
class match:
|
||||
def __init__(self, matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID):
|
||||
|
@ -311,6 +313,16 @@ class match:
|
|||
glob.streams.broadcast(self.playingStreamName, serverPackets.allPlayersSkipped())
|
||||
log.info("MPROOM{}: All players have skipped!".format(self.matchID))
|
||||
|
||||
def updateScore(self, slotID, score):
|
||||
"""
|
||||
Update score for a slot
|
||||
|
||||
:param slotID: the slot that the user that is updating their score is in
|
||||
:param score: the new score to update
|
||||
:return:
|
||||
"""
|
||||
self.slots[slotID].score = score
|
||||
|
||||
def playerCompleted(self, userID):
|
||||
"""
|
||||
Set userID's slot completed to True
|
||||
|
@ -343,6 +355,27 @@ class match:
|
|||
|
||||
:return:
|
||||
"""
|
||||
# Collect some info about the match that just ended to send to the api
|
||||
infoToSend = {
|
||||
"id": self.matchID,
|
||||
"name": self.matchName,
|
||||
"beatmap_id": self.beatmapID,
|
||||
"mods": self.mods,
|
||||
"game_mode": self.gameMode,
|
||||
"scores": {}
|
||||
}
|
||||
|
||||
# Add score info for each player
|
||||
for i in range(0,16):
|
||||
if self.slots[i].user is not None and self.slots[i].status == slotStatuses.PLAYING:
|
||||
infoToSend["scores"][glob.tokens.tokens[self.slots[i].user].userID] = {
|
||||
"score": self.slots[i].score,
|
||||
"mods": self.slots[i].mods
|
||||
}
|
||||
|
||||
# Send the info to the api
|
||||
glob.redis.publish("api:mp_complete_match", json.dumps(infoToSend))
|
||||
|
||||
# Reset inProgress
|
||||
self.inProgress = False
|
||||
|
||||
|
@ -353,6 +386,7 @@ class match:
|
|||
self.slots[i].loaded = False
|
||||
self.slots[i].skip = False
|
||||
self.slots[i].complete = False
|
||||
self.slots[i].score = 0
|
||||
|
||||
# Send match update
|
||||
self.sendUpdates()
|
||||
|
|
Loading…
Reference in New Issue
Block a user