[mw-devel] MW3 r1316 - in trunk/src: . server

arthur at sucs.org arthur at sucs.org
Wed Dec 12 20:42:50 GMT 2012


Author: arthur
Date: 2012-12-12 20:42:50 +0000 (Wed, 12 Dec 2012)
New Revision: 1316

Modified:
   trunk/src/incoming.c
   trunk/src/script_inst.c
   trunk/src/server/servsock.c
   trunk/src/talker.c
   trunk/src/talker.h
Log:
Migrate notsayto over to be a say_to_room message variant


Modified: trunk/src/incoming.c
===================================================================
--- trunk/src/incoming.c	2012-12-11 22:04:12 UTC (rev 1315)
+++ trunk/src/incoming.c	2012-12-12 20:42:50 UTC (rev 1316)
@@ -538,6 +538,14 @@
 					snprintf(tb, len, "%s %s", whom, text);
 					break;
 			}
+		} else
+		if (strcmp(type, "notsayto")==0) {
+			const char *exclude = json_getstring(j, "exclude");
+			if (exclude == NULL) exclude="Unknown";
+			if (text[strlen(text)-1] == '?')
+				snprintf(tb, len, "%s asks (-%s): %s", whom, exclude, text);
+			else
+				snprintf(tb, len, "%s says (-%s): %s", whom, exclude, text);
 		} else {
 			/* same as say for now */
 			snprintf(tb, len, "%s: %s", whom, text);

Modified: trunk/src/script_inst.c
===================================================================
--- trunk/src/script_inst.c	2012-12-11 22:04:12 UTC (rev 1315)
+++ trunk/src/script_inst.c	2012-12-12 20:42:50 UTC (rev 1316)
@@ -2356,7 +2356,7 @@
 	}
 
 	text = eval_arg(pc->argv[0], fargc, fargv);
-	chat_sayto(text,tmp,0);
+	chat_sayto(text,tmp);
 	free(text);
 	free(tmp);
 }

Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c	2012-12-11 22:04:12 UTC (rev 1315)
+++ trunk/src/server/servsock.c	2012-12-12 20:42:50 UTC (rev 1316)
@@ -278,17 +278,26 @@
 		int users_fd = openuserfile(O_RDONLY);
 		struct who who;
 		struct person user;
+		json_t * j = json_init(msg);
 
+		const char * exclude = json_getstring(j, "exclude");
+
 		while (read(who_fd, &who, sizeof(who)) > 0) {
 			if (who.posn < 0) continue;
 			if (who.pid <= 0) continue;
 
 			lseek(users_fd, who.posn, SEEK_SET);
 			if (read(users_fd, &user, sizeof(user)) <= 0) continue;
+
+			/* have we been told to exclude someone in this room */
+			if (exclude!=NULL && strcasecmp(exclude, user.name)==0) continue;
+
+			/* room matches, send them a copy */
 			if (user.room == msg->head.dst) {
 				msg_attach_to(msg, who.pid);
 			}
 		}
+		json_decref(j);
 		close(who_fd);
 		close(users_fd);
 		ipcmsg_destroy(msg);

Modified: trunk/src/talker.c
===================================================================
--- trunk/src/talker.c	2012-12-11 22:04:12 UTC (rev 1315)
+++ trunk/src/talker.c	2012-12-12 20:42:50 UTC (rev 1316)
@@ -508,7 +508,7 @@
 
 	text[0]=0;
 	strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
-	chat_sayto(argv[1],text,0);
+	chat_sayto(argv[1],text);
 }
 
 void t_sayto_warn(CommandList *cm, int argc, const char **argv, char *args)
@@ -526,9 +526,20 @@
 	    printf(_("User '%s' is not logged on.\n"), argv[1]);
 	    return;
 	}
