summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-07-23 17:58:54 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-07-23 17:58:54 +0000
commit6619e19b58fff810cdebc8e00c83a1b5c261214d (patch)
treeab99022cb2d793dd412e4d239bb9aa2a9a334f51 /src/common
parent212c7b263c822dc1850823a88228d331e6092afc (diff)
downloadhercules-6619e19b58fff810cdebc8e00c83a1b5c261214d.tar.gz
hercules-6619e19b58fff810cdebc8e00c83a1b5c261214d.tar.bz2
hercules-6619e19b58fff810cdebc8e00c83a1b5c261214d.tar.xz
hercules-6619e19b58fff810cdebc8e00c83a1b5c261214d.zip
* Changed the restricting mapflag for @jump from nowarp/nowarpto to noteleport
* Simplified the mapindex code a bit * Changed clif_skill_warppoint() so that now the '.gat' adding happens inside and doesn't have to be handled by the calling code git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10901 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r--src/common/mapindex.c42
-rw-r--r--src/common/mapindex.h1
2 files changed, 20 insertions, 23 deletions
diff --git a/src/common/mapindex.c b/src/common/mapindex.c
index 866bb2d1c..73350e016 100644
--- a/src/common/mapindex.c
+++ b/src/common/mapindex.c
@@ -1,14 +1,15 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "mapindex.h"
#include "../common/mmo.h"
#include "../common/showmsg.h"
#include "../common/malloc.h"
+#include "../common/strlib.h"
+#include "mapindex.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
#define MAX_MAPINDEX 2000
@@ -22,22 +23,17 @@ static unsigned short max_index = 0;
char mapindex_cfgfile[80] = "db/map_index.txt";
// Removes the extension from a map name
-char *mapindex_normalize_name(char *mapname)
+char* mapindex_normalize_name(char* mapname)
{
- char *ptr, *ptr2;
- ptr = strchr(mapname, '.');
- if (ptr) { //Check and remove extension.
- while (ptr[1] && (ptr2 = strchr(ptr+1, '.')))
- ptr = ptr2; //Skip to the last dot.
- if(stricmp(ptr,".gat") == 0)
- *ptr = '\0'; //Remove extension.
- }
+ char* ptr = strrchr(mapname, '.');
+ if (ptr && stricmp(ptr, ".gat") == 0)
+ *ptr = '\0'; // remove extension
return mapname;
}
/// Adds a map to the specified index
/// Returns 1 if successful, 0 oherwise
-int mapindex_addmap(int index, const char *name)
+int mapindex_addmap(int index, const char* name)
{
char map_name[MAP_NAME_LENGTH_EXT];
@@ -46,10 +42,10 @@ int mapindex_addmap(int index, const char *name)
return 0;
}
- snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s", name);
+ safestrncpy(map_name, name, MAP_NAME_LENGTH_EXT);
mapindex_normalize_name(map_name);
- if (strlen(map_name) > MAP_NAME_LENGTH-1) {
+ if (strlen(map_name) >= MAP_NAME_LENGTH) {
ShowError("(mapindex_add) Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH);
return 0;
}
@@ -57,10 +53,11 @@ int mapindex_addmap(int index, const char *name)
if (indexes[index].exists)
ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name);
- snprintf(indexes[index].name, MAP_NAME_LENGTH, "%s", map_name);
+ safestrncpy(indexes[index].name, map_name, MAP_NAME_LENGTH);
indexes[index].exists = true;
if (max_index <= index)
max_index = index+1;
+
return 1;
}
@@ -68,9 +65,9 @@ unsigned short mapindex_name2id(const char* name)
{
//TODO: Perhaps use a db to speed this up? [Skotlex]
int i;
- char map_name[MAP_NAME_LENGTH_EXT];
- snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s", name);
+ char map_name[MAP_NAME_LENGTH_EXT];
+ safestrncpy(map_name, name, MAP_NAME_LENGTH_EXT);
mapindex_normalize_name(map_name);
for (i = 1; i < max_index; i++)
@@ -96,7 +93,7 @@ const char* mapindex_id2name(unsigned short id)
{
if (id > MAX_MAPINDEX || !indexes[id].exists) {
ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache.\n", id);
- return indexes[0].name; //Theorically this should never happen, hence we return this string to prevent null pointer crashes.
+ return indexes[0].name; // dummy empty string so that the callee doesn't crash
}
return indexes[id].name;
}
@@ -120,7 +117,8 @@ void mapindex_init(void)
if(line[0] == '/' && line[1] == '/')
continue;
- switch (sscanf(line,"%s\t%d",map_name,&index)) {
+ switch (sscanf(line, "%s\t%d", map_name, &index))
+ {
case 1: //Map with no ID given, auto-assign
index = last_index+1;
case 2: //Map with ID given
diff --git a/src/common/mapindex.h b/src/common/mapindex.h
index 0ec192258..f49ee923b 100644
--- a/src/common/mapindex.h
+++ b/src/common/mapindex.h
@@ -8,7 +8,6 @@
extern char mapindex_cfgfile[80];
//whether to enable auto-adding of maps during run. Not so secure as the map indexes will vary!
-// disabled - since mapindex.h wasn't included in mapindex.c it never got enabled anyway... [FlavioJS]
//#define MAPINDEX_AUTOADD
//Some definitions for the mayor city maps.