add packets

This commit is contained in:
2025-08-04 11:35:51 +02:00
parent d1d71ed086
commit df79a35eae
2 changed files with 12 additions and 5 deletions

View File

@@ -8,11 +8,11 @@
#include <td/common/NonCopyable.h> #include <td/common/NonCopyable.h>
#include <td/protocol/packet/PacketData.h> #include <td/protocol/packet/PacketData.h>
#include <sp/common/GenericHandler.h>
#include <sp/protocol/ConcreteMessage.h> #include <sp/protocol/ConcreteMessage.h>
#include <sp/protocol/MessageBase.h> #include <sp/protocol/MessageBase.h>
#include <sp/protocol/MessageDispatcher.h> #include <sp/protocol/MessageDispatcher.h>
#include <sp/protocol/MessageFactory.h> #include <sp/protocol/MessageFactory.h>
#include <sp/common/GenericHandler.h>
namespace td { namespace td {
namespace protocol { namespace protocol {
@@ -24,10 +24,12 @@ enum class PacketID : std::uint8_t {
KeepAlive, KeepAlive,
LockSteps, LockSteps,
LoggingSuccess, LoggingSuccess,
PlaceTower,
PlayerJoin, PlayerJoin,
PlayerLeave, PlayerLeave,
PlayerLogin, PlayerLogin,
PredictCommand, PredictCommand,
SpawnTroop,
WorldHeader, WorldHeader,
WorldData, WorldData,
}; };
@@ -49,18 +51,21 @@ using DisconnectPacket = PacketMessage<pdata::Disconnect, PacketID::Disconnect>;
using KeepAlivePacket = PacketMessage<pdata::KeepAlive, PacketID::KeepAlive>; using KeepAlivePacket = PacketMessage<pdata::KeepAlive, PacketID::KeepAlive>;
using LockStepsPacket = PacketMessage<pdata::LockSteps, PacketID::LockSteps>; using LockStepsPacket = PacketMessage<pdata::LockSteps, PacketID::LockSteps>;
using LoggingSuccessPacket = PacketMessage<pdata::LoggingSuccess, PacketID::LoggingSuccess>; using LoggingSuccessPacket = PacketMessage<pdata::LoggingSuccess, PacketID::LoggingSuccess>;
using PlaceTowerPacket = PacketMessage<pdata::PlaceTower, PacketID::PlaceTower>;
using PlayerJoinPacket = PacketMessage<pdata::PlayerJoin, PacketID::PlayerJoin>; using PlayerJoinPacket = PacketMessage<pdata::PlayerJoin, PacketID::PlayerJoin>;
using PlayerLeavePacket = PacketMessage<pdata::PlayerLeave, PacketID::PlayerLeave>; using PlayerLeavePacket = PacketMessage<pdata::PlayerLeave, PacketID::PlayerLeave>;
using PlayerLoginPacket = PacketMessage<pdata::PlayerLogin, PacketID::PlayerLogin>; using PlayerLoginPacket = PacketMessage<pdata::PlayerLogin, PacketID::PlayerLogin>;
using PredictCommandPacket = PacketMessage<pdata::PredictCommand, PacketID::PredictCommand>; using PredictCommandPacket = PacketMessage<pdata::PredictCommand, PacketID::PredictCommand>;
using SpawnTroopPacket = PacketMessage<pdata::SpawnTroop, PacketID::SpawnTroop>;
using WorldHeaderPacket = PacketMessage<pdata::WorldHeader, PacketID::WorldHeader>; using WorldHeaderPacket = PacketMessage<pdata::WorldHeader, PacketID::WorldHeader>;
using WorldDataPacket = PacketMessage<pdata::WorldData, PacketID::WorldData>; using WorldDataPacket = PacketMessage<pdata::WorldData, PacketID::WorldData>;
} // namespace packets } // namespace packets
using AllPackets = std::tuple<packets::BeginGamePacket, packets::ChatMessagePacket, packets::DisconnectPacket, using AllPackets = std::tuple<packets::BeginGamePacket, packets::ChatMessagePacket, packets::DisconnectPacket,
packets::KeepAlivePacket, packets::LockStepsPacket, packets::LoggingSuccessPacket, packets::PlayerJoinPacket, packets::KeepAlivePacket, packets::LockStepsPacket, packets::LoggingSuccessPacket, packets::PlaceTowerPacket,
packets::PlayerLeavePacket, packets::PlayerLoginPacket, packets::PredictCommandPacket, packets::WorldHeaderPacket, packets::WorldDataPacket>; packets::PlayerJoinPacket, packets::PlayerLeavePacket, packets::PlayerLoginPacket, packets::PredictCommandPacket,
packets::SpawnTroopPacket, packets::WorldHeaderPacket, packets::WorldDataPacket>;
class PacketHandler : public sp::GenericHandler<AllPackets> {}; class PacketHandler : public sp::GenericHandler<AllPackets> {};

View File

@@ -24,6 +24,8 @@ class ClientSimulation : public protocol::PacketHandler {
static const protocol::LockStep EMPTY_LOCKSTEP; static const protocol::LockStep EMPTY_LOCKSTEP;
using protocol::PacketHandler::Handle;
public: public:
/** /**
* \brief Replay constructor * \brief Replay constructor
@@ -42,8 +44,8 @@ class ClientSimulation : public protocol::PacketHandler {
*/ */
float Update(); float Update();
void Handle(const protocol::packets::LockStepsPacket& a_LockSteps) override; virtual void Handle(const protocol::packets::LockStepsPacket& a_LockSteps) override;
void Handle(const protocol::packets::PredictCommandPacket& a_Predict) override; virtual void Handle(const protocol::packets::PredictCommandPacket& a_Predict) override;
private: private:
void Step(); void Step();