mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-02-01 08:29:53 +00:00
WIP: basic server, no features
This commit is contained in:
@@ -48,3 +48,39 @@ uint32_t SQLiteDatabase::GetAccountCount() {
|
||||
|
||||
return res.getIntField("count");
|
||||
}
|
||||
void SQLiteDatabase::RecordFailedAttempt(const uint32_t accountId) {
|
||||
ExecuteUpdate("UPDATE accounts SET failed_attempts = failed_attempts + 1 WHERE id = ?;", accountId);
|
||||
}
|
||||
|
||||
void SQLiteDatabase::ClearFailedAttempts(const uint32_t accountId) {
|
||||
ExecuteUpdate("UPDATE accounts SET failed_attempts = 0, lockout_time = NULL, last_login = CURRENT_TIMESTAMP WHERE id = ?;", accountId);
|
||||
}
|
||||
|
||||
void SQLiteDatabase::SetLockout(const uint32_t accountId, const int64_t lockoutUntil) {
|
||||
ExecuteUpdate("UPDATE accounts SET lockout_time = datetime(?, 'unixepoch') WHERE id = ?;", lockoutUntil, accountId);
|
||||
}
|
||||
|
||||
bool SQLiteDatabase::IsLockedOut(const uint32_t accountId) {
|
||||
auto [_, result] = ExecuteSelect("SELECT lockout_time FROM accounts WHERE id = ?;", accountId);
|
||||
if (result.eof()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* lockoutTime = result.getStringField("lockout_time");
|
||||
if (lockoutTime == nullptr || strlen(lockoutTime) == 0 || strcmp(lockoutTime, "0") == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If lockout_time is set and in the future, account is locked
|
||||
// For now, simplified check - if lockout_time exists, it's locked
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t SQLiteDatabase::GetFailedAttempts(const uint32_t accountId) {
|
||||
auto [_, result] = ExecuteSelect("SELECT failed_attempts FROM accounts WHERE id = ?;", accountId);
|
||||
if (result.eof()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result.getIntField("failed_attempts");
|
||||
}
|
||||
Reference in New Issue
Block a user