diff --git a/extension.cpp b/extension.cpp index 18e169a..668be97 100644 --- a/extension.cpp +++ b/extension.cpp @@ -33,6 +33,8 @@ #include "string.h" #include "sys/socket.h" #include "CDetour/detours.h" +#include +#include #define DETOUR_CREATE_MEMBER_ADDRESS(name, address) CDetourManager::CreateDetour(GET_MEMBER_CALLBACK(name), GET_MEMBER_TRAMPOLINE(name), address); #define DETOUR_CREATE_STATIC_ADDRESS(name, address) CDetourManager::CreateDetour(GET_STATIC_CALLBACK(name), GET_STATIC_TRAMPOLINE(name), address); @@ -54,6 +56,12 @@ SMEXT_LINK(&g_Interface); CDetour *g_pDetour_SendTo = NULL; CDetour *g_pDetour_RecvFrom = NULL; +char g_PlayerReply[1024]; +bf_write g_PlayerReplyPacket(PlayerReply, 1024); + +char *NewBuf; +char *OldBuf; + /** * @brief */ @@ -63,9 +71,7 @@ DETOUR_DECL_STATIC6(Detour_SendTo, int, int, s, char *, buf, int, len, int, flag { // g_pSM->LogMessage(myself, "A2S_INFO_REPLY: %s", buf); - char *NewBuf; - char *OldBuf; - + delete[] NewBuf; NewBuf = new char[len]; memcpy(NewBuf, buf, len); OldBuf = NewBuf; @@ -109,7 +115,7 @@ DETOUR_DECL_STATIC6(Detour_SendTo, int, int, s, char *, buf, int, len, int, flag if (pPlayer != NULL && pPlayer->IsConnected() && !pPlayer->IsSourceTV()) { - iPlayers += 1; + iPlayers++; } } @@ -122,10 +128,47 @@ DETOUR_DECL_STATIC6(Detour_SendTo, int, int, s, char *, buf, int, len, int, flag return DETOUR_STATIC_CALL(Detour_SendTo)(s, NewBuf, len, flags, to, tolen); } -// if (memcmp(buf, A2S_PLAYER_REPLY, 5) == 0) -// { -// g_pSM->LogMessage(myself, "A2S_PLAYER_REPLY: %s", buf); -// } + if (memcmp(buf, A2S_PLAYER_REPLY, 5) == 0) + { + g_pSM->LogMessage(myself, "A2S_PLAYER_REPLY: %s", buf); + + g_PlayerReply.Reset(); //build up the packet as a bitbuffer so we can use the nice helper functions to do the work for us + + g_PlayerReply.WriteLong(-1);//FF FF FF FF + g_PlayerReply.WriteByte(68);//44 + + g_PlayerReply.WriteByte(playerhelpers->GetNumPlayers()); //number of players + + int iPlayers = 0; + + for (int index = 0; index <= SM_MAXPLAYERS; index++) + { + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + + if (pPlayer != NULL && pPlayer->IsConnected() && pPlayer->IsInGame() && !pPlayer->IsSourceTV()) + { + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + INetChannelInfo *pNetInfo = engine->GetPlayerNetInfo(client); + + g_PlayerReply.WriteByte(iPlayers); + g_PlayerReply.WriteString(pPlayer->GetName()); + + if(pInfo != NULL) + g_PlayerReply.WriteLong(pInfo->GetFragCount()); + else + g_PlayerReply.WriteLong(0); + + if(pNetInfo != NULL) + g_PlayerReply.WriteFloat(pNetInfo->GetTimeConnected()); + else + g_PlayerReply.WriteFloat(0.0); + + iPlayers++; + } + } + + return DETOUR_STATIC_CALL(Detour_SendTo)(s, (const char *)g_PlayerReply.GetData(), g_PlayerReply.GetNumBytesWritten(), flags, to, tolen); + } return DETOUR_STATIC_CALL(Detour_SendTo)(s, buf, len, flags, to, tolen); }