]> PatchyGit - patchyircd.git/commitdiff
try to write \r\n everywhere
authorEgor <egor@patchysicp.xyz>
Wed, 4 May 2022 09:39:23 +0000 (12:39 +0300)
committerEgor <egor@patchysicp.xyz>
Wed, 4 May 2022 09:39:23 +0000 (12:39 +0300)
irc.c
main.c
util.c

diff --git a/irc.c b/irc.c
index a953b60..cec4431 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -266,7 +266,7 @@ int processPacket(struct client_data *client) {
                                if (cl->umode & UMODE_LOPER) append_str(&databuf, "O");
                                if (cl->umode & UMODE_REGISTERED) append_str(&databuf, "r");
                                if (cl->umode & UMODE_WALLOPS) append_str(&databuf, "w");
-                               append_str(&databuf, "\n");
+                               append_str(&databuf, "\r\n");
                                send_log(client->FD, databuf.buf, databuf.len, 0);
                        } else {
                                copy_strf(&databuf, ":%s 324 %s %s +nt\n", hostname, client->nick, nick);
@@ -381,7 +381,7 @@ int processPacket(struct client_data *client) {
                                                cl->hostname);
                                has_output = 1;
                        }
-                       append_str(&databuf, "\n");
+                       append_str(&databuf, "\r\n");
                }
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "WHO") == 0) {
diff --git a/main.c b/main.c
index 659d6ec..27f528e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -88,7 +88,6 @@ int main() {
        SOCKET SD;
        int i;
        char client_addr[100];
-       char *welcomeMessage = ":irc.patchysicp.xyz NOTICE * :Hello welcome to PatchyIRCD!\n"; // TODO: don't hardcode hostname
        puts("[PatchyIRCD]: Starting up...");
        fflush(stdout);
 
@@ -238,7 +237,9 @@ int main() {
                        inet_ntop(AF_INET, &(serverAddrV4.sin_addr), client_addr, sizeof(client_addr));
                        printf("Connection accepted from Socket: %"PRISocket", IP: %s PORT: %d\n", newSocket, client_addr, ntohs(serverAddrV4.sin_port));
                        fflush(stdout);
-                       send_log(newSocket, welcomeMessage, strlen(welcomeMessage), 0);
+                       extern const char *hostname;
+                       copy_strf(&databuf, ":%s NOTICE * :Hello welcome to PatchyIRCD!\r\n", hostname);
+                       send_log(newSocket, databuf.buf, databuf.len, 0);
                        // Add to list of sockets
                        for(i=0;i<CLIENTS;i++) {
                                if(clients[i] == 0){
@@ -263,7 +264,9 @@ int main() {
                        inet_ntop(AF_INET6, &(serverAddrV6.sin6_addr), client_addr, sizeof(client_addr));
                        printf("Connection accepted from Socket: %"PRISocket", IP: %s PORT: %d\n", newSocket, client_addr, ntohs(serverAddrV6.sin6_port));
                        fflush(stdout);
-                       send_log(newSocket, welcomeMessage, strlen(welcomeMessage), 0);
+                       extern const char *hostname;
+                       copy_strf(&databuf, ":%s NOTICE * :Hello welcome to PatchyIRCD!\r\n", hostname);
+                       send_log(newSocket, databuf.buf, databuf.len, 0);
                        // Add to list of sockets
                        for(i=0;i<CLIENTS;i++) {
                                if(clients[i] == 0){
diff --git a/util.c b/util.c
index d971894..b336fae 100644 (file)
--- a/util.c
+++ b/util.c
@@ -22,7 +22,16 @@ void append_strf(struct dynarr *d, const char *s, ...){
        for (;;) {
                char *end = strchr(s, '%');
                if (!end) {
-                       append_str(d, s);
+                       // if format string ends with \n, append \r\n
+                       int len = strlen(s);
+                       if (len) {
+                               if (s[len-1] == '\n' && (len == 1 || s[len-2] != '\r')) {
+                                       append_strn(d, s, len-1);
+                                       append_strn(d, "\r\n", 2);
+                               } else {
+                                       append_strn(d, s, len);
+                               }
+                       }
                        break;
                }
                if (end[1] == 's') { // %s