def socket_auth(cls, password=None): """Authenticate to Steam Server Args: If password is None it will use password supplied in connect Returns: bool, error message """ if password is None: password = cls.password packet = SteamPacket.pack(password, 3) cls.socket_send(packet) # Important to use _socket_send_packet. Do not want this queued or you might end up with endless reconnects result = cls._socket_read(True) if result is None: return False, 'No reply' for response in cls.incoming_packets: if response.packet_id == packet.packet_id: cls.incoming_packets.remove(response) cls.is_connected = True return True, None if response.packet_id == -1: return False, 'Failed. Wrong password?' return False, 'No response to auth packet'
def send(cls, data, response_callback=None, priority=False): packet = SteamPacket.pack(data, 2) packet.response_callback = response_callback if priority: cls.outgoing_queue.appendleft(packet) else: cls.outgoing_queue.append(packet)
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: out('Keep alive') else: cls.incoming_packets.append(packet) if packet.remaining_data: cls._parse_socket_data(packet.remaining_data)
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: out('Keep alive') else: cls.incoming_packets.append(packet) if packet.remaining_data: cls._parse_socket_data(packet.remaining_data)