From 856f57d7fb05806cd676112a389ecf8be5ecf54e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 1 May 2015 16:17:42 +0300 Subject: Add script command for send chat command to client. New script command: clientCommand chatcommand args --- src/map/init.c | 1 + src/map/script.c | 21 +++++++++++++++++++++ src/map/script.h | 1 + src/map/send.c | 15 +++++++++++++++ src/map/send.h | 1 + 5 files changed, 39 insertions(+) diff --git a/src/map/init.c b/src/map/init.c index 5327532..e19224a 100644 --- a/src/map/init.c +++ b/src/map/init.c @@ -109,6 +109,7 @@ HPExport void plugin_init (void) addScriptCommand("areatimer", "siiiii*", areaTimer); addScriptCommand("getareadropitem", "siiiiv*", getAreaDropItem); addScriptCommand("setmount", "?", setMount); + addScriptCommand("clientcommand", "s", clientCommand); do_init_langs(); diff --git a/src/map/script.c b/src/map/script.c index b321541..fd54d5b 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1097,3 +1097,24 @@ BUILDIN(setMount) return true; } + +BUILDIN(clientCommand) +{ + TBL_PC* sd = script->rid2sd(st); + + if (sd == NULL) + { + ShowWarning("player not attached\n"); + script->reportsrc(st); + return false; + } + const char *const command = script_getstr(st, 2); + if (!command) + { + ShowWarning("invalid client command\n"); + script->reportsrc(st); + return false; + } + send_client_command(sd, command); + return true; +} diff --git a/src/map/script.h b/src/map/script.h index b9247b3..24210a1 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -40,5 +40,6 @@ BUILDIN(isPcDead); BUILDIN(areaTimer); BUILDIN(getAreaDropItem); BUILDIN(setMount); +BUILDIN(clientCommand); #endif // EVOL_MAP_SCRIPT diff --git a/src/map/send.c b/src/map/send.c index 6fa91fa..b9d826e 100644 --- a/src/map/send.c +++ b/src/map/send.c @@ -288,3 +288,18 @@ void send_online_list(int fd, const char *buf, unsigned size) WFIFOB (fd, size + 4) = 0; WFIFOSET (fd, len); } + +void send_client_command(TBL_PC *sd, const char *const command) +{ + struct SessionExt *data = session_get_bysd(sd); + if (!data || data->clientVersion < 8) + return; + + const unsigned int len = strlen(command); + const int fd = sd->fd; + WFIFOHEAD (fd, len); + WFIFOW (fd, 0) = 0xb16; + WFIFOW (fd, 2) = len + 4; + memcpy (WFIFOP (fd, 4), command, len); + WFIFOSET (fd, len + 4); +} diff --git a/src/map/send.h b/src/map/send.h index ae9f305..efa89ad 100644 --- a/src/map/send.h +++ b/src/map/send.h @@ -26,5 +26,6 @@ void send_slave_say(TBL_PC *sd, const char *const name, const char *const message); void send_online_list(int fd, const char *buf, unsigned size); +void send_client_command(TBL_PC *sd, const char *const command); #endif // EVOL_MAP_PC -- cgit v1.2.3-70-g09d2