diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-01 16:17:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-01 16:17:42 +0300 |
commit | 856f57d7fb05806cd676112a389ecf8be5ecf54e (patch) | |
tree | 7b21a2c6989de6b79d61acaa7d3a1c663a76fd14 /src/map | |
parent | 4284e5bd3d3c3fd387b4e3a9b73220cafc0f2188 (diff) | |
download | plugin-856f57d7fb05806cd676112a389ecf8be5ecf54e.tar.gz plugin-856f57d7fb05806cd676112a389ecf8be5ecf54e.tar.bz2 plugin-856f57d7fb05806cd676112a389ecf8be5ecf54e.tar.xz plugin-856f57d7fb05806cd676112a389ecf8be5ecf54e.zip |
Add script command for send chat command to client.
New script command: clientCommand chatcommand args
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/init.c | 1 | ||||
-rw-r--r-- | src/map/script.c | 21 | ||||
-rw-r--r-- | src/map/script.h | 1 | ||||
-rw-r--r-- | src/map/send.c | 15 | ||||
-rw-r--r-- | src/map/send.h | 1 |
5 files changed, 39 insertions, 0 deletions
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 |