Skip to content

Commit

Permalink
Core: Rewrite IPC system to use codegen'd structs
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Feb 24, 2025
1 parent f134f04 commit 0130d1b
Show file tree
Hide file tree
Showing 48 changed files with 2,992 additions and 2,096 deletions.
3 changes: 1 addition & 2 deletions modules/custom/cpp/ah_announcement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ class AHAnnouncementModule : public CPPModule
name[0] = std::toupper(name[0]);

// Send message to seller!
message::send(sellerId, std::make_unique<CChatMessagePacket>(PChar, MESSAGE_SYSTEM_3,
fmt::format("Your '{}' has sold to {} for {} gil!", name, PChar->name, price).c_str(), ""));
// message::send(sellerId, std::make_unique<CChatMessagePacket>(PChar, MESSAGE_SYSTEM_3, fmt::format("Your '{}' has sold to {} for {} gil!", name, PChar->name, price).c_str(), ""));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/cbasetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <climits>
#include <cstddef>
#include <cstdint>
#include <span>
#include <utility>
#include <vector>

#include "logging.h"
#include "macros.h"
Expand Down
70 changes: 53 additions & 17 deletions src/common/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,81 @@
#include <type_traits>
#include <vector>

#include "cbasetypes.h"

//
// Forward declarations (before including ipc headers)
//

namespace ipc
{
template <typename T>
auto toBytes(const T& object) -> std::vector<uint8>;

template <typename T>
auto toBytesWithHeader(const T& object) -> std::vector<uint8>;

template <typename T>
auto fromBytes(const std::span<const uint8> message) -> std::optional<T>;

template <typename T>
auto fromBytesWithHeader(const std::span<const uint8> message) -> std::optional<T>;
} // namespace ipc

#include "ipc_structs.h"
#include "ipc_stubs.h"

#include <alpaca/alpaca.h>

namespace ipc
{
// Forward declarations
enum class MessageType : uint8_t;
//
// Helpers
//

template <typename T>
MessageType getEnumType();
auto toBytes(const T& object) -> std::vector<uint8>
{
auto bytes = std::vector<uint8>();
alpaca::serialize(object, bytes);
return bytes;
}

// Helpers
template <typename T>
auto toBytes(const T& object) -> std::vector<uint8_t>
auto toBytesWithHeader(const T& object) -> std::vector<uint8>
{
auto bytes = std::vector<uint8_t>();
auto bytes = std::vector<uint8>();
auto bytes_written = alpaca::serialize(object, bytes);

const auto type = static_cast<uint8_t>(getEnumType<T>());
const auto type = static_cast<uint8>(getEnumType<T>());

std::vector<uint8_t> message(1 + bytes_written);
std::vector<uint8> message(1 + bytes_written);
message[0] = type;
std::memcpy(message.data() + 1, bytes.data(), bytes_written);

return message;
}

template <typename T>
auto fromBytes(const std::vector<uint8_t>& message) -> std::optional<T>
auto fromBytes(const std::span<const uint8> message) -> std::optional<T>
{
if (message.empty())
{
return std::nullopt;
}

auto ec = std::error_code{};
auto object = alpaca::deserialize<T>(message, ec);
if (ec)
{
return std::nullopt;
}

return std::move(object);
}

template <typename T>
auto fromBytesWithHeader(const std::span<const uint8> message) -> std::optional<T>
{
if (message.empty())
{
Expand All @@ -82,12 +126,4 @@ namespace ipc

return std::move(object);
}

// Message handler implementation
class IPCMessageHandler : public IIPCMessageHandler
{
private:
// Don't handle this message type if we get it
void handleMessage_SomeData(const SomeData& message) override = default;
};
} // namespace ipc
216 changes: 214 additions & 2 deletions src/common/ipc_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,227 @@

#pragma once

#include "cbasetypes.h"

#include "common/regional_event.h"
#include "map/packets/message_standard.h"

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

namespace ipc
{
struct SomeData // Example struct. Remove this once we have real structs.
struct EmptyStruct
{
};

struct CharLogin
{
uint32 accountId;
uint32 charId;
};

struct CharVarUpdate
{
uint32 charId;
int32 value;
uint32 expiry;
std::string varName;
};

struct ChatMessageTell
{
uint32 senderId;
std::string senderName;
std::string recipientName;
std::string message;
uint16 zoneId;
uint8 gmLevel;
};

struct ChatMessageParty
{
uint32 partyId;
uint32 senderId;
std::string senderName;
std::string message;
uint16 zoneId;
uint8 gmLevel;
};

struct ChatMessageAlliance
{
uint32 allianceId;
uint32 senderId;
std::string senderName;
std::string message;
uint16 zoneId;
uint8 gmLevel;
};

struct ChatMessageLinkshell
{
uint32 linkshellId;
uint32 senderId;
std::string senderName;
std::string message;
uint16 zoneId;
uint8 gmLevel;
};

struct ChatMessageUnity
{
uint32 unityLeaderId;
uint32 senderId;
std::string senderName;
std::string message;
uint16 zoneId;
uint8 gmLevel;
};

struct ChatMessageYell
{
uint32 senderId;
std::string senderName;
std::string message;
uint16 zoneId;
uint8 gmLevel;
};

struct ChatMessageServerMessage
{
uint32 senderId;
std::string senderName;
std::string message;
uint16 zoneId;
uint8 gmLevel;
};

struct PartyInvite
{
uint32 inviteeId;
uint16 inviteeTargId;
uint32 inviterId;
uint16 inviterTargId;
std::string inviterName;
uint8 inviteType;
};

struct PartyInviteResponse
{
uint32 inviteeId;
uint16 inviteeTargId;
uint32 inviterId;
uint16 inviterTargId;
std::string inviterName;
uint8 inviteAnswer;
};

struct PartyReload
{
uint32 partyId;
};

struct PartyDisband
{
uint32 partyId;
};

struct AllianceReload
{
uint32 allianceId;
};

struct AllianceDissolve
{
uint32 allianceId;
};

struct PlayerKick
{
uint32 charId;
};

struct MessageStandard
{
uint32 charId;
MsgStd message;
};

struct MessageSystem
{
uint32 charId;
MsgStd message;
};

struct LinkshellRankChange
{
uint32 charId;
std::string linkshellName;
uint32 linkshellId;
uint8 permission;
};

struct LinkshellRemove
{
uint32 charId;
std::string linkshellName;
uint32 linkshellId;
uint8 linkshellType;
};

struct LinkshellSetMessage
{
uint32 linkshellId;
std::string poster;
std::string message;
};

struct LuaFunction
{
uint16 zoneId;
std::string funcString;
};

struct KillSession
{
uint32 charId;
};

struct RegionalEvent
{
RegionalEventType type;
uint8 subType;
std::vector<uint8> payload;
};

struct GMSendToZone
{
uint32 targetId;
uint32 requesterId;

uint16 zoneId;
float x;
float y;
float z;
uint8 rot;
uint32 moghouseID;
};

struct GMSendToEntity
{
uint16 zoneId;
};

struct RPCSend
{
uint16 zoneId;
};

struct RPCRecv
{
std::vector<std::string> messages;
uint16 zoneId;
};
} // namespace ipc
Loading

0 comments on commit 0130d1b

Please sign in to comment.