This commit is contained in:
Your Name 2025-06-28 10:58:12 +03:00
parent 718f290ba4
commit 73b55ebd79
3 changed files with 103 additions and 64 deletions

View file

@ -6,10 +6,13 @@
#include "irc.h"
/* Config */
#define HOST "irc.rizon.net"
#define HOST "192.168.0.136"
#define PORT 6667
#define NICK "tester134"
char *channels[] = {"#testo"};
#define NICK "tester"
#define PASS NULL
char *channels[] = {
"#test"
};
#define CHECK_NULL() (client.irc_nick != NULL && client.irc_channel != NULL && client.irc_msg != NULL)
IRCC_client client;
@ -34,6 +37,8 @@ void recvinfo(void) {
die("Disconnected");
irc_status = IRCC_parse(&client);
if (irc_status < 0)
die("Parser");
/* Print */
if (CHECK_NULL() && irc_status == IRCC_PRIVMSG)
@ -46,10 +51,10 @@ void recvinfo(void) {
printf("[T] %s\n", client.irc_msg);
else if (client.irc_nick != NULL && irc_status == IRCC_JOIN)
printf("[>] %s\n", client.irc_nick);
printf("[>] %s (%s)\n", client.irc_nick, client.irc_msg);
else if (client.irc_nick != NULL && irc_status == IRCC_QUIT)
printf("[<] %s\n", client.irc_nick);
printf("[<] %s (%s)\n", client.irc_nick, client.irc_msg);
else
printf("> %s\n", client.irc_raw);
@ -60,23 +65,40 @@ int main(void) {
signal(SIGINT, handler);
int status = IRCC_connect(&client, HOST, PORT);
if (status == IRCC_ERROR)
if (status < 0)
die("Conn refused");
if (IRCC_initssl(&client) == IRCC_ERROR) {
if (IRCC_initssl(&client) < 0) {
IRCC_close(&client);
die("ssl error");
}
/* Register and skip motd */
IRCC_register(&client, NICK);
if (PASS) {
IRCC_send(&client,
IRCC_GET_CMD(IRCC_FMT_PASS),
PASS);
}
/* Registration */
sleep(1);
IRCC_send(&client,
IRCC_GET_CMD(IRCC_FMT_USER),
NICK,
NICK,
NICK,
NICK);
IRCC_send(&client,
IRCC_GET_CMD(IRCC_FMT_NICK),
NICK);
sleep(5);
for (size_t i = 0; i < sizeof(channels) / sizeof(char *); i++) {
if (channels[i] == NULL)
break;
IRCC_join(&client, channels[i], NULL);
IRCC_send(&client,
IRCC_GET_CMD(IRCC_FMT_JOIN),
channels[i]);
}
recvinfo();