Skip to content

Commit

Permalink
Bot Setup: Added bot setup list command, updated loadbots and savebot…
Browse files Browse the repository at this point in the history
…s to

have an optional argument .loadbots <myprofile> .savebots <myprofile>
while still being backwards compatable with original .loadbots .savebots
commands

Updated README to include bot setups, tabs vs spaces

Bot Setups: Fixed build issues

Bot Setups: Fixed build issues

Stuff

Fixing more variable issues

Fixing stuff
  • Loading branch information
skliffmueller committed Mar 14, 2019
1 parent a743d1b commit a4362e4
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ All of the following commands can only be used on _your_ grenades. They will app
- ``.movebot``: moves the last bot you placed to your current position
- ``.nobot``: removes the bot you're aiming at (can also use ``.kickbot`` or ``.removebot``)
- ``.nobots``: clears all bots (``.clearbots``, ``.removebots``, ``.kickbots`` also work)
- ``.savebots``: saves all current bots to a file
- ``.loadbots``: loads bots from the file (written by the last ``.savebots``)
- ``.savebots <setup>``: saves all current bots to a file
- ``.loadbots <setup>``: loads bots from the file (written by the last ``.savebots``)
- ``.botsetups``: list the setups available to load

### Miscellaneous commands
- ``.timer``: starts a timer when you start moving in any direction, and stops it when you stop moving, telling you the duration of time between starting/stopping
Expand Down
3 changes: 3 additions & 0 deletions scripting/practicemode.sp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ public void OnPluginStart() {
RegConsoleCmd("sm_loadbots", Command_LoadBots);
PM_AddChatAlias(".loadbots", "sm_loadbots");

RegConsoleCmd("sm_botsetups", Command_ListSetups);
PM_AddChatAlias(".botsetups", "sm_botsetups");

RegConsoleCmd("sm_botsmenu", Command_BotsMenu);
PM_AddChatAlias(".bots", "sm_botsmenu");
}
Expand Down
75 changes: 72 additions & 3 deletions scripting/practicemode/bots.sp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,21 @@ public Action Command_SaveBots(int client, int args) {

char mapName[PLATFORM_MAX_PATH];
GetCleanMapName(mapName, sizeof(mapName));

char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);

char fileName[PLATFORM_MAX_PATH];
/* This is setup to support the default method of loading bots */
if(GetCmdArgString(fileName, sizeof(fileName)) != 0) {
if(!IsValidFileName(fileName, sizeof(fileName))) {
ReplyToCommand(client, "Invalid: Permitted characters (A-Za-z._-)");
return Plugin_Handled;
}
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s_%s.cfg", mapName, fileName);
} else {
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);
}

KeyValues botsKv = new KeyValues("Bots");

int output_index = 0;
Expand Down Expand Up @@ -524,11 +537,29 @@ public Action Command_LoadBots(int client, int args) {

char mapName[PLATFORM_MAX_PATH];
GetCleanMapName(mapName, sizeof(mapName));

char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);

char fileName[PLATFORM_MAX_PATH];
/* This is setup to support the default method of loading bots */
if(GetCmdArgString(fileName, sizeof(fileName)) != 0) {
if(!IsValidFileName(fileName, sizeof(fileName))) {
ReplyToCommand(client, "Invalid: Permitted characters (A-Za-z._-)");
return Plugin_Handled;
}
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s_%s.cfg", mapName, fileName);
} else {
BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/%s.cfg", mapName);
}

KeyValues botsKv = new KeyValues("Bots");
botsKv.ImportFromFile(path);

if(!botsKv.ImportFromFile(path)) {
delete botsKv;
ReplyToCommand(client, "Invalid: Unable to load setup %s", fileName);
return Plugin_Handled;
}

botsKv.GotoFirstSubKey();

do {
Expand All @@ -552,6 +583,44 @@ public Action Command_LoadBots(int client, int args) {
return Plugin_Handled;
}

public Action Command_ListSetups(int client, int args) {
if (!g_InPracticeMode) {
return Plugin_Handled;
}

char mapName[PLATFORM_MAX_PATH];
GetCleanMapName(mapName, sizeof(mapName));

char path[PLATFORM_MAX_PATH];

BuildPath(Path_SM, path, sizeof(path), "data/practicemode/bots/");

DirectoryListing dirList = OpenDirectory(path);

char fileName[PLATFORM_MAX_PATH];

int mapNameLength = sizeof(mapName);
int fileNameLength = sizeof(fileName);

ReplyToCommand(client, "List of Bot Setups");
ReplyToCommand(client, "------------------");

while(dirList.GetNext(fileName, fileNameLength)) {
if(String_StartsWith(fileName, mapName)) {
char responseName[PLATFORM_MAX_PATH];
for(int i = 0;i < fileNameLength;i++) {
if(i >= mapNameLength) {
responseName[i-mapNameLength] = fileName[i];
}
}

ReplyToCommand(client, "%s", fileName);
}
}

return Plugin_Handled;
}

public Action Command_SwapBot(int client, int args) {
int target = GetClientAimTarget(client, true);
if (!IsPMBot(target)) {
Expand Down
33 changes: 33 additions & 0 deletions scripting/practicemode/util.sp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ static char _colorNames[][] = {"{NORMAL}", "{DARK_RED}", "{PINK}", "{GRE
static char _colorCodes[][] = {"\x01", "\x02", "\x03", "\x04", "\x05", "\x06",
"\x07", "\x08", "\x09", "\x0B", "\x0C", "\x0E"};

static char _validFileNameCharacters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";

stock void SwitchPlayerTeam(int client, int team) {
if (GetClientTeam(client) == team)
return;
Expand Down Expand Up @@ -414,3 +416,34 @@ stock int RemoveDuplicates(ArrayList list, int stringLength) {
}
return count;
}

stock bool IsValidFileName(char[] fileName, int length) {
int testLength = sizeof(_validFileNameCharacters);
bool inNullBytes = false;
for (int i = 0; i < length; i++) {
if(!inNullBytes && StrEqual(fileName[i], "\0")) {
if(i == 0) {
return false;
}
inNullBytes = true;
}
if(inNullBytes) {
if(!StrEqual(fileName[i], "\0")) {
return false;
}
} else {
bool valid = false;
for(int j = 0; j < testLength; j++) {
if(StrEqual(_validFileNameCharacters[j], fileName[i])) {
valid = true;
break;
}
}
if(!valid) {
return false;
}
}

}
return true;
}

0 comments on commit a4362e4

Please sign in to comment.