]> PatchyGit - patchyircd.git/commitdiff
store username/realname in the user struct
authorEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 11:45:42 +0000 (14:45 +0300)
committerEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 11:45:42 +0000 (14:45 +0300)
common.h
irc.c
net.c

index 8ab86e4..4aaabae 100644 (file)
--- a/common.h
+++ b/common.h
@@ -14,6 +14,8 @@ struct client_data {
        char   type;
        char   *nick;
        char   *key; // case-mapped nick
+       char   *username;
+       char   *realname;
        char   buf[2048];
        size_t bufLen;
        size_t bufCap;
diff --git a/irc.c b/irc.c
index d208544..1526ef3 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -90,9 +90,26 @@ int processPacket(struct client_data *client) {
                if (client->nick)
                        printf("USER SET NICKNAME %s\n", client->nick);
                fflush(stdout);
+               if (client->nick && client->username)
+                       newUser(client);
        } else if(strcmp(command, "USER") == 0) {
+               if (argc < 4) // FIXME: error message
+                       return 0;
+               // set username
+               free(client->username); // FIXME: maybe don't allow to change it after registration?
+               client->username = malloc(strlen(args[0])+2);
+               if (!client->username)
+                       abort();
+               client->username[0] = '~';
+               strcpy(client->username + 1, args[0]);
+               // set realname
+               free(client->realname); // ditto
+               client->realname = strdup(args[3]);
+               if (!client->realname)
+                       abort();
                // Send welcome
-               newUser(client);
+               if (client->nick && client->username)
+                       newUser(client);
        } else if(strcmp(command, "MOTD") == 0) {
                // Send welcome
                sendMOTD(client);
@@ -223,7 +240,7 @@ int processPacket(struct client_data *client) {
                if (argc == 0) // FIXME: error message
                        return 0;
                // TODO: actual host
-               copy_strf(&databuf, ":%s 302 %s :%s=+user@~localhost\n", hostname, client->nick, args[0]);
+               copy_strf(&databuf, ":%s 302 %s :%s=+~user@localhost\n", hostname, client->nick, args[0]);
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "WHO") == 0) {
                if (!client->nick) // FIXME: error message
@@ -233,7 +250,7 @@ int processPacket(struct client_data *client) {
                // TODO: actual host info
                struct client_data *cl = findClient(args[0]);
                if (cl)
-                       copy_strf(&databuf, ":%s 352 %s * user ~localhost %s %s H :1 Patchouli Knowledge\n", hostname, client->nick, hostname, args[0]);
+                       copy_strf(&databuf, ":%s 352 %s * ~user localhost %s %s H :1 Patchouli Knowledge\n", hostname, client->nick, hostname, args[0]);
                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 {
@@ -247,12 +264,17 @@ unknown:
 }
 
 void newUser(struct client_data *client) {
-       copy_strf(&databuf, ":%s 001 %s :Welcome to PatchyIRCD!!!\n", hostname, client->nick);
+       copy_strf(&databuf, ":%s 001 %s :Welcome to the Patchy Network, %s\n", hostname, client->nick, client->nick);
        send_log(client->FD, databuf.buf, databuf.len, 0);
-       copy_strf(&databuf, ":%s 002 %s :Your host is PatchyIRCD V0.0.1\n", hostname, client->nick);
+       copy_strf(&databuf, ":%s 002 %s :Your host is PatchyIRCD, running version 0.0.1\n", hostname, client->nick);
        send_log(client->FD, databuf.buf, databuf.len, 0);
        copy_strf(&databuf, ":%s 003 %s :This server was created when I had cybersex with your mother.\n", hostname, client->nick);
        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 :are supported by this server\n", hostname, client->nick);
+       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);
        copy_strf(&databuf, ":%s 252 %s :Jannies don't exist\n", hostname, client->nick);
diff --git a/net.c b/net.c
index a5a7535..dd239e7 100644 (file)
--- a/net.c
+++ b/net.c
@@ -66,6 +66,8 @@ void killConnection(struct client_data *cl, bool byChoice) {
                trie_set(&client_map, cl->key, NULL, NULL);
        free(cl->nick);
        free(cl->key);
+       free(cl->username);
+       free(cl->realname);
        free(cl);
 }