mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-12 18:38:10 +00:00

* feat: convert character ids to 64 bits remove all usages of the PERSISTENT bit with regards to storing of playerIDs on the server. the bit does not exist and was a phantom in the first place. Tested that a full playthrough of ag, ns and gf was still doable. slash commands work, ugc works, friends works, ignore list works, properties work and have names, teaming works. migrating an old mysql database works . need to test an old sqlite database * fix sqlite migration * remove nd specific column migration
85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
#include "MySQLDatabase.h"
|
|
|
|
|
|
void MySQLDatabase::InsertNewMail(const 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<MailInfo> MySQLDatabase::GetMailForPlayer(const LWOOBJID 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<MailInfo> toReturn;
|
|
toReturn.reserve(res->rowsCount());
|
|
|
|
while (res->next()) {
|
|
MailInfo mail;
|
|
mail.id = res->getUInt64("id");
|
|
mail.subject = res->getString("subject").c_str();
|
|
mail.body = res->getString("body").c_str();
|
|
mail.senderUsername = res->getString("sender_name").c_str();
|
|
mail.itemID = res->getUInt("attachment_id");
|
|
mail.itemLOT = res->getInt("attachment_lot");
|
|
mail.itemSubkey = res->getInt("attachment_subkey");
|
|
mail.itemCount = res->getInt("attachment_count");
|
|
mail.timeSent = res->getUInt64("time_sent");
|
|
mail.wasRead = res->getBoolean("was_read");
|
|
|
|
toReturn.push_back(std::move(mail));
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::optional<MailInfo> MySQLDatabase::GetMail(const uint64_t mailId) {
|
|
auto res = ExecuteSelect("SELECT attachment_lot, attachment_count FROM mail WHERE id=? LIMIT 1;", mailId);
|
|
|
|
if (!res->next()) {
|
|
return std::nullopt;
|
|
}
|
|
|
|
MailInfo toReturn;
|
|
toReturn.itemLOT = res->getInt("attachment_lot");
|
|
toReturn.itemCount = res->getInt("attachment_count");
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
uint32_t MySQLDatabase::GetUnreadMailCount(const LWOOBJID characterId) {
|
|
auto res = ExecuteSelect("SELECT COUNT(*) AS number_unread FROM mail WHERE receiver_id=? AND was_read=0;", characterId);
|
|
|
|
if (!res->next()) {
|
|
return 0;
|
|
}
|
|
|
|
return res->getInt("number_unread");
|
|
}
|
|
|
|
void MySQLDatabase::MarkMailRead(const uint64_t mailId) {
|
|
ExecuteUpdate("UPDATE mail SET was_read=1 WHERE id=? LIMIT 1;", mailId);
|
|
}
|
|
|
|
void MySQLDatabase::ClaimMailItem(const uint64_t mailId) {
|
|
ExecuteUpdate("UPDATE mail SET attachment_lot=0 WHERE id=? LIMIT 1;", mailId);
|
|
}
|
|
|
|
void MySQLDatabase::DeleteMail(const uint64_t mailId) {
|
|
ExecuteDelete("DELETE FROM mail WHERE id=? LIMIT 1;", mailId);
|
|
}
|