fix guild creation

This commit is contained in:
Aaron Kimbre 2022-12-20 08:54:52 -06:00
parent 30fbdd3956
commit c4ae05ecee
3 changed files with 21 additions and 7 deletions

View File

@ -459,6 +459,20 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
stmt->execute(); stmt->execute();
delete stmt; delete stmt;
} }
{
sql::PreparedStatement* stmt = Database::CreatePreppedStmt(
"DELETE FROM guild_members WHERE property_id IN (SELECT owner FROM guilds WHERE owner_id=?);"
);
stmt->setUInt64(1, charID);
stmt->execute();
delete stmt;
}
{
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM guilds WHERE owner_id=?;");
stmt->setUInt64(1, charID);
stmt->execute();
delete stmt;
}
{ {
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM charinfo WHERE id=? LIMIT 1;"); sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM charinfo WHERE id=? LIMIT 1;");
stmt->setUInt64(1, charID); stmt->setUInt64(1, charID);

View File

@ -420,7 +420,7 @@ void ClientPackets::HandleGuildCreation(const SystemAddress& sysAddr, Packet* pa
auto creation = (uint32_t)time(nullptr); auto creation = (uint32_t)time(nullptr);
// If not, insert our newly created guild: // If not, insert our newly created guild:
auto insertGuild = Database::CreatePreppedStmt("INSERT INTO `guilds`(`name`, `owner`, `uscore`, `created`) VALUES (?,?,?,?)"); auto insertGuild = Database::CreatePreppedStmt("INSERT INTO `guilds`(`name`, `owner_id`, `uscore`, `created`) VALUES (?,?,?,?)");
insertGuild->setString(1, guildName.c_str()); insertGuild->setString(1, guildName.c_str());
insertGuild->setUInt(2, character->GetID()); insertGuild->setUInt(2, character->GetID());
insertGuild->setUInt(3, characterComp->GetUScore()); insertGuild->setUInt(3, characterComp->GetUScore());
@ -429,7 +429,7 @@ void ClientPackets::HandleGuildCreation(const SystemAddress& sysAddr, Packet* pa
delete insertGuild; delete insertGuild;
// Enable the guild on their character component: // Enable the guild on their character component:
auto get = Database::CreatePreppedStmt("SELECT id, name FROM guilds WHERE owner=?"); auto get = Database::CreatePreppedStmt("SELECT id, name FROM guilds WHERE owner_id=?");
get->setInt(1, character->GetID()); get->setInt(1, character->GetID());
auto* results = get->executeQuery(); auto* results = get->executeQuery();
@ -448,7 +448,7 @@ void ClientPackets::HandleGuildCreation(const SystemAddress& sysAddr, Packet* pa
return; return;
} }
auto insertOwner = Database::CreatePreppedStmt("INSERT INTO `guild_members`(`guild_id`, `character_id`, `rank`, `joined`) VALUES (?,?,?)"); auto insertOwner = Database::CreatePreppedStmt("INSERT INTO `guild_members`(`guild_id`, `character_id`, `rank`, `joined`) VALUES (?,?,?,?)");
insertOwner->setUInt(1, guildId); insertOwner->setUInt(1, guildId);
insertOwner->setUInt(2, character->GetID()); insertOwner->setUInt(2, character->GetID());
insertOwner->setUInt(3, eGuildRank::FOUNDER); insertOwner->setUInt(3, eGuildRank::FOUNDER);

View File

@ -1,15 +1,15 @@
CREATE TABLE IF NOT EXISTS guilds ( CREATE TABLE IF NOT EXISTS guilds (
id BIGINT NOT NULL PRIMARY KEY, id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(35) NOT NULL, name VARCHAR(35) NOT NULL,
owner BIGINT NOT NULL REFERENCES charinfo(id), owner_id BIGINT NOT NULL REFERENCES charinfo(id) ON DELETE CASCADE,
motd TEXT, motd TEXT,
uscore INT NOT NULL DEFAULT 0, uscore INT NOT NULL DEFAULT 0,
created BIGINT UNSIGNED NOT NULL DEFAULT 0 created BIGINT UNSIGNED NOT NULL DEFAULT 0
); );
CREATE TABLE IF NOT EXISTS guild_members ( CREATE TABLE IF NOT EXISTS guild_members (
guild_id BIGINT NOT NULL REFERENCES guilds(id), guild_id BIGINT NOT NULL REFERENCES guilds(id) ON DELETE CASCADE,
character_id BIGINT NOT NULL REFERENCES charinfo(id), character_id BIGINT NOT NULL REFERENCES charinfo(id) ON DELETE CASCADE,
rank INT NOT NULL DEFAULT 4, rank INT NOT NULL DEFAULT 4,
joined BIGINT UNSIGNED NOT NULL DEFAULT 0 joined BIGINT UNSIGNED NOT NULL DEFAULT 0
); );