working dispatcher + factory
All checks were successful
Linux arm64 / Build (push) Successful in 1m17s
All checks were successful
Linux arm64 / Build (push) Successful in 1m17s
This commit is contained in:
@@ -4,17 +4,28 @@
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/MessageBase.h>
|
||||
|
||||
enum class DisconnectFieldsE {
|
||||
Reason = 0
|
||||
|
||||
struct DisconnectPacketData {
|
||||
std::string m_Reason;
|
||||
};
|
||||
|
||||
using DisconnectFields = std::tuple<std::string /*Reason*/>;
|
||||
class DisconnectPacket : public sp::MessageBase<sp::PacketMessage, sp::option::DispatchImpl<DisconnectPacket>> {
|
||||
private:
|
||||
DisconnectPacketData m_Data;
|
||||
|
||||
DeclarePacket(Disconnect){
|
||||
public:
|
||||
PacketConstructor(Disconnect)
|
||||
public:
|
||||
template<typename ... T>
|
||||
DisconnectPacket(T... args) : m_Data{args...} {}
|
||||
|
||||
const std::string& GetReason() const {
|
||||
return GetField<DisconnectFieldsE, DisconnectFieldsE::Reason>();
|
||||
return m_Data.m_Reason;
|
||||
}
|
||||
|
||||
virtual sp::PacketID GetId() const {
|
||||
return Disconnect;
|
||||
}
|
||||
};
|
||||
|
||||
void ff() {
|
||||
sizeof(std::string);
|
||||
}
|
||||
|
||||
@@ -4,19 +4,40 @@
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/MessageBase.h>
|
||||
|
||||
enum class KeepAliveFieldsE {
|
||||
KeepAliveId = 0,
|
||||
|
||||
template <sp::PacketID ID, typename TData>
|
||||
class ConcreteMessage {
|
||||
public:
|
||||
using DataType = TData;
|
||||
|
||||
template<typename... T>
|
||||
ConcreteMessage(const T&... args) : m_Data {args ...};
|
||||
|
||||
private:
|
||||
DataType m_Data;
|
||||
|
||||
virtual sp::PacketID GetId() const {
|
||||
return ID;
|
||||
}
|
||||
};
|
||||
|
||||
using KeepAliveFields = std::tuple<
|
||||
std::uint64_t //<- KeepAliveId
|
||||
>;
|
||||
|
||||
DeclarePacket(KeepAlive){
|
||||
public:
|
||||
PacketConstructor(KeepAlive)
|
||||
|
||||
std::uint64_t GetKeepAliveId() const {
|
||||
return GetField<KeepAliveFieldsE, KeepAliveFieldsE::KeepAliveId>();
|
||||
|
||||
|
||||
struct KeepAlivePacket {
|
||||
std::uint64_t m_AliveId;
|
||||
};
|
||||
|
||||
class KeepAliveMessage : public sp::MessageBase<sp::PacketMessage, sp::option::DispatchImpl<DisconnectPacket>> {
|
||||
private:
|
||||
KeepAlivePacket m_Data;
|
||||
|
||||
public:
|
||||
template <typename... T>
|
||||
KeepAliveMessage(T... args) : m_Data{args...} {}
|
||||
|
||||
virtual sp::PacketID GetId() const {
|
||||
return KeepAlive;
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
enum PacketId {
|
||||
enum PacketIds {
|
||||
KeepAlive = 0,
|
||||
Disconnect,
|
||||
UpgradeTower,
|
||||
|
||||
@@ -4,30 +4,36 @@
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/MessageBase.h>
|
||||
|
||||
|
||||
enum class UpgradeTowerFieldsE {
|
||||
m_Tower = 0,
|
||||
m_Upgrade,
|
||||
struct UpgradeTowerPacketData {
|
||||
sp::BitField<std::uint16_t,
|
||||
sp::Field<std::uint16_t, 12>, // std::uint16_t m_Tower : 12;
|
||||
sp::Field<std::uint8_t, 4> // std::uint8_t m_Upgrade : 4;
|
||||
> m_TowerAndUpgrade;
|
||||
sp::VarInt m_Test;
|
||||
std::map<std::string, std::vector<int>> m_Test2;
|
||||
};
|
||||
|
||||
using UpgradeTowerFields = std::tuple<
|
||||
sp::BitField<std::uint16_t,
|
||||
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
||||
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
||||
>,
|
||||
sp::VarInt, //<- just for testing
|
||||
std::map<std::string, std::vector<int>>
|
||||
>;
|
||||
class UpgradeTowerPacket : public sp::MessageBase<sp::PacketMessage, sp::option::DispatchImpl<UpgradeTowerPacket>> {
|
||||
private:
|
||||
UpgradeTowerPacketData m_Data;
|
||||
|
||||
DeclarePacket(UpgradeTower){
|
||||
public:
|
||||
PacketConstructor(UpgradeTower)
|
||||
public:
|
||||
template <typename... T>
|
||||
UpgradeTowerPacket(T... args) : m_Data{args...} {}
|
||||
|
||||
std::uint16_t GetTowerId() const {
|
||||
return GetField<0>().GetField<UpgradeTowerFieldsE, UpgradeTowerFieldsE::m_Tower>();
|
||||
return m_Data.m_TowerAndUpgrade.GetField<0>();
|
||||
}
|
||||
|
||||
std::uint8_t GetTowerUpgrade() const {
|
||||
return GetField<0>().GetField<UpgradeTowerFieldsE, UpgradeTowerFieldsE::m_Upgrade>();
|
||||
return m_Data.m_TowerAndUpgrade.GetField<1>();
|
||||
}
|
||||
};
|
||||
|
||||
virtual sp::PacketID GetId() const {
|
||||
return UpgradeTower;
|
||||
}
|
||||
|
||||
UpgradeTowerPacketData& GetData() {
|
||||
return m_Data;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user