AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   admins.cfg to MySQL admins (https://forums.alliedmods.net/showthread.php?t=264797)

Pelipoika 06-21-2015 11:52

admins.cfg to MySQL admins
 
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

404UserNotFound 06-22-2015 20:10

Re: admins.cfg to MySQL admins
 
I sure will find this useful.

All I gotta do is convert my admins_simple.ini over to admins.cfg, then use this, then recode this to make a custom "sm_adddonator" command that adds new people to the MySQL admins database and refreshes it.


All times are GMT -4. The time now is 18:38.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.