Protecting Your MySQL-Enhanced Script
#1

A lot of people have problems with their script's getting stolen. Not necessarily the .pwn file, but the .amx file. Now, this may not be a problem with file-based scripts because you need the scriptfiles (or at least the folders) for things to work correctly. But what if your script uses MySQL?

Well! Now there is a simple way to protect yourself and all it requires is a single INI file located somewhere in your scriptfiles directory. You no longer need to keep all of your data inside the script itself!

Instead of me explaining how this is accomplished, I figured I could just provide some code. Please keep in mind that I am using BlueG's MySQL plugin and ******'s y_ini system.

pawn Код:
#include <a_samp>
#include <a_mysql>
#include <YSI\y_ini>

new
    SQL_HOST[30],
    SQL_DATA[30],
    SQL_USER[30],
    SQL_PASS[30],
    SQL_DEBUG;

main()
{
    if(fexist("Server Settings/Critical/sqlinfo.ini")) INI_Load("Server Settings/Critical/sqlinfo.ini"); // This must remain here to load the SQL settings.
    else
    {
        new INI:tempsqlinfo = INI_Open("Server Settings/Critical/sqlinfo.ini");
        INI_WriteInt(tempsqlinfo, "debug", 1);
        INI_WriteString(tempsqlinfo, "host", " ");
        INI_WriteString(tempsqlinfo, "user", " ");
        INI_WriteString(tempsqlinfo, "data", " ");
        INI_WriteString(tempsqlinfo, "pass", " ");
        INI_Close(tempsqlinfo);
       
        print("\n Critical Error: No MySQL information to load, server process automatically terminated! \n");
        SendRconCommand("exit");
    }
}

public OnGameModeInit()
{
    mysql_debug(SQL_DEBUG);
    mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
    return 1;
}

public OnGameModeExit()
{
    mysql_close();
    return 1;
}

INI:sqlinfo[](name[], value[]) // critical SQL information loading
{
    INI_Int("debug", SQL_DEBUG);
    INI_String("host", SQL_HOST, sizeof(SQL_HOST));
    INI_String("user", SQL_USER, sizeof(SQL_USER));
    INI_String("data", SQL_DATA, sizeof(SQL_DATA));
    INI_String("pass", SQL_PASS, sizeof(SQL_PASS));
    return 1;
}
I'm not going to explain the code above, it should be pretty straight forward to you. Good luck!
Reply


Messages In This Thread
Protecting Your MySQL-Enhanced Script - by Scenario - 26.11.2011, 05:37
Re: Protecting Your MySQL-Enhanced Script - by iggy1 - 26.11.2011, 06:38
Re: Protecting Your MySQL-Enhanced Script - by Scenario - 26.11.2011, 14:24
Re: Protecting Your MySQL-Enhanced Script - by Calgon - 26.11.2011, 14:26
Re: Protecting Your MySQL-Enhanced Script - by Scenario - 26.11.2011, 14:29
Re: Protecting Your MySQL-Enhanced Script - by Calgon - 26.11.2011, 14:29
Re: Protecting Your MySQL-Enhanced Script - by Scenario - 26.11.2011, 14:32
Re: Protecting Your MySQL-Enhanced Script - by Calgon - 26.11.2011, 14:37
Re: Protecting Your MySQL-Enhanced Script - by serman - 26.11.2011, 14:42
Re: Protecting Your MySQL-Enhanced Script - by Scenario - 26.11.2011, 14:44

Forum Jump:


Users browsing this thread: 3 Guest(s)