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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| struct irc_msg {
SOCKET serv;
char *nick;
char *event;
char *text;
char *chaine;
char *name;
char *domain;
};
void send_line(SOCKET Client, char* buffer) {
int i = 0;
while(i< strlen(buffer)) {
send(Client, (char *)&buffer[i], 1, 0);
i++;
}
}
int range(struct irc_msg *ircmsg) {
int ret, i = 0;
char *txt = NULL;
ret = sscanf(ircmsg->chaine, ":%s %s", ircmsg->nick, ircmsg->event);
txt = strstr(ircmsg->nick, "!");
if(txt != NULL) { // Si c'est un méssage de client
txt = NULL;
ret = sscanf(ircmsg->chaine, ":%[^!]!%s %[^\n]", ircmsg->nick, ircmsg->domain, ircmsg->text);
txt = strstr(ircmsg->text, ":");
if (txt != NULL && ret == 3) {
while(txt[i+1] != '\n') { // Lecture du texte
ircmsg->text[i] = txt[i+1];
i++;
}
printf("%s : %s %s\n\n", ircmsg->nick, ircmsg->event, ircmsg->text);
return 0;
}
printf("%s : %s\n\n", ircmsg->nick, ircmsg->text);
return 0;
} // End méssage clients
printf("%s\n", ircmsg->chaine);
return 0;
}
int fonctions(struct irc_msg *ircmsg) {
char *txt = NULL;
int t_buff = 0, ret;
FILE* file = NULL;
char buff[500] = "";
char buff2[500] = "";
txt = strstr(ircmsg->chaine, "PING"); // PING
if (txt != NULL && ircmsg->chaine[0] == 'P') {
ircmsg->chaine[1] = 'O';
send_line(ircmsg->serv, ircmsg->chaine);
send_line(ircmsg->serv, "\r\n\r\n");
return 0;
} // End PING
file = fopen("b_words.txt", "r");
while(fgets(buff, 20, file) != NULL) {
t_buff = strlen(buff);
buff[t_buff - 1] = '\0'; // Gros mots
txt = strstr(ircmsg->text, buff);
if (txt != NULL && strcmp(ircmsg->nick, "romfox") != 0) {
sprintf(buff2, "KICK #romfox %s\r\n\r\n",ircmsg->nick);
send_line(ircmsg->serv, buff2);
return 0;
}
} // End gros mots
fclose(file);
// JOIN
if(strcmp(ircmsg->event, "JOIN") == 0 && strcmp(ircmsg->nick, "Bot-fox") != 0) {
file = fopen("bvn.txt", "r");
fgets(buff, 500, file);
fclose(file);
sprintf(buff2, "PRIVMSG #romfox :Bonjour %s\r\n\r\n", ircmsg->nick);
send_line(ircmsg->serv, buff2);
sprintf(buff2, "PRIVMSG %s :%s\r\n\r\n", ircmsg->nick, buff);
send_line(ircmsg->serv, buff2);
return 0;
} // End JOIN
txt = NULL;
txt = strstr(ircmsg->text, "!say"); // !SAY
if (txt != NULL && txt[0] == '!') {
ret = sscanf(ircmsg->text, "!say %[^\n]", buff);
sprintf(buff2, "PRIVMSG #romfox :%s\r\n\r\n", buff);
send_line(ircmsg->serv, buff2);
return 0;
} // End !SAY
txt = NULL;
txt = strstr(ircmsg->text, "!voice"); // !VOICE
if(txt != NULL && ircmsg->text[1] == 'v') {
sprintf(buff, "MODE #romfox +v %s\r\n\r\n", ircmsg->nick);
send_line(ircmsg->serv, buff);
return 0;
} // End !VOICE
txt = NULL; // !KICK
txt = strstr(ircmsg->text, "!kick");
if(txt != NULL && ircmsg->text[1] == 'k') {
sscanf(ircmsg->text, "!kick %[^\n]", buff);
txt = NULL;
txt = strstr(buff, "romfox");
if (txt == NULL) {
sprintf(buff2, "KICK #romfox %s\r\n\r\n", buff);
send_line(ircmsg->serv, buff2);
}
return 0; // End !KICK
return 0;
}
}
int recv_line(struct irc_msg *irc_mss) {
int i = 0, t_buff;
struct timeval temps;
temps.tv_sec = 0;
temps.tv_usec = 100;
fd_set read;
FD_ZERO(&read);
FD_SET(irc_mss->serv, &read);
select(irc_mss->serv+1, &read, NULL, NULL, &temps);
if(FD_ISSET(irc_mss->serv, &read)) {
t_buff = recv(irc_mss->serv, irc_mss->chaine, 512, 0);
irc_mss->chaine[t_buff] = '\0';
range(irc_mss);
fonctions(irc_mss);
}
return 0;
} |
Partager