From a9772cde21407c89abd161d51aff45267f87b1fb Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 14 Feb 2012 15:13:27 -0500 Subject: Clean up and reorganize our header files --- include/CMakeLists.txt | 26 +- include/access.h | 19 +- include/account.h | 129 ++++--- include/anope.h | 288 ++++++++++++---- include/base.h | 106 ++++++ include/bots.h | 11 +- include/botserv.h | 79 +++++ include/channels.h | 22 +- include/commands.h | 7 +- include/config.h | 51 ++- include/defs.h | 52 +++ include/dns.h | 21 +- include/extensible.h | 3 +- include/extern.h | 98 +----- include/hashcomp.h | 15 +- include/lists.h | 94 +++++ include/logger.h | 16 +- include/mail.h | 15 + include/memo.h | 63 ++++ include/modes.h | 57 ++- include/module.h | 52 ++- include/modules.h | 136 +++----- include/oper.h | 4 +- include/opertype.h | 5 +- include/protocol.h | 155 +++++++++ include/regchannel.h | 31 +- include/resource.h | 20 -- include/serialize.h | 162 +++------ include/servers.h | 3 + include/service.h | 110 ++++++ include/services.h | 913 +------------------------------------------------ include/signals.h | 49 +++ include/socketengine.h | 2 + include/sockets.h | 12 +- include/threadengine.h | 3 +- include/timers.h | 10 +- include/uplink.h | 44 +++ include/users.h | 24 +- 38 files changed, 1476 insertions(+), 1431 deletions(-) create mode 100644 include/base.h create mode 100644 include/botserv.h create mode 100644 include/defs.h create mode 100644 include/lists.h create mode 100644 include/memo.h create mode 100644 include/protocol.h delete mode 100644 include/resource.h create mode 100644 include/service.h create mode 100644 include/signals.h create mode 100644 include/uplink.h (limited to 'include') diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index c7d5456c7..5579fdf30 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -20,11 +20,24 @@ endif(NOT WIN32) set(PCH_SOURCES_GCH "") if(CMAKE_COMPILER_IS_GNUCXX) string(REPLACE " " ";" PCH_CXXFLAGS ${CXXFLAGS}) - file(GLOB INCLUDE_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h") - remove_item_from_list(INCLUDE_SRCS "version.h") - set(PCH_SOURCES "module.h;modules.h;services.h") + file(GLOB PCH_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h") + sort_list(PCH_SOURCES) + foreach(PCH_SOURCE ${PCH_SOURCES}) + find_includes(${PCH_SOURCE} INCLUDES) + set(INCLUDES_LIST) + foreach(INCLUDE ${INCLUDES}) + # Extract the filename from the #include line + extract_include_filename(${INCLUDE} FILENAME QUOTE_TYPE) + if(QUOTE_TYPE STREQUAL "quotes") + find_in_list(PCH_SOURCES "${FILENAME}" FOUND) + if(NOT FOUND EQUAL -1) + append_to_list(INCLUDES_LIST ${FILENAME}) + endif(NOT FOUND EQUAL -1) + endif(QUOTE_TYPE STREQUAL "quotes") + endforeach(INCLUDE) + set(PCH_EXTRAFLAGS "") if(DEBUG_BUILD) set(PCH_EXTRAFLAGS "-g") @@ -33,13 +46,14 @@ if(CMAKE_COMPILER_IS_GNUCXX) set(PCH_EXTRAFLAGS ${PCH_EXTRAFLAGS} -fPIC) endif(PCH_SOURCE STREQUAL "module.h") if(GETTEXT_INCLUDE) - set(PCH_GETTEXT_INCLUDE "-I${GETTEXT_INCLUDE}") + set(PCH_GETTEXT_INCLUDE "-I${GETTEXT_INCLUDE}") endif(GETTEXT_INCLUDE) set(PCH_SOURCES_GCH "${PCH_SOURCES_GCH};${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch") add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch - COMMAND ${CMAKE_CXX_COMPILER} ARGS ${PCH_CXXFLAGS} ${PCH_EXTRAFLAGS} ${PCH_GETTEXT_INCLUDE} -I${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${PCH_SOURCE} -o ${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch - DEPENDS ${INCLUDE_SRCS} VERBATIM + COMMAND ${CMAKE_CXX_COMPILER} ARGS ${PCH_CXXFLAGS} ${PCH_EXTRAFLAGS} + ${PCH_GETTEXT_INCLUDE} -I${CMAKE_CURRENT_BINARY_DIR} -I${Anope_SOURCE_DIR}/modules/pseudoclients ${CMAKE_CURRENT_SOURCE_DIR}/${PCH_SOURCE} -o ${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch + DEPENDS ${INCLUDES_LIST} VERBATIM ) endforeach(PCH_SOURCE ${PCH_SOURCES}) endif(CMAKE_COMPILER_IS_GNUCXX) diff --git a/include/access.h b/include/access.h index 8b380895d..e19c15a76 100644 --- a/include/access.h +++ b/include/access.h @@ -1,6 +1,24 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + #ifndef ACCESS_H #define ACCESS_H +#include "services.h" +#include "anope.h" +#include "serialize.h" +#include "service.h" + enum { ACCESS_INVALID = -10000, @@ -28,7 +46,6 @@ class CoreExport PrivilegeManager static void ClearPrivileges(); }; -class ChanAccess; class CoreExport AccessProvider : public Service { diff --git a/include/account.h b/include/account.h index 516bcace5..ffdc7b18f 100644 --- a/include/account.h +++ b/include/account.h @@ -1,10 +1,24 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + #ifndef ACCOUNT_H #define ACCOUNT_H +#include "extensible.h" +#include "serialize.h" #include "anope.h" - -class NickAlias; -class NickCore; +#include "memo.h" +#include "base.h" typedef Anope::insensitive_map nickalias_map; typedef Anope::insensitive_map nickcore_map; @@ -93,8 +107,11 @@ const Anope::string NickCoreFlagStrings[] = { "MEMO_MAIL", "HIDE_STATUS", "SUSPENDED", "AUTOOP", "FORBIDDEN", "UNCONFIRMED", "" }; -class CoreExport NickAlias : public Extensible, public Flags, public Serializable +class CoreExport NickAlias : public Base, public Extensible, public Flags, public Serializable { + Anope::string vhost_ident, vhost_host, vhost_creator; + time_t vhost_created; + public: /** Default constructor * @param nickname The nick @@ -114,7 +131,6 @@ class CoreExport NickAlias : public Extensible, public Flags, public Serializable +class CoreExport NickCore : public Base, public Extensible, public Flags, public Serializable { public: /** Default constructor @@ -254,65 +307,11 @@ class CoreExport NickCore : public Extensible, public Flags u; - Anope::string nick; - - public: - /** Default constructor - * @param nick The nick we're colliding - * @param delay How long to delay before kicking the user off the nick - */ - NickServCollide(User *user, time_t delay); - - /** Default destructor - */ - virtual ~NickServCollide(); - - /** Called when the delay is up - * @param t The current time - */ - void Tick(time_t t); -}; - -/** Timers for removing HELD status from nicks. - */ -class NickServHeld : public Timer -{ - dynamic_reference na; - Anope::string nick; - public: - NickServHeld(NickAlias *n, long t); - - ~NickServHeld(); - - void Tick(time_t); -}; - -/** Timers for releasing nicks to be available for use - */ -class CoreExport NickServRelease : public User, public Timer -{ - Anope::string nick; - - public: - /** Default constructor - * @param na The nick - * @param delay The delay before the nick is released - */ - NickServRelease(NickAlias *na, time_t delay); - - /** Default destructor - */ - virtual ~NickServRelease(); +extern void change_core_display(NickCore *nc); +extern void change_core_display(NickCore *nc, const Anope::string &newdisplay); - /** Called when the delay is up - * @param t The current time - */ - void Tick(time_t t); -}; +extern NickAlias *findnick(const Anope::string &nick); +extern NickCore *findcore(const Anope::string &nick); +extern bool is_on_access(const User *u, const NickCore *nc); #endif // ACCOUNT_H diff --git a/include/anope.h b/include/anope.h index ac7aa0740..992662650 100644 --- a/include/anope.h +++ b/include/anope.h @@ -11,13 +11,8 @@ #ifndef ANOPE_H #define ANOPE_H -#include -#include -#include #include "hashcomp.h" -class Message; - namespace Anope { template class map : public std::map { }; @@ -353,7 +348,7 @@ namespace Anope * @param mask The pattern to check (e.g. foo*bar) * @param case_sensitive Whether or not the match is case sensitive, default false. */ - extern CoreExport bool Match(const Anope::string &str, const Anope::string &mask, bool case_sensitive = false); + extern CoreExport bool Match(const string &str, const string &mask, bool case_sensitive = false); /** Find a message in the message table * @param name The name of the message were looking for @@ -372,20 +367,20 @@ namespace Anope * @param src The data to be converted * @param dest The destination string */ - extern CoreExport void Unhex(const Anope::string &src, Anope::string &dest); - extern CoreExport void Unhex(const Anope::string &src, char *dest); + extern CoreExport void Unhex(const string &src, string &dest); + extern CoreExport void Unhex(const 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); + extern CoreExport void B64Encode(const string &src, 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); + extern CoreExport void B64Decode(const string &src, string &target); /** Returns a sequence of data formatted as the format argument specifies. ** After the format parameter, the function expects at least as many @@ -404,7 +399,7 @@ namespace Anope /** Return the last error, uses errno/GetLastError() to determine this * @return An error message */ - extern CoreExport const Anope::string LastError(); + extern CoreExport const string LastError(); } /** sepstream allows for splitting token seperated lists. @@ -470,95 +465,250 @@ class spacesepstream : public sepstream spacesepstream(const Anope::string &source) : sepstream(source, ' ') { } }; -/** The base class that most classes in Anope inherit from +/** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. + * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or + * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not + * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user + * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time. */ -class dynamic_reference_base; -class CoreExport Base +class CoreException : public std::exception +{ + protected: + /** Holds the error message to be displayed + */ + Anope::string err; + /** Source of the exception + */ + Anope::string source; + public: + /** Default constructor, just uses the error mesage 'Core threw an exception'. + */ + CoreException() : err("Core threw an exception"), source("The core") { } + /** This constructor can be used to specify an error message before throwing. + */ + CoreException(const Anope::string &message) : err(message), source("The core") { } + /** This constructor can be used to specify an error message before throwing, + * and to specify the source of the exception. + */ + CoreException(const Anope::string &message, const Anope::string &src) : err(message), source(src) { } + /** This destructor solves world hunger, cancels the world debt, and causes the world to end. + * Actually no, it does nothing. Never mind. + * @throws Nothing! + */ + virtual ~CoreException() throw() { } + /** Returns the reason for the exception. + * The module should probably put something informative here as the user will see this upon failure. + */ + virtual const Anope::string &GetReason() const + { + return err; + } + + virtual const Anope::string &GetSource() const + { + return source; + } +}; + +class FatalException : public CoreException { - /* References to this base class */ - std::set References; public: - Base(); - virtual ~Base(); - void AddReference(dynamic_reference_base *r); - void DelReference(dynamic_reference_base *r); + FatalException(const Anope::string &reason = "") : CoreException(reason) { } + + virtual ~FatalException() throw() { } }; -class dynamic_reference_base +class ModuleException : public CoreException { - protected: - bool invalid; public: - dynamic_reference_base() : invalid(false) { } - virtual ~dynamic_reference_base() { } - inline void Invalidate() { this->invalid = true; } + /** Default constructor, just uses the error mesage 'Module threw an exception'. + */ + ModuleException() : CoreException("Module threw an exception", "A Module") { } + + /** This constructor can be used to specify an error message before throwing. + */ + ModuleException(const Anope::string &message) : CoreException(message, "A Module") { } + /** This destructor solves world hunger, cancels the world debt, and causes the world to end. + * Actually no, it does nothing. Never mind. + * @throws Nothing! + */ + virtual ~ModuleException() throw() { } +}; + +class ConvertException : public CoreException +{ + public: + ConvertException(const Anope::string &reason = "") : CoreException(reason) { } + + virtual ~ConvertException() throw() { } }; -template -class dynamic_reference : public dynamic_reference_base +/** Convert something to a string + */ +template inline Anope::string stringify(const T &x) +{ + std::ostringstream stream; + + if (!(stream << x)) + throw ConvertException("Stringify fail"); + + return stream.str(); +} + +template inline void convert(const Anope::string &s, T &x, Anope::string &leftover, bool failIfLeftoverChars = true) +{ + leftover.clear(); + std::istringstream i(s.str()); + char c; + bool res = i >> x; + if (!res) + throw ConvertException("Convert fail"); + if (failIfLeftoverChars) + { + if (i.get(c)) + throw ConvertException("Convert fail"); + } + else + { + std::string left; + getline(i, left); + leftover = left; + } +} + +template inline void convert(const Anope::string &s, T &x, bool failIfLeftoverChars = true) +{ + Anope::string Unused; + convert(s, x, Unused, failIfLeftoverChars); +} + +template inline T convertTo(const Anope::string &s, Anope::string &leftover, bool failIfLeftoverChars = true) +{ + T x; + convert(s, x, leftover, failIfLeftoverChars); + return x; +} + +template inline T convertTo(const Anope::string &s, bool failIfLeftoverChars = true) +{ + T x; + convert(s, x, failIfLeftoverChars); + return x; +} + +/** Debug cast to be used instead of dynamic_cast, this uses dynamic_cast + * for debug builds and static_cast on releass builds to speed up the program + * because dynamic_cast relies on RTTI. + */ +#ifdef DEBUG_BUILD +# include +#endif +template inline T debug_cast(O ptr) +{ +#ifdef DEBUG_BUILD + T ret = dynamic_cast(ptr); + if (ptr != NULL && ret == NULL) + throw CoreException(Anope::string("debug_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail"); + return ret; +#else + return static_cast(ptr); +#endif +} + +/*************************************************************************/ + +/** Class with the ability to keep flags on items, they should extend from this + * where T is an enum. + */ +template class Flags { protected: - T *ref; + std::bitset Flag_Values; + const Anope::string *Flag_Strings; + public: - dynamic_reference(T *obj) : ref(obj) + Flags() : Flag_Strings(NULL) { } + Flags(const Anope::string *flag_strings) : Flag_Strings(flag_strings) { } + + /** Add a flag to this item + * @param Value The flag + */ + void SetFlag(T Value) { - if (ref) - ref->AddReference(this); + Flag_Values[Value] = true; } - dynamic_reference(const dynamic_reference &obj) : ref(obj.ref) + /** Remove a flag from this item + * @param Value The flag + */ + void UnsetFlag(T Value) { - if (ref) - ref->AddReference(this); + Flag_Values[Value] = false; } - virtual ~dynamic_reference() + /** Check if this item has a flag + * @param Value The flag + * @return true or false + */ + bool HasFlag(T Value) const { - if (this->invalid) - { - this->invalid = false; - this->ref = NULL; - } - else if (this->operator bool()) - ref->DelReference(this); + return Flag_Values.test(Value); } - virtual operator bool() + /** Check how many flags are set + * @return The number of flags set + */ + size_t FlagCount() const { - if (this->invalid) - { - this->invalid = false; - this->ref = NULL; - } - return this->ref != NULL; + return Flag_Values.count(); } - virtual inline operator T*() + /** Unset all of the flags + */ + void ClearFlags() { - if (this->operator bool()) - return this->ref; - return NULL; + Flag_Values.reset(); } - virtual inline T *operator->() + Anope::string ToString() { - if (this->operator bool()) - return this->ref; - return NULL; + std::vector v = ToVector(); + Anope::string flag_buf; + for (unsigned i = 0; i < v.size(); ++i) + flag_buf += v[i] + " "; + flag_buf.trim(); + return flag_buf; } - virtual inline void operator=(T *newref) + void FromString(const Anope::string &str) { - if (this->invalid) - { - this->invalid = false; - this->ref = NULL; - } - else if (this->operator bool()) - this->ref->DelReference(this); - this->ref = newref; - if (this->operator bool()) - this->ref->AddReference(this); + spacesepstream sep(str); + Anope::string buf; + std::vector v; + + while (sep.GetToken(buf)) + v.push_back(buf); + + FromVector(v); + } + + std::vector ToVector() + { + std::vector ret; + for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i) + if (this->HasFlag(static_cast(i))) + ret.push_back(this->Flag_Strings[i]); + return ret; + } + + void FromVector(const std::vector &strings) + { + this->ClearFlags(); + + for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i) + for (unsigned j = 0; j < strings.size(); ++j) + if (this->Flag_Strings[i] == strings[j]) + this->SetFlag(static_cast(i)); } }; diff --git a/include/base.h b/include/base.h new file mode 100644 index 000000000..2a7cb5147 --- /dev/null +++ b/include/base.h @@ -0,0 +1,106 @@ +/* + * + * Copyright (C) 2008-2011 Adam + * Copyright (C) 2008-2012 Anope Team + * + * Please read COPYING and README for further details. + */ + +#ifndef BASE_H +#define BASE_H + +#include "services.h" + +/** The base class that most classes in Anope inherit from + */ +class CoreExport Base +{ + /* References to this base class */ + std::set References; + public: + Base(); + virtual ~Base(); + void AddReference(dynamic_reference_base *r); + void DelReference(dynamic_reference_base *r); +}; + +class dynamic_reference_base +{ + protected: + bool invalid; + public: + dynamic_reference_base() : invalid(false) { } + virtual ~dynamic_reference_base() { } + inline void Invalidate() { this->invalid = true; } +}; + +template +class dynamic_reference : public dynamic_reference_base +{ + protected: + T *ref; + public: + dynamic_reference(T *obj) : ref(obj) + { + if (ref) + ref->AddReference(this); + } + + dynamic_reference(const dynamic_reference &obj) : ref(obj.ref) + { + if (ref) + ref->AddReference(this); + } + + virtual ~dynamic_reference() + { + if (this->invalid) + { + this->invalid = false; + this->ref = NULL; + } + else if (this->operator bool()) + ref->DelReference(this); + } + + virtual operator bool() + { + if (this->invalid) + { + this->invalid = false; + this->ref = NULL; + } + return this->ref != NULL; + } + + virtual inline operator T*() + { + if (this->operator bool()) + return this->ref; + return NULL; + } + + virtual inline T *operator->() + { + if (this->operator bool()) + return this->ref; + return NULL; + } + + virtual inline void operator=(T *newref) + { + if (this->invalid) + { + this->invalid = false; + this->ref = NULL; + } + else if (this->operator bool()) + this->ref->DelReference(this); + this->ref = newref; + if (this->operator bool()) + this->ref->AddReference(this); + } +}; + +#endif // BASE_H + diff --git a/include/bots.h b/include/bots.h index 93ca7d9b9..243ae7556 100644 --- a/include/bots.h +++ b/include/bots.h @@ -8,7 +8,11 @@ #ifndef BOTS_H #define BOTS_H -class BotInfo; +#include "users.h" +#include "anope.h" +#include "serialize.h" +#include "commands.h" + extern CoreExport Anope::insensitive_map BotListByNick; extern CoreExport Anope::map BotListByUID; @@ -123,4 +127,9 @@ class CoreExport BotInfo : public User, public Flags, public Se CommandInfo *GetCommand(const Anope::string &cname); }; +extern BotInfo *findbot(const Anope::string &nick); + +extern void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); +extern void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); + #endif // BOTS_H diff --git a/include/botserv.h b/include/botserv.h new file mode 100644 index 000000000..e5ef2c8ba --- /dev/null +++ b/include/botserv.h @@ -0,0 +1,79 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#ifndef BOTSERV_H +#define BOTSERV_H + +#include "anope.h" + +/* BotServ SET flags */ +enum BotServFlag +{ + BS_BEGIN, + /* BotServ won't kick ops */ + BS_DONTKICKOPS, + /* BotServ won't kick voices */ + BS_DONTKICKVOICES, + /* BotServ bot accepts fantasy commands */ + BS_FANTASY, + /* BotServ should show greets */ + BS_GREET, + /* BotServ bots are not allowed to be in this channel */ + BS_NOBOT, + /* BotServ kicks for bolds */ + BS_KICK_BOLDS, + /* BotServ kicks for colors */ + BS_KICK_COLORS, + /* BOtServ kicks for reverses */ + BS_KICK_REVERSES, + /* BotServ kicks for underlines */ + BS_KICK_UNDERLINES, + /* BotServ kicks for badwords */ + BS_KICK_BADWORDS, + /* BotServ kicks for caps */ + BS_KICK_CAPS, + /* BotServ kicks for flood */ + BS_KICK_FLOOD, + /* BotServ kicks for repeating */ + BS_KICK_REPEAT, + /* BotServ kicks for italics */ + BS_KICK_ITALICS, + /* BotServ kicks for amsgs */ + BS_KICK_AMSGS, + BS_END +}; + +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", "" +}; + +/* Indices for TTB (Times To Ban) */ +enum +{ + TTB_BOLDS, + TTB_COLORS, + TTB_REVERSES, + TTB_UNDERLINES, + TTB_BADWORDS, + TTB_CAPS, + TTB_FLOOD, + TTB_REPEAT, + TTB_ITALICS, + TTB_AMSGS, + TTB_SIZE +}; + +#endif // BOTSERV_H diff --git a/include/channels.h b/include/channels.h index 2aa4fc765..a4803fe00 100644 --- a/include/channels.h +++ b/include/channels.h @@ -9,6 +9,11 @@ #ifndef CHANNELS_H #define CHANNELS_H +#include "anope.h" +#include "extensible.h" +#include "modes.h" + + typedef Anope::insensitive_map channel_map; extern CoreExport channel_map ChannelList; @@ -35,7 +40,7 @@ enum ChannelFlag const Anope::string ChannelFlagString[] = { "CH_INABIT", "CH_PERSIST", "CH_SYNCING", "" }; -class CoreExport Channel : public Extensible, public Flags +class CoreExport Channel : public Base, public Extensible, public Flags { public: typedef std::multimap ModeList; @@ -229,6 +234,21 @@ class CoreExport Channel : public Extensible, public Flags * @param ts The time when the new topic is being set */ void ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime); + + /** Hold the channel open using ChanServ + */ + void Hold(); }; +extern Channel *findchan(const Anope::string &chan); + +extern User *nc_on_chan(Channel *c, const NickCore *nc); + +extern void do_cmode(const Anope::string &source, const Anope::string &channel, const Anope::string &modes, const Anope::string &ts); +extern void do_join(const Anope::string &source, const Anope::string &channels, const Anope::string &ts); +extern void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason); +extern void do_part(const Anope::string &source, const Anope::string &channels, const Anope::string &reason); + +extern void chan_set_correct_modes(User *user, Channel *c, int give_modes); + #endif // CHANNELS_H diff --git a/include/commands.h b/include/commands.h index c0812620f..cfd46d644 100644 --- a/include/commands.h +++ b/include/commands.h @@ -12,11 +12,8 @@ #ifndef COMMAND_H #define COMMAND_H -#include "services.h" - -class Module; -class BotInfo; -class Command; +#include "service.h" +#include "anope.h" enum CommandFlag { diff --git a/include/config.h b/include/config.h index 0482aac69..d53b7f41c 100644 --- a/include/config.h +++ b/include/config.h @@ -1,14 +1,22 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + #ifndef CONFIG_H #define CONFIG_H -#include -#include -#include -#include -#include -#include - -#include "anope.h" +#include "account.h" +#include "regchannel.h" +#include "users.h" /** A configuration key and value pair */ @@ -23,7 +31,6 @@ typedef std::vector KeyValList; typedef std::multimap ConfigDataHash; // Required forward definitions -class ServerConfig; /** Types of data in the core config */ @@ -341,6 +348,29 @@ class CoreExport ServerConfig void ValidateIP(const Anope::string &p, const Anope::string &, const Anope::string &, bool) const; void ValidateNoSpaces(const Anope::string &, const Anope::string &, const Anope::string &) const; + struct Uplink + { + Anope::string host; + unsigned port; + Anope::string password; + bool ipv6; + + Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { } + bool operator==(const Uplink &other) const + { + if (this->host != other.host) + return false; + if (this->port != other.port) + return false; + if (this->password != other.password) + return false; + if (this->ipv6 != other.ipv6) + return false; + return true; + } + inline bool operator!=(const Uplink &other) const { return !(*this == other); } + }; + /** Below here is a list of variables which contain the config files values */ /* Host to bind to */ @@ -760,4 +790,7 @@ class CoreExport ConfigReader int EnumerateValues(const Anope::string &, int); }; +extern ConfigurationFile services_conf; +extern ServerConfig *Config; + #endif // CONFIG_H diff --git a/include/defs.h b/include/defs.h new file mode 100644 index 000000000..0a248daf7 --- /dev/null +++ b/include/defs.h @@ -0,0 +1,52 @@ +/* + * + * (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. + * + */ + + +class AccessGroup; +class AutoKick; +class BotInfo; +class CallBack; +class ChanAccess; +class Channel; +class ChannelInfo; +class ChannelStatus; +class ClientSocket; +class Command; +class ConnectionSocket; +class DNSPacket; +class dynamic_reference_base; +class Entry; +class InfoFormatter; +class ListenSocket; +class Log; +class LogInfo; +class Memo; +class Message; +class Module; +class NickAlias; +class NickCore; +class OperType; +class Server; +class ServerConfig; +class Socket; +class Thread; +class User; +class XLineManager; +struct BadWord; +struct CommandSource; +struct DNSQuery; +struct Exception; +struct MemoInfo; +struct ModeLock; +struct Oper; +struct XLine; + diff --git a/include/dns.h b/include/dns.h index 7d668cda7..c70b6b7b3 100644 --- a/include/dns.h +++ b/include/dns.h @@ -1,6 +1,24 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + #ifndef DNS_H #define DNS_H +#include "sockets.h" +#include "timers.h" +#include "extern.h" +#include "config.h" + /** Valid query types */ enum QueryType @@ -48,9 +66,6 @@ enum DNSError DNS_ERROR_INVALIDTYPE }; -class Module; -struct DNSQuery; -class DNSPacket; struct CoreExport Question { diff --git a/include/extensible.h b/include/extensible.h index 21a1513a1..1416e1983 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -8,7 +8,6 @@ #define EXTENSIBLE_H #include "anope.h" -#include "hashcomp.h" class CoreExport ExtensibleItem { @@ -24,7 +23,7 @@ class ExtensibleString : public Anope::string, public ExtensibleItem ExtensibleString(const Anope::string &s) : Anope::string(s), ExtensibleItem() { } }; -class CoreExport Extensible : public Base +class CoreExport Extensible { private: typedef Anope::map extensible_map; diff --git a/include/extern.h b/include/extern.h index 0670f285c..aff091913 100644 --- a/include/extern.h +++ b/include/extern.h @@ -12,32 +12,19 @@ #ifndef EXTERN_H #define EXTERN_H +#include "modes.h" + #define E extern CoreExport #define EI extern DllExport -#include "hashcomp.h" - -/* IRC Variables */ - -E IRCDVar *ircd; -E IRCDProto *ircdproto; -E IRCdMessage *ircdmessage; /**** actions.c ****/ E bool bad_password(User *u); E void common_unban(ChannelInfo *ci, User *u, bool full = false); -/**** botserv.c ****/ - -E BotInfo *findbot(const Anope::string &nick); - -E void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); -E void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason); - /**** channels.c ****/ - E Channel *findchan(const Anope::string &chan); E User *nc_on_chan(Channel *c, const NickCore *nc); @@ -49,26 +36,11 @@ E void do_part(const Anope::string &source, const Anope::string &channels, const E void chan_set_correct_modes(User *user, Channel *c, int give_modes); -/**** chanserv.c ****/ - -E void check_modes(Channel *c); - -E ChannelInfo *cs_findchan(const Anope::string &chan); -E bool IsFounder(User *user, ChannelInfo *ci); -E void update_cs_lastseen(User *user, ChannelInfo *ci); -E int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret); - -/**** config.c ****/ - -E ConfigurationFile services_conf; -E ServerConfig *Config; - /**** encrypt.c ****/ + E void enc_encrypt(const Anope::string &src, Anope::string &dest); E bool enc_decrypt(const Anope::string &src, Anope::string &dest); -/**** hostserv.c ****/ - /**** init.c ****/ E void introduce_user(const Anope::string &user); @@ -78,12 +50,8 @@ E bool AtTerm(); E void Fork(); E void Init(int ac, char **av); -/**** ircd.c ****/ -E void pmodule_ircd_proto(IRCDProto *); -E void pmodule_ircd_var(IRCDVar *ircdvar); -E void pmodule_ircd_message(IRCdMessage *message); - /**** language.cpp ****/ + E std::vector languages; E std::vector domains; E void InitLanguages(); @@ -109,31 +77,6 @@ E bool restarting; E Anope::string quitmsg; E time_t start_time; -class UplinkSocket : public ConnectionSocket, public BufferedSocket -{ - public: - UplinkSocket(); - ~UplinkSocket(); - bool Read(const Anope::string &); - void OnConnect(); - void OnError(const Anope::string &); - - class CoreExport Message - { - Anope::string source; - std::stringstream buffer; - public: - Message(); - Message(const Anope::string &); - ~Message(); - template Message &operator<<(const T &val) - { - this->buffer << val; - return *this; - } - }; -}; -E UplinkSocket *UplinkSock; E int CurrentUplink; E void save_databases(); @@ -191,45 +134,14 @@ E bool str_is_pure_wildcard(const Anope::string &str); E Anope::string normalizeBuffer(const Anope::string &); /**** modes.cpp ****/ + /* Number of generic modes we support */ E unsigned GenericChannelModes, GenericUserModes; E std::multimap def_mode_locks; E void SetDefaultMLock(ServerConfig *config); -/**** nickserv.c ****/ - -E void change_core_display(NickCore *nc); -E void change_core_display(NickCore *nc, const Anope::string &newdisplay); - -E NickAlias *findnick(const Anope::string &nick); -E NickCore *findcore(const Anope::string &nick); -E bool is_on_access(const User *u, const NickCore *nc); - /**** process.c ****/ E void process(const Anope::string &buf); -/**** sockets.cpp ****/ - -E int32_t TotalRead; -E int32_t TotalWritten; -E SocketIO normalSocketIO; - -/**** users.c ****/ - -E int32_t opcnt; -E uint32_t maxusercnt, usercnt; -E time_t maxusertime; - -E User *finduser(const Anope::string &nick); - -E User *do_nick(const Anope::string &source, const Anope::string &nick, const Anope::string &username, const Anope::string &host, const Anope::string &server, const Anope::string &realname, time_t ts, const Anope::string &ip, const Anope::string &vhost, const Anope::string &uid, const Anope::string &modes); - -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 Anope::string create_mask(User *u); - #endif /* EXTERN_H */ diff --git a/include/hashcomp.h b/include/hashcomp.h index 3ed90d5cb..0a9df7139 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -13,21 +13,10 @@ #ifndef HASHCOMP_H #define HASHCOMP_H -#ifdef _WIN32 -# ifdef MODULE_COMPILE -# define CoreExport __declspec(dllimport) -# define DllExport __declspec(dllexport) -# else -# define CoreExport __declspec(dllexport) -# define DllExport __declspec(dllimport) -# endif -#else -# define CoreExport -# define DllExport -#endif - #include +#include "services.h" + namespace Anope { class string; diff --git a/include/lists.h b/include/lists.h new file mode 100644 index 000000000..308080c93 --- /dev/null +++ b/include/lists.h @@ -0,0 +1,94 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#ifndef LISTS_H +#define LISTS_H + +#include "services.h" +#include "anope.h" + +/** A class to process numbered lists (passed to most DEL/LIST/VIEW commands). + * The function HandleNumber is called for every number in the list. Note that + * if descending is true it gets called in descending order. This is so deleting + * the index passed to the function from an array will not cause the other indexes + * passed to the function to be incorrect. This keeps us from having to have an + * 'in use' flag on everything. + */ +class CoreExport NumberList +{ + private: + bool is_valid; + + std::set numbers; + + bool desc; + public: + /** Processes a numbered list + * @param list The list + * @param descending True to make HandleNumber get called with numbers in descending order + */ + NumberList(const Anope::string &list, bool descending); + + /** Destructor, does nothing + */ + virtual ~NumberList(); + + /** Should be called after the constructors are done running. This calls the callbacks. + */ + void Process(); + + /** Called with a number from the list + * @param Number The number + */ + virtual void HandleNumber(unsigned Number); + + /** Called when there is an error with the numbered list + * Return false to immediatly stop processing the list and return + * This is all done before we start calling HandleNumber, so no numbers will have been processed yet + * @param list The list + * @return false to stop processing + */ + virtual bool InvalidRange(const Anope::string &list); +}; + +/** This class handles formatting LIST/VIEW replies. + */ +class CoreExport ListFormatter +{ + public: + typedef std::map ListEntry; + private: + std::vector columns; + std::vector entries; + public: + ListFormatter &addColumn(const Anope::string &name); + void addEntry(const ListEntry &entry); + bool isEmpty() const; + void Process(std::vector &); +}; + +/** This class handles formatting INFO replies + */ +class CoreExport InfoFormatter +{ + User *user; + std::vector > replies; + unsigned longest; + public: + InfoFormatter(User *u); + void Process(std::vector &); + Anope::string &operator[](const Anope::string &key); +}; + +#endif // LISTS_H + diff --git a/include/logger.h b/include/logger.h index 3ba93a1e9..a6e3ca113 100644 --- a/include/logger.h +++ b/include/logger.h @@ -1,6 +1,21 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + */ + #ifndef LOGGER_H #define LOGGER_H +#include "anope.h" +#include "defs.h" + enum LogType { LOG_ADMIN, @@ -29,7 +44,6 @@ struct LogFile Anope::string GetName() const; }; -class Command; class CoreExport Log { diff --git a/include/mail.h b/include/mail.h index 31f35d92d..06cfe4b39 100644 --- a/include/mail.h +++ b/include/mail.h @@ -1,7 +1,22 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + #ifndef MAIL_H #define MAIL_H #include "anope.h" +#include "threadengine.h" + extern CoreExport bool Mail(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message); extern CoreExport bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message); diff --git a/include/memo.h b/include/memo.h new file mode 100644 index 000000000..a6df46861 --- /dev/null +++ b/include/memo.h @@ -0,0 +1,63 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#ifndef MEMO_H +#define MEMO_H + +#include "anope.h" +#include "serialize.h" + +/** Memo Flags + */ +enum MemoFlag +{ + /* Memo is unread */ + MF_UNREAD, + /* Sender requests a receipt */ + MF_RECEIPT +}; + +const Anope::string MemoFlagStrings[] = { + "MF_UNREAD", "MF_RECEIPT", "" +}; + +/* Memo info structures. Since both nicknames and channels can have memos, + * we encapsulate memo data in a MemoList to make it easier to handle. */ +class CoreExport Memo : public Flags, public Serializable +{ + public: + Memo(); + + Anope::string serialize_name() const; + serialized_data serialize(); + static void unserialize(serialized_data &); + + Anope::string owner; + time_t time; /* When it was sent */ + Anope::string sender; + Anope::string text; +}; + +struct CoreExport MemoInfo +{ + int16_t memomax; + std::vector memos; + std::vector ignores; + + unsigned GetIndex(Memo *m) const; + void Del(unsigned index); + void Del(Memo *m); + bool HasIgnore(User *u); +}; + +#endif // MEMO_H diff --git a/include/modes.h b/include/modes.h index 2743a23a6..b1195d27d 100644 --- a/include/modes.h +++ b/include/modes.h @@ -9,6 +9,9 @@ #ifndef MODES_H #define MODES_H +#include "anope.h" +#include "base.h" + /** All of the valid user mode names */ enum UserModeName @@ -375,16 +378,6 @@ class StackerInfo class CoreExport ModeManager { protected: - class ModePipe : public Pipe - { - public: - /** Called when there are modes to be set - */ - void OnNotify(); - }; - - static ModePipe *mpipe; - /* List of pairs of user/channels and their stacker info */ static std::list > StackerObjects; @@ -497,4 +490,48 @@ class CoreExport ModeManager static void StackerDel(Base *b); }; +/** Entry flags + */ +enum EntryType +{ + ENTRYTYPE_NONE, + ENTRYTYPE_CIDR, + ENTRYTYPE_NICK_WILD, + ENTRYTYPE_NICK, + ENTRYTYPE_USER_WILD, + ENTRYTYPE_USER, + ENTRYTYPE_HOST_WILD, + ENTRYTYPE_HOST +}; + +/** Represents a mask set on a channel (b/e/I) + */ +class CoreExport Entry : public Flags +{ + ChannelModeName modename; + + public: + unsigned char cidr_len; + Anope::string mask; + Anope::string nick, user, host; + + /** Constructor + * @param _host A full nick!ident@host/cidr mask + * @param mode What mode this host is for - can be CMODE_BEGIN for unknown/no mode + */ + Entry(ChannelModeName mode, const Anope::string &_host); + + /** Get the banned mask for this entry + * @return The mask + */ + const Anope::string GetMask(); + + /** Check if this entry matches a user + * @param u The user + * @param full True to match against a users real host and IP + * @return true on match + */ + bool Matches(User *u, bool full = false) const; +}; + #endif // MODES_H diff --git a/include/module.h b/include/module.h index 6435f9b7f..02f0e61c4 100644 --- a/include/module.h +++ b/include/module.h @@ -1,9 +1,57 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + #ifndef MODULE_H #define MODULE_H -#include "services.h" +/* Just include everything for now */ +#include "access.h" +#include "account.h" +#include "anope.h" +#include "base.h" +#include "bots.h" +#include "botserv.h" +#include "channels.h" +#include "commands.h" +#include "config.h" +#include "dns.h" +#include "extensible.h" +#include "extern.h" +#include "hashcomp.h" +#include "language.h" +#include "lists.h" +#include "logger.h" +#include "mail.h" +#include "memo.h" +#include "modes.h" #include "modules.h" #include "oper.h" -#include "commands.h" +#include "opertype.h" +#include "protocol.h" +#include "pstdint.h" +#include "regchannel.h" +#include "serialize.h" +#include "servers.h" +#include "service.h" +#include "services.h" +#include "signals.h" +#include "socketengine.h" +#include "sockets.h" +#include "threadengine.h" +#include "timers.h" +#include "uplink.h" +#include "users.h" + +#include "global.h" +#include "memoserv.h" +#include "nickserv.h" #endif // MODULE_H diff --git a/include/modules.h b/include/modules.h index d251be353..722526382 100644 --- a/include/modules.h +++ b/include/modules.h @@ -12,20 +12,43 @@ #ifndef MODULES_H #define MODULES_H -#include -#include "services.h" -#include +#include "extensible.h" +#include "base.h" +#include "modes.h" #include "timers.h" -#include "hashcomp.h" +#include "logger.h" -/** Possible return types from events. +/** This definition is used as shorthand for the various classes + * and functions needed to make a module loadable by the OS. + * It defines the class factory and external AnopeInit and AnopeFini functions. */ -enum EventReturn -{ - EVENT_STOP, - EVENT_CONTINUE, - EVENT_ALLOW -}; +#ifdef _WIN32 +# define MODULE_INIT(x) \ + extern "C" DllExport Module *AnopeInit(const Anope::string &, const Anope::string &); \ + extern "C" Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ + { \ + return new x(modname, creator); \ + } \ + BOOLEAN WINAPI DllMain(HINSTANCE, DWORD nReason, LPVOID) \ + { \ + return TRUE; \ + } \ + extern "C" DllExport void AnopeFini(x *); \ + extern "C" void AnopeFini(x *m) \ + { \ + delete m; \ + } +#else +# define MODULE_INIT(x) \ + extern "C" DllExport Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ + { \ + return new x(modname, creator); \ + } \ + extern "C" DllExport void AnopeFini(x *m) \ + { \ + delete m; \ + } +#endif /** * This #define allows us to call a method in all @@ -35,8 +58,8 @@ enum EventReturn #define FOREACH_MOD(y, x) \ if (true) \ { \ - std::vector::iterator safei; \ - for (std::vector::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \ + std::vector::iterator safei; \ + for (std::vector::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \ { \ safei = _i; \ ++safei; \ @@ -62,9 +85,9 @@ else \ #define FOREACH_RESULT(y, x) \ if (true) \ { \ - std::vector::iterator safei; \ + std::vector::iterator safei; \ MOD_RESULT = EVENT_CONTINUE; \ - for (std::vector::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \ + for (std::vector::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \ { \ safei = _i; \ ++safei; \ @@ -86,24 +109,15 @@ if (true) \ else \ static_cast(0) -#ifndef _WIN32 -# include - /* Define these for systems without them */ -# ifndef RTLD_NOW -# define RTLD_NOW 0 -# endif -# ifndef RTLD_LAZY -# define RTLD_LAZY RTLD_NOW -# endif -# ifndef RTLD_GLOBAL -# define RTLD_GLOBAL 0 -# endif -# ifndef RTLD_LOCAL -# define RTLD_LOCAL 0 -# endif -#endif +/** Possible return types from events. + */ +enum EventReturn +{ + EVENT_STOP, + EVENT_CONTINUE, + EVENT_ALLOW +}; -class Message; enum ModuleReturn { @@ -127,10 +141,10 @@ enum ModType { MT_BEGIN, THIRD, SUPPORTED, CORE, DATABASE, ENCRYPTION, PROTOCOL, typedef std::multimap message_map; extern CoreExport message_map MessageMap; -class Module; + extern CoreExport std::list Modules; -class Version +class ModuleVersion { private: int Major; @@ -143,11 +157,11 @@ class Version * @param vMinor The minor version numbber * @param vBuild The build version numbber */ - Version(int vMajor, int vMinor, int vBuild); + ModuleVersion(int vMajor, int vMinor, int vBuild); /** Destructor */ - virtual ~Version(); + virtual ~ModuleVersion(); /** Get the major version of Anope this was built against * @return The major version @@ -165,9 +179,6 @@ class Version int GetBuild() const; }; -class CallBack; -class XLineManager; -struct CommandSource; /** Every module in Anope is actually a class. */ @@ -247,7 +258,7 @@ class CoreExport Module : public Extensible * compiled against * @return The version */ - Version GetVersion() const; + ModuleVersion GetVersion() const; /** Called when the ircd notifies that a user has been kicked from a channel. * @param c The channel the user has been kicked from. @@ -1110,50 +1121,9 @@ class CallBack : public Timer private: Module *m; public: - CallBack(Module *mod, long time_from_now, time_t now = Anope::CurTime, bool repeating = false) : Timer(time_from_now, now, repeating), m(mod) - { - m->CallBacks.push_back(this); - } - - virtual ~CallBack() - { - std::list::iterator it = std::find(m->CallBacks.begin(), m->CallBacks.end(), this); - if (it != m->CallBacks.end()) - m->CallBacks.erase(it); - } -}; - -template -class service_reference : public dynamic_reference -{ - Anope::string type; - Anope::string name; - - public: - service_reference(const Anope::string &t, const Anope::string &n) : dynamic_reference(NULL), type(t), name(n) - { - } + CallBack(Module *mod, long time_from_now, time_t now = Anope::CurTime, bool repeating = false); - inline void operator=(const Anope::string &n) - { - this->name = n; - } - - operator bool() - { - if (this->invalid) - { - this->invalid = false; - this->ref = NULL; - } - if (!this->ref) - { - this->ref = static_cast(Service::FindService(this->type, this->name)); - if (this->ref) - this->ref->AddReference(this); - } - return this->ref; - } + virtual ~CallBack(); }; class CoreExport Message diff --git a/include/oper.h b/include/oper.h index 1a82a8530..ced1d38dc 100644 --- a/include/oper.h +++ b/include/oper.h @@ -9,7 +9,8 @@ #ifndef OPER_H #define OPER_H -class XLineManager; +#include "serialize.h" +#include "service.h" class CoreExport XLine : public Serializable { @@ -29,7 +30,6 @@ class CoreExport XLine : public Serializable Anope::string GetNick() const; Anope::string GetUser() const; Anope::string GetHost() const; - sockaddrs GetIP() const; Anope::string serialize_name() const; serialized_data serialize(); diff --git a/include/opertype.h b/include/opertype.h index 93f3f0629..3f0b8d157 100644 --- a/include/opertype.h +++ b/include/opertype.h @@ -8,9 +8,8 @@ #ifndef OPERTYPE_H #define OPERTYPE_H -#include "hashcomp.h" - -class OperType; +#include "services.h" +#include "account.h" struct CoreExport Oper { diff --git a/include/protocol.h b/include/protocol.h new file mode 100644 index 000000000..f1bb9dbbe --- /dev/null +++ b/include/protocol.h @@ -0,0 +1,155 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#ifndef PROTOCOL_H +#define PROTOCOL_H + +#include "services.h" +#include "anope.h" + +/* Protocol tweaks */ + +struct IRCDVar +{ + const char *name; /* Name of the IRCd command */ + const char *pseudoclient_mode; /* Mode used by BotServ Bots */ + int svsnick; /* Supports SVSNICK */ + int vhost; /* Supports vhost */ + int snline; /* Supports SNline */ + int sqline; /* Supports SQline */ + int szline; /* Supports SZline */ + int join2msg; /* Join 2 Message */ + int chansqline; /* Supports Channel Sqlines */ + int quitonkill; /* IRCD sends QUIT when kill */ + int vident; /* Supports vidents */ + int svshold; /* Supports svshold */ + int tsonmode; /* Timestamp on mode changes */ + int omode; /* On the fly o:lines */ + int umode; /* change user modes */ + int knock_needs_i; /* Check if we needed +i when setting NOKNOCK */ + int svsmode_ucmode; /* Can remove User Channel Modes with SVSMODE */ + int sglineenforce; + int ts6; /* ircd is TS6 */ + const char *globaltldprefix; /* TLD prefix used for Global */ + unsigned maxmodes; /* Max modes to send per line */ + int certfp; /* IRCd sends a SSL users certificate fingerprint */ +}; + + +class CoreExport IRCDProto +{ + private: + virtual void SendSVSKillInternal(const BotInfo *, const User *, const Anope::string &) = 0; + virtual void SendModeInternal(const BotInfo *, const Channel *, const Anope::string &) = 0; + virtual void SendModeInternal(const BotInfo *, const User *, const Anope::string &) = 0; + virtual void SendKickInternal(const BotInfo *, const Channel *, const User *, const Anope::string &) = 0; + virtual void SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); + virtual void SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg); + virtual void SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); + virtual void SendQuitInternal(const User *u, const Anope::string &buf); + virtual void SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf); + virtual void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf); + virtual void SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); + virtual void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf); + public: + virtual ~IRCDProto() { } + + virtual void SendSVSNOOP(const Server *, bool) { } + virtual void SendTopic(BotInfo *, Channel *) = 0; + virtual void SendVhostDel(User *) { } + virtual void SendAkill(User *, const XLine *) = 0; + virtual void SendAkillDel(const XLine *) = 0; + virtual void SendSVSKill(const BotInfo *source, const User *user, const char *fmt, ...); + virtual void SendMode(const BotInfo *bi, const Channel *dest, const char *fmt, ...); + virtual void SendMode(const BotInfo *bi, const User *u, const char *fmt, ...); + virtual void SendClientIntroduction(const User *u) = 0; + virtual void SendKick(const BotInfo *bi, const Channel *chan, const User *user, const char *fmt, ...); + virtual void SendMessage(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendNotice(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendAction(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendPrivmsg(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg); + virtual void SendGlobalPrivmsg(const BotInfo *bi, const Server *desc, const Anope::string &msg); + + virtual void SendQuit(const User *u, const char *fmt, ...); + virtual void SendPing(const Anope::string &servname, const Anope::string &who); + virtual void SendPong(const Anope::string &servname, const Anope::string &who); + virtual void SendJoin(User *, Channel *, const ChannelStatus *) = 0; + virtual void SendSQLineDel(const XLine *x) { } + virtual void SendInvite(const BotInfo *bi, const Anope::string &chan, const Anope::string &nick); + virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...); + virtual void SendGlobops(const BotInfo *source, const char *fmt, ...); + virtual void SendSQLine(User *, const XLine *x) { } + virtual void SendSquit(Server *, const Anope::string &message); + virtual void SendSVSO(const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick); + virtual void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when); + virtual void SendVhost(User *, const Anope::string &, const Anope::string &) { } + virtual void SendConnect() = 0; + virtual void SendSVSHold(const Anope::string &) { } + virtual void SendSVSHoldDel(const Anope::string &) { } + virtual void SendSGLineDel(const XLine *) { } + virtual void SendSZLineDel(const XLine *) { } + virtual void SendSZLine(User *u, const XLine *) { } + virtual void SendSGLine(User *, const XLine *) { } + virtual void SendCTCP(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); + virtual void SendSVSJoin(const Anope::string &, const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendSWhois(const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendBOB() { } + virtual void SendEOB() { } + virtual void SendServer(const Server *) = 0; + virtual bool IsNickValid(const Anope::string &) { return true; } + virtual bool IsChannelValid(const Anope::string &); + virtual void SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...); + virtual void SendLogin(User *u) = 0; + virtual void SendLogout(User *u) = 0; + + /** Send a channel creation message to the uplink. + * On most TS6 IRCds this is a SJOIN with no nick + */ + virtual void SendChannel(Channel *c) { } +}; + +class CoreExport IRCdMessage +{ + public: + virtual bool On436(const Anope::string &, const std::vector &); + virtual bool OnAway(const Anope::string &, const std::vector &); + virtual bool OnJoin(const Anope::string &, const std::vector &); + virtual bool OnKick(const Anope::string &, const std::vector &); + virtual bool OnKill(const Anope::string &, const std::vector &); + virtual bool OnMode(const Anope::string &, const std::vector &) = 0; + virtual bool OnUID(const Anope::string &, const std::vector &); + virtual bool OnNick(const Anope::string &, const std::vector &) = 0; + virtual bool OnPart(const Anope::string &, const std::vector &); + virtual bool OnPing(const Anope::string &, const std::vector &); + virtual bool OnPrivmsg(const Anope::string &, const std::vector &); + virtual bool OnQuit(const Anope::string &, const std::vector &); + virtual bool OnServer(const Anope::string &, const std::vector &) = 0; + virtual bool OnSQuit(const Anope::string &, const std::vector &); + virtual bool OnTopic(const Anope::string &, const std::vector &) = 0; + virtual bool OnWhois(const Anope::string &, const std::vector &); + virtual bool OnCapab(const Anope::string &, const std::vector &); + virtual bool OnSJoin(const Anope::string &, const std::vector &) = 0; + virtual bool OnError(const Anope::string &, const std::vector &); +}; + +extern IRCDVar *ircd; +extern IRCDProto *ircdproto; +extern IRCdMessage *ircdmessage; + +extern void pmodule_ircd_proto(IRCDProto *); +extern void pmodule_ircd_var(IRCDVar *ircdvar); +extern void pmodule_ircd_message(IRCdMessage *message); + +#endif // PROTOCOL_H diff --git a/include/regchannel.h b/include/regchannel.h index 0cd890402..614b98f19 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -9,6 +9,13 @@ #ifndef REGCHANNEL_H #define REGCHANNEL_H +#include "botserv.h" +#include "memo.h" +#include "modes.h" +#include "extensible.h" +#include "logger.h" +#include "modules.h" + typedef Anope::insensitive_map registered_channel_map; extern CoreExport registered_channel_map RegisteredChannelList; @@ -429,25 +436,11 @@ class CoreExport ChannelInfo : public Extensible, public Flags c; - - public: - /** Default constructor - * @param chan The channel - */ - ChanServTimer(Channel *chan); - - /** Called when the delay is up - * @param The current time - */ - void Tick(time_t); -}; +extern void check_modes(Channel *c); +extern ChannelInfo *cs_findchan(const Anope::string &chan); +extern bool IsFounder(User *user, ChannelInfo *ci); +extern void update_cs_lastseen(User *user, ChannelInfo *ci); +extern int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret); #endif // REGCHANNEL_H diff --git a/include/resource.h b/include/resource.h deleted file mode 100644 index cccb0b4f5..000000000 --- a/include/resource.h +++ /dev/null @@ -1,20 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by Win32GUI.rc -// -#define VER_ANOPE 1 -#define MANIFEST_RESOURCE_ID 2 -#define ICON_APP 129 - - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 152 -#define _APS_NEXT_COMMAND_VALUE 40061 -#define _APS_NEXT_CONTROL_VALUE 1167 -#define _APS_NEXT_SYMED_VALUE 104 -#endif -#endif diff --git a/include/serialize.h b/include/serialize.h index 752f26bfa..891af726f 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -1,6 +1,22 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + */ + #ifndef SERIALIZE_H #define SERIALIZE_H +#include + +#include "anope.h" + namespace Serialize { enum DataType @@ -8,58 +24,34 @@ namespace Serialize DT_TEXT, DT_INT }; +} + +class stringstream : public std::stringstream +{ + private: + Serialize::DataType type; + bool key; + unsigned _max; - class stringstream : public std::stringstream + public: + stringstream(); + stringstream(const stringstream &ss); + Anope::string astr() const; + template std::istream &operator>>(T &val) { - private: - DataType type; - bool key; - unsigned _max; - - public: - stringstream() : std::stringstream(), type(DT_TEXT), key(false), _max(0) { } - stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(DT_TEXT), key(false), _max(0) { } - Anope::string astr() const { return this->str(); } - template std::istream &operator>>(T &val) - { - std::istringstream is(this->str()); - is >> val; - return *this; - } - std::istream &operator>>(Anope::string &val) - { - val = this->str(); - return *this; - } - stringstream &setType(DataType t) - { - this->type = t; - return *this; - } - DataType getType() const - { - return this->type; - } - stringstream &setKey() - { - this->key = true; - return *this; - } - bool getKey() const - { - return this->key; - } - stringstream &setMax(unsigned m) - { - this->_max = m; - return *this; - } - unsigned getMax() const - { - return this->_max; - } - }; -} + std::istringstream is(this->str()); + is >> val; + return *this; + } + std::istream &operator>>(Anope::string &val); + stringstream &setType(Serialize::DataType t); + Serialize::DataType getType() const; + stringstream &setKey(); + bool getKey() const; + stringstream &setMax(unsigned m); + unsigned getMax() const; +}; + extern void RegisterTypes(); @@ -71,40 +63,20 @@ class CoreExport Serializable std::list::iterator s_iter; protected: - Serializable() - { - if (serizliable_items == NULL) - serizliable_items = new std::list(); - serizliable_items->push_front(this); - this->s_iter = serizliable_items->begin(); - } + Serializable(); + Serializable(const Serializable &); - Serializable(const Serializable &) - { - serizliable_items->push_front(this); - this->s_iter = serizliable_items->begin(); - } + v