Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Add security to C++ scripted options. #11567

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/server/game/Entities/Creature/GossipDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GossipMenu::GossipMenu()
{
_menuId = 0;
_locale = DEFAULT_LOCALE;
_senderGUID = 0;
}

GossipMenu::~GossipMenu()
Expand Down Expand Up @@ -166,8 +167,10 @@ void PlayerMenu::ClearMenus()
_questMenu.ClearMenu();
}

void PlayerMenu::SendGossipMenu(uint32 titleTextId, uint64 objectGUID) const
void PlayerMenu::SendGossipMenu(uint32 titleTextId, uint64 objectGUID)
{
_gossipMenu.SetSenderGUID(objectGUID);

WorldPacket data(SMSG_GOSSIP_MESSAGE, 100); // guess size
data << uint64(objectGUID);
data << uint32(_gossipMenu.GetMenuId()); // new 2.4.0
Expand Down
5 changes: 4 additions & 1 deletion src/server/game/Entities/Creature/GossipDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class GossipMenu

void SetMenuId(uint32 menu_id) { _menuId = menu_id; }
uint32 GetMenuId() const { return _menuId; }
void SetSenderGUID(uint64 guid) { _senderGUID = guid; }
uint64 GetSenderGUID() const { return _senderGUID; }
void SetLocale(LocaleConstant locale) { _locale = locale; }
LocaleConstant GetLocale() const { return _locale; }

Expand Down Expand Up @@ -215,6 +217,7 @@ class GossipMenu
GossipMenuItemContainer _menuItems;
GossipMenuItemDataContainer _menuItemData;
uint32 _menuId;
uint64 _senderGUID;
LocaleConstant _locale;
};

Expand Down Expand Up @@ -264,7 +267,7 @@ class PlayerMenu
uint32 GetGossipOptionAction(uint32 selection) const { return _gossipMenu.GetMenuItemAction(selection); }
bool IsGossipOptionCoded(uint32 selection) const { return _gossipMenu.IsMenuItemCoded(selection); }

void SendGossipMenu(uint32 titleTextId, uint64 objectGUID) const;
void SendGossipMenu(uint32 titleTextId, uint64 objectGUID);
void SendCloseGossip() const;
void SendPointOfInterest(uint32 poiId) const;

Expand Down
9 changes: 8 additions & 1 deletion src/server/game/Handlers/MiscHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recvData)
if (_player->PlayerTalkClass->IsGossipOptionCoded(gossipListId))
recvData >> code;

// Prevent cheating on C++ scripted menus
if (_player->PlayerTalkClass->GetGossipMenu().GetSenderGUID() != guid)
return;
if (!_player->PlayerTalkClass->GetGossipMenu().GetItem(gossipListId))
return;

Creature* unit = NULL;
GameObject* go = NULL;
if (IS_CRE_OR_VEH_GUID(guid))
Expand Down Expand Up @@ -151,7 +157,8 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recvData)
else
{
go->AI()->GossipSelectCode(_player, menuId, gossipListId, code.c_str());
sScriptMgr->OnGossipSelectCode(_player, go, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId), code.c_str());
if (!sScriptMgr->OnGossipSelectCode(_player, go, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId), code.c_str()))
_player->OnGossipSelect(unit, gossipListId, menuId);
}
}
else
Expand Down