summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-02-14 15:13:27 -0500
committerAdam <Adam@anope.org>2012-02-14 15:13:27 -0500
commita9772cde21407c89abd161d51aff45267f87b1fb (patch)
tree9e57ba6c121d3843888917d968dd4f5d030b57cf /include
parent086790d6331357022f4da17c76b26b9fc6e2ad90 (diff)
Clean up and reorganize our header files
Diffstat (limited to 'include')
-rw-r--r--include/CMakeLists.txt26
-rw-r--r--include/access.h19
-rw-r--r--include/account.h129
-rw-r--r--include/anope.h288
-rw-r--r--include/base.h106
-rw-r--r--include/bots.h11
-rw-r--r--include/botserv.h79
-rw-r--r--include/channels.h22
-rw-r--r--include/commands.h7
-rw-r--r--include/config.h51
-rw-r--r--include/defs.h52
-rw-r--r--include/dns.h21
-rw-r--r--include/extensible.h3
-rw-r--r--include/extern.h98
-rw-r--r--include/hashcomp.h15
-rw-r--r--include/lists.h94
-rw-r--r--include/logger.h16
-rw-r--r--include/mail.h15
-rw-r--r--include/memo.h63
-rw-r--r--include/modes.h57
-rw-r--r--include/module.h52
-rw-r--r--include/modules.h136
-rw-r--r--include/oper.h4
-rw-r--r--include/opertype.h5
-rw-r--r--include/protocol.h155
-rw-r--r--include/regchannel.h31
-rw-r--r--include/resource.h20
-rw-r--r--include/serialize.h162
-rw-r--r--include/servers.h3
-rw-r--r--include/service.h110
-rw-r--r--include/services.h913
-rw-r--r--include/signals.h49
-rw-r--r--include/socketengine.h2
-rw-r--r--include/sockets.h12
-rw-r--r--include/threadengine.h3
-rw-r--r--include/timers.h10
-rw-r--r--include/uplink.h44
-rw-r--r--include/users.h24
38 files changed, 1476 insertions, 1431 deletions
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 *> nickalias_map;
typedef Anope::insensitive_map<NickCore *> 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<NickNameFlag, NS_END>, public Serializable
+class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNameFlag, NS_END>, 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<NickNameFlag, NS_EN
time_t time_registered; /* When the nick was registered */
time_t last_seen; /* When it was seen online for the last time */
NickCore *nc; /* I'm an alias of this */
- HostInfo hostinfo;
Anope::string serialize_name() const;
serialized_data serialize();
@@ -131,9 +147,46 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_EN
* @param u The user
*/
void OnCancel(User *u);
+
+ /** Set a vhost for the user
+ * @param ident The ident
+ * @param host The host
+ * @param creator Who created the vhost
+ * @param time When the vhost was craated
+ */
+ void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime);
+
+ /** Remove a users vhost
+ **/
+ void RemoveVhost();
+
+ /** Check if the user has a vhost
+ * @return true or false
+ */
+ bool HasVhost() const;
+
+ /** Retrieve the vhost ident
+ * @return the ident
+ */
+ const Anope::string &GetVhostIdent() const;
+
+ /** Retrieve the vhost host
+ * @return the host
+ */
+ const Anope::string &GetVhostHost() const;
+
+ /** Retrieve the vhost creator
+ * @return the creator
+ */
+ const Anope::string &GetVhostCreator() const;
+
+ /** Retrieve when the vhost was created
+ * @return the time it was created
+ */
+ time_t GetVhostCreated() const;
};
-class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END>, public Serializable
+class CoreExport NickCore : public Base, public Extensible, public Flags<NickCoreFlag, NI_END>, public Serializable
{
public:
/** Default constructor
@@ -254,65 +307,11 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END
};
-/** Timer for colliding nicks to force people off of nicknames
- */
-class CoreExport NickServCollide : public Timer
-{
- dynamic_reference<User> 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<NickAlias> 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 <string>
-#include <vector>
-#include <set>
#include "hashcomp.h"
-class Message;
-
namespace Anope
{
template<typename T> class map : public std::map<string, T> { };
@@ -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<dynamic_reference_base *> 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<typename T>
-class dynamic_reference : public dynamic_reference_base
+/** Convert something to a string
+ */
+template<typename T> inline Anope::string stringify(const T &x)
+{
+ std::ostringstream stream;
+
+ if (!(stream << x))
+ throw ConvertException("Stringify fail");
+
+ return stream.str();
+}
+
+template<typename T> 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<typename T> inline void convert(const Anope::string &s, T &x, bool failIfLeftoverChars = true)
+{
+ Anope::string Unused;
+ convert(s, x, Unused, failIfLeftoverChars);
+}
+
+template<typename T> inline T convertTo(const Anope::string &s, Anope::string &leftover, bool failIfLeftoverChars = true)
+{
+ T x;
+ convert(s, x, leftover, failIfLeftoverChars);
+ return x;
+}
+
+template<typename T> 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 <typeinfo>
+#endif
+template<typename T, typename O> inline T debug_cast(O ptr)
+{
+#ifdef DEBUG_BUILD
+ T ret = dynamic_cast<T>(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<T>(ptr);
+#endif
+}
+
+/*************************************************************************/
+
+/** Class with the ability to keep flags on items, they should extend from this
+ * where T is an enum.
+ */
+template<typename T, size_t Size = 32> class Flags
{
protected:
- T *ref;
+ std::bitset<Size> 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<T> &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<Anope::string> 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<Anope::string> v;
+
+ while (sep.GetToken(buf))
+ v.push_back(buf);
+
+ FromVector(v);
+ }
+
+ std::vector<Anope::string> ToVector()
+ {
+ std::vector<Anope::string> ret;
+ for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i)
+ if (this->HasFlag(static_cast<T>(i)))
+ ret.push_back(this->Flag_Strings[i]);
+ return ret;
+ }
+
+ void FromVector(const std::vector<Anope::string> &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<T>(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 <Adam@anope.org>
+ * Copyright (C) 2008-2012 Anope Team <team@anope.org>
+ *
+ * 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<dynamic_reference_base *> 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<typename T>
+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<T> &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<BotInfo *> BotListByNick;
extern CoreExport Anope::map<BotInfo *> BotListByUID;
@@ -123,4 +127,9 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, 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 *> 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<ChannelFlag, 3>
+class CoreExport Channel : public Base, public Extensible, public Flags<ChannelFlag, 3>
{
public:
typedef std::multimap<ChannelModeName, Anope::string> ModeList;
@@ -229,6 +234,21 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlag, 3>
* @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 <string>
-#include <fstream>
-#include <sstream>
-#include <vector>
-#include <map>
-#include <deque>
-
-#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<KeyVal> KeyValList;
typedef std::multimap<Anope::string, KeyValList> 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<ExtensibleItem *> 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<Anope::string> languages;
E std::vector<Anope::string> 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<typename T> 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<ChannelModeName, ModeLock> 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 <string>
+#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<unsigned> 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<Anope::string, Anope::string> ListEntry;
+ private:
+ std::vector<Anope::string> columns;
+ std::vector<ListEntry> entries;
+ public:
+ ListFormatter &addColumn(const Anope::string &name);
+ void addEntry(const ListEntry &entry);
+ bool isEmpty() const;
+ void Process(std::vector<Anope::string> &);
+};
+
+/** This class handles formatting INFO replies
+ */
+class CoreExport InfoFormatter
+{
+ User *user;
+ std::vector<std::pair<Anope::string, Anope::string> > replies;
+ unsigned longest;
+ public:
+ InfoFormatter(User *u);
+ void Process(std::vector<Anope::string> &);
+ 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<MemoFlag>, 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<Memo *> memos;
+ std::vector<Anope::string> 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<std::pair<Base *, StackerInfo *> > 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<EntryType>
+{
+ 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 <time.h>
-#include "services.h"
-#include <stdio.h>
+#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<Module*>::iterator safei; \
- for (std::vector<Module*>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \
+ std::vector<Module *>::iterator safei; \
+ for (std::vector<Module *>::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<Module*>::iterator safei; \
+ std::vector<Module *>::iterator safei; \
MOD_RESULT = EVENT_CONTINUE; \
- for (std::vector<Module*>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \
+ for (std::vector<Module *>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \
{ \
safei = _i; \
++safei; \
@@ -86,24 +109,15 @@ if (true) \
else \
static_cast<void>(0)
-#ifndef _WIN32
-# include <dlfcn.h>
- /* 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<Anope::string, Message *> message_map;
extern CoreExport message_map MessageMap;
-class Module;
+
extern CoreExport std::list<Module *> 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<CallBack *>::iterator it = std::find(m->CallBacks.begin(), m->CallBacks.end(), this);
- if (it != m->CallBacks.end())
- m->CallBacks.erase(it);
- }
-};
-
-template<typename T>
-class service_reference : public dynamic_reference<T>
-{
- Anope::string type;
- Anope::string name;
-
- public:
- service_reference(const Anope::string &t, const Anope::string &n) : dynamic_reference<T>(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<T *>(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<Anope::string> &);
+ virtual bool OnAway(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnJoin(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnKick(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnKill(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnMode(const Anope::string &, const std::vector<Anope::string> &) = 0;
+ virtual bool OnUID(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnNick(const Anope::string &, const std::vector<Anope::string> &) = 0;
+ virtual bool OnPart(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnPing(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnPrivmsg(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnQuit(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnServer(const Anope::string &, const std::vector<Anope::string> &) = 0;
+ virtual bool OnSQuit(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnTopic(const Anope::string &, const std::vector<Anope::string> &) = 0;
+ virtual bool OnWhois(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnCapab(const Anope::string &, const std::vector<Anope::string> &);
+ virtual bool OnSJoin(const Anope::string &, const std::vector<Anope::string> &) = 0;
+ virtual bool OnError(const Anope::string &, const std::vector<Anope::string> &);
+};
+
+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<ChannelInfo *> registered_channel_map;
extern CoreExport registered_channel_map RegisteredChannelList;
@@ -429,25 +436,11 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
void ClearLevels();
};
-/** 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
-{
- private:
- dynamic_reference<Channel> 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 <sstream>
+
+#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<typename T> 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<typename T> 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<Serializable *>::iterator s_iter;
protected:
- Serializable()
- {
- if (serizliable_items == NULL)
- serizliable_items = new std::list<Serializable *>();
- 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();
- }
+ virtual ~Serializable();
- virtual ~Serializable()
- {
- serizliable_items->erase(this->s_iter);
- }
-
- Serializable &operator=(const Serializable &)
- {
- return *this;
- }
+ Serializable &operator=(const Serializable &);
public:
- typedef std::map<Anope::string, Serialize::stringstream> serialized_data;
+ typedef std::map<Anope::string, stringstream> serialized_data;
virtual Anope::string serialize_name() const = 0;
virtual serialized_data serialize() = 0;
- static const std::list<Serializable *> &GetItems()
- {
- return *serizliable_items;
- }
+ static const std::list<Serializable *> &GetItems();
};
class CoreExport SerializeType
@@ -118,42 +90,16 @@ class CoreExport SerializeType
unserialize_func unserialize;
public:
- SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f)
- {
- type_order.push_back(this->name);
- types[this->name] = this;
- }
+ SerializeType(const Anope::string &n, unserialize_func f);
+ ~SerializeType();
- ~SerializeType()
- {
- std::vector<Anope::string>::iterator it = std::find(type_order.begin(), type_order.end(), this->name);
- if (it != type_order.end())
- type_order.erase(it);
- types.erase(this->name);
- }
+ const Anope::string &GetName();
- const Anope::string &GetName()
- {
- return this->name;
- }
+ void Create(Serializable::serialized_data &data);
- void Create(Serializable::serialized_data &data)
- {
- this->unserialize(data);
- }
+ static SerializeType *Find(const Anope::string &name);
- static SerializeType *Find(const Anope::string &name)
- {
- Anope::map<SerializeType *>::iterator it = types.find(name);
- if (it != types.end())
- return it->second;
- return NULL;
- }
-
- static const std::vector<Anope::string> &GetTypeOrder()
- {
- return type_order;
- }
+ static const std::vector<Anope::string> &GetTypeOrder();
};
#endif // SERIALIZE_H
diff --git a/include/servers.h b/include/servers.h
index acdbfaa06..c2e56dbde 100644
--- a/include/servers.h
+++ b/include/servers.h
@@ -1,6 +1,9 @@
#ifndef SERVERS_H
#define SERVERS_H
+#include "services.h"
+#include "anope.h"
+
/* Anope */
extern CoreExport Server *Me;
diff --git a/include/service.h b/include/service.h
new file mode 100644
index 000000000..f9e36ff40
--- /dev/null
+++ b/include/service.h
@@ -0,0 +1,110 @@
+/*
+ * (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 SERVICE_H
+#define SERVICE_H
+
+#include "services.h"
+#include "anope.h"
+#include "modules.h"
+
+class CoreExport Service : public Base
+{
+ static Anope::map<Anope::map<Service *> > services;
+ public:
+ static Service *FindService(const Anope::string &t, const Anope::string &n)
+ {
+ Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
+ if (it != services.end())
+ {
+ Anope::map<Service *>::iterator it2 = it->second.find(n);
+ if (it2 != it->second.end())
+ return it2->second;
+ }
+
+ return NULL;
+ }
+
+ static std::vector<Anope::string> GetServiceKeys(const Anope::string &t)
+ {
+ std::vector<Anope::string> keys;
+ Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
+ if (it != services.end())
+ for (Anope::map<Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
+ keys.push_back(it2->first);
+ return keys;
+ }
+
+ Module *owner;
+ Anope::string type;
+ Anope::string name;
+
+ Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n)
+ {
+ this->Register();
+ }
+
+ virtual ~Service()
+ {
+ this->Unregister();
+ }
+
+ void Register()
+ {
+ Anope::map<Service *> &smap = services[this->type];
+ if (smap.find(this->name) != smap.end())
+ throw ModuleException("Service " + this->type + " with name " + this->name + " already exists");
+ smap[this->name] = this;
+ }
+
+ void Unregister()
+ {
+ Anope::map<Service *> &smap = services[this->type];
+ smap.erase(this->name);
+ if (smap.empty())
+ services.erase(this->type);
+ }
+};
+
+template<typename T>
+class service_reference : public dynamic_reference<T>
+{
+ Anope::string type;
+ Anope::string name;
+
+ public:
+ service_reference(const Anope::string &t, const Anope::string &n) : dynamic_reference<T>(NULL), type(t), name(n)
+ {
+ }
+
+ 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<T *>(Service::FindService(this->type, this->name));
+ if (this->ref)
+ this->ref->AddReference(this);
+ }
+ return this->ref;
+ }
+};
+
+#endif // SERVICE_H
+
diff --git a/include/services.h b/include/services.h
index 37b8df1ad..abe262cad 100644
--- a/include/services.h
+++ b/include/services.h
@@ -14,103 +14,24 @@
#ifndef SERVICES_H
#define SERVICES_H
-/*************************************************************************/
-
#include "sysconf.h"
#define BUFSIZE 1024
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstdarg>
#include <stdexcept>
-#include <string.h>
+#include <string.h>
#if HAVE_STRINGS_H
# include <strings.h>
#endif
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <limits.h>
-
-#include <sys/stat.h> /* for umask() on some systems */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <typeinfo>
-#include <ctype.h>
-
-#if GETTEXT_FOUND
-# include <libintl.h>
-#endif
-#define _(x) x
-
-#ifndef _WIN32
-# include <unistd.h>
-# include <grp.h>
-# include <netdb.h>
-# include <netinet/in.h>
-# include <arpa/inet.h>
-# include <sys/socket.h>
-# include <sys/time.h>
-# include <sys/wait.h>
-# include <dirent.h>
-# include <pthread.h>
-# define DllExport
-# define CoreExport
-# define MARK_DEPRECATED __attribute((deprecated))
-#else
-# include "anope_windows.h"
-#endif
-
-/* Telling compilers about printf()-like functions: */
-#ifdef __GNUC__
-# define FORMAT(type, fmt, start) __attribute__((format(type, fmt, start)))
-#else
-# define FORMAT(type, fmt, start)
-#endif
-
-/** 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.
- */
-#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
-
-/* Miscellaneous definitions. */
-#include "hashcomp.h"
-
/* Pull in the various bits of STL */
#include <iostream>
#include <fstream>
#include <sstream>
-#include <string>
#include <map>
#include <exception>
#include <list>
@@ -118,616 +39,19 @@
#include <deque>
#include <bitset>
#include <set>
+#include <algorithm>
-#include "anope.h"
-
-/** 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 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
-{
- public:
- FatalException(const Anope::string &reason = "") : CoreException(reason) { }
+#include "defs.h"
- virtual ~FatalException() throw() { }
-};
-
-class ModuleException : public CoreException
-{
- public:
- /** 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() { }
-};
+#define _(x) 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.
- */
-template<typename T, typename O> inline T debug_cast(O ptr)
-{
-#ifdef DEBUG_BUILD
- T ret = dynamic_cast<T>(ptr);
- if (ptr != NULL && ret == NULL)
- throw CoreException(Anope::string("debug_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail");
- return ret;
+#ifndef _WIN32
+# define DllExport
+# define CoreExport
+# define MARK_DEPRECATED __attribute((deprecated))
#else
- return static_cast<T>(ptr);
+# include "anope_windows.h"
#endif
-}
-
-/*************************************************************************/
-
-/** Class with the ability to keep flags on items, they should extend from this
- * where T is an enum.
- */
-template<typename T, size_t Size = 32> class Flags
-{
- protected:
- std::bitset<Size> Flag_Values;
- const Anope::string *Flag_Strings;
-
- public:
- 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)
- {
- Flag_Values[Value] = true;
- }
-
- /** Remove a flag from this item
- * @param Value The flag
- */
- void UnsetFlag(T Value)
- {
- Flag_Values[Value] = false;
- }
-
- /** Check if this item has a flag
- * @param Value The flag
- * @return true or false
- */
- bool HasFlag(T Value) const
- {
- return Flag_Values.test(Value);
- }
-
- /** Check how many flags are set
- * @return The number of flags set
- */
- size_t FlagCount() const
- {
- return Flag_Values.count();
- }
-
- /** Unset all of the flags
- */
- void ClearFlags()
- {
- Flag_Values.reset();
- }
-
- Anope::string ToString()
- {
- std::vector<Anope::string> v = ToVector();
- Anope::string flag_buf;
- for (unsigned i = 0; i < v.size(); ++i)
- flag_buf += v[i] + " ";
- flag_buf.trim();
- return flag_buf;
- }
-
- void FromString(const Anope::string &str)
- {
- spacesepstream sep(str);
- Anope::string buf;
- std::vector<Anope::string> v;
-
- while (sep.GetToken(buf))
- v.push_back(buf);
-
- FromVector(v);
- }
-
- std::vector<Anope::string> ToVector()
- {
- std::vector<Anope::string> ret;
- for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i)
- if (this->HasFlag(static_cast<T>(i)))
- ret.push_back(this->Flag_Strings[i]);
- return ret;
- }
-
- void FromVector(const std::vector<Anope::string> &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<T>(i));
- }
-};
-
-class Module;
-
-class CoreExport Service : public Base
-{
- static Anope::map<Anope::map<Service *> > services;
- public:
- static Service *FindService(const Anope::string &t, const Anope::string &n)
- {
- Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
- if (it != services.end())
- {
- Anope::map<Service *>::iterator it2 = it->second.find(n);
- if (it2 != it->second.end())
- return it2->second;
- }
-
- return NULL;
- }
-
- static std::vector<Anope::string> GetServiceKeys(const Anope::string &t)
- {
- std::vector<Anope::string> keys;
- Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
- if (it != services.end())
- for (Anope::map<Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
- keys.push_back(it2->first);
- return keys;
- }
-
- Module *owner;
- Anope::string type;
- Anope::string name;
-
- Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n)
- {
- this->Register();
- }
-
- virtual ~Service()
- {
- this->Unregister();
- }
-
- void Register()
- {
- Anope::map<Service *> &smap = services[this->type];
- if (smap.find(this->name) != smap.end())
- throw ModuleException("Service " + this->type + " with name " + this->name + " already exists");
- smap[this->name] = this;
- }
-
- void Unregister()
- {
- Anope::map<Service *> &smap = services[this->type];
- smap.erase(this->name);
- if (smap.empty())
- services.erase(this->type);
- }
-};
-
-#include "sockets.h"
-#include "socketengine.h"
-#include "extensible.h"
-#include "timers.h"
-#include "dns.h"
-
-/*************************************************************************/
-
-class Signal : public Pipe
-{
- static std::vector<Signal *> SignalHandlers;
- static void SignalHandler(int signal);
-
- struct sigaction action, old;
- public:
- int signal;
-
- Signal(int s);
- ~Signal();
-
- virtual void OnNotify() = 0;
-};
-
-class ConvertException : public CoreException
-{
- public:
- ConvertException(const Anope::string &reason = "") : CoreException(reason) { }
-
- virtual ~ConvertException() throw() { }
-};
-
-template<typename T> inline Anope::string stringify(const T &x)
-{
- std::ostringstream stream;
-
- if (!(stream << x))
- throw ConvertException("Stringify fail");
-
- return stream.str();
-}
-
-template<typename T> 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<typename T> inline void convert(const Anope::string &s, T &x, bool failIfLeftoverChars = true)
-{
- Anope::string Unused;
- convert(s, x, Unused, failIfLeftoverChars);
-}
-
-template<typename T> inline T convertTo(const Anope::string &s, Anope::string &leftover, bool failIfLeftoverChars = true)
-{
- T x;
- convert(s, x, leftover, failIfLeftoverChars);
- return x;
-}
-
-template<typename T> inline T convertTo(const Anope::string &s, bool failIfLeftoverChars = true)
-{
- T x;
- convert(s, x, failIfLeftoverChars);
- return x;
-}
-
-/*************************************************************************/
-
-class User;
-class NickCore;
-class NickAlias;
-class BotInfo;
-class ChannelInfo;
-class Channel;
-class Server;
-class Entry;
-
-#include "threadengine.h"
-#include "opertype.h"
-#include "modes.h"
-#include "serialize.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 */
-};
-
-/*************************************************************************/
-
-/** 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<MemoFlag>, 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<Memo *> memos;
- std::vector<Anope::string> ignores;
-
- unsigned GetIndex(Memo *m) const;
- void Del(unsigned index);
- void Del(Memo *m);
- bool HasIgnore(User *u);
-};
-
-struct Session
-{
- Anope::string host; /* Host of the session */
- unsigned count; /* Number of clients with this host */
- unsigned hits; /* Number of subsequent kills for a host */
-};
-
-struct Exception;
-
-/*************************************************************************/
-
-class CoreExport HostInfo
-{
- private:
- Anope::string Ident;
- Anope::string Host;
- Anope::string Creator;
- time_t Time;
-
- public:
- /** Set a vhost for the user
- * @param ident The ident
- * @param host The host
- * @param creator Who created the vhost
- * @param time When the vhost was craated
- */
- void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime);
-
- /** Remove a users vhost
- **/
- void RemoveVhost();
-
- /** Check if the user has a vhost
- * @return true or false
- */
- bool HasVhost() const;
-
- /** Retrieve the vhost ident
- * @return the ident
- */
- const Anope::string &GetIdent() const;
-
- /** Retrieve the vhost host
- * @return the host
- */
- const Anope::string &GetHost() const;
-
- /** Retrieve the vhost creator
- * @return the creator
- */
- const Anope::string &GetCreator() const;
-
- /** Retrieve when the vhost was crated
- * @return the time it was created
- */
- time_t GetTime() const;
-};
-
-/* 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
-};
-
-#include "access.h"
-#include "regchannel.h"
-
-/*************************************************************************/
-
-/* This structure stocks ban data since it must not be removed when
- * user is kicked.
- */
-
-#include "users.h"
-#include "account.h"
-#include "commands.h"
-#include "bots.h"
-#include "channels.h"
-
-/** Channelban type flags
- */
-enum EntryType
-{
- ENTRYTYPE_NONE,
- ENTRYTYPE_CIDR,
- ENTRYTYPE_NICK_WILD,
- ENTRYTYPE_NICK,
- ENTRYTYPE_USER_WILD,
- ENTRYTYPE_USER,
- ENTRYTYPE_HOST_WILD,
- ENTRYTYPE_HOST
-};
-
-class CoreExport Entry : public Flags<EntryType>
-{
- 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;
-};
-
-/*************************************************************************/
-
-/* Mail data */
-
-struct MailInfo
-{
- FILE *pipe;
- User *sender;
- NickCore *recipient;
-};
-
-/*************************************************************************/
-
-/* Defcon */
-
-/*************************************************************************/
/**
* RFC: defination of a valid nick
@@ -738,215 +62,4 @@ struct MailInfo
**/
#define isvalidnick(c) (isalnum(c) || ((c) >= '\x5B' && (c) <= '\x60') || ((c) >= '\x7B' && (c) <= '\x7D') || (c) == '-')
-/*************************************************************************/
-
-/*
- * Forward declaration reqired, because the base IRCDProto class uses some crap from in here.
- */
-class IRCDProto;
-class IRCdMessage;
-struct Uplink;
-class ServerConfig;
-class ConfigurationFile;
-class XLine;
-
-#include "extern.h"
-#include "language.h"
-#include "mail.h"
-#include "servers.h"
-#include "logger.h"
-#include "config.h"
-
-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<Anope::string> &);
- virtual bool OnAway(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnJoin(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnKick(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnKill(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnMode(const Anope::string &, const std::vector<Anope::string> &) = 0;
- virtual bool OnUID(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnNick(const Anope::string &, const std::vector<Anope::string> &) = 0;
- virtual bool OnPart(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnPing(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnPrivmsg(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnQuit(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnServer(const Anope::string &, const std::vector<Anope::string> &) = 0;
- virtual bool OnSQuit(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnTopic(const Anope::string &, const std::vector<Anope::string> &) = 0;
- virtual bool OnWhois(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnCapab(const Anope::string &, const std::vector<Anope::string> &);
- virtual bool OnSJoin(const Anope::string &, const std::vector<Anope::string> &) = 0;
- virtual bool OnError(const Anope::string &, const std::vector<Anope::string> &);
-};
-
-/*************************************************************************/
-
-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); }
-};
-
-/** 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<unsigned> 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);
-};
-
-class CoreExport ListFormatter
-{
- public:
- typedef std::map<Anope::string, Anope::string> ListEntry;
- private:
- std::vector<Anope::string> columns;
- std::vector<ListEntry> entries;
- public:
- ListFormatter &addColumn(const Anope::string &name);
- void addEntry(const ListEntry &entry);
- bool isEmpty() const;
- void Process(std::vector<Anope::string> &);
-};
-
-class CoreExport InfoFormatter
-{
- User *user;
- std::vector<std::pair<Anope::string, Anope::string> > replies;
- unsigned longest;
- public:
- InfoFormatter(User *u);
- void Process(std::vector<Anope::string> &);
- Anope::string &operator[](const Anope::string &key);
-};
-
-#endif /* SERVICES_H */
+#endif // SERVICES_H
diff --git a/include/signals.h b/include/signals.h
new file mode 100644
index 000000000..70fdead42
--- /dev/null
+++ b/include/signals.h
@@ -0,0 +1,49 @@
+/*
+ *
+ * (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 SIGNAL_H
+#define SIGNAL_H
+
+#include <signal.h>
+
+#include "sockets.h"
+
+/** Represents a signal handler
+ */
+class Signal : public Pipe
+{
+ static std::vector<Signal *> SignalHandlers;
+ static void SignalHandler(int signal);
+
+ struct sigaction action, old;
+ public:
+ int signal;
+
+ /** Constructor
+ * @param s The signal to listen for
+ */
+ Signal(int s);
+ ~Signal();
+
+ /**
+ * Called when the signal is received.
+ * Note this is not *immediatly* called when the signal is received,
+ * but it is saved and called at a later time when we are not doing something
+ * important. This is always called on the main thread, even on systems that
+ * spawn threads for signals, like Windows.
+ */
+ virtual void OnNotify() = 0;
+};
+
+#endif
+
diff --git a/include/socketengine.h b/include/socketengine.h
index 947f27327..0cffec6b3 100644
--- a/include/socketengine.h
+++ b/include/socketengine.h
@@ -12,6 +12,8 @@
#ifndef SOCKETENGINE_H
#define SOCKETENGINE_H
+#include "services.h"
+
class CoreExport SocketEngine
{
public:
diff --git a/include/sockets.h b/include/sockets.h
index 126bd3f8a..eb990fd4f 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -12,6 +12,8 @@
#ifndef SOCKETS_H
#define SOCKETS_H
+#include <netinet/in.h>
+
#include "anope.h"
#define NET_BUFSIZE 65535
@@ -26,7 +28,7 @@ union CoreExport sockaddrs
/** Construct the object, sets everything to 0
*/
- sockaddrs();
+ sockaddrs(const Anope::string &address = "");
/** Memset the object to 0
*/
@@ -112,10 +114,6 @@ enum SocketFlag
static const Anope::string SocketFlagStrings[] = { "SF_DEAD", "SF_WRITABLE", "SF_CONNECTING", "SF_CONNECTED", "SF_ACCEPTING", "SF_ACCEPTED", "" };
-class Socket;
-class ClientSocket;
-class ListenSocket;
-class ConnectionSocket;
class CoreExport SocketIO
{
@@ -475,4 +473,8 @@ class CoreExport Pipe : public Socket
virtual void OnNotify();
};
+extern uint32_t TotalRead;
+extern uint32_t TotalWritten;
+extern SocketIO normalSocketIO;
+
#endif // SOCKET_H
diff --git a/include/threadengine.h b/include/threadengine.h
index b840092d4..5d1752a8f 100644
--- a/include/threadengine.h
+++ b/include/threadengine.h
@@ -1,7 +1,8 @@
#ifndef THREADENGINE_H
#define THREADENGINE_H
-class Thread;
+#include "sockets.h"
+#include "extensible.h"
class CoreExport Thread : public Pipe, public Extensible
{
diff --git a/include/timers.h b/include/timers.h
index c51d778f2..d5fc66fb0 100644
--- a/include/timers.h
+++ b/include/timers.h
@@ -11,13 +11,9 @@
#ifndef TIMERS_H
#define TIMERS_H
-#include "services.h"
-#include <time.h>
-#include <algorithm>
-#include <stdio.h>
-#include <stdlib.h>
+#include "anope.h"
-class CoreExport Timer : public Extensible
+class CoreExport Timer
{
private:
/** The time this was created
@@ -88,7 +84,7 @@ class CoreExport Timer : public Extensible
* This will ensure timers are not missed, as well as removing timers that have
* expired and allowing the addition of new ones.
*/
-class CoreExport TimerManager : public Extensible
+class CoreExport TimerManager
{
/** A list of timers
*/
diff --git a/include/uplink.h b/include/uplink.h
new file mode 100644
index 000000000..7f200d426
--- /dev/null
+++ b/include/uplink.h
@@ -0,0 +1,44 @@
+/*
+ *
+ * (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 UPLINK_H
+#define UPLINK_H
+
+#include "sockets.h"
+
+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<typename T> Message &operator<<(const T &val)
+ {
+ this->buffer << val;
+ return *this;
+ }
+ };
+};
+extern UplinkSocket *UplinkSock;
+
+#endif // UPLINK_H
+
diff --git a/include/users.h b/include/users.h
index 703e1ceb7..a6510235f 100644
--- a/include/users.h
+++ b/include/users.h
@@ -8,6 +8,10 @@
#ifndef USERS_H
#define USERS_H
+#include "anope.h"
+#include "modes.h"
+#include "extensible.h"
+
extern CoreExport Anope::insensitive_map<User *> UserListByNick;
extern CoreExport Anope::map<User *> UserListByUID;
@@ -30,8 +34,9 @@ struct ChannelContainer
typedef std::list<ChannelContainer *> UChannelList;
+
/* Online user and channel data. */
-class CoreExport User : public Extensible
+class CoreExport User : public Base, public Extensible
{
protected:
Anope::string vident;
@@ -50,7 +55,7 @@ class CoreExport User : public Extensible
Anope::string chost; /* User's cloaked hostname */
Anope::string realname; /* Realname */
Anope::string fingerprint; /* SSL Fingerprint */
- sockaddrs ip; /* User's IP */
+ Anope::string ip; /* User's IP */
Server *server; /* Server user is connected to */
time_t timestamp; /* Timestamp of the nick */
time_t my_signon; /* When did _we_ see the user? */
@@ -296,4 +301,19 @@ class CoreExport User : public Extensible
void Kill(const Anope::string &source, const Anope::string &reason);
};
+extern int32_t opcnt;
+extern uint32_t maxusercnt, usercnt;
+extern time_t maxusertime;
+
+extern User *finduser(const Anope::string &nick);
+
+extern 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);
+
+extern void do_umode(const Anope::string &user, const Anope::string &modes);
+extern void do_kill(User *user, const Anope::string &reason);
+
+extern bool matches_list(Channel *c, User *user, ChannelModeName mode);
+
+extern Anope::string create_mask(User *u);
+
#endif // USERS_H