[mw-devel] MW3 r1391 - in trunk/src: . client webclient

arthur at sucs.org arthur at sucs.org
Wed Sep 23 14:41:57 BST 2015


Author: arthur
Date: 2015-09-23 14:41:57 +0100 (Wed, 23 Sep 2015)
New Revision: 1391

Modified:
   trunk/src/client/incoming.c
   trunk/src/client/talker.c
   trunk/src/ipc.c
   trunk/src/socket.h
   trunk/src/webclient/comms.c
   trunk/src/webclient/import.c
   trunk/src/webclient/import.h
Log:
Change PID as message src to userposn value,
thus fixing one major dependancy on the who list


Modified: trunk/src/client/incoming.c
===================================================================
--- trunk/src/client/incoming.c	2015-09-22 16:31:15 UTC (rev 1390)
+++ trunk/src/client/incoming.c	2015-09-23 13:41:57 UTC (rev 1391)
@@ -429,7 +429,6 @@
 
 void handle_mesg()
 {
-	long mesg_posn;
 	static struct person mesg_user;
 
 	mesg_waiting = 0;
@@ -437,10 +436,11 @@
 	ipc_message_t * msg = read_socket(ipcsock, 1);
 
 	while (msg != NULL) {
-		if (msg->head.src == 0 || (mesg_posn=get_who_userposn(msg->head.src))<0)
+		if (msg->head.src == SYSTEM_USER) {
 			strcpy(mesg_user.name,"System");
-		else
-			fetch_user(&mesg_user, mesg_posn);
+		} else {
+			fetch_user(&mesg_user, msg->head.src);
+		}
 		accept_pipe_cmd(msg, &mesg_user);
 
 		msg = read_socket(ipcsock, 0);
@@ -502,12 +502,10 @@
 	struct person msg_user;
 	const char *whom = NULL;
 
-	if (msg->head.src == 0) {
+	if (msg->head.src == SYSTEM_USER) {
 		whom = "System";
-	} else
-	if ((msg_posn = get_who_userposn(msg->head.src)) == -1) {
-		whom = "Unknown";
-	}else {
+	} else {
+		msg_posn = msg->head.src;
 		fetch_user(&msg_user, msg_posn);
 		whom = msg_user.name;
 	}

Modified: trunk/src/client/talker.c
===================================================================
--- trunk/src/client/talker.c	2015-09-22 16:31:15 UTC (rev 1390)
+++ trunk/src/client/talker.c	2015-09-23 13:41:57 UTC (rev 1391)
@@ -110,7 +110,7 @@
 }
 
 static void talk_send_to_room(const char * text, int channel, const char * type, int plural) {
-	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, getpid());
+	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, userposn);
 	ipcmsg_destination(msg, channel);
 	json_t * j = json_init(NULL);
 	json_addstring(j, "text", text);
@@ -123,7 +123,7 @@
 
 void talk_send_shout(char * text){
 	mwlog("SHOUT %s", text);
-	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOALL, getpid());
+	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOALL, userposn);
 	json_t * j = json_init(NULL);
 	json_addstring(j, "text", text);
 	ipcmsg_json_encode(msg, j);
@@ -165,7 +165,7 @@
 
 void talk_sayto(char *text, const char *to, const char *type) 
 {
-	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOUSER, getpid());
+	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOUSER, userposn);
 	json_t * j = json_init(NULL);
 	json_addstring(j, "target", to);
 	json_addstring(j, "type", type);
@@ -253,7 +253,7 @@
 
 void t_uptime(CommandList *cm, int argc, const const char **argv, char *args)
 {
-	ipc_message_t * msg = ipcmsg_create(IPC_UPTIME, getpid());
+	ipc_message_t * msg = ipcmsg_create(IPC_UPTIME, userposn);
 	ipcmsg_transmit(msg);
 }
 
@@ -511,7 +511,7 @@
 	mwlog("NSAYTO %s %s", argv[1], text);
 
 	/* variant of say_to_room but with an exclude clause */
-	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, getpid());
+	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, userposn);
 	ipcmsg_destination(msg, user->room);
 	json_t * j = json_init(NULL);
 	json_addstring(j, "text", text);
@@ -1696,7 +1696,7 @@
 		return;
 	}
 
-	ipc_message_t * msg = ipcmsg_create(IPC_REPLAY, getpid());
+	ipc_message_t * msg = ipcmsg_create(IPC_REPLAY, userposn);
 	json_t * j = json_init(NULL);
 	json_addint(j, argv[1], atoll(argv[2]));
 	ipcmsg_json_encode(msg, j);

Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2015-09-22 16:31:15 UTC (rev 1390)
+++ trunk/src/ipc.c	2015-09-23 13:41:57 UTC (rev 1391)
@@ -62,8 +62,7 @@
 	ipcsock->fd = fd;
 	ipcsock->state = IPCSTATE_CONNECTED;
 
-	pid_t mypid = getpid();
-	ipc_message_t * msg = ipcmsg_create(IPC_HELLO, mypid);
+	ipc_message_t * msg = ipcmsg_create(IPC_HELLO, userposn);
 	ipcmsg_append(msg, &userposn, sizeof(userposn));
 	const char *nonce = get_nonce();
 	ipcmsg_append(msg, nonce, strlen(nonce));
