Commit 6ac6ecb3 authored by louiz’'s avatar louiz’

Introduce an IPC connection on the game_server

parent eabbce57
......@@ -2,6 +2,8 @@
#include <game/turn.hpp>
#include <algorithm>
#include <network/ipc_endpoint.hpp>
#include <world/world_callbacks.hpp>
#include <world/entity.hpp>
#include <world/team.hpp>
......@@ -12,11 +14,17 @@
namespace ph = std::placeholders;
GameServer::GameServer(short port):
GameServer::GameServer(short port, const std::string& ipc_path):
Game(),
Server<RemoteGameClient>(port),
replay()
replay(),
ipc(nullptr)
{
if (!ipc_path.empty())
{
this->ipc = std::make_unique<IPCEndpoint>(ipc_path);
this->install_parent_stats_timed_event();
}
this->turn_handler.set_next_turn_callback(std::bind(&GameServer::on_next_turn, this,
ph::_1));
......@@ -29,6 +37,17 @@ GameServer::~GameServer()
{
}
void GameServer::install_parent_stats_timed_event()
{
auto cb = [this]()
{
log_debug("Sending things in the IPC thing");
this->ipc->send("coucou");
this->install_parent_stats_timed_event();
};
this->timed_event_handler.install_timed_event(cb, 5);
}
void GameServer::on_entity_created(const Entity* entity)
{
Team* team = entity->get<Team>();
......
......@@ -19,19 +19,21 @@
#include <game/remote_game_client.hpp>
#include <game/occupants_handler.hpp>
#include <network/server.hpp>
#include <network/timed_event_handler.hpp>
#include <world/world.hpp>
#include <game/replay.hpp>
#include <game/turn_handler.hpp>
class IPCEndpoint;
class GameServer: public Game, public Server<RemoteGameClient>
{
public:
GameServer(short port);
GameServer(short port, const std::string& ipc_path);
~GameServer();
// World* get_world();
virtual void on_new_client(RemoteGameClient*) override final;
virtual void on_client_left(RemoteGameClient*) override final;
void on_new_client(RemoteGameClient*) override final;
void on_client_left(RemoteGameClient*) override final;
void on_entity_created(const Entity* entity);
/**
......@@ -126,13 +128,17 @@ public:
void spawn_callback(Message*);
private:
void install_parent_stats_timed_event();
GameServer(const GameServer&);
GameServer& operator=(const GameServer&);
/**
* Store the already executed Actions, to pass them to save them in a
* file, and send them to the new occupants when they join a running game.
*/
TimedEventHandler timed_event_handler;
Replay replay;
std::unique_ptr<IPCEndpoint> ipc;
};
#endif // __GAME_SERVER_HPP__
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment