[mw-devel] MW3 r1019 - trunk/src

firefury at sucs.org firefury at sucs.org
Fri Mar 28 16:38:01 GMT 2008


Author: firefury
Date: 2008-03-28 16:38:00 +0000 (Fri, 28 Mar 2008)
New Revision: 1019

Modified:
   trunk/src/ipc.c
   trunk/src/ipc.h
   trunk/src/talker.c
Log:
Stop raw broadcasts looping back


Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2008-03-28 16:36:42 UTC (rev 1018)
+++ trunk/src/ipc.c	2008-03-28 16:38:00 UTC (rev 1019)
@@ -97,7 +97,7 @@
 		lseek(users_fd, who.posn, SEEK_SET);
 		if (read(users_fd, &user, sizeof(user)) <= 0) continue;
 		if ((dest) && strcasecmp(user.name, dest)) continue;
-		if ((filter) && (! filter(&user, filterinfo))) continue;
+		if ((filter) && (! filter(&user, &who, filterinfo))) continue;
 		if (! ipc_send_to_pid(who.pid, msgtype, data)) count++;
 		else if (dest) fprintf(stderr, "Write to PID %u failed.\n", who.pid);
 	}

Modified: trunk/src/ipc.h
===================================================================
--- trunk/src/ipc.h	2008-03-28 16:36:42 UTC (rev 1018)
+++ trunk/src/ipc.h	2008-03-28 16:38:00 UTC (rev 1019)
@@ -28,7 +28,7 @@
 	IPC_PROTPOWER	= 25
 };
 
-typedef int (send_filter)(const struct person * usr, const void * info);
+typedef int (send_filter)(const struct person * usr, const struct who * who, const void * info);
 
 int ipc_send_to_pid(pid_t dest, enum ipc_types msgtype, const char * data);
 unsigned int ipc_send_to_username(const char * dest, enum ipc_types msgtype, const char * data);

Modified: trunk/src/talker.c
===================================================================
--- trunk/src/talker.c	2008-03-28 16:36:42 UTC (rev 1018)
+++ trunk/src/talker.c	2008-03-28 16:38:00 UTC (rev 1019)
@@ -67,51 +67,62 @@
 
 extern int g_boTermCap;
 
