summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-21 19:13:39 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-21 19:13:39 +0000
commit76d7e8a0684b38a82e6c05ebd7538b69660e1bef (patch)
treeac874179a3e0268abd949b5220af515bdd6140b4 /src
parent11554b8626d8b421cc9cf2c6f6cc3fe2467e0441 (diff)
Header rearrangement, move inspircd.h to top, remove stdio, stdlib, stdblahblah that we dont even use, remove redeclared <string>, <map>, <vector>.
This (1) fixes the irc::string::move warnings on vc8 (2) speeds up compile a lot git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7098 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules/extra/m_filter_pcre.cpp4
-rw-r--r--src/modules/extra/m_httpclienttest.cpp2
-rw-r--r--src/modules/extra/m_mysql.cpp4
-rw-r--r--src/modules/extra/m_pgsql.cpp7
-rw-r--r--src/modules/extra/m_sqlauth.cpp4
-rw-r--r--src/modules/extra/m_sqlite3.cpp1363
-rw-r--r--src/modules/extra/m_sqllog.cpp3
-rw-r--r--src/modules/extra/m_sqloper.cpp3
-rw-r--r--src/modules/extra/m_sqlutils.cpp7
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp6
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp5
-rw-r--r--src/modules/extra/m_ssl_oper_cert.cpp3
-rw-r--r--src/modules/extra/m_sslinfo.cpp3
-rw-r--r--src/modules/extra/m_testclient.cpp7
-rw-r--r--src/modules/extra/m_ziplink.cpp9
-rw-r--r--src/modules/m_alias.cpp3
-rw-r--r--src/modules/m_alltime.cpp2
-rw-r--r--src/modules/m_antibear.cpp2
-rw-r--r--src/modules/m_antibottler.cpp2
-rw-r--r--src/modules/m_auditorium.cpp2
-rw-r--r--src/modules/m_banexception.cpp4
-rw-r--r--src/modules/m_banredirect.cpp2
-rw-r--r--src/modules/m_blockamsg.cpp6
-rw-r--r--src/modules/m_blockcaps.cpp2
-rw-r--r--src/modules/m_blockcolor.cpp4
-rw-r--r--src/modules/m_botmode.cpp2
-rw-r--r--src/modules/m_cban.cpp2
-rw-r--r--src/modules/m_censor.cpp4
-rw-r--r--src/modules/m_cgiirc.cpp5
-rw-r--r--src/modules/m_chancreate.cpp2
-rw-r--r--src/modules/m_chanfilter.cpp5
-rw-r--r--src/modules/m_chanprotect.cpp2
-rw-r--r--src/modules/m_check.cpp2
-rw-r--r--src/modules/m_chghost.cpp5
-rw-r--r--src/modules/m_chgident.cpp3
-rw-r--r--src/modules/m_cloaking.cpp3
-rw-r--r--src/modules/m_clones.cpp2
-rw-r--r--src/modules/m_conn_join.cpp2
-rw-r--r--src/modules/m_conn_umodes.cpp4
-rw-r--r--src/modules/m_conn_waitpong.cpp4
-rw-r--r--src/modules/m_connflood.cpp3
-rw-r--r--src/modules/m_dccallow.cpp5
-rw-r--r--src/modules/m_deaf.cpp2
-rw-r--r--src/modules/m_denychans.cpp2
-rw-r--r--src/modules/m_devoice.cpp3
-rw-r--r--src/modules/m_filter.cpp4
-rw-r--r--src/modules/m_foobar.cpp3
-rw-r--r--src/modules/m_globalload.cpp3
-rw-r--r--src/modules/m_globops.cpp4
-rw-r--r--src/modules/m_helpop.cpp2
-rw-r--r--src/modules/m_hidechans.cpp2
-rw-r--r--src/modules/m_hideoper.cpp2
-rw-r--r--src/modules/m_hostchange.cpp3
-rw-r--r--src/modules/m_httpd.cpp2
-rw-r--r--src/modules/m_httpd_stats.cpp3
-rw-r--r--src/modules/m_ident.cpp4
-rw-r--r--src/modules/m_invisible.cpp4
-rw-r--r--src/modules/m_inviteexception.cpp3
-rw-r--r--src/modules/m_joinflood.cpp5
-rw-r--r--src/modules/m_jumpserver.cpp4
-rw-r--r--src/modules/m_kicknorejoin.cpp7
-rw-r--r--src/modules/m_knock.cpp5
-rw-r--r--src/modules/m_lockserv.cpp3
-rw-r--r--src/modules/m_md5.cpp4
-rw-r--r--src/modules/m_messageflood.cpp4
-rw-r--r--src/modules/m_namesx.cpp2
-rw-r--r--src/modules/m_nicklock.cpp6
-rw-r--r--src/modules/m_noctcp.cpp4
-rw-r--r--src/modules/m_noinvite.cpp2
-rw-r--r--src/modules/m_nokicks.cpp5
-rw-r--r--src/modules/m_nonicks.cpp2
-rw-r--r--src/modules/m_nonotice.cpp2
-rw-r--r--src/modules/m_oper_hash.cpp4
-rw-r--r--src/modules/m_operchans.cpp2
-rw-r--r--src/modules/m_operjoin.cpp2
-rw-r--r--src/modules/m_operlevels.cpp4
-rw-r--r--src/modules/m_operlog.cpp5
-rw-r--r--src/modules/m_opermodes.cpp4
-rw-r--r--src/modules/m_opermotd.cpp4
-rw-r--r--src/modules/m_override.cpp2
-rw-r--r--src/modules/m_randquote.cpp4
-rw-r--r--src/modules/m_redirect.cpp2
-rw-r--r--src/modules/m_regonlycreate.cpp2
-rw-r--r--src/modules/m_remove.cpp2
-rw-r--r--src/modules/m_restrictbanned.cpp3
-rw-r--r--src/modules/m_restrictchans.cpp5
-rw-r--r--src/modules/m_restrictmsg.cpp6
-rw-r--r--src/modules/m_safelist.cpp5
-rw-r--r--src/modules/m_sajoin.cpp5
-rw-r--r--src/modules/m_samode.cpp3
-rw-r--r--src/modules/m_sanick.cpp4
-rw-r--r--src/modules/m_sapart.cpp4
-rw-r--r--src/modules/m_saquit.cpp4
-rw-r--r--src/modules/m_securelist.cpp6
-rw-r--r--src/modules/m_seenicks.cpp2
-rw-r--r--src/modules/m_services.cpp2
-rw-r--r--src/modules/m_services_account.cpp2
-rw-r--r--src/modules/m_sethost.cpp5
-rw-r--r--src/modules/m_setident.cpp2
-rw-r--r--src/modules/m_setidle.cpp4
-rw-r--r--src/modules/m_setname.cpp5
-rw-r--r--src/modules/m_sha256.cpp4
-rw-r--r--src/modules/m_showwhois.cpp2
-rw-r--r--src/modules/m_silence.cpp5
-rw-r--r--src/modules/m_silence_ext.cpp6
-rw-r--r--src/modules/m_spy.cpp3
-rw-r--r--src/modules/m_ssl_dummy.cpp3
-rw-r--r--src/modules/m_sslmodes.cpp2
-rw-r--r--src/modules/m_stripcolor.cpp2
-rw-r--r--src/modules/m_svshold.cpp2
-rw-r--r--src/modules/m_swhois.cpp2
-rw-r--r--src/modules/m_taxonomy.cpp3
-rw-r--r--src/modules/m_testcommand.cpp3
-rw-r--r--src/modules/m_timedbans.cpp5
-rw-r--r--src/modules/m_tline.cpp4
-rw-r--r--src/modules/m_uhnames.cpp2
-rw-r--r--src/modules/m_uninvite.cpp3
-rw-r--r--src/modules/m_userip.cpp4
-rw-r--r--src/modules/m_vhost.cpp3
-rw-r--r--src/modules/m_watch.cpp2
-rw-r--r--src/modules/m_xmlsocket.cpp4
121 files changed, 802 insertions, 981 deletions
diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp
index 8a3119f20..b21ec12a5 100644
--- a/src/modules/extra/m_filter_pcre.cpp
+++ b/src/modules/extra/m_filter_pcre.cpp
@@ -11,13 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include <pcre.h>
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "m_filter.h"
/* $ModDesc: m_filter with regexps */
diff --git a/src/modules/extra/m_httpclienttest.cpp b/src/modules/extra/m_httpclienttest.cpp
index 19c6c376b..5ec097aaf 100644
--- a/src/modules/extra/m_httpclienttest.cpp
+++ b/src/modules/extra/m_httpclienttest.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "httpclient.h"
/* $ModDep: httpclient.h */
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index 862dde811..1b83617d6 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -11,14 +11,12 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include <mysql.h>
#include <pthread.h>
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "m_sqlv2.h"
/* VERSION 2 API: With nonblocking (threaded) requests */
diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp
index 00be6ec26..9ec369859 100644
--- a/src/modules/extra/m_pgsql.cpp
+++ b/src/modules/extra/m_pgsql.cpp
@@ -11,19 +11,14 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include <cstdlib>
#include <sstream>
-#include <string>
-#include <deque>
-#include <map>
#include <libpq-fe.h>
-
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "configreader.h"
-
#include "m_sqlv2.h"
/* $ModDesc: PostgreSQL Service Provider module for all other m_sql* modules, uses v2 of the SQL API */
diff --git a/src/modules/extra/m_sqlauth.cpp b/src/modules/extra/m_sqlauth.cpp
index be8998e17..8b8073f2d 100644
--- a/src/modules/extra/m_sqlauth.cpp
+++ b/src/modules/extra/m_sqlauth.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
#include "m_sqlv2.h"
#include "m_sqlutils.h"
diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp
index 9568b9708..88b5aebcd 100644
--- a/src/modules/extra/m_sqlite3.cpp
+++ b/src/modules/extra/m_sqlite3.cpp
@@ -1,684 +1,679 @@
-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
- *
- * InspIRCd: (C) 2002-2007 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
- *
- * This program is free but copyrighted software; see
- * the file COPYING for details.
- *
- * ---------------------------------------------------
- */
-
-#include <string>
-#include <deque>
-#include <map>
-#include <sqlite3.h>
-
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
-#include "inspircd.h"
-#include "configreader.h"
-
-#include "m_sqlv2.h"
-
-/* $ModDesc: sqlite3 provider */
-/* $CompileFlags: pkgconfversion("sqlite3","3.3") pkgconfincludes("sqlite3","/sqlite3.h","") */
-/* $LinkerFlags: pkgconflibs("sqlite3","/libsqlite3.so","-lsqlite3") */
-/* $ModDep: m_sqlv2.h */
-
-
-class SQLConn;
-class SQLite3Result;
-class ResultNotifier;
-
-typedef std::map<std::string, SQLConn*> ConnMap;
-typedef std::deque<classbase*> paramlist;
-typedef std::deque<SQLite3Result*> ResultQueue;
-
-ResultNotifier* resultnotify = NULL;
-
-
-class ResultNotifier : public InspSocket
-{
- Module* mod;
- insp_sockaddr sock_us;
- socklen_t uslen;
-
- public:
- /* Create a socket on a random port. Let the tcp stack allocate us an available port */
-#ifdef IPV6
- ResultNotifier(InspIRCd* SI, Module* m) : InspSocket(SI, "::1", 0, true, 3000), mod(m)
-#else
- ResultNotifier(InspIRCd* SI, Module* m) : InspSocket(SI, "127.0.0.1", 0, true, 3000), mod(m)
-#endif
- {
- uslen = sizeof(sock_us);
- if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
- {
- throw ModuleException("Could not create random listening port on localhost");
- }
- }
-
- ResultNotifier(InspIRCd* SI, Module* m, int newfd, char* ip) : InspSocket(SI, newfd, ip), mod(m)
- {
- }
-
- /* Using getsockname and ntohs, we can determine which port number we were allocated */
- int GetPort()
- {
-#ifdef IPV6
- return ntohs(sock_us.sin6_port);
-#else
- return ntohs(sock_us.sin_port);
-#endif
- }
-
- virtual int OnIncomingConnection(int newsock, char* ip)
- {
- Dispatch();
- return false;
- }
-
- void Dispatch();
-};
-
-
-class SQLite3Result : public SQLresult
-{
- private:
- int currentrow;
- int rows;
- int cols;
-
- std::vector<std::string> colnames;
- std::vector<SQLfieldList> fieldlists;
- SQLfieldList emptyfieldlist;
-
- SQLfieldList* fieldlist;
- SQLfieldMap* fieldmap;
-
- public:
- SQLite3Result(Module* self, Module* to, unsigned int id)
- : SQLresult(self, to, id), currentrow(0), rows(0), cols(0), fieldlist(NULL), fieldmap(NULL)
- {
- }
-
- ~SQLite3Result()
- {
- }
-
- void AddRow(int colsnum, char **data, char **colname)
- {
- colnames.clear();
- cols = colsnum;
- for (int i = 0; i < colsnum; i++)
- {
- fieldlists.resize(fieldlists.size()+1);
- colnames.push_back(colname[i]);
- SQLfield sf(data[i] ? data[i] : "", data[i] ? false : true);
- fieldlists[rows].push_back(sf);
- }
- rows++;
- }
-
- void UpdateAffectedCount()
- {
- rows++;
- }
-
- virtual int Rows()
- {
- return rows;
- }
-
- virtual int Cols()
- {
- return cols;
- }
-
- virtual std::string ColName(int column)
- {
- if (column < (int)colnames.size())
- {
- return colnames[column];
- }
- else
- {
- throw SQLbadColName();
- }
- return "";
- }
-
- virtual int ColNum(const std::string &column)
- {
- for (unsigned int i = 0; i < colnames.size(); i++)
- {
- if (column == colnames[i])
- return i;
- }
- throw SQLbadColName();
- return 0;
- }
-
- virtual SQLfield GetValue(int row, int column)
- {
- if ((row >= 0) && (row < rows) && (column >= 0) && (column < Cols()))
- {
- return fieldlists[row][column];
- }
-
- throw SQLbadColName();
-
- /* XXX: We never actually get here because of the throw */
- return SQLfield("",true);
- }
-
- virtual SQLfieldList& GetRow()
- {
- if (currentrow < rows)
- return fieldlists[currentrow];
- else
- return emptyfieldlist;
- }
-
- virtual SQLfieldMap& GetRowMap()
- {
- /* In an effort to reduce overhead we don't actually allocate the map
- * until the first time it's needed...so...
- */
- if(fieldmap)
- {
- fieldmap->clear();
- }
- else
- {
- fieldmap = new SQLfieldMap;
- }
-
- if (currentrow < rows)
- {
- for (int i = 0; i < Cols(); i++)
- {
- fieldmap->insert(std::make_pair(ColName(i), GetValue(currentrow, i)));
- }
- currentrow++;
- }
-
- return *fieldmap;
- }
-
- virtual SQLfieldList* GetRowPtr()
- {
- fieldlist = new SQLfieldList();
-
- if (currentrow < rows)
- {
- for (int i = 0; i < Rows(); i++)
- {
- fieldlist->push_back(fieldlists[currentrow][i]);
- }
- currentrow++;
- }
- return fieldlist;
- }
-
- virtual SQLfieldMap* GetRowMapPtr()
- {
- fieldmap = new SQLfieldMap();
-
- if (currentrow < rows)
- {
- for (int i = 0; i < Cols(); i++)
- {
- fieldmap->insert(std::make_pair(colnames[i],GetValue(currentrow, i)));
- }
- currentrow++;
- }
-
- return fieldmap;
- }
-
- virtual void Free(SQLfieldMap* fm)
- {
- delete fm;
- }
-
- virtual void Free(SQLfieldList* fl)
- {
- delete fl;
- }
-
-
-};
-
-class SQLConn : public classbase
-{
- private:
- ResultQueue results;
- InspIRCd* Instance;
- Module* mod;
- SQLhost host;
- sqlite3* conn;
-
- public:
- SQLConn(InspIRCd* SI, Module* m, const SQLhost& hi)
- : Instance(SI), mod(m), host(hi)
- {
- if (OpenDB() != SQLITE_OK)
- {
- Instance->Log(DEFAULT, "WARNING: Could not open DB with id: " + host.id);
- CloseDB();
- }
- }
-
- ~SQLConn()
- {
- CloseDB();
- }
-
- SQLerror Query(SQLrequest &req)
- {
- /* Pointer to the buffer we screw around with substitution in */
- char* query;
-
- /* Pointer to the current end of query, where we append new stuff */
- char* queryend;
-
- /* Total length of the unescaped parameters */
- unsigned long paramlen;
-
- /* Total length of query, used for binary-safety in mysql_real_query */
- unsigned long querylength = 0;
-
- paramlen = 0;
- for(ParamL::iterator i = req.query.p.begin(); i != req.query.p.end(); i++)
- {
- paramlen += i->size();
- }
-
- /* To avoid a lot of allocations, allocate enough memory for the biggest the escaped query could possibly be.
- * sizeofquery + (totalparamlength*2) + 1
- *
- * The +1 is for null-terminating the string for mysql_real_escape_string
- */
- query = new char[req.query.q.length() + (paramlen*2) + 1];
- queryend = query;
-
- for(unsigned long i = 0; i < req.query.q.length(); i++)
- {
- if(req.query.q[i] == '?')
- {
- if(req.query.p.size())
- {
- char* escaped;
- escaped = sqlite3_mprintf("%q", req.query.p.front().c_str());
- for (char* n = escaped; *n; n++)
- {
- *queryend = *n;
- queryend++;
- }
- sqlite3_free(escaped);
- req.query.p.pop_front();
- }
- else
- break;
- }
- else
- {
- *queryend = req.query.q[i];
- queryend++;
- }
- querylength++;
- }
- *queryend = 0;
- req.query.q = query;
-
- SQLite3Result* res = new SQLite3Result(mod, req.GetSource(), req.id);
- res->dbid = host.id;
- res->query = req.query.q;
- paramlist params;
- params.push_back(this);
- params.push_back(res);
-
- char *errmsg = 0;
- sqlite3_update_hook(conn, QueryUpdateHook, &params);
- if (sqlite3_exec(conn, req.query.q.data(), QueryResult, &params, &errmsg) != SQLITE_OK)
- {
- std::string error(errmsg);
- sqlite3_free(errmsg);
- delete[] query;
- delete res;
- return SQLerror(QSEND_FAIL, error);
- }
- delete[] query;
-
- results.push_back(res);
- SendNotify();
- return SQLerror();
- }
-
- static int QueryResult(void *params, int argc, char **argv, char **azColName)
- {
- paramlist* p = (paramlist*)params;
- ((SQLConn*)(*p)[0])->ResultReady(((SQLite3Result*)(*p)[1]), argc, argv, azColName);
- return 0;
- }
-
- static void QueryUpdateHook(void *params, int eventid, char const * azSQLite, char const * azColName, sqlite_int64 rowid)
- {
- paramlist* p = (paramlist*)params;
- ((SQLConn*)(*p)[0])->AffectedReady(((SQLite3Result*)(*p)[1]));
- }
-
- void ResultReady(SQLite3Result *res, int cols, char **data, char **colnames)
- {
- res->AddRow(cols, data, colnames);
- }
-
- void AffectedReady(SQLite3Result *res)
- {
- res->UpdateAffectedCount();
- }
-
- int OpenDB()
- {
- return sqlite3_open(host.host.c_str(), &conn);
- }
-
- void CloseDB()
- {
- sqlite3_interrupt(conn);
- sqlite3_close(conn);
- }
-
- SQLhost GetConfHost()
- {
- return host;
- }
-
- void SendResults()
- {
- while (results.size())
- {
- SQLite3Result* res = results[0];
- if (res->GetDest())
- {
- res->Send();
- }
- else
- {
- /* If the client module is unloaded partway through a query then the provider will set
- * the pointer to NULL. We cannot just cancel the query as the result will still come
- * through at some point...and it could get messy if we play with invalid pointers...
- */
- delete res;
- }
- results.pop_front();
- }
- }
-
- void ClearResults()
- {
- while (results.size())
- {
- SQLite3Result* res = results[0];
- delete res;
- results.pop_front();
- }
- }
-
- void SendNotify()
- {
- int QueueFD;
- if ((QueueFD = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1)
- {
- /* crap, we're out of sockets... */
- return;
- }
-
- insp_sockaddr addr;
-
-#ifdef IPV6
- insp_aton("::1", &addr.sin6_addr);
- addr.sin6_family = AF_FAMILY;
- addr.sin6_port = htons(resultnotify->GetPort());
-#else
- insp_inaddr ia;
- insp_aton("127.0.0.1", &ia);
- addr.sin_family = AF_FAMILY;
- addr.sin_addr = ia;
- addr.sin_port = htons(resultnotify->GetPort());
-#endif
-
- if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1)
- {
- /* wtf, we cant connect to it, but we just created it! */
- return;
- }
- }
-
-};
-
-
-class ModuleSQLite3 : public Module
-{
- private:
- ConnMap connections;
- unsigned long currid;
-
- public:
- ModuleSQLite3(InspIRCd* Me)
- : Module::Module(Me), currid(0)
- {
- ServerInstance->UseInterface("SQLutils");
-
- if (!ServerInstance->PublishFeature("SQL", this))
- {
- throw ModuleException("m_sqlite3: Unable to publish feature 'SQL'");
- }
-
- resultnotify = new ResultNotifier(ServerInstance, this);
-
- ReadConf();
-
- ServerInstance->PublishInterface("SQL", this);
- }
-
- virtual ~ModuleSQLite3()
- {
- ClearQueue();
- ClearAllConnections();
- resultnotify->SetFd(-1);
- resultnotify->state = I_ERROR;
- resultnotify->OnError(I_ERR_SOCKET);
- resultnotify->ClosePending = true;
- delete resultnotify;
- ServerInstance->UnpublishInterface("SQL", this);
- ServerInstance->UnpublishFeature("SQL");
- ServerInstance->DoneWithInterface("SQLutils");
- }
-
- void Implements(char* List)
- {
- List[I_OnRequest] = List[I_OnRehash] = 1;
- }
-
- void SendQueue()
- {
- for (ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
- {
- iter->second->SendResults();
- }
- }
-
- void ClearQueue()
- {
- for (ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
- {
- iter->second->ClearResults();
- }
- }
-
- bool HasHost(const SQLhost &host)
- {
- for (ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
- {
- if (host == iter->second->GetConfHost())
- return true;
- }
- return false;
- }
-
- bool HostInConf(const SQLhost &h)
- {
- ConfigReader conf(ServerInstance);
- for(int i = 0; i < conf.Enumerate("database"); i++)
- {
- SQLhost host;
- host.id = conf.ReadValue("database", "id", i);
- host.host = conf.ReadValue("database", "hostname", i);
- host.port = conf.ReadInteger("database", "port", i, true);
- host.name = conf.ReadValue("database", "name", i);
- host.user = conf.ReadValue("database", "username", i);
- host.pass = conf.ReadValue("database", "password", i);
- host.ssl = conf.ReadFlag("database", "ssl", "0", i);
- if (h == host)
- return true;
- }
- return false;
- }
-
- void ReadConf()
- {
- ClearOldConnections();
-
- ConfigReader conf(ServerInstance);
- for(int i = 0; i < conf.Enumerate("database"); i++)
- {
- SQLhost host;
-
- host.id = conf.ReadValue("database", "id", i);
- host.host = conf.ReadValue("database", "hostname", i);
- host.port = conf.ReadInteger("database", "port", i, true);
- host.name = conf.ReadValue("database", "name", i);
- host.user = conf.ReadValue("database", "username", i);
- host.pass = conf.ReadValue("database", "password", i);
- host.ssl = conf.ReadFlag("database", "ssl", "0", i);
-
- if (HasHost(host))
- continue;
-
- this->AddConn(host);
- }
- }
-
- void AddConn(const SQLhost& hi)
- {
- if (HasHost(hi))
- {
- ServerInstance->Log(DEFAULT, "WARNING: A sqlite connection with id: %s already exists. Aborting database open attempt.", hi.id.c_str());
- return;
- }
-
- SQLConn* newconn;
-
- newconn = new SQLConn(ServerInstance, this, hi);
-
- connections.insert(std::make_pair(hi.id, newconn));
- }
-
- void ClearOldConnections()
- {
- ConnMap::iterator iter,safei;
- for (iter = connections.begin(); iter != connections.end(); iter++)
- {
- if (!HostInConf(iter->second->GetConfHost()))
- {
- DELETE(iter->second);
- safei = iter;
- --iter;
- connections.erase(safei);
- }
- }
- }
-
- void ClearAllConnections()
- {
- ConnMap::iterator i;
- while ((i = connections.begin()) != connections.end())
- {
- connections.erase(i);
- DELETE(i->second);
- }
- }
-
- virtual void OnRehash(userrec* user, const std::string &parameter)
- {
- ReadConf();
- }
-
- virtual char* OnRequest(Request* request)
- {
- if(strcmp(SQLREQID, request->GetId()) == 0)
- {
- SQLrequest* req = (SQLrequest*)request;
- ConnMap::iterator iter;
- if((iter = connections.find(req->dbid)) != connections.end())
- {
- req->id = NewID();
- req->error = iter->second->Query(*req);
- return SQLSUCCESS;
- }
- else
- {
- req->error.Id(BAD_DBID);
- return NULL;
- }
- }
- return NULL;
- }
-
- unsigned long NewID()
- {
- if (currid+1 == 0)
- currid++;
-
- return ++currid;
- }
-
- virtual Version GetVersion()
- {
- return Version(1,1,0,0,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
- }
-
-};
-
-void ResultNotifier::Dispatch()
-{
- ((ModuleSQLite3*)mod)->SendQueue();
-}
-
-class ModuleSQLite3Factory : public ModuleFactory
-{
- public:
- ModuleSQLite3Factory()
- {
- }
-
- ~ModuleSQLite3Factory()
- {
- }
-
- virtual Module * CreateModule(InspIRCd* Me)
- {
- return new ModuleSQLite3(Me);
- }
-};
-
-extern "C" void * init_module( void )
-{
- return new ModuleSQLite3Factory;
-}
+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ * the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+#include <sqlite3.h>
+#include "users.h"
+#include "channels.h"
+#include "modules.h"
+
+#include "m_sqlv2.h"
+
+/* $ModDesc: sqlite3 provider */
+/* $CompileFlags: pkgconfversion("sqlite3","3.3") pkgconfincludes("sqlite3","/sqlite3.h","") */
+/* $LinkerFlags: pkgconflibs("sqlite3","/libsqlite3.so","-lsqlite3") */
+/* $ModDep: m_sqlv2.h */
+
+
+class SQLConn;
+class SQLite3Result;
+class ResultNotifier;
+
+typedef std::map<std::string, SQLConn*> ConnMap;
+typedef std::deque<classbase*> paramlist;
+typedef std::deque<SQLite3Result*> ResultQueue;
+
+ResultNotifier* resultnotify = NULL;
+
+
+class ResultNotifier : public InspSocket
+{
+ Module* mod;
+ insp_sockaddr sock_us;
+ socklen_t uslen;
+
+ public:
+ /* Create a socket on a random port. Let the tcp stack allocate us an available port */
+#ifdef IPV6
+ ResultNotifier(InspIRCd* SI, Module* m) : InspSocket(SI, "::1", 0, true, 3000), mod(m)
+#else
+ ResultNotifier(InspIRCd* SI, Module* m) : InspSocket(SI, "127.0.0.1", 0, true, 3000), mod(m)
+#endif
+ {
+ uslen = sizeof(sock_us);
+ if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
+ {
+ throw ModuleException("Could not create random listening port on localhost");
+ }
+ }
+
+ ResultNotifier(InspIRCd* SI, Module* m, int newfd, char* ip) : InspSocket(SI, newfd, ip), mod(m)
+ {
+ }
+
+ /* Using getsockname and ntohs, we can determine which port number we were allocated */
+ int GetPort()
+ {
+#ifdef IPV6
+ return ntohs(sock_us.sin6_port);
+#else
+ return ntohs(sock_us.sin_port);
+#endif
+ }
+
+ virtual int OnIncomingConnection(int newsock, char* ip)
+ {
+ Dispatch();
+ return false;
+ }
+
+ void Dispatch();
+};
+
+
+class SQLite3Result : public SQLresult
+{
+ private:
+ int currentrow;
+ int rows;
+ int cols;
+
+ std::vector<std::string> colnames;
+ std::vector<SQLfieldList> fieldlists;
+ SQLfieldList emptyfieldlist;
+
+ SQLfieldList* fieldlist;
+ SQLfieldMap* fieldmap;
+
+ public:
+ SQLite3Result(Module* self, Module* to, unsigned int id)
+ : SQLresult(self, to, id), currentrow(0), rows(0), cols(0), fieldlist(NULL), fieldmap(NULL)
+ {
+ }
+
+ ~SQLite3Result()
+ {
+ }
+
+ void AddRow(int colsnum, char **data, char **colname)
+ {
+ colnames.clear();
+ cols = colsnum;
+ for (int i = 0; i < colsnum; i++)
+ {
+ fieldlists.resize(fieldlists.size()+1);
+ colnames.push_back(colname[i]);
+ SQLfield sf(data[i] ? data[i] : "", data[i] ? false : true);
+ fieldlists[rows].push_back(sf);
+ }
+ rows++;
+ }
+
+ void UpdateAffectedCount()
+ {
+ rows++;
+ }
+
+ virtual int Rows()
+ {
+ return rows;
+ }
+
+ virtual int Cols()
+ {
+ return cols;
+ }
+
+ virtual std::string ColName(int column)
+ {
+ if (column < (int)colnames.size())
+ {
+ return colnames[column];
+ }
+ else
+ {
+ throw SQLbadColName();
+ }
+ return "";
+ }
+
+ virtual int ColNum(const std::string &column)
+ {
+ for (unsigned int i = 0; i < colnames.size(); i++)
+ {
+ if (column == colnames[i])
+ return i;
+ }
+ throw SQLbadColName();
+ return 0;
+ }
+
+ virtual SQLfield GetValue(int row, int column)
+ {
+ if ((row >= 0) && (row < rows) && (column >= 0) && (column < Cols()))
+ {
+ return fieldlists[row][column];
+ }
+
+ throw SQLbadColName();
+
+ /* XXX: We never actually get here because of the throw */
+ return SQLfield("",true);
+ }
+
+ virtual SQLfieldList& GetRow()
+ {
+ if (currentrow < rows)
+ return fieldlists[currentrow];
+ else
+ return emptyfieldlist;
+ }
+
+ virtual SQLfieldMap& GetRowMap()
+ {
+ /* In an effort to reduce overhead we don't actually allocate the map
+ * until the first time it's needed...so...
+ */
+ if(fieldmap)
+ {
+ fieldmap->clear();
+ }
+ else
+ {
+ fieldmap = new SQLfieldMap;
+ }
+
+ if (currentrow < rows)
+ {
+ for (int i = 0; i < Cols(); i++)
+ {
+ fieldmap->insert(std::make_pair(ColName(i), GetValue(currentrow, i)));
+ }
+ currentrow++;
+ }
+
+ return *fieldmap;
+ }
+
+ virtual SQLfieldList* GetRowPtr()
+ {
+ fieldlist = new SQLfieldList();
+
+ if (currentrow < rows)
+ {
+ for (int i = 0; i < Rows(); i++)
+ {
+ fieldlist->push_back(fieldlists[currentrow][i]);
+ }
+ currentrow++;
+ }
+ return fieldlist;
+ }
+
+ virtual SQLfieldMap* GetRowMapPtr()
+ {
+ fieldmap = new SQLfieldMap();
+
+ if (currentrow < rows)
+ {
+ for (int i = 0; i < Cols(); i++)
+ {
+ fieldmap->insert(std::make_pair(colnames[i],GetValue(currentrow, i)));
+ }
+ currentrow++;
+ }
+
+ return fieldmap;
+ }
+
+ virtual void Free(SQLfieldMap* fm)
+ {
+ delete fm;
+ }
+
+ virtual void Free(SQLfieldList* fl)
+ {
+ delete fl;
+ }
+
+
+};
+
+class SQLConn : public classbase
+{
+ private:
+ ResultQueue results;
+ InspIRCd* Instance;
+ Module* mod;
+ SQLhost host;
+ sqlite3* conn;
+
+ public:
+ SQLConn(InspIRCd* SI, Module* m, const SQLhost& hi)
+ : Instance(SI), mod(m), host(hi)
+ {
+ if (OpenDB() != SQLITE_OK)
+ {
+ Instance->Log(DEFAULT, "WARNING: Could not open DB with id: " + host.id);
+ CloseDB();
+ }
+ }
+
+ ~SQLConn()
+ {
+ CloseDB();
+ }
+
+ SQLerror Query(SQLrequest &req)
+ {
+ /* Pointer to the buffer we screw around with substitution in */
+ char* query;
+
+ /* Pointer to the current end of query, where we append new stuff */
+ char* queryend;
+
+ /* Total length of the unescaped parameters */
+ unsigned long paramlen;
+
+ /* Total length of query, used for binary-safety in mysql_real_query */
+ unsigned long querylength = 0;
+
+ paramlen = 0;
+ for(ParamL::iterator i = req.query.p.begin(); i != req.query.p.end(); i++)
+ {
+ paramlen += i->size();
+ }
+
+ /* To avoid a lot of allocations, allocate enough memory for the biggest the escaped query could possibly be.
+ * sizeofquery + (totalparamlength*2) + 1
+ *
+ * The +1 is for null-terminating the string for mysql_real_escape_string
+ */
+ query = new char[req.query.q.length() + (paramlen*2) + 1];
+ queryend = query;
+
+ for(unsigned long i = 0; i < req.query.q.length(); i++)
+ {
+ if(req.query.q[i] == '?')
+ {
+ if(req.query.p.size())
+ {
+ char* escaped;
+ escaped = sqlite3_mprintf("%q", req.query.p.front().c_str());
+ for (char* n = escaped; *n; n++)
+ {
+ *queryend = *n;
+ queryend++;
+ }
+ sqlite3_free(escaped);
+ req.query.p.pop_front();
+ }
+ else
+ break;
+ }
+ else
+ {
+ *queryend = req.query.q[i];
+ queryend++;
+ }
+ querylength++;
+ }
+ *queryend = 0;
+ req.query.q = query;
+
+ SQLite3Result* res = new SQLite3Result(mod, req.GetSource(), req.id);
+ res->dbid = host.id;
+ res->query = req.query.q;
+ paramlist params;
+ params.push_back(this);
+ params.push_back(res);
+
+ char *errmsg = 0;
+ sqlite3_update_hook(conn, QueryUpdateHook, &params);
+ if (sqlite3_exec(conn, req.query.q.data(), QueryResult, &params, &errmsg) != SQLITE_OK)
+ {
+ std::string error(errmsg);
+ sqlite3_free(errmsg);
+ delete[] query;
+ delete res;
+ return SQLerror(QSEND_FAIL, error);
+ }
+ delete[] query;
+
+ results.push_back(res);
+ SendNotify();
+ return SQLerror();
+ }
+
+ static int QueryResult(void *params, int argc, char **argv, char **azColName)
+ {
+ paramlist* p = (paramlist*)params;
+ ((SQLConn*)(*p)[0])->ResultReady(((SQLite3Result*)(*p)[1]), argc, argv, azColName);
+ return 0;
+ }
+
+ static void QueryUpdateHook(void *params, int eventid, char const * azSQLite, char const * azColName, sqlite_int64 rowid)
+ {
+ paramlist* p = (paramlist*)params;
+ ((SQLConn*)(*p)[0])->AffectedReady(((SQLite3Result*)(*p)[1]));
+ }
+
+ void ResultReady(SQLite3Result *res, int cols, char **data, char **colnames)
+ {
+ res->AddRow(cols, data, colnames);
+ }
+
+ void AffectedReady(SQLite3Result *res)
+ {
+ res->UpdateAffectedCount();
+ }
+
+ int OpenDB()
+ {
+ return sqlite3_open(host.host.c_str(), &conn);
+ }
+
+ void CloseDB()
+ {
+ sqlite3_interrupt(conn);
+ sqlite3_close(conn);
+ }
+
+ SQLhost GetConfHost()
+ {
+ return host;
+ }
+
+ void SendResults()
+ {
+ while (results.size())
+ {
+ SQLite3Result* res = results[0];
+ if (res->GetDest())
+ {
+ res->Send();
+ }
+ else
+ {
+ /* If the client module is unloaded partway through a query then the provider will set
+ * the pointer to NULL. We cannot just cancel the query as the result will still come
+ * through at some point...and it could get messy if we play with invalid pointers...
+ */
+ delete res;
+ }
+ results.pop_front();
+ }
+ }
+
+ void ClearResults()
+ {
+ while (results.size())
+ {
+ SQLite3Result* res = results[0];
+ delete res;
+ results.pop_front();
+ }
+ }
+
+ void SendNotify()
+ {
+ int QueueFD;
+ if ((QueueFD = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1)
+ {
+ /* crap, we're out of sockets... */
+ return;
+ }
+
+ insp_sockaddr addr;
+
+#ifdef IPV6
+ insp_aton("::1", &addr.sin6_addr);
+ addr.sin6_family = AF_FAMILY;
+ addr.sin6_port = htons(resultnotify->GetPort());
+#else
+ insp_inaddr ia;
+ insp_aton("127.0.0.1", &ia);
+ addr.sin_family = AF_FAMILY;
+ addr.sin_addr = ia;
+ addr.sin_port = htons(resultnotify->GetPort());
+#endif
+
+ if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1)
+ {
+ /* wtf, we cant connect to it, but we just created it! */
+ return;
+ }
+ }
+
+};
+
+
+class ModuleSQLite3 : public Module
+{
+ private:
+ ConnMap connections;
+ unsigned long currid;
+
+ public:
+ ModuleSQLite3(InspIRCd* Me)
+ : Module::Module(Me), currid(0)
+ {
+ ServerInstance->UseInterface("SQLutils");
+
+ if (!ServerInstance->PublishFeature("SQL", this))
+ {
+ throw ModuleException("m_sqlite3: Unable to publish feature 'SQL'");
+ }
+
+ resultnotify = new ResultNotifier(ServerInstance, this);
+
+ ReadConf();
+
+ ServerInstance->PublishInterface("SQL", this);
+ }
+
+ virtual ~ModuleSQLite3()
+ {
+ ClearQueue();
+ ClearAllConnections();
+ resultnotify->SetFd(-1);
+ resultnotify->state = I_ERROR;
+ resultnotify->OnError(I_ERR_SOCKET);
+ resultnotify->ClosePending = true;
+ delete resultnotify;
+ ServerInstance->UnpublishInterface("SQL", this);
+ ServerInstance->UnpublishFeature("SQL");
+ ServerInstance->DoneWithInterface("SQLutils");
+ }
+
+ void Implements(char* List)
+ {
+ List[I_OnRequest] = List[I_OnRehash] = 1;
+ }
+
+ void SendQueue()
+ {
+ for (ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
+ {
+ iter->second->SendResults();
+ }
+ }
+
+ void ClearQueue()
+ {
+ for (ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
+ {
+ iter->second->ClearResults();
+ }
+ }
+
+ bool HasHost(const SQLhost &host)
+ {
+ for (ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++)
+ {
+ if (host == iter->second->GetConfHost())
+ return true;
+ }
+ return false;
+ }
+
+ bool HostInConf(const SQLhost &h)
+ {
+ ConfigReader conf(ServerInstance);
+ for(int i = 0; i < conf.Enumerate("database"); i++)
+ {
+ SQLhost host;
+ host.id = conf.ReadValue("database", "id", i);
+ host.host = conf.ReadValue("database", "hostname", i);
+ host.port = conf.ReadInteger("database", "port", i, true);
+ host.name = conf.ReadValue("database", "name", i);
+ host.user = conf.ReadValue("database", "username", i);
+ host.pass = conf.ReadValue("database", "password", i);
+ host.ssl = conf.ReadFlag("database", "ssl", "0", i);
+ if (h == host)
+ return true;
+ }
+ return false;
+ }
+
+ void ReadConf()
+ {
+ ClearOldConnections();
+
+ ConfigReader conf(ServerInstance);
+ for(int i = 0; i < conf.Enumerate("database"); i++)
+ {
+ SQLhost host;
+
+ host.id = conf.ReadValue("database", "id", i);
+ host.host = conf.ReadValue("database", "hostname", i);
+ host.port = conf.ReadInteger("database", "port", i, true);
+ host.name = conf.ReadValue("database", "name", i);
+ host.user = conf.ReadValue("database", "username", i);
+ host.pass = conf.ReadValue("database", "password", i);
+ host.ssl = conf.ReadFlag("database", "ssl", "0", i);
+
+ if (HasHost(host))
+ continue;
+
+ this->AddConn(host);
+ }
+ }
+
+ void AddConn(const SQLhost& hi)
+ {
+ if (HasHost(hi))
+ {
+ ServerInstance->Log(DEFAULT, "WARNING: A sqlite connection with id: %s already exists. Aborting database open attempt.", hi.id.c_str());
+ return;
+ }
+
+ SQLConn* newconn;
+
+ newconn = new SQLConn(ServerInstance, this, hi);
+
+ connections.insert(std::make_pair(hi.id, newconn));
+ }
+
+ void ClearOldConnections()
+ {
+ ConnMap::iterator iter,safei;
+ for (iter = connections.begin(); iter != connections.end(); iter++)
+ {
+ if (!HostInConf(iter->second->GetConfHost()))
+ {
+ DELETE(iter->second);
+ safei = iter;
+ --iter;
+ connections.erase(safei);
+ }
+ }
+ }
+
+ void ClearAllConnections()
+ {
+ ConnMap::iterator i;
+ while ((i = connections.begin()) != connections.end())
+ {
+ connections.erase(i);
+ DELETE(i->second);
+ }
+ }
+
+ virtual void OnRehash(userrec* user, const std::string &parameter)
+ {
+ ReadConf();
+ }
+
+ virtual char* OnRequest(Request* request)
+ {
+ if(strcmp(SQLREQID, request->GetId()) == 0)
+ {
+ SQLrequest* req = (SQLrequest*)request;
+ ConnMap::iterator iter;
+ if((iter = connections.find(req->dbid)) != connections.end())
+ {
+ req->id = NewID();
+ req->error = iter->second->Query(*req);
+ return SQLSUCCESS;
+ }
+ else
+ {
+ req->error.Id(BAD_DBID);
+ return NULL;
+ }
+ }
+ return NULL;
+ }
+
+ unsigned long NewID()
+ {
+ if (currid+1 == 0)
+ currid++;
+
+ return ++currid;
+ }
+
+ virtual Version GetVersion()
+ {
+ return Version(1,1,0,0,VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
+ }
+
+};
+
+void ResultNotifier::Dispatch()
+{
+ ((ModuleSQLite3*)mod)->SendQueue();
+}
+
+class ModuleSQLite3Factory : public ModuleFactory
+{
+ public:
+ ModuleSQLite3Factory()
+ {
+ }
+
+ ~ModuleSQLite3Factory()
+ {
+ }
+
+ virtual Module * CreateModule(InspIRCd* Me)
+ {
+ return new ModuleSQLite3(Me);
+ }
+};
+
+extern "C" void * init_module( void )
+{
+ return new ModuleSQLite3Factory;
+}
diff --git a/src/modules/extra/m_sqllog.cpp b/src/modules/extra/m_sqllog.cpp
index 3ebd6c0f3..b4e5d2331 100644
--- a/src/modules/extra/m_sqllog.cpp
+++ b/src/modules/extra/m_sqllog.cpp
@@ -11,14 +11,13 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "configreader.h"
-#include "inspircd.h"
#include "m_sqlv2.h"
-
static Module* SQLModule;
static Module* MyMod;
static std::string dbid;
diff --git a/src/modules/extra/m_sqloper.cpp b/src/modules/extra/m_sqloper.cpp
index df99a6dc4..53f3c56c7 100644
--- a/src/modules/extra/m_sqloper.cpp
+++ b/src/modules/extra/m_sqloper.cpp
@@ -11,11 +11,10 @@
* ---------------------------------------------------
*/
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "configreader.h"
#include "m_sqlv2.h"
diff --git a/src/modules/extra/m_sqlutils.cpp b/src/modules/extra/m_sqlutils.cpp
index 131e20e5e..8c7cebd1b 100644
--- a/src/modules/extra/m_sqlutils.cpp
+++ b/src/modules/extra/m_sqlutils.cpp
@@ -11,18 +11,13 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include <sstream>
-#include <string>
-#include <map>
#include <list>
-
#include "users.h"
#include "channels.h"
#include "modules.h"
-
-#include "inspircd.h"
#include "configreader.h"
-
#include "m_sqlutils.h"
/* $ModDesc: Provides some utilities to SQL client modules, such as mapping queries to users and channels */
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index aae039738..a466eb66d 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -11,8 +11,7 @@
* ---------------------------------------------------
*/
-#include <string>
-#include <vector>
+#include "inspircd.h"
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
@@ -22,11 +21,8 @@
#include "users.h"
#include "channels.h"
#include "modules.h"
-
#include "socket.h"
#include "hashcomp.h"
-#include "inspircd.h"
-
#include "transport.h"
#ifdef WINDOWS
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 90e9c9ab6..7090f1a01 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -11,8 +11,7 @@
* ---------------------------------------------------
*/
-#include <string>
-#include <vector>
+#include "inspircd.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -21,7 +20,6 @@
#include <openssl/applink.c>
#endif
-#include "inspircd_config.h"
#include "configreader.h"
#include "users.h"
#include "channels.h"
@@ -29,7 +27,6 @@
#include "socket.h"
#include "hashcomp.h"
-#include "inspircd.h"
#include "transport.h"
diff --git a/src/modules/extra/m_ssl_oper_cert.cpp b/src/modules/extra/m_ssl_oper_cert.cpp
index 1f9a8b911..068c01845 100644
--- a/src/modules/extra/m_ssl_oper_cert.cpp
+++ b/src/modules/extra/m_ssl_oper_cert.cpp
@@ -14,12 +14,11 @@
/* $ModDesc: Allows for MD5 encrypted oper passwords */
/* $ModDep: transport.h */
-#include <stdio.h>
+#include "inspircd.h"
#include "inspircd_config.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "transport.h"
#include "wildcard.h"
diff --git a/src/modules/extra/m_sslinfo.cpp b/src/modules/extra/m_sslinfo.cpp
index 7dc4bd6f3..1cfe3ded9 100644
--- a/src/modules/extra/m_sslinfo.cpp
+++ b/src/modules/extra/m_sslinfo.cpp
@@ -11,13 +11,12 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "transport.h"
#include "wildcard.h"
-#include "inspircd.h"
#include "dns.h"
/* $ModDesc: Provides /sslinfo command used to test who a mask matches */
diff --git a/src/modules/extra/m_testclient.cpp b/src/modules/extra/m_testclient.cpp
index 10e11cf02..670533dc3 100644
--- a/src/modules/extra/m_testclient.cpp
+++ b/src/modules/extra/m_testclient.cpp
@@ -11,18 +11,13 @@
* ---------------------------------------------------
*/
-#include <string>
-
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-
-#include "inspircd.h"
#include "configreader.h"
#include "m_sqlv2.h"
-
-
class ModuleTestClient : public Module
{
private:
diff --git a/src/modules/extra/m_ziplink.cpp b/src/modules/extra/m_ziplink.cpp
index 2677d3088..1e9c32d26 100644
--- a/src/modules/extra/m_ziplink.cpp
+++ b/src/modules/extra/m_ziplink.cpp
@@ -11,18 +11,13 @@
* ---------------------------------------------------
*/
-#include "zlib.h"
-
-#include "inspircd_config.h"
-#include "configreader.h"
+#include "inspircd.h"
+#include <zlib.h>
#include "users.h"
#include "channels.h"
#include "modules.h"
-
#include "socket.h"
#include "hashcomp.h"
-#include "inspircd.h"
-
#include "transport.h"
/* $ModDesc: Provides zlib link support for servers */
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index 827aeaf30..2ac6ad55e 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -11,12 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "wildcard.h"
-#include <vector>
/* $ModDesc: Provides aliases of commands. */
diff --git a/src/modules/m_alltime.cpp b/src/modules/m_alltime.cpp
index a24e3c979..16b692518 100644
--- a/src/modules/m_alltime.cpp
+++ b/src/modules/m_alltime.cpp
@@ -11,8 +11,6 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
#include "inspircd.h"
#include "modules.h"
diff --git a/src/modules/m_antibear.cpp b/src/modules/m_antibear.cpp
index f0affea7e..f72d607b5 100644
--- a/src/modules/m_antibear.cpp
+++ b/src/modules/m_antibear.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "xline.h"
/* $ModDesc: Sends a numeric on connect which cripples a common type of trojan/spambot */
diff --git a/src/modules/m_antibottler.cpp b/src/modules/m_antibottler.cpp
index 93a5691ef..38ef873d8 100644
--- a/src/modules/m_antibottler.cpp
+++ b/src/modules/m_antibottler.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
diff --git a/src/modules/m_auditorium.cpp b/src/modules/m_auditorium.cpp
index 15ef1943e..8d73f94f0 100644
--- a/src/modules/m_auditorium.cpp
+++ b/src/modules/m_auditorium.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list */
diff --git a/src/modules/m_banexception.cpp b/src/modules/m_banexception.cpp
index 629e43078..d8bda2a85 100644
--- a/src/modules/m_banexception.cpp
+++ b/src/modules/m_banexception.cpp
@@ -11,13 +11,11 @@
* ---------------------------------------------------
*/
-#include <string>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "mode.h"
-#include "inspircd.h"
#include "u_listmode.h"
#include "wildcard.h"
diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp
index ffe7724e2..19a34bb27 100644
--- a/src/modules/m_banredirect.cpp
+++ b/src/modules/m_banredirect.cpp
@@ -11,11 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "mode.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Allows an extended ban (+b) syntax redirecting banned users to another channel */
diff --git a/src/modules/m_blockamsg.cpp b/src/modules/m_blockamsg.cpp
index f1a388890..31c536dd5 100644
--- a/src/modules/m_blockamsg.cpp
+++ b/src/modules/m_blockamsg.cpp
@@ -11,15 +11,11 @@
* ---------------------------------------------------
*/
-#include <string>
-#include <time.h>
-#include "inspircd_config.h"
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-
#include "hashcomp.h"
-#include "inspircd.h"
/* $ModDesc: Attempt to block /amsg, at least some of the irritating mIRC scripts. */
diff --git a/src/modules/m_blockcaps.cpp b/src/modules/m_blockcaps.cpp
index a3991177b..2f5807c53 100644
--- a/src/modules/m_blockcaps.cpp
+++ b/src/modules/m_blockcaps.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "mode.h"
/* $ModDesc: Provides support for channel mode +P to block all-CAPS channel messages and notices */
diff --git a/src/modules/m_blockcolor.cpp b/src/modules/m_blockcolor.cpp
index c63a44ea7..6dd42209f 100644
--- a/src/modules/m_blockcolor.cpp
+++ b/src/modules/m_blockcolor.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <sstream>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style channel mode +c */
diff --git a/src/modules/m_botmode.cpp b/src/modules/m_botmode.cpp
index a4cebc4c7..6e53273ac 100644
--- a/src/modules/m_botmode.cpp
+++ b/src/modules/m_botmode.cpp
@@ -11,13 +11,13 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include <stdio.h>
#include <string>
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style umode +B */
diff --git a/src/modules/m_cban.cpp b/src/modules/m_cban.cpp
index 9aaf5fc6d..b6e197c2f 100644
--- a/src/modules/m_cban.cpp
+++ b/src/modules/m_cban.cpp
@@ -11,12 +11,12 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include <algorithm>
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Gives /cban, aka C:lines. Think Q:lines, for channels. */
diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp
index ae254a120..fc2c55a96 100644
--- a/src/modules/m_censor.cpp
+++ b/src/modules/m_censor.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
typedef std::map<irc::string,irc::string> censor_t;
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index 671588d18..0ec98ed79 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -11,13 +11,10 @@
* ---------------------------------------------------
*/
-#include <vector>
-#include <string>
-#include <stdlib.h>
+#include "inspircd.h"
#include "users.h"
#include "modules.h"
#include "dns.h"
-#include "inspircd.h"
#ifndef WINDOWS
#include <sys/socket.h>
#include <netinet/in.h>
diff --git a/src/modules/m_chancreate.cpp b/src/modules/m_chancreate.cpp
index 1efdf2996..ee42a15bf 100644
--- a/src/modules/m_chancreate.cpp
+++ b/src/modules/m_chancreate.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Creates a snomask with notices whenever a new channel is created */
diff --git a/src/modules/m_chanfilter.cpp b/src/modules/m_chanfilter.cpp
index 4008eb349..901494b95 100644
--- a/src/modules/m_chanfilter.cpp
+++ b/src/modules/m_chanfilter.cpp
@@ -11,15 +11,12 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
#include "u_listmode.h"
-#include "inspircd.h"
/* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
/* $ModDep: ../../include/u_listmode.h */
diff --git a/src/modules/m_chanprotect.cpp b/src/modules/m_chanprotect.cpp
index d35a81532..1afba46ba 100644
--- a/src/modules/m_chanprotect.cpp
+++ b/src/modules/m_chanprotect.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides channel modes +a and +q */
/* $ModDep: ../../include/u_listmode.h */
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp
index d12513af9..ba6f65673 100644
--- a/src/modules/m_check.cpp
+++ b/src/modules/m_check.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "wildcard.h"
/* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp
index f3f7f6387..727495932 100644
--- a/src/modules/m_chghost.cpp
+++ b/src/modules/m_chghost.cpp
@@ -11,14 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Provides support for the CHGHOST command */
/** Handle /CHGHOST
diff --git a/src/modules/m_chgident.cpp b/src/modules/m_chgident.cpp
index 8c251b2bc..740eeadf1 100644
--- a/src/modules/m_chgident.cpp
+++ b/src/modules/m_chgident.cpp
@@ -11,10 +11,9 @@
* ---------------------------------------------------
*/
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for the CHGIDENT command */
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp
index 1b6888426..b5f8373fc 100644
--- a/src/modules/m_cloaking.cpp
+++ b/src/modules/m_cloaking.cpp
@@ -11,13 +11,10 @@
* ---------------------------------------------------
*/
-#include "inspircd_config.h"
-#include "configreader.h"
#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-
#include "m_hash.h"
/* $ModDesc: Provides masking of user hostnames */
diff --git a/src/modules/m_clones.cpp b/src/modules/m_clones.cpp
index afb0c3a4b..2a974f9ca 100644
--- a/src/modules/m_clones.cpp
+++ b/src/modules/m_clones.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "wildcard.h"
/* $ModDesc: Provides the /clones command to retrieve information on a user, channel, or IP address */
diff --git a/src/modules/m_conn_join.cpp b/src/modules/m_conn_join.cpp
index b125a772b..be0ff687f 100644
--- a/src/modules/m_conn_join.cpp
+++ b/src/modules/m_conn_join.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Forces users to join the specified channel(s) on connect */
diff --git a/src/modules/m_conn_umodes.cpp b/src/modules/m_conn_umodes.cpp
index cfed84c45..d880853ad 100644
--- a/src/modules/m_conn_umodes.cpp
+++ b/src/modules/m_conn_umodes.cpp
@@ -11,11 +11,9 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
-#include "inspircd.h"
#include "modules.h"
#include "wildcard.h"
diff --git a/src/modules/m_conn_waitpong.cpp b/src/modules/m_conn_waitpong.cpp
index 9370b9931..20d20bd7c 100644
--- a/src/modules/m_conn_waitpong.cpp
+++ b/src/modules/m_conn_waitpong.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdlib.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
diff --git a/src/modules/m_connflood.cpp b/src/modules/m_connflood.cpp
index 08ba6bbc2..eb9c9af92 100644
--- a/src/modules/m_connflood.cpp
+++ b/src/modules/m_connflood.cpp
@@ -11,11 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Connection throttle */
int conns = 0, throttled = 0;
diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp
index 367a3769e..e875302b8 100644
--- a/src/modules/m_dccallow.cpp
+++ b/src/modules/m_dccallow.cpp
@@ -11,13 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <vector>
-#include <string.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Povides support for the /DCCALLOW command */
diff --git a/src/modules/m_deaf.cpp b/src/modules/m_deaf.cpp
index 109916881..20a2e0f3d 100644
--- a/src/modules/m_deaf.cpp
+++ b/src/modules/m_deaf.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for ircu style usermode +d (deaf to channel messages and channel notices) */
diff --git a/src/modules/m_denychans.cpp b/src/modules/m_denychans.cpp
index d143bffbf..3b3cd50fa 100644
--- a/src/modules/m_denychans.cpp
+++ b/src/modules/m_denychans.cpp
@@ -11,11 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
-#include "inspircd.h"
#include "wildcard.h"
/* $ModDesc: Implements config tags which allow blocking of joins to channels */
diff --git a/src/modules/m_devoice.cpp b/src/modules/m_devoice.cpp
index 3c21a64f6..37ad8e4c6 100644
--- a/src/modules/m_devoice.cpp
+++ b/src/modules/m_devoice.cpp
@@ -18,11 +18,10 @@
/* $ModDesc: Provides voiced users with the ability to devoice themselves. */
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/** Handle /DEVOICE
*/
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index b0c932ada..652e4d85b 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "m_filter.h"
/* $ModDesc: An advanced spam filtering module */
diff --git a/src/modules/m_foobar.cpp b/src/modules/m_foobar.cpp
index cd0b15bd9..0270c1401 100644
--- a/src/modules/m_foobar.cpp
+++ b/src/modules/m_foobar.cpp
@@ -11,12 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: A dummy module for testing */
// Class ModuleFoobar inherits from Module
diff --git a/src/modules/m_globalload.cpp b/src/modules/m_globalload.cpp
index 7cc38eaa1..1d5e8f18b 100644
--- a/src/modules/m_globalload.cpp
+++ b/src/modules/m_globalload.cpp
@@ -13,11 +13,10 @@
/* $ModDesc: Allows global loading of a module. */
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/** Handle /GLOADMODULE
*/
diff --git a/src/modules/m_globops.cpp b/src/modules/m_globops.cpp
index 4dbe8dfb5..95a1e1e37 100644
--- a/src/modules/m_globops.cpp
+++ b/src/modules/m_globops.cpp
@@ -13,12 +13,10 @@
// Globops and +g support module by C.J.Edwards
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for GLOBOPS and user mode +g */
diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp
index 5a02f2bf0..d25e2c0bd 100644
--- a/src/modules/m_helpop.cpp
+++ b/src/modules/m_helpop.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: /helpop Command, Works like Unreal helpop */
static std::map<irc::string, std::string> helpop_map;
diff --git a/src/modules/m_hidechans.cpp b/src/modules/m_hidechans.cpp
index cf7c95c0f..976d8bb49 100644
--- a/src/modules/m_hidechans.cpp
+++ b/src/modules/m_hidechans.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for hiding channels with user mode +I */
diff --git a/src/modules/m_hideoper.cpp b/src/modules/m_hideoper.cpp
index afc2e6cfa..c322fdf3f 100644
--- a/src/modules/m_hideoper.cpp
+++ b/src/modules/m_hideoper.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for hiding oper status with user mode +H */
diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp
index d2e51a187..d8f0aaf59 100644
--- a/src/modules/m_hostchange.cpp
+++ b/src/modules/m_hostchange.cpp
@@ -11,11 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp
index 49c8d8803..04ddb22c3 100644
--- a/src/modules/m_httpd.cpp
+++ b/src/modules/m_httpd.cpp
@@ -11,9 +11,9 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include <algorithm>
#include "modules.h"
-#include "inspircd.h"
#include "httpd.h"
/* $ModDesc: Provides HTTP serving facilities to modules */
diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp
index e800b3d98..3bd27a2aa 100644
--- a/src/modules/m_httpd_stats.cpp
+++ b/src/modules/m_httpd_stats.cpp
@@ -11,14 +11,13 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "configreader.h"
#include "modules.h"
#include "inspsocket.h"
#include "httpd.h"
-#include "inspircd.h"
/* $ModDesc: Provides statistics over HTTP via m_httpd.so */
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index 00d12b8ec..3f3399d3c 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for RFC 1413 ident lookups */
diff --git a/src/modules/m_invisible.cpp b/src/modules/m_invisible.cpp
index 30a20f2ed..96bc705b3 100644
--- a/src/modules/m_invisible.cpp
+++ b/src/modules/m_invisible.cpp
@@ -11,11 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-#include "stdarg.h"
+#include <stdarg.h>
/* $ModDesc: Allows for opered clients to join channels without being seen, similar to unreal 3.1 +I mode */
diff --git a/src/modules/m_inviteexception.cpp b/src/modules/m_inviteexception.cpp
index 88c2c507f..11add8046 100644
--- a/src/modules/m_inviteexception.cpp
+++ b/src/modules/m_inviteexception.cpp
@@ -11,8 +11,7 @@
* ---------------------------------------------------
*/
-#include <string>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp
index b869e5020..bd5b186c0 100644
--- a/src/modules/m_joinflood.cpp
+++ b/src/modules/m_joinflood.cpp
@@ -11,13 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <map>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Provides channel mode +j (join flood protection) */
diff --git a/src/modules/m_jumpserver.cpp b/src/modules/m_jumpserver.cpp
index f21fb8e3a..d936c4f82 100644
--- a/src/modules/m_jumpserver.cpp
+++ b/src/modules/m_jumpserver.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style SAPART command */
diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp
index 627786d35..3fa6c6c60 100644
--- a/src/modules/m_kicknorejoin.cpp
+++ b/src/modules/m_kicknorejoin.cpp
@@ -11,19 +11,14 @@
* ---------------------------------------------------
*/
-#include <time.h>
-#include <map>
-#include <vector>
+#include "inspircd.h"
#include <sstream>
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides channel mode +J (delay rejoin after kick) */
-
-
inline int strtoint(const std::string &str)
{
std::istringstream ss(str);
diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp
index a725844b7..a546a85ee 100644
--- a/src/modules/m_knock.cpp
+++ b/src/modules/m_knock.cpp
@@ -11,13 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for /KNOCK and mode +K */
diff --git a/src/modules/m_lockserv.cpp b/src/modules/m_lockserv.cpp
index 8a8471aa5..cbc454778 100644
--- a/src/modules/m_lockserv.cpp
+++ b/src/modules/m_lockserv.cpp
@@ -11,11 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Allows locking of the server to stop all incoming connections till unlocked again */
diff --git a/src/modules/m_md5.cpp b/src/modules/m_md5.cpp
index 5d6fdd00d..43afbc15c 100644
--- a/src/modules/m_md5.cpp
+++ b/src/modules/m_md5.cpp
@@ -14,15 +14,13 @@
/* $ModDesc: Allows for MD5 encrypted oper passwords */
/* $ModDep: m_hash.h */
-#include "inspircd_config.h"
+#include "inspircd.h"
#ifdef HAS_STDINT
#include <stdint.h>
#endif
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
#include "m_hash.h"
/* The four core functions - F1 is optimized somewhat */
diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp
index f36dacebd..e4510d155 100644
--- a/src/modules/m_messageflood.cpp
+++ b/src/modules/m_messageflood.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <map>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides channel mode +f (message flood protection) */
diff --git a/src/modules/m_namesx.cpp b/src/modules/m_namesx.cpp
index 5f0b0a483..de2f3f859 100644
--- a/src/modules/m_namesx.cpp
+++ b/src/modules/m_namesx.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
static const char* dummy = "ON";
diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp
index f80bff5b1..071eda8ee 100644
--- a/src/modules/m_nicklock.cpp
+++ b/src/modules/m_nicklock.cpp
@@ -11,18 +11,14 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-
#include "hashcomp.h"
-#include "inspircd.h"
/* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
-
/** Handle /NICKLOCK
*/
class cmd_nicklock : public command_t
diff --git a/src/modules/m_noctcp.cpp b/src/modules/m_noctcp.cpp
index 7ac9e0824..c9ed1297c 100644
--- a/src/modules/m_noctcp.cpp
+++ b/src/modules/m_noctcp.cpp
@@ -11,15 +11,13 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style channel mode +c */
-
-
class NoCTCP : public ModeHandler
{
public:
diff --git a/src/modules/m_noinvite.cpp b/src/modules/m_noinvite.cpp
index db3ae400f..219c1c78f 100644
--- a/src/modules/m_noinvite.cpp
+++ b/src/modules/m_noinvite.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style channel mode +V */
diff --git a/src/modules/m_nokicks.cpp b/src/modules/m_nokicks.cpp
index 975d86e3b..e5a37ed62 100644
--- a/src/modules/m_nokicks.cpp
+++ b/src/modules/m_nokicks.cpp
@@ -11,16 +11,13 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style channel mode +Q */
-
-
class NoKicks : public ModeHandler
{
public:
diff --git a/src/modules/m_nonicks.cpp b/src/modules/m_nonicks.cpp
index 1ac82ed29..e7f23e145 100644
--- a/src/modules/m_nonicks.cpp
+++ b/src/modules/m_nonicks.cpp
@@ -11,12 +11,12 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for channel mode +N which prevents nick changes on channel */
diff --git a/src/modules/m_nonotice.cpp b/src/modules/m_nonotice.cpp
index 528eeb0f4..58a69da04 100644
--- a/src/modules/m_nonotice.cpp
+++ b/src/modules/m_nonotice.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style channel mode +T */
diff --git a/src/modules/m_oper_hash.cpp b/src/modules/m_oper_hash.cpp
index 80869898c..a3f6e5210 100644
--- a/src/modules/m_oper_hash.cpp
+++ b/src/modules/m_oper_hash.cpp
@@ -14,12 +14,10 @@
/* $ModDesc: Allows for hashed oper passwords */
/* $ModDep: m_hash.h */
-#include "inspircd_config.h"
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
#include "m_hash.h"
typedef std::map<irc::string, Module*> hashymodules;
diff --git a/src/modules/m_operchans.cpp b/src/modules/m_operchans.cpp
index bfeed72bf..404a02183 100644
--- a/src/modules/m_operchans.cpp
+++ b/src/modules/m_operchans.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for oper-only chans via the +O channel mode */
diff --git a/src/modules/m_operjoin.cpp b/src/modules/m_operjoin.cpp
index 12c17745a..5576fd3f9 100644
--- a/src/modules/m_operjoin.cpp
+++ b/src/modules/m_operjoin.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Forces opers to join the specified channel(s) on oper-up */
diff --git a/src/modules/m_operlevels.cpp b/src/modules/m_operlevels.cpp
index 8832596f6..6e337a914 100644
--- a/src/modules/m_operlevels.cpp
+++ b/src/modules/m_operlevels.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include <string>
-
-#include "inspircd.h"
/* $ModDesc: Gives each oper type a 'level', cannot kill opers 'above' your level. */
diff --git a/src/modules/m_operlog.cpp b/src/modules/m_operlog.cpp
index ce6e7aea4..c2524fb51 100644
--- a/src/modules/m_operlog.cpp
+++ b/src/modules/m_operlog.cpp
@@ -10,12 +10,11 @@
*
* ---------------------------------------------------
*/
-
+
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-#include <vector>
/* $ModDesc: A module which logs all oper commands to the ircd log at default loglevel. */
diff --git a/src/modules/m_opermodes.cpp b/src/modules/m_opermodes.cpp
index 30f6fef9c..25c1b4fe6 100644
--- a/src/modules/m_opermodes.cpp
+++ b/src/modules/m_opermodes.cpp
@@ -11,11 +11,9 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
-#include "inspircd.h"
#include "modules.h"
/* $ModDesc: Sets (and unsets) modes on opers when they oper up */
diff --git a/src/modules/m_opermotd.cpp b/src/modules/m_opermotd.cpp
index f08b287bd..294ea4c2b 100644
--- a/src/modules/m_opermotd.cpp
+++ b/src/modules/m_opermotd.cpp
@@ -11,13 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
static FileReader* opermotd;
diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp
index e7f424194..e19cf7652 100644
--- a/src/modules/m_override.cpp
+++ b/src/modules/m_override.cpp
@@ -11,11 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "configreader.h"
-#include "inspircd.h"
#include "wildcard.h"
/* $ModDesc: Provides support for unreal-style oper-override */
diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp
index 701e5da91..a720be522 100644
--- a/src/modules/m_randquote.cpp
+++ b/src/modules/m_randquote.cpp
@@ -11,13 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
-
static FileReader *quotes = NULL;
std::string q_file = "";
diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp
index ae522bf38..0cbbf751a 100644
--- a/src/modules/m_redirect.cpp
+++ b/src/modules/m_redirect.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides channel mode +L (limit redirection) */
diff --git a/src/modules/m_regonlycreate.cpp b/src/modules/m_regonlycreate.cpp
index 33207da3e..5a85f4d65 100644
--- a/src/modules/m_regonlycreate.cpp
+++ b/src/modules/m_regonlycreate.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Prevents users who's nicks are not registered from creating new channels */
diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp
index 56a54fc37..714490d82 100644
--- a/src/modules/m_remove.cpp
+++ b/src/modules/m_remove.cpp
@@ -11,12 +11,12 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include <sstream>
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
diff --git a/src/modules/m_restrictbanned.cpp b/src/modules/m_restrictbanned.cpp
index 6f0e991e5..c78fd621d 100644
--- a/src/modules/m_restrictbanned.cpp
+++ b/src/modules/m_restrictbanned.cpp
@@ -11,12 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Restricts banned users in a channel. May not speak, etc. */
class ModuleRestrictBanned : public Module
diff --git a/src/modules/m_restrictchans.cpp b/src/modules/m_restrictchans.cpp
index e283440f4..4f8bc04bd 100644
--- a/src/modules/m_restrictchans.cpp
+++ b/src/modules/m_restrictchans.cpp
@@ -11,14 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <map>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Only opers may create new channels if this module is loaded */
class ModuleRestrictChans : public Module
diff --git a/src/modules/m_restrictmsg.cpp b/src/modules/m_restrictmsg.cpp
index e04366b59..0f4379030 100644
--- a/src/modules/m_restrictmsg.cpp
+++ b/src/modules/m_restrictmsg.cpp
@@ -11,15 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
diff --git a/src/modules/m_safelist.cpp b/src/modules/m_safelist.cpp
index 2bcb77a91..174b84833 100644
--- a/src/modules/m_safelist.cpp
+++ b/src/modules/m_safelist.cpp
@@ -10,12 +10,11 @@
*
* ---------------------------------------------------
*/
-
+
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "configreader.h"
-#include "inspircd.h"
#include "wildcard.h"
/** Holds a users m_safelist state
diff --git a/src/modules/m_sajoin.cpp b/src/modules/m_sajoin.cpp
index decce5aef..29abc0ba9 100644
--- a/src/modules/m_sajoin.cpp
+++ b/src/modules/m_sajoin.cpp
@@ -11,14 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Provides support for unreal-style SAJOIN command */
/** Handle /SAJOIN
diff --git a/src/modules/m_samode.cpp b/src/modules/m_samode.cpp
index 89956a17d..92800e701 100644
--- a/src/modules/m_samode.cpp
+++ b/src/modules/m_samode.cpp
@@ -13,11 +13,10 @@
/* $ModDesc: Provides more advanced UnrealIRCd SAMODE command */
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/** Handle /SAMODE
*/
diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp
index 34d9f9ab5..0bebff0b1 100644
--- a/src/modules/m_sanick.cpp
+++ b/src/modules/m_sanick.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for SANICK command */
diff --git a/src/modules/m_sapart.cpp b/src/modules/m_sapart.cpp
index 680b4b4d4..8d01bdf01 100644
--- a/src/modules/m_sapart.cpp
+++ b/src/modules/m_sapart.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style SAPART command */
diff --git a/src/modules/m_saquit.cpp b/src/modules/m_saquit.cpp
index a7cacac5c..037b7016a 100644
--- a/src/modules/m_saquit.cpp
+++ b/src/modules/m_saquit.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for an SAQUIT command, exits user with a reason */
diff --git a/src/modules/m_securelist.cpp b/src/modules/m_securelist.cpp
index 319b58603..9822f6937 100644
--- a/src/modules/m_securelist.cpp
+++ b/src/modules/m_securelist.cpp
@@ -10,14 +10,12 @@
*
* ---------------------------------------------------
*/
-
+
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include <vector>
-#include "inspircd.h"
-
/* $ModDesc: A module overriding /list, and making it safe - stop those sendq problems. */
class ModuleSecureList : public Module
diff --git a/src/modules/m_seenicks.cpp b/src/modules/m_seenicks.cpp
index 959a62b31..e472e60bb 100644
--- a/src/modules/m_seenicks.cpp
+++ b/src/modules/m_seenicks.cpp
@@ -11,12 +11,12 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for seeing local and remote nickchanges via snomasks */
diff --git a/src/modules/m_services.cpp b/src/modules/m_services.cpp
index b8638d94a..0e5c6b588 100644
--- a/src/modules/m_services.cpp
+++ b/src/modules/m_services.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
static bool kludgeme = false;
diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp
index 17c0b2bd9..27d9b335e 100644
--- a/src/modules/m_services_account.cpp
+++ b/src/modules/m_services_account.cpp
@@ -11,11 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
-#include "inspircd.h"
/* $ModDesc: Povides support for ircu-style services accounts, including chmode +R, etc. */
diff --git a/src/modules/m_sethost.cpp b/src/modules/m_sethost.cpp
index 62b6bda83..1cacef956 100644
--- a/src/modules/m_sethost.cpp
+++ b/src/modules/m_sethost.cpp
@@ -11,14 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Provides support for the SETHOST command */
/** Handle /SETHOST
diff --git a/src/modules/m_setident.cpp b/src/modules/m_setident.cpp
index f46c7112c..5122781f1 100644
--- a/src/modules/m_setident.cpp
+++ b/src/modules/m_setident.cpp
@@ -11,9 +11,9 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for the SETIDENT command */
diff --git a/src/modules/m_setidle.cpp b/src/modules/m_setidle.cpp
index 6539bbdc8..f396c5a04 100644
--- a/src/modules/m_setidle.cpp
+++ b/src/modules/m_setidle.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Allows opers to set their idle time */
diff --git a/src/modules/m_setname.cpp b/src/modules/m_setname.cpp
index 8661d9f2c..c93fde452 100644
--- a/src/modules/m_setname.cpp
+++ b/src/modules/m_setname.cpp
@@ -11,14 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Provides support for the SETNAME command */
diff --git a/src/modules/m_sha256.cpp b/src/modules/m_sha256.cpp
index 6e1ac0e56..26c70346e 100644
--- a/src/modules/m_sha256.cpp
+++ b/src/modules/m_sha256.cpp
@@ -50,15 +50,13 @@
/* $ModDesc: Allows for SHA-256 encrypted oper passwords */
/* $ModDep: m_hash.h */
-#include "inspircd_config.h"
+#include "inspircd.h"
#ifdef HAS_STDINT
#include <stdint.h>
#endif
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
-
#include "m_hash.h"
#ifndef HAS_STDINT
diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp
index 70c9865e1..d2324eb73 100644
--- a/src/modules/m_showwhois.cpp
+++ b/src/modules/m_showwhois.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */
diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp
index 773d28ece..8d8ed43c7 100644
--- a/src/modules/m_silence.cpp
+++ b/src/modules/m_silence.cpp
@@ -11,14 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
-#include "inspircd.h"
#include "wildcard.h"
/* $ModDesc: Provides support for the /SILENCE command */
diff --git a/src/modules/m_silence_ext.cpp b/src/modules/m_silence_ext.cpp
index 8b7ac9fbe..450cb14f8 100644
--- a/src/modules/m_silence_ext.cpp
+++ b/src/modules/m_silence_ext.cpp
@@ -11,15 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
-#include <vector>
-#include <stdarg.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
-#include "inspircd.h"
#include "wildcard.h"
/* $ModDesc: Provides support for the /SILENCE command */
diff --git a/src/modules/m_spy.cpp b/src/modules/m_spy.cpp
index 356000f97..17998b964 100644
--- a/src/modules/m_spy.cpp
+++ b/src/modules/m_spy.cpp
@@ -18,11 +18,10 @@
/* $ModDesc: Provides SPYLIST and SPYNAMES capability, allowing opers to see who's in +s channels */
-#include "inspircd_config.h"
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
#include "wildcard.h"
void spy_userlist(userrec *user, chanrec *c)
diff --git a/src/modules/m_ssl_dummy.cpp b/src/modules/m_ssl_dummy.cpp
index 9995e7524..603a0da0e 100644
--- a/src/modules/m_ssl_dummy.cpp
+++ b/src/modules/m_ssl_dummy.cpp
@@ -11,10 +11,9 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "modules.h"
-#include "inspircd.h"
-
/* $ModDesc: Makes remote /whoises to SSL servers work on a non-ssl server */
diff --git a/src/modules/m_sslmodes.cpp b/src/modules/m_sslmodes.cpp
index 92f623fe1..c8eee5a03 100644
--- a/src/modules/m_sslmodes.cpp
+++ b/src/modules/m_sslmodes.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for unreal-style channel mode +z */
diff --git a/src/modules/m_stripcolor.cpp b/src/modules/m_stripcolor.cpp
index 446fd6d61..f8130336d 100644
--- a/src/modules/m_stripcolor.cpp
+++ b/src/modules/m_stripcolor.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides channel +S mode (strip ansi colour) */
diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp
index 5e0f072f8..44206d277 100644
--- a/src/modules/m_svshold.cpp
+++ b/src/modules/m_svshold.cpp
@@ -11,12 +11,12 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include <algorithm>
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "configreader.h"
-#include "inspircd.h"
/* $ModDesc: Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services. */
diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp
index 193191ab5..0c538d88b 100644
--- a/src/modules/m_swhois.cpp
+++ b/src/modules/m_swhois.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
diff --git a/src/modules/m_taxonomy.cpp b/src/modules/m_taxonomy.cpp
index 9fb38d98e..413218082 100644
--- a/src/modules/m_taxonomy.cpp
+++ b/src/modules/m_taxonomy.cpp
@@ -11,11 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides the /TAXONOMY command, used to view all metadata attached to a user */
diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp
index e32e5f846..a32559c68 100644
--- a/src/modules/m_testcommand.cpp
+++ b/src/modules/m_testcommand.cpp
@@ -11,12 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "dns.h"
-#include "inspircd.h"
/* $ModDesc: Povides a proof-of-concept test /WOOT command */
diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp
index 6106abc9a..473785149 100644
--- a/src/modules/m_timedbans.cpp
+++ b/src/modules/m_timedbans.cpp
@@ -13,15 +13,12 @@
/* $ModDesc: Adds timed bans */
-#include <stdio.h>
-#include <vector>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
#include "configreader.h"
-#include "inspircd.h"
-
/** Holds a timed ban
*/
diff --git a/src/modules/m_tline.cpp b/src/modules/m_tline.cpp
index b5017ea2d..37437b5fd 100644
--- a/src/modules/m_tline.cpp
+++ b/src/modules/m_tline.cpp
@@ -11,13 +11,11 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "wildcard.h"
-#include "inspircd.h"
-#include "dns.h"
/* $ModDesc: Provides /tline command used to test who a mask matches */
diff --git a/src/modules/m_uhnames.cpp b/src/modules/m_uhnames.cpp
index a918b4234..3bcfdd2dd 100644
--- a/src/modules/m_uhnames.cpp
+++ b/src/modules/m_uhnames.cpp
@@ -11,10 +11,10 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
static const char* dummy = "ON";
diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp
index babc4dc9f..fe9950e98 100644
--- a/src/modules/m_uninvite.cpp
+++ b/src/modules/m_uninvite.cpp
@@ -13,12 +13,11 @@
/* $ModDesc: Provides the UNINVITE command which lets users un-invite other users from channels (!) */
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "configreader.h"
-#include "inspircd.h"
/** Handle /UNINVITE
*/
diff --git a/src/modules/m_userip.cpp b/src/modules/m_userip.cpp
index b623c39ba..29b1eb5fa 100644
--- a/src/modules/m_userip.cpp
+++ b/src/modules/m_userip.cpp
@@ -11,12 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for USERIP command */
diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp
index 02926dbfa..1b32cba3b 100644
--- a/src/modules/m_vhost.cpp
+++ b/src/modules/m_vhost.cpp
@@ -11,11 +11,10 @@
* ---------------------------------------------------
*/
-#include <stdio.h>
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
-#include "inspircd.h"
/* $ModDesc: Provides masking of user hostnames via traditional /VHOST command */
diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp
index 4aeead214..77bbf90a1 100644
--- a/src/modules/m_watch.cpp
+++ b/src/modules/m_watch.cpp
@@ -11,11 +11,11 @@
* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
-#include "inspircd.h"
/* $ModDesc: Provides support for the /WATCH command */
diff --git a/src/modules/m_xmlsocket.cpp b/src/modules/m_xmlsocket.cpp
index 3603f2fb5..face79635 100644
--- a/src/modules/m_xmlsocket.cpp
+++ b/src/modules/m_xmlsocket.cpp
@@ -11,13 +11,11 @@
* ---------------------------------------------------
*/
-#include "inspircd_config.h"
-#include "configreader.h"
+#include "inspircd.h"
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "hashcomp.h"
-#include "inspircd.h"
/* $ModDesc: Provides XMLSocket support for clients */