-	text[0]=0;
-	strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
-	chat_sayto(argv[1],text,1);
+	snprintf(text, MAXTEXTLENGTH, "%s", args);
+	apply_gag(text);
+	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());
+	ipcmsg_destination(msg, user->room);
+	json_t * j = json_init(NULL);
+	json_addstring(j, "text", text);
+	json_addstring(j, "type", "notsayto");
+	json_addstring(j, "exclude", argv[1]);
+	ipcmsg_json_encode(msg, j);
+	json_decref(j);
+	ipcmsg_transmit(msg);
 }
 
 void t_ventril(CommandList *cm, int argc, const char **argv, char *args)
@@ -1502,7 +1513,7 @@
 	current_rights = RIGHTS_TALK;
 }	
 
-static void talk_sayto(char *text, const char *to, int channel, int exclude) 
+static void talk_sayto(char *text, const char *to, int channel) 
 {
 	char buff[MAXTEXTLENGTH];
 	char gbuff[MAXTEXTLENGTH];
@@ -1533,68 +1544,41 @@
 		if (global) sendbuff = gbuff;
 		else sendbuff = buff;
 
-		/* work out whether to send or not */
-		if (exclude)
-		{
-			if (u.room != user->room)
-			{
-				if (cm_flags(u.chatmode, CM_GLOBAL, CM_MODE_ALL) && strcasecmp(to, u.name))
-					send2user = 1;
-				else
-					send2user = 0;
-			}
-			else
-				send2user = strcasecmp(to, u.name);
-		}
-		else
-			send2user = !strcasecmp(to, u.name);
+		send2user = !strcasecmp(to, u.name);
 
 		if (cm_flags(u.chatmode,CM_ONCHAT,CM_MODE_ALL) && send2user)
 			if (! ipc_send_to_pid(w.pid, IPC_TEXT, sendbuff)) count++;
 	}
 
-	if (exclude)
+	if (count==0)
 	{
-		mwlog("NSAYTO %s %s", to, text);
-	}
-	else
+		printf("User '%s' is not logged on.\n",to);
+	}else
 	{
-		if (count==0)
-		{
-			printf("User '%s' is not logged on.\n",to);
-		}else
-		{
-			mwlog("SAYTO %s %s",to,text);
-		}
+		mwlog("SAYTO %s %s",to,text);
 	}
 
 	close(ufile);
 	close(wfile);
 }
 
-void chat_sayto(const char *to, char *text, int exclude)
+void chat_sayto(const char *to, char *text)
 {
 	char buff[MAXTEXTLENGTH];
 
 	buff[0]=0;
 	if (text[strlen(text)-1] == '?')
 	{
-		if (exclude)
-			snprintf(buff,MAXTEXTLENGTH-1,"asks (-%s): ", to);
-		else
-			snprintf(buff,MAXTEXTLENGTH-1,"asks: ");
+		snprintf(buff,MAXTEXTLENGTH-1,"asks: ");
 	}
 	else
 	{
-		if (exclude)
-			snprintf(buff,MAXTEXTLENGTH-1,"says (-%s): ", to);
-		else
-			snprintf(buff,MAXTEXTLENGTH-1,"says: ");
+		snprintf(buff,MAXTEXTLENGTH-1,"says: ");
 	}
 	apply_gag(text);
 	strncat(buff, text, MAXTEXTLENGTH - strlen(buff) - 1);
 
-	talk_sayto(buff, to, user->room, exclude);
+	talk_sayto(buff, to, user->room);
 }
 
 struct IgnoreList *is_ignored(const char *name, struct IgnoreList **prev)

Modified: trunk/src/talker.h
===================================================================
--- trunk/src/talker.h	2012-12-11 22:04:12 UTC (rev 1315)
+++ trunk/src/talker.h	2012-12-12 20:42:50 UTC (rev 1316)
@@ -64,7 +64,7 @@
 void t_chaton(void);
 
 void chat_say(char *text);
-void chat_sayto(const char *to,char *text, int exclude);
+void chat_sayto(const char *to,char *text);
 void set_talk_rights(void);
 void talk_send_emote(char * text, int channel, int plural);
 void talk_send_rawbcast(char * text);




More information about the mw-devel mailing list