summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--data/CMakeLists.txt2
-rw-r--r--data/example.conf4
-rw-r--r--data/mysql/tables.sql354
-rw-r--r--data/tables.sql386
-rw-r--r--docs/MYSQL27
-rw-r--r--include/modules.h119
-rw-r--r--include/services.h1
-rw-r--r--include/sockets.h24
-rw-r--r--modules/CMakeLists.txt1
-rw-r--r--modules/extra/db_mysql.cpp1550
-rw-r--r--modules/extra/m_mysql.cpp414
-rw-r--r--modules/extra/mysql/db_mysql.h212
-rw-r--r--modules/extra/mysql/db_mysql_execute.cpp159
-rw-r--r--modules/extra/mysql/db_mysql_read.cpp618
-rw-r--r--modules/extra/mysql/db_mysql_write.cpp1040
-rw-r--r--modules/extra/sql.h82
-rw-r--r--modules/socketengines/m_socketengine_epoll.cpp8
-rw-r--r--modules/socketengines/m_socketengine_select.cpp2
-rw-r--r--src/CMakeLists.txt14
-rwxr-xr-xsrc/bin/mydbgen5
-rw-r--r--src/module.cpp11
-rw-r--r--src/modulemanager.cpp34
-rw-r--r--src/modules.cpp16
-rw-r--r--src/socketengines/socketengine_eventfd.cpp47
-rw-r--r--src/socketengines/socketengine_pipe.cpp50
-rw-r--r--src/socketengines/socketengine_win32.cpp76
-rw-r--r--src/sockets.cpp7
28 files changed, 2805 insertions, 2459 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 64d533dcf..30810405b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -330,6 +330,7 @@ check_function_exists(strlcat HAVE_STRLCAT)
check_function_exists(strlcpy HAVE_STRLCPY)
check_function_exists(umask HAVE_UMASK)
check_function_exists(backtrace HAVE_BACKTRACE)
+check_function_exists(eventfd HAVE_EVENTFD)
# Check for the existance of the following types
check_type_size(uint8_t UINT8_T)
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
index 63d55d4cd..461ea287a 100644
--- a/data/CMakeLists.txt
+++ b/data/CMakeLists.txt
@@ -1,6 +1,6 @@
# Only install example.chk and example.conf from this directory
# NOTE: I would've had this just find all files in the directory, but that would include files not needed (like this file)
-set(DATA example.chk example.conf tables.sql)
+set(DATA example.chk example.conf mysql/tables.sql)
install(FILES ${DATA}
DESTINATION data
)
diff --git a/data/example.conf b/data/example.conf
index 1a9ee7ff3..c580399fb 100644
--- a/data/example.conf
+++ b/data/example.conf
@@ -292,9 +292,7 @@ options
*
* Supported:
* - db_plain
- * - db_mysql_write
- * - db_mysql_read
- * - db_mysql_execute
+ * - db_mysql
*/
database = "db_plain"
diff --git a/data/mysql/tables.sql b/data/mysql/tables.sql
new file mode 100644
index 000000000..6b9c41b89
--- /dev/null
+++ b/data/mysql/tables.sql
@@ -0,0 +1,354 @@
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+--
+-- Table structure for table `anope_bs_badwords`
+--
+
+DROP TABLE IF EXISTS `anope_bs_badwords`;
+CREATE TABLE IF NOT EXISTS `anope_bs_badwords` (
+ `channel` varchar(255) NOT NULL default '',
+ `word` varchar(255) NOT NULL,
+ `type` varchar(50) NOT NULL,
+ UNIQUE KEY `channel` (`channel`,`word`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_bs_core`
+--
+
+DROP TABLE IF EXISTS `anope_bs_core`;
+CREATE TABLE IF NOT EXISTS `anope_bs_core` (
+ `nick` varchar(255) NOT NULL default '',
+ `user` varchar(255) NOT NULL default '',
+ `host` text NOT NULL,
+ `rname` text NOT NULL,
+ `flags` text NOT NULL,
+ `created` int(10) unsigned NOT NULL default '0',
+ `chancount` int(11) NOT NULL default '0',
+ PRIMARY KEY (`nick`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_bs_info_metadata`
+--
+
+DROP TABLE IF EXISTS `anope_bs_info_metadata`;
+CREATE TABLE IF NOT EXISTS `anope_bs_info_metadata` (
+ `botname` varchar(255) NOT NULL default '',
+ `name` varchar(255) NOT NULL default '',
+ `value` text NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_cs_access`
+--
+
+DROP TABLE IF EXISTS `anope_cs_access`;
+CREATE TABLE IF NOT EXISTS `anope_cs_access` (
+ `level` int(11) NOT NULL default '0',
+ `display` varchar(255) NOT NULL default '',
+ `channel` varchar(255) NOT NULL default '',
+ `last_seen` int(10) unsigned NOT NULL default '0',
+ `creator` varchar(255) NOT NULL default '',
+ UNIQUE KEY `channel` (`channel`,`display`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_cs_akick`
+--
+
+DROP TABLE IF EXISTS `anope_cs_akick`;
+CREATE TABLE IF NOT EXISTS `anope_cs_akick` (
+ `channel` varchar(255) NOT NULL default '',
+ `flags` varchar(255) NOT NULL default '',
+ `mask` varchar(255) NOT NULL default '',
+ `reason` text NOT NULL,
+ `creator` varchar(255) NOT NULL default '',
+ `created` int(10) unsigned NOT NULL default '0',
+ `last_used` int(10) unsigned NOT NULL default '0',
+ UNIQUE KEY `channel` (`channel`,`mask`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_cs_info`
+--
+
+DROP TABLE IF EXISTS `anope_cs_info`;
+CREATE TABLE IF NOT EXISTS `anope_cs_info` (
+ `name` varchar(255) NOT NULL default '',
+ `founder` text NOT NULL,
+ `successor` text NOT NULL,
+ `descr` text NOT NULL,
+ `time_registered` int(10) unsigned NOT NULL default '0',
+ `last_used` int(10) unsigned NOT NULL default '0',
+ `last_topic` text NOT NULL,
+ `last_topic_setter` text NOT NULL,
+ `last_topic_time` int(10) unsigned NOT NULL default '0',
+ `flags` text NOT NULL,
+ `forbidby` text NOT NULL,
+ `forbidreason` text NOT NULL,
+ `bantype` smallint(6) NOT NULL default '0',
+ `mlock_on` text NOT NULL,
+ `mlock_off` text NOT NULL,
+ `mlock_params` text NOT NULL,
+ `entry_message` text NOT NULL,
+ `memomax` smallint(5) unsigned NOT NULL default '0',
+ `botnick` varchar(255) NOT NULL default '',
+ `botflags` text NOT NULL,
+ `capsmin` smallint(6) NOT NULL default '0',
+ `capspercent` smallint(6) NOT NULL default '0',
+ `floodlines` smallint(6) NOT NULL default '0',
+ `floodsecs` smallint(6) NOT NULL default '0',
+ `repeattimes` smallint(6) NOT NULL default '0',
+ PRIMARY KEY (`name`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_cs_info_metadata`
+--
+
+DROP TABLE IF EXISTS `anope_cs_info_metadata`;
+CREATE TABLE IF NOT EXISTS `anope_cs_info_metadata` (
+ `channel` varchar(255) NOT NULL default '',
+ `name` varchar(255) NOT NULL default '',
+ `value` text NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_cs_levels`
+--
+
+DROP TABLE IF EXISTS `anope_cs_levels`;
+CREATE TABLE IF NOT EXISTS `anope_cs_levels` (
+ `channel` varchar(255) NOT NULL default '',
+ `position` int(11) NOT NULL default '0',
+ `level` int(11) NOT NULL default '0',
+ UNIQUE KEY `channel` (`channel`,`position`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_cs_ttb`
+--
+
+DROP TABLE IF EXISTS `anope_cs_ttb`;
+CREATE TABLE IF NOT EXISTS `anope_cs_ttb` (
+ `channel` varchar(255) NOT NULL default '',
+ `ttb_id` int(11) NOT NULL default '0',
+ `value` int(11) NOT NULL default '0',
+ UNIQUE KEY `channel` (`channel`,`ttb_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_extra`
+--
+
+DROP TABLE IF EXISTS `anope_extra`;
+CREATE TABLE IF NOT EXISTS `anope_extra` (
+ `data` text NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_info`
+--
+
+DROP TABLE IF EXISTS `anope_info`;
+CREATE TABLE IF NOT EXISTS `anope_info` (
+ `version` int(11) default NULL,
+ `date` datetime default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_ms_info`
+--
+
+DROP TABLE IF EXISTS `anope_ms_info`;
+CREATE TABLE IF NOT EXISTS `anope_ms_info` (
+ `receiver` varchar(255) NOT NULL,
+ `number` int(11) NOT NULL default '0',
+ `flags` int(11) NOT NULL default '0',
+ `time` int(10) unsigned NOT NULL default '0',
+ `sender` text NOT NULL,
+ `text` blob NOT NULL,
+ `serv` enum('NICK','CHAN') NOT NULL default 'NICK'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_ns_access`
+--
+
+DROP TABLE IF EXISTS `anope_ns_access`;
+CREATE TABLE IF NOT EXISTS `anope_ns_access` (
+ `display` varchar(255) NOT NULL default '',
+ `access` varchar(160) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_ns_alias`
+--
+
+DROP TABLE IF EXISTS `anope_ns_alias`;
+CREATE TABLE IF NOT EXISTS `anope_ns_alias` (
+ `nick` varchar(255) NOT NULL default '',
+ `last_quit` text NOT NULL,
+ `last_realname` text NOT NULL,
+ `last_usermask` text NOT NULL,
+ `time_registered` int(10) unsigned NOT NULL default '0',
+ `last_seen` int(10) unsigned NOT NULL default '0',
+ `flags` text NOT NULL,
+ `display` varchar(255) NOT NULL default '',
+ PRIMARY KEY (`nick`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_ns_alias_metadata`
+--
+
+DROP TABLE IF EXISTS `anope_ns_alias_metadata`;
+CREATE TABLE IF NOT EXISTS `anope_ns_alias_metadata` (
+ `nick` varchar(255) NOT NULL default '',
+ `name` varchar(255) NOT NULL default '',
+ `value` text NOT NULL,
+ PRIMARY KEY (`name`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_ns_core`
+--
+
+DROP TABLE IF EXISTS `anope_ns_core`;
+CREATE TABLE IF NOT EXISTS `anope_ns_core` (
+ `display` varchar(255) NOT NULL default '',
+ `pass` text NOT NULL,
+ `email` text NOT NULL,
+ `greet` text NOT NULL,
+ `flags` text NOT NULL,
+ `language` smallint(5) unsigned NOT NULL default '0',
+ `channelcount` smallint(5) unsigned NOT NULL default '0',
+ `memomax` smallint(5) unsigned NOT NULL default '0',
+ PRIMARY KEY (`display`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_ns_core_metadata`
+--
+
+DROP TABLE IF EXISTS `anope_ns_core_metadata`;
+CREATE TABLE IF NOT EXISTS `anope_ns_core_metadata` (
+ `nick` varchar(255) NOT NULL default '',
+ `name` varchar(255) NOT NULL default '',
+ `value` text NOT NULL,
+ PRIMARY KEY (`name`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_ns_request`
+--
+
+DROP TABLE IF EXISTS `anope_ns_request`;
+CREATE TABLE IF NOT EXISTS `anope_ns_request` (
+ `nick` varchar(255) NOT NULL default '',
+ `passcode` text NOT NULL,
+ `password` text NOT NULL,
+ `email` text NOT NULL,
+ `requested` int(10) unsigned NOT NULL default '0',
+ PRIMARY KEY (`nick`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_os_akills`
+--
+
+DROP TABLE IF EXISTS `anope_os_akills`;
+CREATE TABLE IF NOT EXISTS `anope_os_akills` (
+ `user` varchar(255) NOT NULL,
+ `host` varchar(255) NOT NULL,
+ `xby` text NOT NULL,
+ `reason` text NOT NULL,
+ `seton` int(10) unsigned NOT NULL default '0',
+ `expire` int(10) unsigned NOT NULL default '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_os_core`
+--
+
+DROP TABLE IF EXISTS `anope_os_core`;
+CREATE TABLE IF NOT EXISTS `anope_os_core` (
+ `maxusercnt` int(11) NOT NULL default '0',
+ `maxusertime` int(10) unsigned NOT NULL default '0',
+ `akills_count` int(11) NOT NULL default '0',
+ `snlines_count` int(11) NOT NULL default '0',
+ `sqlines_count` int(11) NOT NULL default '0',
+ `szlines_count` int(11) NOT NULL default '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_os_exceptions`
+--
+
+DROP TABLE IF EXISTS `anope_os_exceptions`;
+CREATE TABLE IF NOT EXISTS `anope_os_exceptions` (
+ `mask` varchar(255) NOT NULL,
+ `slimit` int(11) NOT NULL default '0',
+ `who` text NOT NULL,
+ `reason` text NOT NULL,
+ `time` int(10) unsigned NOT NULL default '0',
+ `expires` int(10) unsigned NOT NULL default '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `anope_os_xlines`
+--
+
+DROP TABLE IF EXISTS `anope_os_xlines`;
+CREATE TABLE IF NOT EXISTS `anope_os_xlines` (
+ `type` varchar(20) NOT NULL,
+ `mask` varchar(255) NOT NULL,
+ `xby` text NOT NULL,
+ `reason` text NOT NULL,
+ `seton` int(10) unsigned NOT NULL default '0',
+ `expire` int(10) unsigned NOT NULL default '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
diff --git a/data/tables.sql b/data/tables.sql
deleted file mode 100644
index deeef41cc..000000000
--- a/data/tables.sql
+++ /dev/null
@@ -1,386 +0,0 @@
-
--- If you need to create your db, uncomment the following lines.
---
--- CREATE DATABASE anope;
--- USE anope;
-
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_extra'
---
-
-DROP TABLE IF EXISTS anope_extra;
-CREATE TABLE anope_extra (
- data text NOT NULL default ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_commands'
---
-
-DROP TABLE IF EXISTS anope_commands;
-CREATE TABLE anope_commands (
- nick varchar(255) NOT NULL default '',
- service varchar(255) NOT NULL default '',
- command text NOT NULL default ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_ns_core'
---
-
-DROP TABLE IF EXISTS anope_ns_core;
-CREATE TABLE anope_ns_core (
- display varchar(255) NOT NULL default '',
- pass text NOT NULL,
- email text NOT NULL default '',
- greet text NOT NULL default '',
- icq int(10) unsigned NOT NULL default '0',
- url text NOT NULL default '',
- flags text NOT NULL default '',
- language smallint(5) unsigned NOT NULL default '0',
- channelcount smallint(5) unsigned NOT NULL default '0',
- memomax smallint(5) unsigned NOT NULL default '0',
- PRIMARY KEY (display)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
---
--- Table structure for table 'anope_ns_core_metadata'
---
-
-DROP TABLE IF EXISTS anope_ns_core_metadata;
-CREATE TABLE anope_ns_core_metadata (
- nick varchar(255) NOT NULL default '',
- name varchar(255) NOT NULL default '',
- value text NOT NULL default '',
- PRIMARY KEY (name)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- ---------------------------------------------------------
---
--- Table structure for table 'anope_ns_alias'
---
-
-DROP TABLE IF EXISTS anope_ns_alias;
-CREATE TABLE anope_ns_alias (
- nick varchar(255) NOT NULL default '',
- last_quit text NOT NULL,
- last_realname text NOT NULL,
- last_usermask text NOT NULL,
- time_registered int(10) unsigned NOT NULL default '0',
- last_seen int(10) unsigned NOT NULL default '0',
- flags text NOT NULL default '',
- display varchar(255) NOT NULL default '',
- PRIMARY KEY (nick)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
---
--- Table structure for table 'anope_ns_alias_metadata'
---
-
-DROP TABLE IF EXISTS anope_ns_alias_metadata;
-CREATE TABLE anope_ns_alias_metadata (
- nick varchar(255) NOT NULL default '',
- name varchar(255) NOT NULL default '',
- value text NOT NULL default '',
- PRIMARY KEY (name)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_ns_access'
---
-
-DROP TABLE IF EXISTS anope_ns_access;
-CREATE TABLE anope_ns_access (
- display varchar(255) NOT NULL default '',
- access varchar(160) NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- ---------------------------------------------------------
-
---
--- Table structure for table 'anope_ns_request'
---
-
-DROP TABLE IF EXISTS anope_ns_request;
-CREATE TABLE anope_ns_request (
- nick varchar(255) NOT NULL default '',
- passcode text NOT NULL,
- password text NOT NULL,
- email text NOT NULL,
- requested int(10) unsigned NOT NULL default '0',
- PRIMARY KEY (nick)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_cs_access'
---
-
-DROP TABLE IF EXISTS anope_cs_access;
-CREATE TABLE anope_cs_access (
- level int(11) NOT NULL default '0',
- display varchar(255) NOT NULL default '',
- channel varchar(255) NOT NULL default '',
- last_seen int(10) unsigned NOT NULL default '0',
- creator varchar(255) NOT NULL default '',
- UNIQUE KEY (channel,display)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_cs_akick'
---
-
-DROP TABLE IF EXISTS anope_cs_akick;
-CREATE TABLE anope_cs_akick (
- channel varchar(255) NOT NULL default '',
- flags varchar(255) NOT NULL default '',
- mask varchar(255) NOT NULL default '',
- reason text NOT NULL default '',
- creator varchar(255) NOT NULL default '',
- created int(10) unsigned NOT NULL default '0',
- last_used int(10) unsigned NOT NULL default '0',
- UNIQUE KEY channel (channel, mask)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_bs_badwords'
---
-
-DROP TABLE IF EXISTS anope_bs_badwords;
-CREATE TABLE anope_bs_badwords (
- channel varchar(255) NOT NULL default '',
- word varchar(255) NOT NULL,
- type varchar(50) NOT NULL,
- UNIQUE KEY channel (channel,word)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_cs_info'
---
-
-DROP TABLE IF EXISTS anope_cs_info;
-CREATE TABLE anope_cs_info (
- name varchar(255) NOT NULL default '',
- founder text NOT NULL,
- successor text NOT NULL,
- descr text NOT NULL,
- url text NOT NULL,
- email text NOT NULL,
- time_registered int(10) unsigned NOT NULL default '0',
- last_used int(10) unsigned NOT NULL default '0',
- last_topic text NOT NULL,
- last_topic_setter text NOT NULL,
- last_topic_time int(10) unsigned NOT NULL default '0',
- flags text NOT NULL default '',
- forbidby text NOT NULL,
- forbidreason text NOT NULL,
- bantype smallint(6) NOT NULL default '0',
- mlock_on text NOT NULL default '',
- mlock_off text NOT NULL default '',
- mlock_params text NOT NULL default '',
- entry_message text NOT NULL,
- memomax smallint(5) unsigned NOT NULL default '0',
- botnick varchar(255) NOT NULL default '',
- botflags text NOT NULL default '',
- capsmin smallint(6) NOT NULL default '0',
- capspercent smallint(6) NOT NULL default '0',
- floodlines smallint(6) NOT NULL default '0',
- floodsecs smallint(6) NOT NULL default '0',
- repeattimes smallint(6) NOT NULL default '0',
- PRIMARY KEY (name)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_cs_info_metadata'
---
-
-DROP TABLE IF EXISTS anope_cs_info_metadata;
-CREATE TABLE anope_cs_info_metadata (
- channel varchar(255) NOT NULL default '',
- name varchar(255) NOT NULL default '',
- value text NOT NULL default ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_cs_levels'
---
-
-DROP TABLE IF EXISTS anope_cs_levels;
-CREATE TABLE anope_cs_levels (
- channel varchar(255) NOT NULL default '',
- position int(11) NOT NULL default '0',
- level int(11) NOT NULL default '0',
- UNIQUE KEY channel (channel,position)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_cs_ttb'
---
-
-DROP TABLE IF EXISTS anope_cs_ttb;
-CREATE TABLE anope_cs_ttb (
- channel varchar(255) NOT NULL default '',
- ttb_id int(11) NOT NULL default '0',
- value int(11) NOT NULL default '0',
- UNIQUE KEY channel (channel,ttb_id)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_bs_core'
---
-
-DROP TABLE IF EXISTS anope_bs_core;
-CREATE TABLE anope_bs_core (
- nick varchar(255) NOT NULL default '',
- user varchar(255) NOT NULL default '',
- host text NOT NULL default '',
- rname text NOT NULL default '',
- flags text NOT NULL default '',
- created int(10) unsigned NOT NULL default '0',
- chancount int(11) NOT NULL default '0',
- PRIMARY KEY (nick)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_bs_info_metadata'
---
-
-DROP TABLE IF EXISTS anope_bs_info_metadata;
-CREATE TABLE anope_bs_info_metadata (
- botname varchar(255) NOT NULL default '',
- name varchar(255) NOT NULL default '',
- value text NOT NULL default ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_ms_info'
---
-
-DROP TABLE IF EXISTS anope_ms_info;
-CREATE TABLE anope_ms_info (
- receiver varchar(255) NOT NULL,
- number int(11) NOT NULL default '0',
- flags int(11) NOT NULL default '0',
- time int(10) unsigned NOT NULL default '0',
- sender text NOT NULL,
- text blob NOT NULL,
- serv enum('NICK','CHAN') NOT NULL default 'NICK'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_os_akills'
---
-
-DROP TABLE IF EXISTS anope_os_akills;
-CREATE TABLE anope_os_akills (
- user varchar(255) NOT NULL,
- host varchar(255) NOT NULL,
- xby text NOT NULL,
- reason text NOT NULL,
- seton int(10) unsigned NOT NULL default '0',
- expire int(10) unsigned NOT NULL default '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_os_core'
---
-
-DROP TABLE IF EXISTS anope_os_core;
-CREATE TABLE anope_os_core (
- maxusercnt int(11) NOT NULL default '0',
- maxusertime int(10) unsigned NOT NULL default '0',
- akills_count int(11) NOT NULL default '0',
- snlines_count int(11) NOT NULL default '0',
- sqlines_count int(11) NOT NULL default '0',
- szlines_count int(11) NOT NULL default '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_os_exceptions'
---
-
-DROP TABLE IF EXISTS anope_os_exceptions;
-CREATE TABLE anope_os_exceptions (
- mask varchar(255) NOT NULL,
- slimit int(11) NOT NULL default '0',
- who text NOT NULL,
- reason text NOT NULL,
- time int(10) unsigned NOT NULL default '0',
- expires int(10) unsigned NOT NULL default '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_os_xlines'
---
-
-DROP TABLE IF EXISTS anope_os_xlines;
-CREATE TABLE anope_os_xlines (
- type varchar(20) NOT NULL,
- mask varchar(255) NOT NULL,
- xby text NOT NULL,
- reason text NOT NULL,
- seton int(10) unsigned NOT NULL default '0',
- expire int(10) unsigned NOT NULL default '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_metadata'
---
-
-DROP TABLE IF EXISTS anope_metadata;
-CREATE TABLE anope_metadata (
- name varchar(255) NOT NULL default '',
- value text NOT NULL default '',
- PRIMARY KEY (name)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
--- --------------------------------------------------------
-
---
--- Table structure for table 'anope_info'
---
-
-DROP TABLE IF EXISTS anope_info;
-CREATE TABLE anope_info (
- version int(11) default NULL,
- date datetime default NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
diff --git a/docs/MYSQL b/docs/MYSQL
deleted file mode 100644
index a72482107..000000000
--- a/docs/MYSQL
+++ /dev/null
@@ -1,27 +0,0 @@
-Anope MySQL Support
--------------------
-
-MySQL support was readded in version 1.9.2 In the form of three modules.
-
-db_mysql_read - Allows you to load your databases from MySQL.
-db_mysql_write - Allows live updating of SQL tables whenever something is executed in Anope.
-db_mysql_execute - Allows executing of Anope commands via SQL.
-
-To execute commands via SQL, you must insert the command into the anope_commands table, an example is as follows:
-
-INSERT INTO `anope_commands` (nick, service, command) VALUES('Adam', 'NickServ', 'REGISTER qwerty Adam@anope.org');
-
-By default, every 60 seconds Anope checks this table for commands to execute. When Anope sees a new command to execute, it checks the following.
-
-If the nick given is -SQLUser, then the command gets executed by a special fake user within Anope called -SQLUser. -SQLUser has every permission and command available, there are no permission checks at all for this user, it can do anything.
-
-If the nick is not -SQLUser, it checks to see if it is a registered nick. If it is, it sees if there are any users online using the NickCore of that nick.
- If there is a user online with that core the command gets executed as if that user executed it, and the reply goes to that user.
- If there isn't a user online with the core, it creates a fake user as the nick given to it, and gives to it the permissions the user would have if they were online and identified.
-If the nick is not registered, it checks to see if there is a user currently on that nick. If there is, it executes the command as that user, and the reply goes to that user.
- If the nick is not registered and no one is using the nick, it creates a fake user of the nick given to it, and gives it regular nonidentified user access.
-
-Currently there is no way to check to see if a command was executed successfully within Anope from SQL (even if there was, the possibly update delay would be a problem).
-
-IMPORTANT: When using db_mysql_write when you already have a database, you need to do an initial import of the data to SQL (as db_mysql_write only updates it when it is changed, it never actually mass-dumps all of your data into SQL). To do this, start Anope and execute /OperServ SQLSYNC.
-
diff --git a/include/modules.h b/include/modules.h
index 627e04383..307c83d87 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -160,9 +160,6 @@ extern CoreExport message_map MessageMap;
class Module;
extern CoreExport std::list<Module *> Modules;
-/*************************************************************************/
-/* Structure for information about a *Serv command. */
-
class Version
{
private:
@@ -1109,11 +1106,16 @@ enum Implementation
I_END
};
+class Service;
/** Used to manage modules.
*/
class CoreExport ModuleManager
{
+ private:
+ /** A map of service providers
+ */
+ static std::map<Anope::string, Service *> ServiceProviders;
public:
/** Event handler hooks.
* This needs to be public to be used by FOREACH_MOD and friends.
@@ -1202,6 +1204,24 @@ class CoreExport ModuleManager
*/
static void UnloadAll(bool unload_proto);
+ /** Register a service
+ * @param s The service
+ * @return true if it was successfully registeed, else false (service name colision)
+ */
+ static bool RegisterService(Service *s);
+
+ /** Unregister a service
+ * @param s The service
+ * @return true if it was unregistered successfully
+ */
+ static bool UnregisterService(Service *s);
+
+ /** Get a service
+ * @param name The service name
+ * @return The services, or NULL
+ */
+ static Service *GetService(const Anope::string &name);
+
private:
/** Call the module_delete function to safely delete the module
* @param m the module to delete
@@ -1229,6 +1249,99 @@ class CallBack : public Timer
}
};
+class Service
+{
+ public:
+ Module *owner;
+ Anope::string name;
+
+ Service(Module *o, const Anope::string &n);
+
+ virtual ~Service();
+};
+
+class dynamic_reference_base
+{
+ public:
+ dynamic_reference_base();
+
+ virtual ~dynamic_reference_base();
+};
+
+extern std::list<dynamic_reference_base *> dyn_references;
+
+template<typename T>
+class dynamic_reference : public dynamic_reference_base
+{
+ protected:
+ T *ref;
+ public:
+ dynamic_reference() : dynamic_reference_base(), ref(NULL) { }
+
+ dynamic_reference(T *obj) : dynamic_reference_base(), ref(obj) { }
+
+ virtual ~dynamic_reference() { }
+
+ virtual operator bool()
+ {
+ return this->ref;
+ }
+
+ virtual inline T *operator->()
+ {
+ return this->ref;
+ }
+
+ void Invalidate()
+ {
+ this->ref = NULL;
+ }
+
+ static void Invalidate(T *obj)
+ {
+ for (std::list<dynamic_reference_base *>::iterator it = dyn_references.begin(), it_end = dyn_references.end(); it != it_end;)
+ {
+ dynamic_reference<void *> *d = static_cast<dynamic_reference<void *> *>(*it);
+ ++it;
+
+ if (d && d->ref == obj)
+ {
+ d->Invalidate();
+ }
+ }
+ }
+};
+
+template<typename T>
+class service_reference : public dynamic_reference<T>
+{
+ Module *owner;
+ Anope::string name;
+
+ public:
+ service_reference(Module *o, const Anope::string &n) : dynamic_reference<T>(), owner(o), name(n)
+ {
+ }
+
+ ~service_reference()
+ {
+ }
+
+ operator bool()
+ {
+ if (!this->ref)
+ this->ref = static_cast<T *>(ModuleManager::GetService(this->name));
+ return this->ref;
+ }
+
+ inline T *operator->()
+ {
+ if (!this->ref)
+ this->ref = static_cast<T *>(ModuleManager::GetService(this->name));
+ return this->ref;
+ }
+};
+
struct Message
{
Anope::string name;
diff --git a/include/services.h b/include/services.h
index 1a81d6e96..15670c8ac 100644
--- a/include/services.h
+++ b/include/services.h
@@ -30,6 +30,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdexcept>
#include <string.h>
#include <signal.h>
diff --git a/include/sockets.h b/include/sockets.h
index 78ed5f4af..6eeb3bf3d 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -81,6 +81,10 @@ class CoreExport Socket : public Flags<SocketFlag, 1>
/* Type this socket is */
SocketType Type;
+ /** Empty constructor, used for things such as the pipe socket
+ */
+ Socket();
+
/** Default constructor
* @param nsock The socket to use, 0 if we need to create our own
* @param nIPv6 true if using ipv6
@@ -149,6 +153,26 @@ class CoreExport Socket : public Flags<SocketFlag, 1>
void Write(const Anope::string &message);
};
+class CoreExport Pipe : public Socket
+{
+ private:
+ int WritePipe;
+
+ int RecvInternal(char *buf, size_t sz) const;
+
+ int SendInternal(const Anope::string &buf) const;
+ public:
+ Pipe();
+
+ bool ProcessRead();
+
+ bool Read(const Anope::string &);
+
+ void Notify();
+
+ virtual void OnNotify();
+};
+
class CoreExport ClientSocket : public Socket
{
protected:
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt
index 8a90f3a3a..21ca74244 100644
--- a/modules/CMakeLists.txt
+++ b/modules/CMakeLists.txt
@@ -86,7 +86,6 @@ foreach(MODULE_FOLDER ${MODULES_FOLDERS})
# Get a list of ALL files and directories within this modules directory
file(GLOB SUBMODULE_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${MODULE_FOLDER}/*")
remove_item_from_list(SUBMODULE_DIRS "CMakeFiles")
- remove_item_from_list(SUBMODULE_DIRS "extra/mysql") # XXX till sql is fixed
foreach(SUBDIR ${SUBMODULE_DIRS})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}")
diff --git a/modules/extra/db_mysql.cpp b/modules/extra/db_mysql.cpp
new file mode 100644
index 000000000..e93abba10
--- /dev/null
+++ b/modules/extra/db_mysql.cpp
@@ -0,0 +1,1550 @@
+#include "module.h"
+#include "sql.h"
+
+struct NickAliasFlagInfo
+{
+ Anope::string Name;
+ NickNameFlag Flag;
+};
+
+NickAliasFlagInfo NickAliasFlags[] = {
+ {"FORBIDDEN", NS_FORBIDDEN},
+ {"NOEXPIRE", NS_NO_EXPIRE},
+ {"", static_cast<NickNameFlag>(-1)}
+};
+
+struct NickCoreFlagInfo
+{
+ Anope::string Name;
+ NickCoreFlag Flag;
+};
+
+NickCoreFlagInfo NickCoreFlags[] = {
+ {"KILLPROTECT", NI_KILLPROTECT},
+ {"SECURE", NI_SECURE},
+ {"MSG", NI_MSG},
+ {"MEMO_HARDMAX", NI_MEMO_HARDMAX},
+ {"MEMO_SIGNON", NI_MEMO_SIGNON},
+ {"MEMO_RECEIVE", NI_MEMO_RECEIVE},
+ {"PRIVATE", NI_PRIVATE},
+ {"HIDE_EMAIL", NI_HIDE_EMAIL},
+ {"HIDE_MASK", NI_HIDE_MASK},
+ {"HIDE_QUIT", NI_HIDE_QUIT},
+ {"KILL_QUICK", NI_KILL_QUICK},
+ {"KILL_IMMED", NI_KILL_IMMED},
+ {"MEMO_MAIL", NI_MEMO_MAIL},
+ {"HIDE_STATUS", NI_HIDE_STATUS},
+ {"SUSPENDED", NI_SUSPENDED},
+ {"AUTOOP", NI_AUTOOP},
+ {"FORBIDDEN", NI_FORBIDDEN},
+ {"", static_cast<NickCoreFlag>(-1)}
+};
+
+struct BotServFlagInfo
+{
+ Anope::string Name;
+ BotFlag Flag;
+};
+
+BotServFlagInfo BotServFlags[] = {
+ {"PRIVATE", BI_PRIVATE},
+ {"", static_cast<BotFlag>(-1)}
+};
+
+struct BotFlagInfo
+{
+ Anope::string Name;
+ BotServFlag Flag;
+};
+
+BotFlagInfo BotFlags[] = {
+ {"DONTKICKOPS", BS_DONTKICKOPS},
+ {"DONTKICKVOICES", BS_DONTKICKVOICES},
+ {"FANTASY", BS_FANTASY},
+ {"SYMBIOSIS", BS_SYMBIOSIS},
+ {"GREET", BS_GREET},
+ {"NOBOT", BS_NOBOT},
+ {"KICK_BOLDS", BS_KICK_BOLDS},
+ {"KICK_COLORS", BS_KICK_COLORS},
+ {"KICK_REVERSES", BS_KICK_REVERSES},
+ {"KICK_UNDERLINES", BS_KICK_UNDERLINES},
+ {"KICK_BADWORDS", BS_KICK_BADWORDS},
+ {"KICK_CAPS", BS_KICK_CAPS},
+ {"KICK_FLOOD", BS_KICK_FLOOD},
+ {"KICK_REPEAT", BS_KICK_REPEAT},
+ {"KICK_ITALICS", BS_KICK_ITALICS},
+ {"", static_cast<BotServFlag>(-1)}
+};
+
+struct ChannelFlagInfo
+{
+ Anope::string Name;
+ ChannelInfoFlag Flag;
+};
+
+ChannelFlagInfo ChannelFlags[] = {
+ {"KEEPTOPIC", CI_KEEPTOPIC},
+ {"SECUREOPS", CI_SECUREOPS},
+ {"PRIVATE", CI_PRIVATE},
+ {"TOPICLOCK", CI_TOPICLOCK},
+ {"RESTRICTED", CI_RESTRICTED},
+ {"PEACE", CI_PEACE},
+ {"SECURE", CI_SECURE},
+ {"FORBIDDEN", CI_FORBIDDEN},
+ {"NO_EXPIRE", CI_NO_EXPIRE},
+ {"MEMO_HARDMAX", CI_MEMO_HARDMAX},
+ {"OPNOTICE", CI_OPNOTICE},
+ {"SECUREFOUNDER", CI_SECUREFOUNDER},
+ {"SIGNKICK", CI_SIGNKICK},
+ {"SIGNKICK_LEVEL", CI_SIGNKICK_LEVEL},
+ {"XOP", CI_XOP},
+ {"SUSPENDED", CI_SUSPENDED},
+ {"PERSIST", CI_PERSIST},
+ {"", static_cast<ChannelInfoFlag>(-1)}
+};
+
+struct MemoFlagInfo
+{
+ Anope::string Name;
+ MemoFlag Flag;
+};
+
+MemoFlagInfo MemoFlags[] = {
+ {"UNREAD", MF_UNREAD},
+ {"RECEIPT", MF_RECEIPT},
+ {"NOTIFYS", MF_NOTIFYS},
+ {"", static_cast<MemoFlag>(-1)}
+};
+
+static std::vector<Anope::string> MakeVector(const Anope::string &buf)
+{
+ Anope::string s;
+ spacesepstream sep(buf);
+ std::vector<Anope::string> params;
+
+ while (sep.GetToken(s))
+ {
+ if (s[0] == ':')
+ {
+ s.erase(s.begin());
+ if (!s.empty() && !sep.StreamEnd())
+ params.push_back(s + " " + sep.GetRemaining());
+ else if (!s.empty())
+ params.push_back(s);
+ }
+ else
+ params.push_back(s);
+ }
+
+ return params;
+}
+
+static Anope::string BuildFlagsList(ChannelInfo *ci)
+{
+ Anope::string ret;
+
+ for (int i = 0; ChannelFlags[i].Flag != -1; ++i)
+ if (ci->HasFlag(ChannelFlags[i].Flag))
+ ret += " " + ChannelFlags[i].Name;
+
+ if (!ret.empty())
+ ret.erase(ret.begin());
+
+ return ret;
+}
+
+static Anope::string BuildFlagsList(NickAlias *na)
+{
+ Anope::string ret;
+
+ for (int i = 0; NickAliasFlags[i].Flag != -1; ++i)
+ if (na->HasFlag(NickAliasFlags[i].Flag))
+ ret += " " + NickAliasFlags[i].Name;
+
+ if (!ret.empty())
+ ret.erase(ret.begin());
+
+ return ret;
+}
+
+static Anope::string BuildFlagsList(NickCore *nc)
+{
+ Anope::string ret;
+
+ for (int i = 0; NickCoreFlags[i].Flag != -1; ++i)
+ if (nc->HasFlag(NickCoreFlags[i].Flag))
+ ret += " " + NickCoreFlags[i].Name;
+
+ if (!ret.empty())
+ ret.erase(ret.begin());
+
+ return ret;
+}
+
+static Anope::string BuildFlagsList(Memo *m)
+{
+ Anope::string ret;
+
+ for (int i = 0; MemoFlags[i].Flag != -1; ++i)
+ if (m->HasFlag(MemoFlags[i].Flag))
+ ret += " " + MemoFlags[i].Name;
+
+ if (!ret.empty())
+ ret.erase(ret.begin());
+
+ return ret;
+}
+
+static Anope::string MakeMLock(ChannelInfo *ci, bool status)
+{
+ Anope::string ret;
+
+ for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it)
+ {
+ if ((*it)->Class == MC_CHANNEL)
+ {
+ ChannelMode *cm = debug_cast<ChannelMode *>(*it);
+
+ if (ci->HasMLock(cm->Name, status))
+ ret += " " + cm->NameAsString;
+ }
+ }
+
+ if (!ret.empty())
+ ret.erase(ret.begin());
+
+ return ret;
+}
+
+static inline Anope::string GetMLockOn(ChannelInfo *ci)
+{
+ return MakeMLock(ci, true);
+}
+
+static inline Anope::string GetMLockOff(ChannelInfo *ci)
+{
+ return MakeMLock(ci, false);
+}
+
+static Anope::string GetMLockParams(ChannelInfo *ci)
+{
+ Anope::string ret;
+
+ for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it)
+ {
+ if ((*it)->Class == MC_CHANNEL)
+ {
+ ChannelMode *cm = debug_cast<ChannelMode *>(*it);
+
+ Anope::string param;
+ if (ci->GetParam(cm->Name, param))
+ ret += " " + cm->NameAsString + " " + param;
+ }
+ }
+
+ if (!ret.empty())
+ ret.erase(ret.begin());
+
+ return ret;
+}
+
+static Anope::string GetBotFlags(Flags<BotServFlag>& Flags)
+{
+ Anope::string buf;
+
+ for (int i = 0; BotFlags[i].Flag != -1; ++i)
+ if (Flags.HasFlag(BotFlags[i].Flag))
+ buf += " " + BotFlags[i].Name;
+
+ if (!buf.empty())
+ buf.erase(buf.begin());
+
+ return buf;
+}
+
+static Anope::string GetBotServFlags(BotInfo *bi)
+{
+ Anope::string buf;
+
+ for (int i = 0; BotServFlags[i].Flag != -1; ++i)
+ if (bi->HasFlag(BotServFlags[i].Flag))
+ buf += " " + BotServFlags[i].Name;
+
+ if (!buf.empty())
+ buf.erase(buf.begin());;
+
+ return buf;
+}
+
+static NickAlias *CurNick = NULL;
+static NickCore *CurCore = NULL;
+static ChannelInfo *CurChannel = NULL;
+static BotInfo *CurBot = NULL;
+
+static void Write(const Anope::string &data);
+static void WriteNickMetadata(const Anope::string &key, const Anope::string &data);
+static void WriteCoreMetadata(const Anope::string &key, const Anope::string &data);
+static void WriteChannelMetadata(const Anope::string &key, const Anope::string &data);
+static void WriteBotMetadata(const Anope::string &key, const Anope::string &data);
+
+class CommandSQLSync : public Command
+{
+ public:
+ CommandSQLSync() : Command("SQLSYNC", 0, 0, "operserv/sqlsync")
+ {
+ }
+
+ CommandReturn Execute(User *u, const std::vector<Anope::string> &params);
+
+ bool OnHelp(User *u, const Anope::string &subcommand)
+ {
+ notice_help(Config.s_OperServ, u, OPER_HELP_SYNC);
+ return true;
+ }
+
+ void OnServHelp(User *u)
+ {
+ notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SQLSYNC);
+ }
+};
+
+class MySQLInterface : public SQLInterface
+{
+ public:
+ MySQLInterface(Module *o) : SQLInterface(o) { }
+
+ void OnResult(const SQLResult &r);
+
+ void OnError(const SQLResult &r);
+};
+
+class DBMySQL;
+static DBMySQL *me;
+class DBMySQL : public Module
+{
+ private:
+ CommandSQLSync commandsqlsync;
+ MySQLInterface interface;
+ service_reference<SQLProvider> SQL;
+
+ public:
+ time_t lastwarn;
+ bool ro;
+
+ void RunQuery(const Anope::string &query)
+ {
+ if (SQL)
+ {
+ if (readonly && this->ro)
+ {
+ readonly = this->ro = false;
+ ircdproto->SendGlobops(OperServ, "Found SQL again, going out of readonly mode...");
+ }
+
+ SQL->Run(&interface, query);
+ }
+ else
+ {
+ time_t now = time(NULL);
+
+ if (now - Config.UpdateTimeout > lastwarn)
+ {
+ ircdproto->SendGlobops(OperServ, "Unable to locate SQL reference, is m_mysql loaded? Going to readonly...");
+ readonly = this->ro = true;
+ this->lastwarn = now;
+ }
+ }
+ }
+
+ const Anope::string Escape(const Anope::string &query)
+ {
+ return SQL ? SQL->Escape(query) : query;
+ }
+
+ DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator), interface(this), SQL(this, "mysql/main")
+ {
+ me = this;
+
+ this->lastwarn = 0;
+ this->ro = false;
+
+ Implementation i[] = {
+ I_OnLoadDatabase, I_OnServerConnect
+ };
+ ModuleManager::Attach(i, this, 2);
+
+ this->AddCommand(OperServ, &commandsqlsync);
+
+ if (uplink_server)
+ OnServerConnect();
+ }
+
+ void OnServerConnect()
+ {
+ Implementation i[] = {
+ /* Misc */
+ I_OnSaveDatabase, I_OnPostCommand,
+ /* NickServ */
+ I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearAccess,
+ I_OnDelCore, I_OnNickForbidden, I_OnNickGroup, I_OnMakeNickRequest,
+ I_OnDelNickRequest, I_OnNickRegister, I_OnChangeCoreDisplay,
+ I_OnNickSuspended,
+ /* ChanServ */
+ I_OnAccessAdd, I_OnAccessDel, I_OnAccessChange, I_OnAccessClear, I_OnLevelChange,
+ I_OnChanForbidden, I_OnDelChan, I_OnChanRegistered, I_OnChanSuspend,
+ I_OnAkickAdd, I_OnAkickDel,
+ /* BotServ */
+ I_OnBotCreate, I_OnBotChange, I_OnBotDelete,
+ I_OnBotAssign, I_OnBotUnAssign,
+ I_OnBadWordAdd, I_OnBadWordDel,
+ /* MemoServ */
+ I_OnMemoSend, I_OnMemoDel,
+ /* OperServ */
+ I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel,
+ I_OnAddXLine, I_OnDelXLine
+ };
+ ModuleManager::Attach(i, this, 39);
+ }
+
+ EventReturn OnLoadDatabase()
+ {
+ if (!SQL)
+ {
+ Alog() << "Error, unable to find service reference for SQL, is m_mysql loaded and configured properly?";
+ return EVENT_CONTINUE;
+ }
+
+ SQLResult r = SQL->RunQuery("SELECT * FROM `anope_ns_core`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickCore *nc = new NickCore(r.Get(i, "display"));
+ nc->pass = r.Get(i, "pass");
+ nc->email = r.Get(i, "email");
+ nc->greet = r.Get(i, "greet");
+
+ spacesepstream sep(r.Get(i, "flags"));
+ Anope::string buf;
+ while (sep.GetToken(buf))
+ {
+ for (int j = 0; NickCoreFlags[j].Flag != -1; ++j)
+ {
+ if (NickCoreFlags[j].Name == buf)
+ {
+ nc->SetFlag(NickCoreFlags[j].Flag);
+ break;
+ }
+ }
+ }
+
+ nc->language = r.Get(i, "language").is_number_only() ? convertTo<int>(r.Get(i, "language")) : LANG_EN_US;
+ nc->channelcount = r.Get(i, "channelcount").is_number_only() ? convertTo<int>(r.Get(i, "channelcount")) : 0;
+ nc->memos.memomax = r.Get(i, "memomax").is_number_only() ? convertTo<int>(r.Get(i, "memomax")) : 20;
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_ns_access`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickCore *nc = findcore(r.Get(i, "display"));
+ if (!nc)
+ {
+ Alog() << "MySQL: Got NickCore access entry for nonexistant core " << r.Get(i, "display");
+ continue;
+ }
+
+ nc->AddAccess(r.Get(i, "access"));
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_ns_core_metadata`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickCore *nc = findcore(r.Get(i, "display"));
+ if (!nc)
+ {
+ Alog() << "MySQL: Got NickCore access entry for nonexistant core " << r.Get(i, "display");
+ continue;
+ }
+
+ EventReturn MOD_RESULT;;
+ std::vector<Anope::string> Params = MakeVector(r.Get(i, "value"));
+ FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, r.Get(i, "name"), Params));
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_ns_alias`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickCore *nc = findcore(r.Get(i, "display"));
+ if (!nc)
+ {
+ Alog() << "MySQL: Got NickAlias for nick " << r.Get(i, "nick") << " with nonexistant core " << r.Get(i, "display");
+ continue;
+ }
+
+ NickAlias *na = new NickAlias(r.Get(i, "nick"), nc);
+ na->last_quit = r.Get(i, "last_quit");
+ na->last_realname = r.Get(i, "last_realname");
+ na->last_usermask = r.Get(i, "last_usermask");
+ na->time_registered = r.Get(i, "time_registered").is_number_only() ? convertTo<time_t>(r.Get(i, "time_registered")) : time(NULL);
+ na->last_seen = r.Get(i, "last_seen").is_number_only() ? convertTo<time_t>(r.Get(i, "last_seen")) : time(NULL);
+
+ spacesepstream sep(r.Get(i, "flags"));
+ Anope::string buf;
+ while (sep.GetToken(buf))
+ {
+ for (int j = 0; NickAliasFlags[j].Flag != -1; ++j)
+ {
+ if (NickAliasFlags[j].Name == buf)
+ {
+ na->SetFlag(NickAliasFlags[j].Flag);
+ break;
+ }
+ }
+ }
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_ns_alias_metadata`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickAlias *na = findnick(r.Get(i, "nick"));
+ if (!na)
+ {
+ Alog() << "MySQL: Got metadata for nonexistant nick " << r.Get(i, "nick");
+ continue;
+ }
+
+ EventReturn MOD_RESULT;
+ std::vector<Anope::string> Params = MakeVector(r.Get(i, "value"));
+ FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, na->nick, Params));
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_bs_core`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ BotInfo *bi = findbot(r.Get(i, "nick"));
+ if (!bi)
+ bi = new BotInfo(r.Get(i, "nick"));
+ bi->SetIdent(r.Get(i, "user"));
+ bi->host = r.Get(i, "host");
+ bi->realname = r.Get(i, "rname");
+ bi->created = r.Get(i, "created").is_number_only() ? convertTo<time_t>(r.Get(i, "creeated")) : time(NULL);
+
+ spacesepstream sep(r.Get(i, "flags"));
+ Anope::string buf;
+ while (sep.GetToken(buf))
+ {
+ for (int j = 0; BotServFlags[j].Flag != -1; ++j)
+ {
+ if (buf == BotServFlags[j].Name)
+ {
+ bi->SetFlag(BotServFlags[j].Flag);
+ break;
+ }
+ }
+ }
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_bs_info_metadata`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ BotInfo *bi = findbot(r.Get(i, "botname"));
+ if (!bi)
+ {
+ Alog() << "MySQL: BotInfo metadata for nonexistant bot " << r.Get(i, "botname");
+ continue;
+ }
+
+ EventReturn MOD_RESULT;
+ std::vector<Anope::string> Params = MakeVector(r.Get(i, "value"));
+ FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(bi, bi->nick, Params));
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_info`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickCore *nc = NULL;
+
+ if (!r.Get(i, "founder").empty())
+ {
+ nc = findcore(r.Get(i, "founder"));
+ if (!nc)
+ {
+ Alog() << "MySQL: Channel " << r.Get(i, "name") << " with nonexistant founder " << r.Get(i, "founder");
+ continue;
+ }
+
+ ChannelInfo *ci = new ChannelInfo(r.Get(i, "name"));
+ ci->founder = nc;
+ if (!r.Get(i, "successor").empty())
+ ci->successor = findcore(r.Get(i, "successor"));
+ ci->desc = r.Get(i, "descr");
+ ci->time_registered = r.Get(i, "time_registered").is_number_only() ? convertTo<time_t>(r.Get(i, "time_registered")) : time(NULL);
+ ci->last_used = r.Get(i, "last_used").is_number_only() ? convertTo<time_t>(r.Get(i, "last_used")) : time(NULL);
+ ci->last_topic = r.Get(i, "last_topic");
+ ci->last_topic_setter = r.Get(i, "last_topic_setter");
+ ci->last_topic_time = r.Get(i, "last_topic_time").is_number_only() ? convertTo<int>(r.Get(i, "last_topic_time")) : time(NULL);
+ ci->forbidby = r.Get(i, "forbidby");
+ ci->forbidreason = r.Get(i, "forbidreason");
+ ci->bantype = r.Get(i, "bantype").is_number_only() ? convertTo<int>(r.Get(i, "bantype")) : 2;
+ ci->entry_message = r.Get(i, "entry_message");
+ ci->memos.memomax = r.Get(i, "memomax").is_number_only() ? convertTo<int>(r.Get(i, "memomax")) : 20;
+ ci->capsmin = r.Get(i, "capsmin").is_number_only() ? convertTo<int>(r.Get(i, "capsmin")) : 0;
+ ci->capspercent = r.Get(i, "capspercent").is_number_only() ? convertTo<int>(r.Get(i, "capspercent")) : 0;
+ ci->floodlines = r.Get(i, "floodlines").is_number_only() ? convertTo<int>(r.Get(i, "floodlines")) : 0;
+ ci->floodsecs = r.Get(i, "floodsecs").is_number_only() ? convertTo<int>(r.Get(i, "floodsecs")) : 0;
+ ci->repeattimes = r.Get(i, "repeattimes").is_number_only() ? convertTo<int>(r.Get(i, "repeattimes")) : 0;
+ ci->bi = findbot(r.Get(i, "botnick"));
+ if (ci->bi && !r.Get(i, "botflags").empty())
+ {
+ spacesepstream sep(r.Get(i, "botflags"));
+ Anope::string buf;
+ while (sep.GetToken(buf))
+ {
+ for (int j = 0; BotFlags[j].Flag != -1; ++j)
+ {
+ if (buf == BotFlags[j].Name)
+ {
+ ci->botflags.SetFlag(BotFlags[j].Flag);
+ break;
+ }
+ }
+ }
+ }
+
+ if (!r.Get(i, "mlock_on").empty())
+ {
+ std::vector<Anope::string> modes;
+
+ spacesepstream sep(r.Get(i, "mlock_on"));
+ Anope::string buf;
+ while (sep.GetToken(buf))
+ modes.push_back(buf);
+
+ ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
+ }
+ if (!r.Get(i, "mlock_off").empty())
+ {
+ std::vector<Anope::string> modes;
+
+ spacesepstream sep(r.Get(i, "mlock_off"));
+ Anope::string buf;
+ while (sep.GetToken(buf))
+ modes.push_back(buf);
+
+ ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
+ }
+ if (!r.Get(i, "mlock_params").empty())
+ {
+ std::vector<std::pair<Anope::string, Anope::string> > mlp;
+
+ spacesepstream sep(r.Get(i, "mlock_params"));
+ Anope::string buf, buf2;
+ while (sep.GetToken(buf) && sep.GetToken(buf2))
+ mlp.push_back(std::make_pair(Anope::string(buf), Anope::string(buf2)));
+
+ ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp));
+ }
+
+ if (!r.Get(i, "flags").empty())
+ {
+ spacesepstream sep(r.Get(i, "flags"));
+ Anope::string buf;
+
+ while (sep.GetToken(buf))
+ {
+ for (int j = 0; ChannelFlags[j].Flag != -1; ++j)
+ {
+ if (buf == ChannelFlags[j].Name)
+ {
+ ci->SetFlag(ChannelFlags[j].Flag);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_ttb`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
+ if (!ci)
+ {
+ Alog() << "MySQL: Channel ttb for nonexistant channel " << r.Get(i, "channel");
+ continue;
+ }
+
+ ci->ttb[atoi(r.Get(i, "ttb_id").c_str())] = atoi(r.Get(i, "value").c_str());
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_bs_badwords`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
+ if (!ci)
+ {
+ Alog() << "MySQL: Channel badwords entry for nonexistant channel " << r.Get(i, "channel");
+ continue;
+ }
+
+ BadWordType BWTYPE = BW_ANY;
+ if (r.Get(i, "type").equals_cs("SINGLE"))
+ BWTYPE = BW_SINGLE;
+ else if (r.Get(i, "type").equals_cs("START"))
+ BWTYPE = BW_START;
+ else if (r.Get(i, "type").equals_cs("END"))
+ BWTYPE = BW_END;
+ ci->AddBadWord(r.Get(i, "word"), BWTYPE);
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_access`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
+ if (!ci)
+ {
+ Alog() << "MySQL: Channel access entry for nonexistant channel " << r.Get(i, "channel");
+ continue;
+ }
+
+ NickCore *nc = findcore(r.Get(i, "display"));
+ if (!nc)
+ {
+ Alog() << "MySQL: Channel access entry for " << ci->name << " with nonexistant nick " << r.Get(i, "display");
+ continue;
+ }
+
+ ci->AddAccess(nc, atoi(r.Get(i, "level").c_str()), r.Get(i, "creator"), (r.Get(i, "last_seen").is_number_only() ? convertTo<time_t>(r.Get(i, "last_seen")) : time(NULL)));
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_akick`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
+ if (!ci)
+ {
+ Alog() << "MySQL: Channel access entry for nonexistant channel " << r.Get(i, "channel");
+ continue;
+ }
+
+ NickCore *nc = NULL;
+ spacesepstream sep(r.Get(i, "flags"));
+ Anope::string flag, mask;
+ bool stuck = false;
+ while (sep.GetToken(flag))
+ {
+ if (flag.equals_cs("ISNICK"))
+ nc = findcore(r.Get(i, "mask"));
+ else if (flag.equals_cs("STUCK"))
+ stuck = true;
+
+ AutoKick *ak;
+ if (nc)
+ ak = ci->AddAkick(r.Get(i, "creator"), nc, r.Get(i, "reason"), atol(r.Get(i, "created").c_str()), atol(r.Get(i, "last_used").c_str()));
+ else
+ ak = ci->AddAkick(r.Get(i, "creator"), r.Get(i, "mask"), r.Get(i, "reason"), atol(r.Get(i, "created").c_str()), atol(r.Get(i, "last_used").c_str()));
+ if (stuck)
+ ak->SetFlag(AK_STUCK);
+ if (nc)
+ ak->SetFlag(AK_ISNICK);
+ }
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_levels`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
+ if (!ci)
+ {
+ Alog() << "MySQL: Channel level entry for nonexistant channel " << r.Get(i, "channel");
+ continue;
+ }
+
+ ci->levels[atoi(r.Get(i, "position").c_str())] = atoi(r.Get(i, "level").c_str());
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_info_metadata");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
+ if (!ci)
+ {
+ Alog() << "MySQL: Channel metadata for nonexistant channel " << r.Get(i, "channel");
+ continue;
+ }
+
+ EventReturn MOD_RESULT;
+ std::vector<Anope::string> Params = MakeVector(r.Get(i, "value"));
+ FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, ci->name, Params));
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_ns_request`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickRequest *nr = new NickRequest(r.Get(i, "nick"));
+ nr->password = r.Get(i, "passcode");
+ nr->password = r.Get(i, "password");
+ nr->email = r.Get(i, "email");
+ nr->requested = r.Get(i, "requested").is_number_only() ? convertTo<time_t>(r.Get(i, "requested")) : time(NULL);
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_ms_info`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ MemoInfo *mi = NULL;
+ if (r.Get(i, "serv").equals_cs("NICK"))
+ {
+ NickCore *nc = findcore(r.Get(i, "receiver"));
+ if (nc)
+ mi = &nc->memos;
+ }
+ else if (r.Get(i, "serv").equals_cs("CHAN"))
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "receiver"));
+ if (ci)
+ mi = &ci->memos;
+ }
+ if (mi)
+ {
+ Memo *m = new Memo();
+ mi->memos.push_back(m);
+ m->sender = r.Get(i, "sender");
+ if (mi->memos.size() > 1)
+ {
+ m->number = mi->memos[mi->memos.size() - 1]->number + 1;
+ if (m->number < 1)
+ {
+ for (unsigned j = 0; j < mi->memos.size(); ++j)
+ mi->memos[j]->number = j + 1;
+ }
+ }
+ else
+ m->number = 1;
+ m->time = r.Get(i, "time").is_number_only() ? convertTo<time_t>(r.Get(i, "time")) : time(NULL);
+ m->text = r.Get(i, "text");
+
+ if (!r.Get(i, "flags").empty())
+ {
+ spacesepstream sep(r.Get(i, "flags"));
+ Anope::string buf;
+ while (sep.GetToken(buf))
+ {
+ for (unsigned j = 0; MemoFlags[j].Flag != -1; ++j)
+ {
+ if (MemoFlags[j].Name == buf)
+ {
+ m->SetFlag(MemoFlags[j].Flag);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (SQLine)
+ {
+ r = SQL->RunQuery("SELECT * FROM `anope_os_akills`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ Anope::string user = r.Get(i, "user");
+ Anope::string host = r.Get(i, "host");
+ Anope::string by = r.Get(i, "by");
+ Anope::string reason = r.Get(i, "reason");
+ time_t seton = r.Get(i, "seton").is_number_only() ? convertTo<time_t>(r.Get(i, "seton")) : time(NULL);
+ time_t expires = r.Get(i, "expires").is_number_only() ? convertTo<time_t>(r.Get(i, "expires")) : time(NULL);
+
+ XLine *x = SGLine->Add(NULL, NULL, user + "@" + host, expires, reason);
+ if (x)
+ {
+ x->By = by;
+ x->Created = seton;
+ }
+ }
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_os_xlines`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ Anope::string mask = r.Get(i, "mask");
+ Anope::string by = r.Get(i, "xby");
+ Anope::string reason = r.Get(i, "reason");
+ time_t seton = r.Get(i, "seton").is_number_only() ? convertTo<time_t>(r.Get(i, "seton")) : time(NULL);
+ time_t expires = r.Get(i, "expires").is_number_only() ? convertTo<time_t>(r.Get(i, "expires")) : time(NULL);
+
+ XLine *x = NULL;
+ if (SNLine && r.Get(i, "type").equals_cs("SNLINE"))
+ SNLine->Add(NULL, NULL, mask, expires, reason);
+ else if (SQLine && r.Get(i, "type").equals_cs("SQLINE"))
+ SQLine->Add(NULL, NULL, mask, expires, reason);
+ else if (SZLine && r.Get(i, "type").equals_cs("SZLINE"))
+ SZLine->Add(NULL, NULL, mask, expires, reason);
+ if (x)
+ {
+ x->By = by;
+ x->Created = seton;
+ }
+ }
+
+ r = SQL->RunQuery("SELECT * FROM `anope_extra`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ std::vector<Anope::string> params = MakeVector(r.Get(i, "data"));
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(I_OnDatabaseRead, OnDatabaseRead(params));
+ }
+
+ return EVENT_STOP;
+ }
+
+ EventReturn OnSaveDatabase()
+ {
+ this->RunQuery("TRUNCATE TABLE `anope_os_core`");
+
+ this->RunQuery("INSERT DELAYED INTO `anope_os_core` (maxusercnt, maxusertime, akills_count, sglines_count, sqlines_count, szlines_count) VALUES( " + stringify(maxusercnt) + ", " + stringify(maxusertime) + ", " + stringify(SGLine ? SGLine->GetCount() : 0) + ", " + stringify(SQLine ? SQLine->GetCount() : 0) + ", " + stringify(SNLine ? SNLine->GetCount() : 0) + ", " + stringify(SZLine ? SZLine->GetCount() : 0) + ")");
+ for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ {
+ CurCore = it->second;
+ FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteCoreMetadata, CurCore));
+ }
+
+ for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ {
+ CurNick = it->second;
+ FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteNickMetadata, CurNick));
+ }
+
+ for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ {
+ CurChannel = it->second;
+ FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, CurChannel));
+ }
+
+ for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ {
+ CurBot = it->second;
+ FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteBotMetadata, CurBot));
+
+ /* This is for the core bots, bots added by users are already handled by an event */
+ this->RunQuery("INSERT DELAYED INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES('" + this->Escape(CurBot->nick) + "', '" + this->Escape(CurBot->GetIdent()) + "', '" + this->Escape(CurBot->host) + "', '" + this->Escape(CurBot->realname) + "', '" + GetBotServFlags(CurBot) + "', " + CurBot->created + ", " + CurBot->chancount + ") ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(created)");
+ }
+
+ FOREACH_MOD(I_OnDatabaseWrite, OnDatabaseWrite(Write));
+
+ return EVENT_CONTINUE;
+ }
+
+ void OnPostCommand(User *u, const Anope::string &service, const Anope::string &command, const std::vector<Anope::string> &params)
+ {
+ if (service == Config.s_NickServ)
+ {
+ if (u->Account() && ((command.equals_ci("SET") && !params.empty()) || (command.equals_ci("SASET") && u->Account()->HasCommand("nickserv/saset") && params.size() > 1)))
+ {
+ Anope::string cmd = (command == "SET" ? params[0] : params[1]);
+ NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0]));
+ if (!nc)
+ return;
+ if (cmd.equals_ci("PASSWORD") && params.size() > 1)
+ {
+ this->RunQuery("UPDATE `anope_ns_core` SET `pass` = '" + this->Escape(nc->pass) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ }
+ else if (cmd.equals_ci("LANGUAGE") && params.size() > 1)
+ {
+ this->RunQuery("UPDATE `anope_ns_core` SET `language` = '" + this->Escape(nc->language) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ }
+ else if (cmd.equals_ci("EMAIL"))
+ {
+ this->RunQuery("UPDATE `anope_ns_core` SET `email` = '" + this->Escape(nc->email) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ }
+ else if (cmd.equals_ci("GREET"))
+ {
+ this->RunQuery("UPDATE `anope_ns_core` SET `greet` = '" + this->Escape(nc->greet) + " WHERE `display` = '" + this->Escape(nc->display) + "'");
+ }
+ else if (cmd.equals_ci("KILL") || cmd.equals_ci("SECURE") || cmd.equals_ci("PRIVATE") || cmd.equals_ci("MSG") || cmd.equals_ci("HIDE") || cmd.equals_ci("AUTOOP"))
+ {
+ this->RunQuery("UPDATE `anope_ns_core` SET `flags` = '" + BuildFlagsList(nc) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ }
+ }
+ }
+ else if (service == Config.s_ChanServ)
+ {
+ if (command.equals_ci("SET") && u->Account() && params.size() > 1)
+ {
+ ChannelInfo *ci = cs_findchan(params[0]);
+ if (!ci)
+ return;
+ if (!u->Account()->HasPriv("chanserv/set") && check_access(u, ci, CA_SET))
+ return;
+ if (params[1].equals_ci("FOUNDER") && ci->founder)
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `founder` = '" + this->Escape(ci->founder->display) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("SUCCESSOR"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `successor` = '" + this->Escape(ci->successor ? ci->successor->display : "") + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("DESC"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `descr` = '" + this->Escape(ci->desc) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("ENTRYMSG"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `entry_message` = '" + this->Escape(ci->entry_message) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("MLOCK"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `mlock_on` = '" + GetMLockOn(ci) + "' WHERE `name` = " + this->Escape(ci->name) + "'");
+ this->RunQuery("UPDATE `anope_cs_info` SET `mlock_off` = '" + GetMLockOff(ci) + "' WHERE `name` = " + this->Escape(ci->name) + "'");
+ this->RunQuery("UPDATE `anope_cs_info` SET `mlock_params` = '" + GetMLockParams(ci) + "' WHERE `name` = " + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("BANTYPE"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `bantype` = " + stringify(ci->bantype) + " WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("KEEPTOPIC") || params[1].equals_ci("TOPICLOCK") || params[1].equals_ci("PRIVATE") || params[1].equals_ci("SECUREOPS") || params[1].equals_ci("SECUREFOUNDER") || params[1].equals_ci("RESTRICTED") || params[1].equals_ci("SECURE") || params[1].equals_ci("SIGNKICK") || params[1].equals_ci("OPNOTICE") || params[1].equals_ci("XOP") || params[1].equals_ci("PEACE") || params[1].equals_ci("PERSIST") || params[1].equals_ci("NOEXPIRE"))
+ {
+ SQL->RunQuery("UPDATE `anope_cs_info` SET `flags` = '" + BuildFlagsList(ci) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ }
+ }
+ else if (service == Config.s_BotServ)
+ {
+ if (command.equals_ci("KICK") && params.size() > 2)
+ {
+ ChannelInfo *ci = cs_findchan(params[0]);
+ if (!ci)
+ return;
+ if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration"))
+ return;
+ if (params[1].equals_ci("BADWORDS") || params[1].equals_ci("BOLDS") || params[1].equals_ci("CAPS") || params[1].equals_ci("COLORS") || params[1].equals_ci("FLOOD") || params[1].equals_ci("REPEAT") || params[1].equals_ci("REVERSES") || params[1].equals_ci("UNDERLINES"))
+ {
+ if (params[2].equals_ci("ON") || params[2].equals_ci("OFF"))
+ {
+ for (int i = 0; i < TTB_SIZE; ++i)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_cs_ttb` (channel, ttb_id, value) VALUES('" + this->Escape(ci->name) + "', " + stringify(i) + ", " + stringify(ci->ttb[i]) + ") ON DUPLICATE KEY UPDATE channel=VALUES(channel), ttb_id=VALUES(ttb_id), value=VALUES(value)");
+ }
+ this->RunQuery("UPDATE `anope_cs_info` SET `botflags` = '" + GetBotFlags(ci->botflags) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+
+ if (params[1].equals_ci("CAPS"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `capsmin` = " + stringify(ci->capsmin) + ", `capspercent` = " + stringify(ci->capspercent) + " WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("FLOOD"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `floodlines` = " + stringify(ci->floodlines) + ", `floodsecs` = " + stringify(ci->floodsecs) + " WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ else if (params[1].equals_ci("REPEAT"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `repeattimes` = " + stringify(ci->repeattimes) + " WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ }
+ }
+ }
+ else if (command.equals_ci("SET") && params.size() > 2)
+ {
+ ChannelInfo *ci = cs_findchan(params[0]);
+ if (ci && !check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration"))
+ return;
+ BotInfo *bi = NULL;
+ if (!ci)
+ bi = findbot(params[0]);
+ if (bi && params[1].equals_ci("PRIVATE") && u->Account()->HasPriv("botserv/set/private"))
+ {
+ this->RunQuery("UPDATE `anope_bs_core` SET `flags` = '" + GetBotServFlags(bi) + "' WHERE `nick` = '" + this->Escape(bi->nick) + "'");
+ }
+ else if (!ci)
+ return;
+ else if (params[1].equals_ci("DONTKICKOPS") || params[1].equals_ci("DONTKICKVOICES") || params[1].equals_ci("FANTASY") || params[1].equals_ci("GREET") || params[1].equals_ci("SYMBIOSIS") || params[1].equals_ci("NOBOT"))
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `botflags` = '" + GetBotFlags(ci->botflags) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+ }
+ }
+ }
+
+ void OnNickAddAccess(NickCore *nc, const Anope::string &entry)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES('" + this->Escape(nc->display) + "', '" + this->Escape(entry) + "')");
+ }
+
+ void OnNickEraseAccess(NickCore *nc, const Anope::string &entry)
+ {
+ this->RunQuery("DELETE FROM `anope_ns_access` WHERE `display` = '" + this->Escape(nc->display) + "' AND `access` = '" + this->Escape(entry) + "'");
+ }
+
+ void OnNickClearAccess(NickCore *nc)
+ {
+ this->RunQuery("DELETE FROM `anope_ns_access` WHERE `display` = '" + this->Escape(nc->display) + "'");
+ }
+
+ void OnDelCore(NickCore *nc)
+ {
+ this->RunQuery("DELETE FROM `anope_cs_access` WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("DELETE FROM `anope_cs_akick` WHERE `mask` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("DELETE FROM `anope_ns_access` WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("DELETE FROM `anope_ns_alias` WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("DELETE FROM `anope_ns_core` WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("DELETE FROM `anope_ms_info` WHERE `receiver` = '" + this->Escape(nc->display) + "'");
+ }
+
+ void OnNickForbidden(NickAlias *na)
+ {
+ this->RunQuery("UPDATE `anope_ns_alias` SET `flags` = '" + BuildFlagsList(na) + "' WHERE `nick` = '" + this->Escape(na->nick) + "'");
+ }
+
+ void OnNickGroup(User *u, NickAlias *)
+ {
+ OnNickRegister(findnick(u->nick));
+ }
+
+ void OnMakeNickRequest(NickRequest *nr)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_ns_request` (nick, passcode, password, email, requested) VALUES('" + this->Escape(nr->nick) + "', '" + this->Escape(nr->passcode) + "', '" + this->Escape(nr->password) + "', '" + this->Escape(nr->email) + "', " + stringify(nr->requested) + ")");
+ }
+
+ void OnDelNickRequest(NickRequest *nr)
+ {
+ this->RunQuery("DELETE FROM `anope_ns_request` WHERE `nick` = '" + this->Escape(nr->nick) + "'");
+ }
+
+ void InsertAlias(NickAlias *na)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_ns_alias` (nick, last_quit, last_realname, last_usermask, time_registered, last_seen, flags, display) VALUES('" +
+ this->Escape(na->nick) + "', '" + this->Escape(na->last_quit) + "', '" +
+ this->Escape(na->last_realname) + "', '" + this->Escape(na->last_usermask) + "', " + stringify(na->time_registered) + ", " + stringify(na->last_seen) +
+ ", '" + BuildFlagsList(na) + "', '" + this->Escape(na->nc->display) + "') " + "ON DUPLICATE KEY UPDATE last_quit=VALUES(last_quit), "
+ "last_realname=VALUES(last_realname), last_usermask=VALUES(last_usermask), time_registered=VALUES(time_registered), last_seen=VALUES(last_seen), "
+ "flags=VALUES(flags), display=VALUES(display)");
+ }
+
+ void InsertCore(NickCore *nc)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_ns_core` (display, pass, email, greet, flags, language, channelcount, memomax) VALUES('" +
+ this->Escape(nc->display) + "', '" + this->Escape(nc->pass) + "', '" +
+ this->Escape(nc->email) + "', '" + this->Escape(nc->greet) + "', '" +
+ BuildFlagsList(nc) + "', " + stringify(nc->language) + ", " + stringify(nc->channelcount) + ", " +
+ stringify(nc->memos.memomax) + ") " +
+ "ON DUPLICATE KEY UPDATE pass=VALUES(pass), email=VALUES(email), greet=VALUES(greet), flags=VALUES(flags), language=VALUES(language), " +
+ "channelcount=VALUES(channelcount), memomax=VALUES(memomax)");
+ }
+
+ void OnNickRegister(NickAlias *na)
+ {
+ this->InsertAlias(na);
+ this->InsertCore(na->nc);
+ }
+
+ void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay)
+ {
+ this->RunQuery("UPDATE `anope_ns_core` SET `display` = '" + this->Escape(newdisplay) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("UPDATE `anope_ns_alias` SET `display` = '" + this->Escape(newdisplay) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("UPDATE `anope_ns_access` SET `display` = '" + this->Escape(newdisplay) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("UPDATE `anope_cs_access` SET `display` = '" + this->Escape(newdisplay) + "' WHERE `display` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("UPDATE `anope_cs_info` SET `founder` = '" + this->Escape(newdisplay) + "' WHERE `founder` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("UPDATE `anope_cs_info` SET `successor` = '" + this->Escape(newdisplay) + "' WHERE `successor` = '" + this->Escape(nc->display) + "'");
+ this->RunQuery("UPDATE `anope_ms_info` SET `receiver` = '" + this->Escape(newdisplay) + "' WHERE `receiver` = '" + this->Escape(nc->display) + "'");
+ }
+
+ void OnNickSuspend(NickAlias *na)
+ {
+ this->RunQuery("UPDATE `anope_ns_core` SET `flags` = '" + BuildFlagsList(na->nc) + "' WHERE `display` = '" + this->Escape(na->nc->display) + "'");
+ }
+
+ void OnAccessAdd(ChannelInfo *ci, User *u, NickAlias *na, int level)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" + stringify(level) + ", '" + this->Escape(na->nc->display) + "', '" + this->Escape(ci->name) + "', " + stringify(time(NULL)) + ", '" + this->Escape(u->nick) + "')");
+ }
+
+ void OnAccessDel(ChannelInfo *ci, User *u, NickCore *nc)
+ {
+ this->RunQuery("DELETE FROM `anope_cs_access` WHERE `display` = '" + this->Escape(nc->display) + "' AND `channel` = '" + this->Escape(ci->name) + "'");
+ }
+
+ void OnAccessChange(ChannelInfo *ci, User *u, NickAlias *na, int level)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" + stringify(level) + ", '" + this->Escape(na->nc->display) + "', '" + this->Escape(ci->name) + "', " + stringify(time(NULL)) + ", '" + this->Escape(u->nick) + "') ON DUPLICATE KEY UPDATE level=VALUES(level), display=VALUES(display), channel=VALUES(channel), last_seen=VALUES(last_seen), creator=VALUES(creator)");
+ }
+
+ void OnAccessClear(ChannelInfo *ci, User *u)
+ {
+ this->RunQuery("DELETE FROM `anope_cs_access` WHERE `channel` = '" + this->Escape(ci->name) + "'");
+ }
+
+ void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what)
+ {
+ if (pos >= 0)
+ this->RunQuery("UPDATE `anope_cs_levels` SET `level` = " + stringify(what) + " WHERE `channel` = '" + this->Escape(ci->name) + "' AND `position` = " + stringify(pos));
+ else
+ for (int i = 0; i < CA_SIZE; ++i)
+ this->RunQuery("UPDATE `anope_cs_levels` SET `level` = " + stringify(ci->levels[i]) + " WHERE `channel` = '" + this->Escape(ci->name) + "' AND `position` = " + stringify(i));
+ }
+
+ void OnChanForbidden(ChannelInfo *ci)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_cs_info` (name, time_registered, last_used, flags, forbidby, forbidreason) VALUES ('" +
+ this->Escape(ci->name) + "', " + stringify(ci->time_registered) + ", " + stringify(ci->last_used) + ", '" + BuildFlagsList(ci) + "', '" + this->Escape(ci->forbidby) + "', '"
+ + this->Escape(ci->forbidreason) + "')");
+ }
+
+ void OnDelChan(ChannelInfo *ci)
+ {
+ this->Escape("DELETE FROM `anope_cs_access` WHERE `channel` = '" + this->Escape(ci->name) + "'");
+ this->Escape("DELETE FROM `anope_cs_akick` WHERE `channel` = '" + this->Escape(ci->name) + "'");
+ this->Escape("DELETE FROM `anope_cs_info` WHERE `name` = '" + this->Escape(ci->name) + "'");
+ this->Escape("DELETE FROM `anope_cs_levels` WHERE `channel` = '" + this->Escape(ci->name) + "'");
+ this->Escape("DELETE From `anope_cs_ttb` WHERE `channel` = '" + this->Escape(ci->name) + "'");
+ this->Escape("DELETE FROM `anope_bs_badwords` WHERE `channel` = '" + this->Escape(ci->name) + "'");
+ }
+
+ void OnChanRegistered(ChannelInfo *ci)
+ {
+ Anope::string flags = BuildFlagsList(ci), mlockon = GetMLockOn(ci), mlockoff = GetMLockOff(ci), mlockparams = GetMLockParams(ci);
+ this->RunQuery("INSERT DELAYED INTO `anope_cs_info` (name, founder, successor, descr, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, mlock_on, mlock_off, mlock_params, entry_message, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES('" +
+ this->Escape(ci->name) + "', '" + this->Escape(ci->founder ? ci->founder->display : "") + "', '" +
+ this->Escape(ci->successor ? ci->successor->display : "") + "', '" + this->Escape(ci->desc) + "', " +
+ stringify(ci->time_registered) + ", " + stringify(ci->last_used) + ", '" + this->Escape(ci->last_topic) + "', '" +
+ this->Escape(ci->last_topic_setter) + "', " + stringify(ci->last_topic_time) + ", '" + flags + "', '" +
+ this->Escape(ci->forbidby) + "', '" + this->Escape(ci->forbidreason) + "', " + stringify(ci->bantype) + ", '" +
+ mlockon + "', '" + mlockoff + "', '" + mlockparams + "', '" + this->Escape(ci->entry_message) + "', " +
+ stringify(ci->memos.memomax) + ", '" + this->Escape(ci->bi ? ci->bi->nick : "") + "', '" + GetBotFlags(ci->botflags) +
+ "', " + stringify(ci->capsmin) + ", " + stringify(ci->capspercent) + ", " + stringify(ci->floodlines) + ", " + stringify(ci->floodsecs) + ", " + stringify(ci->repeattimes) + ") " +
+ "ON DUPLICATE KEY UPDATE founder=VALUES(founder), successor=VALUES(successor), descr=VALUES(descr), time_registered=VALUES(time_registered), last_used=VALUES(last_used), last_topic=VALUES(last_topic), last_topic_setter=VALUES(last_topic_setter), last_topic_time=VALUES(last_topic_time), flags=VALUES(flags), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), bantype=VALUES(bantype), mlock_on=VALUES(mlock_on), mlock_off=VALUES(mlock_off), mlock_params=VALUES(mlock_params), entry_message=VALUES(entry_message), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(repeattimes)");
+ }
+
+ void OnChanSuspend(ChannelInfo *ci)
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `flags` = '" + BuildFlagsList(ci) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ this->RunQuery("UPDATE `anope_cs_info` SET `forbidby` = '" + this->Escape(ci->forbidby) + " WHERE `name` = '" + this->Escape(ci->name) + "'");
+ this->RunQuery("UPDATE `anope_cs_info` SET `forbidreason` = '" + this->Escape(ci->forbidreason) + " WHERE `name` = '" + this->Escape(ci->name) + "'");
+ }
+
+ void OnAkickAdd(ChannelInfo *ci, AutoKick *ak)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_cs_akick` (channel, flags, mask, reason, creator, created, last_used) VALUES('" + this->Escape(ci->name) + "', '" +
+ (ak->HasFlag(AK_ISNICK) ? "ISNICK " : "") + (ak->HasFlag(AK_STUCK) ? "STUCK " : "") + "', '" +
+ this->Escape(ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask) + "', '" + this->Escape(ak->reason) + "', '" +
+ this->Escape(ak->creator) + "', " + stringify(ak->addtime) + ", " + stringify(ak->last_used) + ")");
+ }
+
+ void OnAkickDel(ChannelInfo *ci, AutoKick *ak)
+ {
+ this->RunQuery("DELETE FROM `anope_cs_akick` WHERE `channel`= '" + this->Escape(ci->name) + "' AND `mask` = '" + (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask));
+ }
+
+ void OnBotCreate(BotInfo *bi)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES('" +
+ this->Escape(bi->nick) + "', '" + this->Escape(bi->GetIdent()) + "', '" + this->Escape(bi->host) + "', '" +
+ this->Escape(bi->realname) + "', '" + GetBotServFlags(bi) + "', " + stringify(bi->created) + ", " + stringify(bi->chancount) + ") " +
+ "ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(chancount)");
+ }
+
+ void OnBotChange(BotInfo *bi)
+ {
+ OnBotCreate(bi);
+ }
+
+ void OnBotDelete(BotInfo *bi)
+ {
+ this->RunQuery("DELETE FROM `anope_bs_core` WHERE `nick` = '" + this->Escape(bi->nick) + "'");
+ this->RunQuery("UPDATE `anope_cs_info` SET `botnick` = '' WHERE `botnick` = '" + this->Escape(bi->nick) + "'");
+ }
+
+ EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi)
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `botnick` = '" + this->Escape(bi->nick) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ return EVENT_CONTINUE;
+ }
+
+ EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci)
+ {
+ this->RunQuery("UPDATE `anope_cs_info` SET `botnick` = '' WHERE `name` = '" + this->Escape(ci->name) + "'");
+ return EVENT_CONTINUE;
+ }
+
+ void OnBadWordAdd(ChannelInfo *ci, BadWord *bw)
+ {
+ Anope::string query = "INSERT DELAYED INTO `anope_bs_badwords` (channel, word, type) VALUES('" + this->Escape(ci->name) + "', '" + this->Escape(bw->word) + "', '";
+ switch (bw->type)
+ {
+ case BW_SINGLE:
+ query += "SINGLE";
+ break;
+ case BW_START:
+ query += "START";
+ break;
+ case BW_END:
+ query += "END";
+ break;
+ default:
+ query += "ANY";
+ }
+ query += "') ON DUPLICATE KEY UPDATE channel=VALUES(channel), word=VALUES(word), type=VALUES(type)";
+ this->RunQuery(query);
+ }
+
+ void OnBadWordDel(ChannelInfo *ci, BadWord *bw)
+ {
+ Anope::string query = "DELETE FROM `anope_bs_badwords` WHERE `channel` = '" + this->Escape(ci->name) + "' AND `word` = '" + this->Escape(bw->word) + " AND `type` = '";
+ switch (bw->type)
+ {
+ case BW_SINGLE:
+ query += "SINGLE";
+ break;
+ case BW_START:
+ query += "START";
+ break;
+ case BW_END:
+ query += "END";
+ break;
+ default:
+ query += "ANY";
+ }
+ query += "'";
+ this->RunQuery(query);
+ }
+
+ void OnMemoSend(User *, NickCore *nc, Memo *m)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES('" +
+ this->Escape(nc->display) + "', " + stringify(m->number) + ", '" + BuildFlagsList(m) + "', " + stringify(m->time) + ", '" +
+ this->Escape(m->sender) + "', '" + this->Escape(m->text) + "', 'NICK')");
+ }
+
+ void OnMemoSend(User *, ChannelInfo *ci, Memo *m)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES('" +
+ this->Escape(ci->name) + "', " + stringify(m->number) + ", '" + BuildFlagsList(m) + "', " + stringify(m->time) + ", '" +
+ this->Escape(m->sender) + "', '" + this->Escape(m->text) + "', 'CHAN')");
+ }
+
+ void OnMemoDel(NickCore *nc, MemoInfo *mi, int number)
+ {
+ if (number)
+ this->RunQuery("DELETE FROM `anope_ms_info` WHERE `receiver` = '" + this->Escape(nc->display) + "' AND `number` = " + stringify(number));
+ else
+ this->RunQuery("DELETE FROM `anope_ms_info` WHERE `receiver` = '" + this->Escape(nc->display) + "'");
+ }
+
+ void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, int number)
+ {
+ if (number)
+ this->RunQuery("DELETE FROM `anope_ms_info` WHERE `receiver` = '" + this->Escape(ci->name) + "' AND `number` = " + stringify(number));
+ else
+ this->RunQuery("DELETE FROM `anope_ms_info` WHERE `receiver` = '" + this->Escape(ci->name) + "'");
+ }
+
+ EventReturn OnAddAkill(User *, XLine *ak)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_os_akills` (user, host, xby, reason, seton, expire) VALUES('" +
+ this->Escape(ak->GetUser()) + "', '" + this->Escape(ak->GetHost()) + "', '" + this->Escape(ak->By) + "', '" +
+ this->Escape(ak->Reason) + "', " + stringify(ak->Created) + ", " + stringify(ak->Expires) + ")");
+ return EVENT_CONTINUE;
+ }
+
+ void OnDelAkill(User *, XLine *ak)
+ {
+ if (ak)
+ this->RunQuery("DELETE FROM `anope_os_akills` WHERE `host` = '" + this->Escape(ak->GetHost()) + "'");
+ else
+ this->RunQuery("TRUNCATE TABLE `anope_os_akills`");
+ }
+
+ EventReturn OnExceptionAdd(User *, Exception *ex)
+ {
+ this->RunQuery("INSERT DELAYED INTO `anope_os_exceptions` (mask, slimit, who, reason, time, expires) VALUES('" +
+ this->Escape(ex->mask) + "', " + stringify(ex->limit) + ", '" + this->Escape(ex->who) + "', '" + this->Escape(ex->reason) + "', " +
+ stringify(ex->time) + ", " + stringify(ex->expires) + ")");
+ return EVENT_CONTINUE;
+ }
+
+ void OnExceptionDel(User *, Exception *ex)
+ {
+ this->RunQuery("DELETE FROM `anope_os_exceptions` WHERE `mask` = '" + this->Escape(ex->mask) + "'");
+ }
+
+ EventReturn OnAddXLine(User *, XLine *x, XLineType Type)
+ {
+ this->RunQuery(Anope::string("INSERT DELAYED INTO `anope_os_sxlines` (type, mask, xby, reason, seton, expire) VALUES('") +
+ (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) + "', '" +
+ this->Escape(x->Mask) + "', '" + this->Escape(x->By) + "', '" + this->Escape(x->Reason) + "', " +
+ stringify(x->Created) + ", " + stringify(x->Expires) + ")");
+ return EVENT_CONTINUE;
+ }
+
+ void OnDelXLine(User *, XLine *x, XLineType Type)
+ {
+ if (x)
+ this->RunQuery("DELETE FROM `anope_os_xlines` WHERE `mask` = '" + this->Escape(x->Mask) + "' AND `type` = '" +
+ (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) + "'");
+ else
+ this->RunQuery(Anope::string("DELETE FROM `anope_os_xlines` WHERE `type` = '") + (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) + "'");
+ }
+};
+
+void MySQLInterface::OnResult(const SQLResult &r)
+{
+ Alog(LOG_DEBUG) << "MySQL successfully executed query: " << r.GetQuery();
+}
+
+void MySQLInterface::OnError(const SQLResult &r)
+{
+ if (!r.GetQuery().empty())
+ Alog(LOG_DEBUG) << "Error executing query " << r.GetQuery() << ": " << r.GetError();
+ else
+ Alog(LOG_DEBUG) << "Error executing query: " << r.GetError();
+}
+
+
+static void Write(const Anope::string &data)
+{
+ me->RunQuery("INSERT DELAYED INTO `anope_extra` (data) VALUES('" + me->Escape(data) + "')");
+}
+
+static void WriteNickMetadata(const Anope::string &key, const Anope::string &data)
+{
+ if (!CurNick)
+ throw CoreException(Anope::string("WriteNickMetadata without a nick to write"));
+
+ me->RunQuery("INSERT DELAYED INTO `anope_ns_alias_metadata` (nick, name, value) VALUES('" + me->Escape(CurNick->nick) + "', '" + me->Escape(key) + "', '" + me->Escape(data) + "')");
+}
+
+static void WriteCoreMetadata(const Anope::string &key, const Anope::string &data)
+{
+ if (!CurCore)
+ throw CoreException(Anope::string("WritCoreMetadata without a core to write"));
+
+ me->RunQuery("INSERT DELAYED INTO `anope_ns_core_metadata` (nick, name, value) VALUES('" + me->Escape(CurCore->display) + "', '" + me->Escape(key) + "', '" + me->Escape(data) + "')");
+}
+
+static void WriteChannelMetadata(const Anope::string &key, const Anope::string &data)
+{
+ if (!CurChannel)
+ throw CoreException(Anope::string("WriteChannelMetadata without a channel to write"));
+
+ me->RunQuery("INSERT DELAYED INTO `anope_cs_info_metadata` (channel, name, value) VALUES('" + me->Escape(CurChannel->name) + "', '" + me->Escape(key) + "', '" + me->Escape(data) + "')");
+}
+
+static void WriteBotMetadata(const Anope::string &key, const Anope::string &data)
+{
+ if (!CurBot)
+ throw CoreException(Anope::string("WriteBotMetadata without a bot to write"));
+
+ me->RunQuery("INSERT DELAYED INTO `anope_bs_info_metadata` (botname, name, value) VALUES('" + me->Escape(CurBot->nick) + "', '" + me->Escape(key) + "', '" + me->Escape(data) + "')");
+}
+
+static void SaveDatabases()
+{
+ me->RunQuery("TRUNCATE TABLE `anope_ns_alias`");
+
+ for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ me->InsertAlias(it->second);
+
+ me->RunQuery("TRUNCATE TABLE `anope_ns_core`");
+ me->RunQuery("TRUNCATE TABLE `anope_ms_info`");
+
+ for (nickcore_map::const_iterator nit = NickCoreList.begin(), nit_end = NickCoreList.end(); nit != nit_end; ++nit)
+ {
+ NickCore *nc = nit->second;
+
+ for (std::vector<Anope::string>::iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it)
+ {
+ me->RunQuery("INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" + me->Escape(nc->display) + ", " + me->Escape(*it) + ")");
+ }
+
+ for (unsigned j = 0, end = nc->memos.memos.size(); j < end; ++j)
+ {
+ Memo *m = nc->memos.memos[j];
+
+ me->OnMemoSend(NULL, nc, m);
+ }
+
+ me->InsertCore(nc);
+ }
+
+
+ me->RunQuery("TRUNCATE TABLE `anope_bs_core`");
+
+ for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ me->OnBotCreate(it->second);
+
+ me->RunQuery("TRUNCATE TABLE `anope_cs_info`");
+ me->RunQuery("TRUNCATE TABLE `anope_bs_badwords`");
+ me->RunQuery("TRUNCATE TABLE `anope_cs_access`");
+ me->RunQuery("TRUNCATE TABLE `anope_cs_akick`");
+ me->RunQuery("TRUNCATE TABLE `anope_cs_levels`");
+
+ for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ {
+ ChannelInfo *ci = it->second;
+
+ me->OnChanRegistered(ci);
+
+ for (unsigned j = 0, end = ci->GetBadWordCount(); j < end; ++j)
+ {
+ BadWord *bw = ci->GetBadWord(j);
+
+ me->OnBadWordAdd(ci, bw);
+ }
+
+ for (unsigned j = 0, end = ci->GetAccessCount(); j < end; ++j)
+ {
+ ChanAccess *access = ci->GetAccess(j);
+
+ me->RunQuery(Anope::string("INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES('") + access->level + "', " + me->Escape(access->nc->display) + ", " + me->Escape(ci->name) + ", " + access->last_seen + ", " + me->Escape(access->creator) + ") ON DUPLICATE KEY UPDATE level=VALUES(level), last_seen=VALUES(last_seen), creator=VALUES(creator)");
+ }
+
+ for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j)
+ {
+ AutoKick *ak = ci->GetAkick(j);
+
+ me->OnAkickAdd(ci, ak);
+ }
+
+ for (int k = 0; k < CA_SIZE; ++k)
+ {
+ me->RunQuery("INSERT DELAYED INTO `anope_cs_levels` (channel, position, level) VALUES(" + me->Escape(ci->name) + ", '" + stringify(k) + "', '" + stringify(ci->levels[k]) + "') ON DUPLICATE KEY UPDATE position=VALUES(position), level=VALUES(level)");
+ }
+
+ for (unsigned j = 0, end = ci->memos.memos.size(); j < end; ++j)
+ {
+ Memo *m = ci->memos.memos[j];
+
+ me->OnMemoSend(NULL, ci, m);
+ }
+ }
+
+ me->RunQuery("TRUNCATE TABLE `anope_ns_request`");
+
+ for (nickrequest_map::const_iterator it = NickRequestList.begin(), it_end = NickRequestList.end(); it != it_end; ++it)
+ me->OnMakeNickRequest(it->second);
+
+ if (SGLine)
+ for (unsigned i = 0, end = SGLine->GetCount(); i < end; ++i)
+ me->OnAddAkill(NULL, SGLine->GetEntry(i));
+
+ if (SZLine)
+ for (unsigned i = 0, end = SZLine->GetCount(); i < end; ++i)
+ me->OnAddXLine(NULL, SZLine->GetEntry(i), X_SZLINE);
+
+ if (SQLine)
+ for (unsigned i = 0, end = SQLine->GetCount(); i < end; ++i)
+ me->OnAddXLine(NULL, SQLine->GetEntry(i), X_SQLINE);
+
+ if (SNLine)
+ for (unsigned i = 0, end = SNLine->GetCount(); i < end; ++i)
+ me->OnAddXLine(NULL, SNLine->GetEntry(i), X_SNLINE);
+
+ for (unsigned i = 0, end = exceptions.size(); i < end; ++i)
+ me->OnExceptionAdd(NULL, exceptions[i]);
+}
+
+CommandReturn CommandSQLSync::Execute(User *u, const std::vector<Anope::string> &params)
+{
+ SaveDatabases();
+ notice_lang(Config.s_OperServ, u, OPER_SYNC_UPDATED);
+ return MOD_CONT;
+}
+
+MODULE_INIT(DBMySQL)
+
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp
new file mode 100644
index 000000000..72176fa70
--- /dev/null
+++ b/modules/extra/m_mysql.cpp
@@ -0,0 +1,414 @@
+/* RequiredLibraries: mysqlclient */
+
+#include "module.h"
+#define NO_CLIENT_LONG_LONG
+#include <mysql/mysql.h>
+#include "sql.h"
+
+/** Non blocking threaded MySQL API, based loosely from InspIRCd's m_mysql.cpp
+ *
+ * This module spawns a single thread that is used to execute blocking MySQL queries.
+ * When a module requests a query to be executed it is added to a list for the thread
+ * (which never stops looping and sleeing) to pick up and execute, the result of which
+ * is inserted in to another queue to be picked up my the main thread. The main thread
+ * uses Pipe to become notified through the socket engine when there are results waiting
+ * to be sent back to the modules requesting the query
+ */
+
+class MySQLService;
+
+/** A query request
+ */
+struct QueryRequest
+{
+ /* The connection to the database */
+ MySQLService *service;
+ /* The interface to use once we have the result to send the data back */
+ SQLInterface *interface;
+ /* The actual query */
+ Anope::string query;
+
+ QueryRequest(MySQLService *s, SQLInterface *i, const Anope::string &q) : service(s), interface(i), query(q) { }
+};
+
+struct QueryResult
+{
+ /* The interface to send the data back on */
+ SQLInterface *interface;
+ /* The result */
+ SQLResult result;
+
+ QueryResult(SQLInterface *i, SQLResult &r) : interface(i), result(r) { }
+};
+
+/** A MySQL result
+ */
+class MySQLResult : public SQLResult
+{
+ MYSQL_RES *res;
+
+ public:
+ MySQLResult(const Anope::string &q, MYSQL_RES *r) : SQLResult(q), res(r)
+ {
+ if (!res)
+ return;
+
+ unsigned num_fields = mysql_num_fields(res);
+
+ if (!num_fields)
+ return;
+
+ Alog(LOG_DEBUG) << "SQL query returned " << num_fields << " fields";
+
+ for (MYSQL_ROW row; (row = mysql_fetch_row(res));)
+ {
+ MYSQL_FIELD *fields = mysql_fetch_fields(res);
+
+ if (fields)
+ {
+ std::map<Anope::string, Anope::string> items;
+
+ for (unsigned field_count = 0; field_count < num_fields; ++field_count)
+ {
+ Alog(LOG_DEBUG) << "Field count " << field_count << " name is: " << (fields[field_count].name ? fields[field_count].name : "") << ", data is: " << (row[field_count] ? row[field_count] : "");
+ Anope::string column = (fields[field_count].name ? fields[field_count].name : "");
+ Anope::string data = (row[field_count] ? row[field_count] : "");
+
+ items[column] = data;
+ }
+
+ this->entries.push_back(items);
+ }
+ }
+ }
+
+ MySQLResult(const Anope::string &q, const Anope::string &err) : SQLResult(q, err), res(NULL)
+ {
+ }
+
+ ~MySQLResult()
+ {
+ if (this->res)
+ mysql_free_result(this->res);
+ }
+};
+
+/** A MySQL connection, there can be multiple
+ */
+class MySQLService : public SQLProvider
+{
+ Anope::string database;
+ Anope::string server;
+ Anope::string user;
+ Anope::string password;
+ int port;
+
+ MYSQL *sql;
+
+ public:
+ /* Locked by the SQL thread when a query is pending on this database,
+ * prevents us from deleting a connection while a query is executing
+ * in the thread
+ */
+ Mutex Lock;
+
+ MySQLService(Module *o, const Anope::string &n, const Anope::string &d, const Anope::string &s, const Anope::string &u, const Anope::string &p, int po);
+
+ ~MySQLService();
+
+ void Run(SQLInterface *i, const Anope::string &query);
+
+ SQLResult RunQuery(const Anope::string &query);
+
+ const Anope::string Escape(const Anope::string &buf);
+
+ void Connect();
+
+ bool CheckConnection();
+};
+
+/** The SQL thread used to execute queries
+ */
+class DispatcherThread : public Thread, public Condition
+{
+ public:
+ DispatcherThread() : Thread() { }
+
+ void Run();
+};
+
+/** The pipe used by the SocketEngine to notify the main thread when
+ * we have results from queries
+ */
+class MySQLPipe : public Pipe
+{
+ public:
+ void OnNotify();
+};
+
+class ModuleSQL;
+static ModuleSQL *me;
+class ModuleSQL : public Module
+{
+ public:
+ /* SQL connections */
+ std::map<Anope::string, MySQLService *> MySQLServices;
+ /* Pending query requests */
+ std::deque<QueryRequest> QueryRequests;
+ /* Pending finished requests with results */
+ std::deque<QueryResult> FinishedRequests;
+ /* The thread used to execute queries */
+ DispatcherThread *DThread;
+ /* Notify pipe */
+ MySQLPipe *SQLPipe;
+
+ ModuleSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
+ {
+ me = this;
+
+ Implementation i[] = { I_OnReload, I_OnModuleUnload };
+ ModuleManager::Attach(i, this, 2);
+
+ SQLPipe = new MySQLPipe();
+
+ DThread = new DispatcherThread();
+ threadEngine.Start(DThread);
+
+ OnReload(true);
+ }
+
+ ~ModuleSQL()
+ {
+ for (std::map<Anope::string, MySQLService *>::iterator it = this->MySQLServices.begin(); it != this->MySQLServices.end(); ++it)
+ delete it->second;
+ MySQLServices.clear();
+
+ DThread->SetExitState();
+ DThread->Wakeup();
+ DThread->Join();
+
+ if (SocketEngine)
+ delete SQLPipe;
+ }
+
+ void OnReload(bool startup)
+ {
+ ConfigReader config;
+ int i, num;
+
+ for (std::map<Anope::string, MySQLService *>::iterator it = this->MySQLServices.begin(); it != this->MySQLServices.end();)
+ {
+ const Anope::string cname = it->first;
+ MySQLService *s = it->second;
+ ++it;
+
+ for (i = 0, num = config.Enumerate("mysql"); i < num; ++i)
+ {
+ if (config.ReadValue("mysql", "name", "", i) == cname)
+ {
+ break;
+ }
+ }
+
+ if (i == num)
+ {
+ Alog() << "MySQL: Removing server connection " << cname;
+
+ delete s;
+ this->MySQLServices.erase(cname);
+ }
+ }
+
+ for (i = 0, num = config.Enumerate("mysql"); i < num; ++i)
+ {
+ Anope::string connname = config.ReadValue("mysql", "name", "main", i);
+
+ if (this->MySQLServices.find(connname) == this->MySQLServices.end())
+ {
+ Anope::string database = config.ReadValue("mysql", "database", "anope", i);
+ Anope::string server = config.ReadValue("mysql", "server", "127.0.0.1", i);
+ Anope::string user = config.ReadValue("mysql", "username", "anope", i);
+ Anope::string password = config.ReadValue("mysql", "password", "", i);
+ int port = config.ReadInteger("mysql", "port", "3306", i, true);
+
+ try
+ {
+ MySQLService *ss = new MySQLService(this, connname, database, server, user, password, port);
+ this->MySQLServices.insert(std::make_pair(connname, ss));
+
+ Alog() << "MySQL: Sucessfully connected to server " << connname << " (" << server << ")";
+ }
+ catch (const SQLException &ex)
+ {
+ Alog() << "MySQL: " << ex.GetReason();
+ }
+ }
+ }
+ }
+
+ void OnModuleUnload(User *, Module *m)
+ {
+ this->DThread->Lock();
+
+ for (unsigned i = this->QueryRequests.size(); i > 0; --i)
+ {
+ QueryRequest &r = this->QueryRequests[i];
+
+ if (r.interface && r.interface->owner == m)
+ {
+ if (i == 0)
+ {
+ r.service->Lock.Lock();
+ r.service->Lock.Unlock();
+ }
+
+ this->QueryRequests.erase(this->QueryRequests.begin() + i);
+ }
+ }
+
+ this->DThread->Unlock();
+ }
+};
+
+MySQLService::MySQLService(Module *o, const Anope::string &n, const Anope::string &d, const Anope::string &s, const Anope::string &u, const Anope::string &p, int po)
+: SQLProvider(o, "mysql/" + n), database(d), server(s), user(u), password(p), port(po), sql(NULL)
+{
+ Connect();
+}
+
+MySQLService::~MySQLService()
+{
+ this->Lock.Lock();
+ this->Lock.Unlock();
+ mysql_close(this->sql);
+
+ for (unsigned i = me->QueryRequests.size(); i > 0; --i)
+ {
+ QueryRequest &r = me->QueryRequests[i];
+
+ if (r.service == this)
+ {
+ if (r.interface)
+ r.interface->OnError(SQLResult("", "SQL Interface is going away"));
+ me->QueryRequests.erase(me->QueryRequests.begin() + i);
+ }
+ }
+}
+
+void MySQLService::Run(SQLInterface *i, const Anope::string &query)
+{
+ me->DThread->Lock();
+ me->QueryRequests.push_back(QueryRequest(this, i, query));
+ me->DThread->Unlock();
+ me->DThread->Wakeup();
+}
+
+SQLResult MySQLService::RunQuery(const Anope::string &query)
+{
+ if (this->CheckConnection() && !mysql_real_query(this->sql, query.c_str(), query.length()))
+ {
+ MYSQL_RES *res = mysql_use_result(this->sql);
+
+ return MySQLResult(query, res);
+ }
+ else
+ {
+ return MySQLResult(query, mysql_error(this->sql));
+ }
+}
+
+const Anope::string MySQLService::Escape(const Anope::string &buf)
+{
+ char buffer[BUFSIZE];
+ mysql_escape_string(buffer, buf.c_str(), buf.length());
+ return buffer;
+}
+
+void MySQLService::Connect()
+{
+ this->sql = mysql_init(this->sql);
+
+ const unsigned int timeout = 1;
+ mysql_options(this->sql, MYSQL_OPT_CONNECT_TIMEOUT, reinterpret_cast<const char *>(&timeout));
+
+ bool connect = mysql_real_connect(this->sql, this->server.c_str(), this->user.c_str(), this->password.c_str(), this->database.c_str(), this->port, NULL, 0);
+
+ if (!connect)
+ throw SQLException("Unable to connect to SQL service " + this->name + ": " + mysql_error(this->sql));
+}
+
+
+bool MySQLService::CheckConnection()
+{
+ if (!this->sql || mysql_ping(this->sql))
+ {
+ try
+ {
+ this->Connect();
+ }
+ catch (const SQLException &)
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void DispatcherThread::Run()
+{
+ this->Lock();
+
+ while (!this->GetExitState())
+ {
+ if (!me->QueryRequests.empty())
+ {
+ QueryRequest &r = me->QueryRequests.front();
+ this->Unlock();
+
+ r.service->Lock.Lock();
+ SQLResult sresult = r.service->RunQuery(r.query);
+ r.service->Lock.Unlock();
+
+ this->Lock();
+ if (me->QueryRequests.front().query == r.query)
+ {
+ if (r.interface)
+ me->FinishedRequests.push_back(QueryResult(r.interface, sresult));
+ me->QueryRequests.pop_front();
+ }
+ }
+ else
+ {
+ if (!me->FinishedRequests.empty())
+ me->SQLPipe->Notify();
+ this->Wait();
+ }
+ }
+
+ this->Unlock();
+}
+
+void MySQLPipe::OnNotify()
+{
+ me->DThread->Lock();
+
+ for (std::deque<QueryResult>::const_iterator it = me->FinishedRequests.begin(), it_end = me->FinishedRequests.end(); it != it_end; ++it)
+ {
+ const QueryResult &qr = *it;
+
+ if (!qr.interface)
+ throw SQLException("NULL qr.interface in MySQLPipe::OnNotify() ?");
+
+ if (qr.result.GetError().empty())
+ qr.interface->OnResult(qr.result);
+ else
+ qr.interface->OnError(qr.result);
+ }
+ me->FinishedRequests.clear();
+
+ me->DThread->Unlock();
+}
+
+MODULE_INIT(ModuleSQL)
+
diff --git a/modules/extra/mysql/db_mysql.h b/modules/extra/mysql/db_mysql.h
deleted file mode 100644
index 011c2647d..000000000
--- a/modules/extra/mysql/db_mysql.h
+++ /dev/null
@@ -1,212 +0,0 @@
-#ifndef DB_MYSQL_H
-#define DB_MYSQL_H
-
-#include "module.h"
-
-struct NickAliasFlagInfo
-{
- std::string Name;
- NickNameFlag Flag;
-};
-
-NickAliasFlagInfo NickAliasFlags[] = {
- {"FORBIDDEN", NS_FORBIDDEN},
- {"NOEXPIRE", NS_NO_EXPIRE},
- {"", static_cast<NickNameFlag>(-1)}
-};
-
-struct NickCoreFlagInfo
-{
- std::string Name;
- NickCoreFlag Flag;
-};
-
-NickCoreFlagInfo NickCoreFlags[] = {
- {"KILLPROTECT", NI_KILLPROTECT},
- {"SECURE", NI_SECURE},
- {"MSG", NI_MSG},
- {"MEMO_HARDMAX", NI_MEMO_HARDMAX},
- {"MEMO_SIGNON", NI_MEMO_SIGNON},
- {"MEMO_RECEIVE", NI_MEMO_RECEIVE},
- {"PRIVATE", NI_PRIVATE},
- {"HIDE_EMAIL", NI_HIDE_EMAIL},
- {"HIDE_MASK", NI_HIDE_MASK},
- {"HIDE_QUIT", NI_HIDE_QUIT},
- {"KILL_QUICK", NI_KILL_QUICK},
- {"KILL_IMMED", NI_KILL_IMMED},
- {"MEMO_MAIL", NI_MEMO_MAIL},
- {"HIDE_STATUS", NI_HIDE_STATUS},
- {"SUSPENDED", NI_SUSPENDED},
- {"AUTOOP", NI_AUTOOP},
- {"FORBIDDEN", NI_FORBIDDEN},
- {"", static_cast<NickCoreFlag>(-1)}
-};
-
-struct BotFlagInfo
-{
- std::string Name;
- BotServFlag Flag;
-};
-
-BotFlagInfo BotFlags[] = {
- {"DONTKICKOPS", BS_DONTKICKOPS},
- {"DONTKICKVOICES", BS_DONTKICKVOICES},
- {"FANTASY", BS_FANTASY},
- {"SYMBIOSIS", BS_SYMBIOSIS},
- {"GREET", BS_GREET},
- {"NOBOT", BS_NOBOT},
- {"KICK_BOLDS", BS_KICK_BOLDS},
- {"KICK_COLORS", BS_KICK_COLORS},
- {"KICK_REVERSES", BS_KICK_REVERSES},
- {"KICK_UNDERLINES", BS_KICK_UNDERLINES},
- {"KICK_BADWORDS", BS_KICK_BADWORDS},
- {"KICK_CAPS", BS_KICK_CAPS},
- {"KICK_FLOOD", BS_KICK_FLOOD},
- {"KICK_REPEAT", BS_KICK_REPEAT},
- {"KICK_ITALICS", BS_KICK_ITALICS},
- {"", static_cast<BotServFlag>(-1)}
-};
-
-struct ChannelFlagInfo
-{
- std::string Name;
- ChannelInfoFlag Flag;
-};
-
-ChannelFlagInfo ChannelFlags[] = {
- {"KEEPTOPIC", CI_KEEPTOPIC},
- {"SECUREOPS", CI_SECUREOPS},
- {"PRIVATE", CI_PRIVATE},
- {"TOPICLOCK", CI_TOPICLOCK},
- {"RESTRICTED", CI_RESTRICTED},
- {"PEACE", CI_PEACE},
- {"SECURE", CI_SECURE},
- {"FORBIDDEN", CI_FORBIDDEN},
- {"NO_EXPIRE", CI_NO_EXPIRE},
- {"MEMO_HARDMAX", CI_MEMO_HARDMAX},
- {"OPNOTICE", CI_OPNOTICE},
- {"SECUREFOUNDER", CI_SECUREFOUNDER},
- {"SIGNKICK", CI_SIGNKICK},
- {"SIGNKICK_LEVEL", CI_SIGNKICK_LEVEL},
- {"XOP", CI_XOP},
- {"SUSPENDED", CI_SUSPENDED},
- {"PERSIST", CI_PERSIST},
- {"", static_cast<ChannelInfoFlag>(-1)}
-};
-
-struct BotServFlagInfo
-{
- std::string Name;
- BotFlag Flag;
-};
-
-BotServFlagInfo BotServFlags[] = {
- {"PRIVATE", BI_PRIVATE},
- {"", static_cast<BotFlag>(-1)}
-};
-
-struct MemoFlagInfo
-{
- std::string Name;
- MemoFlag Flag;
-};
-
-MemoFlagInfo MemoFlags[] = {
- {"UNREAD", MF_UNREAD},
- {"RECEIPT", MF_RECEIPT},
- {"NOTIFYS", MF_NOTIFYS},
- {"", static_cast<MemoFlag>(-1)}
-};
-
-#define MYSQLPP_MYSQL_HEADERS_BURIED
-#include <mysql++/mysql++.h>
-
-inline std::string SQLAssign(const mysqlpp::String &s) { return s.c_str(); }
-
-class DBMySQL;
-static DBMySQL *me;
-
-bool ExecuteQuery(mysqlpp::Query &query)
-{
- Alog(LOG_DEBUG) << "MySQL: " << query.str();
-
- if (!query.execute())
- {
- Alog() << "MySQL: error executing query: " << query.error();
- return false;
- }
-
- return true;
-}
-
-mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query &query)
-{
- Alog(LOG_DEBUG) << "MySQL: " << query.str();
-
- mysqlpp::StoreQueryResult result = query.store();
- if (!result)
- Alog() << "MySQL: error executing query: " << query.error();
- return result;
-}
-
-class DBMySQL : public Module
-{
- private:
- bool LoadConfig()
- {
- ConfigReader config;
-
- Database = config.ReadValue("mysql", "database", "anope", 0);
- Server = config.ReadValue("mysql", "server", "127.0.0.1", 0);
- SQLUser = config.ReadValue("mysql", "username", "anope", 0);
- Password = config.ReadValue("mysql", "password", "", 0);
- Port = config.ReadInteger("mysql", "port", "3306", 0, true);
- Delay = config.ReadInteger("mysql", "updatedelay", "60", 0, true);
-
- return !Password.empty();
- }
-
- public:
- mysqlpp::Connection *Con;
- mysqlpp::NoExceptions *Ne;
-
- std::string Database;
- std::string Server;
- std::string SQLUser;
- std::string Password;
- unsigned int Port;
- unsigned int Delay;
-
- DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
- {
- me = this;
-
- this->SetAuthor("Anope");
- this->SetType(DATABASE);
-
- if (!LoadConfig())
- throw ModuleException(Anope::string("Couldn't load config"));
-
- Con = new mysqlpp::Connection(false);
- Ne = new mysqlpp::NoExceptions(Con);
- if (!Con->connect(Database.c_str(), Server.c_str(), SQLUser.c_str(), Password.c_str(), Port))
- {
- std::string Error = "MySQL: Error connecting to SQL server: ";
- Error += Con->error();
- delete Con;
- throw ModuleException(Anope::string(Error));
- }
-
- mysqlpp::Query query(Con);
- query << "SET NAMES 'utf8'";
- ExecuteQuery(query);
- }
-
- virtual ~DBMySQL()
- {
- delete Ne;
- delete Con;
- }
-};
-
-#endif // DB_MYSQL_H
diff --git a/modules/extra/mysql/db_mysql_execute.cpp b/modules/extra/mysql/db_mysql_execute.cpp
deleted file mode 100644
index 079e88147..000000000
--- a/modules/extra/mysql/db_mysql_execute.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/* RequiredLibraries: mysqlpp */
-
-#include "db_mysql.h"
-
-class FakeNickCore : public NickCore
-{
- public:
- FakeNickCore() : NickCore("-SQLUser")
- {
- NickCoreList.erase(this->display);
- }
-
- ~FakeNickCore()
- {
- NickCoreList[this->display] = this;
- Users.clear();
- }
-
- bool IsServicesOper() const { return true; }
- bool HasCommand(const std::string &) const { return true; }
- bool HasPriv(const std::string &) const { return true; }
-} SQLCore;
-
-class FakeUser : public User
-{
- public:
- FakeUser() : User("-SQLUser", "")
- {
- this->SetIdent("SQL");
- this->host = sstrdup(Config.ServerName);
- this->realname = sstrdup("Fake SQL User");
- this->hostip = sstrdup("255.255.255.255");
- this->vhost = NULL;
- this->server = Me;
-
- UserListByNick.erase("-SQLUser");
- --usercnt;
- }
-
- ~FakeUser()
- {
- UserListByNick["-SQLUser"] = this;
- ++usercnt;
-
- nc = NULL;
- }
-
- void SetNewNick(const std::string &newnick) { this->nick = newnick; }
-
- void SendMessage(const std::string &, const char *, ...) { }
- void SendMessage(const std::string &, const std::string &) { }
-
- NickCore *Account() const { return nc; }
- const bool IsIdentified(bool) const { return nc ? true : false; }
- const bool IsRecognized(bool) const { return true; }
-} SQLUser;
-
-class SQLTimer : public Timer
-{
- public:
- SQLTimer() : Timer(me->Delay, time(NULL), true)
- {
- mysqlpp::Query query(me->Con);
- query << "TRUNCATE TABLE `anope_commands`";
- ExecuteQuery(query);
- }
-
- void Tick(time_t)
- {
- mysqlpp::Query query(me->Con);
- mysqlpp::StoreQueryResult qres;
-
- query << "SELECT * FROM `anope_commands`";
- qres = StoreQuery(query);
-
- if (qres && qres.num_rows())
- {
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- User *u;
- NickAlias *na = NULL;
- bool logout = false;
-
- /* If they want -SQLUser to execute the command, use it */
- if (qres[i]["nick"] == "-SQLUser")
- {
- u = &SQLUser;
- u->SetNewNick("-SQLUser");
- u->Login(&SQLCore);
- logout = true;
- }
- else
- {
- /* See if the nick they want to execute the command is registered */
- na = findnick(SQLAssign(qres[i]["nick"]));
- if (na)
- {
- /* If it is and someone is online using that nick, use them */
- if (!na->nc->Users.empty())
- u = na->nc->Users.front();
- /* Make a fake nick and use that logged in as the nick we want to use */
- else
- {
- u = &SQLUser;
- u->SetNewNick(SQLAssign(qres[i]["nick"]));
- u->Login(na->nc);
- logout = true;
- }
- }
- else
- {
- /* Check if someone is online using the nick now */
- u = finduser(SQLAssign(qres[i]["nick"]));
- /* If they arent make a fake user, and use them */
- if (!u)
- {
- u = &SQLUser;
- u->SetNewNick(SQLAssign(qres[i]["nick"]));
- u->Logout();
- logout = true;
- }
- }
- }
-
- BotInfo *bi = findbot(SQLAssign(qres[i]["service"]));
- if (!bi)
- {
- Alog() << "Warning: SQL command for unknown service " << qres[i]["service"];
- continue;
- }
-
- mod_run_cmd(bi, u, qres[i]["command"].c_str());
-
- if (logout)
- u->Logout();
- }
-
- query << "TRUNCATE TABLE `anope_commands`";
- ExecuteQuery(query);
- }
- }
-};
-
-class DBMySQLExecute : public DBMySQL
-{
- SQLTimer *_SQLTimer;
- public:
- DBMySQLExecute(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator)
- {
- _SQLTimer = new SQLTimer();
- }
-
- ~DBMySQLExecute()
- {
- delete _SQLTimer;
- }
-};
-
-MODULE_INIT(DBMySQLExecute)
diff --git a/modules/extra/mysql/db_mysql_read.cpp b/modules/extra/mysql/db_mysql_read.cpp
deleted file mode 100644
index ff608b700..000000000
--- a/modules/extra/mysql/db_mysql_read.cpp
+++ /dev/null
@@ -1,618 +0,0 @@
-/* RequiredLibraries: mysqlpp */
-
-#include "db_mysql.h"
-
-static std::vector<std::string> MakeVector(std::string buf)
-{
- std::string s;
- spacesepstream sep(buf);
- std::vector<std::string> params;
-
- while (sep.GetToken(s))
- {
- if (s[0] == ':')
- {
- s.erase(s.begin());
- if (!s.empty() && !sep.StreamEnd())
- params.push_back(s + " " + sep.GetRemaining());
- else if (!s.empty())
- params.push_back(s);
- }
- else
- params.push_back(s);
- }
-
- return params;
-}
-
-static void LoadDatabase()
-{
- mysqlpp::Query query(me->Con);
- mysqlpp::StoreQueryResult qres;
-
- query << "SELECT * FROM `anope_ns_core`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickCore *nc = new NickCore(SQLAssign(qres[i]["display"]));
- nc->pass = SQLAssign(qres[i]["pass"]);
- if (qres[i]["email"].size())
- nc->email = sstrdup(qres[i]["email"].c_str());
- if (qres[i]["greet"].size())
- nc->greet = sstrdup(qres[i]["greet"].c_str());
- if (qres[i]["icq"].size())
- nc->icq = atol(qres[i]["icq"].c_str());
- if (qres[i]["url"].size())
- nc->url = sstrdup(qres[i]["url"].c_str());
-
- spacesepstream sep(SQLAssign(qres[i]["flags"]));
- std::string buf;
- while (sep.GetToken(buf))
- for (int j = 0; NickCoreFlags[j].Flag != -1; ++j)
- if (NickCoreFlags[j].Name == buf)
- nc->SetFlag(NickCoreFlags[j].Flag);
-
- nc->language = atoi(qres[i]["language"].c_str());
- nc->channelcount = atoi(qres[i]["channelcount"].c_str());
- nc->memos.memomax = atoi(qres[i]["memomax"].c_str());
- }
-
- query << "SELECT * FROM `anope_ns_access`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickCore *nc = findcore(qres[i]["display"].c_str());
- if (!nc)
- {
- Alog() << "MySQL: Got NickCore access entry for nonexistant core " << qres[i]["display"];
- continue;
- }
-
- nc->AddAccess(SQLAssign(qres[i]["access"]));
- }
-
- query << "SELECT * FROM `anope_ns_core_metadata`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickCore *nc = findcore(qres[i]["display"].c_str());
- if (!nc)
- {
- Alog() << "MySQL: Got NickCore access entry for nonexistant core " << qres[i]["display"];
- continue;
- }
- EventReturn MOD_RESULT;
- std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"]));
- FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, SQLAssign(qres[i]["name"]), Params));
- }
-
- query << "SELECT * FROM `anope_ns_alias`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickCore *nc = findcore(qres[i]["display"].c_str());
- if (!nc)
- {
- Alog() << "MySQL: Got NickAlias for nick " << qres[i]["nick"] << " with nonexistant core " << qres[i]["display"];
- continue;
- }
-
- NickAlias *na = new NickAlias(SQLAssign(qres[i]["nick"]), nc);
- na->last_quit = sstrdup(qres[i]["last_quit"].c_str());
- na->last_realname = sstrdup(qres[i]["last_realname"].c_str());
- na->last_usermask = sstrdup(qres[i]["last_usermask"].c_str());
- na->time_registered = atol(qres[i]["time_registered"].c_str());
- na->last_seen = atol(qres[i]["last_seen"].c_str());
-
- spacesepstream sep(SQLAssign(qres[i]["flags"]));
- std::string buf;
- while (sep.GetToken(buf))
- for (int j = 0; NickAliasFlags[j].Flag != -1; ++j)
- if (NickAliasFlags[j].Name == buf)
- na->SetFlag(NickAliasFlags[j].Flag);
- }
-
- query << "SELECT * FROM `anope_ns_alias_metadata`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickAlias *na = findnick(SQLAssign(qres[i]["nick"]));
- if (!na)
- {
- Alog() << "MySQL: Got metadata for nonexistant nick " << qres[i]["nick"];
- continue;
- }
- EventReturn MOD_RESULT;
- std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"]));
- FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, SQLAssign(qres[i]["name"]), Params));
- }
-
- query << "SELECT * FROM `anope_bs_core`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- BotInfo *bi = findbot(SQLAssign(qres[i]["nick"]));
- if (!bi)
- bi = new BotInfo(SQLAssign(qres[i]["nick"]));
- bi->user = SQLAssign(qres[i]["user"]);
- bi->host = SQLAssign(qres[i]["host"]);
- bi->real = SQLAssign(qres[i]["rname"]);
-
- if (qres[i]["flags"].size())
- {
- spacesepstream sep(SQLAssign(qres[i]["flags"]));
- std::string buf;
- while (sep.GetToken(buf))
- for (unsigned j = 0; BotServFlags[j].Flag != -1; ++j)
- if (buf == BotServFlags[j].Name)
- {
- bi->SetFlag(BotServFlags[j].Flag);
- break;
- }
- }
- bi->created = atol(qres[i]["created"]);
- bi->chancount = atol(qres[i]["chancount"]);
- }
-
- query << "SELECT * FROM `anope_bs_info_metadata`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- BotInfo *bi = findbot(SQLAssign(qres[i]["botname"]));
- if (!bi)
- {
- Alog() << "MySQL: BotInfo metadata for nonexistant bot " << qres[i]["botname"];
- continue;
- }
-
- EventReturn MOD_RESULT;
- std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"]));
- FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(bi, SQLAssign(qres[i]["name"]), Params));
- }
-
- query << "SELECT * FROM `anope_cs_info`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickCore *nc;
- if (qres[i]["founder"].size())
- {
- nc = findcore(qres[i]["founder"].c_str());
- if (!nc)
- {
- Alog() << "MySQL: Channel " << qres[i]["name"] << " with nonexistant founder " << qres[i]["founder"];
- continue;
- }
- }
-
- ChannelInfo *ci = new ChannelInfo(SQLAssign(qres[i]["name"]));
- ci->founder = nc;
- if (qres[i]["successor"].size())
- ci->successor = findcore(qres[i]["successor"].c_str());
- ci->desc = sstrdup(qres[i]["descr"].c_str());
- if (qres[i]["url"].size())
- ci->url = sstrdup(qres[i]["url"].c_str());
- if (qres[i]["email"].size())
- ci->email = sstrdup(qres[i]["email"].c_str());
- ci->time_registered = atol(qres[i]["time_registered"]);
- ci->last_used = atol(qres[i]["last_used"]);
- if (qres[i]["last_topic"].size())
- ci->last_topic = sstrdup(qres[i]["last_topic"].c_str());
- if (qres[i]["last_topic_setter"].size())
- ci->last_topic_setter = SQLAssign(qres[i]["last_topic_setter"]);
- if (qres[i]["last_topic_time"].size())
- ci->last_topic_time = atol(qres[i]["last_topic_time"].c_str());
- if (qres[i]["flags"].size())
- {
- std::string buf;
- spacesepstream sep(SQLAssign(qres[i]["flags"]));
- while (sep.GetToken(buf))
- for (int j = 0; ChannelFlags[j].Flag != -1; ++j)
- if (buf == ChannelFlags[j].Name)
- {
- ci->SetFlag(ChannelFlags[j].Flag);
- break;
- }
- }
- if (qres[i]["forbidby"].size())
- ci->forbidby = sstrdup(qres[i]["forbidby"].c_str());
- if (qres[i]["forbidreason"].size())
- ci->forbidreason = sstrdup(qres[i]["forbidreason"].c_str());
- ci->bantype = atoi(qres[i]["bantype"].c_str());
- if (qres[i]["mlock_on"].size())
- {
- std::vector<Anope::string> modes;
- std::string buf;
-
- spacesepstream sep(SQLAssign(qres[i]["mlock_on"]));
- while (sep.GetToken(buf))
- modes.push_back(Anope::string(buf));
-
- ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
- }
- if (qres[i]["mlock_off"].size())
- {
- std::vector<Anope::string> modes;
- std::string buf;
-
- spacesepstream sep(SQLAssign(qres[i]["mlock_off"]));
- while (sep.GetToken(buf))
- modes.push_back(Anope::string(buf));
-
- ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
- }
- if (qres[i]["mlock_params"].size())
- {
- std::vector<std::pair<Anope::string, Anope::string> > mlp;
- std::string buf, buf2;
-
- spacesepstream sep(SQLAssign(qres[i]["mlock_params"]));
-
- while (sep.GetToken(buf) && sep.GetToken(buf2))
- mlp.push_back(std::make_pair(Anope::string(buf), Anope::string(buf2)));
-
- ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp));
- }
- if (qres[i]["entry_message"].size())
- ci->entry_message = sstrdup(qres[i]["entry_message"].c_str());
- ci->memos.memomax = atoi(qres[i]["memomax"].c_str());
- if (qres[i]["botnick"].size())
- ci->bi = findbot(SQLAssign(qres[i]["botnick"]));
- if (ci->bi)
- {
- if (qres[i]["botflags"].size())
- {
- std::string buf;
- spacesepstream sep(SQLAssign(qres[i]["botflags"]));
- while (sep.GetToken(buf))
- for (int j = 0; BotFlags[j].Flag != -1; ++j)
- if (buf == BotFlags[j].Name)
- {
- ci->botflags.SetFlag(BotFlags[j].Flag);
- break;
- }
- }
- }
- if (qres[i]["capsmin"].size())
- ci->capsmin = atoi(qres[i]["capsmin"].c_str());
- if (qres[i]["capspercent"].size())
- ci->capspercent = atoi(qres[i]["capspercent"].c_str());
- if (qres[i]["floodlines"].size())
- ci->floodlines = atoi(qres[i]["floodlines"].c_str());
- if (qres[i]["floodsecs"].size())
- ci->floodsecs = atoi(qres[i]["floodsecs"].c_str());
- if (qres[i]["repeattimes"].size())
- ci->repeattimes = atoi(qres[i]["repeattimes"].c_str());
- }
-
- query << "SELECT * FROM `anope_cs_ttb";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
- if (!ci)
- {
- Alog() << "MySQL: Channel ttb for nonexistant channel " << qres[i]["channel"];
- continue;
- }
-
- ci->ttb[atoi(qres[i]["ttb_id"].c_str())] = atoi(qres[i]["value"].c_str());
- }
-
- query << "SELECT * FROM `anope_bs_badwords`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
- if (!ci)
- {
- Alog() << "MySQL: Channel badwords entry for nonexistant channel " << qres[i]["channel"];
- continue;
- }
-
- BadWordType BWTYPE = BW_ANY;
- if (qres[i]["type"] == "SINGLE")
- BWTYPE = BW_SINGLE;
- else if (qres[i]["type"] == "START")
- BWTYPE = BW_START;
- else if (qres[i]["type"] == "END")
- BWTYPE = BW_END;
- ci->AddBadWord(SQLAssign(qres[i]["word"]), BWTYPE);
- }
-
- query << "SELECT * FROM `anope_cs_access`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
- if (!ci)
- {
- Alog() << "MySQL: Channel access entry for nonexistant channel " << qres[i]["channel"];
- continue;
- }
- NickCore *nc = findcore(qres[i]["display"]);
- if (!nc)
- {
- Alog() << "MySQL: Channel access entry for " << ci->name << " with nonexistant nick " << qres[i]["display"];
- continue;
- }
-
- ci->AddAccess(nc, atoi(qres[i]["level"]), SQLAssign(qres[i]["creator"]), atol(qres[i]["last_seen"]));
- }
-
- query << "SELECT * FROM `anope_cs_akick`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
- if (!ci)
- {
- Alog() << "MySQL: Channel akick entry for nonexistant channel " << qres[i]["channel"];
- continue;
- }
- NickCore *nc = NULL;
- spacesepstream sep(qres[i]["flags"]);
- std::string flag, mask;
- bool stuck = false;
- while (sep.GetToken(flag))
- if (flag == "ISNICK")
- nc = findcore(qres[i]["mask"]);
- else if (flag == "STUCK")
- stuck = true;
- AutoKick *ak;
- if (nc)
- ak = ci->AddAkick(SQLAssign(qres[i]["creator"]), nc, SQLAssign(qres[i]["reason"]), atol(qres[i]["created"].c_str()), atol(qres[i]["last_used"].c_str()));
- else
- ak = ci->AddAkick(SQLAssign(qres[i]["creator"]), SQLAssign(qres[i]["mask"]), SQLAssign(qres[i]["reason"]), atol(qres[i]["created"].c_str()), atol(qres[i]["last_used"].c_str()));
- if (stuck)
- ak->SetFlag(AK_STUCK);
- if (nc)
- ak->SetFlag(AK_ISNICK);
- }
-
- query << "SELECT * FROM `anope_cs_levels`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
- if (!ci)
- {
- Alog() << "MySQL: Channel level entry for nonexistant channel " << qres[i]["channel"];
- continue;
- }
- ci->levels[atoi(qres[i]["position"])] = atoi(qres[i]["level"]);
- }
-
- query << "SELECT * FROM `anope_cs_info_metadata`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
- if (!ci)
- {
- Alog() << "MySQL: Channel metadata for nonexistant channel " << qres[i]["channel"];
- continue;
- }
-
- EventReturn MOD_RESULT;
- std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"]));
- FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, SQLAssign(qres[i]["name"]), Params));
- }
-
- query << "SELECT * FROM `anope_ns_request`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickRequest *nr = new NickRequest(qres[i]["nick"].c_str());
- nr->passcode = SQLAssign(qres[i]["passcode"]);
- nr->password = SQLAssign(qres[i]["password"]);
- nr->email = sstrdup(qres[i]["email"].c_str());
- nr->requested = atol(qres[i]["requested"].c_str());
- }
-
- EventReturn MOD_RESULT;
- query << "SELECT * FROM `anope_extra`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["data"]));
- FOREACH_RESULT(I_OnDatabaseRead, OnDatabaseRead(params));
- }
-
- query << "SELECT * FROM `anope_ns_core_metadata`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickCore *nc = findcore(qres[i]["nick"].c_str());
- if (nc)
- {
- std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"]));
- FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, SQLAssign(qres[i]["name"]), params));
- }
- }
-
- query << "SELECT * FROM `anope_ns_alias_metadata`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- NickAlias *na = findnick(SQLAssign(qres[i]["nick"]));
- if (na)
- {
- std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"]));
- FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, SQLAssign(qres[i]["name"]), params));
- }
- }
-
- query << "SELECT * FROM `anope_cs_info_metadata`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
- if (ci)
- {
- std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"]));
- FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, SQLAssign(qres[i]["name"]), params));
- }
- }
-
- query << "SELECT * FROM `anope_ms_info`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- MemoInfo *mi = NULL;
- if (qres[i]["serv"] == "NICK")
- {
- NickCore *nc = findcore(qres[i]["receiver"].c_str());
- if (nc)
- mi = &nc->memos;
- }
- else if (qres[i]["serv"] == "CHAN")
- {
- ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["receiver"]));
- if (ci)
- mi = &ci->memos;
- }
- if (mi)
- {
- Memo *m = new Memo();
- mi->memos.push_back(m);
- m->sender = SQLAssign(qres[i]["sender"]);
- if (mi->memos.size() > 1)
- {
- m->number = mi->memos[mi->memos.size() - 2]->number + 1;
- if (m->number < 1)
- {
- for (unsigned j = 0; j < mi->memos.size(); ++j)
- mi->memos[j]->number = j + 1;
- }
- }
- else
- m->number = 1;
- m->time = atol(qres[i]["time"].c_str());
- m->text = sstrdup(qres[i]["text"].c_str());
-
- if (qres[i]["flags"].size())
- {
- spacesepstream sep(SQLAssign(qres[i]["flags"]));
- std::string buf;
- while (sep.GetToken(buf))
- for (unsigned j = 0; MemoFlags[j].Flag != -1; ++j)
- if (MemoFlags[j].Name == buf)
- m->SetFlag(MemoFlags[j].Flag);
- }
- }
- }
-
- query << "SELECT * FROM `anope_os_akills`";
- qres = StoreQuery(query);
-
- if (qres && SGLine)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ci::string user = qres[i]["user"].c_str();
- ci::string host = qres[i]["host"].c_str();
- ci::string by = qres[i]["xby"].c_str();
- std::string reason = SQLAssign(qres[i]["reason"]);
- time_t seton = atol(qres[i]["seton"].c_str());
- time_t expires = atol(qres[i]["expire"].c_str());
-
- XLine *x = SGLine->Add(NULL, NULL, user + "@" + host, expires, reason);
- if (x)
- {
- x->By = by;
- x->Created = seton;
- }
- }
-
- query << "SELECT * FROM `anope_os_xlines`";
- qres = StoreQuery(query);
-
- if (qres)
- for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
- {
- ci::string mask = qres[i]["mask"].c_str();
- ci::string by = qres[i]["xby"].c_str();
- std::string reason = SQLAssign(qres[i]["reason"]);
- time_t seton = atol(qres[i]["seton"].c_str());
- time_t expires = atol(qres[i]["expires"].c_str());
-
- XLine *x = NULL;
- if (qres[i]["type"] == "SNLINE" && SNLine)
- x = SNLine->Add(NULL, NULL, mask, expires, reason);
- else if (qres[i]["type"] == "SQLINE" && SQLine)
- x = SQLine->Add(NULL, NULL, mask, expires, reason);
- else if (qres[i]["type"] == "SZLINE" && SZLine)
- x = SZLine->Add(NULL, NULL,mask, expires, reason);
- if (x)
- {
- x->By = by;
- x->Created = seton;
- }
- }
-}
-
-class DBMySQLRead : public DBMySQL
-{
- public:
- DBMySQLRead(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator)
- {
- Implementation i[] = { I_OnLoadDatabase };
- ModuleManager::Attach(i, this, 1);
- }
-
- ~DBMySQLRead()
- {
- }
-
- EventReturn OnLoadDatabase()
- {
- LoadDatabase();
-
- /* No need to ever reload this again, although this should never be triggered again */
- ModuleManager::Detach(I_OnLoadDatabase, this);
-
- return EVENT_STOP;
- }
-};
-
-MODULE_INIT(DBMySQLRead)
diff --git a/modules/extra/mysql/db_mysql_write.cpp b/modules/extra/mysql/db_mysql_write.cpp
deleted file mode 100644
index 5d2ef2a78..000000000
--- a/modules/extra/mysql/db_mysql_write.cpp
+++ /dev/null
@@ -1,1040 +0,0 @@
-/* RequiredLibraries: mysqlpp */
-
-#include "db_mysql.h"
-
-static std::string BuildFlagsList(ChannelInfo *ci)
-{
- std::string ret;
-
- for (int i = 0; ChannelFlags[i].Flag != -1; ++i)
- if (ci->HasFlag(ChannelFlags[i].Flag))
- ret += " " + ChannelFlags[i].Name;
-
- if (!ret.empty())
- ret.erase(ret.begin());
-
- return ret;
-}
-
-static std::string BuildFlagsList(NickAlias *na)
-{
- std::string ret;
-
- for (int i = 0; NickAliasFlags[i].Flag != -1; ++i)
- if (na->HasFlag(NickAliasFlags[i].Flag))
- ret += " " + NickAliasFlags[i].Name;
-
- if (!ret.empty())
- ret.erase(ret.begin());
-
- return ret;
-}
-
-static std::string BuildFlagsList(NickCore *nc)
-{
- std::string ret;
-
- for (int i = 0; NickCoreFlags[i].Flag != -1; ++i)
- if (nc->HasFlag(NickCoreFlags[i].Flag))
- ret += " " + NickCoreFlags[i].Name;
-
- if (!ret.empty())
- ret.erase(ret.begin());
-
- return ret;
-}
-
-static std::string BuildFlagsList(Memo *m)
-{
- std::string ret;
-
- for (int i = 0; MemoFlags[i].Flag != -1; ++i)
- if (m->HasFlag(MemoFlags[i].Flag))
- ret += " " + MemoFlags[i].Name;
-
- if (!ret.empty())
- ret.erase(ret.begin());
-
- return ret;
-}
-
-static std::string MakeMLock(ChannelInfo *ci, bool status)
-{
- std::string ret;
-
- for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it)
- {
- if ((*it)->Class == MC_CHANNEL)
- {
- ChannelMode *cm = debug_cast<ChannelMode *>(*it);
-
- if (ci->HasMLock(cm->Name, status))
- ret += " " + cm->NameAsString;
- }
- }
-
- if (!ret.empty())
- ret.erase(ret.begin());
-
- return ret;
-}
-
-static inline std::string GetMLockOn(ChannelInfo *ci)
-{
- return MakeMLock(ci, true);
-}
-
-static inline std::string GetMLockOff(ChannelInfo *ci)
-{
- return MakeMLock(ci, false);
-}
-
-static std::string GetMLockParams(ChannelInfo *ci)
-{
- std::string ret;
-
- for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it)
- {
- if ((*it)->Class == MC_CHANNEL)
- {
- ChannelMode *cm = debug_cast<ChannelMode *>(*it);
-
- std::string param;
- if (ci->GetParam(cm->Name, param))
- ret += " " + cm->NameAsString + " " + param;
- }
- }
-
- if (!ret.empty())
- ret.erase(ret.begin());
-
- return ret;
-}
-
-static std::string GetBotFlags(Flags<BotServFlag>& Flags)
-{
- std::string buf;
-
- for (int i = 0; BotFlags[i].Flag != -1; ++i)
- if (Flags.HasFlag(BotFlags[i].Flag))
- buf += " " + BotFlags[i].Name;
-
- if (!buf.empty())
- buf.erase(buf.begin());
-
- return buf;
-}
-
-static std::string GetBotServFlags(BotInfo *bi)
-{
- std::string buf;
-
- for (int i = 0; BotServFlags[i].Flag != -1; ++i)
- if (bi->HasFlag(BotServFlags[i].Flag))
- buf += " " + BotServFlags[i].Name;
-
- if (!buf.empty())
- buf.erase(buf.begin());;
-
- return buf;
-}
-
-static NickAlias *CurNick = NULL;
-static NickCore *CurCore = NULL;
-static ChannelInfo *CurChannel = NULL;
-static BotInfo *CurBot = NULL;
-
-void Write(const std::string &data)
-{
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_extra` (data) VALUES(" << mysqlpp::quote << data << ")";
- ExecuteQuery(query);
-}
-
-void WriteMetadata(const std::string &key, const std::string &data)
-{
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_metadata` (name, value) VALUES(" << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")";
- ExecuteQuery(query);
-}
-
-void WriteNickMetadata(const std::string &key, const std::string &data)
-{
- if (!CurNick)
- throw CoreException(Anope::string("WriteNickMetadata without a nick to write"));
-
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_ns_alias_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurNick->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")";
- ExecuteQuery(query);
-}
-
-void WriteCoreMetadata(const std::string &key, const std::string &data)
-{
- if (!CurCore)
- throw CoreException(Anope::string("WritCoreMetadata without a core to write"));
-
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_ns_core_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurCore->display << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")";
- ExecuteQuery(query);
-}
-
-void WriteChannelMetadata(const std::string &key, const std::string &data)
-{
- if (!CurChannel)
- throw CoreException(Anope::string("WriteChannelMetadata without a channel to write"));
-
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_cs_info_metadata` (channel, name, value) VALUES(" << mysqlpp::quote << CurChannel->name << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")";
- ExecuteQuery(query);
-}
-
-void WriteBotMetadata(const std::string &key, const std::string &data)
-{
- if (!CurBot)
- throw CoreException(Anope::string("WriteBotMetadata without a bot to write"));
-
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_bs_info_metadata` (botname, name, value) VALUES(" << mysqlpp::quote << CurBot->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")";
- ExecuteQuery(query);
-}
-
-static void SaveDatabases()
-{
- mysqlpp::Query query(me->Con);
-
- query << "TRUNCATE TABLE `anope_ns_alias`";
- ExecuteQuery(query);
-
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
- me->OnNickRegister(it->second);
-
- query << "TRUNCATE TABLE `anope_ns_core`";
- ExecuteQuery(query);
- query << "TRUNCATE TABLE `anope_ms_info`";
- ExecuteQuery(query);
-
- for (nickcore_map::const_iterator nit = NickCoreList.begin(), nit_end = NickCoreList.end(); nit != nit_end; ++nit)
- {
- NickCore *nc = nit->second;
-
- for (std::vector<std::string>::iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it)
- {
- query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << *it << ")";
- ExecuteQuery(query);
- }
-
- for (unsigned j = 0, end = nc->memos.memos.size(); j < end; ++j)
- {
- Memo *m = nc->memos.memos[j];
-
- me->OnMemoSend(NULL, nc, m);
- }
- }
-
-
- query << "TRUNCATE TABLE `anope_bs_core`";
- ExecuteQuery(query);
-
- for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
- me->OnBotCreate(it->second);
-
- query << "TRUNCATE TABLE `anope_cs_info`";
- ExecuteQuery(query);
- query << "TRUNCATE TABLE `anope_bs_badwords`";
- ExecuteQuery(query);
- query << "TRUNCATE TABLE `anope_cs_access`";
- ExecuteQuery(query);
- query << "TRUNCATE TABLE `anope_cs_akick`";
- ExecuteQuery(query);
- query << "TRUNCATE TABLE `anope_cs_levels`";
- ExecuteQuery(query);
-
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
- {
- ChannelInfo *ci = it->second;
-
- me->OnChanRegistered(ci);
-
- for (unsigned j = 0, end = ci->GetBadWordCount(); j < end; ++j)
- {
- BadWord *bw = ci->GetBadWord(j);
-
- me->OnBadWordAdd(ci, bw);
- }
-
- for (unsigned j = 0, end = ci->GetAccessCount(); j < end; ++j)
- {
- ChanAccess *access = ci->GetAccess(j);
-
- query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES('" << access->level << "', " << mysqlpp::quote << access->nc->display << ", " << mysqlpp::quote << ci->name << ", " << access->last_seen << ", " << mysqlpp::quote << access->creator << ") ON DUPLICATE KEY UPDATE level=VALUES(level), last_seen=VALUES(last_seen), creator=VALUES(creator)";
- ExecuteQuery(query);
- }
-
- for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j)
- {
- AutoKick *ak = ci->GetAkick(j);
-
- me->OnAkickAdd(NULL, ci, ak);
- }
-
- for (int k = 0; k < CA_SIZE; ++k)
- {
- query << "INSERT DELAYED INTO `anope_cs_levels` (channel, position, level) VALUES(" << mysqlpp::quote << ci->name << ", '" << k << "', '" << ci->levels[k] << "') ON DUPLICATE KEY UPDATE position=VALUES(position), level=VALUES(level)";
- ExecuteQuery(query);
- }
-
- for (unsigned j = 0, end = ci->memos.memos.size(); j < end; ++j)
- {
- Memo *m = ci->memos.memos[j];
-
- me->OnMemoSend(NULL, ci, m);
- }
- }
-
- query << "TRUNCATE TABLE `anope_ns_request`";
- ExecuteQuery(query);
-
- for (nickrequest_map::const_iterator it = NickRequestList.begin(), it_end = NickRequestList.end(); it != it_end; ++it)
- me->OnMakeNickRequest(it->second);
-
- if (SGLine)
- for (unsigned i = 0, end = SGLine->GetCount(); i < end; ++i)
- me->OnAddAkill(NULL, SGLine->GetEntry(i));
-
- if (SZLine)
- for (unsigned i = 0, end = SZLine->GetCount(); i < end; ++i)
- me->OnAddXLine(NULL, SZLine->GetEntry(i), X_SZLINE);
-
- if (SQLine)
- for (unsigned i = 0, end = SQLine->GetCount(); i < end; ++i)
- me->OnAddXLine(NULL, SQLine->GetEntry(i), X_SQLINE);
-
- if (SNLine)
- for (unsigned i = 0, end = SNLine->GetCount(); i < end; ++i)
- me->OnAddXLine(NULL, SNLine->GetEntry(i), X_SNLINE);
-
- for (int i = 0; i < nexceptions; ++i)
- {
- Exception *ex = &exceptions[i];
-
- me->OnExceptionAdd(NULL, ex);
- }
-}
-
-class CommandSyncSQL : public Command
-{
- public:
- CommandSyncSQL(const ci::string &cname) : Command(cname, 0, 0, "operserv/sqlsync")
- {
- }
-
- CommandReturn Execute(User *u, const std::vector<ci::string> &params)
- {
- notice_lang(Config.s_OperServ, u, OPER_SYNC_UPDATING);
- SaveDatabases();
- notice_lang(Config.s_OperServ, u, OPER_SYNC_UPDATED);
- return MOD_CONT;
- }
-
- bool OnHelp(User *u, const Anope::string &subcommand)
- {
- notice_help(Config.s_OperServ, u, OPER_HELP_SYNC);
- return true;
- }
-
- void OnServHelp(User *u)
- {
- notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SQLSYNC);
- }
-};
-
-class DBMySQLWrite : public DBMySQL
-{
- public:
- DBMySQLWrite(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator)
- {
- me = this;
-
- ModuleManager::Attach(I_OnServerConnect, this);
-
- this->AddCommand(OperServ, new CommandSyncSQL("SQLSYNC"));
-
- if (uplink_server)
- OnServerConnect();
- }
-
- ~DBMySQLWrite()
- {
- }
-
- void OnServerConnect()
- {
- Implementation i[] = {
- /* Misc */
- I_OnSaveDatabase, I_OnPostCommand,
- /* NickServ */
- I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearAccess,
- I_OnDelCore, I_OnNickForbidden, I_OnNickGroup, I_OnMakeNickRequest,
- I_OnDelNickRequest, I_OnNickRegister, I_OnChangeCoreDisplay,
- I_OnNickSuspended,
- /* ChanServ */
- I_OnAccessAdd, I_OnAccessDel, I_OnAccessChange, I_OnAccessClear, I_OnLevelChange,
- I_OnChanForbidden, I_OnDelChan, I_OnChanRegistered, I_OnChanSuspend,
- I_OnAkickAdd, I_OnAkickDel,
- /* BotServ */
- I_OnBotCreate, I_OnBotChange, I_OnBotDelete,
- I_OnBotAssign, I_OnBotUnAssign,
- I_OnBadWordAdd, I_OnBadWordDel,
- /* MemoServ */
- I_OnMemoSend, I_OnMemoDel,
- /* OperServ */
- I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel,
- I_OnAddXLine, I_OnDelXLine
- };
- ModuleManager::Attach(i, this, 39);
- }
-
- EventReturn OnSaveDatabase()
- {
- mysqlpp::Query query(me->Con);
-
- query << "TRUNCATE TABLE `anope_os_core`";
- ExecuteQuery(query);
- query << "INSERT DELAYED INTO `anope_os_core` (maxusercnt, maxusertime, akills_count, sglines_count, sqlines_count, szlines_count) VALUES(";
- query << maxusercnt << ", " << maxusertime << ", " << (SGLine ? SGLine->GetCount() : 0) << ", " << (SQLine ? SQLine->GetCount() : 0) << ", " << (SNLine ? SNLine->GetCount() : 0) << ", " << (SZLine ? SZLine->GetCount() : 0) << ")";
- ExecuteQuery(query);
-
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != end; ++it)
- {
- CurCore = it->second;
- FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteCoreMetadata, CurCore));
- }
-
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
- {
- CurNick = it->second;
- FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteNickMetadata, CurNick));
- }
-
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChanelList.end(); it != it_end; ++it)
- {
- CurChannel = it->second;
- FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, CurChannel));
- }
-
- for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
- {
- CurBot = it->second;
- FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteBotMetadata, CurBot));
-
- /* This is for the core bots, bots added by users are already handled by an event */
- query << "INSERT DELAYED INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES(";
- query << mysqlpp::quote << CurBot->nick << ", " << mysqlpp::quote << CurBot->user << ", " << mysqlpp::quote << CurBot->host;
- query << ", " << mysqlpp::quote << CurBot->real << ", '" << GetBotServFlags(CurBot) << "', " << CurBot->created << ", ";
- query << CurBot->chancount << ") ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(created)";
- ExecuteQuery(query);
- }
-
- FOREACH_MOD(I_OnDatabaseWrite, OnDatabaseWrite(Write));
-
- return EVENT_CONTINUE;
- }
-
- void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> &params)
- {
- mysqlpp::Query query(me->Con);
-
- if (service == Config.s_NickServ)
- {
- if (u->Account() && ((command == "SET" && !params.empty()) || (command == "SASET" && u->Account()->HasCommand("nickserv/saset") && params.size() > 1)))
- {
- ci::string cmd = (command == "SET" ? params[0] : params[1]);
- NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0]));
- if (!nc)
- return;
- if (cmd == "PASSWORD" && params.size() > 1)
- {
- query << "UPDATE `anope_ns_core` SET `pass` = " << mysqlpp::quote << nc->pass << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
- else if (cmd == "LANGUAGE" && params.size() > 1)
- {
- query << "UPDATE `anope_ns_core` SET `language` = " << nc->language << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
- else if (cmd == "URL")
- {
- query << "UPDATE `anope_ns_core` SET `url` = " << mysqlpp::quote << (nc->url ? nc->url : "") << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
- else if (cmd == "EMAIL")
- {
- query << "UPDATE `anope_ns_core` SET `email` = " << mysqlpp::quote << (nc->email ? nc->email : "") << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
- else if (cmd == "ICQ")
- {
- query << "UPDATE `anope_ns_core` SET `icq` = " << (nc->icq ? nc->icq : 0) << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
- else if (cmd == "GREET")
- {
- query << "UPDATE `anope_ns_core` SET `greet` = " << mysqlpp::quote << (nc->greet ? nc->greet : "") << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
- else if (cmd == "KILL" || cmd == "SECURE" || cmd == "PRIVATE" || cmd == "MSG" || cmd == "HIDE" || cmd == "AUTOOP")
- {
- query << "UPDATE `anope_ns_core` SET `flags` = '" << BuildFlagsList(nc) << "' WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
- }
- }
- else if (service == Config.s_ChanServ)
- {
- if (command == "SET" && u->Account() && params.size() > 1)
- {
- ChannelInfo *ci = cs_findchan(params[0]);
- if (!ci)
- return;
- if (!u->Account()->HasPriv("chanserv/set") && check_access(u, ci, CA_SET))
- return;
- if (params[1] == "FOUNDER" && ci->founder)
- {
- query << "UPDATE `anope_cs_info` SET `founder` = " << mysqlpp::quote << ci->founder->display << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "SUCCESSOR")
- {
- query << "UPDATE `anope_cs_info` SET `successor` = " << mysqlpp::quote << (ci->successor ? ci->successor->display : "") << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "DESC")
- {
- query << "UPDATE `anope_cs_info` SET `descr` = " << mysqlpp::quote << ci->desc << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "URL")
- {
- query << "UPDATE `anope_cs_info` SET `url` = " << mysqlpp::quote << (ci->url ? ci->url : "") << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "EMAIL")
- {
- query << "UPDATE `anope_cs_info` SET `email` = " << mysqlpp::quote << (ci->email ? ci->email : "") << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "ENTRYMSG")
- {
- query << "UPDATE `anope_cs_info` SET `entry_message` = " << mysqlpp::quote << (ci->entry_message ? ci->entry_message : "") << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "MLOCK")
- {
- query << "UPDATE `anope_cs_info` SET `mlock_on` = '" << GetMLockOn(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_info` SET `mlock_off` = '" << GetMLockOff(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_info` SET `mlock_params` = '" << GetMLockParams(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "BANTYPE")
- {
- query << "UPDATE `anope_cs_info` SET `bantype` = " << ci->bantype << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "KEEPTOPIC" || params[1] == "TOPICLOCK" || params[1] == "PRIVATE" || params[1] == "SECUREOPS" || params[1] == "SECUREFOUNDER" || params[1] == "RESTRICTED" || params[1] == "SECURE" || params[1] == "SIGNKICK" || params[1] == "OPNOTICE" || params[1] == "XOP" || params[1] == "PEACE" || params[1] == "PERSIST" || params[1] == "NOEXPIRE")
- {
- query << "UPDATE `anope_cs_info` SET `flags` = '" << BuildFlagsList(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- }
- }
- else if (Config.s_BotServ && service == Config.s_BotServ)
- {
- if (command == "KICK" && params.size() > 2)
- {
- ChannelInfo *ci = cs_findchan(params[0]);
- if (!ci)
- return;
- if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration"))
- return;
- if (params[1] == "BADWORDS" || params[1] == "BOLDS" || params[1] == "CAPS" || params[1] == "COLORS" || params[1] == "FLOOD" || params[1] == "REPEAT" || params[1] == "REVERSES" || params[1] == "UNDERLINES")
- {
- if (params[2] == "ON" || params[2] == "OFF")
- {
- for (int i = 0; i < TTB_SIZE; ++i)
- {
- query << "INSERT DELAYED INTO `anope_cs_ttb` (channel, ttb_id, value) VALUES(" << mysqlpp::quote << ci->name << ", " << i << ", " << ci->ttb[i] << ") ON DUPLICATE KEY UPDATE channel=VALUES(channel), ttb_id=VALUES(ttb_id), value=VALUES(value)";
- ExecuteQuery(query);
- }
- query << "UPDATE `anope_cs_info` SET `botflags` = '" << GetBotFlags(ci->botflags) << "' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
-
- if (params[1] == "CAPS")
- {
- query << "UPDATE `anope_cs_info` SET `capsmin` = " << ci->capsmin << ", `capspercent` = " << ci->capspercent << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "FLOOD")
- {
- query << "UPDATE `anope_cs_info` SET `floodlines` = " << ci->floodlines << ", `floodsecs` = " << ci->floodsecs << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- else if (params[1] == "REPEAT")
- {
- query << "UPDATE `anope_cs_info` SET `repeattimes` = " << ci->repeattimes << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- }
- }
- }
- else if (command == "SET" && params.size() > 2)
- {
- ChannelInfo *ci = cs_findchan(params[0]);
- if (ci && !check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration"))
- return;
- BotInfo *bi = NULL;
- if (!ci)
- bi = findbot(params[0]);
- if (bi && params[1] == "PRIVATE" && u->Account()->HasPriv("botserv/set/private"))
- {
- query << "UPDATE `anope_bs_core` SET `flags` = '" << GetBotServFlags(bi) << "' WHERE `nick` = " << mysqlpp::quote << bi->nick;
- ExecuteQuery(query);
- }
- else if (!ci)
- return;
- else if (params[1] == "DONTKICKOPS" || params[1] == "DONTKICKVOICES" || params[1] == "FANTASY" || params[1] == "GREET" || params[1] == "SYMBIOSIS" || params[1] == "NOBOT")
- {
- query << "UPDATE `anope_cs_info` SET `botflags` = '" << GetBotFlags(ci->botflags) << "' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
- }
- }
- }
-
- void OnNickAddAccess(NickCore *nc, const Anope::string &entry)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << entry << ")";
- ExecuteQuery(query);
- }
-
- void OnNickEraseAccess(NickCore *nc, const Anope::string &entry)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display << " AND `access` = " << mysqlpp::quote << entry;
- ExecuteQuery(query);
- }
-
- void OnNickClearAccess(NickCore *nc)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
-
- void OnDelCore(NickCore *nc)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_cs_access` WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_cs_akick` WHERE `mask` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_ns_alias` WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_ns_core` WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
-
- void OnNickForbidden(NickAlias *na)
- {
- std::string flags = BuildFlagsList(na);
- mysqlpp::Query query(me->Con);
- query << "UPDATE `anope_ns_alias` SET `flags` = '" << (!flags.empty() ? flags : "") << "' WHERE `nick` = " << mysqlpp::quote << na->nick;
- ExecuteQuery(query);
- }
-
- void OnNickGroup(User *u, NickAlias *)
- {
- OnNickRegister(findnick(u->nick));
- }
-
- void OnMakeNickRequest(NickRequest *nr)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_ns_request` (nick, passcode, password, email, requested) VALUES(" << mysqlpp::quote << nr->nick << ", ";
- query << mysqlpp::quote << nr->passcode << ", " << mysqlpp::quote << nr->password << ", " << mysqlpp::quote << nr->email << ", '";
- query << nr->requested << "')";
- ExecuteQuery(query);
- }
-
- void OnDelNickRequest(NickRequest *nr)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_ns_request` WHERE `nick` = " << mysqlpp::quote << nr->nick;
- ExecuteQuery(query);
- }
-
- void OnNickRegister(NickAlias *na)
- {
- std::string flags = BuildFlagsList(na);
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_ns_alias` (nick, last_quit, last_realname, last_usermask, time_registered, last_seen, flags, display) VALUES(";
- query << mysqlpp::quote << na->nick << ", " << mysqlpp::quote << (na->last_quit ? na->last_quit : "") << ", ";
- query << mysqlpp::quote << (na->last_realname ? na->last_realname : "") << ", ";
- query << mysqlpp::quote << (na->last_usermask ? na->last_usermask : "") << ", " << na->time_registered << ", " << na->last_seen;
- query << ", '" << (!flags.empty() ? flags : "") << "', " << mysqlpp::quote << na->nc->display << ") ";
- query << "ON DUPLICATE KEY UPDATE last_quit=VALUES(last_quit), last_realname=VALUES(last_realname), last_usermask=VALUES(last_usermask), time_registered=VALUES(time_registered), last_seen=VALUES(last_seen), flags=VALUES(flags), display=VALUES(display)";
- ExecuteQuery(query);
-
- flags = BuildFlagsList(na->nc);
- query << "INSERT DELAYED INTO `anope_ns_core` (display, pass, email, greet, icq, url, flags, language, channelcount, memomax) VALUES(";
- query << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << na->nc->pass << ", ";
- query << mysqlpp::quote << (na->nc->email ? na->nc->email : "") << ", " << mysqlpp::quote << (na->nc->greet ? na->nc->greet : "");
- query << ", " << na->nc->icq << ", " << mysqlpp::quote << (na->nc->url ? na->nc->url : "");
- query << ", '" << (!flags.empty() ? flags : "") << "', " << na->nc->language << ", " << na->nc->channelcount << ", ";
- query << na->nc->memos.memomax << ") ";
- query << "ON DUPLICATE KEY UPDATE pass=VALUES(pass), email=VALUES(email), greet=VALUES(greet), icq=VALUES(icq), flags=VALUES(flags), language=VALUES(language), ";
- query << "channelcount=VALUES(channelcount), memomax=VALUES(memomax)";
- ExecuteQuery(query);
- }
-
- void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay)
- {
- mysqlpp::Query query(me->Con);
- query << "UPDATE `anope_ns_core` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "UPDATE `anope_ns_alias` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "UPDATE `anope_ns_access` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_access` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_info` SET `founder` = " << mysqlpp::quote << newdisplay << " WHERE `founder` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_info` SET `successor` = " << mysqlpp::quote << newdisplay << " WHERE `successor` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- query << "UPDATE `anope_ms_info` SET `receiver` = " << mysqlpp::quote << newdisplay << " WHERE `receiver` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
-
- void OnNickSuspend(NickAlias *na)
- {
- mysqlpp::Query query(me->Con);
- query << "UPDATE `anope_ns_core` SET `flags` = '" << BuildFlagsList(na->nc) << "' WHERE `display` = " << mysqlpp::quote << na->nc->display;
- ExecuteQuery(query);
- }
-
- void OnAccessAdd(ChannelInfo *ci, User *u, NickAlias *na, int level)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" << level << ", " << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << ci->name << ", " << time(NULL) << ", " << mysqlpp::quote << u->nick << ")";
- ExecuteQuery(query);
- }
-
- void OnAccessDel(ChannelInfo *ci, User *u, NickCore *nc)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_cs_access` WHERE `display` = " << mysqlpp::quote << nc->display << " AND `channel` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
-
- void OnAccessChange(ChannelInfo *ci, User *u, NickAlias *na, int level)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" << level << ", " << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << ci->name << ", " << time(NULL) << ", " << mysqlpp::quote << u->nick << ") ON DUPLICATE KEY UPDATE level=VALUES(level), display=VALUES(display), channel=VALUES(channel), last_seen=VALUES(last_seen), creator=VALUES(creator)";
- ExecuteQuery(query);
- }
-
- void OnAccessClear(ChannelInfo *ci, User *u)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_cs_access` WHERE `channel` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
-
- void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what)
- {
- mysqlpp::Query query(me->Con);
-
- if (pos >= 0)
- {
- query << "UPDATE `anope_cs_levels` SET `level` = " << what << " WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `position` = " << pos;
- ExecuteQuery(query);
- }
- else
- for (int i = 0; i < CA_SIZE; ++i)
- {
- query << "UPDATE `anope_cs_levels` SET `level` = " << ci->levels[i] << " WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `position` = " << i;
- ExecuteQuery(query);
- }
- }
-
- void OnChanForbidden(ChannelInfo *ci)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_cs_info` (name, time_registered, last_used, flags, forbidby, forbidreason) VALUES (";
- query << mysqlpp::quote << ci->name << ", " << ci->time_registered << ", " << ci->last_used << ", '" << BuildFlagsList(ci) << "', " << mysqlpp::quote << ci->forbidby << ", " << mysqlpp::quote << ci->forbidreason << ")";
- ExecuteQuery(query);
- }
-
- void OnDelChan(ChannelInfo *ci)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_cs_access` WHERE `channel` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_cs_akick` WHERE `channel` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_cs_info` WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_cs_levels` WHERE `channel` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "DELETE From `anope_cs_ttb` WHERE `channel` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "DELETE FROM `anope_bs_badwords` WHERE `channel` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
-
- void OnChanRegistered(ChannelInfo *ci)
- {
- mysqlpp::Query query(me->Con);
- std::string flags = BuildFlagsList(ci), mlockon = GetMLockOn(ci), mlockoff = GetMLockOff(ci), mlockparams = GetMLockParams(ci);
- query << "INSERT DELAYED INTO `anope_cs_info` (name, founder, successor, descr, url, email, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, mlock_on, mlock_off, mlock_params, entry_message, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES(";
- query << mysqlpp::quote << ci->name << ", " << mysqlpp::quote << (ci->founder ? ci->founder->display : "") << ", ";
- query << mysqlpp::quote << (ci->successor ? ci->successor->display : "") << ", " << mysqlpp::quote << ci->desc << ", ";
- query << mysqlpp::quote << (ci->url ? ci->url : "") << ", " << mysqlpp::quote << (ci->email ? ci->email : "") << ", ";
- query << ci->time_registered << ", " << ci->last_used << ", " << mysqlpp::quote << (ci->last_topic ? ci->last_topic : "");
- query << ", " << mysqlpp::quote << (!ci->last_topic_setter.empty() ? ci->last_topic_setter : "");
- query << ", " << ci->last_topic_time << ", '" << (!flags.empty() ? flags : "") << "', ";
- query << mysqlpp::quote << (ci->forbidby ? ci->forbidby : "") << ", " << mysqlpp::quote << (ci->forbidreason ? ci->forbidreason : "") << ", " << ci->bantype << ", '";
- query << mlockon << "', '" << mlockoff << "', '";
- query << mlockparams << "', " << mysqlpp::quote << (ci->entry_message ? ci->entry_message : "") << ", ";
- query << ci->memos.memomax << ", " << mysqlpp::quote << (ci->bi ? ci->bi->nick : "") << ", '" << GetBotFlags(ci->botflags);
- query << "', " << ci->capsmin << ", " << ci->capspercent << ", " << ci->floodlines;
- query << ", " << ci->floodsecs << ", " << ci->repeattimes << ") ";
- query << "ON DUPLICATE KEY UPDATE founder=VALUES(founder), successor=VALUES(successor), descr=VALUES(descr), url=VALUES(url), email=VALUES(email), time_registered=VALUES(time_registered), last_used=VALUES(last_used), last_topic=VALUES(last_topic), last_topic_setter=VALUES(last_topic_setter), last_topic_time=VALUES(last_topic_time), flags=VALUES(flags), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), bantype=VALUES(bantype), mlock_on=VALUES(mlock_on), mlock_off=VALUES(mlock_off), mlock_params=VALUES(mlock_params), entry_message=VALUES(entry_message), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(repeattimes)";
- ExecuteQuery(query);
- }
-
- void OnChanSuspend(ChannelInfo *ci)
- {
- mysqlpp::Query query(me->Con);
- query << "UPDATE `anope_cs_info` SET `flags` = '" << BuildFlagsList(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_info` SET `forbidby` = " << mysqlpp::quote << ci->forbidby << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_info` SET `forbidreason` = " << mysqlpp::quote << ci->forbidreason << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
-
- void OnAkickAdd(ChannelInfo *ci, AutoKick *ak)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_cs_akick` (channel, flags, mask, reason, creator, created, last_used) VALUES(";
- query << mysqlpp::quote << ci->name << ", '";
- if (ak->HasFlag(AK_ISNICK))
- query << "ISNICK ";
- if (ak->HasFlag(AK_STUCK))
- query << "STUCK ";
- query << "', " << mysqlpp::quote << (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask) << ", ";
- query << mysqlpp::quote << ak->reason << ", " << mysqlpp::quote << ak->creator << ", " << ak->addtime;
- query << ", " << ak->last_used << ")";
- ExecuteQuery(query);
- }
-
- void OnAkickDel(ChannelInfo *ci, AutoKick *ak)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_cs_akick` WHERE `channel`= " << mysqlpp::quote << ci->name << " AND `mask` = " << mysqlpp::quote << (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask);
- ExecuteQuery(query);
- }
-
- void OnBotCreate(BotInfo *bi)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES(";
- query << mysqlpp::quote << bi->nick << ", " << mysqlpp::quote << bi->user << ", " << mysqlpp::quote << bi->host << ", ";
- query << mysqlpp::quote << bi->real << ", '" << GetBotServFlags(bi) << "', " << bi->created << ", " << bi->chancount << ") ";
- query << "ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(chancount)";
- ExecuteQuery(query);
- }
-
- void OnBotChange(BotInfo *bi)
- {
- OnBotCreate(bi);
- }
-
- void OnBotDelete(BotInfo *bi)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_bs_core` WHERE `nick` = " << mysqlpp::quote << bi->nick;
- ExecuteQuery(query);
- query << "UPDATE `anope_cs_info` SET `botnick` = '' WHERE `botnick` = " << mysqlpp::quote << bi->nick;
- ExecuteQuery(query);
- }
-
- EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi)
- {
- mysqlpp::Query query(me->Con);
- query << "UPDATE `anope_cs_info` SET `botnick` = " << mysqlpp::quote << bi->nick << " WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- return EVENT_CONTINUE;
- }
-
- EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci)
- {
- mysqlpp::Query query(me->Con);
- query << "UPDATE `anope_cs_info` SET `botnick` = '' WHERE `name` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- return EVENT_CONTINUE;
- }
-
- void OnBadWordAdd(ChannelInfo *ci, BadWord *bw)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_bs_badwords` (channel, word, type) VALUES(" << mysqlpp::quote << ci->name << ", " << mysqlpp::quote << bw->word << ", '";
- switch (bw->type)
- {
- case BW_SINGLE:
- query << "SINGLE";
- break;
- case BW_START:
- query << "START";
- break;
- case BW_END:
- query << "END";
- break;
- default:
- query << "ANY";
- }
- query << "') ON DUPLICATE KEY UPDATE channel=VALUES(channel), word=VALUES(word), type=VALUES(type)";
- ExecuteQuery(query);
- }
-
- void OnBadWordDel(ChannelInfo *ci, BadWord *bw)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_bs_badwords` WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `word` = " << mysqlpp::quote << bw->word << " AND `type` = '";
- switch (bw->type)
- {
- case BW_SINGLE:
- query << "SINGLE";
- break;
- case BW_START:
- query << "START";
- break;
- case BW_END:
- query << "END";
- break;
- default:
- query << "ANY";
- }
- query << "'";
- ExecuteQuery(query);
- }
-
- void OnMemoSend(User *, NickCore *nc, Memo *m)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES(";
- query << mysqlpp::quote << nc->display << ", " << m->number << ", '" << BuildFlagsList(m) << "', " << m->time << ", ";
- query << mysqlpp::quote << m->sender << ", " << mysqlpp::quote << m->text << ", 'NICK')";
- ExecuteQuery(query);
- }
-
- void OnMemoSend(User *, ChannelInfo *ci, Memo *m)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES(";
- query << mysqlpp::quote << ci->name << ", " << m->number << ", '" << BuildFlagsList(m) << "', " << m->time << ", ";
- query << mysqlpp::quote << m->sender << ", " << mysqlpp::quote << m->text << ", 'CHAN')";
- ExecuteQuery(query);
- }
-
- void OnMemoDel(NickCore *nc, MemoInfo *mi, int number)
- {
- mysqlpp::Query query(me->Con);
- if (number)
- query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display << " AND `number` = " << number;
- else
- query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display;
- ExecuteQuery(query);
- }
-
- void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, int number)
- {
- mysqlpp::Query query(me->Con);
- if (number)
- query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << ci->name << " AND `number` = " << number;
- else
- query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << ci->name;
- ExecuteQuery(query);
- }
-
- EventReturn OnAddAkill(User *, XLine *ak)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_os_akills` (user, host, xby, reason, seton, expire) VALUES(";
- query << mysqlpp::quote << ak->GetUser().c_str() << ", " << mysqlpp::quote << ak->GetHost().c_str() << ", " << mysqlpp::quote << ak->By.c_str();
- query << ", " << mysqlpp::quote << ak->Reason << ", " << ak->Created << ", " << ak->Expires << ")";
- ExecuteQuery(query);
- return EVENT_CONTINUE;
- }
-
- void OnDelAkill(User *, XLine *ak)
- {
- mysqlpp::Query query(me->Con);
- if (ak)
- query << "DELETE FROM `anope_os_akills` WHERE `host` = " << mysqlpp::quote << ak->GetHost().c_str();
- else
- query << "TRUNCATE TABLE `anope_os_akills`";
- ExecuteQuery(query);
- }
-
- EventReturn OnExceptionAdd(User *, Exception *ex)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_os_exceptions` (mask, slimit, who, reason, time, expires) VALUES(";
- query << mysqlpp::quote << ex->mask << ", " << ex->limit << ", " << mysqlpp::quote << ex->who << ", ";
- query << mysqlpp::quote << ex->reason << ", " << ex->time << ", " << ex->expires << ")";
- ExecuteQuery(query);
- return EVENT_CONTINUE;
- }
-
- void OnExceptionDel(User *, Exception *ex)
- {
- mysqlpp::Query query(me->Con);
- query << "DELETE FROM `anope_os_exceptions` WHERE `mask` = " << mysqlpp::quote << ex->mask;
- ExecuteQuery(query);
- }
-
- EventReturn OnAddXLine(User *, XLine *x, XLineType Type)
- {
- mysqlpp::Query query(me->Con);
- query << "INSERT DELAYED INTO `anope_os_sxlines` (type, mask, xby, reason, seton, expire) VALUES('";
- query << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "', ";
- query << mysqlpp::quote << x->Mask.c_str() << ", " << mysqlpp::quote << x->By.c_str() << ", " << mysqlpp::quote << x->Reason;
- query << ", " << x->Created << ", " << x->Expires << ")";
- ExecuteQuery(query);
- return EVENT_CONTINUE;
- }
-
- void OnDelXLine(User *, XLine *x, XLineType Type)
- {
- mysqlpp::Query query(me->Con);
- if (x)
- {
- query << "DELETE FROM `anope_os_xlines` WHERE `mask` = " << mysqlpp::quote << x->Mask.c_str() << " AND `type` = '";
- query << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "'";
- }
- else
- query << "DELETE FROM `anope_os_xlines` WHERE `type` = '" << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "'";
- ExecuteQuery(query);
- }
-};
-
-MODULE_INIT(DBMySQLWrite)
diff --git a/modules/extra/sql.h b/modules/extra/sql.h
new file mode 100644
index 000000000..c659f33cc
--- /dev/null
+++ b/modules/extra/sql.h
@@ -0,0 +1,82 @@
+
+/** A SQL exception, can be thrown at various points
+ */
+class SQLException : public ModuleException
+{
+ public:
+ SQLException(const Anope::string &reason) : ModuleException(reason) { }
+
+ virtual ~SQLException() throw() { }
+};
+
+/** A result from a SQL query
+ */
+class SQLResult
+{
+ protected:
+ /* Rows, column, item */
+ std::vector<std::map<Anope::string, Anope::string> > entries;
+ Anope::string query;
+ Anope::string error;
+ public:
+ SQLResult(const Anope::string &q, const Anope::string &err = "") : query(q), error(err) { }
+
+ inline operator bool() const { return this->error.empty(); }
+
+ inline const Anope::string &GetQuery() const { return this->query; }
+ inline const Anope::string &GetError() const { return this->error; }
+
+ int Rows() const { return this->entries.size(); }
+
+ const std::map<Anope::string, Anope::string> &Row(size_t index) const
+ {
+ try
+ {
+ return this->entries.at(index);
+ }
+ catch (const std::out_of_range &)
+ {
+ throw SQLException("Out of bounds access to SQLResult");
+ }
+ }
+
+ const Anope::string Get(size_t index, const Anope::string &col) const
+ {
+ const std::map<Anope::string, Anope::string> rows = this->Row(index);
+
+ std::map<Anope::string, Anope::string>::const_iterator it = rows.find(col);
+ if (it == rows.end())
+ throw SQLException("Unknown column name in SQLResult: " + col);
+
+ return it->second;
+ }
+};
+
+/* An interface used by modules to retrieve the results
+ */
+class SQLInterface
+{
+ public:
+ Module *owner;
+
+ SQLInterface(Module *m) : owner(m) { }
+
+ virtual void OnResult(const SQLResult &r) { }
+
+ virtual void OnError(const SQLResult &r) { }
+};
+
+/** Class providing the SQL service, modules call this to execute queries
+ */
+class SQLProvider : public Service
+{
+ public:
+ SQLProvider(Module *c, const Anope::string &n) : Service(c, n) { }
+
+ virtual void Run(SQLInterface *i, const Anope::string &query) = 0;
+
+ virtual SQLResult RunQuery(const Anope::string &query) = 0;
+
+ virtual const Anope::string Escape(const Anope::string &buf) { return buf; }
+};
+
diff --git a/modules/socketengines/m_socketengine_epoll.cpp b/modules/socketengines/m_socketengine_epoll.cpp
index 5f8569a75..05978caf0 100644
--- a/modules/socketengines/m_socketengine_epoll.cpp
+++ b/modules/socketengines/m_socketengine_epoll.cpp
@@ -121,6 +121,8 @@ class SocketEngineEPoll : public SocketEngineBase
epoll_event *ev = &events[i];
Socket *s = Sockets[ev->data.fd];
+ if (s->HasFlag(SF_DEAD))
+ continue;
if (ev->events & (EPOLLHUP | EPOLLERR))
{
s->ProcessError();
@@ -135,10 +137,10 @@ class SocketEngineEPoll : public SocketEngineBase
s->SetFlag(SF_DEAD);
}
- for (std::map<int, Socket *>::iterator it = Sockets.begin(), it_end = Sockets.end(); it != it_end; )
+ for (int i = 0; i < total; ++i)
{
- Socket *s = it->second;
- ++it;
+ epoll_event *ev = &events[i];
+ Socket *s = Sockets[ev->data.fd];
if (s->HasFlag(SF_DEAD))
delete s;
diff --git a/modules/socketengines/m_socketengine_select.cpp b/modules/socketengines/m_socketengine_select.cpp
index e713915a3..ae82345f6 100644
--- a/modules/socketengines/m_socketengine_select.cpp
+++ b/modules/socketengines/m_socketengine_select.cpp
@@ -73,6 +73,8 @@ class SocketEngineSelect : public SocketEngineBase
{
Socket *s = it->second;
+ if (s->HasFlag(SF_DEAD))
+ continue;
if (FD_ISSET(s->GetSock(), &efdset))
{
s->ProcessError();
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4853591b7..2255b317c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,17 +2,21 @@
file(GLOB SRC_SRCS_CPP RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
set(SRC_SRCS ${SRC_SRCS_C} ${SRC_SRCS_CPP})
-# If using Windows, include windows.cpp, as it's Windows-specific
+# If using Windows, add the windows.cpp, the win32 threading engine, and the socket engine to the list
if(WIN32)
append_to_list(SRC_SRCS win32/windows.cpp)
-endif(WIN32)
-
-# If using Windows, add the win32 threading engine to the list
-if(WIN32)
append_to_list(SRC_SRCS threadengines/threadengine_win32.cpp)
+ append_to_list(SRC_SRCS socketengines/socketengine_win32.cpp)
# If not using Windows, add the pthread threading engine to the list
else(WIN32)
append_to_list(SRC_SRCS threadengines/threadengine_pthread.cpp)
+ # If we have eventfd, use it
+ if(HAVE_EVENTFD)
+ append_to_list(SRC_SRCS socketengines/socketengine_eventfd.cpp)
+ # Else fall back to pipe
+ else(HAVE_EVENTFD)
+ append_to_list(SRC_sRCS socketengines/socketengine_pipe.cpp)
+ endif(HAVE_EVENTFD)
endif(WIN32)
sort_list(SRC_SRCS)
diff --git a/src/bin/mydbgen b/src/bin/mydbgen
index 69e1b8812..f5663ab61 100755
--- a/src/bin/mydbgen
+++ b/src/bin/mydbgen
@@ -5,7 +5,7 @@
DBSQL="tables.sql"
# Schema Version
-SVER="1"
+SVER="2"
# Local Version, defaults to 0
LVER="0"
@@ -132,6 +132,9 @@ rm -f $TFILE
if test "x$FAILED" = "x" ; then
# Try to find out more about this installation
SQLPORT="$(mysql_config --port 2> /dev/null)"
+ if test "$SQLPORT" = "0" ; then
+ SQLPORT=3306
+ fi
echo ""
echo "Your MySQL setup is complete and your Anope schema is up to date. Make"
echo "sure you configure MySQL on your services.conf file prior to launching"
diff --git a/src/module.cpp b/src/module.cpp
index aa46a6f63..9431137b7 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -92,3 +92,14 @@ unsigned Version::GetBuild() const
{
return this->Build;
}
+
+Service::Service(Module *o, const Anope::string &n) : owner(o), name(n)
+{
+ ModuleManager::RegisterService(this);
+}
+
+Service::~Service()
+{
+ ModuleManager::UnregisterService(this);
+}
+
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 11424b78b..8ab72eef5 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -11,6 +11,7 @@
#include "version.h"
#include <algorithm> // std::find
+std::map<Anope::string, Service *> ModuleManager::ServiceProviders;
std::vector<Module *> ModuleManager::EventHandlers[I_END];
void ModuleManager::LoadModuleList(std::list<Anope::string> &ModuleList)
@@ -430,3 +431,36 @@ void ModuleManager::UnloadAll(bool unload_proto)
DeleteModule(m);
}
}
+
+/** Register a service
+ * @oaram s The service
+ * @return true if it was successfully registeed, else false (service name colision)
+ */
+bool ModuleManager::RegisterService(Service *s)
+{
+ return ModuleManager::ServiceProviders.insert(std::make_pair(s->name, s)).second;
+}
+
+/** Unregister a service
+ * @param s The service
+ * @return true if it was unregistered successfully
+ */
+bool ModuleManager::UnregisterService(Service *s)
+{
+ return ModuleManager::ServiceProviders.erase(s->name);
+}
+
+/** Get a service
+ * @param name The service name
+ * @param s The service
+ * @return The service
+ */
+Service *ModuleManager::GetService(const Anope::string &name)
+{
+ std::map<Anope::string, Service *>::const_iterator it = ModuleManager::ServiceProviders.find(name);
+
+ if (it != ModuleManager::ServiceProviders.end())
+ return it->second;
+ return NULL;
+}
+
diff --git a/src/modules.cpp b/src/modules.cpp
index 5cd9b6b69..c90410896 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -381,3 +381,19 @@ Version Module::GetVersion() const
{
return Version(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
}
+
+std::list<dynamic_reference_base *> dyn_references;
+
+dynamic_reference_base::dynamic_reference_base()
+{
+ dyn_references.push_back(this);
+}
+
+dynamic_reference_base::~dynamic_reference_base()
+{
+ std::list<dynamic_reference_base *>::iterator it = std::find(dyn_references.begin(), dyn_references.end(), this);
+
+ if (it != dyn_references.end())
+ dyn_references.erase(it);
+}
+
diff --git a/src/socketengines/socketengine_eventfd.cpp b/src/socketengines/socketengine_eventfd.cpp
new file mode 100644
index 000000000..767a6eddb
--- /dev/null
+++ b/src/socketengines/socketengine_eventfd.cpp
@@ -0,0 +1,47 @@
+#include "services.h"
+#include <sys/eventfd.h>
+
+int Pipe::RecvInternal(char *buf, size_t sz) const
+{
+ static eventfd_t dummy;
+ return !eventfd_read(this->Sock, &dummy);
+}
+
+int Pipe::SendInternal(const Anope::string &) const
+{
+ return !eventfd_write(this->Sock, 1);
+}
+
+Pipe::Pipe() : Socket()
+{
+ this->Sock = eventfd(0, EFD_NONBLOCK);
+ if (this->Sock < 0)
+ throw CoreException(Anope::string("Could not create pipe: ") + strerror(errno));
+
+ this->IPv6 = false;
+ this->Type = SOCKTYPE_CLIENT;
+
+ SocketEngine->AddSocket(this);
+}
+
+bool Pipe::ProcessRead()
+{
+ this->RecvInternal(NULL, 0);
+ return this->Read("");
+}
+
+bool Pipe::Read(const Anope::string &)
+{
+ this->OnNotify();
+ return true;
+}
+
+void Pipe::Notify()
+{
+ this->Write("*");
+}
+
+void Pipe::OnNotify()
+{
+}
+
diff --git a/src/socketengines/socketengine_pipe.cpp b/src/socketengines/socketengine_pipe.cpp
new file mode 100644
index 000000000..ee1069d57
--- /dev/null
+++ b/src/socketengines/socketengine_pipe.cpp
@@ -0,0 +1,50 @@
+#include "services.h"
+
+int Pipe::RecvInternal(char *buf, size_t sz) const
+{
+ static char dummy[512];
+ while (read(this->Sock, &dummy, 512) == 512);
+ return 0;
+}
+
+int Pipe::SendInternal(const Anope::string &) const
+{
+ static const char dummy = '*';
+ return write(this->WritePipe, &dummy, 1);
+}
+
+Pipe::Pipe() : Socket()
+{
+ int fds[2];
+ if (pipe2(fds, O_NONBLOCK))
+ throw CoreException(Anope::string("Could not create pipe: ") + strerror(errno));
+
+ this->Sock = fds[0];
+ this->WritePipe = fds[1];
+ this->IPv6 = false;
+ this->Type = SOCKTYPE_CLIENT;
+
+ SocketEngine->AddSocket(this);
+}
+
+bool Pipe::ProcessRead()
+{
+ this->RecvInternal(NULL, 0);
+ return this->Read("");
+}
+
+bool Pipe::Read(const Anope::string &)
+{
+ this->OnNotify();
+ return true;
+}
+
+void Pipe::Notify()
+{
+ this->SendInternal("");
+}
+
+void Pipe::OnNotify()
+{
+}
+
diff --git a/src/socketengines/socketengine_win32.cpp b/src/socketengines/socketengine_win32.cpp
new file mode 100644
index 000000000..1b1a4e50d
--- /dev/null
+++ b/src/socketengines/socketengine_win32.cpp
@@ -0,0 +1,76 @@
+#include "services.h"
+
+static Socket *newsocket = NULL;
+
+class LSocket : public ListenSocket
+{
+ public:
+ LSocket(const Anope::string &host, int port) : ListenSocket(host, port) { }
+
+ bool OnAccept(Socket *s)
+ {
+ newsocket = s;
+ return true;
+ }
+};
+
+int Pipe::RecvInternal(char *buf, size_t sz) const
+{
+ static char dummy[512];
+ return read(this->Sock, &dummy, 512);
+}
+
+int Pipe::SendInternal(const Anope::string &) const
+{
+ static const char dummy = '*';
+ return write(this->WritePipe, &dummy, 1);
+}
+
+Pipe::Pipe() : Socket()
+{
+ LSocket lfs("127.0.0.1", 0);
+
+ int cfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (cfd == -1)
+ throw CoreException("Error accepting new socket for Pipe");
+
+ sockaddr_in addr;
+ socklen_t sz = sizeof(addr);
+ getsockname(lfs.GetSock(), reinterpret_cast<sockaddr *>(&addr), &sz);
+
+ if (connect(cfd, reinterpret_cast<sockaddr *>(&addr), sz))
+ throw CoreException("Error accepting new socket for Pipe");
+ lfs.ProcessRead();
+ if (!newsocket)
+ throw CoreException("Error accepting new socket for Pipe");
+
+ this->Sock = cfd;
+ this->WritePipe = newsocket->GetSock();
+ this->IPv6 = false;
+ this->Type = SOCKTYPE_CLIENT;
+
+ SocketEngine->AddSocket(this);
+ newsocket = NULL;
+}
+
+bool Pipe::ProcessRead()
+{
+ this->RecvInternal(NULL, 0);
+ return this->Read("");
+}
+
+bool Pipe::Read(const Anope::string &)
+{
+ this->OnNotify();
+ return true;
+}
+
+void Pipe::Notify()
+{
+ this->SendInternal("");
+}
+
+void Pipe::OnNotify()
+{
+}
+
diff --git a/src/sockets.cpp b/src/sockets.cpp
index b85255523..646ee261f 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -25,11 +25,18 @@ SocketEngineBase::SocketEngineBase()
SocketEngineBase::~SocketEngineBase()
{
+ for (std::map<int, Socket *>::const_iterator it = this->Sockets.begin(), it_end = this->Sockets.end(); it != it_end; ++it)
+ delete it->second;
+ this->Sockets.clear();
#ifdef _WIN32
WSACleanup();
#endif
}
+Socket::Socket()
+{
+}
+
/** Constructor
* @param nsock The socket
* @param nIPv6 IPv6?