MySQL Issues
#1

Hey there.
I've been having issues trying to convert my blank GM to MySQL.
First off.
pawn Код:
stock SaveAccount(playerid)
{
    if(LoggingIn[playerid] == 1) return 0;
    new query[300], Float:pos[3], Float:Angle;
    GetPlayerPos(playerid, pos[0],pos[1],pos[2]);
    GetPlayerFacingAngle(playerid, Angle);
    format(query, sizeof(query), "UPDATE `accounts` SET Admin='%d', Sex='%d', Skin='%d', Age='%d', PosX='%.2f', PosY='%.2f' ,PosZ='%.2f', FaceA='%.2f', Interior='%d',VirtualWorld='%d', CellNum='%d', Job='%d', Accent='%d', Faction='%d', Hospital='%d', Insurance='%d', WHERE `Name`='%s'",PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pSex], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pAge], pos[0],pos[1],pos[2], Angle, GetPlayerInterior(playerid),GetPlayerVirtualWorld(playerid),PlayerInfo[playerid][Name]);
    mysql_function_query(handle, query, false, "SendQuery", "");
    return 1;
}
This stock gives me
pawn Код:
B:\Development\SAMP\Blank Gamemode\gamemodes\crp.pwn(1271) : error 075: input line too long (after substitutions)
B:\Development\SAMP\Blank Gamemode\gamemodes\crp.pwn(1272) : error 017: undefined symbol "N"
B:\Development\SAMP\Blank Gamemode\gamemodes\crp.pwn(1273) : warning 217: loose indentation
B:\Development\SAMP\Blank Gamemode\gamemodes\crp.pwn(1273) : error 017: undefined symbol "ame"
B:\Development\SAMP\Blank Gamemode\gamemodes\crp.pwn(1273) : error 029: invalid expression, assumed zero
B:\Development\SAMP\Blank Gamemode\gamemodes\crp.pwn(1273) : error 029: invalid expression, assumed zero
B:\Development\SAMP\Blank Gamemode\gamemodes\crp.pwn(1273) : fatal error 107: too many error messages on one line
I'm not sure whats going on here. Any help is appreciated.
Reply
#2

The line is too long so separate its arguments:
pawn Код:
stock SaveAccount(playerid)
{
    if(LoggingIn[playerid] == 1) return 0;
    new query[300], Float:pos[3], Float:Angle;
    GetPlayerPos(playerid, pos[0],pos[1],pos[2]);
    GetPlayerFacingAngle(playerid, Angle);
    format(query, sizeof(query),
    "UPDATE `accounts` SET Admin='%d', Sex='%d', Skin='%d', Age='%d', PosX='%.2f', PosY='%.2f' ,PosZ='%.2f', FaceA='%.2f', Interior='%d',VirtualWorld='%d', CellNum='%d', Job='%d', Accent='%d', Faction='%d', Hospital='%d', Insurance='%d', WHERE `Name`='%s'",
    PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pSex], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pAge], pos[0],pos[1],pos[2], Angle, GetPlayerInterior(playerid),GetPlayerVirtualWorld(playerid),PlayerInfo[playerid][Name]);
    mysql_function_query(handle, query, false, "SendQuery", "");
    return 1;
}
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The line is too long so separate its arguments:
pawn Код:
stock SaveAccount(playerid)
{
    if(LoggingIn[playerid] == 1) return 0;
    new query[300], Float:pos[3], Float:Angle;
    GetPlayerPos(playerid, pos[0],pos[1],pos[2]);
    GetPlayerFacingAngle(playerid, Angle);
    format(query, sizeof(query),
    "UPDATE `accounts` SET Admin='%d', Sex='%d', Skin='%d', Age='%d', PosX='%.2f', PosY='%.2f' ,PosZ='%.2f', FaceA='%.2f', Interior='%d',VirtualWorld='%d', CellNum='%d', Job='%d', Accent='%d', Faction='%d', Hospital='%d', Insurance='%d', WHERE `Name`='%s'",
    PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pSex], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pAge], pos[0],pos[1],pos[2], Angle, GetPlayerInterior(playerid),GetPlayerVirtualWorld(playerid),PlayerInfo[playerid][Name]);
    mysql_function_query(handle, query, false, "SendQuery", "");
    return 1;
}
Also, if that too (the query) is exceeding the limit, use "\" to continue the string to the next line.

