mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 09:31:30 +00:00
CheckStatus using QueryDatabase
This commit is contained in:
parent
1bfdeeeb16
commit
95c82d9968
@ -268,49 +268,39 @@ void Database::LoginIP(uint32 AccountID, const char* LoginIP)
|
|||||||
|
|
||||||
int16 Database::CheckStatus(uint32 account_id)
|
int16 Database::CheckStatus(uint32 account_id)
|
||||||
{
|
{
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
char *query = nullptr;
|
||||||
char *query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
|
|
||||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT `status`, UNIX_TIMESTAMP(`suspendeduntil`) as `suspendeduntil`, UNIX_TIMESTAMP() as `current`"
|
auto results = QueryDatabase(query, MakeAnyLenString(&query, "SELECT `status`, UNIX_TIMESTAMP(`suspendeduntil`) as `suspendeduntil`, UNIX_TIMESTAMP() as `current`"
|
||||||
" FROM `account` WHERE `id` = %i", account_id), errbuf, &result))
|
" FROM `account` WHERE `id` = %i", account_id));
|
||||||
|
|
||||||
|
if (!results.Success())
|
||||||
{
|
{
|
||||||
|
std::cerr << "Error in CheckStatus query '" << query << "' " << results.ErrorMessage() << std::endl;
|
||||||
safe_delete_array(query);
|
safe_delete_array(query);
|
||||||
|
return 0;
|
||||||
if (mysql_num_rows(result) == 1)
|
|
||||||
{
|
|
||||||
row = mysql_fetch_row(result);
|
|
||||||
|
|
||||||
int16 status = atoi(row[0]);
|
|
||||||
|
|
||||||
int32 suspendeduntil = 0;
|
|
||||||
// MariaDB initalizes with NULL if unix_timestamp() is out of range
|
|
||||||
if (row[1] != NULL) {
|
|
||||||
suspendeduntil = atoi(row[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32 current = atoi(row[2]);
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
|
||||||
|
|
||||||
if(suspendeduntil > current)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mysql_free_result(result);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
safe_delete_array(query);
|
||||||
|
|
||||||
|
if (results.RowCount() == 1)
|
||||||
{
|
{
|
||||||
std::cerr << "Error in CheckStatus query '" << query << "' " << errbuf << std::endl;
|
auto row = results.begin();
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
int16 status = atoi(row[0]);
|
||||||
|
|
||||||
|
int32 suspendeduntil = 0;
|
||||||
|
|
||||||
|
// MariaDB initalizes with NULL if unix_timestamp() is out of range
|
||||||
|
if (row[1] != nullptr) {
|
||||||
|
suspendeduntil = atoi(row[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 current = atoi(row[2]);
|
||||||
|
|
||||||
|
if(suspendeduntil > current)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user