Fix the multiplayer password bug while not breaking anything else, especially not multiplayer as a whole. (tested code)

This commit is contained in:
goeo_ 2017-07-23 14:37:12 -04:00
parent d439490029
commit 401dd5ecdb
2 changed files with 19 additions and 12 deletions

View File

@ -202,19 +202,18 @@ def createMatch(matchID):
# Get match binary data and build packet
match = glob.matches.matches[matchID]
matchData = match.getMatchData()
matchData.matchPassword = ""
matchData = match.getMatchData(censored=True)
return packetHelper.buildPacket(packetIDs.server_newMatch, matchData)
# TODO: Add match object argument to save some CPU
def updateMatch(matchID):
def updateMatch(matchID, censored = False):
# Make sure the match exists
if matchID not in glob.matches.matches:
return bytes()
# Get match binary data and build packet
match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_updateMatch, match.getMatchData())
return packetHelper.buildPacket(packetIDs.server_updateMatch, match.getMatchData(censored=censored))
def matchStart(matchID):
# Make sure the match exists
@ -271,4 +270,4 @@ def notification(message):
return packetHelper.buildPacket(packetIDs.server_notification, [[message, dataTypes.STRING]])
def banchoRestart(msUntilReconnection):
return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.UINT32]])
return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.UINT32]])

View File

@ -66,7 +66,7 @@ class match:
# Create #multiplayer channel
glob.channels.addTempChannel("#multi_{}".format(self.matchID))
def getMatchData(self):
def getMatchData(self, censored = False):
"""
Return binary match data structure for packetHelper
@ -80,12 +80,18 @@ class match:
[int(safeMatch.inProgress), dataTypes.BYTE],
[0, dataTypes.BYTE],
[safeMatch.mods, dataTypes.UINT32],
[safeMatch.matchName, dataTypes.STRING],
[safeMatch.matchPassword, dataTypes.STRING],
[safeMatch.matchName, dataTypes.STRING]
]
if censored and safeMatch.matchPassword:
struct.append(["redacted", dataTypes.STRING])
else:
struct.append([safeMatch.matchPassword, dataTypes.STRING])
struct.extend([
[safeMatch.beatmapName, dataTypes.STRING],
[safeMatch.beatmapID, dataTypes.UINT32],
[safeMatch.beatmapMD5, dataTypes.STRING],
]
[safeMatch.beatmapMD5, dataTypes.STRING]
])
# Slots status IDs, always 16 elements
for i in range(0,16):
@ -611,9 +617,11 @@ class match:
:return:
"""
self.matchDataCache = serverPackets.updateMatch(self.matchID)
censoredDataCache = serverPackets.updateMatch(self.matchID, censored=True)
if self.matchDataCache is not None:
glob.streams.broadcast(self.streamName, self.matchDataCache)
glob.streams.broadcast("lobby", self.matchDataCache)
if censoredDataCache is not None:
glob.streams.broadcast("lobby", censoredDataCache)
else:
log.error("MPROOM{}: Can't send match update packet, match data is None!!!".format(self.matchID))
@ -671,4 +679,4 @@ class match:
glob.streams.broadcast(self.playingStreamName, serverPackets.matchStart(self.matchID))
# Send updates
self.sendUpdates()
self.sendUpdates()