IRC Support for username with spaces

BATs with Donor have bright yellow username in chat
General performance improvements
Code cleaning
Multiplayer improvements and fixes
Fixed some spectator bugs
This commit is contained in:
Nyo
2016-09-02 12:41:19 +02:00
parent e16e4d7493
commit 653303831b
47 changed files with 450 additions and 622 deletions

View File

@@ -4,7 +4,6 @@ from constants import serverPackets
from helpers import userHelper
from helpers import logHelper as log
from constants import actions
from helpers import chatHelper as chat
def handle(userToken, packetData):
# Get usertoken data
@@ -24,9 +23,16 @@ def handle(userToken, packetData):
# 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 changedm 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 != userHelper.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):
log.debug("!!!! UPDATING CACHED STATS !!!!")
# Always update game mode, or we'll cache stats from the wrong game mode if we've changed it
userToken.gameMode = packetData["gameMode"]
userToken.updateCachedStats()
@@ -55,12 +61,5 @@ def handle(userToken, packetData):
token.enqueue(serverPackets.userPanel(userID, force))
token.enqueue(serverPackets.userStats(userID, force))
# Send osu!direct alert if needed
# NOTE: Remove this when osu!direct will be fixed
if userToken.actionID == actions.osuDirect and userToken.osuDirectAlert == False:
userToken.osuDirectAlert = True
chat.sendMessage("FokaBot", userToken.username, "Sup! osu!direct works, but you'll need to update the switcher to have the Download button working. If you didn't update the switcher yet, please do!")
# Console output
log.info("{} changed action: {} [{}][{}]".format(username, str(userToken.actionID), userToken.actionText, userToken.actionMd5))

View File

@@ -16,6 +16,10 @@ def handle(userToken, packetData):
return
match = glob.matches.matches[matchID]
# Host check
if userID != match.hostUserID:
return
# Set slot or match mods according to modType
if match.matchModMode == matchModModes.freeMod:
# Freemod
@@ -25,7 +29,7 @@ def handle(userToken, packetData):
# If host has selected DT/HT and Freemod is enabled, set DT/HT as match mod
if (packetData["mods"] & mods.DoubleTime) > 0:
match.changeMatchMods(mods.DoubleTime)
# Nighcore
# Nightcore
if (packetData["mods"] & mods.Nightcore) > 0:
match.changeMatchMods(match.mods+mods.Nightcore)
elif (packetData["mods"] & mods.HalfTime) > 0:

View File

@@ -13,5 +13,9 @@ def handle(userToken, packetData):
# Get our match
match = glob.matches.matches[matchID]
# Host check
if userToken.userID != match.hostUserID:
return
# Update match password
match.changePassword(packetData["matchPassword"])

View File