pawn Код:
new myString[32] = "This \
                               is \
                                continuation. "

                             ;
Reply
#4

Ahhh... derp.
Now, I have another issue I can't seem to find by search (Maybe I'm blind).
How would I compare Inputtext from a login dialog with a password in the database that was put into the database using "md5('%s').

The Code I have:
pawn Код:
case DIALOG_LOGIN:
        {
            if (!response) return Kick (playerid);
            if(response)
            {
                new query[128];
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login:","{FFFFFF}Please Enter your password below to login. \n\nCannot be blank!","Login","Exit");
                format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name`='%s' AND `Pass`=md5('%s')", PlayerInfo[playerid][Name], PlayerInfo[playerid][pPass]);
                mysql_function_query(handle, query, true, "OnAccountLoad", "d", playerid);
                /*if(inputtext == PlayerInfo[playerid][pPass]) //How Would I compare inputtext with Password stored?
                {
                    LoadAccount(playerid);
                }
                else
                {
                    if(LogginAttempts[playerid] == 2)
                    {
                        LogginAttempts[playerid] = 0;
                        Kick(playerid);
                    }
                    else
                    {
                        LogginAttempts[playerid]++;
                        new str[1024], string[256];
                        format(string, sizeof(string), "{FF4000}Incorrect Password   Attempts: %d\n", LogginAttempts[playerid]);
                        strcat(str, string);
                        format(string, sizeof(string), "{FFFFFF}You will be kicked after 3 attempts.\n");
                        strcat(str, string);
                        format(string, sizeof(string), "{FFFFFF}Please type your password below to login.\n");
                        strcat(str, string);
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login:", str, "Login", "Exit");
                    }
                }*/

            }
        }
Things that may help...
pawn Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
        SetCameraBehindPlayer(playerid);
        PlayerInfo[playerid][pCash] = cache_get_row_int(0,3,handle),
        PlayerInfo[playerid][pAdmin] = cache_get_row_int(0,4,handle),
        PlayerInfo[playerid][pSex] = cache_get_row_int(0,5,handle),
        PlayerInfo[playerid][pSkin] = cache_get_row_int(0,6,handle),
        PlayerInfo[playerid][pAge] = cache_get_row_int(0,7,handle),
        PlayerInfo[playerid][PosX] = cache_get_row_float(0,8,handle),
        PlayerInfo[playerid][PosY] = cache_get_row_float(0,9,handle),
        PlayerInfo[playerid][PosZ] = cache_get_row_float(0,10,handle),
        PlayerInfo[playerid][FaceA] = cache_get_row_float(0,11,handle),
        PlayerInfo[playerid][Interior] = cache_get_row_int(0,12,handle),
        PlayerInfo[playerid][VirtualWorld] = cache_get_row_int(0,13,handle),
        PlayerInfo[playerid][CellNum] = cache_get_row_int(0,14,handle),
        PlayerInfo[playerid][Job] = cache_get_row_int(0,15,handle),
        PlayerInfo[playerid][Accent] = cache_get_row_int(0,16,handle),
        PlayerInfo[playerid][Faction] = cache_get_row_int(0,17,handle),
        PlayerInfo[playerid][Hospital] = cache_get_row_int(0,18,handle),
        PlayerInfo[playerid][Insurance] = cache_get_row_int(0,19,handle);
        LoggingIn[playerid] = 1;
        return 1;
}

stock CreateAccount(playerid,pass[])
{
        new query[240], name[24];
        GetPlayerName(playerid, name, sizeof(name));
        format(query, sizeof(query), "INSERT INTO `accounts` (Name,Pass) VALUES (\'%s\', \'md5('%s')\')", name, pass);
        mysql_function_query(handle, query, false, "SendQuery", "");
}

stock LoadAccount(playerid)
{
        new query[128];
        format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name`='%s'", PlayerInfo[playerid][Name]);
        mysql_function_query(handle, query, true, "OnAccountLoad", "d", playerid);
}
Reply
#5

Quote:
Originally Posted by Jacksta21
Посмотреть сообщение
....
First of all, DON'T use MD5 - it's completely insecure. (read this)

You can use MD5 on the 'inputtext', retrieve the password from the DB & compare using strcmp.

I don't have an idea of what the MD5 function looks like, if it explicitly returns the string, then something like -

pawn Код:
if(!strcmp(md5(inputtext), retrievedPass))
{
 
 // log him in
}
If you are asking on HOW to retrieve the password, then you can search on how to use MySQL, on the forums in the tutorial section.
Reply
#6

Suggestions on which encryption to use?
Whirlpool or something else like the Encrypt plugin?
Thanks for help btw.
EDIT: I'm not asking how, I have that done (I think) just comparing strings & storing/reading them as encrypted strings.
Reply
#7

Quote:
Originally Posted by Jacksta21
Посмотреть сообщение
Suggestions on which encryption to use?
Whirlpool or something else like the Encrypt plugin?
Thanks for help btw.
EDIT: I'm not asking how, I have that done (I think) just comparing strings & storing/reading them as encrypted strings.
https://sampforum.blast.hk/showthread.php?tid=496953
This plugin works quite well, you can use whatever you like from the 'Hash functions' list. (whirlpool is usually the one to go for, but others are equally as safe)
Reply
#8

Okay.. For some reason it will only recoignise the first made accounts password. After that when more rows are added to the databases no ones registered Passwords work?
pawn Код:
case DIALOG_LOGIN:
        {
            if (!response) return Kick (playerid);
            if(response)
            {
                new buf[129];
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login:","{FFFFFF}Please Enter your password below to login. \n\nCannot be blank!","Login","Exit");
                WP_Hash(buf, sizeof(buf), inputtext);
                if(strcmp(buf, PlayerInfo[playerid][pPass]))
                {
                    if(LogginAttempts[playerid] == 2)
                    {
                        LogginAttempts[playerid] = 0;
                        Kick(playerid);
                    }
                    else
                    {
                        LogginAttempts[playerid]++;
                        new str[1024], string[256];
                        format(string, sizeof(string), "{FF4000}Incorrect Password   Attempts: %d\n", LogginAttempts[playerid]);
                        strcat(str, string);
                        format(string, sizeof(string), "{FFFFFF}You will be kicked after 3 attempts.\n");
                        strcat(str, string);
                        format(string, sizeof(string), "{FFFFFF}Please type your password below to login.\n");
                        strcat(str, string);
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login:", str, "Login", "Exit");
                    }
                }
                else
                {
                    LoadAccount(playerid);
                }
            }
        }
pawn Код:
stock CheckAccount(playerid)
{
    new query[82];
    format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%s'", PlayerInfo[playerid][Name]);
    mysql_function_query(handle, query, true, "OnAccountCheck", "d", playerid);
    return 1;
}

forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    if(playerid != INVALID_PLAYER_ID)
    {
        new rows, fields;
        cache_get_data(rows, fields, handle);
        if(rows)
        {
            //cache_get_row(0,1,PlayerInfo[playerid][pPass],handle, 64);
            cache_get_field_content(0, "Pass", PlayerInfo[playerid][pPass], handle, 129);
            ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login:","Please Enter your password below to login.","Login","Exit");
        }
        else
        {
            ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register:","Please Enter a password below to register.","Register","Exit");
        }
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by RajatPawar
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=496953
This plugin works quite well, you can use whatever you like from the 'Hash functions' list. (whirlpool is usually the one to go for, but others are equally as safe)
Don't really know why you would use a entire extra plugin for one function you'd maybe use twice. MySQL supports sha1 and sha2 (the latter from 5.5 onwards) which, in combination with a salt, should be sufficient.
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
Don't really know why you would use a entire extra plugin for one function you'd maybe use twice. MySQL supports sha1 and sha2 (the latter from 5.5 onwards) which, in combination with a salt, should be sufficient.
agreed with him. i used SHA1 too...
i think it good to use
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)