From d33a0f75a5c0c584fbb7cc0076da36d494f39494 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 22 Nov 2012 00:50:33 -0500 Subject: Pretty large coding style cleanup, in source doc cleanup, and allow protocol mods to depend on each other --- src/CMakeLists.txt | 1 - src/access.cpp | 93 ++--- src/account.cpp | 80 ++++ src/actions.cpp | 70 ---- src/base.cpp | 38 +- src/base64.cpp | 1 + src/bin/CMakeLists.txt | 8 - src/bin/anoperc.in | 135 ------- src/bots.cpp | 84 ++-- src/botserv.cpp | 116 ------ src/channels.cpp | 671 ++++++++++--------------------- src/chanserv.cpp | 105 ----- src/command.cpp | 31 +- src/config.cpp | 146 +++---- src/configreader.cpp | 1 + src/dns.cpp | 235 +++++------ src/encrypt.cpp | 10 +- src/hashcomp.cpp | 36 +- src/init.cpp | 211 ++++------ src/language.cpp | 46 ++- src/logger.cpp | 147 +++---- src/mail.cpp | 42 +- src/main.cpp | 313 +++----------- src/memos.cpp | 113 ++++++ src/memoserv.cpp | 110 ----- src/messages.cpp | 240 +++++++---- src/misc.cpp | 334 ++------------- src/modes.cpp | 594 ++++++++++++++++----------- src/module.cpp | 54 ++- src/modulemanager.cpp | 26 +- src/modules.cpp | 28 -- src/nickalias.cpp | 87 ++-- src/nickcore.cpp | 82 +++- src/nickserv.cpp | 157 -------- src/operserv.cpp | 484 ---------------------- src/opertype.cpp | 2 + src/process.cpp | 48 +-- src/protocol.cpp | 106 +++-- src/regchannel.cpp | 388 ++++++++---------- src/serialize.cpp | 94 +++-- src/servers.cpp | 195 ++++----- src/socket_clients.cpp | 9 +- src/socket_transport.cpp | 43 +- src/socketengines/pipeengine_eventfd.cpp | 2 +- src/sockets.cpp | 155 ++----- src/threadengine.cpp | 45 +-- src/timers.cpp | 48 +-- src/tools/CMakeLists.txt | 8 + src/tools/anoperc.in | 135 +++++++ src/uplink.cpp | 204 ++++++++++ src/users.cpp | 337 ++++++---------- src/win32/windows.cpp | 2 +- src/xline.cpp | 425 ++++++++++++++++++++ 53 files changed, 3051 insertions(+), 4124 deletions(-) create mode 100644 src/account.cpp delete mode 100644 src/actions.cpp delete mode 100644 src/bin/CMakeLists.txt delete mode 100644 src/bin/anoperc.in delete mode 100644 src/botserv.cpp delete mode 100644 src/chanserv.cpp create mode 100644 src/memos.cpp delete mode 100644 src/memoserv.cpp delete mode 100644 src/modules.cpp delete mode 100644 src/nickserv.cpp delete mode 100644 src/operserv.cpp create mode 100644 src/tools/anoperc.in create mode 100644 src/uplink.cpp create mode 100644 src/xline.cpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1f383397..b9d58f367 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -119,7 +119,6 @@ add_to_cpack_ignored_files("${SERVICES_BINARY}$" TRUE) configure_file(${Anope_SOURCE_DIR}/include/sysconf.h.cmake ${Anope_BINARY_DIR}/include/sysconf.h) # Go into the following directories and run their CMakeLists.txt as well -add_subdirectory(bin) add_subdirectory(tools) # Set Anope to be installed to the bin directory diff --git a/src/access.cpp b/src/access.cpp index 6b22ba871..863e0d41d 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -7,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #include "service.h" @@ -24,27 +25,27 @@ bool Privilege::operator==(const Privilege &other) const return this->name == other.name; } -std::vector PrivilegeManager::privs; +std::vector PrivilegeManager::Privileges; void PrivilegeManager::AddPrivilege(Privilege p) { unsigned i; - for (i = 0; i < privs.size(); ++i) + for (i = 0; i < Privileges.size(); ++i) { - Privilege &priv = privs[i]; + Privilege &priv = Privileges[i]; if (priv.rank > p.rank) break; } - privs.insert(privs.begin() + i, p); + Privileges.insert(Privileges.begin() + i, p); } void PrivilegeManager::RemovePrivilege(Privilege &p) { - std::vector::iterator it = std::find(privs.begin(), privs.end(), p); - if (it != privs.end()) - privs.erase(it); + std::vector::iterator it = std::find(Privileges.begin(), Privileges.end(), p); + if (it != Privileges.end()) + Privileges.erase(it); for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit) { @@ -55,39 +56,39 @@ void PrivilegeManager::RemovePrivilege(Privilege &p) Privilege *PrivilegeManager::FindPrivilege(const Anope::string &name) { - for (unsigned i = privs.size(); i > 0; --i) - if (privs[i - 1].name.equals_ci(name)) - return &privs[i - 1]; + for (unsigned i = Privileges.size(); i > 0; --i) + if (Privileges[i - 1].name.equals_ci(name)) + return &Privileges[i - 1]; return NULL; } std::vector &PrivilegeManager::GetPrivileges() { - return privs; + return Privileges; } void PrivilegeManager::ClearPrivileges() { - privs.clear(); + Privileges.clear(); } AccessProvider::AccessProvider(Module *o, const Anope::string &n) : Service(o, "AccessProvider", n) { - providers.push_back(this); + Providers.push_back(this); } AccessProvider::~AccessProvider() { - std::list::iterator it = std::find(providers.begin(), providers.end(), this); - if (it != providers.end()) - providers.erase(it); + std::list::iterator it = std::find(Providers.begin(), Providers.end(), this); + if (it != Providers.end()) + Providers.erase(it); } -std::list AccessProvider::providers; +std::list AccessProvider::Providers; const std::list& AccessProvider::GetProviders() { - return providers; + return Providers; } ChanAccess::ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p) @@ -98,7 +99,7 @@ ChanAccess::~ChanAccess() { } -Serialize::Data ChanAccess::serialize() const +Serialize::Data ChanAccess::Serialize() const { Serialize::Data data; @@ -106,17 +107,17 @@ Serialize::Data ChanAccess::serialize() const data["ci"] << this->ci->name; data["mask"] << this->mask; data["creator"] << this->creator; - data["last_seen"].setType(Serialize::DT_INT) << this->last_seen; - data["created"].setType(Serialize::DT_INT) << this->created; - data["data"] << this->Serialize(); + data["last_seen"].SetType(Serialize::DT_INT) << this->last_seen; + data["created"].SetType(Serialize::DT_INT) << this->created; + data["data"] << this->AccessSerialize(); return data; } -Serializable* ChanAccess::unserialize(Serializable *obj, Serialize::Data &data) +Serializable* ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data) { - service_reference aprovider("AccessProvider", data["provider"].astr()); - ChannelInfo *ci = cs_findchan(data["ci"].astr()); + ServiceReference aprovider("AccessProvider", data["provider"].astr()); + ChannelInfo *ci = ChannelInfo::Find(data["ci"].astr()); if (!aprovider || !ci) return NULL; @@ -130,7 +131,7 @@ Serializable* ChanAccess::unserialize(Serializable *obj, Serialize::Data &data) data["creator"] >> access->creator; data["last_seen"] >> access->last_seen; data["created"] >> access->created; - access->Unserialize(data["data"].astr()); + access->AccessUnserialize(data["data"].astr()); if (!obj) ci->AddAccess(access); @@ -145,7 +146,7 @@ bool ChanAccess::Matches(const User *u, const NickCore *nc) const else if (u && Anope::Match(u->GetDisplayedMask(), this->mask)) return true; else if (nc) - for (std::list >::const_iterator it = nc->aliases.begin(); it != nc->aliases.end();) + for (std::list >::const_iterator it = nc->aliases.begin(); it != nc->aliases.end();) { const NickAlias *na = *it++; if (na && Anope::Match(na->nick, this->mask)) @@ -234,16 +235,16 @@ AccessGroup::AccessGroup() : std::vector() { this->ci = NULL; this->nc = NULL; - this->SuperAdmin = this->Founder = false; + this->super_admin = this->founder = false; } bool AccessGroup::HasPriv(const Anope::string &name) const { - if (this->SuperAdmin) + if (this->super_admin) return true; else if (ci->GetLevel(name) == ACCESS_INVALID) return false; - else if (this->Founder) + else if (this->founder) return true; EventReturn MOD_RESULT; FOREACH_RESULT(I_OnGroupCheckPriv, OnGroupCheckPriv(this, name)); @@ -271,13 +272,13 @@ const ChanAccess *AccessGroup::Highest() const bool AccessGroup::operator>(const AccessGroup &other) const { - if (this->SuperAdmin) + if (this->super_admin) return true; - else if (other.SuperAdmin) + else if (other.super_admin) return false; - else if (this->Founder && !other.Founder) + else if (this->founder && !other.founder) return true; - else if (!this->Founder && other.Founder) + else if (!this->founder && other.founder) return false; const std::vector &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -298,13 +299,13 @@ bool AccessGroup::operator>(const AccessGroup &other) const bool AccessGroup::operator<(const AccessGroup &other) const { - if (other.SuperAdmin) + if (other.super_admin) return true; - else if (this->SuperAdmin) + else if (this->super_admin) return false; - else if (other.Founder && !this->Founder) + else if (other.founder && !this->founder) return true; - else if (this->Founder && !other.Founder) + else if (this->founder && !other.founder) return false; const std::vector &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -325,13 +326,13 @@ bool AccessGroup::operator<(const AccessGroup &other) const bool AccessGroup::operator>=(const AccessGroup &other) const { - if (this->SuperAdmin) + if (this->super_admin) return true; - else if (other.SuperAdmin) + else if (other.super_admin) return false; - else if (this->Founder) + else if (this->founder) return true; - else if (other.Founder) + else if (other.founder) return false; const std::vector &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -352,13 +353,13 @@ bool AccessGroup::operator>=(const AccessGroup &other) const bool AccessGroup::operator<=(const AccessGroup &other) const { - if (other.SuperAdmin) + if (other.super_admin) return true; - else if (this->SuperAdmin) + else if (this->super_admin) return false; - else if (other.Founder) + else if (other.founder) return true; - else if (this->Founder) + else if (this->founder) return false; const std::vector &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) diff --git a/src/account.cpp b/src/account.cpp new file mode 100644 index 000000000..b7dd5b51b --- /dev/null +++ b/src/account.cpp @@ -0,0 +1,80 @@ +/* + * + * (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. + * + */ + +#include "services.h" +#include "account.h" +#include "modules.h" +#include "users.h" +#include "protocol.h" +#include "regchannel.h" + +std::set IdentifyRequest::Requests; + +IdentifyRequest::IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass) : owner(o), account(acc), password(pass), dispatched(false), success(false) +{ + Requests.insert(this); +} + +IdentifyRequest::~IdentifyRequest() +{ + Requests.erase(this); +} + +void IdentifyRequest::Hold(Module *m) +{ + holds.insert(m); +} + +void IdentifyRequest::Release(Module *m) +{ + holds.erase(m); + if (holds.empty() && dispatched) + { + if (!success) + this->OnFail(); + delete this; + } +} + +void IdentifyRequest::Success(Module *m) +{ + if (!success) + { + this->OnSuccess(); + success = true; + } +} + +void IdentifyRequest::Dispatch() +{ + if (holds.empty()) + { + if (!success) + this->OnFail(); + delete this; + } + else + dispatched = true; +} + +void IdentifyRequest::ModuleUnload(Module *m) +{ + for (std::set::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end;) + { + IdentifyRequest *ir = *it; + ++it; + + ir->Release(m); + if (ir->owner == m) + delete ir; + } +} diff --git a/src/actions.cpp b/src/actions.cpp deleted file mode 100644 index 512a0fa52..000000000 --- a/src/actions.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* Various routines to perform simple actions. - * - * (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. - */ - -#include "services.h" -#include "users.h" -#include "config.h" -#include "regchannel.h" -#include "channels.h" -#include "extern.h" - -/*************************************************************************/ - -/** - * Note a bad password attempt for the given user. If they've used up - * their limit, toss them off. - * @param u the User to check - * @return true if the user was killed, otherwise false - */ -bool bad_password(User *u) -{ - if (!u || !Config->BadPassLimit) - return false; - - if (Config->BadPassTimeout > 0 && u->invalid_pw_time > 0 && u->invalid_pw_time < Anope::CurTime - Config->BadPassTimeout) - u->invalid_pw_count = 0; - ++u->invalid_pw_count; - u->invalid_pw_time = Anope::CurTime; - if (u->invalid_pw_count >= Config->BadPassLimit) - { - u->Kill(Config->ServerName, "Too many invalid passwords"); - return true; - } - - return false; -} - -/*************************************************************************/ - - -/** - * Unban the user from a channel - * @param ci channel info for the channel - * @param u The user to unban - * @param full True to match against the users real host and IP - * @return void - */ -void common_unban(const ChannelInfo *ci, User *u, bool full) -{ - if (!u || !ci || !ci->c || !ci->c->HasMode(CMODE_BAN)) - return; - - std::pair bans = ci->c->GetModeList(CMODE_BAN); - for (; bans.first != bans.second;) - { - Entry ban(CMODE_BAN, bans.first->second); - ++bans.first; - if (ban.Matches(u, full)) - ci->c->RemoveMode(NULL, CMODE_BAN, ban.GetMask()); - } -} - -/*************************************************************************/ diff --git a/src/base.cpp b/src/base.cpp index af2b38fde..5b8d828b6 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -1,20 +1,18 @@ -#include "services.h" -#include "modules.h" -#include "oper.h" -#include "account.h" -#include "regchannel.h" -#include "access.h" -#include "bots.h" +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ -std::map > Service::services; +#include "services.h" +#include "anope.h" +#include "service.h" -void RegisterTypes() -{ - static SerializeType nc("NickCore", NickCore::unserialize), na("NickAlias", NickAlias::unserialize), bi("BotInfo", BotInfo::unserialize), - ci("ChannelInfo", ChannelInfo::unserialize), access("ChanAccess", ChanAccess::unserialize), logsetting("LogSetting", LogSetting::unserialize), - modelock("ModeLock", ModeLock::unserialize), akick("AutoKick", AutoKick::unserialize), badword("BadWord", BadWord::unserialize), - memo("Memo", Memo::unserialize), xline("XLine", XLine::unserialize); -} +std::map > Service::Services; +std::map > Service::Aliases; Base::Base() { @@ -22,19 +20,19 @@ Base::Base() Base::~Base() { - for (std::set::iterator it = this->References.begin(), it_end = this->References.end(); it != it_end; ++it) + for (std::set::iterator it = this->references.begin(), it_end = this->references.end(); it != it_end; ++it) { (*it)->Invalidate(); } } -void Base::AddReference(dynamic_reference_base *r) +void Base::AddReference(ReferenceBase *r) { - this->References.insert(r); + this->references.insert(r); } -void Base::DelReference(dynamic_reference_base *r) +void Base::DelReference(ReferenceBase *r) { - this->References.erase(r); + this->references.erase(r); } diff --git a/src/base64.cpp b/src/base64.cpp index df4189547..ae026d8ef 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -7,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #include "services.h" diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt deleted file mode 100644 index d1cdb5d06..000000000 --- a/src/bin/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# If not on Windows, generate anoperc and install it along with mydbgen -if(NOT WIN32) - configure_file(${Anope_SOURCE_DIR}/src/bin/anoperc.in ${Anope_BINARY_DIR}/src/bin/anoperc) - install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/anoperc - DESTINATION ${BIN_DIR} - ) - -endif(NOT WIN32) diff --git a/src/bin/anoperc.in b/src/bin/anoperc.in deleted file mode 100644 index 9a71a22c3..000000000 --- a/src/bin/anoperc.in +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/sh -# -# Configuration script for Services -# -# (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. -# -# - - - -ANOPEPID="@INSTDIR@/data/services.pid" -ANOPROG="@INSTDIR@/bin/services" -LOG="@INSTDIR@/data/logs/" -ARCVERSION="1.4" - -isAnopeRunning () { - if [ ! -f $ANOPEPID ] ; then - echo "Warning: Anope is not currently running" - exit 1 - fi - - PID=`cat $ANOPEPID` - - if [ ! `ps auxw | grep $ANOPROG | grep $PID | grep -v -c grep` ] ; then - echo "Warning: Anope is not currently running" - exit 1 - fi -} - -if [ ! -f $ANOPROG ] ; then - echo "Error: $ANOPROG cannot be accessed" - exit 1 -fi - -if [ "$UID" = "0" ] ; then - echo "######################################"; - echo "# Warning: Do NOT run Anope as root! #"; - echo "######################################"; - exit 1 -fi - -if [ "$1" = "start" ] ; then - if [ -f $ANOPEPID ] ; then - PID=`cat $ANOPEPID` - if [ `ps auxw | grep $ANOPROG | grep $PID | grep -v -c grep` = 1 ] ; then - echo "Warning! Anope is already running" - exit 1 - fi - fi - - echo "Starting Anope" - shift - $ANOPROG $* - - if [ "$?" -ne "0" ] ; then - echo "" - echo "Unfortunately it seems Anope did not start successfully" - echo "This error has been logged in your Anope Log file" - echo "Located in "$LOG"" - echo "This may help you diagnose the problem" - echo "Further help may be available from http://www.anope.org/" - exit 1 - fi - -elif [ "$1" = "stop" ] ; then - isAnopeRunning - echo "Terminating Anope" - kill -15 `cat $ANOPEPID` - -elif [ "$1" = "status" ] ; then - if [ -f $ANOPEPID ] ; then - PID=`cat $ANOPEPID` - if [ `ps auxw | grep $PID | grep -v -c grep` = 1 ] ; then - echo "Anope is currently running" - exit 0 - fi - fi - - echo "Anope is not currently running" - -elif [ "$1" = "restart" ] ; then - isAnopeRunning - echo "Restarting Anope" - kill -15 `cat $ANOPEPID` - sleep 1 - - shift - $ANOPROG $* - - if [ "$?" -ne "0" ] ; then - echo "" - echo "Unfortunately it seems Anope did not start successfully" - echo "This error has been logged in your Anope Log file" - echo "Located in "$LOG"" - echo "This may help you diagnose the problem" - echo "Further help may be available from http://www.anope.org/" - exit 1 - fi - -elif [ "$1" = "rehash" ] ; then - isAnopeRunning - echo "Saving Databases and Rehashing Configuration" - kill -1 `cat $ANOPEPID` - -elif [ "$1" = "version" ] ; then - $ANOPROG -version - -elif [ "$1" = "help" ] ; then - if [ "$2" = "paramlist" ] ; then - $ANOPROG -help - else - echo "AnopeRC is a remote control script for easy" - echo "controlling of Anope from the command console" - echo "$0 start Start Anope." - echo "$0 stop Shutdown Anope" - echo "$0 status Show Anope's Status" - echo "$0 restart Restart Anope (Databases will be saved)." - echo "$0 rehash Rehash Configuration and Save Databases" - echo "$0 version Return Anope Version and Build Information" - echo "$0 help Show this help menu" - echo "If you need further help please check the /docs/" - echo "folder or make use of our extensive online support at" - echo "http://www.anope.org/" - fi - -else - echo "Anope Remote Control ($ARCVERSION)" - echo "Usage: $0 [start|stop|status|restart|rehash|version|help]" -fi diff --git a/src/bots.cpp b/src/bots.cpp index 7bb5ace5d..52753148f 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -1,8 +1,10 @@ /* + * * Copyright (C) 2008-2011 Robin Burchell * Copyright (C) 2008-2012 Anope Team * * Please read COPYING and README for further details. + * */ #include "services.h" @@ -10,17 +12,27 @@ #include "bots.h" #include "servers.h" #include "protocol.h" -#include "oper.h" +#include "xline.h" #include "regchannel.h" #include "channels.h" #include "config.h" #include "language.h" -#include "extern.h" #include "serialize.h" -serialize_checker BotListByNick("BotInfo"), BotListByUID("BotInfo"); +Serialize::Checker BotListByNick("BotInfo"), BotListByUID("BotInfo"); + +static const Anope::string BotFlagString[] = { "BEGIN", "CORE", "PRIVATE", "CONF", "" }; +template<> const Anope::string* Flags::flags_strings = BotFlagString; + +static const Anope::string BotServFlagStrings[] = { + "BEGIN", "DONTKICKOPS", "DONTKICKVOICES", "FANTASY", "GREET", "NOBOT", + "KICK_BOLDs", "KICK_COLORS", "KICK_REVERSES", "KICK_UNDERLINES", "KICK_BADWORDS", "KICK_CAPS", + "KICK_FLOOD", "KICK_REPEAT", "KICK_ITALICS", "KICK_AMSGS", "MSG_PRIVMSG", "MSG_NOTICE", + "MSG_NOTICEOPS", "" +}; +template<> const Anope::string* Flags::flags_strings = BotServFlagStrings; -BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", ts6_uid_retrieve()), Flags(BotFlagString), Serializable("BotInfo"), botmodes(bmodes) +BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve()), Serializable("BotInfo"), botmodes(bmodes) { this->lastmsg = this->created = Anope::CurTime; this->introduced = false; @@ -32,13 +44,13 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) { - Anope::string tmodes = !this->botmodes.empty() ? ("+" + this->botmodes) : (ircdproto ? ircdproto->DefaultPseudoclientModes : ""); + Anope::string tmodes = !this->botmodes.empty() ? ("+" + this->botmodes) : (IRCD ? IRCD->DefaultPseudoclientModes : ""); if (!tmodes.empty()) this->SetModesInternal(tmodes.c_str()); XLine x(this->nick, "Reserved for services"); - ircdproto->SendSQLine(NULL, &x); - ircdproto->SendClientIntroduction(this); + IRCD->SendSQLine(NULL, &x); + IRCD->SendClientIntroduction(this); this->introduced = true; } } @@ -48,10 +60,10 @@ BotInfo::~BotInfo() // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) { - ircdproto->SendQuit(this, ""); + IRCD->SendQuit(this, ""); this->introduced = false; XLine x(this->nick); - ircdproto->SendSQLineDel(&x); + IRCD->SendSQLineDel(&x); } for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) @@ -70,11 +82,11 @@ BotInfo::~BotInfo() BotListByUID->erase(this->uid); } -Serialize::Data BotInfo::serialize() const +Serialize::Data BotInfo::Serialize() const { Serialize::Data data; - data["nick"].setMax(64) << this->nick; + data["nick"].SetMax(64)/*XXX*/ << this->nick; data["user"] << this->ident; data["host"] << this->host; data["realname"] << this->realname; @@ -84,12 +96,12 @@ Serialize::Data BotInfo::serialize() const return data; } -Serializable* BotInfo::unserialize(Serializable *obj, Serialize::Data &data) +Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data) { BotInfo *bi; if (obj) bi = anope_dynamic_static_cast(obj); - else if (!(bi = findbot(data["nick"].astr()))) + else if (!(bi = BotInfo::Find(data["nick"].astr()))) bi = new BotInfo(data["nick"].astr(), data["user"].astr(), data["host"].astr(), data["realname"].astr()); data["created"] >> bi->created; bi->FromString(data["flags"].astr()); @@ -100,7 +112,7 @@ void BotInfo::GenerateUID() { if (!this->uid.empty()) throw CoreException("Bot already has a uid?"); - this->uid = ts6_uid_retrieve(); + this->uid = Servers::TS6_UID_Retrieve(); (*BotListByUID)[this->uid] = this; UserListByUID[this->uid] = this; } @@ -139,7 +151,7 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) ci->bi = this; if (ci->c && ci->c->users.size() >= Config->BSMinUsers) - this->Join(ci->c, &Config->BotModeList); + this->Join(ci->c, &ModeManager::DefaultBotModes); } void BotInfo::UnAssign(User *u, ChannelInfo *ci) @@ -178,7 +190,7 @@ void BotInfo::Join(Channel *c, ChannelStatus *status) if (c->FindUser(this) != NULL) return; - if (Config && ircdproto && Config->BSSmartJoin) + if (Config && IRCD && Config->BSSmartJoin) { std::pair bans = c->GetModeList(CMODE_BAN); @@ -197,21 +209,21 @@ void BotInfo::Join(Channel *c, ChannelStatus *status) /* Should we be invited? */ if (c->HasMode(CMODE_INVITE) || (limit && c->users.size() >= limit)) - ircdproto->SendNotice(this, "@" + c->name, "%s invited %s into the channel.", this->nick.c_str(), this->nick.c_str()); + IRCD->SendNotice(this, "@" + c->name, "%s invited %s into the channel.", this->nick.c_str(), this->nick.c_str()); ModeManager::ProcessModes(); } c->JoinUser(this); - if (ircdproto) - ircdproto->SendJoin(this, c, status); + if (IRCD) + IRCD->SendJoin(this, c, status); FOREACH_MOD(I_OnBotJoin, OnBotJoin(c, this)); } void BotInfo::Join(const Anope::string &chname, ChannelStatus *status) { - Channel *c = findchan(chname); + Channel *c = Channel::Find(chname); return this->Join(c ? c : new Channel(chname), status); } @@ -220,7 +232,7 @@ void BotInfo::Part(Channel *c, const Anope::string &reason) if (c->FindUser(this) == NULL) return; - ircdproto->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); + IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); c->DeleteUser(this); } @@ -233,11 +245,6 @@ void BotInfo::OnMessage(User *u, const Anope::string &message) RunCommand(source, message); } -/** Link a command name to a command in services - * @param cname The command name - * @param sname The service name - * @param permission Permission required to execute the command, if any - */ void BotInfo::SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission) { CommandInfo ci; @@ -246,10 +253,6 @@ void BotInfo::SetCommand(const Anope::string &cname, const Anope::string &sname, this->commands[cname] = ci; } -/** Get command info for a command - * @param cname The command name - * @return A struct containing service name and permission - */ CommandInfo *BotInfo::GetCommand(const Anope::string &cname) { CommandInfo::map::iterator it = this->commands.find(cname); @@ -258,3 +261,24 @@ CommandInfo *BotInfo::GetCommand(const Anope::string &cname) return NULL; } +BotInfo* BotInfo::Find(const Anope::string &nick, bool nick_only) +{ + BotInfo *bi = NULL; + if (!nick_only && isdigit(nick[0]) && IRCD->RequiresID) + { + botinfo_map::iterator it = BotListByUID->find(nick); + if (it != BotListByUID->end()) + bi = it->second; + } + else + { + botinfo_map::iterator it = BotListByNick->find(nick); + if (it != BotListByNick->end()) + bi = it->second; + } + + if (bi) + bi->QueueUpdate(); + return bi; +} + diff --git a/src/botserv.cpp b/src/botserv.cpp deleted file mode 100644 index 04949b427..000000000 --- a/src/botserv.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* BotServ functions - * - * (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. - */ - -/*************************************************************************/ - -#include "services.h" -#include "anope.h" -#include "protocol.h" -#include "bots.h" -#include "regchannel.h" -#include "language.h" -#include "extern.h" -#include "access.h" -#include "channels.h" -#include "account.h" - -BotInfo* findbot(const Anope::string &nick) -{ - BotInfo *bi = NULL; - if (isdigit(nick[0]) && ircdproto->RequiresID) - { - botinfo_map::iterator it = BotListByUID->find(nick); - if (it != BotListByUID->end()) - bi = it->second; - } - else - { - botinfo_map::iterator it = BotListByNick->find(nick); - if (it != BotListByNick->end()) - bi = it->second; - } - - if (bi) - bi->QueueUpdate(); - return bi; -} - - -/*************************************************************************/ - -/* 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) -{ - if (!u || !ci) - return; - - if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) - { - ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, ACCESS_DENIED)); - return; - } - - AccessGroup u_access = ci->AccessFor(u), req_access = ci->AccessFor(requester); - if (ci->HasFlag(CI_PEACE) && u != requester && u_access >= req_access) - return; - - if (matches_list(ci->c, u, CMODE_EXCEPT)) - { - ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, _("User matches channel except."))); - return; - } - - Anope::string mask; - get_idealban(ci, u, mask); - - ci->c->SetMode(NULL, CMODE_BAN, mask); - - /* Check if we need to do a signkick or not -GD */ - if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv("SIGNKICK"))) - ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str()); - else - ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str()); -} - -/*************************************************************************/ - -/* 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) -{ - if (!u || !ci || !ci->c || !ci->c->FindUser(u)) - return; - - if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) - { - ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, ACCESS_DENIED)); - return; - } - - AccessGroup u_access = ci->AccessFor(u), req_access = ci->AccessFor(requester); - if (ci->HasFlag(CI_PEACE) && requester != u && u_access >= req_access) - return; - - if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv("SIGNKICK"))) - ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str()); - else - ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str()); -} - diff --git a/src/channels.cpp b/src/channels.cpp index 501dd7146..41755b9c8 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -7,6 +7,7 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. + * */ #include "services.h" @@ -21,16 +22,15 @@ #include "users.h" #include "config.h" #include "access.h" -#include "extern.h" #include "sockets.h" +#include "chanserv.h" channel_map ChannelList; -/** Default constructor - * @param name The channel name - * @param ts The time the channel was created - */ -Channel::Channel(const Anope::string &nname, time_t ts) : Flags(ChannelFlagString) +static const Anope::string ChannelFlagString[] = { "CH_INABIT", "CH_PERSIST", "CH_SYNCING", "" }; +template<> const Anope::string* Flags::flags_strings = ChannelFlagString; + +Channel::Channel(const Anope::string &nname, time_t ts) { if (nname.empty()) throw CoreException("A channel without a name ?"); @@ -46,7 +46,7 @@ Channel::Channel(const Anope::string &nname, time_t ts) : Flags( this->server_modetime = this->chanserv_modetime = 0; this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_ts = this->topic_time = 0; - this->ci = cs_findchan(this->name); + this->ci = ChannelInfo::Find(this->name); if (this->ci) this->ci->c = this; @@ -55,8 +55,6 @@ Channel::Channel(const Anope::string &nname, time_t ts) : Flags( FOREACH_MOD(I_OnChannelCreate, OnChannelCreate(this)); } -/** Default destructor - */ Channel::~Channel() { FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this)); @@ -79,16 +77,16 @@ void Channel::Reset() { UserContainer *uc = *it; - ChannelStatus flags = *uc->Status; - uc->Status->ClearFlags(); + ChannelStatus flags = *uc->status; + uc->status->ClearFlags(); - if (findbot(uc->user->nick)) + if (BotInfo::Find(uc->user->nick)) { for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) { ChannelMode *cm = ModeManager::ChannelModes[i]; - if (flags.HasFlag(cm->Name)) + if (flags.HasFlag(cm->name)) this->SetMode(NULL, cm, uc->user->GetUID(), false); } } @@ -97,7 +95,7 @@ void Channel::Reset() this->CheckModes(); for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) - chan_set_correct_modes((*it)->user, this, 1, false); + this->SetCorrectModes((*it)->user, true, false); if (this->ci && Me && Me->IsSynced()) this->ci->RestoreTopic(); @@ -151,32 +149,32 @@ void Channel::CheckModes() if (!cm) continue; - if (cm->Type == MODE_REGULAR) + if (cm->type == MODE_REGULAR) { - if (!this->HasMode(cm->Name) && ml->set) + if (!this->HasMode(cm->name) && ml->set) this->SetMode(NULL, cm); - else if (this->HasMode(cm->Name) && !ml->set) + else if (this->HasMode(cm->name) && !ml->set) this->RemoveMode(NULL, cm); } - else if (cm->Type == MODE_PARAM) + else if (cm->type == MODE_PARAM) { /* If the channel doesnt have the mode, or it does and it isn't set correctly */ if (ml->set) { Anope::string param; - this->GetParam(cm->Name, param); + this->GetParam(cm->name, param); - if (!this->HasMode(cm->Name) || (!param.empty() && !ml->param.empty() && !param.equals_cs(ml->param))) + if (!this->HasMode(cm->name) || (!param.empty() && !ml->param.empty() && !param.equals_cs(ml->param))) this->SetMode(NULL, cm, ml->param); } else { - if (this->HasMode(cm->Name)) + if (this->HasMode(cm->name)) this->RemoveMode(NULL, cm); } } - else if (cm->Type == MODE_LIST) + else if (cm->type == MODE_LIST) { if (ml->set) this->SetMode(NULL, cm, ml->param); @@ -186,36 +184,32 @@ void Channel::CheckModes() } } -void Channel::JoinUser(User *user) +UserContainer* Channel::JoinUser(User *user) { Log(user, this, "join"); - ChannelStatus *Status = new ChannelStatus(); + ChannelStatus *status = new ChannelStatus(); ChannelContainer *cc = new ChannelContainer(this); - cc->Status = Status; + cc->status = status; user->chans.push_back(cc); UserContainer *uc = new UserContainer(user); - uc->Status = Status; + uc->status = status; this->users.push_back(uc); if (this->ci && this->ci->HasFlag(CI_PERSIST) && this->creation_time > this->ci->time_registered) { Log(LOG_DEBUG) << "Changing TS of " << this->name << " from " << this->creation_time << " to " << this->ci->time_registered; this->creation_time = this->ci->time_registered; - ircdproto->SendChannel(this); + IRCD->SendChannel(this); this->Reset(); } + + return uc; } -/** Remove a user internally from the channel - * @param u The user - */ void Channel::DeleteUser(User *user) { - if (this->ci) - update_cs_lastseen(user, this->ci); - Log(user, this, "leaves"); FOREACH_MOD(I_OnLeaveChannel, OnLeaveChannel(user, this)); @@ -227,7 +221,7 @@ void Channel::DeleteUser(User *user) return; } - delete (*cit)->Status; + delete (*cit)->status; delete *cit; this->users.erase(cit); @@ -259,10 +253,6 @@ void Channel::DeleteUser(User *user) delete this; } -/** Check if the user is on the channel - * @param u The user - * @return A user container if found, else NULL - */ UserContainer *Channel::FindUser(const User *u) const { for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) @@ -271,14 +261,9 @@ UserContainer *Channel::FindUser(const User *u) const return NULL; } -/** Check if a user has a status on a channel - * @param u The user - * @param cms The status mode, or NULL to represent no status - * @return true or false - */ bool Channel::HasUserStatus(const User *u, ChannelModeStatus *cms) const { - if (!u || (cms && cms->Type != MODE_STATUS)) + if (!u || (cms && cms->type != MODE_STATUS)) throw CoreException("Channel::HasUserStatus got bad mode"); /* Usually its more efficient to search the users channels than the channels users */ @@ -286,31 +271,19 @@ bool Channel::HasUserStatus(const User *u, ChannelModeStatus *cms) const if (cc) { if (cms) - return cc->Status->HasFlag(cms->Name); + return cc->status->HasFlag(cms->name); else - return !cc->Status->FlagCount(); + return !cc->status->FlagCount(); } return false; } -/** Check if a user has a status on a channel - * Use the overloaded function for ChannelModeStatus* to check for no status - * @param u The user - * @param Name The Mode name, eg CMODE_OP, CMODE_VOICE - * @return true or false - */ bool Channel::HasUserStatus(const User *u, ChannelModeName Name) const { return HasUserStatus(u, anope_dynamic_static_cast(ModeManager::FindChannelModeByName(Name))); } -/** - * See if a channel has a mode - * @param Name The mode name - * @param param The optional mode param - * @return The number of modes set - */ size_t Channel::HasMode(ChannelModeName Name, const Anope::string ¶m) { if (param.empty()) @@ -322,80 +295,70 @@ size_t Channel::HasMode(ChannelModeName Name, const Anope::string ¶m) return 0; } -/** Get a list of modes on a channel - * @param Name A mode name to get the list of - * @return a pair of iterators for the beginning and end of the list - */ -std::pair Channel::GetModeList(ChannelModeName Name) +std::pair Channel::GetModeList(ChannelModeName mname) { - Channel::ModeList::iterator it = this->modes.find(Name), it_end = it; + Channel::ModeList::iterator it = this->modes.find(mname), it_end = it; if (it != this->modes.end()) - it_end = this->modes.upper_bound(Name); + it_end = this->modes.upper_bound(mname); return std::make_pair(it, it_end); } -/** Set a mode internally on a channel, this is not sent out to the IRCd - * @param setter The user who is setting the mode - * @param cm The mode - * @param param The param - * @param EnforeMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) +void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnChannelModeSet, OnChannelModeSet(this, setter, cm->Name, param)); + FOREACH_RESULT(I_OnChannelModeSet, OnChannelModeSet(this, setter, cm->name, param)); /* Setting v/h/o/a/q etc */ - if (cm->Type == MODE_STATUS) + if (cm->type == MODE_STATUS) { if (param.empty()) { - Log() << "Channel::SetModeInternal() mode " << cm->ModeChar << " with no parameter for channel " << this->name; + Log() << "Channel::SetModeInternal() mode " << cm->mchar << " with no parameter for channel " << this->name; return; } - User *u = finduser(param); + User *u = User::Find(param); if (!u) { - Log() << "MODE " << this->name << " +" << cm->ModeChar << " for nonexistant user " << param; + Log() << "MODE " << this->name << " +" << cm->mchar << " for nonexistant user " << param; return; } - Log(LOG_DEBUG) << "Setting +" << cm->ModeChar << " on " << this->name << " for " << u->nick; + Log(LOG_DEBUG) << "Setting +" << cm->mchar << " on " << this->name << " for " << u->nick; /* Set the status on the user */ ChannelContainer *cc = u->FindChannel(this); if (cc) - cc->Status->SetFlag(cm->Name); + cc->status->SetFlag(cm->name); /* Enforce secureops, etc */ - if (EnforceMLock) - chan_set_correct_modes(u, this, 0, false); + if (enforce_mlock) + this->SetCorrectModes(u, false, false); return; } - if (cm->Type != MODE_LIST) - this->modes.erase(cm->Name); - this->modes.insert(std::make_pair(cm->Name, param)); + if (cm->type != MODE_LIST) + this->modes.erase(cm->name); + this->modes.insert(std::make_pair(cm->name, param)); - if (param.empty() && cm->Type != MODE_REGULAR) + if (param.empty() && cm->type != MODE_REGULAR) { - Log() << "Channel::SetModeInternal() mode " << cm->ModeChar << " for " << this->name << " with a paramater, but its not a param mode"; + Log() << "Channel::SetModeInternal() mode " << cm->mchar << " for " << this->name << " with a paramater, but its not a param mode"; return; } - if (cm->Type == MODE_LIST) + if (cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast(cm); cml->OnAdd(this, param); } /* Channel mode +P or so was set, mark this channel as persistent */ - if (cm->Name == CMODE_PERM) + if (cm->name == CMODE_PERM) { this->SetFlag(CH_PERSIST); if (this->ci) @@ -403,68 +366,62 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop } /* Check if we should enforce mlock */ - if (!EnforceMLock || MOD_RESULT == EVENT_STOP) + if (!enforce_mlock || MOD_RESULT == EVENT_STOP) return; this->CheckModes(); } -/** Remove a mode internally on a channel, this is not sent out to the IRCd - * @param setter The user who is unsetting the mode - * @param cm The mode - * @param param The param - * @param EnforceMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) +void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnChannelModeUnset, OnChannelModeUnset(this, setter, cm->Name, param)); + FOREACH_RESULT(I_OnChannelModeUnset, OnChannelModeUnset(this, setter, cm->name, param)); /* Setting v/h/o/a/q etc */ - if (cm->Type == MODE_STATUS) + if (cm->type == MODE_STATUS) { if (param.empty()) { - Log() << "Channel::RemoveModeInternal() mode " << cm->ModeChar << " with no parameter for channel " << this->name; + Log() << "Channel::RemoveModeInternal() mode " << cm->mchar << " with no parameter for channel " << this->name; return; } - BotInfo *bi = findbot(param); - User *u = bi ? bi : finduser(param); + BotInfo *bi = BotInfo::Find(param); + User *u = bi ? bi : User::Find(param); if (!u) { - Log() << "Channel::RemoveModeInternal() MODE " << this->name << "-" << cm->ModeChar << " for nonexistant user " << param; + Log() << "Channel::RemoveModeInternal() MODE " << this->name << "-" << cm->mchar << " for nonexistant user " << param; return; } - Log(LOG_DEBUG) << "Setting -" << cm->ModeChar << " on " << this->name << " for " << u->nick; + Log(LOG_DEBUG) << "Setting -" << cm->mchar << " on " << this->name << " for " << u->nick; /* Remove the status on the user */ ChannelContainer *cc = u->FindChannel(this); if (cc) - cc->Status->UnsetFlag(cm->Name); + cc->status->UnsetFlag(cm->name); - if (EnforceMLock) + if (enforce_mlock) { /* Reset modes on bots if we're supposed to */ if (this->ci && this->ci->bi && this->ci->bi == bi) { - if (Config->BotModeList.HasFlag(cm->Name)) + if (ModeManager::DefaultBotModes.HasFlag(cm->name)) this->SetMode(bi, cm, bi->GetUID()); } - chan_set_correct_modes(u, this, 0, false); + this->SetCorrectModes(u, false, false); } return; } - if (cm->Type == MODE_LIST && !param.empty()) + if (cm->type == MODE_LIST && !param.empty()) { - std::pair its = this->GetModeList(cm->Name); + std::pair its = this->GetModeList(cm->name); for (; its.first != its.second; ++its.first) if (Anope::Match(param, its.first->second)) { @@ -473,15 +430,15 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A } } else - this->modes.erase(cm->Name); + this->modes.erase(cm->name); - if (cm->Type == MODE_LIST) + if (cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast(cm); cml->OnDel(this, param); } - if (cm->Name == CMODE_PERM) + if (cm->name == CMODE_PERM) { this->UnsetFlag(CH_PERSIST); @@ -497,123 +454,92 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A /* Check for mlock */ - if (!EnforceMLock || MOD_RESULT == EVENT_STOP) + if (!enforce_mlock || MOD_RESULT == EVENT_STOP) return; this->CheckModes(); } -/** Set a mode on a channel - * @param bi The client setting the modes - * @param cm The mode - * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; /* Don't set modes already set */ - if (cm->Type == MODE_REGULAR && HasMode(cm->Name)) + if (cm->type == MODE_REGULAR && HasMode(cm->name)) return; - else if (cm->Type == MODE_PARAM) + else if (cm->type == MODE_PARAM) { ChannelModeParam *cmp = anope_dynamic_static_cast(cm); if (!cmp->IsValid(param)) return; Anope::string cparam; - if (GetParam(cm->Name, cparam) && cparam.equals_cs(param)) + if (GetParam(cm->name, cparam) && cparam.equals_cs(param)) return; } - else if (cm->Type == MODE_STATUS) + else if (cm->type == MODE_STATUS) { - User *u = finduser(param); + User *u = User::Find(param); if (!u || HasUserStatus(u, anope_dynamic_static_cast(cm))) return; } - else if (cm->Type == MODE_LIST) + else if (cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast(cm); - if (this->HasMode(cm->Name, param) || !cml->IsValid(param)) + if (this->HasMode(cm->name, param) || !cml->IsValid(param)) return; } ModeManager::StackerAdd(bi, this, cm, true, param); MessageSource ms(bi); - SetModeInternal(ms, cm, param, EnforceMLock); + SetModeInternal(ms, cm, param, enforce_mlock); } -/** - * Set a mode on a channel - * @param bi The client setting the modes - * @param Name The mode name - * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool enforce_mlock) { - SetMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); + SetMode(bi, ModeManager::FindChannelModeByName(Name), param, enforce_mlock); } -/** Remove a mode from a channel - * @param bi The client setting the modes - * @param cm The mode - * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; /* Don't unset modes that arent set */ - if ((cm->Type == MODE_REGULAR || cm->Type == MODE_PARAM) && !HasMode(cm->Name)) + if ((cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && !HasMode(cm->name)) return; /* Don't unset status that aren't set */ - else if (cm->Type == MODE_STATUS) + else if (cm->type == MODE_STATUS) { - User *u = finduser(param); + User *u = User::Find(param); if (!u || !HasUserStatus(u, anope_dynamic_static_cast(cm))) return; } - else if (cm->Type == MODE_LIST) + else if (cm->type == MODE_LIST) { - if (!this->HasMode(cm->Name, param)) + if (!this->HasMode(cm->name, param)) return; } /* Get the param to send, if we need it */ Anope::string realparam = param; - if (cm->Type == MODE_PARAM) + if (cm->type == MODE_PARAM) { realparam.clear(); ChannelModeParam *cmp = anope_dynamic_static_cast(cm); - if (!cmp->MinusNoArg) - this->GetParam(cmp->Name, realparam); + if (!cmp->minus_no_arg) + this->GetParam(cmp->name, realparam); } ModeManager::StackerAdd(bi, this, cm, false, realparam); MessageSource ms(bi); - RemoveModeInternal(ms, cm, realparam, EnforceMLock); + RemoveModeInternal(ms, cm, realparam, enforce_mlock); } -/** - * Remove a mode from a channel - * @param bi The client setting the modes - * @param Name The mode name - * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool enforce_mlock) { - RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); + RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, enforce_mlock); } -/** Get a param from the channel - * @param Name The mode - * @param Target a string to put the param into - * @return true on success - */ bool Channel::GetParam(ChannelModeName Name, Anope::string &Target) const { std::multimap::const_iterator it = this->modes.find(Name); @@ -629,14 +555,7 @@ bool Channel::GetParam(ChannelModeName Name, Anope::string &Target) const return false; } -/*************************************************************************/ - -/** Set a string of modes on the channel - * @param bi The client setting the modes - * @param EnforceMLock Should mlock be enforced on this mode change - * @param cmodes The modes to set - */ -void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) +void Channel::SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...) { char buf[BUFSIZE] = ""; va_list args; @@ -670,38 +589,38 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) if (add) { - if (cm->Type != MODE_REGULAR && sep.GetToken(sbuf)) + if (cm->type != MODE_REGULAR && sep.GetToken(sbuf)) { - if (cm->Type == MODE_STATUS) + if (cm->type == MODE_STATUS) { - User *targ = finduser(sbuf); + User *targ = User::Find(sbuf); if (targ != NULL) sbuf = targ->GetUID(); } - this->SetMode(bi, cm, sbuf, EnforceMLock); + this->SetMode(bi, cm, sbuf, enforce_mlock); } else - this->SetMode(bi, cm, "", EnforceMLock); + this->SetMode(bi, cm, "", enforce_mlock); } else if (!add) { - if (cm->Type != MODE_REGULAR && sep.GetToken(sbuf)) + if (cm->type != MODE_REGULAR && sep.GetToken(sbuf)) { - if (cm->Type == MODE_STATUS) + if (cm->type == MODE_STATUS) { - User *targ = finduser(sbuf); + User *targ = User::Find(sbuf); if (targ != NULL) sbuf = targ->GetUID(); } - this->RemoveMode(bi, cm, sbuf, EnforceMLock); + this->RemoveMode(bi, cm, sbuf, enforce_mlock); } else - this->RemoveMode(bi, cm, "", EnforceMLock); + this->RemoveMode(bi, cm, "", enforce_mlock); } } } -void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts, bool EnforceMLock) +void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts, bool enforce_mlock) { if (source.GetServer()) { @@ -727,7 +646,7 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, User *setter = source.GetUser(); /* Removing channel modes *may* delete this channel */ - dynamic_reference this_reference(this); + Reference this_reference(this); spacesepstream sep_modes(mode); Anope::string m; @@ -760,24 +679,24 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, Log(LOG_DEBUG) << "Channel::SetModeInternal: Unknown mode char " << m[i]; continue; } - modestring += cm->ModeChar; + modestring += cm->mchar; } - if (cm->Type == MODE_REGULAR) + if (cm->type == MODE_REGULAR) { if (add) - this->SetModeInternal(source, cm, "", EnforceMLock); + this->SetModeInternal(source, cm, "", enforce_mlock); else - this->RemoveModeInternal(source, cm, "", EnforceMLock); + this->RemoveModeInternal(source, cm, "", enforce_mlock); continue; } - else if (cm->Type == MODE_PARAM) + else if (cm->type == MODE_PARAM) { ChannelModeParam *cmp = anope_dynamic_static_cast(cm); - if (!add && cmp->MinusNoArg) + if (!add && cmp->minus_no_arg) { - this->RemoveModeInternal(source, cm, "", EnforceMLock); + this->RemoveModeInternal(source, cm, "", enforce_mlock); continue; } } @@ -785,15 +704,15 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, if (sep_modes.GetToken(token)) { User *u = NULL; - if (cm->Type == MODE_STATUS && (u = finduser(token))) + if (cm->type == MODE_STATUS && (u = User::Find(token))) paramstring += " " + u->nick; else paramstring += " " + token; if (add) - this->SetModeInternal(source, cm, token, EnforceMLock); + this->SetModeInternal(source, cm, token, enforce_mlock); else - this->RemoveModeInternal(source, cm, token, EnforceMLock); + this->RemoveModeInternal(source, cm, token, enforce_mlock); } else Log() << "warning: Channel::SetModesInternal() recieved more modes requiring params than params, modes: " << mode; @@ -808,15 +727,27 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, Log(LOG_DEBUG) << source.GetName() << " is setting " << this->name << " to " << modestring << paramstring; } -/** Kick a user from a channel internally - * @param source The sender of the kick - * @param nick The nick being kicked - * @param reason The reason for the kick - */ +bool Channel::MatchesList(User *u, ChannelModeName mode) +{ + if (!this->HasMode(mode)) + return false; + + + std::pair m = this->GetModeList(mode); + for (; m.first != m.second; ++m.first) + { + Entry e(mode, m.first->second); + if (e.Matches(u)) + return true; + } + + return false; +} + void Channel::KickInternal(MessageSource &source, const Anope::string &nick, const Anope::string &reason) { User *sender = source.GetUser(); - User *target = finduser(nick); + User *target = User::Find(nick); if (!target) { Log() << "Channel::KickInternal got a nonexistent user " << nick << " on " << this->name << ": " << reason; @@ -825,7 +756,7 @@ void Channel::KickInternal(MessageSource &source, const Anope::string &nick, con BotInfo *bi = NULL; if (target->server == Me) - bi = findbot(nick); + bi = BotInfo::Find(nick); if (sender) Log(sender, this, "kick") << "kicked " << target->nick << " (" << reason << ")"; @@ -847,17 +778,11 @@ void Channel::KickInternal(MessageSource &source, const Anope::string &nick, con /* Bots get rejoined */ if (bi) { - bi->Join(this, &Config->BotModeList); + bi->Join(this, &ModeManager::DefaultBotModes); this->UnsetFlag(CH_INHABIT); } } -/** Kick a user from the channel - * @param bi The sender, can be NULL for the service bot for this channel - * @param u The user being kicked - * @param reason The reason for the kick - * @return true if the kick was scucessful, false if a module blocked the kick - */ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) { va_list args; @@ -881,7 +806,7 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) FOREACH_RESULT(I_OnBotKick, OnBotKick(bi, this, u, buf)); if (MOD_RESULT == EVENT_STOP) return false; - ircdproto->SendKick(bi, this, u, "%s", buf); + IRCD->SendKick(bi, this, u, "%s", buf); MessageSource ms(bi); this->KickInternal(ms, u->nick, buf); return true; @@ -894,16 +819,16 @@ Anope::string Channel::GetModes(bool complete, bool plus) for (std::multimap::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) { ChannelMode *cm = ModeManager::FindChannelModeByName(it->first); - if (!cm || cm->Type == MODE_LIST) + if (!cm || cm->type == MODE_LIST) continue; - res += cm->ModeChar; + res += cm->mchar; if (complete && !it->second.empty()) { ChannelModeParam *cmp = anope_dynamic_static_cast(cm); - if (plus || !cmp->MinusNoArg) + if (plus || !cmp->minus_no_arg) params += " " + it->second; } } @@ -913,7 +838,7 @@ Anope::string Channel::GetModes(bool complete, bool plus) void Channel::ChangeTopicInternal(const Anope::string &user, const Anope::string &newtopic, time_t ts) { - User *u = finduser(user); + User *u = User::Find(user); this->topic = newtopic; this->topic_setter = u ? u->nick : user; @@ -930,13 +855,13 @@ void Channel::ChangeTopicInternal(const Anope::string &user, const Anope::string void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts) { - User *u = finduser(user); + User *u = User::Find(user); this->topic = newtopic; this->topic_setter = u ? u->nick : user; this->topic_ts = ts; - ircdproto->SendTopic(this->ci->WhoSends(), this); + IRCD->SendTopic(this->ci->WhoSends(), this); /* Now that the topic is set update the time set. This is *after* we set it so the protocol modules are able to tell the old last set time */ this->topic_time = Anope::CurTime; @@ -947,97 +872,55 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop this->ci->CheckTopic(); } -/** A timer used to keep the BotServ bot/ChanServ in the channel - * after kicking the last user in a channel - */ -class CoreExport ChanServTimer : public Timer +void Channel::Hold() { - private: - dynamic_reference c; - - public: - /** Default constructor - * @param chan The channel - */ - ChanServTimer(Channel *chan) : Timer(Config->CSInhabit), c(chan) - { - BotInfo *bi = findbot(Config->ChanServ); - if (!bi || !c) - return; - c->SetFlag(CH_INHABIT); - if (!c->ci || !c->ci->bi) - bi->Join(c); - else if (!c->FindUser(c->ci->bi)) - c->ci->bi->Join(c); - } - - /** Called when the delay is up - * @param The current time + /** A timer used to keep the BotServ bot/ChanServ in the channel + * after kicking the last user in a channel */ - void Tick(time_t) + class ChanServTimer : public Timer { - if (!c) - return; + private: + Reference c; - c->UnsetFlag(CH_INHABIT); - - if (!c->ci || !c->ci->bi) + public: + /** Constructor + * @param chan The channel + */ + ChanServTimer(Channel *chan) : Timer(Config->CSInhabit), c(chan) { - BotInfo *bi = findbot(Config->ChanServ); - if (bi) - bi->Part(c); + if (!ChanServ || !c) + return; + c->SetFlag(CH_INHABIT); + if (!c->ci || !c->ci->bi) + ChanServ->Join(c); + else if (!c->FindUser(c->ci->bi)) + c->ci->bi->Join(c); } - else if (c->users.size() == 1 || c->users.size() < Config->BSMinUsers) - c->ci->bi->Part(c); - } -}; -void Channel::Hold() -{ - new ChanServTimer(this); -} - -/*************************************************************************/ - -Channel *findchan(const Anope::string &chan) -{ - channel_map::const_iterator it = ChannelList.find(chan); - - if (it != ChannelList.end()) - return it->second; - return NULL; -} - -/*************************************************************************/ - -/* Is the given nick on the given channel? - This function supports links. */ + /** Called when the delay is up + * @param The current time + */ + void Tick(time_t) anope_override + { + if (!c) + return; -User *nc_on_chan(Channel *c, const NickCore *nc) -{ - if (!c || !nc) - return NULL; + c->UnsetFlag(CH_INHABIT); - for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) - { - UserContainer *uc = *it; + if (!c->ci || !c->ci->bi) + { + if (ChanServ) + ChanServ->Part(c); + } + else if (c->users.size() == 1 || c->users.size() < Config->BSMinUsers) + c->ci->bi->Part(c); + } + }; - if (uc->user->Account() == nc) - return uc->user; - } - return NULL; + new ChanServTimer(this); } -/** - * Set the correct modes, or remove the ones granted without permission, - * for the specified user on ths specified channel. This doesn't give - * modes to ignored users, but does remove them if needed. - * @param user The user to give/remove modes to/from - * @param c The channel to give/remove modes on - * @param give_modes Set to 1 to give modes, 0 to not give modes - * @return void - **/ -void chan_set_correct_modes(const User *user, Channel *c, int give_modes, bool check_noop) +void Channel::SetCorrectModes(User *user, bool give_modes, bool check_noop) { ChannelMode *owner = ModeManager::FindChannelModeByName(CMODE_OWNER), *admin = ModeManager::FindChannelModeByName(CMODE_PROTECT), @@ -1045,46 +928,44 @@ void chan_set_correct_modes(const User *user, Channel *c, int give_modes, bool c *halfop = ModeManager::FindChannelModeByName(CMODE_HALFOP), *voice = ModeManager::FindChannelModeByName(CMODE_VOICE); - if (u