Dialog gives wrong information
#1

Hello,

I have a dialog that shows the banned persons details, including BAN ID, username, reason, ip, and expire date.

BUt for some reason the last two don't want to show up correctly


As you can tell by yourself that's a weird looking IP and the expire date is when the UNIX time-stamps started.

The code:

pawn Код:
case DIALOG_BANLIST:
        {
            if(response)
            {
                new banString[800], expireDate[128];
                mtime_UnixToDate(expireDate, sizeof(expireDate), BanInfo[listitem][bUNIXExpire]);
                format(banString, sizeof(banString), "Ban ID: \t\t%d \nUsername:\t%s \nReason: \t%s \nIP: \t\t%s \nExpires on: \t%s ", BanInfo[listitem][bBanIndex], BanInfo[listitem][bBannedPlayer], BanInfo[listitem][bBanReason], BanInfo[listitem][bBannedIP], expireDate);
                ShowPlayerDialog(playerid, DIALOG_BANINFO, DIALOG_STYLE_LIST, "Ban Information", banString, "Ok", "");
            }
        }
And the part where I fetch the MySQL data:
pawn Код:
for (new i = 0; i < rows; ++i)
            {
                while(mysql_fetch_row_format(banQuery, "|"))
                {
                    mysql_fetch_field_row(BanInfo[i][bBanIndex], "BanIndex");
                    mysql_fetch_field_row(BanInfo[i][bBannedPlayer], "BannedPlayer");
                    mysql_fetch_field_row(BanInfo[i][bBannedIP], "BannedIP");
                    mysql_fetch_field_row(BanInfo[i][bBanIssuer], "BanIssuer");
                    mysql_fetch_field_row(BanInfo[i][bBanReason], "BanReason");
                    mysql_fetch_field_row(BanInfo[i][bUNIXExpire], "UNIXExpire");
                    mysql_fetch_field_row(BanInfo[i][bUNIXBan], "UNIXBan");

                    strcat(finalString,BanInfo[i][bBannedPlayer]);
                    strcat(finalString,"\n");
                }
            }
            strcat(finalString, tmp);
            ShowPlayerDialog(playerid,DIALOG_BANLIST,DIALOG_STYLE_LIST, "{ff6600}Banlist", finalString,"Change","Cancel");

More information:

Saving it into enums:
pawn Код:
enum E_BAN_INFO
{
    bBanIndex,
    bBannedPlayer[MAX_PLAYER_NAME],
    bBanIssuer[MAX_PLAYER_NAME],
    bBanReason[128],
    bUNIXExpire,
    bUNIXBan,
    bBannedIP[30]
};
new BanInfo[MAX_BANS][E_BAN_INFO];
When banning someone:

pawn Код:
stock BanPlayer(playerid, playerBanner[], banReason[], banDays)
{
    new pName[MAX_PLAYER_NAME], escapedName[MAX_PLAYER_NAME], escapedActionName[MAX_PLAYER_NAME], safeReason[128], playerIp[16], banQuery[300];

    GetPlayerName(playerid, pName, sizeof(pName));
    mysql_real_escape_string(pName, escapedName);
    mysql_real_escape_string(playerBanner, escapedActionName);
    mysql_real_escape_string(banReason, safeReason);
    GetPlayerIp(playerid, playerIp, sizeof(playerIp));

    if(banDays == 0) { format(banQuery, sizeof(banQuery), "INSERT INTO bans(BannedPlayer, BannedIP, BanIssuer, BanReason, UNIXBan, UNIXExpire, ShouldExpire, Expired) VALUES('%s', '%s', '%s', '%s', %i, 0, 0, 0)", escapedName, playerIp, escapedActionName, safeReason, gettime()); }
    else { format(banQuery, sizeof(banQuery), "INSERT INTO bans(BannedPlayer, BannedIP, BanIssuer, BanReason, UNIXBan, UNIXExpire, ShouldExpire, Expired) VALUES('%s', '%s', '%s', '%s', %i, %i, 1, 0)", escapedName, playerIp, escapedActionName, safeReason, gettime(), gettime() + (banDays * 86400)); }

    mysql_query(banQuery);

    KickEx(playerid, 5);
    return 1;
}


