]> PatchyGit - patchyircd.git/commitdiff
add MONITOR limit
authorEgor <egor@patchysicp.xyz>
Fri, 27 Oct 2023 20:19:25 +0000 (23:19 +0300)
committerEgor <egor@patchysicp.xyz>
Fri, 27 Oct 2023 20:19:25 +0000 (23:19 +0300)
src/common.h
src/irc.c
src/ircfmt.c

index 31d6707..3f1dafe 100644 (file)
@@ -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
index f790f82..508457f 100644 (file)
--- 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);
index 25a89c7..79de2e5 100644 (file)
@@ -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