mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
Merge pull request #1735 from DarkflameUniverse/mailv2
feat: Mail Re-write and packet/bitstream handler POC
This commit is contained in:
30
dNet/BitStreamUtils.cpp
Normal file
30
dNet/BitStreamUtils.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "BitStreamUtils.h"
|
||||
#include "dServer.h"
|
||||
#include "BitStream.h"
|
||||
#include "PacketUtils.h"
|
||||
|
||||
|
||||
void LUBitStream::WriteHeader(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write<MessageID>(ID_USER_PACKET_ENUM);
|
||||
bitStream.Write(this->connectionType);
|
||||
bitStream.Write(this->internalPacketID);
|
||||
bitStream.Write<uint8_t>(0); // padding
|
||||
}
|
||||
|
||||
bool LUBitStream::ReadHeader(RakNet::BitStream& bitStream) {
|
||||
MessageID messageID;
|
||||
bitStream.Read(messageID);
|
||||
if (messageID != ID_USER_PACKET_ENUM) return false;
|
||||
VALIDATE_READ(bitStream.Read(this->connectionType));
|
||||
VALIDATE_READ(bitStream.Read(this->internalPacketID));
|
||||
uint8_t padding;
|
||||
VALIDATE_READ(bitStream.Read<uint8_t>(padding));
|
||||
return true;
|
||||
}
|
||||
|
||||
void LUBitStream::Send(const SystemAddress& sysAddr) const {
|
||||
RakNet::BitStream bitStream;
|
||||
this->WriteHeader(bitStream);
|
||||
this->Serialize(bitStream);
|
||||
Game::server->Send(bitStream, sysAddr, sysAddr == UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
@@ -2,12 +2,13 @@
|
||||
#define __BITSTREAMUTILS__H__
|
||||
|
||||
#include "GeneralUtils.h"
|
||||
#include "MessageIdentifiers.h"
|
||||
#include "BitStream.h"
|
||||
#include "MessageIdentifiers.h"
|
||||
#include "eConnectionType.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
enum class eConnectionType : uint16_t;
|
||||
#define VALIDATE_READ(x) do { if (!x) return false; } while (0)
|
||||
|
||||
struct LUString {
|
||||
std::string string;
|
||||
@@ -45,6 +46,28 @@ struct LUWString {
|
||||
};
|
||||
};
|
||||
|
||||
struct LUBitStream {
|
||||
eConnectionType connectionType = eConnectionType::UNKNOWN;
|
||||
uint32_t internalPacketID = 0xFFFFFFFF;
|
||||
|
||||
LUBitStream() = default;
|
||||
|
||||
template <typename T>
|
||||
LUBitStream(eConnectionType connectionType, T internalPacketID) {
|
||||
this->connectionType = connectionType;
|
||||
this->internalPacketID = static_cast<uint32_t>(internalPacketID);
|
||||
}
|
||||
|
||||
void WriteHeader(RakNet::BitStream& bitStream) const;
|
||||
bool ReadHeader(RakNet::BitStream& bitStream);
|
||||
void Send(const SystemAddress& sysAddr) const;
|
||||
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const {}
|
||||
virtual bool Deserialize(RakNet::BitStream& bitStream) { return true; }
|
||||
virtual void Handle() {};
|
||||
};
|
||||
|
||||
|
||||
namespace BitStreamUtils {
|
||||
template<typename T>
|
||||
void WriteHeader(RakNet::BitStream& bitStream, eConnectionType connectionType, T internalPacketID) {
|
||||
@@ -53,7 +76,6 @@ namespace BitStreamUtils {
|
||||
bitStream.Write(static_cast<uint32_t>(internalPacketID));
|
||||
bitStream.Write<uint8_t>(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace RakNet {
|
||||
|
@@ -1,7 +1,9 @@
|
||||
set(DNET_SOURCES "AuthPackets.cpp"
|
||||
"BitStreamUtils.cpp"
|
||||
"ChatPackets.cpp"
|
||||
"ClientPackets.cpp"
|
||||
"dServer.cpp"
|
||||
"MailInfo.cpp"
|
||||
"MasterPackets.cpp"
|
||||
"PacketUtils.cpp"
|
||||
"WorldPackets.cpp"
|
||||
|
63
dNet/MailInfo.cpp
Normal file
63
dNet/MailInfo.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "MailInfo.h"
|
||||
#include "BitStream.h"
|
||||
#include "DluAssert.h"
|
||||
|
||||
void MailInfo::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write(id);
|
||||
const LUWString subject(this->subject, 50);
|
||||
bitStream.Write(subject);
|
||||
const LUWString body(this->body, 400);
|
||||
bitStream.Write(body);
|
||||
const LUWString sender(this->senderUsername, 32);
|
||||
bitStream.Write(sender);
|
||||
bitStream.Write<uint32_t>(0); // packing
|
||||
|
||||
bitStream.Write<uint64_t>(0); // attachedCurrency
|
||||
bitStream.Write(itemID);
|
||||
|
||||
LOT lot = itemLOT;
|
||||
if (lot <= 0) bitStream.Write<LOT>(LOT_NULL);
|
||||
else bitStream.Write(lot);
|
||||
bitStream.Write<uint32_t>(0); // packing
|
||||
|
||||
bitStream.Write(itemSubkey);
|
||||
|
||||
bitStream.Write(itemCount);
|
||||
bitStream.Write<uint8_t>(0); // subject type (used for auction)
|
||||
bitStream.Write<uint8_t>(0); // packing
|
||||
bitStream.Write<uint32_t>(0); // packing
|
||||
|
||||
bitStream.Write<uint64_t>(timeSent); // expiration date
|
||||
bitStream.Write<uint64_t>(timeSent);// send date
|
||||
bitStream.Write<uint8_t>(wasRead); // was read
|
||||
|
||||
bitStream.Write<uint8_t>(0); // isLocalized
|
||||
bitStream.Write<uint16_t>(1033); // language code
|
||||
bitStream.Write<uint32_t>(0); // packing
|
||||
}
|
||||
|
||||
bool MailInfo::Deserialize(RakNet::BitStream& bitStream) {
|
||||
LUWString subject(50);
|
||||
VALIDATE_READ(bitStream.Read(subject));
|
||||
this->subject = subject.GetAsString();
|
||||
|
||||
LUWString body(400);
|
||||
VALIDATE_READ(bitStream.Read(body));
|
||||
this->body = body.GetAsString();
|
||||
|
||||
LUWString recipientName(32);
|
||||
VALIDATE_READ(bitStream.Read(recipientName));
|
||||
this->recipient = recipientName.GetAsString();
|
||||
|
||||
uint64_t unknown;
|
||||
VALIDATE_READ(bitStream.Read(unknown));
|
||||
|
||||
VALIDATE_READ(bitStream.Read(itemID));
|
||||
VALIDATE_READ(bitStream.Read(itemCount));
|
||||
VALIDATE_READ(bitStream.Read(languageCode));
|
||||
bitStream.IgnoreBytes(4); // padding
|
||||
|
||||
DluAssert(bitStream.GetNumberOfUnreadBits() == 0);
|
||||
|
||||
return true;
|
||||
}
|
34
dNet/MailInfo.h
Normal file
34
dNet/MailInfo.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef __MAILINFO_H__
|
||||
#define __MAILINFO_H__
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include "dCommonVars.h"
|
||||
|
||||
namespace RakNet {
|
||||
class BitStream;
|
||||
}
|
||||
|
||||
struct MailInfo {
|
||||
std::string senderUsername;
|
||||
std::string recipient;
|
||||
std::string subject;
|
||||
std::string body;
|
||||
uint64_t id{};
|
||||
uint32_t senderId{};
|
||||
uint32_t receiverId{};
|
||||
uint64_t timeSent{};
|
||||
bool wasRead{};
|
||||
uint16_t languageCode{};
|
||||
struct {
|
||||
LWOOBJID itemID{};
|
||||
int16_t itemCount{};
|
||||
LOT itemLOT{};
|
||||
LWOOBJID itemSubkey{};
|
||||
};
|
||||
|
||||
void Serialize(RakNet::BitStream& bitStream) const;
|
||||
bool Deserialize(RakNet::BitStream& bitStream);
|
||||
};
|
||||
|
||||
#endif // __MAILINFO_H__
|
Reference in New Issue
Block a user