class loginFailedException(Exception):
class loginBannedException(Exception):
class tokenNotFoundException(Exception):
class channelNoPermissionsException(Exception):
class channelUnknownException(Exception):
class channelModeratedException(Exception):
class noAdminException(Exception):
class commandSyntaxException(Exception):
class banchoConfigErrorException(Exception):
class banchoMaintenanceException(Exception):
class moderatedPMException(Exception):
class userNotFoundException(Exception):
class alreadyConnectedException(Exception):
class stopSpectating(Exception):
class matchWrongPasswordException(Exception):
class matchNotFoundException(Exception):
class matchJoinErrorException(Exception):
class matchCreateError(Exception):
class banchoRestartingException(Exception):
class apiException(Exception):
class invalidArgumentsException(Exception):
class messageTooLongWarnException(Exception):
class messageTooLongException(Exception):
class userSilencedException(Exception):
class need2FAException(Exception):
class userRestrictedException(Exception):
class haxException(Exception):
class forceUpdateException(Exception):
class loginLockedException(Exception):
class unknownStreamException(Exception):
class userTournamentException(Exception):
class userAlreadyInChannelException(Exception):
class userNotInChannelException(Exception):
class missingReportInfoException(Exception):
class invalidUserException(Exception):
class wrongChannelException(Exception):
class periodicLoopException(Exception): FREE = 1
LOCKED = 2
NOT_READY = 4
READY = 8
NO_MAP = 16
PLAYING = 32
OCCUPIED = 124
PLAYING_QUIT = 128 NORMAL = 0
FREE_MOD = 1 NO_TEAM = 0
BLUE = 1
RED = 2 HEAD_TO_HEAD = 0
TAG_COOP = 1
TEAM_VS = 2
TAG_TEAM_VS = 3 SCORE = 0
ACCURACY = 1
COMBO = 2
SCORE_V2 = 3 def loginFailed():
def forceUpdate():
def loginBanned():
def loginLocked():
def loginError():
def needSupporter():
def needVerification():
def userID(uid):
def silenceEndTime(seconds):
def protocolVersion(version = 19):
def mainMenuIcon(icon):
def userSupporterGMT(supporter, GMT, tournamentStaff):
def friendList(userID):
def onlineUsers():
def userLogout(userID):
def userPanel(userID, force = False):
def userStats(userID, force = False):
def sendMessage(fro, to, message):
def channelJoinSuccess(userID, chan):
def channelInfo(chan):
def channelInfoEnd():
def channelKicked(chan):
def userSilenced(userID):
def addSpectator(userID):
def removeSpectator(userID):
def spectatorFrames(data):
def noSongSpectator(userID):
def fellowSpectatorJoined(userID):
def fellowSpectatorLeft(userID):
def createMatch(matchID):
def updateMatch(matchID, censored = False):
def matchStart(matchID):
def disposeMatch(matchID):
def matchJoinSuccess(matchID):
def matchJoinFail():
def changeMatchPassword(newPassword):
def allPlayersLoaded():
def playerSkipped(userID):
def allPlayersSkipped():
def matchFrames(slotID, data):
def matchComplete():
def playerFailed(slotID):
def matchTransferHost():
def matchAbort():
def switchServer(address):
def notification(message):
def banchoRestart(msUntilReconnection):
def rtx(message): def dispose():
def runningUnderUnix():
def scheduleShutdown(sendRestartTime, restart, message = "", delay=20):
def restartServer():
def shutdownServer():
def getSystemInfo(): def connect():
def disconnect():
def fokabotResponse(fro, chan, message): 		VERSION = f.read().strip()
	VERSION = "Unknown"
DATADOG_PREFIX = "peppy" def joinChannel(userID = 0, channel = "", token = None, toIRC = True, force=False):
def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = False, force=False):
def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
def fixUsernameForBancho(username):
def fixUsernameForIRC(username):
def IRCConnect(username):
def IRCDisconnect(username):
def IRCJoinChannel(username, channel):
def IRCPartChannel(username, channel):
def IRCAway(username, message):
import json
import random
import re
import threading
import requests
import time
from common import generalUtils
from common.constants import mods
from common.log import logUtils as log
from common.ripple import userUtils
from constants import exceptions, slotStatuses, matchModModes, matchTeams, matchTeamTypes, matchScoringTypes
from common.constants import gameModes
from common.constants import privileges
from constants import serverPackets
from helpers import systemHelper
from objects import fokabot
from objects import glob
from helpers import chatHelper as chat
from common.web import cheesegull
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		# user online, silence both in db and with packet
		targetToken.silence(silenceTime, reason, userID)
	else:
		# User offline, silence user only in db
		userUtils.silence(targetUserID, silenceTime, reason, userID)

	# Log message
	msg = "{} has been silenced for the following reason: {}".format(target, reason)
	return msg

def removeSilence(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	# Send new silence end packet to user if he's online
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		# User online, remove silence both in db and with packet
		targetToken.silence(0, "", userID)
	else:
		# user offline, remove islene ofnlt from db
		userUtils.silence(targetUserID, 0, "", userID)

	return "{}'s silence reset".format(target)

def ban(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	# Set allowed to 0
	userUtils.ban(targetUserID)

	# Send ban packet to the user if he's online
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		targetToken.enqueue(serverPackets.loginBanned())

	log.rap(userID, "has banned {}".format(target), True)
	return "RIP {}. You will not be missed.".format(target)

def unban(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	# Set allowed to 1
	userUtils.unban(targetUserID)

	log.rap(userID, "has unbanned {}".format(target), True)
	return "Welcome back {}!".format(target)

def restrict(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	# Put this user in restricted mode
	userUtils.restrict(targetUserID)

	# Send restricted mode packet to this user if he's online
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		targetToken.setRestricted()

	log.rap(userID, "has put {} in restricted mode".format(target), True)
	return "Bye bye {}. See you later, maybe.".format(target)

def unrestrict(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	# Set allowed to 1
	userUtils.unrestrict(targetUserID)

	log.rap(userID, "has removed restricted mode from {}".format(target), True)
	return "Welcome back {}!".format(target)

def restartShutdown(restart):
	"""Restart (if restart = True) or shutdown (if restart = False) pep.py safely"""
	msg = "We are performing some maintenance. Bancho will {} in 5 seconds. Thank you for your patience.".format("restart" if restart else "shutdown")

	systemHelper.scheduleShutdown(5, restart, msg)