Beispiel #1
0
def fokabot_reconnect(fro, chan, message):
    # Check if fokabot is already connected
    if glob.tokens.getTokenFromUserID(999) is not None:
        return "{} is already connected to Bancho".format(glob.BOT_NAME)

    # Fokabot is not connected, connect it
    fokabot.connect()
    return False
Beispiel #2
0
def fokabotReconnect(fro, chan, message):
    # Check if fokabot is already connected
    if glob.tokens.getTokenFromUserID(999) is not None:
        return "Fokabot is already connected to Bancho"

    # Fokabot is not connected, connect it
    fokabot.connect()
    return False
Beispiel #3
0
                bcolors.RED)

        try:
            consoleHelper.printNoNl("> Loading chat filters... ")
            glob.chatFilters = chatFilters.chatFilters()
            consoleHelper.printDone()
        except:
            consoleHelper.printError()
            consoleHelper.printColored(
                "[!] Error while loading chat filters. Make sure there is a filters.txt file present",
                bcolors.RED)
            raise

        # Start fokabot
        consoleHelper.printNoNl("> Connecting FokaBot... ")
        fokabot.connect()
        consoleHelper.printDone()

        # Initialize chat channels
        print("> Initializing chat channels... ")
        glob.channels.loadChannels()
        consoleHelper.printDone()

        # Initialize stremas
        consoleHelper.printNoNl("> Creating packets streams... ")
        glob.streams.add("main")
        glob.streams.add("lobby")
        consoleHelper.printDone()

        # Initialize user timeout check loop
        consoleHelper.printNoNl("> Initializing user timeout check loop... ")
Beispiel #4
0
def main():
    """A main function to execute code."""
    try:
        # Server start
        consoleHelper.printServerStartHeader(True)

        # Create data folder if needed
        log.info("Checking folders... ")
        paths = (".data", )
        for i in paths:
            if not os.path.exists(i):
                os.makedirs(i, 0o770)
        log.info("Complete!")

        # Connect to db and redis
        try:
            log.info("Connecting to MySQL database... ")
            glob.db = dbConnector.db(glob.config.DB_HOST,
                                     glob.config.DB_USERNAME,
                                     glob.config.DB_PASSWORD,
                                     glob.config.DB_DATABASE,
                                     glob.config.DB_WORKERS)

            log.info("Connecting to redis... ")
            glob.redis = redis.Redis(glob.config.REDIS_HOST,
                                     glob.config.REDIS_PORT,
                                     glob.config.REDIS_DB,
                                     glob.config.REDIS_PASSWORD)
            glob.redis.ping()
        except Exception:
            # Exception while connecting to db
            log.error(
                "Error while connection to database and redis. Please ensure your config and try again."
            )

        # Empty redis cache
        try:
            glob.redis.set("ripple:online_users", 0)
            glob.redis.eval(
                "return redis.call('del', unpack(redis.call('keys', ARGV[1])))",
                0, "peppy:*")
        except redis.exceptions.ResponseError:
            # Script returns error if there are no keys starting with peppy:*
            pass

        # Save peppy version in redis
        glob.redis.set("peppy:version", glob.__version__)

        # Load bancho_settings
        try:
            log.info("Loading bancho settings from DB... ")
            glob.banchoConf = banchoConfig.banchoConfig()
            log.info("Complete!")
        except:
            log.error(
                "Error while loading bancho_settings. Please make sure the table in DB has all the required rows"
            )
            raise

        # Delete old bancho sessions
        log.info("Deleting cached bancho sessions from DB... ")
        glob.tokens.deleteBanchoSessions()
        log.info("Complete!")

        # Create threads pool
        try:
            log.info("Creating threads pool... ")
            glob.pool = ThreadPool(glob.config.THREADS_COUNT)
            log.info("Complete!")
        except ValueError:
            log.error(
                "Error while creating threads pool. Please check your config.ini and run the server again"
            )

        # Start fokabot
        log.info("Connecting RealistikBot...")
        fokabot.connect()
        log.info("Complete!")

        # Initialize chat channels
        log.info("Initializing chat channels... ")
        glob.channels.loadChannels()
        log.info("Complete!")

        # Initialize stremas
        log.info("Creating packets streams... ")
        glob.streams.add("main")
        glob.streams.add("lobby")
        log.info("Complete!")

        # Initialize user timeout check loop
        log.info("Initializing user timeout check loop... ")
        glob.tokens.usersTimeoutCheckLoop()
        log.info("Complete!")

        # Initialize spam protection reset loop
        log.info("Initializing spam protection reset loop... ")
        glob.tokens.spamProtectionResetLoop()
        log.info("Complete!")

        # Initialize multiplayer cleanup loop
        log.info("Initializing multiplayer cleanup loop... ")
        glob.matches.cleanupLoop()
        log.info("Complete!")

        # Debug mode
        glob.debug = DEBUG
        if glob.debug: log.warning("Server running in debug mode!")

        # Make app
        glob.application = make_app()

        # Server start message and console output
        log.info(
            f"pep.py listening for HTTP(s) clients on 127.0.0.1:{glob.config.PORT}..."
        )

        # Connect to pubsub channels
        pubSub.listener(
            glob.redis, {
                "peppy:disconnect":
                disconnectHandler.handler(),
                "peppy:change_username":
                changeUsernameHandler.handler(),
                "peppy:reload_settings":
                lambda x: x == b"reload" and glob.banchoConf.reload(),
                "peppy:update_cached_stats":
                updateStatsHandler.handler(),
                "peppy:silence":
                updateSilenceHandler.handler(),
                "peppy:ban":
                banHandler.handler(),
                "peppy:notification":
                notificationHandler.handler(),
                "peppy:set_main_menu_icon":
                setMainMenuIconHandler.handler(),
                "peppy:refresh_privs":
                refreshPrivsHandler.handler(),
                "peppy:change_pass":
                changePassword.handler(),
                "peppy:bot_msg":
                bot_msg_handler.handler()
            }).start()

        # We will initialise namespace for fancy stuff. UPDATE: F**K OFF WEIRD PYTHON MODULE.
        glob.namespace = globals() | {
            mod: __import__(mod)
            for mod in sys.modules if mod != "glob"
        }

        # Start tornado
        glob.application.listen(glob.config.PORT)
        tornado.ioloop.IOLoop.instance().start()
    finally:
        system.dispose()