mysql problem
#1

I have a problem, can someone tell why when i register a new account and i rejoin, i have to register again?

OnPlayerConnect

pawn Код:
new query[128];
    new name[24];
    GetPlayerName(playerid, name, sizeof(name));
    new IP[16];
    GetPlayerIp(playerid, IP, 16);
    mysql_format(mysql, query, sizeof(query),"SELECT * FROM `playerdata` WHERE `user` = '%e' LIMIT 1", name);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);

    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_row(0, 2, PlayerInfo[playerid][Password], mysql, 129);
        PlayerInfo[playerid][pAccountID] = cache_get_row_int(0, 0);
        printf("%s", PlayerInfo[playerid][Password]);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.", "Register", "Quit");
    }
The public:

pawn Код:
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_row(0, 2, PlayerInfo[playerid][Password], mysql, 129);
        PlayerInfo[playerid][pAccountID] = cache_get_row_int(0, 0);
        printf("%s", PlayerInfo[playerid][Password]);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.", "Register", "Quit");
    }
    return 1;
}
The register dialog:

pawn Код:
new query[1000];
    if(dialogid == DIALOG_REGISTER)
    {
        if(response)
        {
            new pname[24];
            GetPlayerName(playerid, pname, sizeof(pname));
            new IP[16];
            GetPlayerIp(playerid, IP, sizeof(IP));
            if(CheckInput(inputtext)) return SendClientMessage(playerid, 0x0000ff, "You cannot use this password.");
            if(strlen(inputtext) < 4 || strlen(inputtext) > 20) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.\nYour password must be at least min 4 characters and max 20.", "Register", "Quit");
            WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
            mysql_format(mysql, query, sizeof(query), "INSERT INTO playerdata (user, password, Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions, Cookies, Rank, VipTime, Class, PrototypesStolen, KillAsUsaTeam, KillAsGermanyTeam, KillAsItalyTeam, KillAsJapanTeam, KillAsMercTeam, KillAsMexicoTeam, IP, DaysAlive) VALUES('%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0, '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '%s', '0')", pname, PlayerInfo[Password], InsertTimeStamp(), IP);
            mysql_tquery(mysql, query, "", "");
            new Bannedby[20];
            format(Bannedby, 20, "Not Banned");
            Logged[playerid] = 1;
            new stats[128];
            format(stats, sizeof(stats), "UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1");
            mysql_function_query(mConnectionHandle, stats, false, "", "");
            WindowForPlayer(playerid, "You are now ~r~registered ~w~to Battlefield War Heroes! Enjoy playing!");
            WelcomeDialog(playerid);
            new echo[130];
            new kname[24];
            GetPlayerName(playerid, kname, 24);
            format(echo,sizeof(echo),"0,3** System: %s (%d) (IP: %s) has registered a new account",pname,playerid,IP);
            IRC_GroupSay(gGroupID, IRC_ACHANNEL, echo);
            new admin[128];
            format(admin,sizeof(admin),"** System: %s (%d) (%s) has registered a new account.",pname,playerid,IP);
            SendStaffMessage(LIGHTBLUE,admin);
            new txd[128];
            format(txd,sizeof(txd),"%s (%d) (IP: %s) registered a new account",pname,playerid,IP);
            TextDrawSetString(RegTxd, txd);
            new welcome[130];
            format(welcome, sizeof(welcome), "Welcome to Battlefield War Heroes, ~r~%s! Type ~r~/rules ~w~and ~r~/cmds ~w~for server info.",pname);
            GameTextForPlayer(playerid,welcome,6000,4);
        }
        if(!response)
        {
        SendClientMessage(playerid, COLOR_RED, "** To play you must be registered or logged in.");
        KickTimer[playerid] = SetTimerEx("KickPlayer",200,false,"d",playerid);
        }
    }
mysql log:

Quote:

