-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copied Scheduler, CommandArgs, admin logic from mmlib. Added a few more hooks. Plugins send the game a name so they can be identified when calling game functions (needed for clearing timers when a plugin is unloaded). Added a "removeplugin" command and "adminlistfile" cvar. "pluginlist" cvar renamed to "pluginlistfile".
- Loading branch information
Showing
15 changed files
with
563 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "CommandArgs.h" | ||
#include "util.h" | ||
|
||
CommandArgs::CommandArgs() { | ||
|
||
} | ||
|
||
void CommandArgs::loadArgs() { | ||
std::string firstArgLower = toLowerCase(CMD_ARGV(0)); | ||
isConsoleCmd = firstArgLower != "say" && firstArgLower != "say_team"; | ||
|
||
std::string argStr = CMD_ARGC() > 1 ? CMD_ARGS() : ""; | ||
|
||
if (isConsoleCmd) { | ||
argStr = CMD_ARGV(0) + std::string(" ") + argStr; | ||
} | ||
|
||
if (!isConsoleCmd && argStr.length() > 2 && argStr[0] == '\"' && argStr[argStr.length() - 1] == '\"') { | ||
argStr = argStr.substr(1, argStr.length() - 2); // strip surrounding quotes | ||
} | ||
|
||
while (!argStr.empty()) { | ||
// strip spaces | ||
argStr = trimSpaces(argStr); | ||
|
||
|
||
if (argStr[0] == '\"') { // quoted argument (include the spaces between quotes) | ||
argStr = argStr.substr(1); | ||
int endQuote = argStr.find("\""); | ||
|
||
if (endQuote == -1) { | ||
args.push_back(argStr); | ||
break; | ||
} | ||
|
||
args.push_back(argStr.substr(0, endQuote)); | ||
argStr = argStr.substr(endQuote + 1); | ||
} | ||
else { | ||
// normal argument, separate by space | ||
int nextSpace = argStr.find(" "); | ||
|
||
if (nextSpace == -1) { | ||
args.push_back(argStr); | ||
break; | ||
} | ||
|
||
args.push_back(argStr.substr(0, nextSpace)); | ||
argStr = argStr.substr(nextSpace + 1); | ||
} | ||
} | ||
} | ||
|
||
std::string CommandArgs::ArgV(int idx) { | ||
if (idx >= 0 && idx < (int)args.size()) { | ||
return args[idx]; | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
int CommandArgs::ArgC() { | ||
return args.size(); | ||
} | ||
|
||
std::string CommandArgs::getFullCommand() { | ||
std::string str = ArgV(0); | ||
|
||
for (int i = 1; i < (int)args.size(); i++) { | ||
str += " " + args[i]; | ||
} | ||
|
||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
#include <extdll.h> | ||
#include <string> | ||
#include <vector> | ||
#include <stdint.h> | ||
|
||
struct CommandArgs { | ||
bool isConsoleCmd; | ||
|
||
// gets current globally defined args | ||
EXPORT CommandArgs(); | ||
|
||
EXPORT void loadArgs(); | ||
|
||
// returns empty string if idx is out of bounds | ||
EXPORT std::string ArgV(int idx); | ||
|
||
// return number of args | ||
EXPORT int ArgC(); | ||
|
||
// return entire command string | ||
EXPORT std::string getFullCommand(); | ||
|
||
private: | ||
std::vector<std::string> args; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.