Skip to content

Server Components

hexasec edited this page Dec 5, 2018 · 1 revision

Server Components

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.

Component Interface

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.

Abstract 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.

Component exemple

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;
};

Clone this wiki locally