Merge branch 'master' of git.zxq.co:ripple/pep.py

This commit is contained in:
Giuseppe Guerra 2017-07-28 22:36:19 +02:00
commit eab8bee828
4 changed files with 47 additions and 31 deletions

View File

@ -84,9 +84,8 @@ def alert(fro, chan, message):
return False return False
def alertUser(fro, chan, message): def alertUser(fro, chan, message):
target = message[0].replace("_", " ") target = message[0].lower()
targetToken = glob.tokens.getTokenFromUsername(target, safe=True)
targetToken = glob.tokens.getTokenFromUsername(target)
if targetToken is not None: if targetToken is not None:
targetToken.enqueue(serverPackets.notification(' '.join(message[1:]))) targetToken.enqueue(serverPackets.notification(' '.join(message[1:])))
return False return False
@ -127,12 +126,12 @@ def kickAll(fro, chan, message):
def kick(fro, chan, message): def kick(fro, chan, message):
# Get parameters # Get parameters
target = message[0].lower().replace("_", " ") target = message[0].lower()
if target == "fokabot": if target == "fokabot":
return "Nope." return "Nope."
# Get target token and make sure is connected # 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: if len(tokens) == 0:
return "{} is not online".format(target) return "{} is not online".format(target)
@ -155,13 +154,13 @@ def fokabotReconnect(fro, chan, message):
def silence(fro, chan, message): def silence(fro, chan, message):
for i in message: for i in message:
i = i.lower() i = i.lower()
target = message[0].replace("_", " ") target = message[0]
amount = message[1] amount = message[1]
unit = message[2] unit = message[2]
reason = ' '.join(message[3:]) reason = ' '.join(message[3:])
# Get target user ID # Get target user ID
targetUserID = userUtils.getID(target) targetUserID = userUtils.getIDSafe(target)
userID = userUtils.getID(fro) userID = userUtils.getID(fro)
# Make sure the user exists # Make sure the user exists
@ -201,10 +200,10 @@ def removeSilence(fro, chan, message):
# Get parameters # Get parameters
for i in message: for i in message:
i = i.lower() i = i.lower()
target = message[0].replace("_", " ") target = message[0]
# Make sure the user exists # Make sure the user exists
targetUserID = userUtils.getID(target) targetUserID = userUtils.getIDSafe(target)
userID = userUtils.getID(fro) userID = userUtils.getID(fro)
if not targetUserID: if not targetUserID:
return "{}: user not found".format(target) return "{}: user not found".format(target)
@ -224,10 +223,10 @@ def ban(fro, chan, message):
# Get parameters # Get parameters
for i in message: for i in message:
i = i.lower() i = i.lower()
target = message[0].replace("_", " ") target = message[0]
# Make sure the user exists # Make sure the user exists
targetUserID = userUtils.getID(target) targetUserID = userUtils.getIDSafe(target)
userID = userUtils.getID(fro) userID = userUtils.getID(fro)
if not targetUserID: if not targetUserID:
return "{}: user not found".format(target) return "{}: user not found".format(target)
@ -247,10 +246,10 @@ def unban(fro, chan, message):
# Get parameters # Get parameters
for i in message: for i in message:
i = i.lower() i = i.lower()
target = message[0].replace("_", " ") target = message[0]
# Make sure the user exists # Make sure the user exists
targetUserID = userUtils.getID(target) targetUserID = userUtils.getIDSafe(target)
userID = userUtils.getID(fro) userID = userUtils.getID(fro)
if not targetUserID: if not targetUserID:
return "{}: user not found".format(target) return "{}: user not found".format(target)
@ -265,10 +264,10 @@ def restrict(fro, chan, message):
# Get parameters # Get parameters
for i in message: for i in message:
i = i.lower() i = i.lower()
target = message[0].replace("_", " ") target = message[0]
# Make sure the user exists # Make sure the user exists
targetUserID = userUtils.getID(target) targetUserID = userUtils.getIDSafe(target)
userID = userUtils.getID(fro) userID = userUtils.getID(fro)
if not targetUserID: if not targetUserID:
return "{}: user not found".format(target) return "{}: user not found".format(target)
@ -288,10 +287,10 @@ def unrestrict(fro, chan, message):
# Get parameters # Get parameters
for i in message: for i in message:
i = i.lower() i = i.lower()
target = message[0].replace("_", " ") target = message[0]
# Make sure the user exists # Make sure the user exists
targetUserID = userUtils.getID(target) targetUserID = userUtils.getIDSafe(target)
userID = userUtils.getID(fro) userID = userUtils.getID(fro)
if not targetUserID: if not targetUserID:
return "{}: user not found".format(target) return "{}: user not found".format(target)

