mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-22 21:43:35 +00:00
a60865cd19
* simplify leaderboard code, fully abstract database * update exception catching * update exception catching and sql references, remove ugc from gamemessages fix deleting model remove unrelated changes Update GameMessages.cpp * remove ugc from gamemessages * Update GameMessages.cpp * Update Leaderboard.cpp * bug fixes * fix racing leaderboard * remove extra stuff * update * add sqlite * use a default for optimizations * update sqlite * Fix limits on update and delete * fix bugs * use definition to switch between databases * add switch for different backends * fix include guard and includes * always build both * add mysql if block * Update Database.cpp * add new options and add check to prevent overriding mysql * correct config names * Update README.md * Update README.md * merge to 1 sql file for sqlite database * move to sqlite folder * add back mysql migrations * Update README.md * add migration to correct the folder name or mysql * yes aron * updates * Update CMakeLists.txt * dont use paths at all, add where check to only update if folder name still exist check also doesnt check for slashes and assumes one will be there since it will be. * default dont auto create account for releases we can change this flag * default 0 * add times played query * fix leaderboard not incrementing on a not better score * add env vars with defaults for docker * use an "enum" * default to mariadb * Update .env.example
84 lines
2.6 KiB
C++
84 lines
2.6 KiB
C++
#include "SQLiteDatabase.h"
|
|
|
|
void SQLiteDatabase::InsertNewMail(const IMail::MailInfo& mail) {
|
|
ExecuteInsert(
|
|
"INSERT INTO `mail` "
|
|
"(`sender_id`, `sender_name`, `receiver_id`, `receiver_name`, `time_sent`, `subject`, `body`, `attachment_id`, `attachment_lot`, `attachment_subkey`, `attachment_count`, `was_read`)"
|
|
" VALUES (?,?,?,?,?,?,?,?,?,?,?,0)",
|
|
mail.senderId,
|
|
mail.senderUsername,
|
|
mail.receiverId,
|
|
mail.recipient,
|
|
static_cast<uint32_t>(time(NULL)),
|
|
mail.subject,
|
|
mail.body,
|
|
mail.itemID,
|
|
mail.itemLOT,
|
|
0,
|
|
mail.itemCount);
|
|
}
|
|
|
|
std::vector<IMail::MailInfo> SQLiteDatabase::GetMailForPlayer(const uint32_t characterId, const uint32_t numberOfMail) {
|
|
auto [_, res] = ExecuteSelect(
|
|
"SELECT id, subject, body, sender_name, attachment_id, attachment_lot, attachment_subkey, attachment_count, was_read, time_sent"
|
|
" FROM mail WHERE receiver_id=? limit ?;",
|
|
characterId, numberOfMail);
|
|
|
|
std::vector<IMail::MailInfo> toReturn;
|
|
|
|
while (!res.eof()) {
|
|
IMail::MailInfo mail;
|
|
mail.id = res.getInt64Field("id");
|
|
mail.subject = res.getStringField("subject");
|
|
mail.body = res.getStringField("body");
|
|
mail.senderUsername = res.getStringField("sender_name");
|
|
mail.itemID = res.getIntField("attachment_id");
|
|
mail.itemLOT = res.getIntField("attachment_lot");
|
|
mail.itemSubkey = res.getIntField("attachment_subkey");
|
|
mail.itemCount = res.getIntField("attachment_count");
|
|
mail.timeSent = res.getInt64Field("time_sent");
|
|
mail.wasRead = res.getIntField("was_read");
|
|
|
|
toReturn.push_back(std::move(mail));
|
|
res.nextRow();
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::optional<IMail::MailInfo> SQLiteDatabase::GetMail(const uint64_t mailId) {
|
|
auto [_, res] = ExecuteSelect("SELECT attachment_lot, attachment_count FROM mail WHERE id=? LIMIT 1;", mailId);
|
|
|
|
if (res.eof()) {
|
|
return std::nullopt;
|
|
}
|
|
|
|
IMail::MailInfo toReturn;
|
|
toReturn.itemLOT = res.getIntField("attachment_lot");
|
|
toReturn.itemCount = res.getIntField("attachment_count");
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
uint32_t SQLiteDatabase::GetUnreadMailCount(const uint32_t characterId) {
|
|
auto [_, res] = ExecuteSelect("SELECT COUNT(*) AS number_unread FROM mail WHERE receiver_id=? AND was_read=0;", characterId);
|
|
|
|
if (res.eof()) {
|
|
return 0;
|
|
}
|
|
|
|
return res.getIntField("number_unread");
|
|
}
|
|
|
|
void SQLiteDatabase::MarkMailRead(const uint64_t mailId) {
|
|
ExecuteUpdate("UPDATE mail SET was_read=1 WHERE id=?;", mailId);
|
|
}
|
|
|
|
void SQLiteDatabase::ClaimMailItem(const uint64_t mailId) {
|
|
ExecuteUpdate("UPDATE mail SET attachment_lot=0 WHERE id=?;", mailId);
|
|
}
|
|
|
|
void SQLiteDatabase::DeleteMail(const uint64_t mailId) {
|
|
ExecuteDelete("DELETE FROM mail WHERE id=?;", mailId);
|
|
}
|