]> PatchyGit - patchyircd.git/commitdiff
add error 451 everywhere
authorEgor <egor@patchysicp.xyz>
Wed, 4 May 2022 08:48:00 +0000 (11:48 +0300)
committerEgor <egor@patchysicp.xyz>
Wed, 4 May 2022 08:48:00 +0000 (11:48 +0300)
irc.c

diff --git a/irc.c b/irc.c
index 497409a..a953b60 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -6,6 +6,11 @@ struct trie_node *client_map = NULL;
 struct trie_node *channel_map = NULL;
 
 const char *hostname = "irc.patchysicp.xyz";
+#define is_registered(cl) ((cl)->nick != 0)
+static void err_notregistered(struct client_data *client) {
+       copy_strf(&databuf, ":%s 451 * :You have not registered\n", hostname);
+       send_log(client->FD, databuf.buf, databuf.len, 0);
+}
 int processPacket(struct client_data *client) {
        char *source = NULL;
        (void)source;
@@ -147,8 +152,8 @@ int processPacket(struct client_data *client) {
                // Send welcome
                sendMOTD(client);
        } else if(strcmp(command, "JOIN") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (!args[0]) // FIXME: error message
                        return 0;
                if (!strcmp(args[0], "0")) {
@@ -166,8 +171,8 @@ int processPacket(struct client_data *client) {
                        *p = '\0';
                channel_join(client, args[0], NULL);
        } else if(strcmp(command, "PART") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (!args[0]) // FIXME: error message
                        return 0;
                char *p = strchr(args[0], ','); // TODO: multiple channels
@@ -178,8 +183,8 @@ int processPacket(struct client_data *client) {
                        return 0;
                channel_part(client, chan, args[1] ? args[1] : "");
        } else if(strcmp(command, "TOPIC") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (!args[0]) // FIXME: error message
                        return 0;
                struct channel *chan = findChannel(args[0]);
@@ -212,8 +217,8 @@ int processPacket(struct client_data *client) {
                                } while (trie_findnext(&f) == 1);
                }
        } else if(strcmp(command, "PRIVMSG") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (argc < 2) // FIXME: error message
                        return 0;
                copy_strf(&databuf, ":%s!%s@%s PRIVMSG %s :%s\n", client->nick, client->username, client->hostname, args[0], args[1]);
@@ -242,8 +247,8 @@ int processPacket(struct client_data *client) {
        } else if(strcmp(command, "PONG") == 0) {
                // Do nothing
        } else if(strcmp(command, "MODE") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (argc == 0) // FIXME: error message
                        return 0;
                char *nick = args[0];
@@ -327,6 +332,8 @@ int processPacket(struct client_data *client) {
                        }
                }
        } else if(strcmp(command, "LIST") == 0) {
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                copy_strf(&databuf, ":%s 321 %s Channel :Users  Name\n", hostname, client->nick);
                send_log(client->FD, databuf.buf, databuf.len, 0);
                struct trie_find *f = NULL;
@@ -341,8 +348,8 @@ int processPacket(struct client_data *client) {
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "NAMES") == 0) {
                // TODO: actual channel support
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (argc == 0) // FIXME: error message
                        return 0;
                struct trie_find *f = NULL;
@@ -355,8 +362,8 @@ int processPacket(struct client_data *client) {
                copy_strf(&databuf, ":%s 366 %s :End of /NAMES list\n", hostname, client->nick);
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "USERHOST") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (argc == 0) // FIXME: error message
                        return 0;
                copy_strf(&databuf, ":%s 302 %s", hostname, client->nick);
@@ -378,8 +385,8 @@ int processPacket(struct client_data *client) {
                }
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "WHO") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (argc == 0) // FIXME: error message
                        return 0;
                struct client_data *cl = findClient(args[0]);
@@ -393,8 +400,8 @@ int processPacket(struct client_data *client) {
                copy_strf(&databuf, ":%s 315 %s %s :End of WHO list\n", hostname, client->nick, args[0]);
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "WHOIS") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (argc == 0) // FIXME: error message
                        return 0;
                char *nick = args[1] ? args[1] : args[0];
@@ -419,8 +426,8 @@ int processPacket(struct client_data *client) {
                        send_log(client->FD, databuf.buf, databuf.len, 0);
                }
        } else if(strcmp(command, "AWAY") == 0) {
-               if (!client->nick) // FIXME: error message
-                       return 0;
+               if (!is_registered(client))
+                       return err_notregistered(client), 0;
                if (args[0]) {
                        free(client->away);
                        client->away = mystrdup(args[0]);