mirror of
https://github.com/rehlds/rechecker.git
synced 2024-12-27 04:45:29 +03:00
Implemented unload plugin
Implemented log Hide fake cvar from cvar_vars
This commit is contained in:
parent
e93951b651
commit
107c92c7a0
@ -164,18 +164,10 @@
|
||||
<ClInclude Include="..\public\FileSystem.h" />
|
||||
<ClInclude Include="..\public\interface.h" />
|
||||
<ClInclude Include="..\src\cmdexec.h" />
|
||||
<ClInclude Include="..\src\config.h">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\resource.h" />
|
||||
<ClInclude Include="..\src\engine_rehlds.h" />
|
||||
<ClInclude Include="..\src\main.h" />
|
||||
<ClInclude Include="..\src\precompiled.h" />
|
||||
<ClInclude Include="..\src\task.h">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\common\parsemsg.cpp">
|
||||
@ -184,10 +176,6 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\public\interface.cpp" />
|
||||
<ClCompile Include="..\src\cmdexec.cpp" />
|
||||
<ClCompile Include="..\src\config.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\resource.cpp" />
|
||||
<ClCompile Include="..\src\dllapi.cpp" />
|
||||
<ClCompile Include="..\src\engine_api.cpp">
|
||||
@ -203,10 +191,6 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\sdk_util.cpp" />
|
||||
<ClCompile Include="..\src\task.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\dist\config.ini" />
|
||||
|
@ -462,8 +462,6 @@
|
||||
<ClInclude Include="..\src\engine_rehlds.h" />
|
||||
<ClInclude Include="..\src\cmdexec.h" />
|
||||
<ClInclude Include="..\src\resource.h" />
|
||||
<ClInclude Include="..\src\config.h" />
|
||||
<ClInclude Include="..\src\task.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\common\parsemsg.cpp">
|
||||
@ -482,8 +480,6 @@
|
||||
<ClCompile Include="..\src\sdk_util.cpp" />
|
||||
<ClCompile Include="..\src\cmdexec.cpp" />
|
||||
<ClCompile Include="..\src\resource.cpp" />
|
||||
<ClCompile Include="..\src\config.cpp" />
|
||||
<ClCompile Include="..\src\task.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="sdk">
|
||||
|
@ -101,6 +101,8 @@ void CExecMngr::CommandExecute(IGameClient *pClient)
|
||||
if (!bBreak // erase all cmdexec because have flag is break
|
||||
&& cmdExec != NULL && cmdExec[0] != '\0')
|
||||
{
|
||||
Resource.Log(" -> ExecuteCMD: (%s), for (%s)", cmdExec, pClient->GetName());
|
||||
|
||||
// execute cmdexec
|
||||
SERVER_COMMAND(cmdExec);
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ void CConfig::Load()
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
m_ConfigFailed = true;
|
||||
UTIL_Printf(__FUNCTION__ ": can't find path to " FILE_INI_CONFIG "\n");
|
||||
return;
|
||||
}
|
||||
@ -97,5 +96,4 @@ void CConfig::Load()
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
m_ConfigFailed = false;
|
||||
}
|
||||
|
@ -9,13 +9,11 @@ public:
|
||||
void Load();
|
||||
|
||||
float GetDelay() const { return m_DelayExec; };
|
||||
bool IsConfigLoaded() const { return !m_ConfigFailed; };
|
||||
|
||||
private:
|
||||
void ResetValues();
|
||||
|
||||
private:
|
||||
bool m_ConfigFailed;
|
||||
char m_PathDir[MAX_PATH_LENGTH];
|
||||
|
||||
// settings
|
||||
|
@ -4,6 +4,7 @@ DLL_FUNCTIONS *g_pFunctionTable;
|
||||
|
||||
extern void ServerDeactivate_Post();
|
||||
extern void ClientPutInServer_Post(edict_t *pEntity);
|
||||
extern void StartFrame();
|
||||
|
||||
static DLL_FUNCTIONS gFunctionTable =
|
||||
{
|
||||
|
122
src/main.cpp
122
src/main.cpp
@ -1,6 +1,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
cvar_t mp_consistency = { "mp_consistency", "0", 0, 0.0f, NULL };
|
||||
cvar_t cv_mp_consistency = { "mp_consistency", "0", 0, 0.0f, NULL };
|
||||
cvar_t *pcv_consistency_old = NULL;
|
||||
|
||||
void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index);
|
||||
|
||||
@ -9,6 +10,37 @@ bool OnMetaAttach()
|
||||
if (RehldsApi_Init() != RETURN_LOAD)
|
||||
return false;
|
||||
|
||||
// initialize resource config
|
||||
Resource.Init();
|
||||
|
||||
// set force cvar on own value and replacement of original
|
||||
// NOTE: in gamedll used this cvar not through a pointer thus we create own cvar for gamedll with default values
|
||||
// so for engine set it the cvar values is 1.
|
||||
pcv_consistency_old = g_engfuncs.pfnCVarGetPointer("mp_consistency");
|
||||
|
||||
cv_mp_consistency.value = pcv_consistency_old->value;
|
||||
cv_mp_consistency.string = pcv_consistency_old->string;
|
||||
cv_mp_consistency.flags = pcv_consistency_old->flags;
|
||||
cv_mp_consistency.name = pcv_consistency_old->name;
|
||||
pcv_consistency_old->name = "mp_consistency_";
|
||||
|
||||
g_engfuncs.pfnCVarRegister(&cv_mp_consistency);
|
||||
g_engfuncs.pfnCvar_DirectSet(pcv_consistency_old, "1");
|
||||
|
||||
// to remove the old cvar of cvars list
|
||||
cvar_t *cvar_vars = g_RehldsApi->GetFuncs()->GetCvarVars();
|
||||
for (cvar_t *var = cvar_vars, *prev = NULL; var != NULL; prev = var, var = var->next)
|
||||
{
|
||||
if (var == pcv_consistency_old)
|
||||
{
|
||||
if (prev != NULL)
|
||||
prev->next = var->next;
|
||||
else
|
||||
cvar_vars = cvar_vars->next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// register function from ReHLDS API
|
||||
g_RehldsApi->GetHookchains()->SV_DropClient()->registerHook(&SV_DropClient);
|
||||
g_RehldsApi->GetHookchains()->SV_ActivateServer()->registerHook(&SV_ActivateServer);
|
||||
@ -16,48 +48,46 @@ bool OnMetaAttach()
|
||||
|
||||
SV_AddResource = g_RehldsApi->GetFuncs()->SV_AddResource;
|
||||
|
||||
// initialize resource config
|
||||
Resource.Init();
|
||||
|
||||
/*
|
||||
// initialize config
|
||||
Config.Init();
|
||||
*/
|
||||
|
||||
// set force cvar on own value and replacement of original
|
||||
// NOTE: in gamedll used this cvar not through a pointer thus we create own cvar for gamedll with default values
|
||||
// so for engine set it the cvar values is 1.
|
||||
cvar_t *mp_consistency_old = g_engfuncs.pfnCVarGetPointer("mp_consistency");
|
||||
|
||||
mp_consistency.value = mp_consistency_old->value;
|
||||
mp_consistency.string = mp_consistency_old->string;
|
||||
mp_consistency.flags = mp_consistency_old->flags;
|
||||
mp_consistency_old->name = "mp_consistency_orig";
|
||||
|
||||
g_engfuncs.pfnCVarRegister(&mp_consistency);
|
||||
g_engfuncs.pfnCvar_DirectSet(mp_consistency_old, "1");
|
||||
|
||||
// if all config's is OK go to attach
|
||||
return (Resource.IsConfigLoaded()/* && Config.IsConfigLoaded()*/);
|
||||
// go to attach
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnMetaDetach()
|
||||
{
|
||||
g_RehldsApi->GetHookchains()->SV_DropClient()->unregisterHook(&SV_DropClient);
|
||||
g_RehldsApi->GetHookchains()->SV_ActivateServer()->unregisterHook(&SV_ActivateServer);
|
||||
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponce()->unregisterHook(&SV_CheckConsistencyResponce);
|
||||
cvar_t *pcv_mp_consistency = g_engfuncs.pfnCVarGetPointer("mp_consistency");
|
||||
|
||||
// to restore the pointer address of a string
|
||||
pcv_consistency_old->name = cv_mp_consistency.name;
|
||||
g_engfuncs.pfnCvar_DirectSet(pcv_consistency_old, pcv_mp_consistency->string);
|
||||
|
||||
// restore old cvar mp_consistency
|
||||
cvar_t *cvar_vars = g_RehldsApi->GetFuncs()->GetCvarVars();
|
||||
|
||||
for (cvar_t *var = cvar_vars, *prev = NULL; var != NULL; prev = var, var = var->next)
|
||||
{
|
||||
if (var == pcv_mp_consistency)
|
||||
{
|
||||
if (prev != NULL)
|
||||
prev->next = pcv_consistency_old;
|
||||
else
|
||||
cvar_vars = pcv_consistency_old;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// clear
|
||||
Exec.Clear();
|
||||
/*Task.Clear();*/
|
||||
Resource.Clear();
|
||||
|
||||
g_RehldsApi->GetHookchains()->SV_DropClient()->unregisterHook(&SV_DropClient);
|
||||
g_RehldsApi->GetHookchains()->SV_ActivateServer()->unregisterHook(&SV_ActivateServer);
|
||||
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponce()->unregisterHook(&SV_CheckConsistencyResponce);
|
||||
}
|
||||
|
||||
void ServerDeactivate_Post()
|
||||
{
|
||||
// clear
|
||||
Exec.Clear();
|
||||
/*Task.Clear();*/
|
||||
Resource.Clear();
|
||||
|
||||
SET_META_RESULT(MRES_IGNORED);
|
||||
@ -67,23 +97,13 @@ void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *pClient, bool
|
||||
{
|
||||
// clear buffer cmdexec the client when was disconnected up to perform cmdexec
|
||||
Exec.Clear(pClient);
|
||||
/*Task.Clear(pClient);*/
|
||||
|
||||
// call next hook
|
||||
chain->callNext(pClient, crash, string);
|
||||
}
|
||||
|
||||
/*
|
||||
void StartFrame()
|
||||
{
|
||||
Task.StartFrame();
|
||||
SET_META_RESULT(MRES_IGNORED);
|
||||
}
|
||||
*/
|
||||
|
||||
void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics)
|
||||
{
|
||||
/*Config.Load();*/
|
||||
Resource.LoadResources();
|
||||
|
||||
chain->callNext(runPhysics);
|
||||
@ -92,17 +112,6 @@ void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics)
|
||||
Resource.CreateResourceList();
|
||||
}
|
||||
|
||||
/*
|
||||
void TaskHandler(IGameClient *pClient)
|
||||
{
|
||||
if (!pClient->IsConnected())
|
||||
return;
|
||||
|
||||
// client is connected to putinserver, go execute cmd out buffer
|
||||
Exec.CommandExecute(pClient);
|
||||
}
|
||||
*/
|
||||
|
||||
void ClientPutInServer_Post(edict_t *pEntity)
|
||||
{
|
||||
int nIndex = ENTINDEX(pEntity) - 1;
|
||||
@ -112,17 +121,8 @@ void ClientPutInServer_Post(edict_t *pEntity)
|
||||
|
||||
IGameClient *pClient = g_RehldsApi->GetServerStatic()->GetClient(nIndex);
|
||||
|
||||
/*
|
||||
float time = Config.GetDelay();
|
||||
if (time <= 0.0f)
|
||||
*/
|
||||
// client is connected to putinserver, go execute cmd out buffer
|
||||
Exec.CommandExecute(pClient);
|
||||
/*
|
||||
else
|
||||
Task.AddTask(pClient, time, (xtask_t)TaskHandler);
|
||||
*/
|
||||
|
||||
// client is connected to putinserver, go execute cmd out buffer
|
||||
Exec.CommandExecute(pClient);
|
||||
SET_META_RESULT(MRES_IGNORED);
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ plugin_info_t Plugin_info =
|
||||
"s1lent",
|
||||
"http://www.dedicated-server.ru/",
|
||||
"Rechecker",
|
||||
PT_STARTUP,
|
||||
PT_NEVER,
|
||||
PT_CHANGELEVEL,
|
||||
PT_ANYTIME,
|
||||
};
|
||||
|
||||
meta_globals_t *gpMetaGlobals;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <vector>
|
||||
#include <cstring> // strrchr
|
||||
|
||||
#include <time.h> // time, localtime etc
|
||||
#include <extdll.h>
|
||||
#include <enginecallback.h> // ALERT()
|
||||
|
||||
|
108
src/resource.cpp
108
src/resource.cpp
@ -3,6 +3,9 @@
|
||||
CResourceFile Resource;
|
||||
std::vector<const char *> StringsCache;
|
||||
|
||||
cvar_t cv_rch_log = { "rch_log", "0", 0, 0.0f, NULL };
|
||||
cvar_t *pcv_rch_log = NULL;
|
||||
|
||||
void CResourceFile::CreateResourceList()
|
||||
{
|
||||
int nConsistency = g_RehldsServerData->GetConsistencyNum();
|
||||
@ -23,9 +26,7 @@ void CResourceFile::CreateResourceList()
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
UTIL_Printf(__FUNCTION__ " :: (%s)(%s)(%x)\n", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetFileHash());
|
||||
#endif // _DEBUG
|
||||
Log(__FUNCTION__ " -> file: (%s), cmdexc: (%s), hash: (%x)", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetFileHash());
|
||||
SV_AddResource(t_decal, pRes->GetFileName(), 0, RES_CHECKFILE, m_DecalsNum++);
|
||||
nConsistency++;
|
||||
}
|
||||
@ -46,6 +47,60 @@ void CResourceFile::Clear()
|
||||
ClearStringsCache();
|
||||
}
|
||||
|
||||
void CResourceFile::Log(const char *fmt, ...)
|
||||
{
|
||||
if (pcv_rch_log->string[0] != '1')
|
||||
return;
|
||||
|
||||
static char string[2048];
|
||||
|
||||
FILE *fp;
|
||||
char *file;
|
||||
bool bFirst = false;
|
||||
|
||||
fp = fopen(m_LogFilePath, "r");
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
bFirst = true;
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
fp = fopen(m_LogFilePath, "a");
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(string, sizeof(string), fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
strcat(string, "\n");
|
||||
if (!bFirst)
|
||||
{
|
||||
file = strrchr(m_LogFilePath, '/');
|
||||
if (file == NULL)
|
||||
file = "null";
|
||||
|
||||
fprintf(fp, "L %s: Log file started (file \"%s\") (version \"%s\")\n", m_LogDate, file, Plugin_info.version);
|
||||
}
|
||||
|
||||
fprintf(fp, "L %s: %s", m_LogDate, string);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void CreateDirectory(const char *path)
|
||||
{
|
||||
_mkdir(path
|
||||
#ifndef _WIN32
|
||||
,0755
|
||||
#endif // _WIN32
|
||||
);
|
||||
}
|
||||
|
||||
void CResourceFile::Init()
|
||||
{
|
||||
char *pos;
|
||||
@ -61,8 +116,16 @@ void CResourceFile::Init()
|
||||
|
||||
*(pos + 1) = '\0';
|
||||
|
||||
strncpy(m_LogFilePath, path, sizeof(m_LogFilePath) - 1);
|
||||
m_LogFilePath[sizeof(m_LogFilePath) - 1] = '\0';
|
||||
strcat(m_LogFilePath, "logs/");
|
||||
CreateDirectory(m_LogFilePath);
|
||||
|
||||
// resources.ini
|
||||
snprintf(m_PathDir, sizeof(m_PathDir), "%s" FILE_INI_RESOURCES, path);
|
||||
|
||||
g_engfuncs.pfnCvar_RegisterVariable(&cv_rch_log);
|
||||
pcv_rch_log = g_engfuncs.pfnCVarGetPointer(cv_rch_log.name);
|
||||
}
|
||||
|
||||
inline uint8 hexbyte(uint8 *hex)
|
||||
@ -114,6 +177,27 @@ bool IsFileHasExtension(char *psrc)
|
||||
return strchr(pch, '/') == NULL;
|
||||
}
|
||||
|
||||
void CResourceFile::LogPrepare()
|
||||
{
|
||||
char dateFile[64];
|
||||
char *pos;
|
||||
time_t td;
|
||||
tm *lt;
|
||||
|
||||
td = time(NULL);
|
||||
lt = localtime(&td);
|
||||
|
||||
// remove path to log file
|
||||
if ((pos = strrchr(m_LogFilePath, '/')) != NULL)
|
||||
{
|
||||
*(pos + 1) = '\0';
|
||||
}
|
||||
|
||||
strftime(dateFile, sizeof(dateFile), "L_%d_%m_%Y.log", lt);
|
||||
strftime(m_LogDate, sizeof(m_LogDate), "%m/%d/%Y - %H:%M:%S", lt);
|
||||
strcat(m_LogFilePath, dateFile);
|
||||
}
|
||||
|
||||
void CResourceFile::LoadResources()
|
||||
{
|
||||
char *pos;
|
||||
@ -131,7 +215,6 @@ void CResourceFile::LoadResources()
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
m_ConfigFailed = true;
|
||||
UTIL_Printf(__FUNCTION__ ": can't find path to " FILE_INI_RESOURCES "\n");
|
||||
return;
|
||||
}
|
||||
@ -271,7 +354,7 @@ void CResourceFile::LoadResources()
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
m_ConfigFailed = false;
|
||||
LogPrepare();
|
||||
}
|
||||
|
||||
const char *CResourceFile::GetNextToken(char **pbuf)
|
||||
@ -367,7 +450,7 @@ bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource
|
||||
m_PrevHash = hash;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// strange thing
|
||||
// if this happened when missing all the files from client
|
||||
if (!m_PrevHash)
|
||||
@ -433,12 +516,13 @@ bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource
|
||||
|
||||
if (typeFind != FLAG_TYPE_NONE)
|
||||
{
|
||||
// push exec cmd
|
||||
Exec.AddElement(pSenderClient, pRes, hash);
|
||||
|
||||
#ifdef _DEBUG
|
||||
UTIL_Printf(" -> filename: (%s), exphash: (%x), resphash: (%x), typeFind: (%d), prevhash: (%x)\n", pRes->GetFileName(), pRes->GetFileHash(), hash, typeFind, m_PrevHash);
|
||||
#endif // _DEBUG
|
||||
// TODO: what is?
|
||||
if (hash != 0x0)
|
||||
{
|
||||
// push exec cmd
|
||||
Exec.AddElement(pSenderClient, pRes, hash);
|
||||
}
|
||||
Log(" -> file: (%s), exphash: (%x), got: (%x), typeFind: (%d), prevhash: (%x), (%s)", pRes->GetFileName(), pRes->GetFileHash(), hash, typeFind, m_PrevHash, pSenderClient->GetName());
|
||||
}
|
||||
|
||||
bHandled = true;
|
||||
|
@ -58,12 +58,13 @@ public:
|
||||
void Clear();
|
||||
void LoadResources();
|
||||
void CreateResourceList();
|
||||
void Log(const char *fmt, ...);
|
||||
|
||||
bool FileConsistencyResponce(IGameClient *pSenderClient, resource_t *resource, uint32 hash);
|
||||
bool IsConfigLoaded() const { return !m_ConfigFailed; };
|
||||
|
||||
private:
|
||||
void AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line);
|
||||
void LogPrepare();
|
||||
|
||||
// parse
|
||||
const char *GetNextToken(char **pbuf);
|
||||
@ -74,8 +75,12 @@ private:
|
||||
|
||||
int m_DecalsNum;
|
||||
uint32 m_PrevHash;
|
||||
bool m_ConfigFailed;
|
||||
|
||||
char m_PathDir[MAX_PATH_LENGTH];
|
||||
|
||||
// log data
|
||||
char m_LogFilePath[MAX_PATH_LENGTH];
|
||||
char m_LogDate[64];
|
||||
};
|
||||
|
||||
extern CResourceFile Resource;
|
||||
|
Loading…
Reference in New Issue
Block a user