Add license
This commit is contained in:
parent
f0f90b0c53
commit
93508624c4
3
LICENSE
Normal file
3
LICENSE
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Copyright (C) The Ripple Developers - All Rights Reserved
|
||||||
|
Unauthorized copying of this file, via any medium is strictly prohibited
|
||||||
|
Proprietary and confidential
|
|
@ -46,13 +46,13 @@ def handle(tornadoRequest):
|
||||||
# Banned
|
# Banned
|
||||||
raise exceptions.loginBannedException()
|
raise exceptions.loginBannedException()
|
||||||
|
|
||||||
|
# No login errors!
|
||||||
# Log user IP
|
# Log user IP
|
||||||
userHelper.IPLog(userID, requestIP)
|
userHelper.IPLog(userID, requestIP)
|
||||||
|
|
||||||
# No login errors!
|
|
||||||
# Delete old tokens for that user and generate a new one
|
# Delete old tokens for that user and generate a new one
|
||||||
glob.tokens.deleteOldTokens(userID)
|
glob.tokens.deleteOldTokens(userID)
|
||||||
responseToken = glob.tokens.addToken(userID)
|
responseToken = glob.tokens.addToken(userID, requestIP)
|
||||||
responseTokenString = responseToken.token
|
responseTokenString = responseToken.token
|
||||||
|
|
||||||
# Set silence end UNIX time in token
|
# Set silence end UNIX time in token
|
||||||
|
|
|
@ -29,6 +29,8 @@ def logMessage(message, alertType = "INFO", messageColor = bcolors.ENDC, discord
|
||||||
typeColor = bcolors.RED
|
typeColor = bcolors.RED
|
||||||
elif alertType == "CHAT":
|
elif alertType == "CHAT":
|
||||||
typeColor = bcolors.BLUE
|
typeColor = bcolors.BLUE
|
||||||
|
elif alertType == "DEBUG":
|
||||||
|
typeColor = bcolors.PINK
|
||||||
else:
|
else:
|
||||||
typeColor = bcolors.ENDC
|
typeColor = bcolors.ENDC
|
||||||
|
|
||||||
|
|
|
@ -317,3 +317,19 @@ def IPLog(userID, ip):
|
||||||
"""
|
"""
|
||||||
glob.db.execute("""INSERT INTO ip_user (userid, ip, occurencies) VALUES (%s, %s, '1')
|
glob.db.execute("""INSERT INTO ip_user (userid, ip, occurencies) VALUES (%s, %s, '1')
|
||||||
ON DUPLICATE KEY UPDATE occurencies = occurencies + 1""", [userID, ip])
|
ON DUPLICATE KEY UPDATE occurencies = occurencies + 1""", [userID, ip])
|
||||||
|
|
||||||
|
def saveBanchoSession(userID, ip):
|
||||||
|
"""
|
||||||
|
Save userid and ip of this token in bancho_sessions table.
|
||||||
|
Used to cache logins on LETS requests
|
||||||
|
"""
|
||||||
|
log.debug("Saving bancho session ({}::{}) in db".format(userID, ip))
|
||||||
|
glob.db.execute("INSERT INTO bancho_sessions (id, userid, ip) VALUES (NULL, %s, %s)", [userID, ip])
|
||||||
|
|
||||||
|
def deleteBanchoSessions(userID, ip):
|
||||||
|
"""Delete this bancho session from DB"""
|
||||||
|
log.debug("Deleting bancho session ({}::{}) from db".format(userID, ip))
|
||||||
|
try:
|
||||||
|
glob.db.execute("DELETE FROM bancho_sessions WHERE userid = %s AND ip = %s", [userID, ip])
|
||||||
|
except:
|
||||||
|
log.warning("Token for user: {} ip: {} doesn't exist".format(userID, ip))
|
||||||
|
|
|
@ -10,7 +10,8 @@ import time
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
class token:
|
class token:
|
||||||
"""Osu Token object
|
"""
|
||||||
|
Osu Token object
|
||||||
|
|
||||||
token -- token string
|
token -- token string
|
||||||
userID -- userID associated to that token
|
userID -- userID associated to that token
|
||||||
|
@ -33,13 +34,14 @@ class token:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, __userID, __token = None):
|
def __init__(self, __userID, token = None, ip = ""):
|
||||||
"""
|
"""
|
||||||
Create a token object and set userID and token
|
Create a token object and set userID and token
|
||||||
|
|
||||||
__userID -- user associated to this token
|
__userID -- user associated to this token
|
||||||
__token -- if passed, set token to that value
|
token -- if passed, set token to that value
|
||||||
if not passed, token will be generated
|
if not passed, token will be generated
|
||||||
|
ip -- client ip. optional.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Set stuff
|
# Set stuff
|
||||||
|
@ -48,7 +50,7 @@ class token:
|
||||||
self.rank = userHelper.getRankPrivileges(self.userID)
|
self.rank = userHelper.getRankPrivileges(self.userID)
|
||||||
self.loginTime = int(time.time())
|
self.loginTime = int(time.time())
|
||||||
self.pingTime = self.loginTime
|
self.pingTime = self.loginTime
|
||||||
self.lock = threading.Lock() # <-- Sync primitive
|
self.lock = threading.Lock() # Sync primitive
|
||||||
|
|
||||||
# Default variables
|
# Default variables
|
||||||
self.spectators = []
|
self.spectators = []
|
||||||
|
@ -60,6 +62,7 @@ class token:
|
||||||
self.actionMd5 = ""
|
self.actionMd5 = ""
|
||||||
self.actionMods = 0
|
self.actionMods = 0
|
||||||
self.gameMode = gameModes.std
|
self.gameMode = gameModes.std
|
||||||
|
self.ip = ip
|
||||||
self.country = 0
|
self.country = 0
|
||||||
self.location = [0,0]
|
self.location = [0,0]
|
||||||
self.awayMessage = ""
|
self.awayMessage = ""
|
||||||
|
@ -71,14 +74,18 @@ class token:
|
||||||
# Spam protection
|
# Spam protection
|
||||||
self.longMessageWarning = False
|
self.longMessageWarning = False
|
||||||
self.spamRate = 0
|
self.spamRate = 0
|
||||||
self.lastMessagetime = 0
|
#self.lastMessagetime = 0
|
||||||
|
|
||||||
# Generate/set token
|
# Generate/set token
|
||||||
if __token != None:
|
if token != None:
|
||||||
self.token = __token
|
self.token = token
|
||||||
else:
|
else:
|
||||||
self.token = str(uuid.uuid4())
|
self.token = str(uuid.uuid4())
|
||||||
|
|
||||||
|
# If we have a valid ip, save bancho session in DB so we can cache LETS logins
|
||||||
|
if ip != "":
|
||||||
|
userHelper.saveBanchoSession(self.userID, self.ip)
|
||||||
|
|
||||||
|
|
||||||
def enqueue(self, __bytes):
|
def enqueue(self, __bytes):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from objects import osuToken
|
from objects import osuToken
|
||||||
|
from objects import glob
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
from events import logoutEvent
|
from events import logoutEvent
|
||||||
from helpers import logHelper as log
|
from helpers import logHelper as log
|
||||||
|
from helpers import userHelper
|
||||||
|
|
||||||
class tokenList:
|
class tokenList:
|
||||||
"""
|
"""
|
||||||
|
@ -17,73 +19,77 @@ class tokenList:
|
||||||
"""
|
"""
|
||||||
self.tokens = {}
|
self.tokens = {}
|
||||||
|
|
||||||
def addToken(self, __userID):
|
def addToken(self, userID, ip = ""):
|
||||||
"""
|
"""
|
||||||
Add a token object to tokens list
|
Add a token object to tokens list
|
||||||
|
|
||||||
__userID -- user id associated to that token
|
userID -- user id associated to that token
|
||||||
return -- token object
|
return -- token object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
newToken = osuToken.token(__userID)
|
newToken = osuToken.token(userID, ip=ip)
|
||||||
self.tokens[newToken.token] = newToken
|
self.tokens[newToken.token] = newToken
|
||||||
return newToken
|
return newToken
|
||||||
|
|
||||||
def deleteToken(self, __token):
|
def deleteToken(self, token):
|
||||||
"""
|
"""
|
||||||
Delete a token from token list if it exists
|
Delete a token from token list if it exists
|
||||||
|
|
||||||
__token -- token string
|
token -- token string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if __token in self.tokens:
|
if token in self.tokens:
|
||||||
self.tokens.pop(__token)
|
# Delete session from DB
|
||||||
|
userHelper.deleteBanchoSessions(self.tokens[token].userID, self.tokens[token].ip)
|
||||||
|
|
||||||
|
# Pop token from list
|
||||||
|
self.tokens.pop(token)
|
||||||
|
|
||||||
|
|
||||||
def getUserIDFromToken(self, __token):
|
def getUserIDFromToken(self, token):
|
||||||
"""
|
"""
|
||||||
Get user ID from a token
|
Get user ID from a token
|
||||||
|
|
||||||
__token -- token to find
|
token -- token to find
|
||||||
|
|
||||||
return: false if not found, userID if found
|
return: false if not found, userID if found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Make sure the token exists
|
# Make sure the token exists
|
||||||
if __token not in self.tokens:
|
if token not in self.tokens:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Get userID associated to that token
|
# Get userID associated to that token
|
||||||
return self.tokens[__token].userID
|
return self.tokens[token].userID
|
||||||
|
|
||||||
|
|
||||||
def getTokenFromUserID(self, __userID):
|
def getTokenFromUserID(self, userID):
|
||||||
"""
|
"""
|
||||||
Get token from a user ID
|
Get token from a user ID
|
||||||
|
|
||||||
__userID -- user ID to find
|
userID -- user ID to find
|
||||||
return -- False if not found, token object if found
|
return -- False if not found, token object if found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Make sure the token exists
|
# Make sure the token exists
|
||||||
for _, value in self.tokens.items():
|
for _, value in self.tokens.items():
|
||||||
if value.userID == __userID:
|
if value.userID == userID:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
# Return none if not found
|
# Return none if not found
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def getTokenFromUsername(self, __username):
|
def getTokenFromUsername(self, username):
|
||||||
"""
|
"""
|
||||||
Get token from a username
|
Get token from a username
|
||||||
|
|
||||||
__username -- username to find
|
username -- username to find
|
||||||
return -- False if not found, token object if found
|
return -- False if not found, token object if found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# lowercase
|
# lowercase
|
||||||
who = __username.lower()
|
who = username.lower()
|
||||||
|
|
||||||
# Make sure the token exists
|
# Make sure the token exists
|
||||||
for _, value in self.tokens.items():
|
for _, value in self.tokens.items():
|
||||||
|
@ -94,16 +100,16 @@ class tokenList:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def deleteOldTokens(self, __userID):
|
def deleteOldTokens(self, userID):
|
||||||
"""
|
"""
|
||||||
Delete old userID's tokens if found
|
Delete old userID's tokens if found
|
||||||
|
|
||||||
__userID -- tokens associated to this user will be deleted
|
userID -- tokens associated to this user will be deleted
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Delete older tokens
|
# Delete older tokens
|
||||||
for key, value in self.tokens.items():
|
for key, value in self.tokens.items():
|
||||||
if value.userID == __userID:
|
if value.userID == userID:
|
||||||
# Delete this token from the dictionary
|
# Delete this token from the dictionary
|
||||||
self.tokens.pop(key)
|
self.tokens.pop(key)
|
||||||
|
|
||||||
|
@ -111,36 +117,36 @@ class tokenList:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def multipleEnqueue(self, __packet, __who, __but = False):
|
def multipleEnqueue(self, packet, who, but = False):
|
||||||
"""
|
"""
|
||||||
Enqueue a packet to multiple users
|
Enqueue a packet to multiple users
|
||||||
|
|
||||||
__packet -- packet bytes to enqueue
|
packet -- packet bytes to enqueue
|
||||||
__who -- userIDs array
|
who -- userIDs array
|
||||||
__but -- if True, enqueue to everyone but users in __who array
|
but -- if True, enqueue to everyone but users in who array
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for _, value in self.tokens.items():
|
for _, value in self.tokens.items():
|
||||||
shouldEnqueue = False
|
shouldEnqueue = False
|
||||||
if value.userID in __who and not __but:
|
if value.userID in who and not but:
|
||||||
shouldEnqueue = True
|
shouldEnqueue = True
|
||||||
elif value.userID not in __who and __but:
|
elif value.userID not in who and but:
|
||||||
shouldEnqueue = True
|
shouldEnqueue = True
|
||||||
|
|
||||||
if shouldEnqueue:
|
if shouldEnqueue:
|
||||||
value.enqueue(__packet)
|
value.enqueue(packet)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def enqueueAll(self, __packet):
|
def enqueueAll(self, packet):
|
||||||
"""
|
"""
|
||||||
Enqueue packet(s) to every connected user
|
Enqueue packet(s) to every connected user
|
||||||
|
|
||||||
__packet -- packet bytes to enqueue
|
packet -- packet bytes to enqueue
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for _, value in self.tokens.items():
|
for _, value in self.tokens.items():
|
||||||
value.enqueue(__packet)
|
value.enqueue(packet)
|
||||||
|
|
||||||
def usersTimeoutCheckLoop(self, __timeoutTime = 100, __checkTime = 100):
|
def usersTimeoutCheckLoop(self, __timeoutTime = 100, __checkTime = 100):
|
||||||
"""
|
"""
|
||||||
|
@ -182,3 +188,10 @@ class tokenList:
|
||||||
|
|
||||||
# Schedule a new check (endless loop)
|
# Schedule a new check (endless loop)
|
||||||
threading.Timer(10, self.spamProtectionResetLoop).start()
|
threading.Timer(10, self.spamProtectionResetLoop).start()
|
||||||
|
|
||||||
|
def deleteBanchoSessions(self):
|
||||||
|
"""
|
||||||
|
Truncate bancho_sessions table.
|
||||||
|
Call at bancho startup to delete old cached sessions
|
||||||
|
"""
|
||||||
|
glob.db.execute("TRUNCATE TABLE bancho_sessions")
|
||||||
|
|
5
pep.py
5
pep.py
|
@ -81,6 +81,11 @@ if __name__ == "__main__":
|
||||||
consoleHelper.printColored("[!] Error while loading bancho_settings. Please make sure the table in DB has all the required rows", bcolors.RED)
|
consoleHelper.printColored("[!] Error while loading bancho_settings. Please make sure the table in DB has all the required rows", bcolors.RED)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
# Delete old bancho sessions
|
||||||
|
consoleHelper.printNoNl("> Deleting cached bancho sessions from DB... ")
|
||||||
|
glob.tokens.deleteBanchoSessions()
|
||||||
|
consoleHelper.printDone()
|
||||||
|
|
||||||
# Create threads pool
|
# Create threads pool
|
||||||
try:
|
try:
|
||||||
consoleHelper.printNoNl("> Creating threads pool... ")
|
consoleHelper.printNoNl("> Creating threads pool... ")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user