35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#include "player_repository.h"
|
|
|
|
PlayerRepository::PlayerRepository(sqlite::database& db) : _db(db) {}
|
|
|
|
long long PlayerRepository::create(const std::string& username, const std::string& password,
|
|
const std::string& hostname) {
|
|
_db << "INSERT INTO players (username, password, hostname) VALUES (?, ?, ?);"
|
|
<< username
|
|
<< password
|
|
<< hostname;
|
|
return _db.last_insert_rowid();
|
|
}
|
|
|
|
bool PlayerRepository::authenticate(const std::string& username, const std::string& password) {
|
|
bool authed = false;
|
|
_db << "SELECT id FROM players WHERE username = ? AND password = ?;"
|
|
<< username
|
|
<< password
|
|
>> [&](long long id) {authed = true;};
|
|
return authed;
|
|
}
|
|
|
|
long long PlayerRepository::get_home_machine_id(const std::string& username) {
|
|
long long machine_id = -1;
|
|
_db << "SELECT home_machine_id FROM players WHERE username = ?;"
|
|
<< username
|
|
>> machine_id;
|
|
return machine_id;
|
|
}
|
|
|
|
void PlayerRepository::set_home_machine_id(long long player_id, long long machine_id) {
|
|
_db << "UPDATE players SET home_machine_id = ? WHERE id = ?;"
|
|
<< machine_id << player_id;
|
|
}
|