diff options
author | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-11-12 04:15:18 +0000 |
---|---|---|
committer | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-11-12 04:15:18 +0000 |
commit | e9b4674c08837939dba88d8cfed7494931ac647a (patch) | |
tree | 272ec2980a7c43bba9f55b7352c1f6e6e5f363cf /src/map | |
parent | 74b3120bb7776371ed815c6c038fd467ef4ac366 (diff) | |
download | hercules-e9b4674c08837939dba88d8cfed7494931ac647a.tar.gz hercules-e9b4674c08837939dba88d8cfed7494931ac647a.tar.bz2 hercules-e9b4674c08837939dba88d8cfed7494931ac647a.tar.xz hercules-e9b4674c08837939dba88d8cfed7494931ac647a.zip |
* Fixed @addwarp crashing the map server (bugreport:390).
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11719 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 30 | ||||
-rw-r--r-- | src/map/npc.c | 43 | ||||
-rw-r--r-- | src/map/npc.h | 2 |
3 files changed, 61 insertions, 14 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 32a07e132..ed16dcdf1 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -5492,27 +5492,33 @@ int atcommand_npcmove(const int fd, struct map_session_data* sd, const char* com *------------------------------------------*/ int atcommand_addwarp(const int fd, struct map_session_data* sd, const char* command, const char* message) { - char w1[64], w3[64], w4[64]; - int x,y,ret=0; + char mapname[32]; + int x,y; + unsigned short m; + struct npc_data* nd; + nullpo_retr(-1, sd); - if (!message || !*message || sscanf(message, "%23s %d %d[^\n]", atcmd_player_name, &x, &y) < 3) { + if (!message || !*message || sscanf(message, "%31s %d %d", mapname, &x, &y) < 3) { clif_displaymessage(fd, "usage: @addwarp <mapname> <X> <Y>."); return -1; } - sprintf(w1,"%s,%d,%d", mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y); - sprintf(w3,"%s%d%d%d%d", atcmd_player_name,sd->bl.x, sd->bl.y, x, y); - sprintf(w4,"1,1,%s,%d,%d", atcmd_player_name, x, y); - - // FIXME check if it failed [FlavioJS] - npc_parse_warp(w1, "warp", w3, w4, NULL, NULL, "console"); + m = mapindex_name2id(mapname); + if( m == 0 ) + { + sprintf(atcmd_output, "Unknown map '%s'.", mapname); + clif_displaymessage(fd, atcmd_output); + return -1; + } - sprintf(atcmd_output, "New warp NPC => %s",w3); + nd = npc_add_warp(sd->bl.m, sd->bl.x, sd->bl.y, 1, 1, m, x, y); + if( nd == NULL ) + return -1; + sprintf(atcmd_output, "New warp NPC '%s' created.", nd->exname); clif_displaymessage(fd, atcmd_output); - - return ret; + return 0; } /*========================================== diff --git a/src/map/npc.c b/src/map/npc.c index 4752991c7..5d98f761e 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1481,8 +1481,49 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta } } +struct npc_data* npc_add_warp(short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y) +{ + int i; + struct npc_data *nd; + + CREATE(nd, struct npc_data, 1); + nd->bl.id = npc_get_new_npc_id(); + nd->n = map_addnpc(from_mapid, nd); + nd->bl.prev = nd->bl.next = NULL; + nd->bl.m = from_mapid; + nd->bl.x = from_x; + nd->bl.y = from_y; + safestrncpy(nd->name, "", ARRAYLENGTH(nd->name));// empty display name + snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp_%d_%d_%d", from_mapid, from_x, from_y); + for( i = 0; npc_name2id(nd->exname) != NULL; ++i ) + snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp%d_%d_%d_%d", i, from_mapid, from_x, from_y); + + if( battle_config.warp_point_debug ) + nd->class_ = WARP_DEBUG_CLASS; + else + nd->class_ = WARP_CLASS; + nd->speed = 200; + + nd->u.warp.mapindex = to_mapindex; + nd->u.warp.x = to_x; + nd->u.warp.y = to_y; + nd->u.warp.xs = xs+2;// TODO why +2? [FlavioJS] + nd->u.warp.ys = xs+2; + nd->bl.type = BL_NPC; + nd->bl.subtype = WARP; + npc_setcells(nd); + map_addblock(&nd->bl); + status_set_viewdata(&nd->bl, nd->class_); + status_change_init(&nd->bl); + unit_dataset(&nd->bl); + clif_spawn(&nd->bl); + strdb_put(npcname_db, nd->exname, nd); + + return nd; +} + /// Parses a warp npc. -const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath) +static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath) { int x, y, xs, ys, to_x, to_y, m; unsigned short i; diff --git a/src/map/npc.h b/src/map/npc.h index 07658d654..a21cfd746 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -53,7 +53,7 @@ int npc_buysellsel(struct map_session_data* sd, int id, int type); int npc_buylist(struct map_session_data* sd,int n, unsigned short* item_list); int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list); int npc_parse_mob2(struct spawn_data* mob, int index); // [Wizputer] -const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath); +struct npc_data* npc_add_warp(short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y); int npc_globalmessage(const char* name,const char* mes); void npc_setcells(struct npc_data* nd); |