Skip to content

Commit

Permalink
Bot Setups: Fixed build issues
Browse files Browse the repository at this point in the history
Bot Setups: Fixed build issues

Stuff

Fixing more variable issues

Fixing stuff
  • Loading branch information
skliffmueller committed Mar 14, 2019
1 parent 780ae1d commit bd37322
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
33 changes: 16 additions & 17 deletions scripting/practicemode/bots.sp
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ public Action Command_SaveBots(int client, int args) {

char path[PLATFORM_MAX_PATH];

char setupName[PLATFORM_MAX_PATH];
char fileName[PLATFORM_MAX_PATH];
/* This is setup to support the default method of loading bots */
if(GetCmdArgString(setupName, sizeof(setupName)) != 0) {
if(!IsValidFileName(setupName)) {
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, setupName);
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);
}
Expand Down Expand Up @@ -540,14 +540,14 @@ public Action Command_LoadBots(int client, int args) {

char path[PLATFORM_MAX_PATH];

char setupName[PLATFORM_MAX_PATH];
char fileName[PLATFORM_MAX_PATH];
/* This is setup to support the default method of loading bots */
if(GetCmdArgString(setupName, sizeof(setupName)) != 0) {
if(!IsValidFileName(setupName)) {
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, setupName);
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);
}
Expand All @@ -556,9 +556,9 @@ public Action Command_LoadBots(int client, int args) {

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

botsKv.GotoFirstSubKey();

Expand Down Expand Up @@ -602,20 +602,19 @@ public Action Command_ListSetups(int client, int args) {
int mapNameLength = sizeof(mapName);
int fileNameLength = sizeof(fileName);

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

while(dirList.GetNext(fileName, fileNameLength)) {
if(StrContains(fileName, mapName) == 0) {
char setupName[PLATFORM_MAX_PATH];

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

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

Expand Down
23 changes: 9 additions & 14 deletions scripting/practicemode/util.sp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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[] = {"\x2D\x2E","\x30\x39","\x41\x5A","\x5F\x00","\x61\x00"};
static char _validFileNameCharacters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";

stock void SwitchPlayerTeam(int client, int team) {
if (GetClientTeam(client) == team)
Expand Down Expand Up @@ -417,31 +417,26 @@ stock int RemoveDuplicates(ArrayList list, int stringLength) {
return count;
}

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

0 comments on commit bd37322

Please sign in to comment.