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

This commit is contained in:
8nlight 2023-08-17 10:01:33 +03:00
parent 569a6faea5
commit a50ebb3d26
3 changed files with 16 additions and 20 deletions

View file

@ -1,10 +1,11 @@
#include "irc.h"
//Config
#define HOST "irc.server.net"
#define HOST "localhost"
#define PORT 6667
#define NICK "tester"
char *channels[] = {"#test"};
#define NICK "tester134"
char *channels[] = {"#channel"};
#define CHECK_NULL() (client.nick != NULL && client.channel != NULL && client.msg != NULL)
IRCC_client client;
@ -15,29 +16,23 @@ void die(char *msg) {
exit(1);
}
void recvinfo(int ignore) {
void recvinfo(void) {
while (1) {
unsigned int irc_status = IRCC_recv(&client);
if (irc_status == IRCC_DISCONNECTED) {
if (!ignore)
die("Disconnected");
return;
}
if (irc_status == IRCC_DISCONNECTED)
die("Disconnected");
else if (strstr(client.raw, "No Ident") || irc_status == IRCC_CONNECTED)
else if (irc_status == IRCC_CONNECTED)
return;
//Print
if (!CHECK_NULL())
return;
if (irc_status == IRCC_PRIVMSG)
if (CHECK_NULL() && irc_status == IRCC_PRIVMSG)
printf("[%s %s] %s\n", client.channel, client.nick, client.msg);
else if (irc_status == IRCC_NICK)
else if (CHECK_NULL() && irc_status == IRCC_NICK)
printf("[N] %s is know as %s\n", client.nick, client.msg);
else if (irc_status == IRCC_TOPIC)
else if (CHECK_NULL() && irc_status == IRCC_TOPIC)
printf("[T] %s\n", client.msg);
else if (irc_status == IRCC_JOIN)
@ -57,16 +52,15 @@ int main(void) {
die("Conn refused");
//Socket timeout
struct timeval tv = {5, 5};
struct timeval tv = {IRCC_PING_TIMEOUT, IRCC_PING_TIMEOUT};
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(0);
recvinfo();
sleep(5);
for (size_t i = 0; i < sizeof(channels) / sizeof(char *); i++) {
if (channels[i] == NULL)
@ -82,6 +76,6 @@ int main(void) {
free(tmp);
}
recvinfo(0);
recvinfo();
}