Beispiel #1
0
void Item::Create(uint32 itemid, Player* owner)
{
    SetEntry(itemid);

    if (owner)
    {
        uint64 OwnerGUID = owner->GetGUID();

        SetOwnerGUID(OwnerGUID);
        SetContainerGUID(OwnerGUID);
    }

    SetStackCount(1);

    m_itemProto = ItemPrototypeStorage.LookupEntry(itemid);

    ARCEMU_ASSERT(m_itemProto != NULL);

    SetCharges(0, m_itemProto->Spells[0].Charges);
    SetCharges(1, m_itemProto->Spells[1].Charges);
    SetCharges(2, m_itemProto->Spells[2].Charges);
    SetCharges(3, m_itemProto->Spells[3].Charges);
    SetCharges(4, m_itemProto->Spells[4].Charges);
    SetDurability(m_itemProto->MaxDurability);
    SetDurabilityMax(m_itemProto->MaxDurability);

    m_owner = owner;
    locked = m_itemProto->LockId ? true : false;
}
Beispiel #2
0
void Container::LoadFromDB(Field* fields)
{

    uint32 itemid = fields[2].GetUInt32();
    m_itemProto = ItemPrototypeStorage.LookupEntry(itemid);

    ARCEMU_ASSERT(m_itemProto != NULL);
    SetEntry(itemid);


    SetCreatorGUID(fields[5].GetUInt32());
    SetStackCount(1);

    SetUInt32Value(ITEM_FIELD_FLAGS, fields[8].GetUInt32());
    SetItemRandomPropertyId(fields[9].GetUInt32());

    SetDurabilityMax(m_itemProto->MaxDurability);
    SetDurability(fields[12].GetUInt32());


    SetNumSlots(m_itemProto->ContainerSlots);

    m_Slot = new Item*[m_itemProto->ContainerSlots];
    memset(m_Slot, 0, sizeof(Item*) * (m_itemProto->ContainerSlots));

}
Beispiel #3
0
void Guild::LogGuildEvent(uint8 iEvent, uint8 iStringCount, ...)
{
	if(!m_commandLogging)
		return;

	va_list ap;
	char* strs[4] = {NULL, NULL, NULL, NULL};

	va_start(ap, iStringCount);
	ARCEMU_ASSERT(iStringCount <= 4);

	WorldPacket data(SMSG_GUILD_EVENT, 100);
	uint32 i;
	data << iEvent;
	data << iStringCount;

	for(i = 0; i < iStringCount; ++i)
	{
		strs[i] = va_arg(ap, char*);
		data << strs[i];
	}

	va_end(ap);
	SendPacket(&data);
}
Beispiel #4
0
bool QuestLogEntry::LoadFromDB(Field* fields)
{
	// playerguid,questid,timeleft,area0,area1,area2,area3,kill0,kill1,kill2,kill3
	int f = 3;
	ARCEMU_ASSERT(m_plr && m_quest);
	expirytime = fields[f].GetUInt32();
	f++;
	for(int i = 0; i < 4; ++i)
	{
		m_explored_areas[i] = fields[f].GetUInt32();
		f++;
		CALL_QUESTSCRIPT_EVENT(this, OnExploreArea)(m_explored_areas[i], m_plr, this);
	}

	for(int i = 0; i < 4; ++i)
	{
		m_mobcount[i] = fields[f].GetUInt32();
		f++;
		if(GetQuest()->required_mobtype[i] == QUEST_MOB_TYPE_CREATURE)
		{
			CALL_QUESTSCRIPT_EVENT(this, OnCreatureKill)(GetQuest()->required_mob[i], m_plr, this);
		}
		else
		{
			CALL_QUESTSCRIPT_EVENT(this, OnGameObjectActivate)(GetQuest()->required_mob[i], m_plr, this);
		}
	}

	completed = fields[f].GetUInt32();

	mDirty = false;
	return true;
}
Beispiel #5
0
void WorldSocket::Authenticate()
{
	ARCEMU_ASSERT(pAuthenticationPacket != NULL);
	mQueued = false;

	if(mSession == NULL)
		return;

	if(mSession->HasFlag(ACCOUNT_FLAG_XPACK_02))
		OutPacket(SMSG_AUTH_RESPONSE, 11, "\x0C\x30\x78\x00\x00\x00\x00\x00\x00\x00\x02");
	else if(mSession->HasFlag(ACCOUNT_FLAG_XPACK_01))
		OutPacket(SMSG_AUTH_RESPONSE, 11, "\x0C\x30\x78\x00\x00\x00\x00\x00\x00\x00\x01");
	else
		OutPacket(SMSG_AUTH_RESPONSE, 11, "\x0C\x30\x78\x00\x00\x00\x00\x00\x00\x00\x00");

	sAddonMgr.SendAddonInfoPacket(pAuthenticationPacket, static_cast< uint32 >(pAuthenticationPacket->rpos()), mSession);
	mSession->_latency = _latency;

	delete pAuthenticationPacket;
	pAuthenticationPacket = NULL;

	sWorld.AddSession(mSession);
	sWorld.AddGlobalSession(mSession);

	if(mSession->HasGMPermissions())
		sWorld.gmList.insert(mSession);

}
Beispiel #6
0
void QuestLogEntry::Init(Quest* quest, Player* plr, uint32 slot)
{
	ARCEMU_ASSERT(quest != NULL);
	ARCEMU_ASSERT(plr != NULL);

	m_quest = quest;
	m_plr = plr;
	m_slot = slot;

	iscastquest = false;
	isemotequest = false;
	for(uint32 i = 0; i < 4; ++i)
	{
		if(quest->required_spell[i] != 0)
		{
			iscastquest = true;
			if(!plr->HasQuestSpell(quest->required_spell[i]))
				plr->quest_spells.insert(quest->required_spell[i]);
		}
		else if(quest->required_emote[i] != 0)
		{
			isemotequest = true;
		}
		if(quest->required_mob[i] != 0)
		{
			if(!plr->HasQuestMob(quest->required_mob[i]))
				plr->quest_mobs.insert(quest->required_mob[i]);
		}
	}


	// update slot
	plr->SetQuestLogSlot(this, slot);

	mDirty = true;

	memset(m_mobcount, 0, 4 * 4);
	memset(m_explored_areas, 0, 4 * 4);

	if( m_quest->time > 0 )
		expirytime = UNIXTIME + m_quest->time / 1000;
	else
		expirytime = 0;

	if(!plr->GetSession()->m_loggingInPlayer)  //quest script should not be called on login
		CALL_QUESTSCRIPT_EVENT(this, OnQuestStart)(plr, this);
}
Beispiel #7
0
MapMgr* InstanceMgr::_CreateInstance(uint32 mapid, uint32 instanceid)
{
    MapInfo const* inf = sMySQLStore.GetWorldMapInfo(mapid);

    ARCEMU_ASSERT(inf != nullptr && inf->type == INSTANCE_NULL);
    ARCEMU_ASSERT(mapid < NUM_MAPS && m_maps[mapid] != NULL);

    LogNotice("InstanceMgr : Creating continent %s.", m_maps[mapid]->GetMapName().c_str());

    MapMgr* newMap = new MapMgr(m_maps[mapid], mapid, instanceid);

    ARCEMU_ASSERT(newMap != NULL);

    // Scheduling the new map for running
    ThreadPool.ExecuteTask(newMap);
    m_singleMaps[mapid] = newMap;

    return newMap;
}
Beispiel #8
0
MapMgr* InstanceMgr::_CreateInstance(uint32 mapid, uint32 instanceid)
{
	MapInfo* inf = WorldMapInfoStorage.LookupEntry(mapid);

	ARCEMU_ASSERT(inf != NULL && inf->type == INSTANCE_NULL);
	ARCEMU_ASSERT(mapid < NUM_MAPS && m_maps[ mapid ] != NULL);

	Log.Notice("InstanceMgr", "Creating continent %s.", m_maps[mapid]->GetName());

	MapMgr* newMap = new MapMgr(m_maps[mapid], mapid, instanceid);

	ARCEMU_ASSERT(newMap != NULL);

	// Scheduling the new map for running
	ThreadPool.ExecuteTask(newMap);
	m_singleMaps[mapid] = newMap;

	return newMap;
}
Beispiel #9
0
AuctionHouse::AuctionHouse(uint32 ID)
{
    dbc = sAuctionHouseStore.LookupEntry(ID);
    ARCEMU_ASSERT(dbc != NULL);

    cut_percent = dbc->tax / 100.0f;
    deposit_percent = dbc->fee / 100.0f;

    enabled = true;
}
Beispiel #10
0
void Arena::HookOnPlayerDeath(Player* plr)
{
	ARCEMU_ASSERT(plr != NULL);

	if(plr->m_isGmInvisible == true) return;

	if(m_playersAlive.find(plr->GetLowGUID()) != m_playersAlive.end())
	{
		m_playersCount[plr->GetTeam()]--;
		UpdatePlayerCounts();
		m_playersAlive.erase(plr->GetLowGUID());
	}
}
Beispiel #11
0
bool Transporter::RemovePassenger(Player* passenger)
{
    ARCEMU_ASSERT(passenger != nullptr);

    m_passengers.erase(passenger->getGuidLow());
    LOG_DEBUG("Player %s removed from transport %u.", passenger->GetName(), this->GetGameObjectProperties()->entry);

    if (passenger->HasUnitMovementFlag(MOVEFLAG_TRANSPORT))
    {
        passenger->RemoveUnitMovementFlag(MOVEFLAG_TRANSPORT);
    }

    return true;
}
Beispiel #12
0
bool Transporter::AddPassenger(Player* passenger)
{
    ARCEMU_ASSERT(passenger != nullptr);

    m_passengers.insert(passenger->getGuidLow());
    LOG_DEBUG("Player %s boarded transport %u.", passenger->GetName(), this->GetGameObjectProperties()->entry);

    if (!passenger->HasUnitMovementFlag(MOVEFLAG_TRANSPORT))
    {
        passenger->AddUnitMovementFlag(MOVEFLAG_TRANSPORT);
    }

    return true;
}
Beispiel #13
0
void Guild::SetGuildMaster(PlayerInfo* pNewMaster)
{
	GuildMemberMap::iterator itr = m_members.find(pNewMaster);
	ARCEMU_ASSERT(m_ranks[0] != NULL);
	if(itr == m_members.end())
		return;

	itr->second->pRank = m_ranks[0];
	itr->first->guildRank = itr->second->pRank;
	CharacterDatabase.Execute("UPDATE guild_data SET guildRank = 0 WHERE playerid = %u AND guildid = %u", itr->first->guid, m_guildId);
	CharacterDatabase.Execute("UPDATE guilds SET leaderGuid = %u WHERE guildId = %u", itr->first->guid, m_guildId);
	m_guildLeader = itr->first->guid;
	LogGuildEvent(GUILD_EVENT_LEADER_CHANGED, 2, pNewMaster->name, pNewMaster->name);
}
Beispiel #14
0
void Arena::HookOnAreaTrigger(Player* plr, uint32 id)
{
	int32 buffslot = -1;

	ARCEMU_ASSERT(plr != NULL);

	switch(id)
	{
		case 4536:
		case 4538:
		case 4696:
			buffslot = 0;
			break;
		case 4537:
		case 4539:
		case 4697:
			buffslot = 1;
			break;
	}

	if(buffslot >= 0)
	{
		if(m_buffs[buffslot] != NULL && m_buffs[buffslot]->IsInWorld())
		{
			/* apply the buff */
			SpellEntry* sp = dbcSpell.LookupEntryForced(m_buffs[buffslot]->GetInfo()->sound3);
			ARCEMU_ASSERT(sp != NULL);

			Spell* s = sSpellFactoryMgr.NewSpell(plr, sp, true, 0);
			SpellCastTargets targets(plr->GetGUID());
			s->prepare(&targets);

			/* despawn the gameobject (not delete!) */
			m_buffs[buffslot]->Despawn(0, 30*1000 /*BUFF_RESPAWN_TIME*/);
		}
	}
}
Beispiel #15
0
void EventableObject::event_AddEvent(TimedEvent* ptr)
{
    m_lock.Acquire();

    if(m_holder == NULL)
    {
        m_event_Instanceid = event_GetInstanceID();
        m_holder = sEventMgr.GetEventHolder(m_event_Instanceid);

        if(m_holder == NULL)
        {

            ///////////////////////////////////////// this is for me for debugging purposes - dfighter ////////////////////////////
            // ARCEMU_ASSERT( false );
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            // We still couldn't find an eventholder for us so let's run in WorldRunnable
            m_event_Instanceid = WORLD_INSTANCE;
            m_holder = sEventMgr.GetEventHolder(m_event_Instanceid);
        }
    }

    // We still couldn't find an event holder for ourselves :(
    ARCEMU_ASSERT(m_holder != NULL);

    // If we are flagged not to run in WorldRunnable then we won't!
    // This is much better than adding us to the eventholder and removing on an update
    if(m_event_Instanceid == WORLD_INSTANCE && (ptr->eventFlag & EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT))
    {
        delete ptr->cb;
        delete ptr;

        ///////////////////////////////////////// this is for me for debugging purposes - dfighter ////////////////////////////
        // ARCEMU_ASSERT( false );
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        m_lock.Release();
        return;
    }

    ptr->IncRef();
    ptr->instanceId = m_event_Instanceid;
    pair<uint32, TimedEvent*> p(ptr->eventType, ptr);
    m_events.insert(p);
    m_lock.Release();


    /* Add to event manager */
    m_holder->AddEvent(ptr);
}
Beispiel #16
0
void MapMgr::LoadAllCells()
{
	// eek
	MapCell* cellInfo;
	CellSpawns* spawns;

	for(uint32 x = 0 ; x < _sizeX ; x ++)
	{
		for(uint32 y = 0 ; y < _sizeY ; y ++)
		{
			cellInfo = GetCell(x , y);

			if(!cellInfo)
			{
				// Cell doesn't exist, create it.
				// There is no spoon. Err... cell.
				cellInfo = Create(x , y);
				cellInfo->Init(x , y , this);
				LOG_DETAIL("Created cell [%u,%u] on map %u (instance %u)." , x , y , _mapId , m_instanceID);
				cellInfo->SetActivity(true);
				_map->CellGoneActive(x , y);
				ARCEMU_ASSERT(!cellInfo->IsLoaded());

				spawns = _map->GetSpawnsList(x , y);
				if(spawns)
					cellInfo->LoadObjects(spawns);
			}
			else
			{
				// Cell exists, but is inactive
				if(!cellInfo->IsActive())
				{
					LOG_DETAIL("Activated cell [%u,%u] on map %u (instance %u).", x, y, _mapId, m_instanceID);
					_map->CellGoneActive(x , y);
					cellInfo->SetActivity(true);

					if(!cellInfo->IsLoaded())
					{
						//LOG_DETAIL("Loading objects for Cell [%u][%u] on map %u (instance %u)...",
						//	posX, posY, this->_mapId, m_instanceID);
						spawns = _map->GetSpawnsList(x , y);
						if(spawns)
							cellInfo->LoadObjects(spawns);
					}
				}
			}
		}
	}
}
Beispiel #17
0
Creature* MapScriptInterface::SpawnCreature(uint32 Entry, float cX, float cY, float cZ, float cO, bool AddToWorld, bool tmplate, uint32 Misc1, uint32 Misc2, uint32 phase)
{
	CreatureProto* proto = CreatureProtoStorage.LookupEntry(Entry);
	CreatureInfo* info = CreatureNameStorage.LookupEntry(Entry);
	if(proto == NULL || info == NULL)
	{
		return 0;
	}

	CreatureSpawn* sp = new CreatureSpawn;
	sp->entry = Entry;
	uint32 DisplayID = 0;
	uint8 Gender = info->GenerateModelId(&DisplayID);
	sp->displayid = DisplayID;
	sp->form = 0;
	sp->id = 0;
	sp->movetype = 0;
	sp->x = cX;
	sp->y = cY;
	sp->z = cZ;
	sp->o = cO;
	sp->emote_state = 0;
	sp->flags = 0;
	sp->factionid = proto->Faction;
	sp->bytes0 = 0;
	sp->bytes1 = 0;
	sp->bytes2 = 0;
	//sp->respawnNpcLink = 0;
	sp->stand_state = 0;
	sp->death_state = 0;
	sp->channel_target_creature = sp->channel_target_go = sp->channel_spell = 0;
	sp->MountedDisplayID = 0;
	sp->Item1SlotDisplay = 0;
	sp->Item2SlotDisplay = 0;
	sp->Item3SlotDisplay = 0;
	sp->CanFly = 0;
	sp->phase = phase;

	Creature* p = this->mapMgr.CreateCreature(Entry);
	ARCEMU_ASSERT(p != NULL);
	p->Load(sp, (uint32)NULL, NULL);
	p->setGender(Gender);
	p->spawnid = 0;
	p->m_spawn = 0;
	delete sp;
	if(AddToWorld)
		p->PushToWorld(&mapMgr);
	return p;
}
Beispiel #18
0
void AuctionHouse::UpdateDeletionQueue()
{
    removalLock.Acquire();
    Auction* auct;

    std::list<Auction*>::iterator it = removalList.begin();
    for (; it != removalList.end(); ++it)
    {
        auct = *it;
        ARCEMU_ASSERT(auct->Deleted);
        RemoveAuction(auct);
    }

    removalList.clear();
    removalLock.Release();
}
Beispiel #19
0
void Guild::ChangeGuildMaster(PlayerInfo* pNewMaster, WorldSession* pClient)
{
	if(pClient->GetPlayer()->GetLowGUID() != m_guildLeader)
	{
		Guild::SendGuildCommandResult(pClient, GUILD_PROMOTE_S, "", GUILD_PERMISSIONS);
		return;
	}

	m_lock.Acquire();
	GuildRank* newRank = FindHighestRank();
	if(newRank == NULL)
	{
		m_lock.Release();
		return;
	}

	GuildMemberMap::iterator itr = m_members.find(pNewMaster);
	GuildMemberMap::iterator itr2 = m_members.find(pClient->GetPlayer()->getPlayerInfo());
	ARCEMU_ASSERT(m_ranks[0] != NULL);
	if(itr == m_members.end())
	{
		Guild::SendGuildCommandResult(pClient, GUILD_PROMOTE_S, pNewMaster->name, GUILD_PLAYER_NOT_IN_GUILD_S);
		m_lock.Release();
		return;
	}
	if(itr2 == m_members.end())
	{
		// wtf??
		Guild::SendGuildCommandResult(pClient, GUILD_PROMOTE_S, "", GUILD_INTERNAL);
		m_lock.Release();
		return;
	}

	itr->second->pRank = m_ranks[0];
	itr->first->guildRank = itr->second->pRank;
	itr2->second->pRank = newRank;
	itr2->first->guildRank = newRank;
	CharacterDatabase.Execute("UPDATE guild_data SET guildRank = 0 WHERE playerid = %u AND guildid = %u", itr->first->guid, m_guildId);
	CharacterDatabase.Execute("UPDATE guild_data SET guildRank = %u WHERE playerid = %u AND guildid = %u", newRank->iId, itr2->first->guid, m_guildId);
	CharacterDatabase.Execute("UPDATE guilds SET leaderGuid = %u WHERE guildId = %u", itr->first->guid, m_guildId);
	m_guildLeader = itr->first->guid;
	m_lock.Release();


	LogGuildEvent(GUILD_EVENT_LEADER_CHANGED, 2, pClient->GetPlayer()->GetName(), pNewMaster->name);
	//TODO: Figure out the GUILD_LOG_EVENT_LEADER_CHANGED code
}
Beispiel #20
0
MapMgr* InstanceMgr::_CreateInstance(Instance* in)
{
	if(m_maps[ in->m_mapId ] == 0)
		return NULL;

	Log.Notice("InstanceMgr", "Creating saved instance %u (%s)", in->m_instanceId, m_maps[in->m_mapId]->GetName());
	ARCEMU_ASSERT(in->m_mapMgr == NULL);

	// we don't have to check for world map info here, since the instance wouldn't have been saved if it didn't have any.
	in->m_mapMgr = new MapMgr(m_maps[in->m_mapId], in->m_mapId, in->m_instanceId);
	in->m_mapMgr->pInstance = in;
	in->m_mapMgr->iInstanceMode = in->m_difficulty;
	in->m_mapMgr->InactiveMoveTime = 60 + UNIXTIME;

	ThreadPool.ExecuteTask(in->m_mapMgr);
	return in->m_mapMgr;
}
Beispiel #21
0
void Guild::AddGuildLogEntry(uint8 iEvent, uint8 iParamCount, ...)
{
	if(!m_commandLogging)
		return;

	va_list ap;
	uint32 i;
	GuildLogEvent* ev;

	va_start(ap, iParamCount);
	ARCEMU_ASSERT(iParamCount <= 3);

	ev = new GuildLogEvent;
	ev->iLogId = GenerateGuildLogEventId();
	ev->iEvent = iEvent;
	ev->iTimeStamp = (uint32)UNIXTIME;

	for(i = 0; i < iParamCount; ++i)
		ev->iEventData[i] = va_arg(ap, uint32);

	for(; i < 3; ++i)
		ev->iEventData[i] = 0;

	CharacterDatabase.Execute("INSERT INTO guild_logs VALUES(%u, %u, %u, %u, %u, %u, %u)",
	                          ev->iLogId, m_guildId, ev->iTimeStamp, ev->iEvent, ev->iEventData[0], ev->iEventData[1], ev->iEventData[2]);

	m_lock.Acquire();
	if(m_log.size() >= 25)
	{
		// limit it to 250 events.
		// delete the first (oldest) event.
		CharacterDatabase.Execute("DELETE FROM guild_logs WHERE log_id = %u AND guildid = %u", (*(m_log.begin()))->iLogId, m_guildId);
		delete *(m_log.begin());
		m_log.pop_front();
	}

	m_log.push_back(ev);
	m_lock.Release();
}
Beispiel #22
0
void Summon::Load(CreatureProto* proto, Unit* owner, LocationVector & position, uint32 spellid, int32 summonslot)
{
    ARCEMU_ASSERT(owner != NULL);

    Creature::Load(proto, owner->GetMapMgr(), position.x, position.y, position.z, position.o);

    SetFaction(owner->GetFaction());
    Phase(PHASE_SET, owner->GetPhase());
    SetZoneId(owner->GetZoneId());
    SetCreatedBySpell(spellid);
    this->summonslot = summonslot;

    if (owner->IsPvPFlagged())
        SetPvPFlag();
    else
        RemovePvPFlag();

    if (owner->IsFFAPvPFlagged())
        SetFFAPvPFlag();
    else
        RemoveFFAPvPFlag();

    if (owner->IsSanctuaryFlagged())
        SetSanctuaryFlag();
    else
        RemoveSanctuaryFlag();

    SetCreatedByGUID(owner->GetGUID());

    if (owner->GetSummonedByGUID() == 0)
        SetSummonedByGUID(owner->GetGUID());
    else
        SetSummonedByGUID(owner->GetSummonedByGUID());

    this->owner = owner;

    if (owner->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE))
        SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
}
Beispiel #23
0
void Container::Create(uint32 itemid, Player* owner)
{

    m_itemProto = ItemPrototypeStorage.LookupEntry(itemid);
    ARCEMU_ASSERT(m_itemProto != NULL);

    SetEntry(itemid);

    ///\todo this shouldn't get NULL form containers in mail fix me
    if (owner != NULL)
    {
        SetOwnerGUID(0);
        SetContainerGUID(owner->GetGUID());
    }
    SetStackCount(1);
    SetNumSlots(m_itemProto->ContainerSlots);

    m_Slot = new Item*[m_itemProto->ContainerSlots];
    memset(m_Slot, 0, sizeof(Item*) * (m_itemProto->ContainerSlots));

    m_owner = owner;
}
Beispiel #24
0
void GameEventMgr::GameEventMgrThread::CleanupEntities()
{
    // DO NOT USE THIS FUNCTION UNLESS YOU KNOW WHAT YOU ARE DOING
    ARCEMU_ASSERT(FALSE);
    Log.Success("GameEventMgr", "Cleaning up entity remnants");
    // Better solution: don't have creatures save here in the first place
    for (auto gameEventPair : sGameEventMgr.mGameEvents)
    {
        auto gameEvent = gameEventPair.second;
        for (auto npc : gameEvent->npc_data)
        {
            const char* cleanCreaturesQuery = "DELETE FROM creature_spawns WHERE entry=%u";
            WorldDatabase.Execute(cleanCreaturesQuery, npc.entry);
        }
        for (auto gameobject : gameEvent->gameobject_data)
        {
            const char* cleanGameObjectsQuery = "DELETE FROM gameobject_spawns WHERE entry=%u";
            WorldDatabase.Execute(cleanGameObjectsQuery, gameobject.entry);
        }
    }
    Log.Success("GameEventMgr", "Entity remnants cleaned up, starting main thread");
}
Beispiel #25
0
void CBattlegroundManager::RemovePlayerFromQueues(Player* plr)
{
    m_queueLock.Acquire();

    ARCEMU_ASSERT(plr->m_bgQueueType < BATTLEGROUND_NUM_TYPES);

    sEventMgr.RemoveEvents(plr, EVENT_BATTLEGROUND_QUEUE_UPDATE);

    uint32 lgroup = GetLevelGrouping(plr->getLevel());
    list<uint32>::iterator itr;

    itr = m_queuedPlayers[plr->m_bgQueueType][lgroup].begin();
    while (itr != m_queuedPlayers[plr->m_bgQueueType][lgroup].end())
    {
        if ((*itr) == plr->GetLowGUID())
        {
            Log.Debug("BattlegroundManager", "Removing player %u from queue instance %u type %u", plr->GetLowGUID(), plr->m_bgQueueInstanceId, plr->m_bgQueueType);
            m_queuedPlayers[plr->m_bgQueueType][lgroup].erase(itr);
            break;
        }

        ++itr;
    }

    plr->m_bgIsQueued = false;
    plr->m_bgTeam = plr->GetTeam();
    plr->m_pendingBattleground = NULL;
    SendBattlefieldStatus(plr, BGSTATUS_NOFLAGS, 0, 0, 0, 0, 0);
    m_queueLock.Release();

    Group* group;
    group = plr->GetGroup();
    if (group)  //if da n****s in a group, boot dis bitch ass' group outa da q
    {
        Log.Debug("BattlegroundManager", "Player %u removed whilst in a group. Removing players group %u from queue", plr->GetLowGUID(), group->GetID());
        RemoveGroupFromQueues(group);
    }
}
Beispiel #26
0
void QuestLogEntry::SaveToDB(QueryBuffer* buf)
{
	ARCEMU_ASSERT(m_slot != -1);
	if(!mDirty)
		return;

	std::stringstream ss;

	ss << "DELETE FROM questlog WHERE player_guid = ";
	ss << m_plr->GetLowGUID();
	ss << " AND quest_id = ";
	ss << m_quest->id;
	ss << ";";

	if(buf == NULL)
		CharacterDatabase.Execute(ss.str().c_str());
	else
		buf->AddQueryStr(ss.str());

	ss.rdbuf()->str("");

	ss << "INSERT INTO questlog VALUES(";
	ss << m_plr->GetLowGUID() << "," << m_quest->id << "," << m_slot << "," << expirytime;
	for(int i = 0; i < 4; ++i)
		ss << "," << m_explored_areas[i];

	for(int i = 0; i < 4; ++i)
		ss << "," << m_mobcount[i];

	ss << "," << uint32(completed);

	ss << ")";

	if(buf == NULL)
		CharacterDatabase.Execute(ss.str().c_str());
	else
		buf->AddQueryStr(ss.str());
}
Beispiel #27
0
Creature* MapScriptInterface::SpawnCreature(CreatureSpawn* sp, bool AddToWorld)
{
	if(!sp)
		return NULL;

	CreatureProto* proto = CreatureProtoStorage.LookupEntry(sp->entry);
	CreatureInfo* info = CreatureNameStorage.LookupEntry(sp->entry);
	if(proto == NULL || info == NULL)
	{
		return 0;
	}

	uint8 Gender = info->GenerateModelId(&sp->displayid);
	Creature* p = this->mapMgr.CreateCreature(sp->entry);
	ARCEMU_ASSERT(p != NULL);
	p->Load(sp, (uint32)NULL, NULL);
	p->setGender(Gender);
	p->spawnid = 0;
	p->m_spawn = 0;
	if(AddToWorld)
		p->PushToWorld(&mapMgr);
	return p;
}
Beispiel #28
0
bool Guild::LoadFromDB(Field* f)
{
	m_guildId = f[0].GetUInt32();
	m_guildName = strdup(f[1].GetString());
	m_guildLeader = f[2].GetUInt32();
	m_emblemStyle = f[3].GetUInt32();
	m_emblemColor = f[4].GetUInt32();
	m_borderStyle = f[5].GetUInt32();
	m_borderColor = f[6].GetUInt32();
	m_backgroundColor = f[7].GetUInt32();
	m_guildInfo = strlen(f[8].GetString()) ? strdup(f[8].GetString()) : NULL;
	m_motd = strlen(f[9].GetString()) ? strdup(f[9].GetString()) : NULL;
	m_creationTimeStamp = f[10].GetUInt32();
	m_bankBalance = f[11].GetUInt64();

	// load ranks
	uint32 j;
	QueryResult* result = CharacterDatabase.Query("SELECT * FROM guild_ranks WHERE guildId = %u ORDER BY rankId ASC", m_guildId);
	if(result == NULL)
		return false;

	uint32 sid = 0;

	do
	{
		GuildRank* r = new GuildRank;
		Field* f2 = result->Fetch();
		r->iId = f2[1].GetUInt32();
		if(r->iId != sid)
		{
			Log.Notice("Guild", "Renaming rank %u of guild %s to %u.", r->iId, m_guildName, sid);
			CharacterDatabase.Execute("UPDATE guild_ranks SET rankId = %u WHERE guildId = %u AND rankName = \'%s\'", r->iId,
			                          m_guildId, CharacterDatabase.EscapeString(string(f2[2].GetString())).c_str());

			r->iId = sid;
		}
		sid++;
		r->szRankName = strdup(f2[2].GetString());
		r->iRights = f2[3].GetUInt32();
		r->iGoldLimitPerDay = f2[4].GetUInt32();

		for(j = 0; j < MAX_GUILD_BANK_TABS; ++j)
		{
			r->iTabPermissions[j].iFlags = f2[5 + (j * 2)].GetUInt32();
			r->iTabPermissions[j].iStacksPerDay = f2[6 + (j * 2)].GetUInt32();
		}

		//m_ranks.push_back(r);
		ARCEMU_ASSERT(m_ranks[r->iId] == NULL);
		m_ranks[r->iId] = r;

	}
	while(result->NextRow());
	delete result;

	// load members
	result = CharacterDatabase.Query("SELECT * FROM guild_data WHERE guildid = %u", m_guildId);
	if(result == NULL)
		return false;

	do
	{
		Field* f3 = result->Fetch();
		GuildMember* gm = new GuildMember;
		gm->pPlayer = objmgr.GetPlayerInfo(f3[1].GetUInt32());
		if(gm->pPlayer == NULL)
		{
			delete gm;
			continue;
		}

		if(f3[2].GetUInt32() >= MAX_GUILD_RANKS || m_ranks[f3[2].GetUInt32()] == NULL)
		{
			delete gm;
			continue;
		}

		gm->pRank = m_ranks[f3[2].GetUInt32()];
		if(gm->pRank == NULL)
			gm->pRank = FindLowestRank();
		gm->pPlayer->guild = this;
		gm->pPlayer->guildRank = gm->pRank;
		gm->pPlayer->guildMember = gm;

		if(strlen(f3[3].GetString()))
			gm->szPublicNote = strdup(f3[3].GetString());
		else
			gm->szPublicNote = NULL;

		if(strlen(f3[4].GetString()))
			gm->szOfficerNote = strdup(f3[4].GetString());
		else
			gm->szOfficerNote = NULL;

		gm->uLastWithdrawReset = f3[5].GetUInt32();
		gm->uWithdrawlsSinceLastReset = f3[6].GetUInt32();
		for(j = 0; j < MAX_GUILD_BANK_TABS; ++j)
		{
			gm->uLastItemWithdrawReset[j] = f3[7 + (j * 2)].GetUInt32();
			gm->uItemWithdrawlsSinceLastReset[j] = f3[8 + (j * 2)].GetUInt32();
		}

		m_members.insert(make_pair(gm->pPlayer, gm));

	}
	while(result->NextRow());
	delete result;

	result = CharacterDatabase.Query("SELECT MAX(log_id) FROM guild_logs WHERE guildid = %u", m_guildId);
	m_hiLogId = 1;
	if(result != NULL)
	{
		m_hiLogId = result->Fetch()[0].GetUInt32() + 1;
		delete result;
	}

	result = CharacterDatabase.Query("SELECT MAX(log_id) FROM guild_banklogs WHERE guildid = %u", m_guildId);
	if(result)
	{
		if((result->Fetch()[0].GetUInt32() + 1) > m_hiLogId)
			m_hiLogId = result->Fetch()[0].GetUInt32() + 1;
		delete result;
	}

	// load log
	result = CharacterDatabase.Query("SELECT * FROM guild_logs WHERE guildid = %u ORDER BY timestamp ASC", m_guildId);
	if(result)
	{
		do
		{
			GuildLogEvent* li = new GuildLogEvent;
			li->iLogId = result->Fetch()[0].GetUInt32();
			li->iEvent = static_cast<uint8>(result->Fetch()[3].GetUInt32());
			li->iTimeStamp = result->Fetch()[2].GetUInt32();
			li->iEventData[0] = result->Fetch()[4].GetUInt32();
			li->iEventData[1] = result->Fetch()[5].GetUInt32();
			li->iEventData[2] = result->Fetch()[6].GetUInt32();
			m_log.push_back(li);
		}
		while(result->NextRow());
		delete result;
	}

	result = CharacterDatabase.Query("SELECT * FROM guild_banktabs WHERE guildId = %u ORDER BY tabId ASC", m_guildId);
	sid = 0;
	if(result)
	{
		do
		{
			if((sid++) != result->Fetch()[1].GetUInt32())
			{
				LOG_ERROR("Guild bank tabs are out of order!");
#ifdef WIN32
				TerminateProcess(GetCurrentProcess(), 0);
				return false;
#else
				exit(0);
#endif
			}

			QueryResult* res2 = CharacterDatabase.Query("SELECT * FROM guild_bankitems WHERE guildId = %u AND tabId = %u", m_guildId, result->Fetch()[1].GetUInt32());
			GuildBankTab* pTab = new GuildBankTab;
			pTab->iTabId = (uint8)result->Fetch()[1].GetUInt32();
			pTab->szTabName = (strlen(result->Fetch()[2].GetString()) > 0) ? strdup(result->Fetch()[2].GetString()) : NULL;
			pTab->szTabIcon = (strlen(result->Fetch()[3].GetString()) > 0) ? strdup(result->Fetch()[3].GetString()) : NULL;
			pTab->szTabInfo = (strlen(result->Fetch()[4].GetString()) > 0) ? strdup(result->Fetch()[4].GetString()) : NULL;

			memset(pTab->pSlots, 0, sizeof(Item*) * MAX_GUILD_BANK_SLOTS);

			if(res2)
			{
				do
				{
					Item* pItem = objmgr.LoadItem(res2->Fetch()[3].GetUInt32());
					if(pItem == NULL)
					{
						CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE itemGuid = %u AND guildId = %u AND tabId = %u", res2->Fetch()[3].GetUInt32(), m_guildId, (uint32)pTab->iTabId);
						continue;
					}

					pTab->pSlots[res2->Fetch()[2].GetUInt32()] = pItem;

				}
				while(res2->NextRow());
				delete res2;
			}

			res2 = CharacterDatabase.Query("SELECT * FROM guild_banklogs WHERE guildid = %u AND tabid = %u ORDER BY timestamp ASC", m_guildId, result->Fetch()[1].GetUInt32());
			if(res2 != NULL)
			{
				do
				{
					GuildBankEvent* ev = new GuildBankEvent;
					ev->iLogId = res2->Fetch()[0].GetUInt32();
					ev->iAction = res2->Fetch()[3].GetUInt8();
					ev->uPlayer = res2->Fetch()[4].GetUInt32();
					ev->uEntry = res2->Fetch()[5].GetUInt32();
					ev->iStack = res2->Fetch()[6].GetUInt8();
					ev->uTimeStamp = res2->Fetch()[7].GetUInt32();

					pTab->lLog.push_back(ev);

				}
				while(res2->NextRow());
				delete res2;
			}

			m_bankTabs.push_back(pTab);

		}
		while(result->NextRow());
		delete result;
	}

	result = CharacterDatabase.Query("SELECT * FROM guild_banklogs WHERE guildid = %u AND tabid = 6 ORDER BY timestamp ASC", m_guildId);
	if(result != NULL)
	{
		do
		{
			GuildBankEvent* ev = new GuildBankEvent;
			ev->iLogId = result->Fetch()[0].GetUInt32();
			ev->iAction = result->Fetch()[3].GetUInt8();
			ev->uPlayer = result->Fetch()[4].GetUInt32();
			ev->uEntry = result->Fetch()[5].GetUInt32();
			ev->iStack = result->Fetch()[6].GetUInt8();
			ev->uTimeStamp = result->Fetch()[7].GetUInt32();

			m_moneyLog.push_back(ev);

		}
		while(result->NextRow());
		delete result;
	}

	Log.Debug("Guild", "Loaded guild %s, %u members.", m_guildName, m_members.size());
	return true;
}
Beispiel #29
0
void WorldSocket::InformationRetreiveCallback(WorldPacket & recvData, uint32 requestid)
{
	if(requestid != mRequestID)
		return;

	uint32 error;
	recvData >> error;

	if(error != 0 || pAuthenticationPacket == NULL)
	{
		// something happened wrong @ the logon server
		OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
		return;
	}

	// Extract account information from the packet.
	string AccountName;
	const string* ForcedPermissions;
	uint32 AccountID;
	string GMFlags;
	uint8 AccountFlags;
	string lang = "enUS";
	uint32 i;

	recvData >> AccountID >> AccountName >> GMFlags >> AccountFlags;
	ForcedPermissions = sLogonCommHandler.GetForcedPermissions(AccountName);
	if(ForcedPermissions != NULL)
		GMFlags.assign(ForcedPermissions->c_str());

	LOG_DEBUG(" >> got information packet from logon: `%s` ID %u (request %u)", AccountName.c_str(), AccountID, mRequestID);

	mRequestID = 0;

	// Pull the sessionkey we generated during the logon - client handshake
	uint8 K[40];
	recvData.read(K, 40);

	_crypt.Init(K);

	//checking if player is already connected
	//disconnect current player and login this one(blizzlike)

	if(recvData.rpos() != recvData.wpos())
		recvData.read((uint8*)lang.data(), 4);

	WorldSession* session = sWorld.FindSession(AccountID);
	if(session)
	{
		// AUTH_FAILED = 0x0D
		session->Disconnect();

		// clear the logout timer so he times out straight away
		session->SetLogoutTimer(1);

		// we must send authentication failed here.
		// the stupid newb can relog his client.
		// otherwise accounts dupe up and disasters happen.
		OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
		return;
	}

	Sha1Hash sha;

	uint8 digest[20];
	pAuthenticationPacket->read(digest, 20);

	uint32 t = 0;
	if(m_fullAccountName == NULL)				// should never happen !
		sha.UpdateData(AccountName);
	else
	{
		sha.UpdateData(*m_fullAccountName);

		// this is unused now. we may as well free up the memory.
		delete m_fullAccountName;
		m_fullAccountName = NULL;
	}

	sha.UpdateData((uint8*)&t, 4);
	sha.UpdateData((uint8*)&mClientSeed, 4);
	sha.UpdateData((uint8*)&mSeed, 4);
	sha.UpdateData((uint8*)&K, 40);
	sha.Finalize();

	if(memcmp(sha.GetDigest(), digest, 20))
	{
		// AUTH_UNKNOWN_ACCOUNT = 21
		OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
		return;
	}

	// Allocate session
	WorldSession* pSession = new WorldSession(AccountID, AccountName, this);
	mSession = pSession;
	ARCEMU_ASSERT(mSession != NULL);
	// aquire delete mutex
	pSession->deleteMutex.Acquire();

	// Set session properties
	pSession->SetClientBuild(mClientBuild);
	pSession->LoadSecurity(GMFlags);
	pSession->SetAccountFlags(AccountFlags);
	pSession->m_lastPing = (uint32)UNIXTIME;
	pSession->language = sLocalizationMgr.GetLanguageId(lang);

	if(recvData.rpos() != recvData.wpos())
		recvData >> pSession->m_muted;

	for(i = 0; i < 8; ++i)
		pSession->SetAccountData(i, NULL, true, 0);

	if(sWorld.m_useAccountData)
	{
		QueryResult* pResult = CharacterDatabase.Query("SELECT * FROM account_data WHERE acct = %u", AccountID);
		if(pResult == NULL)
			CharacterDatabase.Execute("INSERT INTO account_data VALUES(%u, '', '', '', '', '', '', '', '', '')", AccountID);
		else
		{
			size_t len;
			const char* data;
			char* d;
			for(i = 0; i < 8; ++i)
			{
				data = pResult->Fetch()[1 + i].GetString();
				len = data ? strlen(data) : 0;
				if(len > 1)
				{
					d = new char[len + 1];
					memcpy(d, data, len + 1);
					pSession->SetAccountData(i, d, true, (uint32)len);
				}
			}

			delete pResult;
		}
	}

	Log.Debug("Auth", "%s from %s:%u [%ums]", AccountName.c_str(), GetRemoteIP().c_str(), GetRemotePort(), _latency);
#ifdef SESSION_CAP
	if(sWorld.GetSessionCount() >= SESSION_CAP)
	{
		OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
		Disconnect();
		return;
	}
#endif

	// Check for queue.
	uint32 playerLimit = sWorld.GetPlayerLimit();
	if((sWorld.GetSessionCount() < playerLimit) || pSession->HasGMPermissions())
	{
		Authenticate();
	}
	else if(playerLimit > 0)
	{
		// Queued, sucker.
		uint32 Position = sWorld.AddQueuedSocket(this);
		mQueued = true;
		Log.Debug("Queue", "%s added to queue in position %u", AccountName.c_str(), Position);

		// Send packet so we know what we're doing
		UpdateQueuePosition(Position);
	}
	else
	{
		OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0E"); // AUTH_REJECT = 14
		Disconnect();
	}

	// release delete mutex
	pSession->deleteMutex.Release();
}
Beispiel #30
0
void Spell::FillTargetMap(uint32 i)
{
	//Spell::prepare() has already a m_caster->IsInWorld() check so if now the caster is no more in world something bad happened.
	ARCEMU_ASSERT(m_caster->IsInWorld());

	uint32 TargetType = 0;
	TargetType |= GetTargetType(m_spellInfo->EffectImplicitTargetA[i], i);

	//never get info from B if it is 0 :P
	if(m_spellInfo->EffectImplicitTargetB[i] != 0)
		TargetType |= GetTargetType(m_spellInfo->EffectImplicitTargetB[i], i);

	if(TargetType & SPELL_TARGET_NOT_IMPLEMENTED)
		return;
	if(TargetType & SPELL_TARGET_NO_OBJECT)  //summon spells that appear infront of caster
	{
		HandleTargetNoObject();
		return;
	}


	//always add this guy :P
	if(!(TargetType & (SPELL_TARGET_AREA | SPELL_TARGET_AREA_SELF | SPELL_TARGET_AREA_CURTARGET | SPELL_TARGET_AREA_CONE | SPELL_TARGET_OBJECT_SELF | SPELL_TARGET_OBJECT_PETOWNER)))
	{
		Object* target = m_caster->GetMapMgr()->_GetObject(m_targets.m_unitTarget);
		AddTarget(i, TargetType, target);
	}

	if(TargetType & SPELL_TARGET_OBJECT_SELF)
		AddTarget(i, TargetType, m_caster);
	if(TargetType & (SPELL_TARGET_AREA | SPELL_TARGET_AREA_SELF))  //targetted aoe
		AddAOETargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets);
	//TODO: arcemu, doesn't support summon slots?
	/*if (TargetType & SPELL_TARGET_OBJECT_CURTOTEMS && u_caster != NULL)
		for (uint32 i=1; i<5; ++i) //totem slots are 1, 2, 3, 4
			AddTarget(i, TargetType, u_caster->m_summonslot[i]);*/
	if(TargetType & SPELL_TARGET_OBJECT_CURPET && p_caster != NULL)
		AddTarget(i, TargetType, p_caster->GetSummon());
	if(TargetType & SPELL_TARGET_OBJECT_PETOWNER)
	{
		uint64 guid = m_targets.m_unitTarget;
		if(GET_TYPE_FROM_GUID(guid) == HIGHGUID_TYPE_PET)
		{
			Pet* p = m_caster->GetMapMgr()->GetPet(GET_LOWGUID_PART(guid));

			if(p != NULL)
				AddTarget(i, TargetType, p->GetPetOwner());
		}
	}
	//targets party, not raid
	if((TargetType & SPELL_TARGET_AREA_PARTY) && !(TargetType & SPELL_TARGET_AREA_RAID))
	{
		if(p_caster == NULL && !m_caster->IsPet() && (!m_caster->IsCreature() || !m_caster->IsTotem()))
			AddAOETargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //npcs
		else
			AddPartyTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //players/pets/totems
	}
	if(TargetType & SPELL_TARGET_AREA_RAID)
	{
		if(p_caster == NULL && !m_caster->IsPet() && (!m_caster->IsCreature() || !m_caster->IsTotem()))
			AddAOETargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //npcs
		else
			AddRaidTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets, (TargetType & SPELL_TARGET_AREA_PARTY) ? true : false); //players/pets/totems
	}
	if(TargetType & SPELL_TARGET_AREA_CHAIN)
		AddChainTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets);
	//target cone
	if(TargetType & SPELL_TARGET_AREA_CONE)
		AddConeTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets);

	if(TargetType & SPELL_TARGET_OBJECT_SCRIPTED)
		AddScriptedOrSpellFocusTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets);
}