Переглянути джерело

- Added a missing break in battle_check_target
- Added config setting "partial_name_scan", which specifies whether @ given names should use a partial string lookup or absolute name lookup. Defaults to no (gm.conf)


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@8578 54d463be-8e91-2dee-dedb-b68131a5f0ec

skotlex 18 роки тому
батько
коміт
9976069fdc
5 змінених файлів з 38 додано та 9 видалено
  1. 3 0
      Changelog-Trunk.txt
  2. 5 0
      conf-tmpl/battle/gm.conf
  3. 3 0
      src/map/battle.c
  4. 1 0
      src/map/battle.h
  5. 26 9
      src/map/map.c

+ 3 - 0
Changelog-Trunk.txt

@@ -4,6 +4,9 @@ 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.
 
 2006/09/01
+	* Added config setting "partial_name_scan", which specifies whether @ given
+	  names should use a partial string lookup or absolute name lookup. Defaults
+	  to no (gm.conf) [Skotlex]
 	* Expanded status_calc_misc so it may also calculate the batk of characters
 	  as well as their regen data (if they have it) [Skotlex]
 	* Fixed a memory leak when using charsave_method:1 [Skotlex]

+ 5 - 0
conf-tmpl/battle/gm.conf

@@ -33,6 +33,11 @@ atcommand_spawn_quantity_limit: 100
 // Maximum number of slave-clones that can be have by using the @slaveclone at command. (0 denotes unlimited quantity)
 atcommand_slave_clone_limit: 25
 
+// If 'no', commands require exact player name. If 'yes', entering a partial 
+// name will work, as long as there's only one match from all players in the 
+// current map server.
+partial_name_scan: yes
+
 // [GM] Can use all skills? (No or mimimum GM level)
 gm_all_skill: no
 

+ 3 - 0
src/map/battle.c

@@ -3193,6 +3193,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
 			} else	//Excepting traps and icewall, you should not be able to target skills.
 				return 0;
 		}
+			break;
 		//Valid targets with no special checks here.
 		case BL_HOM:
 			break;
@@ -3479,6 +3480,7 @@ static const struct battle_data_short {
 	{ "atcommand_gm_only",                 &battle_config.atc_gmonly				},
 	{ "atcommand_spawn_quantity_limit",    &battle_config.atc_spawn_quantity_limit	},
 	{ "atcommand_slave_clone_limit",       &battle_config.atc_slave_clone_limit},
+	{ "partial_name_scan",                 &battle_config.partial_name_scan	},
 	{ "gm_all_skill",                      &battle_config.gm_allskill				},
 	{ "gm_all_skill_add_abra",	            &battle_config.gm_allskill_addabra		},
 	{ "gm_all_equipment",                  &battle_config.gm_allequip				},
@@ -3884,6 +3886,7 @@ void battle_set_defaults() {
 	battle_config.atc_gmonly=0;
 	battle_config.atc_spawn_quantity_limit=0;
 	battle_config.atc_slave_clone_limit=0;
+	battle_config.partial_name_scan=0;
 	battle_config.gm_allskill=0;
 	battle_config.gm_allequip=0;
 	battle_config.gm_skilluncond=0;

+ 1 - 0
src/map/battle.h

@@ -134,6 +134,7 @@ extern struct Battle_Config {
 	unsigned short atc_gmonly;
 	unsigned short atc_spawn_quantity_limit;
 	unsigned short atc_slave_clone_limit;
+	unsigned short partial_name_scan;
 	unsigned short gm_allskill;
 	unsigned short gm_allskill_addabra;
 	unsigned short gm_allequip;

+ 26 - 9
src/map/map.c

@@ -1787,15 +1787,32 @@ struct map_session_data * map_nick2sd(char *nick) {
 	if (nick == NULL)
 		return NULL;
 
-	 pl_allsd = map_getallusers(&users);
-	 
-	for (i = 0; i < users; i++) {
-		pl_sd = pl_allsd[i];
-		// Without case sensitive check (increase the number of similar character names found)
-		if (strcasecmp(pl_sd->status.name, nick) == 0)
-			return pl_sd;
-	}
-	// Exact character name is not found and 0 or more than 1 similar characters have been found ==> we say not found
+	pl_allsd = map_getallusers(&users);
+	if (battle_config.partial_name_scan)
+	{
+		int qty = 0, nicklen = strlen(nick);
+		struct map_session_data *sd = NULL;
+		for (i = 0; i < users; i++) {
+			pl_sd = pl_allsd[i];
+			// Without case sensitive check (increase the number of similar character names found)
+			if (strnicmp(pl_sd->status.name, nick, nicklen) == 0) {
+				// Strict comparison (if found, we finish the function immediatly with correct value)
+				if (strcmp(pl_sd->status.name, nick) == 0)
+					return pl_sd;
+				qty++;
+				sd = pl_sd;
+			}
+		}
+		// We return the found index of a similar account ONLY if there is 1 similar character
+		if (qty == 1)
+			return sd;
+	} else { //Exact Search
+		for (i = 0; i < users; i++) {
+			if (strcasecmp(pl_allsd[i]->status.name, nick) == 0)
+				return pl_allsd[i];
+		}
+	}
+	//Not found.
 	return NULL;
 }