#include "dCommonVars.h" #include "WorldPackets.h" #include "BitStream.h" #include "dMessageIdentifiers.h" #include "PacketUtils.h" #include "GeneralUtils.h" #include "User.h" #include "Character.h" #include "dLogger.h" #include #include "Game.h" #include "LDFFormat.h" #include "dServer.h" #include "dZoneManager.h" #include "ZCompression.h" void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_LOAD_STATIC_ZONE); auto zone = dZoneManager::Instance()->GetZone()->GetZoneID(); bitStream.Write(static_cast(zone.GetMapID())); bitStream.Write(static_cast(zone.GetInstanceID())); //bitStream.Write(static_cast(zone.GetCloneID())); bitStream.Write(0); bitStream.Write(checksum); bitStream.Write(static_cast(0)); // ?? bitStream.Write(x); bitStream.Write(y); bitStream.Write(z); bitStream.Write(static_cast(0)); // Change this to eventually use 4 on activity worlds SEND_PACKET } void WorldPackets::SendCharacterList ( const SystemAddress& sysAddr, User* user ) { if (!user) return; RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_LIST_RESPONSE); std::vector characters = user->GetCharacters(); bitStream.Write(static_cast(characters.size())); bitStream.Write(static_cast(0)); //character index in front, just picking 0 for (uint32_t i = 0; i < characters.size(); ++i) { bitStream.Write(characters[i]->GetObjectID()); bitStream.Write(static_cast(0)); PacketUtils::WriteWString(bitStream, characters[i]->GetName(), 33); PacketUtils::WriteWString(bitStream, characters[i]->GetUnapprovedName(), 33); bitStream.Write(static_cast(characters[i]->GetNameRejected())); bitStream.Write(static_cast(false)); PacketUtils::WriteString(bitStream, "", 10); bitStream.Write(characters[i]->GetShirtColor()); bitStream.Write(characters[i]->GetShirtStyle()); bitStream.Write(characters[i]->GetPantsColor()); bitStream.Write(characters[i]->GetHairStyle()); bitStream.Write(characters[i]->GetHairColor()); bitStream.Write(characters[i]->GetLeftHand()); bitStream.Write(characters[i]->GetRightHand()); bitStream.Write(characters[i]->GetEyebrows()); bitStream.Write(characters[i]->GetEyes()); bitStream.Write(characters[i]->GetMouth()); bitStream.Write(static_cast(0)); bitStream.Write(static_cast(characters[i]->GetZoneID())); bitStream.Write(static_cast(characters[i]->GetZoneInstance())); bitStream.Write(characters[i]->GetZoneClone()); bitStream.Write(characters[i]->GetLastLogin()); const auto& equippedItems = characters[i]->GetEquippedItems(); bitStream.Write(static_cast(equippedItems.size())); for (uint32_t j = 0; j < equippedItems.size(); ++j) { bitStream.Write(equippedItems[j]); } } SEND_PACKET } void WorldPackets::SendCharacterCreationResponse ( const SystemAddress& sysAddr, eCreationResponse response ) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_CREATE_RESPONSE); bitStream.Write(response); SEND_PACKET } void WorldPackets::SendCharacterRenameResponse ( const SystemAddress& sysAddr, eRenameResponse response ) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_RENAME_RESPONSE); bitStream.Write(response); SEND_PACKET } void WorldPackets::SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_DELETE_CHARACTER_RESPONSE); bitStream.Write(static_cast(response)); SEND_PACKET } void WorldPackets::SendTransferToWorld ( const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift ) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_TRANSFER_TO_WORLD); PacketUtils::WriteString(bitStream, serverIP, 33); bitStream.Write(static_cast(serverPort)); bitStream.Write(static_cast(mythranShift)); SEND_PACKET } void WorldPackets::SendServerState ( const SystemAddress& sysAddr ) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_SERVER_STATES); bitStream.Write(static_cast(1)); //If the server is receiving this request, it probably is ready anyway. SEND_PACKET } void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, const LWOOBJID& objectID, const std::string& xmlData, const std::u16string& username, int32_t gm) { RakNet::BitStream bitStream; PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CREATE_CHARACTER); RakNet::BitStream data; data.Write(6); //LDF key count LDFData* objid = new LDFData(u"objid", objectID); LDFData* lot = new LDFData(u"template", 1); LDFData * xmlConfigData = new LDFData(u"xmlData", xmlData); LDFData* name = new LDFData(u"name", username); LDFData* gmlevel = new LDFData(u"gmlevel", gm); LDFData* chatmode = new LDFData(u"chatmode", gm); objid->WriteToPacket(&data); lot->WriteToPacket(&data); name->WriteToPacket(&data); gmlevel->WriteToPacket(&data); chatmode->WriteToPacket(&data); xmlConfigData->WriteToPacket(&data); delete objid; delete lot; delete xmlConfigData; delete gmlevel; delete chatmode; delete name; #ifdef _WIN32 bitStream.Write(data.GetNumberOfBytesUsed() + 1); bitStream.Write(0); bitStream.Write((char*)data.GetData(), data.GetNumberOfBytesUsed()); #else //Compress the data before sending: const int reservedSize = 5 * 1024 * 1024; uint8_t compressedData[reservedSize]; size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData, reservedSize); bitStream.Write(size + 9); //size of data + header bytes (8) bitStream.Write(1); //compressed boolean, true bitStream.Write(data.GetNumberOfBytesUsed()); bitStream.Write(size); for (size_t i = 0; i < size; i++) bitStream.Write(compressedData[i]); #endif PacketUtils::SavePacket("chardata.bin", (const char *)bitStream.GetData(), static_cast(bitStream.GetNumberOfBytesUsed())); SEND_PACKET Game::logger->Log("WorldPackets", "Sent CreateCharacter for ID: %llu\n", objectID); } void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::unordered_map unacceptedItems) { CBITSTREAM PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHAT_MODERATION_STRING); bitStream.Write(static_cast(requestAccepted)); bitStream.Write(static_cast(0)); bitStream.Write(static_cast(requestID)); bitStream.Write(static_cast(0)); for (uint32_t i = 0; i < 33; ++i) { bitStream.Write(static_cast(receiver[i])); } for (std::unordered_map::iterator it = unacceptedItems.begin(); it != unacceptedItems.end(); ++it) { bitStream.Write(it->first); bitStream.Write(it->second); } SEND_PACKET } void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, uint8_t highestLevel, uint8_t prevLevel, uint8_t newLevel) { CBITSTREAM PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_MAKE_GM_RESPONSE); bitStream.Write(success); bitStream.Write(highestLevel); bitStream.Write(prevLevel); bitStream.Write(newLevel); SEND_PACKET }