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); } } }
extern int account_adjust_ladder_rating(t_account * account, char const * clienttag, t_ladder_id id, int delta) { char key[256]; unsigned int oldrating; unsigned int newrating; int retval=0; if (!clienttag || strlen(clienttag)!=4) { eventlog(eventlog_level_error,"account_adjust_ladder_rating","got bad clienttag"); return -1; } sprintf(key,"Record\\%s\\%d\\rating",clienttag,(int)id); /* don't allow rating to go below 1 */ oldrating = account_get_ladder_rating(account,clienttag,id); if (delta<0 && oldrating<=(unsigned int)-delta) newrating = 1; else newrating = oldrating+delta; if (account_set_numattr(account,key,newrating)<0) retval = -1; if (newrating>account_get_ladder_high_rating(account,clienttag,id)) { sprintf(key,"Record\\%s\\%d\\high rating",clienttag,(int)id); if (account_set_numattr(account,key,newrating)<0) retval = -1; } return retval; }
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; }