From 5d84dbb4929c67150a8cd2396c63ac371b310c20 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Thu, 15 Apr 2010 09:18:16 +0400 Subject: [PATCH] [9749] Partly revert "[9736] Added more usable interface for grid visits" In part related broadcasts by explicit provided Map pointer (in different object GetMap() requested) This is must fix recent crashes in Map::MessageBroadcast --- src/game/Map.cpp | 72 +++++++++++++++++++++++++++++++++++++--- src/shared/revision_nr.h | 2 +- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/game/Map.cpp b/src/game/Map.cpp index cfb30c2c6..bf2c71ad0 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -490,28 +490,92 @@ Map::Add(T *obj) void Map::MessageBroadcast(Player *player, WorldPacket *msg, bool to_self) { + CellPair p = MaNGOS::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); + + if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) + { + sLog.outError("Map::MessageBroadcast: Player (GUID: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord); + return; + } + + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) + return; + MaNGOS::MessageDeliverer post_man(*player, msg, to_self); - Cell::VisitWorldObjects(player, post_man, GetVisibilityDistance()); + TypeContainerVisitor message(post_man); + cell.Visit(p, message, *this, *player, GetVisibilityDistance()); } void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg) { + CellPair p = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); + + if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) + { + sLog.outError("Map::MessageBroadcast: Object (GUID: %u TypeId: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); + return; + } + + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) + return; + //TODO: currently on continents when Visibility.Distance.InFlight > Visibility.Distance.Continents //we have alot of blinking mobs because monster move packet send is broken... MaNGOS::ObjectMessageDeliverer post_man(*obj,msg); - Cell::VisitWorldObjects(obj, post_man, GetVisibilityDistance()); + TypeContainerVisitor message(post_man); + cell.Visit(p, message, *this, *obj, GetVisibilityDistance()); } void Map::MessageDistBroadcast(Player *player, WorldPacket *msg, float dist, bool to_self, bool own_team_only) { + CellPair p = MaNGOS::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); + + if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) + { + sLog.outError("Map::MessageBroadcast: Player (GUID: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord); + return; + } + + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) + return; + MaNGOS::MessageDistDeliverer post_man(*player, msg, dist, to_self, own_team_only); - Cell::VisitWorldObjects(player, post_man, GetVisibilityDistance()); + TypeContainerVisitor message(post_man); + cell.Visit(p, message, *this, *player, dist); } void Map::MessageDistBroadcast(WorldObject *obj, WorldPacket *msg, float dist) { + CellPair p = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); + + if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) + { + sLog.outError("Map::MessageBroadcast: Object (GUID: %u TypeId: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); + return; + } + + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) + return; + MaNGOS::ObjectMessageDistDeliverer post_man(*obj, msg, dist); - Cell::VisitWorldObjects(obj, post_man, GetVisibilityDistance()); + TypeContainerVisitor message(post_man); + cell.Visit(p, message, *this, *obj, dist); } bool Map::loaded(const GridPair &p) const diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index f40395df2..22d46e5de 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 "9748" + #define REVISION_NR "9749" #endif // __REVISION_NR_H__