Add enable/disable_logevent() natives
This commit is contained in:
parent
ac37f8053b
commit
17a31b75d7
|
@ -26,12 +26,6 @@ enum
|
|||
// class EventsMngr
|
||||
// *****************************************************
|
||||
|
||||
enum ForwardState
|
||||
{
|
||||
FSTATE_ACTIVE,
|
||||
FSTATE_STOP
|
||||
};
|
||||
|
||||
class EventsMngr
|
||||
{
|
||||
enum MsgParamType
|
||||
|
@ -154,7 +148,7 @@ public:
|
|||
|
||||
struct EventHook
|
||||
{
|
||||
EventHook(EventsMngr::ClEvent *event) : m_event(event) {}
|
||||
explicit EventHook(EventsMngr::ClEvent *event) : m_event(event) {}
|
||||
EventsMngr::ClEvent *m_event;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "amxmodx.h"
|
||||
#include "CLogEvent.h"
|
||||
|
||||
NativeHandle<LogEventHook> LogEventHandles;
|
||||
|
||||
// *****************************************************
|
||||
// class LogEventsMngr
|
||||
// *****************************************************
|
||||
|
@ -164,18 +166,37 @@ void LogEventsMngr::parseLogString()
|
|||
}
|
||||
}
|
||||
|
||||
LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos)
|
||||
void LogEventsMngr::CLogEvent::setForwardState(ForwardState state)
|
||||
{
|
||||
m_State = state;
|
||||
}
|
||||
|
||||
int LogEventsMngr::registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos)
|
||||
{
|
||||
if (pos < 1 || pos > MAX_LOGARGS)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
arelogevents = true;
|
||||
CLogEvent** d = &logevents[pos];
|
||||
auto d = &logevents[pos];
|
||||
|
||||
while (*d)
|
||||
{
|
||||
d = &(*d)->next;
|
||||
}
|
||||
|
||||
return *d = new CLogEvent(plugin, func, this);
|
||||
auto logevent = new CLogEvent(plugin, func, this);
|
||||
auto handle = LogEventHandles.create(logevent);
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
*d = logevent;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void LogEventsMngr::executeLogEvents()
|
||||
|
@ -184,6 +205,11 @@ void LogEventsMngr::executeLogEvents()
|
|||
|
||||
for (CLogEvent* a = logevents[logArgc]; a; a = a->next)
|
||||
{
|
||||
if (a->m_State != FSTATE_ACTIVE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
valid = true;
|
||||
|
||||
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
|
||||
|
@ -227,6 +253,8 @@ void LogEventsMngr::clearLogEvents()
|
|||
}
|
||||
|
||||
clearConditions();
|
||||
|
||||
LogEventHandles.clear();
|
||||
}
|
||||
|
||||
void LogEventsMngr::clearConditions()
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define MAX_LOGARGS 12
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "natives_handles.h"
|
||||
|
||||
// *****************************************************
|
||||
// class LogEventsMngr
|
||||
|
@ -96,12 +97,15 @@ public:
|
|||
LogCond *filters;
|
||||
LogEventsMngr* parent;
|
||||
|
||||
ForwardState m_State;
|
||||
|
||||
CLogEvent *next;
|
||||
CLogEvent(CPluginMngr::CPlugin *p, int f, LogEventsMngr* ppp) : plugin(p), func(f), filters(0), parent(ppp), next(0) {}
|
||||
CLogEvent(CPluginMngr::CPlugin *p, int f, LogEventsMngr* ppp) : plugin(p), func(f), filters(nullptr), parent(ppp), m_State(FSTATE_ACTIVE), next(nullptr) {}
|
||||
~CLogEvent();
|
||||
public:
|
||||
inline CPluginMngr::CPlugin *getPlugin() { return plugin; }
|
||||
void registerFilter(char* filter);
|
||||
void setForwardState(ForwardState value);
|
||||
inline int getFunction() { return func; }
|
||||
};
|
||||
|
||||
|
@ -116,7 +120,7 @@ public:
|
|||
~LogEventsMngr();
|
||||
|
||||
// Interface
|
||||
CLogEvent* registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos);
|
||||
int registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos);
|
||||
inline bool logEventsExist() { return arelogevents; }
|
||||
|
||||
void setLogString(const char* frmt, va_list& vaptr);
|
||||
|
@ -153,4 +157,12 @@ public:
|
|||
inline iterator end() { return iterator(0, this); }
|
||||
};
|
||||
|
||||
struct LogEventHook
|
||||
{
|
||||
explicit LogEventHook(LogEventsMngr::CLogEvent *logevent) : m_logevent(logevent) {}
|
||||
LogEventsMngr::CLogEvent *m_logevent;
|
||||
};
|
||||
|
||||
extern NativeHandle<LogEventHook> LogEventHandles;
|
||||
|
||||
#endif //LOGEVENTS_H
|
||||
|
|
|
@ -3070,29 +3070,66 @@ static cell AMX_NATIVE_CALL parse_loguser(AMX *amx, cell *params)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// native register_logevent(const function[], argsnum, ...);
|
||||
static cell AMX_NATIVE_CALL register_logevent(AMX *amx, cell *params)
|
||||
{
|
||||
CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);
|
||||
int a, iFunc;
|
||||
char* temp = get_amxstring(amx, params[1], 0, a);
|
||||
int length;
|
||||
auto callback = get_amxstring(amx, params[1], 0, length);
|
||||
|
||||
iFunc = registerSPForwardByName(amx, temp, FP_DONE);
|
||||
auto forwardId = registerSPForwardByName(amx, callback, FP_DONE);
|
||||
|
||||
if (iFunc == -1)
|
||||
if (forwardId == -1)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", temp);
|
||||
LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LogEventsMngr::CLogEvent* r = g_logevents.registerLogEvent(plugin, iFunc, params[2]);
|
||||
auto handle = g_logevents.registerLogEvent(g_plugins.findPluginFast(amx), forwardId, params[2]);
|
||||
|
||||
if (r == 0)
|
||||
if (!handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int numparam = *params / sizeof(cell);
|
||||
auto logevent = LogEventHandles.lookup(handle)->m_logevent;
|
||||
auto numparam = *params / sizeof(cell);
|
||||
|
||||
for (int i = 3; i <= numparam; ++i)
|
||||
r->registerFilter(get_amxstring(amx, params[i], 0, a));
|
||||
for (auto i = 3; i <= numparam; ++i)
|
||||
{
|
||||
logevent->registerFilter(get_amxstring(amx, params[i], 0, length));
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
// native enable_logevent(handle);
|
||||
static cell AMX_NATIVE_CALL enable_logevent(AMX *amx, cell *params)
|
||||
{
|
||||
auto handle = LogEventHandles.lookup(params[1]);
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Invalid log event handle %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
handle->m_logevent->setForwardState(FSTATE_ACTIVE);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// native disable_logevent(handle);
|
||||
static cell AMX_NATIVE_CALL disable_logevent(AMX *amx, cell *params)
|
||||
{
|
||||
auto handle = LogEventHandles.lookup(params[1]);
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Invalid log event handle: %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
handle->m_logevent->setForwardState(FSTATE_STOP);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -4665,6 +4702,8 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
|
|||
{"enable_event", enable_event},
|
||||
{"disable_event", disable_event},
|
||||
{"register_logevent", register_logevent},
|
||||
{"enable_logevent", enable_logevent},
|
||||
{"disable_logevent", disable_logevent},
|
||||
{"register_menucmd", register_menucmd},
|
||||
{"register_menuid", register_menuid},
|
||||
{"register_plugin", register_plugin},
|
||||
|
|
|
@ -113,4 +113,10 @@ class NativeHandle
|
|||
}
|
||||
};
|
||||
|
||||
enum ForwardState
|
||||
{
|
||||
FSTATE_ACTIVE,
|
||||
FSTATE_STOP
|
||||
};
|
||||
|
||||
#endif // _NATIVES_NATIVES_HANDLES_H_
|
||||
|
|
|
@ -566,12 +566,32 @@ native disable_event(handle);
|
|||
* - "&" for substring comparison
|
||||
* The argument is compared to the specified string accordingly
|
||||
*
|
||||
* @return 1 on successfully registering event, 0 on failure
|
||||
* @return Log event handle
|
||||
* @error If an invalid callback function is provided, an error will
|
||||
* be thrown.
|
||||
*/
|
||||
native register_logevent(const function[], argsnum, ...);
|
||||
|
||||
/**
|
||||
* Enables a function hook of a game log event which has been previously registered with register_logevent().
|
||||
*
|
||||
* @param handle Value returned from register_logevent()
|
||||
*
|
||||
* @noreturn
|
||||
* @error If an invalid handle is provided, an error will be thrown.
|
||||
*/
|
||||
native enable_logevent(handle);
|
||||
|
||||
/**
|
||||
* Disables a function hook of a game log event which has been previously registered with register_logevent().
|
||||
*
|
||||
* @param handle Value returned from register_logevent()
|
||||
*
|
||||
* @noreturn
|
||||
* @error If an invalid handle is provided, an error will be thrown.
|
||||
*/
|
||||
native disable_logevent(handle);
|
||||
|
||||
/**
|
||||
* Sets display parameters for hudmessages.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user