Added map names check for entrance and maplist
Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
This commit is contained in:
parent
fb01b02283
commit
0e5997e9ef
@ -26,16 +26,17 @@ int instance_start = 0; // To keep the last index + 1 of normal map inserted in
|
|||||||
|
|
||||||
struct instance_data instance_data[MAX_INSTANCE_DATA];
|
struct instance_data instance_data[MAX_INSTANCE_DATA];
|
||||||
|
|
||||||
|
/// Instance DB entry struct
|
||||||
struct instance_db {
|
struct instance_db {
|
||||||
unsigned short id;
|
unsigned short id; ///< Instance ID
|
||||||
StringBuf *name;
|
StringBuf *name; ///< Instance name
|
||||||
unsigned int limit;
|
unsigned int limit; ///< Duration limit
|
||||||
struct {
|
struct {
|
||||||
StringBuf *mapname; ///< Mapname, the limit should be MAP_NAME_LENGTH_EXT
|
StringBuf *mapname; ///< Mapname, the limit should be MAP_NAME_LENGTH_EXT
|
||||||
unsigned short x, y; ///< Map coordinates
|
unsigned short x, y; ///< Map coordinates
|
||||||
} enter;
|
} enter;
|
||||||
StringBuf **maplist; ///< Used maps, the limit should be MAP_NAME_LENGTH_EXT
|
StringBuf **maplist; ///< Used maps in instance, the limit should be MAP_NAME_LENGTH_EXT
|
||||||
uint8 maplist_count;
|
uint8 maplist_count; ///< Number of used maps
|
||||||
};
|
};
|
||||||
|
|
||||||
static DBMap *InstanceDB; /// Instance DB: struct instance_db, key: id
|
static DBMap *InstanceDB; /// Instance DB: struct instance_db, key: id
|
||||||
@ -615,6 +616,8 @@ int instance_delusers(short instance_id)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool instance_db_free_sub(struct instance_db *db);
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Read the instance_db.txt file
|
* Read the instance_db.txt file
|
||||||
*------------------------------------------*/
|
*------------------------------------------*/
|
||||||
@ -623,13 +626,18 @@ static bool instance_readdb_sub(char* str[], int columns, int current)
|
|||||||
uint8 i;
|
uint8 i;
|
||||||
int id = atoi(str[0]);
|
int id = atoi(str[0]);
|
||||||
struct instance_db *db;
|
struct instance_db *db;
|
||||||
bool isNew = false;
|
bool isNew = false, defined = false;
|
||||||
|
|
||||||
if (!id || id > USHRT_MAX) {
|
if (!id || id > USHRT_MAX) {
|
||||||
ShowError("instance_readdb_sub: Cannot add instance with ID '%d'. Valid ID is 1 ~ %d.\n", id, USHRT_MAX);
|
ShowError("instance_readdb_sub: Cannot add instance with ID '%d'. Valid ID is 1 ~ %d.\n", id, USHRT_MAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mapindex_name2id(str[3]) == 0) {
|
||||||
|
ShowError("instance_readdb_sub: Invalid map '%s' as entrance map.\n", str[3]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(db = (struct instance_db *)uidb_get(InstanceDB, id))) {
|
if (!(db = (struct instance_db *)uidb_get(InstanceDB, id))) {
|
||||||
CREATE(db, struct instance_db, 1);
|
CREATE(db, struct instance_db, 1);
|
||||||
db->id = id;
|
db->id = id;
|
||||||
@ -657,13 +665,27 @@ static bool instance_readdb_sub(char* str[], int columns, int current)
|
|||||||
//Instance maps
|
//Instance maps
|
||||||
for (i = 6; i < columns; i++) {
|
for (i = 6; i < columns; i++) {
|
||||||
if (strlen(str[i])) {
|
if (strlen(str[i])) {
|
||||||
|
if (mapindex_name2id(str[i]) == 0) {
|
||||||
|
ShowWarning("instance_readdb_sub: Invalid map '%s' in maplist, skipping...\n", str[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
RECREATE(db->maplist, StringBuf *, db->maplist_count+1);
|
RECREATE(db->maplist, StringBuf *, db->maplist_count+1);
|
||||||
db->maplist[db->maplist_count] = StringBuf_Malloc();
|
db->maplist[db->maplist_count] = StringBuf_Malloc();
|
||||||
|
if (strcmpi(str[i], str[3]) == 0)
|
||||||
|
defined = true;
|
||||||
StringBuf_AppendStr(db->maplist[db->maplist_count], str[i]);
|
StringBuf_AppendStr(db->maplist[db->maplist_count], str[i]);
|
||||||
db->maplist_count++;
|
db->maplist_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!defined) {
|
||||||
|
ShowError("instance_readdb_sub: The entrance map is not defined in instance map list.\n");
|
||||||
|
instance_db_free_sub(db);
|
||||||
|
if (!isNew)
|
||||||
|
uidb_remove(InstanceDB,id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
uidb_put(InstanceDB, id, db);
|
uidb_put(InstanceDB, id, db);
|
||||||
strdb_uiput(InstanceNameDB, StringBuf_Value(db->name), id);
|
strdb_uiput(InstanceNameDB, StringBuf_Value(db->name), id);
|
||||||
@ -671,9 +693,11 @@ static bool instance_readdb_sub(char* str[], int columns, int current)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int instance_db_free(DBKey key, DBData *data, va_list ap) {
|
/**
|
||||||
struct instance_db *db = (struct instance_db *)db_data2ptr(data);
|
* Free InstanceDB single entry
|
||||||
bool clear = va_arg(ap, bool);
|
* @param db Instance Db entry
|
||||||
|
**/
|
||||||
|
static bool instance_db_free_sub(struct instance_db *db) {
|
||||||
if (!db)
|
if (!db)
|
||||||
return 1;
|
return 1;
|
||||||
StringBuf_Free(db->name);
|
StringBuf_Free(db->name);
|
||||||
@ -688,6 +712,17 @@ static int instance_db_free(DBKey key, DBData *data, va_list ap) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free InstanceDB entries
|
||||||
|
**/
|
||||||
|
static int instance_db_free(DBKey key, DBData *data, va_list ap) {
|
||||||
|
struct instance_db *db = (struct instance_db *)db_data2ptr(data);
|
||||||
|
return instance_db_free_sub(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read instance_db.txt files
|
||||||
|
**/
|
||||||
void instance_readdb(void) {
|
void instance_readdb(void) {
|
||||||
const char* filename[] = { DBPATH"instance_db.txt", "import/instance_db.txt"};
|
const char* filename[] = { DBPATH"instance_db.txt", "import/instance_db.txt"};
|
||||||
int f;
|
int f;
|
||||||
@ -697,6 +732,9 @@ void instance_readdb(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload Instance DB
|
||||||
|
**/
|
||||||
void instance_reload(void) {
|
void instance_reload(void) {
|
||||||
InstanceDB->clear(InstanceDB, instance_db_free);
|
InstanceDB->clear(InstanceDB, instance_db_free);
|
||||||
db_clear(InstanceNameDB);
|
db_clear(InstanceNameDB);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user