[mw-devel] MW3 r981 - trunk/src

arthur at sucs.org arthur at sucs.org
Sat Nov 3 18:39:25 GMT 2007


Author: arthur
Date: 2007-11-03 18:39:25 +0000 (Sat, 03 Nov 2007)
New Revision: 981

Modified:
   trunk/src/alias.c
   trunk/src/js.c
   trunk/src/main.c
Log:
call an event handler before SAY on text input


Modified: trunk/src/alias.c
===================================================================
--- trunk/src/alias.c	2007-11-03 14:58:19 UTC (rev 980)
+++ trunk/src/alias.c	2007-11-03 18:39:25 UTC (rev 981)
@@ -16,6 +16,7 @@
 Alias ipc_list=NULL;
 Alias force_list=NULL;
 Alias shutdown_list=NULL;
+Alias eventin_list=NULL;
 
 /* completely destroys the given list */
 void DestroyAllLinks(Alias *list)

Modified: trunk/src/js.c
===================================================================
--- trunk/src/js.c	2007-11-03 14:58:19 UTC (rev 980)
+++ trunk/src/js.c	2007-11-03 18:39:25 UTC (rev 981)
@@ -32,6 +32,7 @@
 extern Alias ipc_list;
 extern Alias force_list;
 extern Alias shutdown_list;
+extern Alias eventin_list;
 
 extern struct person *user;
 extern long userposn;
@@ -46,7 +47,7 @@
 int js_interrupted=1;
 struct alarm *js_timeout_event=NULL;
 
-enum bindtype { K_BIND=0, K_BIND_EVENT, K_BIND_ONOFF, K_BIND_IPC, K_BIND_FORCE, K_BIND_SHUTDOWN, K_BIND_ALIAS, K_BIND_RPC };
+enum bindtype { K_BIND=0, K_BIND_EVENT, K_BIND_ONOFF, K_BIND_IPC, K_BIND_FORCE, K_BIND_SHUTDOWN, K_BIND_ALIAS, K_BIND_RPC, K_BIND_INPUT };
 #define K_BROADCAST 1
 
 JSClass globclass = {
@@ -512,6 +513,12 @@
 			}
 			
 			break;
+		case K_BIND_INPUT:
+			if(AddLink(&eventin_list, function_name, ""))
+			{
+				printf("Input Event bind %s already exists.\n", function_name);
+			}
+			break;
 		default:
 			printf("Unknown bind type %d\n", bind_type);
 			break;
@@ -623,6 +630,12 @@
 			}
 			
 			break;
+		case K_BIND_INPUT:
+			if(DestroyLink(&eventin_list, function_name))
+			{
+				printf("Input Event bind %s does not exist for unbinding.\n", function_name);
+			}
+			break;
 		default:
 			printf("Unknown unbind type %d\n", bind_type);
 			break;
@@ -1353,6 +1366,7 @@
 	JS_DefineProperty(jscx, jsroot, "K_BIND_SHUTDOWN", INT_TO_JSVAL(K_BIND_SHUTDOWN), NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
 	JS_DefineProperty(jscx, jsroot, "K_BIND_RPC", INT_TO_JSVAL(K_BIND_RPC), NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
 	JS_DefineProperty(jscx, jsroot, "K_BIND_ALIAS", INT_TO_JSVAL(K_BIND_ALIAS), NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
+	JS_DefineProperty(jscx, jsroot, "K_BIND_INPUT", INT_TO_JSVAL(K_BIND_INPUT), NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
 
 	// Broadcast constant (for ipc,rpc)
 	JS_DefineProperty(jscx, jsroot, "K_BROADCAST", INT_TO_JSVAL(K_BROADCAST), NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT);

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2007-11-03 14:58:19 UTC (rev 980)
+++ trunk/src/main.c	2007-11-03 18:39:25 UTC (rev 981)
@@ -62,6 +62,7 @@
 extern Alias ipc_list;
 extern Alias force_list;
 extern Alias shutdown_list;
+extern Alias eventin_list;
 
 
 #ifdef RELEASE
@@ -877,8 +878,21 @@
 		{
 			set_talk_rights();
 			c=DoCommand(&comm[1], mudtable);
-		}else
-			chat_say(comm);
+		}else {
+			char *event_name=NULL;
+			script_output=1;
+			while ((event_name = NextLink(eventin_list, event_name)) != NULL) {
+				if (is_js(event_name)) {
+					char *argv[2];
+					argv[0] = comm;
+					argv[1] = NULL;
+					busy++;
+					js_exec(event_name, 1, argv);
+					busy--;
+				}
+			}
+			if (script_output) chat_say(comm);
+		}
 	}else
 	{
 		set_rights();





More information about the mw-devel mailing list