Eluna fix crash in timed events and prepare some for future changes. Ditched EventProcessor

This commit is contained in:
Rochet2
2014-09-13 16:05:16 +03:00
parent 7be917335a
commit 06be9650bb
12 changed files with 388 additions and 346 deletions

View File

@@ -692,6 +692,16 @@ namespace LuaGlobalFunctions
return 0;
}
/**
* Registers a global timed event
* When the passed function is called, the parameters `(eventId, delay, repeats)` are passed to it.
* Repeats will decrease on each call if the event does not repeat indefinitely
*
* @param function function : function to trigger when the time has passed
* @param uint32 delay : set time in milliseconds for the event to trigger
* @param uint32 repeats : how many times for the event to repeat, 0 is infinite
* @return int eventId : unique ID for the timed event used to cancel it or nil
*/
int CreateLuaEvent(lua_State* L)
{
luaL_checktype(L, 1, LUA_TFUNCTION);
@@ -700,34 +710,47 @@ namespace LuaGlobalFunctions
lua_pushvalue(L, 1);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
functionRef = sEluna->m_EventMgr->AddEvent(&sEluna->m_EventMgr->GlobalEvents, functionRef, delay, repeats);
if (functionRef)
if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF)
{
sEluna->eventMgr->globalProcessor->AddEvent(functionRef, delay, repeats);
Eluna::Push(L, functionRef);
else
Eluna::Push(L);
}
return 1;
}
/**
* Removes a global timed event specified by the event ID
*
* @param int eventId : event Id to remove
* @param bool all_Events = false : remove from all events, not just global
*/
int RemoveEventById(lua_State* L)
{
int eventId = Eluna::CHECKVAL<int>(L, 1);
bool all_Events = Eluna::CHECKVAL<bool>(L, 1, false);
// not thread safe
if (all_Events)
sEluna->m_EventMgr->RemoveEvent(eventId);
sEluna->eventMgr->RemoveEvent(eventId);
else
sEluna->m_EventMgr->RemoveEvent(&sEluna->m_EventMgr->GlobalEvents, eventId);
sEluna->eventMgr->globalProcessor->RemoveEvent(eventId);
return 0;
}
/**
* Removes all global timed events
*
* @param bool all_Events = false : remove all events, not just global
*/
int RemoveEvents(lua_State* L)
{
bool all_Events = Eluna::CHECKVAL<bool>(L, 1, false);
// not thread safe
if (all_Events)
sEluna->m_EventMgr->RemoveEvents();
sEluna->eventMgr->RemoveEvents();
else
sEluna->m_EventMgr->GlobalEvents.KillAllEvents(true);
sEluna->eventMgr->globalProcessor->RemoveEvents();
return 0;
}
@@ -1153,25 +1176,25 @@ namespace LuaGlobalFunctions
switch (banMode)
{
case BAN_ACCOUNT:
case BAN_ACCOUNT:
#ifdef CATA
if (!Utf8ToUpperOnlyLatin(nameOrIP))
return 0;
if (!Utf8ToUpperOnlyLatin(nameOrIP))
return 0;
#else
if (!AccountMgr::normalizeString(nameOrIP))
return 0;
if (!AccountMgr::normalizeString(nameOrIP))
return 0;
#endif
break;
case BAN_CHARACTER:
if (!normalizePlayerName(nameOrIP))
break;
case BAN_CHARACTER:
if (!normalizePlayerName(nameOrIP))
return 0;
break;
case BAN_IP:
if (!IsIPAddress(nameOrIP.c_str()))
return 0;
break;
default:
return 0;
break;
case BAN_IP:
if (!IsIPAddress(nameOrIP.c_str()))
return 0;
break;
default:
return 0;
}
eWorld->BanAccount((BanMode)banMode, nameOrIP, duration, reason, whoBanned);