mirror of
https://github.com/anope/anope.git
synced 2026-06-28 18:56:39 +02:00
Moved some global functions to be member functions and misc cleanup
This commit is contained in:
@@ -335,6 +335,18 @@ namespace Anope
|
||||
*/
|
||||
extern CoreExport void Unhex(const Anope::string &src, Anope::string &dest);
|
||||
extern CoreExport void Unhex(const Anope::string &src, char *dest);
|
||||
|
||||
/** Base 64 encode a string
|
||||
* @param src The string to encode
|
||||
* @param target Where the encoded string is placed
|
||||
*/
|
||||
extern CoreExport void B64Encode(const Anope::string &src, Anope::string &target);
|
||||
|
||||
/** Base 64 decode a string
|
||||
* @param src The base64 encoded string
|
||||
* @param target The plain text result
|
||||
*/
|
||||
extern CoreExport void B64Decode(const Anope::string &src, Anope::string &target);
|
||||
|
||||
/** Returns a sequence of data formatted as the format argument specifies.
|
||||
** After the format parameter, the function expects at least as many
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
#include "hashcomp.h"
|
||||
|
||||
E void ModuleRunTimeDirCleanUp();
|
||||
|
||||
/* IRC Variables */
|
||||
|
||||
E IRCDVar *ircd;
|
||||
@@ -27,7 +25,6 @@ E IRCdMessage *ircdmessage;
|
||||
|
||||
/**** actions.c ****/
|
||||
|
||||
E void kill_user(const Anope::string &source, User *user, const Anope::string &reason);
|
||||
E bool bad_password(User *u);
|
||||
E void common_unban(ChannelInfo *ci, User *u, bool full = false);
|
||||
|
||||
@@ -51,7 +48,6 @@ E void do_cmode(const Anope::string &source, const Anope::string &channel, const
|
||||
E void do_join(const Anope::string &source, const Anope::string &channels, const Anope::string &ts);
|
||||
E void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason);
|
||||
E void do_part(const Anope::string &source, const Anope::string &channels, const Anope::string &reason);
|
||||
E void MassChannelModes(BotInfo *bi, const Anope::string &modes);
|
||||
|
||||
E void chan_set_correct_modes(User *user, Channel *c, int give_modes);
|
||||
|
||||
@@ -71,7 +67,6 @@ E void update_cs_lastseen(User *user, ChannelInfo *ci);
|
||||
E int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret);
|
||||
|
||||
E int levelinfo_maxwidth;
|
||||
E Anope::string get_mlock_modes(ChannelInfo *ci, int complete);
|
||||
|
||||
/**** config.c ****/
|
||||
|
||||
@@ -187,7 +182,6 @@ E bool isvalidchar(char c);
|
||||
E Anope::string myStrGetToken(const Anope::string &str, char dilim, int token_number);
|
||||
E Anope::string myStrGetTokenRemainder(const Anope::string &str, char dilim, int token_number);
|
||||
E int myNumToken(const Anope::string &str, char dilim);
|
||||
E void EnforceQlinedNick(const Anope::string &nick, const Anope::string &killer);
|
||||
E bool nickIsServices(const Anope::string &nick, bool bot);
|
||||
|
||||
E void add_entropy_userkeys();
|
||||
@@ -196,8 +190,6 @@ E unsigned char getrandom8();
|
||||
E uint16 getrandom16();
|
||||
E uint32 getrandom32();
|
||||
|
||||
E char *str_signed(unsigned char *str);
|
||||
|
||||
E std::list<Anope::string> BuildStringList(const Anope::string &, char = ' ');
|
||||
E std::vector<Anope::string> BuildStringVector(const Anope::string &, char = ' ');
|
||||
|
||||
@@ -251,13 +243,7 @@ E void do_umode(const Anope::string &user, const Anope::string &modes);
|
||||
E void do_kill(User *user, const Anope::string &reason);
|
||||
|
||||
E bool matches_list(Channel *c, User *user, ChannelModeName mode);
|
||||
E bool is_excepted_mask(ChannelInfo *ci, const Anope::string &mask);
|
||||
|
||||
E Anope::string create_mask(User *u);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
E void b64_encode(const Anope::string &src, Anope::string &target);
|
||||
E void b64_decode(const Anope::string &src, Anope::string &target);
|
||||
|
||||
#endif /* EXTERN_H */
|
||||
|
||||
+13
-1
@@ -129,7 +129,6 @@ class Message;
|
||||
|
||||
extern CoreExport Module *FindModule(const Anope::string &name);
|
||||
int protocol_module_init();
|
||||
extern CoreExport bool moduleMinVersion(int major, int minor, int patch, int build);
|
||||
|
||||
enum ModuleReturn
|
||||
{
|
||||
@@ -1125,6 +1124,10 @@ class CoreExport ModuleManager
|
||||
*/
|
||||
static std::vector<Module *> EventHandlers[I_END];
|
||||
|
||||
/** Clean up the module runtime directory
|
||||
*/
|
||||
static void CleanupRuntimeDirectory();
|
||||
|
||||
/** Load up a list of modules.
|
||||
* @param module_list The list of modules to load
|
||||
**/
|
||||
@@ -1144,6 +1147,15 @@ class CoreExport ModuleManager
|
||||
*/
|
||||
static ModuleReturn UnloadModule(Module *m, User * u);
|
||||
|
||||
/** Checks whether this version of Anope is at least major.minor.patch.build
|
||||
* Throws a ModuleException if not
|
||||
* @param major The major version
|
||||
* @param minor The minor vesion
|
||||
* @param patch The patch version
|
||||
* @param build The build version
|
||||
*/
|
||||
static void RequireVersion(int major, int minor, int patch, int build);
|
||||
|
||||
/** Change the priority of one event in a module.
|
||||
* Each module event has a list of modules which are attached to that event type. If you wish to be called before or after other specific modules, you may use this
|
||||
* method (usually within void Module::Prioritize()) to set your events priority. You may use this call in other methods too, however, this is not supported behaviour
|
||||
|
||||
@@ -376,6 +376,12 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
|
||||
*/
|
||||
ModeLock *GetMLock(ChannelModeName mname, const Anope::string ¶m = "");
|
||||
|
||||
/** Get the current mode locks as a string
|
||||
* @param complete True to show mlock parameters aswell
|
||||
* @return A string of mode locks, eg: +nrt
|
||||
*/
|
||||
Anope::string GetMLockAsString(bool complete) const;
|
||||
|
||||
/** Check whether a user is permitted to be on this channel
|
||||
* @param u The user
|
||||
* @return true if they are allowed, false if they aren't and were kicked
|
||||
|
||||
@@ -284,6 +284,12 @@ class CoreExport User : public Extensible
|
||||
* @return true or false
|
||||
*/
|
||||
bool IsProtected() const;
|
||||
|
||||
/** Kill a user
|
||||
* @param source The user/server doing the kill
|
||||
* @param reason The reason for the kill
|
||||
*/
|
||||
void Kill(const Anope::string &source, const Anope::string &reason);
|
||||
};
|
||||
|
||||
#endif // USERS_H
|
||||
|
||||
@@ -224,16 +224,16 @@ class CommandBSBot : public Command
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
/* The new nick is really different, so we remove the Q line for
|
||||
the old nick. */
|
||||
/* The new nick is really different, so we remove the Q line for the old nick. */
|
||||
if (ircd->sqline)
|
||||
{
|
||||
XLine x(bi->nick);
|
||||
ircdproto->SendSQLineDel(&x);
|
||||
}
|
||||
|
||||
/* We check whether user with this nick is online, and kill it if so */
|
||||
EnforceQlinedNick(nick, Config->s_BotServ);
|
||||
/* Add a Q line for the new nick */
|
||||
XLine x(nick, "Reserved for services");
|
||||
ircdproto->SendSQLine(NULL, &x);
|
||||
}
|
||||
|
||||
if (!user.empty())
|
||||
@@ -241,8 +241,6 @@ class CommandBSBot : public Command
|
||||
else
|
||||
{
|
||||
ircdproto->SendChangeBotNick(bi, nick);
|
||||
XLine x(bi->nick, "Reserved for services");
|
||||
ircdproto->SendSQLine(NULL, &x);
|
||||
}
|
||||
|
||||
if (!nick.equals_cs(bi->nick))
|
||||
@@ -258,8 +256,6 @@ class CommandBSBot : public Command
|
||||
if (!user.empty())
|
||||
{
|
||||
ircdproto->SendClientIntroduction(bi, ircd->pseudoclient_mode);
|
||||
XLine x(bi->nick, "Reserved for services");
|
||||
ircdproto->SendSQLine(NULL, &x);
|
||||
bi->RejoinAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -192,10 +192,17 @@ class CommandCSAKick : public Command
|
||||
}
|
||||
|
||||
/* Check excepts BEFORE we get this far */
|
||||
if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted_mask(ci, mask))
|
||||
if (ci->c)
|
||||
{
|
||||
source.Reply(_(CHAN_EXCEPTED), mask.c_str(), ci->name.c_str());
|
||||
return;
|
||||
std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> modes = ci->c->GetModeList(CMODE_EXCEPT);
|
||||
for (; modes.first != modes.second; ++modes.first)
|
||||
{
|
||||
if (Anope::Match(modes.first->second, mask))
|
||||
{
|
||||
source.Reply(_(CHAN_EXCEPTED), mask.c_str(), ci->name.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check whether target nick has equal/higher access
|
||||
|
||||
@@ -100,7 +100,7 @@ class CommandCSInfo : public Command
|
||||
CheckOptStr(optbuf, CI_NO_EXPIRE, _("No expire"), ci, u->Account());
|
||||
|
||||
source.Reply(_(NICK_INFO_OPTIONS), optbuf.empty() ? _("None") : optbuf.c_str());
|
||||
source.Reply(_(" Mode lock: %s"), get_mlock_modes(ci, 1).c_str());
|
||||
source.Reply(_(" Mode lock: %s"), ci->GetMLockAsString(true).c_str());
|
||||
|
||||
if (!ci->HasFlag(CI_NO_EXPIRE))
|
||||
source.Reply(_(" Expires on: %s"), do_strftime(ci->last_used + Config->CSExpire).c_str());
|
||||
|
||||
@@ -25,7 +25,7 @@ class ENone : public Module
|
||||
{
|
||||
Anope::string buf = "plain:";
|
||||
Anope::string cpass;
|
||||
b64_encode(src, cpass);
|
||||
Anope::B64Encode(src, cpass);
|
||||
buf += cpass;
|
||||
Log(LOG_DEBUG_2) << "(enc_none) hashed password from [" << src << "] to [" << buf << "]";
|
||||
dest = buf;
|
||||
@@ -38,7 +38,7 @@ class ENone : public Module
|
||||
return EVENT_CONTINUE;
|
||||
size_t pos = src.find(':');
|
||||
Anope::string buf = src.substr(pos + 1);
|
||||
b64_decode(buf, dest);
|
||||
Anope::B64Decode(buf, dest);
|
||||
return EVENT_ALLOW;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class CommandNSGhost : public Command
|
||||
{
|
||||
Log(LOG_COMMAND, u, this) << "for " << nick;
|
||||
Anope::string buf = "GHOST command used by " + u->nick;
|
||||
kill_user(Config->s_NickServ, user, buf);
|
||||
user->Kill(Config->s_NickServ, buf);
|
||||
source.Reply(_("Ghost with your nick has been killed."), nick.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class CommandOSNOOP : public Command
|
||||
++it;
|
||||
|
||||
if (u2 && u2->HasMode(UMODE_OPER) && Anope::Match(u2->server->GetName(), server, true))
|
||||
kill_user(Config->s_OperServ, u2, reason);
|
||||
u2->Kill(Config->s_OperServ, reason);
|
||||
}
|
||||
}
|
||||
else if (cmd.equals_ci("REVOKE"))
|
||||
|
||||
@@ -606,7 +606,7 @@ class OSSession : public Module
|
||||
if (!Config->SessionLimitDetailsLoc.empty())
|
||||
u->SendMessage(operserv->Bot(), "%s", Config->SessionLimitDetailsLoc.c_str());
|
||||
|
||||
kill_user(Config->s_OperServ, u, "Session limit exceeded");
|
||||
u->Kill(Config->s_OperServ, "Session limit exceeded");
|
||||
|
||||
++session->hits;
|
||||
if (Config->MaxSessionKill && session->hits >= Config->MaxSessionKill && SGLine)
|
||||
|
||||
@@ -436,7 +436,7 @@ class OSDefcon : public Module
|
||||
}
|
||||
|
||||
if (DConfig.Check(DEFCON_NO_NEW_CLIENTS) || DConfig.Check(DEFCON_AKILL_NEW_CLIENTS))
|
||||
kill_user(Config->s_OperServ, u, DConfig.akillreason);
|
||||
u->Kill(Config->s_OperServ, DConfig.akillreason);
|
||||
|
||||
return EVENT_STOP;
|
||||
}
|
||||
@@ -556,7 +556,7 @@ class OSDefcon : public Module
|
||||
|
||||
if (DConfig.Check(DEFCON_NO_NEW_CLIENTS) || DConfig.Check(DEFCON_AKILL_NEW_CLIENTS))
|
||||
{
|
||||
kill_user(Config->s_OperServ, u, DConfig.akillreason);
|
||||
u->Kill(Config->s_OperServ, DConfig.akillreason);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -574,7 +574,7 @@ class OSDefcon : public Module
|
||||
|
||||
if (DConfig.Check(DEFCON_NO_NEW_CLIENTS) || DConfig.Check(DEFCON_AKILL_NEW_CLIENTS))
|
||||
{
|
||||
kill_user(Config->s_OperServ, u, DConfig.akillreason);
|
||||
u->Kill(Config->s_OperServ, DConfig.akillreason);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ class OSDefcon : public Module
|
||||
if (!Config->SessionLimitDetailsLoc.empty())
|
||||
ircdproto->SendMessage(operserv->Bot(), u->nick, "%s", Config->SessionLimitDetailsLoc.c_str());
|
||||
|
||||
kill_user(Config->s_OperServ, u, "Defcon session limit exceeded");
|
||||
u->Kill(Config->s_OperServ, "Defcon session limit exceeded");
|
||||
++session->hits;
|
||||
if (Config->MaxSessionKill && session->hits >= Config->MaxSessionKill)
|
||||
{
|
||||
@@ -651,7 +651,8 @@ void runDefCon()
|
||||
{
|
||||
Log(operserv->Bot(), "operserv/defcon") << "DEFCON: setting " << DConfig.chanmodes << " on all channels";
|
||||
DefConModesSet = true;
|
||||
MassChannelModes(operserv->Bot(), DConfig.chanmodes);
|
||||
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
|
||||
it->second->SetModes(operserv->Bot(), false, "%s", DConfig.chanmodes.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -666,7 +667,8 @@ void runDefCon()
|
||||
if (!newmodes.empty())
|
||||
{
|
||||
Log(operserv->Bot(), "operserv/defcon") << "DEFCON: setting " << newmodes << " on all channels";
|
||||
MassChannelModes(operserv->Bot(), newmodes);
|
||||
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
|
||||
it->second->SetModes(operserv->Bot(), false, "%s", newmodes.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,8 @@ class BahamutIRCdProto : public IRCDProto
|
||||
|
||||
void SendClientIntroduction(const User *u, const Anope::string &modes)
|
||||
{
|
||||
EnforceQlinedNick(u->nick, Config->s_BotServ);
|
||||
XLine x(u->nick, "Reserved for services");
|
||||
ircdproto->SendSQLine(NULL, &x);
|
||||
send_cmd("", "NICK %s 1 %ld %s %s %s %s 0 0 :%s", u->nick.c_str(), static_cast<long>(u->timestamp), modes.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->server->GetName().c_str(), u->realname.c_str());
|
||||
}
|
||||
|
||||
@@ -248,7 +249,10 @@ class BahamutIRCdProto : public IRCDProto
|
||||
|
||||
void SendChannel(Channel *c)
|
||||
{
|
||||
send_cmd("", "SJOIN %ld %s %s :", static_cast<long>(c->creation_time), c->name.c_str(), get_mlock_modes(c->ci, true).c_str());
|
||||
Anope::string modes = c->GetModes(true, true);
|
||||
if (modes.empty())
|
||||
modes = "+";
|
||||
send_cmd("", "SJOIN %ld %s %s :", static_cast<long>(c->creation_time), c->name.c_str(), modes.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -244,7 +244,10 @@ class InspIRCdTS6Proto : public IRCDProto
|
||||
|
||||
void SendChannel(Channel *c)
|
||||
{
|
||||
send_cmd(Config->Numeric, "FJOIN %s %ld %s :", c->name.c_str(), static_cast<long>(c->creation_time), get_mlock_modes(c->ci, true).c_str());
|
||||
Anope::string modes = c->GetModes(true, true);
|
||||
if (modes.empty())
|
||||
modes = "+";
|
||||
send_cmd(Config->Numeric, "FJOIN %s %ld %s :", c->name.c_str(), static_cast<long>(c->creation_time), modes.c_str());
|
||||
}
|
||||
|
||||
bool IsNickValid(const Anope::string &nick)
|
||||
|
||||
@@ -166,7 +166,8 @@ class PlexusProto : public IRCDProto
|
||||
|
||||
void SendClientIntroduction(const User *u, const Anope::string &modes)
|
||||
{
|
||||
EnforceQlinedNick(u->nick, "");
|
||||
XLine x(u->nick, "Reserved for services");
|
||||
ircdproto->SendSQLine(NULL, &x);
|
||||
send_cmd(Config->Numeric, "UID %s 1 %ld %s %s %s 255.255.255.255 %s 0 %s :%s", u->nick.c_str(), static_cast<long>(u->timestamp), modes.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->GetUID().c_str(), u->host.c_str(), u->realname.c_str());
|
||||
}
|
||||
|
||||
@@ -228,7 +229,10 @@ class PlexusProto : public IRCDProto
|
||||
|
||||
void SendChannel(Channel *c)
|
||||
{
|
||||
send_cmd(Config->Numeric, "SJOIN %ld %s %s :", static_cast<long>(c->creation_time), c->name.c_str(), get_mlock_modes(c->ci, true).c_str());
|
||||
Anope::string modes = c->GetModes(true, true);
|
||||
if (modes.empty())
|
||||
modes = "+";
|
||||
send_cmd(Config->Numeric, "SJOIN %ld %s %s :", static_cast<long>(c->creation_time), c->name.c_str(), modes.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -169,7 +169,8 @@ class RatboxProto : public IRCDProto
|
||||
|
||||
void SendClientIntroduction(const User *u, const Anope::string &modes)
|
||||
{
|
||||
EnforceQlinedNick(u->nick, "");
|
||||
XLine x(u->nick, "Reserved for services");
|
||||
ircdproto->SendSQLine(NULL, &x);
|
||||
send_cmd(Config->Numeric, "UID %s 1 %ld %s %s %s 0 %s :%s", u->nick.c_str(), static_cast<long>(u->timestamp), modes.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->GetUID().c_str(), u->realname.c_str());
|
||||
}
|
||||
|
||||
@@ -223,7 +224,10 @@ class RatboxProto : public IRCDProto
|
||||
|
||||
void SendChannel(Channel *c)
|
||||
{
|
||||
send_cmd("", "SJOIN %ld %s %s :", static_cast<long>(c->creation_time), c->name.c_str(), get_mlock_modes(c->ci, true).c_str());
|
||||
Anope::string modes = c->GetModes(true, true);
|
||||
if (modes.empty())
|
||||
modes = "+";
|
||||
send_cmd("", "SJOIN %ld %s %s :", static_cast<long>(c->creation_time), c->name.c_str(), modes.c_str());
|
||||
}
|
||||
|
||||
bool IsNickValid(const Anope::string &nick)
|
||||
|
||||
@@ -141,7 +141,8 @@ class UnrealIRCdProto : public IRCDProto
|
||||
|
||||
void SendClientIntroduction(const User *u, const Anope::string &modes)
|
||||
{
|
||||
EnforceQlinedNick(u->nick, Config->ServerName);
|
||||
XLine x(u->nick, "Reserved for services");
|
||||
ircdproto->SendSQLine(NULL, &x);
|
||||
send_cmd("", "& %s 1 %ld %s %s %s 0 %s %s * :%s", u->nick.c_str(), static_cast<long>(u->timestamp), u->GetIdent().c_str(), u->host.c_str(), Config->ServerName.c_str(), modes.c_str(), u->host.c_str(), u->realname.c_str());
|
||||
}
|
||||
|
||||
@@ -513,7 +514,7 @@ class Unreal32IRCdMessage : public IRCdMessage
|
||||
else if (params.size() == 11)
|
||||
{
|
||||
Anope::string decoded_ip;
|
||||
b64_decode(params[9], decoded_ip);
|
||||
Anope::B64Decode(params[9], decoded_ip);
|
||||
|
||||
sockaddrs ip;
|
||||
ip.ntop(params[9].length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str());
|
||||
|
||||
+1
-24
@@ -30,7 +30,7 @@ bool bad_password(User *u)
|
||||
u->invalid_pw_time = Anope::CurTime;
|
||||
if (u->invalid_pw_count >= Config->BadPassLimit)
|
||||
{
|
||||
kill_user("", u, "Too many invalid passwords");
|
||||
u->Kill(Config->ServerName, "Too many invalid passwords");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,29 +39,6 @@ bool bad_password(User *u)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Remove a user from the IRC network.
|
||||
* @param source is the nick which should generate the kill, or empty for a server-generated kill.
|
||||
* @param user to remove
|
||||
* @param reason for the kill
|
||||
* @return void
|
||||
*/
|
||||
void kill_user(const Anope::string &source, User *user, const Anope::string &reason)
|
||||
{
|
||||
if (!user)
|
||||
return;
|
||||
|
||||
Anope::string real_source = source.empty() ? Config->ServerName : source;
|
||||
|
||||
Anope::string buf = real_source + " (" + reason + ")";
|
||||
|
||||
ircdproto->SendSVSKill(findbot(source), user, "%s", buf.c_str());
|
||||
|
||||
if (!ircd->quitonkill)
|
||||
do_kill(user, buf);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Unban the user from a channel
|
||||
|
||||
+2
-2
@@ -77,7 +77,7 @@ static const char Pad64 = '=';
|
||||
characters followed by one "=" padding character.
|
||||
*/
|
||||
|
||||
void b64_encode(const Anope::string &src, Anope::string &target)
|
||||
void Anope::B64Encode(const Anope::string &src, Anope::string &target)
|
||||
{
|
||||
size_t src_pos = 0, src_len = src.length();
|
||||
unsigned char input[3];
|
||||
@@ -118,7 +118,7 @@ void b64_encode(const Anope::string &src, Anope::string &target)
|
||||
src from base - 64 numbers into three 8 bit bytes in the target area.
|
||||
*/
|
||||
|
||||
void b64_decode(const Anope::string &src, Anope::string &target)
|
||||
void Anope::B64Decode(const Anope::string &src, Anope::string &target)
|
||||
{
|
||||
target.clear();
|
||||
|
||||
|
||||
@@ -1168,23 +1168,6 @@ void chan_set_correct_modes(User *user, Channel *c, int give_modes)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/** Set modes on every channel
|
||||
* This overrides mlock on channels
|
||||
* @param bi The bot to send the modes from
|
||||
* @param modes The modes
|
||||
*/
|
||||
void MassChannelModes(BotInfo *bi, const Anope::string &modes)
|
||||
{
|
||||
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
|
||||
{
|
||||
Channel *c = it->second;
|
||||
|
||||
if (c->bouncy_modes)
|
||||
return;
|
||||
c->SetModes(bi, false, "%s", modes.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static const Anope::string EntryFlagString[] = { "ENTRYTYPE_NONE", "ENTRYTYPE_CIDR", "ENTRYTYPE_NICK_WILD", "ENTRYTYPE_NICK", "ENTRYTYPE_USER_WILD", "ENTRYTYPE_USER", "ENTRYTYPE_HOST_WILD", "ENTRYTYPE_HOST", "" };
|
||||
|
||||
/** Constructor
|
||||
|
||||
@@ -106,41 +106,6 @@ int levelinfo_maxwidth = 0;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Returns modes for mlock in a nice way. */
|
||||
|
||||
Anope::string get_mlock_modes(ChannelInfo *ci, int complete)
|
||||
{
|
||||
if (!ci)
|
||||
return "";
|
||||
|
||||
Anope::string pos = "+", neg = "-", params;
|
||||
|
||||
for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
|
||||
{
|
||||
const ModeLock &ml = it->second;
|
||||
ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
|
||||
if (!cm || cm->Type == MODE_LIST || cm->Type == MODE_STATUS)
|
||||
continue;
|
||||
|
||||
if (ml.set)
|
||||
pos += cm->ModeChar;
|
||||
else
|
||||
neg += cm->ModeChar;
|
||||
|
||||
if (complete && !ml.param.empty() && cm->Type == MODE_PARAM)
|
||||
params += " " + ml.param;
|
||||
}
|
||||
|
||||
if (pos.length() == 1)
|
||||
pos.clear();
|
||||
if (neg.length() == 1)
|
||||
neg.clear();
|
||||
|
||||
return pos + neg + params;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Check the current modes on a channel; if they conflict with a mode lock,
|
||||
* fix them.
|
||||
*/
|
||||
|
||||
@@ -209,10 +209,6 @@ static void write_pidfile()
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Overall initialization routines. Return 0 on success, -1 on failure. */
|
||||
|
||||
int openlog_failed = 0, openlog_errno = 0;
|
||||
|
||||
void Init(int ac, char **av)
|
||||
{
|
||||
int started_from_term = isatty(0) && isatty(1) && isatty(2);
|
||||
|
||||
+2
-2
@@ -205,7 +205,7 @@ static void services_shutdown()
|
||||
FOREACH_MOD(I_OnShutdown, OnShutdown());
|
||||
ModuleManager::UnloadAll();
|
||||
/* just in case they weren't all removed at least run once */
|
||||
ModuleRunTimeDirCleanUp();
|
||||
ModuleManager::CleanupRuntimeDirectory();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
@@ -402,7 +402,7 @@ int main(int ac, char **av, char **envp)
|
||||
#endif
|
||||
|
||||
/* Clean out the module runtime directory prior to running, just in case files were left behind during a previous run */
|
||||
ModuleRunTimeDirCleanUp();
|
||||
ModuleManager::CleanupRuntimeDirectory();
|
||||
|
||||
/* General initialization first */
|
||||
Init(ac, av);
|
||||
|
||||
@@ -454,28 +454,6 @@ Anope::string myStrGetTokenRemainder(const Anope::string &str, const char dilim,
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Kill the user to enforce the sqline
|
||||
* @param nick to kill
|
||||
* @param killer whom is doing the killing
|
||||
* @return void
|
||||
*/
|
||||
void EnforceQlinedNick(const Anope::string &nick, const Anope::string &killer)
|
||||
{
|
||||
if (findbot(nick))
|
||||
return;
|
||||
|
||||
User *u2 = finduser(nick);
|
||||
|
||||
if (u2)
|
||||
{
|
||||
Log(LOG_NORMAL, "xline") << "Killed Q-lined nick: " << u2->GetMask();
|
||||
kill_user(killer, u2, "This nick is reserved for Services. Please use a non Q-Lined nick.");
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Is the given nick a network service
|
||||
* @param nick to check
|
||||
@@ -691,26 +669,6 @@ std::vector<Anope::string> BuildStringVector(const Anope::string &src, char deli
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Change an unsigned string to a signed string, overwriting the original
|
||||
* string.
|
||||
* @param input string
|
||||
* @return output string, same as input string.
|
||||
*/
|
||||
|
||||
char *str_signed(unsigned char *str)
|
||||
{
|
||||
char *nstr = reinterpret_cast<char *>(str);
|
||||
while (*str)
|
||||
{
|
||||
*nstr = static_cast<char>(*str);
|
||||
++str;
|
||||
++nstr;
|
||||
}
|
||||
|
||||
return nstr;
|
||||
}
|
||||
|
||||
bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case_sensitive)
|
||||
{
|
||||
size_t s = 0, m = 0, str_len = str.length(), mask_len = mask.length();
|
||||
|
||||
+86
-6
@@ -12,6 +12,60 @@
|
||||
std::map<Anope::string, Service *> ModuleManager::ServiceProviders;
|
||||
std::vector<Module *> ModuleManager::EventHandlers[I_END];
|
||||
|
||||
void ModuleManager::CleanupRuntimeDirectory()
|
||||
{
|
||||
Anope::string dirbuf = services_dir + "/modules/runtime";
|
||||
|
||||
Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment please wait";
|
||||
|
||||
#ifndef _WIN32
|
||||
DIR *dirp = opendir(dirbuf.c_str());
|
||||
if (!dirp)
|
||||
{
|
||||
Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
|
||||
return;
|
||||
}
|
||||
struct dirent *dp;
|
||||
while ((dp = readdir(dirp)))
|
||||
{
|
||||
if (!dp->d_ino)
|
||||
continue;
|
||||
if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs(".."))
|
||||
continue;
|
||||
Anope::string filebuf = dirbuf + "/" + dp->d_name;
|
||||
DeleteFile(filebuf.c_str());
|
||||
}
|
||||
closedir(dirp);
|
||||
#else
|
||||
Anope::string szDir = dirbuf + "/*";
|
||||
|
||||
WIN32_FIND_DATA FileData;
|
||||
HANDLE hList = FindFirstFile(szDir.c_str(), &FileData);
|
||||
if (hList != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
bool fFinished = false;
|
||||
while (!fFinished)
|
||||
{
|
||||
if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
Anope::string filebuf = dirbuf + "/" + FileData.cFileName;
|
||||
if (!DeleteFile(filebuf.c_str()))
|
||||
Log(LOG_DEBUG) << "Error deleting file " << filebuf << " - GetLastError() reports " << Anope::LastError();
|
||||
}
|
||||
if (!FindNextFile(hList, &FileData))
|
||||
{
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
fFinished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Log(LOG_DEBUG) << "Invalid File Handle. GetLastError() reports "<< static_cast<int>(GetLastError());
|
||||
|
||||
FindClose(hList);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ModuleManager::LoadModuleList(std::list<Anope::string> &ModuleList)
|
||||
{
|
||||
for (std::list<Anope::string>::iterator it = ModuleList.begin(), it_end = ModuleList.end(); it != it_end; ++it)
|
||||
@@ -215,6 +269,35 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u)
|
||||
return MOD_ERR_OK;
|
||||
}
|
||||
|
||||
void ModuleManager::RequireVersion(int major, int minor, int patch, int build)
|
||||
{
|
||||
if (Anope::VersionMajor() > major)
|
||||
return;
|
||||
else if (Anope::VersionMajor() == major)
|
||||
{
|
||||
if (minor == -1)
|
||||
return;
|
||||
else if (Anope::VersionMinor() > minor)
|
||||
return;
|
||||
else if (Anope::VersionMinor() == minor)
|
||||
{
|
||||
if (patch == -1)
|
||||
return;
|
||||
else if (Anope::VersionPatch() > patch)
|
||||
return;
|
||||
else if (Anope::VersionPatch() == patch)
|
||||
{
|
||||
if (build == -1)
|
||||
return;
|
||||
else if (Anope::VersionBuild() >= build)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw ModuleException("This module requires version " + stringify(major) + "." + stringify(minor) + "." + stringify(patch) + "-" + build + " - this is " + Anope::Version());
|
||||
}
|
||||
|
||||
void ModuleManager::DeleteModule(Module *m)
|
||||
{
|
||||
if (!m || !m->handle)
|
||||
@@ -226,7 +309,7 @@ void ModuleManager::DeleteModule(Module *m)
|
||||
ano_modclearerr();
|
||||
void (*destroy_func)(Module *m) = function_cast<void (*)(Module *)>(dlsym(m->handle, "AnopeFini"));
|
||||
const char *err = ano_moderr();
|
||||
if (!destroy_func && err && *err)
|
||||
if (!destroy_func || err)
|
||||
{
|
||||
Log() << "No destroy function found for " << m->name << ", chancing delete...";
|
||||
delete m; /* we just have to chance they haven't overwrote the delete operator then... */
|
||||
@@ -234,11 +317,8 @@ void ModuleManager::DeleteModule(Module *m)
|
||||
else
|
||||
destroy_func(m); /* Let the module delete it self, just in case */
|
||||
|
||||
if (handle)
|
||||
{
|
||||
if (dlclose(handle))
|
||||
Log() << ano_moderr();
|
||||
}
|
||||
if (dlclose(handle))
|
||||
Log() << ano_moderr();
|
||||
|
||||
if (!filename.empty())
|
||||
DeleteFile(filename.c_str());
|
||||
|
||||
-100
@@ -179,106 +179,6 @@ int Module::DelCommand(BotInfo *bi, Command *c)
|
||||
return MOD_ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Module Callback Functions
|
||||
*******************************************************************************/
|
||||
|
||||
/* Check the current version of anope against a given version number
|
||||
* Specifiying -1 for minor,patch or build
|
||||
* @param major The major version of anope, the first part of the verison number
|
||||
* @param minor The minor version of anope, the second part of the version number
|
||||
* @param patch The patch version of anope, the third part of the version number
|
||||
* @param build The build revision of anope from SVN
|
||||
* @return True if the version newer than the version specified.
|
||||
**/
|
||||
bool moduleMinVersion(int major, int minor, int patch, int build)
|
||||
{
|
||||
bool ret = false;
|
||||
if (Anope::VersionMajor() > major) /* Def. new */
|
||||
ret = true;
|
||||
else if (Anope::VersionMajor() == major) /* Might be newer */
|
||||
{
|
||||
if (minor == -1)
|
||||
return true; /* They dont care about minor */
|
||||
if (Anope::VersionMinor() > minor) /* Def. newer */
|
||||
ret = true;
|
||||
else if (Anope::VersionMinor() == minor) /* Might be newer */
|
||||
{
|
||||
if (patch == -1)
|
||||
return true; /* They dont care about patch */
|
||||
if (Anope::VersionPatch() > patch)
|
||||
ret = true;
|
||||
else if (Anope::VersionPatch() == patch)
|
||||
{
|
||||
#if 0
|
||||
// XXX
|
||||
if (build == -1)
|
||||
return true; /* They dont care about build */
|
||||
if (Anope::VersionBuild >= build)
|
||||
ret = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ModuleRunTimeDirCleanUp()
|
||||
{
|
||||
Anope::string dirbuf = services_dir + "/modules/runtime";
|
||||
|
||||
Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment please wait";
|
||||
|
||||
#ifndef _WIN32
|
||||
DIR *dirp = opendir(dirbuf.c_str());
|
||||
if (!dirp)
|
||||
{
|
||||
Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
|
||||
return;
|
||||
}
|
||||
struct dirent *dp;
|
||||
while ((dp = readdir(dirp)))
|
||||
{
|
||||
if (!dp->d_ino)
|
||||
continue;
|
||||
if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs(".."))
|
||||
continue;
|
||||
Anope::string filebuf = dirbuf + "/" + dp->d_name;
|
||||
DeleteFile(filebuf.c_str());
|
||||
}
|
||||
closedir(dirp);
|
||||
#else
|
||||
Anope::string szDir = dirbuf + "/*";
|
||||
|
||||
WIN32_FIND_DATA FileData;
|
||||
HANDLE hList = FindFirstFile(szDir.c_str(), &FileData);
|
||||
if (hList != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
bool fFinished = false;
|
||||
while (!fFinished)
|
||||
{
|
||||
if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
Anope::string filebuf = dirbuf + "/" + FileData.cFileName;
|
||||
if (!DeleteFile(filebuf.c_str()))
|
||||
Log(LOG_DEBUG) << "Error deleting file " << filebuf << " - GetLastError() reports " << Anope::LastError();
|
||||
}
|
||||
if (!FindNextFile(hList, &FileData))
|
||||
{
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
fFinished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Log(LOG_DEBUG) << "Invalid File Handle. GetLastError() reports "<< static_cast<int>(GetLastError());
|
||||
|
||||
FindClose(hList);
|
||||
#endif
|
||||
Log(LOG_DEBUG) << "Module run time directory has been cleaned out";
|
||||
}
|
||||
|
||||
void Module::SendMessage(CommandSource &source, const char *fmt, ...)
|
||||
{
|
||||
Anope::string language = (source.u && source.u->Account() ? source.u->Account()->language : "");
|
||||
|
||||
+7
-7
@@ -374,7 +374,7 @@ void SGLineManager::Del(XLine *x)
|
||||
void SGLineManager::OnMatch(User *u, XLine *x)
|
||||
{
|
||||
if (u)
|
||||
kill_user(Config->s_OperServ, u, x->Reason);
|
||||
u->Kill(Config->s_OperServ, x->Reason);
|
||||
ircdproto->SendAkill(u, x);
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ XLine *SNLineManager::Add(const Anope::string &mask, const Anope::string &creato
|
||||
++it;
|
||||
|
||||
if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->realname, x->Mask))
|
||||
kill_user(Config->ServerName, user, rreason);
|
||||
user->Kill(Config->ServerName, rreason);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ void SNLineManager::OnMatch(User *u, XLine *x)
|
||||
if (u)
|
||||
{
|
||||
Anope::string reason = "G-Lined: " + x->Reason;
|
||||
kill_user(Config->s_OperServ, u, reason);
|
||||
u->Kill(Config->s_OperServ, reason);
|
||||
}
|
||||
this->Send(u, x);
|
||||
}
|
||||
@@ -516,7 +516,7 @@ XLine *SQLineManager::Add(const Anope::string &mask, const Anope::string &creato
|
||||
++it;
|
||||
|
||||
if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->nick, x->Mask))
|
||||
kill_user(Config->ServerName, user, rreason);
|
||||
user->Kill(Config->ServerName, rreason);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -537,10 +537,10 @@ void SQLineManager::OnMatch(User *u, XLine *x)
|
||||
if (u)
|
||||
{
|
||||
Anope::string reason = "Q-Lined: " + x->Reason;
|
||||
kill_user(Config->s_OperServ, u, reason);
|
||||
u->Kill(Config->s_OperServ, reason);
|
||||
}
|
||||
|
||||
ircdproto->SendSQLine(u, x);
|
||||
this->Send(u, x);
|
||||
}
|
||||
|
||||
void SQLineManager::OnExpire(XLine *x)
|
||||
@@ -600,7 +600,7 @@ void SZLineManager::OnMatch(User *u, XLine *x)
|
||||
if (u)
|
||||
{
|
||||
Anope::string reason = "Z-Lined: " + x->Reason;
|
||||
kill_user(Config->s_OperServ, u, reason);
|
||||
u->Kill(Config->s_OperServ, reason);
|
||||
}
|
||||
|
||||
ircdproto->SendSZLine(u, x);
|
||||
|
||||
@@ -736,6 +736,34 @@ ModeLock *ChannelInfo::GetMLock(ChannelModeName mname, const Anope::string ¶
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Anope::string ChannelInfo::GetMLockAsString(bool complete) const
|
||||
{
|
||||
Anope::string pos = "+", neg = "-", params;
|
||||
|
||||
for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = this->GetMLock().begin(), it_end = this->GetMLock().end(); it != it_end; ++it)
|
||||
{
|
||||
const ModeLock &ml = it->second;
|
||||
ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
|
||||
if (!cm || cm->Type == MODE_LIST || cm->Type == MODE_STATUS)
|
||||
continue;
|
||||
|
||||
if (ml.set)
|
||||
pos += cm->ModeChar;
|
||||
else
|
||||
neg += cm->ModeChar;
|
||||
|
||||
if (complete && !ml.param.empty() && cm->Type == MODE_PARAM)
|
||||
params += " " + ml.param;
|
||||
}
|
||||
|
||||
if (pos.length() == 1)
|
||||
pos.clear();
|
||||
if (neg.length() == 1)
|
||||
neg.clear();
|
||||
|
||||
return pos + neg + params;
|
||||
}
|
||||
|
||||
/** Check whether a user is permitted to be on this channel
|
||||
* @param u The user
|
||||
* @return true if they were banned, false if they are allowed
|
||||
|
||||
+13
-20
@@ -261,7 +261,7 @@ void User::SendMessage(BotInfo *source, Anope::string msg)
|
||||
* back to call do_nick. do_nick changes the nick of the use to the new one, then calls NickAlias::OnCancel
|
||||
* with the users old nick's nickalias (if there is one).
|
||||
*
|
||||
* 2. Calls kill_user, which will either delete the user immediatly or kill them, wait for the QUIT,
|
||||
* 2. Calls User::Kill, which will either delete the user immediatly or kill them, wait for the QUIT,
|
||||
* then delete the user then. Users destructor then calls NickAlias::OnCancel
|
||||
*
|
||||
* NickAlias::OnCancel checks for NS_COLLIDED, it then does one of two things.
|
||||
@@ -324,7 +324,7 @@ void User::Collide(NickAlias *na)
|
||||
ircdproto->SendForceNickChange(this, guestnick, Anope::CurTime);
|
||||
}
|
||||
else
|
||||
kill_user(Config->s_NickServ, this, "Services nickname-enforcer kill");
|
||||
this->Kill(Config->s_NickServ, "Services nickname-enforcer kill");
|
||||
}
|
||||
|
||||
/** Identify the user to the Nick
|
||||
@@ -711,6 +711,17 @@ bool User::IsProtected() const
|
||||
return false;
|
||||
}
|
||||
|
||||
void User::Kill(const Anope::string &source, const Anope::string &reason)
|
||||
{
|
||||
Anope::string real_source = source.empty() ? Config->ServerName : source;
|
||||
Anope::string real_reason = real_source + " (" + reason + ")";
|
||||
|
||||
ircdproto->SendSVSKill(findbot(source), this, "%s", real_reason.c_str());
|
||||
|
||||
if (!ircd->quitonkill)
|
||||
do_kill(this, real_reason);
|
||||
}
|
||||
|
||||
User *finduser(const Anope::string &nick)
|
||||
{
|
||||
if (isdigit(nick[0]) && ircd->ts6)
|
||||
@@ -902,24 +913,6 @@ bool matches_list(Channel *c, User *user, ChannelModeName mode)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Is the given MASK ban-excepted? */
|
||||
bool is_excepted_mask(ChannelInfo *ci, const Anope::string &mask)
|
||||
{
|
||||
if (!ci->c || !ModeManager::FindChannelModeByName(CMODE_EXCEPT))
|
||||
return false;
|
||||
|
||||
std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> modes = ci->c->GetModeList(CMODE_EXCEPT);
|
||||
for (; modes.first != modes.second; ++modes.first)
|
||||
{
|
||||
if (Anope::Match(modes.first->second, mask))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Given a user, return a mask that will most likely match any address the
|
||||
* user will have from that location. For IP addresses, wildcards the
|
||||
* appropriate subnet mask (e.g. 35.1.1.1 -> 35.*; 128.2.1.1 -> 128.2.*);
|
||||
|
||||
Reference in New Issue
Block a user