@@ -129,14 +128,13 @@
 	if (msgtype != IPC_NOOP) {
 		char	buff[MAXTEXTLENGTH];
 		snprintf(buff, MAXTEXTLENGTH - 1, "%s",data);
-		pid_t mypid = getpid();
 		//ensure text (everything after the first 5 bytes) going into the pipes is clean utf-8 after all the truncating etc. that might have happened to it.
 		//
 
 		ipc_check();
 		if(utf8_cleanup(buff)>=0) {
 			ssize_t dgram_len = strlen(buff);
-			ipc_message_t *msg = ipcmsg_create(msgtype, mypid);
+			ipc_message_t *msg = ipcmsg_create(msgtype, userposn);
 			ipcmsg_destination(msg, dest);
 			ipcmsg_append(msg, buff, dgram_len);
 			ipcmsg_send(msg, ipcsock);

Modified: trunk/src/socket.h
===================================================================
--- trunk/src/socket.h	2015-09-22 16:31:15 UTC (rev 1390)
+++ trunk/src/socket.h	2015-09-23 13:41:57 UTC (rev 1391)
@@ -7,6 +7,11 @@
 
 #define IPCPORT_DEFAULT	9999
 
+/* which userposn is the System user, 
+ * 0 is possible but 1 is an impossible location 
+ */
+#define SYSTEM_USER 1
+
 enum ipcsock_state {
 	IPCSTATE_CONNECTED,
 	IPCSTATE_VALID,

Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c	2015-09-22 16:31:15 UTC (rev 1390)
+++ trunk/src/webclient/comms.c	2015-09-23 13:41:57 UTC (rev 1391)
@@ -45,7 +45,6 @@
 typedef struct {
 	struct list_head list;
 	enum ipc_types state;
-	int pid;
 	struct person user;
 	char *text;
 	uint64_t serial;
@@ -145,7 +144,7 @@
 {
 	MESG *msg = malloc(sizeof(MESG));
 	msg->state = ipc->head.type;
-	msg->pid = ipc->head.src;
+	//msg->pid = ipc->head.src;
 	msg->user = *mesg_user;
 	msg->text = json_escape(ipc->body);
 	msg->serial = ipc->head.serial;
@@ -295,7 +294,7 @@
 			mws_add(buff, "\"state\":%d,", tmp->state);
 		mws_add(buff, "\"serial\":%"PRId64",", tmp->serial);
 		mws_add(buff, "\"when\":%"PRId64",", tmp->when);
-		mws_add(buff, "\"pid\":%d,\"username\":\"%s\",\"text\":\"%s\"}", tmp->pid, tmp->user.name, tmp->text);
+		mws_add(buff, "\"username\":\"%s\",\"text\":\"%s\"}", tmp->user.name, tmp->text);
 		if (pos->next != &msglist) {
 			mws_add(buff, ",");
 		}
@@ -565,7 +564,7 @@
         ipc_message_t * msg = read_socket(ipcsock, 1);
 
         while (msg != NULL) {
-                if ((mesg_posn=get_who_userposn(msg->head.src))<0)
+                if ((mesg_posn=msg->head.src)==SYSTEM_USER)
                         strcpy(mesg_user.name,"System");
                 else
                         fetch_user(&mesg_user, mesg_posn);

Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c	2015-09-22 16:31:15 UTC (rev 1390)
+++ trunk/src/webclient/import.c	2015-09-23 13:41:57 UTC (rev 1391)
@@ -64,28 +64,6 @@
         return(0);
 }
 
-int32_t get_who_userposn(int pid)
-{
-        struct who w;
-        int wfile;
-        long found=-1;
-
-        if ((wfile=who_open(O_RDONLY))<0) return(-1);
-
-        while (read(wfile,&w,sizeof(w)))
-        {
-                if (w.posn >= 0 &&
-                    (pid==-w.pid || (pid==w.pid && (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL)))))
-                {
-                        found=w.posn;
-                        break;
-                }
-        }
-        close(wfile);
-
-        return(found);
-}
-
 void fetch_user(struct person *record, int32_t userposn)
 {
         int outfile;  
@@ -184,8 +162,10 @@
         return(found);
 }
 
+extern int userposn;
+
 void talk_send_to_room(const char * text, int channel, const char * type, int plural) {
-	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, getpid());
+	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, userposn);
 	ipcmsg_destination(msg, channel);
 	json_t * j = json_init(NULL);
 	json_addstring(j, "text", text);

Modified: trunk/src/webclient/import.h
===================================================================
--- trunk/src/webclient/import.h	2015-09-22 16:31:15 UTC (rev 1390)
+++ trunk/src/webclient/import.h	2015-09-23 13:41:57 UTC (rev 1391)
@@ -6,7 +6,6 @@
 int get_person(int file, struct person *tmp);
 void update_user(struct person *record, int32_t userposn);
 unsigned long cm_flags(unsigned long cm, unsigned long flags, int mode);
-int32_t get_who_userposn(int pid);
 void fetch_user(struct person *record, int32_t userposn);
 char *quotetext(const char *a);
 void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason);




More information about the mw-devel mailing list