Example #1
0
void ClusterInterface::HandlePlayerTeleport(WorldPacket & pck)
{
	//result has to be 2 here
	uint8 result, method;
	uint32 sessionid, mapid, instanceid;
	LocationVector location;
	uint32 sessionid2;

	pck >> result >> method;

	//someones messing with something
	if (result != 2)
		return;

	pck >> sessionid >> mapid >> instanceid >> location >> sessionid2;

	//we need to get sessionid2!
	WorldSession* s = GetSession(sessionid2);
	if (s == NULL)
		return;

	//if method is 0, simply teleport us to the location provided :)
	if (method == 0)
		sEventMgr.AddEvent(s->GetPlayer(), &Player::EventSafeTeleport, mapid, instanceid, location, EVENT_UNK, 1, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
	else
	{
		Player* p = s->GetPlayer();
		if (p == NULL)
			return; //wtf
		//change the method for 0, and fill it reversely, so the player is teleported to us :)
		//result has to be 2 when sending back here, so it relays it to the original players server
		WorldPacket data(ICMSG_PLAYER_TELEPORT);
		data << uint8(2) << uint8(0) << sessionid2 << p->GetMapId() << p->GetInstanceID() << p->GetPosition() << sessionid;
	}
}
Example #2
0
void ClusterInterface::HandlePlayerChangedServers(WorldPacket & pck)
{
	uint32 sessionid, dsid;
	pck >> sessionid >> dsid;
	if(!_sessions[dsid])
	{
		Log.Error("HandlePlayerChangedServers", "Invalid session: %u", sessionid);
		return;
	}

	WorldSession * s = _sessions[sessionid];
	Player* plr = s->GetPlayer();



	/* build the packet with the players information */
	WorldPacket data(ICMSG_PLAYER_CHANGE_SERVER_INFO, 1000);
	data << sessionid << GUID_LOPART(plr->GetGUID());

	/* pack */
	//data << plr->
	/* remove the player from our world. */
	sEventMgr.AddEvent(plr, &Player::EventRemoveAndDelete, EVENT_PLAYER_DELETE, 1000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT | EVENT_FLAG_DELETES_OBJECT);

	/* dereference the session */
}
Example #3
0
void ClusterInterface::HandlePlayerChangedServers(WorldPacket & pck)
{
	uint32 sessionid, dsid;
	pck >> sessionid >> dsid;
	if(!_sessions[dsid])
	{
		Log.Error("HandlePlayerChangedServers", "Invalid session: %u", sessionid);
		return;
	}

	WorldSession * s = _sessions[sessionid];
	Player * plr = s->GetPlayer();



	/* build the packet with the players information */
	WorldPacket data(ICMSG_PLAYER_CHANGE_SERVER_INFO, 1000);
	data << sessionid << plr->GetGUIDLow();

	/* pack */
	//data << plr->
	/* remove the player from our world. */
	sEventMgr.AddEvent(plr, &Player::EventRemoveAndDelete, EVENT_GAMEOBJECT_EXPIRE	/* meh :P */, 1000, 1);

	/* dereference the session */
}
Example #4
0
	static bool HandleLogCommand(ChatHandler* handler, const char* args)
	{
		WorldSession * Session = handler->GetSession();
		Player* player = Session->GetPlayer();
		uint32 RLimit = 10;
		if((char*)args)
		RLimit = atoi((char*)args);
 
		if(RLimit == 0 || RLimit > 100)
			RLimit = 10;
 
		QueryResult result = WorldDatabase.PQuery("SELECT * FROM `anti-farm log` LIMIT %u", RLimit);
		if(!result)
		{
			Session->SendNotification("There are no records");
				return false;
		}
		Field * fields = NULL;
	do{
		fields = result->Fetch();
		uint32 ID = fields[0].GetUInt32();
		std::string Character = fields[1].GetString();
		std::string Account = fields[2].GetString();
		uint32 Warning = fields[3].GetUInt32();
		char msg[250];
		snprintf(msg, 250, "ID : %u Character : %s Account : %s Warning Level : %u \n" , ID, Character.c_str(), Account.c_str(), Warning);
		handler->PSendSysMessage (msg);
		handler->SetSentErrorMessage (true);
	  }
	while(result->NextRow());
	return true;
	}
Example #5
0
    // Enables or disables hiding of the staff badge
    static bool HandleGMChatCommand(ChatHandler* handler, char const* args)
    {
        if (!*args)
        {
            WorldSession* session = handler->GetSession();
            if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
                session->SendNotification(LANG_GM_CHAT_ON);
            else
                session->SendNotification(LANG_GM_CHAT_OFF);
            return true;
        }

        std::string param = (char*)args;

        if (param == "on")
        {
            handler->GetSession()->GetPlayer()->SetGMChat(true);
            handler->GetSession()->SendNotification(LANG_GM_CHAT_ON);
            return true;
        }

        if (param == "off")
        {
            handler->GetSession()->GetPlayer()->SetGMChat(false);
            handler->GetSession()->SendNotification(LANG_GM_CHAT_OFF);
            return true;
        }

        handler->SendSysMessage(LANG_USE_BOL);
        handler->SetSentErrorMessage(true);
        return false;
    }
    static bool HandleEditAICommand(ChatHandler* handler, const char* args)
	{
		uint32 AIedit = atoi((char*)args);
		WorldSession * Session = handler->GetSession();
		Player* player = Session->GetPlayer();
		WorldDatabase.PExecute("ALTER TABLE `anti-farm log` AUTO_INCREMENT = %u", AIedit);
		Session->SendAreaTriggerMessage("Auto Increment starting point successfully set to %u", AIedit);
		return true;
	}
Example #7
0
    void Callback(QueryResult* result)
    {
        WorldSession* sess = sWorld.FindSession(accountId);
        if (!sess || !sess->GetPlayer() || sess->GetPlayer()->GetObjectGuid() != senderGuid || !sess->GetPlayer()->IsInWorld())
        {
            delete result;
            delete this;
            return;
        }

        if (result)
        {
            Field *fields = result->Fetch();
            mailsCount = fields[0].GetUInt32();
            delete result;
        }
        sess->HandleSendMailCallback(this);
        delete this;
    }
        // This callback is different from the normal HandlePlayerLoginCallback in that it
        // sets up the bot's world session and also stores the pointer to the bot player in the master's
        // world session m_playerBots map
        void HandlePlayerBotLoginCallback(QueryResult* /*dummy*/, SqlQueryHolder* holder)
        {
            if (!holder)
                return;

            LoginQueryHolder* lqh = (LoginQueryHolder*) holder;

            WorldSession* masterSession = sWorld.FindSession(lqh->GetAccountId());

            if (! masterSession || sObjectMgr.GetPlayer(lqh->GetGuid()))
            {
                delete holder;
                return;
            }

            // The bot's WorldSession is owned by the bot's Player object
            // The bot's WorldSession is deleted by PlayerbotMgr::LogoutPlayerBot
            WorldSession* botSession = new WorldSession(lqh->GetAccountId(), nullptr, SEC_PLAYER, 0, LOCALE_enUS);
            botSession->HandlePlayerLogin(lqh); // will delete lqh
            masterSession->GetPlayer()->GetPlayerbotMgr()->OnBotLogin(botSession->GetPlayer());
        }
Example #9
0
        // Playerbot mod: is different from the normal HandlePlayerLoginCallback in that it
        // sets up the bot's world session and also stores the pointer to the bot player in the master's
        // world session m_playerBots map
        void HandlePlayerBotLoginCallback(QueryResult * /*dummy*/, SqlQueryHolder * holder, uint32 masterId)
        {
            if (!holder)
                return;

            LoginQueryHolder* lqh = (LoginQueryHolder*) holder;

            WorldSession* masterSession = sWorld.FindSession(masterId);

            if (! masterSession || sObjectMgr.GetPlayer(lqh->GetGuid()))
            {
                delete holder;
                return;
            }

            // The bot's WorldSession is owned by the bot's Player object
            // The bot's WorldSession is deleted by PlayerbotMgr::LogoutPlayerBot
            WorldSession *botSession = new WorldSession(lqh->GetAccountId(), NULL, SEC_PLAYER, 0, masterSession->GetSessionDbcLocale());
            botSession->m_Address = "bot";
            botSession->HandlePlayerLogin(lqh); // will delete lqh
            masterSession->GetPlayer()->GetPlayerbotMgr()->OnBotLogin(botSession->GetPlayer());
        }
Example #10
0
void ClusterInterface::DestroySession(uint32 sid)
{
	WorldSession * s = _sessions[sid];
	_sessions[sid] = 0;
	if(s)
	{
		/* todo: replace this with an event so we don't remove from the wrong thread */
		if(s->GetPlayer())
			s->LogoutPlayer(true);

		delete s->GetSocket();
		delete s;
	}
}
Example #11
0
	static bool HandleDeleteAllCommand(ChatHandler* handler, const char* args)
	{
		WorldSession * Session = handler->GetSession();
		Player* player = Session->GetPlayer();
	    WorldDatabase.Execute("DELETE FROM `anti-farm log`");
		QueryResult result = WorldDatabase.Query("SELECT `ID` FROM `anti-farm log`");
		if(result)
		{
			Session->SendNotification("Deletion failed");
			return false;
		}
		else
		{
			Session->SendAreaTriggerMessage("Deletion successful!");
			return true;
		}
		return true;
	}
Example #12
0
	static bool HandleDeleteIDCommand(ChatHandler* handler, const char* args)
	{
		if(!*args)
			return false;
		WorldSession * Session = handler->GetSession();
		Player* player = Session->GetPlayer();
		uint32 ID = atoi((char*)args);
		QueryResult result = WorldDatabase.PQuery("SELECT * FROM `anti-farm log` WHERE `ID` = %u", ID);
		if(!result)
		{
			char msg [250];
			snprintf(msg, 250, "Log with Log ID : %u doesn't exist", ID);
			Session->SendNotification(msg);
			return false;
		}
		WorldDatabase.PExecute("DELETE FROM `anti-farm log` WHERE `ID` = %u", ID);
		Session->SendAreaTriggerMessage("Deletion of Log ID : %u Successful!", ID);
		return true;
	}
Example #13
0
	static bool HandleLogCommand(ChatHandler* handler, const char* args)
	{
		WorldSession * Session = handler->GetSession();
		Player* player = Session->GetPlayer();
		uint32 RLimit = 10;
		if((char*)args)
		RLimit = atoi((char*)args);

		if(RLimit == 0 || RLimit > 100)
			RLimit = 10;

		QueryResult result = WorldDatabase.PQuery("SELECT * FROM `anti-farm log` LIMIT %u", RLimit);
		if(!result)
		{
			Session->SendNotification("There are no records");
				return false;
		}
		Field * fields = NULL;
	do{
		uint32 ID = (*result)[0].GetUInt32();
		uint32 guid = (*result)[1].GetUInt32();
		uint32 Warning = (*result)[2].GetUInt32();
		QueryResult nameResult = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid = %u", guid);
		if (nameResult)
		{
			const char * name = (*nameResult)[0].GetCString();
			char msg[250];
			snprintf(msg,250, "ID: %u Character: %s Warning Level: %u\n", ID, name, Warning);
			handler->PSendSysMessage(msg);
			handler->SetSentErrorMessage(true);
		}
		else
		{
			char msg[250];
			snprintf(msg, 250, "ID: %u Character: %u Warning Level: %u \n" , ID, guid, Warning);
			handler->PSendSysMessage (msg);
			handler->SetSentErrorMessage (true);
		}
	  }
	while(result->NextRow());
	return true;
	}
Example #14
0
bool ChatHandler::HandleFullDismountCommand(const char * args, WorldSession *m_session)
{
	Player* p_target = getSelectedChar(m_session, false);
	if(!p_target)
	{
		SystemMessage(m_session, "Select a player or yourself first.");
		return false;
	}

   if(!p_target->IsInWorld())
       return false;

	WorldSession* sess = p_target->GetSession();
   
	if(!sess || !sess->GetSocket())
   	{
       RedSystemMessage(m_session, "Not able to locate player %s.", sess->GetPlayer()->GetName()); 
       return false;
	}

	if(!p_target->m_taxiPaths.size())
		p_target->SetTaxiState(false);

	p_target->SetTaxiPath(NULL);
	p_target->UnSetTaxiPos();
	p_target->m_taxi_ride_time = 0;

	p_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID , 0);
	p_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNTED_TAXI);
	p_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOCK_PLAYER);
	p_target->Dismount();
	sEventMgr.RemoveEvents(p_target, EVENT_PLAYER_TAXI_INTERPOLATE);

	if( p_target->m_taxiPaths.size() )
		p_target->m_taxiPaths.clear();
	return true;
}
Example #15
0
void MapMgr::_PerformObjectDuties()
{
	++mLoopCounter;
	uint32 mstime = getMSTime();
	uint32 difftime = mstime - lastUnitUpdate;
	if(difftime > 500)
		difftime = 500;

	// Update any events.
	// we make update of events before objects so in case there are 0 timediff events they do not get deleted after update but on next server update loop
	eventHolder.Update(difftime);

	// Update creatures.
	{
		creature_iterator = activeCreatures.begin();
		Creature* ptr;
		Pet* ptr2;

		for(; creature_iterator != activeCreatures.end();)
		{
			ptr = *creature_iterator;
			++creature_iterator;
			ptr->Update(difftime);
		}

		pet_iterator = m_PetStorage.begin();
		for(; pet_iterator != m_PetStorage.end();)
		{
			ptr2 = pet_iterator->second;
			++pet_iterator;
			ptr2->Update(difftime);
		}
	}

	// Update players.
	{
		PlayerStorageMap::iterator itr = m_PlayerStorage.begin();
		Player* ptr;
		for(; itr != m_PlayerStorage.end();)
		{
			ptr = itr->second;
			++itr;
			ptr->Update(difftime);
		}

		lastUnitUpdate = mstime;
	}

	// Dynamic objects
	//
	// We take the pointer, increment, and update in this order because during the update the DynamicObject might get deleted,
	// rendering the iterator unincrementable. Which causes a crash!
	{
		for(DynamicObjectStorageMap::iterator itr = m_DynamicObjectStorage.begin(); itr != m_DynamicObjectStorage.end();)
		{

			DynamicObject* o = itr->second;
			++itr;

			o->UpdateTargets();
		}
	}

	// Update gameobjects (not on every loop, however)
	if(mLoopCounter % 2)
	{
		difftime = mstime - lastGameobjectUpdate;

		GameObjectSet::iterator itr = activeGameObjects.begin();
		GameObject* ptr;
		for(; itr != activeGameObjects.end();)
		{
			ptr = *itr;
			++itr;
			if(ptr != NULL)
				ptr->Update(difftime);
		}

		lastGameobjectUpdate = mstime;
	}

	// Sessions are updated every loop.
	{
		int result;
		WorldSession* session;
		SessionSet::iterator itr = Sessions.begin();
		SessionSet::iterator it2;

		for(; itr != Sessions.end();)
		{
			session = (*itr);
			it2 = itr;
			++itr;

			if(session->GetInstance() != m_instanceID)
			{
				Sessions.erase(it2);
				continue;
			}

			// Don't update players not on our map.
			// If we abort in the handler, it means we will "lose" packets, or not process this.
			// .. and that could be disastrous to our client :P
			if(session->GetPlayer() && (session->GetPlayer()->GetMapMgr() != this && session->GetPlayer()->GetMapMgr() != 0))
			{
				continue;
			}

			if((result = session->Update(m_instanceID)) != 0)
			{
				if(result == 1)
				{
					// complete deletion
					sWorld.DeleteSession(session);
				}
				Sessions.erase(it2);
			}
		}
	}

	// Finally, A9 Building/Distribution
	_UpdateObjects();
}
Example #16
0
    static bool GOMove_Command(ChatHandler* handler, const char* args)
    {
        if (!args)
            return false;

        char* ID_t = strtok((char*)args, " ");
        if (!ID_t)
            return false;
        uint32 ID = (uint32)atol(ID_t);

        char* GObjectID_C = strtok(NULL, " ");
        uint32 GObjectID = 0;
        bool isHex = false;
        if (GObjectID_C)
        {
            GObjectID = strtoul(GObjectID_C, NULL, 0); // can take in hex as well as dec
            isHex = (std::string(GObjectID_C).find("0x") != std::string::npos);
        }

        char* ARG_t = strtok(NULL, " ");
        uint32 ARG = 0;
        if (ARG_t)
            ARG = (uint32)atol(ARG_t);

        WorldSession* session = handler->GetSession();
        Player* player = session->GetPlayer();
        uint64 playerGUID = player->GetGUID();

        if (ID < SPAWN) // no args
        {
            if (ID >= DELET && ID <= GOTO) // has target (needs retrieve gameobject)
            {
                GameObject* target = GetObjectByGObjectID(player, GObjectID, isHex);
                if (!target)
                    ChatHandler(player->GetSession()).PSendSysMessage("Object GUID: %u not found. Temp(%u)", GObjectID, isHex ? 1 : 0);
                else
                {
                    float x,y,z,o;
                    target->GetPosition(x,y,z,o);
                    uint32 p = target->GetPhaseMask();
                    switch(ID)
                    {
                    case DELET: DeleteObject(target/*, isHex ? GObjectID : 0*/); SendSelectionInfo(player, GObjectID, isHex, false); break;
                    case X: SpawnObject(player,player->GetPositionX(),y,z,o,p,true,GObjectID, isHex);      break;
                    case Y: SpawnObject(player,x,player->GetPositionY(),z,o,p,true,GObjectID, isHex);      break;
                    case Z: SpawnObject(player,x,y,player->GetPositionZ(),o,p,true,GObjectID, isHex);      break;
                    case O: SpawnObject(player,x,y,z,player->GetOrientation(),p,true,GObjectID, isHex);    break;
                    case GOTO: player->TeleportTo(target->GetMapId(), x,y,z,o);                     break;
                    case RESPAWN: SpawnObject(player,x,y,z,o,p,false,target->GetEntry(), isHex);           break;
                    case GROUND:
                        {
                            float ground = target->GetMap()->GetHeight(target->GetPhaseMask(), x, y, MAX_HEIGHT);
                            if(ground != INVALID_HEIGHT)
                                SpawnObject(player,x,y,ground,o,p,true,GObjectID, isHex);
                        } break;
                    }
                }
            }
            else
            {
                switch(ID)
                {
                case TEST: session->SendAreaTriggerMessage(player->GetName().c_str());      break;
                case FACE: { float piper2 = M_PI/2; float multi = player->GetOrientation()/piper2; float multi_int = floor(multi); float new_ori = (multi-multi_int > 0.5f) ? (multi_int+1)*piper2 : multi_int*piper2; player->SetFacingTo(new_ori); } break;
                case SAVE: SaveObject(player, GObjectID, isHex);                                   break;
                case SELECTNEAR:
                    {
                        GameObject* object = handler->GetNearbyGameObject();
                        object = GetClosestGObjectID(player, object);
                        if (!object)
                            ChatHandler(player->GetSession()).PSendSysMessage("No objects found");
                        else
                        {
                            bool isHex = (object->GetGUIDHigh() != HIGHGUID_GAMEOBJECT);
                            SendSelectionInfo(player, isHex ? object->GetGUIDHigh() : object->GetDBTableGUIDLow() ? object->GetDBTableGUIDLow() : object->GetGUIDLow(), isHex, true);
                            session->SendAreaTriggerMessage("Selected %s", object->GetName().c_str());
                        }
                    } break;
                }
            }
        }
        else if (ARG && ID >= SPAWN)
        {
            if (ID >= NORTH && ID <= PHASE)
            {
                GameObject* target = GetObjectByGObjectID(player, GObjectID, isHex);
                if (!target)
                    ChatHandler(player->GetSession()).PSendSysMessage("Object GUID: %u not found. Temporary: %s", GObjectID, isHex ? "true" : "false");
                else
                {
                    float x,y,z,o;
                    target->GetPosition(x,y,z,o);
                    uint32 p = target->GetPhaseMask();
                    switch(ID)
                    {
                    case NORTH: SpawnObject(player,x+((float)ARG/100),y,z,o,p,true,GObjectID, isHex);                        break;
                    case EAST: SpawnObject(player,x,y-((float)ARG/100),z,o,p,true,GObjectID, isHex);                         break;
                    case SOUTH: SpawnObject(player,x-((float)ARG/100),y,z,o,p,true,GObjectID, isHex);                        break;
                    case WEST: SpawnObject(player,x,y+((float)ARG/100),z,o,p,true,GObjectID, isHex);                         break;
                    case NORTHEAST: SpawnObject(player,x+((float)ARG/100),y-((float)ARG/100),z,o,p,true,GObjectID, isHex);   break;
                    case SOUTHEAST: SpawnObject(player,x-((float)ARG/100),y-((float)ARG/100),z,o,p,true,GObjectID, isHex);   break;
                    case SOUTHWEST: SpawnObject(player,x-((float)ARG/100),y+((float)ARG/100),z,o,p,true,GObjectID, isHex);   break;
                    case NORTHWEST: SpawnObject(player,x+((float)ARG/100),y+((float)ARG/100),z,o,p,true,GObjectID, isHex);   break;
                    case UP: SpawnObject(player,x,y,z+((float)ARG/100),o,p,true,GObjectID, isHex);                           break;
                    case DOWN: SpawnObject(player,x,y,z-((float)ARG/100),o,p,true,GObjectID, isHex);                         break;
                    case RIGHT: SpawnObject(player,x,y,z,o-((float)ARG/100),p,true,GObjectID, isHex);                        break;
                    case LEFT: SpawnObject(player,x,y,z,o+((float)ARG/100),p,true,GObjectID, isHex);                         break;
                    case PHASE: SpawnObject(player,x,y,z,o,ARG,true,GObjectID, isHex);                                       break;
                    }
                }
            }
            else
            {
                switch(ID)
                {
                case SPAWN:
                    {
                        if (SpawnObject(player, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),  player->GetOrientation(), player->GetPhaseMaskForSpawn(), false, ARG, false, true))
                            SpawnQue[player->GetGUID()] = ARG;
                    } break;
                case SPAWNSPELL:
                    {
                        SpawnQue[player->GetGUID()] = ARG;
                    } break;
                case SELECTALLNEAR:
                    { 
                        if (ARG > 5000)
                            ARG = 5000;

                        QueryResult result = WorldDatabase.PQuery("SELECT guid, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE map = '%u' AND position_x BETWEEN '%f'-'%u' AND '%f'+'%u' AND position_y BETWEEN '%f'-'%u' AND '%f'+'%u' AND position_z BETWEEN '%f'-'%u' AND '%f'+'%u' ORDER BY order_ ASC LIMIT 100",
                            player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), player->GetPositionX(), ARG, player->GetPositionX(), ARG, player->GetPositionY(), ARG, player->GetPositionY(), ARG, player->GetPositionZ(), ARG, player->GetPositionZ(), ARG);

                        if (result)
                        {
                            do
                            {
                                Field* fields   = result->Fetch();
                                uint32 guidLow  = fields[0].GetUInt32();

                                if (GameObject* object = GetObjectByGObjectID(player, guidLow, false))
                                    SendSelectionInfo(player, guidLow, false, true);
                            }
                            while (result->NextRow());
                        }
                        for(std::set<uint32>::const_iterator it = GObjects.begin(); it != GObjects.end();)
                        {
                            GameObject* temp = player->GetGameObject(*it);
                            if(!temp)
                            {
                                GObjects.erase(*it++);
                                continue;
                            }
                            if(temp->IsWithinDistInMap(player, ARG))
                                SendSelectionInfo(player, (*it), true, true);
                            ++it;
                        }
                    } break;
                }
            }
        }
        else
            return false;
        return true;
    }
