rewrite parser
This commit is contained in:
parent
79a504e10b
commit
d716e164e4
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
CFLAGS?= -s -Os -flto -pedantic
|
CFLAGS?= -s -Os -flto -pedantic -Wall
|
||||||
CC?=cc
|
CC?=cc
|
||||||
all:
|
all:
|
||||||
$(CC) *.c $(CFLAGS) -obot
|
$(CC) *.c $(CFLAGS) -obot
|
||||||
|
13
cfg.h
13
cfg.h
@ -1,10 +1,17 @@
|
|||||||
//Settings
|
//Settings
|
||||||
#define NICK "historybot"
|
#define NICK "historybotd"
|
||||||
#define HOST "localhost"
|
#define HOST "irc.rizon.net" //localhost"
|
||||||
#define PORT 6667
|
#define PORT 6667
|
||||||
#define DIR "./"
|
#define DIR "./"
|
||||||
|
|
||||||
char *channels[] = {"#channel", NULL};
|
struct CHANNEL {
|
||||||
|
char *channel;
|
||||||
|
char *key;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CHANNEL channels[] = {
|
||||||
|
{"#hp", NULL}
|
||||||
|
};
|
||||||
|
|
||||||
//Put \r\n after string end
|
//Put \r\n after string end
|
||||||
//Exp: {..., "PRIVMSG NickServ IDENTIFY mypassword\r\n", ..., NULL};
|
//Exp: {..., "PRIVMSG NickServ IDENTIFY mypassword\r\n", ..., NULL};
|
||||||
|
21
main.c
21
main.c
@ -40,7 +40,7 @@ void WriteToFile(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, FORMAT, client.nick, client.msg + 1);
|
fprintf(fp, FORMAT, client.nick, client.msg);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,9 +52,6 @@ void recvinfo(void) {
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
else if (irc_status == IRCC_CONNECTED)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,21 +69,9 @@ int main(void) {
|
|||||||
IRCC_register(&client, NICK);
|
IRCC_register(&client, NICK);
|
||||||
|
|
||||||
//Recv motd and join in channel
|
//Recv motd and join in channel
|
||||||
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(struct CHANNEL); i++)
|
||||||
if (channels[i] == NULL)
|
IRCC_join(&client, channels[i].channel, channels[i].key);
|
||||||
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(send_after_join) / sizeof(char *); i++) {
|
for (size_t i = 0; i < sizeof(send_after_join) / sizeof(char *); i++) {
|
||||||
if (send_after_join[i] == NULL)
|
if (send_after_join[i] == NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user