#include #include #include "pso/forward.h" #include "pso/macros.h" #include "pso/TArray.h" #include "pso/TMainTask.h" #include "pso/TMenuList.h" #include "pso/TPlyCharData.h" #include "pso/TPlyDispData.h" #include "pso/TPlyInventory.h" #include "pso/TObject.h" #include "pso/TProtocol.h" #include "pso/TSocket.h" OBJECT_NAME(TProtocol); packet *server_packet = nullptr; void copy_packet(struct packet *pkt) { } int TProtocol::handle_command(struct packet *pkt) { } void TProtocol::parse_packet() { // This is needed to match, either that or cast the sizeof to an int. const int max_packet_size = sizeof(struct packet); while (!is_empty()) { m_packet.bytes[m_packet_offset++] = next(); if (m_packet_offset == sizeof(packet_header)) { if (m_is_encrypted) { m_recv_crypt.encrypt(&m_packet.pkt.header, sizeof(packet_header)); } } // NOTE: The `const int &` is required here to match. // Convert packet size to native endian. const int &packet_size = m_packet_size = to_be_uint16_t(m_packet.pkt.header.size); // Is the packet size invalid? if (packet_size > max_packet_size || !packet_size) { m_packet_size = 0; m_packet_offset = 0; m_is_invalid_packet = true; break; // Do we have the rest of the packet yet? } else if (m_packet_size > 0 && m_packet_offset >= m_packet_size) { // Decrypt it if necessary. if (m_is_encrypted) { m_recv_crypt.encrypt(&m_packet.pkt.data, m_packet_size-sizeof(packet_header)); } struct packet *pkt = &m_packet; m_packet_size = 0; m_packet_offset = 0; if (m_handle_pings_only) { if (pkt->pkt.header.command == 0x1d) { if (!handle_command(pkt)) { continue; } else { break; } } else { copy_packet(pkt); } } else if (handle_command(pkt)) { break; } } } } short TProtocol::send(u8 *data, size_t size) { return TTcpSocket::send(data, size); } void TProtocol::run_task() { TTcpSocket::some_stub(); some_stub(); if (m_is_invalid_packet) { close(); m_is_encrypted = 0; m_connected = 0; m_packet_offset = 0; m_packet_size = 0; } else if (!m_buffer_cleared) { server_packet = &m_packet; parse_packet(); recv(); } } TProtocol::~TProtocol() { } #define fill_with(name, value) memset(&m_##name, value, sizeof(m_##name)) #define copy(name) strncpy(m_##name.m_data, name, sizeof(m_##name.m_data)) TProtocol::TProtocol(TObject *parent, u16 sub_version, int language, char *serial_number, char *access_key, char *password) : TTcpSocket(parent) { u8 thing[6]; m_name = TProtocol_name; memset(thing, 0, sizeof(thing)); { int i = 0; int j = 0; m_smth.m_smth.m_data[i++] = 0; m_smth.m_smth.m_data[i++] = 0; m_smth.m_smth.m_data[i++] = thing[j++]; m_smth.m_smth.m_data[i++] = thing[j++]; i = 0; m_smth.m_smth1.m_data[i++] = thing[j++]; m_smth.m_smth1.m_data[i++] = thing[j++]; m_smth.m_smth1.m_data[i++] = thing[j++]; m_smth.m_smth1.m_data[i++] = thing[j++]; } m_guildcard_tag = TPlyGuildCardTag(-1, -1); m_login_response_state = 0; m_connected = 0; m_joined_game = 0; m_has_meet_user_settings = 0; m_handle_pings_only = false; m_entry_count = 0; m_unused = 0; m_lobby_list_count = 0; m_unused5.m_data[0] = 0; m_unused2 = 0; m_udp_disabled = 0; m_packet_offset = 0; m_packet_size = 0; m_sub_version = sub_version; m_language = language; fill_with(serial_number, 0); fill_with(access_key, 0); fill_with(password, 0); copy(serial_number); copy(access_key); copy(password); fill_with(client_config, 0); m_recv_handlers.m_data[0] = nullptr; m_recv_handlers.m_data[1] = nullptr; m_recv_handlers.m_data[2] = nullptr; m_recv_handlers.m_data[3] = nullptr; m_recv_handlers.m_data[4] = nullptr; m_recv_handlers.m_data[6] = nullptr; m_recv_handlers.m_data[7] = nullptr; m_recv_handlers.m_data[8] = nullptr; m_recv_handlers.m_data[10] = nullptr; m_recv_handlers.m_data[11] = nullptr; m_recv_handlers.m_data[12] = nullptr; m_recv_handlers.m_data[13] = nullptr; m_recv_handlers.m_data[14] = nullptr; m_recv_handlers.m_data[36] = nullptr; m_recv_handlers.m_data[15] = nullptr; m_recv_handlers.m_data[16] = nullptr; m_recv_handlers.m_data[17] = nullptr; m_recv_handlers.m_data[18] = nullptr; m_recv_handlers.m_data[19] = nullptr; m_recv_handlers.m_data[20] = nullptr; m_recv_handlers.m_data[22] = nullptr; m_recv_handlers.m_data[23] = nullptr; m_recv_handlers.m_data[25] = nullptr; m_recv_handlers.m_data[26] = nullptr; m_recv_handlers.m_data[33] = nullptr; m_recv_handlers.m_data[34] = nullptr; m_recv_handlers.m_data[35] = nullptr; m_recv_handlers.m_data[36] = nullptr; m_recv_handlers.m_data[37] = nullptr; m_recv_handlers.m_data[38] = nullptr; m_recv_handlers.m_data[41] = nullptr; m_recv_handlers.m_data[28] = nullptr; m_recv_handlers.m_data[43] = nullptr; m_recv_handlers.m_data[42] = nullptr; m_recv_handlers.m_data[44] = nullptr; m_recv_handlers.m_data[45] = nullptr; m_recv_handlers.m_data[46] = nullptr; m_recv_handlers.m_data[49] = nullptr; m_recv_handlers.m_data[50] = nullptr; m_recv_handlers.m_data[51] = nullptr; m_recv_handlers.m_data[32] = nullptr; m_recv_handlers.m_data[47] = nullptr; m_recv_handlers.m_data[48] = nullptr; } #undef fill_with #undef copy