Cstrike: Remove parsing error and update native error message

This commit is contained in:
Arkshine 2015-09-05 14:28:26 +02:00
parent e87976bc09
commit b6910667a8
4 changed files with 31 additions and 41 deletions

View File

@ -12,21 +12,20 @@
//
#include "CstrikeItemsInfos.h"
#include <amxxmodule.h>
CsItemInfo ItemsManager;
#define PSTATE_NONE
#define PSTATE_ALIASES_TYPE 0
#define PSTATE_ALIASES_ALIAS 1
#define PSTATE_ALIASES_ALIAS_DEFS 2
CsItemInfo::CsItemInfo()
:
m_ParseState(0),
CsItemInfo::CsItemInfo()
:
m_ParseState(PSTATE_ALIASES_TYPE),
m_List(nullptr),
m_ListsRetrievedFromConfig(false)
{
}
{}
CsItemInfo::~CsItemInfo()
{
@ -61,16 +60,16 @@ SMCResult CsItemInfo::ReadSMC_NewSection(const SMCStates *states, const char *na
{
m_List = &m_WeaponAliasesList;
}
else if (strstr(name, "Buy"))
else if (!strcmp(name, "Buy") || !strcmp(name, "BuyEquip") || !strcmp(name, "BuyAmmo"))
{
m_List = &m_BuyAliasesList;
}
else
if (m_List)
{
return SMCResult_HaltFail;
m_ParseState = PSTATE_ALIASES_ALIAS;
}
m_ParseState = PSTATE_ALIASES_ALIAS;
break;
}
case PSTATE_ALIASES_ALIAS:
@ -114,10 +113,6 @@ SMCResult CsItemInfo::ReadSMC_KeyValue(const SMCStates *states, const char *key,
{
m_AliasInfo.classname = value;
}
else
{
return SMCResult_HaltFail;
}
break;
}
}
@ -138,7 +133,7 @@ SMCResult CsItemInfo::ReadSMC_LeavingSection(const SMCStates *states)
{
m_List->replace(m_Alias.chars(), m_AliasInfo);
m_WeaponIdToClass[m_AliasInfo.itemid] = static_cast<CsWeaponClassType>(m_AliasInfo.classid);
m_AliasInfo.clear();
m_ParseState = PSTATE_ALIASES_ALIAS;
@ -151,13 +146,10 @@ SMCResult CsItemInfo::ReadSMC_LeavingSection(const SMCStates *states)
void CsItemInfo::ReadSMC_ParseEnd(bool halted, bool failed)
{
if (halted)
if (!halted && !failed)
{
MF_Log("Invalid or missing key in \"%s\" section. Please check your gamedata files.", m_Alias.chars());
return;
m_ListsRetrievedFromConfig = true;
}
m_ListsRetrievedFromConfig = true;
}
bool CsItemInfo::GetAliasInfos(const char *alias, AliasInfo *info)
@ -238,4 +230,4 @@ CsWeaponClassType CsItemInfo::WeaponIdToClass(int id)
}
return CS_WEAPONCLASS_NONE;
}
}

View File

@ -16,6 +16,7 @@
#include "CstrikeDatas.h"
#include <ITextParsers.h>
#include <am-string.h>
#include <sm_stringhashmap.h>
struct AliasInfo
@ -49,14 +50,14 @@ class CsItemInfo : public ITextListener_SMC
bool HasConfigError();
public:
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
SMCResult ReadSMC_LeavingSection(const SMCStates *states);
void ReadSMC_ParseEnd(bool halted, bool failed);
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name) override;
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value) override;
SMCResult ReadSMC_LeavingSection(const SMCStates *states) override;
void ReadSMC_ParseEnd(bool halted, bool failed) override;
public:
bool GetAliasInfos(const char *alias, AliasInfo *info);
bool GetAliasInfosFromBuy(const char *alias, AliasInfo *info);
bool GetAliasInfosFromName(const char *classname, AliasInfo *info);

View File

@ -38,20 +38,17 @@ void OnAmxxAttach()
ConfigManager = MF_GetConfigManager();
char error[256];
error[0] = '\0';
char error[256] = "";
ConfigManager->AddUserConfigHook("CommandsAliases", &ItemsManager);
if (!ConfigManager->LoadGameConfigFile("modules.games", &MainConfig, error, sizeof(error)) && error[0] != '\0')
if (!ConfigManager->LoadGameConfigFile("modules.games", &MainConfig, error, sizeof(error)) && *error)
{
MF_Log("Could not read module.games gamedata: %s", error);
return;
}
error[0] = '\0';
if (!ConfigManager->LoadGameConfigFile("common.games", &CommonConfig, error, sizeof(error)) && error[0] != '\0')
*error = '\0';
if (!ConfigManager->LoadGameConfigFile("common.games", &CommonConfig, error, sizeof(error)) && *error)
{
MF_Log("Could not read common.games gamedata: %s", error);
return;

View File

@ -1081,7 +1081,7 @@ static cell AMX_NATIVE_CALL cs_set_no_knives(AMX *amx, cell *params)
{
if (!GiveDefaultItemsDetour)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_set_no_knives() is disabled");
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_set_no_knives() is disabled. Check your amxx logs.");
return 0;
}
@ -1700,7 +1700,7 @@ static cell AMX_NATIVE_CALL cs_create_entity(AMX* amx, cell* params)
{
if (CS_CreateNamedEntity <= 0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_create_entity() is disabled");
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_create_entity() is disabled. Check your amxx logs.");
return 0;
}
@ -1722,7 +1722,7 @@ static cell AMX_NATIVE_CALL cs_find_ent_by_class(AMX* amx, cell* params)
{
if (CS_UTIL_FindEntityByString <= 0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_find_ent_by_class() is disabled");
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_find_ent_by_class() is disabled. Check your amxx logs.");
return 0;
}
@ -1745,7 +1745,7 @@ static cell AMX_NATIVE_CALL cs_find_ent_by_owner(AMX* amx, cell* params)
{
if (CS_UTIL_FindEntityByString <= 0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_find_ent_by_owner() is disabled");
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_find_ent_by_owner() is disabled. Check your amxx logs.");
return 0;
}
@ -1781,7 +1781,7 @@ static cell AMX_NATIVE_CALL cs_get_item_id(AMX* amx, cell* params)
{
if (ItemsManager.HasConfigError())
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_get_item_id() is disabled");
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_get_item_id() is disabled disabled because of missing gamedata");
return 0;
}
@ -1808,7 +1808,7 @@ static cell AMX_NATIVE_CALL cs_get_translated_item_alias(AMX* amx, cell* params)
{
if (ItemsManager.HasConfigError())
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_get_translated_item_alias() is disabled");
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_get_translated_item_alias() is disabled because of missing gamedata");
return 0;
}
@ -1851,7 +1851,7 @@ static cell AMX_NATIVE_CALL cs_get_weapon_info(AMX* amx, cell* params)
{
if (GetWeaponInfo <= 0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_get_weapon_info() is disabled");
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_get_weapon_info() is disabled. Check your amxx logs.");
return 0;
}