-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.cpp
More file actions
70 lines (48 loc) · 1.2 KB
/
client.cpp
File metadata and controls
70 lines (48 loc) · 1.2 KB
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
#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <chrono>
#include "resources/GameHandler.h"
#include <mutex>
int PORT ;
std::string HOST ;
std::string SERVER_IP;
extern Game game;
bool readConfig(){
std::ifstream file("../config.json"); // Open the json file
if (!file.is_open()) {
std::cerr << "Failed to open config.json" << std::endl;
return false;
}
json jsonData; // Create a json object
try {
file >> jsonData; // Parse the json data from the file
PORT=jsonData["server_port"].get<int>();
SERVER_IP=jsonData["server_ip"];
HOST=jsonData["server_ip"];
} catch (json::parse_error& e) {
std::cerr << "json parse error: " << e.what() << std::endl;
return false ;
}
return true;
}
int main() {
if(!readConfig()){
return 1;
}
curl_global_init(CURL_GLOBAL_DEFAULT);
GameHandler handler(HOST,SERVER_IP,PORT);
game.SetServersPort(PORT);
game.SetServer(SERVER_IP);
if(!handler.begin()){
std::cerr<<"couldnt connect to server";
return 1;
}
game.SetToken(handler.GetToken());
game.SetClient();
handler.ready();
while (handler.GetGameOn());
handler.join();
curl_global_cleanup();
}