Загрузить файлы в «»

This commit is contained in:
8nlight 2023-08-09 21:54:13 +03:00
parent 0c820b8689
commit 5aa03515c3
1 changed files with 19 additions and 7 deletions

26
main.c
View File

@ -44,11 +44,14 @@ void WriteToFile(void) {
fclose(fp);
}
void recvinfo(void) {
void recvinfo(int ignore) {
while (1) {
unsigned int irc_status = IRCC_recv(&client);
if (irc_status == IRCC_DISCONNECTED)
die("Disconnected");
if (irc_status == IRCC_DISCONNECTED) {
if (!ignore)
die("Disconnected");
return;
}
else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG)
WriteToFile();
@ -68,14 +71,22 @@ int main(void) {
if (status == IRCC_ERROR)
die("Conn refused");
//Register and join in channel
recvinfo();
//Socket timeout
struct timeval tv = {5, 5};
if (setsockopt(client.socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
die("setsockopt");
//Register
recvinfo(1);
IRCC_register(&client, NICK);
//Recv motd and join in channel
recvinfo();
recvinfo(0);
sleep(5);
for (size_t i = 0; i < sizeof(channels) / sizeof(char *); i++) {
if (channels[i] == NULL)
break;
size_t join_size = strlen("JOIN \r\n") + strlen(channels[i]) + 1;
char *tmp = malloc(join_size);
if (tmp == NULL)
@ -86,5 +97,6 @@ int main(void) {
free(tmp);
}
recvinfo();
recvinfo(0);
}