From 4ac1bcc37a184c732e9a2e79cd6639ff301d6a0e Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Wed, 11 Nov 2009 18:05:14 +0300 Subject: [PATCH] [8807] Better check `playercreateinfo_action` data at server startup. --- src/game/ObjectMgr.cpp | 9 +++++++- src/game/Player.cpp | 46 ++++++++++++++++++++++++++++------------ src/game/Player.h | 1 + src/shared/revision_nr.h | 2 +- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index e62dd5133..11b577fdd 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -2554,8 +2554,15 @@ void ObjectMgr::LoadPlayerInfo() continue; } + uint8 action_button = fields[2].GetUInt8(); + uint32 action = fields[3].GetUInt32(); + uint8 action_type = fields[4].GetUInt8(); + + if (!Player::IsActionButtonDataValid(action_button,action,action_type,NULL)) + continue; + PlayerInfo* pInfo = &playerInfo[current_race][current_class]; - pInfo->action.push_back(PlayerCreateInfoAction(fields[2].GetUInt8(),fields[3].GetUInt32(),fields[4].GetUInt8())); + pInfo->action.push_back(PlayerCreateInfoAction(action_button,action,action_type)); bar.step(); ++count; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 296e7f70d..128d01c1f 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -5548,18 +5548,24 @@ void Player::SendInitialActionButtons() const sLog.outDetail( "Action Buttons for '%u' Initialized", GetGUIDLow() ); } -ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type) +bool Player::IsActionButtonDataValid(uint8 button, uint32 action, uint8 type, Player* player) { if(button >= MAX_ACTION_BUTTONS) { - sLog.outError( "Action %u not added into button %u for player %s: button must be < 144", action, button, GetName() ); - return NULL; + if (player) + sLog.outError( "Action %u not added into button %u for player %s: button must be < %u", action, button, player->GetName(), MAX_ACTION_BUTTONS ); + else + sLog.outError( "Table `playercreateinfo_action` have action %u into button %u : button must be < %u", action, button, MAX_ACTION_BUTTONS ); + return false; } if(action >= MAX_ACTION_BUTTON_ACTION_VALUE) { - sLog.outError( "Action %u not added into button %u for player %s: action must be < %u", action, button, GetName(), MAX_ACTION_BUTTON_ACTION_VALUE ); - return NULL; + if (player) + sLog.outError( "Action %u not added into button %u for player %s: action must be < %u", action, button, player->GetName(), MAX_ACTION_BUTTON_ACTION_VALUE ); + else + sLog.outError( "Table `playercreateinfo_action` have action %u into button %u : action must be < %u", action, button, MAX_ACTION_BUTTON_ACTION_VALUE ); + return false; } switch(type) @@ -5567,27 +5573,41 @@ ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type) case ACTION_BUTTON_SPELL: if(!sSpellStore.LookupEntry(action)) { - sLog.outError( "Action %u not added into button %u for player %s: spell not exist", action, button, GetName() ); - return NULL; + if (player) + sLog.outError( "Spell action %u not added into button %u for player %s: spell not exist", action, button, player->GetName() ); + else + sLog.outError( "Table `playercreateinfo_action` have spell action %u into button %u: spell not exist", action, button ); + return false; } - if(!HasSpell(action)) + if(player && !player->HasSpell(action)) { - sLog.outError( "Action %u not added into button %u for player %s: player don't known this spell", action, button, GetName() ); - return NULL; + sLog.outError( "Spell action %u not added into button %u for player %s: player don't known this spell", action, button, player->GetName() ); + return false; } break; case ACTION_BUTTON_ITEM: if(!ObjectMgr::GetItemPrototype(action)) { - sLog.outError( "Action %u not added into button %u for player %s: item not exist", action, button, GetName() ); - return NULL; + if (player) + sLog.outError( "Item action %u not added into button %u for player %s: item not exist", action, button, player->GetName() ); + else + sLog.outError( "Table `playercreateinfo_action` have item action %u into button %u: item not exist", action, button ); + return false; } break; default: - break; // pther cases not checked at this moment + break; // other cases not checked at this moment } + return true; +} + +ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type) +{ + + if (!IsActionButtonDataValid(button,action,type,this)) + return NULL; // it create new button (NEW state) if need or return existed ActionButton& ab = m_actionButtons[button]; diff --git a/src/game/Player.h b/src/game/Player.h index a6b1ea7f6..79014e91d 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1621,6 +1621,7 @@ class MANGOS_DLL_SPEC Player : public Unit m_cinematic = cine; } + static bool IsActionButtonDataValid(uint8 button, uint32 action, uint8 type, Player* player); ActionButton* addActionButton(uint8 button, uint32 action, uint8 type); void removeActionButton(uint8 button); void SendInitialActionButtons() const; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index ccd0b8d40..93843a533 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8806" + #define REVISION_NR "8807" #endif // __REVISION_NR_H__