예제 #1
0
void GameEventMgr::LoadEventsProc(QueryResultVector & results)
{
	// store all loaded events

	// we won't continue if we don't have any event
	if( results.size() != 1 || results[0].result == NULL )
	{
		Log.Warning("GameEvent","There are no events");
		return;
	}

	// UNXITIME is UTC, but we want to think only in localtime
	uint32 current_time = mktime(&g_localTime);

	QueryResult *qry = results[0].result;
	do 
	{
		Field * f = qry->Fetch();
		uint32 event_id = f[0].GetUInt32();
		EventInfo * ev = new EventInfo();
		ev->start_time = f[1].GetUInt32();
		ev->length = f[2].GetUInt32();
		ev->occurence = f[3].GetUInt32();
		ev->name = strdup(f[4].GetString());
		ev->active = false;

		// set the end_time...
		ev->end_time = ev->start_time + ev->length;

		// calculate next start_time if it's needed
		if( ev->end_time < current_time )
		{
			// if it's non-repeatable event, check if it already happened so we don't need to do anything with it
			if( ev->occurence == 0 )
			{
				delete ev;
				continue;
			}

			// easiest way?
			uint32 tdiff = (current_time - ev->end_time) / ev->occurence;
			ev->start_time += (tdiff + 1) * ev->occurence;

			// set the end_time again
			ev->end_time = ev->start_time + ev->length;

			// save it to the database
			WorldDatabase.Execute("UPDATE game_event SET start_time = '%u' WHERE event_id = '%u';", ev->start_time, event_id);
		}

		// store them
		m_GameEventMap.insert( make_pair(event_id, ev) );

	} while( qry->NextRow() );

	Log.Success("GameEvent","%u events loaded", m_GameEventMap.size());
}
예제 #2
0
void WorldSession::LoadPlayerFromDBProc(QueryResultVector & results)
{
    if (results.size() < 1)
    {
        uint8 respons = E_CHAR_LOGIN_NO_CHARACTER;
        OutPacket(SMSG_CHARACTER_LOGIN_FAILED, 1, &respons);
        return;
    }

    QueryResult* result = results[0].result;
    if (!result)
    {
        Log.Error("WorldSession::LoadPlayerFromDBProc", "Player login query failed!");
        uint8 respons = E_CHAR_LOGIN_NO_CHARACTER;
        OutPacket(SMSG_CHARACTER_LOGIN_FAILED, 1, &respons);
        return;
    }

    Field* fields = result->Fetch();

    uint64 playerGuid = fields[0].GetUInt64();
    uint8 _class = fields[1].GetUInt8();

    Player* plr = NULL;

    switch (_class)
    {
    case WARRIOR:
        plr = new Warrior(playerGuid);
        break;
    case PALADIN:
        plr = new Paladin(playerGuid);
        break;
    case HUNTER:
        plr = new Hunter(playerGuid);
        break;
    case ROGUE:
        plr = new Rogue(playerGuid);
        break;
    case PRIEST:
        plr = new Priest(playerGuid);
        break;
    case DEATHKNIGHT:
        plr = new DeathKnight(playerGuid);
        break;
    case SHAMAN:
        plr = new Shaman(playerGuid);
        break;
    case MAGE:
        plr = new Mage(playerGuid);
        break;
    case WARLOCK:
        plr = new Warlock(playerGuid);
        break;
    case DRUID:
        plr = new Druid(playerGuid);
        break;
    }

    if (plr == NULL)
    {
        Log.Error("WorldSession::LoadPlayerFromDBProc", "Class %u unknown!", _class);
        uint8 respons = E_CHAR_LOGIN_NO_CHARACTER;
        OutPacket(SMSG_CHARACTER_LOGIN_FAILED, 1, &respons);
        return;
    }

    plr->SetSession(this);

    m_bIsWLevelSet = false;

    Log.Debug("WorldSession", "Async loading player %u", (uint32)playerGuid);
    m_loggingInPlayer = plr;
    plr->LoadFromDB((uint32)playerGuid);
}