pep.py/objects/matchList.py

46 lines
1.4 KiB
Python
Raw Normal View History

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
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
matchName -- match name, string
matchPassword -- match md5 password. Leave empty for no password
beatmapID -- beatmap ID
beatmapName -- beatmap name, string
beatmapMD5 -- beatmap md5 hash, string
gameMode -- game mode ID. See gameModes.py
hostUserID -- user id of who created the match
2016-04-19 17:40:59 +00:00
return -- match ID
"""
# 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
self.matches[matchID] = match.match(matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID)
2016-04-19 17:40:59 +00:00
return matchID
def disposeMatch(self, matchID):
2016-04-19 17:40:59 +00:00
"""
Destroy match object with id = matchID
2016-04-19 17:40:59 +00:00
matchID -- ID of match to dispose
2016-04-19 17:40:59 +00:00
"""
# Make sure the match exists
if matchID not in self.matches:
2016-04-19 17:40:59 +00:00
return
# Remove match object and stream
match = self.matches.pop(matchID)
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
glob.streams.broadcast("lobby", serverPackets.disposeMatch(matchID))