Преглед на файлове

* Restricted more the parsing of npc code. (fixes bugreport:317)

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11603 54d463be-8e91-2dee-dedb-b68131a5f0ec
FlavioJS преди 17 години
родител
ревизия
d51639d405
променени са 2 файла, в които са добавени 25 реда и са изтрити 7 реда
  1. 1 0
      Changelog-Trunk.txt
  2. 24 7
      src/map/npc.c

+ 1 - 0
Changelog-Trunk.txt

@@ -4,6 +4,7 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2007/10/28
+	* Restricted more the parsing of npc code. (fixes bugreport:317) [FlavioJS]
 	* Fixed a bug sending on the attachment message [Zephyrus]
 2007/10/27
 	* Fixed a typo in r11505 messing up the 'npcmove' command

+ 24 - 7
src/map/npc.c

@@ -1736,6 +1736,11 @@ static const char* npc_skip_script(const char* start, const char* buffer, const
 	return p+1;// return after the last '}'
 }
 
+/// Parses a npc script.
+///
+/// -%TAB%script%TAB%<NPC Name>%TAB%-1,{<code>}
+/// <map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,{<code>}
+/// <map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,<triggerX>,<triggerY>,{<code>}
 static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
 {
 	int x, y, dir = 0, m, xs = 0, ys = 0, class_ = 0;	// [Valaris] thanks to fov
@@ -1758,10 +1763,9 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 	}
 	else
 	{// npc in a map
-		if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4
-		||	(strcasecmp(w2, "script") == 0 && strchr(w4,',') == NULL) )
+		if( sscanf(w1, "%31[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 )
 		{
-			ShowError("npc_parse_script: Unkown format for a script in file '%s', line '%d'. Skipping the rest of file...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
+			ShowError("npc_parse_script: Invalid placement format for a script in file '%s', line '%d'. Skipping the rest of file...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
 			return NULL;// unknown format, don't continue
 		}
 		m = map_mapname2mapid(mapname);
@@ -1769,14 +1773,20 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 
 	if( strcmp(w2, "script") == 0 )
 	{// parsing script with curly
-		const char* real_start;
+		const char* script_start;
+
+		if( strstr(w4,",{") == NULL )
+		{
+			ShowError("npc_parse_script: Missing left curly ',{' in file '%s', line '%d'. Skipping the rest of the file.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
+			return NULL;// can't continue
+		}
+		script_start = strstr(start,",{")+1;
 
-		end = npc_skip_script(start, buffer, filepath);
+		end = npc_skip_script(script_start, buffer, filepath);
 		if( end == NULL )
 			return NULL;// (simple) parse error, don't continue
 
-		real_start = strchr(start,'{');
-		script = parse_script(real_start, filepath, strline(buffer,real_start-buffer), SCRIPT_USE_LABEL_DB);
+		script = parse_script(script_start, filepath, strline(buffer,script_start-buffer), SCRIPT_USE_LABEL_DB);
 		label_list = NULL;
 		label_list_num = 0;
 		src_id = 0;
@@ -2015,6 +2025,13 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co
 	struct script_code *oldscript;
 	const char* end;
 
+	start = strstr(start,"\t{");
+	if( *w4 != '{' || start == NULL )
+	{
+		ShowError("npc_parse_function: Missing left curly '%%TAB%%{' in file '%s', line '%d'. Skipping the rest of the file.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
+		return NULL;// can't continue
+	}
+
 	end = npc_skip_script(start,buffer,filepath);
 	if( end == NULL )
 		return NULL;// (simple) parse error, don't continue