diff options
| author | Adam <Adam@anope.org> | 2010-12-06 17:06:57 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2010-12-12 19:37:03 -0500 |
| commit | aed53dbb47822a79eb9a6b61095ad04ec3d67818 (patch) | |
| tree | 72d3210b5609ea2163854d14ec7fb2f48d8b4d12 /src | |
| parent | a507816701d136a1c22d2f6779d811840d61577c (diff) | |
Cleaned up some things, made the protocol modules use some basic inheritance to cut back on their code duplication. More work can be done in the future to remove even more of it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/actions.cpp | 29 | ||||
| -rw-r--r-- | src/botserv.cpp | 59 | ||||
| -rw-r--r-- | src/command.cpp | 6 | ||||
| -rw-r--r-- | src/commands.cpp | 2 | ||||
| -rw-r--r-- | src/ircd.cpp | 34 | ||||
| -rw-r--r-- | src/messages.cpp | 316 | ||||
| -rw-r--r-- | src/misc.cpp | 64 | ||||
| -rw-r--r-- | src/modes.cpp | 4 | ||||
| -rw-r--r-- | src/operserv.cpp | 14 | ||||
| -rw-r--r-- | src/process.cpp | 2 | ||||
| -rw-r--r-- | src/protocol.cpp | 329 | ||||
| -rw-r--r-- | src/regchannel.cpp | 2 | ||||
| -rw-r--r-- | src/servers.cpp | 61 | ||||
| -rw-r--r-- | src/sessions.cpp | 29 | ||||
| -rw-r--r-- | src/users.cpp | 70 |
15 files changed, 487 insertions, 534 deletions
diff --git a/src/actions.cpp b/src/actions.cpp index 6b3a96a24..b583cafae 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -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->nick, "Too many invalid passwords"); + kill_user("", u, "Too many invalid passwords"); return true; } @@ -41,48 +41,41 @@ bool bad_password(User *u) /** * Remove a user from the IRC network. - * @param source is the nick which should generate the kill, or NULL for a server-generated kill. + * @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, const Anope::string &user, const Anope::string &reason) +void kill_user(const Anope::string &source, User *user, const Anope::string &reason) { - if (user.empty()) + if (!user) return; Anope::string real_source = source.empty() ? Config->ServerName : source; Anope::string buf = real_source + " (" + reason + ")"; - ircdproto->SendSVSKill(findbot(source), finduser(user), "%s", buf.c_str()); + ircdproto->SendSVSKill(findbot(source), user, "%s", buf.c_str()); - if (!ircd->quitonkill && finduser(user)) + if (!ircd->quitonkill) do_kill(user, buf); } /*************************************************************************/ /** - * Unban the nick from a channel + * Unban the user from a channel * @param ci channel info for the channel - * @param nick to remove the ban for + * @param u The user to unban * @return void */ -void common_unban(ChannelInfo *ci, const Anope::string &nick) +void common_unban(ChannelInfo *ci, User *u) { - if (!ci || !ci->c || nick.empty()) - return; - - User *u = finduser(nick); - if (!u) - return; - - if (!ci->c->HasMode(CMODE_BAN)) + if (!u || !ci || !ci->c || !ci->c->HasMode(CMODE_BAN)) return; if (ircd->svsmode_unban) - ircdproto->SendBanDel(ci->c, nick); + ircdproto->SendBanDel(ci->c, u->nick); else { std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = ci->c->GetModeList(CMODE_BAN); diff --git a/src/botserv.cpp b/src/botserv.cpp index 32b6a42a3..ddd8dc15f 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -504,13 +504,14 @@ static void bot_kick(ChannelInfo *ci, User *u, LanguageString message, ...) /*************************************************************************/ -/* Makes a simple ban and kicks the target */ - -void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason) +/* Makes a simple ban and kicks the target + * @param requester The user requesting the kickban + * @param ci The channel + * @param u The user being kicked + * @param reason The reason + */ +void bot_raw_ban(User *requester, ChannelInfo *ci, User *u, const Anope::string &reason) { - Anope::string mask; - User *u = finduser(nick); - if (!u || !ci) return; @@ -522,7 +523,7 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, co ChanAccess *u_access = ci->GetAccess(u), *req_access = ci->GetAccess(requester); int16 u_level = u_access ? u_access->level : 0, req_level = req_access ? req_access->level : 0; - if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && u_level >= req_level) + if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(u->nick) && u_level >= req_level) return; if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted(ci, u) == 1) @@ -531,6 +532,7 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, co return; } + Anope::string mask; get_idealban(ci, u, mask); ci->c->SetMode(NULL, CMODE_BAN, mask); @@ -544,12 +546,14 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, co /*************************************************************************/ -/* Makes a kick with a "dynamic" reason ;) */ - -void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason) +/* Makes a kick with a "dynamic" reason ;) + * @param requester The user requesting the kick + * @param ci The channel + * @param u The user being kicked + * @param reason The reason for the kick + */ +void bot_raw_kick(User *requester, ChannelInfo *ci, User *u, const Anope::string &reason) { - User *u = finduser(nick); - if (!u || !ci || !ci->c || !ci->c->FindUser(u)) return; @@ -561,7 +565,7 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, c ChanAccess *u_access = ci->GetAccess(u), *req_access = ci->GetAccess(requester); int16 u_level = u_access ? u_access->level : 0, req_level = req_access ? req_access->level : 0; - if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && u_level >= req_level) + if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(u->nick) && u_level >= req_level) return; if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(requester, ci, CA_SIGNKICK))) @@ -572,35 +576,6 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, c /*************************************************************************/ -/* Makes a mode operation on a channel for a nick */ - -void bot_raw_mode(User *requester, ChannelInfo *ci, const Anope::string &mode, const Anope::string &nick) -{ - char buf[BUFSIZE] = ""; - User *u; - - u = finduser(nick); - - if (!u || !ci || !ci->c || !ci->c->FindUser(u)) - return; - - snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(Anope::CurTime)); - - if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && mode[0] == '-' && requester != u) - { - ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester, ACCESS_DENIED).c_str()); - return; - } - - ChanAccess *u_access = ci->GetAccess(u), *req_access = ci->GetAccess(requester); - int16 u_level = u_access ? u_access->level : 0, req_level = req_access ? req_access->level : 0; - if (mode[0] == '-' && ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && u_level >= req_level) - return; - - ci->c->SetModes(NULL, "%s %s", mode.c_str(), nick.c_str()); -} - -/*************************************************************************/ /** * Normalize buffer stripping control characters and colors * @param A string to be parsed for control and color codes diff --git a/src/command.cpp b/src/command.cpp index f7edbfaa2..290f74d1f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -16,7 +16,7 @@ CommandSource::~CommandSource() // Send to the user if the reply is more than one line if (!this->fantasy || !this->ci || this->reply.size() > 1) - u->SendMessage(this->service->nick, message); + u->SendMessage(this->service, message); else if (this->ci->botflags.HasFlag(BS_MSG_PRIVMSG)) ircdproto->SendPrivmsg(this->service, this->ci->name, message.c_str()); else if (this->ci->botflags.HasFlag(BS_MSG_NOTICE)) @@ -24,7 +24,7 @@ CommandSource::~CommandSource() else if (this->ci->botflags.HasFlag(BS_MSG_NOTICEOPS)) ircdproto->SendNoticeChanops(this->service, this->ci->c, message.c_str()); else - u->SendMessage(this->service->nick, message); + u->SendMessage(this->service, message); } } @@ -60,7 +60,7 @@ void CommandSource::Reply(const char *message, ...) va_start(args, message); vsnprintf(buf, BUFSIZE - 1, message, args); - this->reply.push_back(message); + this->reply.push_back(buf); va_end(args); } diff --git a/src/commands.cpp b/src/commands.cpp index e9671f3bd..6c5c556e5 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -187,7 +187,7 @@ void mod_help_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &cm u->SendMessage(bi, NO_HELP_AVAILABLE, cmd.c_str()); else { - u->SendMessage(bi->nick, " "); + u->SendMessage(bi, " "); /* Inform the user what permission is required to use the command */ if (!c->permission.empty()) diff --git a/src/ircd.cpp b/src/ircd.cpp deleted file mode 100644 index edab02be4..000000000 --- a/src/ircd.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Main ircd functions. - * - * (C) 2003-2010 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - */ - -#include "services.h" -#include "extern.h" - -IRCDProto *ircdproto; - -/** - * Globals we want from the protocol file - **/ -IRCDVar *ircd; - -void pmodule_ircd_proto(IRCDProto *proto) -{ - ircdproto = proto; -} - -/** - * Set routines for modules to set the prefered function for dealing with things. - **/ -void pmodule_ircd_var(IRCDVar *ircdvar) -{ - ircd = ircdvar; -} - diff --git a/src/messages.cpp b/src/messages.cpp index 945414f05..0f3e7f1a1 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -12,207 +12,7 @@ #include "services.h" #include "modules.h" -/*************************************************************************/ - -int m_nickcoll(const Anope::string &user) -{ - introduce_user(user); - return MOD_CONT; -} - -/*************************************************************************/ - -int m_away(const Anope::string &source, const Anope::string &msg) -{ - User *u = finduser(source); - - if (u && msg.empty()) /* un-away */ - check_memos(u); - return MOD_CONT; -} - -/*************************************************************************/ - -int m_kill(const Anope::string &nick, const Anope::string &msg) -{ - BotInfo *bi; - - /* Recover if someone kills us. */ - if (!Config->s_BotServ.empty() && (bi = findbot(nick))) - { - introduce_user(nick); - bi->RejoinAll(); - } - else - do_kill(nick, msg); - - return MOD_CONT; -} - -/*************************************************************************/ - -bool m_time(const Anope::string &source, const std::vector<Anope::string> &) -{ - if (source.empty()) - return MOD_CONT; - - time_t t; - time(&t); - 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); - return MOD_CONT; -} - -/*************************************************************************/ - -int m_motd(const Anope::string &source) -{ - if (source.empty()) - return MOD_CONT; - - 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()); - char buf[BUFSIZE]; - while (fgets(buf, sizeof(buf), f)) - { - buf[strlen(buf) - 1] = 0; - ircdproto->SendNumeric(Config->ServerName, 372, source, ":- %s", buf); - } - fclose(f); - ircdproto->SendNumeric(Config->ServerName, 376, source, ":End of /MOTD command."); - } - else - ircdproto->SendNumeric(Config->ServerName, 422, source, ":- MOTD file not found! Please contact your IRC administrator."); - return MOD_CONT; -} - -/*************************************************************************/ - -int m_privmsg(const Anope::string &source, const Anope::string &receiver, const Anope::string &message) -{ - if (source.empty() || receiver.empty() || message.empty()) - return MOD_CONT; - - User *u = finduser(source); - - if (!u) - { - Log() << message << ": user record for " << source << " not found"; - - BotInfo *bi = findbot(receiver); - if (bi) - ircdproto->SendMessage(bi, source, "%s", GetString(USER_RECORD_NOT_FOUND).c_str()); - - return MOD_CONT; - } - - if (receiver[0] == '#' && !Config->s_BotServ.empty()) - { - ChannelInfo *ci = cs_findchan(receiver); - if (ci) - { - /* Some paranoia checks */ - if (!ci->HasFlag(CI_FORBIDDEN) && ci->c && ci->bi) - botchanmsgs(u, ci, message); - } - } - else - { - /* Check if we should ignore. Operators always get through. */ - if (allow_ignore && !is_oper(u)) - { - if (get_ignore(source)) - { - Anope::string target = myStrGetToken(message, ' ', 0); - BotInfo *bi = findbot(target); - if (bi) - Log(bi) << "Ignored message from " << source << " using command " << target; - return MOD_CONT; - } - } - - /* If a server is specified (nick@server format), make sure it matches - * us, and strip it off. */ - Anope::string botname = receiver; - size_t s = receiver.find('@'); - if (s != Anope::string::npos) - { - Anope::string servername(receiver.begin() + s + 1, receiver.end()); - botname = botname.substr(0, s); - if (!servername.equals_ci(Config->ServerName)) - return MOD_CONT; - } - else if (Config->UseStrictPrivMsg) - { - BotInfo *bi = findbot(receiver); - if (!bi) - return MOD_CONT; - Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source; - u->SendMessage(bi, INVALID_TARGET, receiver.c_str(), receiver.c_str(), Config->ServerName.c_str(), receiver.c_str()); - return MOD_CONT; - } - - BotInfo *bi = findbot(botname); - - if (bi) - { - if (message[0] == '\1' && message[message.length() - 1] == '\1') - { - if (message.substr(0, 6).equals_ci("\1PING ")) - { - Anope::string buf = message; - buf.erase(buf.begin()); - buf.erase(buf.end() - 1); - ircdproto->SendCTCP(bi, u->nick, "%s", buf.c_str()); - } - else if (message.substr(0, 9).equals_ci("\1VERSION\1")) - { - ircdproto->SendCTCP(bi, u->nick, "VERSION Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, Config->EncModuleList.begin()->c_str(), Anope::Build().c_str()); - } - } - if (bi == NickServ || bi == MemoServ || bi == BotServ) - mod_run_cmd(bi, u, message, false); - else if (bi == ChanServ) - { - if (!is_oper(u) && Config->CSOpersOnly) - u->SendMessage(ChanServ, ACCESS_DENIED); - else - mod_run_cmd(bi, u, message, false); - } - else if (bi == HostServ) - { - if (!ircd->vhost) - u->SendMessage(HostServ, SERVICE_OFFLINE, Config->s_HostServ.c_str()); - else - mod_run_cmd(bi, u, message, false); - } - else if (bi == OperServ) - { - if (!is_oper(u) && Config->OSOpersOnly) - { - u->SendMessage(OperServ, ACCESS_DENIED); - if (Config->WallBadOS) - ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config->s_OperServ.c_str(), u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str()); - } - else - { - Log(OperServ) << u->nick << ": " << message; - mod_run_cmd(bi, u, message, false); - } - } - } - } - - return MOD_CONT; -} - -/*************************************************************************/ - -bool m_stats(const Anope::string &source, const std::vector<Anope::string> ¶ms) +bool OnStats(const Anope::string &source, const std::vector<Anope::string> ¶ms) { if (params.size() < 1) return true; @@ -222,7 +22,7 @@ bool m_stats(const Anope::string &source, const std::vector<Anope::string> ¶ switch (params[0][0]) { case 'l': - if (u && is_oper(u)) + 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", uplink_server->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - start_time)); @@ -233,7 +33,7 @@ bool m_stats(const Anope::string &source, const std::vector<Anope::string> ¶ case 'o': case 'O': /* Check whether the user is an operator */ - if (u && !is_oper(u) && Config->HideStatsO) + if (u && !u->HasMode(UMODE_OPER) && Config->HideStatsO) ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); else { @@ -269,45 +69,103 @@ bool m_stats(const Anope::string &source, const std::vector<Anope::string> ¶ return true; } -bool m_version(const Anope::string &source, const std::vector<Anope::string> &) +bool OnTime(const Anope::string &source, const std::vector<Anope::string> &) +{ + if (source.empty()) + return true; + + time_t t; + time(&t); + 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); + return true; +} + +bool OnVersion(const Anope::string &source, const std::vector<Anope::string> &) { if (!source.empty()) ircdproto->SendNumeric(Config->ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, Config->EncModuleList.begin()->c_str(), Anope::Build().c_str()); - return MOD_CONT; + return true; } -/*************************************************************************/ - -int m_whois(const Anope::string &source, const Anope::string &who) +/* XXX We should cache the file somewhere not open/read/close it on every request */ +bool OnMotd(const Anope::string &source, const std::vector<Anope::string> &) { - if (!source.empty() && !who.empty()) + if (source.empty()) + return true; + + FILE *f = fopen(Config->MOTDFilename.c_str(), "r"); + if (f) { - User *u; - BotInfo *bi = findbot(who); - if (bi) - { - ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); - ircdproto->SendNumeric(Config->ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str()); - ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str()); - 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.", who.c_str()); - } - else if (!ircd->svshold && (u = finduser(who)) && u->server == Me) + ircdproto->SendNumeric(Config->ServerName, 375, source, ":- %s Message of the Day", Config->ServerName.c_str()); + char buf[BUFSIZE]; + while (fgets(buf, sizeof(buf), f)) { - 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(Config->ServerName, 312, source, "%s %s :%s", u->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str()); - ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", u->nick.c_str()); + buf[strlen(buf) - 1] = 0; + ircdproto->SendNumeric(Config->ServerName, 372, source, ":- %s", buf); } - else - ircdproto->SendNumeric(Config->ServerName, 401, source, "%s :No such service.", who.c_str()); + fclose(f); + ircdproto->SendNumeric(Config->ServerName, 376, source, ":End of /MOTD command."); } - return MOD_CONT; + else + ircdproto->SendNumeric(Config->ServerName, 422, source, ":- MOTD file not found! Please contact your IRC administrator."); + + return true; } +#define ProtocolFunc(x) \ + inline bool x(const Anope::string &source, const std::vector<Anope::string> ¶ms) \ + { \ + return ircdmessage->x(source, params); \ + } + +ProtocolFunc(On436) +ProtocolFunc(OnAway) +ProtocolFunc(OnJoin) +ProtocolFunc(OnKick) +ProtocolFunc(OnKill) +ProtocolFunc(OnMode) +ProtocolFunc(OnNick) +ProtocolFunc(OnUID) +ProtocolFunc(OnPart) +ProtocolFunc(OnPing) +ProtocolFunc(OnPrivmsg) +ProtocolFunc(OnQuit) +ProtocolFunc(OnServer) +ProtocolFunc(OnSQuit) +ProtocolFunc(OnTopic) +ProtocolFunc(OnWhois) +ProtocolFunc(OnCapab) +ProtocolFunc(OnSJoin) +ProtocolFunc(OnError) + void init_core_messages() { - static Message message_stats("STATS", m_stats); - static Message message_time("TIME", m_time); - static Message message_verssion("VERSION", m_version); + static Message message_stats("STATS", OnStats); + static Message message_time("TIME", OnTime); + static Message message_verssion("VERSION", OnVersion); + static Message message_motd("MOTD", OnMotd); + + static Message message_436("436", On436); + static Message message_away("AWAY", OnAway); + static Message message_join("JOIN", OnJoin); + static Message message_kick("KICK", OnKick); + static Message message_kill("KILL", OnKill); + static Message message_mode("MODE", OnMode); + static Message message_nick("NICK", OnNick); + static Message message_uid("UID", OnUID); + static Message message_part("PART", OnPart); + static Message message_ping("PING", OnPing); + static Message message_privmsg("PRIVMSG", OnPrivmsg); + static Message message_quit("QUIT", OnQuit); + static Message message_server("SERVER", OnServer); + static Message message_squit("SQUIT", OnSQuit); + static Message message_topic("TOPIC", OnTopic); + static Message message_whois("WHOIS", OnWhois); + static Message message_capab("CAPAB", OnCapab); + static Message message_sjoin("SJOIN", OnSJoin); + static Message message_error("ERROR", OnError); } diff --git a/src/misc.cpp b/src/misc.cpp index c885188f8..51899270b 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -70,68 +70,6 @@ int tolower(char c) /*************************************************************************/ /** - * strscpy: Copy at most len-1 characters from a string to a buffer, and - * add a null terminator after the last character copied. - * @param d Buffer to copy into - * @param s Data to copy int - * @param len Length of data - * @return updated buffer - */ -char *strscpy(char *d, const char *s, size_t len) -{ - char *d_orig = d; - - if (!len) - return d; - while (--len && (*d++ = *s++)); - *d = '\0'; - return d_orig; -} - -/*************************************************************************/ - -/** - * strnrepl: Replace occurrences of `old' with `new' in string `s'. Stop - * replacing if a replacement would cause the string to exceed - * `size' bytes (including the null terminator). Return the - * string. - * @param s String - * @param size size of s - * @param old character to replace - * @param newstr character to replace with - * @return updated s - */ -char *strnrepl(char *s, int32 size, const char *old, const char *newstr) -{ - char *ptr = s; - int32 left = strlen(s); - int32 avail = size - (left + 1); - int32 oldlen = strlen(old); - int32 newlen = strlen(newstr); - int32 diff = newlen - oldlen; - - while (left >= oldlen) - { - if (strncmp(ptr, old, oldlen)) - { - --left; - ++ptr; - continue; - } - if (diff > avail) - break; - if (diff) - memmove(ptr + oldlen + diff, ptr + oldlen, left + 1 - oldlen); - strncpy(ptr, newstr, newlen); - ptr += newlen; - left -= oldlen; - } - return s; -} - -/*************************************************************************/ - -/** * merge_args: Take an argument count and argument vector and merge them * into a single string in which each argument is separated by * a space. @@ -576,7 +514,7 @@ void EnforceQlinedNick(const Anope::string &nick, const Anope::string &killer) if (u2) { Log(LOG_NORMAL, "xline") << "Killed Q-lined nick: " << u2->GetMask(); - kill_user(killer, u2->nick, "This nick is reserved for Services. Please use a non Q-Lined nick."); + kill_user(killer, u2, "This nick is reserved for Services. Please use a non Q-Lined nick."); } } diff --git a/src/modes.cpp b/src/modes.cpp index 7439c852c..1daea86b3 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -256,7 +256,7 @@ bool ChannelModeKey::IsValid(const Anope::string &value) const */ bool ChannelModeAdmin::CanSet(User *u) const { - if (u && is_oper(u)) + if (u && u->HasMode(UMODE_OPER)) return true; return false; @@ -268,7 +268,7 @@ bool ChannelModeAdmin::CanSet(User *u) const */ bool ChannelModeOper::CanSet(User *u) const { - if (u && is_oper(u)) + if (u && u->HasMode(UMODE_OPER)) return true; return false; diff --git a/src/operserv.cpp b/src/operserv.cpp index e7de407bd..911384e79 100644 --- a/src/operserv.cpp +++ b/src/operserv.cpp @@ -587,8 +587,8 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_ User *user = *it; ++it; - if (!is_oper(user) && Anope::Match(user->realname, x->Mask)) - kill_user(Config->ServerName, user->nick, rreason); + if (!user->HasMode(UMODE_OPER) && Anope::Match(user->realname, x->Mask)) + kill_user(Config->ServerName, user, rreason); } } @@ -605,7 +605,7 @@ void SNLineManager::OnMatch(User *u, XLine *x) ircdproto->SendSGLine(x); Anope::string reason = "G-Lined: " + x->Reason; - kill_user(Config->s_OperServ, u->nick, reason); + kill_user(Config->s_OperServ, u, reason); } void SNLineManager::OnExpire(XLine *x) @@ -675,7 +675,7 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_ UserContainer *uc = *it; ++it; - if (is_oper(uc->user)) + if (uc->user->HasMode(UMODE_OPER)) continue; c->Kick(NULL, uc->user, "%s", reason.c_str()); } @@ -688,8 +688,8 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_ User *user = *it; ++it; - if (!is_oper(user) && Anope::Match(user->nick, x->Mask)) - kill_user(Config->ServerName, user->nick, rreason); + if (!user->HasMode(UMODE_OPER) && Anope::Match(user->nick, x->Mask)) + kill_user(Config->ServerName, user, rreason); } } } @@ -709,7 +709,7 @@ void SQLineManager::OnMatch(User *u, XLine *x) ircdproto->SendSQLine(x); Anope::string reason = "Q-Lined: " + x->Reason; - kill_user(Config->s_OperServ, u->nick, reason); + kill_user(Config->s_OperServ, u, reason); } void SQLineManager::OnExpire(XLine *x) diff --git a/src/process.cpp b/src/process.cpp index 285c4ae6b..4a7811c69 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -101,7 +101,7 @@ IgnoreData *get_ignore(const Anope::string &nick) if (u) { /* Opers are not ignored, even if a matching entry may be present. */ - if (is_oper(u)) + if (u->HasMode(UMODE_OPER)) return NULL; for (; ign != ign_end; ++ign) if (match_usermask((*ign)->mask, u)) diff --git a/src/protocol.cpp b/src/protocol.cpp index 545824681..cc4112970 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -1,4 +1,24 @@ #include "services.h" +#include "modules.h" + +IRCDProto *ircdproto; +IRCDVar *ircd; +IRCdMessage *ircdmessage; + +void pmodule_ircd_proto(IRCDProto *proto) +{ + ircdproto = proto; +} + +void pmodule_ircd_var(IRCDVar *ircdvar) +{ + ircd = ircdvar; +} + +void pmodule_ircd_message(IRCdMessage *message) +{ + ircdmessage = message; +} void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { @@ -269,3 +289,312 @@ bool IRCDProto::IsChannelValid(const Anope::string &chan) return true; } + +bool IRCdMessage::On436(const Anope::string &, const std::vector<Anope::string> ¶ms) +{ + if (!params.empty()) + introduce_user(params[0]); + return true; +} + +bool IRCdMessage::OnAway(const Anope::string &source, const std::vector<Anope::string> ¶ms) +{ + User *u = finduser(source); + if (u && params.empty()) /* un-away */ + check_memos(u); + return true; +} + +bool IRCdMessage::OnJoin(const Anope::string &source, const std::vector<Anope::string> ¶ms) +{ + if (!params.empty()) + do_join(source, params[0], params.size() > 1 ? params[1] : ""); + return true; +} + +bool IRCdMessage::OnKick(const Anope::string &source, const std::vector<Anope::string> ¶ms) +{ + if (params.size() > 2) + do_kick(source, params[0], params[1], params[2]); + return true; +} + +/** Called on KILL + * @params[0] The nick + * @params[1] The reason + */ +bool IRCdMessage::OnKill(const Anope::string &source, const std::vector<Anope::string> ¶ms) +{ + User *u = finduser(params[0]); + BotInfo *bi; + + if (!u) + return true; + + /* Recover if someone kills us. */ + if (!Config->s_BotServ.empty() && u->server == Me && (bi = dynamic_cast<BotInfo *>(u))) + { + introduce_user(bi->nick); + bi->RejoinAll(); + } + else + do_kill(u, params[1]); + + + return true; +} + +bool IRCdMessage::OnUID(const Anope::string &source, const std::vector<Anope::string> ¶ms) +{ + return true; +} + +bool IRCdMessage::OnPart(const Anope::string &source, const std::vector<Anope::string> ¶ms) +{ + if (!params.empty()) + do_part(source, params[0], params.size() > 1 ? params[1] : ""); + return true; +} + +bool IRCdMessage::OnPing(const Anope::string &, const std::vector<Anope::string> ¶ms) +{ + if (!params.empty()) + ircdproto->SendPong(params.size() > 1 ? params[1] : Config->ServerName, params[0]); + return true; +} + +bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope::string> ¶ms) +{ + const Anope::string &receiver = params.size() > 0 ? params[0] : ""; + const Anope::string &message = params.size() > 1 ? params[1] : ""; + + /* Messages from servers can happen on some IRCds, check for . */ + if (source.empty() || receiver.empty() || message.empty() || source.find('.') != Anope::string::npos) + return true; + + User *u = finduser(source); + + if (!u) + { + Log() << message << ": |
