scoreboard ping never worked right way. It use player cl_cmdrate and cl_updaterate. And maybe to do with TICKS
I maybe found that scoreboard code, below
Code:
void CPlayerResource::UpdatePlayerData( void )
{
for ( int i = 1; i <= gpGlobals->maxClients; i++ )
{
CBasePlayer *pPlayer = (CBasePlayer*)UTIL_PlayerByIndex( i );
if ( pPlayer && pPlayer->IsConnected() )
{
m_iKills.Set( i, pPlayer->FragCount() );
m_iAssists.Set(i, pPlayer->AssistsCount() );
m_iDeaths.Set( i, pPlayer->DeathCount() );
m_bConnected.Set( i, 1 );
m_iTeam.Set( i, pPlayer->GetTeamNumber() );
m_iPendingTeam.Set( i, pPlayer->GetPendingTeamNumber() );
m_bAlive.Set( i, pPlayer->IsAlive()?1:0 );
m_iHealth.Set(i, MAX( 0, pPlayer->GetHealth() ) );
m_iCoachingTeam.Set( i, pPlayer->GetCoachingTeam() );
// Don't update ping / packetloss everytime
if ( !(m_nUpdateCounter%20) )
{
// update ping all 20 think ticks = (20*0.1=2seconds)
int ping, packetloss;
UTIL_GetPlayerConnectionInfo( i, ping, packetloss );
// calc avg for scoreboard so it's not so jittery
ping = 0.8f * m_iPing.Get(i) + 0.2f * ping;
m_iPing.Set( i, ping );
// m_iPacketloss.Set( i, packetloss );
}
}
else
{
m_bConnected.Set( i, 0 );
}
}
}
//... SECOND CODE BLOCK ...
//-----------------------------------------------------------------------------
// Purpose:
// Input : playerIndex -
// ping -
// packetloss -
//-----------------------------------------------------------------------------
void UTIL_GetPlayerConnectionInfo( int playerIndex, int& ping, int &packetloss )
{
CBasePlayer *player = UTIL_PlayerByIndex( playerIndex );
if ( player->IsSplitScreenPlayer() &&
player->GetSplitScreenPlayerOwner() )
{
player = player->GetSplitScreenPlayerOwner();
playerIndex = player->entindex();
}
INetChannelInfo *nci = engine->GetPlayerNetInfo(playerIndex);
if ( nci && player && !player->IsBot() )
{
float latency = nci->GetAvgLatency( FLOW_OUTGOING ); // in seconds
// that should be the correct latency, we assume that cmdrate is higher
// then updaterate, what is the case for default settings
const char * szCmdRate = engine->GetClientConVarValue( playerIndex, "cl_cmdrate" );
const char * szUpdateRate = engine->GetClientConVarValue( playerIndex, "cl_updaterate" );
static const ConVar *pSvClientCmdrateDifference = g_pCVar->FindVar( "sv_client_cmdrate_difference" );
static const ConVar *pMinUpdateRate = g_pCVar->FindVar( "sv_minupdaterate" );
static const ConVar *pMaxUpdateRate = g_pCVar->FindVar( "sv_maxupdaterate" );
float flUpdateRateValue = Q_atof( szUpdateRate );
if ( !player->IsHLTV() )
{
if ( pMinUpdateRate && pMaxUpdateRate )
flUpdateRateValue = clamp( flUpdateRateValue, pMinUpdateRate->GetFloat(), pMaxUpdateRate->GetFloat() );
}
float flCmdRateValue = Q_atof( szCmdRate );
if ( player->IsHLTV() )
{
flCmdRateValue = flUpdateRateValue;
}
else
{
// First, we make it stay within range of cl_updaterate.
if ( pSvClientCmdrateDifference )
{
float diff = flCmdRateValue - flUpdateRateValue;
float diffMaxCap = pSvClientCmdrateDifference->GetFloat();
if ( fabs( diff ) > diffMaxCap )
{
if ( diff > 0 )
flCmdRateValue = flUpdateRateValue + diffMaxCap;
else
flCmdRateValue = flUpdateRateValue - diffMaxCap;
}
}
static const ConVar *pMinCmdRate = g_pCVar->FindVar( "sv_mincmdrate" );
static const ConVar *pMaxCmdRate = g_pCVar->FindVar( "sv_maxcmdrate" );
if ( pMinUpdateRate && pMaxUpdateRate )
flCmdRateValue = clamp( flCmdRateValue, pMinCmdRate->GetFloat(), pMaxCmdRate->GetFloat() );
}
latency -= (0.5f/flCmdRateValue) + TICKS_TO_TIME( 1.0f ); // correct latency
// in GoldSrc we had a different, not fixed tickrate. so we have to adjust
// Source pings by half a tick to match the old GoldSrc pings.
latency -= TICKS_TO_TIME( 0.5f );
ping = latency * 1000.0f; // as msecs
ping = clamp( ping, 5, 1000 ); // set bounds, dont show pings under 5 msecs
packetloss = 100.0f * nci->GetAvgLoss( FLOW_INCOMING ); // loss in percentage
packetloss = clamp( packetloss, 0, 100 );
}
else
{
ping = 0;
packetloss = 0;
}
}
*edit
This is maybe STATUS in console
Code:
/*
==================
Host_Status_PrintClient
Print client info to console
==================
*/
void Host_Status_PrintClient( IClient *client, bool bShowAddress, void (*print) (const char *fmt, ...) )
{
INetChannelInfo *nci = client->GetNetChannel();
const char *state = "challenging";
if ( client->IsActive() )
state = "active";
else if ( client->IsSpawned() )
state = "spawning";
else if ( client->IsConnected() )
state = "connecting";
if ( nci != NULL )
{
print( "# %2i %i \"%s\" %s %s %i %i %s %d",
client->GetUserID(), client->GetPlayerSlot() + 1, client->GetClientName(), client->GetNetworkIDString(), COM_FormatSeconds( nci->GetTimeConnected() ),
(int)(1000.0f*nci->GetAvgLatency( FLOW_OUTGOING )), (int)(100.0f*nci->GetAvgLoss(FLOW_INCOMING)), state, (int)nci->GetDataRate() );
if ( bShowAddress )
{
print( " %s", nci->GetAddress() );
}
}
else
{
print( "#%2i \"%s\" %s %s %.0f",
client->GetUserID(), client->GetClientName(), client->GetNetworkIDString(), state, client->GetUpdateRate() );
}
print( "\n" );
}
__________________