2021-12-05 17:54:36 +00:00
|
|
|
#include "WorldPackets.h"
|
2024-01-07 07:05:57 +00:00
|
|
|
#include "dCommonVars.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "BitStream.h"
|
|
|
|
#include "GeneralUtils.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Game.h"
|
|
|
|
#include "LDFFormat.h"
|
|
|
|
#include "dServer.h"
|
|
|
|
#include "ZCompression.h"
|
2023-05-03 21:38:32 +00:00
|
|
|
#include "eConnectionType.h"
|
2023-09-21 01:06:28 +00:00
|
|
|
#include "BitStreamUtils.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-07 07:05:57 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone) {
|
2022-07-28 13:39:57 +00:00
|
|
|
RakNet::BitStream bitStream;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::LOAD_STATIC_ZONE);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-12-24 00:11:00 +00:00
|
|
|
bitStream.Write<uint16_t>(zone.GetMapID());
|
|
|
|
bitStream.Write<uint16_t>(zone.GetInstanceID());
|
|
|
|
//bitStream.Write<uint32_t>(zone.GetCloneID());
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(0);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bitStream.Write(checksum);
|
2023-12-24 00:11:00 +00:00
|
|
|
bitStream.Write<uint16_t>(0); // ??
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bitStream.Write(x);
|
|
|
|
bitStream.Write(y);
|
|
|
|
bitStream.Write(z);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-24 00:11:00 +00:00
|
|
|
bitStream.Write<uint32_t>(0); // Change this to eventually use 4 on activity worlds
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
void WorldPackets::SendCharacterCreationResponse(const SystemAddress& sysAddr, eCharacterCreationResponse response) {
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream bitStream;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHARACTER_CREATE_RESPONSE);
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(response);
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void WorldPackets::SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response) {
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream bitStream;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHARACTER_RENAME_RESPONSE);
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(response);
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WorldPackets::SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response) {
|
2022-07-28 13:39:57 +00:00
|
|
|
RakNet::BitStream bitStream;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::DELETE_CHARACTER_RESPONSE);
|
2023-12-24 00:11:00 +00:00
|
|
|
bitStream.Write<uint8_t>(response);
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void WorldPackets::SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift) {
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream bitStream;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::TRANSFER_TO_WORLD);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-09-21 01:06:28 +00:00
|
|
|
bitStream.Write(LUString(serverIP));
|
2023-12-24 00:11:00 +00:00
|
|
|
bitStream.Write<uint16_t>(serverPort);
|
|
|
|
bitStream.Write<uint8_t>(mythranShift);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void WorldPackets::SendServerState(const SystemAddress& sysAddr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
RakNet::BitStream bitStream;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::SERVER_STATES);
|
2023-12-24 00:11:00 +00:00
|
|
|
bitStream.Write<uint8_t>(1); //If the server is receiving this request, it probably is ready anyway.
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-01-07 07:05:57 +00:00
|
|
|
void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm) {
|
2022-07-28 13:39:57 +00:00
|
|
|
RakNet::BitStream bitStream;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CREATE_CHARACTER);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
RakNet::BitStream data;
|
|
|
|
data.Write<uint32_t>(7); //LDF key count
|
|
|
|
|
2024-01-07 07:05:57 +00:00
|
|
|
std::unique_ptr<LDFData<LWOOBJID>> objid(new LDFData<LWOOBJID>(u"objid", player));
|
|
|
|
std::unique_ptr<LDFData<LOT>> lot(new LDFData<LOT>(u"template", 1));
|
|
|
|
std::unique_ptr<LDFData<std::string>> xmlConfigData(new LDFData<std::string>(u"xmlData", xmlData));
|
|
|
|
std::unique_ptr<LDFData<std::u16string>> name(new LDFData<std::u16string>(u"name", username));
|
|
|
|
std::unique_ptr<LDFData<int32_t>> gmlevel(new LDFData<int32_t>(u"gmlevel", static_cast<int32_t>(gm)));
|
|
|
|
std::unique_ptr<LDFData<int32_t>> chatmode(new LDFData<int32_t>(u"chatmode", static_cast<int32_t>(gm)));
|
|
|
|
std::unique_ptr<LDFData<int64_t>> reputationLdf(new LDFData<int64_t>(u"reputation", reputation));
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-26 14:15:29 +00:00
|
|
|
objid->WriteToPacket(data);
|
|
|
|
lot->WriteToPacket(data);
|
|
|
|
name->WriteToPacket(data);
|
|
|
|
gmlevel->WriteToPacket(data);
|
|
|
|
chatmode->WriteToPacket(data);
|
|
|
|
xmlConfigData->WriteToPacket(data);
|
|
|
|
reputationLdf->WriteToPacket(data);
|
2022-03-31 23:12:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
//Compress the data before sending:
|
2022-09-06 03:28:47 +00:00
|
|
|
const uint32_t reservedSize = ZCompression::GetMaxCompressedLength(data.GetNumberOfBytesUsed());
|
|
|
|
uint8_t* compressedData = new uint8_t[reservedSize];
|
|
|
|
|
|
|
|
// TODO There should be better handling here for not enough memory...
|
|
|
|
if (!compressedData) return;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData, reservedSize);
|
|
|
|
|
2022-09-06 03:28:47 +00:00
|
|
|
assert(size <= reservedSize);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bitStream.Write<uint32_t>(size + 9); //size of data + header bytes (8)
|
|
|
|
bitStream.Write<uint8_t>(1); //compressed boolean, true
|
|
|
|
bitStream.Write<uint32_t>(data.GetNumberOfBytesUsed());
|
|
|
|
bitStream.Write<uint32_t>(size);
|
|
|
|
|
2022-09-06 03:28:47 +00:00
|
|
|
/**
|
|
|
|
* In practice, this warning serves no purpose for us. We allocate the max memory needed on the heap
|
|
|
|
* and then compress the data. In the off chance that the compression actually increases the size,
|
|
|
|
* an assertion is done to prevent bad data from being saved or sent.
|
|
|
|
*/
|
|
|
|
#pragma warning(disable:6385) // C6385 Reading invalid data from 'compressedData'.
|
2024-01-07 07:05:57 +00:00
|
|
|
bitStream.WriteAlignedBytes(compressedData, size);
|
2022-09-06 03:28:47 +00:00
|
|
|
#pragma warning(default:6385)
|
2021-12-07 11:12:29 +00:00
|
|
|
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2022-09-06 03:28:47 +00:00
|
|
|
delete[] compressedData;
|
2024-01-07 07:05:57 +00:00
|
|
|
LOG("Sent CreateCharacter for ID: %llu", player);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 09:01:43 +00:00
|
|
|
void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems) {
|
2022-08-05 13:40:12 +00:00
|
|
|
CBITSTREAM;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHAT_MODERATION_STRING);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bitStream.Write<uint8_t>(unacceptedItems.empty()); // Is sentence ok?
|
|
|
|
bitStream.Write<uint16_t>(0x16); // Source ID, unknown
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-24 00:11:00 +00:00
|
|
|
bitStream.Write<uint8_t>(requestID); // request ID
|
|
|
|
bitStream.Write<char>(0); // chat mode
|
2022-07-17 06:54:36 +00:00
|
|
|
|
2023-09-21 01:06:28 +00:00
|
|
|
bitStream.Write(LUWString(receiver, 42)); // receiver name
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto it : unacceptedItems) {
|
|
|
|
bitStream.Write<uint8_t>(it.first); // start index
|
|
|
|
bitStream.Write<uint8_t>(it.second); // length
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (int i = unacceptedItems.size(); 64 > i; i++) {
|
|
|
|
bitStream.Write<uint16_t>(0);
|
|
|
|
}
|
2022-07-17 06:54:36 +00:00
|
|
|
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 23:16:45 +00:00
|
|
|
void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel) {
|
2022-08-05 13:40:12 +00:00
|
|
|
CBITSTREAM;
|
2023-09-21 01:06:28 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::MAKE_GM_RESPONSE);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bitStream.Write<uint8_t>(success);
|
2023-03-24 23:16:45 +00:00
|
|
|
bitStream.Write(static_cast<uint16_t>(highestLevel));
|
|
|
|
bitStream.Write(static_cast<uint16_t>(prevLevel));
|
|
|
|
bitStream.Write(static_cast<uint16_t>(newLevel));
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-08-05 13:40:12 +00:00
|
|
|
SEND_PACKET;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|