forked from DFHack/stonesense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionState.cpp
43 lines (37 loc) · 1.22 KB
/
ConnectionState.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
#include "ConnectionState.h"
#include <iostream>
using namespace std;
ConnectionState::ConnectionState() {
df_network_out = new DFHack::color_ostream_wrapper(std::cout);
network_client = new DFHack::RemoteClient(df_network_out);
is_connected = network_client->connect();
if (!is_connected) return;
MaterialListCall.bind(network_client, "GetMaterialList", "RemoteFortressReader");
GrowthListCall.bind(network_client, "GetGrowthList", "RemoteFortressReader");
BlockListCall.bind(network_client, "GetBlockList", "RemoteFortressReader");
HashCheckCall.bind(network_client, "CheckHashes", "RemoteFortressReader");
TiletypeListCall.bind(network_client, "GetTiletypeList", "RemoteFortressReader");
}
ConnectionState::~ConnectionState() {
network_client->disconnect();
delete network_client;
delete df_network_out;
}
void ConnectionState::Connect()
{
connection_state = new ConnectionState;
if (!connection_state->is_connected)
{
delete connection_state;
connection_state = NULL;
}
}
void ConnectionState::Disconnect()
{
if (connection_state)
{
delete connection_state;
connection_state = NULL;
}
}
ConnectionState *connection_state = NULL;