* Cleaned up junk left in the code by the mapcache/mapindex update

- Added mapindex_getmapname(_ext) to help with ".gat" adding/removing
- Moved related processing to the interface (prevents duplicity)

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10963 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ultramage 2007-08-08 17:41:49 +00:00
parent 3ffa0a9dec
commit f5f77a5d51
15 changed files with 190 additions and 214 deletions

View File

@ -3,6 +3,10 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK. AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/08/08
* Cleaned up junk left in the code by the mapcache/mapindex update
- Added mapindex_getmapname(_ext) to help with ".gat" adding/removing
- Moved related processing to the interface (prevents duplicity)
2007/08/07 2007/08/07
* Expanded isloggedin script command to support an optional argument (char id) * Expanded isloggedin script command to support an optional argument (char id)
* Expanded warpparty command to accept target "Leader", this will warp the * Expanded warpparty command to accept target "Leader", this will warp the

View File

@ -3446,26 +3446,22 @@ int parse_char(int fd)
ShowWarning("Unable to find map-server for '%s', sending to major city '%s'.\n", mapindex_id2name(cd->last_point.map), mapindex_id2name(j)); ShowWarning("Unable to find map-server for '%s', sending to major city '%s'.\n", mapindex_id2name(cd->last_point.map), mapindex_id2name(j));
cd->last_point.map = j; cd->last_point.map = j;
} }
{
//Send player to map
uint32 subnet_map_ip;
char map_name[MAP_NAME_LENGTH_EXT];
snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(cd->last_point.map));
//Send player to map
WFIFOHEAD(fd,28); WFIFOHEAD(fd,28);
WFIFOW(fd,0) = 0x71; WFIFOW(fd,0) = 0x71;
WFIFOL(fd,2) = cd->char_id; WFIFOL(fd,2) = cd->char_id;
memcpy(WFIFOP(fd,6), map_name, MAP_NAME_LENGTH_EXT); safestrncpy((char*)WFIFOP(fd,6), mapindex_getmapname_ext(mapindex_id2name(cd->last_point.map),NULL), MAP_NAME_LENGTH_EXT);
{
// Advanced subnet check [LuzZza] // Advanced subnet check [LuzZza]
uint32 subnet_map_ip;
subnet_map_ip = lan_subnetcheck(ipl); subnet_map_ip = lan_subnetcheck(ipl);
WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : server[i].ip); WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : server[i].ip);
WFIFOW(fd,26) = ntows(htons(server[i].port)); // [!] LE byte order here [!] WFIFOW(fd,26) = ntows(htons(server[i].port)); // [!] LE byte order here [!]
WFIFOSET(fd,28); WFIFOSET(fd,28);
ShowInfo("Character selection '%s' (account: %d, slot: %d).\n",
cd->name, sd->account_id, ch);
} }
ShowInfo("Character selection '%s' (account: %d, slot: %d).\n", cd->name, sd->account_id, ch);
if (auth_fifo_pos >= AUTH_FIFO_SIZE) if (auth_fifo_pos >= AUTH_FIFO_SIZE)
auth_fifo_pos = 0; auth_fifo_pos = 0;
auth_fifo[auth_fifo_pos].account_id = sd->account_id; auth_fifo[auth_fifo_pos].account_id = sd->account_id;

View File

@ -3182,17 +3182,15 @@ int parse_char(int fd)
ShowWarning("Unable to find map-server for '%s', sending to major city '%s'.\n", mapindex_id2name(char_dat.last_point.map), mapindex_id2name(j)); ShowWarning("Unable to find map-server for '%s', sending to major city '%s'.\n", mapindex_id2name(char_dat.last_point.map), mapindex_id2name(j));
char_dat.last_point.map = j; char_dat.last_point.map = j;
} }
{
//Send player to map //Send player to map
uint32 subnet_map_ip;
char map_name[MAP_NAME_LENGTH_EXT];
snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(char_dat.last_point.map));
WFIFOHEAD(fd,28); WFIFOHEAD(fd,28);
WFIFOW(fd,0) = 0x71; WFIFOW(fd,0) = 0x71;
WFIFOL(fd,2) = char_dat.char_id; WFIFOL(fd,2) = char_dat.char_id;
memcpy(WFIFOP(fd,6), map_name, MAP_NAME_LENGTH_EXT); safestrncpy((char*)WFIFOP(fd,6), mapindex_getmapname_ext(mapindex_id2name(char_dat.last_point.map),NULL), MAP_NAME_LENGTH_EXT);
{
// Advanced subnet check [LuzZza] // Advanced subnet check [LuzZza]
uint32 subnet_map_ip;
subnet_map_ip = lan_subnetcheck(ipl); subnet_map_ip = lan_subnetcheck(ipl);
WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : server[i].ip); WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : server[i].ip);
WFIFOW(fd,26) = ntows(htons(server[i].port)); // [!] LE byte order here [!] WFIFOW(fd,26) = ntows(htons(server[i].port)); // [!] LE byte order here [!]

View File

