diff --git a/LogApi/LogApi.cpp b/LogApi/LogApi.cpp index 018aa75..68c3e3d 100644 --- a/LogApi/LogApi.cpp +++ b/LogApi/LogApi.cpp @@ -6,7 +6,7 @@ CLogApi gLogApi; void CLogApi::ServerActivate() { // Enable Log API (0 Disable, 1 Enable) - this->m_log_api_on = gLogUtil.CvarRegister("log_api_enable", "1"); + this->m_log_api_on = gLogUtil.CvarRegister("log_api_enable", "0"); // Set Log API Address (API HTTP/s Address Ie. https://api.yoursite.com/) this->m_log_api_address = gLogUtil.CvarRegister("log_api_address", ""); @@ -17,6 +17,9 @@ void CLogApi::ServerActivate() // Set Log API Bearer Token (Authentication Token or leave empty to disable) this->m_log_api_bearer = gLogUtil.CvarRegister("log_api_bearer", ""); + // Execute Settings File + g_engfuncs.pfnServerCommand("exec addons/logapi/logapi.cfg\n"); + // Clear events this->m_Events.clear(); diff --git a/LogApi/LogEvent.cpp b/LogApi/LogEvent.cpp index e18920b..953f05c 100644 --- a/LogApi/LogEvent.cpp +++ b/LogApi/LogEvent.cpp @@ -55,7 +55,7 @@ void CLogEvent::ClientConnect(edict_t* pEntity, const char* pszName, const char* { this->m_Event.clear(); - if (pEntity) + if (!FNullEnt(pEntity)) { this->m_Event["Event"] = __func__; @@ -78,7 +78,7 @@ void CLogEvent::ClientPutInServer(edict_t* pEntity) { this->m_Event.clear(); - if (pEntity) + if (!FNullEnt(pEntity)) { this->m_Event["Event"] = __func__; @@ -99,7 +99,7 @@ void CLogEvent::ClientDisconnect(edict_t* pEntity) { this->m_Event.clear(); - if (pEntity) + if (!FNullEnt(pEntity)) { this->m_Event["Event"] = __func__; @@ -120,7 +120,7 @@ void CLogEvent::ClientKill(edict_t* pEntity) { this->m_Event.clear(); - if (pEntity) + if (!FNullEnt(pEntity)) { this->m_Event["Event"] = __func__; @@ -141,7 +141,7 @@ void CLogEvent::ClientUserInfoChanged(edict_t* pEntity, char* InfoBuffer) { this->m_Event.clear(); - if (pEntity) + if (!FNullEnt(pEntity)) { this->m_Event["Event"] = __func__; @@ -157,3 +157,87 @@ void CLogEvent::ClientUserInfoChanged(edict_t* pEntity, char* InfoBuffer) gLogApi.SendEvent(LogApi::Events::ClientUserInfoChanged, this->m_Event); } } + +void CLogEvent::ClientCommand(edict_t* pEntity) +{ + if (gLogApi.EventEnabled(__func__)) + { + this->m_Event.clear(); + + if (!FNullEnt(pEntity)) + { + auto Command = g_engfuncs.pfnCmd_Argv(0); + + if (Command) + { + if (Command[0u] != '\0') + { + this->m_Event["Event"] = __func__; + + this->m_Event["UserId"] = g_engfuncs.pfnGetPlayerUserId(pEntity); + + this->m_Event["Name"] = STRING(pEntity->v.netname); + + this->m_Event["AuthId"] = g_engfuncs.pfnGetPlayerAuthId(pEntity); + + this->m_Event["Command"] = Command; + + this->m_Event["Args"] = ""; + + auto Args = g_engfuncs.pfnCmd_Args(); + + if (Args) + { + if (Args[0u] != '\0') + { + this->m_Event["Args"] = Args; + } + } + } + } + } + + gLogApi.SendEvent(LogApi::Events::ClientCommand, this->m_Event); + } +} + +void CLogEvent::ClientSay(edict_t* pEntity) +{ + if (gLogApi.EventEnabled(__func__)) + { + this->m_Event.clear(); + + if (!FNullEnt(pEntity)) + { + auto Type = g_engfuncs.pfnCmd_Argv(0); + + if (Type) + { + if (Type[0u] != '\0') + { + auto Message = g_engfuncs.pfnCmd_Args(); + + if (Message[0u] != '\0') + { + if (!Q_stricmp(Type, "say") || !Q_stricmp(Type, "say_team")) + { + this->m_Event["Event"] = __func__; + + this->m_Event["UserId"] = g_engfuncs.pfnGetPlayerUserId(pEntity); + + this->m_Event["Name"] = STRING(pEntity->v.netname); + + this->m_Event["AuthId"] = g_engfuncs.pfnGetPlayerAuthId(pEntity); + + this->m_Event["Type"] = Type; + + this->m_Event["Message"] = Message; + } + } + } + } + } + + gLogApi.SendEvent(LogApi::Events::ClientSay, this->m_Event); + } +} diff --git a/LogApi/LogEvent.h b/LogApi/LogEvent.h index 44019cc..20d39d1 100644 --- a/LogApi/LogEvent.h +++ b/LogApi/LogEvent.h @@ -12,6 +12,8 @@ namespace LogApi ClientDisconnect, ClientKill, ClientUserInfoChanged, + ClientCommand, + ClientSay, }; } @@ -26,6 +28,8 @@ class CLogEvent void ClientDisconnect(edict_t* pEntity); void ClientKill(edict_t* pEntity); void ClientUserInfoChanged(edict_t* pEntity, char* InfoBuffer); + void ClientCommand(edict_t* pEntity); + void ClientSay(edict_t* pEntity); private: // Current event data nlohmann::ordered_json m_Event; diff --git a/LogApi/LogUtil.cpp b/LogApi/LogUtil.cpp index 6472976..709f52f 100644 --- a/LogApi/LogUtil.cpp +++ b/LogApi/LogUtil.cpp @@ -50,3 +50,47 @@ void CLogUtil::ServerExecute(std::string CommandData) g_engfuncs.pfnServerCommand(ExecuteCommand); } } + +void CLogUtil::ClientPrint(edict_t* pEntity, int msg_dest, const char* Format, ...) +{ + va_list argList; + + va_start(argList, Format); + + char Buffer[188] = { 0 }; + + int Length = vsnprintf(Buffer, sizeof(Buffer), Format, argList); + + va_end(argList); + + if (msg_dest == PRINT_CONSOLE) + { + if (Length > 125) + { + Length = 125; + } + + Buffer[Length++] = '\n'; + Buffer[Length++] = '\n'; + Buffer[Length] = 0; + } + + static int iMsgTextMsg; + + if (iMsgTextMsg || (iMsgTextMsg = gpMetaUtilFuncs->pfnGetUserMsgID(PLID, "TextMsg", NULL))) + { + if (pEntity) + { + g_engfuncs.pfnMessageBegin(MSG_ONE, iMsgTextMsg, NULL, pEntity); + } + else + { + g_engfuncs.pfnMessageBegin(MSG_BROADCAST, iMsgTextMsg, NULL, NULL); + } + + g_engfuncs.pfnWriteByte(msg_dest); + g_engfuncs.pfnWriteString("%s"); + g_engfuncs.pfnWriteString(Buffer); + g_engfuncs.pfnMessageEnd(); + } +} \ No newline at end of file diff --git a/LogApi/LogUtil.h b/LogApi/LogUtil.h index 2cbb18d..92b0a0a 100644 --- a/LogApi/LogUtil.h +++ b/LogApi/LogUtil.h @@ -1,10 +1,18 @@ #pragma once +// Client Print +constexpr auto PRINT_NOTIFY = 1; +constexpr auto PRINT_CONSOLE = 2; +constexpr auto PRINT_CHAT = 3; +constexpr auto PRINT_CENTER = 4; +constexpr auto PRINT_RADIO = 5; + class CLogUtil { public: cvar_t* CvarRegister(const char* Name, const char* Value); void ServerExecute(std::string Command); + void ClientPrint(edict_t* pEntity, int msg_dest, const char* Format, ...); private: std::map m_Cvar; diff --git a/LogApi/MetaDLL.cpp b/LogApi/MetaDLL.cpp index c75ffbb..bd046c1 100644 --- a/LogApi/MetaDLL.cpp +++ b/LogApi/MetaDLL.cpp @@ -40,6 +40,8 @@ C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS* pFunctionTable, int* interface gDLL_FunctionTable_Post.pfnClientUserInfoChanged = DLL_POST_ClientUserInfoChanged; + gDLL_FunctionTable_Post.pfnClientCommand = DLL_POST_ClientCommand; + memcpy(pFunctionTable, &gDLL_FunctionTable_Post, sizeof(DLL_FUNCTIONS)); return 1; @@ -104,4 +106,13 @@ void DLL_POST_ClientUserInfoChanged(edict_t* pEntity, char* InfoBuffer) RETURN_META(MRES_IGNORED); } + +void DLL_POST_ClientCommand(edict_t* pEntity) +{ + gLogEvent.ClientCommand(pEntity); + + gLogEvent.ClientSay(pEntity); + + RETURN_META(MRES_IGNORED); +} #pragma endregion \ No newline at end of file diff --git a/LogApi/MetaDLL.h b/LogApi/MetaDLL.h index 8013de2..5f647b1 100644 --- a/LogApi/MetaDLL.h +++ b/LogApi/MetaDLL.h @@ -12,4 +12,5 @@ void DLL_POST_ClientPutInServer(edict_t* pEntity); void DLL_POST_ClientDisconnect(edict_t* pEntity); void DLL_POST_ClientKill(edict_t* pEntity); void DLL_POST_ClientUserInfoChanged(edict_t* pEntity, char* InfoBuffer); +void DLL_POST_ClientCommand(edict_t* pEntity); #pragma endregion \ No newline at end of file diff --git a/cstrike/addons/logapi/events.json b/cstrike/addons/logapi/events.json index 25d1569..be19989 100644 --- a/cstrike/addons/logapi/events.json +++ b/cstrike/addons/logapi/events.json @@ -6,5 +6,7 @@ "ClientPutInServer": false, "ClientDisconnect": false, "ClientKill": false, - "ClientUserInfoChanged": false + "ClientUserInfoChanged": false, + "ClientCommand": false, + "ClientSay": false } \ No newline at end of file