Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
louiz’
batajelo
Commits
6ac6ecb3
Commit
6ac6ecb3
authored
Apr 15, 2015
by
louiz’
Browse files
Introduce an IPC connection on the game_server
parent
eabbce57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
src/game/game_server.cpp
src/game/game_server.cpp
+21
-2
src/game/game_server.hpp
src/game/game_server.hpp
+10
-4
No files found.
src/game/game_server.cpp
View file @
6ac6ecb3
...
...
@@ -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
>
();
...
...
src/game/game_server.hpp
View file @
6ac6ecb3
...
...
@@ -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__
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment