]> PatchyGit - patchyircd.git/commitdiff
irc: use bool for irc_process_line return type
authorEgor <egor@patchysicp.xyz>
Sun, 25 Jan 2026 00:34:54 +0000 (02:34 +0200)
committerEgor <egor@patchysicp.xyz>
Sun, 25 Jan 2026 00:34:54 +0000 (02:34 +0200)
src/admin.cpp
src/admin.hpp
src/irc.cpp
src/irc.hpp
src/net.cpp

index bb2be59..fee79be 100644 (file)
@@ -458,25 +458,25 @@ void admin_dostring(const char *command)
                fprintf(stderr, "%s\n", lua_tostring(L, -1));
        lua_settop(L, 0);
 }
-int admin_command(Client *client, char *source, char *command, int argc, char *args[])
+bool admin_command(Client *client, char *source, char *command, int argc, char *args[])
 {
        if (!is_registered(client))
-               return err_notregistered(client), sendbuf(client), 0;
+               return err_notregistered(client), sendbuf(client), false;
        if (!(client->umode & UMODE_OPER))
-               return err_noprivileges(client), sendbuf(client), 0;
+               return err_noprivileges(client), sendbuf(client), false;
        lua_State *L = GL;
 
        if (lua_getglobal(L, "commands") != LUA_TTABLE) {
                fprintf(stderr, "no command table\n");
                lua_pop(L, 1);
-               return 0;
+               return false;
        }
        lua_getfield(L, -1, command);
        lua_remove(L, -2);
        if (!lua_isfunction(L, -1)) {
                fprintf(stderr, "command not found: %s\n", command);
                lua_pop(L, 1);
-               return 0;
+               return false;
        }
        *(Client **)lua_newuserdatauv(L, sizeof(Client *), 0) = client;
        luaL_setmetatable(L, "client");
@@ -493,7 +493,7 @@ int admin_command(Client *client, char *source, char *command, int argc, char *a
                fprintf(stderr, "%s\n", lua_tostring(L, -1));
                lua_pop(L, 1);
        }
-       return 0;
+       return false;
 }
 int admin_hook(const char *hook, Client *cl1, Client *cl2, Channel *chan, char *txt)
 {
index f8050c5..1401aa8 100644 (file)
@@ -6,6 +6,6 @@
 void admin_init(void);
 void admin_fini(void);
 void admin_dostring(const char *command);
-int admin_command(Client *client, char *source, char *command, int argc, char *args[]);
+bool admin_command(Client *client, char *source, char *command, int argc, char *args[]);
 int admin_hook(const char *hook, Client *cl1, Client *cl2, Channel *chan, char *txt);
 #endif
index 29b111f..a0b1ea8 100644 (file)
@@ -107,7 +107,7 @@ static int match_list(Client *cl, stringset &list)
                        return 1;
        return 0;
 }
