diff --git a/plugins/include/files.inc b/plugins/include/files.inc index bd4ec8d3..1ad4fb99 100644 --- a/plugins/include/files.inc +++ b/plugins/include/files.inc @@ -16,6 +16,7 @@ enum FileType FileType_File = 2, /* File is a file */ }; +#define PLATFORM_MAX_PATH 256 /** * @brief Opens a directory/folder for contents enumeration. @@ -39,4 +40,4 @@ native Handle:OpenDirectory(const String:path[]); * @return True on success, false if there are no more files to read. * @error Invalid or corrupt Handle. */ -native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=0); +native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown); diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 00d61855..a0d93225 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -19,6 +19,7 @@ struct Plugin #include #include #include +#include /** * Declare this as a struct in your plugin to expose its information. @@ -143,9 +144,9 @@ native GetClientCount(bool:inGameOnly=true); * @param client Player index. * @param name Buffer to store the client's name. * @param maxlen Maximum length of string buffer (includes NULL terminator). - * @noreturn + * @return True on success, false otherwise. */ -native GetClientName(client, String:name[], maxlen); +native bool:GetClientName(client, String:name[], maxlen); /** * Retrieves a client's IP address. @@ -153,9 +154,9 @@ native GetClientName(client, String:name[], maxlen); * @param client Player index. * @param name Buffer to store the client's ip address. * @param maxlen Maximum length of string buffer (includes NULL terminator). - * @noreturn + * @return True on success, false otherwise. */ -native GetClientIP(client, String:ip[], maxlen); +native bool:GetClientIP(client, String:ip[], maxlen); /** * Retrieves a client's authentication string (SteamID). @@ -163,9 +164,9 @@ native GetClientIP(client, String:ip[], maxlen); * @param client Player index. * @param auth Buffer to store the client's auth string. * @param maxlen Maximum length of string buffer (includes NULL terminator). - * @return Returns 0 on failure, non-zero otherwise. + * @return True on success, false otherwise. */ -native GetClientAuthString(client, String:auth[], maxlen); +native bool:GetClientAuthString(client, String:auth[], maxlen); /** * Returns if a certain player is connected. diff --git a/plugins/include/string.inc b/plugins/include/string.inc index 7498a575..de4c72b5 100644 --- a/plugins/include/string.inc +++ b/plugins/include/string.inc @@ -74,6 +74,28 @@ stock bool:StrEqual(const String:str1[], const String:str2[], bool:caseSensitive */ native StrCopy(String:dest[], destLen, const String:source[]); +/** + * Formats a string according to the SourceMod format rules (see documentation). + * + * @param buffer Destination string buffer. + * @param maxlength Maximum length of output string buffer. + * @param format Formatting rules. + * @param ... Variable number of format parameters. + */ +native Format(String:buffer[], maxlength, const String:format[], {Handle,Float,String,_}:...); + +/** + * Formats a string according to the SourceMod format rules (see documentation). + * @note This is the same as Format(), except none of the input buffers can overlap the same + * memory as the output buffer. Since this security check is removed, it is slightly faster. + * + * @param buffer Destination string buffer. + * @param maxlength Maximum length of output string buffer. + * @param format Formatting rules. + * @param ... Variable number of format parameters. + */ +native FormatEx(String:buffer[], maxlength, const String:format[], {Handle,Float,String,_}:...); + /** * Converts a string to an integer. * diff --git a/plugins/test.sma b/plugins/test.sma index c3354368..8143007f 100644 --- a/plugins/test.sma +++ b/plugins/test.sma @@ -1,4 +1,5 @@ #include +#include public Plugin:myinfo = { @@ -7,22 +8,23 @@ public Plugin:myinfo = description = "Tests Stuff", version = "1.0.0.0", url = "http://www.sourcemod.net/" -} +}; -copy(String:dest[], maxlength, const String:source[]) -{ - new len - - while (source[len] != '\0' && len < maxlength) - { - dest[len] = source[len] - len++ - } - - dest[len] = '\0' -} +native PrintStuff(const String:buffer[]); public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max) { - return true + new String:buffer[PLATFORM_MAX_PATH]; + new FileType:type; + + new Handle:dir = OpenDirectory("addons/stripper"); + while (ReadDirEntry(dir, buffer, sizeof(buffer), type)) + { + decl String:stuff[1024]; + Format(stuff, sizeof(stuff), "Type: %d Dir: %s", _:type, buffer) + PrintStuff(stuff); + } + CloseHandle(dir); + + return true; }