Пример #1
0
void
LadderReferencedObject::activate(const LadderKey& ladderKey_) const
{
	if (referenceType == referenceTypeAccount)
	{
		if (ladderKey_.getLadderSort()==ladder_sort_highestrated)
		{

			t_clienttag clienttag = ladderKey_.getClienttag();
			t_ladder_id ladderId = ladderKey_.getLadderId();
  			char const * timestr;
			t_bnettime bt;

			account_set_ladder_active_wins(account,clienttag,ladderId,
					account_get_ladder_wins(account,clienttag,ladderId));
			account_set_ladder_active_losses(account,clienttag,ladderId,
					account_get_ladder_losses(account,clienttag,ladderId));
			account_set_ladder_active_draws(account,clienttag,ladderId,
					account_get_ladder_draws(account,clienttag,ladderId));
			account_set_ladder_active_disconnects(account,clienttag,ladderId,
					account_get_ladder_disconnects(account,clienttag,ladderId));
			account_set_ladder_active_rating(account,clienttag,ladderId,
					account_get_ladder_rating(account,clienttag,ladderId));
			account_set_ladder_active_rank(account,clienttag,ladderId,
					account_get_ladder_rank(account,clienttag,ladderId));
			if (!(timestr = account_get_ladder_last_time(account,clienttag,ladderId)))
				timestr = BNETD_LADDER_DEFAULT_TIME;
			bnettime_set_str(&bt,timestr);
			account_set_ladder_active_last_time(account,clienttag,ladderId,bt);
		}
	}
}
Пример #2
0
extern int account_inc_ladder_draws(t_account * account, char const * clienttag, t_ladder_id id)
{
    char key[256];
    
    if (!clienttag || strlen(clienttag)!=4)
    {
       eventlog(eventlog_level_error,"account_inc_ladder_draws","got bad clienttag");
       return -1;
    }
    sprintf(key,"Record\\%s\\%d\\draws",clienttag,(int)id);
    return account_set_numattr(account,key,account_get_ladder_draws(account,clienttag,id)+1);
}
Пример #3
0
bool
LadderReferencedObject::getData(const LadderKey& ladderKey_, unsigned int& uid_, unsigned int& primary_, unsigned int& secondary_, unsigned int& tertiary_) const
{
	// returns false in case of failures - and also when no need to add this referencedObject to ladder
	t_clienttag clienttag = ladderKey_.getClienttag();
	t_ladder_id ladderId = ladderKey_.getLadderId();
	
	if (referenceType == referenceTypeAccount)
	{
		uid_ = account_get_uid(account);
		if (clienttag == CLIENTTAG_WARCRAFT3_UINT || clienttag == CLIENTTAG_WAR3XP_UINT)
		{
			if (!(primary_ = account_get_ladder_level(account,clienttag,ladderId)))
				return false;
			secondary_ = account_get_ladder_xp(account,clienttag,ladderId);
			tertiary_ = 0;
			return true;
		}else{
			t_ladder_sort ladderSort = ladderKey_.getLadderSort();
			unsigned int rating, wins, games;
			// current ladders
			if (ladderKey_.getLadderTime() == ladder_time_current)
			{
				rating = account_get_ladder_rating(account,clienttag,ladderId);
				if (!rating) return false;
				wins   = account_get_ladder_wins(account,clienttag,ladderId);
				games  = wins +
					 account_get_ladder_losses(account,clienttag,ladderId)+
					 account_get_ladder_disconnects(account,clienttag,ladderId)+
				         account_get_ladder_draws(account,clienttag,ladderId);
			}else{ // active ladders
				rating = account_get_ladder_active_rating(account,clienttag,ladderId);
				if (!rating) return false;
				wins   = account_get_ladder_active_wins(account,clienttag,ladderId);
				games  = wins +
			 		 account_get_ladder_active_losses(account,clienttag,ladderId)+
					 account_get_ladder_active_disconnects(account,clienttag,ladderId)+
					 account_get_ladder_active_draws(account,clienttag,ladderId);
			}
			unsigned int ratio  = (wins<<10)/games;
			switch (ladderSort)
			{
			case ladder_sort_highestrated:
				primary_   = rating;
				secondary_ = wins;
				tertiary_  = ratio;
				return true;
			case ladder_sort_mostwins:
				primary_   = wins;
				secondary_ = rating;
				tertiary_  = ratio;
				return true;
			case ladder_sort_mostgames:
				primary_   = games;
				secondary_ = rating;
				tertiary_  = ratio;
				return true;
			default:
				return false;
			}
		}
	}
	else if (referenceType == referenceTypeTeam)
	{
		uid_    = team_get_teamid(team);
		if (!(primary_ = team_get_level(team)))
			return false;
		secondary_ = team_get_xp(team);
		tertiary_ = 0;
		return true;
	}

	return false;
}