*Update to Mangos 6888. Source: Mangos.

*Major change: Make corpse erase async, Avoid DB access on deleting guild member.
*Skip 6885 because of performance concern.

--HG--
branch : trunk
This commit is contained in:
megamage
2008-12-08 16:34:03 -06:00
parent 5321be4c0a
commit ce643187f0
24 changed files with 448 additions and 392 deletions
+2
View File
@@ -176,6 +176,7 @@ CREATE TABLE `character_aura` (
`caster_guid` bigint(20) unsigned NOT NULL default '0' COMMENT 'Full Global Unique Identifier',
`spell` int(11) unsigned NOT NULL default '0',
`effect_index` int(11) unsigned NOT NULL default '0',
`stackcount` int(11) NOT NULL default '1',
`amount` int(11) NOT NULL default '0',
`maxduration` int(11) NOT NULL default '0',
`remaintime` int(11) NOT NULL default '0',
@@ -1170,6 +1171,7 @@ CREATE TABLE `pet_aura` (
`caster_guid` bigint(20) unsigned NOT NULL default '0' COMMENT 'Full Global Unique Identifier',
`spell` int(11) unsigned NOT NULL default '0',
`effect_index` int(11) unsigned NOT NULL default '0',
`stackcount` int(11) NOT NULL default '1',
`amount` int(11) NOT NULL default '0',
`maxduration` int(11) NOT NULL default '0',
`remaintime` int(11) NOT NULL default '0',
+14 -15
View File
@@ -45,21 +45,20 @@ AggressorAI::AggressorAI(Creature &c) : i_creature(c), i_victimGuid(0), i_state(
void
AggressorAI::MoveInLineOfSight(Unit *u)
{
// Ignore Z for flying creatures
if( !i_creature.canFly() && i_creature.GetDistanceZ(u) > CREATURE_Z_ATTACK_RANGE )
return;
if( !i_creature.getVictim() && !i_creature.hasUnitState(UNIT_STAT_STUNNED) && i_creature.canAttack(u) &&
( i_creature.IsHostileTo( u ) /*|| u->getVictim() && i_creature.IsFriendlyTo( u->getVictim() )*/ ) &&
u->isInAccessiblePlaceFor(&i_creature) )
{
float attackRadius = i_creature.GetAttackDistance(u);
if(i_creature.IsWithinDistInMap(u, attackRadius) && i_creature.IsWithinLOSInMap(u) )
{
AttackStart(u);
//u->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
}
}
if(!i_creature.getVictim() && i_creature.canStartAttack(u))
AttackStart(u);
/*
if(!i_creature.getVictim())
{
AttackStart(u);
}
else if(sMapStore.LookupEntry(i_creature.GetMapId())->IsDungeon())
{
u->SetInCombatWith(&i_creature);
i_creature.AddThreat(u, 0.0f);
}
*/
}
void AggressorAI::EnterEvadeMode()
+1 -1
View File
@@ -542,7 +542,7 @@ uint8 ArenaTeam::GetSlot() const
void ArenaTeam::BroadcastPacket(WorldPacket *packet)
{
for (MemberList::iterator itr = members.begin(); itr != members.end(); itr++)
for (MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
{
Player *player = objmgr.GetPlayer(itr->guid);
if(player)
+40 -2
View File
@@ -496,6 +496,11 @@ void Creature::Update(uint32 diff)
m_regenTimer = 2000;
break;
}
case DEAD_FALLING:
{
if (!FallGround())
setDeathState(JUST_DIED);
}
default:
break;
}
@@ -762,7 +767,7 @@ void Creature::prepareGossipMenu( Player *pPlayer,uint32 gossipid )
// lazy loading single time at use
LoadGossipOptions();
for( GossipOptionList::iterator i = m_goptions.begin( ); i != m_goptions.end( ); i++ )
for( GossipOptionList::iterator i = m_goptions.begin( ); i != m_goptions.end( ); ++i )
{
GossipOption* gso=&*i;
if(gso->GossipId == gossipid)
@@ -1097,7 +1102,7 @@ uint32 Creature::GetNpcTextId()
GossipOption const* Creature::GetGossipOption( uint32 id ) const
{
for( GossipOptionList::const_iterator i = m_goptions.begin( ); i != m_goptions.end( ); i++ )
for( GossipOptionList::const_iterator i = m_goptions.begin( ); i != m_goptions.end( ); ++i )
{
if(i->Action==id )
return &*i;
@@ -1427,7 +1432,15 @@ bool Creature::LoadFromDB(uint32 guid, Map *map)
m_respawnTime = objmgr.GetCreatureRespawnTime(m_DBTableGuid,GetInstanceId());
if(m_respawnTime > time(NULL)) // not ready to respawn
{
m_deathState = DEAD;
if(canFly())
{
float tz = GetMap()->GetHeight(data->posX,data->posY,data->posZ,false);
if(data->posZ - tz > 0.1)
Relocate(data->posX,data->posY,tz);
}
}
else if(m_respawnTime) // respawn time set but expired
{
m_respawnTime = 0;
@@ -1632,6 +1645,9 @@ void Creature::setDeathState(DeathState s)
if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY) || isWorldBoss())
SaveRespawnTime();
if (canFly() && FallGround())
return;
if(!IsStopped())
StopMoving();
}
@@ -1646,6 +1662,9 @@ void Creature::setDeathState(DeathState s)
if ( LootTemplates_Skinning.HaveLootFor(GetCreatureInfo()->SkinLootId) )
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
if (canFly() && FallGround())
return;
Unit::setDeathState(CORPSE);
}
if(s == JUST_ALIVED)
@@ -1665,6 +1684,25 @@ void Creature::setDeathState(DeathState s)
}
}
bool Creature::FallGround()
{
// Let's abort after we called this function one time
if (getDeathState() == DEAD_FALLING)
return false;
// Let's do with no vmap because no way to get far distance with vmap high call
float tz = GetMap()->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), false);
// Abort too if the ground is very near
if (fabs(GetPositionZ() - tz) < 0.1f)
return false;
Unit::setDeathState(DEAD_FALLING);
GetMotionMaster()->MovePoint(0, GetPositionX(), GetPositionY(), tz);
Relocate(GetPositionX(), GetPositionY(), tz);
return true;
}
void Creature::Respawn()
{
RemoveCorpse();
+1
View File
@@ -534,6 +534,7 @@ class TRINITY_DLL_SPEC Creature : public Unit
const char* GetNameForLocaleIdx(int32 locale_idx) const;
void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState
bool FallGround();
bool LoadFromDB(uint32 guid, Map *map);
void SaveToDB();
+42 -38
View File
@@ -24,6 +24,7 @@
#include "Log.h"
#include "Database/DatabaseEnv.h"
#include "Database/DatabaseImpl.h"
#include "Platform/Define.h"
#include "MapManager.h"
#include "ObjectAccessor.h"
@@ -31,49 +32,52 @@
#include "ObjectDefines.h"
#include "Corpse.h"
static void CorpsesEraseCallBack(QueryResult *result, bool bones)
{
if(!result)
return;
do
{
Field *fields = result->Fetch();
uint32 guidlow = fields[0].GetUInt32();
float positionX = fields[1].GetFloat();
float positionY = fields[2].GetFloat();
uint32 mapid = fields[3].GetUInt32();
uint64 player_guid = MAKE_NEW_GUID(fields[4].GetUInt32(), 0, HIGHGUID_PLAYER);
uint64 guid = MAKE_NEW_GUID(guidlow, 0, HIGHGUID_CORPSE);
sLog.outDebug("[Global event] Removing %s %u (X:%f Y:%f Map:%u).",(bones?"bones":"corpse"),guidlow,positionX,positionY,mapid);
/// Resurrectable - convert corpses to bones
if(!bones)
{
if(!ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid))
{
sLog.outDebug("Corpse %u not found in world. Delete from DB.",guidlow);
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
}
}
else
///- or delete bones
{
MapManager::Instance().RemoveBonesFromMap(mapid, guid, positionX, positionY);
///- remove bones from the database
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
}
} while (result->NextRow());
delete result;
}
/// Handle periodic erase of corpses and bones
static void CorpsesErase(bool bones,uint32 delay)
{
///- Get the list of eligible corpses/bones to be removed
//No SQL injection (uint32 and enum)
QueryResult *result = CharacterDatabase.PQuery("SELECT guid,position_x,position_y,map,player FROM corpse WHERE UNIX_TIMESTAMP()-time > '%u' AND corpse_type %s '0'", delay, (bones ? "=" : "<>") );
if(result)
{
do
{
Field *fields = result->Fetch();
uint32 guidlow = fields[0].GetUInt32();
float positionX = fields[1].GetFloat();
float positionY = fields[2].GetFloat();
uint32 mapid = fields[3].GetUInt32();
uint64 player_guid = MAKE_NEW_GUID(fields[4].GetUInt32(), 0, HIGHGUID_PLAYER);
uint64 guid = MAKE_NEW_GUID(guidlow, 0, HIGHGUID_CORPSE);
sLog.outDebug("[Global event] Removing %s %u (X:%f Y:%f Map:%u).",(bones?"bones":"corpse"),guidlow,positionX,positionY,mapid);
/// Resurrectable - convert corpses to bones
if(!bones)
{
if(!ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid))
{
sLog.outDebug("Corpse %u not found in world. Delete from DB.",guidlow);
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
}
}
else
///- or delete bones
{
MapManager::Instance().RemoveBonesFromMap(mapid, guid, positionX, positionY);
///- remove bones from the database
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
}
} while (result->NextRow());
delete result;
}
CharacterDatabase.AsyncPQuery(&CorpsesEraseCallBack, bones, "SELECT guid,position_x,position_y,map,player FROM corpse WHERE UNIX_TIMESTAMP()-time > '%u' AND corpse_type %s '0'", delay, (bones ? "=" : "<>"));
}
/// not thread guarded variant for call from other thread
+1 -1
View File
@@ -334,7 +334,7 @@ void QuestMenu::AddMenuItem( uint32 QuestId, uint8 Icon)
bool QuestMenu::HasItem( uint32 questid )
{
for (QuestMenuItemList::iterator i = m_qItems.begin(); i != m_qItems.end(); i++)
for (QuestMenuItemList::iterator i = m_qItems.begin(); i != m_qItems.end(); ++i)
{
if(i->m_qId==questid)
{
+6 -6
View File
@@ -72,24 +72,24 @@ inline void PlayerCreatureRelocationWorker(Player* pl, Creature* c)
pl->UpdateVisibilityOf(c);
// Creature AI reaction
if(c->HasReactState(REACT_AGGRESSIVE) && !c->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING))
if(c->HasReactState(REACT_AGGRESSIVE) && !c->hasUnitState(UNIT_STAT_SIGHTLESS))
{
if( c->AI() && c->IsWithinSightDist(pl) /*c->AI()->IsVisible(pl)*/ && !c->IsInEvadeMode() )
if( c->AI() && c->IsWithinSightDist(pl) && !c->IsInEvadeMode() )
c->AI()->MoveInLineOfSight(pl);
}
}
inline void CreatureCreatureRelocationWorker(Creature* c1, Creature* c2)
{
if(c1->HasReactState(REACT_AGGRESSIVE) && !c1->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING))
if(c1->HasReactState(REACT_AGGRESSIVE) && !c1->hasUnitState(UNIT_STAT_SIGHTLESS))
{
if( c1->AI() && c1->IsWithinSightDist(c2) /*c1->AI()->IsVisible(c2)*/ && !c1->IsInEvadeMode() )
if( c1->AI() && c1->IsWithinSightDist(c2) && !c1->IsInEvadeMode() )
c1->AI()->MoveInLineOfSight(c2);
}
if(c2->HasReactState(REACT_AGGRESSIVE) && !c2->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING))
if(c2->HasReactState(REACT_AGGRESSIVE) && !c2->hasUnitState(UNIT_STAT_SIGHTLESS))
{
if( c2->AI() && c1->IsWithinSightDist(c2) /*c2->AI()->IsVisible(c1)*/ && !c2->IsInEvadeMode() )
if( c2->AI() && c1->IsWithinSightDist(c2) && !c2->IsInEvadeMode() )
c2->AI()->MoveInLineOfSight(c1);
}
}
+1 -1
View File
@@ -1112,7 +1112,7 @@ void Group::_setLeader(const uint64 &guid)
void Group::_removeRolls(const uint64 &guid)
{
for (Rolls::iterator it = RollId.begin(); it < RollId.end(); it++)
for (Rolls::iterator it = RollId.begin(); it < RollId.end(); ++it)
{
Roll* roll = *it;
Roll::PlayerVote::iterator itr2 = roll->playerVote.find(guid);
+57 -71
View File
@@ -10,12 +10,12 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Database/DatabaseEnv.h"
@@ -71,13 +71,7 @@ bool Guild::create(uint64 lGuid, std::string gname)
guildbank_money = 0;
purchased_tabs = 0;
QueryResult *result = CharacterDatabase.Query( "SELECT MAX(guildid) FROM guild" );
if( result )
{
Id = (*result)[0].GetUInt32()+1;
delete result;
}
else Id = 1;
Id = objmgr.GenerateGuildId();
// gname already assigned to Guild::name, use it to encode string for DB
CharacterDatabase.escape_string(gname);
@@ -116,12 +110,12 @@ bool Guild::AddMember(uint64 plGuid, uint32 plRank)
if(pl)
{
if(pl->GetGuildId() != 0)
return false;
return false;
}
else
{
if(Player::GetGuildIdFromDB(plGuid) != 0) // player already in guild
return false;
return false;
}
// remove all player signs from another petitions
@@ -432,64 +426,62 @@ void Guild::LoadPlayerStatsByGuid(uint64 guid)
void Guild::SetLeader(uint64 guid)
{
leaderGuid = guid;
this->ChangeRank(guid, GR_GUILDMASTER);
ChangeRank(guid, GR_GUILDMASTER);
CharacterDatabase.PExecute("UPDATE guild SET leaderguid='%u' WHERE guildid='%u'", GUID_LOPART(guid), Id);
}
void Guild::DelMember(uint64 guid, bool isDisbanding)
{
if(this->leaderGuid == guid && !isDisbanding)
if(leaderGuid == guid && !isDisbanding)
{
std::ostringstream ss;
ss<<"SELECT guid FROM guild_member WHERE guildid='"<<Id<<"' AND guid!='"<<this->leaderGuid<<"' ORDER BY rank ASC LIMIT 1";
QueryResult *result = CharacterDatabase.Query( ss.str().c_str() );
if( result )
MemberSlot* oldLeader = NULL;
MemberSlot* best = NULL;
uint64 newLeaderGUID = 0;
for(Guild::MemberList::iterator i = members.begin(); i != members.end(); ++i)
{
uint64 newLeaderGUID;
Player *newLeader;
std::string newLeaderName, oldLeaderName;
newLeaderGUID = (*result)[0].GetUInt64();
delete result;
this->SetLeader(newLeaderGUID);
newLeader = objmgr.GetPlayer(newLeaderGUID);
// If player not online data in data field will be loaded from guild tabs no need to update it !!
if(newLeader)
if(i->first == GUID_LOPART(guid))
{
newLeader->SetRank(GR_GUILDMASTER);
newLeaderName = newLeader->GetName();
}
else
objmgr.GetPlayerNameByGUID(newLeaderGUID, newLeaderName);
// when leader non-exist (at guild load with deleted leader only) not send broadcasts
if(objmgr.GetPlayerNameByGUID(guid, oldLeaderName))
{
WorldPacket data(SMSG_GUILD_EVENT, (1+1+oldLeaderName.size()+1+newLeaderName.size()+1));
data << (uint8)GE_LEADER_CHANGED;
data << (uint8)2;
data << oldLeaderName;
data << newLeaderName;
this->BroadcastPacket(&data);
data.Initialize(SMSG_GUILD_EVENT, (1+1+oldLeaderName.size()+1));
data << (uint8)GE_LEFT;
data << (uint8)1;
data << oldLeaderName;
this->BroadcastPacket(&data);
oldLeader = &(i->second);
continue;
}
sLog.outDebug( "WORLD: Sent (SMSG_GUILD_EVENT)" );
if(!best || best->RankId > i->second.RankId)
{
best = &(i->second);
newLeaderGUID = i->first;
}
}
else
if(!best)
{
this->Disband();
Disband();
return;
}
SetLeader(newLeaderGUID);
// If player not online data in data field will be loaded from guild tabs no need to update it !!
if(Player *newLeader = objmgr.GetPlayer(newLeaderGUID))
newLeader->SetRank(GR_GUILDMASTER);
// when leader non-exist (at guild load with deleted leader only) not send broadcasts
if(oldLeader)
{
WorldPacket data(SMSG_GUILD_EVENT, (1+1+(oldLeader->name).size()+1+(best->name).size()+1));
data << (uint8)GE_LEADER_CHANGED;
data << (uint8)2;
data << oldLeader->name;
data << best->name;
BroadcastPacket(&data);
data.Initialize(SMSG_GUILD_EVENT, (1+1+(oldLeader->name).size()+1));
data << (uint8)GE_LEFT;
data << (uint8)1;
data << oldLeader->name;
BroadcastPacket(&data);
}
sLog.outDebug( "WORLD: Sent (SMSG_GUILD_EVENT)" );
}
members.erase(GUID_LOPART(guid));
@@ -679,7 +671,7 @@ int32 Guild::GetRank(uint32 LowGuid)
MemberList::iterator itr = members.find(LowGuid);
if (itr==members.end())
return -1;
return itr->second.RankId;
}
@@ -687,7 +679,7 @@ void Guild::Disband()
{
WorldPacket data(SMSG_GUILD_EVENT, 1);
data << (uint8)GE_DISBANDED;
this->BroadcastPacket(&data);
BroadcastPacket(&data);
while (!members.empty())
{
@@ -787,11 +779,11 @@ void Guild::Query(WorldSession *session)
void Guild::SetEmblem(uint32 emblemStyle, uint32 emblemColor, uint32 borderStyle, uint32 borderColor, uint32 backgroundColor)
{
this->EmblemStyle = emblemStyle;
this->EmblemColor = emblemColor;
this->BorderStyle = borderStyle;
this->BorderColor = borderColor;
this->BackgroundColor = backgroundColor;
EmblemStyle = emblemStyle;
EmblemColor = emblemColor;
BorderStyle = borderStyle;
BorderColor = borderColor;
BackgroundColor = backgroundColor;
CharacterDatabase.PExecute("UPDATE guild SET EmblemStyle=%u, EmblemColor=%u, BorderStyle=%u, BorderColor=%u, BackgroundColor=%u WHERE guildid = %u", EmblemStyle, EmblemColor, BorderStyle, BorderColor, BackgroundColor, Id);
}
@@ -975,15 +967,10 @@ void Guild::DisplayGuildBankMoneyUpdate()
WorldPacket data(SMSG_GUILD_BANK_LIST, 8+1+4+1+1);
data << uint64(GetGuildBankMoney());
data << uint8(0);
// remaining slots for today
size_t rempos = data.wpos();
data << uint32(0); // will be filled later
data << uint8(0); // TabId, default 0
data << uint32(0); // slot withdrow, default 0
data << uint8(0); // Tell client this is a tab content packet
data << uint8(0); // not send items
BroadcastPacket(&data);
sLog.outDebug("WORLD: Sent (SMSG_GUILD_BANK_LIST)");
@@ -1918,7 +1905,7 @@ uint8 Guild::CanStoreItem( uint8 tab, uint8 slot, GuildItemPosCountVec &dest, ui
return EQUIP_ERR_OK;
}
// not specific slot or have space for partly store only in specific slot
// not specific slot or have spece for partly store only in specific slot
// search stack in tab for merge to
if( pItem->GetMaxStackCount() > 1 )
@@ -1980,9 +1967,8 @@ void Guild::SendGuildBankTabText(WorldSession *session, uint8 TabId)
bool GuildItemPosCount::isContainedIn(GuildItemPosCountVec const &vec) const
{
for(GuildItemPosCountVec::const_iterator itr = vec.begin(); itr != vec.end();++itr)
if(itr->slot == this->slot)
if(itr->slot == slot)
return true;
return false;
}
+1 -1
View File
@@ -344,7 +344,7 @@ void InstanceSaveManager::PackInstances()
uint32 InstanceNumber = 1;
// we do assume std::set is sorted properly on integer value
for (std::set< uint32 >::iterator i = InstanceSet.begin(); i != InstanceSet.end(); i++)
for (std::set< uint32 >::iterator i = InstanceSet.begin(); i != InstanceSet.end(); ++i)
{
if (*i != InstanceNumber)
{
+4 -4
View File
@@ -913,7 +913,7 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint8 groupId) co
}
// Rolling non-grouped items
for (LootStoreItemList::const_iterator i = Entries.begin() ; i != Entries.end() ; i++ )
for (LootStoreItemList::const_iterator i = Entries.begin() ; i != Entries.end() ; ++i )
{
if ( !i->Roll() )
continue; // Bad luck for the entry
@@ -933,7 +933,7 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint8 groupId) co
}
// Now processing groups
for (LootGroups::const_iterator i = Groups.begin( ) ; i != Groups.end( ) ; i++ )
for (LootGroups::const_iterator i = Groups.begin( ) ; i != Groups.end( ) ; ++i )
i->Process(loot);
}
@@ -962,7 +962,7 @@ bool LootTemplate::HasQuestDrop(LootTemplateMap const& store, uint8 groupId) con
}
// Now processing groups
for (LootGroups::const_iterator i = Groups.begin() ; i != Groups.end() ; i++ )
for (LootGroups::const_iterator i = Groups.begin() ; i != Groups.end() ; ++i )
if (i->HasQuestDrop())
return true;
@@ -980,7 +980,7 @@ bool LootTemplate::HasQuestDropForPlayer(LootTemplateMap const& store, Player co
}
// Checking non-grouped entries
for (LootStoreItemList::const_iterator i = Entries.begin() ; i != Entries.end() ; i++ )
for (LootStoreItemList::const_iterator i = Entries.begin() ; i != Entries.end() ; ++i )
{
if (i->mincountOrRef < 0) // References processing
{
+5 -5
View File
@@ -59,7 +59,7 @@ void MapInstanced::Update(const uint32& t)
void MapInstanced::MoveAllCreaturesInMoveList()
{
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); i++)
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
{
i->second->MoveAllCreaturesInMoveList();
}
@@ -69,7 +69,7 @@ void MapInstanced::MoveAllCreaturesInMoveList()
void MapInstanced::RemoveAllObjectsInRemoveList()
{
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); i++)
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
{
i->second->RemoveAllObjectsInRemoveList();
}
@@ -81,7 +81,7 @@ bool MapInstanced::RemoveBones(uint64 guid, float x, float y)
{
bool remove_result = false;
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); i++)
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
{
remove_result = remove_result || i->second->RemoveBones(guid, x, y);
}
@@ -92,11 +92,11 @@ bool MapInstanced::RemoveBones(uint64 guid, float x, float y)
void MapInstanced::UnloadAll(bool pForce)
{
// Unload instanced maps
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); i++)
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
i->second->UnloadAll(pForce);
// Delete the maps only after everything is unloaded to prevent crashes
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); i++)
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
delete i->second;
m_InstancedMaps.clear();
+9 -9
View File
@@ -253,7 +253,7 @@ Group * ObjectMgr::GetGroupByLeader(const uint64 &guid) const
Guild * ObjectMgr::GetGuildById(const uint32 GuildId) const
{
for(GuildSet::const_iterator itr = mGuildSet.begin(); itr != mGuildSet.end(); itr++)
for(GuildSet::const_iterator itr = mGuildSet.begin(); itr != mGuildSet.end(); ++itr)
if ((*itr)->GetId() == GuildId)
return *itr;
@@ -262,7 +262,7 @@ Guild * ObjectMgr::GetGuildById(const uint32 GuildId) const
Guild * ObjectMgr::GetGuildByName(std::string guildname) const
{
for(GuildSet::const_iterator itr = mGuildSet.begin(); itr != mGuildSet.end(); itr++)
for(GuildSet::const_iterator itr = mGuildSet.begin(); itr != mGuildSet.end(); ++itr)
if ((*itr)->GetName() == guildname)
return *itr;
@@ -271,7 +271,7 @@ Guild * ObjectMgr::GetGuildByName(std::string guildname) const
std::string ObjectMgr::GetGuildNameById(const uint32 GuildId) const
{
for(GuildSet::const_iterator itr = mGuildSet.begin(); itr != mGuildSet.end(); itr++)
for(GuildSet::const_iterator itr = mGuildSet.begin(); itr != mGuildSet.end(); ++itr)
if ((*itr)->GetId() == GuildId)
return (*itr)->GetName();
@@ -289,7 +289,7 @@ Guild* ObjectMgr::GetGuildByLeader(const uint64 &guid) const
ArenaTeam* ObjectMgr::GetArenaTeamById(const uint32 ArenaTeamId) const
{
for(ArenaTeamSet::const_iterator itr = mArenaTeamSet.begin(); itr != mArenaTeamSet.end(); itr++)
for(ArenaTeamSet::const_iterator itr = mArenaTeamSet.begin(); itr != mArenaTeamSet.end(); ++itr)
if ((*itr)->GetId() == ArenaTeamId)
return *itr;
@@ -298,7 +298,7 @@ ArenaTeam* ObjectMgr::GetArenaTeamById(const uint32 ArenaTeamId) const
ArenaTeam* ObjectMgr::GetArenaTeamByName(std::string arenateamname) const
{
for(ArenaTeamSet::const_iterator itr = mArenaTeamSet.begin(); itr != mArenaTeamSet.end(); itr++)
for(ArenaTeamSet::const_iterator itr = mArenaTeamSet.begin(); itr != mArenaTeamSet.end(); ++itr)
if ((*itr)->GetName() == arenateamname)
return *itr;
@@ -307,7 +307,7 @@ ArenaTeam* ObjectMgr::GetArenaTeamByName(std::string arenateamname) const
ArenaTeam* ObjectMgr::GetArenaTeamByCapitan(uint64 const& guid) const
{
for(ArenaTeamSet::const_iterator itr = mArenaTeamSet.begin(); itr != mArenaTeamSet.end(); itr++)
for(ArenaTeamSet::const_iterator itr = mArenaTeamSet.begin(); itr != mArenaTeamSet.end(); ++itr)
if ((*itr)->GetCaptain() == guid)
return *itr;
@@ -2960,7 +2960,7 @@ void ObjectMgr::LoadQuests()
delete result;
// Post processing
for (QuestMap::iterator iter = mQuestTemplates.begin(); iter != mQuestTemplates.end(); iter++)
for (QuestMap::iterator iter = mQuestTemplates.begin(); iter != mQuestTemplates.end(); ++iter)
{
Quest * qinfo = iter->second;
@@ -4179,7 +4179,7 @@ void ObjectMgr::LoadPageTexts()
{
std::ostringstream ss;
ss<< "The text page(s) ";
for (std::set<uint32>::iterator itr= checkedPages.begin();itr!=checkedPages.end(); itr++)
for (std::set<uint32>::iterator itr= checkedPages.begin();itr!=checkedPages.end(); ++itr)
ss << *itr << " ";
ss << "create(s) a circular reference, which can cause the server to freeze. Changing Next_Page of page "
<< pageItr->Page_ID <<" to 0";
@@ -5209,7 +5209,7 @@ AreaTrigger const* ObjectMgr::GetGoBackTrigger(uint32 Map) const
{
const MapEntry *mapEntry = sMapStore.LookupEntry(Map);
if(!mapEntry) return NULL;
for (AreaTriggerMap::const_iterator itr = mAreaTriggers.begin(); itr != mAreaTriggers.end(); itr++)
for (AreaTriggerMap::const_iterator itr = mAreaTriggers.begin(); itr != mAreaTriggers.end(); ++itr)
{
if(itr->second.target_mapId == mapEntry->entrance_map)
{
+1 -1
View File
@@ -1506,7 +1506,7 @@ bool Pet::addSpell(uint16 spell_id, uint16 active, PetSpellState state, uint16 s
uint32 chainstart = spellmgr.GetFirstSpellInChain(spell_id);
for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); itr++)
for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
{
if(itr->second->state == PETSPELL_REMOVED) continue;
+9 -9
View File
@@ -2476,7 +2476,7 @@ void Player::SendInitialSpells()
uint16 spellCooldowns = m_spellCooldowns.size();
data << uint16(spellCooldowns);
for(SpellCooldowns::const_iterator itr=m_spellCooldowns.begin(); itr!=m_spellCooldowns.end(); itr++)
for(SpellCooldowns::const_iterator itr=m_spellCooldowns.begin(); itr!=m_spellCooldowns.end(); ++itr)
{
SpellEntry const *sEntry = sSpellStore.LookupEntry(itr->first);
if(!sEntry)
@@ -3298,7 +3298,7 @@ bool Player::_removeSpell(uint16 spell_id)
Mail* Player::GetMail(uint32 id)
{
for(PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); itr++)
for(PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
{
if ((*itr)->messageID == id)
{
@@ -5510,7 +5510,7 @@ void Player::SendInitialReputations()
RepListID a = 0;
for (FactionStateList::const_iterator itr = m_factions.begin(); itr != m_factions.end(); itr++)
for (FactionStateList::const_iterator itr = m_factions.begin(); itr != m_factions.end(); ++itr)
{
// fill in absent fields
for (; a != itr->first; a++)
@@ -6519,7 +6519,7 @@ void Player::DuelComplete(DuelCompleteType type)
/* remove auras */
std::vector<uint32> auras2remove;
AuraMap const& vAuras = duel->opponent->GetAuras();
for (AuraMap::const_iterator i = vAuras.begin(); i != vAuras.end(); i++)
for (AuraMap::const_iterator i = vAuras.begin(); i != vAuras.end(); ++i)
{
if (!i->second->IsPositive() && i->second->GetCasterGUID() == GetGUID() && i->second->GetAuraApplyTime() >= duel->startTime)
auras2remove.push_back(i->second->GetId());
@@ -6530,7 +6530,7 @@ void Player::DuelComplete(DuelCompleteType type)
auras2remove.clear();
AuraMap const& auras = GetAuras();
for (AuraMap::const_iterator i = auras.begin(); i != auras.end(); i++)
for (AuraMap::const_iterator i = auras.begin(); i != auras.end(); ++i)
{
if (!i->second->IsPositive() && i->second->GetCasterGUID() == duel->opponent->GetGUID() && i->second->GetAuraApplyTime() >= duel->startTime)
auras2remove.push_back(i->second->GetId());
@@ -15072,13 +15072,13 @@ void Player::SendRaidInfo()
uint32 counter = 0, i;
for(i = 0; i < TOTAL_DIFFICULTIES; i++)
for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end(); itr++)
for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end(); ++itr)
if(itr->second.perm) counter++;
data << counter;
for(i = 0; i < TOTAL_DIFFICULTIES; i++)
{
for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end(); itr++)
for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end(); ++itr)
{
if(itr->second.perm)
{
@@ -15597,7 +15597,7 @@ void Player::_SaveMail()
if (!m_mailsLoaded)
return;
for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); itr++)
for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
{
Mail *m = (*itr);
if (m->state == MAIL_STATE_CHANGED)
@@ -16277,7 +16277,7 @@ void Player::PetSpellInitialize()
if(pet->isControlled() && (pet->getPetType() == HUNTER_PET || cinfo && cinfo->type == CREATURE_TYPE_DEMON && getClass() == CLASS_WARLOCK))
{
for(PetSpellMap::iterator itr = pet->m_spells.begin();itr != pet->m_spells.end();itr++)
for(PetSpellMap::iterator itr = pet->m_spells.begin();itr != pet->m_spells.end();++itr)
{
if(itr->second->state == PETSPELL_REMOVED)
continue;
+2 -2
View File
@@ -650,7 +650,7 @@ void Spell::FillTargetMap()
/*if(m_caster->GetTypeId() == TYPEID_PLAYER)
{
Player *me = (Player*)m_caster;
for (std::list<Unit*>::const_iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end(); itr++)
for (std::list<Unit*>::const_iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end(); ++itr)
{
Unit *owner = (*itr)->GetOwner();
Unit *u = owner ? owner : (*itr);
@@ -4584,7 +4584,7 @@ uint8 Spell::CheckCasterAuras() const
{
//Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
Unit::AuraMap const& auras = m_caster->GetAuras();
for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); itr++)
for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
{
if(itr->second)
{
+2 -2
View File
@@ -194,7 +194,7 @@ Unit* HostilReference::getSourceUnit()
void ThreatContainer::clearReferences()
{
for(std::list<HostilReference*>::iterator i = iThreatList.begin(); i != iThreatList.end(); i++)
for(std::list<HostilReference*>::iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
{
(*i)->unlink();
delete (*i);
@@ -208,7 +208,7 @@ HostilReference* ThreatContainer::getReferenceByTarget(Unit* pVictim)
{
HostilReference* result = NULL;
uint64 guid = pVictim->GetGUID();
for(std::list<HostilReference*>::iterator i = iThreatList.begin(); i != iThreatList.end(); i++)
for(std::list<HostilReference*>::iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
{
if((*i)->getUnitGuid() == guid)
{
+6 -1
View File
@@ -61,7 +61,12 @@ struct TRINITY_DLL_DECL Traveller
template<>
inline float Traveller<Creature>::Speed()
{
return i_traveller.GetSpeed( i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE))
return i_traveller.GetSpeed(MOVE_WALK);
else if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_FLYING2))
return i_traveller.GetSpeed(MOVE_FLY);
else
return i_traveller.GetSpeed(MOVE_RUN);
}
template<>
+5 -1
View File
@@ -342,7 +342,8 @@ enum DeathState
JUST_DIED = 1,
CORPSE = 2,
DEAD = 3,
JUST_ALIVED = 4
JUST_ALIVED = 4,
DEAD_FALLING= 5
};
enum UnitState
@@ -364,6 +365,9 @@ enum UnitState
UNIT_STAT_ISOLATED = 0x2000, // area auras do not affect other players
UNIT_STAT_ATTACK_PLAYER = 0x4000,
UNIT_STAT_CASTING = 0x8000,
UNIT_STAT_SIGHTLESS =
(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING
| UNIT_STAT_STUNNED | UNIT_STAT_CONFUSED),
UNIT_STAT_ALL_STATE = 0xffff //(UNIT_STAT_STOPPED | UNIT_STAT_MOVING | UNIT_STAT_IN_COMBAT | UNIT_STAT_IN_FLIGHT)
};
+3
View File
@@ -129,6 +129,9 @@ World::~World()
m_weathers.clear();
while (!cliCmdQueue.empty())
delete cliCmdQueue.next();
VMAP::VMapFactory::clear();
if(m_resultQueue) delete m_resultQueue;
+3 -3
View File
@@ -469,7 +469,7 @@ int WorldSocket::handle_input_missing_data (void)
if (m_Header.space () > 0)
{
// Couldn't receive the whole header this time
// Couldn't receive the whole header this time.
ACE_ASSERT (message_block.length () == 0);
errno = EWOULDBLOCK;
return -1;
@@ -503,7 +503,7 @@ int WorldSocket::handle_input_missing_data (void)
if (m_RecvPct.space () > 0)
{
//couldn't receive the whole data this time
// Couldn't receive the whole data this time.
ACE_ASSERT (message_block.length () == 0);
errno = EWOULDBLOCK;
return -1;
@@ -572,7 +572,7 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
if (closing_)
return -1;
// Dump received packet
// Dump received packet.
if (sWorldLog.LogWorld ())
{
sWorldLog.Log ("CLIENT:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
+227 -219
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
* Copyright (C) 2005-2008,2007 MaNGOS <http://getmangos.com/>
*
* Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
*
@@ -10,12 +10,12 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file WorldSocketMgr.cpp
@@ -46,315 +46,323 @@
#include "Database/DatabaseEnv.h"
#include "WorldSocket.h"
/**
* This is a helper class to WorldSocketMgr ,that manages
/**
* This is a helper class to WorldSocketMgr ,that manages
* network threads, and assigning connections from acceptor thread
* to other network threads
*/
class ReactorRunnable : protected ACE_Task_Base
{
public:
public:
ReactorRunnable () :
m_ThreadId (-1),
m_Connections (0),
m_Reactor (0)
{
ACE_Reactor_Impl* imp = 0;
ReactorRunnable () :
m_ThreadId (-1),
m_Connections (0),
m_Reactor (0)
{
ACE_Reactor_Impl* imp = 0;
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
imp = new ACE_Dev_Poll_Reactor ();
imp = new ACE_Dev_Poll_Reactor ();
imp->max_notify_iterations (128);
imp->restart (1);
imp->max_notify_iterations (128);
imp->restart (1);
#else
#else
imp = new ACE_TP_Reactor ();
imp->max_notify_iterations (128);
imp = new ACE_TP_Reactor ();
imp->max_notify_iterations (128);
#endif
#endif
m_Reactor = new ACE_Reactor (imp, 1);
}
m_Reactor = new ACE_Reactor (imp, 1);
}
virtual ~ReactorRunnable ()
{
this->Stop ();
this->Wait ();
virtual ~ReactorRunnable ()
{
Stop ();
Wait ();
if (m_Reactor)
delete m_Reactor;
}
if (m_Reactor)
delete m_Reactor;
}
void Stop ()
{
m_Reactor->end_reactor_event_loop ();
}
void Stop ()
{
m_Reactor->end_reactor_event_loop ();
}
int Start ()
{
if (m_ThreadId != -1)
return -1;
int Start ()
{
if (m_ThreadId != -1)
return -1;
return (m_ThreadId = this->activate ());
}
return (m_ThreadId = activate ());
}
void Wait ()
{
ACE_Task_Base::wait ();
}
void Wait () { ACE_Task_Base::wait (); }
long Connections ()
{
return static_cast<long> (m_Connections.value ());
}
long Connections ()
{
return static_cast<long> (m_Connections.value ());
}
int AddSocket (WorldSocket* sock)
{
ACE_GUARD_RETURN (ACE_Thread_Mutex, Guard, m_NewSockets_Lock, -1);
int AddSocket (WorldSocket* sock)
{
ACE_GUARD_RETURN (ACE_Thread_Mutex, Guard, m_NewSockets_Lock, -1);
++m_Connections;
sock->AddReference();
sock->reactor (m_Reactor);
m_NewSockets.insert (sock);
++m_Connections;
sock->AddReference();
sock->reactor (m_Reactor);
m_NewSockets.insert (sock);
return 0;
}
return 0;
}
ACE_Reactor* GetReactor ()
{
return m_Reactor;
}
ACE_Reactor* GetReactor ()
{
return m_Reactor;
}
protected:
protected:
void AddNewSockets ()
{
ACE_GUARD (ACE_Thread_Mutex, Guard, m_NewSockets_Lock);
void AddNewSockets ()
{
ACE_GUARD (ACE_Thread_Mutex, Guard, m_NewSockets_Lock);
if (m_NewSockets.empty ())
return;
if (m_NewSockets.empty ())
return;
for (SocketSet::iterator i = m_NewSockets.begin (); i != m_NewSockets.end (); ++i)
{
WorldSocket* sock = (*i);
for (SocketSet::iterator i = m_NewSockets.begin (); i != m_NewSockets.end (); ++i)
{
WorldSocket* sock = (*i);
if (sock->IsClosed ())
{
sock->RemoveReference ();
--m_Connections;
}
else
m_Sockets.insert (sock);
}
if (sock->IsClosed ())
{
sock->RemoveReference ();
--m_Connections;
}
else
m_Sockets.insert (sock);
}
m_NewSockets.clear ();
}
m_NewSockets.clear ();
}
virtual int svc (void)
{
DEBUG_LOG ("Network Thread Starting");
virtual int svc ()
{
DEBUG_LOG ("Network Thread Starting");
WorldDatabase.ThreadStart ();
WorldDatabase.ThreadStart ();
ACE_ASSERT (m_Reactor);
ACE_ASSERT (m_Reactor);
SocketSet::iterator i, t;
SocketSet::iterator i, t;
while (!m_Reactor->reactor_event_loop_done ())
{
// Don't be too smart to move this outside the loop
// the run_reactor_event_loop will modify interval
ACE_Time_Value interval (0, 10000);
while (!m_Reactor->reactor_event_loop_done ())
{
// dont be too smart to move this outside the loop
// the run_reactor_event_loop will modify interval
ACE_Time_Value interval (0, 10000);
if (m_Reactor->run_reactor_event_loop (interval) == -1)
break;
if (m_Reactor->run_reactor_event_loop (interval) == -1)
break;
AddNewSockets ();
AddNewSockets ();
for (i = m_Sockets.begin (); i != m_Sockets.end ();)
{
if ((*i)->Update () == -1)
{
t = i;
i++;
(*t)->CloseSocket ();
(*t)->RemoveReference ();
--m_Connections;
m_Sockets.erase (t);
}
else
i++;
}
}
for (i = m_Sockets.begin (); i != m_Sockets.end ();)
{
if ((*i)->Update () == -1)
{
t = i;
i++;
(*t)->CloseSocket ();
(*t)->RemoveReference ();
--m_Connections;
m_Sockets.erase (t);
}
else
i++;
}
}
WorldDatabase.ThreadEnd ();
WorldDatabase.ThreadEnd ();
DEBUG_LOG ("Network Thread Exitting");
DEBUG_LOG ("Network Thread Exitting");
return 0;
}
return 0;
}
private:
typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt;
typedef std::set<WorldSocket*> SocketSet;
private:
typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt;
typedef std::set<WorldSocket*> SocketSet;
ACE_Reactor* m_Reactor;
AtomicInt m_Connections;
int m_ThreadId;
ACE_Reactor* m_Reactor;
AtomicInt m_Connections;
int m_ThreadId;
SocketSet m_Sockets;
SocketSet m_Sockets;
SocketSet m_NewSockets;
ACE_Thread_Mutex m_NewSockets_Lock;
SocketSet m_NewSockets;
ACE_Thread_Mutex m_NewSockets_Lock;
};
WorldSocketMgr::WorldSocketMgr () :
m_NetThreadsCount (0),
m_NetThreads (0),
m_SockOutKBuff (-1),
m_SockOutUBuff (65536),
m_UseNoDelay (true),
m_Acceptor (0) {}
m_NetThreadsCount (0),
m_NetThreads (0),
m_SockOutKBuff (-1),
m_SockOutUBuff (65536),
m_UseNoDelay (true),
m_Acceptor (0)
{
}
WorldSocketMgr::~WorldSocketMgr ()
{
if (m_NetThreads)
delete [] m_NetThreads;
if (m_NetThreads)
delete [] m_NetThreads;
if(m_Acceptor)
delete m_Acceptor;
if(m_Acceptor)
delete m_Acceptor;
}
int WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address)
int
WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address)
{
m_UseNoDelay = sConfig.GetBoolDefault ("Network.TcpNodelay", true);
m_UseNoDelay = sConfig.GetBoolDefault ("Network.TcpNodelay", true);
int num_threads = sConfig.GetIntDefault ("Network.Threads", 1);
int num_threads = sConfig.GetIntDefault ("Network.Threads", 1);
if (num_threads <= 0)
{
sLog.outError ("Network.Threads is wrong in your config file");
return -1;
}
if (num_threads <= 0)
{
sLog.outError ("Network.Threads is wrong in your config file");
return -1;
}
m_NetThreadsCount = static_cast<size_t> (num_threads + 1);
m_NetThreadsCount = static_cast<size_t> (num_threads + 1);
m_NetThreads = new ReactorRunnable[m_NetThreadsCount];
m_NetThreads = new ReactorRunnable[m_NetThreadsCount];
sLog.outBasic ("Max alowed socket connections %d",ACE::max_handles ());
sLog.outBasic ("Max allowed socket connections %d",ACE::max_handles ());
m_SockOutKBuff = sConfig.GetIntDefault ("Network.OutKBuff", -1); // -1 means use default
// -1 means use default
m_SockOutKBuff = sConfig.GetIntDefault ("Network.OutKBuff", -1);
m_SockOutUBuff = sConfig.GetIntDefault ("Network.OutUBuff", 65536);
m_SockOutUBuff = sConfig.GetIntDefault ("Network.OutUBuff", 65536);
if ( m_SockOutUBuff <= 0 )
{
sLog.outError ("Network.OutUBuff is wrong in your config file");
return -1;
}
if ( m_SockOutUBuff <= 0 )
{
sLog.outError ("Network.OutUBuff is wrong in your config file");
return -1;
}
WorldSocket::Acceptor *acc = new WorldSocket::Acceptor;
m_Acceptor = acc;
WorldSocket::Acceptor *acc = new WorldSocket::Acceptor;
m_Acceptor = acc;
ACE_INET_Addr listen_addr (port, address);
ACE_INET_Addr listen_addr (port, address);
if (acc->open (listen_addr, m_NetThreads[0].GetReactor (), ACE_NONBLOCK) == -1)
{
sLog.outError ("Failed to open acceptor ,check if the port is free");
return -1;
}
if (acc->open (listen_addr, m_NetThreads[0].GetReactor (), ACE_NONBLOCK) == -1)
{
sLog.outError ("Failed to open acceptor ,check if the port is free");
return -1;
}
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Start ();
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Start ();
return 0;
return 0;
}
int WorldSocketMgr::StartNetwork (ACE_UINT16 port, const char* address)
int
WorldSocketMgr::StartNetwork (ACE_UINT16 port, const char* address)
{
if (!sLog.IsOutDebug ())
ACE_Log_Msg::instance ()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS);
if (!sLog.IsOutDebug ())
ACE_Log_Msg::instance ()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS);
if (this->StartReactiveIO (port, address) == -1)
return -1;
if (StartReactiveIO (port, address) == -1)
return -1;
return 0;
return 0;
}
void WorldSocketMgr::StopNetwork ()
void
WorldSocketMgr::StopNetwork ()
{
if (m_Acceptor)
{
WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor);
if (m_Acceptor)
{
WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor);
if (acc)
acc->close ();
}
if (acc)
acc->close ();
}
if (m_NetThreadsCount != 0)
{
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Stop ();
}
if (m_NetThreadsCount != 0)
{
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Stop ();
}
this->Wait ();
Wait ();
}
void WorldSocketMgr::Wait ()
void
WorldSocketMgr::Wait ()
{
if (m_NetThreadsCount != 0)
{
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Wait ();
}
if (m_NetThreadsCount != 0)
{
for (size_t i = 0; i < m_NetThreadsCount; ++i)
m_NetThreads[i].Wait ();
}
}
int WorldSocketMgr::OnSocketOpen (WorldSocket* sock)
int
WorldSocketMgr::OnSocketOpen (WorldSocket* sock)
{
// set some options here
if (m_SockOutKBuff >= 0)
if (sock->peer ().set_option (SOL_SOCKET,
SO_SNDBUF,
(void*) & m_SockOutKBuff,
sizeof (int)) == -1 && errno != ENOTSUP)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen set_option SO_SNDBUF");
return -1;
}
// set some options here
if (m_SockOutKBuff >= 0)
{
if (sock->peer ().set_option (SOL_SOCKET,
SO_SNDBUF,
(void*) & m_SockOutKBuff,
sizeof (int)) == -1 && errno != ENOTSUP)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen set_option SO_SNDBUF");
return -1;
}
}
static const int ndoption = 1;
static const int ndoption = 1;
// Set TCP_NODELAY.
if (m_UseNoDelay)
if (sock->peer ().set_option (ACE_IPPROTO_TCP,
TCP_NODELAY,
(void*) & ndoption,
sizeof (int)) == -1)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen: peer ().set_option TCP_NODELAY errno = %s", ACE_OS::strerror (errno));
return -1;
}
// Set TCP_NODELAY.
if (m_UseNoDelay)
{
if (sock->peer ().set_option (ACE_IPPROTO_TCP,
TCP_NODELAY,
(void*)&ndoption,
sizeof (int)) == -1)
{
sLog.outError ("WorldSocketMgr::OnSocketOpen: peer ().set_option TCP_NODELAY errno = %s", ACE_OS::strerror (errno));
return -1;
}
}
sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff);
sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff);
// we skip the Acceptor Thread
size_t min = 1;
// we skip the Acceptor Thread
size_t min = 1;
ACE_ASSERT (m_NetThreadsCount >= 1);
ACE_ASSERT (m_NetThreadsCount >= 1);
for (size_t i = 1; i < m_NetThreadsCount; ++i)
if (m_NetThreads[i].Connections () < m_NetThreads[min].Connections ())
min = i;
for (size_t i = 1; i < m_NetThreadsCount; ++i)
if (m_NetThreads[i].Connections () < m_NetThreads[min].Connections ())
min = i;
return m_NetThreads[min].AddSocket (sock);
return m_NetThreads[min].AddSocket (sock);
}
WorldSocketMgr* WorldSocketMgr::Instance ()
WorldSocketMgr*
WorldSocketMgr::Instance ()
{
return ACE_Singleton<WorldSocketMgr,ACE_Thread_Mutex>::instance();
return ACE_Singleton<WorldSocketMgr,ACE_Thread_Mutex>::instance();
}
+6
View File
@@ -99,8 +99,14 @@ namespace VMAP
void VMapFactory::clear()
{
if(iIgnoreSpellIds)
{
delete iIgnoreSpellIds;
iIgnoreSpellIds = NULL;
}
if(gVMapManager)
{
delete gVMapManager;
gVMapManager = NULL;
}
}
}