Fix flag with break
This commit is contained in:
s1lentq 2015-11-17 22:05:20 +06:00
parent d76230de9e
commit 50f6476db6
7 changed files with 73 additions and 36 deletions

1
dist/resources.ini vendored
View File

@ -8,6 +8,7 @@
# #
# [file_name] - the path of the file # [file_name] - the path of the file
# [file_hash] - hash the file of responce client # [file_hash] - hash the file of responce client
# [file_md5hash] - md5 hash (from big-endian to little endian) the file of responce client
# #
# -> Format # -> Format
# path to file hash (exec cmd) # path to file hash (exec cmd)

View File

@ -18,6 +18,7 @@
#include "const.h" #include "const.h"
#define MAX_QPATH 64 // Must match value in quakedefs.h #define MAX_QPATH 64 // Must match value in quakedefs.h
#define MAX_RESOURCE_LIST 1280
///////////////// /////////////////
// Customization // Customization

View File

@ -37,6 +37,8 @@ void StringReplace(char *src, const char *strold, const char *strnew)
} }
} }
extern uint32 swap_endian(uint32 value);
char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash) char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash)
{ {
int len; int len;
@ -55,6 +57,7 @@ char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32
// replace key values // replace key values
StringReplace(string, "[file_name]", pResource->GetFileName()); StringReplace(string, "[file_name]", pResource->GetFileName());
StringReplace(string, "[file_hash]", UTIL_VarArgs("%x", responseHash)); StringReplace(string, "[file_hash]", UTIL_VarArgs("%x", responseHash));
StringReplace(string, "[file_md5hash]", UTIL_VarArgs("%x", swap_endian(responseHash)));
// replace of templates for identification // replace of templates for identification
StringReplace(string, "[userid]", UTIL_VarArgs("#%u", g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()))); StringReplace(string, "[userid]", UTIL_VarArgs("#%u", g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict())));
@ -62,7 +65,7 @@ char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32
StringReplace(string, "[ip]", UTIL_VarArgs("%i.%i.%i.%i", net->ip[0], net->ip[1], net->ip[2], net->ip[3])); StringReplace(string, "[ip]", UTIL_VarArgs("%i.%i.%i.%i", net->ip[0], net->ip[1], net->ip[2], net->ip[3]));
StringReplace(string, "[name]", pClient->GetName()); StringReplace(string, "[name]", pClient->GetName());
if (string != NULL && string[0] != '\0') if (string[0] != '\0')
{ {
Resource.Log(" -> ExecuteCMD: (%s), for (%s)", string, pClient->GetName()); Resource.Log(" -> ExecuteCMD: (%s), for (%s)", string, pClient->GetName());
} }
@ -111,12 +114,13 @@ void CExecMngr::CommandExecute(IGameClient *pClient)
// execute cmdexec // execute cmdexec
SERVER_COMMAND(cmdExec); SERVER_COMMAND(cmdExec);
} }
bBreak = pRes->IsBreak();
} }
// erase cmdexec // erase cmdexec
delete pExec; delete pExec;
iter = m_execList.erase(iter); iter = m_execList.erase(iter);
bBreak = (pRes->GetFileFlag() == FLAG_TYPE_BREAK);
} }
} }

View File

