Ejemplo n.º 1
0
def init():
    # Config.show_keep_alive_after_idle = 1
    Config = Factory.get('Config')
    Lang = Factory.get('Translation')
    try:
        Config.printSettings()
        Db.init()

        if not ServerControl.is_server_running():
            out(Lang.get('server_not_running'))
            ServerControl.start_server()

        custom_import(Config.events_config, 'events')  #Load events

        Rcon.init(Config.rcon_host, Config.rcon_port, Config.query_port,
                  Config.rcon_password, Config.rcon_socket_timeout)

        InputHandler.init()  #Activate listening for terminal input

        #custom_import(Config.events_config,'input') #Load terminal input configuration
        custom_import(Config.tasks_config, 'tasks')  #Load tasks

        # Prevent threads from dying due to early main completed execution.
        while True:
            if Storage.terminate_application is True:
                exit()
            time.sleep(1)  # Important part of not being a CPU hog.

    except KeyboardInterrupt:
        Storage.terminate_application = True
Ejemplo n.º 2
0
def init():
    # Config.show_keep_alive_after_idle = 1
    Config = Factory.get('Config')
    Lang = Factory.get('Translation')
    try:
        Config.printSettings()
        Db.init()

        if not ServerControl.is_server_running():
            out(Lang.get('server_not_running'))
            ServerControl.start_server()

        custom_import(Config.events_config,'events') #Load events

        Rcon.init(Config.rcon_host, Config.rcon_port, Config.query_port, Config.rcon_password, Config.rcon_socket_timeout)

        InputHandler.init() #Activate listening for terminal input

        #custom_import(Config.events_config,'input') #Load terminal input configuration
        custom_import(Config.tasks_config,'tasks') #Load tasks

        # Prevent threads from dying due to early main completed execution.
        while True:
            if Storage.terminate_application is True:
                exit()
            time.sleep(1)  # Important part of not being a CPU hog.

    except KeyboardInterrupt:
        Storage.terminate_application = True
Ejemplo n.º 3
0
    def reconnect(cls):
        cls.is_reconnecting = True
        cls.is_connected = False
        cls.close_socket()
        cls.incoming_packets.clear()
        if not ServerControl.is_server_running():
            out('Waiting for connection to query port.')
            while not ServerControl.is_server_running():
                time.sleep(1)
            out('Query successful.')

        result, err = cls.socket_connect(cls.socket_host, cls.socket_port, cls.socket_query_port, cls.password, cls.socket_timeout)
        while not result:
            out('Retrying reconnect in {}s'.format(Config.reconnect_wait))
            time.sleep(Config.reconnect_wait)
            result, err = cls.socket_connect(cls.socket_host, cls.socket_port, cls.socket_query_port, cls.password, cls.socket_timeout)

        cls.is_reconnecting = False
Ejemplo n.º 4
0
    def socket_connect(cls, host, port, query_port, password=None, timeout=None):
        if not ServerControl.is_server_running():
            out('Waiting for connection to query port.')
            while not ServerControl.is_server_running():
                time.sleep(1)
            out('Query successful.')

        out('Connecting to {}:{}...'.format(host, port))
        cls.timestamp_transmission_opened = time.time()
        result, err = super().socket_connect(host, port, query_port, password, timeout)
        if result:
            out('Connected!')
            result, err = cls.socket_auth(password)
            if not result:
                return result, err
        else:
            out('Unable to connect: ', err)

        return result, err
Ejemplo n.º 5
0
    def socket_connect(cls, host, port, query_port, password=None, timeout=None):
        if not ServerControl.is_server_running():
            out('Waiting for connection to query port.')
            while not ServerControl.is_server_running():
                time.sleep(1)
            out('Query successful.')

        out('Connecting to {}:{}...'.format(host, port))
        cls.timestamp_transmission_opened = time.time()
        result, err = super().socket_connect(host, port, query_port, password, timeout)
        if result:
            out('Connected!')
            result, err = cls.socket_auth(password)
            if not result:
                return result, err
        else:
            out('Unable to connect: ', err)

        return result, err
Ejemplo n.º 6
0
    def reconnect(cls):
        cls.is_reconnecting = True
        cls.is_connected = False
        cls.close_socket()
        cls.incoming_packets.clear()
        if not ServerControl.is_server_running():
            out('Waiting for connection to query port.')
            while not ServerControl.is_server_running():
                time.sleep(1)
            out('Query successful.')

        result, err = cls.socket_connect(cls.socket_host, cls.socket_port,
                                         cls.socket_query_port, cls.password,
                                         cls.socket_timeout)
        while not result:
            out('Retrying reconnect in {}s'.format(Config.reconnect_wait))
            time.sleep(Config.reconnect_wait)
            result, err = cls.socket_connect(cls.socket_host, cls.socket_port,
                                             cls.socket_query_port,
                                             cls.password, cls.socket_timeout)

        cls.is_reconnecting = False