-
Notifications
You must be signed in to change notification settings - Fork 0
/
bekad.cpp
executable file
·67 lines (61 loc) · 2.32 KB
/
bekad.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
#include "server.h"
#include <cstdlib>
#include <signal.h>
using namespace beka;
Server server;
void sig_handler(int signo)
{
if (signo == SIGINT)
{
server.terminateServer();
printf("\nexiting...\n");
exit(0);
}
}
int main()
{
std::string result;
if (signal(SIGINT, sig_handler) == SIG_ERR)
printf("\ncan't catch SIGINT\n");
while (1)
{
if (!(result = server.waitForResponse()).empty())
{
rapidjson::Document d;
d.Parse(result.c_str());
if (strcmp(d["request"].GetString(), "connect") == 0)
server.addUser(d["username"].GetString(), d["temp_id"].GetInt(), d["request_id"].GetInt());
else if (strcmp(d["request"].GetString(), "quit_server") == 0)
server.deleteUser(d["user_id"].GetInt(), d["request_id"].GetInt());
else if (strcmp(d["request"].GetString(), "list_channels") == 0)
server.sendChannelsList(d["user_id"].GetInt(), d["request_id"].GetInt());
else if (strcmp(d["request"].GetString(), "join_channel") == 0)
server.joinUserToChannel(d["user_id"].GetInt(), d["channel_name"].GetString(), d["request_id"].GetInt());
else if (strcmp(d["request"].GetString(), "list_users") == 0)
server.sendUsersOnChannel(d["user_id"].GetInt(), d["channel_name"].GetString(), d["request_id"].GetInt());
else if (strcmp(d["request"].GetString(), "quit_channel") == 0)
server.removeUserFromChannel(d["user_id"].GetInt(), d["channel_name"].GetString(), d["request_id"].GetInt());
else if (strcmp(d["request"].GetString(), "send_message") == 0)
{
server.sendPM(d["user"].GetString(), d["message"]["text"].GetString(), d["user_id"].GetInt(), d["request_id"].GetInt());
}
else if (strcmp(d["request"].GetString(), "send_channel_message") == 0)
{
server.sendToChannel(d["channel_name"].GetString(), d["message"]["text"].GetString(), d["user_id"].GetInt(), d["request_id"].GetInt());
}
else if (strcmp(d["request"].GetString(), "kick") == 0)
{
/*
{"request":"kick","ban":true,"kicked_user":"niema","user_id":10370,"request_id":4,"reason":"bo tak","channel":"guwno"}
*
*/
server.kickUser(d["ban"].GetBool(), d["user_id"].GetInt(), d["kicked_user"].GetString(), d["channel_name"].GetString(), d["reason"].GetString(), d["request_id"].GetInt());
}
else
{
server.sendUnknownRequest(d["user_id"].GetInt(), d["request_id"].GetInt());
}
}
}
return 0;
}