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.
126 lines
2.9 KiB
126 lines
2.9 KiB
#include "MultiSend.h" |
|
#include <fstream> |
|
#include <iostream> |
|
using namespace rapidxml; |
|
|
|
bool MultiSend::MatchID(uint32_t ID) |
|
{ |
|
if ((ID & 0xFFFF0000) == 0xFFFF0000) |
|
{ |
|
return true; |
|
} |
|
if ((ID & 0x8FFF0000) == 0x8FFF0000) |
|
{ |
|
uint16_t GroupID = (ID & 0x0000FFFF); |
|
return (std::find(Groups.begin(), Groups.end(), GroupID) != Groups.end()); |
|
} |
|
return (::GetCurrentProcessId() == ID); |
|
} |
|
|
|
void MultiSend::LoadGroups() |
|
{ |
|
m_Group.Map.clear(); |
|
Groups.clear(); |
|
string Path = m_AshitaCore->GetAshitaInstallPathA(); |
|
Path += "config\\MultiSend.xml"; |
|
|
|
std::ifstream Reader(Path, ios::in | ios::binary | ios::ate); |
|
if (Reader.is_open()) |
|
{ |
|
Reader.seekg(0, ios::end); |
|
uint32_t Size = (uint32_t)Reader.tellg(); |
|
|
|
m_Group.rawdata = new char[Size + 1]; |
|
Reader.seekg(0, ios::beg); |
|
Reader.read(m_Group.rawdata, Size); |
|
Reader.close(); |
|
m_Group.rawdata[Size] = '\0'; |
|
try |
|
{ |
|
m_Group.doc.parse<0>(m_Group.rawdata); |
|
m_AshitaCore->GetChatManager()->Write("MultiSend: Groups loaded."); |
|
m_Group.Loaded = true; |
|
} |
|
catch (...) |
|
{ |
|
m_AshitaCore->GetChatManager()->Write("MultiSend: Groups failed to parse."); |
|
m_Group.doc.clear(); |
|
m_Group.Loaded = false; |
|
delete m_Group.rawdata; |
|
} |
|
} |
|
else |
|
{ |
|
if (m_Group.Loaded) |
|
{ |
|
m_Group.doc.clear(); |
|
delete m_Group.rawdata; |
|
m_Group.Loaded = false; |
|
} |
|
m_AshitaCore->GetChatManager()->Write("MultiSend: No groups file found."); |
|
} |
|
|
|
if (m_Group.Loaded) |
|
{ |
|
ReadXML(); |
|
MatchGroups(); |
|
} |
|
} |
|
|
|
void MultiSend::ReadXML() |
|
{ |
|
m_Group.Map.clear(); |
|
|
|
xml_node<> *Node = m_Group.doc.first_node(); |
|
if (_stricmp(Node->name(), "multisend") == 0) Node = Node->first_node(); |
|
while (Node) |
|
{ |
|
if (_stricmp(Node->name(), "group") == 0) |
|
{ |
|
xml_attribute<> *Attr = Node->first_attribute("index"); |
|
if (Attr) |
|
{ |
|
xml_attribute<> *Attr2 = Node->first_attribute("name"); |
|
if (Attr2) |
|
{ |
|
m_Group.Map.insert(std::make_pair((uint16_t)atoi(Attr->value()), std::string(Attr2->value()))); |
|
} |
|
} |
|
} |
|
Node = Node->next_sibling(); |
|
} |
|
} |
|
|
|
void MultiSend::MatchGroups() |
|
{ |
|
Groups.clear(); |
|
if (CurrentName.length() < 3) return; |
|
if (!m_Group.Loaded) return; |
|
|
|
xml_node<> *Node = m_Group.doc.first_node(); |
|
if (_stricmp(Node->name(), "multisend") == 0) Node = Node->first_node(); |
|
while (Node) |
|
{ |
|
if (_stricmp(Node->name(), "group") == 0) |
|
{ |
|
xml_attribute<> *Attr = Node->first_attribute("index"); |
|
if (Attr) |
|
{ |
|
xml_attribute<> *Attr2 = Node->first_attribute("name"); |
|
if (Attr2) |
|
{ |
|
uint16_t Index = (uint16_t)atoi(Attr->value()); |
|
for (xml_node<> *SubNode = Node->first_node("char"); SubNode != NULL; SubNode = SubNode->next_sibling("char")) |
|
{ |
|
if (_stricmp(CurrentName.c_str(), SubNode->value()) == 0) |
|
{ |
|
Groups.push_back(Index); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
Node = Node->next_sibling(); |
|
} |
|
} |