Multisend is a replacement for servo. No synchronization is needed, just load and go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

133 lines
3.6 KiB

#include "MultiSend.h"
bool MultiSend::ReadCommand()
{
if (p_MMF->Command.Command[s_position].active)
{
if (CheckMatch(p_MMF->Command.Command[s_position]))
{
const char* text = new char[248];
memcpy((void*)text, &(p_MMF->Command.Command[s_position].command), 248);
if (c_debug)
{
m_AshitaCore->GetChatManager()->Writef("Sending command: %s", text);
}
if (m_AshitaCore->GetPluginManager()->GetPlugin("Shorthand"))
{
m_AshitaCore->GetChatManager()->QueueCommand(text, -1);
}
else
{
m_AshitaCore->GetChatManager()->QueueCommand(text, 0);
}
delete text;
}
s_position++;
if (s_position == 100) s_position = 0;
return true;
}
return false;
}
void MultiSend::SendCommand(multisend_type type, uint32_t param, const char* Command)
{
char* Text = new char[248];
memset((void*)Text, 0, 248);
memcpy(Text, Command, strlen(Command));
if (c_safemode)
SanitizeCommand(Text);
SubValues(Text);
Claim(&(p_MMF->Command.ProcessID), 0);
int NextPosition = p_MMF->Command.Position + 1;
if (NextPosition == 100) NextPosition = 0;
p_MMF->Command.Command[NextPosition].active = false;
memset(&(p_MMF->Command.Command[p_MMF->Command.Position].command), 0, 248);
if (strlen(Text) > 247)
{
memcpy(&(p_MMF->Command.Command[p_MMF->Command.Position].command), Text, 247);
}
else
{
memcpy(&(p_MMF->Command.Command[p_MMF->Command.Position].command), Text, strlen(Text));
}
if (c_debug)
{
m_AshitaCore->GetChatManager()->Writef("Publishing position %d : %s", p_MMF->Command.Position, Text);
}
p_MMF->Command.Command[p_MMF->Command.Position].sender_process_id = GetCurrentProcessId();
p_MMF->Command.Command[p_MMF->Command.Position].type = type;
p_MMF->Command.Command[p_MMF->Command.Position].param = param;
p_MMF->Command.Command[p_MMF->Command.Position].active = true;
p_MMF->Command.Position = NextPosition;
InterlockedExchange(&(p_MMF->Command.ProcessID), 0);
delete Text;
}
void MultiSend::UpdateName(std::string Name)
{
Claim(&(p_MMF->Name.ProcessID), 0xFFFF0000);
bool Written = false;
for (int x = 0; x < 100; x++)
{
if (!p_MMF->Name.Names[x].Active)
{
if (!Written)
{
memcpy(&(p_MMF->Name.Names[x].Name), Name.c_str(), strlen(Name.c_str()) + 1);
p_MMF->Name.Names[x].Process = GetCurrentProcessId();
p_MMF->Name.Names[x].Active = 1;
Written = true;
}
continue;
}
else if (p_MMF->Name.Names[x].Process == GetCurrentProcessId())
{
memset(&(p_MMF->Name.Names[x]), 0, sizeof(MMF_Name_Single));
if (!Written)
{
memcpy(&(p_MMF->Name.Names[x].Name), Name.c_str(), strlen(Name.c_str()) + 1);
p_MMF->Name.Names[x].Process = GetCurrentProcessId();
p_MMF->Name.Names[x].Active = 1;
Written = true;
}
}
else if (strcmp((const char*)&(p_MMF->Name.Names[x].Name), Name.c_str()) == 0)
{
memset(&(p_MMF->Name.Names[x]), 0, sizeof(MMF_Name_Single));
if (!Written)
{
memcpy(&(p_MMF->Name.Names[x].Name), Name.c_str(), strlen(Name.c_str()) + 1);
p_MMF->Name.Names[x].Process = GetCurrentProcessId();
p_MMF->Name.Names[x].Active = 1;
Written = true;
}
}
}
s_name = Name;
MatchGroups();
InterlockedExchange(&(p_MMF->Name.ProcessID), 0);
}
void MultiSend::Claim(uint32_t* Target, uint32_t Mod)
{
uint32_t val = GetCurrentProcessId() + Mod;
int FailCount = 0;
InterlockedCompareExchange(Target, val, 0);
while (*Target != val)
{
FailCount++;
if (FailCount == 50)
{
InterlockedExchange(Target, val);
return;
}
::Sleep(1);
InterlockedCompareExchange(Target, val, 0);
}
}