Expose ParseFile_INI to API.
Some minor changes have been made in parser: - Added ReadINI_ParseStart and ReadINI_ParseEnd call. - Function returns SMCResult instead of bool. To avoid unecessary complexity and duplicating natives, this feels more appropriate to let these functions to share some SMCResult and SMCParse constants. Since properly documented, this should be ok. - Made sure curtok is set to 0 when ptr_val is null, otherwise unexpected value would be passed into the forward.
This commit is contained in:
135
plugins/testsuite/textparse_test.cfg
Normal file
135
plugins/testsuite/textparse_test.cfg
Normal file
@ -0,0 +1,135 @@
|
||||
/**
|
||||
* This file is used to set various options that are important to SourceMod's core.
|
||||
* If this file is missing or an option in this file is missing, then the default values will be used.
|
||||
*/
|
||||
"Core"
|
||||
{
|
||||
/**
|
||||
* This option determines if SourceMod logging is enabled.
|
||||
*
|
||||
* "on" - Logging is enabled (default)
|
||||
* "off" - Logging is disabled
|
||||
*/
|
||||
"Logging" "on"
|
||||
|
||||
/**
|
||||
* This option determines how SourceMod logging should be handled.
|
||||
*
|
||||
* "daily" - New log file is created for each day (default)
|
||||
* "map" - New log file is created for each map change
|
||||
* "game" - Use game's log files
|
||||
*/
|
||||
"LogMode" "daily"
|
||||
|
||||
/**
|
||||
* Language that multilingual enabled plugins and extensions will use to print messages.
|
||||
* Only languages listed in languages.cfg are valid.
|
||||
*
|
||||
* The default value is "en"
|
||||
*/
|
||||
"ServerLang" "en"
|
||||
|
||||
/**
|
||||
* String to use as the public chat trigger. Set an empty string to disable.
|
||||
*/
|
||||
"PublicChatTrigger" "!"
|
||||
|
||||
/**
|
||||
* String to use as the silent chat trigger. Set an empty string to disable.
|
||||
*/
|
||||
"SilentChatTrigger" "/"
|
||||
|
||||
/**
|
||||
* If a say command is a silent chat trigger, and is used by an admin,
|
||||
* but it does not evaluate to an actual command, it will be displayed
|
||||
* publicly. This setting allows you to suppress accidental typings.
|
||||
*
|
||||
* The default value is "no". A value of "yes" will supress.
|
||||
*/
|
||||
"SilentFailSuppress" "no"
|
||||
|
||||
/**
|
||||
* Password setinfo key that clients must set. You must change this in order for
|
||||
* passwords to work, for security reasons.
|
||||
*/
|
||||
"PassInfoVar" "_password"
|
||||
|
||||
/**
|
||||
* Specifies the sound that gets played when an item is selected from a menu.
|
||||
*/
|
||||
"MenuItemSound" "buttons/button14.wav"
|
||||
|
||||
/**
|
||||
* Specifies the sound that gets played when an "Exit" button is selected
|
||||
* from a menu.
|
||||
*/
|
||||
"MenuExitSound" "buttons/combine_button7.wav"
|
||||
|
||||
/**
|
||||
* Specifies the sound that gets played when an "Exit Back" button is selected
|
||||
* from a menu. This is the special "Back" button that is intended to roll back
|
||||
* to a previous menu.
|
||||
*/
|
||||
"MenuExitBackSound" "buttons/combine_button7.wav"
|
||||
|
||||
/**
|
||||
* Enables or disables whether SourceMod reads a client's cl_language cvar to set
|
||||
* their language for server-side phrase translation.
|
||||
*
|
||||
* "on" - Translate using the client's language (default)
|
||||
* "off" - Translate using default server's language
|
||||
*/
|
||||
"AllowClLanguageVar" "On"
|
||||
|
||||
/**
|
||||
* Enables or Disables SourceMod's automatic gamedata updating.
|
||||
*
|
||||
* The default value is "no". A value of "yes" will block the Auto Updater.
|
||||
*/
|
||||
"DisableAutoUpdate" "no"
|
||||
|
||||
/**
|
||||
* If set to yes, a successful gamedata update will attempt to restart SourceMod.
|
||||
* SourceMod is unloaded and reloaded, and the map is changed to the current map.
|
||||
* Since gamedata updates occur when the server loads, impact should be minimal.
|
||||
* But to be safe, this option is disabled by default.
|
||||
*/
|
||||
"ForceRestartAfterUpdate" "no"
|
||||
|
||||
/**
|
||||
* URL to use for retrieving update information.
|
||||
* SSL is not yet supported.
|
||||
*/
|
||||
"AutoUpdateURL" "http://update.sourcemod.net/update/"
|
||||
|
||||
/**
|
||||
* Whether to show debug spew.
|
||||
* Currently this will log details about the gamedata updating process.
|
||||
*/
|
||||
"DebugSpew" "no"
|
||||
|
||||
/**
|
||||
* If set to yes, SourceMod will validate steamid auth strings with the Steam backend before giving out admin access.
|
||||
* This can prevent malicious users from impersonating admins with stolen Steam apptickets.
|
||||
* If Steam is down, admins will not be authenticated until Steam comes back up.
|
||||
* This option increases the security of your server, but is still experimental.
|
||||
*/
|
||||
"SteamAuthstringValidation" "yes"
|
||||
|
||||
/**
|
||||
* Enables or disables whether SourceMod blocks known or potentially malicious plugins from loading.
|
||||
* It is STRONGLY advised that this is left enabled, there have been cases in the past with plugins that
|
||||
* allow anyone to delete files on the server, gain full rcon control, etc.
|
||||
*
|
||||
* "yes" - Block malware or illegal plugins from loading (default)
|
||||
* "no" - Warn about malware or illegal plugins loading
|
||||
*/
|
||||
"BlockBadPlugins" "yes"
|
||||
|
||||
/**
|
||||
* If a plugin takes too long to execute, hanging or freezing the game server in the process,
|
||||
* SourceMod will attempt to terminate that plugin after the specified timeout length has
|
||||
* passed. You can disable this feature by setting the value to "0".
|
||||
*/
|
||||
"SlowScriptTimeout" "8"
|
||||
}
|
68
plugins/testsuite/textparse_test.ini
Normal file
68
plugins/testsuite/textparse_test.ini
Normal file
@ -0,0 +1,68 @@
|
||||
;CSDM Configuration File
|
||||
; Default settings by BAILOPAN
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;You must be running the Main plugin for this section
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
[settings]
|
||||
|
||||
;Sets whether CSDM is enabled or not.
|
||||
enabled = 1
|
||||
|
||||
;Sets whether or not players should be stripped of weapons on round start
|
||||
; (excludes knife)
|
||||
strip_weapons = 1
|
||||
|
||||
;Sets how long weapons should stay on the ground for after being dropped
|
||||
;in seconds. note that enabling this can create lots of lag for clients
|
||||
; AND server. 0 is immediate, -1 is infinite.
|
||||
weapons_stay = 0
|
||||
|
||||
;Sets the spawn mode.
|
||||
; "none" - users spawn at normal map spawn points
|
||||
; "preset" - csdm_spawn_preset.amxx required, uses predefined spawns in config files
|
||||
; -- others may be supplied by 3rd party plugins
|
||||
spawnmode = preset
|
||||
|
||||
;Sets whether the bomb is removed
|
||||
remove_bomb = 1
|
||||
|
||||
;Sets the spawn waiting time
|
||||
spawn_wait_time = 0.75
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;You must be running the protection plugin for this section
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
[protection] ; some comment
|
||||
|
||||
;Is spawn protection enabled?
|
||||
enabled = 1
|
||||
|
||||
;Colors of glow shell, leave this in quotes
|
||||
;The digits are R, G, B, A where A is the alpha transparency
|
||||
; (as A gets higher, the glow shell is thicker)
|
||||
colors = "0 255 0 200"
|
||||
|
||||
;Number of seconds someone is respawned for.
|
||||
time = 2
|
||||
|
||||
;;;;;;;;;;;;;;;;
|
||||
;;WEAPON MENUS;;
|
||||
;;;;;;;;;;;;;;;;
|
||||
|
||||
;Format for weapon menus is:
|
||||
;shortname "Display Name" menupage
|
||||
;Change the '1' to a '0' to block the weapon
|
||||
;Removing or moving things
|
||||
; from the list will change the order of the menus!
|
||||
|
||||
[secondary] gabe // < just to test param.
|
||||
usp USP 1
|
||||
glock18 Glock 1
|
||||
deagle Deagle 1
|
||||
|
||||
;List weapons here the bots can randomly have
|
||||
;The short name must match one in the list above
|
||||
[botsecondary
|
||||
deagle
|
||||
usp
|
@ -6,17 +6,24 @@ new Trie:ExpectedKVData;
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_concmd("textparse_vdf", "ConsoleCommand_TextParseVDF");
|
||||
register_clcmd("textparse_ini", "ServerCommand_TextParseINI");
|
||||
register_concmd("textparse", "ConsoleCommand_TextParse");
|
||||
}
|
||||
|
||||
public ConsoleCommand_TextParse()
|
||||
{
|
||||
InitializeTextParseSMC();
|
||||
InitializeTextParseINI();
|
||||
}
|
||||
|
||||
/**
|
||||
* VDF Config format
|
||||
* SMC Config format
|
||||
*/
|
||||
|
||||
public ConsoleCommand_TextParseVDF()
|
||||
InitializeTextParseSMC()
|
||||
{
|
||||
server_print("Testing text parser with VDF config file format...");
|
||||
SuccessCount = 0;
|
||||
|
||||
server_print("Testing text parser with SMC config file format...");
|
||||
|
||||
new const configFile[] = "addons/amxmodx/scripting/testsuite/textparse_test.cfg";
|
||||
|
||||
@ -53,7 +60,7 @@ public ConsoleCommand_TextParseVDF()
|
||||
SMC_SetParseEnd(parser, "ReadCore_ParseEnd");
|
||||
|
||||
new line, col;
|
||||
new SMCError:err = SMC_ParseFile_VDF(parser, configFile, line, col);
|
||||
new SMCError:err = SMC_ParseFile(parser, configFile, line, col);
|
||||
|
||||
if (err != SMCError_Okay)
|
||||
{
|
||||
@ -66,22 +73,24 @@ public ConsoleCommand_TextParseVDF()
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
SMC_DestroyParser(parser);
|
||||
|
||||
server_print("^tTests successful: %d/%d", SuccessCount, expectedStartEndCount + expectedSectionCount + expectedKeyValueCount + expectedLineCount + 1);
|
||||
|
||||
SMC_DestroyParser(parser);
|
||||
TrieDestroy(ExpectedKVData);
|
||||
SuccessCount = 0;
|
||||
}
|
||||
|
||||
public ReadCore_ParseStart(TextParser:smc)
|
||||
public ReadCore_ParseStart(TextParser:handle)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
public ReadCore_NewSection(TextParser:smc, const name[])
|
||||
public ReadCore_NewSection(TextParser:handle, const name[])
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
public ReadCore_KeyValue(TextParser:smc, const key[], const value[])
|
||||
public ReadCore_KeyValue(TextParser:handle, const key[], const value[])
|
||||
{
|
||||
new buffer[128];
|
||||
if (TrieGetString(ExpectedKVData, key, buffer, charsmax(buffer)) && equal(value, buffer))
|
||||
@ -90,27 +99,124 @@ public ReadCore_KeyValue(TextParser:smc, const key[], const value[])
|
||||
}
|
||||
}
|
||||
|
||||
public ReadCore_EndSection(TextParser:smc)
|
||||
public ReadCore_EndSection(TextParser:handle)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
public ReadCore_CurrentLine(TextParser:smc, const line[], lineno)
|
||||
public ReadCore_CurrentLine(TextParser:handle, const line[], lineno)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
public ReadCore_ParseEnd(TextParser:smc)
|
||||
public ReadCore_ParseEnd(TextParser:handle, bool:halted, bool:failed)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* INI Config format
|
||||
*/
|
||||
public ServerCommand_TextParseINI()
|
||||
{
|
||||
|
||||
public InitializeTextParseINI()
|
||||
{
|
||||
SuccessCount = 0;
|
||||
|
||||
server_print("Testing text parser with INI config file format...");
|
||||
|
||||
new const configFile[] = "addons/amxmodx/scripting/testsuite/textparse_test.ini";
|
||||
|
||||
ExpectedKVData = TrieCreate();
|
||||
TrieSetString(ExpectedKVData, "settings", "");
|
||||
TrieSetString(ExpectedKVData, "enabled", "1");
|
||||
TrieSetString(ExpectedKVData, "strip_weapons", "1");
|
||||
TrieSetString(ExpectedKVData, "weapons_stay", "0");
|
||||
TrieSetString(ExpectedKVData, "spawnmode", "preset");
|
||||
TrieSetString(ExpectedKVData, "remove_bomb", "1");
|
||||
TrieSetString(ExpectedKVData, "spawn_wait_time", "0.75");
|
||||
TrieSetString(ExpectedKVData, "protection", "");
|
||||
TrieSetString(ExpectedKVData, "colors", "0 255 0 200");
|
||||
TrieSetString(ExpectedKVData, "time", "time");
|
||||
TrieSetString(ExpectedKVData, "secondary", "");
|
||||
TrieSetString(ExpectedKVData, "usp USP 1", "");
|
||||
TrieSetString(ExpectedKVData, "glock18 Glock 1", "");
|
||||
TrieSetString(ExpectedKVData, "deagle Deagle 1", "");
|
||||
TrieSetString(ExpectedKVData, "botsecondary", "");
|
||||
TrieSetString(ExpectedKVData, "deagle", "");
|
||||
TrieSetString(ExpectedKVData, "usp", "");
|
||||
|
||||
new const expectedSectionCount = 4;
|
||||
new const expectedStartEndCount = 2;
|
||||
new const expectedKeyValueCount = TrieGetSize(ExpectedKVData) - expectedSectionCount;
|
||||
new const expectedLineCount = TrieGetSize(ExpectedKVData); // This doesn't include blanck/comments line.
|
||||
|
||||
new TextParser:parser = SMC_CreateParser(.ini_format = true);
|
||||
|
||||
SMC_SetReaders(parser, "ReadCSDM_NewSection", "ReadCSDM_KeyValue");
|
||||
SMC_SetParseStart(parser, "ReadCSDM_ParseStart");
|
||||
SMC_SetRawLine(parser, "ReadCSDM_CurrentLine");
|
||||
SMC_SetParseEnd(parser, "ReadCSDM_ParseEnd");
|
||||
|
||||
new line, col;
|
||||
new SMCError:err = SMC_ParseFile(parser, configFile, line, col);
|
||||
|
||||
if (err != SMCError_Okay)
|
||||
{
|
||||
new buffer[64];
|
||||
server_print("Error: %s", SMC_GetErrorString(err, buffer, charsmax(buffer)) ? buffer : "Fatal parse error");
|
||||
}
|
||||
|
||||
if (line == expectedLineCount + 1)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
server_print("^tTests successful: %d/%d", SuccessCount, expectedStartEndCount + expectedSectionCount + expectedKeyValueCount + expectedLineCount + 1);
|
||||
|
||||
SMC_DestroyParser(parser);
|
||||
TrieDestroy(ExpectedKVData);
|
||||
}
|
||||
|
||||
public ReadCSDM_ParseStart(TextParser:handle)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
public ReadCSDM_NewSection(TextParser:handle, const section[], bool:invalid_tokens, bool:close_bracket, bool:extra_tokens, curtok)
|
||||
{
|
||||
if (TrieKeyExists(ExpectedKVData, section))
|
||||
{
|
||||
if ((equal(section, "secondary") && !extra_tokens) ||
|
||||
(equal(section, "botsecondary") && close_bracket))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
++SuccessCount;
|
||||
}
|
||||
}
|
||||
|
||||
public ReadCSDM_KeyValue(TextParser:handle, const key[], const value[], bool:invalid_tokens, bool:equal_token, bool:quotes, curtok)
|
||||
{
|
||||
new buffer[128];
|
||||
if (TrieGetString(ExpectedKVData, key, buffer, charsmax(buffer)) && equal(value, buffer))
|
||||
{
|
||||
if (equal(value, "colors") && !quotes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
++SuccessCount;
|
||||
}
|
||||
}
|
||||
|
||||
public ReadCSDM_CurrentLine(TextParser:handle, const line[], lineno, curtok)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
||||
|
||||
public ReadCSDM_ParseEnd(TextParser:handle, bool:halted, bool:failed)
|
||||
{
|
||||
++SuccessCount;
|
||||
}
|
Reference in New Issue
Block a user