[mw-devel] [Git][arthur/mw][master] webclient: Send sayto messages as sayto messages

Andrew Price welshbyte at sucs.org
Tue Jun 27 22:24:35 BST 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
d6cc4fc1 by Andrew Price at 2017-06-27T22:05:48+01:00
webclient: Send sayto messages as sayto messages

- - - - -


1 changed file:

- src/webclient/comms.c


Changes:

=====================================
src/webclient/comms.c
=====================================
--- a/src/webclient/comms.c
+++ b/src/webclient/comms.c
@@ -16,6 +16,7 @@
 #include <strings.h>
 #include <pwd.h>
 #include <inttypes.h>
+#include <ctype.h>
 
 #include <talker_privs.h>
 #include <special.h>
@@ -426,28 +427,37 @@ static int handle_command(CONNECTION *co)
 		}
 	}else
 	if (co->authd && strncasecmp(buff, "sayto ", 6)==0) {
-		char *tmp;
-		char *tmpm;
-		char duser[17];
-		char msg[8192];
-		char *tmpu;
-                char line[8192];
-		tmp = remove_first_word(buff);
-		tmpm = remove_first_word(tmp);
-		tmpu = strtok(tmp," ");
-		snprintf(msg,sizeof msg, "%s", tmpm);
-		snprintf(duser,17,"%s",tmpu);
-		if (buff[strlen(buff)-1]=='?') {
-	                snprintf(line, sizeof line, "%s asks: %s", user->record.name, msg);
-		}else {
-			snprintf(line, sizeof line, "%s says: %s", user->record.name, msg);
-		}
-		mwlog("SAYTO %s %s", duser, msg);
-                ipc_send_to_username(duser, IPC_TEXT, line);
-                snprintf(buff, sizeof buff, "{\"status\":\"sayto sent to %s (%s)\"}", duser, msg);
-                send(co->fd, buff, strlen(buff), 0);
+		char *to;
+		char *text;
+		char *status;
+		const char *type = "says";
+
+		if (buff[strlen(buff) - 1] == '?')
+			type = "asks";
+
+		to = buff + 6; // Skip 'sayto '
+		while (isspace(*to)) to++; // Skip whitespace to username
+		text = to;
+		while (!isspace(*text)) text++; // Skip username
+		*text = '\0'; // Hasta la vista, username
+		text++;
+		while (*text && isspace(*text)) text++;  // Trim space before message
+
+		ipc_message_t * msg = ipcmsg_create(IPC_SAYTOUSER, user->posn);
+		json_t * j = json_init(NULL);
+		json_addstring(j, "target", to);
+		json_addstring(j, "type", type);
+		json_addstring(j, "text", text);
+		ipcmsg_json_encode(msg, j);
+		json_decref(j);
+		ipcmsg_transmit(msg);
+
+		mwlog("SAYTO %s %s", to, text);
+
+		asprintf(&status, "{\"status\":\"sayto sent to %s (%s)\"}", to, text);
+		send(co->fd, status, strlen(status), 0);
 		user->record.idletime = lastcomm;
-                return 1;
+		return 1;
 	}else
         if (co->authd && strncasecmp(buff, "emote ", 6)==0) {
 		talk_send_to_room(&buff[6], user->record.room, "emote", 0);



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/d6cc4fc15206da84b90861f94d8fa44618bcac82

---
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/d6cc4fc15206da84b90861f94d8fa44618bcac82
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20170627/5c6286ce/attachment-0001.html>


More information about the mw-devel mailing list