@ -13,6 +13,23 @@ bool OnMetaAttach()
// initialize resource config // initialize resource config
Resource.Init(); Resource.Init();
// if have already registered take it
cvar_t *pcv_consistency_prev = g_engfuncs.pfnCVarGetPointer("mp_consistency_");
if (pcv_consistency_prev != NULL)
{
pcv_consistency_old = g_engfuncs.pfnCVarGetPointer("mp_consistency");
const char *tempName = pcv_consistency_old->name;
pcv_consistency_old->name = pcv_consistency_prev->name;
pcv_consistency_prev->value = pcv_consistency_old->value;
pcv_consistency_prev->string = pcv_consistency_old->string;
pcv_consistency_prev->flags = pcv_consistency_old->flags;
pcv_consistency_prev->name = tempName;
}
else
{
// set force cvar on own value and replacement of original // 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 // 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. // so for engine set it the cvar values is 1.
@ -22,9 +39,11 @@ bool OnMetaAttach()
cv_mp_consistency.string = pcv_consistency_old->string; cv_mp_consistency.string = pcv_consistency_old->string;
cv_mp_consistency.flags = pcv_consistency_old->flags; cv_mp_consistency.flags = pcv_consistency_old->flags;
cv_mp_consistency.name = pcv_consistency_old->name; cv_mp_consistency.name = pcv_consistency_old->name;
pcv_consistency_old->name = "mp_consistency_";
pcv_consistency_old->name = STRING(ALLOC_STRING("mp_consistency_"));
g_engfuncs.pfnCVarRegister(&cv_mp_consistency); g_engfuncs.pfnCVarRegister(&cv_mp_consistency);
}
g_engfuncs.pfnCvar_DirectSet(pcv_consistency_old, "1"); g_engfuncs.pfnCvar_DirectSet(pcv_consistency_old, "1");
// to remove the old cvar of cvars list // to remove the old cvar of cvars list
@ -57,12 +76,13 @@ void OnMetaDetach()
cvar_t *pcv_mp_consistency = g_engfuncs.pfnCVarGetPointer("mp_consistency"); cvar_t *pcv_mp_consistency = g_engfuncs.pfnCVarGetPointer("mp_consistency");
// to restore the pointer address of a string // to restore the pointer address of a string
const char *tempName = pcv_consistency_old->name;
pcv_consistency_old->name = cv_mp_consistency.name; pcv_consistency_old->name = cv_mp_consistency.name;
g_engfuncs.pfnCvar_DirectSet(pcv_consistency_old, pcv_mp_consistency->string); g_engfuncs.pfnCvar_DirectSet(pcv_consistency_old, pcv_mp_consistency->string);
pcv_mp_consistency->name = tempName;
// restore old cvar mp_consistency // restore old cvar mp_consistency
cvar_t *cvar_vars = g_RehldsApi->GetFuncs()->GetCvarVars(); cvar_t *cvar_vars = g_RehldsApi->GetFuncs()->GetCvarVars();
for (cvar_t *var = cvar_vars, *prev = NULL; var != NULL; prev = var, var = var->next) for (cvar_t *var = cvar_vars, *prev = NULL; var != NULL; prev = var, var = var->next)
{ {
if (var == pcv_mp_consistency) if (var == pcv_mp_consistency)

View File

@ -4,7 +4,7 @@ plugin_info_t Plugin_info =
{ {
META_INTERFACE_VERSION, META_INTERFACE_VERSION,
"Rechecker", "Rechecker",
"1.1", "1.2",
__DATE__, __DATE__,
"s1lent", "s1lent",
"http://www.dedicated-server.ru/", "http://www.dedicated-server.ru/",
@ -30,7 +30,7 @@ C_DLLEXPORT int Meta_Query(char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMe
*pPlugInfo = &(Plugin_info); *pPlugInfo = &(Plugin_info);
gpMetaUtilFuncs = pMetaUtilFuncs; gpMetaUtilFuncs = pMetaUtilFuncs;
return 1; return TRUE;
} }
C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs) C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
@ -40,7 +40,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
if (!OnMetaAttach()) if (!OnMetaAttach())
{ {
return 0; return FALSE;
} }
gMetaFunctionTable.pfnGetEntityAPI2 = GetEntityAPI2; gMetaFunctionTable.pfnGetEntityAPI2 = GetEntityAPI2;
@ -48,11 +48,11 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS)); memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS));
return 1; return TRUE;
} }
C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{ {
OnMetaDetach(); OnMetaDetach();
return 1; return TRUE;
} }

View File

