From d5e9d1ecbee0f7540acbe4343bd68e6482e8394a Mon Sep 17 00:00:00 2001 From: mekolat Date: Thu, 14 Apr 2016 11:08:39 -0400 Subject: implement SMSG_SCRIPT_MESSAGE --- src/map/clif.cpp | 20 ++++++++++++++++++++ src/map/clif.hpp | 1 + src/map/script-fun.cpp | 23 +++++++++++++++++++++++ tools/protocol.py | 18 ++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 386ac63..bf20b57 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -3886,6 +3886,26 @@ void clif_npc_send_title(Session *s, BlockId npcid, XString msg) send_buffer(s, buf); } +void clif_server_message(dumb_ptr sd, uint8_t type, XString msg) +{ + nullpo_retv(sd); + + size_t msg_len = msg.size() + 8; + if (msg_len > 512) + return; + + // for newer clients + Packet_Head<0x0229> head_229; + head_229.message_type = type; + Buffer buf = create_vpacket<0x0229, 5, 1>(head_229, msg); + + // falback for older clients + Packet_Head<0x008d> head_8d; + Buffer altbuf = create_vpacket<0x008d, 8, 1>(head_8d, msg); + + clif_send(buf, sd, SendWho::SELF, wrap(5), altbuf); +} + void clif_change_music(dumb_ptr sd, XString music) { nullpo_retv(sd); diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 28f58a9..c339cfd 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -105,6 +105,7 @@ void clif_sitnpc_towards(dumb_ptr sd, dumb_ptr nd, D void clif_setnpcdirection(dumb_ptr nd, DIR direction); void clif_setnpcdirection_towards(dumb_ptr sd, dumb_ptr nd, DIR direction); void clif_npc_send_title(Session *s, BlockId npcid, XString msg); +void clif_server_message(dumb_ptr, uint8_t, XString msg); void clif_change_music(dumb_ptr sd, XString music); void clif_npc_action(dumb_ptr, BlockId, short, int, short, short); void clif_send_mask(dumb_ptr, int); diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index fe5a961..0d211a7 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2949,6 +2949,28 @@ void builtin_title(ScriptState *st) clif_npc_send_title(sd->sess, st->oid, msg); } +static +void builtin_smsg(ScriptState *st) +{ + dumb_ptr sd = script_rid2sd(st); + if (HARG(2)) + { + CharName player = stringish(ZString(conv_str(st, &AARG(2)))); + sd = map_nick2sd(player); + if (sd == nullptr) + return; + } + + int type = HARG(1) ? conv_num(st, &AARG(0)) : 0; + ZString msg = ZString(conv_str(st, (HARG(1) ? &AARG(1) : &AARG(0)))); + if (sd == nullptr) + return; + if (type < 0 || type > 0xFF) + type = 0; + + clif_server_message(sd, type, msg); +} + static void builtin_music(ScriptState *st) { @@ -3490,6 +3512,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(message, "Ps"_s, '\0'), BUILTIN(npctalk, "ss?"_s, '\0'), BUILTIN(title, "s"_s, '\0'), + BUILTIN(smsg, "e??"_s, '\0'), BUILTIN(music, "s"_s, '\0'), BUILTIN(mapmask, "i?"_s, '\0'), BUILTIN(getmask, ""_s, 'i'), diff --git a/tools/protocol.py b/tools/protocol.py index 5d27f0d..800c3ec 100755 --- a/tools/protocol.py +++ b/tools/protocol.py @@ -4761,6 +4761,24 @@ def build_context(): Change npc title ''', ) + map_user.s(0x0229, 'script message', + define='SMSG_SCRIPT_MESSAGE', + head=[ + at(0, u16, 'packet id'), + at(2, u16, 'packet length'), + at(4, u8, 'message type'), + ], + head_size=5, + repeat=[ + at(0, u8, 'c'), + ], + repeat_size=1, + pre=[NOTHING], + post=[PRETTY], + desc=''' + Send server message + ''', + ) # TOC_LOGINCHAR # login char -- cgit v1.2.3-60-g2f50 From d3c96421dd371db34119de1437fe7f25a05dc4bc Mon Sep 17 00:00:00 2001 From: mekolat Date: Fri, 15 Apr 2016 11:12:56 -0400 Subject: implement SMSG_PLAYER_CLIENT_COMMAND --- src/map/clif.cpp | 14 ++++++++++++++ src/map/clif.hpp | 1 + src/map/script-fun.cpp | 19 +++++++++++++++++-- tools/protocol.py | 17 +++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index bf20b57..df21a88 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -3906,6 +3906,20 @@ void clif_server_message(dumb_ptr sd, uint8_t type, XString ms clif_send(buf, sd, SendWho::SELF, wrap(5), altbuf); } +void clif_remote_command(dumb_ptr sd, XString cmd) +{ + nullpo_retv(sd); + + size_t msg_len = cmd.size() + 4; + if (msg_len > 512) + return; + + Packet_Head<0x0230> head_230; + Buffer buf = create_vpacket<0x0230, 4, 1>(head_230, cmd); + + clif_send(buf, sd, SendWho::SELF, wrap(6)); +} + void clif_change_music(dumb_ptr sd, XString music) { nullpo_retv(sd); diff --git a/src/map/clif.hpp b/src/map/clif.hpp index c339cfd..4783290 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -106,6 +106,7 @@ void clif_setnpcdirection(dumb_ptr nd, DIR direction); void clif_setnpcdirection_towards(dumb_ptr sd, dumb_ptr nd, DIR direction); void clif_npc_send_title(Session *s, BlockId npcid, XString msg); void clif_server_message(dumb_ptr, uint8_t, XString msg); +void clif_remote_command(dumb_ptr, XString); void clif_change_music(dumb_ptr sd, XString music); void clif_npc_action(dumb_ptr, BlockId, short, int, short, short); void clif_send_mask(dumb_ptr, int); diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 0d211a7..07076d5 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2957,8 +2957,6 @@ void builtin_smsg(ScriptState *st) { CharName player = stringish(ZString(conv_str(st, &AARG(2)))); sd = map_nick2sd(player); - if (sd == nullptr) - return; } int type = HARG(1) ? conv_num(st, &AARG(0)) : 0; @@ -2971,6 +2969,22 @@ void builtin_smsg(ScriptState *st) clif_server_message(sd, type, msg); } +static +void builtin_remotecmd(ScriptState *st) +{ + dumb_ptr sd = script_rid2sd(st); + if (HARG(1)) + { + CharName player = stringish(ZString(conv_str(st, &AARG(1)))); + sd = map_nick2sd(player); + } + + ZString msg = ZString(conv_str(st, &AARG(0))); + if (sd == nullptr) + return; + clif_remote_command(sd, msg); +} + static void builtin_music(ScriptState *st) { @@ -3513,6 +3527,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(npctalk, "ss?"_s, '\0'), BUILTIN(title, "s"_s, '\0'), BUILTIN(smsg, "e??"_s, '\0'), + BUILTIN(remotecmd, "s?"_s, '\0'), BUILTIN(music, "s"_s, '\0'), BUILTIN(mapmask, "i?"_s, '\0'), BUILTIN(getmask, ""_s, 'i'), diff --git a/tools/protocol.py b/tools/protocol.py index 800c3ec..0adc95a 100755 --- a/tools/protocol.py +++ b/tools/protocol.py @@ -4779,6 +4779,23 @@ def build_context(): Send server message ''', ) + map_user.s(0x0230, 'remote client command', + define='SMSG_PLAYER_CLIENT_COMMAND', + head=[ + at(0, u16, 'packet id'), + at(2, u16, 'packet length'), + ], + head_size=4, + repeat=[ + at(0, u8, 'c'), + ], + repeat_size=1, + pre=[NOTHING], + post=[PRETTY], + desc=''' + Execute a client command remotely + ''', + ) # TOC_LOGINCHAR # login char -- cgit v1.2.3-60-g2f50