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 multiplayer(fro, chan, message):
|
||||||
def mpMake():
|
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():
|
def mpClose():
|
||||||
myToken = glob.tokens.getTokenFromUsername(fro)
|
myToken = glob.tokens.getTokenFromUsername(fro)
|
||||||
|
@ -771,7 +782,8 @@ def multiplayer(fro, chan, message):
|
||||||
try:
|
try:
|
||||||
subcommands = {
|
subcommands = {
|
||||||
"make": mpMake,
|
"make": mpMake,
|
||||||
"clear": mpClose
|
"clear": mpClose,
|
||||||
|
"join": mpJoin
|
||||||
}
|
}
|
||||||
requestedSubcommand = message[0].lower().strip()
|
requestedSubcommand = message[0].lower().strip()
|
||||||
if requestedSubcommand not in subcommands:
|
if requestedSubcommand not in subcommands:
|
||||||
|
|
|
@ -30,8 +30,5 @@ def handle(userToken, packetData):
|
||||||
match.setHost(userID)
|
match.setHost(userID)
|
||||||
match.sendUpdates()
|
match.sendUpdates()
|
||||||
match.changePassword(packetData["matchPassword"])
|
match.changePassword(packetData["matchPassword"])
|
||||||
|
|
||||||
# Console output
|
|
||||||
log.info("MPROOM{}: Room created!".format(matchID))
|
|
||||||
except exceptions.matchCreateError:
|
except exceptions.matchCreateError:
|
||||||
log.error("Error while creating match!")
|
log.error("Error while creating match!")
|
||||||
|
|
|
@ -25,7 +25,7 @@ class slot:
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
|
||||||
class match:
|
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
|
Create a new match object
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class match:
|
||||||
self.matchModMode = matchModModes.NORMAL # default value
|
self.matchModMode = matchModModes.NORMAL # default value
|
||||||
self.seed = 0
|
self.seed = 0
|
||||||
self.matchDataCache = bytes()
|
self.matchDataCache = bytes()
|
||||||
|
self.isTourney = isTourney
|
||||||
|
|
||||||
# Create all slots and reset them
|
# Create all slots and reset them
|
||||||
self.slots = []
|
self.slots = []
|
||||||
|
@ -67,6 +68,7 @@ class match:
|
||||||
|
|
||||||
# Create #multiplayer channel
|
# Create #multiplayer channel
|
||||||
glob.channels.addTempChannel("#multi_{}".format(self.matchID))
|
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):
|
def getMatchData(self, censored = False):
|
||||||
"""
|
"""
|
||||||
|
@ -457,7 +459,7 @@ class match:
|
||||||
self.setSlot(slotID, slotStatuses.FREE, 0, None, 0)
|
self.setSlot(slotID, slotStatuses.FREE, 0, None, 0)
|
||||||
|
|
||||||
# Check if everyone left
|
# Check if everyone left
|
||||||
if self.countUsers() == 0 and disposeMatch:
|
if self.countUsers() == 0 and disposeMatch and not self.isTourney:
|
||||||
# Dispose match
|
# Dispose match
|
||||||
glob.matches.disposeMatch(self.matchID)
|
glob.matches.disposeMatch(self.matchID)
|
||||||
log.info("MPROOM{}: Room disposed because all users left".format(self.matchID))
|
log.info("MPROOM{}: Room disposed because all users left".format(self.matchID))
|
||||||
|
|
|
@ -9,7 +9,7 @@ class matchList:
|
||||||
self.matches = {}
|
self.matches = {}
|
||||||
self.lastID = 1
|
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
|
Add a new match to matches list
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class matchList:
|
||||||
# Add a new match to matches list and create its stream
|
# Add a new match to matches list and create its stream
|
||||||
matchID = self.lastID
|
matchID = self.lastID
|
||||||
self.lastID+=1
|
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
|
return matchID
|
||||||
|
|
||||||
def disposeMatch(self, matchID):
|
def disposeMatch(self, matchID):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user