From 0fe7c7715770182c0ccef67e3ab839281897d364 Mon Sep 17 00:00:00 2001 From: 8nlight <8nlight@disroot.org> Date: Thu, 17 Aug 2023 07:46:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cfg.h | 15 +++++++++------ main.c | 19 ++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cfg.h b/cfg.h index 4f6367c..b8a05e2 100644 --- a/cfg.h +++ b/cfg.h @@ -1,13 +1,16 @@ -#define NICK "history" -#define HOST "irc.server.net" +//Settings +#define NICK "historybot" +#define HOST "localhost" #define PORT 6667 -#define DIR "tmp/" +#define DIR "./" char *channels[] = {"#channel"}; //Output -#define FORMAT_TXT "<%s> %s\n" +#define FORMAT_TXT "<%s> %s\n" #define FORMAT_HTML "[%s] %s
\n" -#define FORMAT FORMAT_TXT +#define FORMAT_AWK "%s %s\n" +#define FORMAT FORMAT_AWK -#define EXT ".txt" +//File ext +#define EXT ".awk" diff --git a/main.c b/main.c index d3936dd..84e581f 100644 --- a/main.c +++ b/main.c @@ -44,14 +44,11 @@ void WriteToFile(void) { fclose(fp); } -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 (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG) WriteToFile(); @@ -66,22 +63,22 @@ int main(void) { die("Cant chdir"); //512 - size of raw buffer (max irc) - IRCC_init(&client, 512); + IRCC_init(&client, IRCC_MSG_MAX); int status = IRCC_connect(&client, HOST, PORT); if (status == IRCC_ERROR) 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); + recvinfo(); 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) @@ -97,6 +94,6 @@ int main(void) { free(tmp); } - recvinfo(0); + recvinfo(); }