[11:59:21] [DEBUG] mysql_errno - connection: 1
[11:59:42] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `Bans` WHERE (`Username` = 'yugyyygu' OR `IP` = '1", callback: "(null)", format: "(null)"
[11:59:42] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[11:59:42] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM `Bans` WHERE (`Username` = 'yugyyygu' OR `IP` = '192.168.1.3') AND `Banned` = 1 LIMIT 1"..
[11:59:42] [DEBUG] cache_get_row_count - connection: 1
[11:59:42] [DEBUG] mysql_format - connection: 0, len: 128, format: "SELECT * FROM `playerdata` WHERE `user` = '%e' LIMIT 1"
[11:59:42] [DEBUG] mysql_tquery - connection: 0, query: "", callback: "OnAccountCheck", format: "i"
[11:59:42] [DEBUG] cache_get_data - connection: 0
[11:59:42] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE ServerStats SET TotalJoins = TotalJoins + 1", callback: "(null)", format: "(null)"
[11:59:42] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[11:59:42] [DEBUG] mysql_tquery - scheduling query "UPDATE ServerStats SET TotalJoins = TotalJoins + 1"..
[11:59:42] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[11:59:43] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[11:59:43] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[11:59:43] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[11:59:43] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[11:59:43] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[11:59:43] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[11:59:43] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[11:59:43] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[11:59:43] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[11:59:45] [DEBUG] mysql_format - connection: 0, len: 1000, format: "INSERT INTO playerdata (user, password, Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions,..."
[11:59:45] [DEBUG] mysql_tquery - connection: 0, query: "", callback: "(null)", format: "(null)"
[11:59:45] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1", callback: "(null)", format: "(null)"
[11:59:45] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[11:59:45] [DEBUG] mysql_tquery - scheduling query "UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1"..
[11:59:45] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[11:59:45] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[11:59:45] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[11:59:45] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[11:59:45] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[11:59:52] [DEBUG] mysql_tquery - connection: 0, query: "UPDATE `playerdata` SET Scores='0', Cash='0', Admin='0', Deaths=", callback: "(null)", format: "(null)"

What's wrong? lol
Reply
#2

In OnPlayerConnect, after mysql_tquery you can't use cache functions yet. Remove the part below mysql_tquery, and leave the task of displaying dialog to OnAccountCheck (code inside it is ok).
Reply
#3

Did already but when i connect for some strange reasons it doesn't show the register/login dialog.
Reply
#4

Found the culprit - look closely at your logs.
Quote:

mysql_format - connection: 0, len: 128, format: "SELECT * FROM `playerdata` WHERE `user` = '%e' LIMIT 1"

As you can see the connection is 0, not 1 as in other queries. You are either executing that too early, before establishing connection, or something earlier breaks it.
Reply
#5

This is the FULL OnPlayerConnect:

pawn Код:
public OnPlayerConnect(playerid)
{
    IsPlayerBanned(playerid);
    new query[128];
    new name[24];
    GetPlayerName(playerid, name, sizeof(name));
    new IP[16];
    GetPlayerIp(playerid, IP, 16);
    mysql_format(mysql, query, sizeof(query),"SELECT * FROM `playerdata` WHERE `user` = '%e' LIMIT 1", name);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
   
    MoneyGiven[playerid] = -1;
    JustLogged[playerid] = 0;
   
    SendDeathMessage(INVALID_PLAYER_ID,playerid, 200);
    SetPVarInt(playerid, "spawned", 0);
   
    StealingA69Prot[playerid] = 0;
    CapturingABAP[playerid] = 0;
    CapturingA69[playerid] = 0;
    CapturingHQ[playerid] = 0;
    CapturingBS[playerid] = 0;
    CapturingSFB[playerid] = 0;
    SpeedWarnings[playerid] = 0;
    ArmourWarnings[playerid] = 0;
    pAlive[playerid] = 0;
    pCheck[playerid] = 0;
    IsTakingOverTurf[playerid] = 0;
    RhinoKills[playerid] = 0;
    HydraKills[playerid] = 0;
    HunterKills[playerid] = 0;
    SeaSparrowKills[playerid] = 0;
    RustlerKills[playerid] = 0;
    cowit[playerid] = 0;
    killstreak[playerid] = 0;
   
    //==============Map Icons================================
    SetPlayerMapIcon(playerid,6, 388.7785,2481.7974,16.4844, 5, 0, MAPICON_GLOBAL); //Abandoned Airport
    SetPlayerMapIcon(playerid,7, 160.7681,1903.1256,18.7615, 6, 0, MAPICON_GLOBAL); //Area69
    SetPlayerMapIcon(playerid,8, 397.7717,858.3791,20.0455, 11, 0, MAPICON_GLOBAL); //Hunter Quarry
    SetPlayerMapIcon(playerid,9, -2498.7642,2359.2964,14.1182, 18, 0, MAPICON_GLOBAL); //Bayside
    SetPlayerMapIcon(playerid,10, -1400.9016,660.2661,34.5781, 20, 0, MAPICON_GLOBAL); //Red Gant Bridge
    SetPlayerMapIcon(playerid,12, 1602.0250,1435.7529,10.8261, 21, 0, MAPICON_GLOBAL); //LV Airport
   
    GangZoneShowForPlayer(playerid, Zone[AbandonedAp], 0xC0C0C075);
    GangZoneShowForPlayer(playerid, Zone[Area69], 0xC0C0C075);
    GangZoneShowForPlayer(playerid, Zone[HunterQuarry], 0xC0C0C075);
    GangZoneShowForPlayer(playerid, Zone[Bayside], 0xC0C0C075);
    GangZoneShowForPlayer(playerid, Zone[SFBridge], 0xC0C0C075);
    GangZoneShowForPlayer(playerid, Zone[LVAirport], 0xC0C0C075);

    TextDrawSetString(Sprite0, Sprites[random(sizeof(Sprites))]);
    TextDrawShowForPlayer(playerid,Sprite0);
   
    TextDrawShowForPlayer(playerid, WebSiteTxd);
    TextDrawShowForPlayer(playerid, LogoTxd);

    new joinMsg[110], lname[24];
    GetPlayerName(playerid, lname, sizeof(lname));
    format(joinMsg, sizeof(joinMsg), "3[%d]3 +++ %s has joined the server.", playerid, lname);
    IRC_GroupSay(gGroupID, IRC_CHANNEL, joinMsg);

    new ipschan[150];
    new IPP[40];
    GetPlayerIp(playerid, IPP, sizeof(IPP));
    format(ipschan, sizeof(ipschan), "** %s (%d) IP: %s - %s", name,playerid,IPP,InsertTimeStamp());
    dini_Set("/Logs/playerips.txt",name,IPP);
    JoinsLog(ipschan);
    IRC_GroupSay(gGroupID, IRC_IPCHANNEL, ipschan);
   
    new stats[128];
    format(stats, sizeof(stats), "UPDATE ServerStats SET TotalJoins = TotalJoins + 1");
    mysql_function_query(mConnectionHandle, stats, false, "", "");

    for( new i = 0; i <= 50; i ++ ) SCM(playerid,-1, "" );
    new welcome[250];
    format(welcome,sizeof(welcome),"{53C506}** {FFFFFF}Welcome to {F70505}%s - Please read /rules and /cmds {FFFFFF}for server info.",BUILD);
    SCM(playerid, -1, welcome);
    SCM(playerid,0xFF8080FF, "** Earn Battlefield Achievements (BA) to get extra score and money! Check /acinfo for more");
    SCM(playerid,0xFF8080FF, "** NOTICE: If you see anyone hacking please report it using /report [id] [reason]");
    return 1;
}
I don't see anything wrong.

IsPlayerBanned is the stock that check if the player is banned (stored in the "Bans" table.
Reply
#6

Change ALL "mysql" variable occurances to "mConnectionHandle", or establish connection on "mysql".

Also, tip:
pawn Код:
//If you don't need number of fields, then:
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows)
//can be substitued with
if(cache_num_rows(mConnectionHandle))
Reply
#7

Ok changed all "mysql" variable with "mConnectionHandle", got a problem here:

pawn Код:
mysql_format(mConnectionHandle, query, sizeof(query), "INSERT INTO playerdata (user, password, Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions, Cookies, Rank, VipTime, Class, PrototypesStolen, KillAsUsaTeam, KillAsGermanyTeam, KillAsItalyTeam, KillAsJapanTeam, KillAsMercTeam, KillAsMexicoTeam, IP, DaysAlive) VALUES('%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0, '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '%s', '0')", pname, PlayerInfo[Password], InsertTimeStamp(), IP);
            mysql_tquery(mConnectionHandle, query, "", "");
Input line too long. Any tip to how run this long query?

After i fix this, i'll try the register/login.
Reply
#8

You can place new line between arguments. If the string itself is too long, you might need to create it earlier using strcpy and strcat. Alternatively you can use Zeex's patches for compiler (somewhere in tools subforum), which allows lines up to 4k characters.
Reply
#9

Ok fixed the long query, now it shows the register dialog. But i get the same problem of the first post. It asks me everytime to register again.

mysq_log:

Quote:

[13:00:41] [DEBUG] CMySQLConnection::Connect - connection was successful
[13:00:41] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[13:00:41] [DEBUG] CMySQLConnection::Connect - connection was successful
[13:00:41] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[13:00:41] [DEBUG] mysql_errno - connection: 1
[13:01:02] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT * FROM `playerdata` WHERE `user` = '%e' LIMIT 1"
[13:01:02] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `playerdata` WHERE `user` = 'uihuhuguhhlllll' LIMI", callback: "OnAccountCheck", format: "i"
[13:01:02] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:01:02] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM `playerdata` WHERE `user` = 'uihuhuguhhlllll' LIMIT 1"..
[13:01:02] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `Bans` WHERE (`Username` = 'uihuhuguhhlllll' OR `I", callback: "(null)", format: "(null)"
[13:01:02] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:01:02] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM `Bans` WHERE (`Username` = 'uihuhuguhhlllll' OR `IP` = '192.168.1.3') AND `Banned` = 1 LIMIT 1"..
[13:01:02] [DEBUG] cache_get_row_count - connection: 1
[13:01:02] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE ServerStats SET TotalJoins = TotalJoins + 1", callback: "(null)", format: "(null)"
[13:01:02] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:01:02] [DEBUG] mysql_tquery - scheduling query "UPDATE ServerStats SET TotalJoins = TotalJoins + 1"..
[13:01:02] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(i)] - starting query execution
[13:01:02] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(i)] - query was successful
[13:01:02] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[13:01:02] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(i)] - data being passed to ProcessCallbacks()
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[13:01:02] [DEBUG] Calling callback "OnAccountCheck"..
[13:01:02] [DEBUG] cache_get_data - connection: 1
[13:01:02] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[13:01:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[13:01:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[13:01:02] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[13:01:02] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[13:01:05] [DEBUG] mysql_format - connection: 1, len: 1000, format: "INSERT INTO playerdata(user, password, Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions, ..."
[13:01:05] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO playerdata(user, password, Scores, Cash, Admin, Deat", callback: "(null)", format: "(null)"
[13:01:05] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:01:05] [DEBUG] mysql_tquery - scheduling query "INSERT INTO playerdata(user, password, Scores, Cash, Admin, Deaths, Nopm, Muted, Vip, Warn, RegisterDate, Jailed, AdminActions, Cookies, Rank, VipTime, Class, PrototypesStolen, KillAsUsaTeam, KillAsGermanyTeam, KillAsItalyTeam, KillAsJapanTeam, KillAsMercTeam, KillAsMexicoTeam, IP, DaysAlive) VALUES('uihuhuguhhlllll', '', 0, 0, 0, 0, 0, 0, 0, 0, '26/1/2014 13:1:5', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '192.168.1.3', '0')"..
[13:01:05] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1", callback: "(null)", format: "(null)"
[13:01:05] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:01:05] [DEBUG] mysql_tquery - scheduling query "UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1"..
[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - error will be triggered in OnQueryError
[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[13:01:05] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[13:01:05] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[13:01:10] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `playerdata` SET Scores='0', Cash='0', Admin='0', Deaths=", callback: "(null)", format: "(null)"
[13:01:10] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:01:10] [DEBUG] mysql_tquery - scheduling query "UPDATE `playerdata` SET Scores='0', Cash='0', Admin='0', Deaths='0', Nopm='0', Muted='0', Vip='0', Warn='0', RegisterDate='0', Jailed='0', AdminActions='0', Cookies='0', Rank='0', VipTime='0', Class='0', PrototypesStolen='0', Exp='0', Duty='0', KillAsUsaTeam='0', KillAsGermanyTeam='0', KillAsItalyTeam='0', KillAsJapanTeam='0', KillAsMercTeam='0', KillAsMexicoTeam='0', DaysAlive='0' WHERE user='uihuhuguhhlllll'"..
[13:01:10] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[13:01:10] [DEBUG] CMySQLQuery::Execute[()] - error will be triggered in OnQueryError
[13:01:10] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[13:01:10] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called

Reply
#10

Quote:

[13:01:05] [DEBUG] CMySQLQuery::Execute[()] - error will be triggered in OnQueryError

Your insert query is invalid (lots of fields, easy to make a typo). Use additional tool, like phpmyadmin, heidisql or any type of mysql database manager - execute the insert query there and take a look at error. Or simply find in your mysql_log line starting with [ERROR] and take a look there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)