@ -159,6 +159,16 @@ void CResourceFile::Init()
pcv_rch_log = g_engfuncs.pfnCVarGetPointer(cv_rch_log.name); pcv_rch_log = g_engfuncs.pfnCVarGetPointer(cv_rch_log.name);
} }
uint32 __declspec(naked) swap_endian(uint32 value)
{
__asm
{
mov eax, dword ptr[esp + 4]
bswap eax
ret
}
}
inline uint8 hexbyte(uint8 *hex) inline uint8 hexbyte(uint8 *hex)
{ {
return ((hex[0] > '9' ? toupper(hex[0]) - 'A' + 10 : hex[0] - '0') << 4) return ((hex[0] > '9' ? toupper(hex[0]) - 'A' + 10 : hex[0] - '0') << 4)
@ -240,6 +250,7 @@ void CResourceFile::LoadResources()
char filename[MAX_PATH_LENGTH]; char filename[MAX_PATH_LENGTH];
char cmdBufExec[MAX_PATH_LENGTH]; char cmdBufExec[MAX_PATH_LENGTH];
int cline = 0; int cline = 0;
bool bBreak;
fp = fopen(m_PathDir, "r"); fp = fopen(m_PathDir, "r");
@ -261,6 +272,7 @@ void CResourceFile::LoadResources()
const char *pToken = GetNextToken(&pos); const char *pToken = GetNextToken(&pos);
argc = 0; argc = 0;
bBreak = false;
flag = FLAG_TYPE_NONE; flag = FLAG_TYPE_NONE;
memset(hash, 0, sizeof(hash)); memset(hash, 0, sizeof(hash));
@ -309,7 +321,7 @@ void CResourceFile::LoadResources()
} }
else if (_stricmp(cmdBufExec, "BREAK") == 0) else if (_stricmp(cmdBufExec, "BREAK") == 0)
{ {
flag = FLAG_TYPE_BREAK; bBreak = true;
cmdBufExec[0] = '\0'; cmdBufExec[0] = '\0';
} }
else else
@ -327,7 +339,7 @@ void CResourceFile::LoadResources()
} }
else if (_stricmp(pToken, "BREAK") == 0) else if (_stricmp(pToken, "BREAK") == 0)
{ {
flag = FLAG_TYPE_BREAK; bBreak = true;
} }
break; break;
} }
@ -368,13 +380,13 @@ void CResourceFile::LoadResources()
UTIL_Printf(__FUNCTION__ ": Failed to load \"" FILE_INI_RESOURCES "\"; parsing hash failed on line %d\n", cline); UTIL_Printf(__FUNCTION__ ": Failed to load \"" FILE_INI_RESOURCES "\"; parsing hash failed on line %d\n", cline);
continue; continue;
} }
else if (strlen(cmdBufExec) <= 0 && (flag != FLAG_TYPE_IGNORE && flag != FLAG_TYPE_BREAK)) else if (strlen(cmdBufExec) <= 0 && (flag != FLAG_TYPE_IGNORE && !bBreak))
{ {
UTIL_Printf(__FUNCTION__ ": Failed to load \"" FILE_INI_RESOURCES "\"; parsing command line is empty on line %d\n", cline); UTIL_Printf(__FUNCTION__ ": Failed to load \"" FILE_INI_RESOURCES "\"; parsing command line is empty on line %d\n", cline);
continue; continue;
} }
AddElement(filename, cmdBufExec, flag, *(uint32 *)&hash[0], cline); AddElement(filename, cmdBufExec, flag, *(uint32 *)&hash[0], cline, bBreak);
} }
else if (pToken != NULL || argc > ARG_TYPE_FILE_NAME) else if (pToken != NULL || argc > ARG_TYPE_FILE_NAME)
{ {
@ -450,9 +462,9 @@ const char *CResourceFile::GetNextToken(char **pbuf)
return res; return res;
} }
void CResourceFile::AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line) void CResourceFile::AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak)
{ {
auto nRes = new CResourceBuffer(filename, cmdExec, flag, hash, line); auto nRes = new CResourceBuffer(filename, cmdExec, flag, hash, line, bBreak);
// to mark files which are not required to add to the resource again // to mark files which are not required to add to the resource again
for (auto iter = m_resourceList.cbegin(), end = m_resourceList.cend(); iter != end; ++iter) for (auto iter = m_resourceList.cbegin(), end = m_resourceList.cend(); iter != end; ++iter)
@ -513,9 +525,6 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource
switch (typeFind) switch (typeFind)
{ {
case FLAG_TYPE_BREAK:
/* empty */
break;
case FLAG_TYPE_IGNORE: case FLAG_TYPE_IGNORE:
tempResourceList.push_back(pRes); tempResourceList.push_back(pRes);
break; break;
@ -568,13 +577,14 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource
if (hashFoundFile == NULL) if (hashFoundFile == NULL)
hashFoundFile = "null"; hashFoundFile = "null";
Log(" -> file: (%s), exphash: (%x), got: (%x), typeFind: (%d), prevhash: (%x), (%s), prevfiles: (%s), findathash: (%s)", pRes->GetFileName(), pRes->GetFileHash(), hash, typeFind, m_PrevHash, pSenderClient->GetName(), prevHashFoundFile, hashFoundFile); Log(" -> file: (%s), exphash: (%x), got: (%x), typeFind: (%d), prevhash: (%x), (%s), prevfiles: (%s), findathash: (%s), md5hex: (%x)", pRes->GetFileName(), pRes->GetFileHash(), hash, typeFind, m_PrevHash, pSenderClient->GetName(), prevHashFoundFile, hashFoundFile, swap_endian(hash));
} }
bHandled = true; bHandled = true;
} }
m_PrevHash = hash; m_PrevHash = hash;
AddFileResponse(pSenderClient, resource->szFileName, hash);
return !bHandled; return !bHandled;
} }
@ -599,7 +609,7 @@ void ClearStringsCache()
StringsCache.clear(); StringsCache.clear();
} }
CResourceBuffer::CResourceBuffer(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line) CResourceBuffer::CResourceBuffer(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak)
{ {
m_FileName = DuplicateString(filename); m_FileName = DuplicateString(filename);
m_CmdExec = (cmdExec[0] != '\0') ? DuplicateString(cmdExec) : NULL; m_CmdExec = (cmdExec[0] != '\0') ? DuplicateString(cmdExec) : NULL;
@ -609,6 +619,7 @@ CResourceBuffer::CResourceBuffer(char *filename, char *cmdExec, flag_type_resour
m_Flag = flag; m_Flag = flag;
m_FileHash = hash; m_FileHash = hash;
m_Line = line; m_Line = line;
m_Break = bBreak;
} }
CResourceFile::ResponseBuffer::ResponseBuffer(IGameClient *pSenderClient, char *filename, uint32 hash) CResourceFile::ResponseBuffer::ResponseBuffer(IGameClient *pSenderClient, char *filename, uint32 hash)

View File

@ -1,9 +1,7 @@
#pragma once #pragma once
#define FILE_INI_RESOURCES "resources.ini" #define FILE_INI_RESOURCES "resources.ini"
#define MAX_CMD_LENGTH 128 #define MAX_CMD_LENGTH 128
#define MAX_RESOURCE_LIST 1280
enum flag_type_resources enum flag_type_resources
{ {
@ -11,7 +9,6 @@ enum flag_type_resources
FLAG_TYPE_EXISTS, // to comparison with the specified hash value FLAG_TYPE_EXISTS, // to comparison with the specified hash value
FLAG_TYPE_MISSING, // check it missing file on client FLAG_TYPE_MISSING, // check it missing file on client
FLAG_TYPE_IGNORE, // ignore the specified hash value FLAG_TYPE_IGNORE, // ignore the specified hash value
FLAG_TYPE_BREAK, // do not check a next files
FLAG_TYPE_HASH_ANY, // any file with any the hash value FLAG_TYPE_HASH_ANY, // any file with any the hash value
}; };
@ -29,7 +26,7 @@ enum arg_type_e
class CResourceBuffer class CResourceBuffer
{ {
public: public:
CResourceBuffer(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line); CResourceBuffer(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak);
uint32 GetFileHash() const { return m_FileHash; }; uint32 GetFileHash() const { return m_FileHash; };
flag_type_resources GetFileFlag() const { return m_Flag; }; flag_type_resources GetFileFlag() const { return m_Flag; };
@ -38,6 +35,7 @@ public:
const char *GetCmdExec() const { return m_CmdExec; }; const char *GetCmdExec() const { return m_CmdExec; };
int GetLine() const { return m_Line; }; int GetLine() const { return m_Line; };
bool IsBreak() const { return m_Break; };
bool IsDuplicate() const { return m_Duplicate; }; bool IsDuplicate() const { return m_Duplicate; };
void SetDuplicate() { m_Duplicate = true; }; void SetDuplicate() { m_Duplicate = true; };
@ -49,7 +47,9 @@ private:
const char *m_FileName; const char *m_FileName;
const char *m_CmdExec; const char *m_CmdExec;
bool m_Duplicate;
bool m_Duplicate; // for to check for duplicate
bool m_Break; // do not check a next files
}; };
class CResourceFile class CResourceFile
@ -82,7 +82,7 @@ private:
private: private:
// for temporary files of responses // for temporary files of responses
void AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line); void AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak);
void AddFileResponse(IGameClient *pSenderClient, char *filename, uint32 hash); void AddFileResponse(IGameClient *pSenderClient, char *filename, uint32 hash);
const char *FindFilenameOfHash(uint32 hash); const char *FindFilenameOfHash(uint32 hash);
void LogPrepare(); void LogPrepare();