-int irc_parse_line(Client *client, char *p, char *end) {
+bool irc_parse_line(Client *client, char *p, char *end) {
        char *source = NULL;
        char *command = NULL;
        char *args[16] = {0};
@@ -121,12 +121,12 @@ int irc_parse_line(Client *client, char *p, char *end) {
                        if (memchr(p, '\0', end-p)) {
                                log_client(client, "sent a NULL\n");
                                killConnection(client, 0);
-                               return 1; // null detected
+                               return true; // null detected
                        }
                        if (memchr(p, '\r', end-p)) {
                                log_client(client, "sent an extra CR\n");
                                killConnection(client, 0);
-                               return 1; // internal \r detected
+                               return true; // internal \r detected
                        }
                }
                if (*p == ':') {
@@ -134,7 +134,7 @@ int irc_parse_line(Client *client, char *p, char *end) {
                        while (*p != ' ' && *p != '\n')
                                p++;
                        if (*p++ == '\n') {
-                               return 0; // no command
+                               return false; // no command
                        }
                        p[-1] = '\0';
                }
@@ -207,15 +207,15 @@ constexpr size_t command_hash(std::string_view sv) {
 #define MATCH_END
 #endif
 
-int irc_process_line(Client *client, char *source, std::string_view command, int argc, char *args[]) {
+bool irc_process_line(Client *client, char *source, std::string_view command, int argc, char *args[]) {
        (void)source;
        databuf.clear();
        if (command.empty())
-               return 0;
+               return false;
        MATCH_BEGIN {
        } MATCH_COMMAND("PING") {
                if (!args[0])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                msg_pong(args[0]);
                sendbuf(client);
        } MATCH_COMMAND("CAP") {
@@ -237,7 +237,7 @@ int irc_process_line(Client *client, char *source, std::string_view command, int
                };
 
                if (!args[0])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                stringupper(args[0]);
                if (strcmp(args[0], "LS") == 0) {
                        if (args[1] && atoi(args[1]) >= 302)
@@ -261,7 +261,7 @@ int irc_process_line(Client *client, char *source, std::string_view command, int
                        sendbuf(client);
                } else if (strcmp(args[0], "REQ") == 0) {
                        if (!args[1]) // FIXME: error message
-                               return 0;
+                               return false;
                        char *p;
                        if ((p = strtok(args[1], " "))) {
                                do {
@@ -296,16 +296,16 @@ int irc_process_line(Client *client, char *source, std::string_view command, int
                }
        } MATCH_COMMAND("AUTHENTICATE") {
                if (!args[0])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (client->username && client->username[0] != '~')
-                       return err_saslalready(), sendbuf(client), 0;
+                       return err_saslalready(), sendbuf(client), false;
                if (!(client->umode & UMODE_SECURE))
-                       return err_saslfail(), sendbuf(client), 0;
+                       return err_saslfail(), sendbuf(client), false;
                if (client->saslusername)
                        return 0; // not ideal, but we can't respond to the new message before responding to the old one
                if (!client->saslbuf) {
                        if (strcmp(args[0], "PLAIN") != 0 && strcmp(args[0], "EXTERNAL") != 0)
-                               return rpl_saslmechs(), sendbuf(client), 0;
+                               return rpl_saslmechs(), sendbuf(client), false;
                        copy_strf(&databuf, ":%s AUTHENTICATE +\r\n", hostname), sendbuf(client);
                        // RFC 4616 spec says the three parts of the response can be up to 255 bytes long
                        // That's 255*3 + 2, but we'll add another NUL byte after the pass, so it's 768.
@@ -426,13 +426,13 @@ saslcleanup:
                                delete[] client->saslbuf;
                                client->saslbuf = 0;
                                client->saslbufLen = 0;
-                               return 0;
+                               return false;
                        }
                }
        } MATCH_COMMAND("NICK") {
                // User now registered
                if (!args[0])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (is_registered(client)) {
                        setNick(client, args[0]);
                } else {
@@ -442,9 +442,9 @@ saslcleanup:
                }
        } MATCH_COMMAND("USER") {
                if (argc < 4)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (is_registered(client))
-                       return err_alreadyregistered(client), sendbuf(client), 0;
+                       return err_alreadyregistered(client), sendbuf(client), false;
                // set username, but only if we didn't auth yet
                if (!client->username || client->username[0] == '~') {
                        args[0][-1] = '~'; // ugly hack
@@ -457,11 +457,11 @@ saslcleanup:
                newUser(client);
        } MATCH_COMMAND("PASS") {
                if (is_registered(client))
-                       return err_alreadyregistered(client), sendbuf(client), 0;
+                       return err_alreadyregistered(client), sendbuf(client), false;
                if (client->umode & UMODE_REGISTERED || client->passwait)
-                       return 0; // FIXME: error message
+                       return false; // FIXME: error message
                if (argc < 1)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (client->pass_reg) {
                        memset(client->pass_reg, 0, strlen(client->pass_reg));
                        delete[] client->pass_reg;
@@ -470,9 +470,9 @@ saslcleanup:
                memset(args[0], 0, strlen(args[0]));
        } MATCH_COMMAND("WEBIRC") {
                if (is_registered(client))
-                       return err_alreadyregistered(client), sendbuf(client), 0;
+                       return err_alreadyregistered(client), sendbuf(client), false;
                if (argc < 4)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (!client->webircwait) {
                        client->webircpeername = mystrdup(args[3]);
                        if (argc > 4 && (!strncmp(args[4], "secure", 6) || strstr(args[4], " secure")))
@@ -511,9 +511,9 @@ saslcleanup:
                }
        } MATCH_COMMAND("OPER") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc < 2)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                stringlower(args[0]);
                job_password_check<"ops">(client, args[0], args[1], [client](int res) {
                        if (!(client->umode & UMODE_SECURE) || res != 0) {
@@ -528,13 +528,13 @@ saslcleanup:
                memset(args[1], 0, strlen(args[1]));
        } MATCH_COMMAND("NEWACC") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc < 2)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                stringlower(args[0]);
                const char *hash = password_hash(args[1]);
                if (!hash)
-                       return 0; // TODO: error message
+                       return false; // TODO: error message
                memset(args[1], 0, strlen(args[1]));
                {
                        auto stmt = db::disk("INSERT INTO newusers(account, hash, regnuh, regpeer, regtime) VALUES(?, ?, ?, ?, unixepoch());");
@@ -549,7 +549,7 @@ saslcleanup:
                sendbuf(client);
        } MATCH_COMMAND("GHOST") {
                if (!(client->umode & UMODE_REGISTERED))
-                       return 0; // FIXME: error message
+                       return false; // FIXME: error message
                const char *desired_nick = client->username;
                if (args[0]) {
                        stringlower(args[0]);
@@ -561,38 +561,38 @@ saslcleanup:
                                if (stmt.step())
                                        username = stmt.text(0);
                                if (!username.data() || username != client->username)
-                                       return err_nicknameinuse(client, desired_nick), sendbuf(client), 0;
+                                       return err_nicknameinuse(client, desired_nick), sendbuf(client), false;
                        }
                }
                Client *cl = findClient(desired_nick);
                if (!cl)
-                       return err_nosuchnick(client, desired_nick), sendbuf(client), 0;
+                       return err_nosuchnick(client, desired_nick), sendbuf(client), false;
                if (client == cl)
-                       return err_nicknameinuse(client, desired_nick), sendbuf(client), 0;
+                       return err_nicknameinuse(client, desired_nick), sendbuf(client), false;
                killConnection(cl, 0);
        } MATCH_COMMAND("WALLOPS") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc < 1)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (!(client->umode & UMODE_OPER))
-                       return err_noprivileges(client), sendbuf(client), 0;
+                       return err_noprivileges(client), sendbuf(client), false;
                msg_wallops(client, args[0]);
                for (auto cl : client_map)
                        if (cl->umode & UMODE_WALLOPS)
                                sendbuf(cl);
        } MATCH_COMMAND("KILL") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (!(client->umode & UMODE_OPER))
-                       return err_noprivileges(client), sendbuf(client), 0;
+                       return err_noprivileges(client), sendbuf(client), false;
                if (argc < 1)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                Client *cl = findClient(args[0]);
                if (!cl)
-                       return 0; // FIXME: error message
+                       return false; // FIXME: error message
                if (client == cl)
-                       return 0; // FIXME: error message
+                       return false; // FIXME: error message
                msg_kill(client, cl, args[1] ? args[1] : "(no reason)");
                for (auto cl2 : client_map)
                        if (cl2->umode & UMODE_OPER)
@@ -601,28 +601,28 @@ saslcleanup:
                killConnection(cl, 0);
        } MATCH_COMMAND("JEDGAR") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (!(client->umode & UMODE_OPER))
-                       return err_noprivileges(client), sendbuf(client), 0;
+                       return err_noprivileges(client), sendbuf(client), false;
                if (argc < 1)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                Channel *chan = findChannel(args[0]);
                if (!chan)
-                       return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchchannel(client, args[0]), sendbuf(client), false;
                if (!chan->members.has(client))
-                       return err_notonchannel(client, chan), sendbuf(client), 0;
+                       return err_notonchannel(client, chan), sendbuf(client), false;
                chan->o.add(client);
                copy_strf(&databuf, ":cia!cia@cia.gov MODE %s +o %s\r\n", chan->name, client->nick);
                sendbuf_chan(chan);
        } MATCH_COMMAND("JOIN") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (!args[0])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (!strcmp(args[0], "0")) {
                        for (auto chan : client->channels.pop_view())
                                channel_part(client, chan, "I fell for a classic prank", NULL);
-                       return 0;
+                       return false;
                }
                char *p = args[0];
                char *q = args[1];
@@ -637,9 +637,9 @@ saslcleanup:
                } while (p);
        } MATCH_COMMAND("PART") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (!args[0])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                char *p = args[0];
                do {
                        char *channel = p;
@@ -647,52 +647,52 @@ saslcleanup:
                                *p++ = '\0';
                        Channel *chan = findChannel(channel);
                        if (!chan)
-                               return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
+                               return err_nosuchchannel(client, args[0]), sendbuf(client), false;
                        channel_part(client, chan, args[1] ? args[1] : "", NULL);
                } while (p);
        } MATCH_COMMAND("TOPIC") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (!args[0])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                Channel *chan = findChannel(args[0]);
                if (!chan)
-                       return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchchannel(client, args[0]), sendbuf(client), false;
                if (!args[1]) {
                        // TODO: +s
                        channel_sendtopic(client, chan, 0);
                } else {
                        // TODO: membership check, maybe?
                        if (chan->dmode & DMODE_TOPICPROT && !chan->o.has(client))
-                               return 0; // FIXME: error 482
+                               return false; // FIXME: error 482
                        channel_topic(client, chan, args[1], client->nick, get_time());
                }
        } MATCH_COMMAND("INVITE") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (!args[0]) {
                        // List pending invites
                        for (auto chan : client->invites)
                                rpl_invitelist(client, chan), sendbuf(client);
-                       return rpl_endofinvitelist(client), sendbuf(client), 0;
+                       return rpl_endofinvitelist(client), sendbuf(client), false;
                }
                if (!args[1])
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                Channel *chan = findChannel(args[1]);
                if (!chan)
-                       return err_nosuchchannel(client, args[1]), sendbuf(client), 0;
+                       return err_nosuchchannel(client, args[1]), sendbuf(client), false;
                if (chan->dmode & DMODE_INVITEONLY) {
                        if (!chan->o.has(client))
-                               return err_chanoprivsneeded(client, chan), sendbuf(client), 0;
+                               return err_chanoprivsneeded(client, chan), sendbuf(client), false;
                } else {
                        if (!chan->members.has(client))
-                               return err_notonchannel(client, chan), sendbuf(client), 0;
+                               return err_notonchannel(client, chan), sendbuf(client), false;
                }
                Client *cl = findClient(args[0]);
                if (!cl)
-                       return err_nosuchnick(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchnick(client, args[0]), sendbuf(client), false;
                if (chan->members.has(cl))
-                       return err_useronchannel(client, cl->nick, chan), sendbuf(client), 0;
+                       return err_useronchannel(client, cl->nick, chan), sendbuf(client), false;
                chan->invitees.add(cl);
                cl->invites.add(chan);
                rpl_inviting(client, cl, chan);
@@ -702,16 +702,16 @@ saslcleanup:
                sendbuf_chan_caps(chan, CAP_INVITENOTIFY, 0);
        } MATCH_COMMAND("KICK") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc < 2)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                Channel *chan = findChannel(args[0]);
                if (!chan)
-                       return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchchannel(client, args[0]), sendbuf(client), false;
                if (!chan->o.has(client))
-                       return err_chanoprivsneeded(client, chan), sendbuf(client), 0;
+                       return err_chanoprivsneeded(client, chan), sendbuf(client), false;
                if (!chan->members.has(client))
-                       return err_notonchannel(client, chan), sendbuf(client), 0;
+                       return err_notonchannel(client, chan), sendbuf(client), false;
                char *p = args[1];
                do {
                        char *nick = p;
@@ -728,13 +728,13 @@ saslcleanup:
        } MATCH_COMMAND("NOTICE") {
 privmsg_notice_common:
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc < 2)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                client->lastactivity = get_time();
                if (!strcmp(args[0], "cia")) {
                        admin_hook(command[0] == 'P' ? "privmsgtoservice" : "noticetoservice", client, 0, 0, args[1]);
-                       return 0;
+                       return false;
                }
                (command[0] == 'P' ? msg_privmsg : msg_notice)(client, args[0], args[1]);
                /* TODO: multiple targets */
@@ -745,26 +745,26 @@ privmsg_notice_common:
                if (strchr("#&", args[0][is_modmsg])) {
                        Channel *chan = findChannel(args[0]+is_modmsg);
                        if (!chan)
-                               return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
+                               return err_nosuchchannel(client, args[0]), sendbuf(client), false;
                        if (match_list(client, chan->listq))
-                               return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
+                               return err_cannotsendtochan(client, chan->name), sendbuf(client), false;
                        if (match_list(client, chan->listb) && !match_list(client, chan->liste))
-                               return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
+                               return err_cannotsendtochan(client, chan->name), sendbuf(client), false;
                        if (chan->dmode & DMODE_INVITEONLY
                                        && !chan->invitees.has(client) && !match_list(client, chan->listI))
-                               return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
+                               return err_cannotsendtochan(client, chan->name), sendbuf(client), false;
                        if (chan->dmode & DMODE_NOEXTERNAL && !chan->members.has(client))
-                               return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
+                               return err_cannotsendtochan(client, chan->name), sendbuf(client), false;
                        if (chan->dmode & DMODE_MODERATED && !chan->v.has(client) && !chan->o.has(client))
-                               return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
+                               return err_cannotsendtochan(client, chan->name), sendbuf(client), false;
                        switch (admin_hook("sendtochannel", client, 0, chan, args[1])) {
                        case -1:
                                msg_quit(client, "Quit: eel bearing atlantean", "");
                                sendbuf_visible(client);
                                killConnection(client, 1);
-                               return 1;
+                               return true;
                        case 1:
-                               return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
+                               return err_cannotsendtochan(client, chan->name), sendbuf(client), false;
                        }
                        if (!is_modmsg) {
                                sendbuf_list_sans_self(client, chan->members, 0);
@@ -778,15 +778,15 @@ privmsg_notice_common:
                } else {
                        Client *cl = findClient(args[0]);
                        if (!cl)
-                               return err_nosuchnick(client, args[0]), sendbuf(client), 0;
+                               return err_nosuchnick(client, args[0]), sendbuf(client), false;
                        switch (admin_hook("sendtoclient", client, cl, 0, args[1])) {
                        case -1:
                                msg_quit(client, "Quit: eel bearing atlantean", "");
                                sendbuf_visible(client);
                                killConnection(client, 1);
-                               return 1;
+                               return true;
                        case 1:
-                               return err_cantsendtouser(client, cl), sendbuf(client), 0;
+                               return err_cantsendtouser(client, cl), sendbuf(client), false;
                        }
                        sendbuf(cl);
                        if (cl->away)
@@ -796,20 +796,20 @@ privmsg_notice_common:
                msg_quit(client, "Quit: ", args[0] ? args[0] : "");
                sendbuf_visible(client);
                killConnection(client, 1);
-               return 1;
+               return true;
        } MATCH_COMMAND("PONG") {
                // Do nothing
        // Server Queries and Commands
        } MATCH_COMMAND("MOTD") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (args[0] && strcmp(args[0], hostname) != 0)
-                       return err_nosuchserver(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchserver(client, args[0]), sendbuf(client), false;
                // Send welcome
                sendMOTD(client);
        } MATCH_COMMAND("HELP") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                char line[512];
                FILE *f = fopen(getdatafile("help.txt"), "re");
                if (f) {
@@ -827,16 +827,16 @@ privmsg_notice_common:
                }
        } MATCH_COMMAND("VERSION") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (args[0] && strcmp(args[0], hostname) != 0)
-                       return err_nosuchserver(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchserver(client, args[0]), sendbuf(client), false;
                rpl_version(client, PACKAGE_VERSION, PACKAGE_STRING), sendbuf(client);
                rpl_isupport(client), sendbuf(client);
        } MATCH_COMMAND("ADMIN") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (args[0] && strcmp(args[0], hostname) != 0)
-                       return err_nosuchserver(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchserver(client, args[0]), sendbuf(client), false;
                char line[512];
                FILE *f = fopen(getdatafile("admin.txt"), "re");
                if (f) {
@@ -864,32 +864,32 @@ privmsg_notice_common:
                }
        } MATCH_COMMAND("LUSERS") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                sendLUSERS(client);
        } MATCH_COMMAND("TIME") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (args[0] && strcmp(args[0], hostname) != 0)
