summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlethality <lethality@anope.org>2012-02-23 00:04:36 +0000
committerlethality <lethality@anope.org>2012-02-23 00:04:36 +0000
commitf01aab5f9bf5c14162438d1707e6e6cd9730c703 (patch)
tree4df360cd61e7dd1fd749d90e9dbe9e3cf1d739af
parent826de43724d4584f9150a1fb8cebe8f49d9431a7 (diff)
parent3850b073ddf610415de54dced9ff134397779676 (diff)
Merge branch '1.9' of ssh://anope.git.sf.net/gitroot/anope/anope into 1.9
-rw-r--r--data/example.conf7
-rw-r--r--data/modules.example.conf22
-rw-r--r--docs/Changes2
-rw-r--r--docs/Changes.conf1
-rw-r--r--include/anope.h3
-rw-r--r--include/config.h2
-rw-r--r--include/defs.h1
-rw-r--r--include/module.h1
-rw-r--r--include/modules.h4
-rw-r--r--include/oper.h38
-rw-r--r--include/protocol.h24
-rw-r--r--include/regexpr.h47
-rw-r--r--include/uplink.h8
-rw-r--r--modules/commands/cs_akick.cpp4
-rw-r--r--modules/commands/cs_invite.cpp2
-rw-r--r--modules/commands/cs_list.cpp6
-rw-r--r--modules/commands/ms_del.cpp10
-rw-r--r--modules/commands/ns_ajoin.cpp12
-rw-r--r--modules/commands/ns_list.cpp6
-rw-r--r--modules/commands/os_akill.cpp203
-rw-r--r--modules/commands/os_chankill.cpp2
-rw-r--r--modules/commands/os_forbid.cpp15
-rw-r--r--modules/commands/os_ignore.cpp6
-rw-r--r--modules/commands/os_list.cpp10
-rw-r--r--modules/commands/os_oline.cpp4
-rw-r--r--modules/commands/os_sxline.cpp334
-rw-r--r--modules/database/db_old.cpp2
-rw-r--r--modules/extra/m_dnsbl.cpp11
-rw-r--r--modules/extra/m_proxyscan.cpp11
-rw-r--r--modules/extra/m_regex_pcre.cpp55
-rw-r--r--modules/extra/m_regex_posix.cpp57
-rw-r--r--modules/extra/m_regex_tre.cpp58
-rw-r--r--modules/protocol/bahamut.cpp108
-rw-r--r--modules/protocol/inspircd-ts6.h145
-rw-r--r--modules/protocol/inspircd11.cpp126
-rw-r--r--modules/protocol/inspircd12.cpp12
-rw-r--r--modules/protocol/inspircd20.cpp22
-rw-r--r--modules/protocol/plexus.cpp109
-rw-r--r--modules/protocol/ratbox.cpp97
-rw-r--r--modules/protocol/unreal.cpp101
-rw-r--r--modules/pseudoclients/operserv.cpp99
-rw-r--r--src/config.cpp2
-rw-r--r--src/main.cpp71
-rw-r--r--src/messages.cpp32
-rw-r--r--src/misc.cpp39
-rw-r--r--src/modulemanager.cpp2
-rw-r--r--src/operserv.cpp220
-rw-r--r--src/protocol.cpp78
-rw-r--r--src/regchannel.cpp4
49 files changed, 1499 insertions, 736 deletions
diff --git a/data/example.conf b/data/example.conf
index 73c6627a3..a746051c0 100644
--- a/data/example.conf
+++ b/data/example.conf
@@ -498,6 +498,13 @@ options
* If set, Services do not allow ownership of nick names, only ownership of accounts.
*/
nonicknameownership = no
+
+ /* The regex engine to use, as provided by the regex modules.
+ * Leave commented to disable regex matching.
+ *
+ * Note for this to work the regex module providing the regex engine must be loaded.
+ */
+ regexengine = "regex/pcre"
}
/*
diff --git a/data/modules.example.conf b/data/modules.example.conf
index 715be1898..101437d04 100644
--- a/data/modules.example.conf
+++ b/data/modules.example.conf
@@ -311,6 +311,28 @@ sqlite
}
/*
+ * m_regex_pcre
+ *
+ * Provides the regex engine regex/pcre, which uses the Perl Compatible Regular Expressions library.
+ */
+module { name = "m_regex_pcre" }
+
+/*
+ * m_regex_posix
+ *
+ * Provides the regex engine regex/posix, which uses the POSIX compliant regular expressions.
+ * This is likely the only regex module you will not need extra libraries for.
+ */
+#module { name = "m_regex_posix" }
+
+/*
+ * m_regex_tre
+ *
+ * Provides the regex engine regex/tre, which uses the TRE regex library.
+ */
+#module { name = "m_regex_tre" }
+
+/*
* m_rewrite
*
* Allows rewriting commands sent to clients.
diff --git a/docs/Changes b/docs/Changes
index 25b5dc142..7ad5a07da 100644
--- a/docs/Changes
+++ b/docs/Changes
@@ -1,5 +1,7 @@
Anope Version 1.9.7
--------------------
+A Added ability for using regex as patterns for various commands
+A Extended ability of operserv/akill to also match against nick and realname
Anope Version 1.9.6
--------------------
diff --git a/docs/Changes.conf b/docs/Changes.conf
index cdfbfa094..a9dd31cbf 100644
--- a/docs/Changes.conf
+++ b/docs/Changes.conf
@@ -1,6 +1,7 @@
Anope Version 1.9.7
-------------------
operserv:notifications removed in favor of log{} blocks
+options:regexengine added
Anope Version 1.9.6
-------------------
diff --git a/include/anope.h b/include/anope.h
index 421d735a3..b286d0fb6 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -346,8 +346,9 @@ namespace Anope
* @param str The string to check against the pattern (e.g. foobar)
* @param mask The pattern to check (e.g. foo*bar)
* @param case_sensitive Whether or not the match is case sensitive, default false.
+ * @param use_regex Whether or not to try regex. case_sensitive is not used in regex.
*/
- extern CoreExport bool Match(const string &str, const string &mask, bool case_sensitive = false);
+ extern CoreExport bool Match(const string &str, const string &mask, bool case_sensitive = false, bool use_regex = false);
/** Find a message in the message table
* @param name The name of the message were looking for
diff --git a/include/config.h b/include/config.h
index d53b7f41c..1ec67984a 100644
--- a/include/config.h
+++ b/include/config.h
@@ -456,6 +456,8 @@ class CoreExport ServerConfig
bool HidePrivilegedCommands;
/* If set, nicks cant be owned/everything is entirely account based */
bool NoNicknameOwnership;
+ /* Regex engine to use */
+ Anope::string RegexEngine;
/* A vector of our logfile options */
std::vector<LogInfo *> LogInfos;
diff --git a/include/defs.h b/include/defs.h
index 0a248daf7..098f48edd 100644
--- a/include/defs.h
+++ b/include/defs.h
@@ -35,6 +35,7 @@ class Module;
class NickAlias;
class NickCore;
class OperType;
+class Regex;
class Server;
class ServerConfig;
class Socket;
diff --git a/include/module.h b/include/module.h
index 94f565a3a..6865a2c17 100644
--- a/include/module.h
+++ b/include/module.h
@@ -36,6 +36,7 @@
#include "oper.h"
#include "opertype.h"
#include "protocol.h"
+#include "regexpr.h"
#include "regchannel.h"
#include "serialize.h"
#include "servers.h"
diff --git a/include/modules.h b/include/modules.h
index 1cb496a54..ce6bbba51 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -516,7 +516,7 @@ class CoreExport Module : public Extensible
/** Called before a XLine is deleted
* @param u The user deleting the XLine
- * @param x The XLine, can be NULL for all XLines
+ * @param x The XLine
* @param xlm The xline manager it was deleted from
*/
virtual void OnDelXLine(User *u, XLine *x, XLineManager *xlm) { }
@@ -835,7 +835,6 @@ class CoreExport Module : public Extensible
* @param nc The nickcore of the memo being deleted
* @param mi The memo info
* @param m The memo
- * @param number What memo number is being deleted, can be 0 for all memos
*/
virtual void OnMemoDel(const NickCore *nc, MemoInfo *mi, Memo *m) { }
@@ -843,7 +842,6 @@ class CoreExport Module : public Extensible
* @param ci The channel of the memo being deleted
* @param mi The memo info
* @param m The memo
- * @param number What memo number is being deleted, can be 0 for all memos
*/
virtual void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, Memo *m) { }
diff --git a/include/oper.h b/include/oper.h
index ced1d38dc..b3034b7c5 100644
--- a/include/oper.h
+++ b/include/oper.h
@@ -14,8 +14,10 @@
class CoreExport XLine : public Serializable
{
+ void InitRegex();
public:
Anope::string Mask;
+ Regex *regex;
Anope::string By;
time_t Created;
time_t Expires;
@@ -25,11 +27,18 @@ class CoreExport XLine : public Serializable
XLine(const Anope::string &mask, const Anope::string &reason = "", const Anope::string &uid = "");
- XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid);
+ XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid = "");
+ ~XLine();
Anope::string GetNick() const;
Anope::string GetUser() const;
Anope::string GetHost() const;
+ Anope::string GetReal() const;
+
+ Anope::string GetReason() const;
+
+ bool HasNickOrReal() const;
+ bool IsRegex() const;
Anope::string serialize_name() const;
serialized_data serialize();
@@ -41,7 +50,8 @@ class CoreExport XLineManager : public Service
char type;
/* List of XLines in this XLineManager */
std::vector<XLine *> XLines;
- static std::map<Anope::string, XLine *, ci::less> XLinesByUID;
+ /* Akills can have the same IDs, sometimes */
+ static std::multimap<Anope::string, XLine *, ci::less> XLinesByUID;
public:
/* List of XLine managers we check users against in XLineManager::CheckAll */
static std::list<XLineManager *> XLineManagers;
@@ -63,7 +73,7 @@ class CoreExport XLineManager : public Service
* Wparam u The user
* @return A pair of the XLineManager the user was found in and the XLine they matched, both may be NULL for no match
*/
- static std::pair<XLineManager *, XLine *> CheckAll(User *u);
+ static void CheckAll(User *u);
/** Generate a unique ID for this XLine
* @return A unique ID
@@ -116,15 +126,13 @@ class CoreExport XLineManager : public Service
void Clear();
/** Checks if a mask can/should be added to the XLineManager
+ * @param source The source adding the mask.
* @param mask The mask
* @param expires When the mask would expire
- * @return A pair of int and XLine*.
- * 1 - Mask already exists
- * 2 - Mask already exists, but the expiry time was changed
- * 3 - Mask is already covered by another mask
- * In each case the XLine it matches/is covered by is returned in XLine*
+ * @param reason the reason
+ * @return true if the mask can be added
*/
- std::pair<int, XLine *> CanAdd(const Anope::string &mask, time_t expires);
+ bool CanAdd(CommandSource &source, const Anope::string &mask, time_t expires, const Anope::string &reason);
/** Checks if this list has an entry
* @param mask The mask
@@ -134,15 +142,21 @@ class CoreExport XLineManager : public Service
/** Check a user against all of the xlines in this XLineManager
* @param u The user
- * @return The xline the user marches, if any. Also calls OnMatch()
+ * @return The xline the user marches, if any.
+ */
+ XLine *CheckAllXLines(User *u);
+
+ /** Check a user against an xline
+ * @param u The user
+ * @param x The xline
*/
- virtual XLine *Check(User *u);
+ virtual bool Check(User *u, XLine *x) = 0;
/** Called when a user matches a xline in this XLineManager
* @param u The user
* @param x The XLine they match
*/
- virtual void OnMatch(User *u, XLine *x);
+ virtual void OnMatch(User *u, XLine *x) = 0;
/** Called when an XLine expires
* @param x The xline
diff --git a/include/protocol.h b/include/protocol.h
index f1bb9dbbe..edfc5bd53 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -48,11 +48,11 @@ struct IRCDVar
class CoreExport IRCDProto
{
- private:
- virtual void SendSVSKillInternal(const BotInfo *, const User *, const Anope::string &) = 0;
- virtual void SendModeInternal(const BotInfo *, const Channel *, const Anope::string &) = 0;
+ protected:
+ virtual void SendSVSKillInternal(const BotInfo *, const User *, const Anope::string &);
+ virtual void SendModeInternal(const BotInfo *, const Channel *, const Anope::string &);
virtual void SendModeInternal(const BotInfo *, const User *, const Anope::string &) = 0;
- virtual void SendKickInternal(const BotInfo *, const Channel *, const User *, const Anope::string &) = 0;
+ virtual void SendKickInternal(const BotInfo *, const Channel *, const User *, const Anope::string &);
virtual void SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf);
virtual void SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg);
virtual void SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf);
@@ -60,14 +60,14 @@ class CoreExport IRCDProto
virtual void SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf);
virtual void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf);
virtual void SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf);
- virtual void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf);
+ virtual void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf);
public:
virtual ~IRCDProto() { }
virtual void SendSVSNOOP(const Server *, bool) { }
- virtual void SendTopic(BotInfo *, Channel *) = 0;
+ virtual void SendTopic(BotInfo *, Channel *);
virtual void SendVhostDel(User *) { }
- virtual void SendAkill(User *, const XLine *) = 0;
+ virtual void SendAkill(User *, XLine *) = 0;
virtual void SendAkillDel(const XLine *) = 0;
virtual void SendSVSKill(const BotInfo *source, const User *user, const char *fmt, ...);
virtual void SendMode(const BotInfo *bi, const Channel *dest, const char *fmt, ...);
@@ -86,12 +86,12 @@ class CoreExport IRCDProto
virtual void SendPong(const Anope::string &servname, const Anope::string &who);
virtual void SendJoin(User *, Channel *, const ChannelStatus *) = 0;
virtual void SendSQLineDel(const XLine *x) { }
- virtual void SendInvite(const BotInfo *bi, const Anope::string &chan, const Anope::string &nick);
+ virtual void SendInvite(const BotInfo *bi, const Channel *c, const User *u);
virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...);
virtual void SendGlobops(const BotInfo *source, const char *fmt, ...);
virtual void SendSQLine(User *, const XLine *x) { }
virtual void SendSquit(Server *, const Anope::string &message);
- virtual void SendSVSO(const Anope::string &, const Anope::string &, const Anope::string &) { }
+ virtual void SendSVSO(const BotInfo *, const Anope::string &, const Anope::string &) { }
virtual void SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick);
virtual void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when);
virtual void SendVhost(User *, const Anope::string &, const Anope::string &) { }
@@ -103,14 +103,14 @@ class CoreExport IRCDProto
virtual void SendSZLine(User *u, const XLine *) { }
virtual void SendSGLine(User *, const XLine *) { }
virtual void SendCTCP(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...);
- virtual void SendSVSJoin(const Anope::string &, const Anope::string &, const Anope::string &, const Anope::string &) { }
- virtual void SendSWhois(const Anope::string &, const Anope::string &, const Anope::string &) { }
+ virtual void SendSVSJoin(const BotInfo *bi, const Anope::string &, const Anope::string &, const Anope::string &) { }
+ virtual void SendSWhois(const BotInfo *bi, const Anope::string &, const Anope::string &) { }
virtual void SendBOB() { }
virtual void SendEOB() { }
virtual void SendServer(const Server *) = 0;
virtual bool IsNickValid(const Anope::string &) { return true; }
virtual bool IsChannelValid(const Anope::string &);
- virtual void SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...);
+ virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...);
virtual void SendLogin(User *u) = 0;
virtual void SendLogout(User *u) = 0;
diff --git a/include/regexpr.h b/include/regexpr.h
new file mode 100644
index 000000000..a333c7e1b
--- /dev/null
+++ b/include/regexpr.h
@@ -0,0 +1,47 @@
+/*
+ *
+ * (C) 2003-2012 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.
+ *
+ */
+
+#ifndef REGEXPR_H
+#define REGEXPR_H
+
+#include "services.h"
+#include "anope.h"
+#include "service.h"
+
+class RegexException : public CoreException
+{
+ public:
+ RegexException(const Anope::string &reason = "") : CoreException(reason) { }
+
+ virtual ~RegexException() throw() { }
+};
+
+class CoreExport Regex
+{
+ Anope::string expression;
+ protected:
+ Regex(const Anope::string &expr) : expression(expr) { }
+ public:
+ virtual ~Regex() { }
+ const Anope::string &GetExpression() { return expression; }
+ virtual bool Matches(const Anope::string &str) = 0;
+};
+
+class CoreExport RegexProvider : public Service
+{
+ public:
+ RegexProvider(Module *o, const Anope::string &n) : Service(o, "Regex", n) { }
+ virtual Regex *Compile(const Anope::string &) = 0;
+};
+
+#endif // REGEXPR_H
+
diff --git a/include/uplink.h b/include/uplink.h
index 7f200d426..70b20a28b 100644
--- a/include/uplink.h
+++ b/include/uplink.h
@@ -25,11 +25,15 @@ class UplinkSocket : public ConnectionSocket, public BufferedSocket
class CoreExport Message
{
- Anope::string source;
+ private:
+ const Server *server;
+ const User *user;
std::stringstream buffer;
+
public:
Message();
- Message(const Anope::string &);
+ explicit Message(const Server *);
+ explicit Message(const User *);
~Message();
template<typename T> Message &operator<<(const T &val)
{
diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp
index 328a169d4..beaa8ffd3 100644
--- a/modules/commands/cs_akick.cpp
+++ b/modules/commands/cs_akick.cpp
@@ -207,6 +207,8 @@ class CommandCSAKick : public Command
if (!Number || Number > ci->GetAkickCount())
return;
+ FOREACH_MOD(I_OnAkickDel, OnAkickDel(source.u, ci, ci->GetAkick(Number - 1)));
+
++Deleted;
ci->EraseAkick(Number - 1);
}
@@ -236,6 +238,8 @@ class CommandCSAKick : public Command
bool override = !ci->AccessFor(u).HasPriv("AKICK");
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to delete " << mask;
+ FOREACH_MOD(I_OnAkickDel, OnAkickDel(u, ci, ci->GetAkick(i)));
+
ci->EraseAkick(i);
source.Reply(_("\002%s\002 deleted from %s autokick list."), mask.c_str(), ci->name.c_str());
diff --git a/modules/commands/cs_invite.cpp b/modules/commands/cs_invite.cpp
index b38828c9d..be3132907 100644
--- a/modules/commands/cs_invite.cpp
+++ b/modules/commands/cs_invite.cpp
@@ -71,7 +71,7 @@ class CommandCSInvite : public Command
{
bool override = !ci->AccessFor(u).HasPriv("INVITE");
- ircdproto->SendInvite(ci->WhoSends(), chan, u2->nick);
+ ircdproto->SendInvite(ci->WhoSends(), c, u2);
if (u2 != u)
{
source.Reply(_("\002%s\002 has been invited to \002%s\002."), u2->nick.c_str(), c->name.c_str());
diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp
index 57c14d157..77d7613fe 100644
--- a/modules/commands/cs_list.cpp
+++ b/modules/commands/cs_list.cpp
@@ -87,7 +87,7 @@ class CommandCSList : public Command
else if (channoexpire && !ci->HasFlag(CI_NO_EXPIRE))
continue;
- if (pattern.equals_ci(ci->name) || ci->name.equals_ci(spattern) || Anope::Match(ci->name, pattern) || Anope::Match(ci->name, spattern))
+ if (pattern.equals_ci(ci->name) || ci->name.equals_ci(spattern) || Anope::Match(ci->name, pattern, false, true) || Anope::Match(ci->name, spattern, false, true))
{
if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nchans <= Config->CSListMax)
{
@@ -125,6 +125,10 @@ class CommandCSList : public Command
"(Channels with the \002PRIVATE\002 option set are not listed.)\n"
"Note that a preceding '#' specifies a range, channel names\n"
"are to be written without '#'."));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str());
return true;
}
};
diff --git a/modules/commands/ms_del.cpp b/modules/commands/ms_del.cpp
index f0b65eeac..65969b025 100644
--- a/modules/commands/ms_del.cpp
+++ b/modules/commands/ms_del.cpp
@@ -107,13 +107,15 @@ class CommandMSDel : public Command
}
else
{
- if (ci)
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, NULL));
- else
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, NULL));
/* Delete all memos. */
for (unsigned i = 0, end = mi->memos.size(); i < end; ++i)
+ {
+ if (ci)
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[i]));
+ else
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[i]));
delete mi->memos[i];
+ }
mi->memos.clear();
if (!chan.empty())
source.Reply(_("All memos for channel %s have been deleted."), chan.c_str());
diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp
index 5a5dbe7f0..03b710356 100644
--- a/modules/commands/ns_ajoin.cpp
+++ b/modules/commands/ns_ajoin.cpp
@@ -194,8 +194,9 @@ class NSAJoin : public Module
void OnNickIdentify(User *u) anope_override
{
AJoinList *channels = u->Account()->GetExt<AJoinList *>("ns_ajoin_channels");
+ BotInfo *bi = findbot(Config->NickServ);
- if (channels == NULL)
+ if (channels == NULL || bi == NULL)
return;
for (unsigned i = 0; i < channels->size(); ++i)
@@ -255,15 +256,14 @@ class NSAJoin : public Module
}
}
- if (need_invite)
+ if (need_invite && c != NULL)
{
- BotInfo *bi = findbot(Config->NickServ);
- if (!bi || !ci->AccessFor(u).HasPriv("INVITE"))
+ if (!ci->AccessFor(u).HasPriv("INVITE"))
continue;
- ircdproto->SendInvite(bi, channels->at(i).first, u->nick);
+ ircdproto->SendInvite(bi, c, u);
}
- ircdproto->SendSVSJoin(Config->NickServ, u->nick, channels->at(i).first, key);
+ ircdproto->SendSVSJoin(bi, u->nick, channels->at(i).first, key);
}
}
};
diff --git a/modules/commands/ns_list.cpp b/modules/commands/ns_list.cpp
index 491ed8733..de2852302 100644
--- a/modules/commands/ns_list.cpp
+++ b/modules/commands/ns_list.cpp
@@ -93,7 +93,7 @@ class CommandNSList : public Command
* Instead we build a nice nick!user@host buffer to compare.
* The output is then generated separately. -TheShadow */
Anope::string buf = Anope::printf("%s!%s", na->nick.c_str(), !na->last_usermask.empty() ? na->last_usermask.c_str() : "*@*");
- if (na->nick.equals_ci(pattern) || Anope::Match(buf, pattern))
+ if (na->nick.equals_ci(pattern) || Anope::Match(buf, pattern, false, true))
{
if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nnicks <= Config->NSListMax)
{
@@ -156,6 +156,10 @@ class CommandNSList : public Command
" \n"
" \002LIST * NOEXPIRE\002\n"
" Lists all registered nicks which have been set to not expire.\n"));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str());
return true;
}
diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp
index 89485f706..f59c26e1f 100644
--- a/modules/commands/os_akill.cpp
+++ b/modules/commands/os_akill.cpp
@@ -60,19 +60,24 @@ class CommandOSAKill : public Command
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
User *u = source.u;
- unsigned last_param = 2;
Anope::string expiry, mask;
- time_t expires;
- mask = params.size() > 1 ? params[1] : "";
- if (!mask.empty() && mask[0] == '+')
+ if (params.size() < 2)
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ spacesepstream sep(params[1]);
+ sep.GetToken(mask);
+
+ if (mask[0] == '+')
{
expiry = mask;
- mask = params.size() > 2 ? params[2] : "";
- last_param = 3;
+ sep.GetToken(mask);
}
- expires = !expiry.empty() ? dotime(expiry) : Config->AutokillExpiry;
+ time_t expires = !expiry.empty() ? dotime(expiry) : Config->AutokillExpiry;
/* If the expiry given does not contain a final letter, it's in days,
* said the doc. Ah well.
*/
@@ -87,84 +92,108 @@ class CommandOSAKill : public Command
else if (expires > 0)
expires += Anope::CurTime;
- if (params.size() <= last_param)
+ if (sep.StreamEnd())
{
this->OnSyntaxError(source, "ADD");
return;
}
- Anope::string reason = params[last_param];
- if (last_param == 2 && params.size() > 3)
- reason += " " + params[3];
- if (!mask.empty() && !reason.empty())
+ Anope::string reason;
+ if (mask.find('#') != Anope::string::npos)
{
- User *targ = NULL;
- std::pair<int, XLine *> canAdd = akills->CanAdd(mask, expires);
- if (mask.find('!') != Anope::string::npos)
- source.Reply(_("\002Reminder\002: AKILL masks cannot contain nicknames; make sure you have \002not\002 included a nick portion in your mask."));
- else if (mask.find('@') == Anope::string::npos && !(targ = finduser(mask)))
- source.Reply(BAD_USERHOST_MASK);
- else if (mask.find_first_not_of("~@.*?") == Anope::string::npos)
- source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
- else if (canAdd.first == 1)
- source.Reply(_("\002%s\002 already exists on the AKILL list."), canAdd.second->Mask.c_str());
- else if (canAdd.first == 2)
- source.Reply(_("Expiry time of \002%s\002 changed."), canAdd.second->Mask.c_str());
- else if (canAdd.first == 3)
- source.Reply(_("\002%s\002 is already covered by %s."), mask.c_str(), canAdd.second->Mask.c_str());
- else
+ Anope::string remaining = sep.GetRemaining();
+
+ size_t co = remaining[0] == ':' ? 0 : remaining.rfind(" :");
+ if (co == Anope::string::npos)
{
- if (targ)
- mask = "*@" + targ->host;
- unsigned int affected = 0;
- for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (Anope::Match(it->second->GetIdent() + "@" + it->second->host, mask))
- ++affected;
- float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
-
- if (percent > 95)
- {
- source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
- Log(LOG_ADMIN, u, this) << "tried to akill " << percent << "% of the network (" << affected << " users)";
- return;
- }
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
- if (Config->AddAkiller)
- reason = "[" + u->nick + "] " + reason;
+ if (co != 0)
+ ++co;
- Anope::string id;
- if (Config->AkillIds)
- {
- id = XLineManager::GenerateUID();
- reason = reason + " (ID: " + id + ")";
- }
+ reason = remaining.substr(co + 1);
+ mask += " " + remaining.substr(0, co);
+ mask.trim();
+ }
+ else
+ reason = sep.GetRemaining();
- XLine *x = new XLine(mask, u->nick, expires, reason, id);
+ if (mask[0] == '/' && mask[mask.length() - 1] == '/')
+ {
+ if (Config->RegexEngine.empty())
+ {
+ source.Reply(_("Regex is enabled."));
+ return;
+ }
- EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, akills));
- if (MOD_RESULT == EVENT_STOP)
- {
- delete x;
- return;
- }
+ service_reference<RegexProvider> provider("Regex", Config->RegexEngine);
+ if (!provider)
+ {
+ source.Reply(_("Unable to find regex engine %s"), Config->RegexEngine.c_str());
+ return;
+ }
+
+ try
+ {
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
+ delete provider->Compile(stripped_mask);
+ }
+ catch (const RegexException &ex)
+ {
+ source.Reply("%s", ex.GetReason().c_str());
+ return;
+ }
+ }
- akills->AddXLine(x);
- if (Config->AkillOnAdd)
- akills->Send(NULL, x);
+ User *targ = finduser(mask);
+ if (targ)
+ mask = "*@" + targ->host;
+
+ if (!akills->CanAdd(source, mask, expires, reason))
+ return;
+ else if (mask.find_first_not_of("/~@.*?") == Anope::string::npos)
+ {
+ source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
+ return;
+ }
- source.Reply(_("\002%s\002 added to the AKILL list."), mask.c_str());
+ XLine *x = new XLine(mask, u->nick, expires, reason);
+ if (Config->AkillIds)
+ x->UID = XLineManager::GenerateUID();
- Log(LOG_ADMIN, u, this) << "on " << mask << " (" << x->Reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ unsigned int affected = 0;
+ for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (akills->Check(it->second, x))
+ ++affected;
+ float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
- if (readonly)
- source.Reply(READ_ONLY_MODE);
- }
+ if (percent > 95)
+ {
+ source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
+ Log(LOG_ADMIN, u, this) << "tried to akill " << percent << "% of the network (" << affected << " users)";
+ delete x;
+ return;
}
- else
- this->OnSyntaxError(source, "ADD");
- return;
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, akills));
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ delete x;
+ return;
+ }
+
+ akills->AddXLine(x);
+ if (Config->AkillOnAdd)
+ akills->Send(NULL, x);
+
+ source.Reply(_("\002%s\002 added to the AKILL list."), mask.c_str());
+
+ Log(LOG_ADMIN, u, this) << "on " << mask << " (" << x->Reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ if (readonly)
+ source.Reply(READ_ONLY_MODE);
}
void DoDel(CommandSource &source, const std::vector<Anope::string> &params)
@@ -199,10 +228,14 @@ class CommandOSAKill : public Command
return;
}
- FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, akills));
+ do
+ {
+ FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, akills));
- source.Reply(_("\002%s\002 deleted from the AKILL list."), x->Mask.c_str());
- AkillDelCallback::DoDel(source, x);
+ source.Reply(_("\002%s\002 deleted from the AKILL list."), x->Mask.c_str());
+ AkillDelCallback::DoDel(source, x);
+ }
+ while ((x = akills->HasEntry(mask)));
}
@@ -240,7 +273,7 @@ class CommandOSAKill : public Command
entry["Number"] = stringify(number);
entry["Mask"] = x->Mask;
entry["Creator"] = x->By;
- entry["Created"] = do_strftime(x->Created);
+ entry["Created"] = do_strftime(x->Created, NULL, true);
entry["Expires"] = expire_left(NULL, x->Expires);
entry["Reason"] = x->Reason;
this->list.addEntry(entry);
@@ -255,13 +288,13 @@ class CommandOSAKill : public Command
{
XLine *x = akills->GetEntry(i);
- if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask))
+ if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask, false, true))
{
ListFormatter::ListEntry entry;
entry["Number"] = stringify(i + 1);
entry["Mask"] = x->Mask;
entry["Creator"] = x->By;
- entry["Created"] = do_strftime(x->Created);
+ entry["Created"] = do_strftime(x->Created, NULL, true);
entry["Expires"] = expire_left(source.u->Account(), x->Expires);
entry["Reason"] = x->Reason;
list.addEntry(entry);
@@ -316,18 +349,18 @@ class CommandOSAKill : public Command
void DoClear(CommandSource &source)
{
User *u = source.u;
- FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, NULL, akills));
for (unsigned i = akills->GetCount(); i > 0; --i)
{
XLine *x = akills->GetEntry(i - 1);
+ FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, akills));
akills->DelXLine(x);
}
source.Reply(_("The AKILL list has been cleared."));
}
public:
- CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 4)
+ CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 2)
{
this->SetDesc(_("Manipulate the AKILL list"));
this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037"));
@@ -367,11 +400,14 @@ class CommandOSAKill : public Command
source.Reply(_("Allows Services operators to manipulate the AKILL list. If\n"
"a user matching an AKILL mask attempts to connect, Services\n"
"will issue a KILL for that user and, on supported server\n"
- "types, will instruct all servers to add a ban (K-line) for\n"
- "the mask which the user matched.\n"
+ "types, will instruct all servers to add a ban for the mask\n"
+ "which the user matched.\n"
" \n"
- "\002AKILL ADD\002 adds the given nick or user@host/ip mask to the AKILL\n"
- "list for the given reason (which \002must\002 be given).\n"
+ "\002AKILL ADD\002 adds the given mask to the AKILL\n"
+ "list for the given reason, which \002must\002 be given.\n"
+ "Mask should be in the format of nick!user@host#real name,\n"
+ "though all that is required is user@host. If a real name is specified,\n"
+ "the reason must be prepended with a :.\n"
"\037expiry\037 is specified as an integer followed by one of \037d\037 \n"
"(days), \037h\037 (hours), or \037m\037 (minutes). Combinations (such as \n"
"\0371h30m\037) are not permitted. If a unit specifier is not \n"
@@ -380,7 +416,12 @@ class CommandOSAKill : public Command
"usermask to be added starts with a \037+\037, an expiry time must\n"
"be given, even if it is the same as the default. The\n"
"current AKILL default expiry time can be found with the\n"
- "\002STATS AKILL\002 command.\n"
+ "\002STATS AKILL\002 command.\n"));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your mask in // if this desired.", Config->RegexEngine.c_str());
+ source.Reply(_(
" \n"
"The \002AKILL DEL\002 command removes the given mask from the\n"
"AKILL list if it is present. If a list of entry numbers is \n"
diff --git a/modules/commands/os_chankill.cpp b/modules/commands/os_chankill.cpp
index 8b56eb3c2..bbfb5121b 100644
--- a/modules/commands/os_chankill.cpp
+++ b/modules/commands/os_chankill.cpp
@@ -82,7 +82,7 @@ class CommandOSChanKill : public Command
XLine *x = new XLine("*@" + uc->user->host, u->nick, expires, realreason, XLineManager::GenerateUID());
akills->AddXLine(x);
- akills->Check(uc->user);
+ akills->OnMatch(uc->user, x);
}
Log(LOG_ADMIN, u, this) << "on " << c->name << " (" << realreason << ")";
diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp
index 908e2f2ca..d305de3c6 100644
--- a/modules/commands/os_forbid.cpp
+++ b/modules/commands/os_forbid.cpp
@@ -41,7 +41,7 @@ class MyForbidService : public ForbidService
{
ForbidData *d = this->forbidData[i - 1];
- if ((ftype == FT_NONE || ftype == d->type) && Anope::Match(mask, d->mask))
+ if ((ftype == FT_NONE || ftype == d->type) && Anope::Match(mask, d->mask, false, true))
return d;
}
return NULL;
@@ -217,6 +217,10 @@ class CommandOSForbid : public Command
source.Reply(" ");
source.Reply(_("Forbid allows you to forbid usage of certain nicknames, channels,\n"
"and email addresses. Wildcards are accepted for all entries."));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str());
return true;
}
};
@@ -273,8 +277,13 @@ class OSForbid : public Module
BotInfo *bi = findbot(Config->OperServ);
ForbidData *d = this->forbidService.FindForbid(c->name, FT_CHAN);
if (bi != NULL && d != NULL)
- {
- if (!c->HasFlag(CH_INHABIT))
+ {
+ if (ircd->chansqline)
+ {
+ XLine x(c->name, bi->nick, Anope::CurTime + Config->CSInhabit, d->reason);
+ ircdproto->SendSQLine(NULL, &x);
+ }
+ else if (!c->HasFlag(CH_INHABIT))
{
/* Join ChanServ and set a timer for this channel to part ChanServ later */
c->Hold();
diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp
index f2012f212..3d84a4635 100644
--- a/modules/commands/os_ignore.cpp
+++ b/modules/commands/os_ignore.cpp
@@ -119,7 +119,7 @@ class OSIgnoreService : public IgnoreService
tmp = mask + "!*@*";
for (; ign != ign_end; ++ign)
- if (Anope::Match(tmp, ign->mask))
+ if (Anope::Match(tmp, ign->mask, false, true))
break;
}
@@ -297,6 +297,10 @@ class CommandOSIgnore : public Command
"Wildcards are permitted.\n"
" \n"
"Ignores will not be enforced on IRC Operators."));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str());
return true;
}
};
diff --git a/modules/commands/os_list.cpp b/modules/commands/os_list.cpp
index e9d67b52e..2850e0203 100644
--- a/modules/commands/os_list.cpp
+++ b/modules/commands/os_list.cpp
@@ -67,7 +67,7 @@ class CommandOSChanList : public Command
{
Channel *c = cit->second;
- if (!pattern.empty() && !Anope::Match(c->name, pattern))
+ if (!pattern.empty() && !Anope::Match(c->name, pattern, false, true))
continue;
if (!Modes.empty())
for (std::list<ChannelModeName>::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it)
@@ -102,6 +102,10 @@ class CommandOSChanList : public Command
"is given, lists only the channels the user using it is on. If SECRET is\n"
"specified, lists only channels matching \002pattern\002 that have the +s or\n"
"+p mode."));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str());
return true;
}
};
@@ -194,6 +198,10 @@ class CommandOSUserList : public Command
"the format nick!user@host). If \002channel\002 is given, lists only users\n"
"that are on the given channel. If INVISIBLE is specified, only users\n"
"with the +i flag will be listed."));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str());
return true;
}
};
diff --git a/modules/commands/os_oline.cpp b/modules/commands/os_oline.cpp
index 5992f296e..3076da434 100644
--- a/modules/commands/os_oline.cpp
+++ b/modules/commands/os_oline.cpp
@@ -34,7 +34,7 @@ class CommandOSOLine : public Command
source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
else if (u2 && flag[0] == '+')
{
- ircdproto->SendSVSO(Config->OperServ, nick, flag);
+ ircdproto->SendSVSO(source.owner, nick, flag);
u2->SetMode(source.owner, UMODE_OPER);
u2->SendMessage(source.owner, _("You are now an IRC Operator."));
source.Reply(_("Operflags \002%s\002 have been added for \002%s\002."), flag.c_str(), nick.c_str());
@@ -42,7 +42,7 @@ class CommandOSOLine : public Command
}
else if (u2 && flag[0] == '-')
{
- ircdproto->SendSVSO(Config->OperServ, nick, flag);
+ ircdproto->SendSVSO(source.owner, nick, flag);
source.Reply(_("Operflags \002%s\002 have been added for \002%s\002."), flag.c_str(), nick.c_str());
Log(LOG_ADMIN, u, this) << "for " << nick;
}
diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp
index e65811571..d6c2ba094 100644
--- a/modules/commands/os_sxline.cpp
+++ b/modules/commands/os_sxline.cpp
@@ -141,7 +141,7 @@ class CommandOSSXLineBase : public Command
entry["Number"] = stringify(Number);
entry["Mask"] = x->Mask;
entry["By"] = x->By;
- entry["Created"] = do_strftime(x->Created);
+ entry["Created"] = do_strftime(x->Created, NULL, true);
entry["Expires"] = expire_left(NULL, x->Expires);
entry["Reason"] = x->Reason;
list.addEntry(entry);
@@ -156,13 +156,13 @@ class CommandOSSXLineBase : public Command
{
XLine *x = this->xlm()->GetEntry(i);
- if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask))
+ if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask, false, true))
{
ListFormatter::ListEntry entry;
entry["Number"] = stringify(i + 1);
entry["Mask"] = x->Mask;
entry["By"] = x->By;
- entry["Created"] = do_strftime(x->Created);
+ entry["Created"] = do_strftime(x->Created, NULL, true);
entry["Expires"] = expire_left(source.u->Account(), x->Expires);
entry["Reason"] = x->Reason;
list.addEntry(entry);
@@ -307,85 +307,105 @@ class CommandOSSNLine : public CommandOSSXLineBase
sep.GetToken(mask);
Anope::string reason = sep.GetRemaining();
- if (!mask.empty() && !reason.empty())
+ if (mask.empty() || reason.empty())
{
- std::pair<int, XLine *> canAdd = this->xlm()->CanAdd(mask, expires);
- if (mask.find_first_not_of("*?") == Anope::string::npos)
- source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
- else if (canAdd.first == 1)
- source.Reply(_("\002%s\002 already exists on the %s list."), canAdd.second->Mask.c_str(), source.command.c_str());
- else if (canAdd.first == 2)
- source.Reply(_("Expiry time of \002%s\002 changed."), canAdd.second->Mask.c_str());
- else if (canAdd.first == 3)
- source.Reply(_("\002%s\002 is already covered by %s."), mask.c_str(), canAdd.second->Mask.c_str());
- else
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ if (mask[0] == '/' && mask[mask.length() - 1] == '/')
+ {
+ if (Config->RegexEngine.empty())
{
- /* Clean up the last character of the mask if it is a space
- * See bug #761
- */
- unsigned masklen = mask.length();
- if (mask[masklen - 1] == ' ')
- mask.erase(masklen - 1);
- unsigned int affected = 0;
- for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (Anope::Match(it->second->realname, mask))
- ++affected;
- float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
-
- if (percent > 95)
- {
- source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
- Log(LOG_ADMIN, u, this) << "tried to " << source.command << " " << percent << "% of the network (" << affected << " users)";
- return;
- }
+ source.Reply(_("Regex is enabled."));
+ return;
+ }
- if (Config->AddAkiller)
- reason = "[" + u->nick + "] " + reason;
+ service_reference<RegexProvider> provider("Regex", Config->RegexEngine);
+ if (!provider)
+ {
+ source.Reply(_("Unable to find regex engine %s"), Config->RegexEngine.c_str());
+ return;
+ }
- Anope::string id;
- if (Config->AkillIds)
- {
- id = XLineManager::GenerateUID();
- reason = reason + " (ID: " + id + ")";
- }
+ try
+ {
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
+ delete provider->Compile(stripped_mask);
+ }
+ catch (const RegexException &ex)
+ {
+ source.Reply("%s", ex.GetReason().c_str());
+ return;
+ }
+ }
- XLine *x = new XLine(mask, u->nick, expires, reason, id);
+ if (!this->xlm()->CanAdd(source, mask, expires, reason))
+ return;
+ else if (mask.find_first_not_of("/.*?") == Anope::string::npos)
+ {
+ source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
+ return;
+ }
- EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm()));
- if (MOD_RESULT == EVENT_STOP)
- {
- delete x;
- return;
- }
+ /* Clean up the last character of the mask if it is a space
+ * See bug #761
+ */
+ unsigned masklen = mask.length();
+ if (mask[masklen - 1] == ' ')
+ mask.erase(masklen - 1);
- this->xlm()->AddXLine(x);
- if (Config->KillonSNline && !ircd->sglineenforce)
- {
- Anope::string rreason = "G-Lined: " + reason;
+ XLine *x = new XLine(mask, u->nick, expires, reason);
+ if (Config->AkillIds)
+ x->UID = XLineManager::GenerateUID();
- for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
- {
- User *user = it->second;
- ++it;
+ unsigned int affected = 0;
+ for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (this->xlm()->Check(it->second, x))
+ ++affected;
+ float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
- if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->realname, x->Mask))
- user->Kill(Config->ServerName, rreason);
- }
- }
+ if (percent > 95)
+ {
+ source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
+ Log(LOG_ADMIN, u, this) << "tried to " << source.command << " " << percent << "% of the network (" << affected << " users)";
+ delete x;
+ return;
+ }
- source.Reply(_("\002%s\002 added to the %s list."), mask.c_str(), source.command.c_str());
- Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm()));
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ delete x;
+ return;
+ }
- if (readonly)
- source.Reply(READ_ONLY_MODE);
- }
+ this->xlm()->AddXLine(x);
+ if (Config->KillonSNline)
+ {
+ this->xlm()->Send(u, x);
+
+ if (!ircd->sglineenforce)
+ {
+ Anope::string rreason = "G-Lined: " + reason;
+
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
+ {
+ User *user = it->second;
+ ++it;
+
+ if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->realname, x->Mask, false, true))
+ user->Kill(Config->ServerName, rreason);
+ }
+ }
}
- else
- this->OnSyntaxError(source, "ADD");
- return;
+ source.Reply(_("\002%s\002 added to the %s list."), mask.c_str(), source.command.c_str());
+ Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ if (readonly)
+ source.Reply(READ_ONLY_MODE);
}
service_reference<XLineManager> snlines;
@@ -421,6 +441,10 @@ class CommandOSSNLine : public CommandOSSXLineBase
"\002STATS AKILL\002 command.\n"
"Note: because the realname mask may contain spaces, the\n"
"separator between it and the reason is a colon.\n"));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your mask in // if this desired.", Config->RegexEngine.c_str());
source.Reply(_(" \n"
"The \002SNLINE DEL\002 command removes the given mask from the\n"
"SNLINE list if it is present. If a list of entry numbers is \n"
@@ -496,95 +520,118 @@ class CommandOSSQLine : public CommandOSSXLineBase
Anope::string reason = params[last_param];
if (last_param == 2 && params.size() > 3)
reason += " " + params[3];
- if (!mask.empty() && !reason.empty())
+
+ if (mask.empty() || reason.empty())
{
- std::pair<int, XLine *> canAdd = this->sqlines->CanAdd(mask, expires);
- if (mask.find_first_not_of("*") == Anope::string::npos)
- source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
- else if (canAdd.first == 1)
- source.Reply(_("\002%s\002 already exists on the SQLINE list."), canAdd.second->Mask.c_str());
- else if (canAdd.first == 2)
- source.Reply(_("Expiry time of \002%s\002 changed."), canAdd.second->Mask.c_str());
- else if (canAdd.first == 3)
- source.Reply(_("\002%s\002 is already covered by %s."), mask.c_str(), canAdd.second->Mask.c_str());
- else
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ if (mask[0] == '/' && mask[mask.length() - 1] == '/')
+ {
+ if (Config->RegexEngine.empty())
{
- unsigned int affected = 0;
- for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (Anope::Match(it->second->nick, mask))
- ++affected;
- float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
+ source.Reply(_("Regex is enabled."));
+ return;
+ }
- if (percent > 95)
- {
- source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
- Log(LOG_ADMIN, u, this) << "tried to SQLine " << percent << "% of the network (" << affected << " users)";
- return;
- }
+ service_reference<RegexProvider> provider("Regex", Config->RegexEngine);
+ if (!provider)
+ {
+ source.Reply(_("Unable to find regex engine %s"), Config->RegexEngine.c_str());
+ return;
+ }
- Anope::string id = XLineManager::GenerateUID();
- reason = reason + " (ID: " + id + ")";
+ try
+ {
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
+ delete provider->Compile(stripped_mask);
+ }
+ catch (const RegexException &ex)
+ {
+ source.Reply("%s", ex.GetReason().c_str());
+ return;
+ }
+ }
- XLine *x = new XLine(mask, u->nick, expires, reason, id);
+ if (!this->sqlines->CanAdd(source, mask, expires, reason))
+ return;
+ else if (mask.find_first_not_of("./?*") == Anope::string::npos)
+ {
+ source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
+ return;
+ }
- EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm()));
- if (MOD_RESULT == EVENT_STOP)
- {
- delete x;
- return;
- }
+ XLine *x = new XLine(mask, u->nick, expires, reason);
+ if (Config->AkillIds)
+ x->UID = XLineManager::GenerateUID();
+
+ unsigned int affected = 0;
+ for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (this->xlm()->Check(it->second, x))
+ ++affected;
+ float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
- this->xlm()->AddXLine(x);
- if (Config->KillonSQline)
+ if (percent > 95)
+ {
+ source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
+ Log(LOG_ADMIN, u, this) << "tried to SQLine " << percent << "% of the network (" << affected << " users)";
+ delete x;
+ return;
+ }
+
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm()));
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ delete x;
+ return;
+ }
+
+ this->xlm()->AddXLine(x);
+ if (Config->KillonSQline)
+ {
+ Anope::string rreason = "Q-Lined: " + reason;
+
+ if (mask[0] == '#')
+ {
+ for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit)
{
- Anope::string rreason = "Q-Lined: " + reason;
+ Channel *c = cit->second;
- if (mask[0] == '#')
+ if (!Anope::Match(c->name, mask, false, true))
+ continue;
+ for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
{
- for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit)
- {
- Channel *c = cit->second;
-
- if (!Anope::Match(c->name, mask))
- continue;
- for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
- {
- UserContainer *uc = *it;
- ++it;
-
- if (uc->user->HasMode(UMODE_OPER) || uc->user->server == Me)
- continue;
- c->Kick(NULL, uc->user, "%s", reason.c_str());
- }
- }
- }
- else
- {
- for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
- {
- User *user = it->second;
- ++it;
-
- if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->nick, x->Mask))
- user->Kill(Config->ServerName, rreason);
- }
+ UserContainer *uc = *it;
+ ++it;
+
+ if (uc->user->HasMode(UMODE_OPER) || uc->user->server == Me)
+ continue;
+ c->Kick(NULL, uc->user, "%s", reason.c_str());
}
}
- this->xlm()->Send(NULL, x);
-
- source.Reply(_("\002%s\002 added to the SQLINE list."), mask.c_str());
- Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ }
+ else
+ {
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
+ {
+ User *user = it->second;
+ ++it;
- if (readonly)
- source.Reply(READ_ONLY_MODE);
+ if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->nick, x->Mask, false, true))
+ user->Kill(Config->ServerName, rreason);
+ }
}
+ this->xlm()->Send(u, x);
}
- else
- this->OnSyntaxError(source, "ADD");
- return;
+ source.Reply(_("\002%s\002 added to the SQLINE list."), mask.c_str());
+ Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+
+ if (readonly)
+ source.Reply(READ_ONLY_MODE);
}
service_reference<XLineManager> sqlines;
@@ -607,8 +654,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
"connect, Services will not allow it to pursue his IRC\n"
"session.\n"
"If the first character of the mask is #, services will \n"
- "prevent the use of matching channels (on IRCds that \n"
- "support it).\n"));
+ "prevent the use of matching channels."));
source.Reply(_(" \n"
"\002SQLINE ADD\002 adds the given (nick's) mask to the SQLINE\n"
"list for the given reason (which \002must\002 be given).\n"
@@ -621,6 +667,10 @@ class CommandOSSQLine : public CommandOSSXLineBase
"must be given, even if it is the same as the default. The\n"
"current SQLINE default expiry time can be found with the\n"
"\002STATS AKILL\002 command.\n"));
+ if (!Config->RegexEngine.empty())
+ source.Reply(" \n"
+ "Regex matches are also supported using the %s engine.\n"
+ "Enclose your mask in // if this desired.", Config->RegexEngine.c_str());
source.Reply(_(" \n"
"The \002SQLINE DEL\002 command removes the given mask from the\n"
"SQLINE list if it is present. If a list of entry numbers is \n"
diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp
index 45d6aaaea..5268a345d 100644
--- a/modules/database/db_old.cpp
+++ b/modules/database/db_old.cpp
@@ -516,6 +516,7 @@ static void LoadNicks()
READ(read_buffer(sbuf, f));
m->sender = sbuf;
READ(read_string(m->text, f));
+ m->owner = nc->display;
nc->memos.memos.push_back(m);
}
READ(read_uint16(&u16, f));
@@ -795,6 +796,7 @@ static void LoadChannels()
READ(read_buffer(sbuf, f));
m->sender = sbuf;
READ(read_string(m->text, f));
+ m->owner = ci->name;
ci->memos.memos.push_back(m);
}
diff --git a/modules/extra/m_dnsbl.cpp b/modules/extra/m_dnsbl.cpp
index 71011760e..d4c49501c 100644
--- a/modules/extra/m_dnsbl.cpp
+++ b/modules/extra/m_dnsbl.cpp
@@ -135,9 +135,16 @@ class ModuleDNSBL : public Module
return;
/* At this time we only support IPv4 */
- sockaddrs user_ip(user->ip);
- if (user_ip.sa.sa_family != AF_INET)
+ sockaddrs user_ip;
+ try
+ {
+ user_ip.pton(AF_INET, user->ip);
+ }
+ catch (const SocketException &)
+ {
+ /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */
return;
+ }
const unsigned long &ip = user_ip.sa4.sin_addr.s_addr;
unsigned long reverse_ip = (ip << 24) | ((ip & 0xFF00) << 8) | ((ip & 0xFF0000) >> 8) | (ip >> 24);
diff --git a/modules/extra/m_proxyscan.cpp b/modules/extra/m_proxyscan.cpp
index ea35e8f77..badc293fc 100644
--- a/modules/extra/m_proxyscan.cpp
+++ b/modules/extra/m_proxyscan.cpp
@@ -346,10 +346,17 @@ class ModuleProxyScan : public Module
if (exempt || !user || !Me->IsSynced() || !user->server->IsSynced())
return;
- sockaddrs user_ip(user->ip);
/* At this time we only support IPv4 */
- if (user_ip.sa.sa_family != AF_INET)
+ sockaddrs user_ip;
+ try
+ {
+ user_ip.pton(AF_INET, user->ip);
+ }
+ catch (const SocketException &)
+ {
+ /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */
return;
+ }
if (!this->con_notice.empty() && !this->con_source.empty())
{
diff --git a/modules/extra/m_regex_pcre.cpp b/modules/extra/m_regex_pcre.cpp
new file mode 100644
index 000000000..998a7692d
--- /dev/null
+++ b/modules/extra/m_regex_pcre.cpp
@@ -0,0 +1,55 @@
+/* RequiredLibraries: pcre */
+
+#include "module.h"
+#include <pcre.h>
+
+class PCRERegex : public Regex
+{
+ pcre *regex;
+
+ public:
+ PCRERegex(const Anope::string &expr) : Regex(expr)
+ {
+ const char *error;
+ int erroffset;
+ this->regex = pcre_compile(expr.c_str(), PCRE_CASELESS, &error, &erroffset, NULL);
+ if (!this->regex)
+ throw RegexException("Error in regex " + expr + " at offset " + stringify(erroffset) + ": " + error);
+ }
+
+ ~PCRERegex()
+ {
+ pcre_free(this->regex);
+ }
+
+ bool Matches(const Anope::string &str)
+ {
+ return pcre_exec(this->regex, NULL, str.c_str(), str.length(), 0, 0, NULL, 0) > -1;
+ }
+};
+
+class PCRERegexProvider : public RegexProvider
+{
+ public:
+ PCRERegexProvider(Module *creator) : RegexProvider(creator, "regex/pcre") { }
+
+ Regex *Compile(const Anope::string &expression) anope_override
+ {
+ return new PCRERegex(expression);
+ }
+};
+
+class ModuleRegexPCRE : public Module
+{
+ PCRERegexProvider pcre_regex_provider;
+
+ public:
+ ModuleRegexPCRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED),
+ pcre_regex_provider(this)
+ {
+ this->SetAuthor("Anope");
+ this->SetPermanent(true);
+ }
+};
+
+MODULE_INIT(ModuleRegexPCRE)
diff --git a/modules/extra/m_regex_posix.cpp b/modules/extra/m_regex_posix.cpp
new file mode 100644
index 000000000..409a057ba
--- /dev/null
+++ b/modules/extra/m_regex_posix.cpp
@@ -0,0 +1,57 @@
+#include "module.h"
+#include <sys/types.h>
+#include <regex.h>
+
+class POSIXRegex : public Regex
+{
+ regex_t regbuf;
+
+ public:
+ POSIXRegex(const Anope::string &expr) : Regex(expr)
+ {
+ int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB);
+ if (err)
+ {
+ char buf[BUFSIZE];
+ regerror(err, &this->regbuf, buf, sizeof(buf));
+ regfree(&this->regbuf);
+ throw RegexException("Error in regex " + expr + ": " + buf);
+ }
+ }
+
+ ~POSIXRegex()
+ {
+ regfree(&this->regbuf);
+ }
+
+ bool Matches(const Anope::string &str)
+ {
+ return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0;
+ }
+};
+
+class POSIXRegexProvider : public RegexProvider
+{
+ public:
+ POSIXRegexProvider(Module *creator) : RegexProvider(creator, "regex/posix") { }
+
+ Regex *Compile(const Anope::string &expression) anope_override
+ {
+ return new POSIXRegex(expression);
+ }
+};
+
+class ModuleRegexPOSIX : public Module
+{
+ POSIXRegexProvider posix_regex_provider;
+
+ public:
+ ModuleRegexPOSIX(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED),
+ posix_regex_provider(this)
+ {
+ this->SetAuthor("Anope");
+ this->SetPermanent(true);
+ }
+};
+
+MODULE_INIT(ModuleRegexPOSIX)
diff --git a/modules/extra/m_regex_tre.cpp b/modules/extra/m_regex_tre.cpp
new file mode 100644
index 000000000..8cfbd3b18
--- /dev/null
+++ b/modules/extra/m_regex_tre.cpp
@@ -0,0 +1,58 @@
+/* RequiredLibraries: tre */
+
+#include "module.h"
+#include <tre/regex.h>
+
+class TRERegex : public Regex
+{
+ regex_t regbuf;
+
+ public:
+ TRERegex(const Anope::string &expr) : Regex(expr)
+ {
+ int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB);
+ if (err)
+ {
+ char buf[BUFSIZE];
+ regerror(err, &this->regbuf, buf, sizeof(buf));
+ regfree(&this->regbuf);
+ throw RegexException("Error in regex " + expr + ": " + buf);
+ }
+ }
+
+ ~TRERegex()
+ {
+ regfree(&this->regbuf);
+ }
+
+ bool Matches(const Anope::string &str)
+ {
+ return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0;
+ }
+};
+
+class TRERegexProvider : public RegexProvider
+{
+ public:
+ TRERegexProvider(Module *creator) : RegexProvider(creator, "regex/tre") { }
+
+ Regex *Compile(const Anope::string &expression) anope_override
+ {
+ return new TRERegex(expression);
+ }
+};
+
+class ModuleRegexTRE : public Module
+{
+ TRERegexProvider tre_regex_provider;
+
+ public:
+ ModuleRegexTRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED),
+ tre_regex_provider(this)
+ {
+ this->SetAuthor("Anope");
+ this->SetPermanent(true);
+ }
+};
+
+MODULE_INIT(ModuleRegexTRE)
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp
index 8645c7176..a26669a9b 100644
--- a/modules/protocol/bahamut.cpp
+++ b/modules/protocol/bahamut.cpp
@@ -13,8 +13,8 @@
#include "module.h"
-IRCDVar myIrcd[] = {
- {"Bahamut 1.8.x", /* ircd name */
+IRCDVar myIrcd = {
+ "Bahamut 1.8.x", /* ircd name */
"+", /* Modes used by pseudoclients */
1, /* SVSNICK */
0, /* Vhost */
@@ -35,10 +35,7 @@ IRCDVar myIrcd[] = {
0, /* ts6 */
"$", /* TLD Prefix for Global */
6, /* Max number of modes we can send per line */
- 0, /* IRCd sends a SSL users certificate fingerprint */
- }
- ,
- {NULL}
+ 0 /* IRCd sends a SSL users certificate fingerprint */
};
@@ -47,32 +44,40 @@ class BahamutIRCdProto : public IRCDProto
void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override
{
if (Capab.count("TSMODE") > 0)
- UplinkSocket::Message(source ? source->nick : Config->ServerName) << "MODE " << dest->name << " " << dest->creation_time << " " << buf;
+ {
+ if (source)
+ UplinkSocket::Message(source) << "MODE " << dest->name << " " << dest->creation_time << " " << buf;
+ else
+ UplinkSocket::Message(Me) << "MODE " << dest->name << " " << dest->creation_time << " " << buf;
+ }
else
- UplinkSocket::Message(source ? source->nick : Config->ServerName) << "MODE " << dest->name << " " << buf;
+ IRCDProto::SendModeInternal(source, dest, buf);
}
void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(bi ? bi->nick : Config->ServerName) << "SVSMODE " << u->nick << " " << u->timestamp << " " << buf;
+ if (bi)
+ UplinkSocket::Message(bi) << "SVSMODE " << u->nick << " " << u->timestamp << " " << buf;
+ else
+ UplinkSocket::Message(Me) << "SVSMODE " << u->nick << " " << u->timestamp << " " << buf;
}
/* SVSHOLD - set */
void SendSVSHold(const Anope::string &nick) anope_override
{
- UplinkSocket::Message(Config->ServerName) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << " :Being held for registered user";
+ UplinkSocket::Message(Me) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << " :Being held for registered user";
}
/* SVSHOLD - release */
void SendSVSHoldDel(const Anope::string &nick) anope_override
{
- UplinkSocket::Message(Config->ServerName) << "SVSHOLD " << nick << " 0";
+ UplinkSocket::Message(Me) << "SVSHOLD " << nick << " 0";
}
/* SQLINE */
void SendSQLine(User *, const XLine *x) anope_override
{
- UplinkSocket::Message() << "SQLINE " << x->Mask << " :" << x->Reason;
+ UplinkSocket::Message() << "SQLINE " << x->Mask << " :" << x->GetReason();
}
/* UNSLINE */
@@ -98,9 +103,9 @@ class BahamutIRCdProto : public IRCDProto
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
/* this will likely fail so its only here for legacy */
- UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->Reason;
+ UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->GetReason();
/* this is how we are supposed to deal with it */
- UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->Reason;
+ UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->GetReason();
}
/* SVSNOOP */
@@ -112,19 +117,34 @@ class BahamutIRCdProto : public IRCDProto
/* SGLINE */
void SendSGLine(User *, const XLine *x) anope_override
{
- UplinkSocket::Message() << "SGLINE " << x->Mask.length() << " :" << x->Mask << ":" << x->Reason;
+ UplinkSocket::Message() << "SGLINE " << x->Mask.length() << " :" << x->Mask << ":" << x->GetReason();
}
/* RAKILL */
void SendAkillDel(const XLine *x) anope_override
{
+ if (x->IsRegex() || x->HasNickOrReal())
+ return;
+
+ /* ZLine if we can instead */
+ try
+ {
+ if (x->GetUser() == "*")
+ {
+ sockaddrs(x->GetHost());
+ ircdproto->SendSZLineDel(x);
+ return;
+ }
+ }
+ catch (const SocketException &) { }
+
UplinkSocket::Message() << "RAKILL " << x->GetHost() << " " << x->GetUser();
}
/* TOPIC */
void SendTopic(BotInfo *whosets, Channel *c) anope_override
{
- UplinkSocket::Message(whosets->nick) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_time << " :" << c->topic;
+ UplinkSocket::Message(whosets) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_time << " :" << c->topic;
}
/* UNSQLINE */
@@ -136,7 +156,7 @@ class BahamutIRCdProto : public IRCDProto
/* JOIN - SJOIN */
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
- UplinkSocket::Message(user->nick) << "SJOIN " << c->creation_time << " " << c->name;
+ UplinkSocket::Message(user) << "SJOIN " << c->creation_time << " " << c->name;
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -155,13 +175,48 @@ class BahamutIRCdProto : public IRCDProto
}
}
- void SendAkill(User *, const XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) anope_override
{
+ if (x->IsRegex() || x->HasNickOrReal())
+ {
+ if (!u)
+ {
+ /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (x->manager->Check(it->second, x))
+ this->SendAkill(it->second, x);
+ return;
+ }
+
+ XLine *old = x;
+
+ if (old->manager->HasEntry("*@" + u->host))
+ return;
+
+ /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
+ x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(x);
+
+ Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
+ }
+
+ /* ZLine if we can instead */
+ try
+ {
+ if (x->GetUser() == "*")
+ {
+ sockaddrs(x->GetHost());
+ ircdproto->SendSZLine(u, x);
+ return;
+ }
+ }
+ catch (const SocketException &) { }
+
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800)
timeleft = 172800;
- UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->Reason;
+ UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->GetReason();
}
/*
@@ -169,7 +224,10 @@ class BahamutIRCdProto : public IRCDProto
*/
void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->nick : "") << "SVSKILL " << user->nick << " :" << buf;
+ if (source)
+ UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf;
+ else
+ UplinkSocket::Message() << "SVSKILL " << user->nick << " :" << buf;
}
void SendBOB() anope_override
@@ -182,14 +240,6 @@ class BahamutIRCdProto : public IRCDProto
UplinkSocket::Message() << "BURST 0";
}
- void SendKickInternal(const BotInfo *source, const Channel *chan, const User *user, const Anope::string &buf) anope_override
- {
- if (!buf.empty())
- UplinkSocket::Message(source->nick) << "KICK " << chan->name << " " << user->nick << " :" << buf;
- else
- UplinkSocket::Message(source->nick) << "KICK " << chan->name << " " << user->nick;
- }
-
void SendClientIntroduction(const User *u) anope_override
{
Anope::string modes = "+" + u->GetModes();
@@ -544,7 +594,7 @@ class ProtoBahamut : public Module
{
this->SetAuthor("Anope");
- pmodule_ircd_var(myIrcd);
+ pmodule_ircd_var(&myIrcd);
pmodule_ircd_proto(&this->ircd_proto);
pmodule_ircd_message(&this->ircd_message);
diff --git a/modules/protocol/inspircd-ts6.h b/modules/protocol/inspircd-ts6.h
index 8ba879c4c..ec6246e49 100644
--- a/modules/protocol/inspircd-ts6.h
+++ b/modules/protocol/inspircd-ts6.h
@@ -36,7 +36,7 @@ class InspIRCdTS6Proto : public IRCDProto
if (!has_chgidentmod)
Log() << "CHGIDENT not loaded!";
else
- UplinkSocket::Message(Config->HostServ) << "CHGIDENT " << nick << " " << vIdent;
+ UplinkSocket::Message(findbot(Config->HostServ)) << "CHGIDENT " << nick << " " << vIdent;
}
void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost)
@@ -44,7 +44,7 @@ class InspIRCdTS6Proto : public IRCDProto
if (!has_chghostmod)
Log() << "CHGHOST not loaded!";
else
- UplinkSocket::Message(Config->Numeric) << "CHGHOST " << nick << " " << vhost;
+ UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost;
}
public:
@@ -52,12 +52,26 @@ class InspIRCdTS6Proto : public IRCDProto
void SendAkillDel(const XLine *x) anope_override
{
BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->Numeric) << "GLINE " << x->Mask;
+
+ /* InspIRCd may support regex bans */
+ if (x->IsRegex() && has_rlinemod)
+ {
+ Anope::string mask = x->Mask;
+ size_t h = x->Mask.find('#');
+ if (h != Anope::string::npos)
+ mask = mask.replace(h, 1, ' ');
+ UplinkSocket::Message(bi) << "RLINE " << mask;
+ return;
+ }
+ else if (x->IsRegex() || x->HasNickOrReal())
+ return;
+
+ UplinkSocket::Message(bi) << "GLINE " << x->Mask;
}
void SendTopic(BotInfo *whosets, Channel *c) anope_override
{
- UplinkSocket::Message(whosets->GetUID()) << "FTOPIC " << c->name << " " << Anope::CurTime << " " << c->topic_setter << " :" << c->topic;
+ UplinkSocket::Message(whosets) << "FTOPIC " << c->name << " " << Anope::CurTime << " " << c->topic_setter << " :" << c->topic;
}
void SendVhostDel(User *u) anope_override
@@ -71,60 +85,93 @@ class InspIRCdTS6Proto : public IRCDProto
this->SendChgIdentInternal(u->nick, u->GetIdent());
}
- void SendAkill(User *, const XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) anope_override
{
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- User *u = finduser(Config->OperServ);
- UplinkSocket::Message(u ? u->GetUID() : Config->Numeric) << "ADDLINE G " << x->GetUser() << "@" << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason;
- }
- void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(source ? source->GetUID() : Config->Numeric) << "KILL " << user->GetUID() << " :" << buf;
+ BotInfo *bi = findbot(Config->OperServ);
+ /* InspIRCd may support regex bans, if they do we can send this and forget about it */
+ if (x->IsRegex() && has_rlinemod)
+ {
+ Anope::string mask = x->Mask;
+ size_t h = x->Mask.find('#');
+ if (h != Anope::string::npos)
+ mask = mask.replace(h, 1, ' ');
+ UplinkSocket::Message(bi) << "RLINE " << mask << " " << timeleft << " :" << x->Reason;
+ return;
+ }
+ else if (x->IsRegex() || x->HasNickOrReal())
+ {
+ if (!u)
+ {
+ /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (x->manager->Check(it->second, x))
+ this->SendAkill(it->second, x);
+ return;
+ }
+
+ XLine *old = x;
+
+ if (old->manager->HasEntry("*@" + u->host))
+ return;
+
+ /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
+ x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(x);
+
+ Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
+ }
+
+ /* ZLine if we can instead */
+ try
+ {
+ if (x->GetUser() == "*")
+ {
+ sockaddrs(x->GetHost());
+ ircdproto->SendSZLine(u, x);
+ return;
+ }
+ }
+ catch (const SocketException &) { }
+
+ UplinkSocket::Message(bi) << "ADDLINE G " << x->GetUser() << "@" << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason;
}
- void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) anope_override
+ void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(Config->Numeric) << "PUSH " << dest << " ::" << source << " " << numeric << " " << dest << " " << buf;
+ UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << dest << " " << buf;
}
void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->GetUID() : Config->Numeric) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
+ UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
}
void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(bi ? bi->GetUID() : Config->Numeric) << "MODE " << u->GetUID() << " " << buf;
+ UplinkSocket::Message(bi) << "MODE " << u->GetUID() << " " << buf;
}
void SendClientIntroduction(const User *u) anope_override
{
Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Config->Numeric) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->my_signon << " " << modes << " :" << u->realname;
- }
-
- void SendKickInternal(const BotInfo *source, const Channel *chan, const User *user, const Anope::string &buf) anope_override
- {
- if (!buf.empty())
- UplinkSocket::Message(source->GetUID()) << "KICK " << chan->name << " " << user->GetUID() << " :" << buf;
- else
- UplinkSocket::Message(source->GetUID()) << "KICK " << chan->name << " " << user->GetUID() << " :" << user->nick;
+ UplinkSocket::Message(Me) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->my_signon << " " << modes << " :" << u->realname;
}
/* SERVER services-dev.chatspike.net password 0 :Description here */
void SendServer(const Server *server) anope_override
{
- UplinkSocket::Message("") << "SERVER " << server->GetName() << " " << Config->Uplinks[CurrentUplink]->password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
+ UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[CurrentUplink]->password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
}
/* JOIN */
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
- UplinkSocket::Message(Config->Numeric) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID();
+ UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID();
/* Note that we can send this with the FJOIN but choose not to
* because the mode stacker will handle this and probably will
* merge these modes with +nrt and other mlocked modes
@@ -150,7 +197,7 @@ class InspIRCdTS6Proto : public IRCDProto
/* UNSQLINE */
void SendSQLineDel(const XLine *x) anope_override
{
- UplinkSocket::Message(Config->Numeric) << "DELLINE Q " << x->Mask;
+ UplinkSocket::Message(Me) << "DELLINE Q " << x->Mask;
}
/* SQLINE */
@@ -160,7 +207,7 @@ class InspIRCdTS6Proto : public IRCDProto
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- UplinkSocket::Message(Config->Numeric) << "ADDLINE Q " << x->Mask << " " << Config->OperServ << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason;
+ UplinkSocket::Message(Me) << "ADDLINE Q " << x->Mask << " " << Config->OperServ << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason;
}
/* Functions that use serval cmd functions */
@@ -176,9 +223,9 @@ class InspIRCdTS6Proto : public IRCDProto
void SendConnect() anope_override
{
SendServer(Me);
- UplinkSocket::Message(Config->Numeric) << "BURST";
+ UplinkSocket::Message(Me) << "BURST";
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
- UplinkSocket::Message(Config->Numeric) << "VERSION :Anope-" << Anope::Version() << " " << Config->ServerName << " :" << ircd->name << " - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString();
+ UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Config->ServerName << " :" << ircd->name << " - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString();
}
/* SVSHOLD - set */
@@ -186,7 +233,7 @@ class InspIRCdTS6Proto : public IRCDProto
{
BotInfo *bi = findbot(Config->NickServ);
if (bi)
- UplinkSocket::Message(bi->GetUID()) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << " :Being held for registered user";
+ UplinkSocket::Message(bi) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << " :Being held for registered user";
}
/* SVSHOLD - release */
@@ -194,13 +241,13 @@ class InspIRCdTS6Proto : public IRCDProto
{
BotInfo *bi = findbot(Config->NickServ);
if (bi)
- UplinkSocket::Message(bi->GetUID()) << "SVSHOLD " << nick;
+ UplinkSocket::Message(bi) << "SVSHOLD " << nick;
}
/* UNSZLINE */
void SendSZLineDel(const XLine *x) anope_override
{
- UplinkSocket::Message(Config->Numeric) << "DELLINE Z " << x->GetHost();
+ UplinkSocket::Message(Me) << "DELLINE Z " << x->GetHost();
}
/* SZLINE */
@@ -210,39 +257,38 @@ class InspIRCdTS6Proto : public IRCDProto
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- UplinkSocket::Message(Config->Numeric) << "ADDLINE Z " << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft <<" :" << x->Reason;
+ UplinkSocket::Message(Me) << "ADDLINE Z " << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft <<" :" << x->Reason;
}
- void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override
+ void SendSVSJoin(const BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override
{
User *u = finduser(nick);
- BotInfo *bi = findbot(source);
- UplinkSocket::Message(bi->GetUID()) << "SVSJOIN " << u->GetUID() << " " << chan;
+ UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan;
}
- void SendSWhois(const Anope::string &, const Anope::string &who, const Anope::string &mask) anope_override
+ void SendSWhois(const BotInfo *, const Anope::string &who, const Anope::string &mask) anope_override
{
User *u = finduser(who);
- UplinkSocket::Message(Config->Numeric) << "METADATA " << u->GetUID() << " swhois :" << mask;
+ UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask;
}
void SendBOB() anope_override
{
- UplinkSocket::Message(Config->Numeric) << "BURST " << Anope::CurTime;
+ UplinkSocket::Message(Me) << "BURST " << Anope::CurTime;
}
void SendEOB() anope_override
{
- UplinkSocket::Message(Config->Numeric) << "ENDBURST";
+ UplinkSocket::Message(Me) << "ENDBURST";
}
void SendGlobopsInternal(BotInfo *source, const Anope::string &buf)
{
if (has_globopsmod)
- UplinkSocket::Message(source ? source->GetUID() : Config->Numeric) << "SNONOTICE g :" << buf;
+ UplinkSocket::Message(source) << "SNONOTICE g :" << buf;
else
- UplinkSocket::Message(source ? source->GetUID() : Config->Numeric) << "SNONOTICE A :" << buf;
+ UplinkSocket::Message(source) << "SNONOTICE A :" << buf;
}
void SendLogin(User *u) anope_override
@@ -250,17 +296,17 @@ class InspIRCdTS6Proto : public IRCDProto
if (!u->Account() || u->Account()->HasFlag(NI_UNCONFIRMED))
return;
- UplinkSocket::Message(Config->Numeric) << "METADATA " << u->GetUID() << " accountname :" << u->Account()->display;
+ UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << u->Account()->display;
}
void SendLogout(User *u) anope_override
{
- UplinkSocket::Message(Config->Numeric) << "METADATA " << u->GetUID() << " accountname :";
+ UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :";
}
void SendChannel(Channel *c) anope_override
{
- UplinkSocket::Message(Config->Numeric) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :";
+ UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :";
}
bool IsNickValid(const Anope::string &nick) anope_override
@@ -455,7 +501,8 @@ class InspircdIRCdMessage : public IRCdMessage
bool event_idle(const Anope::string &source, const std::vector<Anope::string> &params)
{
BotInfo *bi = findbot(params[0]);
- UplinkSocket::Message(bi ? bi->GetUID() : params[0]) << "IDLE " << source << " " << start_time << (bi ? Anope::CurTime - bi->lastmsg : 0);
+ if (bi)
+ UplinkSocket::Message(bi) << "IDLE " << source << " " << start_time << " " << (Anope::CurTime - bi->lastmsg);
return true;
}
@@ -464,7 +511,7 @@ bool event_time(const Anope::string &source, const std::vector<Anope::string> &p
if (params.size() < 2)
return true;
- UplinkSocket::Message(Config->Numeric) << "TIME " << source << " " << params[1] << " " << Anope::CurTime;
+ UplinkSocket::Message(Me) << "TIME " << source << " " << params[1] << " " << Anope::CurTime;
return true;
}
@@ -473,7 +520,7 @@ bool event_rsquit(const Anope::string &source, const std::vector<Anope::string>
/* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */
Server *s = Server::Find(params[0]);
if (s && s->HasFlag(SERVER_JUPED))
- UplinkSocket::Message(Config->Numeric) << "SQUIT " << s->GetSID() << " :" << (params.size() > 1 ? params[1].c_str() : "");
+ UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << (params.size() > 1 ? params[1].c_str() : "");
ircdmessage->OnSQuit(source, params);
diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp
index 49a90f831..f4c8c2202 100644
--- a/modules/protocol/inspircd11.cpp
+++ b/modules/protocol/inspircd11.cpp
@@ -13,8 +13,8 @@
#include "module.h"
-IRCDVar myIrcd[] = {
- {"InspIRCd 1.1", /* ircd name */
+IRCDVar myIrcd = {
+ "InspIRCd 1.1", /* ircd name */
"+I", /* Modes used by pseudoclients */
1, /* SVSNICK */
1, /* Vhost */
@@ -35,10 +35,7 @@ IRCDVar myIrcd[] = {
0, /* ts6 */
"$", /* TLD Prefix for Global */
20, /* Max number of modes we can send per line */
- 0, /* IRCd sends a SSL users certificate fingerprint */
- }
- ,
- {NULL}
+ 0 /* IRCd sends a SSL users certificate fingerprint */
};
static bool has_servicesmod = false;
@@ -51,15 +48,15 @@ static bool has_hidechansmod = false;
/* CHGHOST */
void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
+ BotInfo *bi = findbot(Config->OperServ);
if (has_chghostmod)
{
if (nick.empty() || vhost.empty())
return;
- UplinkSocket::Message(Config->OperServ) << "CHGHOST " << nick << " " << vhost;
+ UplinkSocket::Message(bi) << "CHGHOST " << nick << " " << vhost;
}
else
{
- BotInfo *bi = findbot(Config->OperServ);
if (bi)
ircdproto->SendGlobops(bi, "CHGHOST not loaded!");
}
@@ -67,8 +64,8 @@ void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
bool event_idle(const Anope::string &source, const std::vector<Anope::string> &params)
{
- if (!params.empty())
- UplinkSocket::Message(params[0]) << "IDLE " << source << " " << Anope::CurTime << " 0";
+ BotInfo *bi = findbot(params[0]);
+ UplinkSocket::Message(bi) << "IDLE " << source << " " << start_time << " " << (bi ? Anope::CurTime - bi->lastmsg : 0);
return true;
}
@@ -84,12 +81,27 @@ class InspIRCdProto : public IRCDProto
{
void SendAkillDel(const XLine *x) anope_override
{
- UplinkSocket::Message(Config->OperServ) << "GLINE " << x->Mask;
+ if (x->IsRegex() || x->HasNickOrReal())
+ return;
+
+ /* ZLine if we can instead */
+ try
+ {
+ if (x->GetUser() == "*")
+ {
+ sockaddrs(x->GetHost());
+ ircdproto->SendSZLineDel(x);
+ return;
+ }
+ }
+ catch (const SocketException &) { }
+
+ UplinkSocket::Message(findbot(Config->OperServ)) << "GLINE " << x->Mask;
}
void SendTopic(BotInfo *whosets, Channel *c) anope_override
{
- UplinkSocket::Message(whosets->nick) << "FTOPIC " << c->name << " " << c->topic_time << " " << c->topic_setter <<" :" << c->topic;
+ UplinkSocket::Message(whosets) << "FTOPIC " << c->name << " " << c->topic_time << " " << c->topic_setter <<" :" << c->topic;
}
void SendVhostDel(User *u) anope_override
@@ -103,60 +115,104 @@ class InspIRCdProto : public IRCDProto
inspircd_cmd_chgident(u->nick, u->GetIdent());
}
- void SendAkill(User *, const XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) anope_override
{
+ if (x->IsRegex() || x->HasNickOrReal())
+ {
+ if (!u)
+ {
+ /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (x->manager->Check(it->second, x))
+ this->SendAkill(it->second, x);
+ return;
+ }
+
+ XLine *old = x;
+
+ if (old->manager->HasEntry("*@" + u->host))
+ return;
+
+ /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
+ x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(x);
+
+ Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
+ }
+
+ /* ZLine if we can instead */
+ try
+ {
+ if (x->GetUser() == "*")
+ {
+ sockaddrs(x->GetHost());
+ ircdproto->SendSZLine(u, x);
+ return;
+ }
+ }
+ catch (const SocketException &) { }
+
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- UplinkSocket::Message(Config->ServerName) << "ADDLINE G " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason;
+ UplinkSocket::Message(Me) << "ADDLINE G " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason();
}
void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->nick : Config->ServerName) << "KILL " << user->nick << " :" << buf;
+ if (source)
+ UplinkSocket::Message(source) << "KILL " << user->nick << " :" << buf;
+ else
+ UplinkSocket::Message(Me) << "KILL " << user->nick << " :" << buf;
}
- void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) anope_override
+ void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source) << "PUSH " << dest << " ::" << source << " " << numeric << " " << dest << " " << buf;
+ UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << dest << " " << buf;
}
void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->nick : Config->ServerName) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
+ if (source)
+ UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
+ else
+ UplinkSocket::Message(Me) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
}
void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(bi ? bi->nick : Config->ServerName) << "MODE " << u->nick << " " << buf;
+ if (bi)
+ UplinkSocket::Message(bi) << "MODE " << u->nick << " " << buf;
+ else
+ UplinkSocket::Message(Me) << "MODE " << u->nick << " " << buf;
}
void SendClientIntroduction(const User *u) anope_override
{
Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Config->ServerName) << "NICK " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " " << modes << " 0.0.0.0 :" << u->realname;
- UplinkSocket::Message(u->nick) << "OPERTYPE Service";
+ UplinkSocket::Message(Me) << "NICK " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " " << modes << " 0.0.0.0 :" << u->realname;
+ UplinkSocket::Message(u) << "OPERTYPE Service";
}
void SendKickInternal(const BotInfo *source, const Channel *chan, const User *user, const Anope::string &buf) anope_override
{
if (!buf.empty())
- UplinkSocket::Message(source->nick) << "KICK " << chan->name << " " << user->nick << " :" << buf;
+ UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick << " :" << buf;
else
- UplinkSocket::Message(source->nick) << "KICK " << chan->name << " " << user->nick << " :" << user->nick;
+ UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick << " :" << user->nick;
}
/* SERVER services-dev.chatspike.net password 0 :Description here */
void SendServer(const Server *server) anope_override
{
- UplinkSocket::Message(Config->ServerName) << "SERVER " << server->GetName() << " " << currentpass << " " << server->GetHops() << " :" << server->GetDescription();
+ UplinkSocket::Message(Me) << "SERVER " << server->GetName() << " " << currentpass << " " << server->GetHops() << " :" << server->GetDescription();
}
/* JOIN */
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
- UplinkSocket::Message(user->nick) << "JOIN " << c->name << " " << c->creation_time;
+ UplinkSocket::Message(user) << "JOIN " << c->name << " " << c->creation_time;
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -178,7 +234,7 @@ class InspIRCdProto : public IRCDProto
/* UNSQLINE */
void SendSQLineDel(const XLine *x) anope_override
{
- UplinkSocket::Message(Config->OperServ) << "QLINE " << x->Mask;
+ UplinkSocket::Message(findbot(Config->OperServ)) << "QLINE " << x->Mask;
}
/* SQLINE */
@@ -188,7 +244,7 @@ class InspIRCdProto : public IRCDProto
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- UplinkSocket::Message(Config->ServerName) << "ADDLINE Q " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason;
+ UplinkSocket::Message(Me) << "ADDLINE Q " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason();
}
/* Functions that use serval cmd functions */
@@ -207,7 +263,7 @@ class InspIRCdProto : public IRCDProto
SendServer(Me);
UplinkSocket::Message() << "BURST";
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
- UplinkSocket::Message(Config->ServerName) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << ircd->name << " - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString();
+ UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << ircd->name << " - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString();
}
/* CHGIDENT */
@@ -217,7 +273,7 @@ class InspIRCdProto : public IRCDProto
{
if (nick.empty() || vIdent.empty())
return;
- UplinkSocket::Message(Config->OperServ) << "CHGIDENT " << nick << " " << vIdent;
+ UplinkSocket::Message(findbot(Config->OperServ)) << "CHGIDENT " << nick << " " << vIdent;
}
else
Log() << "CHGIDENT not loaded!";
@@ -226,19 +282,19 @@ class InspIRCdProto : public IRCDProto
/* SVSHOLD - set */
void SendSVSHold(const Anope::string &nick) anope_override
{
- UplinkSocket::Message(Config->OperServ) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << "s :Being held for registered user";
+ UplinkSocket::Message(findbot(Config->OperServ)) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << "s :Being held for registered user";
}
/* SVSHOLD - release */
void SendSVSHoldDel(const Anope::string &nick) anope_override
{
- UplinkSocket::Message(Config->OperServ) << "SVSHOLD " << nick;
+ UplinkSocket::Message(findbot(Config->OperServ)) << "SVSHOLD " << nick;
}
/* UNSZLINE */
void SendSZLineDel(const XLine *x) anope_override
{
- UplinkSocket::Message(Config->OperServ) << "ZLINE " << x->GetHost();
+ UplinkSocket::Message(findbot(Config->OperServ)) << "ZLINE " << x->GetHost();
}
/* SZLINE */
@@ -248,10 +304,10 @@ class InspIRCdProto : public IRCDProto
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- UplinkSocket::Message(Config->ServerName) << "ADDLINE Z " << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason;
+ UplinkSocket::Message(Me) << "ADDLINE Z " << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason();
}
- void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override
+ void SendSVSJoin(const BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override
{
UplinkSocket::Message(source) << "SVSJOIN " << nick << " " << chan;
}
@@ -914,7 +970,7 @@ class ProtoInspIRCd : public Module
{
this->SetAuthor("Anope");
- pmodule_ircd_var(myIrcd);
+ pmodule_ircd_var(&myIrcd);
pmodule_ircd_proto(&this->ircd_proto);
pmodule_ircd_message(&this->ircd_message);
diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp
index e2ec39ebe..b2985c08a 100644
--- a/modules/protocol/inspircd12.cpp
+++ b/modules/protocol/inspircd12.cpp
@@ -17,10 +17,11 @@
static bool has_globopsmod = false;
static bool has_chghostmod = false;
static bool has_chgidentmod = false;
+static bool has_rlinemod = false;
#include "inspircd-ts6.h"
-IRCDVar myIrcd[] = {
- {"InspIRCd 1.2", /* ircd name */
+IRCDVar myIrcd = {
+ "InspIRCd 1.2", /* ircd name */
"+I", /* Modes used by pseudoclients */
1, /* SVSNICK */
1, /* Vhost */
@@ -42,9 +43,6 @@ IRCDVar myIrcd[] = {
"$", /* TLD Prefix for Global */
20, /* Max number of modes we can send per line */
1, /* IRCd sends a SSL users certificate fingerprint */
- }
- ,
- {NULL}
};
static bool has_servicesmod = false;
@@ -372,6 +370,8 @@ class Inspircd12IRCdMessage : public InspircdIRCdMessage
has_hidechansmod = true;
if (params[1].find("m_servprotect.so") != Anope::string::npos)
ircd->pseudoclient_mode = "+Ik";
+ if (params[1].find("m_rline.so") != Anope::string::npos)
+ has_rlinemod = true;
}
else if (params[0].equals_cs("CAPABILITIES"))
{
@@ -705,7 +705,7 @@ class ProtoInspIRCd : public Module
{
this->SetAuthor("Anope");
- pmodule_ircd_var(myIrcd);
+ pmodule_ircd_var(&myIrcd);
pmodule_ircd_proto(&this->ircd_proto);
pmodule_ircd_message(&this->ircd_message);
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
index 619afdbde..f58f6e172 100644
--- a/modules/protocol/inspircd20.cpp
+++ b/modules/protocol/inspircd20.cpp
@@ -17,10 +17,11 @@
static bool has_chghostmod = false;
static bool has_chgidentmod = false;
static bool has_globopsmod = true; // Not a typo
+static bool has_rlinemod = false;
#include "inspircd-ts6.h"
-IRCDVar myIrcd[] = {
- {"InspIRCd 2.0", /* ircd name */
+IRCDVar myIrcd = {
+ "InspIRCd 2.0", /* ircd name */
"+I", /* Modes used by pseudoclients */
1, /* SVSNICK */
1, /* Vhost */
@@ -42,9 +43,6 @@ IRCDVar myIrcd[] = {
"$", /* TLD Prefix for Global */
20, /* Max number of modes we can send per line */
1, /* IRCd sends a SSL users certificate fingerprint */
- }
- ,
- {NULL}
};
static bool has_servicesmod = false;
@@ -58,9 +56,9 @@ class InspIRCdProto : public InspIRCdTS6Proto
UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202";
UplinkSocket::Message() << "CAPAB END";
SendServer(Me);
- UplinkSocket::Message(Config->Numeric) << "BURST";
+ UplinkSocket::Message(Me) << "BURST";
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
- UplinkSocket::Message(Config->Numeric) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << ircd->name <<" - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString();
+ UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << ircd->name <<" - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString();
}
};
@@ -559,8 +557,16 @@ class Inspircd20IRCdMessage : public InspircdIRCdMessage
Anope::string module;
while (ssep.GetToken(module))
+ {
if (module.equals_cs("m_svshold.so"))
has_svsholdmod = true;
+ else if (module.find("m_rline.so") == 0)
+ {
+ has_rlinemod = true;
+ if (!Config->RegexEngine.empty() && Config->RegexEngine != module.substr(11))
+ Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << Config->RegexEngine << ". This may cause inconsistencies.";
+ }
+ }
}
else if (params[0].equals_cs("MODSUPPORT"))
{
@@ -718,7 +724,7 @@ class ProtoInspIRCd : public Module
{
this->SetAuthor("Anope");
- pmodule_ircd_var(myIrcd);
+ pmodule_ircd_var(&myIrcd);
pmodule_ircd_proto(&this->ircd_proto);
pmodule_ircd_message(&this->ircd_message);
diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp
index 0755ac327..983e52630 100644
--- a/modules/protocol/plexus.cpp
+++ b/modules/protocol/plexus.cpp
@@ -13,8 +13,8 @@
static Anope::string TS6UPLINK;
-IRCDVar myIrcd[] = {
- {"hybrid-7.2.3+plexus-3.0.1", /* ircd name */
+IRCDVar myIrcd = {
+ "hybrid-7.2.3+plexus-3.0.1", /* ircd name */
"+oi", /* Modes used by pseudoclients */
1, /* SVSNICK */
1, /* Vhost */
@@ -36,49 +36,49 @@ IRCDVar myIrcd[] = {
"$$", /* TLD Prefix for Global */
4, /* Max number of modes we can send per line */
1, /* IRCd sends a SSL users certificate fingerprint */
- }
- ,
- {NULL}
};
class PlexusProto : public IRCDProto
{
void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->GetUID() : Me->GetSID()) << "OPERWALL :" << buf;
+ UplinkSocket::Message(source) << "OPERWALL :" << buf;
}
void SendSQLine(User *, const XLine *x) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "RESV * " << x->Mask << " :" << x->Reason;
+ UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->GetReason();
}
void SendSGLineDel(const XLine *x) anope_override
{
BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "UNXLINE * " << x->Mask;
+ UplinkSocket::Message(bi) << "UNXLINE * " << x->Mask;
}
void SendSGLine(User *, const XLine *x) anope_override
{
BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "XLINE * " << x->Mask << " 0 :" << x->Reason;
+ UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason();
}
void SendAkillDel(const XLine *x) anope_override
{
+ if (x->IsRegex() || x->HasNickOrReal())
+ return;
+
BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "UNKLINE * " << x->GetUser() << " " << x->GetHost();
+ UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost();
}
void SendSQLineDel(const XLine *x) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "UNRESV * " << x->Mask;
+ UplinkSocket::Message(Me) << "UNRESV * " << x->Mask;
}
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID();
+ UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID();
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -97,19 +97,38 @@ class PlexusProto : public IRCDProto
}
}
- void SendAkill(User *, const XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) anope_override
{
+ BotInfo *bi = findbot(Config->OperServ);
+
+ if (x->IsRegex() || x->HasNickOrReal())
+ {
+ if (!u)
+ {
+ /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (x->manager->Check(it->second, x))
+ this->SendAkill(it->second, x);
+ return;
+ }
+
+ XLine *old = x;
+
+ if (old->manager->HasEntry("*@" + u->host))
+ return;
+
+ /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
+ x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(x);
+
+ Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
+ }
+
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->Reason;
- }
-
- void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(source ? source->GetUID() : Me->GetSID()) << "KILL " << user->GetUID() << " :" << buf;
+ UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason();
}
void SendServer(const Server *server) anope_override
@@ -117,12 +136,12 @@ class PlexusProto : public IRCDProto
if (server == Me)
UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription();
else
- UplinkSocket::Message(Me->GetSID()) << "SID " << server->GetName() << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
+ UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
}
void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "ENCAP " << u->server->GetName() << " SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when;
+ UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when;
}
void SendVhostDel(User *u) anope_override
@@ -137,8 +156,8 @@ class PlexusProto : public IRCDProto
void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override
{
if (!ident.empty())
- UplinkSocket::Message(Me->GetSID()) << "ENCAP * CHGIDENT " << u->GetUID() << " " << ident;
- UplinkSocket::Message(Me->GetSID()) << "ENCAP * CHGHOST " << u->GetUID() << " " << host;
+ UplinkSocket::Message(Me) << "ENCAP * CHGIDENT " << u->GetUID() << " " << ident;
+ UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " " << host;
}
void SendConnect() anope_override
@@ -181,40 +200,12 @@ class PlexusProto : public IRCDProto
void SendClientIntroduction(const User *u) anope_override
{
Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me->GetSID()) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 255.255.255.255 " << u->GetUID() << " 0 " << u->host << " :" << u->realname;
- }
-
- void SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf) anope_override
- {
- if (!buf.empty())
- UplinkSocket::Message(bi->GetUID()) << "PART " << chan->name << " :" << buf;
- else
- UplinkSocket::Message(bi->GetUID()) << "PART " << chan->name;
- }
-
- void SendModeInternal(const BotInfo *bi, const Channel *dest, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(bi ? bi->GetUID() : Me->GetSID()) << "MODE " << dest->name << " " << buf;
+ UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 255.255.255.255 " << u->GetUID() << " 0 " << u->host << " :" << u->realname;
}
void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(bi ? bi->GetUID() : Me->GetSID()) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf;
- }
-
- void SendKickInternal(const BotInfo *bi, const Channel *chan, const User *user, const Anope::string &buf) anope_override
- {
- if (!buf.empty())
- UplinkSocket::Message(bi->GetUID()) << "KICK " << chan->name << " " << user->GetUID() << " :" << buf;
- else
- UplinkSocket::Message(bi->GetUID()) << "KICK " << chan->name << " " << user->GetUID();
- }
-
- /* INVITE */
- void SendInvite(const BotInfo *source, const Anope::string &chan, const Anope::string &nick) anope_override
- {
- User *u = finduser(nick);
- UplinkSocket::Message(source->GetUID()) << "INVITE " << (u ? u->GetUID() : nick) << " " << chan;
+ UplinkSocket::Message(bi) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf;
}
void SendLogin(User *u) anope_override
@@ -222,17 +213,17 @@ class PlexusProto : public IRCDProto
if (!u->Account())
return;
- UplinkSocket::Message(Me->GetSID()) << "ENCAP * SU " << u->GetUID() << " " << u->Account()->display;
+ UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << u->Account()->display;
}
void SendLogout(User *u) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "ENCAP * SU " << u->GetUID();
+ UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID();
}
void SendTopic(BotInfo *bi, Channel *c) anope_override
{
- UplinkSocket::Message(bi->GetUID()) << "ENCAP * TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_time + 1 << " :" << c->topic;
+ UplinkSocket::Message(bi) << "ENCAP * TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_time + 1 << " :" << c->topic;
}
void SendChannel(Channel *c) anope_override
@@ -240,7 +231,7 @@ class PlexusProto : public IRCDProto
Anope::string modes = c->GetModes(true, true);
if (modes.empty())
modes = "+";
- UplinkSocket::Message(Me->GetSID()) << "SJOIN " << c->creation_time << " " << c->name << " " << modes << "%s :";
+ UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :";
}
};
@@ -656,7 +647,7 @@ class ProtoPlexus : public Module
{
this->SetAuthor("Anope");
- pmodule_ircd_var(myIrcd);
+ pmodule_ircd_var(&myIrcd);
pmodule_ircd_proto(&this->ircd_proto);
pmodule_ircd_message(&this->ircd_message);
diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp
index c694b1ddc..ed871480d 100644
--- a/modules/protocol/ratbox.cpp
+++ b/modules/protocol/ratbox.cpp
@@ -13,8 +13,8 @@
static Anope::string TS6UPLINK;
-IRCDVar myIrcd[] = {
- {"Ratbox 2.0+", /* ircd name */
+IRCDVar myIrcd = {
+ "Ratbox 2.0+", /* ircd name */
"+oiS", /* Modes used by pseudoclients */
0, /* SVSNICK */
0, /* Vhost */
@@ -36,44 +36,44 @@ IRCDVar myIrcd[] = {
"$$", /* TLD Prefix for Global */
4, /* Max number of modes we can send per line */
0, /* IRCd sends a SSL users certificate fingerprint */
- }
- ,
- {NULL}
};
class RatboxProto : public IRCDProto
{
void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->GetUID() : Me->GetSID()) << "OPERWALL :" << buf;
+ UplinkSocket::Message(source) << "OPERWALL :" << buf;
}
void SendSQLine(User *, const XLine *x) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "RESV * " << x->Mask << " :" << x->Reason;
+ UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->GetReason();
}
void SendSGLineDel(const XLine *x) anope_override
{
BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "UNXLINE * " << x->Mask;
+ UplinkSocket::Message(bi) << "UNXLINE * " << x->Mask;
}
void SendSGLine(User *, const XLine *x) anope_override
{
BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "XLINE * " << x->Mask << " 0 :" << x->Reason;
+ UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason();
}
void SendAkillDel(const XLine *x) anope_override
{
+ if (x->IsRegex() || x->HasNickOrReal())
+ return;
+
BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "UNKLINE * " << x->GetUser() << " " << x->GetHost();
+ UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost();
}
void SendSQLineDel(const XLine *x) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "UNRESV * " << x->Mask;
+ UplinkSocket::Message(Me) << "UNRESV * " << x->Mask;
}
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
@@ -92,19 +92,38 @@ class RatboxProto : public IRCDProto
}
}
- void SendAkill(User *, const XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) anope_override
{
+ BotInfo *bi = findbot(Config->OperServ);
+
+ if (x->IsRegex() || x->HasNickOrReal())
+ {
+ if (!u)
+ {
+ /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (x->manager->Check(it->second, x))
+ this->SendAkill(it->second, x);
+ return;
+ }
+
+ XLine *old = x;
+
+ if (old->manager->HasEntry("*@" + u->host))
+ return;
+
+ /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
+ x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(x);
+
+ Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
+ }
+
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- BotInfo *bi = findbot(Config->OperServ);
- UplinkSocket::Message(bi ? bi->GetUID() : Config->OperServ) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->Reason;
- }
-
- void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(source ? source->GetUID() : Me->GetSID()) << "KILL " << user->GetUID() << " :" << buf;
+ UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason();
}
/* SERVER name hop descript */
@@ -151,40 +170,12 @@ class RatboxProto : public IRCDProto
void SendClientIntroduction(const User *u) anope_override
{
Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me->GetSID()) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname;
- }
-
- void SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf) anope_override
- {
- if (!buf.empty())
- UplinkSocket::Message(bi->GetUID()) << "PART " << chan->name << " :" << buf;
- else
- UplinkSocket::Message(bi->GetUID()) << "PART " << chan->name;
- }
-
- void SendModeInternal(const BotInfo *bi, const Channel *dest, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(bi ? bi->GetUID() : Me->GetSID()) << "MODE " << dest->name << " " << buf;
+ UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname;
}
void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(bi ? bi->GetUID() : Me->GetSID()) << "SVSMODE " << u->nick << " " << buf;
- }
-
- void SendKickInternal(const BotInfo *bi, const Channel *chan, const User *user, const Anope::string &buf) anope_override
- {
- if (!buf.empty())
- UplinkSocket::Message(bi->GetUID()) << "KICK " << chan->name << " " << user->GetUID() << " :" << buf;
- else
- UplinkSocket::Message(bi->GetUID()) << "KICK " << chan->name << " " << user->GetUID();
- }
-
- /* INVITE */
- void SendInvite(const BotInfo *source, const Anope::string &chan, const Anope::string &nick) anope_override
- {
- User *u = finduser(nick);
- UplinkSocket::Message(source->GetUID()) << "INVITE " << (u ? u->GetUID() : nick) << " " << chan;
+ UplinkSocket::Message(bi) << "SVSMODE " << u->nick << " " << buf;
}
void SendLogin(User *u) anope_override
@@ -192,12 +183,12 @@ class RatboxProto : public IRCDProto
if (!u->Account())
return;
- UplinkSocket::Message(Me->GetSID()) << "ENCAP * SU " << u->GetUID() << " " << u->Account()->display;
+ UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << u->Account()->display;
}
void SendLogout(User *u) anope_override
{
- UplinkSocket::Message(Me->GetSID()) << "ENCAP * SU " << u->GetUID();
+ UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID();
}
void SendChannel(Channel *c) anope_override
@@ -226,7 +217,7 @@ class RatboxProto : public IRCDProto
status.SetFlag(CMODE_OP);
bi->Join(c, &status);
}
- UplinkSocket::Message(bi->GetUID()) << "TOPIC " << c->name << " :" << c->topic;
+ IRCDProto::SendTopic(bi, c);
if (needjoin)
bi->Part(c);
}
@@ -570,7 +561,7 @@ class ProtoRatbox : public Module
{
this->SetAuthor("Anope");
- pmodule_ircd_var(myIrcd);
+ pmodule_ircd_var(&myIrcd);
pmodule_ircd_proto(&this->ircd_proto);
pmodule_ircd_message(&this->ircd_message);
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp
index 78d4a04be..f7c752095 100644
--- a/modules/protocol/unreal.cpp
+++ b/modules/protocol/unreal.cpp
@@ -13,8 +13,8 @@
#include "module.h"
-IRCDVar myIrcd[] = {
- {"UnrealIRCd 3.2.x", /* ircd name */
+IRCDVar myIrcd = {
+ "UnrealIRCd 3.2.x", /* ircd name */
"+Soiq", /* Modes used by pseudoclients */
1, /* SVSNICK */
1, /* Vhost */
@@ -35,10 +35,7 @@ IRCDVar myIrcd[] = {
0, /* ts6 */
"$", /* TLD Prefix for Global */
12, /* Max number of modes we can send per line */
- 0, /* IRCd sends a SSL users certificate fingerprint */
- }
- ,
- {NULL}
+ 0 /* IRCd sends a SSL users certificate fingerprint */
};
class UnrealIRCdProto : public IRCDProto
@@ -51,12 +48,27 @@ class UnrealIRCdProto : public IRCDProto
void SendAkillDel(const XLine *x) anope_override
{
+ if (x->IsRegex() || x->HasNickOrReal())
+ return;
+
+ /* ZLine if we can instead */
+ try
+ {
+ if (x->GetUser() == "*")
+ {
+ sockaddrs(x->GetHost());
+ ircdproto->SendSZLineDel(x);
+ return;
+ }
+ }
+ catch (const SocketException &) { }
+
UplinkSocket::Message() << "BD - G " << x->GetUser() << " " << x->GetHost() << " " << Config->OperServ;
}
void SendTopic(BotInfo *whosets, Channel *c) anope_override
{
- UplinkSocket::Message(whosets->nick) << ") " << c->name << " " << c->topic_setter << " " << c->topic_time + 1 << " :" << c->topic;
+ UplinkSocket::Message(whosets) << ") " << c->name << " " << c->topic_setter << " " << c->topic_time + 1 << " :" << c->topic;
}
void SendVhostDel(User *u) anope_override
@@ -68,28 +80,63 @@ class UnrealIRCdProto : public IRCDProto
u->SetMode(bi, UMODE_CLOAK);
}
- void SendAkill(User *, const XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) anope_override
{
+ if (x->IsRegex() || x->HasNickOrReal())
+ {
+ if (!u)
+ {
+ /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
+ for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (x->manager->Check(it->second, x))
+ this->SendAkill(it->second, x);
+ return;
+ }
+
+ XLine *old = x;
+
+ if (old->manager->HasEntry("*@" + u->host))
+ return;
+
+ /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
+ x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(x);
+
+ Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
+ }
+
+ /* ZLine if we can instead */
+ try
+ {
+ if (x->GetUser() == "*")
+ {
+ sockaddrs(x->GetHost());
+ ircdproto->SendSZLine(u, x);
+ return;
+ }
+ }
+ catch (const SocketException &) { }
+
// Calculate the time left before this would expire, capping it at 2 days
time_t timeleft = x->Expires - Anope::CurTime;
- if (timeleft > 172800)
+ if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- UplinkSocket::Message() << "BD + G " << x->GetUser() << " " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->Reason;
+ UplinkSocket::Message() << "BD + G " << x->GetUser() << " " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->GetReason();
}
void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->nick : Config->ServerName) << "h " << user->nick << " :" << buf;
+ UplinkSocket::Message(source) << "h " << user->nick << " :" << buf;
}
void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(source ? source->nick : Config->ServerName) << "G " << dest->name << " " << buf;
+ UplinkSocket::Message(source) << "G " << dest->name << " " << buf;
}
void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override
{
- UplinkSocket::Message(bi ? bi->nick : Config->ServerName) << "v " << u->nick <<" " << buf;
+ UplinkSocket::Message(bi) << "v " << u->nick <<" " << buf;
}
void SendClientIntroduction(const User *u) anope_override
@@ -101,9 +148,9 @@ class UnrealIRCdProto : public IRCDProto
void SendKickInternal(const BotInfo *source, const Channel *chan, const User *user, const Anope::string &buf) anope_override
{
if (!buf.empty())
- UplinkSocket::Message(source->nick) << "H " << chan->name << " " << user->nick << " :" << buf;
+ UplinkSocket::Message(source) << "H " << chan->name << " " << user->nick << " :" << buf;
else
- UplinkSocket::Message(source->nick) << "H " << chan->name << " " << user->nick;
+ UplinkSocket::Message(source) << "H " << chan->name << " " << user->nick;
}
/* SERVER name hop descript */
@@ -119,7 +166,7 @@ class UnrealIRCdProto : public IRCDProto
/* JOIN */
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
{
- UplinkSocket::Message(Config->ServerName) << "~ " << c->creation_time << " " << c->name << " :" << user->nick;
+ UplinkSocket::Message(Me) << "~ " << c->creation_time << " " << c->name << " :" << user->nick;
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -152,7 +199,7 @@ class UnrealIRCdProto : public IRCDProto
*/
void SendSQLine(User *, const XLine *x) anope_override
{
- UplinkSocket::Message() << "c " << x->Mask << " :" << x->Reason;
+ UplinkSocket::Message() << "c " << x->Mask << " :" << x->GetReason();
}
/*
@@ -161,7 +208,7 @@ class UnrealIRCdProto : public IRCDProto
** parv[1] = nick
** parv[2] = options
*/
- void SendSVSO(const Anope::string &source, const Anope::string &nick, const Anope::string &flag) anope_override
+ void SendSVSO(const BotInfo *source, const Anope::string &nick, const Anope::string &flag) anope_override
{
UplinkSocket::Message(source) << "BB " << nick << " " << flag;
}
@@ -169,7 +216,7 @@ class UnrealIRCdProto : public IRCDProto
/* NICK <newnick> */
void SendChangeBotNick(const BotInfo *oldnick, const Anope::string &newnick) anope_override
{
- UplinkSocket::Message(oldnick->nick) << "& " << newnick << " " << Anope::CurTime;
+ UplinkSocket::Message(oldnick) << "& " << newnick << " " << Anope::CurTime;
}
/* Functions that use serval cmd functions */
@@ -177,9 +224,9 @@ class UnrealIRCdProto : public IRCDProto
void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
{
if (!vIdent.empty())
- UplinkSocket::Message(Config->ServerName) << "AZ " << u->nick << " " << vIdent;
+ UplinkSocket::Message(Me) << "AZ " << u->nick << " " << vIdent;
if (!vhost.empty())
- UplinkSocket::Message(Config->ServerName) << "AL " << u->nick << " " << vhost;
+ UplinkSocket::Message(Me) << "AL " << u->nick << " " << vhost;
}
void SendConnect() anope_override
@@ -240,7 +287,7 @@ class UnrealIRCdProto : public IRCDProto
time_t timeleft = x->Expires - Anope::CurTime;
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- UplinkSocket::Message() << "BD + Z * " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->Reason;
+ UplinkSocket::Message() << "BD + Z * " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->GetReason();
}
/* SGLINE */
@@ -249,7 +296,7 @@ class UnrealIRCdProto : public IRCDProto
*/
void SendSGLine(User *, const XLine *x) anope_override
{
- Anope::string edited_reason = x->Reason;
+ Anope::string edited_reason = x->GetReason();
edited_reason = edited_reason.replace_all_cs(" ", "_");
UplinkSocket::Message() << "BR + " << edited_reason << " :" << x->Mask;
}
@@ -263,7 +310,7 @@ class UnrealIRCdProto : public IRCDProto
/* In older Unreal SVSJOIN and SVSNLINE tokens were mixed so SVSJOIN and SVSNLINE are broken
when coming from a none TOKEN'd server
*/
- void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &param) anope_override
+ void SendSVSJoin(const BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &param) anope_override
{
if (!param.empty())
UplinkSocket::Message(source) << "BX " << nick << " " << chan << " :" << param;
@@ -271,14 +318,14 @@ class UnrealIRCdProto : public IRCDProto
UplinkSocket::Message(source) << "BX " << nick << " :" << chan;
}
- void SendSWhois(const Anope::string &source, const Anope::string &who, const Anope::string &mask) anope_override
+ void SendSWhois(const BotInfo *source, const Anope::string &who, const Anope::string &mask) anope_override
{
UplinkSocket::Message(source) << "BA " << who << " :" << mask;
}
void SendEOB() anope_override
{
- UplinkSocket::Message(Config->ServerName) << "ES";
+ UplinkSocket::Message(Me) << "ES";
}
bool IsNickValid(const Anope::string &nick) anope_override
@@ -1157,7 +1204,7 @@ class ProtoUnreal : public Module
{
this->SetAuthor("Anope");
- pmodule_ircd_var(myIrcd);
+ pmodule_ircd_var(&myIrcd);
pmodule_ircd_proto(&this->ircd_proto);
pmodule_ircd_message(&this->ircd_message);
diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp
index aeaa7e3c7..0224547eb 100644
--- a/modules/pseudoclients/operserv.cpp
+++ b/modules/pseudoclients/operserv.cpp
@@ -22,9 +22,9 @@ class SGLineManager : public XLineManager
void OnMatch(User *u, XLine *x) anope_override
{
+ this->Send(u, x);
if (u)
u->Kill(Config->OperServ, x->Reason);
- this->Send(u, x);
}
void OnExpire(XLine *x) anope_override
@@ -34,6 +34,11 @@ class SGLineManager : public XLineManager
void Send(User *u, XLine *x) anope_override
{
+ ircdproto->SendAkill(u, x);
+ }
+
+ void SendDel(XLine *x) anope_override
+ {
try
{
if (!ircd->szline)
@@ -41,29 +46,50 @@ class SGLineManager : public XLineManager
else if (x->GetUser() != "*")
throw SocketException("Can not ZLine a username");
sockaddrs(x->GetHost());
- ircdproto->SendSZLine(u, x);
+ ircdproto->SendSZLineDel(x);
}
catch (const SocketException &)
{
- ircdproto->SendAkill(u, x);
+ ircdproto->SendAkillDel(x);
}
}
- void SendDel(XLine *x) anope_override
+ bool Check(User *u, XLine *x) anope_override
{
- try
+ if (x->regex)
{
- if (!ircd->szline)
- throw SocketException("SZLine is not supported");
- else if (x->GetUser() != "*")
- throw SocketException("Can not ZLine a username");
- sockaddrs(x->GetHost());
- ircdproto->SendSZLineDel(x);
+ Anope::string uh = u->GetIdent() + "@" + u->host, nuhr = u->nick + "!" + uh + "#" + u->realname;
+ if (x->regex->Matches(uh) || x->regex->Matches(nuhr))
+ return true;
+
+ return false;
}
- catch (const SocketException &)
+
+ if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick()))
+ return false;
+
+ if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser()))
+ return false;
+
+ if (!x->GetReal().empty() && !Anope::Match(u->realname, x->GetReal()))
+ return false;
+
+ if (!x->GetHost().empty())
{
- ircdproto->SendAkillDel(x);
+ try
+ {
+ cidr cidr_ip(x->GetHost());
+ sockaddrs ip(u->ip);
+ if (cidr_ip.match(ip))
+ return true;
+ }
+ catch (const SocketException &) { }
}
+
+ if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost()))
+ return true;
+
+ return false;
}
};
@@ -74,13 +100,13 @@ class SQLineManager : public XLineManager
void OnMatch(User *u, XLine *x) anope_override
{
+ this->Send(u, x);
+
if (u)
{
Anope::string reason = "Q-Lined: " + x->Reason;
u->Kill(Config->OperServ, reason);
}
-
- this->Send(u, x);
}
void OnExpire(XLine *x) anope_override
@@ -98,12 +124,18 @@ class SQLineManager : public XLineManager
ircdproto->SendSQLineDel(x);
}
+ bool Check(User *u, XLine *x) anope_override
+ {
+ if (x->regex)
+ return x->regex->Matches(u->nick);
+ return Anope::Match(u->nick, x->Mask);
+ }
+
bool CheckChannel(Channel *c)
{
- if (ircd->chansqline)
- for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it)
- if (Anope::Match(c->name, (*it)->Mask))
- return true;
+ for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it)
+ if (Anope::Match(c->name, (*it)->Mask, false, true))
+ return true;
return false;
}
};
@@ -115,12 +147,13 @@ class SNLineManager : public XLineManager
void OnMatch(User *u, XLine *x) anope_override
{
+ this->Send(u, x);
+
if (u)
{
Anope::string reason = "G-Lined: " + x->Reason;
u->Kill(Config->OperServ, reason);
}
- this->Send(u, x);
}
void OnExpire(XLine *x) anope_override
@@ -138,27 +171,11 @@ class SNLineManager : public XLineManager
ircdproto->SendSGLineDel(x);
}
- XLine *Check(User *u) anope_override
+ bool Check(User *u, XLine *x) anope_override
{
- for (unsigned i = this->GetList().size(); i > 0; --i)
- {
- XLine *x = this->GetList()[i - 1];
-
- if (x->Expires && x->Expires < Anope::CurTime)
- {
- this->OnExpire(x);
- this->DelXLine(x);
- continue;
- }
-
- if (Anope::Match(u->realname, x->Mask))
- {
- this->OnMatch(u, x);
- return x;
- }
- }
-
- return NULL;
+ if (x->regex)
+ return x->regex->Matches(u->realname);
+ return Anope::Match(u->realname, x->Mask, false, true);
}
};
@@ -237,7 +254,7 @@ class OperServCore : public Module
void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override
{
if (ircd->sqline && !u->HasMode(UMODE_OPER))
- this->sqlines.Check(u);
+ this->sqlines.CheckAllXLines(u);
}
EventReturn OnCheckKick(User *u, ChannelInfo *ci, bool &kick) anope_override
diff --git a/src/config.cpp b/src/config.cpp
index 784142556..758bf1544 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -11,7 +11,6 @@
#include "services.h"
#include "config.h"
-#include "module.h"
#include "extern.h"
#include "bots.h"
#include "access.h"
@@ -1157,6 +1156,7 @@ ConfigItems::ConfigItems(ServerConfig *conf)
{"options", "retrywait", "60", new ValueContainerInt(&conf->RetryWait), DT_INTEGER, ValidateNotZero},
{"options", "hideprivilegedcommands", "no", new ValueContainerBool(&conf->HidePrivilegedCommands), DT_BOOLEAN, NoValidation},
{"options", "nonicknameownership", "no", new ValueContainerBool(&conf->NoNicknameOwnership), DT_BOOLEAN | DT_NORELOAD, NoValidation},
+ {"options", "regexengine", "", new ValueContainerString(&conf->RegexEngine), DT_STRING, NoValidation},
{"nickserv", "name", "", new ValueContainerString(&conf->NickServ), DT_STRING, NoValidation},
{"nickserv", "emailregistration", "no", new ValueContainerBool(&conf->NSEmailReg), DT_BOOLEAN, NoValidation},
{"nickserv", "forceemail", "no", new ValueContainerBool(&conf->NSForceEmail), DT_BOOLEAN, ValidateEmailReg},
diff --git a/src/main.cpp b/src/main.cpp
index 55f185057..1d0a3e963 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -178,50 +178,71 @@ void UplinkSocket::OnError(const Anope::string &error)
Log(LOG_TERMINAL) << "Unable to connect to server " << Config->Uplinks[CurrentUplink]->host << ":" << Config->Uplinks[CurrentUplink]->port << (!error.empty() ? (": " + error) : "");
}
-UplinkSocket::Message::Message()
+UplinkSocket::Message::Message() : server(NULL), user(NULL)
{
}
-UplinkSocket::Message::Message(const Anope::string &s) : source(s)
+UplinkSocket::Message::Message(const Server *s) : server(s), user(NULL)
{
}
+UplinkSocket::Message::Message(const User *u) : server(NULL), user(u)
+{
+ if (!u)
+ server = Me;
+}
+
UplinkSocket::Message::~Message()
{
- if (!UplinkSock)
- {
- if (!this->source.empty())
- Log(LOG_DEBUG) << "Attempted to send \"" << this->source << " " << this->buffer.str() << "\" with UplinkSock NULL";
- else
- Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" with UplinkSock NULL";
- return;
- }
+ Anope::string message_source = "";
- if (this->source == Me->GetName())
+ if (this->server != NULL)
{
+ if (this->server != Me && !this->server->HasFlag(SERVER_JUPED))
+ {
+ Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->server->GetName() << " who is not from me?";
+ return;
+ }
+
if (ircd->ts6)
- this->source = Me->GetSID();
+ message_source = this->server->GetSID();
+ else
+ message_source = this->server->GetName();
}
- else if (!this->source.empty() && this->source != Me->GetSID())
+ else if (this->user != NULL)
{
- BotInfo *bi = findbot(this->source);
- if (bi != NULL)
+ if (this->user->server != Me && !this->user->server->HasFlag(SERVER_JUPED))
{
- if (bi->introduced == false)
- {
- Log(LOG_DEBUG) << "Attempted to send \"" << this->source << " " << this->buffer.str() << "\" with source not introduced";
- return;
- }
+ Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->user->nick << " who is not from me?";
+ return;
+ }
- if (ircd->ts6)
- this->source = bi->GetUID();
+ BotInfo *bi = findbot(this->user->nick);
+ if (bi != NULL && bi->introduced == false)
+ {
+ Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced";
+ return;
}
+
+ if (ircd->ts6)
+ message_source = this->user->GetUID();
+ else
+ message_source = this->user->nick;
+ }
+
+ if (!UplinkSock)
+ {
+ if (!message_source.empty())
+ Log(LOG_DEBUG) << "Attempted to send \"" << message_source << " " << this->buffer.str() << "\" with UplinkSock NULL";
+ else
+ Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" with UplinkSock NULL";
+ return;
}
- if (!this->source.empty())
+ if (!message_source.empty())
{
- UplinkSock->Write(":" + this->source + " " + this->buffer.str());
- Log(LOG_RAWIO) << "Sent: :" << this->source << " " << this->buffer.str();
+ UplinkSock->Write(":" + message_source + " " + this->buffer.str());
+ Log(LOG_RAWIO) << "Sent: :" << message_source << " " << this->buffer.str();
}
else
{
diff --git a/src/messages.cpp b/src/messages.cpp
index fa93e528c..52e7c57c1 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -30,17 +30,17 @@ bool OnStats(const Anope::string &source, const std::vector<Anope::string> &para
case 'l':
if (u && u->HasMode(UMODE_OPER))
{
- ircdproto->SendNumeric(Config->ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
- ircdproto->SendNumeric(Config->ServerName, 211, source, "%s %d %d %d %d %d %d %ld", Config->Uplinks[CurrentUplink]->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - start_time));
+ ircdproto->SendNumeric(211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
+ ircdproto->SendNumeric(211, source, "%s %d %d %d %d %d %d %ld", Config->Uplinks[CurrentUplink]->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - start_time));
}
- ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]);
+ ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
break;
case 'o':
case 'O':
/* Check whether the user is an operator */
if (u && !u->HasMode(UMODE_OPER) && Config->HideStatsO)
- ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]);
+ ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
else
{
for (unsigned i = 0; i < Config->Opers.size(); ++i)
@@ -49,10 +49,10 @@ bool OnStats(const Anope::string &source, const std::vector<Anope::string> &para
NickAlias *na = findnick(o->name);
if (na)
- ircdproto->SendNumeric(Config->ServerName, 243, source, "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str());
+ ircdproto->SendNumeric(243, source, "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str());
}
- ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]);
+ ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
}
break;
@@ -60,14 +60,14 @@ bool OnStats(const Anope::string &source, const std::vector<Anope::string> &para
case 'u':
{
time_t uptime = Anope::CurTime - start_time;
- ircdproto->SendNumeric(Config->ServerName, 242, source, ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60);
- ircdproto->SendNumeric(Config->ServerName, 250, source, ":Current users: %d (%d ops); maximum %d", usercnt, opcnt, maxusercnt);
- ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]);
+ ircdproto->SendNumeric(242, source, ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60);
+ ircdproto->SendNumeric(250, source, ":Current users: %d (%d ops); maximum %d", usercnt, opcnt, maxusercnt);
+ ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
break;
} /* case 'u' */
default:
- ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]);
+ ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]);
}
return true;
@@ -83,14 +83,14 @@ bool OnTime(const Anope::string &source, const std::vector<Anope::string> &)
struct tm *tm = localtime(&t);
char buf[64];
strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm);
- ircdproto->SendNumeric(Config->ServerName, 391, source, "%s :%s", Config->ServerName.c_str(), buf);
+ ircdproto->SendNumeric(391, source, "%s :%s", Config->ServerName.c_str(), buf);
return true;
}
bool OnVersion(const Anope::string &source, const std::vector<Anope::string> &)
{
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
- ircdproto->SendNumeric(Config->ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, enc ? enc->name.c_str() : "unknown", Anope::VersionBuildString().c_str());
+ ircdproto->SendNumeric(351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, enc ? enc->name.c_str() : "unknown", Anope::VersionBuildString().c_str());
return true;
}
@@ -103,18 +103,18 @@ bool OnMotd(const Anope::string &source, const std::vector<Anope::string> &)
FILE *f = fopen(Config->MOTDFilename.c_str(), "r");
if (f)
{
- ircdproto->SendNumeric(Config->ServerName, 375, source, ":- %s Message of the Day", Config->ServerName.c_str());
+ ircdproto->SendNumeric(375, source, ":- %s Message of the Day", Config->ServerName.c_str());
char buf[BUFSIZE];
while (fgets(buf, sizeof(buf), f))
{
buf[strlen(buf) - 1] = 0;
- ircdproto->SendNumeric(Config->ServerName, 372, source, ":- %s", buf);
+ ircdproto->SendNumeric(372, source, ":- %s", buf);
}
fclose(f);
- ircdproto->SendNumeric(Config->ServerName, 376, source, ":End of /MOTD command.");
+ ircdproto->SendNumeric(376, source, ":End of /MOTD command.");
}
else
- ircdproto->SendNumeric(Config->ServerName, 422, source, ":- MOTD file not found! Please contact your IRC administrator.");
+ ircdproto->SendNumeric(422, source, ":- MOTD file not found! Please contact your IRC administrator.");
return true;
}
diff --git a/src/misc.cpp b/src/misc.cpp
index 5f36358d3..855155409 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -18,6 +18,7 @@
#include "config.h"
#include "bots.h"
#include "language.h"
+#include "regexpr.h"
#include <errno.h>
#include <sys/types.h>
@@ -570,10 +571,46 @@ std::vector<Anope::string> BuildStringVector(const Anope::string &src, char deli
/*************************************************************************/
-bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case_sensitive)
+bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case_sensitive, bool use_regex)
{
size_t s = 0, m = 0, str_len = str.length(), mask_len = mask.length();
+ if (use_regex && mask_len >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/')
+ {
+ Anope::string stripped_mask = mask.substr(1, mask_len - 2);
+ // This is often called with the same mask multiple times in a row, so cache it
+ static Regex *r = NULL;
+
+ if (r == NULL || r->GetExpression() != stripped_mask)
+ {
+ service_reference<RegexProvider> provider("Regex", Config->RegexEngine);
+ if (provider)
+ {
+ try
+ {
+ delete r;
+ r = NULL;
+ // This may throw
+ r = provider->Compile(stripped_mask);
+ }
+ catch (const RegexException &ex)
+ {
+ Log(LOG_DEBUG) << ex.GetReason();
+ }
+ }
+ else
+ {
+ delete r;
+ r = NULL;
+ }
+ }
+
+ if (r != NULL && r->Matches(str))
+ return true;
+
+ // Fall through to non regex match
+ }
+
while (s < str_len && m < mask_len && mask[m] != '*')
{
char string = str[s], wild = mask[m];
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index d16b71cad..6837f7d1f 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -462,7 +462,7 @@ void ModuleManager::UnloadAll()
{
std::vector<Anope::string> modules[MT_END];
for (std::list<Module *>::iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
- if ((*it)->type != PROTOCOL)
+ if ((*it)->type != PROTOCOL && !(*it)->GetPermanent())
modules[(*it)->type].push_back((*it)->name);
for (size_t i = MT_BEGIN + 1; i != MT_END; ++i)
diff --git a/src/operserv.cpp b/src/operserv.cpp
index 6cdbf2ff3..018c9b4e0 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -16,19 +16,54 @@
#include "users.h"
#include "extern.h"
#include "sockets.h"
+#include "regexpr.h"
+#include "config.h"
+#include "commands.h"
/* List of XLine managers we check users against in XLineManager::CheckAll */
std::list<XLineManager *> XLineManager::XLineManagers;
-std::map<Anope::string, XLine *, ci::less> XLineManager::XLinesByUID;
+std::multimap<Anope::string, XLine *, ci::less> XLineManager::XLinesByUID;
+
+void XLine::InitRegex()
+{
+ if (!Config->RegexEngine.empty() && this->Mask.length() >= 2 && this->Mask[0] == '/' && this->Mask[this->Mask.length() - 1] == '/')
+ {
+ Anope::string stripped_mask = this->Mask.substr(1, this->Mask.length() - 2);
+
+ service_reference<RegexProvider> provider("Regex", Config->RegexEngine);
+ if (provider)
+ {
+ try
+ {
+ this->regex = provider->Compile(stripped_mask);
+ }
+ catch (const RegexException &ex)
+ {
+ Log(LOG_DEBUG) << ex.GetReason();
+ }
+ }
+ }
+}
XLine::XLine(const Anope::string &mask, const Anope::string &reason, const Anope::string &uid) : Mask(mask), Created(0), Expires(0), Reason(reason), UID(uid)
{
+ regex = NULL;
manager = NULL;
+
+ this->InitRegex();
}
XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid) : Mask(mask), By(by), Created(Anope::CurTime), Expires(expires), Reason(reason), UID(uid)
{
+ regex = NULL;
manager = NULL;
+
+ this->InitRegex();
+}
+
+XLine::~XLine()
+{
+ delete regex;
}
Anope::string XLine::GetNick() const
@@ -47,7 +82,7 @@ Anope::string XLine::GetUser() const
if (host_t != Anope::string::npos)
{
- if (user_t != Anope::string::npos)
+ if (user_t != Anope::string::npos && host_t > user_t)
return this->Mask.substr(user_t + 1, host_t - user_t - 1);
else
return this->Mask.substr(0, host_t);
@@ -58,12 +93,49 @@ Anope::string XLine::GetUser() const
Anope::string XLine::GetHost() const
{
- size_t host_t = this->Mask.find('@');
+ size_t host_t = this->Mask.find('@'), real_t = this->Mask.find('#');
+
+ if (host_t != Anope::string::npos)
+ {
+ if (real_t != Anope::string::npos && real_t > host_t)
+ return this->Mask.substr(host_t + 1, real_t - host_t - 1);
+ else
+ return this->Mask.substr(host_t + 1);
+ }
+ else
+ return "";
+}
+
+Anope::string XLine::GetReal() const
+{
+ size_t real_t = this->Mask.find('#');
- if (host_t == Anope::string::npos)
- return this->Mask;
+ if (real_t != Anope::string::npos)
+ return this->Mask.substr(real_t + 1);
else
- return this->Mask.substr(host_t + 1);
+ return "";
+}
+
+Anope::string XLine::GetReason() const
+{
+ Anope::string r = this->Reason;
+ if (Config->AddAkiller && !this->By.empty())
+ r = "[" + this->By + "] " + r;
+ if (!this->UID.empty())
+ r += " (ID: " + this->UID + ")";
+ return r;
+}
+
+bool XLine::HasNickOrReal() const
+{
+ bool r = this->GetNick().find_first_not_of("?*") != Anope::string::npos;
+ r = r || this->GetReal().find_first_not_of("?*") != Anope::string::npos;
+ return r;
+}
+
+bool XLine::IsRegex() const
+{
+ return !this->Mask.empty() && this->Mask[0] == '/' && this->Mask[this->Mask.length() - 1] == '/';
}
Anope::string XLine::serialize_name() const
@@ -128,40 +200,43 @@ void XLineManager::UnregisterXLineManager(XLineManager *xlm)
* @param u The user
* @return A pair of the XLineManager the user was found in and the XLine they matched, both may be NULL for no match
*/
-std::pair<XLineManager *, XLine *> XLineManager::CheckAll(User *u)
+void XLineManager::CheckAll(User *u)
{
- std::pair<XLineManager *, XLine *> ret;
-
- ret.first = NULL;
- ret.second = NULL;
-
for (std::list<XLineManager *>::iterator it = XLineManagers.begin(), it_end = XLineManagers.end(); it != it_end; ++it)
{
XLineManager *xlm = *it;
- XLine *x = xlm->Check(u);
+ XLine *x = xlm->CheckAllXLines(u);
if (x)
{
- ret.first = xlm;
- ret.second = x;
+ xlm->OnMatch(u, x);
break;
}
}
-
- return ret;
}
Anope::string XLineManager::GenerateUID()
{
Anope::string id;
- for (int i = 0; i < 10; ++i)
+ int count = 0;
+ while (id.empty() || XLinesByUID.count(id) > 0)
{
- char c;
- do
- c = (random() % 75) + 48;
- while (!isupper(c) && !isdigit(c));
- id += c;
+ if (++count > 10)
+ {
+ id.clear();
+ Log(LOG_DEBUG) << "Unable to generate XLine UID";
+ break;
+ }
+
+ for (int i = 0; i < 10; ++i)
+ {
+ char c;
+ do
+ c = (random() % 75) + 48;
+ while (!isupper(c) && !isdigit(c));
+ id += c;
+ }
}
return id;
@@ -212,7 +287,7 @@ void XLineManager::AddXLine(XLine *x)
{
x->manager = this;
if (!x->UID.empty())
- XLinesByUID[x->UID] = x;
+ XLinesByUID.insert(std::make_pair(x->UID, x));
this->XLines.push_back(x);
}
@@ -225,7 +300,15 @@ bool XLineManager::DelXLine(XLine *x)
std::vector<XLine *>::iterator it = std::find(this->XLines.begin(), this->XLines.end(), x);
if (!x->UID.empty())
- XLinesByUID.erase(x->UID);
+ {
+ std::multimap<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID.find(x->UID), it3 = XLinesByUID.upper_bound(x->UID);
+ for (; it2 != XLinesByUID.end() && it2 != it3; ++it2)
+ if (it2->second == x)
+ {
+ XLinesByUID.erase(it2);
+ break;
+ }
+ }
if (it != this->XLines.end())
{
@@ -266,53 +349,57 @@ void XLineManager::Clear()
}
/** Checks if a mask can/should be added to the XLineManager
+ * @param source The source adding the mask.
* @param mask The mask
* @param expires When the mask would expire
- * @return A pair of int and XLine*.
- * 1 - Mask already exists
- * 2 - Mask already exists, but the expiry time was changed
- * 3 - Mask is already covered by another mask
- * In each case the XLine it matches/is covered by is returned in XLine*
+ * @param reason the reason
+ * @return true if the mask can be added
*/
-std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t expires)
+bool XLineManager::CanAdd(CommandSource &source, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
- std::pair<int, XLine *> ret;
-
- ret.first = 0;
- ret.second = NULL;
-
for (unsigned i = this->GetCount(); i > 0; --i)
{
XLine *x = this->GetEntry(i - 1);
- ret.second = x;
if (x->Mask.equals_ci(mask))
{
if (!x->Expires || x->Expires >= expires)
{
- ret.first = 1;
- break;
+ if (x->Reason != reason)
+ {
+ x->Reason = reason;
+ source.Reply(_("Reason for %s updated."), x->Mask.c_str());
+ }
+ else
+ source.Reply(_("%s already exists."), mask.c_str());
}
else
{
x->Expires = expires;
-
- ret.first = 2;
- break;
+ if (x->Reason != reason)
+ {
+ x->Reason = reason;
+ source.Reply(_("Expiry and reason updated for %s."), x->Mask.c_str());
+ }
+ else
+ source.Reply(_("Expiry for %s updated."), x->Mask.c_str());
}
+
+ return false;
}
else if (Anope::Match(mask, x->Mask) && (!x->Expires || x->Expires >= expires))
{
- ret.first = 3;
- break;
+ source.Reply(_("%s is already covered by %s."), mask.c_str(), x->Mask.c_str());
+ return false;
}
else if (Anope::Match(x->Mask, mask) && (!expires || x->Expires <= expires))
{
+ source.Reply(_("Removing %s because %s covers it."), x->Mask.c_str(), mask.c_str());
this->DelXLine(x);
}
}
- return ret;
+ return true;
}
/** Checks if this list has an entry
@@ -322,8 +409,10 @@ std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t e
XLine *XLineManager::HasEntry(const Anope::string &mask)
{
std::map<Anope::string, XLine *, ci::less>::iterator it = XLinesByUID.find(mask);
- if (it != XLinesByUID.end() && (it->second->manager == NULL || it->second->manager == this))
- return it->second;
+ if (it != XLinesByUID.end())
+ for (std::map<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID.upper_bound(mask); it != it2; ++it)
+ if (it->second->manager == NULL || it->second->manager == this)
+ return it->second;
for (unsigned i = 0, end = this->XLines.size(); i < end; ++i)
{
XLine *x = this->XLines[i];
@@ -337,9 +426,9 @@ XLine *XLineManager::HasEntry(const Anope::string &mask)
/** Check a user against all of the xlines in this XLineManager
* @param u The user
- * @return The xline the user marches, if any. Also calls OnMatch()
+ * @return The xline the user marches, if any.
*/
-XLine *XLineManager::Check(User *u)
+XLine *XLineManager::CheckAllXLines(User *u)
{
for (unsigned i = this->XLines.size(); i > 0; --i)
{
@@ -352,30 +441,9 @@ XLine *XLineManager::Check(User *u)
continue;
}
- if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick()))
- continue;
-
- if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser()))
- continue;
-
- if (!x->GetHost().empty())
- {
- try
- {
- cidr cidr_ip(x->GetHost());
- sockaddrs ip(u->ip);
- if (cidr_ip.match(ip))
- {
- OnMatch(u, x);
- return x;
- }
- }
- catch (const SocketException &) { }
- }
-
- if (x->GetHost().empty() || (Anope::Match(u->host, x->GetHost()) || (!u->chost.empty() && Anope::Match(u->chost, x->GetHost())) || (!u->vhost.empty() && Anope::Match(u->vhost, x->GetHost()))))
+ if (this->Check(u, x))
{
- OnMatch(u, x);
+ this->OnMatch(u, x);
return x;
}
}
@@ -383,14 +451,6 @@ XLine *XLineManager::Check(User *u)
return NULL;
}
-/** Called when a user matches a xline in this XLineManager
- * @param u The user
- * @param x The XLine they match
- */
-void XLineManager::OnMatch(User *u, XLine *x)
-{
-}
-
/** Called when an XLine expires
* @param x The xline
*/
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 051f6f2d1..f51880bbe 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -39,6 +39,24 @@ void pmodule_ircd_message(IRCdMessage *message)
ircdmessage = message;
}
+void IRCDProto::SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf)
+{
+ UplinkSocket::Message(source) << "KILL " << (ircd->ts6 ? user->GetUID() : user->nick) << " :" << buf;
+}
+
+void IRCDProto::SendModeInternal(const BotInfo *bi, const Channel *dest, const Anope::string &buf)
+{
+ UplinkSocket::Message(bi) << "MODE " << dest->name << " " << buf;
+}
+
+void IRCDProto::SendKickInternal(const BotInfo *bi, const Channel *c, const User *u, const Anope::string &r)
+{
+ if (!r.empty())
+ UplinkSocket::Message(bi) << "KICK " << c->name << " " << (ircd->ts6 ? u->GetUID() : u->nick) << " :" << r;
+ else
+ UplinkSocket::Message(bi) << "KICK " << c->name << " " << (ircd->ts6 ? u->GetUID() : u->nick);
+}
+
void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
{
if (Config->NSDefFlags.HasFlag(NI_MSG))
@@ -49,33 +67,36 @@ void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest
void IRCDProto::SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg)
{
- UplinkSocket::Message(bi->nick) << "NOTICE " << dest << " :" << msg;
+ UplinkSocket::Message(bi) << "NOTICE " << dest << " :" << msg;
}
void IRCDProto::SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
{
- UplinkSocket::Message(bi->nick) << "PRIVMSG " << dest << " :" << buf;
+ UplinkSocket::Message(bi) << "PRIVMSG " << dest << " :" << buf;
}
void IRCDProto::SendQuitInternal(const User *u, const Anope::string &buf)
{
if (!buf.empty())
- UplinkSocket::Message(u->nick) << "QUIT :" << buf;
+ UplinkSocket::Message(u) << "QUIT :" << buf;
else
- UplinkSocket::Message(u->nick) << "QUIT";
+ UplinkSocket::Message(u) << "QUIT";
}
void IRCDProto::SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf)
{
if (!buf.empty())
- UplinkSocket::Message(bi->nick) << "PART " << chan->name << " :" << buf;
+ UplinkSocket::Message(bi) << "PART " << chan->name << " :" << buf;
else
- UplinkSocket::Message(bi->nick) << "PART " << chan->name;
+ UplinkSocket::Message(bi) << "PART " << chan->name;
}
void IRCDProto::SendGlobopsInternal(const BotInfo *source, const Anope::string &buf)
{
- UplinkSocket::Message(source ? source->nick : Config->ServerName) << "GLOBOPS :" << buf;
+ if (source)
+ UplinkSocket::Message(source) << "GLOBOPS :" << buf;
+ else
+ UplinkSocket::Message(Me) << "GLOBOPS :" << buf;
}
void IRCDProto::SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
@@ -84,14 +105,19 @@ void IRCDProto::SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, c
this->SendNoticeInternal(bi, dest, "\1" + s + "\1");
}
-void IRCDProto::SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf)
+void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf)
{
Anope::string n = stringify(numeric);
if (numeric < 10)
n = "0" + n;
if (numeric < 100)
n = "0" + n;
- UplinkSocket::Message(source) << n << " " << dest << " " << buf;
+ UplinkSocket::Message(Me) << n << " " << dest << " " << buf;
+}
+
+void IRCDProto::SendTopic(BotInfo *bi, Channel *c)
+{
+ UplinkSocket::Message(bi) << "TOPIC " << c->name << " :" << c->topic;
}
void IRCDProto::SendSVSKill(const BotInfo *source, const User *user, const char *fmt, ...)
@@ -183,12 +209,12 @@ void IRCDProto::SendPrivmsg(const BotInfo *bi, const Anope::string &dest, const
void IRCDProto::SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg)
{
- UplinkSocket::Message(bi->nick) << "NOTICE " << ircd->globaltldprefix << dest->GetName() << " :" << msg;
+ UplinkSocket::Message(bi) << "NOTICE " << ircd->globaltldprefix << dest->GetName() << " :" << msg;
}
void IRCDProto::SendGlobalPrivmsg(const BotInfo *bi, const Server *dest, const Anope::string &msg)
{
- UplinkSocket::Message(bi->nick) << "PRIVMSG " << ircd->globaltldprefix << dest->GetName() << " :" << msg;
+ UplinkSocket::Message(bi) << "PRIVMSG " << ircd->globaltldprefix << dest->GetName() << " :" << msg;
}
void IRCDProto::SendQuit(const User *u, const char *fmt, ...)
@@ -204,9 +230,9 @@ void IRCDProto::SendQuit(const User *u, const char *fmt, ...)
void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who)
{
if (servname.empty())
- UplinkSocket::Message(Config->ServerName) << "PING " << who;
+ UplinkSocket::Message(Me) << "PING " << who;
else
- UplinkSocket::Message(Config->ServerName) << "PING " << servname << " " << who;
+ UplinkSocket::Message(Me) << "PING " << servname << " " << who;
}
/**
@@ -218,14 +244,14 @@ void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who
void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who)
{
if (servname.empty())
- UplinkSocket::Message(Config->ServerName) << "PONG " << who;
+ UplinkSocket::Message(Me) << "PONG " << who;
else
- UplinkSocket::Message(Config->ServerName) << "PONG " << servname << " " << who;
+ UplinkSocket::Message(Me) << "PONG " << servname << " " << who;
}
-void IRCDProto::SendInvite(const BotInfo *bi, const Anope::string &chan, const Anope::string &nick)
+void IRCDProto::SendInvite(const BotInfo *bi, const Channel *c, const User *u)
{
- UplinkSocket::Message(bi->nick) << "INVITE " << nick << " " << chan;
+ UplinkSocket::Message(bi) << "INVITE " << (ircd->ts6 ? u->GetUID() : u->nick) << " " << c->name;
}
void IRCDProto::SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...)
@@ -260,7 +286,7 @@ void IRCDProto::SendSquit(Server *s, const Anope::string &message)
void IRCDProto::SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick)
{
- UplinkSocket::Message(bi->nick) << "NICK " << newnick << " " << Anope::CurTime;
+ UplinkSocket::Message(bi) << "NICK " << newnick << " " << Anope::CurTime;
}
void IRCDProto::SendForceNickChange(const User *u, const Anope::string &newnick, time_t when)
@@ -278,14 +304,14 @@ void IRCDProto::SendCTCP(const BotInfo *bi, const Anope::string &dest, const cha
SendCTCPInternal(bi, dest, buf);
}
-void IRCDProto::SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...)
+void IRCDProto::SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendNumericInternal(source, numeric, dest, buf);
+ SendNumericInternal(numeric, dest, buf);
}
bool IRCDProto::IsChannelValid(const Anope::string &chan)
@@ -518,16 +544,16 @@ bool IRCdMessage::OnWhois(const Anope::string &source, const std::vector<Anope::
if (u && u->server == Me)
{
BotInfo *bi = findbot(u->nick);
- ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
+ ircdproto->SendNumeric(311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
if (bi)
- ircdproto->SendNumeric(Config->ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str());
- ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", u->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str());
+ ircdproto->SendNumeric(307, source, "%s :is a registered nick", bi->nick.c_str());
+ ircdproto->SendNumeric(312, source, "%s %s :%s", u->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str());
if (bi)
- ircdproto->SendNumeric(Config->ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(start_time));
- ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", params[0].c_str());
+ ircdproto->SendNumeric(317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(start_time));
+ ircdproto->SendNumeric(318, source, "%s :End of /WHOIS list.", params[0].c_str());
}
else
- ircdproto->SendNumeric(Config->ServerName, 401, source, "%s :No such user.", params[0].c_str());
+ ircdproto->SendNumeric(401, source, "%s :No such user.", params[0].c_str());
}
return true;
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 34a578917..25526ee8b 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -660,7 +660,7 @@ void ChannelInfo::EraseAkick(unsigned index)
{
if (this->akick.empty() || index >= this->akick.size())
return;
-
+
delete this->akick[index];
this->akick.erase(this->akick.begin() + index);
}
@@ -719,6 +719,8 @@ void ChannelInfo::EraseBadWord(unsigned index)
{
if (this->badwords.empty() || index >= this->badwords.size())
return;
+
+ FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, this->badwords[index]));
delete this->badwords[index];
this->badwords.erase(this->badwords.begin() + index);