Browse Source

1.04 - Adding safemode feature to prevent accidental chatlog spam.

pull/1/head
zombie343 6 years ago
parent
commit
e4e4f65868
  1. 2
      README.md
  2. 29
      src/MultiSend/Commands.cpp
  3. 2
      src/MultiSend/IO.cpp
  4. 5
      src/MultiSend/Main.cpp
  5. 6
      src/MultiSend/MultiSend.h
  6. 19
      src/MultiSend/Substitute.cpp

2
README.md

@ -17,6 +17,8 @@ Commands are as follows(all can be prefixed with /ms or /multisend): @@ -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.

29
src/MultiSend/Commands.cpp

@ -1,4 +1,4 @@ @@ -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) @@ -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) @@ -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;
}

2
src/MultiSend/IO.cpp

@ -57,6 +57,8 @@ void MultiSend::SendCommand(uint32_t ID, const char* Command) @@ -57,6 +57,8 @@ 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);

5
src/MultiSend/Main.cpp

@ -84,6 +84,9 @@ bool MultiSend::Initialize(IAshitaCore* core, ILogManager* log, uint32_t id) @@ -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) @@ -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;
}

6
src/MultiSend/MultiSend.h

@ -8,8 +8,8 @@ @@ -8,8 +8,8 @@
#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 <time.h>
#include <list>
#include <map>
@ -70,6 +70,7 @@ class MultiSend : IPlugin, Ashita::Threading::AS_Thread @@ -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: @@ -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);

19
src/MultiSend/Substitute.cpp

@ -66,3 +66,22 @@ void MultiSend::SubValues(char* Input) @@ -66,3 +66,22 @@ void MultiSend::SubValues(char* Input)
memset(Input, 0, 248);
memcpy(Input, base, strlen(base));
}
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.");
}
}

Loading…
Cancel
Save