1
0
mirror of https://github.com/anope/anope.git synced 2026-06-30 20:06:39 +02:00

Create and use constructors for NickInfo, NickAlias, ChannelInfo. Inherit all three from Extensible. Convert to use that instead of moduleData stuff.

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1705 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
rburchell
2008-11-15 17:55:55 +00:00
parent 5384c97c14
commit b2b0e1d235
8 changed files with 124 additions and 154 deletions
+21 -3
View File
@@ -20,6 +20,16 @@ class NickCore;
class NickAlias
{
public:
NickAlias()
{
next = prev = NULL;
nick = last_quit = last_realname = last_usermask = NULL;
time_registered = last_seen = 0;
status = 0;
nc = NULL;
u = NULL;
}
NickAlias *next, *prev;
char *nick; /* Nickname */
char *last_quit; /* Last quit message */
@@ -31,13 +41,22 @@ class NickAlias
NickCore *nc; /* I'm an alias of this */
/* Not saved */
ModuleData *moduleData; /* Module saved data attached to the nick alias */
User *u; /* Current online user that has me */
};
class NickCore
class NickCore : public Extensible
{
public:
NickCore()
{
next = prev = NULL;
display = email = greet = url = NULL;
pass[0] = '\0';
icq = flags = 0;
language = accesscount = channelcount = 0;
lastmail = 0;
}
NickCore *next, *prev;
char *display; /* How the nick is displayed */
@@ -54,7 +73,6 @@ class NickCore
uint16 channelcount; /* Number of channels currently registered */
/* Unsaved data */
ModuleData *moduleData; /* Module saved data attached to the NickCore */
time_t lastmail; /* Last time this nick record got a mail */
SList aliases; /* List of aliases */
};
+2 -58
View File
@@ -384,6 +384,7 @@ class Extensible
/* forward declarations, mostly used by older code */
class User;
class ChannelInfo;
typedef struct server_ Server;
@@ -392,7 +393,6 @@ typedef struct c_elist EList;
typedef struct c_elist_entry Entry;
typedef struct ModuleData_ ModuleData; /* ModuleData struct */
typedef struct memo_ Memo;
typedef struct chaninfo_ ChannelInfo;
typedef struct badword_ BadWord;
typedef struct bandata_ BanData;
typedef struct userdata_ UserData;
@@ -689,63 +689,7 @@ struct badword_ {
#define BW_START 2
#define BW_END 3
struct chaninfo_ {
ChannelInfo *next, *prev;
char name[CHANMAX];
NickCore *founder;
NickCore *successor; /* Who gets the channel if the founder
* nick is dropped or expires */
char founderpass[PASSMAX];
char *desc;
char *url;
char *email;
time_t time_registered;
time_t last_used;
char *last_topic; /* Last topic on the channel */
char last_topic_setter[NICKMAX]; /* Who set the last topic */
time_t last_topic_time; /* When the last topic was set */
uint32 flags; /* See below */
char *forbidby;
char *forbidreason;
int16 bantype;
int16 *levels; /* Access levels for commands */
uint16 accesscount;
ChanAccess *access; /* List of authorized users */
uint16 akickcount;
AutoKick *akick; /* List of users to kickban */
uint32 mlock_on, mlock_off; /* See channel modes below */
uint32 mlock_limit; /* 0 if no limit */
char *mlock_key; /* NULL if no key */
char *mlock_flood; /* NULL if no +f */
char *mlock_redirect; /* NULL if no +L */
char *entry_message; /* Notice sent on entering channel */
MemoInfo memos;
struct channel_ *c; /* Pointer to channel record (if *
* channel is currently in use) */
ModuleData *moduleData; /* Module saved data attached to the ChannelInfo */
/* For BotServ */
BotInfo *bi; /* Bot used on this channel */
uint32 botflags; /* BS_* below */
int16 *ttb; /* Times to ban for each kicker */
uint16 bwcount;
BadWord *badwords; /* For BADWORDS kicker */
int16 capsmin, capspercent; /* For CAPS kicker */
int16 floodlines, floodsecs; /* For FLOOD kicker */
int16 repeattimes; /* For REPEAT kicker */
};
#include "regchannel.h"
/* Retain topic even after last person leaves channel */
#define CI_KEEPTOPIC 0x00000001
+3 -4
View File
@@ -324,7 +324,7 @@ void load_cs_dbase(void)
while ((c = getc_db(f)) != 0) {
if (c != 1)
fatal("Invalid format in %s", ChanDBName);
ci = (ChannelInfo *)scalloc(sizeof(ChannelInfo), 1);
ci = new ChannelInfo();
*last = ci;
last = &ci->next;
ci->prev = prev;
@@ -1640,7 +1640,7 @@ ChannelInfo *makechan(const char *chan)
int i;
ChannelInfo *ci;
ci = (ChannelInfo *)scalloc(sizeof(ChannelInfo), 1);
ci = new ChannelInfo();
strscpy(ci->name, chan, CHANMAX);
ci->time_registered = time(NULL);
reset_levels(ci);
@@ -1806,9 +1806,8 @@ int delchan(ChannelInfo * ci)
if (debug >= 2) {
alog("debug: delchan() calling on moduleCleanStruct()");
}
moduleCleanStruct(&ci->moduleData);
free(ci);
delete ci;
if (nc)
nc->channelcount--;
+1 -1
View File
@@ -125,7 +125,7 @@ NickAlias *makenick(const char *nick)
NickCore *nc;
/* First make the core */
nc = (NickCore *)scalloc(1, sizeof(NickCore));
nc = new NickCore();
nc->display = sstrdup(nick);
slist_init(&nc->aliases);
insert_core(nc);
+1 -1
View File
@@ -405,7 +405,7 @@ NickAlias *makenick(const char *nick)
NickCore *nc;
/* First make the core */
nc = (NickCore *)scalloc(1, sizeof(NickCore));
nc = new NickCore();
nc->display = sstrdup(nick);
slist_init(&nc->aliases);
insert_core(nc);
-6
View File
@@ -1312,22 +1312,16 @@ void moduleDelAllDataMod(Module * m)
}
/* Remove the nick Cores */
for (nc = nclists[i]; nc; nc = nc->next) {
moduleDelAllData(&nc->moduleData);
/* Remove any memo data for this nick core */
for (j = 0; j < nc->memos.memocount; j++) {
moduleCleanStruct(&nc->memos.memos[j].moduleData);
}
}
/* Remove the nick Aliases */
for (na = nalists[i]; na; na = na->next) {
moduleDelAllData(&na->moduleData);
}
}
for (i = 0; i < 256; i++) {
/* Remove any chan info data */
for (ci = chanlists[i]; ci; ci = ci->next) {
moduleDelAllData(&ci->moduleData);
/* Remove any memo data for this nick core */
for (j = 0; j < ci->memos.memocount; j++) {
moduleCleanStruct(&ci->memos.memos[j].moduleData);
+90 -68
View File
@@ -199,53 +199,53 @@ class OSInfo : public Module
/* OINFO_SYNTAX */
"Syntax: OINFO [ADD|DEL] Nickname <Information>",
/* OINFO_ADD_SUCCESS */
"Eine OperInfo Linie wurde zu den Nicknamen %s hinzugefügt",
"Eine OperInfo Linie wurde zu den Nicknamen %s hinzugefgt",
/* OINFO_DEL_SUCCESS */
"Die OperInfo Linie wurde von den Nicknamen %s enfernt",
/* OCINFO_SYNTAX */
"Syntax: OINFO [ADD|DEL] Channel <Information>",
/* OCINFO_ADD_SUCCESS */
"Eine OperInfo Linie wurde zu den Channel %s hinzugefügt",
"Eine OperInfo Linie wurde zu den Channel %s hinzugefgt",
/* OCINFO_DEL_SUCCESS */
"Die OperInfo Linie wurde von den Channel %s enfernt",
/* OINFO_HELP */
"Syntax: OINFO [ADD|DEL] Nickname <Information>\n"
"Addiert oder löscht eine OperInfo Linie zu den angegebenen\n"
"Addiert oder lscht eine OperInfo Linie zu den angegebenen\n"
"Nicknamen.Sie wird angezeigt wenn ein Oper mit /ns info sich\n"
"über den Nicknamen informiert.",
"ber den Nicknamen informiert.",
/* OCINFO_HELP */
"Syntax: OINFO [ADD|DEL] chan <info>\n"
"Addiert oder löscht eine OperInfo Linie zu den angegebenen\n"
"Addiert oder lscht eine OperInfo Linie zu den angegebenen\n"
"Channel.Sie wird angezeigt wenn ein Oper mit /cs info sich\n"
"über den Channel informiert.",
"ber den Channel informiert.",
/* OINFO_HELP_CMD */
" OINFO Addiert / Löscht eine OperInfo Linie zu / von einen Nicknamen",
" OINFO Addiert / Lscht eine OperInfo Linie zu / von einen Nicknamen",
/* OCINFO_HELP_CMD */
" OINFO Addiert / Löscht eine OperInfo Linie zu / von einen Channel"
" OINFO Addiert / Lscht eine OperInfo Linie zu / von einen Channel"
};
const char* langtable_pt[] = {
/* OINFO_SYNTAX */
"Sintaxe: OINFO [ADD|DEL] nick <informação>",
"Sintaxe: OINFO [ADD|DEL] nick <informao>",
/* OINFO_ADD_SUCCESS */
"A linha OperInfo foi adicionada ao nick %s",
/* OINFO_DEL_SUCCESS */
"A linha OperInfo foi removida do nick %s",
/* OCINFO_SYNTAX */
"Sintaxe: OINFO [ADD|DEL] canal <informação>",
"Sintaxe: OINFO [ADD|DEL] canal <informao>",
/* OCINFO_ADD_SUCCESS */
"A linha OperInfo foi adicionada ao canal %s",
/* OCINFO_DEL_SUCCESS */
"A linha OperInfo foi removida do canal %s",
/* OINFO_HELP */
"Sintaxe: OINFO [ADD|DEL] nick <informação>\n"
"Adiciona ou apaga informação para Operadores ao nick fornecido\n"
"Isto será mostrado quando qualquer Operador usar /ns info nick\n"
"e pode ser usado para 'etiquetar' usuários etc...",
"Sintaxe: OINFO [ADD|DEL] nick <informao>\n"
"Adiciona ou apaga informao para Operadores ao nick fornecido\n"
"Isto ser mostrado quando qualquer Operador usar /ns info nick\n"
"e pode ser usado para 'etiquetar' usurios etc...",
/* OCINFO_HELP */
"Sintaxe: OINFO [ADD|DEL] canal <informação>\n"
"Adiciona ou apaga informação para Operadores ao canal fornecido\n"
"Isto será mostrado quando qualquer Operador usar /cs info canal\n"
"Sintaxe: OINFO [ADD|DEL] canal <informao>\n"
"Adiciona ou apaga informao para Operadores ao canal fornecido\n"
"Isto ser mostrado quando qualquer Operador usar /cs info canal\n"
"e pode ser usado para 'etiquetar' canais etc...",
/* OINFO_HELP_CMD */
" OINFO Adiciona ou Apaga a linha OperInfo para um nick",
@@ -255,31 +255,31 @@ class OSInfo : public Module
const char* langtable_ru[] = {
/* OINFO_SYNTAX */
"Ñèíòàêñèñ: OINFO ADD|DEL íèê òåñò",
": OINFO ADD|DEL ",
/* OINFO_ADD_SUCCESS */
"Îïåð-Èíôîðìàöèÿ äëÿ íèêà %s äîáàâëåíà",
"- %s ",
/* OINFO_DEL_SUCCESS */
"Îïåð-Èíôîðìàöèÿ äëÿ íèêà %s áûëà óäàëåíà",
"- %s ",
/* OCINFO_SYNTAX */
"Ñèíòàêñèñ: OINFO ADD|DEL #êàíàë òåêñò",
": OINFO ADD|DEL # ",
/* OCINFO_ADD_SUCCESS */
"Îïåð-Èíôîðìàöèÿ äëÿ êàíàëà %s óñïåøíî óñòàíîâëåíà",
"- %s ",
/* OCINFO_DEL_SUCCESS */
"Îïåð-Èíôîðìàöèÿ äëÿ êàíàëà %s áûëà óäàëåíà",
"- %s ",
/* OINFO_HELP */
"Ñèíòàêñèñ: OINFO ADD|DEL íèê òåêñò\n"
"Óñòàíàâëèâàåò èëè óäàëÿåò Îïåð-Èíôîðìàöèþ äëÿ óêàçàííîãî íèêà,\n"
"êîòîðàÿ áóäåò ïîêàçàíà ëþáîìó îïåðàòîðó, çàïðàøèâàþùåìó INFO íèêà.\n"
"Ìîæåò áûòü èñïîëüçîâàíà äëÿ 'ïîìåòêè' ïîëüçîâàòåëåé è ò. ä...",
": OINFO ADD|DEL  \n"
" - ,\n"
" , INFO .\n"
" '' . ...",
/* OCINFO_HELP */
"Ñèíòàêñèñ: OINFO ADD|DEL #êàíàë òåêñò\n"
"Óñòàíàâëèâàåò èëè óäàëÿåò Îïåð-Èíôîðìàöèþ äëÿ óêàçàííîãî êàíàëà,\n"
"êîòîðàÿ áóäåò ïîêàçàíà ëþáîìó îïåðàòîðó, çàïðàøèâàþùåìó INFO êàíàëà.\n"
"Ìîæåò áûòü èñïîëüçîâàíà äëÿ 'ïîìåòêè' êàíàëîâ è ò. ä...",
": OINFO ADD|DEL # \n"
" - ,\n"
" , INFO .\n"
" '' . ...",
/* OINFO_HELP_CMD */
" OINFO Äîáàâëÿåò/Óäàëÿåò îïåð-èíôî äëÿ íèêà",
" OINFO / - ",
/* OCINFO_HELP_CMD */
" OINFO Äîáàâëÿåò/Óäàëÿåò îïåð-èíôî äëÿ êàíàëà"
" OINFO / - "
};
const char* langtable_it[] = {
@@ -323,7 +323,20 @@ class OSInfo : public Module
~OSInfo()
{
char *av[1];
for (int i = 0; i < 1024; i++)
{
/* Remove the nick Cores */
for (NickCore *nc = nclists[i]; nc; nc = nc->next)
{
char *c;
if (nc->GetExt("os_modinfo", c));
{
free(c);
nc->Shrink("os_modinfo");
}
}
}
av[0] = sstrdup(EVENT_START);
mSaveData(1, av);
free(av[0]);
@@ -369,9 +382,8 @@ int myAddNickInfo(User * u)
/* ok we've found the user */
if ((na = findnick(nick))) {
/* Add the module data to the user */
moduleAddData(&na->nc->moduleData, "info", info);
moduleNoticeLang(s_NickServ, u,
OINFO_ADD_SUCCESS, nick);
na->nc->Extend("os_info", strdup(info));
moduleNoticeLang(s_NickServ, u, OINFO_ADD_SUCCESS, nick);
/* NickCore not found! */
} else {
notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED,
@@ -381,10 +393,16 @@ int myAddNickInfo(User * u)
}
} else if (strcasecmp(cmd, "DEL") == 0) {
/* ok we've found the user */
if ((na = findnick(nick))) {
moduleDelData(&na->nc->moduleData, "info");
moduleNoticeLang(s_NickServ, u,
OINFO_DEL_SUCCESS, nick);
if ((na = findnick(nick)))
{
char *c;
if (na->nc->GetExt("os_info", c))
{
free(c);
na->nc->Shrink("os_info");
}
moduleNoticeLang(s_NickServ, u, OINFO_DEL_SUCCESS, nick);
/* NickCore not found! */
} else {
notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED,
@@ -437,9 +455,8 @@ int myAddChanInfo(User * u)
if (info) {
if ((ci = cs_findchan(chan))) {
/* Add the module data to the channel */
moduleAddData(&ci->moduleData, "info", info);
moduleNoticeLang(s_ChanServ, u,
OCINFO_ADD_SUCCESS, chan);
ci->Extend("os_info", strdup(info));
moduleNoticeLang(s_ChanServ, u, OCINFO_ADD_SUCCESS, chan);
/* ChanInfo */
} else {
notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED,
@@ -450,9 +467,13 @@ int myAddChanInfo(User * u)
} else if (strcasecmp(cmd, "DEL") == 0) {
if ((ci = cs_findchan(chan))) {
/* Del the module data from the channel */
moduleDelData(&ci->moduleData, "info");
moduleNoticeLang(s_ChanServ, u,
OCINFO_DEL_SUCCESS, chan);
char *c;
if (ci->GetExt("os_info", c))
{
free(c);
ci->Shrink("os_info");
}
moduleNoticeLang(s_ChanServ, u, OCINFO_DEL_SUCCESS, chan);
/* ChanInfo */
} else {
notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED,
@@ -487,7 +508,6 @@ int myNickInfo(User * u)
{
char *text = NULL;
char *nick = NULL;
char *info = NULL;
NickAlias *na = NULL;
/* Only show our goodies to opers */
@@ -500,9 +520,10 @@ int myNickInfo(User * u)
/* ok we've found the user */
if ((na = findnick(nick))) {
/* If we have any info on this user */
if ((info = moduleGetData(&na->nc->moduleData, "info"))) {
notice_user(s_NickServ, u, " OperInfo: %s", info);
free(info);
char *c;
if (na->nc->GetExt("os_info", c))
{
notice_user(s_NickServ, u, " OperInfo: %s", c);
}
/* NickCore not found! */
} else {
@@ -524,7 +545,6 @@ int myChanInfo(User * u)
{
char *text = NULL;
char *chan = NULL;
char *info = NULL;
ChannelInfo *ci = NULL;
/* Only show our goodies to opers */
@@ -536,9 +556,10 @@ int myChanInfo(User * u)
if (chan) {
if ((ci = cs_findchan(chan))) {
/* If we have any info on this channel */
if ((info = moduleGetData(&ci->moduleData, "info"))) {
notice_user(s_ChanServ, u, " OperInfo: %s", info);
free(info);
char *c;
if (ci->GetExt("os_info", c))
{
notice_user(s_ChanServ, u, " OperInfo: %s", c);
}
}
free(chan);
@@ -584,14 +605,14 @@ int mLoadData(void)
/* Take the \n from the end of the line */
info[len - 1] = '\0';
if (stricmp(type, "C") == 0) {
if ((ci = cs_findchan(name))) {
moduleAddData(&ci->moduleData, "info",
info);
if ((ci = cs_findchan(name)))
{
ci->Extend("os_info", strdup("info"));
}
} else if (stricmp(type, "N") == 0) {
if ((na = findnick(name))) {
moduleAddData(&na->nc->moduleData, "info",
info);
if ((na = findnick(name)))
{
na->nc->Extend("os_info", strdup(info));
}
}
free(info);
@@ -619,7 +640,6 @@ int mSaveData(int argc, char **argv)
int i = 0;
int ret = 0;
FILE *out;
char *info = NULL;
if (argc >= 1) {
if (!stricmp(argv[0], EVENT_START)) {
@@ -632,9 +652,10 @@ int mSaveData(int argc, char **argv)
for (i = 0; i < 1024; i++) {
for (nc = nclists[i]; nc; nc = nc->next) {
/* If we have any info on this user */
if ((info = moduleGetData(&nc->moduleData, "info"))) {
fprintf(out, "N %s %s\n", nc->display, info);
free(info);
char *c;
if (nc->GetExt("os_info", c))
{
fprintf(out, "N %s %s\n", nc->display, c);
}
}
}
@@ -643,9 +664,10 @@ int mSaveData(int argc, char **argv)
for (i = 0; i < 256; i++) {
for (ci = chanlists[i]; ci; ci = ci->next) {
/* If we have any info on this channel */
if ((info = moduleGetData(&ci->moduleData, "info"))) {
fprintf(out, "C %s %s\n", ci->name, info);
free(info);
char *c;
if (ci->GetExt("os_info", c))
{
fprintf(out, "C %s %s\n", ci->name, c);
}
}
}
+6 -13
View File
@@ -197,7 +197,7 @@ void load_old_ns_dbase(void)
if (c != 1)
fatal("Invalid format in %s", NickDBName);
na = (NickAlias *)scalloc(sizeof(NickAlias), 1);
na = new NickAlias();
SAFE(read_buffer(bufn, f));
na->nick = sstrdup(bufn);
@@ -268,7 +268,7 @@ void load_old_ns_dbase(void)
/* This nick was a master nick, so it also has all the
* core info! =)
*/
nc = (NickCore *)scalloc(1, sizeof(NickCore));
nc = new NickCore();
slist_init(&nc->aliases);
/* The initial display is what used to be the master nick */
@@ -479,7 +479,7 @@ void load_ns_dbase(void)
if (c != 1)
fatal("Invalid format in %s", NickDBName);
nc = (NickCore *)scalloc(1, sizeof(NickCore));
nc = new NickCore();
*nclast = nc;
nclast = &nc->next;
nc->prev = ncprev;
@@ -565,7 +565,7 @@ void load_ns_dbase(void)
if (c != 1)
fatal("Invalid format in %s", NickDBName);
na = (NickAlias *)scalloc(1, sizeof(NickAlias));
na = new NickAlias();
SAFE(read_string(&na->nick, f));
@@ -1262,10 +1262,7 @@ static int delcore(NickCore * nc)
free(nc->memos.memos);
}
moduleCleanStruct(&nc->moduleData);
free(nc);
delete nc;
return 1;
}
@@ -1346,11 +1343,7 @@ int delnick(NickAlias * na)
if (na->last_quit)
free(na->last_quit);
moduleCleanStruct(&na->moduleData);
free(na);
delete na;
return 1;
}