Add submodules
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# TODO: Rewrite this shit
|
||||
from common import generalUtils
|
||||
from objects import glob
|
||||
from helpers import generalFunctions
|
||||
|
||||
|
||||
class banchoConfig:
|
||||
"""
|
||||
@@ -26,8 +27,8 @@ class banchoConfig:
|
||||
"""
|
||||
(re)load bancho_settings from DB and set values in config array
|
||||
"""
|
||||
self.config["banchoMaintenance"] = generalFunctions.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'bancho_maintenance'")["value_int"])
|
||||
self.config["freeDirect"] = generalFunctions.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'free_direct'")["value_int"])
|
||||
self.config["banchoMaintenance"] = generalUtils.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'bancho_maintenance'")["value_int"])
|
||||
self.config["freeDirect"] = generalUtils.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'free_direct'")["value_int"])
|
||||
self.config["menuIcon"] = glob.db.fetch("SELECT value_string FROM bancho_settings WHERE name = 'menu_icon'")["value_string"]
|
||||
self.config["loginNotification"] = glob.db.fetch("SELECT value_string FROM bancho_settings WHERE name = 'login_notification'")["value_string"]
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from objects import glob
|
||||
from common.log import logUtils as log
|
||||
from objects import channel
|
||||
from helpers import logHelper as log
|
||||
from objects import glob
|
||||
|
||||
|
||||
class channelList:
|
||||
"""
|
||||
|
@@ -1,79 +0,0 @@
|
||||
from objects import glob
|
||||
|
||||
class buffer():
|
||||
"""
|
||||
A file buffer object.
|
||||
This buffer caches data in memory and when it's full, it writes the content to a file.
|
||||
"""
|
||||
def __init__(self, fileName, writeType="a", maxLength=512):
|
||||
"""
|
||||
A file buffer object
|
||||
|
||||
:param fileName: Path and name of file on disk .
|
||||
:param writeType: File write type. Optional. Default: "a" .
|
||||
:param maxLength: Max length before writing buffer to disk. Optional. Default: 512.
|
||||
"""
|
||||
self.content = ""
|
||||
self.length = 0
|
||||
self.fileName = fileName
|
||||
self.writeType = writeType
|
||||
self.maxLength = maxLength
|
||||
|
||||
def write(self, newData):
|
||||
"""
|
||||
Add data to buffer.
|
||||
If the total length of the data in buffer is greater than or equal to self.maxLength,
|
||||
the content is written on the disk and the buffer resets
|
||||
|
||||
:param newData: Data to append to buffer
|
||||
:return:
|
||||
"""
|
||||
self.content += newData
|
||||
self.length += len(newData)
|
||||
if self.length >= self.maxLength:
|
||||
self.flush()
|
||||
|
||||
def flush(self):
|
||||
"""
|
||||
Write buffer content to disk and reset its content
|
||||
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
glob.fLocks.lockFile(self.fileName)
|
||||
with open(self.fileName, self.writeType) as f:
|
||||
f.write(self.content)
|
||||
finally:
|
||||
glob.fLocks.unlockFile(self.fileName)
|
||||
|
||||
self.content = ""
|
||||
self.length = 0
|
||||
|
||||
class buffersList():
|
||||
"""
|
||||
A list of buffers
|
||||
"""
|
||||
def __init__(self):
|
||||
self.buffers = {}
|
||||
|
||||
def write(self, fileName, content):
|
||||
"""
|
||||
Write some data to an existing buffer in this list (or create a new one if it doesn't exist).
|
||||
If the buffer is full, the data is written to the file and the buffer resets.
|
||||
|
||||
:param fileName: Path of file/buffer
|
||||
:param content: New content
|
||||
:return:
|
||||
"""
|
||||
if fileName not in self.buffers:
|
||||
self.buffers[fileName] = buffer(fileName)
|
||||
self.buffers[fileName].write(content)
|
||||
|
||||
def flushAll(self):
|
||||
"""
|
||||
Write all buffers to file and flush them
|
||||
|
||||
:return:
|
||||
"""
|
||||
for _, value in self.buffers.items():
|
||||
value.flush()
|
@@ -1,20 +0,0 @@
|
||||
import threading
|
||||
|
||||
class fileLocks:
|
||||
def __init__(self):
|
||||
# Dictionary containing threading.Lock s
|
||||
self.locks = {}
|
||||
|
||||
def lockFile(self, fileName):
|
||||
if fileName in self.locks:
|
||||
# Acquire existing lock
|
||||
self.locks[fileName].acquire()
|
||||
else:
|
||||
# Create new lock and acquire it
|
||||
self.locks[fileName] = threading.Lock()
|
||||
self.locks[fileName].acquire()
|
||||
|
||||
def unlockFile(self, fileName):
|
||||
if fileName in self.locks:
|
||||
# Release lock if it exists
|
||||
self.locks[fileName].release()
|
@@ -1,11 +1,12 @@
|
||||
"""FokaBot related functions"""
|
||||
from helpers import userHelper
|
||||
from objects import glob
|
||||
from constants import actions
|
||||
from constants import serverPackets
|
||||
from constants import fokabotCommands
|
||||
import re
|
||||
from helpers import generalFunctions
|
||||
|
||||
from common import generalUtils
|
||||
from common.constants import actions
|
||||
from common.ripple import userUtils
|
||||
from constants import fokabotCommands
|
||||
from constants import serverPackets
|
||||
from objects import glob
|
||||
|
||||
# Tillerino np regex, compiled only once to increase performance
|
||||
npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)")
|
||||
@@ -34,13 +35,13 @@ def fokabotResponse(fro, chan, message):
|
||||
for i in fokabotCommands.commands:
|
||||
# Loop though all commands
|
||||
#if i["trigger"] in message:
|
||||
if generalFunctions.strContains(message, i["trigger"]):
|
||||
if generalUtils.strContains(message, i["trigger"]):
|
||||
# message has triggered a command
|
||||
|
||||
# Make sure the user has right permissions
|
||||
if i["privileges"] is not None:
|
||||
# Rank = x
|
||||
if userHelper.getPrivileges(userHelper.getID(fro)) & i["privileges"] == 0:
|
||||
if userUtils.getPrivileges(userUtils.getID(fro)) & i["privileges"] == 0:
|
||||
return False
|
||||
|
||||
# Check argument number
|
||||
|
@@ -1,12 +1,14 @@
|
||||
"""Global objects and variables"""
|
||||
|
||||
from objects import tokenList
|
||||
import time
|
||||
|
||||
from common.ddog import datadogClient
|
||||
from common.files import fileBuffer, fileLocks
|
||||
from objects import channelList
|
||||
from objects import matchList
|
||||
from objects import fileLocks
|
||||
from objects import fileBuffer
|
||||
from objects import streamList
|
||||
import time
|
||||
from objects import tokenList
|
||||
from common.web import schiavo
|
||||
|
||||
try:
|
||||
with open("version") as f:
|
||||
@@ -16,6 +18,7 @@ try:
|
||||
except:
|
||||
VERSION = "¯\_(xd)_/¯"
|
||||
|
||||
DATADOG_PREFIX = "peppy"
|
||||
application = None
|
||||
db = None
|
||||
conf = None
|
||||
@@ -26,6 +29,8 @@ matches = matchList.matchList()
|
||||
restarting = False
|
||||
fLocks = fileLocks.fileLocks()
|
||||
fileBuffers = fileBuffer.buffersList()
|
||||
schiavo = schiavo.schiavo()
|
||||
dog = datadogClient.datadogClient()
|
||||
verifiedCache = {}
|
||||
cloudflare = False
|
||||
chatFilters = None
|
||||
@@ -36,7 +41,6 @@ busyThreads = 0
|
||||
debug = False
|
||||
outputRequestTime = False
|
||||
outputPackets = False
|
||||
discord = False
|
||||
gzip = False
|
||||
localize = False
|
||||
sentry = False
|
||||
|
@@ -1,17 +1,19 @@
|
||||
# TODO: Enqueue all
|
||||
from constants import gameModes
|
||||
import copy
|
||||
|
||||
from common import generalUtils
|
||||
from common.constants import gameModes
|
||||
from common.log import logUtils as log
|
||||
from constants import dataTypes
|
||||
from constants import matchModModes
|
||||
from constants import matchScoringTypes
|
||||
from constants import matchTeamTypes
|
||||
from constants import matchModModes
|
||||
from constants import slotStatuses
|
||||
from objects import glob
|
||||
from constants import serverPackets
|
||||
from constants import dataTypes
|
||||
from constants import matchTeams
|
||||
from helpers import logHelper as log
|
||||
from constants import serverPackets
|
||||
from constants import slotStatuses
|
||||
from helpers import chatHelper as chat
|
||||
from helpers import generalFunctions
|
||||
import copy
|
||||
from objects import glob
|
||||
|
||||
|
||||
class slot:
|
||||
def __init__(self):
|
||||
@@ -35,7 +37,7 @@ class match:
|
||||
beatmapMD5 = ""
|
||||
slots = []
|
||||
hostUserID = 0
|
||||
gameMode = gameModes.std
|
||||
gameMode = gameModes.STD
|
||||
matchScoringType = matchScoringTypes.score
|
||||
matchTeamType = matchTeamTypes.headToHead
|
||||
matchModMode = matchModModes.normal
|
||||
@@ -59,7 +61,7 @@ class match:
|
||||
self.mods = 0
|
||||
self.matchName = matchName
|
||||
if matchPassword != "":
|
||||
self.matchPassword = generalFunctions.stringMd5(matchPassword)
|
||||
self.matchPassword = generalUtils.stringMd5(matchPassword)
|
||||
else:
|
||||
self.matchPassword = ""
|
||||
self.beatmapID = beatmapID
|
||||
@@ -487,7 +489,7 @@ class match:
|
||||
newPassword -- new password string
|
||||
"""
|
||||
if newPassword != "":
|
||||
self.matchPassword = generalFunctions.stringMd5(newPassword)
|
||||
self.matchPassword = generalUtils.stringMd5(newPassword)
|
||||
else:
|
||||
self.matchPassword = ""
|
||||
|
||||
|
@@ -1,14 +1,15 @@
|
||||
from constants import actions
|
||||
from constants import gameModes
|
||||
from helpers import userHelper
|
||||
import threading
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from common.constants import gameModes, actions
|
||||
from common.log import logUtils as log
|
||||
from common.ripple import userUtils
|
||||
from constants import serverPackets
|
||||
from events import logoutEvent
|
||||
from helpers import logHelper as log
|
||||
from objects import glob
|
||||
import uuid
|
||||
import time
|
||||
import threading
|
||||
from helpers import chatHelper as chat
|
||||
from objects import glob
|
||||
|
||||
|
||||
class token:
|
||||
|
||||
@@ -25,11 +26,11 @@ class token:
|
||||
"""
|
||||
# Set stuff
|
||||
self.userID = userID
|
||||
self.username = userHelper.getUsername(self.userID)
|
||||
self.privileges = userHelper.getPrivileges(self.userID)
|
||||
self.admin = userHelper.isInPrivilegeGroup(self.userID, "developer") or userHelper.isInPrivilegeGroup(self.userID, "community manager")
|
||||
self.username = userUtils.getUsername(self.userID)
|
||||
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 = userHelper.isRestricted(self.userID)
|
||||
self.restricted = userUtils.isRestricted(self.userID)
|
||||
self.loginTime = int(time.time())
|
||||
self.pingTime = self.loginTime
|
||||
self.timeOffset = timeOffset
|
||||
@@ -58,7 +59,7 @@ class token:
|
||||
self.actionText = ""
|
||||
self.actionMd5 = ""
|
||||
self.actionMods = 0
|
||||
self.gameMode = gameModes.std
|
||||
self.gameMode = gameModes.STD
|
||||
self.beatmapID = 0
|
||||
self.rankedScore = 0
|
||||
self.accuracy = 0.0
|
||||
@@ -78,7 +79,7 @@ class token:
|
||||
|
||||
# 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)
|
||||
userUtils.saveBanchoSession(self.userID, self.ip)
|
||||
|
||||
# Join main stream
|
||||
self.joinStream("main")
|
||||
@@ -275,7 +276,7 @@ class token:
|
||||
"""
|
||||
# Silence in db and token
|
||||
self.silenceEndTime = int(time.time())+seconds
|
||||
userHelper.silence(self.userID, seconds, reason, author)
|
||||
userUtils.silence(self.userID, seconds, reason, author)
|
||||
|
||||
# Send silence packet to target
|
||||
self.enqueue(serverPackets.silenceEndTime(seconds))
|
||||
@@ -316,7 +317,7 @@ class token:
|
||||
|
||||
def updateCachedStats(self):
|
||||
"""Update all cached stats for this token"""
|
||||
stats = userHelper.getUserStats(self.userID, self.gameMode)
|
||||
stats = userUtils.getUserStats(self.userID, self.gameMode)
|
||||
log.debug(str(stats))
|
||||
if stats is None:
|
||||
log.warning("Stats query returned None")
|
||||
@@ -336,7 +337,7 @@ class token:
|
||||
If false, get the cached one. Optional. Default: False
|
||||
"""
|
||||
if force:
|
||||
self.restricted = userHelper.isRestricted(self.userID)
|
||||
self.restricted = userUtils.isRestricted(self.userID)
|
||||
if self.restricted:
|
||||
self.setRestricted()
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
from objects import osuToken
|
||||
from objects import glob
|
||||
import time
|
||||
import threading
|
||||
import time
|
||||
|
||||
from common.ripple import userUtils
|
||||
from events import logoutEvent
|
||||
from helpers import userHelper
|
||||
from objects import glob
|
||||
from objects import osuToken
|
||||
|
||||
|
||||
class tokenList:
|
||||
"""
|
||||
@@ -39,7 +41,7 @@ class tokenList:
|
||||
if token in self.tokens:
|
||||
# Delete session from DB
|
||||
if self.tokens[token].ip != "":
|
||||
userHelper.deleteBanchoSessions(self.tokens[token].userID, self.tokens[token].ip)
|
||||
userUtils.deleteBanchoSessions(self.tokens[token].userID, self.tokens[token].ip)
|
||||
|
||||
# Pop token from list
|
||||
self.tokens.pop(token)
|
||||
|
Reference in New Issue
Block a user