mirror of
https://github.com/anope/anope.git
synced 2026-07-08 00:43:12 +02:00
Burned slist, rewrote operservs XLine code
This commit is contained in:
+10
-5
@@ -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);
|
||||
|
||||
+2
-1
@@ -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: "
|
||||
|
||||
@@ -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;
|
||||
|
||||
+62
-37
@@ -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++)
|
||||
|
||||
@@ -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";
|
||||
|
||||
+4
-1
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+12
-8
@@ -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;
|
||||
}
|
||||
|
||||
+2
-12
@@ -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;
|
||||
|
||||
+3
-15
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
+166
-172
@@ -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);
|
||||
|
||||
static int akill_del_callback(SList *slist, void *item, va_list args)
|
||||
class AkillDelCallback : public NumberList
|
||||
{
|
||||
User *u = va_arg(args, User *);
|
||||
FOREACH_MOD(I_OnDelAkill, OnDelAkill(u, static_cast<Akill *>(item)));
|
||||
return 1;
|
||||
}
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
class AkillViewCallback : public AkillListCallback
|
||||
{
|
||||
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 (mask && *reason)
|
||||
{
|
||||
XLine *x = SGLine->Add(OperServ, u, mask, expires, reason);
|
||||
|
||||
if (!strchr(mask, '@'))
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, BAD_USERHOST_MASK);
|
||||
if (!x)
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (mask && strspn(mask, "~@.*?") == strlen(mask))
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask);
|
||||
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;
|
||||
const ci::string mask = params.size() > 1 ? params[0] : "";
|
||||
|
||||
mask = params.size() > 1 ? params[1].c_str() : NULL;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* Lists an AKILL entry, prefixing it with the header if needed */
|
||||
int akill_list(int number, Akill *ak, User *u, int *sent_header)
|
||||
{
|
||||
char mask[BUFSIZE];
|
||||
|
||||
if (!ak)
|
||||
return 0;
|
||||
|
||||
if (!*sent_header)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_HEADER);
|
||||
*sent_header = 1;
|
||||
}
|
||||
|
||||
snprintf(mask, sizeof(mask), "%s@%s", ak->user, ak->host);
|
||||
notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_FORMAT, number, mask, ak->reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
MODULE_INIT(OSAKill)
|
||||
|
||||
@@ -26,7 +26,6 @@ class CommandOSChanKill : public Command
|
||||
const char *expiry, *channel;
|
||||
char reason[BUFSIZE];
|
||||
time_t expires;
|
||||
char *mask = new char[Config.UserLen + Config.HostLen + 2];
|
||||
unsigned last_param = 1;
|
||||
Channel *c;
|
||||
|
||||
@@ -46,7 +45,6 @@ class CommandOSChanKill : public Command
|
||||
if (expires != 0 && expires < 60)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME);
|
||||
delete [] mask;
|
||||
return MOD_CONT;
|
||||
}
|
||||
else if (expires > 0)
|
||||
@@ -55,7 +53,6 @@ class CommandOSChanKill : public Command
|
||||
if (params.size() <= last_param)
|
||||
{
|
||||
this->OnSyntaxError(u, "");
|
||||
delete [] mask;
|
||||
return MOD_CONT;
|
||||
}
|
||||
snprintf(reason, sizeof(reason), "%s%s", params[last_param].c_str(), (params.size() > last_param + 1 ? params[last_param + 1].c_str() : ""));
|
||||
@@ -77,10 +74,8 @@ class CommandOSChanKill : public Command
|
||||
if (is_oper(uc->user))
|
||||
continue;
|
||||
|
||||
strlcpy(mask, "*@", Config.UserLen + Config.HostLen + 2); /* Use *@" for the akill's, */
|
||||
strlcat(mask, uc->user->host, Config.UserLen + Config.HostLen + 2);
|
||||
add_akill(NULL, mask, Config.s_OperServ, expires, realreason.c_str());
|
||||
check_akill(uc->user->nick.c_str(), uc->user->GetIdent().c_str(), uc->user->host, NULL, NULL);
|
||||
SGLine->Add(OperServ, u, ci::string("*@") + uc->user->host, expires, realreason);
|
||||
SGLine->Check(uc->user);
|
||||
}
|
||||
if (Config.WallOSAkill)
|
||||
ircdproto->SendGlobops(OperServ, "%s used CHANKILL on %s (%s)", u->nick.c_str(), channel, realreason.c_str());
|
||||
@@ -88,7 +83,6 @@ class CommandOSChanKill : public Command
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, CHAN_X_NOT_IN_USE, channel);
|
||||
}
|
||||
delete [] mask;
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
|
||||
+10
-14
@@ -160,12 +160,10 @@ class OSDEFCON : public Module
|
||||
{
|
||||
if (CheckDefCon(DEFCON_AKILL_NEW_CLIENTS))
|
||||
{
|
||||
std::string mask = "*@" + std::string(u->host);
|
||||
Alog() << "DEFCON: adding akill for " << mask;
|
||||
add_akill(NULL, mask.c_str(), Config.s_OperServ,
|
||||
time(NULL) + Config.DefConAKILL,
|
||||
Config.DefConAkillReason ? Config.DefConAkillReason :
|
||||
"DEFCON AKILL");
|
||||
Alog() << "DEFCON: adding akill for *@" << u->host;
|
||||
XLine *x = SGLine->Add(NULL, NULL, ci::string("*@") + u->host, time(NULL) + Config.DefConAKILL, Config.DefConAkillReason ? Config.DefConAkillReason : "DEFCON AKILL");
|
||||
if (x)
|
||||
x->By = Config.s_OperServ;
|
||||
}
|
||||
|
||||
if (CheckDefCon(DEFCON_NO_NEW_CLIENTS) || CheckDefCon(DEFCON_AKILL_NEW_CLIENTS))
|
||||
@@ -199,7 +197,7 @@ class OSDEFCON : public Module
|
||||
{
|
||||
std::string param;
|
||||
|
||||
if (GetDefConParam(Name, ¶m))
|
||||
if (GetDefConParam(Name, param))
|
||||
{
|
||||
c->SetMode(OperServ, Name, param);
|
||||
}
|
||||
@@ -301,10 +299,8 @@ class OSDEFCON : public Module
|
||||
session->hits++;
|
||||
if (Config.MaxSessionKill && session->hits >= Config.MaxSessionKill)
|
||||
{
|
||||
char akillmask[BUFSIZE];
|
||||
snprintf(akillmask, sizeof(akillmask), "*@%s", u->host);
|
||||
add_akill(NULL, akillmask, Config.s_OperServ, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded");
|
||||
ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask);
|
||||
SGLine->Add(NULL, NULL, ci::string("*@") + u->host, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded");
|
||||
ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2*@%s\2 due to excessive connections", u->host);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,18 +369,18 @@ void runDefCon()
|
||||
if (Config.DefConChanModes[0] == '+' || Config.DefConChanModes[0] == '-')
|
||||
{
|
||||
Alog() << "DEFCON: setting " << Config.DefConChanModes << " on all channels";
|
||||
DefConModesSet = 1;
|
||||
DefConModesSet = true;
|
||||
MassChannelModes(OperServ, Config.DefConChanModes);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Config.DefConChanModes && (DefConModesSet != 0))
|
||||
if (Config.DefConChanModes && DefConModesSet)
|
||||
{
|
||||
if (Config.DefConChanModes[0] == '+' || Config.DefConChanModes[0] == '-')
|
||||
{
|
||||
DefConModesSet = 0;
|
||||
DefConModesSet = false;
|
||||
if ((newmodes = defconReverseModes(Config.DefConChanModes)))
|
||||
{
|
||||
Alog() << "DEFCON: setting " << newmodes << " on all channels";
|
||||
|
||||
@@ -1,410 +0,0 @@
|
||||
/* OperServ core functions
|
||||
*
|
||||
* (C) 2003-2010 Anope Team
|
||||
* Contact us at team@anope.org
|
||||
*
|
||||
* Please read COPYING and README for further details.
|
||||
*
|
||||
* Based on the original code of Epona by Lara.
|
||||
* Based on the original code of Services by Andy Church.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "hashcomp.h"
|
||||
|
||||
int sgline_view_callback(SList *slist, int number, void *item, va_list args);
|
||||
int sgline_list_callback(SList *slist, int number, void *item, va_list args);
|
||||
int sgline_view(int number, SXLine *sx, User *u, int *sent_header);
|
||||
int sgline_list(int number, SXLine *sx, User *u, int *sent_header);
|
||||
|
||||
static int sxline_del_callback(SList *slist, void *item, va_list args)
|
||||
{
|
||||
User *u = va_arg(args, User *);
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, static_cast<SXLine *>(item), SX_SGLINE));
|
||||
return 1;
|
||||
}
|
||||
|
||||
class CommandOSSGLine : public Command
|
||||
{
|
||||
private:
|
||||
CommandReturn OnAdd(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
int deleted = 0;
|
||||
unsigned last_param = 2;
|
||||
const char *param, *expiry;
|
||||
char rest[BUFSIZE];
|
||||
time_t expires;
|
||||
|
||||
param = params.size() > 1 ? params[1].c_str() : NULL;
|
||||
if (param && *param == '+')
|
||||
{
|
||||
expiry = param;
|
||||
param = params.size() > 2 ? params[2].c_str() : NULL;
|
||||
last_param = 3;
|
||||
}
|
||||
else
|
||||
expiry = NULL;
|
||||
|
||||
expires = expiry ? dotime(expiry) : Config.SGLineExpiry;
|
||||
/* If the expiry given does not contain a final letter, it's in days,
|
||||
* said the doc. Ah well.
|
||||
*/
|
||||
if (expiry && isdigit(expiry[strlen(expiry) - 1]))
|
||||
expires *= 86400;
|
||||
/* Do not allow less than a minute expiry time */
|
||||
if (expires && expires < 60)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME);
|
||||
return MOD_CONT;
|
||||
}
|
||||
else if (expires > 0)
|
||||
expires += time(NULL);
|
||||
|
||||
if (!param)
|
||||
{
|
||||
this->OnSyntaxError(u, "ADD");
|
||||
return MOD_CONT;
|
||||
}
|
||||
snprintf(rest, sizeof(rest), "%s%s%s", param, params.size() > last_param ? " " : "", params.size() > last_param ? params[last_param].c_str() : "");
|
||||
|
||||
if (std::string(rest).find(':') == std::string::npos)
|
||||
{
|
||||
this->OnSyntaxError(u, "ADD");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
sepstream sep(rest, ':');
|
||||
std::string mask;
|
||||
sep.GetToken(mask);
|
||||
std::string reason = sep.GetRemaining();
|
||||
|
||||
if (!mask.empty() && !reason.empty()) {
|
||||
/* Clean up the last character of the mask if it is a space
|
||||
* See bug #761
|
||||
*/
|
||||
unsigned masklen = mask.size();
|
||||
if (mask[masklen - 1] == ' ')
|
||||
mask.erase(masklen - 1);
|
||||
|
||||
const char *cmask = mask.c_str();
|
||||
|
||||
/* We first do some sanity check on the proposed mask. */
|
||||
|
||||
if (!mask.empty() && strspn(cmask, "*?") == strlen(cmask)) {
|
||||
notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, cmask);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
deleted = add_sgline(u, cmask, u->nick.c_str(), expires, reason.c_str());
|
||||
if (deleted < 0)
|
||||
return MOD_CONT;
|
||||
else if (deleted)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_DELETED_SEVERAL, deleted);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_ADDED, cmask);
|
||||
|
||||
if (Config.WallOSSGLine)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
if (!expires)
|
||||
strcpy(buf, "does not expire");
|
||||
else
|
||||
{
|
||||
int wall_expiry = expires - time(NULL);
|
||||
const char *s = NULL;
|
||||
|
||||
if (wall_expiry >= 86400)
|
||||
{
|
||||
wall_expiry /= 86400;
|
||||
s = "day";
|
||||
}
|
||||
else if (wall_expiry >= 3600)
|
||||
{
|
||||
wall_expiry /= 3600;
|
||||
s = "hour";
|
||||
}
|
||||
else if (wall_expiry >= 60)
|
||||
{
|
||||
wall_expiry /= 60;
|
||||
s = "minute";
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, wall_expiry == 1 ? "" : "s");
|
||||
}
|
||||
|
||||
ircdproto->SendGlobops(OperServ, "%s added an SGLINE for %s (%s)", u->nick.c_str(), cmask, buf);
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
notice_lang(Config.s_OperServ, u, READ_ONLY_MODE);
|
||||
|
||||
}
|
||||
else
|
||||
this->OnSyntaxError(u, "ADD");
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnDel(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
const char *mask;
|
||||
int res = 0;
|
||||
|
||||
mask = params.size() > 1 ? params[1].c_str() : NULL;
|
||||
|
||||
if (!mask)
|
||||
{
|
||||
this->OnSyntaxError(u, "DEL");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (!sglines.count)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask))
|
||||
{
|
||||
/* Deleting a range */
|
||||
res = slist_delete_range(&sglines, mask, sxline_del_callback);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
else if (res == 1)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_DELETED_ONE);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_DELETED_SEVERAL, res);
|
||||
}
|
||||
else {
|
||||
if ((res = slist_indexof(&sglines, const_cast<char *>(mask))) == -1)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_NOT_FOUND, mask);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, static_cast<SXLine *>(sglines.list[res]), SX_SGLINE));
|
||||
slist_delete(&sglines, res);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_DELETED, mask);
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
notice_lang(Config.s_OperServ, u, READ_ONLY_MODE);
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnList(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
const char *mask;
|
||||
int res, sent_header = 0;
|
||||
|
||||
if (!sglines.count) {
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
mask = params.size() > 1 ? params[1].c_str() : NULL;
|
||||
|
||||
if (!mask || (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask)))
|
||||
{
|
||||
res = slist_enum(&sglines, mask, &sgline_list_callback, u, &sent_header);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
char *amask;
|
||||
|
||||
for (i = 0; i < sglines.count; ++i)
|
||||
{
|
||||
amask = (static_cast<SXLine *>(sglines.list[i]))->mask;
|
||||
if (!stricmp(mask, amask) || Anope::Match(amask, mask, false))
|
||||
sgline_list(i + 1, static_cast<SXLine *>(sglines.list[i]), u, &sent_header);
|
||||
}
|
||||
|
||||
if (!sent_header)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_NO_MATCH);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, END_OF_ANY_LIST, "SGLine");
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnView(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
const char *mask;
|
||||
int res, sent_header = 0;
|
||||
|
||||
if (!sglines.count)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
mask = params.size() > 1 ? params[1].c_str() : NULL;
|
||||
|
||||
if (!mask || (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask)))
|
||||
{
|
||||
res = slist_enum(&sglines, mask, &sgline_view_callback, u, &sent_header);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
char *amask;
|
||||
|
||||
for (i = 0; i < sglines.count; ++i)
|
||||
{
|
||||
amask = (static_cast<SXLine *>(sglines.list[i]))->mask;
|
||||
if (!stricmp(mask, amask) || Anope::Match(amask, mask, false))
|
||||
sgline_view(i + 1, static_cast<SXLine *>(sglines.list[i]), u, &sent_header);
|
||||
}
|
||||
|
||||
if (!sent_header)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnClear(User *u)
|
||||
{
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, NULL, SX_SGLINE));
|
||||
slist_clear(&sglines, 1);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_CLEAR);
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
public:
|
||||
CommandOSSGLine() : Command("SGLINE", 1, 3, "operserv/sgline")
|
||||
{
|
||||
}
|
||||
|
||||
CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
ci::string cmd = params[0];
|
||||
|
||||
if (cmd == "ADD")
|
||||
return this->OnAdd(u, params);
|
||||
else if (cmd == "DEL")
|
||||
return this->OnDel(u, params);
|
||||
else if (cmd == "LIST")
|
||||
return this->OnList(u, params);
|
||||
else if (cmd == "VIEW")
|
||||
return this->OnView(u, params);
|
||||
else if (cmd == "CLEAR")
|
||||
return this->OnClear(u);
|
||||
else
|
||||
this->OnSyntaxError(u, "");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
bool OnHelp(User *u, const ci::string &subcommand)
|
||||
{
|
||||
notice_help(Config.s_OperServ, u, OPER_HELP_SGLINE);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(User *u, const ci::string &subcommand)
|
||||
{
|
||||
syntax_error(Config.s_OperServ, u, "SGLINE", OPER_SGLINE_SYNTAX);
|
||||
}
|
||||
};
|
||||
|
||||
class OSSGLine : public Module
|
||||
{
|
||||
public:
|
||||
OSSGLine(const std::string &modname, const std::string &creator) : Module(modname, creator)
|
||||
{
|
||||
|
||||
this->SetAuthor("Anope");
|
||||
this->SetVersion(VERSION_STRING);
|
||||
this->SetType(CORE);
|
||||
|
||||
this->AddCommand(OperServ, new CommandOSSGLine());
|
||||
|
||||
if (!ircd->sgline)
|
||||
throw ModuleException("Your IRCd does not support SGLine");
|
||||
|
||||
ModuleManager::Attach(I_OnOperServHelp, this);
|
||||
}
|
||||
void OnOperServHelp(User *u)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SGLINE);
|
||||
}
|
||||
};
|
||||
|
||||
/* Lists an SGLINE entry, prefixing it with the header if needed */
|
||||
int sgline_view(int number, SXLine *sx, User *u, int *sent_header)
|
||||
{
|
||||
char timebuf[32], expirebuf[256];
|
||||
struct tm tm;
|
||||
|
||||
if (!sx)
|
||||
return 0;
|
||||
|
||||
if (!*sent_header)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_VIEW_HEADER);
|
||||
*sent_header = 1;
|
||||
}
|
||||
|
||||
tm = *localtime(&sx->seton);
|
||||
strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm);
|
||||
expire_left(u->Account(), expirebuf, sizeof(expirebuf), sx->expires);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_VIEW_FORMAT, number, sx->mask, sx->by, timebuf, expirebuf, sx->reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Callback for enumeration purposes */
|
||||
int sgline_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 sgline_view(number, static_cast<SXLine *>(item), u, sent_header);
|
||||
}
|
||||
|
||||
/* Lists an SGLINE entry, prefixing it with the header if needed */
|
||||
int sgline_list(int number, SXLine *sx, User *u, int *sent_header)
|
||||
{
|
||||
if (!sx)
|
||||
return 0;
|
||||
|
||||
if (!*sent_header)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_LIST_HEADER);
|
||||
*sent_header = 1;
|
||||
}
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_SGLINE_LIST_FORMAT, number, sx->mask, sx->reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Callback for enumeration purposes */
|
||||
int sgline_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 sgline_list(number, static_cast<SXLine *>(item), u, sent_header);
|
||||
}
|
||||
|
||||
MODULE_INIT(OSSGLine)
|
||||
@@ -0,0 +1,426 @@
|
||||
/* OperServ core functions
|
||||
*
|
||||
* (C) 2003-2010 Anope Team
|
||||
* Contact us at team@anope.org
|
||||
*
|
||||
* Please read COPYING and README for further details.
|
||||
*
|
||||
* Based on the original code of Epona by Lara.
|
||||
* Based on the original code of Services by Andy Church.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "hashcomp.h"
|
||||
|
||||
class SNLineDelCallback : public NumberList
|
||||
{
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
SNLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
~SNLineDelCallback()
|
||||
{
|
||||
if (!Deleted)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_NO_MATCH);
|
||||
else if (Deleted == 0)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_DELETED_ONE);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_DELETED_SEVERAL, Deleted);
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SNLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
++Deleted;
|
||||
DoDel(u, x);
|
||||
}
|
||||
|
||||
static void DoDel(User *u, XLine *x)
|
||||
{
|
||||
SNLine->DelXLine(x);
|
||||
}
|
||||
};
|
||||
|
||||
class SNLineListCallback : public NumberList
|
||||
{
|
||||
protected:
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
SNLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
~SNLineListCallback()
|
||||
{
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
virtual void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SNLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class SNLineViewCallback : public SNLineListCallback
|
||||
{
|
||||
public:
|
||||
SNLineViewCallback(User *_u, const std::string &numlist) : SNLineListCallback(_u, numlist)
|
||||
{
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SNLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_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_SNLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class CommandOSSNLine : public Command
|
||||
{
|
||||
private:
|
||||
CommandReturn OnAdd(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
unsigned last_param = 2;
|
||||
const char *param, *expiry;
|
||||
char rest[BUFSIZE];
|
||||
time_t expires;
|
||||
|
||||
param = params.size() > 1 ? params[1].c_str() : NULL;
|
||||
if (param && *param == '+')
|
||||
{
|
||||
expiry = param;
|
||||
param = params.size() > 2 ? params[2].c_str() : NULL;
|
||||
last_param = 3;
|
||||
}
|
||||
else
|
||||
expiry = NULL;
|
||||
|
||||
expires = expiry ? dotime(expiry) : Config.SNLineExpiry;
|
||||
/* If the expiry given does not contain a final letter, it's in days,
|
||||
* said the doc. Ah well.
|
||||
*/
|
||||
if (expiry && isdigit(expiry[strlen(expiry) - 1]))
|
||||
expires *= 86400;
|
||||
/* Do not allow less than a minute expiry time */
|
||||
if (expires && expires < 60)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME);
|
||||
return MOD_CONT;
|
||||
}
|
||||
else if (expires > 0)
|
||||
expires += time(NULL);
|
||||
|
||||
if (!param)
|
||||
{
|
||||
this->OnSyntaxError(u, "ADD");
|
||||
return MOD_CONT;
|
||||
}
|
||||
snprintf(rest, sizeof(rest), "%s%s%s", param, params.size() > last_param ? " " : "", params.size() > last_param ? params[last_param].c_str() : "");
|
||||
|
||||
if (std::string(rest).find(':') == std::string::npos)
|
||||
{
|
||||
this->OnSyntaxError(u, "ADD");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
sepstream sep(rest, ':');
|
||||
ci::string mask;
|
||||
sep.GetToken(mask);
|
||||
std::string reason = sep.GetRemaining();
|
||||
|
||||
if (!mask.empty() && !reason.empty()) {
|
||||
/* Clean up the last character of the mask if it is a space
|
||||
* See bug #761
|
||||
*/
|
||||
unsigned masklen = mask.size();
|
||||
if (mask[masklen - 1] == ' ')
|
||||
mask.erase(masklen - 1);
|
||||
|
||||
XLine *x = SNLine->Add(OperServ, u, mask, expires, reason);
|
||||
|
||||
if (!x)
|
||||
return MOD_CONT;
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_ADDED, mask.c_str());
|
||||
|
||||
if (Config.WallOSSNLine)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
if (!expires)
|
||||
strcpy(buf, "does not expire");
|
||||
else
|
||||
{
|
||||
int wall_expiry = expires - time(NULL);
|
||||
const char *s = NULL;
|
||||
|
||||
if (wall_expiry >= 86400)
|
||||
{
|
||||
wall_expiry /= 86400;
|
||||
s = "day";
|
||||
}
|
||||
else if (wall_expiry >= 3600)
|
||||
{
|
||||
wall_expiry /= 3600;
|
||||
s = "hour";
|
||||
}
|
||||
else if (wall_expiry >= 60)
|
||||
{
|
||||
wall_expiry /= 60;
|
||||
s = "minute";
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, wall_expiry == 1 ? "" : "s");
|
||||
}
|
||||
|
||||
ircdproto->SendGlobops(findbot(Config.s_OperServ), "%s added an SNLINE for %s (%s)", u->nick.c_str(), mask.c_str(), buf);
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
notice_lang(Config.s_OperServ, u, READ_ONLY_MODE);
|
||||
|
||||
}
|
||||
else
|
||||
this->OnSyntaxError(u, "ADD");
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnDel(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
if (SNLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
const ci::string mask = params.size() > 1 ? params[1] : "";
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
this->OnSyntaxError(u, "DEL");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SNLineDelCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
XLine *x = SNLine->HasEntry(mask);
|
||||
|
||||
if (!x)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_NOT_FOUND, mask.c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, X_SNLINE));
|
||||
|
||||
SNLineDelCallback::DoDel(u, x);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_DELETED, mask.c_str());
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
notice_lang(Config.s_OperServ, u, READ_ONLY_MODE);
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnList(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
if (SNLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
const ci::string mask = params.size() > 1 ? params[1] : "";
|
||||
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SNLineListCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
bool SentHeader = false;
|
||||
|
||||
for (unsigned i = 0; i < SNLine->GetCount(); ++i)
|
||||
{
|
||||
XLine *x = SNLine->GetEntry(i);
|
||||
|
||||
if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask)))
|
||||
{
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
SNLineListCallback::DoList(u, x, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_NO_MATCH);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, END_OF_ANY_LIST, "SNLine");
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnView(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
if (SNLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
const ci::string mask = params.size() > 1 ? params[1] : "";
|
||||
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SNLineViewCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
bool SentHeader = false;
|
||||
|
||||
for (unsigned i = 0; i < SNLine->GetCount(); ++i)
|
||||
{
|
||||
XLine *x = SNLine->GetEntry(i);
|
||||
|
||||
if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask)))
|
||||
{
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_VIEW_HEADER);
|
||||
}
|
||||
|
||||
SNLineViewCallback::DoList(u, x, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
CommandReturn OnClear(User *u)
|
||||
{
|
||||
FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, NULL, X_SNLINE));
|
||||
SNLine->Clear();
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_CLEAR);
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
public:
|
||||
CommandOSSNLine() : Command("SNLINE", 1, 3, "operserv/snline")
|
||||
{
|
||||
}
|
||||
|
||||
CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
ci::string cmd = params[0];
|
||||
|
||||
if (cmd == "ADD")
|
||||
return this->OnAdd(u, params);
|
||||
else if (cmd == "DEL")
|
||||
return this->OnDel(u, params);
|
||||
else if (cmd == "LIST")
|
||||
return this->OnList(u, params);
|
||||
else if (cmd == "VIEW")
|
||||
return this->OnView(u, params);
|
||||
else if (cmd == "CLEAR")
|
||||
return this->OnClear(u);
|
||||
else
|
||||
this->OnSyntaxError(u, "");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
bool OnHelp(User *u, const ci::string &subcommand)
|
||||
{
|
||||
notice_help(Config.s_OperServ, u, OPER_HELP_SNLINE);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(User *u, const ci::string &subcommand)
|
||||
{
|
||||
syntax_error(Config.s_OperServ, u, "SNLINE", OPER_SNLINE_SYNTAX);
|
||||
}
|
||||
};
|
||||
|
||||
class OSSNLine : public Module
|
||||
{
|
||||
public:
|
||||
OSSNLine(const std::string &modname, const std::string &creator) : Module(modname, creator)
|
||||
{
|
||||
|
||||
this->SetAuthor("Anope");
|
||||
this->SetVersion("$Id$");
|
||||
this->SetType(CORE);
|
||||
|
||||
this->AddCommand(OperServ, new CommandOSSNLine());
|
||||
|
||||
if (!ircd->snline)
|
||||
throw ModuleException("Your IRCd does not support SNLine");
|
||||
|
||||
ModuleManager::Attach(I_OnOperServHelp, this);
|
||||
}
|
||||
void OnOperServHelp(User *u)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SNLINE);
|
||||
}
|
||||
};
|
||||
|
||||
MODULE_INIT(OSSNLine)
|
||||
+171
-159
@@ -14,24 +14,122 @@
|
||||
|
||||
#include "module.h"
|
||||
|
||||
int sqline_view_callback(SList *slist, int number, void *item, va_list args);
|
||||
int sqline_list_callback(SList *slist, int number, void *item, va_list args);
|
||||
int sqline_view(int number, SXLine *sx, User *u, int *sent_header);
|
||||
int sqline_list(int number, SXLine *sx, User *u, int *sent_header);
|
||||
|
||||
static int sxline_del_callback(SList *slist, void *item, va_list args)
|
||||
class SQLineDelCallback : public NumberList
|
||||
{
|
||||
User *u = va_arg(args, User *);
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, static_cast<SXLine *>(item), SX_SQLINE));
|
||||
return 1;
|
||||
}
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
SQLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
~SQLineDelCallback()
|
||||
{
|
||||
if (!Deleted)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH);
|
||||
else if (Deleted == 0)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED_ONE);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED_SEVERAL, Deleted);
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SQLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
++Deleted;
|
||||
DoDel(u, x);
|
||||
}
|
||||
|
||||
static void DoDel(User *u, XLine *x)
|
||||
{
|
||||
SQLine->DelXLine(x);
|
||||
}
|
||||
};
|
||||
|
||||
class SQLineListCallback : public NumberList
|
||||
{
|
||||
protected:
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
SQLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
~SQLineListCallback()
|
||||
{
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
virtual void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SQLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class SQLineViewCallback : public SQLineListCallback
|
||||
{
|
||||
public:
|
||||
SQLineViewCallback(User *_u, const std::string &numlist) : SQLineListCallback(_u, numlist)
|
||||
{
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SQLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_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_SQLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf,
|
||||
expirebuf, x->Reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CommandOSSQLine : 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];
|
||||
@@ -70,25 +168,11 @@ class CommandOSSQLine : public Command
|
||||
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 (strspn(mask, "*") == strlen(mask))
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask);
|
||||
XLine *x = SQLine->Add(OperServ, u, mask, expires, reason);
|
||||
|
||||
if (!x)
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
/* Channel SQLINEs are only supported on Bahamut servers */
|
||||
if (*mask == '#' && !ircd->chansqline)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_CHANNELS_UNSUPPORTED);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
deleted = add_sqline(u, mask, u->nick.c_str(), expires, reason);
|
||||
if (deleted < 0)
|
||||
return MOD_CONT;
|
||||
else if (deleted)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED_SEVERAL, deleted);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_ADDED, mask);
|
||||
|
||||
if (Config.WallOSSQLine)
|
||||
@@ -136,47 +220,36 @@ class CommandOSSQLine : 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;
|
||||
|
||||
if (!mask)
|
||||
{
|
||||
this->OnSyntaxError(u, "DEL");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (!sqlines.count)
|
||||
if (SQLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask))
|
||||
const ci::string mask = params.size() > 1 ? params[1] : "";
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
/* Deleting a range */
|
||||
res = slist_delete_range(&sqlines, mask, sxline_del_callback);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
else if (res == 1)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED_ONE);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED_SEVERAL, res);
|
||||
this->OnSyntaxError(u, "DEL");
|
||||
return MOD_CONT;
|
||||
}
|
||||
else {
|
||||
if ((res = slist_indexof(&sqlines, const_cast<char *>(mask))) == -1)
|
||||
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SQLineDelCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
XLine *x = SQLine->HasEntry(mask);
|
||||
|
||||
if (!x)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NOT_FOUND, mask);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NOT_FOUND, mask.c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, static_cast<SXLine *>(sqlines.list[res]), SX_SQLINE));
|
||||
slist_delete(&sqlines, res);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED, mask);
|
||||
FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, X_SQLINE));
|
||||
|
||||
SQLineDelCallback::DoDel(u, x);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED, mask.c_str());
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
@@ -187,39 +260,37 @@ class CommandOSSQLine : public Command
|
||||
|
||||
CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
const char *mask;
|
||||
int res, sent_header = 0;
|
||||
|
||||
if (!sqlines.count)
|
||||
if (SQLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_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(&sqlines, mask, &sqline_list_callback, u, &sent_header);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
}
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SQLineListCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
int i;
|
||||
char *amask;
|
||||
bool SentHeader = false;
|
||||
|
||||
for (i = 0; i < sqlines.count; ++i)
|
||||
for (unsigned i = 0; i < SQLine->GetCount(); ++i)
|
||||
{
|
||||
amask = (static_cast<SXLine *>(sqlines.list[i]))->mask;
|
||||
if (!stricmp(mask, amask) || Anope::Match(amask, mask, false))
|
||||
sqline_list(i + 1, static_cast<SXLine *>(sqlines.list[i]), u, &sent_header);
|
||||
XLine *x = SQLine->GetEntry(i);
|
||||
|
||||
if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask)))
|
||||
{
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
SQLineListCallback::DoList(u, x, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sent_header)
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, END_OF_ANY_LIST, "SQLine");
|
||||
@@ -230,39 +301,37 @@ class CommandOSSQLine : public Command
|
||||
|
||||
CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
const char *mask;
|
||||
int res, sent_header = 0;
|
||||
|
||||
if (!sqlines.count)
|
||||
if (SQLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_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(&sqlines, mask, &sqline_view_callback, u, &sent_header);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
}
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SQLineViewCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
int i;
|
||||
char *amask;
|
||||
bool SentHeader = false;
|
||||
|
||||
for (i = 0; i < sqlines.count; ++i)
|
||||
for (unsigned i = 0; i < SQLine->GetCount(); ++i)
|
||||
{
|
||||
amask = (static_cast<SXLine *>(sqlines.list[i]))->mask;
|
||||
if (!stricmp(mask, amask) || Anope::Match(amask, mask, false))
|
||||
sqline_view(i + 1, static_cast<SXLine *>(sqlines.list[i]), u, &sent_header);
|
||||
XLine *x = SQLine->GetEntry(i);
|
||||
|
||||
if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask)))
|
||||
{
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_VIEW_HEADER);
|
||||
}
|
||||
|
||||
SQLineViewCallback::DoList(u, x, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sent_header)
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
@@ -271,8 +340,8 @@ class CommandOSSQLine : public Command
|
||||
|
||||
CommandReturn DoClear(User *u)
|
||||
{
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, NULL, SX_SQLINE));
|
||||
slist_clear(&sqlines, 1);
|
||||
FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, NULL, X_SQLINE));
|
||||
SGLine->Clear();
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_CLEAR);
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -335,61 +404,4 @@ class OSSQLine : public Module
|
||||
}
|
||||
};
|
||||
|
||||
int sqline_view(int number, SXLine *sx, User *u, int *sent_header)
|
||||
{
|
||||
char timebuf[32], expirebuf[256];
|
||||
struct tm tm;
|
||||
|
||||
if (!sx)
|
||||
return 0;
|
||||
|
||||
if (!*sent_header)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_VIEW_HEADER);
|
||||
*sent_header = 1;
|
||||
}
|
||||
|
||||
tm = *localtime(&sx->seton);
|
||||
strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm);
|
||||
expire_left(u->Account(), expirebuf, sizeof(expirebuf), sx->expires);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_VIEW_FORMAT, number, sx->mask, sx->by, timebuf, expirebuf, sx->reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Callback for enumeration purposes */
|
||||
int sqline_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 sqline_view(number, static_cast<SXLine *>(item), u, sent_header);
|
||||
}
|
||||
|
||||
/* Lists an SQLINE entry, prefixing it with the header if needed */
|
||||
int sqline_list(int number, SXLine *sx, User *u, int *sent_header)
|
||||
{
|
||||
if (!sx)
|
||||
return 0;
|
||||
|
||||
if (!*sent_header)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_LIST_HEADER);
|
||||
*sent_header = 1;
|
||||
}
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_LIST_FORMAT, number, sx->mask, sx->reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Callback for enumeration purposes */
|
||||
int sqline_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 sqline_list(number, static_cast<SXLine *>(item), u, sent_header);
|
||||
}
|
||||
|
||||
MODULE_INIT(OSSQLine)
|
||||
|
||||
+62
-52
@@ -46,7 +46,7 @@ class CommandOSStats : public Command
|
||||
{
|
||||
int timeout;
|
||||
/* AKILLs */
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_AKILL_COUNT, akills.count);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_AKILL_COUNT, SGLine->GetCount());
|
||||
timeout = Config.AutokillExpiry + 59;
|
||||
if (timeout >= 172800)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_AKILL_EXPIRE_DAYS, timeout / 86400);
|
||||
@@ -62,30 +62,30 @@ class CommandOSStats : public Command
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_AKILL_EXPIRE_MIN);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_AKILL_EXPIRE_NONE);
|
||||
if (ircd->sgline)
|
||||
if (ircd->snline)
|
||||
{
|
||||
/* SGLINEs */
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_COUNT, sglines.count);
|
||||
timeout = Config.SGLineExpiry + 59;
|
||||
/* SNLINEs */
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_COUNT, SNLine->GetCount());
|
||||
timeout = Config.SNLineExpiry + 59;
|
||||
if (timeout >= 172800)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_EXPIRE_DAYS, timeout / 86400);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_EXPIRE_DAYS, timeout / 86400);
|
||||
else if (timeout >= 86400)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_EXPIRE_DAY);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_EXPIRE_DAY);
|
||||
else if (timeout >= 7200)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_EXPIRE_HOURS, timeout / 3600);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_EXPIRE_HOURS, timeout / 3600);
|
||||
else if (timeout >= 3600)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_EXPIRE_HOUR);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_EXPIRE_HOUR);
|
||||
else if (timeout >= 120)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_EXPIRE_MINS, timeout / 60);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_EXPIRE_MINS, timeout / 60);
|
||||
else if (timeout >= 60)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_EXPIRE_MIN);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_EXPIRE_MIN);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SGLINE_EXPIRE_NONE);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SNLINE_EXPIRE_NONE);
|
||||
}
|
||||
if (ircd->sqline)
|
||||
{
|
||||
/* SQLINEs */
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SQLINE_COUNT, sqlines.count);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SQLINE_COUNT, SQLine->GetCount());
|
||||
timeout = Config.SQLineExpiry + 59;
|
||||
if (timeout >= 172800)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SQLINE_EXPIRE_DAYS, timeout / 86400);
|
||||
@@ -105,7 +105,7 @@ class CommandOSStats : public Command
|
||||
if (ircd->szline)
|
||||
{
|
||||
/* SZLINEs */
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SZLINE_COUNT, szlines.count);
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SZLINE_COUNT, SZLine->GetCount());
|
||||
timeout = Config.SZLineExpiry + 59;
|
||||
if (timeout >= 172800)
|
||||
notice_lang(Config.s_OperServ, u, OPER_STATS_SZLINE_EXPIRE_DAYS, timeout / 86400);
|
||||
@@ -316,64 +316,74 @@ class OSStats : public Module
|
||||
|
||||
void get_operserv_stats(long *nrec, long *memuse)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
long mem = 0, count = 0, mem2 = 0, count2 = 0;
|
||||
Akill *ak;
|
||||
SXLine *sx;
|
||||
XLine *x;
|
||||
|
||||
count += akills.count;
|
||||
mem += akills.capacity;
|
||||
mem += akills.count * sizeof(Akill);
|
||||
count += SGLine->GetCount();
|
||||
mem += SGLine->GetCount() * sizeof(XLine);
|
||||
|
||||
for (i = 0; i < akills.count; ++i)
|
||||
for (i = 0; i < SGLine->GetCount(); ++i)
|
||||
{
|
||||
ak = static_cast<Akill *>(akills.list[i]);
|
||||
mem += strlen(ak->user) + 1;
|
||||
mem += strlen(ak->host) + 1;
|
||||
mem += strlen(ak->by) + 1;
|
||||
mem += strlen(ak->reason) + 1;
|
||||
x = SGLine->GetEntry(i);
|
||||
|
||||
mem += x->GetNick().length() + 1;
|
||||
mem += x->GetUser().length() + 1;
|
||||
mem += x->GetHost().length() + 1;
|
||||
mem += x->Mask.length() + 1;
|
||||
mem += x->By.length() + 1;
|
||||
mem += x->Reason.length() + 1;
|
||||
}
|
||||
|
||||
if (ircd->sgline)
|
||||
if (ircd->snline)
|
||||
{
|
||||
count += sglines.count;
|
||||
mem += sglines.capacity;
|
||||
mem += sglines.count * sizeof(SXLine);
|
||||
count += SNLine->GetCount();
|
||||
mem += SNLine->GetCount() * sizeof(XLine);
|
||||
|
||||
for (i = 0; i < sglines.count; ++i)
|
||||
for (i = 0; i < SNLine->GetCount(); ++i)
|
||||
{
|
||||
sx = static_cast<SXLine *>(sglines.list[i]);
|
||||
mem += strlen(sx->mask) + 1;
|
||||
mem += strlen(sx->by) + 1;
|
||||
mem += strlen(sx->reason) + 1;
|
||||
x = SNLine->GetEntry(i);
|
||||
|
||||
mem += x->GetNick().length() + 1;
|
||||
mem += x->GetUser().length() + 1;
|
||||
mem += x->GetHost().length() + 1;
|
||||
mem += x->Mask.length() + 1;
|
||||
mem += x->By.length() + 1;
|
||||
mem += x->Reason.length() + 1;
|
||||
}
|
||||
}
|
||||
if (ircd->sqline)
|
||||
{
|
||||
count += sqlines.count;
|
||||
mem += sqlines.capacity;
|
||||
mem += sqlines.count * sizeof(SXLine);
|
||||
count += SQLine->GetCount();
|
||||
mem += SGLine->GetCount() * sizeof(XLine);
|
||||
|
||||
for (i = 0; i < sqlines.count; ++i)
|
||||
for (i = 0; i < SQLine->GetCount(); ++i)
|
||||
{
|
||||
sx = static_cast<SXLine *>(sqlines.list[i]);
|
||||
mem += strlen(sx->mask) + 1;
|
||||
mem += strlen(sx->by) + 1;
|
||||
mem += strlen(sx->reason) + 1;
|
||||
x = SNLine->GetEntry(i);
|
||||
|
||||
mem += x->GetNick().length() + 1;
|
||||
mem += x->GetUser().length() + 1;
|
||||
mem += x->GetHost().length() + 1;
|
||||
mem += x->Mask.length() + 1;
|
||||
mem += x->By.length() + 1;
|
||||
mem += x->Reason.length() + 1;
|
||||
}
|
||||
}
|
||||
if (ircd->szline)
|
||||
{
|
||||
count += szlines.count;
|
||||
mem += szlines.capacity;
|
||||
mem += szlines.count * sizeof(SXLine);
|
||||
|
||||
for (i = 0; i < szlines.count; ++i)
|
||||
count += SZLine->GetCount();
|
||||
mem += SZLine->GetCount() * sizeof(XLine);
|
||||
|
||||
for (i = 0; i < SZLine->GetCount(); ++i)
|
||||
{
|
||||
sx = static_cast<SXLine *>(szlines.list[i]);
|
||||
mem += strlen(sx->mask) + 1;
|
||||
mem += strlen(sx->by) + 1;
|
||||
mem += strlen(sx->reason) + 1;
|
||||
x = SZLine->GetEntry(i);
|
||||
|
||||
mem += x->GetNick().length() + 1;
|
||||
mem += x->GetUser().length() + 1;
|
||||
mem += x->GetHost().length() + 1;
|
||||
mem += x->Mask.length() + 1;
|
||||
mem += x->By.length() + 1;
|
||||
mem += x->Reason.length() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+168
-157
@@ -14,24 +14,122 @@
|
||||
|
||||
#include "module.h"
|
||||
|
||||
int szline_view_callback(SList *slist, int number, void *item, va_list args);
|
||||
int szline_list_callback(SList *slist, int number, void *item, va_list args);
|
||||
int szline_view(int number, SXLine *sx, User *u, int *sent_header);
|
||||
int szline_list(int number, SXLine *sx, User *u, int *sent_header);
|
||||
|
||||
static int sxline_del_callback(SList *slist, void *item, va_list args)
|
||||
class SZLineDelCallback : public NumberList
|
||||
{
|
||||
User *u = va_arg(args, User *);
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, static_cast<SXLine *>(item), SX_SZLINE));
|
||||
return 1;
|
||||
}
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
SZLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
~SZLineDelCallback()
|
||||
{
|
||||
if (!Deleted)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH);
|
||||
else if (Deleted == 0)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED_ONE);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED_SEVERAL, Deleted);
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SZLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
++Deleted;
|
||||
DoDel(u, x);
|
||||
}
|
||||
|
||||
static void DoDel(User *u, XLine *x)
|
||||
{
|
||||
SZLine->DelXLine(x);
|
||||
}
|
||||
};
|
||||
|
||||
class SZLineListCallback : public NumberList
|
||||
{
|
||||
protected:
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
SZLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
~SZLineListCallback()
|
||||
{
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
virtual void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SZLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class SZLineViewCallback : public SZLineListCallback
|
||||
{
|
||||
public:
|
||||
SZLineViewCallback(User *_u, const std::string &numlist) : SZLineListCallback(_u, numlist)
|
||||
{
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
{
|
||||
XLine *x = SZLine->GetEntry(Number - 1);
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_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_SZLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf,
|
||||
expirebuf, x->Reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CommandOSSZLine : 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];
|
||||
@@ -70,25 +168,11 @@ class CommandOSSZLine : public Command
|
||||
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. */
|
||||
XLine *x = SZLine->Add(OperServ, u, mask, expires, reason);
|
||||
|
||||
if (strchr(mask, '!') || strchr(mask, '@'))
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_ONLY_IPS);
|
||||
if (!x)
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (strspn(mask, "*?") == strlen(mask))
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
deleted = add_szline(u, mask, u->nick.c_str(), expires, reason);
|
||||
if (deleted < 0)
|
||||
return MOD_CONT;
|
||||
else if (deleted)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED_SEVERAL, deleted);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_ADDED, mask);
|
||||
|
||||
if (Config.WallOSSZLine)
|
||||
@@ -136,48 +220,36 @@ class CommandOSSZLine : 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;
|
||||
|
||||
if (!mask)
|
||||
{
|
||||
this->OnSyntaxError(u, "DEL");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (!szlines.count)
|
||||
if (SZLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_LIST_EMPTY);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask))
|
||||
const ci::string mask = params.size() > 1 ? params[1].c_str() : "";
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
/* Deleting a range */
|
||||
res = slist_delete_range(&szlines, mask, sxline_del_callback);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
else if (res == 1)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED_ONE);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED_SEVERAL, res);
|
||||
this->OnSyntaxError(u, "DEL");
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SZLineDelCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
if ((res = slist_indexof(&szlines, const_cast<char *>(mask))) == -1)
|
||||
XLine *x = SZLine->HasEntry(mask);
|
||||
|
||||
if (!x)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NOT_FOUND, mask);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NOT_FOUND, mask.c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, static_cast<SXLine *>(szlines.list[res]), SX_SZLINE));
|
||||
slist_delete(&szlines, res);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED, mask);
|
||||
FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, X_SZLINE));
|
||||
|
||||
SZLineDelCallback::DoDel(u, x);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_DELETED, mask.c_str());
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
@@ -188,39 +260,37 @@ class CommandOSSZLine : public Command
|
||||
|
||||
CommandReturn DoList(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
const char *mask;
|
||||
int res, sent_header = 0;
|
||||
|
||||
if (!szlines.count)
|
||||
if (SZLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_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(&szlines, mask, &szline_list_callback, u, &sent_header);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
}
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SZLineListCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
int i;
|
||||
char *amask;
|
||||
bool SentHeader = false;
|
||||
|
||||
for (i = 0; i < szlines.count; ++i)
|
||||
for (unsigned i = 0; i < SZLine->GetCount(); ++i)
|
||||
{
|
||||
amask = (static_cast<SXLine *>(szlines.list[i]))->mask;
|
||||
if (!stricmp(mask, amask) || Anope::Match(amask, mask, false))
|
||||
szline_list(i + 1, static_cast<SXLine *>(szlines.list[i]), u, &sent_header);
|
||||
XLine *x = SZLine->GetEntry(i);
|
||||
|
||||
if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask)))
|
||||
{
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
SZLineListCallback::DoList(u, x, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sent_header)
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
@@ -229,39 +299,37 @@ class CommandOSSZLine : public Command
|
||||
|
||||
CommandReturn DoView(User *u, const std::vector<ci::string> ¶ms)
|
||||
{
|
||||
const char *mask;
|
||||
int res, sent_header = 0;
|
||||
|
||||
if (!szlines.count)
|
||||
if (SZLine->GetList().empty())
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_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(&szlines, mask, &szline_view_callback, u, &sent_header);
|
||||
if (!res)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH);
|
||||
return MOD_CONT;
|
||||
}
|
||||
}
|
||||
if (!mask.empty() && isdigit(mask[0]) && strspn(mask.c_str(), "1234567890,-") == mask.length())
|
||||
(new SZLineViewCallback(u, mask.c_str()))->Process();
|
||||
else
|
||||
{
|
||||
int i;
|
||||
char *amask;
|
||||
bool SentHeader = false;
|
||||
|
||||
for (i = 0; i < szlines.count; ++i)
|
||||
for (unsigned i = 0; i < SZLine->GetCount(); ++i)
|
||||
{
|
||||
amask = (static_cast<SXLine *>(szlines.list[i]))->mask;
|
||||
if (!stricmp(mask, amask) || Anope::Match(amask, mask, false))
|
||||
szline_view(i + 1, static_cast<SXLine *>(szlines.list[i]), u, &sent_header);
|
||||
XLine *x = SZLine->GetEntry(i);
|
||||
|
||||
if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask)))
|
||||
{
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_HEADER);
|
||||
}
|
||||
|
||||
SZLineViewCallback::DoList(u, x, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sent_header)
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_NO_MATCH);
|
||||
}
|
||||
|
||||
@@ -270,8 +338,8 @@ class CommandOSSZLine : public Command
|
||||
|
||||
CommandReturn DoClear(User *u)
|
||||
{
|
||||
FOREACH_MOD(I_OnDelSXLine, OnDelSXLine(u, NULL, SX_SZLINE));
|
||||
slist_clear(&szlines, 1);
|
||||
FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, NULL, X_SZLINE));
|
||||
SZLine->Clear();
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_CLEAR);
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -334,61 +402,4 @@ class OSSZLine : public Module
|
||||
}
|
||||
};
|
||||
|
||||
int szline_view(int number, SXLine *sx, User *u, int *sent_header)
|
||||
{
|
||||
char timebuf[32], expirebuf[256];
|
||||
struct tm tm;
|
||||
|
||||
if (!sx)
|
||||
return 0;
|
||||
|
||||
if (!*sent_header)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_HEADER);
|
||||
*sent_header = 1;
|
||||
}
|
||||
|
||||
tm = *localtime(&sx->seton);
|
||||
strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm);
|
||||
expire_left(u->Account(), expirebuf, sizeof(expirebuf), sx->expires);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_FORMAT, number, sx->mask, sx->by, timebuf, expirebuf, sx->reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Callback for enumeration purposes */
|
||||
int szline_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 szline_view(number, static_cast<SXLine *>(item), u, sent_header);
|
||||
}
|
||||
|
||||
/* Callback for enumeration purposes */
|
||||
int szline_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 szline_list(number, static_cast<SXLine *>(item), u, sent_header);
|
||||
}
|
||||
|
||||
/* Lists an SZLINE entry, prefixing it with the header if needed */
|
||||
int szline_list(int number, SXLine *sx, User *u, int *sent_header)
|
||||
{
|
||||
if (!sx)
|
||||
return 0;
|
||||
|
||||
if (!*sent_header)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_LIST_HEADER);
|
||||
*sent_header = 1;
|
||||
}
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_LIST_FORMAT, number, sx->mask, sx->reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
MODULE_INIT(OSSZLine)
|
||||
|
||||
Reference in New Issue
Block a user