mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-04-26 08:36:30 +00:00
WIP debugging
This commit is contained in:
parent
b7c579fb84
commit
b01b3cc38d
@ -62,6 +62,7 @@ std::optional<MailInfo> MySQLDatabase::GetMail(const uint64_t mailId) {
|
||||
}
|
||||
|
||||
uint32_t MySQLDatabase::GetUnreadMailCount(const uint32_t characterId) {
|
||||
LOG("Getting unread mail count for character %i", characterId);
|
||||
auto res = ExecuteSelect("SELECT COUNT(*) AS number_unread FROM mail WHERE receiver_id=? AND was_read=0;", characterId);
|
||||
|
||||
if (!res->next()) {
|
||||
|
@ -34,28 +34,29 @@ namespace {
|
||||
}
|
||||
|
||||
namespace Mail {
|
||||
std::map<eMessageID, std::function<std::unique_ptr<MailLUBitStream>(const SystemAddress&, Entity* const)>> handlers = {
|
||||
{eMessageID::SendRequest, [](const SystemAddress& sysAddr, Entity* const player) {
|
||||
std::map<eMessageID, std::function<std::unique_ptr<MailLUBitStream>()>> g_Handlers = {
|
||||
{eMessageID::SendRequest, []() {
|
||||
return std::make_unique<SendRequest>();
|
||||
}},
|
||||
{eMessageID::DataRequest, [](const SystemAddress& sysAddr, Entity* const player) {
|
||||
{eMessageID::DataRequest, []() {
|
||||
return std::make_unique<DataRequest>();
|
||||
}},
|
||||
{eMessageID::AttachmentCollectRequest, [](const SystemAddress& sysAddr, Entity* const player) {
|
||||
{eMessageID::AttachmentCollectRequest, []() {
|
||||
return std::make_unique<AttachmentCollectRequest>();
|
||||
}},
|
||||
{eMessageID::DeleteRequest, [](const SystemAddress& sysAddr, Entity* const player) {
|
||||
{eMessageID::DeleteRequest, []() {
|
||||
return std::make_unique<DeleteRequest>();
|
||||
}},
|
||||
{eMessageID::ReadRequest, [](const SystemAddress& sysAddr, Entity* const player) {
|
||||
{eMessageID::ReadRequest, []() {
|
||||
return std::make_unique<ReadRequest>();
|
||||
}},
|
||||
{eMessageID::NotificationRequest, [](const SystemAddress& sysAddr, Entity* const player) {
|
||||
{eMessageID::NotificationRequest, []() {
|
||||
return std::make_unique<NotificationRequest>();
|
||||
}},
|
||||
};
|
||||
|
||||
void MailLUBitStream::Serialize(RakNet::BitStream& bitStream) const {
|
||||
LOG("Writing %s", StringifiedEnum::ToString(messageID).data());
|
||||
bitStream.Write(messageID);
|
||||
}
|
||||
|
||||
@ -160,28 +161,32 @@ namespace Mail {
|
||||
|
||||
void NotificationResponse::Serialize(RakNet::BitStream& bitStream) const {
|
||||
MailLUBitStream::Serialize(bitStream);
|
||||
LOG("notification: %s", StringifiedEnum::ToString(notification).data());
|
||||
bitStream.Write(notification);
|
||||
bitStream.Write<uint64_t>(0); // unused
|
||||
bitStream.Write<uint64_t>(0); // unused
|
||||
LOG("auctionID: %llu", auctionID);
|
||||
bitStream.Write(auctionID);
|
||||
bitStream.Write<uint64_t>(0); // unused
|
||||
LOG("mailCount: %i", mailCount);
|
||||
bitStream.Write(mailCount);
|
||||
}
|
||||
|
||||
void DataRequest::Handle() {
|
||||
auto playerMail = Database::Get()->GetMailForPlayer(player->GetObjectID(), 20);
|
||||
|
||||
if (playerMail.size() > 0) {
|
||||
DataResponse response;
|
||||
response.playerMail = playerMail;
|
||||
response.Send(sysAddr);
|
||||
}
|
||||
LOG("DataRequest::Handle()");
|
||||
auto playerMail = Database::Get()->GetMailForPlayer(static_cast<uint32_t>(player->GetObjectID()), 20);
|
||||
LOG("DataRequest::Handle() - Got %i mail", playerMail.size());
|
||||
DataResponse response;
|
||||
response.playerMail = playerMail;
|
||||
response.Send(sysAddr);
|
||||
}
|
||||
|
||||
void DataResponse::Serialize(RakNet::BitStream& bitStream) const {
|
||||
MailLUBitStream::Serialize(bitStream);
|
||||
|
||||
LOG("throtttled: %i", throttled);
|
||||
bitStream.Write(this->throttled);
|
||||
|
||||
LOG("playerMail.size(): %i", this->playerMail.size());
|
||||
bitStream.Write<uint16_t>(this->playerMail.size());
|
||||
bitStream.Write<uint16_t>(0); // packing
|
||||
for (const auto& mail : this->playerMail) {
|
||||
@ -269,7 +274,13 @@ namespace Mail {
|
||||
}
|
||||
|
||||
void NotificationRequest::Handle() {
|
||||
auto unreadMailCount = Database::Get()->GetUnreadMailCount(player->GetObjectID());
|
||||
auto character = player->GetCharacter();
|
||||
if (!character) {
|
||||
NotificationResponse(eNotificationResponse::UnknownError, 0).Send(sysAddr);
|
||||
return;
|
||||
}
|
||||
|
||||
auto unreadMailCount = Database::Get()->GetUnreadMailCount(character->GetID());
|
||||
if (unreadMailCount > 0) NotificationResponse(eNotificationResponse::NewMail, unreadMailCount).Send(sysAddr);
|
||||
}
|
||||
}
|
||||
@ -282,9 +293,11 @@ void Mail::HandleMail(RakNet::BitStream& inStream, const SystemAddress& sysAddr,
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = handlers.find(data.messageID);
|
||||
if (it != handlers.end()) {
|
||||
auto request = it->second(sysAddr, player);
|
||||
auto it = g_Handlers.find(data.messageID);
|
||||
if (it != g_Handlers.end()) {
|
||||
auto request = it->second();
|
||||
request->sysAddr = sysAddr;
|
||||
request->player = player;
|
||||
if (!request->Deserialize(inStream)) {
|
||||
LOG_DEBUG("Error Reading Mail Request: %s", StringifiedEnum::ToString(data.messageID).data());
|
||||
return;
|
||||
|
@ -89,12 +89,11 @@ namespace Mail {
|
||||
|
||||
struct MailLUBitStream : public LUBitStream {
|
||||
eMessageID messageID = eMessageID::UnknownError;
|
||||
const SystemAddress sysAddr = UNASSIGNED_SYSTEM_ADDRESS;
|
||||
Entity* const player = nullptr;
|
||||
SystemAddress sysAddr = UNASSIGNED_SYSTEM_ADDRESS;
|
||||
Entity* player = nullptr;
|
||||
|
||||
MailLUBitStream() = default;
|
||||
MailLUBitStream(eMessageID _messageID) : LUBitStream(eConnectionType::CLIENT, MessageType::Client::MAIL), messageID{_messageID} {};
|
||||
MailLUBitStream(const SystemAddress& _sysAddr, Entity* const _player) : sysAddr(_sysAddr), player(_player) {};
|
||||
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
virtual bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
@ -119,13 +118,13 @@ namespace Mail {
|
||||
eNotificationResponse notification = eNotificationResponse::UnknownError;
|
||||
LWOOBJID auctionID = LWOOBJID_EMPTY;
|
||||
uint32_t mailCount = 1;
|
||||
|
||||
NotificationResponse(eNotificationResponse _notification) : MailLUBitStream(eMessageID::NotificationResponse), notification{_notification} {};
|
||||
NotificationResponse(eNotificationResponse _notification, uint32_t _mailCount) : MailLUBitStream(eMessageID::NotificationResponse), notification{_notification}, mailCount{_mailCount} {};
|
||||
void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
};
|
||||
|
||||
struct DataRequest : public MailLUBitStream {
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override { return true; };
|
||||
void Handle() override;
|
||||
};
|
||||
|
||||
@ -190,6 +189,7 @@ namespace Mail {
|
||||
|
||||
struct NotificationRequest : public MailLUBitStream {
|
||||
NotificationRequest() : MailLUBitStream(eMessageID::NotificationRequest) {};
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override { return true; };
|
||||
void Handle() override;
|
||||
};
|
||||
|
||||
|
@ -217,7 +217,7 @@ namespace GMZeroCommands {
|
||||
}
|
||||
|
||||
void RequestMailCount(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
Mail::NotificationResponse(Mail::eNotificationResponse::NewMail, Database::Get()->GetUnreadMailCount(entity->GetObjectID())).Send(sysAddr);
|
||||
Mail::NotificationResponse(Mail::eNotificationResponse::NewMail, Database::Get()->GetUnreadMailCount(entity->GetCharacter()->GetID())).Send(sysAddr);
|
||||
}
|
||||
|
||||
void InstanceInfo(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
|
@ -348,7 +348,7 @@ int main(int argc, char** argv) {
|
||||
StartChatServer();
|
||||
|
||||
Game::im->GetInstance(0, false, 0);
|
||||
Game::im->GetInstance(1000, false, 0);
|
||||
Game::im->GetInstance(1100, false, 0);
|
||||
StartAuthServer();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "BitStreamUtils.h"
|
||||
#include "dServer.h"
|
||||
#include "BitStream.h"
|
||||
#include "PacketUtils.h"
|
||||
|
||||
|
||||
void LUBitStream::WriteHeader(RakNet::BitStream& bitStream) const {
|
||||
@ -25,5 +26,7 @@ void LUBitStream::Send(const SystemAddress& sysAddr) const {
|
||||
RakNet::BitStream bitStream;
|
||||
this->WriteHeader(bitStream);
|
||||
this->Serialize(bitStream);
|
||||
LOG("%s", sysAddr.ToString(true));
|
||||
PacketUtils::SavePacket("mailv2", reinterpret_cast<const char *>(bitStream.GetData()), bitStream.GetNumberOfBytesUsed());
|
||||
Game::server->Send(bitStream, sysAddr, sysAddr == UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ set(DNET_SOURCES "AuthPackets.cpp"
|
||||
"ChatPackets.cpp"
|
||||
"ClientPackets.cpp"
|
||||
"dServer.cpp"
|
||||
"MailInfo.cpp"
|
||||
"MasterPackets.cpp"
|
||||
"PacketUtils.cpp"
|
||||
"WorldPackets.cpp"
|
||||
|
@ -3,22 +3,26 @@
|
||||
#include "DluAssert.h"
|
||||
|
||||
void MailInfo::Serialize(RakNet::BitStream& bitStream) const {
|
||||
LOG("Writing MailInfo");
|
||||
LOG("ID: %llu", id);
|
||||
bitStream.Write(id);
|
||||
|
||||
LOG("Subject: %s", subject.c_str());
|
||||
const LUWString subject(this->subject, 50);
|
||||
bitStream.Write(subject);
|
||||
|
||||
LOG("Body: %s", body.c_str());
|
||||
const LUWString body(this->body, 400);
|
||||
bitStream.Write(body);
|
||||
|
||||
LOG("Sender: %s", senderUsername.c_str());
|
||||
const LUWString sender(this->senderUsername, 32);
|
||||
bitStream.Write(sender);
|
||||
bitStream.Write<uint32_t>(0); // packing
|
||||
|
||||
bitStream.Write<uint64_t>(0); // attachedCurrency
|
||||
LOG("ItemID: %llu", itemID);
|
||||
bitStream.Write(itemID);
|
||||
|
||||
LOT lot = itemLOT;
|
||||
LOG("ItemLOT: %u", lot);
|
||||
if (lot <= 0) bitStream.Write<LOT>(LOT_NULL);
|
||||
else bitStream.Write(lot);
|
||||
bitStream.Write<uint32_t>(0); // packing
|
||||
|
@ -26,8 +26,8 @@ struct MailInfo {
|
||||
LWOOBJID itemSubkey{};
|
||||
};
|
||||
|
||||
void Serialize(RakNet::BitStream& bitStream) const {}
|
||||
bool Deserialize(RakNet::BitStream& bitStream) { return true; }
|
||||
void Serialize(RakNet::BitStream& bitStream) const;
|
||||
bool Deserialize(RakNet::BitStream& bitStream);
|
||||
};
|
||||
|
||||
#endif // __MAILINFO_H__
|
||||
|
Loading…
x
Reference in New Issue
Block a user