-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot v2.txt
66 lines (64 loc) · 1.89 KB
/
bot v2.txt
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
void* chat_bot(void* arg)
{
char bot_buf[MAX_CLIENT][CHATDATA] ;
char chatData[CHATDATA];
int n = 0, pointer = 0, flag = 0, sent = 0;
char buf[CHATDATA];
char file_name[] = "bot_phrase.txt";
int word_line = words_num_in_file(file_name);
char** data = read_data(file_name, word_line);
int random = 0;
srand(time(0));
SOCKET c_socket = *(SOCKET*)arg; // bot socket
while (1) {
memset(chatData, 0, sizeof(chatData));
if ((n = recv(c_socket, chatData, sizeof(chatData),0)) > 0) {
if (strstr(chatData, end) != NULL) {
memset(chatData, '\0', sizeof(chatData));
memset(buf, '\0', sizeof(buf));
if (sent) {
sprintf(chatData, "%s: %s", nickname, escape);
send(c_socket, chatData, strlen(chatData),0);
flag = 0;
pointer = 0;
sent = 0;
}
else {
sprintf(buf, data[rand() % word_line]);
str(buf, CHATDATA);
sprintf(chatData, "%s: %s", nickname, buf);
send(c_socket, chatData, strlen(chatData),0);
sent = 1;
}
Sleep(1000);
}
else {
if (flag && !strstr(chatData, start_mess)) {
strcpy(bot_buf[pointer++], chatData);
}
if (strstr(chatData,list)) {// client want to update screen
system("cls");
pointer = 0;
flag = 1;
}
//printPony();
printf("%s", chatData);
if (strstr(chatData, start_mess)) { //delete aaa
random = rand() % pointer;
memset(chatData, '\0', sizeof(chatData));
sprintf(chatData, "%s: %s", nickname, bot_buf[random]);
puts(bot_buf[random]);
send(c_socket, chatData, sizeof(chatData), 0);
Sleep(3000);
}
if (strstr(chatData, notification)) {
Sleep(4000);
for (int i = 0; i < strlen(chatData); i++) { //clean notification
printf("\b \b");
}
send(c_socket, update, sizeof(update), 0);
}
}
}
}
}