mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-19 04:01:29 +00:00
Make Database::CheckStatus() 2038 safe
This commit is contained in:
parent
26a95998da
commit
9c42f28b0d
@ -171,30 +171,27 @@ void Database::LoginIP(uint32 AccountID, const char* LoginIP) {
|
|||||||
QueryDatabase(query);
|
QueryDatabase(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 Database::CheckStatus(uint32 account_id) {
|
int16 Database::CheckStatus(uint32 account_id)
|
||||||
std::string query = StringFormat("SELECT `status`, UNIX_TIMESTAMP(`suspendeduntil`) as `suspendeduntil`, UNIX_TIMESTAMP() as `current`"
|
{
|
||||||
" FROM `account` WHERE `id` = %i", account_id);
|
std::string query = StringFormat(
|
||||||
|
"SELECT `status`, TIMESTAMPDIFF(SECOND, NOW(), `suspendeduntil`) FROM `account` WHERE `id` = %i",
|
||||||
|
account_id);
|
||||||
|
|
||||||
auto results = QueryDatabase(query);
|
auto results = QueryDatabase(query);
|
||||||
if (!results.Success()) {
|
if (!results.Success())
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (results.RowCount() != 1)
|
if (results.RowCount() != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
auto row = results.begin();
|
auto row = results.begin();
|
||||||
int16 status = atoi(row[0]);
|
int16 status = atoi(row[0]);
|
||||||
int32 suspendeduntil = 0;
|
int32 date_diff = 0;
|
||||||
|
|
||||||
// MariaDB initalizes with NULL if unix_timestamp() is out of range
|
if (row[1] != nullptr)
|
||||||
if (row[1] != nullptr) {
|
date_diff = atoi(row[1]);
|
||||||
suspendeduntil = atoi(row[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32 current = atoi(row[2]);
|
if (date_diff > 0)
|
||||||
|
|
||||||
if(suspendeduntil > current)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user