feat: read from server macros folder as well (#1906)

This commit is contained in:
David Markowitz
2025-10-11 15:33:38 -07:00
committed by GitHub
parent ff645a6662
commit fd6029ae10
2 changed files with 24 additions and 15 deletions

View File

@@ -81,6 +81,9 @@ public:
[[nodiscard]] [[nodiscard]]
AssetStream GetFile(const char* name) const; AssetStream GetFile(const char* name) const;
[[nodiscard]]
AssetStream GetFile(const std::string& name) const { return GetFile(name.c_str()); };
private: private:
void LoadPackIndex(); void LoadPackIndex();

View File

@@ -52,7 +52,7 @@
#include "eInventoryType.h" #include "eInventoryType.h"
#include "ePlayerFlag.h" #include "ePlayerFlag.h"
#include "StringifiedEnum.h" #include "StringifiedEnum.h"
#include "BinaryPathFinder.h"
namespace DEVGMCommands { namespace DEVGMCommands {
void SetGMLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args) { void SetGMLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -368,6 +368,20 @@ namespace DEVGMCommands {
} }
} }
void HandleMacro(Entity& entity, const SystemAddress& sysAddr, std::istream& inStream) {
if (inStream.good()) {
std::string line;
while (std::getline(inStream, line)) {
// Do this in two separate calls to catch both \n and \r\n
line.erase(std::remove(line.begin(), line.end(), '\n'), line.end());
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
SlashCommandHandler::HandleChatCommand(GeneralUtils::ASCIIToUTF16(line), &entity, sysAddr);
}
} else {
ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?");
}
}
void RunMacro(Entity* entity, const SystemAddress& sysAddr, const std::string args) { void RunMacro(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' '); const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.empty()) return; if (splitArgs.empty()) return;
@@ -376,24 +390,16 @@ namespace DEVGMCommands {
if (splitArgs[0].find("/") != std::string::npos) return; if (splitArgs[0].find("/") != std::string::npos) return;
if (splitArgs[0].find("\\") != std::string::npos) return; if (splitArgs[0].find("\\") != std::string::npos) return;
auto infile = Game::assetManager->GetFile(("macros/" + splitArgs[0] + ".scm").c_str()); const auto resServerPath = BinaryPathFinder::GetBinaryDir() / "resServer";
auto infile = Game::assetManager->GetFile("macros/" + splitArgs[0] + ".scm");
if (!infile) { auto resServerInFile = std::ifstream(resServerPath / "macros" / (splitArgs[0] + ".scm"));
if (!infile.good() && !resServerInFile.good()) {
ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?"); ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?");
return; return;
} }
if (infile.good()) { HandleMacro(*entity, sysAddr, infile);
std::string line; HandleMacro(*entity, sysAddr, resServerInFile);
while (std::getline(infile, line)) {
// Do this in two separate calls to catch both \n and \r\n
line.erase(std::remove(line.begin(), line.end(), '\n'), line.end());
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
SlashCommandHandler::HandleChatCommand(GeneralUtils::ASCIIToUTF16(line), entity, sysAddr);
}
} else {
ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?");
}
} }
void AddMission(Entity* entity, const SystemAddress& sysAddr, const std::string args) { void AddMission(Entity* entity, const SystemAddress& sysAddr, const std::string args) {