Compare commits

..
6 Commits
Author SHA1 Message Date
retoor 5492c95dd3 chore: bump buffer limits and add epoll event update helper for client writes 2025-05-06 16:00:18 +00:00
retoor 21d73bc185 chore: add .gitignore with build artifacts and test binaries 2025-05-06 14:09:26 +00:00
retoor 2ee1ff809c fix: rename logmsg to log_event and add structured logging with host info in IRC server
- Renamed `logmsg` function to `log_event` for consistency with new logging format
- Added ISO 8601 timestamp buffer `timebuf` and replaced `tbuf` with it in log output
- Updated join/leave log messages to include client host and structured format (e.g., "user joined: <nick> (<host>) joined channel <name>")
- Moved leave log call inside the member removal loop to ensure it fires only on actual removal
2025-05-06 13:52:54 +00:00
retoor 33ce55f862 feat: add --log flag and structured logmsg function for join/part/disconnect events 2025-05-06 13:44:09 +00:00
retoor 7a2e4b570e fix: strip leading numeric codes from IRC reply prefixes in send_motd and send_lusers 2025-05-06 13:26:23 +00:00
retoor 8b3fb39b21 chore: add initial IRC server with epoll and load testing tool scaffolding 2025-05-06 13:00:06 +00:00
2 changed files with 20 additions and 7 deletions
+4
View File
@@ -0,0 +1,4 @@
irc_echo_boy.py
irc_server
load_test
motd.txt
+16 -7
View File
@@ -21,12 +21,12 @@
// MIT License
#define MAX_EVENTS 4096
#define MAX_CHANNELS 1024
#define MAX_NICKLEN 51
#define MAX_USERLEN 51
#define MAX_CHANNELLEN 51
#define MAX_TOPICLEN 256
#define MAX_MSG 512
#define MAX_CHANNELS 4096
#define MAX_NICKLEN 4096
#define MAX_USERLEN 4096
#define MAX_CHANNELLEN 128
#define MAX_TOPICLEN 4096
#define MAX_MSG 4096
#define MOTD_FILE "motd.txt"
#define SERVER_NAME "rirc"
#define VERSION "1.0"
@@ -39,7 +39,7 @@ typedef struct Client {
char nickname[MAX_NICKLEN+1];
char user[MAX_USERLEN+1];
char realname[MAX_USERLEN+1];
char host[64];
char host[128];
int registered;
int pass_ok;
char readbuf[MAX_MSG*2];
@@ -117,6 +117,12 @@ static void del_epoll(int fd) {
epoll_ctl(epoll_fd, EPOLL_CTL_DEL, fd, NULL);
}
static void update_client_events(Client *c) {
uint32_t events = EPOLLIN;
if (c->writebuf_len > 0) events |= EPOLLOUT;
mod_epoll(c->fd, events, c);
}
static void send_reply(Client *c, const char *fmt, ...) {
char buf[MAX_MSG];
va_list ap;
@@ -125,6 +131,7 @@ static void send_reply(Client *c, const char *fmt, ...) {
va_end(ap);
int n = snprintf(c->writebuf + c->writebuf_len, sizeof(c->writebuf) - c->writebuf_len, ":%s %s\r\n", SERVER_NAME, buf);
if (n > 0 && c->writebuf_len + n < sizeof(c->writebuf)) c->writebuf_len += n;
update_client_events(c);
}
static void send_raw(Client *c, const char *fmt, ...) {
@@ -135,6 +142,7 @@ static void send_raw(Client *c, const char *fmt, ...) {
va_end(ap);
int n = snprintf(c->writebuf + c->writebuf_len, sizeof(c->writebuf) - c->writebuf_len, "%s\r\n", buf);
if (n > 0 && c->writebuf_len + n < sizeof(c->writebuf)) c->writebuf_len += n;
update_client_events(c);
}
static Channel *find_channel(const char *name) {
@@ -517,6 +525,7 @@ int main(int argc, char **argv) {
char *line, *saveptr;
line = strtok_r(c->readbuf, "\r\n", &saveptr);
while (line) {
printf("%s\n",line);
handle_line(c, line);
line = strtok_r(NULL, "\r\n", &saveptr);
}