summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt1
-rw-r--r--src/map/atcommand.c30
-rw-r--r--src/map/npc.c43
-rw-r--r--src/map/npc.h2
4 files changed, 62 insertions, 14 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 6d87bfb77..9863be09c 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,7 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/11/13
+ * Fixed @addwarp crashing the map server (bugreport:390). [FlavioJS]
* The Forget-me-not status now behaves like Decrease AGI [ultramage]
- doesn't cancel Impressive Riff, Wind Walker, True Sight (bugreport:187)
- additionally, it doesn't cancel Cart Boost
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);