[mw-devel] MW3 r1133 - trunk/src

welshbyte at sucs.org welshbyte at sucs.org
Sat Dec 12 14:49:51 GMT 2009


Author: welshbyte
Date: 2009-12-12 14:49:51 +0000 (Sat, 12 Dec 2009)
New Revision: 1133

Modified:
   trunk/src/incoming.c
   trunk/src/proto.h
   trunk/src/script_inst.c
   trunk/src/talker.c
Log:
- Rework is_ignored() to return a pointer to the found node and (optionally) set a pointer to the previous one.
- Get rid of a bunch of code which does a now-unnecessary second loop over the ignore list.


Modified: trunk/src/incoming.c
===================================================================
--- trunk/src/incoming.c	2009-12-12 14:36:46 UTC (rev 1132)
+++ trunk/src/incoming.c	2009-12-12 14:49:51 UTC (rev 1133)
@@ -573,13 +573,13 @@
 			reset_timeout(user->timeout);
 			break;
 		case IPC_TEXT:
-			if (!is_ignored(mesg_user->name)) force_text(newbuff, mesg_user->name);
+			if (!is_ignored(mesg_user->name, NULL)) force_text(newbuff, mesg_user->name);
 			break;
 		case IPC_SCRIPTIPC:
-			if (!is_ignored(mesg_user->name)) force_ipc(newbuff, mesg_user->name);
+			if (!is_ignored(mesg_user->name, NULL)) force_ipc(newbuff, mesg_user->name);
 			break;
 		case IPC_SCRIPTRPC:
-			if (!is_ignored(mesg_user->name)) force_rpc(newbuff, mesg_user->name);
+			if (!is_ignored(mesg_user->name, NULL)) force_rpc(newbuff, mesg_user->name);
 			break;
 		case IPC_CHECKONOFF:
 			force_checkonoff(newbuff, mesg_user->name);
@@ -651,7 +651,6 @@
 static void force_wiz(char *newbuff, char *from)
 {
 	char tb[MAXTEXTLENGTH];
-	int pre;
 	tb[0]=0;
 
 	if (s_timestamp(user->special))
@@ -668,7 +667,6 @@
 		strncat(tb, from, MAXTEXTLENGTH - strlen(tb) - 1);
 		strncat(tb, "> ", MAXTEXTLENGTH - strlen(tb) - 1);
 	}
-	pre = strlen(tb);
 	strncat(tb, newbuff, MAXTEXTLENGTH - strlen(tb) - 1);
 
 	StackMesg(tb, from, 0);

Modified: trunk/src/proto.h
===================================================================
--- trunk/src/proto.h	2009-12-12 14:36:46 UTC (rev 1132)
+++ trunk/src/proto.h	2009-12-12 14:49:51 UTC (rev 1133)
@@ -228,7 +228,7 @@
 /* newmain.c */
 void filed_help(char *topic);
 /* talker.c */
-int is_ignored(char *name);
+struct IgnoreList *is_ignored(char *name, struct IgnoreList **prev);
 int screen_h(void);
 int screen_w(void);
 void sendipc(char *to, char *text, int broadcast);

