16 Commits

Author SHA1 Message Date
Nyo
7b06f2921e .BANCHO. Add more privileges check through direct privilege value 2016-11-15 19:27:21 +01:00
Nyo
ef940771d8 .HIDE. Update submodules 2016-11-13 19:06:47 +01:00
Nyo
b03d51abff .HIDE. Update submodules 2016-11-13 18:47:10 +01:00
Nyo
8ef02faf36 .HIDE. Update submodules 2016-11-13 12:36:10 +01:00
Nyo
d29dcd25f7 .BANCHO. Remove schiavo logs for /np in #spect_* 2016-11-13 12:35:15 +01:00
Nyo
cd75d1ad8d .BANCHO. Add bancho components RAM usage as datadog stats 2016-11-13 12:25:38 +01:00
Nyo
c7c5528588 .BANCHO. .FIX. Fix /away command, add support for /away command on IRC 2016-11-13 12:23:45 +01:00
Nyo
3b150d70cd .BANCHO. Decrease IRC polling time to 1 second 2016-11-12 22:55:43 +01:00
Nyo
d249dd593f .HIDE. Update requirements.txt 2016-11-01 09:57:43 +01:00
Nyo
78a6931805 .HIDE. Update submodules 2016-10-31 16:50:34 +01:00
Nyo
555c9cca1f .HIDE. Update requirements.txt 2016-10-31 16:40:54 +01:00
Nyo
83c514b75e .HIDE. Update submodules 2016-10-31 16:39:54 +01:00
Nyo
0e5471383e .BANCHO. Update submodules 2016-10-20 20:23:49 +02:00
Nyo
abc8e058a1 .BANCHO. .HIDE. Remove cloudflare option in config.ini 2016-10-20 20:22:23 +02:00
Nyo
0a53b31e42 .BANCHO. Enabled update command 2016-10-16 10:56:41 +02:00
Nyo
b61ac0e9b6 .BANCHO. .HIDE. Changed mirror/apiurl to mirror/api in config file 2016-10-16 10:43:04 +02:00
12 changed files with 76 additions and 37 deletions

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@ filters.txt
common_funzia
common_refractor
common_memato
redistest.py

2
common

Submodule common updated: a899c0be89...cccd620817

View File

@@ -684,7 +684,7 @@ def updateBeatmap(fro, chan, to):
if beatmapData is None:
return "Couldn't find beatmap data in database. Please load the beatmap's leaderboard and try again."
response = requests.post("{}/api/v1/update_beatmap".format(glob.conf.config["mirror"]["apiurl"]), {
response = requests.post("{}/api/v1/update_beatmap".format(glob.conf.config["mirror"]["url"]), {
"beatmap_set_id": beatmapData["beatmapset_id"],
"beatmap_name": beatmapData["song_name"],
"username": token.username,
@@ -837,8 +837,7 @@ commands = [
"callback": pp
}, {
"trigger": "!update",
"callback": updateBeatmap,
"privileges": privileges.ADMIN_MANAGE_SERVERS, # TODO: Remove privileges for !update
"callback": updateBeatmap
}
#
# "trigger": "!acc",

View File

@@ -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

View File

@@ -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))

View File

@@ -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
@@ -358,3 +362,11 @@ def IRCPartChannel(username, channel):
log.warning("{} doesn't exist".format(username))
return
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

View File

@@ -42,9 +42,8 @@ class config:
self.config.get("server","gzip")
self.config.get("server","gziplevel")
self.config.get("server","cikey")
self.config.get("server","cloudflare")
self.config.get("mirror","apiurl")
self.config.get("mirror","url")
self.config.get("mirror","apikey")
self.config.get("debug","enable")
@@ -94,10 +93,9 @@ class config:
self.config.set("server", "gzip", "1")
self.config.set("server", "gziplevel", "6")
self.config.set("server", "cikey", "changeme")
self.config.set("server", "cloudflare", "0")
self.config.add_section("mirror")
self.config.set("mirror", "apiurl", "http://storage.ripple.moe")
self.config.set("mirror", "url", "http://storage.ripple.moe")
self.config.set("mirror", "apikey", "anotherkey")
self.config.add_section("debug")

View File

@@ -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:

View File

@@ -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,13 +25,11 @@ banchoConf = None
tokens = tokenList.tokenList()
channels = channelList.channelList()
matches = matchList.matchList()
restarting = False
fLocks = fileLocks.fileLocks()
fileBuffers = fileBuffer.buffersList()
schiavo = schiavo.schiavo()
dog = datadogClient.datadogClient()
verifiedCache = {}
cloudflare = False
chatFilters = None
userIDCache = {}
pool = None
@@ -46,8 +43,8 @@ gzip = False
localize = False
sentry = False
irc = False
restarting = False
startTime = int(time.time())
streams = streamList.streamList()

View File

@@ -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
@@ -427,3 +428,23 @@ class token:
def leaveAllStreams(self):
for i in self.streams:
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)

16
pep.py
View File

@@ -202,15 +202,25 @@ 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)
except:
consoleHelper.printColored("[!] Error while starting Datadog client! Please check your config.ini and run the server again", bcolors.RED)
# Cloudflare memes
glob.cloudflare = generalUtils.stringToBool(glob.conf.config["server"]["cloudflare"])
# IRC start message and console output
glob.irc = generalUtils.stringToBool(glob.conf.config["irc"]["enable"])
if glob.irc:

View File

@@ -3,4 +3,5 @@ tornado
mysqlclient
psutil
raven
bcrypt
bcrypt>=3.1.1
dill