OP_STATUS PageBasedAutocompleteItem::UpdateRank(const OpStringC& match_text)
{
	m_rank = 0;
	// title match
	OpString title;
	RETURN_IF_ERROR(GetTitle(title));
	if (m_search_type == PAGE_CONTENT)
		m_rank += CalculateRank(match_text, title, " ", RANK_PAGE_TITLE_FACTOR / 2);
	else
		m_rank += CalculateRank(match_text, title, " ", RANK_PAGE_TITLE_FACTOR);

	// url address match
	OpString address;
	RETURN_IF_ERROR(GetStrippedAddress(address));
	m_rank += CalculateRank(match_text, address, "/", RANK_PAGE_URL_FACTOR);

	if (m_search_type == BOOKMARK)
	{
		m_rank = m_rank * 2; // bookmark bonus;

		if (m_bookmark)
			m_rank += CalculateRank(match_text, m_bookmark->GetName(), " ", RANK_BOOKMARK_TITLE_FACTOR);

		// for bookmarks display and go to url address might be not the same thing, which is awesome;)
		OpString display_addr;
		if(HasDisplayAddress() && OpStatus::IsSuccess(GetDisplayAddress(display_addr)))
		{
			OpString domain;
			unsigned domain_offset = 0;
			RETURN_IF_ERROR(StringUtils::FindDomain(display_addr, domain, domain_offset));

			OpString cut_address;
			RETURN_IF_ERROR(cut_address.Set(display_addr.SubString(domain_offset).CStr()));
			m_rank += CalculateRank(match_text, cut_address, "/", RANK_PAGE_URL_FACTOR);
		}

		OpAutoVector<OpString> nick_urls;
		if (address.HasContent() && !uni_strpbrk(address.CStr(), UNI_L(".:/?\\")))
			g_hotlist_manager->ResolveNickname(address, nick_urls);

		// Check if it's a bookmark nickname
		if (nick_urls.GetCount() >= 1)
		{
			// address might have nick value, in case we deal with nicknamed bookmark
			if (address == match_text)
				m_rank += RANK_BOOKMARK_NICKNAME_FACTOR;
			else
				m_rank += CalculateRank(match_text, address, " ", RANK_PAGE_URL_FACTOR) * 2;
		}
	}

	// time ranking
	time_t two_months_earlier = g_timecache->CurrentTime() - 60*24*60*60;
	time_t access_time = GetAccessed();
	m_rank += max(RANK_TIME_FACTOR * (access_time - two_months_earlier) / (60*24*60*60) , RANK_TIME_MAX_DOWNGRADE);

	return OpStatus::OK;
}
예제 #2
0
파일: HonorMgr.cpp 프로젝트: Maduse/server
void HonorMgr::Update()
{
    if (!m_owner)
        return;

    uint32 todayHK = 0;
    uint32 todayDK = 0;
    uint32 yesterdayKills = 0;
    uint32 thisWeekKills = 0;
    float yesterdayCP = 0.0f;
    float thisWeekCP = 0.0f;

    uint32 today = sWorld.GetGameDay();
    uint32 yesterday = today - 1;
    uint32 thisWeekBegin = sHonorMaintenancer.GetWeekBeginDay();

    m_totalDK = m_storedDK;
    m_totalHK = m_storedHK;

    for (auto& itr : m_honorCP)
    {
        if (itr.type == HONORABLE)
        {
            if (itr.date == today)
                ++todayHK;

            if (itr.date == yesterday)
                ++yesterdayKills;

            if (itr.date >= thisWeekBegin)
            {
                ++thisWeekKills;
                ++m_totalHK;
            }
        }

        if (itr.type != DISHONORABLE)
        {
            if (itr.date == yesterday)
                yesterdayCP += itr.cp;

            if (itr.date >= thisWeekBegin)
                thisWeekCP += itr.cp;
        }

        if (itr.type == DISHONORABLE)
        {
            if (itr.date == today)
                ++todayDK;
            
            ++m_totalDK;
        }
    }

    m_rank = CalculateRank(m_rankPoints, m_totalHK);
    if (m_rank.visualRank > 0 && (m_rank.visualRank > m_highestRank.visualRank))
        SetHighestRank(m_rank);

    // HIGHEST RANK
    m_owner->SetByteValue(PLAYER_FIELD_BYTES, 3, m_highestRank.rank);
    // RANK (Patent)
    m_owner->SetByteValue(PLAYER_BYTES_3, 3, m_rank.rank);
    
    uint32 honorBar = uint32(m_rankPoints >= 0.0f ? m_rankPoints : -1 * m_rankPoints);
    honorBar = uint8(((honorBar - m_rank.minRP) / (m_rank.maxRP - m_rank.minRP)) * (m_rank.positive ? 255 : -255));
    
    // PLAYER_FIELD_HONOR_BAR
    m_owner->SetUInt32Value(PLAYER_FIELD_BYTES2, honorBar);

    // TODAY
    m_owner->SetUInt16Value(PLAYER_FIELD_SESSION_KILLS, 0, todayHK);
    m_owner->SetUInt16Value(PLAYER_FIELD_SESSION_KILLS, 1, todayDK);

    // YESTERDAY
    m_owner->SetUInt32Value(PLAYER_FIELD_YESTERDAY_KILLS, yesterdayKills);
    m_owner->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, uint32(yesterdayCP > 0.0f ? yesterdayCP : 0.0f));

    // THIS WEEK
    m_owner->SetUInt32Value(PLAYER_FIELD_THIS_WEEK_KILLS, thisWeekKills);
    m_owner->SetUInt32Value(PLAYER_FIELD_THIS_WEEK_CONTRIBUTION, uint32(thisWeekCP > 0.0f ? thisWeekCP : 0.0f));

    // LAST WEEK
    m_owner->SetUInt32Value(PLAYER_FIELD_LAST_WEEK_KILLS, m_lastWeekHK);
    m_owner->SetUInt32Value(PLAYER_FIELD_LAST_WEEK_CONTRIBUTION, uint32(m_lastWeekCP > 0.0f ? m_lastWeekCP : 0.0f));
    m_owner->SetUInt32Value(PLAYER_FIELD_LAST_WEEK_RANK, m_standing);

    // LIFE TIME
    m_owner->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, m_totalHK);
    m_owner->SetUInt32Value(PLAYER_FIELD_LIFETIME_DISHONORABLE_KILLS, m_totalDK);
}