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

This commit is contained in:
8nlight 2023-08-17 07:46:35 +03:00
parent 5aa03515c3
commit 0fe7c77157
2 changed files with 17 additions and 17 deletions

13
cfg.h
View File

@ -1,13 +1,16 @@
#define NICK "history" //Settings
#define HOST "irc.server.net" #define NICK "historybot"
#define HOST "localhost"
#define PORT 6667 #define PORT 6667
#define DIR "tmp/" #define DIR "./"
char *channels[] = {"#channel"}; char *channels[] = {"#channel"};
//Output //Output
#define FORMAT_TXT "<%s> %s\n" #define FORMAT_TXT "<%s> %s\n"
#define FORMAT_HTML "[%s] %s<br>\n" #define FORMAT_HTML "[%s] %s<br>\n"
#define FORMAT FORMAT_TXT #define FORMAT_AWK "%s %s\n"
#define FORMAT FORMAT_AWK
#define EXT ".txt" //File ext
#define EXT ".awk"

17
main.c
View File

@ -44,14 +44,11 @@ void WriteToFile(void) {
fclose(fp); fclose(fp);
} }
void recvinfo(int ignore) { void recvinfo(void) {
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)
if (!ignore)
die("Disconnected"); 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();
@ -66,22 +63,22 @@ int main(void) {
die("Cant chdir"); die("Cant chdir");
//512 - size of raw buffer (max irc) //512 - size of raw buffer (max irc)
IRCC_init(&client, 512); IRCC_init(&client, IRCC_MSG_MAX);
int status = IRCC_connect(&client, HOST, PORT); int status = IRCC_connect(&client, HOST, PORT);
if (status == IRCC_ERROR) if (status == IRCC_ERROR)
die("Conn refused"); die("Conn refused");
//Socket timeout //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) if (setsockopt(client.socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
die("setsockopt"); die("setsockopt");
//Register //Register
recvinfo(1); recvinfo();
IRCC_register(&client, NICK); IRCC_register(&client, NICK);
//Recv motd and join in channel //Recv motd and join in channel
recvinfo(0); recvinfo();
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) if (channels[i] == NULL)
@ -97,6 +94,6 @@ int main(void) {
free(tmp); free(tmp);
} }
recvinfo(0); recvinfo();
} }