From 52fc576db08be0639a44da4351c521f1f98d308c Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 27 Oct 2023 23:19:25 +0300 Subject: [PATCH] add MONITOR limit --- src/common.h | 2 ++ src/irc.c | 10 ++++++++-- src/ircfmt.c | 4 +--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/common.h b/src/common.h index 31d6707..3f1dafe 100644 --- a/src/common.h +++ b/src/common.h @@ -11,6 +11,8 @@ struct tls; #endif +#define MONITOR_LIMIT 100 + #define SETBIT(var, bit, val) ((void)((val) ? ((var)|=(bit)) : ((var)&=~(bit)))) #define UMODE_INVISIBLE 1 #define UMODE_OPER 2 diff --git a/src/irc.c b/src/irc.c index f790f82..508457f 100644 --- a/src/irc.c +++ b/src/irc.c @@ -1076,14 +1076,20 @@ int processPacket(struct client_data *client, char *source, char *command, int a if (strchr(args[1], ' ')) return err_needmoreparams(client, command), sendbuf(client), 0; /* FIXME: wrong error */ stringlower(args[1]); + int monitor_count = 0; + map_foreach(&client->monitor, 0, 0) + monitor_count++; char *p = args[1]; do { char *nick = p; + if (monitor_count == MONITOR_LIMIT) + return rpl_monlistfull(client, MONITOR_LIMIT,nick), sendbuf(client), 0; if ((p = strchr(nick, ','))) *p++ = '\0'; - /* TODO: rpl_monlistfull */ - if (map_set(&client->monitor, nick, /* dummy */ nick, 0) == -1) + char *existing; + if (map_set(&client->monitor, nick, /* dummy */ nick, (void **)&existing) == -1) abort(); + monitor_count += !existing; struct client_data *cl = map_get(&client_map, nick); if (cl) rpl_mononline(client, cl), sendbuf(client); diff --git a/src/ircfmt.c b/src/ircfmt.c index 25a89c7..79de2e5 100644 --- a/src/ircfmt.c +++ b/src/ircfmt.c @@ -133,7 +133,7 @@ void rpl_myinfo(struct client_data *client) // 004 } void rpl_isupport(struct client_data *client) // 005 { - copy_strf(&databuf, ":%s 005 %s NETWORK=PatchyIRC CASEMAPPING=ascii NICKLEN=%u EXCEPTS=e INVEX=I MAXTARGETS=1 CHANMODES=beIqw,k,l,Pimnst CHANTYPES=#& PREFIX=(ov)@+ STATUSMSG=@+ BOT=B WHOX MONITOR :are supported by this server\r\n", hostname, client->nick, MAX_NICKLEN-1); + copy_strf(&databuf, ":%s 005 %s NETWORK=PatchyIRC CASEMAPPING=ascii NICKLEN=%u EXCEPTS=e INVEX=I MAXTARGETS=1 CHANMODES=beIqw,k,l,Pimnst CHANTYPES=#& PREFIX=(ov)@+ STATUSMSG=@+ BOT=B WHOX MONITOR=%u :are supported by this server\r\n", hostname, client->nick, MAX_NICKLEN-1, MONITOR_LIMIT); } #if 0 @@ -701,12 +701,10 @@ void rpl_endofmonlist(struct client_data *client) // 733 { copy_strf(&databuf, ":%s 733 %s :End of MONITOR list\r\n", hostname, client->nick); } -#if 0 void rpl_monlistfull(struct client_data *client, int limit, const char *targets) // 734 { copy_strf(&databuf, ":%s 734 %s %d %s :Monitor list is full.\r\n", hostname, client->nick, limit, targets); } -#endif // 900 RPL_LOGGEDIN // 901 RPL_LOGGEDOUT // 902 ERR_NICKLOCKED -- 2.56.0