Esempio n. 1
0
def handle(userToken, packetData):
    # Get usertoken data
    userID = userToken.userID
    username = userToken.username

    # Make sure we are not banned
    #if userUtils.isBanned(userID):
    #	userToken.enqueue(serverPackets.loginBanned())
    #	return

    # Send restricted message if needed
    #if userToken.restricted:
    #	userToken.checkRestricted(True)

    # Change action packet
    packetData = clientPackets.userActionChange(packetData)

    # If we are not in spectate status but we're spectating someone, stop spectating
    '''
if userToken.spectating != 0 and userToken.actionID != actions.WATCHING and userToken.actionID != actions.IDLE and userToken.actionID != actions.AFK:
	userToken.stopSpectating()

# If we are not in multiplayer but we are in a match, part match
if userToken.matchID != -1 and userToken.actionID != actions.MULTIPLAYING and userToken.actionID != actions.MULTIPLAYER and userToken.actionID != actions.AFK:
	userToken.partMatch()
		'''

    # Update cached stats if our pp changed if we've just submitted a score or we've changed gameMode
    #if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userUtils.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):

    # Update cached stats if we've changed gamemode
    if userToken.gameMode != packetData["gameMode"]:
        userToken.gameMode = packetData["gameMode"]
        userToken.updateCachedStats()

    # Always update action id, text, md5 and beatmapID
    userToken.actionID = packetData["actionID"]
    userToken.actionText = packetData["actionText"]
    userToken.actionMd5 = packetData["actionMd5"]
    userToken.actionMods = packetData["actionMods"]
    userToken.beatmapID = packetData["beatmapID"]

    # Enqueue our new user panel and stats to us and our spectators
    recipients = [userToken]
    if len(userToken.spectators) > 0:
        for i in userToken.spectators:
            if i in glob.tokens.tokens:
                recipients.append(glob.tokens.tokens[i])

    for i in recipients:
        if i is not None:
            # Force our own packet
            force = True if i == userToken else False
            i.enqueue(serverPackets.userPanel(userID, force))
            i.enqueue(serverPackets.userStats(userID, force))

    # Console output
    log.info("{} changed action: {} [{}][{}][{}]".format(
        username, str(userToken.actionID), userToken.actionText,
        userToken.actionMd5, userToken.beatmapID))
Esempio n. 2
0
def handle(userToken, packetData):
    def r(bid, refresh=False):
        url = "{}/v1/cacheBeatmap?bid={}&refresh={}".format(
            glob.conf.config["server"]["letsapiurl"].rstrip("/"), bid,
            int(bool(refresh)))
        requests.post(url, timeout=40)

    # Get usertoken data
    userID = userToken.userID
    username = userToken.username

    # Make sure we are not banned
    #if userUtils.isBanned(userID):
    #	userToken.enqueue(serverPackets.loginBanned())
    #	return

    # Send restricted message if needed
    #if userToken.restricted:
    #	userToken.checkRestricted(True)

    # Change action packet
    packetData = clientPackets.userActionChange(packetData)

    # If we are not in spectate status but we're spectating someone, stop spectating
    '''
	if userToken.spectating != 0 and userToken.actionID != actions.WATCHING and userToken.actionID != actions.IDLE and userToken.actionID != actions.AFK:
		userToken.stopSpectating()

	# If we are not in multiplayer but we are in a match, part match
	if userToken.matchID != -1 and userToken.actionID != actions.MULTIPLAYING and userToken.actionID != actions.MULTIPLAYER and userToken.actionID != actions.AFK:
		userToken.partMatch()
	'''

    # Update cached stats if our pp changed if we've just submitted a score or we've changed gameMode
    #if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userUtils.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):

    # Update cached stats if we've changed gamemode
    if userToken.gameMode != packetData["gameMode"]:
        userToken.gameMode = packetData["gameMode"]
        userToken.updateCachedStats()

    # Always update action id, text, md5 and beatmapID
    userToken.actionID = packetData["actionID"]
    #userToken.actionID = packetData["actionText"]
    userToken.actionMd5 = packetData["actionMd5"]
    userToken.actionMods = packetData["actionMods"]
    userToken.beatmapID = packetData["beatmapID"]

    for sys_filter in glob.db.fetchAll(
            "select * from bancho_filter_system where active = 1 and find_in_set('status', `type`)"
    ):
        packetData['actionText'] = reigexp.replace(sys_filter['match_type'],
                                                   sys_filter['from_text'],
                                                   packetData['actionText'],
                                                   sys_filter['replace_type'],
                                                   sys_filter['to_text'])

    if packetData["actionMods"] & mods.V2 and eligible.scoreV2(userID):
        userToken.specialMode = 2
        if userToken.actionID in (0, 1, 14):
            UserText = packetData["actionText"] + "on V2"
        else:
            UserText = packetData["actionText"] + " on V2"
    elif packetData[
            "actionMods"] & mods.RL and not packetData["actionMods"] & mods.V2:
        userToken.specialMode = 1
        if userToken.actionID in (0, 1, 14):
            UserText = packetData["actionText"] + "on Relax"
        else:
            UserText = packetData["actionText"] + " on Relax"
    else:
        userToken.specialMode = 0
        UserText = packetData["actionText"]
    userToken.actionText = UserText

    userToken.updateCachedStats()
    if str(userToken.beatmapID).isdigit() and userToken.beatmapID > 0:
        r(userToken.beatmapID, False)
    glob.db.execute("UPDATE user_config SET current_status = %s WHERE id = %s",
                    [UserText, userID])

    # Enqueue our new user panel and stats to us and our spectators
    recipients = [userToken]
    for i in userToken.spectators:
        if i in glob.tokens.tokens:
            recipients.append(glob.tokens.tokens[i])

    for i in recipients:
        if i is not None:
            # Force our own packet
            force = True if i == userToken else False
            i.enqueue(serverPackets.userPanel(userID, force))
            i.enqueue(serverPackets.userStats(userID, force))

    # Console output
    log.info("{} changed action: {} [{}][{}][{}]".format(
        username, str(userToken.actionID), userToken.actionText,
        userToken.actionMd5, userToken.beatmapID))
