diff options
author | DDuarte <dnpd.dd@gmail.com> | 2014-09-01 03:03:26 +0100 |
---|---|---|
committer | DDuarte <dnpd.dd@gmail.com> | 2014-09-01 03:03:26 +0100 |
commit | d5c0aeaa1830aa12eaa521d485b45ca9221b3194 (patch) | |
tree | f484d0ce61d00b031dac0f435054515554282807 | |
parent | dd4dbdcd16bb72b1b45c7971cb8b9e06030b6e16 (diff) |
Scripts/Commands: Replace regex usage
Sorry for the shitty C code but std::regex is not supported by GCC 4.7 and 4.8
-rw-r--r-- | src/server/scripts/Commands/cs_server.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index 43afea1b381..14a68d1fdae 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -30,8 +30,6 @@ EndScriptData */ #include "ScriptMgr.h" #include "SystemConfig.h" -#include <regex> - class server_commandscript : public CommandScript { public: @@ -296,9 +294,9 @@ public: } private: - static bool ParseExitCode(std::string const& exitCodeStr, int32& exitCode) + static bool ParseExitCode(char const* exitCodeStr, int32& exitCode) { - exitCode = atoi(exitCodeStr.c_str()); + exitCode = atoi(exitCodeStr); // Handle atoi() errors if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0')) @@ -319,28 +317,42 @@ private: return false; // #delay [#exit_code] [reason] - std::regex regex("([0-9]+) ([0-9]*) ?(.*)"); - std::cmatch cm; + char* delayStr = strtok((char*)args, " "); + if (!delayStr || !isNumeric(delayStr)) + return false; + + char* exitCodeStr = nullptr; - if (!std::regex_match(args, cm, regex)) + if (strlen(args) > 255) return false; - std::string delayStr = cm[1]; - std::string exitCodeStr = cm[2]; - std::string reason = cm[3]; + char reason[255] = { 0 }; + + while (char* nextToken = strtok(nullptr, " ")) + { + if (isNumeric(nextToken)) + exitCodeStr = nextToken; + else + { + strcat(reason, nextToken); + strcat(reason, " "); + strcat(reason, strtok(nullptr, "\0")); + break; + } + } - int32 delay = atoi(delayStr.c_str()); + int32 delay = atoi(delayStr); // Prevent interpret wrong arg value as 0 secs shutdown time if ((delay == 0 && (delayStr[0] != '0' || delayStr[1] != '\0')) || delay < 0) return false; int32 exitCode = defaultExitCode; - if (exitCodeStr.length() > 0) + if (exitCodeStr) if (!ParseExitCode(exitCodeStr, exitCode)) return false; - sWorld->ShutdownServ(delay, shutdownMask, static_cast<uint8>(exitCode), reason); + sWorld->ShutdownServ(delay, shutdownMask, static_cast<uint8>(exitCode), std::string(reason)); return true; } |