r4723 - in trunk/data/qcsrc: client common menu menu/nexuiz server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Oct 11 03:00:31 EDT 2008


Author: div0
Date: 2008-10-11 03:00:30 -0400 (Sat, 11 Oct 2008)
New Revision: 4723

Modified:
   trunk/data/qcsrc/client/Main.qc
   trunk/data/qcsrc/client/mapvoting.qc
   trunk/data/qcsrc/client/progs.src
   trunk/data/qcsrc/common/campaign_file.qc
   trunk/data/qcsrc/common/gamecommand.qc
   trunk/data/qcsrc/common/util.qc
   trunk/data/qcsrc/common/util.qh
   trunk/data/qcsrc/menu/gamecommand.qc
   trunk/data/qcsrc/menu/menu.qc
   trunk/data/qcsrc/menu/nexuiz/dialog_singleplayer.c
   trunk/data/qcsrc/menu/nexuiz/keybinder.c
   trunk/data/qcsrc/menu/nexuiz/maplist.c
   trunk/data/qcsrc/menu/nexuiz/slider_resolution.c
   trunk/data/qcsrc/menu/nexuiz/util.qc
   trunk/data/qcsrc/menu/nexuiz/weaponslist.c
   trunk/data/qcsrc/menu/progs.src
   trunk/data/qcsrc/server/campaign.qc
   trunk/data/qcsrc/server/cl_player.qc
   trunk/data/qcsrc/server/cl_weapons.qc
   trunk/data/qcsrc/server/clientcommands.qc
   trunk/data/qcsrc/server/defs.qh
   trunk/data/qcsrc/server/g_world.qc
   trunk/data/qcsrc/server/gamecommand.qc
   trunk/data/qcsrc/server/ipban.qc
   trunk/data/qcsrc/server/progs.src
   trunk/data/qcsrc/server/t_items.qc
   trunk/data/qcsrc/server/vote.qc
   trunk/data/qcsrc/server/vote.qh
Log:
Experimental new tokenizer (should now be 1:1 compatible to the console parsing), used for about anything now.
Votes no longer get accidentally reformatted, e.g. "(foo)" to "( foo )".


Modified: trunk/data/qcsrc/client/Main.qc
===================================================================
--- trunk/data/qcsrc/client/Main.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/client/Main.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -253,7 +253,7 @@
 	float argc;
 	// Tokenize String
 	//argc = tokenize(strMessage);
-	argc = tokenizebyseparator(strMessage, " ");
+	argc = tokenize_sane(strMessage);
 	
 	// Acquire Command
 	local string strCmd;
