-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
64 lines (49 loc) · 1.88 KB
/
main.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
#include "server.hpp"
#include "command.hpp"
int main() {
serverhandel server;
command cmd;
std::string buffer;
if (!server.server_init()) {
std::cerr << "Server initialization failed" << std::endl;
return -1;
}
if (!server.server_lisen()) {
std::cerr << "Server listening failed" << std::endl;
return -2;
}
while (true) {
std::cout << "Waiting for client connection..." << std::endl;
if (server.server_accept_client()) {
std::cout << "Client connected." << std::endl;
server.server_send_msg("/--------------------/\n");
server.server_send_msg("menu\n");
server.server_send_msg("Enter a command or type 'exit' to quit\n");
while (true) {
buffer = server.server_read();
server.trim_end(buffer);
if (buffer == "exit") {
server.server_send_msg("Exiting the server...\n");
server.server_close();
std::cout << "Program finished." << std::endl;
return 0;
}
if (buffer == "terminal") {
buffer = cmd.open_terminal();
server.server_send_msg(buffer);
buffer = "nothing"; // Reset buffer for next read
}
else if (buffer == "firefox") {
buffer = cmd.open_firefox();
server.server_send_msg(buffer);
buffer = "nothing"; // Reset buffer for next read
}
else if (buffer == "calculator") {
buffer = cmd.open_calculator();
server.server_send_msg(buffer);
buffer = "nothing"; // Reset buffer for next read
}
}
}
}
}