@ -15,46 +15,84 @@
struct _indexes { struct _indexes {
char name[MAP_NAME_LENGTH]; //Stores map name char name[MAP_NAME_LENGTH]; //Stores map name
bool exists; //Set to 1 if index exists
} indexes[MAX_MAPINDEX]; } indexes[MAX_MAPINDEX];
static unsigned short max_index = 0; static unsigned short max_index = 0;
char mapindex_cfgfile[80] = "db/map_index.txt"; char mapindex_cfgfile[80] = "db/map_index.txt";
// Removes the extension from a map name #define mapindex_exists(id) (indexes[id].name[0] != '\0')
char* mapindex_normalize_name(char* mapname)
/// Retrieves the map name from 'string' (removing .gat extension if present).
/// Result gets placed either into 'buf' or in a static local buffer.
const char* mapindex_getmapname(const char* string, char* output)
{ {
char* ptr = strrchr(mapname, '.'); static char buf[MAP_NAME_LENGTH];
if (ptr && stricmp(ptr, ".gat") == 0) char* dest = (output != NULL) ? output : buf;
*ptr = '\0'; // remove extension
return mapname; size_t len = strnlen(string, MAP_NAME_LENGTH_EXT);
if (len == MAP_NAME_LENGTH_EXT) {
ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!", 2*MAP_NAME_LENGTH_EXT, string);
len--;
}
if (len >= 4 && stricmp(&string[len-4], ".gat") == 0)
len -= 4; // strip .gat extension
len = min(len, MAP_NAME_LENGTH-1);
safestrncpy(dest, string, len+1);
return dest;
}
/// Retrieves the map name from 'string' (adding .gat extension if not already present).
/// Result gets placed either into 'buf' or in a static local buffer.
const char* mapindex_getmapname_ext(const char* string, char* output)
{
static char buf[MAP_NAME_LENGTH_EXT];
char* dest = (output != NULL) ? output : buf;
size_t len = strnlen(string, MAP_NAME_LENGTH);
if (len == MAP_NAME_LENGTH) {
ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!", 2*MAP_NAME_LENGTH, string);
len--;
}
safestrncpy(dest, string, len+1);
if (len < 4 || stricmp(&dest[len-4], ".gat") != 0) {
strcpy(&dest[len], ".gat");
len += 4; // add .gat extension
}
return dest;
} }
/// Adds a map to the specified index /// Adds a map to the specified index
/// Returns 1 if successful, 0 oherwise /// 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]; char map_name[MAP_NAME_LENGTH];
if (index < 0 || index >= MAX_MAPINDEX) { if (index < 0 || index >= MAX_MAPINDEX) {
ShowError("(mapindex_add) Map index (%d) for \"%s\" out of range (max is %d)\n", index, name, MAX_MAPINDEX); ShowError("(mapindex_add) Map index (%d) for \"%s\" out of range (max is %d)\n", index, name, MAX_MAPINDEX);
return 0; return 0;
} }
safestrncpy(map_name, name, MAP_NAME_LENGTH_EXT); mapindex_getmapname(name, map_name);
mapindex_normalize_name(map_name);
if (strlen(map_name) >= MAP_NAME_LENGTH) { if (map_name[0] == '\0') {
ShowError("(mapindex_add) Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH); ShowError("(mapindex_add) Cannot add maps with no name.\n");
return 0; return 0;
} }
//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;
//}
if (indexes[index].exists) if (mapindex_exists(index))
ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name); ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name);
safestrncpy(indexes[index].name, map_name, MAP_NAME_LENGTH); safestrncpy(indexes[index].name, map_name, MAP_NAME_LENGTH);
indexes[index].exists = true;
if (max_index <= index) if (max_index <= index)
max_index = index+1; max_index = index+1;
@ -66,9 +104,8 @@ unsigned short mapindex_name2id(const char* name)
//TODO: Perhaps use a db to speed this up? [Skotlex] //TODO: Perhaps use a db to speed this up? [Skotlex]
int i; int i;
char map_name[MAP_NAME_LENGTH_EXT]; char map_name[MAP_NAME_LENGTH];
safestrncpy(map_name, name, MAP_NAME_LENGTH_EXT); mapindex_getmapname(name, map_name);
mapindex_normalize_name(map_name);
for (i = 1; i < max_index; i++) for (i = 1; i < max_index; i++)
{ {
@ -91,7 +128,7 @@ unsigned short mapindex_name2id(const char* name)
const char* mapindex_id2name(unsigned short id) const char* mapindex_id2name(unsigned short id)
{ {
if (id > MAX_MAPINDEX || !indexes[id].exists) { if (id > MAX_MAPINDEX || !mapindex_exists(id)) {
ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache.\n", id); ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache.\n", id);
return indexes[0].name; // dummy empty string so that the callee doesn't crash return indexes[0].name; // dummy empty string so that the callee doesn't crash
} }

View File

@ -36,7 +36,9 @@ extern char mapindex_cfgfile[80];
#define MAP_VEINS "veins" #define MAP_VEINS "veins"
#define MAP_JAIL "sec_pri" #define MAP_JAIL "sec_pri"
#define MAP_NOVICE "new_zone01" #define MAP_NOVICE "new_zone01"
char *mapindex_normalize_name(char *mapname);
const char* mapindex_getmapname(const char* string, char* output);
const char* mapindex_getmapname_ext(const char* string, char* output);
int mapindex_addmap(int index, const char *name); int mapindex_addmap(int index, const char *name);
unsigned short mapindex_name2id(const char*); unsigned short mapindex_name2id(const char*);
const char* mapindex_id2name(unsigned short); const char* mapindex_id2name(unsigned short);

View File

@ -28,7 +28,7 @@ struct dbt *auth_db;
static const int packet_len_table[0x3d] = { // U - used, F - free static const int packet_len_table[0x3d] = { // U - used, F - free
60, 3,-1,27,10,-1, 6,-1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff 60, 3,-1,27,10,-1, 6,-1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff
6,-1,18, 7,-1,49,30,10, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, U->2b07 6,-1,18, 7,-1,35,30,10, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, U->2b07
6,30,-1,10,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, U->2b0a, U->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f 6,30,-1,10,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, U->2b0a, U->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f
11,-1,10, 6,11,-1, 0,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17 11,-1,10, 6,11,-1, 0,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17
-1,-1,-1,-1,-1,-1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f -1,-1,-1,-1,-1,-1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f
@ -310,25 +310,25 @@ int chrif_changemapserver(struct map_session_data* sd, short map, int x, int y,
return 0; return 0;
} }
// map-server change request acknowledgement (positive or negative) /// map-server change request acknowledgement (positive or negative)
int chrif_changemapserverack(int fd) /// R 2b06 <account_id>.L <login_id1>.L <login_id2>.L <char_id>.L <map_index>.W <x>.W <y>.W <ip>.L <port>.W
int chrif_changemapserverack(int account_id, int login_id1, int login_id2, int char_id, short map_index, short x, short y, uint32 ip, uint16 port)
{ {
struct map_session_data *sd;
char mapname[MAP_NAME_LENGTH_EXT];
sd = map_id2sd(RFIFOL(fd,2));
if (sd == NULL || sd->status.char_id != RFIFOL(fd,14)) struct map_session_data *sd;
sd = map_id2sd(account_id);
if (sd == NULL || sd->status.char_id != char_id)
return -1; return -1;
if (RFIFOL(fd,6) == 1) { if (login_id1 == 1) { //FIXME: charserver says '0'!
if (battle_config.error_log) if (battle_config.error_log)
ShowError("map server change failed.\n"); ShowError("map server change failed.\n");
clif_authfail_fd(sd->fd, 0); clif_authfail_fd(sd->fd, 0);
return 0; return 0;
} }
sprintf(mapname, "%s.gat", mapindex_id2name(RFIFOW(fd,18))); clif_changemapserver(sd, map_index, x, y, ntohl(ip), ntohs(port));
clif_changemapserver(sd, mapname, RFIFOW(fd,20), RFIFOW(fd,22), ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28)));
//Player has been saved already, remove him from memory. [Skotlex] //Player has been saved already, remove him from memory. [Skotlex]
map_quit(sd); map_quit(sd);
@ -1297,7 +1297,7 @@ int chrif_parse(int fd)
case 0x2b00: map_setusers(fd); break; case 0x2b00: map_setusers(fd); break;
case 0x2b03: clif_charselectok(RFIFOL(fd,2)); break; case 0x2b03: clif_charselectok(RFIFOL(fd,2)); break;
case 0x2b04: chrif_recvmap(fd); break; case 0x2b04: chrif_recvmap(fd); break;
case 0x2b06: chrif_changemapserverack(fd); break; case 0x2b06: chrif_changemapserverack(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOW(fd,18), RFIFOW(fd,20), RFIFOW(fd,22), RFIFOL(fd,24), RFIFOW(fd,28)); break;
case 0x2b07: clif_updatemaxid(RFIFOL(fd,2), RFIFOL(fd,6)); break; case 0x2b07: clif_updatemaxid(RFIFOL(fd,2), RFIFOL(fd,6)); break;
case 0x2b09: map_addchariddb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break; case 0x2b09: map_addchariddb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break;
case 0x2b0b: chrif_changedgm(fd); break; case 0x2b0b: chrif_changedgm(fd); break;

View File

@ -1187,21 +1187,15 @@ static void clif_spiritball_single(int fd, struct map_session_data *sd)
/*========================================== /*==========================================
* *
*------------------------------------------*/ *------------------------------------------*/
static int clif_set0192(int fd, int m, int x, int y, int type) static void clif_set0192(int fd, int m, int x, int y, int type)
{ {
char map_name[MAP_NAME_LENGTH_EXT];
sprintf(map_name, "%s.gat", map[m].name);
WFIFOHEAD(fd, packet_len(0x192)); WFIFOHEAD(fd, packet_len(0x192));
WFIFOW(fd,0) = 0x192; WFIFOW(fd,0) = 0x192;
WFIFOW(fd,2) = x; WFIFOW(fd,2) = x;
WFIFOW(fd,4) = y; WFIFOW(fd,4) = y;
WFIFOW(fd,6) = type; WFIFOW(fd,6) = type;
memcpy(WFIFOP(fd,8),map_name,MAP_NAME_LENGTH_EXT); safestrncpy((char*)WFIFOP(fd,8), mapindex_getmapname_ext(map[m].name,NULL), MAP_NAME_LENGTH_EXT);
WFIFOSET(fd,packet_len(0x192)); WFIFOSET(fd,packet_len(0x192));
return 0;
} }
// new and improved weather display [Valaris] // new and improved weather display [Valaris]
@ -1650,49 +1644,38 @@ void clif_setwaitclose(int fd)
/*========================================== /*==========================================
* *
*------------------------------------------*/ *------------------------------------------*/
int clif_changemap(struct map_session_data *sd, short map, int x, int y) void clif_changemap(struct map_session_data *sd, short map, int x, int y)
{ {
int fd; int fd;
char map_name[MAP_NAME_LENGTH_EXT]; nullpo_retv(sd);
nullpo_retr(0, sd);
fd = sd->fd; fd = sd->fd;
sprintf(map_name, "%s.gat", mapindex_id2name(map));
WFIFOHEAD(fd, packet_len(0x91)); WFIFOHEAD(fd, packet_len(0x91));
WFIFOW(fd,0) = 0x91; WFIFOW(fd,0) = 0x91;
memcpy(WFIFOP(fd,2), map_name, MAP_NAME_LENGTH_EXT); safestrncpy((char*)WFIFOP(fd,2), mapindex_getmapname_ext(mapindex_id2name(map),NULL), MAP_NAME_LENGTH_EXT);
WFIFOW(fd,18) = x; WFIFOW(fd,18) = x;
WFIFOW(fd,20) = y; WFIFOW(fd,20) = y;
WFIFOSET(fd, packet_len(0x91)); WFIFOSET(fd, packet_len(0x91));
return 0;
} }
/*========================================== /*==========================================
* Tells the client to connect to another map-server * Tells the client to connect to another map-server
*------------------------------------------*/ *------------------------------------------*/
int clif_changemapserver(struct map_session_data* sd, const char* mapname, int x, int y, uint32 ip, uint16 port) void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
{ {
int fd; int fd;
nullpo_retv(sd);
nullpo_retr(0, sd);
fd = sd->fd; fd = sd->fd;
WFIFOHEAD(fd, packet_len(0x92)); WFIFOHEAD(fd, packet_len(0x92));
WFIFOW(fd,0) = 0x92; WFIFOW(fd,0) = 0x92;
//Better not trust the null-terminator is there. [Skotlex] safestrncpy((char*)WFIFOP(fd,2), mapindex_getmapname_ext(mapindex_id2name(map_index),NULL), MAP_NAME_LENGTH_EXT);
memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH_EXT);
WFIFOB(fd,17) = 0; //Null terminator for mapname WFIFOB(fd,17) = 0; //Null terminator for mapname
WFIFOW(fd,18) = x; WFIFOW(fd,18) = x;
WFIFOW(fd,20) = y; WFIFOW(fd,20) = y;
WFIFOL(fd,22) = htonl(ip); WFIFOL(fd,22) = htonl(ip);
WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!] WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
WFIFOSET(fd, packet_len(0x92)); WFIFOSET(fd, packet_len(0x92));
return 0;
} }
int clif_blown(struct block_list *bl) int clif_blown(struct block_list *bl)
@ -4717,22 +4700,21 @@ int clif_skill_delunit(struct skill_unit *unit)
/*========================================== /*==========================================
* *
*------------------------------------------*/ *------------------------------------------*/
int clif_skill_warppoint(struct map_session_data* sd, int skill_num, int skill_lv, int map1, int map2, int map3, int map4) void clif_skill_warppoint(struct map_session_data* sd, int skill_num, int skill_lv, int map1, int map2, int map3, int map4)
{ {
int fd; int fd;
nullpo_retv(sd);
nullpo_retr(0, sd);
fd = sd->fd; fd = sd->fd;
WFIFOHEAD(fd,packet_len(0x11c)); WFIFOHEAD(fd,packet_len(0x11c));
WFIFOW(fd,0) = 0x11c; WFIFOW(fd,0) = 0x11c;
WFIFOW(fd,2) = skill_num; WFIFOW(fd,2) = skill_num;
memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT); memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
if (map1 == -1) strcpy((char*)WFIFOP(fd, 4), "Random"); if (map1 == -1) safestrncpy((char*)WFIFOP(fd, 4), "Random", MAP_NAME_LENGTH_EXT);
if (map1 > 0) snprintf((char*)WFIFOP(fd, 4), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map1)); if (map1 > 0) safestrncpy((char*)WFIFOP(fd, 4), mapindex_getmapname_ext(mapindex_id2name(map1),NULL), MAP_NAME_LENGTH_EXT);
if (map2 > 0) snprintf((char*)WFIFOP(fd,20), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map2)); if (map2 > 0) safestrncpy((char*)WFIFOP(fd,20), mapindex_getmapname_ext(mapindex_id2name(map2),NULL), MAP_NAME_LENGTH_EXT);
if (map3 > 0) snprintf((char*)WFIFOP(fd,36), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map3)); if (map3 > 0) safestrncpy((char*)WFIFOP(fd,36), mapindex_getmapname_ext(mapindex_id2name(map3),NULL), MAP_NAME_LENGTH_EXT);
if (map4 > 0) snprintf((char*)WFIFOP(fd,52), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map4)); if (map4 > 0) safestrncpy((char*)WFIFOP(fd,52), mapindex_getmapname_ext(mapindex_id2name(map4),NULL), MAP_NAME_LENGTH_EXT);
WFIFOSET(fd,packet_len(0x11c)); WFIFOSET(fd,packet_len(0x11c));
sd->menuskill_id = skill_num; sd->menuskill_id = skill_num;
@ -4740,7 +4722,6 @@ int clif_skill_warppoint(struct map_session_data* sd, int skill_num, int skill_l
sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
else else
sd->menuskill_val = skill_lv; sd->menuskill_val = skill_lv;
return 0;
} }
/*========================================== /*==========================================
* *
@ -5698,7 +5679,6 @@ int clif_party_created(struct map_session_data *sd,int flag)
int clif_party_member_info(struct party_data *p, struct map_session_data *sd) int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
{ {
unsigned char buf[96]; unsigned char buf[96];
char map_name[MAP_NAME_LENGTH_EXT];
if (!sd) { //Pick any party member (this call is used when changing item share rules) if (!sd) { //Pick any party member (this call is used when changing item share rules)
int i; int i;
@ -5707,8 +5687,6 @@ int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
sd = p->data[i].sd; sd = p->data[i].sd;
} }
snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(sd->mapindex));
WBUFW(buf, 0) = 0x1e9; WBUFW(buf, 0) = 0x1e9;
WBUFL(buf, 2) = sd->status.account_id; WBUFL(buf, 2) = sd->status.account_id;
WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable. WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable.
@ -5717,7 +5695,7 @@ int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline. WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline.
memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH); memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH); memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
memcpy(WBUFP(buf,63), map_name, MAP_NAME_LENGTH_EXT); safestrncpy((char*)WBUFP(buf,63), mapindex_getmapname_ext(mapindex_id2name(sd->mapindex),NULL), MAP_NAME_LENGTH_EXT);
WBUFB(buf,79) = (p->party.item&1)?1:0; WBUFB(buf,79) = (p->party.item&1)?1:0;
WBUFB(buf,80) = (p->party.item&2)?1:0; WBUFB(buf,80) = (p->party.item&2)?1:0;
clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY); clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
@ -5742,17 +5720,13 @@ int clif_party_info(struct party_data* p, struct map_session_data *sd)
for(i = 0, c = 0; i < MAX_PARTY; i++) for(i = 0, c = 0; i < MAX_PARTY; i++)
{ {
struct party_member* m = &p->party.member[i]; struct party_member* m = &p->party.member[i];
char map_name[MAP_NAME_LENGTH_EXT];
if(!m->account_id) continue; if(!m->account_id) continue;
if(party_sd == NULL) party_sd = p->data[i].sd; if(party_sd == NULL) party_sd = p->data[i].sd;
snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(m->map));
WBUFL(buf,28+c*46) = m->account_id; WBUFL(buf,28+c*46) = m->account_id;
memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH); memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
memcpy(WBUFP(buf,28+c*46+28), map_name, MAP_NAME_LENGTH_EXT); safestrncpy((char*)WBUFP(buf,28+c*46+28), mapindex_getmapname_ext(mapindex_id2name(m->map),NULL), MAP_NAME_LENGTH_EXT);
WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1; WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1; WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
c++; c++;
@ -6016,15 +5990,12 @@ int clif_hpmeter(struct map_session_data *sd)
/*========================================== /*==========================================
* 使 * 使
*------------------------------------------*/ *------------------------------------------*/
int clif_party_move(struct party *p,struct map_session_data *sd,int online) void clif_party_move(struct party* p, struct map_session_data* sd, int online)
{ {
unsigned char buf[128]; unsigned char buf[128];
char map_name[MAP_NAME_LENGTH_EXT];
nullpo_retr(0, sd); nullpo_retv(sd);
nullpo_retr(0, p); nullpo_retv(p);
snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", map[sd->bl.m].name);
WBUFW(buf, 0) = 0x104; WBUFW(buf, 0) = 0x104;
WBUFL(buf, 2) = sd->status.account_id; WBUFL(buf, 2) = sd->status.account_id;
@ -6034,9 +6005,8 @@ int clif_party_move(struct party *p,struct map_session_data *sd,int online)
WBUFB(buf,14) = !online; WBUFB(buf,14) = !online;
memcpy(WBUFP(buf,15),p->name, NAME_LENGTH); memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH); memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
memcpy(WBUFP(buf,63),map_name, MAP_NAME_LENGTH_EXT); safestrncpy((char*)WBUFP(buf,63), mapindex_getmapname_ext(map[sd->bl.m].name,NULL), MAP_NAME_LENGTH_EXT);
clif_send(buf,packet_len(0x104),&sd->bl,PARTY); clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
return 0;
} }
/*========================================== /*==========================================
* *
@ -6411,13 +6381,10 @@ int clif_bladestop(struct block_list *src,struct block_list *dst,
/*========================================== /*==========================================
* *
*------------------------------------------*/ *------------------------------------------*/
int clif_changemapcell(int m,int x,int y,int cell_type,int type) void clif_changemapcell(short m, short x, short y, int cell_type, int type)
{ {
struct block_list bl; struct block_list bl;
unsigned char buf[32]; unsigned char buf[32];
char map_name[MAP_NAME_LENGTH_EXT];
snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", map[m].name);
bl.type = BL_NUL; bl.type = BL_NUL;
bl.m = m; bl.m = m;
@ -6427,13 +6394,8 @@ int clif_changemapcell(int m,int x,int y,int cell_type,int type)
WBUFW(buf,2) = x; WBUFW(buf,2) = x;
WBUFW(buf,4) = y; WBUFW(buf,4) = y;
WBUFW(buf,6) = cell_type; WBUFW(buf,6) = cell_type;
memcpy(WBUFP(buf,8),map_name,MAP_NAME_LENGTH_EXT); safestrncpy((char*)WBUFP(buf,8), mapindex_getmapname_ext(map[m].name,NULL), MAP_NAME_LENGTH_EXT);
if(!type) clif_send(buf,packet_len(0x192),&bl,(!type)?AREA:ALL_SAMEMAP);
clif_send(buf,packet_len(0x192),&bl,AREA);
else
clif_send(buf,packet_len(0x192),&bl,ALL_SAMEMAP);
return 0;
} }
/*========================================== /*==========================================
@ -7789,13 +7751,10 @@ void clif_gospel_info(struct map_session_data *sd, int type)
void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type) void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
{ {
int fd=sd->fd; int fd=sd->fd;
char map_name[MAP_NAME_LENGTH_EXT];
snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(sd->feel_map[feel_level].index));
WFIFOHEAD(fd,packet_len(0x20e)); WFIFOHEAD(fd,packet_len(0x20e));
WFIFOW(fd,0) = 0x20e; WFIFOW(fd,0) = 0x20e;
memcpy(WFIFOP(fd,2),map_name, MAP_NAME_LENGTH_EXT); safestrncpy((char*)WFIFOP(fd,2), mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index),NULL), MAP_NAME_LENGTH_EXT);
WFIFOL(fd,26) = sd->bl.id; WFIFOL(fd,26) = sd->bl.id;
WFIFOB(fd,30) = feel_level; WFIFOB(fd,30) = feel_level;
WFIFOB(fd,31) = type?1:0; WFIFOB(fd,31) = type?1:0;
@ -9703,8 +9662,9 @@ void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
*------------------------------------------*/ *------------------------------------------*/
void clif_parse_UseSkillMap(int fd, struct map_session_data* sd) void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
{ {
int skill_num; int skill_num = RFIFOW(fd,2);
skill_num = RFIFOW(fd,2); char map_name[MAP_NAME_LENGTH];
mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
if(skill_num != sd->menuskill_id) if(skill_num != sd->menuskill_id)
return; return;
@ -9716,7 +9676,7 @@ void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
} }
pc_delinvincibletimer(sd); pc_delinvincibletimer(sd);
skill_castend_map(sd,skill_num,(char*)RFIFOP(fd,4)); skill_castend_map(sd,skill_num,map_name);
} }
/*========================================== /*==========================================
* *

View File

@ -80,8 +80,8 @@ int clif_clearunit_delayed(struct block_list* bl, unsigned int tick);
int clif_spawn(struct block_list*); //area int clif_spawn(struct block_list*); //area
int clif_walkok(struct map_session_data*); // self int clif_walkok(struct map_session_data*); // self
void clif_move(struct unit_data *ud); //area void clif_move(struct unit_data *ud); //area
int clif_changemap(struct map_session_data*,short,int,int); //self void clif_changemap(struct map_session_data*,short,int,int); //self
int clif_changemapserver(struct map_session_data* sd, const char* mapname, int x, int y, uint32 ip, uint16 port); //self void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port); //self
int clif_blown(struct block_list *); // area int clif_blown(struct block_list *); // area
int clif_slide(struct block_list *,int,int); // area int clif_slide(struct block_list *,int,int); // area
int clif_fixpos(struct block_list *); // area int clif_fixpos(struct block_list *); // area
@ -191,7 +191,7 @@ int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
int clif_skill_poseffect(struct block_list *src,int skill_id, int clif_skill_poseffect(struct block_list *src,int skill_id,
int val,int x,int y,int tick); int val,int x,int y,int tick);
int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst); int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst);
int clif_skill_warppoint(struct map_session_data* sd, int skill_num, int skill_lv, int map1, int map2, int map3, int map4); void clif_skill_warppoint(struct map_session_data* sd, int skill_num, int skill_lv, int map1, int map2, int map3, int map4);
int clif_skill_memo(struct map_session_data *sd,int flag); int clif_skill_memo(struct map_session_data *sd,int flag);
int clif_skill_teleportmessage(struct map_session_data *sd,int flag); int clif_skill_teleportmessage(struct map_session_data *sd,int flag);
int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger); int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger);
@ -209,7 +209,7 @@ int clif_marionette(struct block_list *src, struct block_list *target);
int clif_spiritball(struct map_session_data *sd); int clif_spiritball(struct map_session_data *sd);
int clif_combo_delay(struct block_list *src,int wait); int clif_combo_delay(struct block_list *src,int wait);
int clif_bladestop(struct block_list *src,struct block_list *dst,int bool_); int clif_bladestop(struct block_list *src,struct block_list *dst,int bool_);
int clif_changemapcell(int m,int x,int y,int cell_type,int type); void clif_changemapcell(short m, short x, short y, int cell_type, int type);
int clif_status_load(struct block_list *bl,int type, int flag); int clif_status_load(struct block_list *bl,int type, int flag);
int clif_status_change(struct block_list *bl,int type,int flag); int clif_status_change(struct block_list *bl,int type,int flag);
@ -265,7 +265,7 @@ int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag
int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag); int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag);
int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag); int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag);
int clif_party_message(struct party_data* p, int account_id, const char* mes, int len); int clif_party_message(struct party_data* p, int account_id, const char* mes, int len);
int clif_party_move(struct party *p,struct map_session_data *sd,int online); void clif_party_move(struct party* p, struct map_session_data* sd, int online);
int clif_party_xy(struct map_session_data *sd); int clif_party_xy(struct map_session_data *sd);
int clif_party_xy_single(int fd, struct map_session_data *sd); int clif_party_xy_single(int fd, struct map_session_data *sd);
int clif_party_hp(struct map_session_data *sd); int clif_party_hp(struct map_session_data *sd);

View File

@ -12,6 +12,7 @@
#include "../common/mapindex.h" #include "../common/mapindex.h"
#include "../common/showmsg.h" #include "../common/showmsg.h"
#include "../common/ers.h" #include "../common/ers.h"
#include "../common/strlib.h"
#include "map.h" #include "map.h"
#include "guild.h" #include "guild.h"
@ -184,9 +185,9 @@ static int guild_read_castledb(void)
gc=(struct guild_castle *)aCalloc(1,sizeof(struct guild_castle)); gc=(struct guild_castle *)aCalloc(1,sizeof(struct guild_castle));
gc->castle_id=atoi(str[0]); gc->castle_id=atoi(str[0]);
memcpy(gc->map_name,mapindex_normalize_name(str[1]),MAP_NAME_LENGTH); safestrncpy(gc->map_name,mapindex_getmapname(str[1],NULL),MAP_NAME_LENGTH);
memcpy(gc->castle_name,str[2],NAME_LENGTH); safestrncpy(gc->castle_name,str[2],NAME_LENGTH);
memcpy(gc->castle_event,str[3],NAME_LENGTH); safestrncpy(gc->castle_event,str[3],NAME_LENGTH);
idb_put(castle_db,gc->castle_id,gc); idb_put(castle_db,gc->castle_id,gc);
@ -250,14 +251,12 @@ struct guild_castle *guild_castle_search(int gcid)
} }
// mapnameに対応したアジトのgcを返す // mapnameに対応したアジトのgcを返す
struct guild_castle *guild_mapname2gc(char *mapname) struct guild_castle* guild_mapname2gc(const char* mapname)
{ {
int i; int i;
struct guild_castle *gc=NULL; for(i = 0; i < MAX_GUILDCASTLE; i++)
{
mapindex_normalize_name(mapname); struct guild_castle* gc;
for(i=0;i<MAX_GUILDCASTLE;i++){
gc = guild_castle_search(i); gc = guild_castle_search(i);
if(!gc) continue; if(!gc) continue;
if(strcmp(gc->map_name,mapname)==0) return gc; if(strcmp(gc->map_name,mapname)==0) return gc;

View File

@ -24,7 +24,7 @@ struct guild *guild_search(int guild_id);
struct guild *guild_searchname(char *str); struct guild *guild_searchname(char *str);
struct guild_castle *guild_castle_search(int gcid); struct guild_castle *guild_castle_search(int gcid);
struct guild_castle *guild_mapname2gc(char *mapname); struct guild_castle* guild_mapname2gc(const char* mapname);
struct guild_castle* guild_mapindex2gc(short mapindex); struct guild_castle* guild_mapindex2gc(short mapindex);
struct map_session_data *guild_getavailablesd(struct guild *g); struct map_session_data *guild_getavailablesd(struct guild *g);

View File

@ -2475,7 +2475,7 @@ int map_addmap(char *mapname)
return 1; return 1;
} }
memcpy(map[map_num].name, mapindex_normalize_name(mapname), MAP_NAME_LENGTH); mapindex_getmapname(mapname, map[map_num].name);
map_num++; map_num++;
return 0; return 0;
} }

View File

@ -311,8 +311,7 @@ struct mob_data *mob_once_spawn_sub(struct block_list *bl, int m,
/*========================================== /*==========================================
* The MOB appearance for one time (for scripts) * The MOB appearance for one time (for scripts)
*------------------------------------------*/ *------------------------------------------*/
int mob_once_spawn (struct map_session_data *sd, const char *mapname, int mob_once_spawn (struct map_session_data* sd, const char* mapname, short x, short y, const char* mobname, int class_, int amount, const char* event)
short x, short y, const char *mobname, int class_, int amount, const char *event)
{ {
struct mob_data* md = NULL; struct mob_data* md = NULL;
int m, count, lv = 255; int m, count, lv = 255;
@ -327,7 +326,8 @@ int mob_once_spawn (struct map_session_data *sd, const char *mapname,
if (m < 0 || amount <= 0) // 値が異常なら召喚を止める if (m < 0 || amount <= 0) // 値が異常なら召喚を止める
return 0; return 0;
for (count = 0; count < amount; count++) { for (count = 0; count < amount; count++)
{
md = mob_once_spawn_sub(sd?&sd->bl:NULL, m, x, y, mobname, md = mob_once_spawn_sub(sd?&sd->bl:NULL, m, x, y, mobname,
class_<0? class_<0?
mob_get_random_id(-class_-1, battle_config.random_monster_checklv?3:1, lv): mob_get_random_id(-class_-1, battle_config.random_monster_checklv?3:1, lv):

View File

@ -9576,42 +9576,33 @@ BUILDIN_FUNC(flagemblem)
BUILDIN_FUNC(getcastlename) BUILDIN_FUNC(getcastlename)
{ {
char mapname[MAP_NAME_LENGTH_EXT]; const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
struct guild_castle *gc; struct guild_castle* gc = guild_mapname2gc(mapname);
char* name = (gc) ? gc->castle_name : "";
strncpy(mapname, script_getstr(st,2), MAP_NAME_LENGTH_EXT); script_pushconststr(st,name);
gc = guild_mapname2gc(mapname);
if(gc)
script_pushconststr(st,gc->castle_name);
else
script_pushconststr(st,"");
return 0; return 0;
} }
BUILDIN_FUNC(getcastledata) BUILDIN_FUNC(getcastledata)
{ {
char mapname[MAP_NAME_LENGTH_EXT]; const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
int index = script_getnum(st,3); int index = script_getnum(st,3);
const char *event=NULL;
struct guild_castle *gc;
int i;
strncpy(mapname, script_getstr(st,2), MAP_NAME_LENGTH_EXT); struct guild_castle* gc = guild_mapname2gc(mapname);
gc = guild_mapname2gc(mapname);
if(script_hasdata(st,4) && index==0 && gc) { if(script_hasdata(st,4) && index==0 && gc) {
event=script_getstr(st,4); const char* event = script_getstr(st,4);
check_event(st, event); check_event(st, event);
guild_addcastleinfoevent(gc->castle_id,17,event); guild_addcastleinfoevent(gc->castle_id,17,event);
} }
if(gc){ if(gc){
switch(index){ switch(index){
case 0: case 0: {
int i;
for(i=1;i<26;i++) // Initialize[AgitInit] for(i=1;i<26;i++) // Initialize[AgitInit]
guild_castledataload(gc->castle_id,i); guild_castledataload(gc->castle_id,i);
break; } break;
case 1: case 1:
script_pushint(st,gc->guild_id); break; script_pushint(st,gc->guild_id); break;
case 2: case 2:
@ -9659,13 +9650,10 @@ BUILDIN_FUNC(getcastledata)
BUILDIN_FUNC(setcastledata) BUILDIN_FUNC(setcastledata)
{ {
char mapname[MAP_NAME_LENGTH_EXT];
int index=script_getnum(st,3); int index=script_getnum(st,3);
int value=script_getnum(st,4); int value=script_getnum(st,4);
struct guild_castle *gc;
strncpy(mapname, script_getstr(st,2), MAP_NAME_LENGTH_EXT); struct guild_castle* gc = guild_mapname2gc( mapindex_getmapname(script_getstr(st,2),NULL) );
gc = guild_mapname2gc(mapname);
if(gc) { if(gc) {
// Save Data byself First // Save Data byself First

View File

@ -6328,14 +6328,6 @@ int skill_castend_map (struct map_session_data *sd, int skill_num, const char *m
return 0; return 0;
} }
if (strlen(map) > MAP_NAME_LENGTH_EXT-1)
{ //Map_length check, as it is sent by the client and we shouldn't trust it [Skotlex]
if (battle_config.error_log)
ShowError("skill_castend_map: Received map name '%s' too long!\n", map);
skill_failed(sd);
return 0;
}
pc_stop_attack(sd); pc_stop_attack(sd);
pc_stop_walking(sd,0); pc_stop_walking(sd,0);