Fix various bugs with multiplayer teams and mp commands
This commit is contained in:
parent
def4891008
commit
29359ad4fd
|
@ -10,7 +10,7 @@ from common import generalUtils
|
||||||
from common.constants import mods
|
from common.constants import mods
|
||||||
from common.log import logUtils as log
|
from common.log import logUtils as log
|
||||||
from common.ripple import userUtils
|
from common.ripple import userUtils
|
||||||
from constants import exceptions, slotStatuses, matchModModes, matchTeams
|
from constants import exceptions, slotStatuses, matchModModes, matchTeams, matchTeamTypes
|
||||||
from common.constants import gameModes
|
from common.constants import gameModes
|
||||||
from common.constants import privileges
|
from common.constants import privileges
|
||||||
from constants import serverPackets
|
from constants import serverPackets
|
||||||
|
@ -924,6 +924,7 @@ def multiplayer(fro, chan, message):
|
||||||
_match.beatmapName = beatmapData["song_name"]
|
_match.beatmapName = beatmapData["song_name"]
|
||||||
_match.beatmapMD5 = beatmapData["beatmap_md5"]
|
_match.beatmapMD5 = beatmapData["beatmap_md5"]
|
||||||
_match.gameMode = gameMode
|
_match.gameMode = gameMode
|
||||||
|
_match.resetReady()
|
||||||
_match.sendUpdates()
|
_match.sendUpdates()
|
||||||
return "Match map has been updated"
|
return "Match map has been updated"
|
||||||
|
|
||||||
|
@ -939,10 +940,16 @@ def multiplayer(fro, chan, message):
|
||||||
raise exceptions.invalidArgumentsException("Match team type must be between 0 and 3")
|
raise exceptions.invalidArgumentsException("Match team type must be between 0 and 3")
|
||||||
if not 0 <= matchScoringType <= 3:
|
if not 0 <= matchScoringType <= 3:
|
||||||
raise exceptions.invalidArgumentsException("Match scoring type must be between 0 and 3")
|
raise exceptions.invalidArgumentsException("Match scoring type must be between 0 and 3")
|
||||||
|
oldMatchTeamType = _match.matchTeamType
|
||||||
_match.matchTeamType = matchTeamType
|
_match.matchTeamType = matchTeamType
|
||||||
_match.matchScoringType = matchScoringType
|
_match.matchScoringType = matchScoringType
|
||||||
if len(message) >= 4:
|
if len(message) >= 4:
|
||||||
_match.forceSize(int(message[3]))
|
_match.forceSize(int(message[3]))
|
||||||
|
if _match.matchTeamType != oldMatchTeamType:
|
||||||
|
_match.initializeTeams()
|
||||||
|
if _match.matchTeamType == matchTeamTypes.TAG_COOP or _match.matchTeamType == matchTeamTypes.TAG_TEAM_VS:
|
||||||
|
_match.matchModMode = matchModModes.NORMAL
|
||||||
|
|
||||||
_match.sendUpdates()
|
_match.sendUpdates()
|
||||||
return "Match settings have been updated!"
|
return "Match settings have been updated!"
|
||||||
|
|
||||||
|
@ -1002,8 +1009,10 @@ def multiplayer(fro, chan, message):
|
||||||
freeMod = True
|
freeMod = True
|
||||||
|
|
||||||
_match.matchModMode = matchModModes.FREE_MOD if freeMod else matchModModes.NORMAL
|
_match.matchModMode = matchModModes.FREE_MOD if freeMod else matchModModes.NORMAL
|
||||||
|
_match.resetReady()
|
||||||
|
if _match.matchModMode == matchModModes.FREE_MOD:
|
||||||
|
_match.resetMods()
|
||||||
_match.changeMods(newMods)
|
_match.changeMods(newMods)
|
||||||
|
|
||||||
return "Match mods have been updated!"
|
return "Match mods have been updated!"
|
||||||
|
|
||||||
def mpTeam():
|
def mpTeam():
|
||||||
|
@ -1039,10 +1048,10 @@ def multiplayer(fro, chan, message):
|
||||||
readableStatus = readableStatuses[slot.status]
|
readableStatus = readableStatuses[slot.status]
|
||||||
empty = False
|
empty = False
|
||||||
msg += "* [{team}] <{status}> ~ {username}{mods}\n".format(
|
msg += "* [{team}] <{status}> ~ {username}{mods}\n".format(
|
||||||
team="red" if slot.team == 0 else "blue",
|
team="red" if slot.team == matchTeams.RED else "blue" if slot.team == matchTeams.BLUE else "!! no team !!",
|
||||||
status=readableStatus,
|
status=readableStatus,
|
||||||
username=glob.tokens.tokens[slot.user].username,
|
username=glob.tokens.tokens[slot.user].username,
|
||||||
mods=" (+ {})".format(generalUtils.readableMods(slot.mods))
|
mods=" (+ {})".format(generalUtils.readableMods(slot.mods)) if slot.mods > 0 else ""
|
||||||
)
|
)
|
||||||
if empty:
|
if empty:
|
||||||
msg += "\nNobody."
|
msg += "\nNobody."
|
||||||
|
|
|
@ -71,6 +71,7 @@ def handle(userToken, packetData):
|
||||||
|
|
||||||
oldBeatmapMD5 = match.beatmapMD5
|
oldBeatmapMD5 = match.beatmapMD5
|
||||||
oldMods = match.mods
|
oldMods = match.mods
|
||||||
|
oldMatchTeamType = match.matchTeamType
|
||||||
|
|
||||||
match.mods = packetData["mods"]
|
match.mods = packetData["mods"]
|
||||||
match.beatmapMD5 = packetData["beatmapMD5"]
|
match.beatmapMD5 = packetData["beatmapMD5"]
|
||||||
|
@ -80,31 +81,19 @@ def handle(userToken, packetData):
|
||||||
|
|
||||||
# Reset ready if needed
|
# Reset ready if needed
|
||||||
if oldMods != match.mods or oldBeatmapMD5 != match.beatmapMD5:
|
if oldMods != match.mods or oldBeatmapMD5 != match.beatmapMD5:
|
||||||
for i in range(0,16):
|
match.resetReady()
|
||||||
if match.slots[i].status == slotStatuses.READY:
|
|
||||||
match.slots[i].status = slotStatuses.NOT_READY
|
|
||||||
|
|
||||||
# Reset mods if needed
|
# Reset mods if needed
|
||||||
if match.matchModMode == matchModModes.NORMAL:
|
if match.matchModMode == matchModModes.NORMAL:
|
||||||
# Reset slot mods if not freeMods
|
# Reset slot mods if not freeMods
|
||||||
for i in range(0,16):
|
match.resetMods()
|
||||||
match.slots[i].mods = 0
|
|
||||||
else:
|
else:
|
||||||
# Reset match mods if freemod
|
# Reset match mods if freemod
|
||||||
match.mods = 0
|
match.mods = 0
|
||||||
|
|
||||||
# Set/reset teams
|
# Initialize teams if team type changed
|
||||||
if match.matchTeamType == matchTeamTypes.TEAM_VS or match.matchTeamType == matchTeamTypes.TAG_TEAM_VS:
|
if match.matchTeamType != oldMatchTeamType:
|
||||||
# Set teams
|
match.initializeTeams()
|
||||||
c=0
|
|
||||||
for i in range(0,16):
|
|
||||||
if match.slots[i].team == matchTeams.NO_TEAM:
|
|
||||||
match.slots[i].team = matchTeams.RED if c % 2 == 0 else matchTeams.BLUE
|
|
||||||
c+=1
|
|
||||||
else:
|
|
||||||
# Reset teams
|
|
||||||
for i in range(0,16):
|
|
||||||
match.slots[i].team = matchTeams.NO_TEAM
|
|
||||||
|
|
||||||
# Force no freemods if tag coop
|
# Force no freemods if tag coop
|
||||||
if match.matchTeamType == matchTeamTypes.TAG_COOP or match.matchTeamType == matchTeamTypes.TAG_TEAM_VS:
|
if match.matchTeamType == matchTeamTypes.TAG_COOP or match.matchTeamType == matchTeamTypes.TAG_TEAM_VS:
|
||||||
|
|
|
@ -26,7 +26,7 @@ def handle(userToken, packetData):
|
||||||
|
|
||||||
# Check password
|
# Check password
|
||||||
if match.matchPassword != "" and match.matchPassword != password:
|
if match.matchPassword != "" and match.matchPassword != password:
|
||||||
raise exceptions.matchWrongPasswordException
|
raise exceptions.matchWrongPasswordException()
|
||||||
|
|
||||||
# Password is correct, join match
|
# Password is correct, join match
|
||||||
userToken.joinMatch(matchID)
|
userToken.joinMatch(matchID)
|
||||||
|
|
|
@ -15,7 +15,7 @@ from objects import glob
|
||||||
class slot:
|
class slot:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.status = slotStatuses.FREE
|
self.status = slotStatuses.FREE
|
||||||
self.team = 0
|
self.team = matchTeams.NO_TEAM
|
||||||
self.userID = -1
|
self.userID = -1
|
||||||
self.user = None
|
self.user = None
|
||||||
self.mods = 0
|
self.mods = 0
|
||||||
|
@ -77,6 +77,7 @@ class match:
|
||||||
def getMatchData(self, censored = False):
|
def getMatchData(self, censored = False):
|
||||||
"""
|
"""
|
||||||
Return binary match data structure for packetHelper
|
Return binary match data structure for packetHelper
|
||||||
|
Return binary match data structure for packetHelper
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
@ -411,7 +412,7 @@ class match:
|
||||||
self.inProgress = False
|
self.inProgress = False
|
||||||
|
|
||||||
# Reset slots
|
# Reset slots
|
||||||
self.resetSlotsReady()
|
self.resetSlots()
|
||||||
|
|
||||||
# Send match update
|
# Send match update
|
||||||
self.sendUpdates()
|
self.sendUpdates()
|
||||||
|
@ -426,7 +427,7 @@ class match:
|
||||||
# Console output
|
# Console output
|
||||||
log.info("MPROOM{}: Match completed".format(self.matchID))
|
log.info("MPROOM{}: Match completed".format(self.matchID))
|
||||||
|
|
||||||
def resetSlotsReady(self):
|
def resetSlots(self):
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
if self.slots[i].user is not None and self.slots[i].status == slotStatuses.PLAYING:
|
if self.slots[i].user is not None and self.slots[i].status == slotStatuses.PLAYING:
|
||||||
self.slots[i].status = slotStatuses.NOT_READY
|
self.slots[i].status = slotStatuses.NOT_READY
|
||||||
|
@ -465,7 +466,10 @@ class match:
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
if self.slots[i].status == slotStatuses.FREE:
|
if self.slots[i].status == slotStatuses.FREE:
|
||||||
# Occupy slot
|
# Occupy slot
|
||||||
self.setSlot(i, slotStatuses.NOT_READY, 0, user.token, 0)
|
team = matchTeams.NO_TEAM
|
||||||
|
if self.matchTeamType == matchTeamTypes.TEAM_VS or self.matchTeamType == matchTeamTypes.TAG_TEAM_VS:
|
||||||
|
team = matchTeams.RED if i % 2 == 0 else matchTeams.BLUE
|
||||||
|
self.setSlot(i, slotStatuses.NOT_READY, team, user.token, 0)
|
||||||
|
|
||||||
# Send updated match data
|
# Send updated match data
|
||||||
self.sendUpdates()
|
self.sendUpdates()
|
||||||
|
@ -786,9 +790,28 @@ class match:
|
||||||
return
|
return
|
||||||
self.inProgress = False
|
self.inProgress = False
|
||||||
self.isStarting = False
|
self.isStarting = False
|
||||||
self.resetSlotsReady()
|
self.resetSlots()
|
||||||
self.sendUpdates()
|
self.sendUpdates()
|
||||||
glob.streams.broadcast(self.playingStreamName, serverPackets.matchAbort())
|
glob.streams.broadcast(self.playingStreamName, serverPackets.matchAbort())
|
||||||
glob.streams.dispose(self.playingStreamName)
|
glob.streams.dispose(self.playingStreamName)
|
||||||
glob.streams.remove(self.playingStreamName)
|
glob.streams.remove(self.playingStreamName)
|
||||||
log.info("MPROOM{}: Match aborted".format(self.matchID))
|
log.info("MPROOM{}: Match aborted".format(self.matchID))
|
||||||
|
|
||||||
|
def initializeTeams(self):
|
||||||
|
if self.matchTeamType == matchTeamTypes.TEAM_VS or self.matchTeamType == matchTeamTypes.TAG_TEAM_VS:
|
||||||
|
# Set teams
|
||||||
|
for i, _slot in enumerate(self.slots):
|
||||||
|
_slot.team = matchTeams.RED if i % 2 == 0 else matchTeams.BLUE
|
||||||
|
else:
|
||||||
|
# Reset teams
|
||||||
|
for _slot in self.slots:
|
||||||
|
_slot.team = matchTeams.NO_TEAM
|
||||||
|
|
||||||
|
def resetMods(self):
|
||||||
|
for _slot in self.slots:
|
||||||
|
_slot.mods = 0
|
||||||
|
|
||||||
|
def resetReady(self):
|
||||||
|
for _slot in self.slots:
|
||||||
|
if _slot.status == slotStatuses.READY:
|
||||||
|
_slot.status = slotStatuses.NOT_READY
|
Loading…
Reference in New Issue
Block a user