Esempio n. 3
0
def handle(userToken, packetData):
    # Get usertoken data
    userID = userToken.userID
    username = userToken.username

    # Make sure we are not banned
    #if userUtils.isBanned(userID):
    #    userToken.enqueue(serverPackets.loginBanned())
    #    return

    # Send restricted message if needed
    #if userToken.restricted:
    #    userToken.checkRestricted(True)

    # Change action packet
    packetData = clientPackets.userActionChange(packetData)

    # If we are not in spectate status but we're spectating someone, stop spectating
    '''
if userToken.spectating != 0 and userToken.actionID != actions.WATCHING and userToken.actionID != actions.IDLE and userToken.actionID != actions.AFK:
    userToken.stopSpectating()

# If we are not in multiplayer but we are in a match, part match
if userToken.matchID != -1 and userToken.actionID != actions.MULTIPLAYING and userToken.actionID != actions.MULTIPLAYER and userToken.actionID != actions.AFK:
    userToken.partMatch()
        '''

    # Update cached stats if our pp changed if we've just submitted a score or we've changed gameMode
    #if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userUtils.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):

    # Update cached stats if we've changed gamemode
    if userToken.gameMode != packetData["gameMode"]:
        userToken.gameMode = packetData["gameMode"]
        userToken.updateCachedStats()

    # Always update action id, text, md5 and beatmapID
    userToken.actionID = packetData["actionID"]
    #userToken.actionID = packetData["actionText"]
    userToken.actionMd5 = packetData["actionMd5"]
    userToken.actionMods = packetData["actionMods"]
    userToken.beatmapID = packetData["beatmapID"]

    if bool(packetData["actionMods"] & 128) == True:
        userToken.autopiloting = False
        userToken.relaxing = True
        userToken.ScoreV2 = False
        userToken.lastMod = userToken.currentMod
        userToken.currentMod = 'Relax'
        if userToken.actionID in (0, 1, 14):
            UserText = packetData["actionText"] + "on Relax"
        else:
            UserText = packetData["actionText"] + " on Relax"
        userToken.actionText = UserText
        userToken.updateCachedStats()
        if userToken.currentMod != userToken.lastMod:
            userToken.enqueue(
                serverPackets.notification("You're playing with Relax"))

    # autopiloten
    elif bool(packetData["actionMods"] & 8192) == True:
        userToken.autopiloting = True
        userToken.relaxing = False
        userToken.ScoreV2 = False
        userToken.lastMod = userToken.currentMod
        userToken.currentMod = 'Autopilot'
        if userToken.actionID in (0, 1, 14):
            UserText = packetData["actionText"] + "on Autopilot"
        else:
            UserText = packetData["actionText"] + " on Autopilot"
        userToken.actionText = UserText
        userToken.updateCachedStats()
        if userToken.currentMod != userToken.lastMod:
            userToken.enqueue(
                serverPackets.notification("You're playing with Autopilot"))

    # score v2
    elif bool(packetData["actionMods"] & 536870912) == True:
        userToken.autopiloting = False
        userToken.relaxing = False
        userToken.ScoreV2 = True
        userToken.lastMod = userToken.currentMod
        userToken.currentMod = 'ScoreV2'
        if userToken.actionID in (0, 1, 14):
            UserText = packetData["actionText"] + "on ScoreV2"
        else:
            UserText = packetData["actionText"] + " on ScoreV2"
        userToken.actionText = UserText
        userToken.updateCachedStats()
        if userToken.currentMod != userToken.lastMod:
            userToken.enqueue(
                serverPackets.notification("You're playing with ScoreV2"))

    else:
        userToken.relaxing = False
        userToken.autopiloting = False
        userToken.ScoreV2 = False
        userToken.lastMod = userToken.currentMod
        userToken.currentMod = 'Regular'
        UserText = packetData["actionText"]
        userToken.actionText = UserText
        userToken.updateCachedStats()
        if userToken.currentMod != userToken.lastMod:
            userToken.enqueue(
                serverPackets.notification("You're playing in regular mode"))

    glob.db.execute("UPDATE users_stats SET current_status = %s WHERE id = %s",
                    [UserText, userID])
    # Enqueue our new user panel and stats to us and our spectators
    recipients = [userToken]
    if len(userToken.spectators) > 0:
        for i in userToken.spectators:
            if i in glob.tokens.tokens:
                recipients.append(glob.tokens.tokens[i])

    for i in recipients:
        if i != None:
            # Force our own packet
            force = True if i == userToken else False
            i.enqueue(serverPackets.userPanel(userID, force))
            i.enqueue(serverPackets.userStats(userID, force))

    # Console output
    log.info("{} changed action: {} [{}][{}][{}]".format(
        username, str(userToken.actionID), userToken.actionText,
        userToken.actionMd5, userToken.beatmapID))
