2016-05-18 17:12:46 +00:00
|
|
|
from objects import match
|
|
|
|
from objects import glob
|
|
|
|
from constants import serverPackets
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2016-09-02 15:45:10 +00:00
|
|
|
class matchList:
|
2016-04-19 17:40:59 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Initialize a matchList object"""
|
|
|
|
self.matches = {}
|
|
|
|
self.lastID = 1
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
def createMatch(self, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID):
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Add a new match to matches list
|
|
|
|
|
2016-11-17 18:13:06 +00:00
|
|
|
:param matchName: match name, string
|
|
|
|
:param matchPassword: match md5 password. Leave empty for no password
|
|
|
|
:param beatmapID: beatmap ID
|
|
|
|
:param beatmapName: beatmap name, string
|
|
|
|
:param beatmapMD5: beatmap md5 hash, string
|
|
|
|
:param gameMode: game mode ID. See gameModes.py
|
|
|
|
:param hostUserID: user id of who created the match
|
|
|
|
:return: match ID
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
2016-10-04 21:43:02 +00:00
|
|
|
# Add a new match to matches list and create its stream
|
2016-04-19 17:40:59 +00:00
|
|
|
matchID = self.lastID
|
|
|
|
self.lastID+=1
|
2016-08-17 14:41:05 +00:00
|
|
|
self.matches[matchID] = match.match(matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID)
|
2016-04-19 17:40:59 +00:00
|
|
|
return matchID
|
|
|
|
|
2016-09-02 10:41:19 +00:00
|
|
|
def disposeMatch(self, matchID):
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
2016-09-02 10:41:19 +00:00
|
|
|
Destroy match object with id = matchID
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2016-11-17 18:13:06 +00:00
|
|
|
:param matchID: ID of match to dispose
|
|
|
|
:return:
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
# Make sure the match exists
|
2016-09-02 10:41:19 +00:00
|
|
|
if matchID not in self.matches:
|
2016-04-19 17:40:59 +00:00
|
|
|
return
|
|
|
|
|
2016-10-04 21:43:02 +00:00
|
|
|
# Remove match object and stream
|
2016-12-26 09:33:05 +00:00
|
|
|
_match = self.matches.pop(matchID)
|
|
|
|
glob.streams.dispose(_match.streamName)
|
|
|
|
glob.streams.dispose(_match.playingStreamName)
|
|
|
|
glob.streams.remove(_match.streamName)
|
|
|
|
glob.streams.remove(_match.playingStreamName)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Send match dispose packet to everyone in lobby
|
2016-10-04 20:10:07 +00:00
|
|
|
glob.streams.broadcast("lobby", serverPackets.disposeMatch(matchID))
|