1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-04 14:53:12 +02:00
Files
unrealircd/src/modules/operinfo.c
T
Bram Matthys c0a46abd60 ModData API: add ModDataInfo .priority item and use it to speed up
things by making the keys with the most lookups first, e.g. "reputation",
"geoip", "certfp". This order is based on actual lookup counts during a
quick test with 250 clones doing some typical IRC traffic.

Key:		Lookups:	Position before:	After split:	After split+order:
"reputation"	20362		37			14		1
"geoip"		10555		44			15		2
"certfp"	9264		23			8		3
"webirc"	7407		27			10		4
"websocket"	7110		55			19		5

We could also consider going for a hash table, but this may be "good enough" for now.
2025-09-29 16:50:44 +02:00

102 lines
2.2 KiB
C

/*
* Store oper login in ModData, used by WHOIS and for auditting purposes.
* (C) Copyright 2021-.. Syzop and The UnrealIRCd Team
* License: GPLv2 or later
*/
#include "unrealircd.h"
ModuleHeader MOD_HEADER
= {
"operinfo",
"5.0",
"Store oper login in ModData",
"UnrealIRCd Team",
"unrealircd-6",
};
/* Forward declarations */
int operinfo_local_oper(Client *client, int up, const char *oper_block, const char *operclass);
void operinfo_free(ModData *m);
const char *operinfo_serialize(ModData *m);
void operinfo_unserialize(const char *str, ModData *m);
ModDataInfo *operlogin_md = NULL; /* Module Data structure which we acquire */
ModDataInfo *operclass_md = NULL; /* Module Data structure which we acquire */
MOD_INIT()
{
ModDataInfo mreq;
MARK_AS_OFFICIAL_MODULE(modinfo);
memset(&mreq, 0, sizeof(mreq));
mreq.name = "operlogin";
mreq.free = operinfo_free;
mreq.serialize = operinfo_serialize;
mreq.unserialize = operinfo_unserialize;
mreq.sync = MODDATA_SYNC_EARLY;
mreq.type = MODDATATYPE_CLIENT;
mreq.priority = -999993;
operlogin_md = ModDataAdd(modinfo->handle, mreq);
if (!operlogin_md)
abort();
memset(&mreq, 0, sizeof(mreq));
mreq.name = "operclass";
mreq.free = operinfo_free;
mreq.serialize = operinfo_serialize;
mreq.unserialize = operinfo_unserialize;
mreq.sync = MODDATA_SYNC_EARLY;
mreq.type = MODDATATYPE_CLIENT;
mreq.priority = -999992;
operclass_md = ModDataAdd(modinfo->handle, mreq);
if (!operclass_md)
abort();
HookAdd(modinfo->handle, HOOKTYPE_LOCAL_OPER, 0, operinfo_local_oper);
return MOD_SUCCESS;
}
MOD_LOAD()
{
return MOD_SUCCESS;
}
MOD_UNLOAD()
{
return MOD_SUCCESS;
}
int operinfo_local_oper(Client *client, int up, const char *oper_block, const char *operclass)
{
if (up)
{
moddata_client_set(client, "operlogin", oper_block);
moddata_client_set(client, "operclass", operclass);
} else {
moddata_client_set(client, "operlogin", NULL);
moddata_client_set(client, "operclass", NULL);
}
return 0;
}
void operinfo_free(ModData *m)
{
safe_free(m->str);
}
const char *operinfo_serialize(ModData *m)
{
if (!m->str)
return NULL;
return m->str;
}
void operinfo_unserialize(const char *str, ModData *m)
{
safe_strdup(m->str, str);
}