Rename CPlugin::SetErrorState to EvictWithError.
This commit is contained in:
parent
c4c6efb140
commit
82ff7d5af7
@ -59,7 +59,7 @@ public:
|
|||||||
virtual AutoConfig *GetConfig(size_t i) = 0;
|
virtual AutoConfig *GetConfig(size_t i) = 0;
|
||||||
virtual void AddLibrary(const char *name) = 0;
|
virtual void AddLibrary(const char *name) = 0;
|
||||||
virtual void AddConfig(bool create, const char *cfg, const char *folder) = 0;
|
virtual void AddConfig(bool create, const char *cfg, const char *folder) = 0;
|
||||||
virtual void SetErrorState(PluginStatus status, const char *fmt, ...) = 0;
|
virtual void EvictWithError(PluginStatus status, const char *fmt, ...) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IScriptManager
|
class IScriptManager
|
||||||
|
@ -143,7 +143,7 @@ CPlugin *CPlugin::Create(const char *file)
|
|||||||
CPlugin *pPlugin = new CPlugin(file);
|
CPlugin *pPlugin = new CPlugin(file);
|
||||||
|
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
pPlugin->SetErrorState(Plugin_BadLoad, "Unable to open file");
|
pPlugin->EvictWithError(Plugin_BadLoad, "Unable to open file");
|
||||||
return pPlugin;
|
return pPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ IPluginRuntime *CPlugin::GetRuntime()
|
|||||||
return m_pRuntime;
|
return m_pRuntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...)
|
void CPlugin::EvictWithError(PluginStatus status, const char *error_fmt, ...)
|
||||||
{
|
{
|
||||||
if (m_status == Plugin_Running)
|
if (m_status == Plugin_Running)
|
||||||
{
|
{
|
||||||
@ -265,7 +265,7 @@ bool CPlugin::ReadInfo()
|
|||||||
}
|
}
|
||||||
if (m_FileVersion > 5) {
|
if (m_FileVersion > 5) {
|
||||||
base->LocalToString(info->filevers, (char **)&pFileVers);
|
base->LocalToString(info->filevers, (char **)&pFileVers);
|
||||||
SetErrorState(Plugin_Failed, "Newer SourceMod required (%s or higher)", pFileVers);
|
EvictWithError(Plugin_Failed, "Newer SourceMod required (%s or higher)", pFileVers);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -311,7 +311,7 @@ void CPlugin::Call_OnPluginStart()
|
|||||||
int err;
|
int err;
|
||||||
if ((err=pFunction->Execute(&result)) != SP_ERROR_NONE)
|
if ((err=pFunction->Execute(&result)) != SP_ERROR_NONE)
|
||||||
{
|
{
|
||||||
SetErrorState(Plugin_Error, "Error detected in plugin startup (see error logs)");
|
EvictWithError(Plugin_Error, "Error detected in plugin startup (see error logs)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ APLRes CPlugin::AskPluginLoad()
|
|||||||
pFunction->PushStringEx(m_errormsg, sizeof(m_errormsg), 0, SM_PARAM_COPYBACK);
|
pFunction->PushStringEx(m_errormsg, sizeof(m_errormsg), 0, SM_PARAM_COPYBACK);
|
||||||
pFunction->PushCell(sizeof(m_errormsg));
|
pFunction->PushCell(sizeof(m_errormsg));
|
||||||
if ((err = pFunction->Execute(&result)) != SP_ERROR_NONE) {
|
if ((err = pFunction->Execute(&result)) != SP_ERROR_NONE) {
|
||||||
SetErrorState(Plugin_Failed, "unexpected error %d in AskPluginLoad callback", err);
|
EvictWithError(Plugin_Failed, "unexpected error %d in AskPluginLoad callback", err);
|
||||||
return APLRes_Failure;
|
return APLRes_Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +435,7 @@ bool CPlugin::TryCompile()
|
|||||||
char loadmsg[255];
|
char loadmsg[255];
|
||||||
m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg));
|
m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg));
|
||||||
if (!m_pRuntime) {
|
if (!m_pRuntime) {
|
||||||
SetErrorState(Plugin_BadLoad, "Unable to load plugin (%s)", loadmsg);
|
EvictWithError(Plugin_BadLoad, "Unable to load plugin (%s)", loadmsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,7 +634,7 @@ void CPlugin::DependencyDropped(CPlugin *pOwner)
|
|||||||
/* :IDEA: in the future, add native trapping? */
|
/* :IDEA: in the future, add native trapping? */
|
||||||
if (m_FakeNativesMissing || m_LibraryMissing)
|
if (m_FakeNativesMissing || m_LibraryMissing)
|
||||||
{
|
{
|
||||||
SetErrorState(Plugin_Error, "Depends on plugin: %s", pOwner->GetFilename());
|
EvictWithError(Plugin_Error, "Depends on plugin: %s", pOwner->GetFilename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -990,7 +990,7 @@ void CPluginManager::LoadAll_SecondPass()
|
|||||||
if (!RunSecondPass(pPlugin, error, sizeof(error)))
|
if (!RunSecondPass(pPlugin, error, sizeof(error)))
|
||||||
{
|
{
|
||||||
g_Logger.LogError("[SM] Unable to load plugin \"%s\": %s", pPlugin->GetFilename(), error);
|
g_Logger.LogError("[SM] Unable to load plugin \"%s\": %s", pPlugin->GetFilename(), error);
|
||||||
pPlugin->SetErrorState(Plugin_BadLoad, "%s", error);
|
pPlugin->EvictWithError(Plugin_BadLoad, "%s", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1208,9 +1208,9 @@ bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin)
|
|||||||
|
|
||||||
if (m_bBlockBadPlugins) {
|
if (m_bBlockBadPlugins) {
|
||||||
if (bulletinUrl[0] != '\0') {
|
if (bulletinUrl[0] != '\0') {
|
||||||
pPlugin->SetErrorState(Plugin_BadLoad, "Known malware detected and blocked. See %s for more info", bulletinUrl);
|
pPlugin->EvictWithError(Plugin_BadLoad, "Known malware detected and blocked. See %s for more info", bulletinUrl);
|
||||||
} else {
|
} else {
|
||||||
pPlugin->SetErrorState(Plugin_BadLoad, "Possible malware or illegal plugin detected and blocked");
|
pPlugin->EvictWithError(Plugin_BadLoad, "Possible malware or illegal plugin detected and blocked");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1322,7 +1322,7 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
pPlugin->SetErrorState(Plugin_Error, "Library not found: %s", lib);
|
pPlugin->EvictWithError(Plugin_Error, "Library not found: %s", lib);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
found->AddDependent(pPlugin);
|
found->AddDependent(pPlugin);
|
||||||
@ -1345,7 +1345,7 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin)
|
|||||||
native->name[0] != '@' &&
|
native->name[0] != '@' &&
|
||||||
!(native->flags & SP_NTVFLAG_OPTIONAL))
|
!(native->flags & SP_NTVFLAG_OPTIONAL))
|
||||||
{
|
{
|
||||||
pPlugin->SetErrorState(Plugin_Error, "Native not found: %s", native->name);
|
pPlugin->EvictWithError(Plugin_Error, "Native not found: %s", native->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,10 +131,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
// Evicts the plugin from memory and sets an error state.
|
||||||
* Sets an error state on the plugin
|
void EvictWithError(PluginStatus status, const char *error_fmt, ...);
|
||||||
*/
|
|
||||||
void SetErrorState(PluginStatus status, const char *error_fmt, ...);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the plugin's identity information
|
* Initializes the plugin's identity information
|
||||||
|
@ -390,7 +390,7 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
|
|||||||
|
|
||||||
if (params[0] == 1)
|
if (params[0] == 1)
|
||||||
{
|
{
|
||||||
pPlugin->SetErrorState(Plugin_Failed, "%s", str);
|
pPlugin->EvictWithError(Plugin_Failed, "%s", str);
|
||||||
|
|
||||||
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str);
|
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str);
|
||||||
}
|
}
|
||||||
@ -402,10 +402,10 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
|
|||||||
DetectExceptions eh(pContext);
|
DetectExceptions eh(pContext);
|
||||||
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1);
|
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1);
|
||||||
if (eh.HasException()) {
|
if (eh.HasException()) {
|
||||||
pPlugin->SetErrorState(Plugin_Failed, "%s", str);
|
pPlugin->EvictWithError(Plugin_Failed, "%s", str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pPlugin->SetErrorState(Plugin_Failed, "%s", buffer);
|
pPlugin->EvictWithError(Plugin_Failed, "%s", buffer);
|
||||||
pContext->ReportFatalError("%s", buffer);
|
pContext->ReportFatalError("%s", buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -674,7 +674,7 @@ static cell_t RequireFeature(IPluginContext *pContext, const cell_t *params)
|
|||||||
g_pSM->Format(default_message, sizeof(default_message), "Feature \"%s\" not available", name);
|
g_pSM->Format(default_message, sizeof(default_message), "Feature \"%s\" not available", name);
|
||||||
msg = default_message;
|
msg = default_message;
|
||||||
}
|
}
|
||||||
pPlugin->SetErrorState(Plugin_Error, "%s", msg);
|
pPlugin->EvictWithError(Plugin_Error, "%s", msg);
|
||||||
|
|
||||||
if (!eh.HasException())
|
if (!eh.HasException())
|
||||||
pContext->ReportFatalError("%s", msg);
|
pContext->ReportFatalError("%s", msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user