diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 36 | ||||
-rw-r--r-- | src/char_sql/char.c | 30 | ||||
-rw-r--r-- | src/common/mapindex.c | 73 | ||||
-rw-r--r-- | src/common/mapindex.h | 4 | ||||
-rw-r--r-- | src/map/chrif.c | 20 | ||||
-rw-r--r-- | src/map/clif.c | 140 | ||||
-rw-r--r-- | src/map/clif.h | 10 | ||||
-rw-r--r-- | src/map/guild.c | 19 | ||||
-rw-r--r-- | src/map/guild.h | 4 | ||||
-rw-r--r-- | src/map/map.c | 4 | ||||
-rw-r--r-- | src/map/mob.c | 12 | ||||
-rw-r--r-- | src/map/script.c | 38 | ||||
-rw-r--r-- | src/map/skill.c | 10 | ||||
-rw-r--r-- | src/map/unit.c | 6 |
14 files changed, 189 insertions, 217 deletions
diff --git a/src/char/char.c b/src/char/char.c index 4ae02e360..b1675b7ab 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -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)); 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)); - - WFIFOHEAD(fd,28); - WFIFOW(fd,0) = 0x71; - WFIFOL(fd,2) = cd->char_id; - memcpy(WFIFOP(fd,6), map_name, MAP_NAME_LENGTH_EXT); - - // Advanced subnet check [LuzZza] - subnet_map_ip = lan_subnetcheck(ipl); - 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 [!] - WFIFOSET(fd,28); - - ShowInfo("Character selection '%s' (account: %d, slot: %d).\n", - cd->name, sd->account_id, ch); - } + + //Send player to map + WFIFOHEAD(fd,28); + WFIFOW(fd,0) = 0x71; + WFIFOL(fd,2) = cd->char_id; + safestrncpy((char*)WFIFOP(fd,6), mapindex_getmapname_ext(mapindex_id2name(cd->last_point.map),NULL), MAP_NAME_LENGTH_EXT); + { + // Advanced subnet check [LuzZza] + uint32 subnet_map_ip; + subnet_map_ip = lan_subnetcheck(ipl); + 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 [!] + WFIFOSET(fd,28); + } + ShowInfo("Character selection '%s' (account: %d, slot: %d).\n", cd->name, sd->account_id, ch); + if (auth_fifo_pos >= AUTH_FIFO_SIZE) auth_fifo_pos = 0; auth_fifo[auth_fifo_pos].account_id = sd->account_id; diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 430f0832a..1b598b662 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -3182,22 +3182,20 @@ 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)); char_dat.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(char_dat.last_point.map)); - WFIFOHEAD(fd,28); - WFIFOW(fd,0) = 0x71; - WFIFOL(fd,2) = char_dat.char_id; - memcpy(WFIFOP(fd,6), map_name, MAP_NAME_LENGTH_EXT); - - // Advanced subnet check [LuzZza] - subnet_map_ip = lan_subnetcheck(ipl); - 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 [!] - WFIFOSET(fd,28); - } + + //Send player to map + WFIFOHEAD(fd,28); + WFIFOW(fd,0) = 0x71; + WFIFOL(fd,2) = char_dat.char_id; + safestrncpy((char*)WFIFOP(fd,6), mapindex_getmapname_ext(mapindex_id2name(char_dat.last_point.map),NULL), MAP_NAME_LENGTH_EXT); + { + // Advanced subnet check [LuzZza] + uint32 subnet_map_ip; + subnet_map_ip = lan_subnetcheck(ipl); + 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 [!] + WFIFOSET(fd,28); + } if (auth_fifo_pos >= AUTH_FIFO_SIZE) auth_fifo_pos = 0; auth_fifo[auth_fifo_pos].account_id = sd->account_id; diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 73350e016..7e55daff8 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -15,46 +15,84 @@ struct _indexes { char name[MAP_NAME_LENGTH]; //Stores map name - bool exists; //Set to 1 if index exists } indexes[MAX_MAPINDEX]; 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) +#define mapindex_exists(id) (indexes[id].name[0] != '\0') + +/// 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) +{ + static char buf[MAP_NAME_LENGTH]; + char* dest = (output != NULL) ? output : buf; + + 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) { - char* ptr = strrchr(mapname, '.'); - if (ptr && stricmp(ptr, ".gat") == 0) - *ptr = '\0'; // remove extension - return mapname; + 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 /// Returns 1 if successful, 0 oherwise 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) { ShowError("(mapindex_add) Map index (%d) for \"%s\" out of range (max is %d)\n", index, name, MAX_MAPINDEX); return 0; } - safestrncpy(map_name, name, MAP_NAME_LENGTH_EXT); - mapindex_normalize_name(map_name); + mapindex_getmapname(name, map_name); - 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); + if (map_name[0] == '\0') { + ShowError("(mapindex_add) Cannot add maps with no name.\n"); 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); safestrncpy(indexes[index].name, map_name, MAP_NAME_LENGTH); - indexes[index].exists = true; if (max_index <= index) 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] int i; - char map_name[MAP_NAME_LENGTH_EXT]; - safestrncpy(map_name, name, MAP_NAME_LENGTH_EXT); - mapindex_normalize_name(map_name); + char map_name[MAP_NAME_LENGTH]; + mapindex_getmapname(name, map_name); 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) { - 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); return indexes[0].name; // dummy empty string so that the callee doesn't crash } diff --git a/src/common/mapindex.h b/src/common/mapindex.h index f49ee923b..0d2c0c46e 100644 --- a/src/common/mapindex.h +++ b/src/common/mapindex.h @@ -36,7 +36,9 @@ extern char mapindex_cfgfile[80]; #define MAP_VEINS "veins" #define MAP_JAIL "sec_pri" #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); unsigned short mapindex_name2id(const char*); const char* mapindex_id2name(unsigned short); diff --git a/src/map/chrif.c b/src/map/chrif.c index 128966a91..5be283329 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -28,7 +28,7 @@ struct dbt *auth_db; 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 - 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 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 @@ -310,25 +310,25 @@ int chrif_changemapserver(struct map_session_data* sd, short map, int x, int y, return 0; } -// map-server change request acknowledgement (positive or negative) -int chrif_changemapserverack(int fd) +/// map-server change request acknowledgement (positive or negative) +/// 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)); + sd = map_id2sd(account_id); - if (sd == NULL || sd->status.char_id != RFIFOL(fd,14)) + if (sd == NULL || sd->status.char_id != char_id) return -1; - if (RFIFOL(fd,6) == 1) { + if (login_id1 == 1) { //FIXME: charserver says '0'! if (battle_config.error_log) ShowError("map server change failed.\n"); clif_authfail_fd(sd->fd, 0); return 0; } - sprintf(mapname, "%s.gat", mapindex_id2name(RFIFOW(fd,18))); - clif_changemapserver(sd, mapname, RFIFOW(fd,20), RFIFOW(fd,22), ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28))); + clif_changemapserver(sd, map_index, x, y, ntohl(ip), ntohs(port)); //Player has been saved already, remove him from memory. [Skotlex] map_quit(sd); @@ -1297,7 +1297,7 @@ int chrif_parse(int fd) case 0x2b00: map_setusers(fd); break; case 0x2b03: clif_charselectok(RFIFOL(fd,2)); 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 0x2b09: map_addchariddb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break; case 0x2b0b: chrif_changedgm(fd); break; diff --git a/src/map/clif.c b/src/map/clif.c index 6ab8ea438..ccd54c086 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -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)); WFIFOW(fd,0) = 0x192; WFIFOW(fd,2) = x; WFIFOW(fd,4) = y; 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)); - - return 0; } // 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; - char map_name[MAP_NAME_LENGTH_EXT]; - - nullpo_retr(0, sd); - + nullpo_retv(sd); fd = sd->fd; - sprintf(map_name, "%s.gat", mapindex_id2name(map)); - WFIFOHEAD(fd, packet_len(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,20) = y; WFIFOSET(fd, packet_len(0x91)); - - return 0; } /*========================================== * 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; - - nullpo_retr(0, sd); - + nullpo_retv(sd); fd = sd->fd; + WFIFOHEAD(fd, packet_len(0x92)); WFIFOW(fd,0) = 0x92; - //Better not trust the null-terminator is there. [Skotlex] - memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH_EXT); + safestrncpy((char*)WFIFOP(fd,2), mapindex_getmapname_ext(mapindex_id2name(map_index),NULL), MAP_NAME_LENGTH_EXT); WFIFOB(fd,17) = 0; //Null terminator for mapname WFIFOW(fd,18) = x; WFIFOW(fd,20) = y; WFIFOL(fd,22) = htonl(ip); WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!] WFIFOSET(fd, packet_len(0x92)); - - return 0; } 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; - - nullpo_retr(0, sd); + nullpo_retv(sd); fd = sd->fd; WFIFOHEAD(fd,packet_len(0x11c)); WFIFOW(fd,0) = 0x11c; WFIFOW(fd,2) = skill_num; memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT); - if (map1 == -1) strcpy((char*)WFIFOP(fd, 4), "Random"); - if (map1 > 0) snprintf((char*)WFIFOP(fd, 4), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map1)); - if (map2 > 0) snprintf((char*)WFIFOP(fd,20), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map2)); - if (map3 > 0) snprintf((char*)WFIFOP(fd,36), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map3)); - if (map4 > 0) snprintf((char*)WFIFOP(fd,52), MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(map4)); + if (map1 == -1) safestrncpy((char*)WFIFOP(fd, 4), "Random", MAP_NAME_LENGTH_EXT); + if (map1 > 0) safestrncpy((char*)WFIFOP(fd, 4), mapindex_getmapname_ext(mapindex_id2name(map1),NULL), MAP_NAME_LENGTH_EXT); + if (map2 > 0) safestrncpy((char*)WFIFOP(fd,20), mapindex_getmapname_ext(mapindex_id2name(map2),NULL), MAP_NAME_LENGTH_EXT); + if (map3 > 0) safestrncpy((char*)WFIFOP(fd,36), mapindex_getmapname_ext(mapindex_id2name(map3),NULL), MAP_NAME_LENGTH_EXT); + if (map4 > 0) safestrncpy((char*)WFIFOP(fd,52), mapindex_getmapname_ext(mapindex_id2name(map4),NULL), MAP_NAME_LENGTH_EXT); WFIFOSET(fd,packet_len(0x11c)); 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. else 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) { 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) int i; @@ -5707,17 +5687,15 @@ int clif_party_member_info(struct party_data *p, struct map_session_data *sd) sd = p->data[i].sd; } - snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(sd->mapindex)); - - WBUFW(buf,0)=0x1e9; - WBUFL(buf,2)= sd->status.account_id; - WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable. - WBUFW(buf,10)=sd->bl.x; - WBUFW(buf,12)=sd->bl.y; - WBUFB(buf,14)=0; //Unconfirmed byte, could be online/offline. + WBUFW(buf, 0) = 0x1e9; + WBUFL(buf, 2) = sd->status.account_id; + WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable. + WBUFW(buf,10) = sd->bl.x; + WBUFW(buf,12) = sd->bl.y; + WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline. memcpy(WBUFP(buf,15), p->party.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,80) = (p->party.item&2)?1:0; 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++) { struct party_member* m = &p->party.member[i]; - char map_name[MAP_NAME_LENGTH_EXT]; - if(!m->account_id) continue; 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; 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+45) = (m->online) ? 0 : 1; c++; @@ -6016,27 +5990,23 @@ 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]; - char map_name[MAP_NAME_LENGTH_EXT]; - nullpo_retr(0, sd); - nullpo_retr(0, p); - - snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", map[sd->bl.m].name); - - WBUFW(buf, 0)=0x104; - WBUFL(buf, 2)=sd->status.account_id; - WBUFL(buf, 6)=0; - WBUFW(buf,10)=sd->bl.x; - WBUFW(buf,12)=sd->bl.y; - WBUFB(buf,14)=!online; + nullpo_retv(sd); + nullpo_retv(p); + + WBUFW(buf, 0) = 0x104; + WBUFL(buf, 2) = sd->status.account_id; + WBUFL(buf, 6) = 0; + WBUFW(buf,10) = sd->bl.x; + WBUFW(buf,12) = sd->bl.y; + WBUFB(buf,14) = !online; memcpy(WBUFP(buf,15),p->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); - 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; 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.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,4) = y; WBUFW(buf,6) = cell_type; - memcpy(WBUFP(buf,8),map_name,MAP_NAME_LENGTH_EXT); - if(!type) - clif_send(buf,packet_len(0x192),&bl,AREA); - else - clif_send(buf,packet_len(0x192),&bl,ALL_SAMEMAP); - - return 0; + safestrncpy((char*)WBUFP(buf,8), mapindex_getmapname_ext(map[m].name,NULL), MAP_NAME_LENGTH_EXT); + clif_send(buf,packet_len(0x192),&bl,(!type)?AREA:ALL_SAMEMAP); } /*========================================== @@ -7786,20 +7748,17 @@ void clif_gospel_info(struct map_session_data *sd, int type) * Info about Star Glaldiator save map [Komurka] * type: 1: Information, 0: Map registered *------------------------------------------*/ -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; - 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)); - WFIFOW(fd,0)=0x20e; - memcpy(WFIFOP(fd,2),map_name, MAP_NAME_LENGTH_EXT); - WFIFOL(fd,26)=sd->bl.id; - WFIFOB(fd,30)=feel_level; - WFIFOB(fd,31)=type?1:0; - WFIFOSET(fd, packet_len(0x20e)); + WFIFOW(fd,0) = 0x20e; + 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; + WFIFOB(fd,30) = feel_level; + WFIFOB(fd,31) = type?1:0; + WFIFOSET(fd,packet_len(0x20e)); } /*========================================== @@ -9701,10 +9660,11 @@ void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) /*========================================== * スキル使用(map指定) *------------------------------------------*/ -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; - skill_num = RFIFOW(fd,2); + int 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) return; @@ -9716,7 +9676,7 @@ void clif_parse_UseSkillMap(int fd,struct map_session_data *sd) } pc_delinvincibletimer(sd); - skill_castend_map(sd,skill_num,(char*)RFIFOP(fd,4)); + skill_castend_map(sd,skill_num,map_name); } /*========================================== * メモ要求 diff --git a/src/map/clif.h b/src/map/clif.h index a8193faaa..458dfd281 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -80,8 +80,8 @@ int clif_clearunit_delayed(struct block_list* bl, unsigned int tick); int clif_spawn(struct block_list*); //area int clif_walkok(struct map_session_data*); // self void clif_move(struct unit_data *ud); //area -int 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_changemap(struct map_session_data*,short,int,int); //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_slide(struct block_list *,int,int); // 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 val,int x,int y,int tick); 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_teleportmessage(struct map_session_data *sd,int flag); 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_combo_delay(struct block_list *src,int wait); 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_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_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_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_single(int fd, struct map_session_data *sd); int clif_party_hp(struct map_session_data *sd); diff --git a/src/map/guild.c b/src/map/guild.c index 57582b470..ba0fc2829 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -12,6 +12,7 @@ #include "../common/mapindex.h" #include "../common/showmsg.h" #include "../common/ers.h" +#include "../common/strlib.h" #include "map.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->castle_id=atoi(str[0]); - memcpy(gc->map_name,mapindex_normalize_name(str[1]),MAP_NAME_LENGTH); - memcpy(gc->castle_name,str[2],NAME_LENGTH); - memcpy(gc->castle_event,str[3],NAME_LENGTH); + safestrncpy(gc->map_name,mapindex_getmapname(str[1],NULL),MAP_NAME_LENGTH); + safestrncpy(gc->castle_name,str[2],NAME_LENGTH); + safestrncpy(gc->castle_event,str[3],NAME_LENGTH); idb_put(castle_db,gc->castle_id,gc); @@ -250,15 +251,13 @@ struct guild_castle *guild_castle_search(int gcid) } // mapnameに対応したアジトのgcを返す -struct guild_castle *guild_mapname2gc(char *mapname) +struct guild_castle* guild_mapname2gc(const char* mapname) { int i; - struct guild_castle *gc=NULL; - - mapindex_normalize_name(mapname); - - for(i=0;i<MAX_GUILDCASTLE;i++){ - gc=guild_castle_search(i); + for(i = 0; i < MAX_GUILDCASTLE; i++) + { + struct guild_castle* gc; + gc = guild_castle_search(i); if(!gc) continue; if(strcmp(gc->map_name,mapname)==0) return gc; } diff --git a/src/map/guild.h b/src/map/guild.h index 9f21cd550..07a4b2520 100644 --- a/src/map/guild.h +++ b/src/map/guild.h @@ -24,8 +24,8 @@ struct guild *guild_search(int guild_id); struct guild *guild_searchname(char *str); struct guild_castle *guild_castle_search(int gcid); -struct guild_castle *guild_mapname2gc(char *mapname); -struct guild_castle *guild_mapindex2gc(short mapindex); +struct guild_castle* guild_mapname2gc(const char* mapname); +struct guild_castle* guild_mapindex2gc(short mapindex); struct map_session_data *guild_getavailablesd(struct guild *g); int guild_getindex(struct guild *g,int account_id,int char_id); diff --git a/src/map/map.c b/src/map/map.c index cac652ae8..bec53c20b 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2462,7 +2462,7 @@ int map_readfromcache(struct map_data *m, FILE *fp) return 0; } -int map_addmap(char *mapname) +int map_addmap(char* mapname) { if (strcmpi(mapname,"clear")==0) { map_num=0; @@ -2475,7 +2475,7 @@ int map_addmap(char *mapname) return 1; } - memcpy(map[map_num].name, mapindex_normalize_name(mapname), MAP_NAME_LENGTH); + mapindex_getmapname(mapname, map[map_num].name); map_num++; return 0; } diff --git a/src/map/mob.c b/src/map/mob.c index a7c8f878c..ebfe62aa1 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -311,10 +311,9 @@ struct mob_data *mob_once_spawn_sub(struct block_list *bl, int m, /*========================================== * The MOB appearance for one time (for scripts) *------------------------------------------*/ -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) +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) { - struct mob_data *md = NULL; + struct mob_data* md = NULL; int m, count, lv = 255; if(sd) lv = sd->status.base_level; @@ -327,7 +326,8 @@ int mob_once_spawn (struct map_session_data *sd, const char *mapname, if (m < 0 || amount <= 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, class_<0? mob_get_random_id(-class_-1, battle_config.random_monster_checklv?3:1, lv): @@ -336,8 +336,8 @@ int mob_once_spawn (struct map_session_data *sd, const char *mapname, if (!md) continue; if(class_ == MOBID_EMPERIUM) { - struct guild_castle *gc = guild_mapname2gc(map[md->bl.m].name); - struct guild *g = gc?guild_search(gc->guild_id):NULL; + struct guild_castle* gc = guild_mapname2gc(map[md->bl.m].name); + struct guild* g = gc?guild_search(gc->guild_id):NULL; if(gc) { md->guardian_data = aCalloc(1, sizeof(struct guardian_data)); md->guardian_data->castle = gc; diff --git a/src/map/script.c b/src/map/script.c index ec68e2b9f..8412d0019 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -9576,42 +9576,33 @@ BUILDIN_FUNC(flagemblem) BUILDIN_FUNC(getcastlename) { - char mapname[MAP_NAME_LENGTH_EXT]; - struct guild_castle *gc; - - strncpy(mapname, script_getstr(st,2), MAP_NAME_LENGTH_EXT); - gc = guild_mapname2gc(mapname); - - if(gc) - script_pushconststr(st,gc->castle_name); - else - script_pushconststr(st,""); + const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL); + struct guild_castle* gc = guild_mapname2gc(mapname); + char* name = (gc) ? gc->castle_name : ""; + script_pushconststr(st,name); return 0; } BUILDIN_FUNC(getcastledata) { - char mapname[MAP_NAME_LENGTH_EXT]; - int index=script_getnum(st,3); - const char *event=NULL; - struct guild_castle *gc; - int i; + const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL); + int index = script_getnum(st,3); - strncpy(mapname, script_getstr(st,2), MAP_NAME_LENGTH_EXT); - gc = guild_mapname2gc(mapname); + struct guild_castle* gc = guild_mapname2gc(mapname); if(script_hasdata(st,4) && index==0 && gc) { - event=script_getstr(st,4); + const char* event = script_getstr(st,4); check_event(st, event); guild_addcastleinfoevent(gc->castle_id,17,event); } if(gc){ switch(index){ - case 0: + case 0: { + int i; for(i=1;i<26;i++) // Initialize[AgitInit] guild_castledataload(gc->castle_id,i); - break; + } break; case 1: script_pushint(st,gc->guild_id); break; case 2: @@ -9659,13 +9650,10 @@ BUILDIN_FUNC(getcastledata) BUILDIN_FUNC(setcastledata) { - char mapname[MAP_NAME_LENGTH_EXT]; int index=script_getnum(st,3); int value=script_getnum(st,4); - struct guild_castle *gc; - - strncpy(mapname, script_getstr(st,2), MAP_NAME_LENGTH_EXT); - gc = guild_mapname2gc(mapname); + + struct guild_castle* gc = guild_mapname2gc( mapindex_getmapname(script_getstr(st,2),NULL) ); if(gc) { // Save Data byself First diff --git a/src/map/skill.c b/src/map/skill.c index dee052c43..431278123 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -6328,14 +6328,6 @@ int skill_castend_map (struct map_session_data *sd, int skill_num, const char *m 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_walking(sd,0); @@ -6419,7 +6411,7 @@ int skill_castend_map (struct map_session_data *sd, int skill_num, const char *m return 0; } //Now that there's a mapindex, use that in val3 rather than a string. [Skotlex] - group->val2=(x<<16)|y; + group->val2 = (x<<16)|y; group->val3 = mapindex; } break; diff --git a/src/map/unit.c b/src/map/unit.c index c53a8b6c6..80267bd49 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -709,13 +709,13 @@ int unit_can_move(struct block_list *bl) if (!ud) return 0; - + if (ud->skilltimer != -1 && (!sd || !pc_checkskill(sd, SA_FREECAST) || skill_get_inf2(ud->skillid)&INF2_GUILD_SKILL)) return 0; // prevent moving while casting - + if (DIFF_TICK(ud->canmove_tick, gettick()) > 0) return 0; - + if (sd && ( pc_issit(sd) || sd->vender_id || |