-                       return err_nosuchserver(client, args[0]), sendbuf(client), 0;
+                       return err_nosuchserver(client, args[0]), sendbuf(client), false;
                rpl_time(client, get_time()), sendbuf(client);
        } MATCH_COMMAND("MODE") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc == 0)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                char *nick = args[0];
                if (argc == 1) { // get mode
                        if (*nick != '#' && *nick != '&') {
                                Client *cl = findClient(nick);
                                if (!cl)
-                                       return err_nosuchnick(client, nick), sendbuf(client), 0;
+                                       return err_nosuchnick(client, nick), sendbuf(client), false;
                                if (client != cl)
-                                       return err_usersdontmatch(client, "Can't view mode for other users"), sendbuf(client), 0;
+                                       return err_usersdontmatch(client, "Can't view mode for other users"), sendbuf(client), false;
                                rpl_umodeis(client), sendbuf(client);
                        } else {
                                Channel *chan = findChannel(nick);
                                if (!chan)
-                                       return err_nosuchchannel(client, nick), sendbuf(client), 0;
+                                       return err_nosuchchannel(client, nick), sendbuf(client), false;
                                rpl_channelmodeis(client, chan), sendbuf(client);
                                rpl_creationtime(client, chan), sendbuf(client);
                        }
@@ -897,9 +897,9 @@ privmsg_notice_common:
                        if (*nick != '#' && *nick != '&') {
                                Client *cl = findClient(nick);
                                if (!cl)
-                                       return err_nosuchnick(client, nick), sendbuf(client), 0;
+                                       return err_nosuchnick(client, nick), sendbuf(client), false;
                                if (client != cl)
-                                       return err_usersdontmatch(client, "Can't change mode for other users"), sendbuf(client), 0;
+                                       return err_usersdontmatch(client, "Can't change mode for other users"), sendbuf(client), false;
                                int is_plus;
                                char *p = args[1];
                                switch (*p++) {
@@ -941,9 +941,9 @@ privmsg_notice_common:
                        } else {
                                Channel *chan = findChannel(nick);
                                if (!chan)
-                                       return err_nosuchchannel(client, nick), sendbuf(client), 0;
+                                       return err_nosuchchannel(client, nick), sendbuf(client), false;
                                if (!chan->o.has(client))
-                                       return 0; // TODO: error
+                                       return false; // TODO: error
                                if (argc == 2) { // Type A channel modes
                                        int all = !strcmp(args[1], "+0");
                                        int any = 0;
@@ -985,14 +985,14 @@ privmsg_notice_common:
                                                any = 1;
                                        }
                                        if (any)
-                                               return 0;
+                                               return false;
                                }
                                channel_mode(client, chan, args+1);
                        }
                }
        } MATCH_COMMAND("LIST") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                rpl_liststart(client), sendbuf(client);
                for (auto chan : channel_map)
                        if (client->umode & UMODE_OPER || !(chan->dmode & DMODE_SECRET) || chan->members.has(client))
