From aa28da18fe2854174f8b54db520e5a1979902abf Mon Sep 17 00:00:00 2001 From: 8nl <8nlight@disroot.org> Date: Tue, 23 Jan 2024 17:00:22 +0000 Subject: [PATCH] Upload files to "/" --- cfg.h | 4 ++-- main.c | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cfg.h b/cfg.h index a701f15..ad274eb 100644 --- a/cfg.h +++ b/cfg.h @@ -1,6 +1,6 @@ //Settings -#define NICK "historybotd" -#define HOST "irc.rizon.net" //localhost" +#define NICK "histbot" +#define HOST "192.168.0.184" //localhost" #define PORT 6667 #define DIR "./" diff --git a/main.c b/main.c index 9c46440..b2e394d 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,11 @@ +#include +#include +#include +#include +#include #include "irc.h" #include "cfg.h" -#include + IRCC_client client; void die(char *msg) { @@ -18,17 +23,17 @@ char *GetFilename(void) { //Get filename + date struct tm tm = GetTime(); - size_t filename_size = strlen(client.channel + 1) + (sizeof(tm.tm_year) * 3) + strlen(EXT) + 3; + size_t filename_size = strlen(client.irc_channel + 1) + (sizeof(tm.tm_year) * 3) + strlen(EXT) + 3; char *filename = malloc(filename_size + 1); if (filename == NULL) die("malloc returned NULL"); - snprintf(filename, filename_size, "%s-%d-%d-%d%s", client.channel + 1, tm.tm_year + 1900, tm.tm_mon, tm.tm_mday, EXT); + snprintf(filename, filename_size, "%s_%d-%d-%d%s", client.irc_channel + 1, tm.tm_mday, tm.tm_mon, tm.tm_year, EXT); return filename; } void WriteToFile(void) { - if (client.msg[1] == '.' || client.channel[0] != '#') + if (client.irc_msg[1] == '.' || client.irc_channel[0] != '#') return; char *filename = GetFilename(); @@ -36,21 +41,22 @@ void WriteToFile(void) { free(filename); if (fp == NULL) { - printf("Cant open file %s\n", client.channel); + printf("Cant open file %s\n", client.irc_channel); return; } - fprintf(fp, FORMAT, client.nick, client.msg); + fprintf(fp, FORMAT, client.irc_nick, client.irc_msg); fclose(fp); } void recvinfo(void) { while (1) { - unsigned int irc_status = IRCC_recv(&client); + int irc_status = IRCC_recv(&client); if (irc_status == IRCC_DISCONNECTED) die("Disconnected"); - else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG) + irc_status = IRCC_parse(&client); + if (client.irc_nick != NULL && client.irc_channel != NULL && client.irc_msg != NULL && irc_status == IRCC_PRIVMSG) WriteToFile(); } } @@ -77,7 +83,7 @@ int main(void) { if (send_after_join[i] == NULL) break; - send(client.socket, send_after_join[i], strlen(send_after_join[i]), 0); + send(client.irc_socket, send_after_join[i], strlen(send_after_join[i]), 0); } recvinfo();