Compare commits
12 Commits
api
...
privileges
Author | SHA1 | Date | |
---|---|---|---|
|
7b06f2921e | ||
|
ef940771d8 | ||
|
b03d51abff | ||
|
8ef02faf36 | ||
|
d29dcd25f7 | ||
|
cd75d1ad8d | ||
|
c7c5528588 | ||
|
3b150d70cd | ||
|
d249dd593f | ||
|
78a6931805 | ||
|
555c9cca1f | ||
|
83c514b75e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ filters.txt
|
||||
common_funzia
|
||||
common_refractor
|
||||
common_memato
|
||||
redistest.py
|
||||
|
2
common
2
common
Submodule common updated: 97ed79d4a1...cccd620817
@@ -11,14 +11,17 @@ def handle(userToken, packetData):
|
||||
userID = userToken.userID
|
||||
username = userToken.username
|
||||
|
||||
# Update privileges
|
||||
userToken.updatePrivileges()
|
||||
|
||||
# Make sure we are not banned
|
||||
if userUtils.isBanned(userID):
|
||||
if userUtils.isBanned(priv=userToken.privileges):
|
||||
userToken.enqueue(serverPackets.loginBanned())
|
||||
return
|
||||
|
||||
# Send restricted message if needed
|
||||
if not userToken.restricted:
|
||||
if userUtils.isRestricted(userID):
|
||||
if userUtils.isRestricted(priv=userToken.privileges):
|
||||
userToken.setRestricted()
|
||||
|
||||
# Change action packet
|
||||
|
@@ -64,9 +64,9 @@ def handle(tornadoRequest):
|
||||
|
||||
# Make sure we are not banned or locked
|
||||
priv = userUtils.getPrivileges(userID)
|
||||
if userUtils.isBanned(userID) == True and priv & privileges.USER_PENDING_VERIFICATION == 0:
|
||||
if userUtils.isBanned(priv=priv) == True and not userUtils.isPending(priv=priv):
|
||||
raise exceptions.loginBannedException()
|
||||
if userUtils.isLocked(userID) == True and priv & privileges.USER_PENDING_VERIFICATION == 0:
|
||||
if userUtils.isLocked(priv=priv) == True and not userUtils.isPending(priv=priv):
|
||||
raise exceptions.loginLockedException()
|
||||
|
||||
# 2FA check
|
||||
@@ -195,6 +195,10 @@ def handle(tornadoRequest):
|
||||
location = locationHelper.getLocation(requestIP)
|
||||
countryLetters = locationHelper.getCountry(requestIP)
|
||||
country = countryHelper.getCountryID(countryLetters)
|
||||
|
||||
# Set country in db if user has no country (first bancho login)
|
||||
if userUtils.getCountry(userID) == "XX":
|
||||
userUtils.setCountry(userID, countryLetters)
|
||||
else:
|
||||
# Set location to 0,0 and get country from db
|
||||
log.warning("Location skipped")
|
||||
@@ -206,10 +210,6 @@ def handle(tornadoRequest):
|
||||
responseToken.setLocation(location)
|
||||
responseToken.setCountry(country)
|
||||
|
||||
# Set country in db if user has no country (first bancho login)
|
||||
if userUtils.getCountry(userID) == "XX":
|
||||
userUtils.setCountry(userID, countryLetters)
|
||||
|
||||
# Send to everyone our userpanel if we are not restricted or tournament
|
||||
if not responseToken.restricted:
|
||||
glob.streams.broadcast("main", serverPackets.userPanel(userID))
|
||||
|
@@ -256,6 +256,10 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
|
||||
|
||||
# TODO: Make sure the recipient has not disabled PMs for non-friends or he's our friend
|
||||
|
||||
# Away check
|
||||
if recipientToken.awayCheck(userID):
|
||||
sendMessage(to, fro, "\x01ACTION is away: {message}\x01".format(code=chr(int(1)), message=recipientToken.awayMessage))
|
||||
|
||||
# Check message templates (mods/admins only)
|
||||
if message in messageTemplates.templates and token.admin == True:
|
||||
sendMessage(fro, to, messageTemplates.templates[message])
|
||||
@@ -278,7 +282,7 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
|
||||
sendMessage("FokaBot", to if isChannel else fro, fokaMessage)
|
||||
|
||||
# File and discord logs (public chat only)
|
||||
if to.startswith("#"):
|
||||
if to.startswith("#") and not (message.startswith("\x01ACTION is playing") and to.startswith("#spect_")):
|
||||
log.chat("{fro} @ {to}: {message}".format(fro=username, to=to, message=str(message.encode("utf-8"))))
|
||||
glob.schiavo.sendChatlog("**{fro} @ {to}:** {message}".format(fro=username, to=to, message=str(message.encode("utf-8"))[2:-1]))
|
||||
return 0
|
||||
@@ -357,4 +361,12 @@ def IRCPartChannel(username, channel):
|
||||
if not userID:
|
||||
log.warning("{} doesn't exist".format(username))
|
||||
return
|
||||
return partChannel(userID, channel)
|
||||
return partChannel(userID, channel)
|
||||
|
||||
def IRCAway(username, message):
|
||||
userID = userUtils.getID(username)
|
||||
if not userID:
|
||||
log.warning("{} doesn't exist".format(username))
|
||||
return
|
||||
glob.tokens.getTokenFromUserID(userID).setAwayMessage(message)
|
||||
return 305 if message == "" else 306
|
@@ -296,7 +296,6 @@ class Client:
|
||||
# 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:
|
||||
print("DISCONNECTERINOOOOOOOOOOOOOOOOOOOOO")
|
||||
value.disconnect(quitmsg="Connected from another client")
|
||||
return
|
||||
elif command == "USER":
|
||||
@@ -440,7 +439,6 @@ class Client:
|
||||
|
||||
# Send the message to bancho and reply
|
||||
if not recipientIRC.startswith("#"):
|
||||
print("PMPMPM!!!!!!!!!!")
|
||||
recipientBancho = chat.fixUsernameForBancho(recipientIRC)
|
||||
else:
|
||||
recipientBancho = recipientIRC
|
||||
@@ -489,10 +487,14 @@ class Client:
|
||||
"""(fake) PONG command handler"""
|
||||
pass
|
||||
|
||||
def awayHandler(self, command, arguments):
|
||||
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")
|
||||
|
||||
def mainHandler(self, command, arguments):
|
||||
"""Handler for post-login commands"""
|
||||
handlers = {
|
||||
#"AWAY": away_handler,
|
||||
"AWAY": self.awayHandler,
|
||||
#"ISON": ison_handler,
|
||||
"JOIN": self.joinHandler,
|
||||
#"LIST": list_handler,
|
||||
@@ -518,11 +520,6 @@ class Client:
|
||||
self.replyCode(421, "Unknown command ({})".format(command))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Server:
|
||||
def __init__(self, port):
|
||||
#self.host = socket.getfqdn("127.0.0.1")[:63]
|
||||
@@ -622,7 +619,7 @@ class Server:
|
||||
[x.socket for x in self.clients.values()
|
||||
if x.writeBufferSize() > 0],
|
||||
[],
|
||||
2)
|
||||
1)
|
||||
|
||||
# Handle incoming connections
|
||||
for x in iwtd:
|
||||
|
@@ -1,7 +1,6 @@
|
||||
"""Global objects and variables"""
|
||||
|
||||
import time
|
||||
|
||||
from common.ddog import datadogClient
|
||||
from common.files import fileBuffer, fileLocks
|
||||
from objects import channelList
|
||||
@@ -26,7 +25,6 @@ banchoConf = None
|
||||
tokens = tokenList.tokenList()
|
||||
channels = channelList.channelList()
|
||||
matches = matchList.matchList()
|
||||
restarting = False
|
||||
fLocks = fileLocks.fileLocks()
|
||||
fileBuffers = fileBuffer.buffersList()
|
||||
schiavo = schiavo.schiavo()
|
||||
@@ -45,8 +43,8 @@ gzip = False
|
||||
localize = False
|
||||
sentry = False
|
||||
irc = False
|
||||
restarting = False
|
||||
|
||||
startTime = int(time.time())
|
||||
|
||||
|
||||
streams = streamList.streamList()
|
||||
|
@@ -30,7 +30,7 @@ class token:
|
||||
self.privileges = userUtils.getPrivileges(self.userID)
|
||||
self.admin = userUtils.isInPrivilegeGroup(self.userID, "developer") or userUtils.isInPrivilegeGroup(self.userID, "community manager")
|
||||
self.irc = irc
|
||||
self.restricted = userUtils.isRestricted(self.userID)
|
||||
self.restricted = userUtils.isRestricted(priv=self.privileges)
|
||||
self.loginTime = int(time.time())
|
||||
self.pingTime = self.loginTime
|
||||
self.timeOffset = timeOffset
|
||||
@@ -51,6 +51,7 @@ class token:
|
||||
self.country = 0
|
||||
self.location = [0,0]
|
||||
self.awayMessage = ""
|
||||
self.sentAway = []
|
||||
self.matchID = -1
|
||||
self.tillerino = [0,0,-1.0] # beatmap, mods, acc
|
||||
self.silenceEndTime = 0
|
||||
@@ -426,4 +427,24 @@ class token:
|
||||
|
||||
def leaveAllStreams(self):
|
||||
for i in self.streams:
|
||||
self.leaveStream(i)
|
||||
self.leaveStream(i)
|
||||
|
||||
def awayCheck(self, userID):
|
||||
"""
|
||||
Returns True if userID doesn't know that we are away
|
||||
Returns False if we are not away or if userID already knows we are away
|
||||
|
||||
:param userID: original sender userID
|
||||
:return:
|
||||
"""
|
||||
if self.awayMessage == "" or userID in self.sentAway:
|
||||
return False
|
||||
self.sentAway.append(userID)
|
||||
return True
|
||||
|
||||
def updatePrivileges(self):
|
||||
"""
|
||||
Force updating self.privileges from db
|
||||
:return:
|
||||
"""
|
||||
self.privileges = userUtils.getPrivileges(self.userID)
|
13
pep.py
13
pep.py
@@ -202,6 +202,19 @@ if __name__ == "__main__":
|
||||
[
|
||||
datadogClient.periodicCheck("online_users", lambda: len(glob.tokens.tokens)),
|
||||
datadogClient.periodicCheck("multiplayer_matches", lambda: len(glob.matches.matches)),
|
||||
|
||||
datadogClient.periodicCheck("ram_clients", lambda: generalUtils.getTotalSize(glob.tokens)),
|
||||
datadogClient.periodicCheck("ram_matches", lambda: generalUtils.getTotalSize(glob.matches)),
|
||||
datadogClient.periodicCheck("ram_channels", lambda: generalUtils.getTotalSize(glob.channels)),
|
||||
datadogClient.periodicCheck("ram_file_buffers", lambda: generalUtils.getTotalSize(glob.fileBuffers)),
|
||||
datadogClient.periodicCheck("ram_file_locks", lambda: generalUtils.getTotalSize(glob.fLocks)),
|
||||
datadogClient.periodicCheck("ram_datadog", lambda: generalUtils.getTotalSize(glob.datadogClient)),
|
||||
datadogClient.periodicCheck("ram_verified_cache", lambda: generalUtils.getTotalSize(glob.verifiedCache)),
|
||||
datadogClient.periodicCheck("ram_userid_cache", lambda: generalUtils.getTotalSize(glob.userIDCache)),
|
||||
#datadogClient.periodicCheck("ram_pool", lambda: generalUtils.getTotalSize(glob.pool)),
|
||||
datadogClient.periodicCheck("ram_irc", lambda: generalUtils.getTotalSize(glob.ircServer)),
|
||||
datadogClient.periodicCheck("ram_tornado", lambda: generalUtils.getTotalSize(glob.application)),
|
||||
datadogClient.periodicCheck("ram_db", lambda: generalUtils.getTotalSize(glob.db)),
|
||||
])
|
||||
else:
|
||||
consoleHelper.printColored("[!] Warning! Datadog stats tracking is disabled!", bcolors.YELLOW)
|
||||
|
@@ -3,4 +3,5 @@ tornado
|
||||
mysqlclient
|
||||
psutil
|
||||
raven
|
||||
bcrypt
|
||||
bcrypt>=3.1.1
|
||||
dill
|
Reference in New Issue
Block a user