From 1e9464ea732b734bc587a884140939c49250f29f Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Wed, 19 Nov 2008 06:25:58 +0300 Subject: [PATCH 1/4] [6839] Restore expected storing in guid/id counters first free guid/id.n all cases Prevent use uninitilized values for some id types. --- src/game/ObjectMgr.cpp | 90 ++++++++++++++-------------------------- src/game/ObjectMgr.h | 6 ++- src/game/PlayerDump.cpp | 3 +- src/shared/revision_nr.h | 2 +- 4 files changed, 39 insertions(+), 62 deletions(-) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 01b20bddf..900dea2b2 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -115,8 +115,12 @@ ObjectMgr::ObjectMgr() m_hiGoGuid = 1; m_hiDoGuid = 1; m_hiCorpseGuid = 1; - m_hiPetNumber = 1; + m_ItemTextId = 1; + m_mailid = 1; + m_auctionid = 1; + m_guildId = 1; + m_arenaTeamId = 1; mGuildBankTabPrice.resize(GUILD_BANK_MAX_TABS); mGuildBankTabPrice[0] = 100; @@ -5079,7 +5083,6 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_hiCharGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5087,7 +5090,6 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_hiCreatureGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5098,7 +5100,6 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_hiItemGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5112,7 +5113,6 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_hiGoGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5120,39 +5120,27 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_auctionid = (*result)[0].GetUInt32()+1; - delete result; } - else - { - m_auctionid = 0; - } + result = CharacterDatabase.Query( "SELECT MAX(id) FROM mail" ); if( result ) { m_mailid = (*result)[0].GetUInt32()+1; - delete result; } - else - { - m_mailid = 0; - } + result = CharacterDatabase.Query( "SELECT MAX(id) FROM item_text" ); if( result ) { - m_ItemTextId = (*result)[0].GetUInt32(); - + m_ItemTextId = (*result)[0].GetUInt32()+1; delete result; } - else - m_ItemTextId = 0; result = CharacterDatabase.Query( "SELECT MAX(guid) FROM corpse" ); if( result ) { m_hiCorpseGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5160,7 +5148,6 @@ void ObjectMgr::SetHighestGuids() if (result) { m_arenaTeamId = (*result)[0].GetUInt32()+1; - delete result; } @@ -5168,64 +5155,58 @@ void ObjectMgr::SetHighestGuids() if (result) { m_guildId = (*result)[0].GetUInt32()+1; - delete result; } } uint32 ObjectMgr::GenerateArenaTeamId() { - ++m_arenaTeamId; - if(m_arenaTeamId>=0xFFFFFFFF) + if(m_arenaTeamId>=0xFFFFFFFE) { sLog.outError("Arena team ids overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_arenaTeamId; + return m_arenaTeamId++; } uint32 ObjectMgr::GenerateGuildId() { - ++m_guildId; - if(m_guildId>=0xFFFFFFFF) + if(m_guildId>=0xFFFFFFFE) { sLog.outError("Guild ids overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_guildId; + return m_guildId++; } uint32 ObjectMgr::GenerateAuctionID() { - ++m_auctionid; - if(m_auctionid>=0xFFFFFFFF) + if(m_auctionid>=0xFFFFFFFE) { sLog.outError("Auctions ids overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_auctionid; + return m_auctionid++; } uint32 ObjectMgr::GenerateMailID() { - ++m_mailid; - if(m_mailid>=0xFFFFFFFF) + if(m_mailid>=0xFFFFFFFE) { sLog.outError("Mail ids overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_mailid; + return m_mailid++; } uint32 ObjectMgr::GenerateItemTextID() { - ++m_ItemTextId; - if(m_ItemTextId>=0xFFFFFFFF) + if(m_ItemTextId>=0xFFFFFFFE) { sLog.outError("Item text ids overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_ItemTextId; + return m_ItemTextId++; } uint32 ObjectMgr::CreateItemText(std::string text) @@ -5247,61 +5228,54 @@ uint32 ObjectMgr::GenerateLowGuid(HighGuid guidhigh) switch(guidhigh) { case HIGHGUID_ITEM: - ++m_hiItemGuid; - if(m_hiItemGuid>=0xFFFFFFFF) + if(m_hiItemGuid>=0xFFFFFFFE) { sLog.outError("Item guid overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_hiItemGuid; + return m_hiItemGuid++; case HIGHGUID_UNIT: - ++m_hiCreatureGuid; - if(m_hiCreatureGuid>=0x00FFFFFF) + if(m_hiCreatureGuid>=0x00FFFFFE) { sLog.outError("Creature guid overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_hiCreatureGuid; + return m_hiCreatureGuid++; case HIGHGUID_PET: - ++m_hiPetGuid; - if(m_hiPetGuid>=0x00FFFFFF) + if(m_hiPetGuid>=0x00FFFFFE) { sLog.outError("Pet guid overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_hiPetGuid; + return m_hiPetGuid++; case HIGHGUID_PLAYER: - ++m_hiCharGuid; - if(m_hiCharGuid>=0xFFFFFFFF) + if(m_hiCharGuid>=0xFFFFFFFE) { sLog.outError("Players guid overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_hiCharGuid; + return m_hiCharGuid++; case HIGHGUID_GAMEOBJECT: - ++m_hiGoGuid; - if(m_hiGoGuid>=0x00FFFFFF) + if(m_hiGoGuid>=0x00FFFFFE) { sLog.outError("Gameobject guid overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_hiGoGuid; + return m_hiGoGuid++; case HIGHGUID_CORPSE: - ++m_hiCorpseGuid; - if(m_hiCorpseGuid>=0xFFFFFFFF) + if(m_hiCorpseGuid>=0xFFFFFFFE) { sLog.outError("Corpse guid overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_hiCorpseGuid; + return m_hiCorpseGuid++; case HIGHGUID_DYNAMICOBJECT: - ++m_hiDoGuid; - if(m_hiDoGuid>=0xFFFFFFFF) + if(m_hiDoGuid>=0xFFFFFFFE) { sLog.outError("DynamicObject guid overflow!! Can't continue, shutting down server. "); World::StopNow(ERROR_EXIT_CODE); } - return m_hiDoGuid; + return m_hiDoGuid++; default: ASSERT(0); } diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 38cf68dc9..c09daa071 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -772,12 +772,16 @@ class ObjectMgr const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; } uint32 GetScriptId(const char *name); protected: + + // first free id for selected id type uint32 m_auctionid; uint32 m_mailid; uint32 m_ItemTextId; uint32 m_arenaTeamId; uint32 m_guildId; + uint32 m_hiPetNumber; + // first free low guid for seelcted guid type uint32 m_hiCharGuid; uint32 m_hiCreatureGuid; uint32 m_hiPetGuid; @@ -786,8 +790,6 @@ class ObjectMgr uint32 m_hiDoGuid; uint32 m_hiCorpseGuid; - uint32 m_hiPetNumber; - QuestMap mQuestTemplates; typedef UNORDERED_MAP GossipTextMap; diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp index 33577d5a3..b7e66c968 100644 --- a/src/game/PlayerDump.cpp +++ b/src/game/PlayerDump.cpp @@ -389,7 +389,8 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str } else incHighest = false; } - else guid = objmgr.m_hiCharGuid; + else + guid = objmgr.m_hiCharGuid; // normalize the name if specified and check if it exists if(!normalizePlayerName(name)) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 516976f8b..c4f3c9932 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 "6838" + #define REVISION_NR "6839" #endif // __REVISION_NR_H__ From 59a5964b1252a000a3d60a059e06bc047aa25cf4 Mon Sep 17 00:00:00 2001 From: arrai Date: Wed, 19 Nov 2008 10:08:10 +0100 Subject: [PATCH 2/4] [6840] Fixed displaying escaped GM ticket ingame --- src/game/Formulas.h | 2 +- src/game/GMTicketHandler.cpp | 4 ---- src/game/GMTicketMgr.h | 13 ++++++++++--- src/shared/revision_nr.h | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/game/Formulas.h b/src/game/Formulas.h index 5ba6ffdbb..43e77d333 100644 --- a/src/game/Formulas.h +++ b/src/game/Formulas.h @@ -27,7 +27,7 @@ namespace MaNGOS { inline uint32 hk_honor_at_level(uint32 level, uint32 count=1) { - return ceil(count*(-0.53177f + 0.59357f * exp((level +23.54042f) / 26.07859f ))); + return (uint32)ceil(count*(-0.53177f + 0.59357f * exp((level +23.54042f) / 26.07859f ))); } } namespace XP diff --git a/src/game/GMTicketHandler.cpp b/src/game/GMTicketHandler.cpp index 79fdb492a..ace7d97ec 100644 --- a/src/game/GMTicketHandler.cpp +++ b/src/game/GMTicketHandler.cpp @@ -64,8 +64,6 @@ void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket & recv_data ) std::string ticketText; recv_data >> ticketText; - CharacterDatabase.escape_string(ticketText); - if(GMTicket* ticket = ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow())) ticket->SetText(ticketText.c_str()); else @@ -103,8 +101,6 @@ void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data ) sLog.outDebug("TicketCreate: map %u, x %f, y %f, z %f, text %s, unk1 %u, unk2 %u", map, x, y, z, ticketText.c_str(), unk1, unk2); - CharacterDatabase.escape_string(ticketText); - if(ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow())) { WorldPacket data( SMSG_GMTICKET_CREATE, 4 ); diff --git a/src/game/GMTicketMgr.h b/src/game/GMTicketMgr.h index 6425c6865..01e00874d 100644 --- a/src/game/GMTicketMgr.h +++ b/src/game/GMTicketMgr.h @@ -50,7 +50,10 @@ class GMTicket { m_text = text ? text : ""; m_lastUpdate = time(NULL); - CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", m_text.c_str(), m_guid); + + std::string escapedString = m_text; + CharacterDatabase.escape_string(escapedString); + CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", escapedString.c_str(), m_guid); } void DeleteFromDB() const @@ -62,7 +65,11 @@ class GMTicket { CharacterDatabase.BeginTransaction(); DeleteFromDB(); - CharacterDatabase.PExecute("INSERT INTO character_ticket (guid, ticket_text) VALUES ('%u', '%s')", m_guid, GetText()); + + std::string escapedString = m_text; + CharacterDatabase.escape_string(escapedString); + + CharacterDatabase.PExecute("INSERT INTO character_ticket (guid, ticket_text) VALUES ('%u', '%s')", m_guid, escapedString.c_str()); CharacterDatabase.CommitTransaction(); } private: @@ -115,4 +122,4 @@ class GMTicketMgr }; #define ticketmgr MaNGOS::Singleton::Instance() -#endif \ No newline at end of file +#endif diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index c4f3c9932..b39349b28 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 "6839" + #define REVISION_NR "6840" #endif // __REVISION_NR_H__ From cd507622065603800b276209889a0d30d6e69bb2 Mon Sep 17 00:00:00 2001 From: ApoC Date: Fri, 21 Nov 2008 12:38:15 +0100 Subject: [PATCH 3/4] [6841] Fixed texts loading for waypoints. Better reporting of unused script text, now it excludes from report also ids used for waypoints. Signed-off-by: ApoC --- src/game/ObjectMgr.cpp | 3 ++ src/game/WaypointManager.cpp | 68 ++++++++++++++++++++++++++---------- src/game/WaypointManager.h | 1 + src/shared/revision_nr.h | 2 +- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 900dea2b2..d5c3d27b9 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -42,6 +42,7 @@ #include "InstanceSaveMgr.h" #include "SpellAuras.h" #include "Util.h" +#include "WaypointManager.h" INSTANTIATE_SINGLETON_1(ObjectMgr); @@ -7281,6 +7282,8 @@ void ObjectMgr::LoadDbScriptStrings() CheckScripts(sGameObjectScripts,ids); CheckScripts(sEventScripts,ids); + WaypointMgr.CheckTextsExistance(ids); + for(std::set::const_iterator itr = ids.begin(); itr != ids.end(); ++itr) sLog.outErrorDb( "Table `db_script_string` has unused string id %u", *itr); } diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp index 6b58a2234..7478f8efe 100644 --- a/src/game/WaypointManager.cpp +++ b/src/game/WaypointManager.cpp @@ -122,32 +122,18 @@ void WaypointManager::Load() be.emote = fields[7].GetUInt32(); be.spell = fields[8].GetUInt32(); - // load and store without holes in array - int j = 0; for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i) { - be.textid[j] = fields[9+i].GetUInt32(); - if(be.textid[j]) + be.textid[i] = fields[9+i].GetUInt32(); + if(be.textid[i]) { - if (be.textid[j] < MIN_DB_SCRIPT_STRING_ID || be.textid[j] >= MAX_DB_SCRIPT_STRING_ID) + if (be.textid[i] < MIN_DB_SCRIPT_STRING_ID || be.textid[i] >= MAX_DB_SCRIPT_STRING_ID) { - sLog.outErrorDb( "Table `db_script_string` not have string id %u", be.textid[j]); + sLog.outErrorDb( "Table `db_script_string` not have string id %u", be.textid[i]); continue; } - - if (!objmgr.GetMangosStringLocale (be.textid[j])) - { - sLog.outErrorDb("ERROR: Waypoint path %d (point %d), have invalid text id (%i) in `textid%d, ignored.", - id, point, be.textid[j], i+1); - continue; - } - - ++j; // to next internal field } } - // fill array tail - for(; j < MAX_WAYPOINT_TEXT; ++j) - be.textid[j] = 0; // save memory by not storing empty behaviors if(!be.isEmpty()) @@ -306,3 +292,49 @@ void WaypointManager::SetNodeText(uint32 id, uint32 point, const char *text_fiel if(field == "model2") node.behavior->model2 = text ? atoi(text) : 0; } } + +void WaypointManager::CheckTextsExistance(std::set& ids) +{ + WaypointPathMap::iterator pmItr = m_pathMap.begin(); + for ( ; pmItr != m_pathMap.end(); ++pmItr) + { + for (int i = 0; i < pmItr->second.size(); ++i) + { + if (!pmItr->second[i].behavior) + continue; + + // Now we check text existence and put all zero texts ids to the end of array + + // Counting leading zeros for futher textid shift + int zeroCount = 0; + for (int j = 0; j < MAX_WAYPOINT_TEXT; ++j) + { + if (!pmItr->second[i].behavior->textid[j]) + { + ++zeroCount; + continue; + } + else + { + if (!objmgr.GetMangosStringLocale(pmItr->second[i].behavior->textid[j])) + { + sLog.outErrorDb("ERROR: Some waypoint has textid%u with not existing %u text.", j, pmItr->second[i].behavior->textid[j]); + pmItr->second[i].behavior->textid[j] = 0; + ++zeroCount; + continue; + } + else + ids.erase(pmItr->second[i].behavior->textid[j]); + + // Shifting check + if (zeroCount) + { + // Correct textid but some zeros leading, so move it forward. + pmItr->second[i].behavior->textid[j-zeroCount] = pmItr->second[i].behavior->textid[j]; + pmItr->second[i].behavior->textid[j] = 0; + } + } + } + } + } +} diff --git a/src/game/WaypointManager.h b/src/game/WaypointManager.h index 0a8307aac..939d7f2af 100644 --- a/src/game/WaypointManager.h +++ b/src/game/WaypointManager.h @@ -76,6 +76,7 @@ class WaypointManager void DeletePath(uint32 id); void SetNodePosition(uint32 id, uint32 point, float x, float y, float z); void SetNodeText(uint32 id, uint32 point, const char *text_field, const char *text); + void CheckTextsExistance(std::set& ids); private: void _addNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index b39349b28..2dd1470a8 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 "6840" + #define REVISION_NR "6841" #endif // __REVISION_NR_H__ From 809bd7392f5b739c41955e6bad8a22b622cb7361 Mon Sep 17 00:00:00 2001 From: hunuza Date: Fri, 21 Nov 2008 18:07:05 +0100 Subject: [PATCH 4/4] Avoid sending some unnecessary group updates. --- src/game/Player.cpp | 8 ++++---- src/game/Unit.cpp | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 939120841..be86e1d4b 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -5150,6 +5150,10 @@ bool Player::SetPosition(float x, float y, float z, float orientation, bool tele x = GetPositionX(); y = GetPositionY(); z = GetPositionZ(); + + // group update + if(GetGroup() && (old_x != x || old_y != y)) + SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POSITION); } // code block for underwater state update @@ -5157,10 +5161,6 @@ bool Player::SetPosition(float x, float y, float z, float orientation, bool tele CheckExploreSystem(); - // group update - if(GetGroup()) - SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POSITION); - return true; } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index ed9524447..e81534c66 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -9673,6 +9673,9 @@ void Unit::SetMaxHealth(uint32 val) void Unit::SetPower(Powers power, uint32 val) { + if(GetPower(power) == val) + return; + uint32 maxPower = GetMaxPower(power); if(maxPower < val) val = maxPower;