Server crash when logging in
#1

I tryed updating my server from dini to SQLite but when i log in, the server crashes.

Here's the crash info:
Код:
Server crashed while executing GM.amx
[23:29:38] [debug] AMX backtrace:
[23:29:38] [debug] #0 native db_get_field_assoc () [0044de40] from samp-server.exe
[23:29:38] [debug] #1 000426bc in public OnDialogResponse (playerid=0, dialogid=5, response=1, listitem=-1, inputtext[]=@0x00058144 "numelemeu") at D:\Scripting\SAMP\Green Country RP\gamemodes\GM.pwn:4432
[23:29:39] [debug] Native backtrace:
[23:29:39] [debug] #0 0044dae1 in ?? () from samp-server.exe
[23:29:39] [debug] #1 004010b6 in ?? () from samp-server.exe
[23:29:39] [debug] #2 69a458ca in ?? () from plugins\crashdetect.DLL
[23:29:39] [debug] #3 69a4774f in ?? () from plugins\crashdetect.DLL
[23:29:39] [debug] #4 69a40834 in ?? () from plugins\crashdetect.DLL
[23:29:39] [debug] #5 69a4591a in ?? () from plugins\crashdetect.DLL
[23:29:39] [debug] #6 0046de11 in ?? () from samp-server.exe
[23:29:39] [debug] #7 00452970 in ?? () from samp-server.exe
[23:29:39] [debug] #8 7799e023 in ?? () from C:\Windows\SysWOW64\ntdll.dll
[23:29:39] [debug] #9 769e14d1 in ?? () from C:\Windows\syswow64\kernel32.dll
[23:29:39] [debug] #10 004a50fe in ?? () from samp-server.exe
[23:29:39] [debug] #11 68106ac3 in ?? () from samp-server.exe
[23:29:39] [debug] #12 004b3328 in ?? () from samp-server.exe
And here's the login system:
pawn Код:
case DIALOG_LOGIN1:
        {
            if(!response)
            {
                Kick(playerid);
            }
            else
            {
                new pwlength = strlen(inputtext);
                if(pwlength > 0)
                {
                    new buf[145];
                    WP_Hash(buf,sizeof(buf),inputtext);
                    new Query[256], DBResult:Result;
                    FormatQuery(Query, "SELECT * FROM `Users` WHERE `Name` = '%s' AND `Password` = '%s'", Name(playerid), buf);
                    Result = db_query(Database,Query);
                    if(db_num_rows(Result))
                    {
                        new Field[30];
                        db_get_field_assoc(Result, "Email", Field, 30 ); // Line 4432
                        pInfo[playerid][Email] = strval(Field);
                        db_get_field_assoc(Result, "Age", Field, 30 );
                        pInfo[playerid][Age] = strval(Field);
                        db_get_field_assoc(Result, "Admin", Field, 30 );
                        pInfo[playerid][Admin] = strval(Field);
                        db_get_field_assoc(Result, "Money", Field, 30 );
                        pInfo[playerid][Money] = strval(Field);
                        db_get_field_assoc(Result, "WeaponLic", Field, 30 );
                        pInfo[playerid][WeaponLic] = strval(Field);
                        db_get_field_assoc(Result, "Buletin", Field, 30 );
                        pInfo[playerid][Buletin] = strval(Field);
                        db_get_field_assoc(Result, "Faction", Field, 30 );
                        pInfo[playerid][Faction] = strval(Field);
                        db_get_field_assoc(Result, "Rank", Field, 30 );
                        pInfo[playerid][Rank] = strval(Field);
                                        // And so on...
And here's the query for the register system:
pawn Код:
new Query[256];
FormatQuery(Query,"UPDATE `Users` SET (`Email` = '%s',`Money` = '250',`Banned` = '0',`Buletin` = '0',`WeaponLic` = '0',`Sex` = '0',`Age` = '0',`Faction` = '0',`Rank` = '0',`Jailed` = '0',`JailTime` = '0',`Arrests` = '0',`Wanted` = '0',`Deaths` = '0',`Crimes` = '0',`Level` = '1',`RP` = '0',`RobTool` = '0') WHERE `Name` = '%s'",inputtext,Name(playerid));
db_free_result( db_query(Database, Query) );
FormatQuery(Query,"UPDATE `Users` SET (`BankMoney` = '0',`HouseOwned` = '-1',`Fishes` = '0',`Job` = '0',`Clothes` = '0',`Phone` = '0',`PhoneCredit` = '0',`PhoneNumber` = '0',`Phonebook` = '0',`Ceas` = '0',`Momeala` = '0',`GPS` = '0',`TimePlayed` = '0',`Hours` = '0',`Radio` = '0',`PayDayMoney` = '0',`MaxWork` = '0',`posX` = '0',`posY` = '0',`posZ` = '0',`VirtualWorld` = '0',`Interior` = '0') WHERE `Name` = '%s'",Name(playerid));
db_free_result( db_query(Database, Query) );
Thanks.
Reply
#2

Native db_get_field_assoc can crash the server when the field you're trying to retrieve data from is empty/NULL. The crash came from line 4432 so you got the field's name if you look at that line.

It's recommended to use default values and using "NOT NULL" while creating the tables to avoid such as things.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Native db_get_field_assoc can crash the server when the field you're trying to retrieve data from is empty/NULL. The crash came from line 4432 so you got the field's name if you look at that line.

It's recommended to use default values and using "NOT NULL" while creating the tables to avoid such as things.
Thanks for the advice, I looked at the database with a database browser, but all fields except for the Name and Password fields are empty, even though when someone registeres I made the fields like `Banned` = '0'.

And how do I set it so it's not null? Is it like MySQL? Here's the query to create the table when the server starts:
Код:
CREATE TABLE IF NOT EXISTS `Users` (`Name`,`Password`,`Admin`,`Money`,`Age`,`Sex`,`Email`,`Banned`,`Buletin`,`WeaponLic`,`Faction`,`Rank`,`Jailed`,`JailTime`,`Arrests`,`Wanted`,`Deaths`,`Crimes`,`Level`,`RP`,`BankMoney`,`RobTool`,`HouseOwned`,`Clothes`,`Job`,`Phone`,`PhoneNumber`,`PhoneCredit`,`Phonebook`,`Fishes`,`Ceas`,`Momeala`,`GPS`,`Radio`,`TimePlayed`,`Hours`,`TimeLeftUntilQuitjob`,`PayDayMoney`,`MaxWork`,`posX`,`posY`,`posZ`,`Interior`,`VirtualWorld`
Reply
#4

Use data-types in the table. For example (assuming passwords use Whirlpool, thus the lenght is 129):
pawn Код:
CREATE TABLE IF NOT EXISTS Users (Name VARCHAR(21) COLLATE NOCASE,Password VARCHAR(129),Admin INTEGER DEFAULT 0 NOT NULL, ...
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Use data-types in the table. For example (assuming passwords use Whirlpool, thus the lenght is 129):
pawn Код:
CREATE TABLE IF NOT EXISTS Users (Name VARCHAR(21) COLLATE NOCASE,Password VARCHAR(129),Admin INTEGER DEFAULT 0 NOT NULL, ...
Thank you very much
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)