EDIT: I forgot to mention that in this implementation E stands for Entity which is just an ID, C => Component as data-only types and S for Systems which should implement logic
Currently i'm working on a small hobby project which is a multiplayer card game with a client/server architecture. I'm using a framework for the network part which triggers message events to services objects like this:
class AuthRequestMessage : public fqpnet::IMessage
{
public:
//methods for serialization
inline const std::string& getLoginId() const
{ return loginId_; }
inline const std::string& getPassword() const
{ return loginId_; }
private:
std::string loginId_;
std::string password_;
};
//Handles authentication
class GatewayService : public fqpnet::Service
{
public:
//registers handlers
GatewayService()
private:
void onAuthRequestMessage(const AuthRequestMessage* msg, ClientSession* session);
};
and now i'm at the point where i have to create the player entity. My first thought was to create the player entity directly in the message handler. But it feels like this code should be in a system so i created a system and added a method:
class PlayerSystem : public entityx::System<PlayerSystem>
{
public:
//Entity createPlayer(/*info needed...*/);
//update etc
};
But this feels rather bad too as the method is only used once in the handler. My third attempt was to use the builtin messaging system of the ECS:
struct PlayerAuthRequest
{
//id etc
};
class PlayerSystem : public entityx::System<PlayerSystem>
{
public:
void receive(const PlayerAuthRequest& request);
};
//and now just emit the event in the message handler
void GatewayService::onAuthRequestMessage(const AuthRequestMessage* msg,
ClientSession* session)
{
//verify, load from db etc.
eventMgr->emit<PlayerAuthRequest>(/*data*/);
}
Which of these approaches would be the best? Or are there alternative ones? Basicly i just want to do it in the right way to learn. Performance does not really matter to me.