#include "MultiSend.h" bool MultiSend::HandleCommand(const char* command, int32_t type) { std::string arg; const char* com = command + GetArg(command, &arg); if ((_strnicmp(command, "/ms", 3)) && (_stricmp(arg.c_str(), "/multisend"))) { return false; } if (strlen(com) < 2) return true; if ((_stricmp(arg.c_str(), "/ms") == 0) || (_stricmp(arg.c_str(), "/multisend")) == 0) { com++; com += GetArg(com, &arg); } if ((_stricmp(arg.c_str(), "send") == 0) || (_stricmp(arg.c_str(), "/mss") == 0)) { if (strlen(com) < 2) return true; SendCommand(0xFFFF0000, com + 1); return true; } else if ((_stricmp(arg.c_str(), "sendto") == 0) || (_stricmp(arg.c_str(), "/mst") == 0)) { if (strlen(com) < 2) { m_AshitaCore->GetChatManager()->Write("MultiSend: Invalid command."); return true; } com++; com += GetArg(com, &arg); arg = SubValues(arg); Claim(&(MMF_Pointer->Name.ProcessID), 0); for (int x = 0; x < 100; x++) { if (MMF_Pointer->Name.Names[x].Active) { if (_stricmp((const char*)&(MMF_Pointer->Name.Names[x].Name), arg.c_str()) == 0) { SendCommand(MMF_Pointer->Name.Names[x].Process, com + 1); InterlockedExchange(&(MMF_Pointer->Name.ProcessID), 0); return true; } } } InterlockedExchange(&(MMF_Pointer->Name.ProcessID), 0); m_AshitaCore->GetChatManager()->Write("MultiSend: Character not found."); return true; } else if ((_stricmp(arg.c_str(), "sendgroup") == 0) || (_stricmp(arg.c_str(), "/msg") == 0)) { if (strlen(com) < 3) { m_AshitaCore->GetChatManager()->Write("MultiSend: Invalid command."); return true; } com++; com += GetArg(com, &arg); for (std::map::iterator it = m_Group.Map.begin(); it != m_Group.Map.end(); it++) { if (_stricmp((*it).second.c_str(), arg.c_str()) == 0) { SendCommand(0x8FFF0000 + (*it).first, com + 1); return true; } } m_AshitaCore->GetChatManager()->Write("MultiSend: Group not found."); return true; } else if (_stricmp(arg.c_str(), "followme") == 0) { if (strlen(com) < 2) return true; com++; com += GetArg(com, &arg); if (_stricmp(arg.c_str(), "on") == 0) { InterlockedExchange(&(MMF_Pointer->Follow.FollowID), GetCurrentProcessId()); if (!Zoning) { Following = false; uint16_t myindex = m_AshitaCore->GetDataManager()->GetParty()->GetMemberTargetIndex(0); uint32_t mPosX = (uint32_t)floor(m_AshitaCore->GetDataManager()->GetEntity()->GetLocalX(myindex) * 100); uint32_t mPosZ = (uint32_t)floor(m_AshitaCore->GetDataManager()->GetEntity()->GetLocalZ(myindex) * 100); MMF_Pointer->Follow.PosX = mPosX; MMF_Pointer->Follow.PosZ = mPosZ; MMF_Pointer->Follow.Follow = 1; } else { Following = false; MMF_Pointer->Follow.Follow = 3; } m_AshitaCore->GetChatManager()->Write("MultiSend: Followme enabled."); } else if (_stricmp(arg.c_str(), "off") == 0) { InterlockedExchange(&(MMF_Pointer->Follow.FollowID), 0); MMF_Pointer->Follow.Follow = 0; m_AshitaCore->GetChatManager()->Write("MultiSend: Followme disabled."); } else { m_AshitaCore->GetChatManager()->Writef("MultiSend: Followme is currently %s.", (MMF_Pointer->Follow.FollowID == GetCurrentProcessId()) ? "enabled" : "disabled"); } return true; } else if (_stricmp(arg.c_str(), "follow") == 0) { if (strlen(com) < 2) return true; com++; com += GetArg(com, &arg); if (_stricmp(arg.c_str(), "on") == 0) { FollowEnabled = true; m_AshitaCore->GetChatManager()->Write("MultiSend: Follow enabled. Note that if someone is not currently using followme, no movement will occur."); } else if (_stricmp(arg.c_str(), "off") == 0) { FollowEnabled = false; m_AshitaCore->GetChatManager()->Write("MultiSend: Follow disabled."); } else { m_AshitaCore->GetChatManager()->Writef("MultiSend: Follow is currently %s.", FollowEnabled ? "enabled" : "disabled"); } return true; } else if (_stricmp(arg.c_str(), "ignoreself") == 0) { if (strlen(com) < 2) return true; com++; com += GetArg(com, &arg); if (_stricmp(arg.c_str(), "on") == 0) { IgnoreSelf = true; m_AshitaCore->GetChatManager()->Write("MultiSend: Now ignoring self-published commands."); } else if (_stricmp(arg.c_str(), "off") == 0) { IgnoreSelf = false; m_AshitaCore->GetChatManager()->Write("MultiSend: Now accepting self-published commands."); } else { m_AshitaCore->GetChatManager()->Writef("MultiSend: Ignore self is currently %s.", IgnoreSelf ? "enabled" : "disabled"); } return true; } else if (_stricmp(arg.c_str(), "debug") == 0) { if (strlen(com) < 2) return true; com++; com += GetArg(com, &arg); if (_stricmp(arg.c_str(), "on") == 0) { _Debug = true; m_AshitaCore->GetChatManager()->Write("MultiSend: Debug prints enabled."); } else if (_stricmp(arg.c_str(), "off") == 0) { _Debug = false; m_AshitaCore->GetChatManager()->Write("MultiSend: Debug prints disabled."); } else { m_AshitaCore->GetChatManager()->Writef("MultiSend: Debug prints currently %s.", _Debug ? "enabled" : "disabled"); } 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(); return true; } else if (_stricmp(arg.c_str(), "help") == 0) { m_AshitaCore->GetChatManager()->Write("Multisend Command Listing"); m_AshitaCore->GetChatManager()->Write("/ms send [command] - Sends [command] to all characters with multisend loaded."); m_AshitaCore->GetChatManager()->Write("/ms sendto [char name] [command] - Sends [command] to all characters with multisend loaded named [char name]."); m_AshitaCore->GetChatManager()->Write("/ms sendgroup [group name] [command] - Sends [command] to all characters with multisend loaded that are defined within the group [group name]."); m_AshitaCore->GetChatManager()->Write("/ms follow on/off - When enabled, the current character will obey followme."); m_AshitaCore->GetChatManager()->Write("/ms followme on/off - When enabled, all characters with follow enabled will follow this character. Only one character can have this active at a time, if you activate it on a second the first will deactivate automatically."); 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; } return (_strnicmp(command, "/ms ", 4) == 0); } uint32_t MultiSend::GetArg(const char* text, std::string* buffer) { std::string working(text); if (working[0] == '"') { size_t second = working.substr(1).find_first_of('"'); if (second != string::npos) { *buffer = working.substr(1, second); return second + 1; } } size_t space = working.find_first_of(' '); if (space != string::npos) { *buffer = working.substr(0, space); return space; } *buffer = string(text); return strlen(text); }