示例#1
0
    def socket_auth(cls, password=None):
        out('Authenticating...')
        result, err = super().socket_auth(password)
        if result:
            out('Auth: Successful')
            EventHandler.triggerEvent(EventHandler.E_RCON_CONNECTED)
        else:
            out('Auth: Failed. ', err)

        return result,err
示例#2
0
    def _parse_socket_data(cls,binary_string):
        """ Parses data from socket_read() and stores packet objects in cls.incoming_packets

        Recursive function. Handles multiple packets in one binary string
        """
        packet = SteamPacket.unpack(binary_string)
        packet.timestamp = time.time()

        if packet.keep_alive_packet:
            EventHandler.triggerEvent(EventHandler.E_KEEP_ALIVE)
            out('Keep alive')
        else:
            cls.incoming_packets.append(packet)

        if packet.remaining_data:
            cls._parse_socket_data(packet.remaining_data)
示例#3
0
    def _socket_read(cls, wait=False):
        result, err = super()._socket_read(wait)

        if result is False:
            if not cls.read_error_displayed:
                out('Error: {}'.format(err))
                cls.read_error_displayed = True
            return result, err

        if result:
            Storage.last_recv_packet = time.time()

        if cls.read_error_displayed:
            out('Socket reading restored.')
            cls.read_error_displayed = False

        EventHandler.triggerEvent(EventHandler.E_ANY_SERVER_RESPONSE)
        return result,err
示例#4
0
    def parse(packet):
        if packet.decoded["body"].strip() == 'No Players Connected':
            player_list = {}
        else:
            body = packet.decoded["body"].split("\n")
            
            rx = re.compile('[\d]+\. (?P<name>[^,]+), (?P<steamid>[\d]+)', re.IGNORECASE)
            player_list = {}
        
            for line in body:
                match = rx.search(line)
                if match is None: #empty string
                    continue
                
                steam_id = match.group("steamid")
                name = match.group("name")
                
                player_list[steam_id] = name
            
        connected_ids = set(player_list.keys()) - set(Storage.players_online_steam_name.keys())
        connected = {}
        for steam_id in connected_ids:
            connected[steam_id] = player_list[steam_id]
            if steam_id not in Storage.players_online_player_name:
                player = Db.find_player(steam_id=steam_id)
                if player and player.name:
                    Storage.players_online_player_name[steam_id] = player.name
                else:
                    Storage.players_online_player_name[steam_id] = ""
        
        disconnected_ids = set(Storage.players_online_steam_name.keys()) - set(player_list.keys())
        disconnected = {}
        for steam_id in disconnected_ids:
            disconnected[steam_id] = Storage.players_online_steam_name[steam_id]
        
        Storage.players_online_steam_name = player_list
        
        if len(connected):
            for steam_id in connected:
                name = Storage.players_online_steam_name[steam_id]
                player = Db.find_player(name,steam_id)
                if player is None:
                    EventHandler.triggerEvent(EventHandler.E_NEW_PLAYER, steam_id, name)

            EventHandler.triggerEvent(EventHandler.E_CONNECT, connected)
            
        if len(disconnected):
            EventHandler.triggerEvent(EventHandler.E_DISCONNECT, disconnected)
            
            
        return connected,disconnected,Storage.players_online_steam_name
示例#5
0
文件: rcon.py 项目: LDMBatman/pyarc
 def reconnect(cls):
     EventHandler.triggerEvent(EventHandler.E_DISCONNECT, Storage.players_online_steam_name)
     Storage.players_online_steam_name = {}
     super().reconnect()