@@ -6,6 +6,7 @@ from constants import matchTeamTypes
from constants import matchTeams
from constants import slotStatuses
from helpers import logHelper as log
from helpers import generalFunctions
def handle(userToken, packetData):
# Read new settings
@@ -13,7 +14,7 @@ def handle(userToken, packetData):
# Get match ID
matchID = userToken.matchID
# Make sure the match exists
if matchID not in glob.matches.matches:
return
@@ -21,6 +22,10 @@ def handle(userToken, packetData):
# Get match object
match = glob.matches.matches[matchID]
# Host check
if userToken.userID != match.hostUserID:
return
# Some dank memes easter egg
memeTitles = [
"RWC 2020",
@@ -53,7 +58,10 @@ def handle(userToken, packetData):
# Update match settings
match.inProgress = packetData["inProgress"]
match.matchPassword = packetData["matchPassword"]
if packetData["matchPassword"] != "":
match.matchPassword = generalFunctions.stringMd5(packetData["matchPassword"])
else:
match.matchPassword = ""
match.beatmapName = packetData["beatmapName"]
match.beatmapID = packetData["beatmapID"]
match.hostUserID = packetData["hostUserID"]
@@ -71,14 +79,14 @@ def handle(userToken, packetData):
# Reset ready if needed
if oldMods != match.mods or oldBeatmapMD5 != match.beatmapMD5:
for i in range(0,16):
if match.slots[i]["status"] == slotStatuses.ready:
match.slots[i]["status"] = slotStatuses.notReady
if match.slots[i].status == slotStatuses.ready:
match.slots[i].status = slotStatuses.notReady
# Reset mods if needed
if match.matchModMode == matchModModes.normal:
# Reset slot mods if not freeMods
for i in range(0,16):
match.slots[i]["mods"] = 0
match.slots[i].mods = 0
else:
# Reset match mods if freemod
match.mods = 0
@@ -88,13 +96,13 @@ def handle(userToken, packetData):
# Set teams
c=0
for i in range(0,16):
if match.slots[i]["team"] == matchTeams.noTeam:
match.slots[i]["team"] = matchTeams.red if c % 2 == 0 else matchTeams.blue
if match.slots[i].team == matchTeams.noTeam:
match.slots[i].team = matchTeams.red if c % 2 == 0 else matchTeams.blue
c+=1
else:
# Reset teams
for i in range(0,16):
match.slots[i]["team"] = matchTeams.noTeam
match.slots[i].team = matchTeams.noTeam
# Force no freemods if tag coop
if match.matchTeamType == matchTeamTypes.tagCoop or match.matchTeamType == matchTeamTypes.tagTeamVs:
@@ -105,4 +113,3 @@ def handle(userToken, packetData):
# Console output
log.info("MPROOM{}: Updated room settings".format(match.matchID))
#consoleHelper.printColored("> MPROOM{}: DEBUG: Host is {}".format(match.matchID, match.hostUserID), bcolors.PINK)

View File

@@ -4,6 +4,7 @@ from objects import glob
from constants import exceptions
from helpers import logHelper as log
from helpers import chatHelper as chat
from helpers import generalFunctions
def handle(userToken, packetData):
# read packet data
@@ -12,12 +13,15 @@ def handle(userToken, packetData):
# Get match from ID
joinMatch(userToken, packetData["matchID"], packetData["password"])
def joinMatch(userToken, matchID, password):
def joinMatch(userToken, matchID, password, isPasswordHashed = False):
try:
# TODO: leave other matches
# TODO: Stop spectating
# Stop spectating
userToken.stopSpectating()
# get usertoken data
# Leave other matches
userToken.partMatch()
# Get usertoken data
userID = userToken.userID
# Make sure the match exists
@@ -27,6 +31,10 @@ def joinMatch(userToken, matchID, password):
# Match exists, get object
match = glob.matches.matches[matchID]
# Hash password if needed
if isPasswordHashed == False and password != "":
password = generalFunctions.stringMd5(password)
# Check password
# TODO: Admins can enter every match
if match.matchPassword != "":

View File

@@ -2,16 +2,10 @@ from helpers import userHelper
from constants import serverPackets
from constants import exceptions
from objects import glob
from helpers import consoleHelper
from constants import bcolors
from helpers import locationHelper
from helpers import countryHelper
import time
from helpers import generalFunctions
import sys
import traceback
from helpers import requestHelper
from helpers import discordBotHelper
from helpers import logHelper as log
from helpers import chatHelper as chat
from constants import privileges

View File

@@ -15,21 +15,16 @@ def handle(userToken, _=None):
# the server, so we accept logout packets sent at least 5 seconds after login
# if the user logs out before 5 seconds, he will be disconnected later with timeout check
if int(time.time()-userToken.loginTime) >= 5 or userToken.irc == True:
# Stop spectating if needed
# TODO: Call stopSpectatingEvent!!!!!!!!!
if userToken.spectating != 0:
# The user was spectating someone
spectatorHostToken = glob.tokens.getTokenFromUserID(userToken.spectating)
if spectatorHostToken != None:
# The host is still online, send removeSpectator to him
spectatorHostToken.enqueue(serverPackets.removeSpectator(userID))
# Stop spectating
userToken.stopSpectating()
# Part matches
userToken.partMatch()
# Part all joined channels
for i in userToken.joinedChannels:
chat.partChannel(token=userToken, channel=i)
# TODO: Lobby left if joined
# Enqueue our disconnection to everyone else
glob.tokens.enqueueAll(serverPackets.userLogout(userID))

View File

@@ -25,7 +25,7 @@ def handle(userToken, packetData):
# Enqueue frames to who's playing
for i in range(0,16):
if match.slots[i]["userID"] > -1 and match.slots[i]["status"] == slotStatuses.playing:
token = glob.tokens.getTokenFromUserID(match.slots[i]["userID"])
if match.slots[i].userID > -1 and match.slots[i].status == slotStatuses.playing:
token = glob.tokens.getTokenFromUserID(match.slots[i].userID)
if token != None:
token.enqueue(serverPackets.matchFrames(slotID, packetData))

View File

@@ -1,3 +1,4 @@
from events import matchBeatmapEvent
def handle(userToken, packetData):
matchBeatmapEvent.handle(userToken, packetData, True)

View File

@@ -14,6 +14,10 @@ def handle(userToken, packetData):
return
match = glob.matches.matches[matchID]
# Host check
if userID != match.hostUserID:
return
# Make sure we aren't locking our slot
ourSlot = match.getUserSlotID(userID)
if packetData["slotID"] == ourSlot:

View File

@@ -1,3 +1,4 @@
from events import matchBeatmapEvent
def handle(userToken, packetData):
matchBeatmapEvent.handle(userToken, packetData, False)

View File

@@ -3,7 +3,6 @@ from constants import slotStatuses
from constants import serverPackets
def handle(userToken, _):
# TODO: Host check
# Get match ID and match object
matchID = userToken.matchID
@@ -19,10 +18,12 @@ def handle(userToken, _):
# The match exists, get object
match = glob.matches.matches[matchID]
force = False # TODO: Force thing
# Host check
if userToken.userID != match.hostUserID:
return
# Make sure we have enough players
if (match.countUsers() < 2 or not match.checkTeams()) and not force:
if (match.countUsers() < 2 or match.checkTeams() == False):
return
# Change inProgress value
@@ -30,16 +31,16 @@ def handle(userToken, _):
# Set playing to ready players and set load, skip and complete to False
for i in range(0,16):
if (match.slots[i]["status"] & slotStatuses.ready) > 0:
match.slots[i]["status"] = slotStatuses.playing
match.slots[i]["loaded"] = False
match.slots[i]["skip"] = False
match.slots[i]["complete"] = False
if (match.slots[i].status & slotStatuses.ready) > 0:
match.slots[i].status = slotStatuses.playing
match.slots[i].loaded = False
match.slots[i].skip = False
match.slots[i].complete = False
# Send match start packet
for i in range(0,16):
if (match.slots[i]["status"] & slotStatuses.playing) > 0 and match.slots[i]["userID"] != -1:
token = glob.tokens.getTokenFromUserID(match.slots[i]["userID"])
if (match.slots[i].status & slotStatuses.playing) > 0 and match.slots[i].userID != -1:
token = glob.tokens.getTokenFromUserID(match.slots[i].userID)
if token != None:
token.enqueue(serverPackets.matchStart(matchID))

View File

@@ -19,5 +19,9 @@ def handle(userToken, packetData):
# Match exists, get object
match = glob.matches.matches[matchID]
# Host check
if userToken.userID != match.hostUserID:
return
# Transfer host
match.transferHost(packetData["slotID"])

View File

@@ -1,28 +1,2 @@
from objects import glob
def handle(userToken, _):
# get data from usertoken
userID = userToken.userID
# Get match ID and match object
matchID = userToken.matchID
# Make sure we are in a match
if matchID == -1:
return
# Make sure the match exists
if matchID not in glob.matches.matches:
return
# The match exists, get object
match = glob.matches.matches[matchID]
# Set slot to free
match.userLeft(userID)
# Part #multiplayer channel
#chat.partChannel(token=userToken, channel="#multi_{}".format(matchID), kick=True)
# Set usertoken match to -1
userToken.partMatch()
def handle(userToken, _=None):
userToken.partMatch()

View File

@@ -2,8 +2,6 @@ from constants import serverPackets
from helpers import logHelper as log
def handle(userToken, packetData):
log.debug("Requested status update")
# Update cache and send new stats
userToken.updateCachedStats()
userToken.enqueue(serverPackets.userStats(userToken.userID))

View File

@@ -1,37 +1,2 @@
from objects import glob
from constants import serverPackets
from constants import exceptions
from helpers import logHelper as log
from helpers import chatHelper as chat
def handle(userToken, _):
try:
# get user token data
userID = userToken.userID
username = userToken.username
# Remove our userID from host's spectators
target = userToken.spectating
targetToken = glob.tokens.getTokenFromUserID(target)
if targetToken == None:
raise exceptions.tokenNotFoundException
targetToken.removeSpectator(userID)
# Part #spectator channel
chat.partChannel(token=userToken, channel="#spect_{}".format(target))
# Send the spectator left packet to host
targetToken.enqueue(serverPackets.removeSpectator(userID))
for c in targetToken.spectators:
spec = glob.tokens.getTokenFromUserID(c)
spec.enqueue(serverPackets.fellowSpectatorLeft(userID))
#targetToken.enqueue(serverPackets.fellowSpectatorLeft(userID))
# Console output
log.info("{} are no longer spectating {}".format(username, target))
except exceptions.tokenNotFoundException:
log.warning("Spectator stop: token not found")
finally:
# Set our spectating user to 0
userToken.stopSpectating()
def handle(userToken, _=None):
userToken.stopSpectating()