Esempio n. 4
0
def handle(userToken, packetData):
    # Get usertoken data
    userID = userToken.userID
    username = userToken.username

    # Make sure we are not banned
    #if userUtils.isBanned(userID):
    #	userToken.enqueue(serverPackets.loginBanned())
    #	return

    # Send restricted message if needed
    #if userToken.restricted:
    #	userToken.checkRestricted(True)

    # Change action packet
    packetData = clientPackets.userActionChange(packetData)

    # If we are not in spectate status but we're spectating someone, stop spectating
    '''
if userToken.spectating != 0 and userToken.actionID != actions.WATCHING and userToken.actionID != actions.IDLE and userToken.actionID != actions.AFK:
	userToken.stopSpectating()

# If we are not in multiplayer but we are in a match, part match
if userToken.matchID != -1 and userToken.actionID != actions.MULTIPLAYING and userToken.actionID != actions.MULTIPLAYER and userToken.actionID != actions.AFK:
	userToken.partMatch()
		'''

    # Update cached stats if our pp changed if we've just submitted a score or we've changed gameMode
    #if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userUtils.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):

    # Update cached stats if we've changed gamemode
    if userToken.gameMode != packetData["gameMode"]:
        userToken.gameMode = packetData["gameMode"]
        userToken.updateCachedStats()

    # Always update action id, text, md5 and beatmapID
    userToken.actionID = packetData["actionID"]
    userToken.actionMd5 = packetData["actionMd5"]
    userToken.actionMods = packetData["actionMods"]
    userToken.beatmapID = packetData["beatmapID"]

    if userToken.actionID != 1:
        if packetData["actionMods"] & 128:
            # Only reload on mode change.
            if not userToken.relaxing: userToken.updateCachedStats()
            userToken.relaxing = True
            userToken.autopiloting = False
            userToken.actionText = "[RX] " + packetData["actionText"]
            userToken.updateCachedStats()
        #autopiloten
        elif packetData["actionMods"] & 8192:
            # Only reload on mode change.
            if not userToken.autopiloting: userToken.updateCachedStats()
            userToken.autopiloting = True
            userToken.relaxing = False
            userToken.actionText = "[AP] " + packetData["actionText"]
            userToken.updateCachedStats()
        else:
            if (not userToken.autopiloting) and (not userToken.relaxing):
                userToken.updateCachedStats()
            userToken.relaxing = False
            userToken.autopiloting = False
            userToken.actionText = "[VN] " + packetData["actionText"]
            userToken.updateCachedStats()

    # Enqueue our new user panel and stats to us and our spectators
    p = (serverPackets.userPanel(userID) + serverPackets.userStats(userID))
    userToken.enqueue(p)
    if userToken.spectators:
        for i in userToken.spectators:
            glob.tokens.tokens[i].enqueue(p)

    # Console output
    log.info(
        f"{username} updated their presence! [Action ID: {userToken.actionID} // Action Text: {userToken.actionText}]"
    )