@@ -305,7 +305,7 @@
 float GameCommand(string msg)
 {
 	float argc;
-	argc = tokenize(msg);
+	argc = tokenize_sane(msg);
 	string cmd;
 	cmd = argv(0);
 	if(cmd == "mv_download") {
@@ -879,7 +879,7 @@
 	{
 		if (!keys) 
 		{
-			n = tokenize(findkeysforcommand(command));
+			n = tokenize_insane(findkeysforcommand(command)); // uses '...' strings
 			for(j = 0; j < n; ++j)
 			{
 				k = stof(argv(j));

Modified: trunk/data/qcsrc/client/mapvoting.qc
===================================================================
--- trunk/data/qcsrc/client/mapvoting.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/client/mapvoting.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -242,7 +242,7 @@
 	}
 	else
 	{
-		Cmd_MapVote_MapDownload(tokenize(strcat("mv_download ", ftos(id))));
+		Cmd_MapVote_MapDownload(tokenize_sane(strcat("mv_download ", ftos(id))));
 	}
 }
 

Modified: trunk/data/qcsrc/client/progs.src
===================================================================
--- trunk/data/qcsrc/client/progs.src	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/client/progs.src	2008-10-11 07:00:30 UTC (rev 4723)
@@ -1,14 +1,14 @@
 ../../csprogs.dat
 pre.qh
 
+../common/util-pre.qh
 Defs.qc
 csqc_constants.qc
 ../common/constants.qh
-
 csqc_builtins.qc
+../common/util.qh
 
 ../common/mapinfo.qh
-../common/util.qh
 interpolate.qh
 teamradar.qh
 waypointsprites.qh

Modified: trunk/data/qcsrc/common/campaign_file.qc
===================================================================
--- trunk/data/qcsrc/common/campaign_file.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/common/campaign_file.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -31,7 +31,7 @@
 				continue; // comment
 			if(lineno >= offset)
 			{
-				entlen = tokenize(l);
+				entlen = tokenize_insane(l); // using insane tokenizer for CSV
 
 #define CAMPAIGN_GETARG0                  if(i >= entlen)
 #define CAMPAIGN_GETARG1 CAMPAIGN_GETARG0     error("syntax error in campaign file: line has not enough fields");

Modified: trunk/data/qcsrc/common/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/common/gamecommand.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/common/gamecommand.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -49,7 +49,7 @@
 	float argc;
 	float i, j, f, n;
 	string s, s2;
-	argc = tokenize(command);
+	argc = tokenize_sane(command);
 	if(argv(0) == "help")
 	{
 		print("  rpn EXPRESSION... - a RPN calculator.\n");
@@ -441,8 +441,8 @@
 					// s s2 union
 					s2 = rpn_pop();
 					s = rpn_get();
-					f = tokenize(s);
-					f2 = tokenize(strcat(s, " ", s2));
+					f = tokenize_sane(s);
+					f2 = tokenize_sane(strcat(s, " ", s2));
 					// tokens 0..(f-1) represent s
 					// tokens f..f2 represent s2
 					// UNION: add all tokens to s that are in s2 but not in s
@@ -459,13 +459,13 @@
 					if(substring(s, 0, 1) == " ")
 						s = substring(s, 1, 99999);
 					rpn_set(s);
-					tokenize(command);
+					tokenize_sane(command);
 				} else if(rpncmd == "intersection") {
 					// s s2 intersection
 					s2 = rpn_pop();
 					s = rpn_get();
-					f = tokenize(s);
-					f2 = tokenize(strcat(s, " ", s2));
+					f = tokenize_sane(s);
+					f2 = tokenize_sane(strcat(s, " ", s2));
 					// tokens 0..(f-1) represent s
 					// tokens f..f2 represent s2
 					// INTERSECTION: keep only the tokens from s that are also in s2
@@ -481,13 +481,13 @@
 					if(substring(s, 0, 1) == " ")
 						s = substring(s, 1, 99999);
 					rpn_set(s);
-					tokenize(command);
+					tokenize_sane(command);
 				} else if(rpncmd == "difference") {
 					// s s2 difference
 					s2 = rpn_pop();
 					s = rpn_get();
-					f = tokenize(s);
-					f2 = tokenize(strcat(s, " ", s2));
+					f = tokenize_sane(s);
+					f2 = tokenize_sane(strcat(s, " ", s2));
 					// tokens 0..(f-1) represent s
 					// tokens f..f2 represent s2
 					// DIFFERENCE: keep only the tokens from s that are not in s2
@@ -502,11 +502,11 @@
 					if(substring(s, 0, 1) == " ")
 						s = substring(s, 1, 99999);
 					rpn_set(s);
-					tokenize(command);
+					tokenize_sane(command);
 				} else if(rpncmd == "shuffle") {
 					// s shuffle
 					s = rpn_get();
-					f = tokenize(s);
+					f = tokenize_sane(s);
 
 					for(i = 0; i < f - 1; ++i) {
 						// move a random item from i..f-1 to position i
@@ -518,13 +518,13 @@
 						for(j = i; j < f; ++j)
 							if(j != f2)
 								s = strcat(s, " ", argv(j));
-						f = tokenize(s);
+						f = tokenize_sane(s);
 					}
 
 					if(substring(s, 0, 1) == " ")
 						s = substring(s, 1, 99999);
 					rpn_set(s);
-					tokenize(command);
+					tokenize_sane(command);
 					} else if(rpncmd == "fexists_assert") {
 					s = rpn_pop();
 					if(!rpn_error)

Modified: trunk/data/qcsrc/common/util.qc
===================================================================
--- trunk/data/qcsrc/common/util.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/common/util.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -646,7 +646,7 @@
 	string neworder;
 	float i, n, w;
 
-	n = tokenize(order);
+	n = tokenize_sane(order);
 	for(i = 0; i < n; ++i)
 	{
 		w = stof(argv(i));
@@ -656,7 +656,7 @@
 
 	if(complete)
 	{
-		n = tokenize(neworder);
+		n = tokenize_sane(neworder);
 		for(w = to; w >= from; --w)
 		{
 			for(i = 0; i < n; ++i)
@@ -675,7 +675,7 @@
 	string s;
 	float w, n;
 
-	n = tokenize(order);
+	n = tokenize_sane(order);
 
 	if(i >= 0 && i < n && j >= 0 && j < n && i != j)
 	{
@@ -875,7 +875,7 @@
 {
 	// undo what cvar_settemp did
 	float n, i;
-	n = tokenize(cvar_string("settemp_list"));
+	n = tokenize_sane(cvar_string("settemp_list"));
 	for(i = 0; i < n - 3; i += 3)
 		cvar_set(argv(i + 1), cvar_string(argv(i + 2)));
 	cvar_set("settemp_list", "0");
@@ -897,3 +897,158 @@
 	eps = (max(a, -a) + max(c, -c)) * 0.001;
 	return b == median(a - eps, b, c + eps);
 }
+
+
+
+#ifdef MENUQC
+float (string s) _tokenize_builtin = #58;
+string (float argnum) _argv_builtin = #59;
+float (string s, string sep) _tokenizebyseparator_builtin = #479;
+#else
+float (string s) _tokenize_builtin = #441;
+string (float argnum) _argv_builtin = #442;
+float (string s, string sep) _tokenizebyseparator_builtin = #479;
+#endif
+
+float MAX_TOKENS = 256;
+string _argv_sane_buffer[MAX_TOKENS];
+float _argv_sane_startpos[MAX_TOKENS];
+float _argv_sane_endpos[MAX_TOKENS];
+float _argc_sane;
+
+string _argv_sane(float i)
+{
+	// Perl-ish -1 for the last argument
+	if(i < 0)
+		i = _argc_sane + i;
+	return _argv_sane_buffer[i];
+}
+
+float _argv_start_index_sane(float i)
+{
+	// Perl-ish -1 for the last argument
+	if(i < 0)
+		i = _argc_sane + i;
+	return _argv_sane_startpos[i];
+}
+
+float _argv_end_index_sane(float i)
+{
+	// Perl-ish -1 for the last argument
+	if(i < 0)
+		i = _argc_sane + i;
+	return _argv_sane_endpos[i];
+}
+
+string TOKENIZE_SANE_WHITESPACE_CHARS = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
+string TOKENIZE_SANE_COMMENT_BREAKERS = "\x0d\x0a";
+// change this if DP changes its type to "char"!
+
+float _tokenize_sane(string s)
+{
+	// This MUST match COM_ParseToken_Console!
+	string com_token, tmp;
+	float data;
+	float end;
+	float i;
+	
+	_argc_sane = 0;
+	data = 0;
+	end = strlen(s);
+
+	for(i = 0; i < MAX_TOKENS; ++i)
+	{
+		if(_argv_sane_buffer[i])
+			strunzone(_argv_sane_buffer[i]);
+		_argv_sane_buffer[i] = string_null;
+		_argv_sane_startpos[i] = 0;
+	}
+
+	for(;;)
+	{
+		// skip whitespace
+		for(; data < end && strstrofs(TOKENIZE_SANE_WHITESPACE_CHARS, substring(s, data, 1), 0) >= 0; ++data)
+			;
+		if(data == end)
+			break;
+
+		if(substring(s, data, 2) == "//")
+		{
+			// comment
+
+			// Any call to the tokenizer ALREADY assumes it's a single line, so we can safely abort if we see a comment.
+			/*
+			data += 2;
+			while(data < end && strstrofs(TOKENIZE_SANE_COMMENT_BREAKERS, substring(s, data, 1), 0) >= 0)
+				++data;
+			continue; // go to skipwhite again
+			*/
+
+			// I'd like to simply put a "break" here, but then fteqcc says this function has unreachable code
+			return _argc_sane;
+		}
+		else if(substring(s, data, 1) == "\"")
+		{
+			// quoted string
+			com_token = "";
+			_argv_sane_startpos[_argc_sane] = data;
+			for(++data; data < end && substring(s, data, 1) != "\""; ++data)
+			{
+				// allow escaped " and \ case
+				tmp = substring(s, data, 2);
+				if(tmp == "\\\"" || tmp == "\\\\")
+					++data;
+				com_token = strcat(com_token, substring(s, data, 1));
+			}
+			if(substring(s, data, 1) == "\"")
+				++data;
+			_argv_sane_endpos[_argc_sane] = data;
+			_argv_sane_buffer[_argc_sane] = strzone(com_token);
+			++_argc_sane;
+		}
+		else
+		{
+			// regular word
+			com_token = "";
+			_argv_sane_startpos[_argc_sane] = data;
+			for(; data < end && strstrofs(TOKENIZE_SANE_WHITESPACE_CHARS, substring(s, data, 1), 0) < 0; ++data)
+				com_token = strcat(com_token, substring(s, data, 1));
+			_argv_sane_endpos[_argc_sane] = data;
+			_argv_sane_buffer[_argc_sane] = strzone(com_token);
+			++_argc_sane;
+		}
+	}
+
+	return _argc_sane;
+}
+
+
+
+var void(void) func_null;
+
+// "sane" tokenizer
+// matching the console 1:1
+
+float tokenize_sane(string s)
+{
+	argv = _argv_sane;
+	argv_start_index = _argv_start_index_sane;
+	argv_end_index = _argv_end_index_sane;
+	return _tokenize_sane(s);
+}
+
+float tokenize_insane(string s)
+{
+	argv = _argv_builtin;
+	argv_start_index = func_null;
+	argv_end_index = func_null;
+	return _tokenize_builtin(s);
+}
+
+float tokenizebyseparator(string s, string sep)
+{
+	argv = _argv_builtin;
+	argv_start_index = func_null;
+	argv_end_index = func_null;
+	return _tokenizebyseparator_builtin(s, sep);
+}

Modified: trunk/data/qcsrc/common/util.qh
===================================================================
--- trunk/data/qcsrc/common/util.qh	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/common/util.qh	2008-10-11 07:00:30 UTC (rev 4723)
@@ -105,3 +105,14 @@
 
 float almost_equals(float a, float b);
 float almost_in_bounds(float a, float b, float c);
+
+#undef tokenize
+#undef tokenizebyseparator
+#undef argv
+
+var string(float) argv;
+var float(float) argv_start_index;
+var float(float) argv_end_index;
+float tokenize_sane(string s);
+float tokenize_insane(string s);
+float tokenizebyseparator(string s, string sep);

Modified: trunk/data/qcsrc/menu/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/menu/gamecommand.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/gamecommand.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -34,7 +34,7 @@
 void GameCommand(string theCommand)
 {
 	float argc;
-	argc = tokenize(theCommand);
+	argc = tokenize_sane(theCommand);
 
 	if(argv(0) == "help" || argc == 0)
 	{

Modified: trunk/data/qcsrc/menu/menu.qc
===================================================================
--- trunk/data/qcsrc/menu/menu.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/menu.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -82,7 +82,7 @@
 	}
 	draw_currentSkin = strzone(draw_currentSkin);
 	while((s = fgets(fh)))
-		if(tokenize(s) == 2)
+		if(tokenize_insane(s) == 2) // uses '...' syntax for vectors
 			Skin_ApplySetting(argv(0), argv(1));
 	fclose(fh);
 

Modified: trunk/data/qcsrc/menu/nexuiz/dialog_singleplayer.c
===================================================================
--- trunk/data/qcsrc/menu/nexuiz/dialog_singleplayer.c	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/nexuiz/dialog_singleplayer.c	2008-10-11 07:00:30 UTC (rev 4723)
@@ -28,7 +28,7 @@
 	{
 		if(substring(s, 0, 4) == "set ")
 			s = substring(s, 4, strlen(s) - 4);
-		n = tokenize(s);
+		n = tokenize_sane(s);
 		if(argv(0) == "bot_number")
 			cvar_set("bot_number", argv(1));
 		else if(argv(0) == "skill")

Modified: trunk/data/qcsrc/menu/nexuiz/keybinder.c
===================================================================
--- trunk/data/qcsrc/menu/nexuiz/keybinder.c	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/nexuiz/keybinder.c	2008-10-11 07:00:30 UTC (rev 4723)
@@ -50,7 +50,7 @@
 		return;
 	while((s = fgets(fh)))
 	{
-		if(tokenize(s) != 2)
+		if(tokenize_sane(s) != 2)
 			continue;
 		Nexuiz_KeyBinds_Functions[Nexuiz_KeyBinds_Count] = strzone(argv(0));
 		Nexuiz_KeyBinds_Descriptions[Nexuiz_KeyBinds_Count] = strzone(argv(1));
@@ -116,7 +116,7 @@
 	if(func == "")
 		return;
 
-	n = tokenize(findkeysforcommand(func));
+	n = tokenize_insane(findkeysforcommand(func)); // uses '...' strings
 	nvalid = 0;
 	for(j = 0; j < n; ++j)
 	{
@@ -186,7 +186,7 @@
 	if(func == "")
 		return;
 
-	n = tokenize(findkeysforcommand(func));
+	n = tokenize_insane(findkeysforcommand(func)); // uses '...' strings
 	for(j = 0; j < n; ++j)
 	{
 		k = stof(argv(j));
@@ -300,7 +300,7 @@
 	draw_Text(me.realUpperMargin * eY + extraMargin * eX, descr, me.realFontSize, theColor, theAlpha, 0);
 	if(func != "")
 	{
-		n = tokenize(findkeysforcommand(func));
+		n = tokenize_insane(findkeysforcommand(func)); // uses '...' strings
 		s = "";
 		for(j = 0; j < n; ++j)
 		{

Modified: trunk/data/qcsrc/menu/nexuiz/maplist.c
===================================================================
--- trunk/data/qcsrc/menu/nexuiz/maplist.c	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/nexuiz/maplist.c	2008-10-11 07:00:30 UTC (rev 4723)
@@ -103,7 +103,7 @@
 	else
 	{
 		s = "";
-		n = tokenize(cvar_string("g_maplist"));
+		n = tokenize_sane(cvar_string("g_maplist"));
 		for(i = 0; i < n; ++i)
 			if(argv(i) != bspname)
 				s = strcat(s, " ", argv(i));
@@ -212,7 +212,7 @@
 	s = "0";
 	for(i = 1; i < MapInfo_count; i *= 2)
 		s = strcat(s, s);
-	n = tokenize(cvar_string("g_maplist"));
+	n = tokenize_sane(cvar_string("g_maplist"));
 	for(i = 0; i < n; ++i)
 	{
 		j = MapInfo_FindName(argv(i));

Modified: trunk/data/qcsrc/menu/nexuiz/slider_resolution.c
===================================================================
--- trunk/data/qcsrc/menu/nexuiz/slider_resolution.c	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/nexuiz/slider_resolution.c	2008-10-11 07:00:30 UTC (rev 4723)
@@ -47,7 +47,7 @@
 {
 	if(me.value >= 0 || me.value < me.nValues)
 	{
-		tokenize(me.getIdentifier(me));
+		tokenize_sane(me.getIdentifier(me));
 		cvar_set("vid_width", argv(0));
 		cvar_set("vid_height", argv(1));
 		cvar_set("vid_conwidth", argv(2));

Modified: trunk/data/qcsrc/menu/nexuiz/util.qc
===================================================================
--- trunk/data/qcsrc/menu/nexuiz/util.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/nexuiz/util.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -36,7 +36,7 @@
 	me.saveCvars_Multi(me);
 	s = cvar_string(me.cvarName);
 
-	n = tokenize(me.cvarNames_Multi);
+	n = tokenize_sane(me.cvarNames_Multi);
 	for(i = 0; i < n; ++i)
 		cvar_set(argv(i), s);
 }
@@ -193,7 +193,7 @@
 	local float argc;
 	while(strlen((s = getextresponse())))
 	{
-		argc = tokenize(s);
+		argc = tokenize_sane(s);
 		Item_Nex_ExtResponseSystem_Parse(argc);
 	}
 }

Modified: trunk/data/qcsrc/menu/nexuiz/weaponslist.c
===================================================================
--- trunk/data/qcsrc/menu/nexuiz/weaponslist.c	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/nexuiz/weaponslist.c	2008-10-11 07:00:30 UTC (rev 4723)
@@ -40,7 +40,7 @@
 		print("AUTOFIXED\n");
 		cvar_set("cl_weaponpriority", t);
 	}
-	me.nItems = tokenize(t);
+	me.nItems = tokenize_sane(t);
 	drawListBox(me);
 }
 void WeaponsList_MoveUp_Click(entity box, entity me)
@@ -99,7 +99,7 @@
 {
 	float n, i;
 	string s;
-	n = tokenize(cvar_string("cl_weaponpriority"));
+	n = tokenize_sane(cvar_string("cl_weaponpriority"));
 	s = "";
 	for(i = 0; i < n; ++i)
 		s = strcat(s, WeaponName(stof(argv(i))), ", ");

Modified: trunk/data/qcsrc/menu/progs.src
===================================================================
--- trunk/data/qcsrc/menu/progs.src	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/menu/progs.src	2008-10-11 07:00:30 UTC (rev 4723)
@@ -1,14 +1,15 @@
 ../../menu.dat
 
 config.qh
+../common/util-pre.qh
 msys.qh
 mbuiltin.qh
+../common/util.qh
 
 oo/base.h
 
 ../common/constants.qh
 ../common/mapinfo.qh
-../common/util.qh
 ../common/campaign_common.qh
 
 gamecommand.qh

Modified: trunk/data/qcsrc/server/campaign.qc
===================================================================
--- trunk/data/qcsrc/server/campaign.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/campaign.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -76,7 +76,7 @@
 	{
 		while((l = fgets(fh)))
 		{
-			len = tokenize(l);
+			len = tokenize_sane(l);
 			if(len != 3)
 				continue;
 			if(argv(0) != "set")

Modified: trunk/data/qcsrc/server/cl_player.qc
===================================================================
--- trunk/data/qcsrc/server/cl_player.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/cl_player.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -74,7 +74,7 @@
 	if (animfile < 0)
 		return '0 1 2';
 	line = fgets(animfile);
-	c = tokenize(line);
+	c = tokenize_sane(line);
 	if (c != 3)
 	{
 		animparseerror = TRUE;
@@ -802,7 +802,7 @@
 void PrecacheGlobalSound(string samplestring)
 {
 	float n, i;
-	tokenize(samplestring);
+	tokenize_sane(samplestring);
 	n = stof(argv(1));
 	if(n > 0)
 	{
@@ -824,7 +824,7 @@
 		return;
 	while((s = fgets(fh)))
 	{
-		if(tokenize(s) != 3)
+		if(tokenize_sane(s) != 3)
 		{
 			dprint("Invalid sound info line: ", s, "\n");
 			continue;
@@ -868,7 +868,7 @@
 		return;
 	while((s = fgets(fh)))
 	{
-		if(tokenize(s) != 3)
+		if(tokenize_sane(s) != 3)
 			continue;
 		field = GetPlayerSoundSampleField(argv(0));
 		if(GetPlayerSoundSampleField_notFound)
@@ -903,7 +903,7 @@
 	if(sample == "")
 		return;
 
-	tokenize(sample);
+	tokenize_sane(sample);
 	n = stof(argv(1));
 	if(n > 0)
 		sample = strcat(argv(0), ftos(ceil(random() * n)), ".wav"); // randomization

Modified: trunk/data/qcsrc/server/cl_weapons.qc
===================================================================
--- trunk/data/qcsrc/server/cl_weapons.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/cl_weapons.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -9,7 +9,7 @@
 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain)
 {
 	float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
-	n = tokenize(weaponorder);
+	n = tokenize_sane(weaponorder);
 	switchtonext = switchtolast = 0;
 	first_valid = prev_valid = 0;
 

Modified: trunk/data/qcsrc/server/clientcommands.qc
===================================================================
--- trunk/data/qcsrc/server/clientcommands.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/clientcommands.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -225,7 +225,7 @@
 	local string cmd;
 	local float i;
 
-	tokenize(s);
+	tokenize_sane(s);
 
 	if(GameCommand_Vote(s, self)) {
 		return;
@@ -342,7 +342,7 @@
 	} else if(argv(0) == "maplist") {
 		local float n, j;
 		local string col;
-		n = tokenize(cvar_string("g_maplist"));
+		n = tokenize_sane(cvar_string("g_maplist"));
 		sprint(self, "^7Maps in list: ");
 		for(i = 0, j = 0; i < n; ++i)
 		{
@@ -371,10 +371,10 @@
 	} else if(argv(0) == "voice") {
 		VoiceMessage(argv(1));
 	} else if(argv(0) == "say") {
-		Say(self, FALSE, substring(s, 4, strlen(s) - 4));
+		Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
 		//clientcommand(self, formatmessage(s));
 	} else if(argv(0) == "say_team") {
-		Say(self, TRUE, substring(s, 9, strlen(s) - 9));
+		Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
 		//clientcommand(self, formatmessage(s));
 	} else if(argv(0) == "info") {
 		cmd = cvar_string(strcat("sv_info_", argv(1)));

Modified: trunk/data/qcsrc/server/defs.qh
===================================================================
--- trunk/data/qcsrc/server/defs.qh	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/defs.qh	2008-10-11 07:00:30 UTC (rev 4723)
@@ -245,7 +245,6 @@
 .float vote_next;
 .float vote_vote;
 void VoteThink();
-string VoteParse();
 float VoteAllowed(string vote);
 void VoteReset();
 void VoteAccept();

Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/g_world.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -168,7 +168,7 @@
 		return;
 	while((s = fgets(fh)))
 	{
-		n = tokenize(s);
+		n = tokenize_sane(s);
 		if(n < 1)
 			continue;
 		if(argv(0) == "//")
@@ -363,7 +363,7 @@
 		{
 			while((s = fgets(fd)))
 			{
-				l = tokenize(s);
+				l = tokenize_sane(s);
 				if(l < 2)
 					continue;
 				if(argv(0) == "cd")

Modified: trunk/data/qcsrc/server/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/server/gamecommand.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/gamecommand.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -420,7 +420,7 @@
 	fh = fopen("effectinfo.txt", FILE_READ);
 	while((s = fgets(fh)))
 	{
-		tokenize(s);
+		tokenize_sane(s);
 		if(argv(0) == "effect")
 		{
 			if(db_get(d, argv(1)) != "1")
@@ -456,7 +456,7 @@
 	float argc;
 	entity client;
 	float entno;
-	argc = tokenize(command);
+	argc = tokenize_sane(command);
 
 	if(argv(0) == "help" || argc == 0)
 	{

Modified: trunk/data/qcsrc/server/ipban.qc
===================================================================
--- trunk/data/qcsrc/server/ipban.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/ipban.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -55,7 +55,7 @@
 		Ban_Delete(i);
 	ban_count = 0;
 	ban_loaded = TRUE;
-	n = tokenize(cvar_string("g_banned_list"));
+	n = tokenize_sane(cvar_string("g_banned_list"));
 	if(stof(argv(0)) == 1)
 	{
 		ban_count = (n - 1) / 2;
@@ -207,7 +207,7 @@
 	float entno;
 	float masksize;
 
-	argc = tokenize(command);
+	argc = tokenize_sane(command);
 	if(argv(0) == "help")
 	{
 		print("  kickban # n m p - kickban player n for m seconds, using mask size p (1 to 4)\n");

Modified: trunk/data/qcsrc/server/progs.src
===================================================================
--- trunk/data/qcsrc/server/progs.src	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/progs.src	2008-10-11 07:00:30 UTC (rev 4723)
@@ -1,12 +1,13 @@
 ../../progs.dat // output filename
 
+../common/util-pre.qh
 sys.qh
 builtins.qh
 constants.qh
 ../common/constants.qh
 defs.qh		// Should rename this, it has fields and globals
-
 extensions.qh
+../common/util.qh
 
 //// tZork Turrets ////
 tturrets/include/turret_tturrets_early.qh
@@ -14,7 +15,6 @@
 campaign.qh
 ../common/campaign_common.qh
 ../common/mapinfo.qh
-../common/util.qh
 ../common/util.qc
 
 portals.qh

Modified: trunk/data/qcsrc/server/t_items.qc
===================================================================
--- trunk/data/qcsrc/server/t_items.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/t_items.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -613,7 +613,7 @@
 	if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
 	{
 		s = cvar_string(strcat("g_weaponreplace_", ftos(wpn)));
-		t = tokenize(s);
+		t = tokenize_sane(s);
 		if(t >= 2)
 		{
 			self.team = --internalteam;
@@ -1128,7 +1128,7 @@
 	precache_sound("misc/powerup.wav");
 	precache_sound("weapons/weaponpickup.wav");
 
-	n = tokenize(self.netname);
+	n = tokenize_sane(self.netname);
 	for(i = 0; i < n; ++i)
 	{
 		if(argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;

Modified: trunk/data/qcsrc/server/vote.qc
===================================================================
--- trunk/data/qcsrc/server/vote.qc	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/vote.qc	2008-10-11 07:00:30 UTC (rev 4723)
@@ -14,11 +14,11 @@
 entity GetKickVoteVictim(string vote, string cmd, entity caller)
 {
 	float tokens;
-	float i, n, t;
+	float n, t;
 	string ns;
 	entity e;
 
-	tokens = tokenize(vote);
+	tokens = tokenize_sane(vote);
 	ns = "";
 
 	if(tokens >= 2)
@@ -37,10 +37,7 @@
 
 	if(ns != "")
 	{
-		GetKickVoteVictim_reason = "";
-		for(i = t; i < tokens; ++i)
-			GetKickVoteVictim_reason = strcat(GetKickVoteVictim_reason, argv(i), " ");
-		GetKickVoteVictim_reason = substring(GetKickVoteVictim_reason, 0, strlen(GetKickVoteVictim_reason) - 1);
+		GetKickVoteVictim_reason = substring(vote, argv_start_index(t), argv_end_index(-1) - argv_start_index(t));
 
 		n = stof(ns);
 		if(ns == ftos(n)) if(n >= 1) if(n <= maxclients)
@@ -58,8 +55,57 @@
 	return world;
 }
 
+string RemapVote_display;
+string RemapVote_vote;
+float RemapVote(string vote, string cmd, entity e)
+{
+	float vote_argc;
+	entity victim;
+	vote_argc = tokenize_sane(vote);
+
+	print(">>", vote, "<<\n");
+
+	if(!VoteAllowed(argv(0)))
+	{
+		return FALSE;
+	}
+
+	// VoteAllowed tokenizes!
+	vote_argc = tokenize_sane(vote);
+
+	// remap chmap to gotomap (forces intermission)
+	if(vote_argc < 2)
+		if(argv(0) == "chmap" || argv(0) == "gotomap" || argv(0) == "kick" || argv(0) == "kickban") // won't work without arguments
+			return FALSE;
+	if(argv(0) == "chmap")
+		vote = strcat("gotomap ", substring(vote, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
+	if(argv(0) == "gotomap")
+	{
+		if(!(vote = ValidateMap(substring(vote, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), e)))
+			return FALSE;
+		vote = strcat("gotomap ", vote);
+		vote_argc = tokenize_sane(vote); // ValidateMap may have done some stuff to it
+	}
+
+	// make kick and kickban votes a bit nicer (and reject them if formatted badly)
+	if(argv(0) == "kick" || argv(0) == "kickban")
+	{
+		if(!(victim = GetKickVoteVictim(vote, cmd, e)))
+			return FALSE;
+		RemapVote_vote = GetKickVoteVictim_newcommand;
+		RemapVote_display = strcat("^1", vote, " (^7", victim.netname, "^1): ", GetKickVoteVictim_reason);
+	}
+	else
+	{
+		RemapVote_vote = vote;
+		RemapVote_display = strzone(strcat("^1", vote));
+	}
+
+	return TRUE;
+}
+
 float GameCommand_Vote(string s, entity e) {
-	local entity victim;
+	tokenize_sane(s);
 	if(argv(0) == "help") {
 		print_to(e, "  vote COMMANDS ARGUMENTS. See 'vote help' for more info.");
 		return TRUE;
@@ -86,7 +132,7 @@
 					print_to(e, "^1There is already a vote called.");
 				} else {
 					local string vote;
-					vote = VoteParse();
+					vote = VoteParse(s);
 					if(vote == "") {
 						print_to(e, "^1Your vote is empty. See help for more info.");
 					} else if(e
@@ -94,37 +140,9 @@
 							print_to(e, strcat("^1You have to wait ^2", ftos(e.vote_next - time), "^1 seconds before you can again call a vote."));
 					} else if(VoteCheckNasty(vote)) {
 						print_to(e, "Syntax error in command. See help for more info.");
-					} else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
-						// remap chmap to gotomap (forces intermission)
-						if(vote == "chmap" || vote == "gotomap") // won't work without arguments
-							return TRUE;
-						if(substring(vote, 0, 6) == "chmap ")
-							vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
-						if(substring(vote, 0, 8) == "gotomap ")
-						{
-							if(!(vote = ValidateMap(substring(vote, 8, strlen(vote) - 8), e)))
-								return TRUE;
-							vote = strcat("gotomap ", vote);
-						}
-
-						// make kick and kickban votes a bit nicer (and reject them if formatted badly)
-						if(substring(vote, 0, 5) == "kick " || substring(vote, 0, 8) == "kickban ")
-						{
-							if(!(victim = GetKickVoteVictim(vote, "vcall", e)))
-								return TRUE;
-							vote = GetKickVoteVictim_newcommand;
-							votecalledvote_display = strzone(strcat("^1", vote, " (^7", victim.netname, "^1): ", GetKickVoteVictim_reason));
-						}
-						else if(vote == "kick" || vote == "kickban")
-						{
-							print_to(e, strcat("Usage: ", vote, " #playernumber (as in \"status\")\n"));
-							return TRUE;
-						}
-						else
-						{
-							votecalledvote_display = strzone(strcat("^1", vote));
-						}
-						votecalledvote = strzone(vote);
+					} else if(RemapVote(vote, "vcall", e)) {
+						votecalledvote = strzone(RemapVote_vote);
+						votecalledvote_display = strzone(RemapVote_display);
 						votecalled = TRUE;
 						votecalledmaster = FALSE;
 						votefinished = time + cvar("sv_vote_timeout");
@@ -183,41 +201,17 @@
 			}
 		} else if(argv(1) == "do") {
 			if(!e || e.vote_master) {
-				local string dovote, dovote_display;
-				dovote = VoteParse();
+				local string dovote;
+				dovote = VoteParse(s);
 				if(dovote == "") {
 					print_to(e, "^1Your command was empty. See help for more info.");
 				} else if(VoteCheckNasty(dovote)) {
 					print_to(e, "Syntax error in command. See help for more info.");
-				} else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
-					if(dovote == "chmap" || dovote == "gotomap") // won't work without arguments
-						return TRUE;
-					if(substring(dovote, 0, 6) == "chmap ")
-						dovote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
-					if(substring(dovote, 0, 8) == "gotomap ")
-					{
-						if(!(dovote = ValidateMap(substring(dovote, 8, strlen(dovote) - 8), e)))
-							return TRUE;
-						dovote = strcat("gotomap ", dovote);
-					}
-
-					dovote_display = dovote;
-					if(substring(dovote, 0, 5) == "kick " || substring(dovote, 0, 8) == "kickban ")
-					{
-						if(!(victim = GetKickVoteVictim(dovote, "vdo", e)))
-							return TRUE;
-						dovote = GetKickVoteVictim_newcommand;
-						dovote_display = strcat("^1", dovote, " (^7", victim.netname, "^1): ", GetKickVoteVictim_reason);
-					}
-					else if(dovote == "kick" || dovote == "kickban")
-					{
-						print_to(e, strcat("Usage: ", dovote, " #playernumber (as in \"status\")\n"));
-						return TRUE;
-					}
-					bprint("\{1}^2* ^3", VoteNetname(e), "^2 used his ^3master^2 status to do \"^2", dovote_display, "^2\".\n");
+				} else if(RemapVote(dovote, "vdo", e)) { // strcat seems to be necessary
+					bprint("\{1}^2* ^3", VoteNetname(e), "^2 used his ^3master^2 status to do \"^2", RemapVote_display, "^2\".\n");
 					if(cvar("sv_eventlog"))
-						GameLogEcho(strcat(":vote:vdo:", ftos(e.playerid), ":", dovote_display));
-					localcmd(strcat(dovote, "\n"));
+						GameLogEcho(strcat(":vote:vdo:", ftos(e.playerid), ":", RemapVote_display));
+					localcmd(strcat(RemapVote_vote, "\n"));
 				} else {
 					print_to(e, "^1This command is not ok. See help for more info.");
 				}
@@ -378,21 +372,12 @@
 	}
 }
 
-string VoteParse() {
-	local float index;
-	index = 3;
-	local string vote;
-	vote = argv(2);
-	while(argv(index) != "") {
-		vote = strcat(vote, " ", argv(index));
-		++index;
-	}
-
-	return vote;
+string VoteParse(string all) {
+	return substring(all, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
 }
 
 float VoteAllowed(string votecommand) {
-	tokenize(cvar_string("sv_vote_commands"));
+	tokenize_sane(cvar_string("sv_vote_commands"));
 	local float index;
 	index = 0;
 	while(argv(index) != "") {

Modified: trunk/data/qcsrc/server/vote.qh
===================================================================
--- trunk/data/qcsrc/server/vote.qh	2008-10-11 05:18:44 UTC (rev 4722)
+++ trunk/data/qcsrc/server/vote.qh	2008-10-11 07:00:30 UTC (rev 4723)
@@ -8,7 +8,7 @@
 string VoteNetname(entity e);
 string ValidateMap(string m, entity e);
 void VoteThink();
-string VoteParse();
+string VoteParse(string s);
 float VoteAllowed(string votecommand);
 void VoteReset();
 void VoteAccept();




More information about the nexuiz-commits mailing list