@@ -1000,9 +1000,9 @@ privmsg_notice_common:
                rpl_listend(client), sendbuf(client);
        } MATCH_COMMAND("NAMES") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc == 0)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                char *p = args[0];
                do {
                        char *channel = p;
@@ -1018,9 +1018,9 @@ privmsg_notice_common:
                } while (p);
        } MATCH_COMMAND("USERHOST") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc == 0)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                Client *cls[5], **p = cls;
                for (int i = 0; i < 5; i++) {
                        if (!args[i])
@@ -1034,9 +1034,9 @@ privmsg_notice_common:
        // User-Based Queries
        } MATCH_COMMAND("WHO") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc == 0)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (strchr("#&", args[0][0])) {
                        Channel *chan = findChannel(args[0]);
                        // TODO: handle chanmode +s, umode +i
@@ -1069,9 +1069,9 @@ privmsg_notice_common:
                rpl_endofwho(client, args[0]), sendbuf(client);
        } MATCH_COMMAND("WHOIS") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc == 0)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                char *nick = args[1] ? args[1] : args[0];
                Client *cl = findClient(nick);
                if (cl) {
@@ -1110,7 +1110,7 @@ privmsg_notice_common:
                }
        } MATCH_COMMAND("AWAY") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (args[0]) {
                        delete[] client->away;
                        client->away = mystrdup(args[0]);
@@ -1125,24 +1125,24 @@ privmsg_notice_common:
                sendbuf_monitor(client->key, cookie, CAP_AWAYNOTIFY|CAP_EXTENDEDMONITOR, 0);
        } MATCH_COMMAND("MONITOR") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc == 0)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                if (!args[0][0] || args[0][1])
