-
Notifications
You must be signed in to change notification settings - Fork 5
Server Components
hexasec edited this page Dec 5, 2018
·
1 revision
The server is structured for adding new functionalities in an easy way: the components. Indeed the server can load components and use it for TCP or UDP or Both.
class IServerComponent {
public:
virtual ~IServerComponent() = default;
virtual bool run(boost::asio::ip::tcp::socket &, struct TCPStreamBufferData &) const = 0;
virtual bool run(boost::asio::ip::udp::socket &, boost::asio::ip::udp::endpoint, struct UDPClientStreamBufferData &) const = 0;
virtual int getCommand() const noexcept = 0;
};
-
bool run(boost::asio::ip::tcp::socket &, struct TCPStreamBufferData &)is the method for TCP implementation of the component. -
bool run(boost::asio::ip::udp::socket &, boost::asio::ip::udp::endpoint, struct UDPClientStreamBufferData &)is the method for UDP implementation of the component.
class AServerComponent : public IServerComponent {
public:
explicit AServerComponent(int command);
~AServerComponent() override = default;
bool run(boost::asio::ip::tcp::socket &, struct TCPStreamBufferData &) const override = 0;
bool run(boost::asio::ip::udp::socket &, boost::asio::ip::udp::endpoint, struct UDPClientStreamBufferData &) const override = 0;
int getCommand() const noexcept override;
protected:
int _command;
};
The abstraction class of a server component only implement the int getCommand() method wich just return the command related to the component.
Here is an exemple of an implented component: MoveComponent
class MoveComponent : public AServerComponent {
public:
explicit MoveComponent(std::list<struct UDPPlayer> &players) : AServerComponent(MOVE), _players(players) {}
~MoveComponent() final = default;
bool run(boost::asio::ip::tcp::socket &, struct TCPStreamBufferData &) const final;
bool run(boost::asio::ip::udp::socket &, boost::asio::ip::udp::endpoint, struct UDPClientStreamBufferData &) const final;
private:
std::list<struct UDPPlayer> &_players;
};