Skip to content

Commit 998bb3f

Browse files
committed
also write platform_id and platform to db.
1 parent 9794f9e commit 998bb3f

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/authentication/authentication_thread.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ void AuthenticationThread::run() {
3838
// check if the user has a peer_id associated with the reconnection_token if db
3939
// enabled
4040
if (db.enabled) {
41+
user_data.platform_id = user_data.reconnection_token;
4142
user_data.id = db.get_peer_or_insert(user_data.reconnection_token,
42-
user_data.game_id, user_data.id);
43+
user_data.game_id, user_data.id,
44+
user_data.platform_id, user_data.platform);
4345
}
4446
logger.debug_log("[WebSocketServer] upgraded anon user: ", user_data.game_id, " ",
4547
user_data.id);

src/database/database.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ void Database::connect_to_db() {
8181
"id TEXT NOT NULL, "
8282
"peer_id TEXT NOT NULL, "
8383
"name TEXT NOT NULL, "
84+
"platform_id TEXT NOT NULL, "
85+
"platform TEXT NOT NULL, "
8486
"game_id TEXT NOT NULL, "
8587
"timestamp TIMESTAMPTZ DEFAULT NOW(), "
8688
"PRIMARY KEY (id, game_id),"
@@ -155,11 +157,6 @@ void Database::set_user_data(const std::string& game_id, const std::string& peer
155157
}
156158
}
157159

158-
if (name.empty()) {
159-
std::cerr << "Name is required for user data" << std::endl;
160-
return;
161-
}
162-
163160
pqxx::work txn(*connection);
164161

165162
// Only update existing row
@@ -225,7 +222,9 @@ std::tuple<int64_t, int, std::string, std::string> Database::leaderboard_get_use
225222
return {score, rank, timestamp, name};
226223
}
227224
std::string Database::get_peer_or_insert(const std::string& reconnection_token,
228-
const std::string& game_id, const std::string& peer_id) {
225+
const std::string& game_id, const std::string& peer_id,
226+
const std::string platform_id,
227+
const std::string& platform) {
229228
ensure_connection();
230229
pqxx::work txn(*connection);
231230

@@ -241,8 +240,9 @@ std::string Database::get_peer_or_insert(const std::string& reconnection_token,
241240
}
242241

243242
// Not found, insert new peer
244-
txn.exec(pqxx::zview("INSERT INTO peers (id, peer_id, name, game_id) VALUES ($1, $2, $3, $4);"),
245-
pqxx::params(reconnection_token, peer_id, "", game_id));
243+
txn.exec(pqxx::zview("INSERT INTO peers (id, peer_id, name, game_id, platform_id, platform) "
244+
"VALUES ($1, $2, $3, $4, $5, $6);"),
245+
pqxx::params(reconnection_token, peer_id, "", game_id, platform_id, platform));
246246
txn.commit();
247247
return peer_id;
248248
}

src/database/database.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Database {
1919
void leaderboard_set_score(const std::string& leaderboard_id, const std::string& game_id,
2020
const std::string& user_id, int64_t score, std::string& mode);
2121
std::string get_peer_or_insert(const std::string& reconnection_token,
22-
const std::string& game_id, const std::string& peer_id);
22+
const std::string& game_id, const std::string& peer_id,
23+
const std::string platform_id, const std::string& platform);
2324
void set_user_data(const std::string& game_id, const std::string& peer_id,
2425
const boost::container::flat_map<std::string, AnyElement>& user_data);
2526
std::vector<std::tuple<std::string, int64_t, std::string>> leaderboard_get_top(

0 commit comments

Comments
 (0)