From d716e164e4a6d04460e3295ad02dac2c5cedea63 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Dec 2023 16:41:27 +0300 Subject: [PATCH] rewrite parser --- Makefile | 2 +- README.md | 2 -- cfg.h | 13 ++++++++++--- main.c | 21 +++------------------ 4 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 README.md diff --git a/Makefile b/Makefile index b545937..06c2793 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS?= -s -Os -flto -pedantic +CFLAGS?= -s -Os -flto -pedantic -Wall CC?=cc all: $(CC) *.c $(CFLAGS) -obot diff --git a/README.md b/README.md deleted file mode 100644 index 6c8480e..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# history - diff --git a/cfg.h b/cfg.h index 7721da8..a701f15 100644 --- a/cfg.h +++ b/cfg.h @@ -1,10 +1,17 @@ //Settings -#define NICK "historybot" -#define HOST "localhost" +#define NICK "historybotd" +#define HOST "irc.rizon.net" //localhost" #define PORT 6667 #define DIR "./" -char *channels[] = {"#channel", NULL}; +struct CHANNEL { + char *channel; + char *key; +}; + +struct CHANNEL channels[] = { + {"#hp", NULL} +}; //Put \r\n after string end //Exp: {..., "PRIVMSG NickServ IDENTIFY mypassword\r\n", ..., NULL}; diff --git a/main.c b/main.c index 23a6679..9c46440 100644 --- a/main.c +++ b/main.c @@ -40,7 +40,7 @@ void WriteToFile(void) { return; } - fprintf(fp, FORMAT, client.nick, client.msg + 1); + fprintf(fp, FORMAT, client.nick, client.msg); fclose(fp); } @@ -52,9 +52,6 @@ void recvinfo(void) { else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG) WriteToFile(); - - else if (irc_status == IRCC_CONNECTED) - return; } } @@ -72,21 +69,9 @@ int main(void) { IRCC_register(&client, NICK); //Recv motd and join in channel - recvinfo(); 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) - die("malloc retured NULL"); - - snprintf(tmp, join_size, "JOIN %s\r\n", channels[i]); - send(client.socket, tmp, join_size, 0); - free(tmp); - } + for (size_t i = 0; i < sizeof(channels) / sizeof(struct CHANNEL); i++) + IRCC_join(&client, channels[i].channel, channels[i].key); for (size_t i = 0; i < sizeof(send_after_join) / sizeof(char *); i++) { if (send_after_join[i] == NULL)