[mw-devel] [Git][arthur/mw][master] Store messages after processing

Andrew Price welshbyte at sucs.org
Wed Nov 15 02:57:39 GMT 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
5e203b86 by Andrew Price at 2017-11-15T02:49:10+00:00
Store messages after processing

Move the store_message() call to after the apply_gag()ing and message
routing has been done. That way the message will still be replayed with
a gag applied after a server restart.

- - - - -


1 changed file:

- src/server/servsock.c


Changes:

=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -359,10 +359,6 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
 	 *    all below this point are intended to be retransmitted
 	 */
 
-	/* set the unique serial number and timestamp */
-	assign_serial(msg);
-	store_message(msg);
-
 	/* load sender */
 	struct user from;
 	fetch_user(&from, conn->user);
@@ -374,12 +370,8 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
 		const char * exclude = json_getstring(j, "exclude");
 		msg_attach_to_channel(msg, msg->head.dst, exclude);
 		json_decref(j);
-		ipcmsg_destroy(msg);
-		return;
-	}
-
-	/* message is for a specific username */
-	if (msg->head.type == IPC_SAYTOUSER) {
+	} else if (msg->head.type == IPC_SAYTOUSER) {
+		/* message is for a specific username */
 		msg_apply_gag(&from, msg, "text");
 		/* eventually this should be a server maintained list */
 		json_t * j = json_init(msg);
@@ -388,15 +380,9 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
 			send_error(conn, msg, "User '%s' not found", target);
 		}
 		json_decref(j);
-		ipcmsg_destroy(msg);
-		return;
-
-	}
-
-	/* send message to everyone (unless this room is soundproof) */
-	if (msg->head.type == IPC_SAYTOALL) {
+	} else if (msg->head.type == IPC_SAYTOALL) {
+		/* send message to everyone (unless this room is soundproof) */
 		msg_apply_gag(&from, msg, "text");
-
 		/* load the senders room to see if its soundproof */
 		struct room room;
 		RoomInit(&room);
@@ -410,42 +396,29 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
 			msg->head.type = IPC_SAYTOROOM;
 			msg->head.dst = from.record.room;
 			msg_attach_to_channel(msg, room.num, NULL);
-			printf("Shout in soundproof room (%d) change to SAYTORROM %d\n",
+			printf("Shout in soundproof room (%d) change to SAYTOROOM %d\n",
 			       room.sproof, from.record.room);
 		} else {
 			msg_attach_to_all(msg);
 		}
-
 		RoomDestroy(&room);
-		ipcmsg_destroy(msg);
-		return;
-	}
-
-	if (msg->head.type == IPC_EVENT) {
+	} else if (msg->head.type == IPC_EVENT) {
 		printf("Event message\n");
 		msg_attach_to_all(msg);
-		ipcmsg_destroy(msg);
-		return;
-	}
-
-	if (msg->head.type == IPC_WIZ) {
+	} else if (msg->head.type == IPC_WIZ) {
 		printf("Wiz message\n");
 		msg_attach_to_perm(msg, PERM_WIZCHAT);
-		ipcmsg_destroy(msg);
-		return;
-	}
-
-	/* it was a broadcast message */
-	if (msg->head.dst == SYSTEM_USER) {
+	} else if (msg->head.dst == SYSTEM_USER) {
+		/* it was a broadcast message */
 		printf("Broadcast message to system user %s\n", ipc_nametype(msg->head.type));
 		msg_attach_to_all(msg);
-		ipcmsg_destroy(msg);
-		return;
+	} else {
+		/* otherwise redistribute this message to intended target */
+		printf("Unhandled direct-to-user command %s\n", ipc_nametype(msg->head.type));
+		msg_attach_to_userid(msg, msg->head.dst);
 	}
-
-	/* otherwise redistribute this message to intended target */
-	printf("Unhandled direct-to-user command %s\n", ipc_nametype(msg->head.type));
-	msg_attach_to_userid(msg, msg->head.dst);
+	assign_serial(msg);
+	store_message(msg);
 	ipcmsg_destroy(msg);
 }
 



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

---
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/5e203b86272e2a2ce8ce831adad3ce0ecf7effa3
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/20171115/efe3bdd4/attachment-0001.html>


More information about the mw-devel mailing list