diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 63d0938..d017082 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -127,7 +127,7 @@ def kick(fro, chan, message): return "Nope." # Get target token and make sure is connected - tokens = glob.tokens.getTokenFromUsername(target, all=True) + tokens = glob.tokens.getTokenFromUsername(target, _all=True) if len(tokens) == 0: return "{} is not online".format(target) diff --git a/events/changeActionEvent.py b/events/changeActionEvent.py index 07135c9..5e541fd 100644 --- a/events/changeActionEvent.py +++ b/events/changeActionEvent.py @@ -1,6 +1,4 @@ -from common.constants import actions from common.log import logUtils as log -from common.ripple import userUtils from constants import clientPackets from constants import serverPackets from objects import glob diff --git a/events/createMatchEvent.py b/events/createMatchEvent.py index 17af080..f9992d9 100644 --- a/events/createMatchEvent.py +++ b/events/createMatchEvent.py @@ -1,7 +1,6 @@ from common.log import logUtils as log from constants import clientPackets from constants import exceptions -from constants import serverPackets from objects import glob diff --git a/events/joinMatchEvent.py b/events/joinMatchEvent.py index 8745a93..324beef 100644 --- a/events/joinMatchEvent.py +++ b/events/joinMatchEvent.py @@ -1,4 +1,3 @@ -from common import generalUtils from common.log import logUtils as log from constants import clientPackets from constants import exceptions diff --git a/events/loginEvent.py b/events/loginEvent.py index 184a6df..2316331 100644 --- a/events/loginEvent.py +++ b/events/loginEvent.py @@ -15,6 +15,7 @@ from objects import glob def handle(tornadoRequest): # Data to return + responseToken = None responseTokenString = "ayy" responseData = bytes() @@ -29,9 +30,6 @@ def handle(tornadoRequest): # 2:-3 thing is because requestData has some escape stuff that we don't need loginData = str(tornadoRequest.request.body)[2:-3].split("\\n") try: - # If true, print error to console - err = False - # Make sure loginData is valid if len(loginData) < 3: raise exceptions.invalidArgumentsException() @@ -220,25 +218,23 @@ def handle(tornadoRequest): except exceptions.loginFailedException: # Login failed error packet # (we don't use enqueue because we don't have a token since login has failed) - err = True responseData += serverPackets.loginFailed() except exceptions.invalidArgumentsException: # Invalid POST data # (we don't use enqueue because we don't have a token since login has failed) - err = True responseData += serverPackets.loginFailed() responseData += serverPackets.notification("I see what you're doing...") except exceptions.loginBannedException: # Login banned error packet - err = True responseData += serverPackets.loginBanned() except exceptions.loginLockedException: # Login banned error packet - err = True responseData += serverPackets.loginLocked() except exceptions.banchoMaintenanceException: # Bancho is in maintenance mode - responseData = responseToken.queue + responseData = bytes() + if responseToken is not None: + responseData = responseToken.queue responseData += serverPackets.notification("Our bancho server is in maintenance mode. Please try to login again later.") responseData += serverPackets.loginFailed() except exceptions.banchoRestartingException: @@ -251,7 +247,6 @@ def handle(tornadoRequest): except exceptions.haxException: # Using oldoldold client, we don't have client data. Force update. # (we don't use enqueue because we don't have a token since login has failed) - err = True responseData += serverPackets.forceUpdate() responseData += serverPackets.notification("Hory shitto, your client is TOO old! Nice prehistory! Please turn update it from the settings!") except: diff --git a/events/matchBeatmapEvent.py b/events/matchBeatmapEvent.py index 7ad0445..e10140d 100644 --- a/events/matchBeatmapEvent.py +++ b/events/matchBeatmapEvent.py @@ -1,6 +1,6 @@ from objects import glob -def handle(userToken, packetData, has): +def handle(userToken, _, has): # Get usertoken data userID = userToken.userID diff --git a/events/matchCompleteEvent.py b/events/matchCompleteEvent.py index c488a30..fc6adf2 100644 --- a/events/matchCompleteEvent.py +++ b/events/matchCompleteEvent.py @@ -1,6 +1,6 @@ from objects import glob -def handle(userToken, packetData): +def handle(userToken, _): # Get usertoken data userID = userToken.userID diff --git a/events/matchFramesEvent.py b/events/matchFramesEvent.py index 8467c63..864d712 100644 --- a/events/matchFramesEvent.py +++ b/events/matchFramesEvent.py @@ -1,5 +1,4 @@ from objects import glob -from constants import slotStatuses from constants import serverPackets def handle(userToken, packetData): diff --git a/events/matchPlayerLoadEvent.py b/events/matchPlayerLoadEvent.py index a94186f..a40a099 100644 --- a/events/matchPlayerLoadEvent.py +++ b/events/matchPlayerLoadEvent.py @@ -1,6 +1,6 @@ from objects import glob -def handle(userToken, packetData): +def handle(userToken, _): # Get userToken data userID = userToken.userID diff --git a/events/matchSkipEvent.py b/events/matchSkipEvent.py index 809063f..cbfc592 100644 --- a/events/matchSkipEvent.py +++ b/events/matchSkipEvent.py @@ -1,6 +1,6 @@ from objects import glob -def handle(userToken, packetData): +def handle(userToken, _): # Get userToken data userID = userToken.userID diff --git a/events/matchStartEvent.py b/events/matchStartEvent.py index 3ba7282..da83b37 100644 --- a/events/matchStartEvent.py +++ b/events/matchStartEvent.py @@ -1,6 +1,4 @@ from objects import glob -from constants import slotStatuses -from constants import serverPackets def handle(userToken, _): diff --git a/events/partLobbyEvent.py b/events/partLobbyEvent.py index 38be1b4..37e8d5e 100644 --- a/events/partLobbyEvent.py +++ b/events/partLobbyEvent.py @@ -1,7 +1,5 @@ from common.log import logUtils as log from helpers import chatHelper as chat -from objects import glob - def handle(userToken, _): # Get usertoken data diff --git a/events/spectateFramesEvent.py b/events/spectateFramesEvent.py index 6cb1495..dfbe6f4 100644 --- a/events/spectateFramesEvent.py +++ b/events/spectateFramesEvent.py @@ -1,6 +1,5 @@ from objects import glob from constants import serverPackets -from constants import exceptions def handle(userToken, packetData): # get token data diff --git a/events/tournamentMatchInfoRequestEvent.py b/events/tournamentMatchInfoRequestEvent.py index aec1ef8..6646949 100644 --- a/events/tournamentMatchInfoRequestEvent.py +++ b/events/tournamentMatchInfoRequestEvent.py @@ -1,5 +1,4 @@ from constants import clientPackets -from constants import serverPackets from objects import glob def handle(userToken, packetData): diff --git a/handlers/mainHandler.pyx b/handlers/mainHandler.pyx index 453ccd7..5e624a7 100644 --- a/handlers/mainHandler.pyx +++ b/handlers/mainHandler.pyx @@ -58,190 +58,190 @@ from helpers import packetHelper from objects import glob -class handler(SentryMixin, requestsManager.asyncRequestHandler): +class handler(requestsManager.asyncRequestHandler): @tornado.web.asynchronous @tornado.gen.engine def asyncPost(self): - try: - # Track time if needed - if glob.outputRequestTime: - # Start time - st = datetime.datetime.now() + #try: + # Track time if needed + if glob.outputRequestTime: + # Start time + st = datetime.datetime.now() - # Client's token string and request data - requestTokenString = self.request.headers.get("osu-token") - requestData = self.request.body + # Client's token string and request data + requestTokenString = self.request.headers.get("osu-token") + requestData = self.request.body - # Server's token string and request data - responseTokenString = "ayy" - responseData = bytes() + # Server's token string and request data + responseTokenString = "ayy" + responseData = bytes() - if requestTokenString is None: - # No token, first request. Handle login. - responseTokenString, responseData = loginEvent.handle(self) - else: - userToken = None # default value - try: - # This is not the first packet, send response based on client's request - # Packet start position, used to read stacked packets - pos = 0 + if requestTokenString is None: + # No token, first request. Handle login. + responseTokenString, responseData = loginEvent.handle(self) + else: + userToken = None # default value + try: + # This is not the first packet, send response based on client's request + # Packet start position, used to read stacked packets + pos = 0 - # Make sure the token exists - if requestTokenString not in glob.tokens.tokens: - raise exceptions.tokenNotFoundException() + # Make sure the token exists + if requestTokenString not in glob.tokens.tokens: + raise exceptions.tokenNotFoundException() - # Token exists, get its object and lock it - userToken = glob.tokens.tokens[requestTokenString] - userToken.lock.acquire() + # Token exists, get its object and lock it + userToken = glob.tokens.tokens[requestTokenString] + userToken.lock.acquire() - # Keep reading packets until everything has been read - while pos < len(requestData): - # Get packet from stack starting from new packet - leftData = requestData[pos:] + # Keep reading packets until everything has been read + while pos < len(requestData): + # Get packet from stack starting from new packet + leftData = requestData[pos:] - # Get packet ID, data length and data - packetID = packetHelper.readPacketID(leftData) - dataLength = packetHelper.readPacketLength(leftData) - packetData = requestData[pos:(pos+dataLength+7)] + # Get packet ID, data length and data + packetID = packetHelper.readPacketID(leftData) + dataLength = packetHelper.readPacketLength(leftData) + packetData = requestData[pos:(pos+dataLength+7)] - # Console output if needed - if glob.outputPackets == True and packetID != 4: - log.debug("Incoming packet ({})({}):\n\nPacket code: {}\nPacket length: {}\nSingle packet data: {}\n".format(requestTokenString, userToken.username, str(packetID), str(dataLength), str(packetData))) + # Console output if needed + if glob.outputPackets == True and packetID != 4: + log.debug("Incoming packet ({})({}):\n\nPacket code: {}\nPacket length: {}\nSingle packet data: {}\n".format(requestTokenString, userToken.username, str(packetID), str(dataLength), str(packetData))) - # Event handler - def handleEvent(ev): - def wrapper(): - ev.handle(userToken, packetData) - return wrapper + # Event handler + def handleEvent(ev): + def wrapper(): + ev.handle(userToken, packetData) + return wrapper - eventHandler = { - packetIDs.client_changeAction: handleEvent(changeActionEvent), - packetIDs.client_logout: handleEvent(logoutEvent), - packetIDs.client_friendAdd: handleEvent(friendAddEvent), - packetIDs.client_friendRemove: handleEvent(friendRemoveEvent), - packetIDs.client_userStatsRequest: handleEvent(userStatsRequestEvent), - packetIDs.client_requestStatusUpdate: handleEvent(requestStatusUpdateEvent), - packetIDs.client_userPanelRequest: handleEvent(userPanelRequestEvent), + eventHandler = { + packetIDs.client_changeAction: handleEvent(changeActionEvent), + packetIDs.client_logout: handleEvent(logoutEvent), + packetIDs.client_friendAdd: handleEvent(friendAddEvent), + packetIDs.client_friendRemove: handleEvent(friendRemoveEvent), + packetIDs.client_userStatsRequest: handleEvent(userStatsRequestEvent), + packetIDs.client_requestStatusUpdate: handleEvent(requestStatusUpdateEvent), + packetIDs.client_userPanelRequest: handleEvent(userPanelRequestEvent), - packetIDs.client_channelJoin: handleEvent(channelJoinEvent), - packetIDs.client_channelPart: handleEvent(channelPartEvent), - packetIDs.client_sendPublicMessage: handleEvent(sendPublicMessageEvent), - packetIDs.client_sendPrivateMessage: handleEvent(sendPrivateMessageEvent), - packetIDs.client_setAwayMessage: handleEvent(setAwayMessageEvent), + packetIDs.client_channelJoin: handleEvent(channelJoinEvent), + packetIDs.client_channelPart: handleEvent(channelPartEvent), + packetIDs.client_sendPublicMessage: handleEvent(sendPublicMessageEvent), + packetIDs.client_sendPrivateMessage: handleEvent(sendPrivateMessageEvent), + packetIDs.client_setAwayMessage: handleEvent(setAwayMessageEvent), - packetIDs.client_startSpectating: handleEvent(startSpectatingEvent), - packetIDs.client_stopSpectating: handleEvent(stopSpectatingEvent), - packetIDs.client_cantSpectate: handleEvent(cantSpectateEvent), - packetIDs.client_spectateFrames: handleEvent(spectateFramesEvent), + packetIDs.client_startSpectating: handleEvent(startSpectatingEvent), + packetIDs.client_stopSpectating: handleEvent(stopSpectatingEvent), + packetIDs.client_cantSpectate: handleEvent(cantSpectateEvent), + packetIDs.client_spectateFrames: handleEvent(spectateFramesEvent), - packetIDs.client_joinLobby: handleEvent(joinLobbyEvent), - packetIDs.client_partLobby: handleEvent(partLobbyEvent), - packetIDs.client_createMatch: handleEvent(createMatchEvent), - packetIDs.client_joinMatch: handleEvent(joinMatchEvent), - packetIDs.client_partMatch: handleEvent(partMatchEvent), - packetIDs.client_matchChangeSlot: handleEvent(changeSlotEvent), - packetIDs.client_matchChangeSettings: handleEvent(changeMatchSettingsEvent), - packetIDs.client_matchChangePassword: handleEvent(changeMatchPasswordEvent), - packetIDs.client_matchChangeMods: handleEvent(changeMatchModsEvent), - packetIDs.client_matchReady: handleEvent(matchReadyEvent), - packetIDs.client_matchNotReady: handleEvent(matchReadyEvent), - packetIDs.client_matchLock: handleEvent(matchLockEvent), - packetIDs.client_matchStart: handleEvent(matchStartEvent), - packetIDs.client_matchLoadComplete: handleEvent(matchPlayerLoadEvent), - packetIDs.client_matchSkipRequest: handleEvent(matchSkipEvent), - packetIDs.client_matchScoreUpdate: handleEvent(matchFramesEvent), - packetIDs.client_matchComplete: handleEvent(matchCompleteEvent), - packetIDs.client_matchNoBeatmap: handleEvent(matchNoBeatmapEvent), - packetIDs.client_matchHasBeatmap: handleEvent(matchHasBeatmapEvent), - packetIDs.client_matchTransferHost: handleEvent(matchTransferHostEvent), - packetIDs.client_matchFailed: handleEvent(matchFailedEvent), - packetIDs.client_matchChangeTeam: handleEvent(matchChangeTeamEvent), - packetIDs.client_invite: handleEvent(matchInviteEvent), + packetIDs.client_joinLobby: handleEvent(joinLobbyEvent), + packetIDs.client_partLobby: handleEvent(partLobbyEvent), + packetIDs.client_createMatch: handleEvent(createMatchEvent), + packetIDs.client_joinMatch: handleEvent(joinMatchEvent), + packetIDs.client_partMatch: handleEvent(partMatchEvent), + packetIDs.client_matchChangeSlot: handleEvent(changeSlotEvent), + packetIDs.client_matchChangeSettings: handleEvent(changeMatchSettingsEvent), + packetIDs.client_matchChangePassword: handleEvent(changeMatchPasswordEvent), + packetIDs.client_matchChangeMods: handleEvent(changeMatchModsEvent), + packetIDs.client_matchReady: handleEvent(matchReadyEvent), + packetIDs.client_matchNotReady: handleEvent(matchReadyEvent), + packetIDs.client_matchLock: handleEvent(matchLockEvent), + packetIDs.client_matchStart: handleEvent(matchStartEvent), + packetIDs.client_matchLoadComplete: handleEvent(matchPlayerLoadEvent), + packetIDs.client_matchSkipRequest: handleEvent(matchSkipEvent), + packetIDs.client_matchScoreUpdate: handleEvent(matchFramesEvent), + packetIDs.client_matchComplete: handleEvent(matchCompleteEvent), + packetIDs.client_matchNoBeatmap: handleEvent(matchNoBeatmapEvent), + packetIDs.client_matchHasBeatmap: handleEvent(matchHasBeatmapEvent), + packetIDs.client_matchTransferHost: handleEvent(matchTransferHostEvent), + packetIDs.client_matchFailed: handleEvent(matchFailedEvent), + packetIDs.client_matchChangeTeam: handleEvent(matchChangeTeamEvent), + packetIDs.client_invite: handleEvent(matchInviteEvent), - packetIDs.client_tournamentMatchInfoRequest: handleEvent(tournamentMatchInfoRequestEvent), - packetIDs.client_tournamentJoinMatchChannel: handleEvent(tournamentJoinMatchChannelEvent), - packetIDs.client_tournamentLeaveMatchChannel: handleEvent(tournamentLeaveMatchChannelEvent), - } + packetIDs.client_tournamentMatchInfoRequest: handleEvent(tournamentMatchInfoRequestEvent), + packetIDs.client_tournamentJoinMatchChannel: handleEvent(tournamentJoinMatchChannelEvent), + packetIDs.client_tournamentLeaveMatchChannel: handleEvent(tournamentLeaveMatchChannelEvent), + } - # Packets processed if in restricted mode. - # All other packets will be ignored if the user is in restricted mode - packetsRestricted = [ - packetIDs.client_logout, - packetIDs.client_userStatsRequest, - packetIDs.client_requestStatusUpdate, - packetIDs.client_userPanelRequest, - packetIDs.client_changeAction, - packetIDs.client_channelJoin, - packetIDs.client_channelPart, - ] + # Packets processed if in restricted mode. + # All other packets will be ignored if the user is in restricted mode + packetsRestricted = [ + packetIDs.client_logout, + packetIDs.client_userStatsRequest, + packetIDs.client_requestStatusUpdate, + packetIDs.client_userPanelRequest, + packetIDs.client_changeAction, + packetIDs.client_channelJoin, + packetIDs.client_channelPart, + ] - # Process/ignore packet - if packetID != 4: - if packetID in eventHandler: - if userToken.restricted == False or (userToken.restricted == True and packetID in packetsRestricted): - eventHandler[packetID]() - else: - log.warning("Ignored packet id from {} ({}) (user is restricted)".format(requestTokenString, packetID)) + # Process/ignore packet + if packetID != 4: + if packetID in eventHandler: + if userToken.restricted == False or (userToken.restricted == True and packetID in packetsRestricted): + eventHandler[packetID]() else: - log.warning("Unknown packet id from {} ({})".format(requestTokenString, packetID)) + log.warning("Ignored packet id from {} ({}) (user is restricted)".format(requestTokenString, packetID)) + else: + log.warning("Unknown packet id from {} ({})".format(requestTokenString, packetID)) - # Update pos so we can read the next stacked packet - # +7 because we add packet ID bytes, unused byte and data length bytes - pos += dataLength+7 + # Update pos so we can read the next stacked packet + # +7 because we add packet ID bytes, unused byte and data length bytes + pos += dataLength+7 - # Token queue built, send it - responseTokenString = userToken.token - responseData = userToken.queue - userToken.resetQueue() - except exceptions.tokenNotFoundException: - # Token not found. Disconnect that user - responseData = serverPackets.loginError() - responseData += serverPackets.notification("Whoops! Something went wrong, please login again.") - log.warning("Received packet from unknown token ({}).".format(requestTokenString)) - log.info("{} has been disconnected (invalid token)".format(requestTokenString)) - finally: - # Unlock token - if userToken is not None: - # Update ping time for timeout - userToken.updatePingTime() - # Release token lock - userToken.lock.release() - # Delete token if kicked - if userToken.kicked: - glob.tokens.deleteToken(userToken) + # Token queue built, send it + responseTokenString = userToken.token + responseData = userToken.queue + userToken.resetQueue() + except exceptions.tokenNotFoundException: + # Token not found. Disconnect that user + responseData = serverPackets.loginError() + responseData += serverPackets.notification("Whoops! Something went wrong, please login again.") + log.warning("Received packet from unknown token ({}).".format(requestTokenString)) + log.info("{} has been disconnected (invalid token)".format(requestTokenString)) + finally: + # Unlock token + if userToken is not None: + # Update ping time for timeout + userToken.updatePingTime() + # Release token lock + userToken.lock.release() + # Delete token if kicked + if userToken.kicked: + glob.tokens.deleteToken(userToken) - if glob.outputRequestTime: - # End time - et = datetime.datetime.now() + if glob.outputRequestTime: + # End time + et = datetime.datetime.now() - # Total time: - tt = float((et.microsecond-st.microsecond)/1000) - log.debug("Request time: {}ms".format(tt)) + # Total time: + tt = float((et.microsecond-st.microsecond)/1000) + log.debug("Request time: {}ms".format(tt)) - # Send server's response to client - # We don't use token object because we might not have a token (failed login) - if glob.gzip: - # First, write the gzipped response - self.write(gzip.compress(responseData, int(glob.conf.config["server"]["gziplevel"]))) + # Send server's response to client + # We don't use token object because we might not have a token (failed login) + if glob.gzip: + # First, write the gzipped response + self.write(gzip.compress(responseData, int(glob.conf.config["server"]["gziplevel"]))) - # Then, add gzip headers - self.add_header("Vary", "Accept-Encoding") - self.add_header("Content-Encoding", "gzip") - else: - # First, write the response - self.write(responseData) + # Then, add gzip headers + self.add_header("Vary", "Accept-Encoding") + self.add_header("Content-Encoding", "gzip") + else: + # First, write the response + self.write(responseData) - # Add all the headers AFTER the response has been written - self.set_status(200) - self.add_header("cho-token", responseTokenString) - self.add_header("cho-protocol", "19") - self.add_header("Connection", "keep-alive") - self.add_header("Keep-Alive", "timeout=5, max=100") - self.add_header("Content-Type", "text/html; charset=UTF-8") - except: - log.error("Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc())) - if glob.sentry: - yield tornado.gen.Task(self.captureException, exc_info=True) + # Add all the headers AFTER the response has been written + self.set_status(200) + self.add_header("cho-token", responseTokenString) + self.add_header("cho-protocol", "19") + self.add_header("Connection", "keep-alive") + self.add_header("Keep-Alive", "timeout=5, max=100") + self.add_header("Content-Type", "text/html; charset=UTF-8") + #except: + # log.error("Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc())) + # if glob.sentry: + # yield tornado.gen.Task(self.captureException, exc_info=True) #finally: # self.finish() diff --git a/helpers/configHelper.py b/helpers/configHelper.py index e94ac4a..ed5a351 100644 --- a/helpers/configHelper.py +++ b/helpers/configHelper.py @@ -74,7 +74,7 @@ class config: self.config.get("localize","enable") self.config.get("localize","ipapiurl") return True - except: + except configparser.Error: return False def generateDefaultConfig(self): diff --git a/helpers/locationHelper.py b/helpers/locationHelper.py index 25bc172..0dc4303 100644 --- a/helpers/locationHelper.py +++ b/helpers/locationHelper.py @@ -30,7 +30,7 @@ def getLocation(ip): try: # Try to get position from Pikolo Aul's Go-Sanic ip API result = json.loads(urllib.request.urlopen("{}/{}".format(glob.conf.config["localize"]["ipapiurl"], ip), timeout=3).read().decode())["loc"].split(",") - return (float(result[0]), float(result[1])) + return float(result[0]), float(result[1]) except: log.error("Error in get position") - return (0, 0) + return 0, 0 diff --git a/helpers/packetHelper.pyx b/helpers/packetHelper.pyx index b334834..61194a3 100644 --- a/helpers/packetHelper.pyx +++ b/helpers/packetHelper.pyx @@ -136,7 +136,7 @@ cpdef bytes packData(__data, int dataType): return data -cpdef bytes buildPacket(int __packet, list __packetData = []): +cpdef bytes buildPacket(int __packet, list __packetData = None): """ Builds a packet @@ -144,6 +144,9 @@ cpdef bytes buildPacket(int __packet, list __packetData = []): :param __packetData: packet structure [[data, dataType], [data, dataType], ...] :return: packet bytes """ + # Default argument + if __packetData is None: + __packetData = [] # Set some variables cdef bytes packetData = bytes() cdef int packetLength = 0 @@ -183,7 +186,7 @@ cpdef int readPacketLength(bytes stream): return unpackData(stream[3:7], dataTypes.UINT32) -cpdef readPacketData(bytes stream, list structure=[], bint hasFirstBytes = True): +cpdef readPacketData(bytes stream, list structure=None, bint hasFirstBytes = True): """ Read packet data from `stream` according to `structure` :param stream: packet bytes @@ -192,6 +195,10 @@ cpdef readPacketData(bytes stream, list structure=[], bint hasFirstBytes = True) if False, `stream` has only packet data. Default: True :return: {name: unpackedValue, ...} """ + # Default list argument + if structure is None: + structure = [] + # Read packet ID (first 2 bytes) cdef dict data = {} diff --git a/irc/ircserver.py b/irc/ircserver.py index 06c6072..40a27e6 100644 --- a/irc/ircserver.py +++ b/irc/ircserver.py @@ -350,11 +350,11 @@ class Client: self.sendMotd() self.__handleCommand = self.mainHandler - def quitHandler(self, command, arguments): + def quitHandler(self, _, arguments): """QUIT command handler""" self.disconnect(self.IRCUsername if len(arguments) < 1 else arguments[0]) - def joinHandler(self, command, arguments): + def joinHandler(self, _, arguments): """JOIN command handler""" if len(arguments) < 1: self.reply461("JOIN") @@ -421,7 +421,7 @@ class Client: self.reply403(channel) continue - def partHandler(self, command, arguments): + def partHandler(self, _, arguments): """PART command handler""" if len(arguments) < 1: self.reply461("PART") @@ -505,7 +505,7 @@ class Client: """LUSERS command handler""" self.sendLusers() - def pingHandler(self, command, arguments): + def pingHandler(self, _, arguments): """PING command handler""" if len(arguments) < 1: self.replyCode(409, "No origin specified") @@ -516,7 +516,7 @@ class Client: """(fake) PONG command handler""" pass - def awayHandler(self, command, arguments): + def awayHandler(self, _, arguments): """AWAY command handler""" response = chat.IRCAway(self.banchoUsername, " ".join(arguments)) self.replyCode(response, "You are no longer marked as being away" if response == 305 else "You have been marked as being away") @@ -621,12 +621,11 @@ class Server: value.message(":{} PRIVMSG {} :{}".format(fro, to, message)) - def removeClient(self, client, quitmsg): + def removeClient(self, client, _): """ Remove a client from connected clients :param client: client object - :param quitmsg: QUIT argument, useless atm :return: """ if client.socket in self.clients: @@ -639,6 +638,7 @@ class Server: :return: """ # Sentry + sentryClient = None if glob.sentry: sentryClient = raven.Client(glob.conf.config["sentry"]["ircdns"]) @@ -690,7 +690,7 @@ class Server: lastAliveCheck = now except: log.error("[IRC] Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc())) - if glob.sentry: + if glob.sentry and sentryClient is not None: sentryClient.captureException() def main(port=6667): diff --git a/objects/channelList.py b/objects/channelList.py index b27b4df..c1896d8 100644 --- a/objects/channelList.py +++ b/objects/channelList.py @@ -1,5 +1,4 @@ from common.log import logUtils as log -from constants import serverPackets from objects import channel from objects import glob from helpers import chatHelper as chat diff --git a/objects/match.py b/objects/match.py index 809330d..796941e 100644 --- a/objects/match.py +++ b/objects/match.py @@ -376,7 +376,7 @@ class match: """ Add someone to users in match - :param userID: user id of the user + :param user: user object of the user :return: True if join success, False if fail (room is full) """ # Make sure we're not in this match @@ -404,7 +404,7 @@ class match: """ Remove someone from users in match - :param userID: user if of the user + :param user: user object of the user :return: """ # Make sure the user is in room diff --git a/objects/matchList.py b/objects/matchList.py index 8b49cc8..f82f755 100644 --- a/objects/matchList.py +++ b/objects/matchList.py @@ -1,7 +1,6 @@ from objects import match from objects import glob from constants import serverPackets -from common.log import logUtils as log class matchList: def __init__(self): @@ -40,11 +39,11 @@ class matchList: return # Remove match object and stream - match = self.matches.pop(matchID) - glob.streams.dispose(match.streamName) - glob.streams.dispose(match.playingStreamName) - glob.streams.remove(match.streamName) - glob.streams.remove(match.playingStreamName) + _match = self.matches.pop(matchID) + glob.streams.dispose(_match.streamName) + glob.streams.dispose(_match.playingStreamName) + glob.streams.remove(_match.streamName) + glob.streams.remove(_match.playingStreamName) # Send match dispose packet to everyone in lobby glob.streams.broadcast("lobby", serverPackets.disposeMatch(matchID)) \ No newline at end of file diff --git a/objects/osuToken.py b/objects/osuToken.py index 40f0fd6..c2a57bf 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -98,7 +98,7 @@ class token: """ Add bytes (packets) to queue - :param bytes: (packet) bytes to enqueue + :param bytes_: (packet) bytes to enqueue """ # Never enqueue for IRC clients or Foka @@ -144,7 +144,8 @@ class token: """ Set client location - :param location: [latitude, longitude] + :param latitude: latitude + :param longitude: longitude """ self.location = (latitude, longitude) diff --git a/objects/tokenList.py b/objects/tokenList.py index 059417f..bc0f65d 100644 --- a/objects/tokenList.py +++ b/objects/tokenList.py @@ -1,6 +1,8 @@ import threading import time +import redis + from common.ripple import userUtils from common.log import logUtils as log from constants import serverPackets @@ -17,6 +19,7 @@ class tokenList: Add a token object to tokens list :param userID: user id associated to that token + :param ip: ip address of the client :param irc: if True, set this token as IRC client :param timeOffset: the time offset from UTC for this user. Default: 0. :param tournament: if True, flag this client as a tournement client. Default: True. @@ -54,13 +57,13 @@ class tokenList: # Get userID associated to that token return self.tokens[token].userID - def getTokenFromUserID(self, userID, ignoreIRC=False, all=False): + def getTokenFromUserID(self, userID, ignoreIRC=False, _all=False): """ Get token from a user ID :param userID: user ID to find :param ignoreIRC: if True, consider bancho clients only and skip IRC clients - :param all: if True, return a list with all clients that match given username, otherwise return + :param _all: if True, return a list with all clients that match given username, otherwise return only the first occurrence. :return: False if not found, token object if found """ @@ -70,18 +73,18 @@ class tokenList: if value.userID == userID: if ignoreIRC and value.irc: continue - if all: + if _all: ret.append(value) else: return value # Return full list or None if not found - if all: + if _all: return ret else: return None - def getTokenFromUsername(self, username, ignoreIRC=False, safe=False, all=False): + def getTokenFromUsername(self, username, ignoreIRC=False, safe=False, _all=False): """ Get an osuToken object from an username @@ -89,7 +92,7 @@ class tokenList: :param ignoreIRC: if True, consider bancho clients only and skip IRC clients :param safe: if True, username is a safe username, compare it with token's safe username rather than normal username - :param all: if True, return a list with all clients that match given username, otherwise return + :param _all: if True, return a list with all clients that match given username, otherwise return only the first occurrence. :return: osuToken object or None """ @@ -102,13 +105,13 @@ class tokenList: if (not safe and value.username.lower() == who) or (safe and value.safeUsername == who): if ignoreIRC and value.irc: continue - if all: + if _all: ret.append(value) else: return value # Return full list or None if not found - if all: + if _all: return ret else: return None @@ -215,7 +218,7 @@ class tokenList: try: # TODO: Make function or some redis meme glob.redis.eval("return redis.call('del', unpack(redis.call('keys', ARGV[1])))", 0, "peppy:sessions:*") - except: + except redis.RedisError: pass diff --git a/pep.py b/pep.py index 8739e2a..65df73c 100644 --- a/pep.py +++ b/pep.py @@ -142,7 +142,7 @@ if __name__ == "__main__": consoleHelper.printNoNl("> Creating threads pool... ") glob.pool = ThreadPool(int(glob.conf.config["server"]["threads"])) consoleHelper.printDone() - except: + except ValueError: consoleHelper.printError() consoleHelper.printColored("[!] Error while creating threads pool. Please check your config.ini and run the server again", bcolors.RED) @@ -248,9 +248,10 @@ if __name__ == "__main__": glob.irc = generalUtils.stringToBool(glob.conf.config["irc"]["enable"]) if glob.irc: # IRC port + ircPort = 0 try: ircPort = int(glob.conf.config["irc"]["port"]) - except: + except ValueError: consoleHelper.printColored("[!] Invalid IRC port! Please check your config.ini and run the server again", bcolors.RED) log.logMessage("**pep.py** IRC server started!", discord="bunker", of="info.txt", stdout=False) consoleHelper.printColored("> IRC server listening on 127.0.0.1:{}...".format(ircPort), bcolors.GREEN) @@ -259,9 +260,10 @@ if __name__ == "__main__": consoleHelper.printColored("[!] Warning! IRC server is disabled!", bcolors.YELLOW) # Server port + serverPort = 0 try: serverPort = int(glob.conf.config["server"]["port"]) - except: + except ValueError: consoleHelper.printColored("[!] Invalid server port! Please check your config.ini and run the server again", bcolors.RED) # Server start message and console output diff --git a/requirements.txt b/requirements.txt index 9fd8fdd..a484af3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ raven bcrypt>=3.1.1 dill redis -cython \ No newline at end of file +cython +datadog \ No newline at end of file