diff options
| author | Adam <Adam@Anope.org> | 2010-05-24 23:36:40 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2010-06-18 21:04:05 -0400 |
| commit | 2fba686904e6f78ebab35df171c5757afeebf05d (patch) | |
| tree | 523782bccc479606206f271cd6708b2f70fe8278 /src/core | |
| parent | 3a2c2a916a26f4fa1844e71a9f1c2fc25337fd2b (diff) | |
Burned slist, rewrote operservs XLine code
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/bs_bot.c | 15 | ||||
| -rw-r--r-- | src/core/cs_drop.c | 3 | ||||
| -rw-r--r-- | src/core/cs_forbid.c | 3 | ||||
| -rw-r--r-- | src/core/db_plain.cpp | 99 | ||||
| -rw-r--r-- | src/core/hs_delall.c | 8 | ||||
| -rw-r--r-- | src/core/ns_drop.c | 5 | ||||
| -rw-r--r-- | src/core/ns_forbid.c | 5 | ||||
| -rw-r--r-- | src/core/ns_group.c | 20 | ||||
| -rw-r--r-- | src/core/ns_saset.c | 14 | ||||
| -rw-r--r-- | src/core/ns_set.c | 18 | ||||
| -rw-r--r-- | src/core/ns_suspend.c | 8 | ||||
| -rw-r--r-- | src/core/os_akill.c | 336 | ||||
| -rw-r--r-- | src/core/os_chankill.c | 10 | ||||
| -rw-r--r-- | src/core/os_defcon.c | 24 | ||||
| -rw-r--r-- | src/core/os_sgline.c | 410 | ||||
| -rw-r--r-- | src/core/os_snline.cpp | 426 | ||||
| -rw-r--r-- | src/core/os_sqline.c | 324 | ||||
| -rw-r--r-- | src/core/os_stats.c | 114 | ||||
| -rw-r--r-- | src/core/os_szline.c | 321 |
19 files changed, 1107 insertions, 1056 deletions
diff --git a/src/core/bs_bot.c b/src/core/bs_bot.c index d8cb3db6d..2c5888554 100644 --- a/src/core/bs_bot.c +++ b/src/core/bs_bot.c @@ -242,7 +242,8 @@ class CommandBSBot : public Command the old nick. */ if (ircd->sqline) { - ircdproto->SendSQLineDel(bi->nick); + XLine x(bi->nick.c_str()); + ircdproto->SendSQLineDel(&x); } /* We check whether user with this nick is online, and kill it if so */ @@ -251,9 +252,11 @@ class CommandBSBot : public Command if (user) ircdproto->SendQuit(bi, "Quit: Be right back"); - else { + else + { ircdproto->SendChangeBotNick(bi, nick); - ircdproto->SendSQLine(bi->nick, "Reserved for services"); + XLine x(bi->nick.c_str(), "Reserved for services"); + ircdproto->SendSQLine(&x); } if (bi->nick != nick) @@ -273,7 +276,8 @@ class CommandBSBot : public Command bi->uid = ts6_uid_retrieve(); } ircdproto->SendClientIntroduction(bi->nick, bi->user, bi->host, bi->real, ircd->pseudoclient_mode, bi->uid); - ircdproto->SendSQLine(bi->nick, "Reserved for services"); + XLine x(bi->nick.c_str(), "Reserved for services"); + ircdproto->SendSQLine(&x); bi->RejoinAll(); } @@ -309,7 +313,8 @@ class CommandBSBot : public Command FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", u->nick.c_str()); - ircdproto->SendSQLineDel(bi->nick); + XLine x(bi->nick.c_str()); + ircdproto->SendSQLineDel(&x); delete bi; notice_lang(Config.s_BotServ, u, BOT_BOT_DELETED, nick); diff --git a/src/core/cs_drop.c b/src/core/cs_drop.c index baae58026..afeb522a9 100644 --- a/src/core/cs_drop.c +++ b/src/core/cs_drop.c @@ -66,7 +66,8 @@ class CommandCSDrop : public Command if (ircd->chansqline && (ci->HasFlag(CI_FORBIDDEN))) { - ircdproto->SendSQLineDel(ci->name.c_str()); + XLine x(ci->name.c_str()); + ircdproto->SendSQLineDel(&x); } Alog() << Config.s_ChanServ << ": Channel " << ci->name << " dropped by " << u->GetMask() << " (founder: " diff --git a/src/core/cs_forbid.c b/src/core/cs_forbid.c index 06447c800..141865bf7 100644 --- a/src/core/cs_forbid.c +++ b/src/core/cs_forbid.c @@ -87,7 +87,8 @@ class CommandCSForbid : public Command if (ircd->chansqline) { - ircdproto->SendSQLine(ci->name, reason ? reason : "Forbidden"); + XLine x(chan, "Forbidden"); + ircdproto->SendSQLine(&x); } Alog() << Config.s_ChanServ << ": " << u->nick << " set FORBID for channel " << ci->name; diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp index 710d4eb50..98212539e 100644 --- a/src/core/db_plain.cpp +++ b/src/core/db_plain.cpp @@ -458,31 +458,42 @@ static void LoadOperInfo(const std::vector<std::string> ¶ms) maxusercnt = atol(params[1].c_str()); maxusertime = strtol(params[2].c_str(), NULL, 10); } - else if (params[0] == "SGLINE" || params[0] == "SQLINE" || params[0] == "SZLINE") + else if (params[0] == "SNLINE" || params[0] == "SQLINE" || params[0] == "SZLINE") { - SXLine *sx = new SXLine; - sx->mask = sstrdup(params[1].c_str()); - sx->by = sstrdup(params[2].c_str()); - sx->seton = atol(params[3].c_str()); - sx->expires = atol(params[4].c_str()); - sx->reason = sstrdup(params[5].c_str()); - if (params[0] == "SGLINE") - slist_add(&sglines, sx); - else if (params[0] == "SQLINE") - slist_add(&sqlines, sx); - else if (params[0] == "SZLINE") - slist_add(&szlines, sx); + ci::string mask = params[1].c_str(); + ci::string by = params[2].c_str(); + time_t seton = atol(params[3].c_str()); + time_t expires = atol(params[4].c_str()); + std::string reason = params[5]; + + XLine *x = NULL; + if (params[0] == "SNLINE" && SNLine) + x = SNLine->Add(NULL, NULL, mask, expires, reason); + else if (params[0] == "SQLINE" && SQLine) + x = SQLine->Add(NULL, NULL, mask, expires, reason); + else if (params[0] == "SZLINE" && SZLine) + x = SZLine->Add(NULL, NULL, mask, expires, reason); + if (x) + { + x->By = by; + x->Created = seton; + } } - else if (params[0] == "AKILL") + else if (params[0] == "AKILL" && SGLine) { - Akill *ak = new Akill; - ak->user = sstrdup(params[1].c_str()); - ak->host = sstrdup(params[2].c_str()); - ak->by = sstrdup(params[3].c_str()); - ak->seton = atol(params[4].c_str()); - ak->expires = atol(params[5].c_str()); - ak->reason = sstrdup(params[6].c_str()); - slist_add(&akills, ak); + ci::string user = params[1].c_str(); + ci::string host = params[2].c_str(); + ci::string by = params[3].c_str(); + time_t seton = atol(params[4].c_str()); + time_t expires = atol(params[5].c_str()); + std::string reason = params[6]; + + XLine *x = SGLine->Add(NULL, NULL, user + "@" + host, expires, reason); + if (x) + { + x->By = by; + x->Created = seton; + } } else if (params[0] == "EXCEPTION") { @@ -1133,7 +1144,7 @@ class DBPlain : public Module } db << "MD BI TTB BOLDS " << ci->ttb[0] << " COLORS " << ci->ttb[1] << " REVERSES " << ci->ttb[2] << " UNDERLINES " << ci->ttb[3] << " BADWORDS " << ci->ttb[4] << " CAPS " << ci->ttb[5] << " FLOOD " << ci->ttb[6] << " REPEAT " << ci->ttb[7] << endl; if (ci->capsmin) - db << "MD BI CAPSMINS " << ci->capsmin << endl; + db << "MD BI CAPSMIN " << ci->capsmin << endl; if (ci->capspercent) db << "MD BI CAPSPERCENT " << ci->capspercent << endl; if (ci->floodlines) @@ -1153,28 +1164,42 @@ class DBPlain : public Module FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, ci)); } - for (int i = 0; i < akills.count; ++i) + db << "OS STATS " << maxusercnt << " " << maxusertime << endl; + + if (SGLine) { - Akill *ak = static_cast<Akill *>(akills.list[i]); - db << "OS AKILL " << ak->user << " " << ak->host << " " << ak->by << " " << ak->seton << " " << ak->expires << " :" << ak->reason << endl; + for (unsigned i = 0; i < SGLine->GetCount(); ++i) + { + XLine *x = SGLine->GetEntry(i); + db << "OS AKILL " << x->GetUser() << " " << x->GetHost() << " " << x->By << " " << x->Created << " " << x->Expires << " :" << x->Reason << endl; + } } - db << "OS STATS " << maxusercnt << " " << maxusertime << endl; - SXLine *sx; - for (int i = 0; i < sglines.count; ++i) + if (SNLine) { - sx = static_cast<SXLine *>(sglines.list[i]); - db << "OS SGLINE " << sx->mask << " " << sx->by << " " << sx->seton << " " << sx->expires << " :" << sx->reason << endl; + for (unsigned i = 0; i < SNLine->GetCount(); ++i) + { + XLine *x = SNLine->GetEntry(i); + db << "OS SNLINE " << x->Mask << " " << x->By << " " << x->Created << " " << x->Expires << " :" << x->Reason << endl; + } } - for (int i = 0; i < sqlines.count; ++i) + + if (SQLine) { - sx = static_cast<SXLine *>(sqlines.list[i]); - db << "OS SQLINE " << sx->mask << " " << sx->by << " " << sx->seton << " " << sx->expires << " :" << sx->reason << endl; + for (unsigned i = 0; i < SQLine->GetCount(); ++i) + { + XLine *x = SQLine->GetEntry(i); + db << "OS SQLINE " << x->Mask << " " << x->By << " " << x->Created << " " << x->Expires << " :" << x->Reason << endl; + } } - for (int i = 0; i < szlines.count; ++i) + + if (SZLine) { - sx = static_cast<SXLine *>(szlines.list[i]); - db << "OS SZLINE " << sx->mask << " " << sx->by << " " << sx->seton << " " << sx->expires << " :" << sx->reason << endl; + for (unsigned i = 0; i < SZLine->GetCount(); ++i) + { + XLine *x = SZLine->GetEntry(i); + db << "OS SZLINE " << x->Mask << " " << x->By << " " << x->Created << " " << x->Expires << " :" << x->Reason << endl; + } } for (int i = 0; i < nexceptions; i++) diff --git a/src/core/hs_delall.c b/src/core/hs_delall.c index 05c67660d..aaab9b6e1 100644 --- a/src/core/hs_delall.c +++ b/src/core/hs_delall.c @@ -23,10 +23,8 @@ class CommandHSDelAll : public Command CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) { - int i; const char *nick = params[0].c_str(); NickAlias *na; - NickCore *nc; if ((na = findnick(nick))) { if (na->HasFlag(NS_FORBIDDEN)) @@ -35,10 +33,10 @@ class CommandHSDelAll : public Command return MOD_CONT; } FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); - nc = na->nc; - for (i = 0; i < nc->aliases.count; ++i) + NickCore *nc = na->nc; + for (std::list<NickAlias *>::iterator it = nc->aliases.begin(); it != nc->aliases.end(); ++it) { - na = static_cast<NickAlias *>(nc->aliases.list[i]); + na = *it; na->hostinfo.RemoveVhost(); } Alog() << "vHosts for all nicks in group \002" << nc->display << "\002 deleted by oper \002" << u->nick << "\002"; diff --git a/src/core/ns_drop.c b/src/core/ns_drop.c index 72f99cf7a..16c73f04a 100644 --- a/src/core/ns_drop.c +++ b/src/core/ns_drop.c @@ -69,7 +69,10 @@ class CommandNSDrop : public Command notice_lang(Config.s_NickServ, u, READ_ONLY_MODE); if (ircd->sqline && (na->HasFlag(NS_FORBIDDEN))) - ircdproto->SendSQLineDel(na->nick); + { + XLine x(na->nick); + ircdproto->SendSQLineDel(&x); + } Alog() << Config.s_NickServ << ": " << u->GetMask() << " dropped nickname " << na->nick << " (group " << na->nc->display << ") (e-mail: " << (na->nc->email ? na->nc->email : "none") << ")"; delete na; diff --git a/src/core/ns_forbid.c b/src/core/ns_forbid.c index e4c179243..70943ceeb 100644 --- a/src/core/ns_forbid.c +++ b/src/core/ns_forbid.c @@ -69,7 +69,10 @@ class CommandNSForbid : public Command if (ircd->sqline) - ircdproto->SendSQLine(na->nick, reason ? reason : "Forbidden"); + { + XLine x(na->nick, reason ? reason : "Forbidden"); + ircdproto->SendSQLine(&x); + } if (Config.WallForbid) ircdproto->SendGlobops(NickServ, "\2%s\2 used FORBID on \2%s\2", u->nick.c_str(), nick); diff --git a/src/core/ns_group.c b/src/core/ns_group.c index 10478f8a1..dd6f9b3be 100644 --- a/src/core/ns_group.c +++ b/src/core/ns_group.c @@ -80,7 +80,7 @@ class CommandNSGroup : public Command notice_lang(Config.s_NickServ, u, NICK_GROUP_SAME, target->nick); else if (na && na->nc != u->Account()) notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); - else if (Config.NSMaxAliases && (target->nc->aliases.count >= Config.NSMaxAliases) && !target->nc->IsServicesOper()) + else if (Config.NSMaxAliases && (target->nc->aliases.size() >= Config.NSMaxAliases) && !target->nc->IsServicesOper()) notice_lang(Config.s_NickServ, u, NICK_GROUP_TOO_MANY, target->nick, Config.s_NickServ, Config.s_NickServ); else if (enc_check_password(pass, target->nc->pass) != 1) { @@ -163,7 +163,7 @@ class CommandNSUngroup : public Command const char *nick = params.size() ? params[0].c_str() : NULL; NickAlias *na = nick ? findnick(nick) : findnick(u->nick); - if (u->Account()->aliases.count == 1) + if (u->Account()->aliases.size() == 1) notice_lang(Config.s_NickServ, u, NICK_UNGROUP_ONE_NICK); else if (!na) notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick ? nick : u->nick.c_str()); @@ -173,14 +173,19 @@ class CommandNSUngroup : public Command { NickCore *oldcore = na->nc; - slist_remove(&oldcore->aliases, na); + std::list<NickAlias *>::iterator it = std::find(oldcore->aliases.begin(), oldcore->aliases.end(), na); + if (it != oldcore->aliases.end()) + { + oldcore->aliases.erase(it); + } + if (!stricmp(oldcore->display, na->nick)) { change_core_display(oldcore); } na->nc = new NickCore(na->nick); - slist_add(&na->nc->aliases, na); + na->nc->aliases.push_back(na); na->nc->pass = oldcore->pass; if (oldcore->email) @@ -224,7 +229,6 @@ class CommandNSGList : public Command const char *nick = params.size() ? params[0].c_str() : NULL; NickCore *nc = u->Account(); - int i; if (nick && (stricmp(nick, u->nick.c_str()) && !u->Account()->IsServicesOper())) notice_lang(Config.s_NickServ, u, ACCESS_DENIED, Config.s_NickServ); @@ -238,9 +242,9 @@ class CommandNSGList : public Command int wont_expire; notice_lang(Config.s_NickServ, u, nick ? NICK_GLIST_HEADER_X : NICK_GLIST_HEADER, nc->display); - for (i = 0; i < nc->aliases.count; ++i) + for (std::list<NickAlias *>::iterator it = nc->aliases.begin(); it != nc->aliases.end(); ++it) { - NickAlias *na2 = static_cast<NickAlias *>(nc->aliases.list[i]); + NickAlias *na2 = *it; if (!(wont_expire = na2->HasFlag(NS_NO_EXPIRE))) { @@ -250,7 +254,7 @@ class CommandNSGList : public Command } notice_lang(Config.s_NickServ, u, wont_expire ? NICK_GLIST_REPLY_NOEXPIRE : NICK_GLIST_REPLY, na2->nick, buf); } - notice_lang(Config.s_NickServ, u, NICK_GLIST_FOOTER, nc->aliases.count); + notice_lang(Config.s_NickServ, u, NICK_GLIST_FOOTER, nc->aliases.size()); } return MOD_CONT; } diff --git a/src/core/ns_saset.c b/src/core/ns_saset.c index 3bedbd301..7117ffab7 100644 --- a/src/core/ns_saset.c +++ b/src/core/ns_saset.c @@ -20,8 +20,6 @@ private: CommandReturn DoSetDisplay(User *u, const std::vector<ci::string> ¶ms, NickCore *nc) { ci::string param = params.size() > 2 ? params[2] : ""; - int i; - NickAlias *na; if (param.empty()) { @@ -30,17 +28,9 @@ private: } /* First check whether param is a valid nick of the group */ - for (i = 0; i < nc->aliases.count; ++i) - { - na = static_cast<NickAlias *>(nc->aliases.list[i]); - if (na->nick == param) - { - param = na->nick; /* Because case may differ */ - break; - } - } + NickAlias *na = findnick(param); - if (i == nc->aliases.count) + if (!na || na->nc != nc) { notice_lang(Config.s_NickServ, u, NICK_SASET_DISPLAY_INVALID, nc->display); return MOD_CONT; diff --git a/src/core/ns_set.c b/src/core/ns_set.c index 79561af76..1325f6b32 100644 --- a/src/core/ns_set.c +++ b/src/core/ns_set.c @@ -27,21 +27,9 @@ class CommandNSSet : public Command return MOD_CONT; } - int i; - NickAlias *na; - - /* First check whether param is a valid nick of the group */ - for (i = 0; i < nc->aliases.count; ++i) - { - na = static_cast<NickAlias *>(nc->aliases.list[i]); - if (na->nick == param) - { - param = na->nick; /* Because case may differ */ - break; - } - } - - if (i == nc->aliases.count) + NickAlias *na = findnick(param); + + if (!na || na->nc != nc) { notice_lang(Config.s_NickServ, u, NICK_SET_DISPLAY_INVALID); return MOD_CONT; diff --git a/src/core/ns_suspend.c b/src/core/ns_suspend.c index 1f0b885a4..94408adac 100644 --- a/src/core/ns_suspend.c +++ b/src/core/ns_suspend.c @@ -23,11 +23,10 @@ class CommandNSSuspend : public Command CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) { - NickAlias *na, *na2; + NickAlias *na; User *u2; const char *nick = params[0].c_str(); const char *reason = params[1].c_str(); - int i; if (readonly) { @@ -61,9 +60,10 @@ class CommandNSSuspend : public Command na->nc->UnsetFlag(NI_KILL_QUICK); na->nc->UnsetFlag(NI_KILL_IMMED); - for (i = 0; i < na->nc->aliases.count; ++i) + for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(); it != na->nc->aliases.end(); ++it) { - na2 = static_cast<NickAlias *>(na->nc->aliases.list[i]); + NickAlias *na2 = *it; + if (na2->nc == na->nc) { if (na2->last_quit) diff --git a/src/core/os_akill.c b/src/core/os_akill.c index 590767bbe..47a2b9dd1 100644 --- a/src/core/os_akill.c +++ b/src/core/os_akill.c @@ -14,24 +14,123 @@ #include "module.h" -int akill_view_callback(SList *slist, int number, void *item, va_list args); -int akill_list_callback(SList *slist, int number, void *item, va_list args); -int akill_view(int number, Akill *ak, User *u, int *sent_header); -int akill_list(int number, Akill *ak, User *u, int *sent_header); +class AkillDelCallback : public NumberList +{ + User *u; + unsigned Deleted; + public: + AkillDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0) + { + } + + ~AkillDelCallback() + { + if (!Deleted) + notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_MATCH); + else if (Deleted == 1) + notice_lang(Config.s_OperServ, u, OPER_AKILL_DELETED_ONE); + else + notice_lang(Config.s_OperServ, u, OPER_AKILL_DELETED_SEVERAL, Deleted); + } + + void HandleNumber(unsigned Number) + { + XLine *x = SGLine->GetEntry(Number - 1); + + if (!x) + return; + + ++Deleted; + DoDel(u, x); + } + + static void DoDel(User *u, XLine *x) + { + SGLine->DelXLine(x); + } +}; + +class AkillListCallback : public NumberList +{ + protected: + User *u; + bool SentHeader; + public: + AkillListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false) + { + } + + ~AkillListCallback() + { + if (!SentHeader) + notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_MATCH); + else + notice_lang(Config.s_OperServ, u, END_OF_ANY_LIST, "Akill"); + } + + void HandleNumber(unsigned Number) + { + XLine *x = SGLine->GetEntry(Number - 1); + + if (!x) + return; + + if (!SentHeader) + { + SentHeader = true; + notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_HEADER); + } + + DoList(u, x, Number); + } + + static void DoList(User *u, XLine *x, unsigned Number) + { + notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); + } +}; -static int akill_del_callback(SList *slist, void *item, va_list args) +class AkillViewCallback : public AkillListCallback { - User *u = va_arg(args, User *); - FOREACH_MOD(I_OnDelAkill, OnDelAkill(u, static_cast<Akill *>(item))); - return 1; -} + public: + AkillViewCallback(User *_u, const std::string &numlist) : AkillListCallback(_u, numlist) + { + } + + void HandleNumber(unsigned Number) + { + XLine *x = SGLine->GetEntry(Number - 1); + + if (!x) + return; + + if (!SentHeader) + { + SentHeader = true; + notice_lang(Config.s_OperServ, u, OPER_AKILL_VIEW_HEADER); + } + + DoList(u, x, Number); + } + + static void DoList(User *u, XLine *x, unsigned Number) + { + char timebuf[32], expirebuf[256]; + struct tm tm; + + tm = *localtime(&x->Created); + strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); + expire_left(u->Account(), expirebuf, sizeof(expirebuf), x->Expires); + + notice_lang(Config.s_OperServ, u, OPER_AKILL_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str()); + } +}; class CommandOSAKill : public Command { private: CommandReturn DoAdd(User *u, const std::vector<ci::string> ¶ms) { - int deleted = 0; unsigned last_param = 2; const char *expiry, *mask; char reason[BUFSIZE]; @@ -68,37 +167,13 @@ class CommandOSAKill : public Command return MOD_CONT; } snprintf(reason, sizeof(reason), "%s%s%s", params[last_param].c_str(), last_param == 2 && params.size() > 3 ? " " : "", last_param == 2 && params.size() > 3 ? params[3].c_str() : ""); - if (mask && *reason) { - /* We first do some sanity check on the proposed mask. */ - if (strchr(mask, '!')) - { - notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_NICK); - return MOD_CONT; - } - - if (!strchr(mask, '@')) - { - notice_lang(Config.s_OperServ, u, BAD_USERHOST_MASK); - return MOD_CONT; - } + if (mask && *reason) + { + XLine *x = SGLine->Add(OperServ, u, mask, expires, reason); - if (mask && strspn(mask, "~@.*?") == strlen(mask)) - { - notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask); + if (!x) return MOD_CONT; - } - - std::string realreason; - if (Config.AddAkiller) - realreason = "[" + u->nick + "] " + std::string(reason); - else - realreason = reason; - deleted = add_akill(u, mask, u->nick.c_str(), expires, realreason.c_str()); - if (deleted < 0) - return MOD_CONT; - else if (deleted) - notice_lang(Config.s_OperServ, u, OPER_AKILL_DELETED_SEVERAL, deleted); notice_lang(Config.s_OperServ, u, OPER_AKILL_ADDED, mask); if (Config.WallOSAkill) @@ -131,7 +206,7 @@ class CommandOSAKill : public Command snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, wall_expiry == 1 ? "" : "s"); } - ircdproto->SendGlobops(OperServ, "%s added an AKILL for %s (%s) (%s)", u->nick.c_str(), mask, realreason.c_str(), buf); + ircdproto->SendGlobops(OperServ, "%s added an AKILL for %s (%s) (%s)", u->nick.c_str(), mask, reason, buf); } if (readonly) @@ -145,49 +220,36 @@ class CommandOSAKill : public Command CommandReturn DoDel(User *u, const std::vector<ci::string> ¶ms) { - const char *mask; - int res = 0; - - mask = params.size() > 1 ? params[1].c_str() : NULL; + const ci::string mask = params.size() > 1 ? params[0] : ""; - if (!mask) + if (mask.empty()) { this->OnSyntaxError(u, "DEL"); return MOD_CONT; } - if (!akills.count) + if (SGLine->GetList().empty()) { notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_EMPTY); return MOD_CONT; } - if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask)) - { - /* Deleting a range */ - res = slist_delete_range(&akills, mask, akill_del_callback, u); - if (!res) - { - notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_MATCH); - return MOD_CONT; - } - else if (res == 1) - notice_lang(Config.s_OperServ, u, OPER_AKILL_DELETED_ONE); - else - notice_lang(Config.s_OperServ, u, OPER_AKILL_DELETED_SEVERAL, res); - } + if (isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + (new AkillDelCallback(u, mask.c_str()))->Process(); else { - if ((res = slist_indexof(&akills, const_cast<void *>(static_cast<const void *>(mask)))) == -1) // XXX: possibly unsafe cast + XLine *x = SGLine->HasEntry(mask); + + if (!x) { - notice_lang(Config.s_OperServ, u, OPER_AKILL_NOT_FOUND, mask); + notice_lang(Config.s_OperServ, u, OPER_AKILL_NOT_FOUND, mask.c_str()); return MOD_CONT; } - FOREACH_MOD(I_OnDelAkill, OnDelAkill(u, static_cast<Akill *>(akills.list[res]))); + FOREACH_MOD(I_OnDelAkill, OnDelAkill(u, x)); - slist_delete(&akills, res); - notice_lang(Config.s_OperServ, u, OPER_AKILL_DELETED, mask); + AkillDelCallback::DoDel(u, x); + notice_lang(Config.s_OperServ, u, OPER_AKILL_DELETED, mask.c_str()); } if (readonly) @@ -198,41 +260,37 @@ class CommandOSAKill : public Command CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms) { - const char *mask; - int res, sent_header = 0; - - if (!akills.count) + if (SGLine->GetList().empty()) { notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_EMPTY); return MOD_CONT; } - mask = params.size() > 1 ? params[1].c_str() : NULL; + const ci::string mask = params.size() > 1 ? params[1] : ""; - if (!mask || (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask))) - { - res = slist_enum(&akills, mask, &akill_list_callback, u, &sent_header); - if (!res) - { - notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_MATCH); - return MOD_CONT; - } - else - notice_lang(Config.s_OperServ, u, END_OF_ANY_LIST, "Akill"); - } + if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + (new AkillListCallback(u, mask.c_str()))->Process(); else { - int i; - char amask[BUFSIZE]; + bool SentHeader = false; - for (i = 0; i < akills.count; ++i) + for (unsigned i = 0; i < SGLine->GetCount(); ++i) { - snprintf(amask, sizeof(amask), "%s@%s", (static_cast<Akill *>(akills.list[i]))->user, (static_cast<Akill *>(akills.list[i]))->host); - if (!stricmp(mask, amask) || Anope::Match(amask, mask, false)) - akill_list(i + 1, static_cast<Akill *>(akills.list[i]), u, &sent_header); + XLine *x = SGLine->GetEntry(i); + + if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + { + if (!SentHeader) + { + SentHeader = true; + notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_HEADER); + } + + AkillListCallback::DoList(u, x, i); + } } - if (!sent_header) + if (!SentHeader) notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_MATCH); else notice_lang(Config.s_OperServ, u, END_OF_ANY_LIST, "Akill"); @@ -243,39 +301,37 @@ class CommandOSAKill : public Command CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms) { - const char *mask; - int res, sent_header = 0; - - if (!akills.count) + if (SGLine->GetList().empty()) { notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_EMPTY); return MOD_CONT; } - mask = params.size() > 1 ? params[1].c_str() : NULL; + const ci::string mask = params.size() > 1 ? params[1] : ""; - if (!mask || (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask))) - { - res = slist_enum(&akills, mask, &akill_view_callback, u, &sent_header); - if (!res) - { - notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_MATCH); - return MOD_CONT; - } - } + if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length()) + (new AkillViewCallback(u, mask.c_str()))->Process(); else { - int i; - char amask[BUFSIZE]; + bool SentHeader = false; - for (i = 0; i < akills.count; ++i) + for (unsigned i = 0; i < SGLine->GetCount(); ++i) { - snprintf(amask, sizeof(amask), "%s@%s", (static_cast<Akill *>(akills.list[i]))->user, (static_cast<Akill *>(akills.list[i]))->host); - if (!stricmp(mask, amask) || Anope::Match(amask, mask, false)) - akill_view(i + 1, static_cast<Akill *>(akills.list[i]), u, &sent_header); + XLine *x = SGLine->GetEntry(i); + + if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + { + if (!SentHeader) + { + SentHeader = true; + notice_lang(Config.s_OperServ, u, OPER_AKILL_VIEW_HEADER); + } + + AkillViewCallback::DoList(u, x, i); + } } - if (!sent_header) + if (!SentHeader) notice_lang(Config.s_OperServ, u, OPER_AKILL_NO_MATCH); } @@ -285,7 +341,7 @@ class CommandOSAKill : public Command CommandReturn DoClear(User *u) { FOREACH_MOD(I_OnDelAkill, OnDelAkill(u, NULL)); - slist_clear(&akills, 1); + SGLine->Clear(); notice_lang(Config.s_OperServ, u, OPER_AKILL_CLEAR); return MOD_CONT; @@ -344,66 +400,4 @@ class OSAKill : public Module } }; -int akill_view(int number, Akill *ak, User *u, int *sent_header) -{ - char mask[BUFSIZE]; - char timebuf[32], expirebuf[256]; - struct tm tm; - - if (!ak) - return 0; - - if (!*sent_header) - { - notice_lang(Config.s_OperServ, u, OPER_AKILL_VIEW_HEADER); - *sent_header = 1; - } - - snprintf(mask, sizeof(mask), "%s@%s", ak->user, ak->host); - tm = *localtime(&ak->seton); - strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); - expire_left(u->Account(), expirebuf, sizeof(expirebuf), ak->expires); - notice_lang(Config.s_OperServ, u, OPER_AKILL_VIEW_FORMAT, number, mask, ak->by, timebuf, expirebuf, ak->reason); - - return 1; -} - -/* Lists an AKILL entry, prefixing it with the header if needed */ -int akill_list_callback(SList *slist, int number, void *item, va_list args) -{ - User *u = va_arg(args, User *); - int *sent_header = va_arg(args, int *); - - return akill_list(number, static_cast<Akill *>(item), u, sent_header); -} - -/* Callback for enumeration purposes */ -int akill_view_callback(SList *slist, int number, void *item, va_list args) -{ - User *u = va_arg(args, User *); - int *sent_header = va_arg(args, int *); - - return akill_view(number, static_cast<Akill *>(item), u, sent_header); -} - |