Example #17
0
void ClusterInterface::HandleTeleportResult(WorldPacket & pck)
{
	uint32 sessionid;
	uint8 result;
	uint32 mapid, instanceid;
	LocationVector vec;
	float o;

	pck >> sessionid;

	WorldSession* s = GetSession(sessionid);

	if (!s)
	{
		//tell the realm-server we have no session
		WorldPacket data(ICMSG_ERROR_HANDLER, 5);
		data << uint8(1); //1 = no session
		data << sessionid;
		sClusterInterface.SendPacket(&data);
		return;
	}

	pck >> result >> mapid >> instanceid >> vec >> o;

	//the destination is on the same server
	if (result == 1)
	{
		if (s->GetPlayer() != NULL)
			sEventMgr.AddEvent(s->GetPlayer(), &Player::EventClusterMapChange, mapid, instanceid, vec, EVENT_UNK, 1, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
	}
	else
	{
		//make this non-async, needs redone to support packing the player
		//since were saving it HAS TO BE HERE so the new server has the correct data
		WorldPacket nw(SMSG_NEW_WORLD);
		nw << mapid << vec << o;
		s->SendPacket(&nw);

		uint32 oldmapid = s->GetPlayer()->GetMapId();
		uint32 oldinstanceid = s->GetPlayer()->GetInstanceID();
		uint32 playerlowguid = s->GetPlayer()->GetLowGUID();
		s->GetPlayer()->SetMapId(mapid);
		s->GetPlayer()->SetInstanceID(instanceid);
		s->GetPlayer()->SetPosition(vec.x, vec.y, vec.z, o);
		s->GetPlayer()->SaveToDB(true);

		//need to shift back to old ones for removing from world :)
		s->GetPlayer()->SetMapId(oldmapid);
		s->GetPlayer()->SetInstanceID(oldinstanceid);

		WorldPacket data(ICMSG_SWITCH_SERVER, 100);
		data << sessionid << playerlowguid << mapid << instanceid << vec << o;
		sClusterInterface.SendPacket(&data);

		RPlayerInfo * pRPlayer = GetPlayer(playerlowguid);
		bool newRplr = false;
		if(pRPlayer == NULL)
		{
			pRPlayer = new RPlayerInfo;
			newRplr = true;
		}
		s->GetPlayer()->UpdateRPlayerInfo(pRPlayer, newRplr);
		pRPlayer->MapId = mapid;
		pRPlayer->InstanceId = instanceid;
		data.Initialize(ICMSG_PLAYER_INFO);
		pRPlayer->Pack(data);
		sClusterInterface.SendPacket(&data);

		sEventMgr.AddEvent(s->GetPlayer(), &Player::HandleClusterRemove, EVENT_UNK, 1, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
	}
}
Example #18
0
void MapMgr::_PerformObjectDuties()
{
	++mLoopCounter;
	uint32 mstime = getMSTime();
	uint32 difftime = mstime - lastUnitUpdate;
	if(difftime > 500)
		difftime = 500;

	// Update creatures.
	{
		CreatureSet::iterator itr = activeCreatures.begin();
		PetStorageMap::iterator it2 = m_PetStorage.begin();
		Creature * ptr;
		Pet * ptr2;

		for(; itr != activeCreatures.end();)
		{
			ptr = *itr;
			++itr;
			ptr->Update(difftime);
		}

		for(; it2 != m_PetStorage.end();)
		{
			ptr2 = it2->second;
			++it2;

			ptr2->Update(difftime);
		}		
	}

	// Update any events.
	eventHolder.Update(difftime);

	// Update players.
	{
		PlayerStorageMap::iterator itr = m_PlayerStorage.begin();
		Player* ptr;
		for(; itr != m_PlayerStorage.end(); )
		{
			ptr = static_cast< Player* >( (itr->second) );
			++itr;
			if( ptr != NULL )
				ptr->Update( difftime );
		}

		lastUnitUpdate = mstime;
	}

	// Update gameobjects (not on every loop, however)
	if( mLoopCounter % 2 )
	{
		difftime = mstime - lastGameobjectUpdate;

		GameObjectSet::iterator itr = activeGameObjects.begin();
		GameObject * ptr;
		for(; itr != activeGameObjects.end(); )
		{
			ptr = *itr;
			++itr;
			ptr->Update( difftime );
		}

		lastGameobjectUpdate = mstime;
	}	

	// Sessions are updated every loop.
	{
		int result;
		WorldSession * session;
		SessionSet::iterator itr = Sessions.begin();
		SessionSet::iterator it2;

		for(; itr != Sessions.end();)
		{
			session = (*itr);
			it2 = itr;
			++itr;

			if(session->GetInstance() != m_instanceID)
			{
				Sessions.erase(it2);
				continue;
			}

			// Don't update players not on our map.
			// If we abort in the handler, it means we will "lose" packets, or not process this.
			// .. and that could be diasterous to our client :P
			if(session->GetPlayer() && (session->GetPlayer()->GetMapMgr() != this && session->GetPlayer()->GetMapMgr() != 0))
			{
				continue;
			}

			if((result = session->Update(m_instanceID)))
			{
				if(result == 1)
				{
					// complete deletion
					sWorld.DeleteSession(session);
				}
				Sessions.erase(it2);
			}
		}
	}

	// Finally, A9 Building/Distribution
	_UpdateObjects();
}