Reset all mysql data when I write /rcon gmx
#1

Hello. I'm using Stricken Kid MySQL plugin and I've wierd issue with it. When I write /rcon gmx (if I'm logged in as Administrator) or gmx (in console), all data is cleared. In addition to this error, everything is saving normal - when performed GameModeExit, all data is stored, when performed OnPlayerConnect, everything is loading correctly.

Code of all my GM (it's tiny):
pawn Код:
#include <a_samp>
#include <md5>
#include <mysql>
#include <mselection>
#include <sscanf2>
#include <ucmd>

#if !defined isnull
    #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

#if MAX_PLAYERS == 500
    #undef MAX_PLAYERS
    #define MAX_PLAYERS             (500)
#endif

#define SQL_HOST                    "PRIVATE"
#define SQL_USR                     "PRIVATE"
#define SQL_PSWRD                   "PRIVATE"
#define SQL_DB                      "PRIVATE"
#define HidePlayerDialog(%1)        ShowPlayerDialog(%1, -1, 0, "", "", "", "")
#define MAXIMUM_LOGIN_TRIES         (4)
#define function%0(%1)              forward%0(%1); public %0(%1)

enum
{
    DIALOG_INFO = 0,
    DIALOG_LOGIN,
    DIALOG_REGISTER
};

enum E_PLAYER_DATA
{
    bool:loggedIn,
    score,
    kasa,
    smierci,
    zabojstw,
    loginAttempt,
    Float:posX,
    Float:posY,
    Float:posZ,
    Float:Angle,
    skin,
    savepData,
    bool:FirstSpawn
};
new pData[MAX_PLAYERS][E_PLAYER_DATA], MySQL:hMYSQL;
new skinlist = mS_INVALID_LISTID;
new gVehicleNames[212][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Pereniel", "Sentinel", "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana",
    "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto", "Taxi", "Washington", "Bobcat",
    "Mr Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks",
    "Hotknife", "Trailer", "Previon", "Coach", "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy",
    "Solair", "Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", "Harley", "RC Baron", "RC Raider", "Glendale", "Oceanic",
    "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR3 50", "Walton", "Regina",
    "Comet", "BMX", "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher", "FBI Rancher",
    "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa",
    "RC Goblin", "Hotring Racer", "Hotring Racer", "Bloodring Banger", "Rancher", "Super GT", "Elegant", "Journey", "Bike",
    "Mountain Bike", "Beagle", "Cropdust", "Stunt", "Tanker", "RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona", "FBI Truck", "Willard", "Forklift", "Traktor",
    "Combine", "Feltzer", "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover", "Sadler",
    "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor",
    "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna",
    "Bandito", "Freight", "Trailer", "Kart", "Mower", "Duneride", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley",
    "Stafford", "BF-400", "Newsvan", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Trailer", "Trailer",
    "Andromeda", "Dodo", "RC Cam", "Launch", "Radiowoz", "Radiowoz", "Radiowoz", "Radiowoz", "Picador", "S.W.A.T. Van",
    "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage Trailer", "Luggage Trailer", "Stair Trailer", "Boxville", "Farm Plow", "Utility Trailer"
};

main()
{
    new OdliczWlaczenie;
    new Ladowanie;
    new buf[120], strin[110], gamemodetext[20], mapname[20], weburl[20], hostname[60];
    OdliczWlaczenie = GetTickCount();
    printf(#Ładowanie nazw z bazy danych...);
    mysql_query("SELECT `gamemodetext`, `mapname`, `weburl`, `hostname` FROM `konfiguracja`");
    mysql_store_result();
    mysql_fetch_row(strin);
    sscanf(strin, "p<|>s[20]s[20]s[20]s[60]", gamemodetext, mapname, weburl, hostname);
    format(buf, sizeof(buf), "gamemodetext %s", gamemodetext), SendRconCommand(buf);
    format(buf, sizeof(buf), "mapname %s", mapname), SendRconCommand(buf);
    format(buf, sizeof(buf), "weburl %s", weburl), SendRconCommand(buf);
    format(buf, sizeof(buf), "hostname %s", hostname), SendRconCommand(buf);
    mysql_free_result();
    Ladowanie = GetTickCount() - OdliczWlaczenie;
    printf(#Czas ładowania danych: %d ms, Ladowanie);
    printf(#Dane zostały załadowane poprawnie!\n#PSD załadowano poprawnie!);
}

public OnGameModeInit()
{  
    UsePlayerPedAnims();
    for(new i = 0; i <= 299; i++)
    {
        AddPlayerClass(i, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
    }
    hMYSQL = mysql_init(1);
    new mHandle = mysql_connect(SQL_HOST, SQL_USR, SQL_PSWRD, SQL_DB, hMYSQL, 1);
    if(!mHandle) return printf("Nie można nawiązać połączenia z bazą!\nW związku z zaistniałą sytuacją, serwer zostanie wyłączony!"), SendRconCommand("exit");
   
    new BigString[1050];
    BigString = "";
    strcat(BigString, "CREATE TABLE IF NOT EXISTS `kontagraczy`(");
    strcat(BigString, "`id` int(11) NOT NULL AUTO_INCREMENT,");
    strcat(BigString, "`login` varchar(24) NOT NULL,");
    strcat(BigString, "`haslo` varchar(129) NOT NULL,");
    strcat(BigString, "`score` int(11) NOT NULL DEFAULT '0',");
    strcat(BigString, "`kasa` int(11) NOT NULL DEFAULT '0',");
    strcat(BigString, "`smierci` int(11) NOT NULL DEFAULT '0',");
    strcat(BigString, "`zabojstw` int(11) NOT NULL DEFAULT '0',");
    strcat(BigString, "`pozycja_X` double NOT NULL DEFAULT '0.0',");
    strcat(BigString, "`pozycja_Y` double NOT NULL DEFAULT '0.0',");
    strcat(BigString, "`pozycja_Z` double NOT NULL DEFAULT '0.0',");
    strcat(BigString, "`kat` double NOT NULL DEFAULT '0.0',");
    strcat(BigString, "`skin` int(3) NOT NULL DEFAULT '0',");
    strcat(BigString, "PRIMARY KEY (`id`),");
    strcat(BigString, "UNIQUE KEY `login` (`login`)");
    strcat(BigString, ") ENGINE = MyISAM  DEFAULT CHARSET = latin1 AUTO_INCREMENT = 2;");
    mysql_query(BigString), printf("Tabela `kontagraczy` została dodana!");
   
    new ConfigQuery[670];
    strcat(ConfigQuery, "CREATE TABLE IF NOT EXISTS `konfiguracja` (");
    strcat(ConfigQuery, "`gamemodetext` varchar(20) NOT NULL,");
    strcat(ConfigQuery, "`mapname` varchar(20) NOT NULL,");
    strcat(ConfigQuery, "`weburl` varchar(20) NOT NULL,");
    strcat(ConfigQuery, "`hostname` varchar(60) NOT NULL,");
    strcat(ConfigQuery, "PRIMARY KEY (`gamemodetext`)");
    strcat(ConfigQuery, ") ENGINE = InnoDB  DEFAULT CHARSET = latin1 AUTO_INCREMENT = 7;");
    mysql_query(ConfigQuery), printf("Tabela `konfiguracja` została dodana!");
   
    skinlist = LoadModelSelectionMenu("skins.txt");
    return 1;
}

public OnGameModeExit()
{
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i)) return OnPlayerDisconnect(i,1);
    }
    mysql_close(hMYSQL);
    return 1;
}

public OnPlayerConnect(playerid)
{
    new buf[130];
    pData[playerid][loggedIn] = false;
    pData[playerid][loginAttempt] = false;
    pData[playerid][score] = false;
    pData[playerid][kasa] = false;
    pData[playerid][smierci] = false;
    pData[playerid][zabojstw] = false;
    pData[playerid][posX] = 0.0;
    pData[playerid][posY] = 0.0;
    pData[playerid][posZ] = 0.0;
    pData[playerid][Angle] = 0.0;
    pData[playerid][skin] = false;
    pData[playerid][FirstSpawn] = true;
    SetPlayerFightingStyle(playerid, 15);
   
    PlayAudioStreamForPlayer(playerid, "http://kotstudent.pl/kotstudent.mp3");
    if(!accountPlayerExists(playerid)) return format(buf, sizeof(buf), "Witaj, %s!\nTwoje konto nie jest zarejestrowane.\nWpisz hasło w poniższe okno, a następnie kliknij przycisk 'REJESTRUJ'", PlayerName(playerid)), ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Rejestracja", buf, "Rejestruj", "");//, OnPlayerRequestClass(playerid, classid);
    format(buf, sizeof(buf), "Witaj, %s!\nTwoje konto jest zarejestrowane.\nWpisz hasło w poniższe okno, a następnie kliknij przycisk 'ZALOGUJ'", PlayerName(playerid)), ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logowanie", buf, "Zaloguj", "Opuść");
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    SaveData(playerid);
    KillTimer(pData[playerid][savepData]), printf("Dane gracza %s zostały zapisane po raz ostatni!", PlayerName(playerid));
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    if(pData[playerid][loggedIn] == false)
    {
        pData[playerid][FirstSpawn] = true;
        SetPlayerInterior(playerid, 0);
        SetPlayerPos(playerid, 3935.8965, -1096.5420, 3.2836);
        SetPlayerFacingAngle(playerid, 166.8000);
        SetPlayerCameraPos(playerid, 3934.8000 + (3.8*floatsin(-300.0, degrees)), -1101.0745 + (3.8*floatcos(-300.0, degrees)), 3.6500);
        SetPlayerCameraLookAt(playerid, 3935.2124, -1097.0251, 3.6500);
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(pData[playerid][FirstSpawn] == true && pData[playerid][loggedIn] == true)
    {
        SetPlayerScore(playerid,pData[playerid][score]);
        GivePlayerMoney(playerid,pData[playerid][kasa]);
        pData[playerid][FirstSpawn] = false;
        SetPlayerSkin(playerid, pData[playerid][skin]);
    }
    StopAudioStreamForPlayer(playerid);
    pData[playerid][savepData] = SetTimerEx("SaveData", 1 * 60 * 1000, true, !"i", playerid);
    return 1;
}
   
public OnPlayerDeath(playerid, killerid, reason)
{
    switch(killerid)
    {
        case INVALID_PLAYER_ID: pData[playerid][zabojstw]++;
        default: pData[playerid][smierci]++;
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch (dialogid)
    {
        case DIALOG_INFO: return 1;
        case DIALOG_LOGIN:
        {
            if(!response) return SendClientMessage(playerid, -1, "Brak zalogowania, automatyczny kick."), HidePlayerDialog(playerid), Kick(playerid);
            if(!passwordCorrect(inputtext))
            {
                pData[playerid][loginAttempt]++;
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logowanie", "Twoje konto jest zarejstrowane.\nPowtуrz hasło, ponieważ wprowadzone jest nieprawidłowe.", "Zaloguj", "Opuść");
                return SendClientMessage(playerid, -1, "Nieprawidlowe haslo, sprobuj ponownie.");
            }
            loginPlayer(playerid, inputtext);
        }
        case DIALOG_REGISTER:
        {
            new buf[129];
            if(!response) return 1;
            if(!passwordCorrect(inputtext))
            {
                format(buf, sizeof(buf), "Witaj, %s!\nTwoje konto nie jest zarejestrowane.\nProszę wpisać hasło w poniższe okno, a następnie kliknąć przycisk 'REJESTRUJ'", PlayerName(playerid));
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Rejestracja", buf, "Rejestruj", "");
                return SendClientMessage(playerid, -1, "Hasło może się składać tylko z liter i cyfr.");
            }
            format(buf, sizeof(buf), "INSERT INTO kontagraczy (login, haslo) VALUES ('%s', '%s')", PlayerName(playerid), MD5_Hash(passHash(inputtext, PlayerName(playerid))));
            if(mysql_query(buf) || mysql_affected_rows() < 1) return SendClientMessage(playerid, -1, "Wystapil blad podczas wysylania formularza. Sprobuj ponownie."), Kick(playerid);
            return 1;
        }
    }
    return 1;
}

public OnPlayerText(playerid, text[])
{
    new LogString[300];
    if(!strcmp(text, "pomoc"))
    {
        SendClientMessage(playerid, -1, "Dostępne komendy tekstowe: pomoc, skin oraz kill. Aby ich użyć, wystarczy wpisać te słowa na czacie.");
        return 0;
    }
    else if(!strcmp(text, "skin"))
    {
        ShowModelSelectionMenu(playerid, skinlist, "Wybierz skin");
        return 0;
    }
    else if(!strcmp(text, "kill"))
    {
        SetPlayerHealth(playerid, -100.0);
        return 0;
    }
    format(LogString, sizeof(LogString), "%s: %s", PlayerName(playerid), text);
    printf(LogString);
    return 1;
}


public OnPlayerCommandPerformed(success, playerid, cmdtext[])
{
    new text[100];
    if(!success) return format(text, sizeof(text), "Na serwerze nie ma takiej komendy jak %s! Zobacz: /cmd, /autor, /strona, /atrakcje", cmdtext), SendClientMessage(playerid, -1, text);
    if(!strcmp(cmdtext, "/", true)) return SendClientMessage(playerid, -1, "Nie znasz komend? Wystarczy, że wpiszesz słowo pomoc na czacie serwera!");
    else SendClientMessage(playerid, -1, "Nie znasz komend? Wystarczy, że wpiszesz słowo pomoc na czacie serwera!");
    return 1;
}

public OnPlayerModelSelection(playerid, response, listid, modelid)
{
    if(listid == skinlist)
    {
        if(!response) return SendClientMessage(playerid, 0xFF0000FF, "Wybуr skina został anulowany");
        SendClientMessage(playerid, 0xFF0000FF, "Skin wybrany");
        SetPlayerSkin(playerid, modelid);
        return 1;
    }
    return 1;
}

CMD:v(playerid, params[])
{
    str_del_free_space(params);
    if(isnull(params)) return SendClientMessage(playerid, -1, "Zła nazwa pojazdu!");
    CreatePlayerVehicle(playerid, GetVehicleModelIdByName(params));
    return 1;
}

function SaveData(playerid)
{
    new OdliczWlaczenie;
    new Ladowanie;
    OdliczWlaczenie = GetTickCount();
    print("Zapisywanie danych...");
    GetPlayerPos(playerid, pData[playerid][posX], pData[playerid][posY], pData[playerid][posZ]);
    GetPlayerFacingAngle(playerid, pData[playerid][Angle]);
    new buf[300];
    format(buf, sizeof(buf), "UPDATE `kontagraczy` SET `score` = '%d', `kasa` = '%d', `smierci` = '%d', `zabojstw` = '%d', `pozycja_X` = '%f', `pozycja_Y` = '%f', `pozycja_Z` = '%f', `kat` = '%f', `skin` = '%d' WHERE `login` = '%s'",
    pData[playerid][score],
    pData[playerid][kasa],
    pData[playerid][smierci],
    pData[playerid][zabojstw],
    pData[playerid][posX],
    pData[playerid][posY],
    pData[playerid][posZ],
    pData[playerid][Angle],
    GetPlayerSkin(playerid),
    PlayerName(playerid));
    printf(buf);
    mysql_query(buf);
    Ladowanie = GetTickCount() - OdliczWlaczenie;
    printf(#Czas zapisywania danych: %d ms, Ladowanie);
    if(IsPlayerConnected(playerid)) return print("Zapisano poprawnie wszystkie dane!");
    return 1;
}

CreatePlayerVehicle(playerid, modelid)
{
    new vehicle, Float:X, Float:Y, Float:Z, Float:angle;
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        vehicle = GetPlayerVehicleID(playerid);
        GetVehiclePos(vehicle, X, Y, Z);
        GetVehicleZAngle(vehicle, angle);
        DestroyVehicle(vehicle);
    }
    else
    {
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, angle);
    }
    vehicle = AddStaticVehicle(modelid, X, Y, Z + 1, angle, -1, -1);
    LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));
    SetVehicleNumberPlate(vehicle, PlayerName(playerid));//"{000000}"VehiclePlate"");
    PutPlayerInVehicle(playerid, vehicle, 0);
    return 1;
}

GetVehicleModelIdByName(vehiclename[])
{
    for(new i = 0; i < 211; i++)
        if(strfind(gVehicleNames[i], vehiclename, true) != -1) return i + 400;
    return -1;
}

str_del_free_space(string[], _char = ' ')
{
    new len = strlen (string);
    if(len)
    {
        new begin = -1, end = len;
        while (string[++begin] == _char) {}
        if(string[begin] == EOS)
        {
             string [0] = 0;
             return 1;
        }
        while (string[--end] == _char) {}
        strmid (string, string, begin, end+1, len+1);
    }
    return 1;
}

PlayerName(p){new N[MAX_PLAYER_NAME];GetPlayerName(p, N, sizeof(N));return N;}
passHash(const pass[], const name[])
{
    new hash[32];
    format(hash, sizeof(hash), "%sx6m5K%s", pass, name);
    return hash;
}

loadpData(playerid)
{
    pData[playerid][score] = strval(getPlayerAccountData(playerid, "score"));
    pData[playerid][kasa] = strval(getPlayerAccountData(playerid, "kasa"));
    pData[playerid][smierci] = strval(getPlayerAccountData(playerid, "smierci"));
    pData[playerid][zabojstw] = strval(getPlayerAccountData(playerid, "zabojstw"));
    pData[playerid][posX] = floatstr(getPlayerAccountData(playerid, "pozycja_X"));
    pData[playerid][posY] = floatstr(getPlayerAccountData(playerid, "pozycja_Y"));
    pData[playerid][posZ] = floatstr(getPlayerAccountData(playerid, "pozycja_Z"));
    pData[playerid][Angle] = floatstr(getPlayerAccountData(playerid, "kat"));
    pData[playerid][skin] = strval(getPlayerAccountData(playerid, "skin"));
}

getPlayerAccountData(playerid, const data[])
{
    new buf[127], result[80];
    format(buf, sizeof(buf), "SELECT %s FROM kontagraczy WHERE login = '%s'", data, PlayerName(playerid));
    if(mysql_query(buf)) mysql_ping();
    mysql_store_result(), mysql_fetch_row(result), mysql_free_result();
    return result;
}

accountPlayerExists(playerid)
{
    new buf[127], bool:exists = false, nick[MAX_PLAYER_NAME];
    mysql_real_escape_string(PlayerName(playerid), nick);
    format(buf, sizeof(buf), "SELECT 1 FROM kontagraczy WHERE login = '%s'", nick);
    if(mysql_query(buf)) mysql_ping();
    mysql_store_result();
    if(mysql_num_rows()) exists = true;
    mysql_free_result();
    return exists;
}

passwordCorrect(szPassword[])
{
    new length = strlen(szPassword);
    if(!(5 <= length < 20)) return 0;
    for (new i = 0; i != length; i++)
    {
        switch (szPassword[i])
        {
            case 'a' .. 'z': continue;
            case 'A' .. 'Z': continue;
            case '0' .. '9': continue;
            case '!', '@', '#', '$', '%', '^', '&', '*', '(', ')': continue;
            default: return 0;
        }
    }
    return 1;
}

loginPlayer(playerid, const password[])
{
    new buf[129];
    if(pData[playerid][loginAttempt] >= MAXIMUM_LOGIN_TRIES)
    {
        SendClientMessage(playerid, -1, "Wykorzystałeś limit prуb zalogowań! Zostałeś wyrzucony.");
        HidePlayerDialog(playerid);
        return Kick(playerid);
    }
    format(buf, sizeof(buf), "SELECT haslo FROM kontagraczy WHERE login = '%s'", PlayerName(playerid));
    mysql_query(buf), mysql_store_result(), mysql_fetch_row(buf), mysql_free_result();
    if(strcmp(MD5_Hash(passHash(password, PlayerName(playerid))), buf, true) != 0 && buf[0])
    {
        pData[playerid][loginAttempt]++;
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logowanie", "Twoje konto jest zarejstrowane.\nPowtуrz hasło, ponieważ wprowadzone jest nieprawidłowe.", "Zaloguj", "Opuść");
        return SendClientMessage(playerid, -1, "Nieprawidlowe haslo, sprobuj ponownie.");
    }
    pData[playerid][loggedIn] = true;
    SendClientMessage(playerid, -1, "Zostales zalogowany, milej Gry.");
    loadpData(playerid), SetSpawnInfo(playerid, NO_TEAM, pData[playerid][skin], pData[playerid][posX], pData[playerid][posY], pData[playerid][posZ], pData[playerid][Angle], 0, 0, 0, 0, 0, 0), SpawnPlayer(playerid);
    return 1;
}
Reply
#2

Why don't you make command when is called a timer will save player data and then gmx ?

pawn Код:
passHash(const pass[], const name[])
{
    new hash[32];
    format(hash, sizeof(hash), "%sx6m5K%s", pass, name);
    return hash;
}
Also i notice that you thing you are hashing players password , but you are wrong . I can easy separete password from this ! You should thing for better hashing algorithm (Whirlpool)
Reply
#3

I wrote clearly - when the gmx is entered in the console or using the /rcon gmx, the data are resetted. I don't need additional commands for create timer, I need only explanation - why this is happening, that all data are resetted...

And I know, that MD5 sucks in terms of safety.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)