diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/battleground.h | 4 | ||||
-rw-r--r-- | src/map/chat.h | 2 | ||||
-rw-r--r-- | src/map/guild.c | 4 | ||||
-rw-r--r-- | src/map/map.h | 4 | ||||
-rw-r--r-- | src/map/mob.c | 46 | ||||
-rw-r--r-- | src/map/mob.h | 2 | ||||
-rw-r--r-- | src/map/npc.c | 20 | ||||
-rw-r--r-- | src/map/pc.h | 2 | ||||
-rw-r--r-- | src/map/script.c | 6 |
9 files changed, 47 insertions, 43 deletions
diff --git a/src/map/battleground.h b/src/map/battleground.h index 946ac2692..c2b74a534 100644 --- a/src/map/battleground.h +++ b/src/map/battleground.h @@ -22,8 +22,8 @@ struct battleground_data { // BG Cementery unsigned short mapindex, x, y; // Logout Event - char logout_event[50]; - char die_event[50]; + char logout_event[EVENT_NAME_LENGTH]; + char die_event[EVENT_NAME_LENGTH]; }; void do_init_battleground(void); diff --git a/src/map/chat.h b/src/map/chat.h index be3efb513..b80832d3d 100644 --- a/src/map/chat.h +++ b/src/map/chat.h @@ -22,7 +22,7 @@ struct chat_data { uint32 maxLvl; // maximum base level allowed to join struct map_session_data* usersd[20]; struct block_list* owner; - char npc_event[50]; + char npc_event[EVENT_NAME_LENGTH]; }; diff --git a/src/map/guild.c b/src/map/guild.c index 47abf3cac..c80b124ef 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -36,7 +36,7 @@ static DBMap* guild_infoevent_db; // int guild_id -> struct eventlist* static DBMap* guild_castleinfoevent_db; // int castle_id_index -> struct eventlist* struct eventlist { - char name[50]; + char name[EVENT_NAME_LENGTH]; struct eventlist *next; }; @@ -1545,7 +1545,7 @@ int guild_broken(int guild_id,int flag) struct guild_castle *gc=NULL; struct map_session_data *sd; int i; - char name[50]; + char name[EVENT_NAME_LENGTH]; if(flag!=0 || g==NULL) return 0; diff --git a/src/map/map.h b/src/map/map.h index 456384360..3241efea1 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -159,6 +159,8 @@ enum { #define CHATROOM_PASS_SIZE (8 + 1) //Max allowed chat text length #define CHAT_SIZE_MAX (255 + 1) +//24 for npc name + 24 for label + 2 for a "::" and 1 for EOS +#define EVENT_NAME_LENGTH ( NAME_LENGTH * 2 + 3 ) #define DEFAULT_AUTOSAVE_INTERVAL 5*60*1000 @@ -268,7 +270,7 @@ struct spawn_data { unsigned ai :2; //Holds if mob is special ai. unsigned dynamic :1; //Whether this data is indexed by a map's dynamic mob list } state; - char name[NAME_LENGTH],eventname[50]; //Name/event + char name[NAME_LENGTH],eventname[EVENT_NAME_LENGTH]; //Name/event }; diff --git a/src/map/mob.c b/src/map/mob.c index ccb4ab923..0a99b83b1 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -160,7 +160,8 @@ struct view_data * mob_get_viewdata(int class_) *------------------------------------------*/ int mob_parse_dataset(struct spawn_data *data) { - int i; + size_t len; + //FIXME: This implementation is not stable, npc scripts will stop working once MAX_MOB_DB changes value! [Skotlex] if(data->class_ > 2*MAX_MOB_DB){ // large/tiny mobs [Valaris] data->state.size=2; @@ -173,32 +174,33 @@ int mob_parse_dataset(struct spawn_data *data) if ((!mobdb_checkid(data->class_) && !mob_is_clone(data->class_)) || !data->num) return 0; - if (data->eventname[0]) - { - if(npc_event_isspecial(data->eventname)) - { //Portable monster big/small implementation. [Skotlex] - i = atoi(data->eventname); - if (i) { - if (i&2) - data->state.size=1; - else if (i&4) - data->state.size=2; - if (i&8) - data->state.ai=1; - data->eventname[0] = '\0'; //Clear event as it is not used. - } - } else if( ( i = strlen(data->eventname) ) > 0 ) { - if (data->eventname[i-1] == '"') - data->eventname[i-1] = '\0'; //Remove trailing quote. - if (data->eventname[0] == '"') //Strip leading quotes - memmove(data->eventname, data->eventname+1, i-1); + if( npc_event_isspecial(data->eventname) ) + {//Portable monster big/small implementation. [Skotlex] + int i = atoi(data->eventname); + + if( i ) + { + if( i&2 ) + data->state.size = 1; + else if( i&4 ) + data->state.size = 2; + if( i&8 ) + data->state.ai = 1; } + data->eventname[0] = '\0'; //Clear event as it is not used. + } + else if( ( len = strlen(data->eventname) ) > 0 ) + { + if( data->eventname[len-1] == '"' ) + data->eventname[len-1] = '\0'; //Remove trailing quote. + if( data->eventname[0] == '"' ) //Strip leading quotes + memmove(data->eventname, data->eventname+1, len-1); } if(strcmp(data->name,"--en--")==0) - strncpy(data->name,mob_db(data->class_)->name,NAME_LENGTH-1); + safestrncpy(data->name, mob_db(data->class_)->name, sizeof(data->name)); else if(strcmp(data->name,"--ja--")==0) - strncpy(data->name,mob_db(data->class_)->jname,NAME_LENGTH-1); + safestrncpy(data->name, mob_db(data->class_)->jname, sizeof(data->name)); return 1; } diff --git a/src/map/mob.h b/src/map/mob.h index 6978d7ebc..6658c96d3 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -160,7 +160,7 @@ struct mob_data { short skillidx; unsigned int skilldelay[MAX_MOBSKILL]; - char npc_event[50]; + char npc_event[EVENT_NAME_LENGTH]; }; diff --git a/src/map/npc.c b/src/map/npc.c index 1ebed0f00..c5c18aea0 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -105,7 +105,7 @@ struct view_data* npc_get_viewdata(int class_) int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd) { - char name[NAME_LENGTH*2+3]; + char name[EVENT_NAME_LENGTH]; if( nd->touching_id ) return 0; // Attached a player already. Can't trigger on anyone else. @@ -119,7 +119,7 @@ int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd) int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd) { - char name[NAME_LENGTH*2+3]; + char name[EVENT_NAME_LENGTH]; if( sd->areanpc_id == nd->bl.id ) return 0; @@ -245,7 +245,7 @@ int npc_event_export(char* lname, void* data, va_list ap) if ((lname[0]=='O' || lname[0]=='o')&&(lname[1]=='N' || lname[1]=='n')) { struct event_data *ev; - char buf[NAME_LENGTH*2+3]; + char buf[EVENT_NAME_LENGTH]; char* p = strchr(lname, ':'); // エクスポートされる ev = (struct event_data *) aMalloc(sizeof(struct event_data)); @@ -644,7 +644,7 @@ void npc_timerevent_quit(struct map_session_data* sd) // Execute OnTimerQuit if( nd && nd->bl.type == BL_NPC ) { - char buf[NAME_LENGTH*2+3]; + char buf[EVENT_NAME_LENGTH]; struct event_data *ev; snprintf(buf, ARRAYLENGTH(buf), "%s::OnTimerQuit", nd->exname); @@ -821,7 +821,7 @@ int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap) sd->bl.y < nd->bl.y - ys || sd->bl.y > nd->bl.y + ys || pc_ishiding(sd) || leavemap ) { - char name[NAME_LENGTH*2+3]; + char name[EVENT_NAME_LENGTH]; nd->touching_id = sd->touching_id = 0; snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_name); @@ -902,7 +902,7 @@ int npc_touch_areanpc(struct map_session_data* sd, int m, int x, int y) int npc_touch_areanpc2(struct mob_data *md) { int i, m = md->bl.m, x = md->bl.x, y = md->bl.y, id; - char eventname[NAME_LENGTH*2+3]; + char eventname[EVENT_NAME_LENGTH]; struct event_data* ev; int xs, ys; @@ -1152,7 +1152,7 @@ int npc_buysellsel(struct map_session_data* sd, int id, int type) //npc_buylist for script-controlled shops. static int npc_buylist_sub(struct map_session_data* sd, int n, unsigned short* item_list, struct npc_data* nd) { - char npc_ev[NAME_LENGTH*2+3]; + char npc_ev[EVENT_NAME_LENGTH]; int i; int key_nameid = 0; int key_amount = 0; @@ -1387,7 +1387,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list) /// npc_selllist for script-controlled shops static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_list, struct npc_data* nd) { - char npc_ev[NAME_LENGTH*2+3]; + char npc_ev[EVENT_NAME_LENGTH]; int i, idx; int key_nameid = 0; int key_amount = 0; @@ -2219,7 +2219,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) { struct event_data* ev; - char buf[NAME_LENGTH*2+3]; // 24 for npc name + 24 for label + 2 for a "::" and 1 for EOS + char buf[EVENT_NAME_LENGTH]; snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); // generate the data and insert it @@ -2407,7 +2407,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) { struct event_data* ev; - char buf[NAME_LENGTH*2+3]; // 24 for npc name + 24 for label + 2 for a "::" and 1 for EOS + char buf[EVENT_NAME_LENGTH]; snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); // generate the data and insert it diff --git a/src/map/pc.h b/src/map/pc.h index beae8a0a3..191c51eb6 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -378,7 +378,7 @@ struct map_session_data { unsigned short pvp_rank, pvp_lastusers; unsigned short pvp_won, pvp_lost; - char eventqueue[MAX_EVENTQUEUE][NAME_LENGTH*2+3]; + char eventqueue[MAX_EVENTQUEUE][EVENT_NAME_LENGTH]; int eventtimer[MAX_EVENTTIMER]; unsigned short eventcount; // [celest] diff --git a/src/map/script.c b/src/map/script.c index 739104f32..bf0b4f652 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -585,7 +585,7 @@ static void check_event(struct script_state *st, const char *evt) } else { - ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n", evt); + ShowWarning("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n", evt); script_reportsrc(st); } } @@ -8187,8 +8187,8 @@ BUILDIN_FUNC(cmdothernpc) // Added by RoVeRT { const char* npc = script_getstr(st,2); const char* command = script_getstr(st,3); - char event[51]; - snprintf(event, 51, "%s::OnCommand%s", npc, command); + char event[EVENT_NAME_LENGTH]; + snprintf(event, sizeof(event), "%s::OnCommand%s", npc, command); check_event(st, event); npc_event_do(event); return 0; |