diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 85c0834..7cad3a8 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -84,9 +84,8 @@ def alert(fro, chan, message): return False def alertUser(fro, chan, message): - target = message[0].replace("_", " ") - - targetToken = glob.tokens.getTokenFromUsername(target) + target = message[0].lower() + targetToken = glob.tokens.getTokenFromUsername(target, safe=True) if targetToken is not None: targetToken.enqueue(serverPackets.notification(' '.join(message[1:]))) return False @@ -127,12 +126,12 @@ def kickAll(fro, chan, message): def kick(fro, chan, message): # Get parameters - target = message[0].lower().replace("_", " ") + target = message[0].lower() if target == "fokabot": return "Nope." # Get target token and make sure is connected - tokens = glob.tokens.getTokenFromUsername(target, _all=True) + tokens = glob.tokens.getTokenFromUsername(target, safe=True, _all=True) if len(tokens) == 0: return "{} is not online".format(target) @@ -155,13 +154,13 @@ def fokabotReconnect(fro, chan, message): def silence(fro, chan, message): for i in message: i = i.lower() - target = message[0].replace("_", " ") + target = message[0] amount = message[1] unit = message[2] reason = ' '.join(message[3:]) # Get target user ID - targetUserID = userUtils.getID(target) + targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) # Make sure the user exists @@ -201,10 +200,10 @@ def removeSilence(fro, chan, message): # Get parameters for i in message: i = i.lower() - target = message[0].replace("_", " ") + target = message[0] # Make sure the user exists - targetUserID = userUtils.getID(target) + targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) @@ -224,10 +223,10 @@ def ban(fro, chan, message): # Get parameters for i in message: i = i.lower() - target = message[0].replace("_", " ") + target = message[0] # Make sure the user exists - targetUserID = userUtils.getID(target) + targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) @@ -247,10 +246,10 @@ def unban(fro, chan, message): # Get parameters for i in message: i = i.lower() - target = message[0].replace("_", " ") + target = message[0] # Make sure the user exists - targetUserID = userUtils.getID(target) + targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) @@ -265,10 +264,10 @@ def restrict(fro, chan, message): # Get parameters for i in message: i = i.lower() - target = message[0].replace("_", " ") + target = message[0] # Make sure the user exists - targetUserID = userUtils.getID(target) + targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) @@ -288,10 +287,10 @@ def unrestrict(fro, chan, message): # Get parameters for i in message: i = i.lower() - target = message[0].replace("_", " ") + target = message[0] # Make sure the user exists - targetUserID = userUtils.getID(target) + targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) diff --git a/constants/serverPackets.py b/constants/serverPackets.py index 4756e8c..101d0cd 100644 --- a/constants/serverPackets.py +++ b/constants/serverPackets.py @@ -202,17 +202,18 @@ def createMatch(matchID): # Get match binary data and build packet match = glob.matches.matches[matchID] - return packetHelper.buildPacket(packetIDs.server_newMatch, match.getMatchData()) + matchData = match.getMatchData(censored=True) + return packetHelper.buildPacket(packetIDs.server_newMatch, matchData) # TODO: Add match object argument to save some CPU -def updateMatch(matchID): +def updateMatch(matchID, censored = False): # Make sure the match exists if matchID not in glob.matches.matches: return bytes() # Get match binary data and build packet match = glob.matches.matches[matchID] - return packetHelper.buildPacket(packetIDs.server_updateMatch, match.getMatchData()) + return packetHelper.buildPacket(packetIDs.server_updateMatch, match.getMatchData(censored=censored)) def matchStart(matchID): # Make sure the match exists @@ -269,4 +270,4 @@ def notification(message): return packetHelper.buildPacket(packetIDs.server_notification, [[message, dataTypes.STRING]]) def banchoRestart(msUntilReconnection): - return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.UINT32]]) \ No newline at end of file + return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.UINT32]]) diff --git a/irc/ircserver.py b/irc/ircserver.py index 40a27e6..863a4d3 100644 --- a/irc/ircserver.py +++ b/irc/ircserver.py @@ -17,6 +17,7 @@ import traceback import raven from common.log import logUtils as log +from common.ripple import userUtils from helpers import chatHelper as chat from objects import glob @@ -44,6 +45,7 @@ class Client: self.IRCUsername = "" self.banchoUsername = "" self.supposedUsername = "" + self.supposedUserID = 0 self.joinedChannels = [] def messageChannel(self, channel, command, message, includeSelf=False): @@ -280,9 +282,10 @@ class Client: m = hashlib.md5() m.update(arguments[0].encode("utf-8")) tokenHash = m.hexdigest() - supposedUsername = glob.db.fetch("SELECT users.username FROM users LEFT JOIN irc_tokens ON users.id = irc_tokens.userid WHERE irc_tokens.token = %s LIMIT 1", [tokenHash]) - if supposedUsername: - self.supposedUsername = chat.fixUsernameForIRC(supposedUsername["username"]) + supposedUser = glob.db.fetch("SELECT users.username, users.id FROM users LEFT JOIN irc_tokens ON users.id = irc_tokens.userid WHERE irc_tokens.token = %s LIMIT 1", [tokenHash]) + if supposedUser: + self.supposedUsername = chat.fixUsernameForIRC(supposedUser["username"]) + self.supposedUserID = supposedUser["id"] self.__handleCommand = self.registerHandler else: # Wrong IRC Token @@ -310,6 +313,11 @@ class Client: self.reply("464 :Password incorrect") return + # Make sure that the user is not banned/restricted: + if not userUtils.isAllowed(self.supposedUserID): + self.reply("465 :You're banned") + return + # Make sure we are not connected to Bancho token = glob.tokens.getTokenFromUsername(chat.fixUsernameForBancho(nick), True) if token is not None: diff --git a/objects/match.py b/objects/match.py index 796941e..f51eeeb 100644 --- a/objects/match.py +++ b/objects/match.py @@ -66,7 +66,7 @@ class match: # Create #multiplayer channel glob.channels.addTempChannel("#multi_{}".format(self.matchID)) - def getMatchData(self): + def getMatchData(self, censored = False): """ Return binary match data structure for packetHelper @@ -80,12 +80,18 @@ class match: [int(safeMatch.inProgress), dataTypes.BYTE], [0, dataTypes.BYTE], [safeMatch.mods, dataTypes.UINT32], - [safeMatch.matchName, dataTypes.STRING], - [safeMatch.matchPassword, dataTypes.STRING], + [safeMatch.matchName, dataTypes.STRING] + ] + if censored and safeMatch.matchPassword: + struct.append(["redacted", dataTypes.STRING]) + else: + struct.append([safeMatch.matchPassword, dataTypes.STRING]) + + struct.extend([ [safeMatch.beatmapName, dataTypes.STRING], [safeMatch.beatmapID, dataTypes.UINT32], - [safeMatch.beatmapMD5, dataTypes.STRING], - ] + [safeMatch.beatmapMD5, dataTypes.STRING] + ]) # Slots status IDs, always 16 elements for i in range(0,16): @@ -611,9 +617,11 @@ class match: :return: """ self.matchDataCache = serverPackets.updateMatch(self.matchID) + censoredDataCache = serverPackets.updateMatch(self.matchID, censored=True) if self.matchDataCache is not None: glob.streams.broadcast(self.streamName, self.matchDataCache) - glob.streams.broadcast("lobby", self.matchDataCache) + if censoredDataCache is not None: + glob.streams.broadcast("lobby", censoredDataCache) else: log.error("MPROOM{}: Can't send match update packet, match data is None!!!".format(self.matchID)) @@ -671,4 +679,4 @@ class match: glob.streams.broadcast(self.playingStreamName, serverPackets.matchStart(self.matchID)) # Send updates - self.sendUpdates() \ No newline at end of file + self.sendUpdates()