Anyone knows why this is like this?
Reply
#2

Hello there.
The code you have provided has nothing to do with Your problem.

Please here this function:
pawn Код:
mtime_UnixToDate()
About IP..

How looks like ban function? I mean the part with IP writing.

Greetz,
LetsOWN
Reply
#3

Date: It looks like your conversion from Unix timestamp to date is failing.
IP: Are you sure you didn't store the IP as an integer? GetPlayerIp returns the IP as a string in case you didn't know
Reply
#4

Quote:
Originally Posted by Jakku
Посмотреть сообщение
Date: It looks like your conversion from Unix timestamp to date is failing.
IP: Are you sure you didn't store the IP as an integer? GetPlayerIp returns the IP as a string in case you didn't know
Yea, I save it into a string.
pawn Код:
enum E_BAN_INFO
{
    bBanIndex,
    bBannedPlayer[MAX_PLAYER_NAME],
    bBanIssuer[MAX_PLAYER_NAME],
    bBanReason[128],
    bUNIXExpire,
    bUNIXBan,
    bBannedIP[30]
};
new BanInfo[MAX_BANS][E_BAN_INFO];
Reply
#5

Anyone?
Reply
#6

How you store it in the database? (IP)
Reply
#7

pawn Код:
stock BanPlayer(playerid, playerBanner[], banReason[], banDays)
{
    new pName[MAX_PLAYER_NAME], escapedName[MAX_PLAYER_NAME], escapedActionName[MAX_PLAYER_NAME], safeReason[128], playerIp[16], banQuery[300];

    GetPlayerName(playerid, pName, sizeof(pName));
    mysql_real_escape_string(pName, escapedName);
    mysql_real_escape_string(playerBanner, escapedActionName);
    mysql_real_escape_string(banReason, safeReason);
    GetPlayerIp(playerid, playerIp, sizeof(playerIp));

    if(banDays == 0) { format(banQuery, sizeof(banQuery), "INSERT INTO bans(BannedPlayer, BannedIP, BanIssuer, BanReason, UNIXBan, UNIXExpire, ShouldExpire, Expired) VALUES('%s', '%s', '%s', '%s', %i, 0, 0, 0)", escapedName, playerIp, escapedActionName, safeReason, gettime()); }
    else { format(banQuery, sizeof(banQuery), "INSERT INTO bans(BannedPlayer, BannedIP, BanIssuer, BanReason, UNIXBan, UNIXExpire, ShouldExpire, Expired) VALUES('%s', '%s', '%s', '%s', %i, %i, 1, 0)", escapedName, playerIp, escapedActionName, safeReason, gettime(), gettime() + (banDays * 86400)); }

    mysql_query(banQuery);

    KickEx(playerid, 5);
    return 1;
}
Storing it as that. But the logs just show the IP normal like if it would have been 127.0.0.1 in the DB, it fetches it also like that.
Reply
#8

Print the IP before showing the dialog; does it match with what is in the DB?
Reply
#9

In your database how it is stored? How you see it if u go to table with phpmyadmin (or something like this)
Reply
#10

Alright I think I've noticed the problem.

This is the output of the IP: 365698819

But what's wrong with the code, as I can see it's alright. (It's obviously not though)

Once again the fetch codes

pawn Код:
mysql_fetch_field_row(BanInfo[i][bBanIndex], "BanIndex");
                    mysql_fetch_field_row(BanInfo[i][bBannedPlayer], "BannedPlayer");
                    mysql_fetch_field_row(BanInfo[i][bBannedIP], "BannedIP");
                    mysql_fetch_field_row(BanInfo[i][bBanIssuer], "BanIssuer");
                    mysql_fetch_field_row(BanInfo[i][bBanReason], "BanReason");
                    mysql_fetch_field_row(BanInfo[i][bUNIXExpire], "UNIXExpire");
                    mysql_fetch_field_row(BanInfo[i][bUNIXBan], "UNIXBan");
                    printf("%s",BanInfo[i][bBannedIP]);
                    strcat(finalString,BanInfo[i][bBannedPlayer]);
                    strcat(finalString,"\n");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)