diff --git a/README.md b/README.md index 17fb0bd..c1322d6 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Commands are as follows(all can be prefixed with /ms or /multisend): /ms debug on/off - When enabled, all received commands are printed to log and any character with followme updated will spam log with position updates. For debug purposes, obviously. +/ms safemode on/off - When enabled, '/echo' will be inserted for commands missing the leading '/' to prevent chatlog spam + /ms reload - Will reload groups xml. /ms help - Print an ingame reference. diff --git a/src/MultiSend/Commands.cpp b/src/MultiSend/Commands.cpp index 3a925f7..36122a0 100644 --- a/src/MultiSend/Commands.cpp +++ b/src/MultiSend/Commands.cpp @@ -1,4 +1,4 @@ -#include "MultiSend.h" +#include "MultiSend.h" bool MultiSend::HandleCommand(const char* command, int32_t type) { @@ -202,6 +202,32 @@ bool MultiSend::HandleCommand(const char* command, int32_t type) return true; } + else if (_stricmp(arg.c_str(), "safemode") == 0) + { + if (strlen(com) < 2) return true; + com++; + com += GetArg(com, &arg); + + if (_stricmp(arg.c_str(), "on") == 0) + { + _SafeMode = true; + m_AshitaCore->GetChatManager()->Write("MultiSend: Safe mode enabled."); + } + + else if (_stricmp(arg.c_str(), "off") == 0) + { + _SafeMode = false; + m_AshitaCore->GetChatManager()->Write("MultiSend: Safe mode disabled."); + } + + else + { + m_AshitaCore->GetChatManager()->Writef("MultiSend: Safe mode currently %s.", _SafeMode ? "enabled" : "disabled"); + } + + return true; + } + else if (_stricmp(arg.c_str(), "reload") == 0) { LoadGroups(); @@ -219,6 +245,7 @@ bool MultiSend::HandleCommand(const char* command, int32_t type) m_AshitaCore->GetChatManager()->Write("/ms reload - Reloads group file without reloading MultiSend."); m_AshitaCore->GetChatManager()->Write("/ms ignoreself on/off - When enabled, send and sendgroup commands sent by this character will not execute on this character."); m_AshitaCore->GetChatManager()->Write("/ms debug on/off - When enabled, debug prints will be visible."); + m_AshitaCore->GetChatManager()->Write("/ms safemode on/off - When enabled, '/echo' will be inserted for commands missing the leading '/' to prevent chatlog spam."); return true; } diff --git a/src/MultiSend/IO.cpp b/src/MultiSend/IO.cpp index 41895cd..b92a4b6 100644 --- a/src/MultiSend/IO.cpp +++ b/src/MultiSend/IO.cpp @@ -57,8 +57,10 @@ void MultiSend::SendCommand(uint32_t ID, const char* Command) char* Text = new char[248]; memset((void*)Text, 0, 248); memcpy(Text, Command, strlen(Command)); + if (_SafeMode) + SanitizeCommand(Text); SubValues(Text); - + Claim(&(MMF_Pointer->Command.ProcessID), 0); int NextPosition = MMF_Pointer->Command.Position + 1; diff --git a/src/MultiSend/Main.cpp b/src/MultiSend/Main.cpp index 04af330..a2c5f1e 100644 --- a/src/MultiSend/Main.cpp +++ b/src/MultiSend/Main.cpp @@ -84,6 +84,9 @@ bool MultiSend::Initialize(IAshitaCore* core, ILogManager* log, uint32_t id) } _Debug = false; + //SafeMode enabled by Default (to avoid accidental chatlog spam): + //Allows for prepend of "/echo " to commands that are missing a leading "/". + _SafeMode = true; this->Start(); @@ -116,7 +119,7 @@ __declspec(dllexport) void __stdcall CreatePluginInfo(plugininfo_t* lpBuffer) strcpy_s(g_PluginInfo->Author, sizeof(g_PluginInfo->Author), "Thorny"); g_PluginInfo->InterfaceVersion = ASHITA_INTERFACE_VERSION; - g_PluginInfo->PluginVersion = 1.03f; + g_PluginInfo->PluginVersion = 1.04f; g_PluginInfo->Priority = 0; } diff --git a/src/MultiSend/MultiSend.h b/src/MultiSend/MultiSend.h index 68d081d..48f375b 100644 --- a/src/MultiSend/MultiSend.h +++ b/src/MultiSend/MultiSend.h @@ -6,10 +6,10 @@ #endif #define SAFE_DELETE(p) if(p) { delete p; p = NULL; } -#include "C:\Ashita 3\Plugins\ADK\Ashita.h" +#include "C:\Ashita3\Plugins\ADK\Ashita.h" #include "Structs.h" -#include "..\..\pluginheaders\Utilities.h" -#include "..\..\pluginheaders\rapidxml.hpp" +#include "..\..\..\..\..\..\pluginheaders\Utilities.h" +#include "..\..\..\..\..\..\pluginheaders\rapidxml.hpp" #include #include #include @@ -70,6 +70,7 @@ class MultiSend : IPlugin, Ashita::Threading::AS_Thread volatile bool IgnoreSelf; volatile bool _Debug; + volatile bool _SafeMode; public: MultiSend(void); @@ -91,6 +92,7 @@ public: bool ReadCommand(); void SetFollow(bool Active); void SendCommand(uint32_t ID, const char* Command); + void SanitizeCommand(char* Input); std::string SubValues(std::string Input); void SubValues(char* Input); void UpdateName(std::string Name); diff --git a/src/MultiSend/Substitute.cpp b/src/MultiSend/Substitute.cpp index 711020d..e0a58e8 100644 --- a/src/MultiSend/Substitute.cpp +++ b/src/MultiSend/Substitute.cpp @@ -65,4 +65,23 @@ void MultiSend::SubValues(char* Input) const char* base = Working.c_str(); memset(Input, 0, 248); memcpy(Input, base, strlen(base)); -} \ No newline at end of file +} + +void MultiSend::SanitizeCommand(char* Input) +{ + if (Input[0] != '/') + { + if (_Debug) + m_AshitaCore->GetChatManager()->Write("Detected command without leading '/'. Prepending '/echo'..."); + char* prepend = "/echo "; + size_t plen = strlen(prepend); + memmove(Input + plen, Input, strlen(Input) + 1); + memcpy(Input, prepend, strlen(prepend)); + } + else + { + if (_Debug) + m_AshitaCore->GetChatManager()->Write("No Sanitization Needed."); + } + +}