Ejemplo n.º 1
0
def updateCountry(userID, newScore, gameMode, mode='normal'):
    """
	Update gamemode's country leaderboard.
	Doesn't do anything if userID is banned/restricted.

	:param userID: user, country is determined by the user
	:param newScore: new score or pp
	:param gameMode: gameMode number
	:return:
	"""
    if userUtils.isAllowed(userID):
        COUNTRYLESS = 'xx'
        if features.GLOBAL_COUNTRY_RANKS == 'clan':
            country = userUtils.getUserCountryClan(userID)
        else:
            country = userUtils.getCountry(userID)
        if country is not None and len(
                country) > 0 and country.lower() != COUNTRYLESS:
            log.debug("Updating {} country leaderboard...".format(country))
            if features.RANKING_SCOREV2 and mode == 'alternative':
                k = "ripple:leaderboard_alt:{}:{}"
            elif mode == 'relax':
                k = "ripple:leaderboard_relax:{}:{}"
            else:
                k = "ripple:leaderboard:{}:{}"
            k = k.format(scoreUtils.readableGameMode(gameMode),
                         country.lower())
            glob.redis.zadd(k, str(userID), str(newScore))
    else:
        log.debug(
            "Clan leaderboard update for user {} skipped (not allowed)".format(
                userID))
Ejemplo n.º 2
0
def update(userID, newScore, gameMode):
	"""
	Update gamemode's leaderboard.
	Doesn't do anything if userID is banned/restricted.
	:param userID: user
	:param newScore: new score or pp
	:param gameMode: gameMode number
	"""
	if userUtils.isAllowed(userID):
		log.debug("Updating leaderboard...")
		glob.redis.zadd("ripple:leaderboard_auto:{}".format(scoreUtils.readableGameMode(gameMode)), str(userID), str(newScore))
	else:
		log.debug("Leaderboard update for user {} skipped (not allowed)".format(userID))
Ejemplo n.º 3
0
def updateCountry(userID, newScore, gameMode):
	"""
	Update gamemode's country leaderboard.
	Doesn't do anything if userID is banned/restricted.
	:param userID: user, country is determined by the user
	:param newScore: new score or pp
	:param gameMode: gameMode number
	:return:
	"""
	if userUtils.isAllowed(userID):
		country = userUtils.getCountry(userID)
		if country is not None and len(country) > 0 and country.lower() != "xx":
			log.debug("Updating {} country leaderboard...".format(country))
			k = "ripple:leaderboard_auto:{}:{}".format(scoreUtils.readableGameMode(gameMode), country.lower())
			glob.redis.zadd(k, str(userID), str(newScore))
	else:
		log.debug("Country leaderboard update for user {} skipped (not allowed)".format(userID))
Ejemplo n.º 4
0
def update(userID, newScore, gameMode, *, relax=False):
    """
	Update gamemode's leaderboard.
	Doesn't do anything if userID is banned/restricted.

	:param userID: user
	:param newScore: new score or pp
	:param gameMode: gameMode number
	:param relax: if True, update relax global leaderboard, otherwise update classic global leaderboard
	"""
    if userUtils.isAllowed(userID):
        log.debug("Updating leaderboard...")
        glob.redis.zadd(
            "ripple:leaderboard:{}{}".format(
                scoreUtils.readableGameMode(gameMode),
                ":relax" if relax else ""), str(userID), str(newScore))
    else:
        log.debug(
            "Leaderboard update for user {} skipped (not allowed)".format(
                userID))
Ejemplo n.º 5
0
def update(userID, newScore, gameMode, mode='normal'):
    """
	Update gamemode's leaderboard.
	Doesn't do anything if userID is banned/restricted.

	:param userID: user
	:param newScore: new score or pp
	:param gameMode: gameMode number
	"""
    if userUtils.isAllowed(userID):
        log.debug("Updating leaderboard...")
        if features.RANKING_SCOREV2 and mode == 'alternative':
            k = "ripple:leaderboard_alt:{}"
        elif mode == 'relax':
            k = "ripple:leaderboard_relax:{}"
        else:
            k = "ripple:leaderboard:{}"
        k = k.format(scoreUtils.readableGameMode(gameMode))
        glob.redis.zadd(k, str(userID), str(newScore))
    else:
        log.debug(
            "Leaderboard update for user {} skipped (not allowed)".format(
                userID))
