diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 979e8a86..3c7dfb09 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -765,115 +765,199 @@ static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params) static cell_t GetLatency(IPluginContext *pContext, const cell_t *params) { int client = params[1]; + float value; CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { + } + else if (!pPlayer->IsInGame()) + { return pContext->ThrowNativeError("Client %d is not in game", client); - } else if (pPlayer->IsFakeClient()) { + } + else if (pPlayer->IsFakeClient()) + { return pContext->ThrowNativeError("Client %d is a bot", client); } INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); - return sp_ftoc(pInfo->GetLatency(params[2])); + if (params[2] == MAX_FLOWS) + { + value = pInfo->GetLatency(FLOW_INCOMING) + pInfo->GetLatency(FLOW_OUTGOING); + } + else + { + value = pInfo->GetLatency(params[2]); + } + + return sp_ftoc(value); } static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params) { int client = params[1]; + float value; CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { + } + else if (!pPlayer->IsInGame()) + { return pContext->ThrowNativeError("Client %d is not in game", client); - } else if (pPlayer->IsFakeClient()) { + } + else if (pPlayer->IsFakeClient()) + { return pContext->ThrowNativeError("Client %d is a bot", client); } INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); - return sp_ftoc(pInfo->GetAvgLatency(params[2])); + if (params[2] == MAX_FLOWS) + { + value = pInfo->GetAvgLatency(FLOW_INCOMING) + pInfo->GetAvgLatency(FLOW_OUTGOING); + } + else + { + value = pInfo->GetAvgLatency(params[2]); + } + + return sp_ftoc(value); } static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params) { int client = params[1]; + float value; CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { + } + else if (!pPlayer->IsInGame()) + { return pContext->ThrowNativeError("Client %d is not in game", client); - } else if (pPlayer->IsFakeClient()) { + } + else if (pPlayer->IsFakeClient()) + { return pContext->ThrowNativeError("Client %d is a bot", client); } INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); - return sp_ftoc(pInfo->GetAvgLoss(params[2])); + if (params[2] == MAX_FLOWS) + { + value = pInfo->GetAvgLoss(FLOW_INCOMING) + pInfo->GetAvgLoss(FLOW_OUTGOING); + } + else + { + value = pInfo->GetAvgLoss(params[2]); + } + + return sp_ftoc(value); } static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params) { int client = params[1]; + float value; CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { + } + else if (!pPlayer->IsInGame()) + { return pContext->ThrowNativeError("Client %d is not in game", client); - } else if (pPlayer->IsFakeClient()) { + } + else if (pPlayer->IsFakeClient()) + { return pContext->ThrowNativeError("Client %d is a bot", client); } INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); - return sp_ftoc(pInfo->GetAvgChoke(params[2])); + if (params[2] == MAX_FLOWS) + { + value = pInfo->GetAvgChoke(FLOW_INCOMING) + pInfo->GetAvgChoke(FLOW_OUTGOING); + } + else + { + value = pInfo->GetAvgChoke(params[2]); + } + + return sp_ftoc(value); } static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params) { int client = params[1]; + float value; CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { + } + else if (!pPlayer->IsInGame()) + { return pContext->ThrowNativeError("Client %d is not in game", client); - } else if (pPlayer->IsFakeClient()) { + } + else if (pPlayer->IsFakeClient()) + { return pContext->ThrowNativeError("Client %d is a bot", client); } INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); - return sp_ftoc(pInfo->GetAvgData(params[2])); + if (params[2] == MAX_FLOWS) + { + value = pInfo->GetAvgData(FLOW_INCOMING) + pInfo->GetAvgData(FLOW_OUTGOING); + } + else + { + value = pInfo->GetAvgData(params[2]); + } + + return sp_ftoc(value); } static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params) { int client = params[1]; + float value; CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { + } + else if (!pPlayer->IsInGame()) + { return pContext->ThrowNativeError("Client %d is not in game", client); - } else if (pPlayer->IsFakeClient()) { + } + else if (pPlayer->IsFakeClient()) + { return pContext->ThrowNativeError("Client %d is a bot", client); } INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); - return sp_ftoc(pInfo->GetAvgPackets(params[2])); + if (params[2] == MAX_FLOWS) + { + value = pInfo->GetAvgPackets(FLOW_INCOMING) + pInfo->GetAvgPackets(FLOW_OUTGOING); + } + else + { + value = pInfo->GetAvgPackets(params[2]); + } + + return sp_ftoc(value); } static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 6a946133..e17807dc 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -35,11 +35,14 @@ #endif #define _clients_included +/** + * Network flow directions. + */ enum NetFlow { NetFlow_Outgoing = 0, /**< Outgoing traffic */ NetFlow_Incoming, /**< Incoming traffic */ - NetFlow_Both /**< Incoming and outgoing traffic */ + NetFlow_Both, /**< Both values added together */ }; #define MAXPLAYERS 64 /**< Maximum number of players that can be in server */