[mw-devel] MW3 r877 - trunk/src

pwb at sucs.org pwb at sucs.org
Tue Apr 4 16:45:33 BST 2006


Author: pwb
Date: 2006-04-04 16:45:32 +0100 (Tue, 04 Apr 2006)
New Revision: 877

Modified:
   trunk/src/script_inst.c
   trunk/src/talker.c
   trunk/src/talker.h
Log:
.notsayto now makes sure the user is on before letting it go ahead. Fixes #2.

There is now an "ison" function, please use that instead of grovelling through the who file in future.


Modified: trunk/src/script_inst.c
===================================================================
--- trunk/src/script_inst.c	2006-04-03 19:06:31 UTC (rev 876)
+++ trunk/src/script_inst.c	2006-04-04 15:45:32 UTC (rev 877)
@@ -1676,49 +1676,18 @@
 
 void scr_ison( struct code *pc, int fargc, char **fargv )
 {
-	struct person u;
-	struct who w;
-	int ufile,wfile;
 	char *who;
-	int found=0;
+	int found;
 
-	if (pc->argc<1) {
-		if (script_debug) printf("Error in %s at %s too few arguments.\n", pc->inst->name, pc->debug);
-		return;
-	}
-
 	who=eval_arg(pc->argv[0], fargc, fargv);
+	found = ison(who);
 
-	wfile=openwhofile(O_RDONLY);
-	ufile=openuserfile(O_RDONLY);
-
-	while (read(wfile,&w,sizeof(w)) && !found)
-	{
-		/* Skip invalid entries */
-		if (w.posn < 0)
-			continue;
-
-		lseek(ufile,w.posn,0);
-		read(ufile,&u,sizeof(u));
-
-		if (w.pid>-1 && kill(w.pid,0)==0)
-		{
-			if (cm_flags(u.chatmode,CM_ONCHAT,CM_MODE_ALL) && !strcasecmp(who, u.name))
-			{
-				found=1;
-				if (script_debug) printf("- ISON: found user '%s'\n", u.name);
-			}
-		}
-	}
-
-	close(ufile);
-	close(wfile);
-
 	compare_count++;
 	if (found) {
+		if (script_debug) printf("- ISON: found user '%s'\n", who);
 		compare_match++;
 	} else {
-		if (script_debug) escprintf("- ISON: couldnt see '%s'\n", who);
+		if (script_debug) escprintf("- ISON: couldn't see '%s'\n", who);
 	}
 
 	free(who);

Modified: trunk/src/talker.c
===================================================================
--- trunk/src/talker.c	2006-04-03 19:06:31 UTC (rev 876)
+++ trunk/src/talker.c	2006-04-04 15:45:32 UTC (rev 877)
@@ -67,6 +67,33 @@
 
 extern int g_boTermCap;
 
+int ison(char * uname)
+{
+    // XXX: write some abstraction for reading the whofile
+    struct person u;
+    struct who w;
+    int ufile, wfile;
+    int found = 0;
+
+    wfile = openwhofile(O_RDONLY);
+    ufile = openuserfile(O_RDONLY);
+
+    while (read(wfile, &w, sizeof(w)) && !found) {
+	// skip invalid entries
+	if (w.posn < 0) continue;
+
+	lseek(ufile, w.posn, 0);
+	read(ufile, &u, sizeof(u));
+
+	if (w.pid > -1 && kill(w.pid, 0) == 0)
+	    if (cm_flags(u.chatmode, CM_ONCHAT, CM_MODE_ALL) && !strcasecmp(uname, u.name))
+		found = 1;
+    }
+    close(ufile);
+    close(wfile);
+    return found;
+}
+
 int screen_h(void)
 {
 	char	*szLines;
@@ -362,6 +389,11 @@
 {
 	char text[MAXTEXTLENGTH];
 
+	// check that the excluded person is on
+	if (!ison(argv[1])) {
+	    printf(_("User %s not logged on.\n"), argv[1]);
+	    return;
+	}
 	text[0]=0;
 	strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
 	chat_sayto(argv[1],text,1);

Modified: trunk/src/talker.h
===================================================================
--- trunk/src/talker.h	2006-04-03 19:06:31 UTC (rev 876)
+++ trunk/src/talker.h	2006-04-04 15:45:32 UTC (rev 877)
@@ -1,6 +1,9 @@
 #include "Parse.h"
 
 /* talker.c */
+int ison(char * uname);
+
+/* talker command functions */
 void t_bind(CommandList *cm, int argc, char **argv, char *args);
 void t_unbind(CommandList *cm, int argc, char **argv, char *args);
 void t_scrhelp(CommandList *cm, int argc, char **argv, char *args);




More information about the mw-devel mailing list