Skip to content

Commit

Permalink
Chat: Fix linking of dynguid objects
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jan 13, 2024
1 parent 510cc7d commit 27999d8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
2 changes: 1 addition & 1 deletion sql/base/mangos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4774,7 +4774,7 @@ INSERT INTO `mangos_string` VALUES
(514,'%d - |cffffffff|Hcreature_entry:%d|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(515,'%d%s - |cffffffff|Hcreature:%d|h[%s X:%f Y:%f Z:%f MapId:%d]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(516,'%d - |cffffffff|Hgameobject_entry:%d|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(517,'%d%s, Entry %d - |cffffffff|Hgameobject:%d|h[%s X:%f Y:%f Z:%f MapId:%d]SpawnGroup:%u|h|r',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(517,'%d%s, Entry %d - |cffffffff|Hgameobject:%d:%d|h[%s X:%f Y:%f Z:%f MapId:%d]|h|r SpawnGroup:%u',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(518,'%d - |cffffffff|Hitemset:%d|h[%s %s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(519,'|cffffffff|Htele:%s|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(520,'%d - |cffffffff|Hspell:%d|h[%s]|h|r ',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
Expand Down
20 changes: 20 additions & 0 deletions src/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,26 @@ bool ChatHandler::ExtractUint32KeyFromLink(char** text, char const* linkType, ui
return ExtractUInt32(&arg, value);
}

bool ChatHandler::ExtractUint32KeysFromLink(char** text, char const* linkType1, char const* linkType2, uint32& value1, uint32& value2)
{
char const* linkTypes[2];
linkTypes[0] = linkType1;
linkTypes[1] = linkType2;

int foundIdx;
char something1[100];
char* something1Pointer = &something1[0];

char* arg = ExtractKeyFromLink(text, linkTypes, &foundIdx, &something1Pointer);
if (!arg)
return false;

if (foundIdx == -1)
return ExtractUInt32(&arg, value1) && ExtractUInt32(text, value2);

return ExtractUInt32(&arg, value1) && ExtractUInt32(&something1Pointer, value2);
}

GameObject* ChatHandler::GetGameObjectWithGuid(uint32 lowguid, uint32 entry) const
{
if (!m_session)
Expand Down
1 change: 1 addition & 0 deletions src/game/Chat/Chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class ChatHandler
char* ExtractKeyFromLink(char** text, char const* linkType, char** something1 = nullptr);
static char* ExtractKeyFromLink(char** text, char const* const* linkTypes, int* found_idx = nullptr, char** something1 = nullptr);
bool ExtractUint32KeyFromLink(char** text, char const* linkType, uint32& value);
bool ExtractUint32KeysFromLink(char** text, char const* linkType1, char const* linkType2, uint32& value1, uint32& value2);

uint32 ExtractAccountId(char** args, std::string* accountName = nullptr, Player** targetIfNullArg = nullptr);
uint32 ExtractSpellIdFromLink(char** text);
Expand Down
50 changes: 17 additions & 33 deletions src/game/Chat/Level2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,18 +1025,14 @@ bool ChatHandler::HandleGameObjectDeleteCommand(char* args)
bool ChatHandler::HandleGameObjectTurnCommand(char* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
uint32 lowguid;
if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid))
uint32 lowguid, entry;
if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry))
return false;

if (!lowguid)
if (!lowguid || !entry)
return false;

GameObject* obj = nullptr;

// by DB guid
if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
obj = GetGameObjectWithGuid(lowguid, go_data->id);
GameObject* obj = GetGameObjectWithGuid(lowguid, entry);

if (!obj)
{
Expand All @@ -1059,18 +1055,14 @@ bool ChatHandler::HandleGameObjectTurnCommand(char* args)
bool ChatHandler::HandleGameObjectMoveCommand(char* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
uint32 lowguid;
if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid))
uint32 lowguid, entry;
if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry))
return false;

if (!lowguid)
if (!lowguid || !entry)
return false;

GameObject* obj = nullptr;

// by DB guid
if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
obj = GetGameObjectWithGuid(lowguid, go_data->id);
GameObject* obj = GetGameObjectWithGuid(lowguid, entry);

if (!obj)
{
Expand Down Expand Up @@ -1208,18 +1200,14 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args)
bool ChatHandler::HandleGameObjectPhaseCommand(char* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
uint32 lowguid;
if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid))
uint32 lowguid, entry;
if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry))
return false;

if (!lowguid)
if (!lowguid || !entry)
return false;

GameObject* obj = nullptr;

// by DB guid
if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
obj = GetGameObjectWithGuid(lowguid, go_data->id);
GameObject* obj = GetGameObjectWithGuid(lowguid, entry);

if (!obj)
{
Expand Down Expand Up @@ -1320,18 +1308,14 @@ bool ChatHandler::HandleGameObjectRespawnCommand(char* args)
bool ChatHandler::HandleGameObjectActivateCommand(char* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
uint32 lowguid;
if (!ExtractUint32KeyFromLink(&args, "Hgameobject", lowguid))
uint32 lowguid, entry;
if (!ExtractUint32KeysFromLink(&args, "Hgameobject", nullptr, lowguid, entry))
return false;

if (!lowguid)
if (!lowguid || !entry)
return false;

GameObject* obj = nullptr;

// by DB guid
if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
obj = GetGameObjectWithGuid(lowguid, go_data->id);
GameObject* obj = GetGameObjectWithGuid(lowguid, entry);

if (!obj)
{
Expand Down Expand Up @@ -1405,7 +1389,7 @@ bool ChatHandler::HandleGameObjectNearSpawnedCommand(char* args)
uint32 spawnGroupId = 0;
if (SpawnGroupEntry* groupEntry = player->GetMap()->GetMapDataContainer().GetSpawnGroupByGuid(guid, TYPEID_GAMEOBJECT))
spawnGroupId = groupEntry->Id;
PSendSysMessage(LANG_GO_MIXED_LIST_CHAT, guid.GetCounter(), PrepareStringNpcOrGoSpawnInformation<GameObject>(guid).c_str(), entry, guid, goInfo->name, x, y, z, go->GetMapId(), spawnGroupId);
PSendSysMessage(LANG_GO_MIXED_LIST_CHAT, guid.GetCounter(), PrepareStringNpcOrGoSpawnInformation<GameObject>(guid).c_str(), entry, guid.GetCounter(), entry, goInfo->name, x, y, z, go->GetMapId(), spawnGroupId);
}

PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE, distance, gameobjects.size());
Expand Down

0 comments on commit 27999d8

Please sign in to comment.