]> PatchyGit - patchyircd.git/commitdiff
add %u format string
authorEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 22:03:14 +0000 (01:03 +0300)
committerEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 22:03:14 +0000 (01:03 +0300)
irc.c
util.c

diff --git a/irc.c b/irc.c
index 536a432..1a2f059 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -328,10 +328,8 @@ int processPacket(struct client_data *client) {
                if (trie_findfirst(&f, &channel_map) == 1)
                        do {
                                struct channel *chan = f->n->value;
-                               //copy_strf(&databuf, ":%s 322 %s %s %d :%s\n", hostname, client->nick,
-                               //              channel->name, channel->member_count, channel->topic ? channel->topic : "");
-                               copy_strf(&databuf, ":%s 322 %s %s 0 :%s\n", hostname, client->nick,
-                                               channel->name, channel->topic ? channel->topic : "");
+                               copy_strf(&databuf, ":%s 322 %s %s %u :%s\n", hostname, client->nick,
+                                               chan->name, chan->member_count, chan->topic ? chan->topic : "");
                                send_log(client->FD, databuf.buf, databuf.len, 0);
                        } while(trie_findnext(&f) == 1);
                copy_strf(&databuf, ":%s 323 %s :End of /LIST\n", hostname, client->nick);
@@ -450,8 +448,7 @@ void newUser(struct client_data *client) {
        send_log(client->FD, databuf.buf, databuf.len, 0);
        copy_strf(&databuf, ":%s 004 %s PatchyIRCD 0.0.1 i nt\n", hostname, client->nick);
        send_log(client->FD, databuf.buf, databuf.len, 0);
-       // FIXME: output nicklen from the actual macro
-       copy_strf(&databuf, ":%s 005 %s CASEMAPPING=rfc1459 NICKLEN=31 CHANTYPES=#& PREFIX=(ov)@+ :are supported by this server\n", hostname, client->nick);
+       copy_strf(&databuf, ":%s 005 %s CASEMAPPING=rfc1459 NICKLEN=%u CHANTYPES=#& PREFIX=(ov)@+ :are supported by this server\n", hostname, client->nick, MAX_NICKLEN-1);
        send_log(client->FD, databuf.buf, databuf.len, 0);
        copy_strf(&databuf, ":%s 251 %s :This server exists\n", hostname, client->nick);
        send_log(client->FD, databuf.buf, databuf.len, 0);
@@ -524,9 +521,7 @@ void channel_sendtopic(struct client_data *client, struct channel *chan, int joi
        if (chan->topic) {
                copy_strf(&databuf, ":%s 332 %s %s :%s\n", hostname, client->nick, chan->name, chan->topic);
                send_log(client->FD, databuf.buf, databuf.len, 0);
-               // FIXME: needs %d
-               //copy_strf(&databuf, ":%s 333 %s %s %s %d\n", hostname, client->nick, chan->name, chan->topic_who, chan->topic_when);
-               copy_strf(&databuf, ":%s 333 %s %s %s 0\n", hostname, client->nick, chan->name, chan->topic_who);
+               copy_strf(&databuf, ":%s 333 %s %s %s %u\n", hostname, client->nick, chan->name, chan->topic_who, (unsigned)chan->topic_when);
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if (!joining) {
                copy_strf(&databuf, ":%s 331 %s %s :No topic is set\n", hostname, client->nick, chan->name);
diff --git a/util.c b/util.c
index df9b878..d971894 100644 (file)
--- a/util.c
+++ b/util.c
@@ -30,6 +30,19 @@ void append_strf(struct dynarr *d, const char *s, ...){
                        const char *c = va_arg(ap, const char *);
                        append_str(d, c ? c : "(null)");
                        s = end + 2;
+               } else if (end[1] == 'u') { // %u
+                       append_strn(d, s, end-s);
+                       unsigned c = va_arg(ap, unsigned);
+                       char buf[11] = {0};
+                       char *p = &buf[10];
+                       if (!c)
+                               *--p = '0';
+                       while (c) {
+                               *--p = '0' + c%10;
+                               c /= 10;
+                       }
+                       append_str(d, p);
+                       s = end + 2;
                } else if (end[1] == '%') { // %%
                        append_strn(d, s, end-s+1);
                        s = end + 2;