View File

@ -202,17 +202,18 @@ def createMatch(matchID):
# Get match binary data and build packet # Get match binary data and build packet
match = glob.matches.matches[matchID] 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 # TODO: Add match object argument to save some CPU
def updateMatch(matchID): def updateMatch(matchID, censored = False):
# Make sure the match exists # Make sure the match exists
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return bytes() return bytes()
# Get match binary data and build packet # Get match binary data and build packet
match = glob.matches.matches[matchID] 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): def matchStart(matchID):
# Make sure the match exists # Make sure the match exists

View File

@ -17,6 +17,7 @@ import traceback
import raven import raven
from common.log import logUtils as log from common.log import logUtils as log
from common.ripple import userUtils
from helpers import chatHelper as chat from helpers import chatHelper as chat
from objects import glob from objects import glob
@ -44,6 +45,7 @@ class Client:
self.IRCUsername = "" self.IRCUsername = ""
self.banchoUsername = "" self.banchoUsername = ""
self.supposedUsername = "" self.supposedUsername = ""
self.supposedUserID = 0
self.joinedChannels = [] self.joinedChannels = []
def messageChannel(self, channel, command, message, includeSelf=False): def messageChannel(self, channel, command, message, includeSelf=False):
@ -280,9 +282,10 @@ class Client:
m = hashlib.md5() m = hashlib.md5()
m.update(arguments[0].encode("utf-8")) m.update(arguments[0].encode("utf-8"))
tokenHash = m.hexdigest() 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]) 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 supposedUsername: if supposedUser:
self.supposedUsername = chat.fixUsernameForIRC(supposedUsername["username"]) self.supposedUsername = chat.fixUsernameForIRC(supposedUser["username"])
self.supposedUserID = supposedUser["id"]
self.__handleCommand = self.registerHandler self.__handleCommand = self.registerHandler
else: else:
# Wrong IRC Token # Wrong IRC Token
@ -310,6 +313,11 @@ class Client:
self.reply("464 :Password incorrect") self.reply("464 :Password incorrect")
return 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 # Make sure we are not connected to Bancho
token = glob.tokens.getTokenFromUsername(chat.fixUsernameForBancho(nick), True) token = glob.tokens.getTokenFromUsername(chat.fixUsernameForBancho(nick), True)
if token is not None: if token is not None:

View File

@ -66,7 +66,7 @@ class match:
# Create #multiplayer channel # Create #multiplayer channel
glob.channels.addTempChannel("#multi_{}".format(self.matchID)) glob.channels.addTempChannel("#multi_{}".format(self.matchID))
def getMatchData(self): def getMatchData(self, censored = False):
""" """
Return binary match data structure for packetHelper Return binary match data structure for packetHelper
@ -80,12 +80,18 @@ class match:
[int(safeMatch.inProgress), dataTypes.BYTE], [int(safeMatch.inProgress), dataTypes.BYTE],
[0, dataTypes.BYTE], [0, dataTypes.BYTE],
[safeMatch.mods, dataTypes.UINT32], [safeMatch.mods, dataTypes.UINT32],
[safeMatch.matchName, dataTypes.STRING], [safeMatch.matchName, dataTypes.STRING]
[safeMatch.matchPassword, 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.beatmapName, dataTypes.STRING],
[safeMatch.beatmapID, dataTypes.UINT32], [safeMatch.beatmapID, dataTypes.UINT32],
[safeMatch.beatmapMD5, dataTypes.STRING], [safeMatch.beatmapMD5, dataTypes.STRING]
] ])
# Slots status IDs, always 16 elements # Slots status IDs, always 16 elements
for i in range(0,16): for i in range(0,16):
@ -611,9 +617,11 @@ class match:
:return: :return:
""" """
self.matchDataCache = serverPackets.updateMatch(self.matchID) self.matchDataCache = serverPackets.updateMatch(self.matchID)
censoredDataCache = serverPackets.updateMatch(self.matchID, censored=True)
if self.matchDataCache is not None: if self.matchDataCache is not None:
glob.streams.broadcast(self.streamName, self.matchDataCache) glob.streams.broadcast(self.streamName, self.matchDataCache)
glob.streams.broadcast("lobby", self.matchDataCache) if censoredDataCache is not None:
glob.streams.broadcast("lobby", censoredDataCache)
else: else:
log.error("MPROOM{}: Can't send match update packet, match data is None!!!".format(self.matchID)) log.error("MPROOM{}: Can't send match update packet, match data is None!!!".format(self.matchID))