-
Notifications
You must be signed in to change notification settings - Fork 0
greeter
Justin Schwartz edited this page Jun 27, 2020
·
1 revision
A simple module that greets people when they connect to the zone. Notable example of how much overhead is reduced when making very small module, even if you don't count the fleshed-out error handling as something you'd normally do.
$#module greeter
$#callback global CB_PLAYERACTION
void paction(Player *p, int action, Arena *a)
{
if (action == PA_CONNECT)
chat->SendMessage(p, "Greetings, human.");
}
$#endcallback
#include "asss.h"
local Imodman *mm;
local Ilogman *lm = 0;
local Ichat *chat = 0;
local void paction(Player *p, int action, Arena *a);
void paction(Player *p, int action, Arena *a)
{
if (action == PA_CONNECT)
chat->SendMessage(p, "Greetings, human.");
}
EXPORT int MM_greeter(int action, Imodman *_mm, Arena *arena)
{
int failedLoad = FALSE;
if (action == MM_LOAD)
{
mm = _mm;
lm = mm->GetInterface(I_LOGMAN, ALLARENAS);
if (!lm)
return MM_FAIL;
chat = mm->GetInterface(I_CHAT, ALLARENAS);
if (!chat)
{
lm->Log(L_ERROR, "<greeter> error obtaining required interface I_CHAT " I_CHAT);
failedLoad = TRUE;
goto ace_fail_load;
}
mm->RegCallback(CB_PLAYERACTION, paction, ALLARENAS);
return MM_OK;
}
else if (action == MM_UNLOAD)
{
mm->UnregCallback(CB_PLAYERACTION, paction, ALLARENAS);
ace_fail_load:
mm->ReleaseInterface(lm);
mm->ReleaseInterface(chat);
if (failedLoad)
return MM_FAIL;
else
return MM_OK;
}
return MM_FAIL;
}