Super simple
Code:
public void OnPluginStart()
{
RegConsoleCmd("sm_parse", test);
}
public Action test(int client, int args)
{
Handle SMC = SMC_CreateParser();
SMC_SetReaders(SMC, NewSection, KeyValue, EndSection);
SMC_ParseFile(SMC, "admins.cfg"); //...cstrike/file.txt or ...tf/file.txt
CloseHandle(SMC);
return Plugin_Handled;
}
char sname[64];
char sauth[16];
char sidentity[32];
char sflags[32];
char simmunity[10];
public SMCResult NewSection(Handle smc, const char[] name, bool opt_quotes)
{
if(!StrEqual(name, "Admins"))
{
Format(sname, sizeof(sname), "%s", name);
}
}
public SMCResult KeyValue(Handle smc, const char[] key, const char[] value, bool key_quotes, bool value_quotes)
{
if(StrEqual(key, "auth"))
{
Format(sauth, sizeof(sauth), "%s", value);
}
else if(StrEqual(key, "identity"))
{
Format(sidentity, sizeof(sidentity), "%s", value);
}
else if(StrEqual(key, "flags"))
{
Format(sflags, sizeof(sflags), "%s", value);
}
else if(StrEqual(key, "immunity"))
{
Format(simmunity, sizeof(simmunity), "%s", value);
}
}
public SMCResult EndSection(Handle smc)
{
PrintToServer("INSERT INTO sm_admins (name, authtype, identity, flags, immunity) VALUES ('%s', '%s', '%s', '%s', '%s');" ,sname, sauth, sidentity, sflags, simmunity);
}
I figured someone might find it usefull
__________________