-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (49 loc) · 1.25 KB
/
Copy pathmain.cpp
File metadata and controls
58 lines (49 loc) · 1.25 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
#include <iostream>
#include <string>
#include <thread>
#include "ServerThread.h"
#include "ClientThread.h"
#include "RemoteServer.h"
#include "config.h"
void usage() {
std::cout << "Usage: maze -s N M [PORT] or HOST [PORT]" << std::endl;
std::cout << " N: grid size." << std::endl;
std::cout << " M: number of treasures." << std::endl;
exit(-1);
}
int main(int argc, char* argv[]) {
bool fake = false;
if (argc > 1 && std::string(argv[1]) == "-f") {
fake = true;
++argv;
--argc;
}
if (argc < 2)
usage();
ClientThread ct(fake);
try {
if (std::string(argv[1]) == "-s") {
if (argc < 4 || argc > 5)
usage();
ServerThread *st = new ServerThread(std::stoi(argv[2]), std::stoi(argv[3]), ct);
const char* port = argc == 5 ? argv[4] : PORT;
st->init(port);
st->acceptClients();
ct.init(st);
} else {
if(argc > 3)
usage();
RemoteServer* serv = new RemoteServer(ct);
const char* host = argv[1];
const char* port = argc == 3 ? argv[2] : PORT;
serv->init(host, port);
ct.init(serv);
}
ct.loop();
} catch(std::string const& e) {
std::cerr << "Error : " << e << std::endl;
return -1;
}
std::cout << "Game exiting...\n";
return 0;
}