Add !mp make and !mp join
This commit is contained in:
parent
3373bc9581
commit
af554c94d5
|
@ -759,7 +759,18 @@ def report(fro, chan, message):
|
|||
|
||||
def multiplayer(fro, chan, message):
|
||||
def mpMake():
|
||||
return "Not implemented yet."
|
||||
if len(message) < 2:
|
||||
raise exceptions.invalidArgumentsException("Wrong syntax: !mp make <name>")
|
||||
matchID = glob.matches.createMatch(" ".join(message[1:]), generalUtils.stringMd5(generalUtils.randomString(32)), 0, "Tournament", "", 0, -1, isTourney=True)
|
||||
return "Tourney match #{} created!".format(matchID)
|
||||
|
||||
def mpJoin():
|
||||
if len(message) < 2 or not message[1].isdigit():
|
||||
return exceptions.invalidArgumentsException("Wrong syntax: !mp join <id>")
|
||||
matchID = int(message[1])
|
||||
userToken = glob.tokens.getTokenFromUsername(fro, ignoreIRC=True)
|
||||
userToken.joinMatch(matchID)
|
||||
return "Joined match #{}!".format(matchID)
|
||||
|
||||
def mpClose():
|
||||
myToken = glob.tokens.getTokenFromUsername(fro)
|
||||
|
@ -771,7 +782,8 @@ def multiplayer(fro, chan, message):
|
|||
try:
|
||||
subcommands = {
|
||||
"make": mpMake,
|
||||
"clear": mpClose
|
||||
"clear": mpClose,
|
||||
"join": mpJoin
|
||||
}
|
||||
requestedSubcommand = message[0].lower().strip()
|
||||
if requestedSubcommand not in subcommands:
|
||||
|
|
|
@ -30,8 +30,5 @@ def handle(userToken, packetData):
|
|||
match.setHost(userID)
|
||||
match.sendUpdates()
|
||||
match.changePassword(packetData["matchPassword"])
|
||||
|
||||
# Console output
|
||||
log.info("MPROOM{}: Room created!".format(matchID))
|
||||
except exceptions.matchCreateError:
|
||||
log.error("Error while creating match!")
|
||||
|
|
|
@ -25,7 +25,7 @@ class slot:
|
|||
self.score = 0
|
||||
|
||||
class match:
|
||||
def __init__(self, matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID):
|
||||
def __init__(self, matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID, isTourney=False):
|
||||
"""
|
||||
Create a new match object
|
||||
|
||||
|
@ -55,6 +55,7 @@ class match:
|
|||
self.matchModMode = matchModModes.NORMAL # default value
|
||||
self.seed = 0
|
||||
self.matchDataCache = bytes()
|
||||
self.isTourney = isTourney
|
||||
|
||||
# Create all slots and reset them
|
||||
self.slots = []
|
||||
|
@ -67,6 +68,7 @@ class match:
|
|||
|
||||
# Create #multiplayer channel
|
||||
glob.channels.addTempChannel("#multi_{}".format(self.matchID))
|
||||
log.info("MPROOM{}: {} match created!".format(self.matchID, "Tourney" if self.isTourney else "Normal"))
|
||||
|
||||
def getMatchData(self, censored = False):
|
||||
"""
|
||||
|
@ -457,7 +459,7 @@ class match:
|
|||
self.setSlot(slotID, slotStatuses.FREE, 0, None, 0)
|
||||
|
||||
# Check if everyone left
|
||||
if self.countUsers() == 0 and disposeMatch:
|
||||
if self.countUsers() == 0 and disposeMatch and not self.isTourney:
|
||||
# Dispose match
|
||||
glob.matches.disposeMatch(self.matchID)
|
||||
log.info("MPROOM{}: Room disposed because all users left".format(self.matchID))
|
||||
|
|
|
@ -9,7 +9,7 @@ class matchList:
|
|||
self.matches = {}
|
||||
self.lastID = 1
|
||||
|
||||
def createMatch(self, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID):
|
||||
def createMatch(self, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID, isTourney=False):
|
||||
"""
|
||||
Add a new match to matches list
|
||||
|
||||
|
@ -25,7 +25,7 @@ class matchList:
|
|||
# Add a new match to matches list and create its stream
|
||||
matchID = self.lastID
|
||||
self.lastID+=1
|
||||
self.matches[matchID] = match.match(matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID)
|
||||
self.matches[matchID] = match.match(matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID, isTourney)
|
||||
return matchID
|
||||
|
||||
def disposeMatch(self, matchID):
|
||||
|
|
Loading…
Reference in New Issue
Block a user