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

arthur at sucs.org arthur at sucs.org
Mon Sep 21 16:48:11 BST 2015


Author: arthur
Date: 2015-09-21 16:48:10 +0100 (Mon, 21 Sep 2015)
New Revision: 1388

Modified:
   trunk/src/client/incoming.c
   trunk/src/server/servsock.c
   trunk/src/socket.h
   trunk/src/webclient/comms.c
Log:
Prep work for persistant/replay messaging; Add serial numbers and datestamps to every message processed by the server, fix timestamp printing to use those values instead of wallclock


Modified: trunk/src/client/incoming.c
===================================================================
--- trunk/src/client/incoming.c	2015-09-21 12:56:34 UTC (rev 1387)
+++ trunk/src/client/incoming.c	2015-09-21 15:48:10 UTC (rev 1388)
@@ -47,7 +47,7 @@
 static struct mstack *MesgStack=NULL;
 
 static void accept_pipe_cmd(ipc_message_t *msg, struct person *mesg_user);
-static void force_text(const char *text, const char *from);
+static void force_text(ipc_message_t *msg, const char *text, const char *from);
 static void force_ipc(char *text, char *from);
 static void force_rpc(char *text, char *from);
 static void force_checkonoff(char *text, char *from);
@@ -490,7 +490,7 @@
 		snprintf(tb, len, "Unknown %s Error: %s", type, text);
 	}
 
-	force_text(buff, "System");
+	force_text(msg, buff, "System");
 	json_decref(j);
 }
 
@@ -573,7 +573,7 @@
 			/* same as say for now */
 			snprintf(tb, len, "%s: %s", whom, text);
 		}
-		force_text(buff, whom);
+		force_text(msg, buff, whom);
 	} else
 	if (msg->head.type == IPC_SAYTOUSER) {
 		const char * type = json_getstring(j, "type");
@@ -608,7 +608,7 @@
 		} else  {
 			snprintf(tb, len, "%s says: %s", whom, text);
 		}
-		force_text(buff, whom);
+		force_text(msg, buff, whom);
 	} else
 	if (msg->head.type == IPC_SAYTOALL) {
 		const char * text = json_getstring(j, "text");
@@ -632,7 +632,7 @@
 		}
 	
 		snprintf(tb, len, "%s shouts: %s", whom, text);
-		force_text(buff, whom);
+		force_text(msg, buff, whom);
 	} else {
 		printf("Unknown message type %4.4s", (char *)&msg->head.type);
 	}
@@ -700,7 +700,7 @@
 			reset_timeout(user->timeout);
 			break;
 		case IPC_TEXT:
-			if (!is_ignored(mesg_user->name, NULL)) force_text(newbuff, mesg_user->name);
+			if (!is_ignored(mesg_user->name, NULL)) force_text(msg, newbuff, mesg_user->name);
 			break;
 		case IPC_SCRIPTIPC:
 			if (!is_ignored(mesg_user->name, NULL)) force_ipc(newbuff, mesg_user->name);
@@ -747,7 +747,7 @@
 	new_mail_waiting++;
 }
 
-static void force_text(const char *text, const char *from)
+static void force_text(ipc_message_t *msg, const char *text, const char *from)
 {
 	char tb[MAXTEXTLENGTH];
 	struct mstack *mesg;
@@ -761,7 +761,7 @@
 		time_t t;
 		struct tm *tt;
  
-		t=time(0);
+		t= msg->head.when;
 		tt=localtime(&t);
 		strftime(tb, MAXTEXTLENGTH,"%H:%M ", tt);
 	}

Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c	2015-09-21 12:56:34 UTC (rev 1387)
+++ trunk/src/server/servsock.c	2015-09-21 15:48:10 UTC (rev 1388)
@@ -20,6 +20,7 @@
 #include <ipc.h>
 
 #include "servsock.h"
+#include "replay.h"
 
 struct list_head connection_list;
 
@@ -308,6 +309,13 @@
 		return;
 	}
 
+	/**** end of messages to the server
+	 *    all below this point are intended to be retransmitted
+	 */
+
+	/* set the unique serial number and timestamp */
+	assign_serial(msg);
+
 	/* send message to everyone in the room */
 	if (msg->head.type == IPC_SAYTOROOM) {
 		/* eventually this should be a server maintained list */

Modified: trunk/src/socket.h
===================================================================
--- trunk/src/socket.h	2015-09-21 12:56:34 UTC (rev 1387)
+++ trunk/src/socket.h	2015-09-21 15:48:10 UTC (rev 1388)
@@ -20,6 +20,8 @@
 	uint32_t dst;
 	uint32_t type;
 	uint32_t len;
+	uint64_t serial;
+	 int64_t when;
 } __attribute__((packed)) ipc_msghead_t;
 
 typedef struct {

Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c	2015-09-21 12:56:34 UTC (rev 1387)
+++ trunk/src/webclient/comms.c	2015-09-21 15:48:10 UTC (rev 1388)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <strings.h>
 #include <pwd.h>
+#include <inttypes.h>
 
 #include <talker_privs.h>
 #include <special.h>
@@ -47,6 +48,8 @@
 	int pid;
 	struct person user;
 	char *text;
+	uint64_t serial;
+	time_t when;
 } MESG;
 
 
@@ -138,18 +141,19 @@
 
 
 /* we got a message */
-static void accept_pipe_cmd(enum ipc_types state, char *newbuff, int mesg_pid, struct person *mesg_user)
+static void accept_pipe_cmd(ipc_message_t *ipc, struct person *mesg_user)
 {
 	MESG *msg = malloc(sizeof(MESG));
-	msg->state = state;
-	msg->pid = mesg_pid;
+	msg->state = ipc->head.type;
+	msg->pid = ipc->head.src;
 	msg->user = *mesg_user;
-	msg->text = json_escape(newbuff);
+	msg->text = json_escape(ipc->body);
+	msg->serial = ipc->head.serial;
+	msg->when = ipc->head.when;
 
 	list_add_tail(&msg->list, &msglist);
 
-	printf("From=%s type=%d msg='%s'\n", mesg_user->name, state, newbuff);
-
+	printf("From=%s type=%d msg='%s'\n", mesg_user->name, ipc->head.type, ipc->body);
 }
 
 static int handle_command(CONNECTION *co);
@@ -289,6 +293,8 @@
 			mws_add(buff, "\"state\":\"%4.4s\",", (char *)&(tmp->state));
 		else
 			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);
 		if (pos->next != &msglist) {
 			mws_add(buff, ",");
@@ -556,8 +562,6 @@
         long mesg_posn;
         static struct person mesg_user;
 
-        char newbuff[MAXPIPELENGTH];
-
         ipc_message_t * msg = read_socket(ipcsock, 1);
 
         while (msg != NULL) {
@@ -565,10 +569,9 @@
                         strcpy(mesg_user.name,"System");
                 else
                         fetch_user(&mesg_user, mesg_posn);
-                bzero(newbuff, sizeof(newbuff));
-                memcpy(newbuff, msg->body, _MIN(sizeof(newbuff)-1, msg->bodylen));
-                accept_pipe_cmd(msg->head.type, newbuff, msg->head.src, &mesg_user);
 
+                accept_pipe_cmd(msg, &mesg_user);
+
                 ipcmsg_destroy(msg);
                 msg = read_socket(ipcsock, 0);
         }




More information about the mw-devel mailing list