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

This commit is contained in:
8nlight 2023-08-09 21:54:13 +03:00
parent 0c820b8689
commit 5aa03515c3

26
main.c
View File

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