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 10:41:19 +00:00
|
|
|
class matchList():
|
2016-04-19 17:40:59 +00:00
|
|
|
matches = {}
|
|
|
|
usersInLobby = []
|
|
|
|
lastID = 1
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Initialize a matchList object"""
|
|
|
|
self.matches = {}
|
|
|
|
self.usersInLobby = []
|
|
|
|
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-08-17 14:41:05 +00:00
|
|
|
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
|
|
|
|
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-08-17 14:41:05 +00:00
|
|
|
def lobbyUserJoin(self, userID):
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Add userID to users in lobby
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
userID -- user who joined mp lobby
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
# Make sure the user is not already in mp lobby
|
2016-08-17 14:41:05 +00:00
|
|
|
if userID not in self.usersInLobby:
|
2016-04-19 17:40:59 +00:00
|
|
|
# We don't need to join #lobby, client will automatically send a packet for it
|
2016-08-17 14:41:05 +00:00
|
|
|
self.usersInLobby.append(userID)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
def lobbyUserPart(self, userID):
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Remove userID from users in lobby
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
userID -- user who left mp lobby
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
# Make sure the user is in mp lobby
|
2016-08-17 14:41:05 +00:00
|
|
|
if userID in self.usersInLobby:
|
2016-04-19 17:40:59 +00:00
|
|
|
# Part lobby and #lobby channel
|
2016-08-17 14:41:05 +00:00
|
|
|
self.usersInLobby.remove(userID)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
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-09-02 10:41:19 +00:00
|
|
|
matchID -- ID of match to dispose
|
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
|
|
|
|
|
|
|
|
# Remove match object
|
2016-09-02 10:41:19 +00:00
|
|
|
self.matches.pop(matchID)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Send match dispose packet to everyone in lobby
|
|
|
|
for i in self.usersInLobby:
|
|
|
|
token = glob.tokens.getTokenFromUserID(i)
|
|
|
|
if token != None:
|
2016-09-02 10:41:19 +00:00
|
|
|
token.enqueue(serverPackets.disposeMatch(matchID))
|