diff --git a/irc_server.c b/irc_server.c index 444ab64..012a41e 100644 --- a/irc_server.c +++ b/irc_server.c @@ -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); }