void OnQuestComplete( PlayerPointer mTarget, QuestLogEntry * qLogEntry) { if( mTarget == NULL || mTarget->GetMapMgr() == NULL || mTarget->GetMapMgr()->GetInterface() == NULL ) return; float SSX = mTarget->GetPositionX(); float SSY = mTarget->GetPositionY(); float SSZ = mTarget->GetPositionZ(); GameObjectPointer skull1 = mTarget->GetMapMgr()->GetInterface()->GetGameObjectNearestCoords(SSX, SSY, SSZ, 2551); if(skull1) return; CreaturePointer Kin_weelay = mTarget->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(SSX, SSY, SSZ, 2519); if(Kin_weelay == NULL) return; string msg1 = "Ah. Good "; msg1 += mTarget->GetName(); msg1 += ". Now let us see what tale these heads tell..."; Kin_weelay->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, msg1.c_str()); Kin_weelay->CastSpell(Kin_weelay, dbcSpell.LookupEntry(3644), false); skull1->Despawn(5000); GameObjectPointer skull2 = mTarget->GetMapMgr()->GetInterface()->GetGameObjectNearestCoords(SSX, SSY, SSZ, 2551); if(skull2) skull2->Despawn(5000); if(Kin_weelay == NULL) return; string msg = "There, "; msg += mTarget->GetName(); msg += ". You may now speak to the Bloodscalp chief and his witchdoctor."; sEventMgr.AddEvent(TO_UNIT(Kin_weelay), &Creature::SendChatMessage, (uint8)CHAT_MSG_MONSTER_SAY, (uint32)LANG_UNIVERSAL, msg.c_str(), EVENT_UNIT_CHAT_MSG, 500, 1, 1); }
void WorldSession::HandleInviteToGuild(WorldPacket & recv_data) { CHECK_PACKET_SIZE(recv_data, 1); std::string inviteeName; recv_data >> inviteeName; PlayerPointer plyr = objmgr.GetPlayer( inviteeName.c_str() , false); Guild *pGuild = _player->m_playerInfo->guild; if(!plyr) { Guild::SendGuildCommandResult(this, GUILD_INVITE_S,inviteeName.c_str(),GUILD_PLAYER_NOT_FOUND); return; } else if(!pGuild) { Guild::SendGuildCommandResult(this, GUILD_CREATE_S,"",GUILD_PLAYER_NOT_IN_GUILD); return; } if( plyr->GetGuildId() ) { Guild::SendGuildCommandResult(this, GUILD_INVITE_S,plyr->GetName(),ALREADY_IN_GUILD); return; } else if( plyr->GetGuildInvitersGuid()) { Guild::SendGuildCommandResult(this, GUILD_INVITE_S,plyr->GetName(),ALREADY_INVITED_TO_GUILD); return; } else if(!_player->m_playerInfo->guildRank->CanPerformCommand(GR_RIGHT_INVITE)) { Guild::SendGuildCommandResult(this, GUILD_INVITE_S,"",GUILD_PERMISSIONS); return; } else if(plyr->GetTeam()!=_player->GetTeam() && _player->GetSession()->GetPermissionCount() == 0 && !sWorld.cross_faction_world) { Guild::SendGuildCommandResult(this, GUILD_INVITE_S,"",GUILD_NOT_ALLIED); return; } else if(pGuild->GetNumMembers() >= MAX_GUILD_MEMBERS) { // We can't handle >= 500 members, or WoW will #132. I don't have the proper error code, so just throw the internal one. Guild::SendGuildCommandResult(this, GUILD_INVITE_S,"",GUILD_INTERNAL); return; } Guild::SendGuildCommandResult(this, GUILD_INVITE_S,inviteeName.c_str(),GUILD_U_HAVE_INVITED); //41 WorldPacket data(SMSG_GUILD_INVITE, 100); data << _player->GetName(); data << pGuild->GetGuildName(); plyr->GetSession()->SendPacket(&data); plyr->SetGuildInvitersGuid( _player->GetLowGUID() ); }
bool ChatHandler::HandleAddHonorCommand(const char* args, WorldSession* m_session) { uint32 HonorAmount = args ? atol(args) : 1; PlayerPointer plr = getSelectedChar(m_session, true); if(plr == 0) return true; BlueSystemMessage(m_session, "Adding %u honor to player %s.", HonorAmount, plr->GetName()); GreenSystemMessage(plr->GetSession(), "You have had %u honor points added to your character.", HonorAmount); HonorHandler::AddHonorPointsToPlayer(plr, HonorAmount); return true; }
bool ChatHandler::HandleResetReputationCommand(const char *args, WorldSession *m_session) { PlayerPointer plr = getSelectedChar(m_session); if(!plr) { SystemMessage(m_session, "Select a player or yourself first."); return true; } plr->_InitialReputation(); SystemMessage(m_session, "Done. Relog for changes to take effect."); sGMLog.writefromsession(m_session, "used reset reputation for %s", plr->GetName()); return true; }
void Channel::Invite(ObjectGuid p, const char *newname) { if (!IsOn(p)) { WorldPacket data; MakeNotMember(&data); SendToOne(&data, p); return; } PlayerPointer newp = GetPlayer(newname); if (!newp) { WorldPacket data; MakePlayerNotFound(&data, newname); SendToOne(&data, p); return; } PlayerPointer plr = GetPlayer(p); if (!plr.get()) return; if (newp->GetTeam() != plr->GetTeam() && !sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)) { WorldPacket data; MakeInviteWrongFaction(&data); SendToOne(&data, p); return; } if (IsOn(newp->GetObjectGuid())) { WorldPacket data; MakePlayerAlreadyMember(&data, newp->GetObjectGuid()); SendToOne(&data, p); return; } WorldPacket data; if (!newp->GetSocial()->HasIgnore(p)) { MakeInvite(&data, p); SendToOne(&data, newp->GetObjectGuid()); data.clear(); } MakePlayerInvited(&data, newp->GetName()); SendToOne(&data, p); }
bool ChatHandler::HandleAddKillCommand(const char* args, WorldSession* m_session) { uint32 KillAmount = args ? atol(args) : 1; PlayerPointer plr = getSelectedChar(m_session, true); if(plr == 0) return true; BlueSystemMessage(m_session, "Adding %u kills to player %s.", KillAmount, plr->GetName()); GreenSystemMessage(plr->GetSession(), "You have had %u honor kills added to your character.", KillAmount); for(uint32 i = 0; i < KillAmount; ++i) HonorHandler::OnPlayerKilledUnit(plr, NULLPLR); return true; }
bool ChatHandler::HandleInvincibleCommand(const char *args, WorldSession *m_session) { PlayerPointer chr = getSelectedChar(m_session); char msg[100]; if(chr) { chr->bInvincible = !chr->bInvincible; snprintf(msg, 100, "Invincibility is now %s", chr->bInvincible ? "ON. You may have to leave and re-enter this zone for changes to take effect." : "OFF. Exit and re-enter this zone for this change to take effect."); } else { snprintf(msg, 100, "Select a player or yourself first."); } if(chr!=m_session->GetPlayer()&&chr) sGMLog.writefromsession(m_session, "toggled invincibility on %s", chr->GetName()); SystemMessage(m_session, msg); return true; }
void OnQuestComplete( PlayerPointer mTarget, QuestLogEntry * qLogEntry) { if( mTarget == NULL || mTarget->GetMapMgr() == NULL || mTarget->GetMapMgr()->GetInterface() == NULL ) return; float X = mTarget->GetPositionX(); float Y = mTarget->GetPositionY(); float Z = mTarget->GetPositionZ(); CreaturePointer MacKinley = mTarget->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(X, Y, Z, 2501); if(MacKinley) { string say = "Bah! "; say += mTarget->GetName(); say += ", this foot won't budge!"; MacKinley->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, say.c_str()); } }
void OnQuestComplete( PlayerPointer mTarget, QuestLogEntry * qLogEntry) { if( mTarget == NULL || mTarget->GetMapMgr() == NULL || mTarget->GetMapMgr()->GetInterface() == NULL ) return; float X = mTarget->GetPositionX(); float Y = mTarget->GetPositionY(); float Z = mTarget->GetPositionZ(); CreaturePointer Crank = mTarget->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(X, Y, Z, 2498); if(Crank) { string say = "Hm... if you're looking to adle wits. "; say += mTarget->GetName(); say += ", then the secret behind Zanzil's zombies might just fo the trick!"; Crank->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, say.c_str()); } }
void WorldSession::HandleGuildDecline(WorldPacket & recv_data) { WorldPacket data; PlayerPointer plyr = GetPlayer(); if(!plyr) return; PlayerPointer inviter = objmgr.GetPlayer( plyr->GetGuildInvitersGuid() ); plyr->UnSetGuildInvitersGuid(); if(!inviter) return; data.Initialize(SMSG_GUILD_DECLINE); data << plyr->GetName(); inviter->GetSession()->SendPacket(&data); }
void OnQuestStart(PlayerPointer mTarget, QuestLogEntry * qLogEntry) { if( !mTarget || !mTarget->GetMapMgr() || !mTarget->GetMapMgr()->GetInterface() ) return; Yor = sEAS.SpawnCreature( mTarget, 17393, -4634.246582f, -13071.686523f, -14.755350f, 1.569997f, 0 ); if( !Yor ) return; Yor->CastSpell( Yor, 25035, true ); // Apparition Effect Yor->m_escorter = mTarget; Yor->GetAIInterface()->StopMovement( 1000 ); Yor->SetUInt32Value( UNIT_NPC_FLAGS, 0 ); char msg[256]; snprintf((char*)msg, 256, "Come, %s . Let us leave the water together, purified.", mTarget->GetName() ); Yor->SendChatMessage( CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, msg ); sEAS.CreateCustomWaypointMap( Yor ); sEAS.WaypointCreate( Yor, -4650.081055f, -13016.692383f, 1.776296f, 2.021601f, 0, 256, 16393 ); sEAS.WaypointCreate( Yor, -3886.341553f, -13098.914063f, 3.964841f, 1.855801f, 1000, 256, 16393 ); sEAS.WaypointCreate( Yor, -4677.421387f, -12983.874023f, 0.833827f, 2.335760f, 0, 256, 16393 ); // Should look player sEAS.EnableWaypoints( Yor ); //We have to set up these pointers first to resolve ambiguity in the event manager template UnitPointer Totem = TO_UNIT(Yor); UnitPointer Plr = TO_UNIT(mTarget); // Change to Stillpine form sEventMgr.AddEvent(Totem, &Unit::EventCastSpell, Totem, dbcSpell.LookupEntry(30446), EVENT_CREATURE_UPDATE, 15500, 0, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT); string msg2 = "[Furbolg] We go now, together. We will seek Vark."; sEventMgr.AddEvent(Totem, &Unit::SendChatMessage, (uint8)CHAT_MSG_MONSTER_SAY, (uint32)LANG_UNIVERSAL, msg2.c_str(), EVENT_UNIT_CHAT_MSG, 26500, 0, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT); // Change to nightsaber form sEventMgr.AddEvent(Totem, &Unit::EventCastSpell, Totem, dbcSpell.LookupEntry(30448), EVENT_CREATURE_UPDATE, 30000, 0, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT); string msg3 = "[Furbolg] Follow me to Vark."; sEventMgr.AddEvent(Totem, &Unit::SendChatMessage, (uint8)CHAT_MSG_MONSTER_SAY, (uint32)LANG_UNIVERSAL, msg3.c_str(), EVENT_UNIT_CHAT_MSG, 31000, 0, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT); if( mTarget->CalcDistance( Totem, Plr ) <= 10 ) sEventMgr.AddEvent(Totem, &Unit::EventCastSpell, Plr, dbcSpell.LookupEntry(30448), EVENT_CREATURE_UPDATE, 31000, 0, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT); }
void WorldSession::HandleAcceptTrade(WorldPacket & recv_data) { if(!_player->IsInWorld() || _player->mTradeTarget == 0) return; uint32 TradeStatus = TRADE_STATUS_ACCEPTED; PlayerPointer pTarget = _player->GetTradeTarget(); if(pTarget == NULL || !pTarget->IsInWorld()) TradeStatus = TRADE_STATUS_PLAYER_NOT_FOUND; // Tell the other player we're green. if(pTarget->m_session && pTarget->m_session->GetSocket()) pTarget->m_session->SendTradeStatus(TradeStatus); _player->mTradeStatus = TradeStatus; //Both sides accepted? Let's trade! if(_player->mTradeStatus == TRADE_STATUS_ACCEPTED && pTarget->mTradeStatus == TRADE_STATUS_ACCEPTED) { // Ready! uint32 ItemCount = 0; uint32 TargetItemCount = 0; ItemPointer pItem; // Count items on both sides, check if bags are empty. for(uint32 Index = 0; Index < 6; ++Index) { if(_player->mTradeItems[Index] != NULL) { pItem = _player->mTradeItems[Index]; if( pItem != NULL && pItem->IsContainer() && TO_CONTAINER(pItem)->HasItems()) { sCheatLog.writefromsession(this, "%s involved in bag-trick trade with %s", _player->GetName(),pTarget->GetName()); _player->GetItemInterface()->BuildInventoryChangeError( pItem, NULLITEM, INV_ERR_CANT_TRADE_EQUIP_BAGS); TradeStatus = TRADE_STATUS_CANCELLED; break; } else ++ItemCount; } if(pTarget->mTradeItems[Index] != NULL) { pItem = pTarget->mTradeItems[Index]; if( pItem != NULL && pItem->IsContainer() && TO_CONTAINER(pItem)->HasItems() ) { sCheatLog.writefromsession(this, "%s involved in bag-trick trade with %s.", pTarget->GetName(),_player->GetName()); pTarget->GetItemInterface()->BuildInventoryChangeError( pItem, NULLITEM, INV_ERR_CANT_TRADE_EQUIP_BAGS); TradeStatus = TRADE_STATUS_CANCELLED; break; } else ++TargetItemCount; } } //Do we have something to trade? if( ItemCount == 0 && TargetItemCount == 0 && _player->mTradeGold == 0 && pTarget->mTradeGold == 0 ) TradeStatus = TRADE_STATUS_CANCELLED; //Do we have enough free slots on both sides? else if((_player->m_ItemInterface->CalculateFreeSlots(NULL) + ItemCount) < TargetItemCount || (pTarget->m_ItemInterface->CalculateFreeSlots(NULL) + TargetItemCount) < ItemCount ) TradeStatus = TRADE_STATUS_CANCELLED; //Everything still ok? else if(TradeStatus == TRADE_STATUS_ACCEPTED) { uint64 Guid; //Swapp 6 itemslots (7th will not trade) for(uint32 Index = 0; Index < 6; ++Index) { Guid = _player->mTradeItems[Index] ? _player->mTradeItems[Index]->GetGUID() : 0; if(Guid != 0) { if( _player->mTradeItems[Index]->IsSoulbound()) _player->GetItemInterface()->BuildInventoryChangeError( _player->mTradeItems[Index], NULLITEM, INV_ERR_CANNOT_TRADE_THAT); else { //Remove from player pItem = _player->m_ItemInterface->SafeRemoveAndRetreiveItemByGuidRemoveStats(Guid, true); //and add to pTarget if(pItem != NULL) { pItem->SetOwner(pTarget); if( !pTarget->m_ItemInterface->AddItemToFreeSlot(pItem) ) { pItem->Destructor(); pItem = NULLITEM; } } if(GetPermissionCount()>0 || pTarget->GetSession()->GetPermissionCount()>0) sGMLog.writefromsession(this, "trade item %s with %s (soulbound = %d)", _player->mTradeItems[Index]->GetProto()->Name1, pTarget->GetName()); } } Guid = pTarget->mTradeItems[Index] ? pTarget->mTradeItems[Index]->GetGUID() : 0; if(Guid != 0) { if( pTarget->mTradeItems[Index]->IsSoulbound()) pTarget->GetItemInterface()->BuildInventoryChangeError( pTarget->mTradeItems[Index], NULLITEM, INV_ERR_CANNOT_TRADE_THAT); else { //Remove from pTarget pItem = pTarget->m_ItemInterface->SafeRemoveAndRetreiveItemByGuidRemoveStats(Guid, true); //and add to initiator if(pItem != NULL) { pItem->SetOwner(_player); if( !_player->m_ItemInterface->AddItemToFreeSlot(pItem) ) { pItem->Destructor(); pItem = NULLITEM; } } if(GetPermissionCount()>0 || pTarget->GetSession()->GetPermissionCount()>0) sGMLog.writefromsession(this, "trade item %s with %s", pTarget->mTradeItems[Index]->GetProto()->Name1, _player->GetName()); } } } // Trade Gold if(_player->mTradeGold) { pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, _player->mTradeGold); _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)_player->mTradeGold); } if(pTarget->mTradeGold) { _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, pTarget->mTradeGold); pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)pTarget->mTradeGold); } pTarget->SaveToDB(false); _player->SaveToDB(false); TradeStatus = TRADE_STATUS_COMPLETE; } SendTradeStatus(TradeStatus); if(pTarget->m_session && pTarget->m_session->GetSocket()) pTarget->m_session->SendTradeStatus(TradeStatus); // Reset Trade Vars _player->ResetTradeVariables(); pTarget->ResetTradeVariables(); } }
void ArathiBasin::AssaultControlPoint(PlayerPointer pPlayer, uint32 Id) { #if defined(BG_ANTI_CHEAT) && !defined(_DEBUG) if(!m_started) { SendChatMessage(CHAT_MSG_BG_SYSTEM_NEUTRAL, pPlayer->GetGUID(), "%s has been removed from the game for cheating.", pPlayer->GetName()); pPlayer->SoftDisconnect(); return; } #endif bool isVirgin = false; uint32 Team = pPlayer->m_bgTeam; uint32 Owner; if(m_basesOwnedBy[Id]==-1 && m_basesAssaultedBy[Id]==-1) { isVirgin = true; // omgwtfbbq our flag is a virgin? m_mapMgr->GetStateManager().UpdateWorldState(NeutralFields[Id], 0); } if(m_basesOwnedBy[Id] != -1) { Owner = m_basesOwnedBy[Id]; // set it to uncontrolled for now m_basesOwnedBy[Id] = -1; // this control point just got taken over by someone! oh noes! if( m_spiritGuides[Id] != NULL ) { map<CreaturePointer,set<uint32> >::iterator itr = m_resurrectMap.find(m_spiritGuides[Id]); if( itr != m_resurrectMap.end() ) { for( set<uint32>::iterator it2 = itr->second.begin(); it2 != itr->second.end(); ++it2 ) { PlayerPointer r_plr = m_mapMgr->GetPlayer( *it2 ); if( r_plr != NULL && r_plr->isDead() ) { HookHandleRepop( r_plr ); QueueAtNearestSpiritGuide(r_plr, itr->first); } } } m_resurrectMap.erase( itr ); m_spiritGuides[Id]->Despawn( 0, 0 ); m_spiritGuides[Id] = NULLCREATURE; } // detract one from the teams controlled points m_capturedBases[Owner] -= 1; m_mapMgr->GetStateManager().UpdateWorldState(Owner ? WORLDSTATE_AB_HORDE_CAPTUREBASE : WORLDSTATE_AB_ALLIANCE_CAPTUREBASE, m_capturedBases[Owner]); // reset the world states m_mapMgr->GetStateManager().UpdateWorldState(OwnedFields[Id][Owner], 0); // modify the resource update time period if(m_capturedBases[Owner]==0) this->event_RemoveEvents(EVENT_AB_RESOURCES_UPDATE_TEAM_0+Owner); else this->event_ModifyTime(EVENT_AB_RESOURCES_UPDATE_TEAM_0 + Owner, ResourceUpdateIntervals[m_capturedBases[Owner]]); } // Contested Flag, not ours, and is not virgin uint32 otherTeam = Team ? 0 : 1; if( !isVirgin && m_basesLastOwnedBy[Id] == Team && m_basesOwnedBy[Id] == -1 ) { m_mapMgr->GetStateManager().UpdateWorldState(AssaultFields[Id][Team ? 0 : 1], 0); this->event_RemoveEvents(EVENT_AB_CAPTURE_CP_1 + Id); SendChatMessage(Team ? CHAT_MSG_BG_SYSTEM_HORDE : CHAT_MSG_BG_SYSTEM_ALLIANCE, pPlayer->GetGUID(), "$N has defended the %s!", ControlPointNames[Id]); m_basesAssaultedBy[Id] = Team; CaptureControlPoint( Id, Team ); return; } // n***a stole my flag! if(m_basesAssaultedBy[Id] != -1) { Owner = m_basesAssaultedBy[Id]; // woah! vehicle hijack! m_basesAssaultedBy[Id] = Team; m_mapMgr->GetStateManager().UpdateWorldState(AssaultFields[Id][Owner], 0); // make sure the event does not trigger sEventMgr.RemoveEvents(shared_from_this(), EVENT_AB_CAPTURE_CP_1 + Id); // no need to remove the spawn, SpawnControlPoint will do this. } m_basesAssaultedBy[Id] = Team; // spawn the new control point gameobject SpawnControlPoint(Id, Team ? AB_SPAWN_TYPE_HORDE_ASSAULT : AB_SPAWN_TYPE_ALLIANCE_ASSAULT); // send out the chat message and sound SendChatMessage(Team ? CHAT_MSG_BG_SYSTEM_HORDE : CHAT_MSG_BG_SYSTEM_ALLIANCE, pPlayer->GetGUID(), "$N claims the %s! If left unchallenged, the %s will control it in 1 minute!", ControlPointNames[Id], Team ? "Horde" : "Alliance"); // guessed PlaySoundToAll(Team ? SOUND_ALLIANCE_CAPTURE : SOUND_HORDE_CAPTURE); // update the client's map with the new assaulting field m_mapMgr->GetStateManager().UpdateWorldState(AssaultFields[Id][Team], 1); // create the 60 second event. sEventMgr.AddEvent(TO_ARATHIBASIN(shared_from_this()), &ArathiBasin::CaptureControlPoint, Id, Team, EVENT_AB_CAPTURE_CP_1 + Id, 60000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT); // update players info pPlayer->m_bgScore.MiscData[BG_SCORE_AB_BASE_ASSAULTED]++; UpdatePvPData(); }
MapMgrPointer InstanceMgr::GetInstance(ObjectPointer obj) { PlayerPointer plr; Instance * in; InstanceMap::iterator itr; InstanceMap * instancemap; MapInfo * inf = WorldMapInfoStorage.LookupEntry(obj->GetMapId()); // we can *never* teleport to maps without a mapinfo. if( inf == NULL || obj->GetMapId() >= NUM_MAPS ) return NULLMAPMGR; if( obj->IsPlayer() ) { // players can join instances based on their groups/solo status. plr = TO_PLAYER( obj ); // single-instance maps never go into the instance set. if( inf->type == INSTANCE_NULL ) return m_singleMaps[obj->GetMapId()]; m_mapLock.Acquire(); instancemap = m_instances[obj->GetMapId()]; if(instancemap != NULL) { // check our instance_id, which we saved before in Player::_Relocate uint32 plr_instanceID = obj->GetInstanceID(); itr = instancemap->find(plr_instanceID); if(itr != instancemap->end()) { in = itr->second; if(in && in->m_mapMgr) { m_mapLock.Release(); return in->m_mapMgr; } } // iterate over our instances, and see if any of them are owned/joinable by him. for(itr = instancemap->begin(); itr != instancemap->end();) { in = itr->second; ++itr; // Is this our instance? uint8 poinst = PlayerOwnsInstance(in, plr); if(poinst >= OWNER_CHECK_OK ) { //Has it been created yet? if(in->m_mapMgr == NULL) { // create the actual instance. in->m_mapMgr = _CreateInstance(in); m_mapLock.Release(); // first one to enter, set the group instance ID if( plr->GetGroup() && !plr->GetSession()->HasGMPermissions() ) plr->GetGroup()->SetGroupInstanceID(in->m_instanceId); return in->m_mapMgr; } else // instance has found and verfied; us it. { if( poinst != OWNER_CHECK_GM_INSIDE && in->m_mapMgr->HasPlayers() && plr->GetGroup() && plr->GetGroup()->GetGroupInstanceID() != in->m_instanceId ) { Log.Warning("InstanceMgr","Reset GroupInstanceID for existing instance %u [%s] , old_ID = %u, new_ID = %u", in->m_mapId, in->m_mapInfo->name, plr->GetGroup()->GetGroupInstanceID(), in->m_instanceId ); plr->GetGroup()->SetGroupInstanceID(in->m_instanceId); } else if(in->m_mapMgr->HasPlayers() && plr->GetGroup() && plr->GetGroup()->GetGroupInstanceID() != in->m_instanceId) { Log.Warning("InstanceMgr","Forced GroupInstanceID for instance %u [%s] started by GM, old_ID = %u, new_ID = %u", in->m_mapId, in->m_mapInfo->name, plr->GetGroup()->GetGroupInstanceID(), in->m_instanceId ); plr->GetGroup()->SetGroupInstanceID(in->m_instanceId); } m_mapLock.Release(); return in->m_mapMgr; } } else DEBUG_LOG("InstanceMgr","Check failed %s",plr->GetName()); } } // if we're here, it means there are no instances on that map, or none of the instances on that map are joinable // by this player. m_mapLock.Release(); return NULLMAPMGR; } else { // units are *always* limited to their set instance ids. if(inf->type == INSTANCE_NULL) return m_singleMaps[obj->GetMapId()]; m_mapLock.Acquire(); instancemap = m_instances[obj->GetMapId()]; if(instancemap) { itr = instancemap->find(obj->GetInstanceID()); if(itr != instancemap->end()) { // we never create instances just for units. m_mapLock.Release(); return itr->second->m_mapMgr; } } // instance is non-existant (shouldn't really happen for units...) m_mapLock.Release(); return NULLMAPMGR; } }
uint32 InstanceMgr::PreTeleport(uint32 mapid, PlayerPointer plr, uint32 instanceid) { // preteleport is where all the magic happens :P instance creation, etc. MapInfo * inf = WorldMapInfoStorage.LookupEntry(mapid); Group * pGroup = plr->GetGroup() ; InstanceMap * instancemap; Instance * in; if(inf == NULL || mapid>=NUM_MAPS) return INSTANCE_ABORT_NOT_FOUND; // main continent check. if(inf->type == INSTANCE_NULL) { // this will be useful when clustering comes into play. // we can check if the destination world server is online or not and then cancel them before they load. return (m_singleMaps[mapid] != NULL) ? INSTANCE_OK : INSTANCE_ABORT_NOT_FOUND; } // shouldn't happen if(inf->type==INSTANCE_PVP) return INSTANCE_ABORT_NOT_FOUND; if( !plr->triggerpass_cheat ) { // players without groups cannot enter raid instances (no soloing them:P) if( pGroup == NULL && (inf->type == INSTANCE_RAID || inf->type == INSTANCE_MULTIMODE)) return INSTANCE_ABORT_NOT_IN_RAID_GROUP; // check that heroic mode is available if the player has requested it. if(plr->iInstanceType && inf->type != INSTANCE_MULTIMODE) return INSTANCE_ABORT_HEROIC_MODE_NOT_AVAILABLE; } // if we are here, it means: // 1) we're a non-raid instance // 2) we're a raid instance, and the person is in a group. // so, first we have to check if they have an instance on this map already, if so, allow them to teleport to that. // otherwise, we can create them a new one. m_mapLock.Acquire(); instancemap = m_instances[mapid]; if(instancemap) { InstanceMap::iterator itr; if(instanceid != 0) { //try to find our instance in ones active now. itr = instancemap->find(instanceid); if(itr != instancemap->end()) { Instance *inn = itr->second; if( PlayerOwnsInstance( inn, plr ) >= OWNER_CHECK_OK ) { m_mapLock.Release(); return INSTANCE_OK; } } //There are no active maps, re-check if this concerns a saved instance. Instance * saved_in = sInstanceMgr.GetSavedInstance( mapid, plr->GetLowGUID() ); if( saved_in && saved_in->m_instanceId == instanceid ) { if ( PlayerOwnsInstance( saved_in, plr ) >= OWNER_CHECK_OK ) { m_mapLock.Release(); return INSTANCE_OK; } } m_mapLock.Release(); return INSTANCE_ABORT_NOT_FOUND; } else { // search all active instances and see if we have one here. for(itr = instancemap->begin(); itr != instancemap->end();) { in = itr->second; ++itr; if(PlayerOwnsInstance(in, plr) >= OWNER_CHECK_OK ) { m_mapLock.Release(); // check the player count and in combat status. if(in->m_mapMgr && in->m_mapMgr->HasPlayers() && !plr->triggerpass_cheat) { if( in->m_mapMgr->IsCombatInProgress()) return INSTANCE_ABORT_ENCOUNTER; // check if we are full if( in->m_mapMgr->GetPlayerCount() >= inf->playerlimit ) return INSTANCE_ABORT_FULL; } // found our instance, allow him in. return INSTANCE_OK; } else DEBUG_LOG("InstanceMgr","Check failed %s",plr->GetName()); } } } else { if(instanceid != 0) { return INSTANCE_ABORT_NOT_FOUND; } // gotta create the hashmap. m_instances[mapid] = new InstanceMap; instancemap = m_instances[mapid]; } // if we're here, it means we need to create a new instance. in = new Instance; in->m_creation = UNIXTIME; in->m_expiration = (inf->type == INSTANCE_NONRAID) ? 0 : UNIXTIME + inf->cooldown; // expire time 0 is 10 minutes after last player leaves in->m_creatorGuid = pGroup ? 0 : plr->GetLowGUID(); // creator guid is 0 if its owned by a group. in->m_creatorGroup = pGroup ? pGroup->GetID() : 0; in->m_difficulty = plr->iInstanceType; in->m_instanceId = GenerateInstanceID(); in->m_mapId = mapid; in->m_mapMgr = NULLMAPMGR; // always start off without a map manager, it is created in GetInstance() //crash fix; GM's without group will start up raid instances as if they where nonraids //this to avoid exipring check, this is mainly for developers purpose; GM's should NOT invite any players here! if( plr->triggerpass_cheat && !plr->GetGroup() && inf->type == INSTANCE_RAID) { inf->type = INSTANCE_NONRAID; sGMLog.writefromsession(plr->GetSession(), "Started a raid instance %d [%s] as non_raid instance.", mapid, inf->name); DEBUG_LOG("InstanceMgr","Started a raid instance %d [%s] as non_raid instance.", mapid, inf->name); } in->m_mapInfo = inf; in->m_isBattleground=false; plr->SetInstanceID(in->m_instanceId); if( plr->GetGroup() && !plr->GetSession()->HasGMPermissions())//GM should not set the instanceID pGroup->SetGroupInstanceID(in->m_instanceId); DEBUG_LOG("InstanceMgr", "Prepared new instance %u for player %u and group %u on map %u. (%u)",in->m_instanceId, in->m_creatorGuid, in->m_creatorGroup, in->m_mapId, in->m_instanceId); // apply it in the instance map instancemap->insert( InstanceMap::value_type( in->m_instanceId, in ) ); // create the actual instance (if we don't GetInstance() won't be able to access it). in->m_mapMgr = _CreateInstance(in); // instance created ok, i guess? return the ok for him to transport. m_mapLock.Release(); return INSTANCE_OK; }
void StatDumper::DumpStats() { if( Filename[0] == NULL ) return; FILE* f = fopen( Filename, "w" ); if( !f ) return; Log.Debug( "StatDumper", "Writing %s", Filename ); // Dump Header fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(f, "<?xml-stylesheet type=\"text/xsl\" href=\"server_stats.xsl\"?>\n"); fprintf(f, "<serverpage>\n"); fprintf(f, " <status>\n"); uint32 races[RACE_DRAENEI+1]; uint32 classes[DRUID+1]; memset(&races[0], 0, sizeof(uint32)*(RACE_DRAENEI+1)); memset(&classes[0], 0, sizeof(uint32)*(RACE_DRAENEI+1)); std::deque<PlayerPointer> gms; { // Dump server information. #ifdef WIN32 // fprintf(f, " <platform>%s r%u/%s-Win-%s </platform>\n", sWorld.GetCoreName(), BUILD_REVISION, CONFIG, ARCH); GetCoreName function is not implemented yet on core fprintf(f, " <platform>%s r%u/%s-Win-%s </platform>\n", "WowEmu", BUILD_REVISION, CONFIG, ARCH); #else // fprintf(f, " <platform>%s r%u/%s-%s </platform>\n", sWorld.GetCoreName(), BUILD_REVISION, PLATFORM_TEXT, ARCH); GetCoreName function is not implemented yet on core fprintf(f, " <platform>%s r%u/%s-%s </platform>\n", "WowEmu", BUILD_REVISION, PLATFORM_TEXT, ARCH); #endif char uptime[80]; GenerateUptimeString(uptime); float AvgLat; uint32 GMCount; int gm = 0; int count = 0; int avg = 0; // lock players reader objmgr._playerslock.AcquireReadLock(); HM_NAMESPACE::hash_map<uint32, PlayerPointer>::const_iterator itr; for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++) { if(itr->second->GetSession() && itr->second->IsInWorld()) { count++; avg += itr->second->GetSession()->GetLatency(); if(itr->second->GetSession()->GetPermissionCount()) { gm++; gms.push_back(itr->second); } classes[itr->second->getClass()]++; races[itr->second->getRace()]++; } } objmgr._playerslock.ReleaseReadLock(); AvgLat = count ? (float)((float)avg / (float)count) : 0; GMCount = gm; fprintf(f, " <uptime>%s</uptime>\n", uptime); fprintf(f, " <oplayers>%u</oplayers>\n", (unsigned int)(sWorld.AlliancePlayers + sWorld.HordePlayers)); fprintf(f, " <cpu>%2.2f</cpu>\n", GetCPUUsage()); fprintf(f, " <qplayers>%u</qplayers>\n", (unsigned int)sWorld.GetQueueCount()); fprintf(f, " <ram>%.3f</ram>\n", GetRAMUsage()); fprintf(f, " <avglat>%.3f</avglat>\n", AvgLat); fprintf(f, " <threads>%u</threads>\n", (unsigned int)ThreadPool.GetActiveThreadCount()); fprintf(f, " <fthreads>%u</fthreads>\n", (unsigned int)ThreadPool.GetFreeThreadCount()); time_t t = (time_t)UNIXTIME; fprintf(f, " <gmcount>%u</gmcount>\n", (unsigned int)GMCount); fprintf(f, " <lastupdate>%s</lastupdate>\n", asctime(localtime(&t))); fprintf(f, " <alliance>%u</alliance>\n", (unsigned int)sWorld.AlliancePlayers); fprintf(f, " <horde>%u</horde>\n", (unsigned int)sWorld.HordePlayers); fprintf(f, " <acceptedconns>%u</acceptedconns>\n", (unsigned int)sWorld.mAcceptedConnections); fprintf(f, " <peakcount>%u</peakcount>\n", (unsigned int)sWorld.PeakSessionCount); fprintf(f, " <wdbquerysize>%u</wdbquerysize>\n", WorldDatabase.GetQueueSize()); fprintf(f, " <cdbquerysize>%u</cdbquerysize>\n", CharacterDatabase.GetQueueSize()); } fprintf(f, " </status>\n"); static const char * race_names[RACE_DRAENEI+1] = { NULL, "human", "orc", "dwarf", "nightelf", "undead", "tauren", "gnome", "troll", NULL, "bloodelf", "draenei", }; static const char * class_names[DRUID+1] = { NULL, "warrior", "paladin", "hunter", "rogue", "priest", "deathknight", "shaman", "mage", "warlock", NULL, "druid", }; fprintf(f, " <statsummary>\n"); uint32 i; for(i = 0; i <= RACE_DRAENEI; ++i) { if( race_names[i] != NULL ) fprintf(f, " <%s>%u</%s>\n", race_names[i], races[i], race_names[i]); } for(i = 0; i <= DRUID; ++i) { if( class_names[i] != NULL ) fprintf(f, " <%s>%u</%s>\n", class_names[i], classes[i], class_names[i]); } fprintf(f, " </statsummary>\n"); PlayerPointer plr; uint32 t = (uint32)time(NULL); char otime[100]; { fprintf(f, " <instances>\n"); // need a big buffer.. static char buf[500000]; memset(buf, 0, 500000); // Dump Instance Information //sWorldCreator.BuildXMLStats(buf); sInstanceMgr.BuildXMLStats(buf); fprintf(f, buf); fprintf(f, " </instances>\n"); } { // GM Information fprintf(f, " <gms>\n"); while(!gms.empty()) { plr = gms.front(); gms.pop_front(); if(!plr->bGMTagOn) continue; FillOnlineTime(t - plr->OnlineTime, otime); fprintf(f, " <gmplr>\n"); fprintf(f, " <name>%s</name>\n", plr->GetName()); fprintf(f, " <race>%u</race>\n", plr->getRace()); fprintf(f, " <class>%u</class>\n", (unsigned int)plr->getClass()); fprintf(f, " <gender>%u</gender>\n", (unsigned int)plr->getGender()); fprintf(f, " <pvprank>%u</pvprank>\n", (unsigned int)plr->GetPVPRank()); fprintf(f, " <level>%u</level>\n", (unsigned int)plr->GetUInt32Value(UNIT_FIELD_LEVEL)); fprintf(f, " <map>%u</map>\n", (unsigned int)plr->GetMapId()); fprintf(f, " <areaid>%u</areaid>\n", (unsigned int)plr->GetAreaID()); fprintf(f, " <ontime>%s</ontime>\n", otime); fprintf(f, " <latency>%u</latency>\n", (unsigned int)plr->GetSession()->GetLatency()); fprintf(f, " <permissions>%s</permissions>\n", plr->GetSession()->GetPermissions()); fprintf(f, " </gmplr>\n"); } fprintf(f, " </gms>\n"); } { fprintf(f, " <sessions>\n"); // Dump Player Information objmgr._playerslock.AcquireReadLock(); HM_NAMESPACE::hash_map<uint32, PlayerPointer>::const_iterator itr; for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++) { plr = itr->second; if(itr->second->GetSession() && itr->second->IsInWorld()) { FillOnlineTime(t - plr->OnlineTime, otime); fprintf(f, " <plr>\n"); fprintf(f, " <name>%s</name>\n", plr->GetName()); fprintf(f, " <race>%u</race>\n", (unsigned int)plr->getRace()); fprintf(f, " <class>%u</class>\n", (unsigned int)plr->getClass()); fprintf(f, " <gender>%u</gender>\n", (unsigned int)plr->getGender()); fprintf(f, " <pvprank>%u</pvprank>\n", (unsigned int)plr->GetPVPRank()); fprintf(f, " <level>%u</level>\n", (unsigned int)plr->GetUInt32Value(UNIT_FIELD_LEVEL)); fprintf(f, " <map>%u</map>\n", (unsigned int)plr->GetMapId()); fprintf(f, " <areaid>%u</areaid>\n", (unsigned int)plr->GetAreaID()); //requested by Zdarkside for he's online map. I hope it does not scre up any parser. If so, then make a better one :P fprintf(f, " <xpos>%f</xpos>\n", plr->GetPositionX ()); fprintf(f, " <ypos>%f</ypos>\n", plr->GetPositionY()); fprintf(f, " <ontime>%s</ontime>\n", otime); fprintf(f, " <latency>%u</latency>\n", (unsigned int)plr->GetSession()->GetLatency()); fprintf(f, " </plr>\n"); if(plr->GetSession()->GetPermissionCount() > 0) gms.push_back(plr); } } objmgr._playerslock.ReleaseReadLock(); fprintf(f, " </sessions>\n"); } fprintf(f, "</serverpage>\n"); fclose(f); }