Ejemplo n.º 6
0
    def registerHandler(self, command, arguments):
        """NICK and USER commands handler"""
        if command == "NICK":
            if len(arguments) < 1:
                self.reply("431 :No nickname given")
                return
            nick = arguments[0]

            # Make sure this is the first time we set our nickname
            if self.IRCUsername != "":
                self.reply("432 * %s :Erroneous nickname" % nick)
                return

            # Make sure the IRC token was correct:
            # (self.supposedUsername is already fixed for IRC)
            if nick.lower() != self.supposedUsername.lower():
                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:
                self.reply("433 * {} :Nickname is already in use".format(nick))
                return

            # Everything seems fine, set username (nickname)
            self.IRCUsername = nick  # username for IRC
            self.banchoUsername = chat.fixUsernameForBancho(
                self.IRCUsername)  # username for bancho

            # Disconnect other IRC clients from the same user
            for _, value in self.server.clients.items():
                if value.IRCUsername.lower() == self.IRCUsername.lower(
                ) and value != self:
                    value.disconnect(quitmsg="Connected from another client")
                    return
        elif command == "USER":
            # Ignore USER command, we use nickname only
            return
        elif command == "QUIT":
            # Disconnect if we have received a QUIT command
            self.disconnect()
            return
        else:
            # Ignore any other command while logging in
            return

        # If we now have a valid username, connect to bancho and send IRC welcome stuff
        if self.IRCUsername != "":
            # Bancho connection
            chat.IRCConnect(self.banchoUsername)

            # IRC reply
            self.replyCode(1, "Welcome to the Internet Relay Network")
            self.replyCode(
                2, "Your host is {}, running version pep.py-{}".format(
                    self.server.host, glob.VERSION))
            self.replyCode(3, "This server was created since the beginning")
            self.replyCode(
                4, "{} pep.py-{} o o".format(self.server.host, glob.VERSION))
            self.sendLusers()
            self.sendMotd()
            self.__handleCommand = self.mainHandler
Ejemplo n.º 7
0
def rxupdate(userID, newScore, gameMode):
	"""
	Update gamemode's leaderboard.
	Doesn't do anything if userID is banned/restricted.

	:param userID: user
	:param newScore: new score or pp
	:param gameMode: gameMode number
	"""
	mode = scoreUtils.readableGameMode(gameMode)

	newPlayer = False
	us = glob.db.fetch("SELECT * FROM relaxboard_{} WHERE user=%s LIMIT 1".format(mode), [userID])
	if us is None:
		newPlayer = True

	# Find player who is right below our score
	target = glob.db.fetch("SELECT * FROM relaxboard_{} WHERE v <= %s ORDER BY position ASC LIMIT 1".format(mode), [newScore])
	plus = 0
	if target is None:
		# Wow, this user completely sucks at this game.
		target = glob.db.fetch("SELECT * FROM relaxboard_{} ORDER BY position DESC LIMIT 1".format(mode))
		plus = 1

	# Set newT
	if target is None:
		# Okay, nevermind. It's not this user to suck. It's just that no-one has ever entered the leaderboard thus far.
		# So, the player is now #1. Yay!
		newT = 1
	else:
		# Otherwise, just give them the position of the target.
		newT = target["position"] + plus

	# Make some place for the new "place holder".
	if newPlayer:
		glob.db.execute("UPDATE relaxboard_{} SET position = position + 1 WHERE position >= %s ORDER BY position DESC".format(mode), [newT])
	else:
		glob.db.execute("DELETE FROM relaxboard_{} WHERE user = %s".format(mode), [userID])
		glob.db.execute("UPDATE relaxboard_{} SET position = position + 1 WHERE position < %s AND position >= %s ORDER BY position DESC".format(mode), [us["position"], newT])

	#if newT <= 1:
	#	log.info("{} is now #{} ({})".format(userID, newT, mode), "bunker")

	# Finally, insert the user back.
	glob.db.execute("INSERT INTO relaxboard_{} (position, user, v) VALUES (%s, %s, %s);".format(mode), [newT, userID, newScore])
	if gameMode == 0:
		newPlayer = False
		us = glob.db.fetch("SELECT * FROM users_relax_peak_rank WHERE userid = %s LIMIT 1", [userID])
		if us is None:
			newPlayer = True
		if newPlayer:
			glob.db.execute("INSERT INTO users_relax_peak_rank (userid, peak_rank) VALUES (%s, %s);", [userID, newT])
		else:
			if us["peak_rank"] > newT:
						glob.db.execute("UPDATE users_relax_peak_rank SET peak_rank = %s WHERE userid = %s", [newT,userID])
						
	
	if userUtils.isAllowed(userID):
		log.debug("Updating relaxboard...")
		glob.redis.zadd("ripple:relaxboard:{}".format(scoreUtils.readableGameMode(gameMode)), str(userID), str(newScore))
	else:
		log.debug("Relaxboard update for user {} skipped (not allowed)".format(userID))