From 5232d8fa98cbfb7a85e15b182eeb1e22d5b7376a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 30 Nov 2014 17:11:40 +0300 Subject: map: send full moving path to client. Also fix memory issue in string translation. --- src/map/clif.c | 23 ++++++++++++++++++----- src/map/clif.h | 3 +++ src/map/init.c | 2 ++ src/map/send.c | 31 +++++++++++++++++++++++++++++++ src/map/send.h | 1 + 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index f92a9f7..4e7f47b 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -78,7 +78,8 @@ void eclif_charnameack(int *fdPtr, struct block_list *bl) int fd = *fdPtr; struct map_session_data* sd = (struct map_session_data*)session[fd]->session_data; const char *tr = lang_pctrans(((TBL_NPC*)bl)->name, sd); - const int len = 8 + strlen(tr) + 1; + const int trLen = strlen(tr); + const int len = 8 + trLen + 1; // if no recipient specified just update nearby clients if (fd == 0) { @@ -87,7 +88,7 @@ void eclif_charnameack(int *fdPtr, struct block_list *bl) WBUFW(buf, 0) = 0xB01; WBUFW(buf, 2) = len; WBUFL(buf, 4) = bl->id; - memcpy(WBUFP(buf, 8), tr, len); + memcpy(WBUFP(buf, 8), tr, trLen); clif->send(buf, len, bl, AREA); aFree(buf); } @@ -97,7 +98,7 @@ void eclif_charnameack(int *fdPtr, struct block_list *bl) WFIFOW(fd, 0) = 0xB01; WFIFOW(fd, 2) = len; WFIFOL(fd, 4) = bl->id; - memcpy(WFIFOP(fd, 8), tr, len); + memcpy(WFIFOP(fd, 8), tr, trLen); WFIFOSET(fd, len); } } @@ -182,7 +183,7 @@ void eclif_sendlook(struct block_list *bl, int *id, int *type, int *val, int *va bool eclif_send(const void* buf, int *len, struct block_list* bl, enum send_target *type) { if (*type == SELF) - return; + return true; eclif_handle_invisible_map(bl, *type); return true; } @@ -200,13 +201,14 @@ int eclif_send_actual(int *fd, void *buf, int *len) if (*len >= 2) { const int packet = RBUFW (buf, 0); - if (packet == 0xb02 || packet == 0xb03) + if (packet >= 0xb02 && packet <= 0xb05) { struct SessionExt *data = session_get(*fd); if (!data) return 0; if (data->clientVersion < 3) { // not sending new packets to old clients + ShowWarning("skip packet %d\n", packet); hookStop(); return 0; } @@ -224,3 +226,14 @@ void eclif_set_unit_idle_post(struct block_list* bl, struct map_session_data *ts if (bl->type == BL_MOB && tsd) send_mob_info(bl, tsd ? &tsd->bl : bl, *target); } + +void eclif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, + struct unit_data* ud, enum send_target *target) +{ + send_advmoving(ud, tsd ? &tsd->bl : bl, *target); +} + +void eclif_move(struct unit_data *ud) +{ + send_advmoving(ud, ud->bl, AREA_WOS); +} diff --git a/src/map/clif.h b/src/map/clif.h index 3b28390..79da4a4 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -19,5 +19,8 @@ void eclif_authok_post(struct map_session_data *sd); void eclif_changemap_post(struct map_session_data *sd, short *m, int *x, int *y); void eclif_set_unit_idle_post(struct block_list* bl, struct map_session_data *tsd, enum send_target *target); +void eclif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, + struct unit_data* ud, enum send_target *target); +void eclif_move(struct unit_data *ud); #endif // EVOL_MAP_CLIF diff --git a/src/map/init.c b/src/map/init.c index fb91cfe..2794692 100644 --- a/src/map/init.c +++ b/src/map/init.c @@ -115,6 +115,8 @@ HPExport void plugin_init (void) addHookPost("clif->changemap", eclif_changemap_post); addHookPost("clif->set_unit_idle", eclif_set_unit_idle_post); addHookPost("status->set_viewdata", estatus_set_viewdata_post); + addHookPost("clif->set_unit_walking", eclif_set_unit_walking); + addHookPost("clif->move", eclif_move); langScriptId = script->add_str("Lang"); } diff --git a/src/map/send.c b/src/map/send.c index 59402ad..b3ab051 100644 --- a/src/map/send.c +++ b/src/map/send.c @@ -12,6 +12,7 @@ #include "../../../common/strlib.h" #include "../../../map/mob.h" #include "../../../map/pc.h" +#include "../../../map/unit.h" #include "map/send.h" @@ -119,3 +120,33 @@ void send_mob_info(struct block_list* bl1, struct block_list* bl2, clif->send(&buf, sizeof(buf), bl2, target); } + +void send_advmoving(struct unit_data* ud, struct block_list *tbl, enum send_target target) +{ + if (!ud) + return; + + struct block_list *bl = ud->bl; + + if (ud->walkpath.path_len <= ud->walkpath.path_pos) + return; + const bool haveMoves = (ud->walkpath.path_len > ud->walkpath.path_pos); + + int i = 14; + const int len = ud->walkpath.path_len - ud->walkpath.path_pos; + if (haveMoves) + i += len; + + char *buf; + CREATE(buf, char, i); + WBUFW (buf, 0) = 0xb04; + WBUFW (buf, 2) = i; + WBUFL (buf, 4) = bl->id; + WBUFW (buf, 8) = status->get_speed(bl); + WBUFW (buf, 10) = bl->x; + WBUFW (buf, 12) = bl->y; + if (haveMoves) + memcpy(buf + 14, ud->walkpath.path + ud->walkpath.path_pos, len); + clif->send(buf, i, tbl, target); + aFree(buf); +} diff --git a/src/map/send.h b/src/map/send.h index 05b20f1..d66bca0 100644 --- a/src/map/send.h +++ b/src/map/send.h @@ -11,5 +11,6 @@ void send_changelook(int fd, int id, int type, int val); void send_mapmask(int fd, int mask); void send_mapmask_brodcast(const int map, const int mask); void send_mob_info(struct block_list* bl1, struct block_list* bl2, enum send_target target); +void send_advmoving(struct unit_data* ud, struct block_list *tbl, enum send_target target); #endif // EVOL_MAP_PC -- cgit v1.2.3-70-g09d2