Make Database::CheckStatus() 2038 safe

This commit is contained in:
Michael Cook (mackal) 2019-03-12 14:31:23 -04:00
parent 26a95998da
commit 9c42f28b0d

View File

@ -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;