Modified: trunk/src/script_inst.c
===================================================================
--- trunk/src/script_inst.c	2009-12-12 14:36:46 UTC (rev 1132)
+++ trunk/src/script_inst.c	2009-12-12 14:49:51 UTC (rev 1133)
@@ -651,7 +651,7 @@
 				{
 					if (cm_flags(p.chatmode,CM_ONCHAT,CM_MODE_ANY))
 					{
-						if (!is_ignored(p.name))
+						if (!is_ignored(p.name, NULL))
 						{   
 		  					newnode = malloc(sizeof(struct IgnoreList));
 							newnode->name = malloc(sizeof(char) * (strlen(p.name) + 1));
@@ -674,18 +674,8 @@
 			int32_t		tempposn; 
 			struct person	tempusr;
 
-			if (!is_old(&tempusr,what, &tempposn))
-			{
-				/* doesnt exist */
-			}
-		 	else if (! ison(what)) {
-				/* not logged on */
-			}
-			else if (is_ignored(what))
-			{
-				/* already ignored */
-		 	}
-			else
+			/* User exists, is logged on and isn't already ignored */
+			if (is_old(&tempusr,what, &tempposn) && ison(what) && !is_ignored(what, NULL))
 			{   
 				newnode = malloc(sizeof(struct IgnoreList));
 			 	newnode->name = strdup(what);
@@ -717,42 +707,22 @@
 		/* ignore one user */
 		else
 		{
-			if (is_ignored(what))
+			struct IgnoreList *found, *prev = NULL;
+			found = is_ignored(what, &prev);
+			if (found)
 			{
-			 	struct IgnoreList *prev, *temp, *tail;
-			 	char *n=NULL;
+				/* if at front */
+				if (prev == NULL) ignored = ignored->next;
+				/* in middle/end */
+			 	else prev->next = found->next;
+			 	free(found->name);
+			 	free(found);
 
-				tail = ignored;
-				prev = NULL;
-				while (tail != NULL)
-				{
-				 	if (!strcasecmp(what, tail->name))
-				 	{
-				 		n = strdup(tail->name);
-				 	 	temp = tail;
-				 	 	/* if at front */
-				 	 	if (prev == NULL) ignored = ignored->next;
-				 	 	/* in middle/end */
-				 	 	else prev->next = tail->next;
-				 	 	free(temp->name);
-				 	 	free(temp);
-				 	 	break;
-				 	}
-				 	prev = tail;
-				 	tail = tail->next;
-				}
-				free(n);
 				compare_match++;
 				mwlog("Q-UNIGNORE(%s)", what);
 			}
-			else
-			{
-				/* not ignored */
-			}
 		}
-
 	}
-
 	free(what);
 }
 

Modified: trunk/src/talker.c
===================================================================
--- trunk/src/talker.c	2009-12-12 14:36:46 UTC (rev 1132)
+++ trunk/src/talker.c	2009-12-12 14:49:51 UTC (rev 1133)
@@ -1028,7 +1028,7 @@
 			{
 				if (cm_flags(p.chatmode,CM_ONCHAT,CM_MODE_ANY))
 				{
-					if (is_ignored(p.name))
+					if (is_ignored(p.name, NULL))
 					{
 						printf("*** User '%s' already ignored ***\n", p.name);
 					}
@@ -1066,7 +1066,7 @@
 			snprintf(text,MAXTEXTLENGTH-1,"*** User '%s' is not currently logged on ***", tempusr.name);
 			display_message(text, 1, 1);
 		}
-		else if (is_ignored(argv[argloop]))
+		else if (is_ignored(argv[argloop], NULL))
 		{
 			snprintf(text,MAXTEXTLENGTH-1,"*** User '%s' is already being ignored ***", tempusr.name);
 			display_message(text, 1, 1);
@@ -1131,36 +1131,21 @@
 	namecount = 0;
 	for (argloop = 1; argloop < argc; argloop++)
 	{
-		if (is_ignored(argv[argloop]))
+		struct IgnoreList *found, *prev = NULL;
+		found = is_ignored(argv[argloop], &prev);
+		if (found)
 		{
-			struct IgnoreList *prev, *temp, *tail;
-			char *n = NULL;
+			/* if at front */
+			if (prev == NULL) ignored = ignored->next;
+			/* in middle/end */
+			else prev->next = found->next;
+			free(found->name);
+			free(found);
 
-			tail = ignored;
-			prev = NULL;   
-			while (tail != NULL)
-			{
-				if (!strcasecmp(argv[argloop], tail->name))
-				{
-					n = strdup(tail->name);
-					temp = tail;
-					/* if at front */
-					if (prev == NULL) ignored = ignored->next;
-					/* in middle/end */
-					else prev->next = tail->next;
-					free(temp->name);
-					free(temp);
-					break;
-				}
-				prev = tail;
-				tail = tail->next;
-			}
-
-			namebuff[namecount] = malloc(sizeof(char) * (strlen(n) + 1));
-			strcpy(namebuff[namecount], n);
+			/* argv is here for the duration so we can point into it */
+			namebuff[namecount] = argv[argloop];
 			namecount++;
-			snprintf(text,MAXTEXTLENGTH-1,"*** You have just unignored user '%s' ***", n);
-			free(n);
+			snprintf(text,MAXTEXTLENGTH-1,"*** You have just unignored user '%s' ***", argv[argloop]);
 			display_message(text, 1, 1);
 		}
 		else
@@ -1643,17 +1628,20 @@
 	return (b);
 }
 
-int is_ignored(char *name)
+struct IgnoreList *is_ignored(char *name, struct IgnoreList **prev)
 {
 	struct IgnoreList *tail;
 
+	if (prev != NULL) *prev = NULL;
+
 	tail = ignored;
 	while (tail != NULL)
 	{
-		if (!strcasecmp(tail->name, name)) return(1);
+		if (!strcasecmp(tail->name, name)) return tail;
+		if (prev != NULL) *prev = tail;
 		tail = tail->next;
 	}
-	return(0);
+	return NULL;
 }
 
 void sendipc(char *to, char *text, int broadcast) 




More information about the mw-devel mailing list