]> PatchyGit - patchyircd.git/commitdiff
irc: turn channel length limit into a define
authorEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 04:54:13 +0000 (06:54 +0200)
committerEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 04:54:13 +0000 (06:54 +0200)
Also add 476 response.

Also move that stuff out of config.h. This isn't something that should
be configured at compile time.

src/common.h
src/config.h
src/irc.cpp
src/ircfmt.cpp
src/ircfmt.h

index 5d7e02b..43288ea 100644 (file)
@@ -11,6 +11,8 @@
 struct tls;
 #endif
 
+#define MAX_NICKLEN 32
+#define MAX_CHANLEN 33
 #define MONITOR_LIMIT 100
 
 #define SETBIT(var, bit, val) ((void)((val) ? ((var)|=(bit)) : ((var)&=~(bit))))
index f34bca1..0139baa 100644 (file)
@@ -1,4 +1,3 @@
-#define MAX_NICKLEN 32
 #ifndef ADMINLOC1
 #define ADMINLOC1 "Location 1"
 #endif
index fc54316..5c14123 100644 (file)
@@ -1466,13 +1466,13 @@ void channel_join(struct client_data *client, const char *channel, const char *c
 {
        // TODO: check channel limit?
        if (channel[0] != '#' && channel[0] != '&')
-               return; // FIXME: error
+               return err_badchanmask(client, channel), sendbuf(client);
        if (strchr(channel, '\7') || strchr(channel, ' ') || strchr(channel, ','))
-               return; // FIXME: error
+               return err_badchanmask(client, channel), sendbuf(client);
        size_t chanlen = strlen(channel);
-       if (chanlen > 32)
-               return; // FIXME: error
-       char key[33];
+       if (chanlen >= MAX_CHANLEN)
+               return err_badchanmask(client, channel), sendbuf(client);
+       char key[MAX_CHANLEN];
        memcpy(key, channel, chanlen+1);
        stringlower(key);
        struct channel *chan = channel_map.get(key);
@@ -1784,9 +1784,9 @@ struct client_data *findClient(const char *nickname)
 struct channel *findChannel(const char *channel)
 {
        size_t chanlen = strlen(channel);
-       if (chanlen > 32)
+       if (chanlen >= MAX_CHANLEN)
                return NULL;
-       char key[33];
+       char key[MAX_CHANLEN];
        memcpy(key, channel, chanlen+1);
        stringlower(key);
        return channel_map.get(key);
index 969c373..f2d8d56 100644 (file)
@@ -150,7 +150,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=%u :are supported by this server\r\n", hostname, client->nick, MAX_NICKLEN-1, MONITOR_LIMIT);
+       copy_strf(&databuf, ":%s 005 %s NETWORK=PatchyIRC CASEMAPPING=ascii NICKLEN=%u CHANNELLEN=%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, MAX_CHANLEN-1, MONITOR_LIMIT);
 
 }
 #if 0
@@ -648,7 +648,10 @@ void err_badchannelkey(struct client_data *client, struct channel *chan) // 475
 {
        copy_strf(&databuf, ":%s 475 %s %s :Cannot join channel (+k)\r\n", hostname, client->nick, chan->name);
 }
-// 476 ERR_BADCHANMASK
+void err_badchanmask(struct client_data *client, const char *channel) // 476
+{
+       copy_strf(&databuf, ":%s 476 %s :Bad Channel Mask\r\n", hostname, client->nick, channel);
+}
 void err_noprivileges(struct client_data *client) // 481
 {
        copy_strf(&databuf, ":%s 481 %s :Permission Denied- You're not an IRC operator\r\n", hostname, client->nick);
index 75ef093..8757660 100644 (file)
@@ -122,7 +122,7 @@ void err_unknownmode(struct client_data *client, char mode); // 472
 void err_inviteonlychan(struct client_data *client, struct channel *chan); // 473
 void err_bannedfromchan(struct client_data *client, struct channel *chan); // 474
 void err_badchannelkey(struct client_data *client, struct channel *chan); // 475
-// 476 ERR_BADCHANMASK
+void err_badchanmask(struct client_data *client, const char *channel); // 476
 void err_noprivileges(struct client_data *client); // 481
 void err_chanoprivsneeded(struct client_data *client, struct channel *chan); // 481
 // 483 ERR_CANTKILLSERVER