core/smn_player.cpp
changeset 2054 31593cdc67c7
parent 2042 4a2faafca477
child 2162 59c5dc056c69
     1.1 --- a/core/smn_player.cpp	Wed May 14 22:40:36 2008 +0000
     1.2 +++ b/core/smn_player.cpp	Thu May 15 05:52:30 2008 +0000
     1.3 @@ -765,115 +765,199 @@
     1.4  static cell_t GetLatency(IPluginContext *pContext, const cell_t *params)
     1.5  {
     1.6  	int client = params[1];
     1.7 +	float value;
     1.8  
     1.9  	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.10  	if (!pPlayer)
    1.11  	{
    1.12  		return pContext->ThrowNativeError("Client index %d is invalid", client);
    1.13 -	} else if (!pPlayer->IsInGame()) {
    1.14 +	}
    1.15 +	else if (!pPlayer->IsInGame())
    1.16 +	{
    1.17  		return pContext->ThrowNativeError("Client %d is not in game", client);
    1.18 -	} else if (pPlayer->IsFakeClient()) {
    1.19 +	}
    1.20 +	else if (pPlayer->IsFakeClient())
    1.21 +	{
    1.22  		return pContext->ThrowNativeError("Client %d is a bot", client);
    1.23  	}
    1.24  
    1.25  	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
    1.26  
    1.27 -	return sp_ftoc(pInfo->GetLatency(params[2]));
    1.28 +	if (params[2] == MAX_FLOWS)
    1.29 +	{
    1.30 +		value = pInfo->GetLatency(FLOW_INCOMING) + pInfo->GetLatency(FLOW_OUTGOING);
    1.31 +	}
    1.32 +	else
    1.33 +	{
    1.34 +		value = pInfo->GetLatency(params[2]);
    1.35 +	}
    1.36 +
    1.37 +	return sp_ftoc(value);
    1.38  }
    1.39  
    1.40  static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params)
    1.41  {
    1.42  	int client = params[1];
    1.43 +	float value;
    1.44  
    1.45  	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.46  	if (!pPlayer)
    1.47  	{
    1.48  		return pContext->ThrowNativeError("Client index %d is invalid", client);
    1.49 -	} else if (!pPlayer->IsInGame()) {
    1.50 +	}
    1.51 +	else if (!pPlayer->IsInGame())
    1.52 +	{
    1.53  		return pContext->ThrowNativeError("Client %d is not in game", client);
    1.54 -	} else if (pPlayer->IsFakeClient()) {
    1.55 +	}
    1.56 +	else if (pPlayer->IsFakeClient())
    1.57 +	{
    1.58  		return pContext->ThrowNativeError("Client %d is a bot", client);
    1.59  	}
    1.60  
    1.61  	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
    1.62  
    1.63 -	return sp_ftoc(pInfo->GetAvgLatency(params[2]));
    1.64 +	if (params[2] == MAX_FLOWS)
    1.65 +	{
    1.66 +		value = pInfo->GetAvgLatency(FLOW_INCOMING) + pInfo->GetAvgLatency(FLOW_OUTGOING);
    1.67 +	}
    1.68 +	else
    1.69 +	{
    1.70 +		value = pInfo->GetAvgLatency(params[2]);
    1.71 +	}
    1.72 +
    1.73 +	return sp_ftoc(value);
    1.74  }
    1.75  
    1.76  static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params)
    1.77  {
    1.78  	int client = params[1];
    1.79 +	float value;
    1.80  
    1.81  	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.82  	if (!pPlayer)
    1.83  	{
    1.84  		return pContext->ThrowNativeError("Client index %d is invalid", client);
    1.85 -	} else if (!pPlayer->IsInGame()) {
    1.86 +	}
    1.87 +	else if (!pPlayer->IsInGame())
    1.88 +	{
    1.89  		return pContext->ThrowNativeError("Client %d is not in game", client);
    1.90 -	} else if (pPlayer->IsFakeClient()) {
    1.91 +	}
    1.92 +	else if (pPlayer->IsFakeClient())
    1.93 +	{
    1.94  		return pContext->ThrowNativeError("Client %d is a bot", client);
    1.95  	}
    1.96  
    1.97  	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
    1.98  
    1.99 -	return sp_ftoc(pInfo->GetAvgLoss(params[2]));
   1.100 +	if (params[2] == MAX_FLOWS)
   1.101 +	{
   1.102 +		value = pInfo->GetAvgLoss(FLOW_INCOMING) + pInfo->GetAvgLoss(FLOW_OUTGOING);
   1.103 +	}
   1.104 +	else
   1.105 +	{
   1.106 +		value = pInfo->GetAvgLoss(params[2]);
   1.107 +	}
   1.108 +
   1.109 +	return sp_ftoc(value);
   1.110  }
   1.111  
   1.112  static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params)
   1.113  {
   1.114  	int client = params[1];
   1.115 +	float value;
   1.116  
   1.117  	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.118  	if (!pPlayer)
   1.119  	{
   1.120  		return pContext->ThrowNativeError("Client index %d is invalid", client);
   1.121 -	} else if (!pPlayer->IsInGame()) {
   1.122 +	}
   1.123 +	else if (!pPlayer->IsInGame())
   1.124 +	{
   1.125  		return pContext->ThrowNativeError("Client %d is not in game", client);
   1.126 -	} else if (pPlayer->IsFakeClient()) {
   1.127 +	}
   1.128 +	else if (pPlayer->IsFakeClient())
   1.129 +	{
   1.130  		return pContext->ThrowNativeError("Client %d is a bot", client);
   1.131  	}
   1.132  
   1.133  	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
   1.134  
   1.135 -	return sp_ftoc(pInfo->GetAvgChoke(params[2]));
   1.136 +	if (params[2] == MAX_FLOWS)
   1.137 +	{
   1.138 +		value = pInfo->GetAvgChoke(FLOW_INCOMING) + pInfo->GetAvgChoke(FLOW_OUTGOING);
   1.139 +	}
   1.140 +	else
   1.141 +	{
   1.142 +		value = pInfo->GetAvgChoke(params[2]);
   1.143 +	}
   1.144 +
   1.145 +	return sp_ftoc(value);
   1.146  }
   1.147  
   1.148  static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params)
   1.149  {
   1.150  	int client = params[1];
   1.151 +	float value;
   1.152  
   1.153  	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.154  	if (!pPlayer)
   1.155  	{
   1.156  		return pContext->ThrowNativeError("Client index %d is invalid", client);
   1.157 -	} else if (!pPlayer->IsInGame()) {
   1.158 +	}
   1.159 +	else if (!pPlayer->IsInGame())
   1.160 +	{
   1.161  		return pContext->ThrowNativeError("Client %d is not in game", client);
   1.162 -	} else if (pPlayer->IsFakeClient()) {
   1.163 +	}
   1.164 +	else if (pPlayer->IsFakeClient())
   1.165 +	{
   1.166  		return pContext->ThrowNativeError("Client %d is a bot", client);
   1.167  	}
   1.168  
   1.169  	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
   1.170  
   1.171 -	return sp_ftoc(pInfo->GetAvgData(params[2]));
   1.172 +	if (params[2] == MAX_FLOWS)
   1.173 +	{
   1.174 +		value = pInfo->GetAvgData(FLOW_INCOMING) + pInfo->GetAvgData(FLOW_OUTGOING);
   1.175 +	}
   1.176 +	else
   1.177 +	{
   1.178 +		value = pInfo->GetAvgData(params[2]);
   1.179 +	}
   1.180 +
   1.181 +	return sp_ftoc(value);
   1.182  }
   1.183  
   1.184  static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
   1.185  {
   1.186  	int client = params[1];
   1.187 +	float value;
   1.188  
   1.189  	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.190  	if (!pPlayer)
   1.191  	{
   1.192  		return pContext->ThrowNativeError("Client index %d is invalid", client);
   1.193 -	} else if (!pPlayer->IsInGame()) {
   1.194 +	}
   1.195 +	else if (!pPlayer->IsInGame())
   1.196 +	{
   1.197  		return pContext->ThrowNativeError("Client %d is not in game", client);
   1.198 -	} else if (pPlayer->IsFakeClient()) {
   1.199 +	}
   1.200 +	else if (pPlayer->IsFakeClient())
   1.201 +	{
   1.202  		return pContext->ThrowNativeError("Client %d is a bot", client);
   1.203  	}
   1.204  
   1.205  	INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
   1.206  
   1.207 -	return sp_ftoc(pInfo->GetAvgPackets(params[2]));
   1.208 +	if (params[2] == MAX_FLOWS)
   1.209 +	{
   1.210 +		value = pInfo->GetAvgPackets(FLOW_INCOMING) + pInfo->GetAvgPackets(FLOW_OUTGOING);
   1.211 +	}
   1.212 +	else
   1.213 +	{
   1.214 +		value = pInfo->GetAvgPackets(params[2]);
   1.215 +	}
   1.216 +
   1.217 +	return sp_ftoc(value);
   1.218  }
   1.219  
   1.220  static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)