mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
Overaul, need to test
This commit is contained in:
29
dNet/BitStreamUtils.cpp
Normal file
29
dNet/BitStreamUtils.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "BitStreamUtils.h"
|
||||
#include "dServer.h"
|
||||
#include "BitStream.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);
|
||||
}
|
@@ -3,18 +3,12 @@
|
||||
|
||||
#include "GeneralUtils.h"
|
||||
#include "BitStream.h"
|
||||
#include "MessageIdentifiers.h"
|
||||
#include "eConnectionType.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace MessageType {
|
||||
enum class Auth : uint32_t;
|
||||
enum class Client : uint32_t;
|
||||
enum class Server : uint32_t;
|
||||
enum class World : uint32_t;
|
||||
enum class Master : uint32_t;
|
||||
}
|
||||
|
||||
enum class eConnectionType : uint16_t;
|
||||
#define VALIDATE_READ(x) do { if (!x) return false; } while (0)
|
||||
|
||||
struct LUString {
|
||||
std::string string;
|
||||
@@ -52,19 +46,28 @@ struct LUWString {
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct LUHeader {
|
||||
MessageID messageID;
|
||||
eConnectionType connectionType;
|
||||
T internalPacketID;
|
||||
struct LUBitStream {
|
||||
eConnectionType connectionType = eConnectionType::UNKNOWN;
|
||||
uint32_t internalPacketID = 0xFFFFFFFF;
|
||||
|
||||
LUHeader(eConnectionType connectionType, T internalPacketID, MessageID messageID = ID_USER_PACKET_ENUM) {
|
||||
this->messageID = messageID;
|
||||
LUBitStream() = default;
|
||||
|
||||
template <typename T>
|
||||
LUBitStream(eConnectionType connectionType, T internalPacketID) {
|
||||
this->connectionType = connectionType;
|
||||
this->internalPacketID = internalPacketID;
|
||||
};
|
||||
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) {
|
||||
@@ -119,46 +122,6 @@ namespace RakNet {
|
||||
value.string.resize(value.size);
|
||||
this->Write(value.string);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void RakNet::BitStream::Write<LUHeader<MessageType::Auth>>(LUHeader<MessageType::Auth> value) {
|
||||
this->Write<MessageID>(value.messageID);
|
||||
this->Write<eConnectionType>(value.connectionType);
|
||||
this->Write<uint32_t>(static_cast<uint32_t>(value.internalPacketID));
|
||||
this->Write<uint8_t>(0);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void RakNet::BitStream::Write<LUHeader<MessageType::Client>>(LUHeader<MessageType::Client> value) {
|
||||
this->Write<MessageID>(value.messageID);
|
||||
this->Write<eConnectionType>(value.connectionType);
|
||||
this->Write<uint32_t>(static_cast<uint32_t>(value.internalPacketID));
|
||||
this->Write<uint8_t>(0);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void RakNet::BitStream::Write<LUHeader<MessageType::Server>>(LUHeader<MessageType::Server> value) {
|
||||
this->Write<MessageID>(value.messageID);
|
||||
this->Write<eConnectionType>(value.connectionType);
|
||||
this->Write<uint32_t>(static_cast<uint32_t>(value.internalPacketID));
|
||||
this->Write<uint8_t>(0);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void RakNet::BitStream::Write<LUHeader<MessageType::World>>(LUHeader<MessageType::World> value) {
|
||||
this->Write<MessageID>(value.messageID);
|
||||
this->Write<eConnectionType>(value.connectionType);
|
||||
this->Write<uint32_t>(static_cast<uint32_t>(value.internalPacketID));
|
||||
this->Write<uint8_t>(0);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void RakNet::BitStream::Write<LUHeader<MessageType::Master>>(LUHeader<MessageType::Master> value) {
|
||||
this->Write<MessageID>(value.messageID);
|
||||
this->Write<eConnectionType>(value.connectionType);
|
||||
this->Write<uint32_t>(static_cast<uint32_t>(value.internalPacketID));
|
||||
this->Write<uint8_t>(0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //!__BITSTREAMUTILS__H__
|
||||
|
@@ -1,4 +1,5 @@
|
||||
set(DNET_SOURCES "AuthPackets.cpp"
|
||||
"BitStreamUtils.cpp"
|
||||
"ChatPackets.cpp"
|
||||
"ClientPackets.cpp"
|
||||
"dServer.cpp"
|
||||
|
87
dNet/MailInfo.cpp
Normal file
87
dNet/MailInfo.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#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<uint16_t>(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>(0); // packing
|
||||
bitStream.Write<uint32_t>(0); // packing
|
||||
}
|
||||
|
||||
bool MailInfo::Deserialize(RakNet::BitStream& bitStream) {
|
||||
VALIDATE_READ(bitStream.Read(id));
|
||||
|
||||
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 sender(32);
|
||||
VALIDATE_READ(bitStream.Read(sender));
|
||||
this->senderUsername = sender.GetAsString();
|
||||
|
||||
bitStream.IgnoreBytes(4); // packing
|
||||
|
||||
bitStream.IgnoreBytes(8); // attachedCurrency
|
||||
VALIDATE_READ(bitStream.Read(itemID));
|
||||
|
||||
LOT lot;
|
||||
VALIDATE_READ(bitStream.Read(lot));
|
||||
if (lot == LOT_NULL) itemLOT = 0;
|
||||
else itemLOT = lot;
|
||||
bitStream.IgnoreBytes(4); // packing
|
||||
|
||||
VALIDATE_READ(bitStream.Read(itemSubkey));
|
||||
|
||||
VALIDATE_READ(bitStream.Read(itemCount));
|
||||
|
||||
bitStream.IgnoreBytes(1); // subject type (used for auction)
|
||||
bitStream.IgnoreBytes(1); // packing
|
||||
bitStream.IgnoreBytes(4); // packing
|
||||
|
||||
VALIDATE_READ(bitStream.Read(timeSent)); // expiration date
|
||||
VALIDATE_READ(bitStream.Read(timeSent)); // send date
|
||||
VALIDATE_READ(bitStream.Read(wasRead)); // was read
|
||||
|
||||
bitStream.IgnoreBytes(1); // isLocalized
|
||||
bitStream.IgnoreBytes(2); // packing
|
||||
bitStream.IgnoreBytes(4); // packing
|
||||
|
||||
DluAssert(bitStream.GetNumberOfUnreadBits() == 0);
|
||||
|
||||
return true;
|
||||
}
|
33
dNet/MailInfo.h
Normal file
33
dNet/MailInfo.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#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{};
|
||||
struct {
|
||||
LWOOBJID itemID{};
|
||||
int32_t itemCount{};
|
||||
LOT itemLOT{};
|
||||
LWOOBJID itemSubkey{};
|
||||
};
|
||||
|
||||
void Serialize(RakNet::BitStream& bitStream) const {}
|
||||
bool Deserialize(RakNet::BitStream& bitStream) { return true; }
|
||||
};
|
||||
|
||||
#endif // __MAILINFO_H__
|
Reference in New Issue
Block a user