#include "PacketHandler.h" #include "BitStream.h" #include "DluAssert.h" #include #include #include void RaknetPacket::Serialize(RakNet::BitStream& bitStream) const { bitStream.Write(static_cast(messageID)); } bool RaknetPacket::Deserialize(RakNet::BitStream& bitStream) { uint8_t id; if (!bitStream.Read(id)) { return false; } messageID = static_cast(id); return true; } namespace PacketHandler { std::map()>> g_Handlers = { {ID_INTERNAL_PING, []() { return std::make_unique(); }}, {ID_PING, []() { return std::make_unique(); }}, {ID_PING_OPEN_CONNECTIONS, []() { return std::make_unique(); }}, {ID_CONNECTED_PONG, []() { return std::make_unique(); }}, {ID_CONNECTION_REQUEST, []() { return std::make_unique(); }}, {ID_SECURED_CONNECTION_RESPONSE, []() { return std::make_unique(); }}, {ID_SECURED_CONNECTION_CONFIRMATION, []() { return std::make_unique(); }}, {ID_RPC_MAPPING, []() { return std::make_unique(); }}, {ID_DETECT_LOST_CONNECTIONS, []() { return std::make_unique(); }}, {ID_OPEN_CONNECTION_REQUEST, []() { return std::make_unique(); }}, {ID_OPEN_CONNECTION_REPLY, []() { return std::make_unique(); }}, {ID_RPC, []() { return std::make_unique(); }}, {ID_RPC_REPLY, []() { return std::make_unique(); }}, {ID_OUT_OF_BAND_INTERNAL, []() { return std::make_unique(); }}, {ID_CONNECTION_REQUEST_ACCEPTED, []() { return std::make_unique(); }}, {ID_CONNECTION_ATTEMPT_FAILED, []() { return std::make_unique(); }}, {ID_ALREADY_CONNECTED, []() { return std::make_unique(); }}, {ID_NEW_INCOMING_CONNECTION, []() { return std::make_unique(); }}, {ID_NO_FREE_INCOMING_CONNECTIONS, []() { return std::make_unique(); }}, {ID_DISCONNECTION_NOTIFICATION, []() { return std::make_unique(); }}, {ID_CONNECTION_LOST, []() { return std::make_unique(); }}, {ID_RSA_PUBLIC_KEY_MISMATCH, []() { return std::make_unique(); }}, {ID_CONNECTION_BANNED, []() { return std::make_unique(); }}, {ID_INVALID_PASSWORD, []() { return std::make_unique(); }}, {ID_MODIFIED_PACKET, []() { return std::make_unique(); }}, {ID_TIMESTAMP, []() { return std::make_unique(); }}, {ID_PONG, []() { return std::make_unique(); }}, {ID_ADVERTISE_SYSTEM, []() { return std::make_unique(); }}, {ID_REMOTE_DISCONNECTION_NOTIFICATION, []() { return std::make_unique(); }}, {ID_REMOTE_CONNECTION_LOST, []() { return std::make_unique(); }}, {ID_REMOTE_NEW_INCOMING_CONNECTION, []() { return std::make_unique(); }}, {ID_DOWNLOAD_PROGRESS, []() { return std::make_unique(); }}, {ID_FILE_LIST_TRANSFER_HEADER, []() { return std::make_unique(); }}, {ID_FILE_LIST_TRANSFER_FILE, []() { return std::make_unique(); }}, {ID_DDT_DOWNLOAD_REQUEST, []() { return std::make_unique(); }}, {ID_TRANSPORT_STRING, []() { return std::make_unique(); }}, {ID_REPLICA_MANAGER_CONSTRUCTION, []() { return std::make_unique(); }}, {ID_REPLICA_MANAGER_DESTRUCTION, []() { return std::make_unique(); }}, {ID_REPLICA_MANAGER_SCOPE_CHANGE, []() { return std::make_unique(); }}, {ID_REPLICA_MANAGER_SERIALIZE, []() { return std::make_unique(); }}, {ID_REPLICA_MANAGER_DOWNLOAD_STARTED, []() { return std::make_unique(); }}, {ID_REPLICA_MANAGER_DOWNLOAD_COMPLETE, []() { return std::make_unique(); }}, {ID_CONNECTION_GRAPH_REQUEST, []() { return std::make_unique(); }}, {ID_CONNECTION_GRAPH_REPLY, []() { return std::make_unique(); }}, {ID_CONNECTION_GRAPH_UPDATE, []() { return std::make_unique(); }}, {ID_CONNECTION_GRAPH_NEW_CONNECTION, []() { return std::make_unique(); }}, {ID_CONNECTION_GRAPH_CONNECTION_LOST, []() { return std::make_unique(); }}, {ID_CONNECTION_GRAPH_DISCONNECTION_NOTIFICATION, []() { return std::make_unique(); }}, {ID_ROUTE_AND_MULTICAST, []() { return std::make_unique(); }}, {ID_RAKVOICE_OPEN_CHANNEL_REQUEST, []() { return std::make_unique(); }}, {ID_RAKVOICE_OPEN_CHANNEL_REPLY, []() { return std::make_unique(); }}, {ID_RAKVOICE_CLOSE_CHANNEL, []() { return std::make_unique(); }}, {ID_RAKVOICE_DATA, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_GET_CHANGELIST_SINCE_DATE, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_CREATION_LIST, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_DELETION_LIST, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_GET_PATCH, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_PATCH_LIST, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_REPOSITORY_FATAL_ERROR, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_FINISHED_INTERNAL, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_FINISHED, []() { return std::make_unique(); }}, {ID_AUTOPATCHER_RESTART_APPLICATION, []() { return std::make_unique(); }}, {ID_NAT_PUNCHTHROUGH_REQUEST, []() { return std::make_unique(); }}, {ID_NAT_TARGET_NOT_CONNECTED, []() { return std::make_unique(); }}, {ID_NAT_TARGET_CONNECTION_LOST, []() { return std::make_unique(); }}, {ID_NAT_CONNECT_AT_TIME, []() { return std::make_unique(); }}, {ID_NAT_SEND_OFFLINE_MESSAGE_AT_TIME, []() { return std::make_unique(); }}, {ID_NAT_IN_PROGRESS, []() { return std::make_unique(); }}, {ID_DATABASE_QUERY_REQUEST, []() { return std::make_unique(); }}, {ID_DATABASE_UPDATE_ROW, []() { return std::make_unique(); }}, {ID_DATABASE_REMOVE_ROW, []() { return std::make_unique(); }}, {ID_DATABASE_QUERY_REPLY, []() { return std::make_unique(); }}, {ID_DATABASE_UNKNOWN_TABLE, []() { return std::make_unique(); }}, {ID_DATABASE_INCORRECT_PASSWORD, []() { return std::make_unique(); }}, {ID_READY_EVENT_SET, []() { return std::make_unique(); }}, {ID_READY_EVENT_UNSET, []() { return std::make_unique(); }}, {ID_READY_EVENT_ALL_SET, []() { return std::make_unique(); }}, {ID_READY_EVENT_QUERY, []() { return std::make_unique(); }}, {ID_LOBBY_GENERAL, []() { return std::make_unique(); }}, {ID_AUTO_RPC_CALL, []() { return std::make_unique(); }}, {ID_AUTO_RPC_REMOTE_INDEX, []() { return std::make_unique(); }}, {ID_AUTO_RPC_UNKNOWN_REMOTE_INDEX, []() { return std::make_unique(); }}, {ID_RPC_REMOTE_ERROR, []() { return std::make_unique(); }}, {ID_USER_PACKET_ENUM, []() { return std::make_unique(); }}, }; void HandlePacket(RakNet::BitStream& inStream, const SystemAddress& sysAddr) { RaknetPacket data; if (!data.Deserialize(inStream)) { fprintf(stderr, "Error reading packet header\n"); return; } auto it = g_Handlers.find(data.messageID); if (it != g_Handlers.end()) { auto packet = it->second(); packet->sysAddr = sysAddr; if (!packet->Deserialize(inStream)) { fprintf(stderr, "Error reading packet data for message ID: %i\n", data.messageID); return; } packet->Handle(); } else { fprintf(stderr, "Unhandled packet with ID: %i\n", data.messageID); } } }