diff --git a/core/DebugReporter.cpp b/core/DebugReporter.cpp index 29e203d3..d86fa111 100644 --- a/core/DebugReporter.cpp +++ b/core/DebugReporter.cpp @@ -2,7 +2,7 @@ * vim: set ts=4 : * ============================================================================= * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under @@ -181,6 +181,9 @@ int DebugReport::_GetPluginIndex(IPluginContext *ctx) } iter->Release(); - return -1; + + /* If we don't know which plugin this is, it's one being loaded. Fake its index for now. */ + + return g_PluginSys.GetPluginCount() + 1; } diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 5f7d21a6..273e223a 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -2,7 +2,7 @@ * vim: set ts=4 : * ============================================================================= * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under @@ -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 29d6ac5b..e17807dc 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -1,7 +1,7 @@ /** * vim: set ts=4 : * ============================================================================= - * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. + * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. * ============================================================================= * * This file is part of the SourceMod/SourcePawn SDK. @@ -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 */