-
Notifications
You must be signed in to change notification settings - Fork 172
/
epsilonServer.cpp
84 lines (74 loc) · 2.21 KB
/
epsilonServer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "epsilonServer.h"
#include "playerInfo.h"
#include "gameGlobalInfo.h"
#include "soundManager.h"
#include "multiplayer_client.h"
#include "preferenceManager.h"
#include "GMActions.h"
#include "main.h"
EpsilonServer::EpsilonServer(int server_port)
: GameServer("Server", VERSION_NUMBER, server_port)
{
if (game_server)
{
new GameGlobalInfo();
new GameMasterActions();
PlayerInfo* info = new PlayerInfo();
info->client_id = 0;
my_player_info = info;
engine->setGameSpeed(0.0);
for(auto proxy : PreferencesManager::get("serverproxy").split(":"))
{
if (proxy != "")
connectToProxy(sp::io::network::Address(proxy));
}
}
}
void EpsilonServer::onNewClient(int32_t client_id)
{
LOG(INFO) << "New client: " << client_id;
PlayerInfo* info = new PlayerInfo();
info->client_id = client_id;
}
void EpsilonServer::onDisconnectClient(int32_t client_id)
{
LOG(INFO) << "Client left: " << client_id;
foreach(PlayerInfo, i, player_info_list)
if (i->client_id == client_id)
i->destroy();
player_info_list.update();
}
void disconnectFromServer()
{
soundManager->stopMusic();
if (game_client)
game_client->destroy();
if (game_server)
game_server->destroy();
if (gameGlobalInfo)
gameGlobalInfo->destroy();
if (gameMasterActions)
gameMasterActions->destroy();
foreach(PlayerInfo, i, player_info_list)
i->destroy();
if (my_player_info)
my_player_info->destroy();
}
std::unordered_set<int32_t> EpsilonServer::onVoiceChat(int32_t client_id, int32_t target_identifier)
{
if (target_identifier == 0)
{
//Communicate to local ship.
int32_t ship_id = -1;
foreach(PlayerInfo, i, player_info_list)
if (i->client_id == client_id)
ship_id = i->ship_id;
std::unordered_set<int32_t> result;
foreach(PlayerInfo, i, player_info_list)
if (i->ship_id == ship_id && i->client_id != client_id)
result.insert(i->client_id);
return result;
}
//Else communicate to everyone.
return GameServer::onVoiceChat(client_id, target_identifier);
}