]> PatchyGit - patchyircd.git/commitdiff
add AWAY command
authorEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 13:05:29 +0000 (16:05 +0300)
committerEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 13:05:29 +0000 (16:05 +0300)
common.h
irc.c
net.c

index b00d0d1..b252631 100644 (file)
--- a/common.h
+++ b/common.h
@@ -17,6 +17,7 @@ struct client_data {
        char   *username;
        char   *realname;
        char   *hostname;
+       char   *away;
        char   buf[2048];
        size_t bufLen;
        size_t bufCap;
diff --git a/irc.c b/irc.c
index 17575e7..26820be 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -145,7 +145,22 @@ int processPacket(struct client_data *client) {
                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]);
-               sendall_log(client->FD, databuf.buf, databuf.len, 0);
+               if (args[0][0] == '#') {
+                       sendall_log(client->FD, databuf.buf, databuf.len, 0);
+               } else {
+                       struct client_data *cl = findClient(args[0]);
+                       if (!cl) {
+                               copy_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, args[0]);
+                               send_log(client->FD, databuf.buf, databuf.len, 0);
+                               return 0;
+                       } else {
+                               send_log(cl->FD, databuf.buf, databuf.len, 0);
+                               if (cl->away) {
+                                       copy_strf(&databuf, ":%s 301 %s %s :%s\n", hostname, client->nick, cl->nick, cl->away);
+                                       send_log(client->FD, databuf.buf, databuf.len, 0);
+                               }
+                       }
+               }
        // Start GitHub Copilot - this shit actually be copy pasting my code lmao
        } else if(strcmp(command, "QUIT") == 0) {
                copy_strf(&databuf, ":%s!%s@%s QUIT :%s\n", client->nick, client->username, client->hostname, args[0] ? args[0] : "Client Quit");
@@ -272,10 +287,29 @@ int processPacket(struct client_data *client) {
                                copy_strf(&databuf, ":%s 313 %s %s :is an IRC operator\n", hostname, client->nick, cl->nick);
                                send_log(client->FD, databuf.buf, databuf.len, 0);
                        }
+                       if (cl->away) {
+                               copy_strf(&databuf, ":%s 301 %s %s :%s\n", hostname, client->nick, cl->nick, cl->away);
+                               send_log(client->FD, databuf.buf, databuf.len, 0);
+                       }
                        copy_strf(&databuf, ":%s 318 %s %s :End of /WHOIS list\n", hostname, client->nick, cl->nick);
                        send_log(client->FD, databuf.buf, databuf.len, 0);
                } else {
-                       copy_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, cl->nick);
+                       copy_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, nick);
+                       send_log(client->FD, databuf.buf, databuf.len, 0);
+               }
+       } else if(strcmp(command, "AWAY") == 0) {
+               if (!client->nick) // FIXME: error message
+                       return 0;
+               if (args[0]) {
+                       free(client->away);
+                       client->away = strdup(args[0]);
+                       if (!client->away) abort();
+                       copy_strf(&databuf, ":%s 306 %s :You have been marked as being away\n", hostname, client->nick);
+                       send_log(client->FD, databuf.buf, databuf.len, 0);
+               } else {
+                       free(client->away);
+                       client->away = NULL;
+                       copy_strf(&databuf, ":%s 305 %s :You are no longer marked as being away\n", hostname, client->nick);
                        send_log(client->FD, databuf.buf, databuf.len, 0);
                }
        } else {
diff --git a/net.c b/net.c
index 266a452..323ed34 100644 (file)
--- a/net.c
+++ b/net.c
@@ -69,6 +69,7 @@ void killConnection(struct client_data *cl, bool byChoice) {
        free(cl->username);
        free(cl->realname);
        free(cl->hostname);
+       free(cl->away);
        free(cl);
 }