mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-10 09:28:06 +00:00
WIP
no crashes
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "CheatDetection.h"
|
||||
#include "Amf3.h"
|
||||
#include "eObjectBits.h"
|
||||
|
||||
void ClientPackets::HandleChatMessage(const SystemAddress& sysAddr, Packet* packet) {
|
||||
User* user = UserManager::Instance()->GetUser(sysAddr);
|
||||
@@ -391,36 +392,29 @@ void ClientPackets::HandleChatModerationRequest(const SystemAddress& sysAddr, Pa
|
||||
WorldPackets::SendChatModerationResponse(sysAddr, bAllClean, requestID, receiver, segments);
|
||||
}
|
||||
|
||||
void ClientPackets::HandleGuildCreation(const SystemAddress& sysAddr, Packet* packet) {
|
||||
std::string guildName = PacketUtils::ReadString(8, packet, true);
|
||||
void ClientPackets::HandleGuildCreation(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LUWString guildName(31);
|
||||
inStream.Read(guildName);
|
||||
|
||||
auto user = UserManager::Instance()->GetUser(sysAddr);
|
||||
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) return;
|
||||
|
||||
auto character = user->GetLastUsedChar();
|
||||
if (!character) return;
|
||||
|
||||
Game::logger->Log("ClientPackets", "User %s wants to create a guild with name: %s", character->GetName().c_str(), guildName.c_str());
|
||||
LOG("User %s wants to create a guild with name: %s", character->GetName().c_str(), guildName.GetAsString().c_str());
|
||||
|
||||
// First, check to see if there is a guild with that name or not:
|
||||
auto stmt = Database::CreatePreppedStmt("SELECT * FROM guilds WHERE name=?");
|
||||
stmt->setString(1, guildName.c_str());
|
||||
|
||||
auto res = stmt->executeQuery();
|
||||
if (res->rowsCount() > 0) {
|
||||
Game::logger->Log("ClientPackets", "But a guild already exists with that name!");
|
||||
auto usedName = GeneralUtils::UTF8ToUTF16(guildName);
|
||||
SendGuildCreateResponse(sysAddr, eGuildCreationResponse::REJECTED_EXISTS, LWOOBJID_EMPTY, usedName);
|
||||
if (Database::Get()->CheckGuildNameExists(guildName.GetAsString().c_str())) {
|
||||
LOG("But a guild already exists with that name!");
|
||||
SendGuildCreateResponse(packet->systemAddress, eGuildCreationResponse::REJECTED_EXISTS, LWOOBJID_EMPTY, guildName.string);
|
||||
return;
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
if (!Game::chatFilter->IsSentenceOkay(guildName, character->GetGMLevel()).empty()) {
|
||||
Game::logger->Log("ClientPackets", "But they used bad words!");
|
||||
auto usedName = GeneralUtils::UTF8ToUTF16(guildName);
|
||||
SendGuildCreateResponse(sysAddr, eGuildCreationResponse::REJECTED_BAD_NAME, LWOOBJID_EMPTY, usedName);
|
||||
if (!Game::chatFilter->IsSentenceOkay(guildName.GetAsString().c_str(), character->GetGMLevel()).empty()) {
|
||||
LOG("But they used bad words!");
|
||||
SendGuildCreateResponse(packet->systemAddress, eGuildCreationResponse::REJECTED_BAD_NAME, LWOOBJID_EMPTY, guildName.string);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -432,61 +426,36 @@ void ClientPackets::HandleGuildCreation(const SystemAddress& sysAddr, Packet* pa
|
||||
if (!characterComp) return;
|
||||
|
||||
if (characterComp->GetGuildID() != 0) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"You are already in a guild! Leave your current guild first.");
|
||||
ChatPackets::SendSystemMessage(packet->systemAddress, u"You are already in a guild! Leave your current guild first.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto creation = (uint32_t)time(nullptr);
|
||||
LOG("Creating Guild");
|
||||
// If not, insert our newly created guild:
|
||||
auto insertGuild = Database::CreatePreppedStmt("INSERT INTO `guilds`(`name`, `owner_id`, `reputation`, `created`) VALUES (?,?,?,?)");
|
||||
insertGuild->setString(1, guildName.c_str());
|
||||
insertGuild->setUInt(2, character->GetID());
|
||||
insertGuild->setUInt(3, characterComp->GetUScore());
|
||||
insertGuild->setUInt(4, creation);
|
||||
insertGuild->execute();
|
||||
delete insertGuild;
|
||||
auto newGuild = Database::Get()->CreateGuild(guildName.GetAsString(), character->GetID(), characterComp->GetUScore());
|
||||
|
||||
// Enable the guild on their character component:
|
||||
auto get = Database::CreatePreppedStmt("SELECT id, name FROM guilds WHERE owner_id=?");
|
||||
get->setInt(1, character->GetID());
|
||||
|
||||
auto* results = get->executeQuery();
|
||||
LWOOBJID guildId = LWOOBJID_EMPTY;
|
||||
std::u16string name;
|
||||
while (results->next()) {
|
||||
guildId = results->getInt(1);
|
||||
name = GeneralUtils::UTF8ToUTF16(results->getString(2).c_str());
|
||||
characterComp->SetGuild(guildId, name);
|
||||
}
|
||||
|
||||
if (guildId == LWOOBJID_EMPTY){
|
||||
Game::logger->Log("ClientPackets", "Unknown error ocurred while creating a guild!");
|
||||
auto usedName = GeneralUtils::UTF8ToUTF16(guildName);
|
||||
SendGuildCreateResponse(sysAddr, eGuildCreationResponse::UNKNOWN_ERROR, LWOOBJID_EMPTY, usedName);
|
||||
if (!newGuild){
|
||||
LOG("Unknown error ocurred while creating a guild! Got %i", newGuild->id);
|
||||
SendGuildCreateResponse(packet->systemAddress, eGuildCreationResponse::UNKNOWN_ERROR, LWOOBJID_EMPTY, guildName.string);
|
||||
return;
|
||||
}
|
||||
|
||||
Database::Get()->InsertGuildMember(newGuild->id, character->GetID(), eGuildRank::FOUNDER);
|
||||
|
||||
auto insertOwner = Database::CreatePreppedStmt("INSERT INTO `guild_members`(`guild_id`, `character_id`, `rank`, `joined`) VALUES (?,?,?,?)");
|
||||
insertOwner->setUInt(1, guildId);
|
||||
insertOwner->setUInt(2, character->GetID());
|
||||
insertOwner->setUInt(3, eGuildRank::FOUNDER);
|
||||
insertOwner->setUInt(4, creation);
|
||||
insertOwner->execute();
|
||||
delete insertOwner;
|
||||
characterComp->SetGuild(newGuild->id, guildName.string);
|
||||
SendGuildCreateResponse(packet->systemAddress, eGuildCreationResponse::CREATED, newGuild->id, guildName.string);
|
||||
AMFArrayValue data;
|
||||
data.Insert("bOn", true);
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, packet->systemAddress, "ToggleGuildUI", data);
|
||||
|
||||
//Send the guild create response:
|
||||
SendGuildCreateResponse(sysAddr, eGuildCreationResponse::CREATED, guildId, name);
|
||||
// TODO: enable guild ui here
|
||||
}
|
||||
|
||||
|
||||
void ClientPackets::SendGuildCreateResponse(const SystemAddress& sysAddr, eGuildCreationResponse guildResponse, LWOOBJID guildID, std::u16string& guildName) {
|
||||
void ClientPackets::SendGuildCreateResponse(const SystemAddress& sysAddr, eGuildCreationResponse guildResponse, LWOOBJID guild_id, std::u16string& guildName) {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
bitStream.Write(eClientMessageType::GUILD_CREATE_RESPONSE);
|
||||
bitStream.Write(guildResponse);
|
||||
bitStream.Write(guildID);
|
||||
GeneralUtils::SetBit(guild_id, eObjectBits::CHARACTER);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GUILD_CREATE_RESPONSE);
|
||||
bitStream.Write<uint8_t>(guildResponse);
|
||||
bitStream.Write(guild_id);
|
||||
bitStream.Write(LUWString(guildName));
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@ namespace ClientPackets {
|
||||
void SendTop5HelpIssues(Packet* packet);
|
||||
|
||||
// Guild stuff
|
||||
void HandleGuildCreation(const SystemAddress& sysAddr, Packet* packet);
|
||||
void SendGuildCreateResponse(const SystemAddress& sysAddr, eGuildCreationResponse guildResponse, LWOOBJID guildID, std::u16string& guildName);
|
||||
void HandleGuildCreation(Packet* packet);
|
||||
void SendGuildCreateResponse(const SystemAddress& sysAddr, eGuildCreationResponse guildResponse, LWOOBJID guild_id, std::u16string& guildName);
|
||||
};
|
||||
|
||||
#endif // CLIENTPACKETS_H
|
||||
|
Reference in New Issue
Block a user