From 53cb43a742ba59318e32d4de48b0347bd44ac0bb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 13 Jan 2024 12:11:43 +0200 Subject: [PATCH] Require entity packets to have an entity_id field of correct type --- source/game/remotecall.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/game/remotecall.h b/source/game/remotecall.h index e5e0fb7..b9c2ac6 100644 --- a/source/game/remotecall.h +++ b/source/game/remotecall.h @@ -1,6 +1,7 @@ #ifndef MSP_GAME_REMOTECALL_H_ #define MSP_GAME_REMOTECALL_H_ +#include #include #include #include @@ -10,6 +11,9 @@ namespace Msp::Game { +template +concept HasEntityIdField = requires(P p) { { (p.entity_id) } -> std::same_as; }; + template class RemoteCallBase: protected Net::PacketReceiver

{ @@ -24,7 +28,7 @@ protected: template - requires std::is_base_of_v + requires std::is_base_of_v && HasEntityIdField

class RemoteEntityCallBase: protected RemoteCallBase, const P &)> { protected: @@ -98,7 +102,7 @@ RemoteCallBase::RemoteCallBase(Replicator *r, Function f): template - requires std::is_base_of_v + requires std::is_base_of_v && HasEntityIdField

void RemoteEntityCallBase::prepare(Handle entity, P &packet) { Handle zygote = entity->template get_component(); @@ -113,7 +117,7 @@ void RemoteEntityCallBase::prepare(Handle entity, P &packet) } template - requires std::is_base_of_v + requires std::is_base_of_v && HasEntityIdField

void RemoteEntityCallBase::call(const P &packet) { Handle entity = this->replicator->find_entity(packet.entity_id); -- 2.45.2