mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-13 02:48:19 +00:00
WIP
no crashes
This commit is contained in:
@@ -103,6 +103,17 @@ public:
|
||||
std::optional<uint32_t> GetDonationTotal(const uint32_t activityId) override;
|
||||
std::optional<bool> IsPlaykeyActive(const int32_t playkeyId) override;
|
||||
std::vector<IUgc::Model> GetUgcModels(const LWOOBJID& propertyId) override;
|
||||
std::optional<IGuilds::Guild> CreateGuild(const std::string_view name, const int32_t owner_id, const uint64_t reputation) override;
|
||||
std::optional<IGuilds::Guild> GetGuild(const uint32_t guild_id) override;
|
||||
std::optional<IGuilds::Guild> GetGuildByName(const std::string_view name) override;
|
||||
bool CheckGuildNameExists(const std::string_view name) override;
|
||||
void SetMOTD(const uint32_t guild_id, const std::string_view motd) override;
|
||||
void DeleteGuild(const uint32_t guild_id) override;
|
||||
void InsertGuildMember(const uint32_t guild_id, const uint32_t member_id, const uint16_t rank) override;
|
||||
void DeleteGuildMember(const uint32_t member_id) override;
|
||||
uint32_t GetMembersGuild(const uint32_t member_id) override;
|
||||
std::vector<GuildMember> GetGuildMembers(const uint32_t guild_id) override;
|
||||
bool CheckIsInGuild(const uint32_t guild_id, const uint32_t character_id) override;
|
||||
private:
|
||||
|
||||
// Generic query functions that can be used for any query.
|
||||
|
@@ -6,6 +6,8 @@ set(DDATABASES_DATABASES_MYSQL_TABLES_SOURCES
|
||||
"CharXml.cpp"
|
||||
"CommandLog.cpp"
|
||||
"Friends.cpp"
|
||||
"Guilds.cpp"
|
||||
"GuildMembers.cpp"
|
||||
"Leaderboard.cpp"
|
||||
"Mail.cpp"
|
||||
"MigrationHistory.cpp"
|
||||
|
35
dDatabase/GameDatabase/MySQL/Tables/GuildMembers.cpp
Normal file
35
dDatabase/GameDatabase/MySQL/Tables/GuildMembers.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "MySQLDatabase.h"
|
||||
|
||||
void MySQLDatabase::InsertGuildMember(const uint32_t guild_id, const uint32_t member_id, const uint16_t rank){
|
||||
ExecuteInsert("INSERT INTO guild_members (guild_id, character_id, rank) VALUES (?, ?, ?);", guild_id, member_id, rank);
|
||||
}
|
||||
|
||||
void MySQLDatabase::DeleteGuildMember(const uint32_t member_id){
|
||||
ExecuteDelete("DELETE FROM guild_members WHERE character_id = ?;", member_id);
|
||||
}
|
||||
|
||||
uint32_t MySQLDatabase::GetMembersGuild(const uint32_t member_id){
|
||||
auto res = ExecuteSelect("SELECT * FROM guild_members WHERE character_id = ?;", member_id);
|
||||
if (!res->next()) return 0;
|
||||
return res->getUInt("guild_id");
|
||||
}
|
||||
|
||||
std::vector<IGuildMembers::GuildMember> MySQLDatabase::GetGuildMembers(const uint32_t guild_id){
|
||||
auto res = ExecuteSelect("SELECT * FROM guild_members WHERE guild_id = ?;", guild_id);
|
||||
std::vector<GuildMember> toReturn;
|
||||
toReturn.reserve(res->rowsCount());
|
||||
|
||||
while (res->next()) {
|
||||
GuildMember member;
|
||||
member.id = res->getUInt("character_id");
|
||||
member.rank = res->getUInt("rank");
|
||||
toReturn.push_back(member);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
bool MySQLDatabase::CheckIsInGuild(const uint32_t guild_id, const uint32_t character_id) {
|
||||
auto res = ExecuteSelect("SELECT * FROM guild_members WHERE guild_id = ? AND character_id = ?;", guild_id, character_id);
|
||||
if (res->next()) return true;
|
||||
return false;
|
||||
}
|
46
dDatabase/GameDatabase/MySQL/Tables/Guilds.cpp
Normal file
46
dDatabase/GameDatabase/MySQL/Tables/Guilds.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "MySQLDatabase.h"
|
||||
|
||||
std::optional<IGuilds::Guild> MySQLDatabase::CreateGuild(const std::string_view name, const int32_t owner_id, const uint64_t reputation) {
|
||||
ExecuteInsert("INSERT INTO guilds (name, owner_id, reputation) VALUES (?, ?, ?);", name, owner_id, reputation);
|
||||
return GetGuildByName(name);
|
||||
}
|
||||
|
||||
std::optional<IGuilds::Guild> MySQLDatabase::GetGuild(const uint32_t guild_id) {
|
||||
auto return_res = ExecuteSelect("SELECT * from guilds where id = ?", guild_id);
|
||||
if (!return_res->next()) return std::nullopt;
|
||||
|
||||
IGuilds::Guild toReturn;
|
||||
toReturn.id = return_res->getInt64("id");
|
||||
toReturn.owner_id = return_res->getUInt("owner_id");
|
||||
toReturn.name = return_res->getString("name").c_str();
|
||||
toReturn.motd = return_res->getString("motd").c_str();
|
||||
toReturn.reputation = return_res->getUInt64("reputation");
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
std::optional<IGuilds::Guild> MySQLDatabase::GetGuildByName(const std::string_view name) {
|
||||
auto return_res = ExecuteSelect("SELECT * from guilds where name = ?", name);
|
||||
if (!return_res->next()) return std::nullopt;
|
||||
|
||||
IGuilds::Guild toReturn;
|
||||
toReturn.id = return_res->getUInt("id");
|
||||
toReturn.owner_id = return_res->getUInt("owner_id");
|
||||
toReturn.name = return_res->getString("name").c_str();
|
||||
toReturn.motd = return_res->getString("motd").c_str();
|
||||
toReturn.reputation = return_res->getUInt64("reputation");
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
bool MySQLDatabase::CheckGuildNameExists(const std::string_view name) {
|
||||
auto res = ExecuteSelect("SELECT * FROM guilds WHERE name = ?;", name);
|
||||
return res->next();
|
||||
}
|
||||
void MySQLDatabase::SetMOTD(const uint32_t guild_id, const std::string_view motd) {
|
||||
auto res = ExecuteUpdate("Update guilds SET motd = ? WHERE id = ?;", motd, guild_id);
|
||||
if (res != 1) throw res;
|
||||
}
|
||||
|
||||
void MySQLDatabase::DeleteGuild(const uint32_t guild_id) {
|
||||
ExecuteDelete("DELETE FROM guilds where id = ?;", guild_id);
|
||||
}
|
Reference in New Issue
Block a user