示例#6
0
def init():
    EventHandler.registerEvent(EventHandler.E_KEEP_ALIVE,EventOther.keep_alive)
    EventHandler.registerEvent(EventHandler.E_ANY_SERVER_RESPONSE,EventOther.server_last_response)

    # event_playerlist.py
    EventHandler.registerEvent(EventHandler.E_CONNECT,EventsPlayerlist.players_connected)
    EventHandler.registerEvent(EventHandler.E_CONNECT,EventsPlayerlist.update_gui_listplayers)
    EventHandler.registerEvent(EventHandler.E_CONNECT,EventsPlayerlist.welcome_message)
    EventHandler.registerEvent(EventHandler.E_CONNECT,EventsPlayerlist.notify_player_sever_restart)

    EventHandler.registerEvent(EventHandler.E_DISCONNECT,EventsPlayerlist.update_gui_listplayers)
    EventHandler.registerEvent(EventHandler.E_DISCONNECT,EventsPlayerlist.upload_to_web_players_online)
    EventHandler.registerEvent(EventHandler.E_CONNECT,EventsPlayerlist.upload_to_web_players_online)

    EventHandler.registerEvent(EventHandler.E_DISCONNECT,EventsPlayerlist.players_disconnected)

    # event_chat.py
    EventHandler.registerEvent(EventHandler.E_CHAT,EventChat.output_chat)
    #EventHandler.registerEvent(EventHandler.E_CHAT,EventChat.store_chat)
    EventHandler.registerEvent(EventHandler.E_CHAT,EventChat.update_player_name)
    EventHandler.registerEvent(EventHandler.E_CHAT,EventChat.parse_chat_command)


    # event_other.py
    EventHandler.registerEvent(EventHandler.E_RCON_CONNECTED,EventOther.get_version)
    EventHandler.registerEvent(EventHandler.E_RCON_CONNECTED,EventOther.store_settings_to_db)
    EventHandler.registerEvent(EventHandler.E_RCON_CONNECTED,EventOther.check_savegame_integrity)

    EventHandler.registerEvent(EventHandler.E_NEW_ARK_VERSION,EventOther.new_ark_version)
    EventHandler.registerEvent(EventHandler.E_NEW_PLAYER,EventOther.add_player_to_database)
示例#7
0
    def parse(packet):
        """Returns parsed chat data from packet.
        
        Triggers Events.E_CHAT for each line. Arguments: steam_name, player_name, text, line
        
        Syntax per line is: Steam Name (Ingame Name): Text
        
        The return of this function is useful for unit tests.
        
        Returns:
            List: Items are one dictionary per line with keys:
                steam_name, player_name, text, line
                
        """
        results = []
        
        #if packet.decoded['type'] == 0:
        if packet.decoded['body'].lower().strip() == 'server received, but no response!!':
            debug_out("No new chat data.",level=3)
        else:
            latest_chat = packet.decoded['body'].split("\n")
            latest_chat.reverse()
            line_breaks = ''
            for line in latest_chat:
                line = line.strip()
                if len(line):
                    regex_server_msg = re.compile('^SERVER: (?P<line>[^\n]+)', re.IGNORECASE)
                    regex_player_msg = re.compile('^(?P<steam_name>.+) \((?P<player_name>[^:]+)\): (?P<line>[^\n]+)')
                    
                    server = regex_server_msg.search(line)
                    player = regex_player_msg.search(line)
                    
                    if server is not None:
                        steam_name = 'SERVER'
                        player_name = 'SERVER'
                        text = server.group('line')
                        if line_breaks:
                            text += '\n' + line_breaks
                            line += '\n' + line_breaks
                            line_breaks = ''

                        EventHandler.triggerEvent(EventHandler.E_CHAT_FROM_SERVER, text, line)
                    elif player is not None:
                        steam_name = player.group('steam_name')
                        player_name = player.group('player_name')
                        text = player.group('line')
                        if line_breaks:
                            text += '\n' + line_breaks
                            line += '\n' + line_breaks
                            line_breaks = ''

                        EventHandler.triggerEvent(EventHandler.E_CHAT, steam_name, player_name, text, line)
                    else:
                        line_breaks += line + '\n'
                        continue
                        #Process line break in a message.
                
                    
                    result = {
                        'steam_name': steam_name,
                        'player_name': player_name,
                        'text': text.strip(),
                        'line': line.strip(),
                    }
                    results.append(result)

        results.reverse()
        return results
示例#8
0
 def run():
     if ServerControl.new_version() is True:
         EventHandler.triggerEvent(EventHandler.E_NEW_ARK_VERSION)
     else:
         debug_out('No server update available',level=3)