-                       return err_needmoreparams(client, command), sendbuf(client), 0; /* FIXME: wrong error */
+                       return err_needmoreparams(client, command), sendbuf(client), false; /* FIXME: wrong error */
                switch (args[0][0]) {
                case '+': {
                        if (argc < 2)
-                               return err_needmoreparams(client, command), sendbuf(client), 0;
+                               return err_needmoreparams(client, command), sendbuf(client), false;
                        if (strchr(args[1], ' '))
-                               return err_needmoreparams(client, command), sendbuf(client), 0; /* FIXME: wrong error */
+                               return err_needmoreparams(client, command), sendbuf(client), false; /* FIXME: wrong error */
                        stringlower(args[1]);
                        size_t monitor_count = client->monitor.size();
                        char *p = args[1];
                        do {
                                char *nick = p;
                                if (monitor_count == MONITOR_LIMIT)
-                                       return rpl_monlistfull(client, MONITOR_LIMIT,nick), sendbuf(client), 0;
+                                       return rpl_monlistfull(client, MONITOR_LIMIT,nick), sendbuf(client), false;
                                if ((p = strchr(nick, ',')))
                                        *p++ = '\0';
                                if (client->monitor.add(nick))
@@ -1157,9 +1157,9 @@ privmsg_notice_common:
                }
                case '-': {
                        if (argc < 2)
-                               return err_needmoreparams(client, command), sendbuf(client), 0;
+                               return err_needmoreparams(client, command), sendbuf(client), false;
                        if (strchr(args[1], ' '))
-                               return err_needmoreparams(client, command), sendbuf(client), 0; /* FIXME: wrong error */
+                               return err_needmoreparams(client, command), sendbuf(client), false; /* FIXME: wrong error */
                        stringlower(args[1]);
                        char *p = args[1];
                        do {
@@ -1188,13 +1188,13 @@ privmsg_notice_common:
                        }
                        break;
                default:
-                       return err_needmoreparams(client, command), sendbuf(client), 0; /* FIXME: wrong error */
+                       return err_needmoreparams(client, command), sendbuf(client), false; /* FIXME: wrong error */
                }
        } MATCH_COMMAND("SETNAME") {
                if (!is_registered(client))
-                       return err_notregistered(client), sendbuf(client), 0;
+                       return err_notregistered(client), sendbuf(client), false;
                if (argc == 0)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                delete[] client->realname;
                client->realname = mystrdup(args[0]);
                msg_setname(client);
@@ -1204,13 +1204,13 @@ privmsg_notice_common:
                        sendbuf(client);
        } MATCH_COMMAND("LUA") {
                if (argc < 1)
-                       return err_needmoreparams(client, command), sendbuf(client), 0;
+                       return err_needmoreparams(client, command), sendbuf(client), false;
                return admin_command(client, source, args[0], argc-1, args+1);
        } MATCH_ELSE {
 unknown:
                err_unknowncommand(client, command), sendbuf(client);
        } MATCH_END
-       return 0;
+       return false;
 }
 
 void newUser(Client *client) {
index f4cf610..97a83d1 100644 (file)
@@ -9,8 +9,8 @@
 #define is_registered(cl) ((cl)->regstate == REG_REGISTERED)
 void sendbuf_monitor(const char *nick, int cookie, int positive, int negative);
 const char *format_umodes(Client *cl);
-int irc_parse_line(Client *client, char *p, char *end);
-int irc_process_line(Client *client, char *source, std::string_view command, int argc, char *args[]);
+bool irc_parse_line(Client *client, char *p, char *end);
+bool irc_process_line(Client *client, char *source, std::string_view command, int argc, char *args[]);
 void newUser(Client *client);
 void sendLUSERS(Client *client);
 void sendMOTD(Client *client);
index d718aaf..f416180 100644 (file)
@@ -200,7 +200,7 @@ void read_proc(Client *cl)
                        char *p = (char *)memchr(cl->rbuf, '\n', cl->rlen);
                        if (!p)
                                break;
-                       if (irc_parse_line(cl, cl->rbuf, p) == 1)
+                       if (irc_parse_line(cl, cl->rbuf, p))
                                return;
                        p++;
                        memmove(cl->rbuf, p, cl->rbuf + cl->rlen - p);