Timestamp problem
#1

Hey guys i'm having a problem with my temp ban system that checks if a player is banned or not. To be exact it more to do with the conversion of the unix timestamp to Day, Hours and Minutes but when it does it i basically use says.

12345 Days, 678 Hours, 4 minutes.


pawn Код:
stock CheckAccountBan(playerid)
{
    new bExpiration;
    format(Query, sizeof(Query), "SELECT * FROM `server_bans` WHERE (Username = '%s' OR IpAddress = '%s') AND status = 1", GetPName(playerid), GetIP(playerid));
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() >= 1)
    {
        new bReason[126], bannedBy[MAX_PLAYER_NAME];
        while(mysql_fetch_row_format(Query,"|"))
        {
            mysql_fetch_field_row(bReason, "Reason");
            mysql_fetch_field_row(bannedBy, "BannedBy");
            mysql_fetch_field_row(Query, "Expiration"); bExpiration = strval(Query);

            if(bExpiration > 0)
            {
                if(gettime() >= bExpiration)
                {
                    format(Query, sizeof(Query), "UPDATE `server_bans` SET Status = 0 WHERE Username = %s", GetPName(playerid));
                    mysql_query(Query);
                    new string[100];
                    format(string,sizeof(string),"{FFFFFF}You've been unbanned from the server \nAccount Name:{33C9CC}%s{FFFFFF}\nPlease login to continue.",GetPName(playerid));
                    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Account Login",string,"Login","");
                }
                else
                {
                    new days,hours,minutes,time;
                    time = bExpiration-gettime()/3600;
                    while (time >= 86400)
                    {
                        days++;
                        time-=86400;
                    }
                    while(time >=  3600)
                    {
                        hours++;
                        time-=3600;
                    }
                    while(time >= 60)
                    {
                        minutes++;
                        time-=60;
                    }
                   
                    new string[300];
                    format(string, sizeof(string), "{FFFFFF}You are banned from this server\n\n{0094BD}Reason: {FFFFFF}%s\n\n{0094BD}Banned By: {FFFFFF}%s\n{0094BD}Unbanned in: {FFFFFF}%d Hours - %d Minutes - %d Seconds", bReason, bannedBy,days, hours, minutes);
                    ShowPlayerDialog(playerid, DIALOG_BANNED, DIALOG_STYLE_MSGBOX, "Banned", string, "Close", "");
                    print("Banned player joined the server");
                }

            } else {
                new string[300];
                format(string, sizeof(string), "{FFFFFF}You are banned from this server\n\n{0094BD}Reason: {FFFFFF}%s\n\n{0094BD}Banned By: {FFFFFF}%s", bReason, bannedBy);
                ShowPlayerDialog(playerid, DIALOG_BANNED, DIALOG_STYLE_MSGBOX, "Banned", string, "Close", "");
            }

        }
        return 1;
    }
    return 0;
}
Reply
#2

Still needed asap
Reply
#3

Just don't convert the current timestamp to hours before substracting it from the expiration timestamp. Also, here's a faster method:
pawn Код:
d = time / 86400,   // compute days
time = time % 86400,
h = time / 3600,    // compute hours
time = time % 3600,
m = time / 60,      // compute minutes
time = time % 60;   // compute seconds
It utilizes the modulus (%) operator.
Reply
#4

EDIT: it still is showing the incorrect days (533234)
Reply
#5

Did you edit the part where it's dividing the timestamp by 3600?
pawn Код:
time = bExpiration - gettime() / 3600;
// change to
time = bExpiration - gettime();
Reply
#6

Pm'ed you the new code if you could change it for me since i'm not in the best frame of mind.
Reply
#7

Solved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)