-static int send_filter_oneroom(const struct person * usr, const void * info) {
+struct filter_info {
+	int	channel;
+	int	noloopback;
+};
+
+static int send_filter_oneroom(const struct person * usr, const struct who * who, const void * info) {
 	// Everyone in a room except people with global turned on
-	int	channel = *(int*) info;
+	struct filter_info *	f_info = (struct filter_info *) info;
 
+	if ((f_info->noloopback) && (getpid() == who->pid)) return 0;
 	if (! cm_flags(usr->chatmode, CM_ONCHAT, CM_MODE_ALL)) return 0;
 	if (cm_flags(usr->chatmode, CM_GLOBAL, CM_MODE_ALL)) return 0;
 	
-	return (usr->room == channel);
+	return (usr->room == f_info->channel);
 }
 
-static int send_filter_nonglobal(const struct person * usr, const void * info) {
+static int send_filter_nonglobal(const struct person * usr, const struct who * who, const void * info) {
 	// Everyone outside a room with global turned off
-	int	channel = *(int*) info;
+	struct filter_info *	f_info = (struct filter_info *) info;
 
+	if ((f_info->noloopback) && (getpid() == who->pid)) return 0;
 	if (! cm_flags(usr->chatmode, CM_ONCHAT, CM_MODE_ALL)) return 0;
 	if (cm_flags(usr->chatmode, CM_GLOBAL, CM_MODE_ALL)) return 0;
 	
-	return (usr->room != channel);
+	return (usr->room != f_info->channel);
 }
 
-static int send_filter_global(const struct person * usr, const void * info) {
+static int send_filter_global(const struct person * usr, const struct who * who, const void * info) {
 	// Everyone with global turned on
 	// Except if the room is soundproof - in that case only people in
 	// the room with global turned on.
-	int		channel = *(int*) info;
-	int		sproof=0;
-	struct room	tmp_room;
+	struct filter_info *	f_info = (struct filter_info *) info;
+	int			sproof=0;
+	struct room		tmp_room;
 
+	if ((f_info->noloopback) && (getpid() == who->pid)) return 0;
 	if (! cm_flags(usr->chatmode, CM_ONCHAT, CM_MODE_ALL)) return 0;
 	if (! cm_flags(usr->chatmode, CM_GLOBAL, CM_MODE_ALL)) return 0;
 
-	if (usr->room == channel) return 1; // Users on the channel always get it
+	if (usr->room == f_info->channel) return 1; // Users on the channel always get it
 
 	RoomInit(&tmp_room);
-	if (LoadRoom(&tmp_room, channel) && (tmp_room.sproof>0)) sproof=1;
+	if (LoadRoom(&tmp_room, f_info->channel) && (tmp_room.sproof>0)) sproof=1;
 	RoomDestroy(&tmp_room);
 	
 	return (! sproof);
 }
 
 static void talk_send_to_room(const char * text, int channel) {
-	char		buff[MAXTEXTLENGTH];
-	struct room	tmp_room;
+	char			buff[MAXTEXTLENGTH];
+	struct room		tmp_room;
+	struct filter_info	f_info;
 
-	ipc_send_to_all(IPC_TEXT, text, send_filter_oneroom, &channel);
+	memset(&f_info, 0, sizeof(f_info));
+	f_info.channel = channel;
+	ipc_send_to_all(IPC_TEXT, text, send_filter_oneroom, &f_info);
 	
 	RoomInit(&tmp_room);
 	LoadRoom(&tmp_room, channel);
@@ -119,18 +130,21 @@
 	
 	if (myroom.hidden > 0) snprintf(buff, MAXTEXTLENGTH, "?:%s", text);
 	else snprintf(buff, MAXTEXTLENGTH, "%d:%s", channel, text);
-	ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &channel);
+	ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &f_info);
 }
 
 void talk_send_shout(char * text){
-	char buff[MAXTEXTLENGTH];
+	char			buff[MAXTEXTLENGTH];
+	struct filter_info	f_info;
 	
+	memset(&f_info, 0, sizeof(f_info));
+	f_info.channel = user->room;
 	mwlog("SHOUT %s", text);
 	snprintf(buff, MAXTEXTLENGTH, "%s shouts %s", user->name, text);
-	ipc_send_to_all(IPC_TEXT, buff, send_filter_oneroom, &(user->room));
-	ipc_send_to_all(IPC_TEXT, buff, send_filter_nonglobal, &(user->room));
+	ipc_send_to_all(IPC_TEXT, buff, send_filter_oneroom, &f_info);
+	ipc_send_to_all(IPC_TEXT, buff, send_filter_nonglobal, &f_info);
 	snprintf(buff, MAXTEXTLENGTH, "*:%s shouts %s", user->name, text);
-	ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &(user->room));
+	ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &f_info);
 }
 
 static void talk_send_say(char * text, int channel){
@@ -150,13 +164,17 @@
 }
 
 void talk_send_rawbcast(char * text){
-	char buff[MAXTEXTLENGTH];
+	char			buff[MAXTEXTLENGTH];
+	struct filter_info	f_info;
 	
+	memset(&f_info, 0, sizeof(f_info));
+	f_info.channel = user->room;
+	f_info.noloopback = 1;
 	mwlog("RAWBCAST %s", text);
-	ipc_send_to_all(IPC_TEXT, text, send_filter_oneroom, &(user->room));
-	ipc_send_to_all(IPC_TEXT, text, send_filter_nonglobal, &(user->room));
+	ipc_send_to_all(IPC_TEXT, text, send_filter_oneroom, &f_info);
+	ipc_send_to_all(IPC_TEXT, text, send_filter_nonglobal, &f_info);
 	snprintf(buff, MAXTEXTLENGTH, "*:%s", text);
-	ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &(user->room));
+	ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &f_info);
 }
 
 void talk_send_emote(char * text, int channel, int pleural){





More information about the mw-devel mailing list