]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Merge insp20
authorattilamolnar <attilamolnar@hush.com>
Wed, 5 Jun 2013 23:07:22 +0000 (01:07 +0200)
committerattilamolnar <attilamolnar@hush.com>
Wed, 5 Jun 2013 23:07:22 +0000 (01:07 +0200)
389 files changed:
.gitignore
configure
docs/conf/helpop-full.conf.example
docs/conf/helpop.conf.example
docs/conf/inspircd.conf.example
docs/conf/modules.conf.example
docs/conf/modules/unrealircd.conf.example
docs/conf/opers.conf.example
include/bancache.h
include/base.h
include/builtinmodes.h [new file with mode: 0644]
include/caller.h
include/channels.h
include/command_parse.h
include/commands/cmd_whowas.h
include/compat.h [new file with mode: 0644]
include/configparser.h
include/configreader.h
include/consolecolors.h
include/ctables.h
include/cull_list.h
include/dns.h [deleted file]
include/dynamic.h
include/exitcodes.h
include/extensible.h
include/filelogger.h
include/hash_map.h [deleted file]
include/hashcomp.h
include/inspircd.h
include/inspsocket.h
include/inspstring.h
include/listmode.h [new file with mode: 0644]
include/logger.h
include/membership.h
include/mode.h
include/modes/cmode_b.h [deleted file]
include/modes/cmode_k.h [deleted file]
include/modes/cmode_l.h [deleted file]
include/modes/cmode_o.h [deleted file]
include/modes/cmode_v.h [deleted file]
include/modes/simplemodes.h [deleted file]
include/modes/umode_o.h [deleted file]
include/modes/umode_s.h [deleted file]
include/modules.h
include/modules/account.h [new file with mode: 0644]
include/modules/cap.h [new file with mode: 0644]
include/modules/dns.h [new file with mode: 0644]
include/modules/hash.h [new file with mode: 0644]
include/modules/httpd.h [new file with mode: 0644]
include/modules/regex.h [new file with mode: 0644]
include/modules/sasl.h [new file with mode: 0644]
include/modules/spanningtree.h [new file with mode: 0644]
include/modules/sql.h [new file with mode: 0644]
include/modules/ssl.h [new file with mode: 0644]
include/numerics.h
include/protocol.h
include/snomasks.h
include/socket.h
include/socketengine.h
include/testsuite.h
include/threadengine.h
include/threadengines/threadengine_pthread.h
include/threadengines/threadengine_win32.h
include/timer.h
include/typedefs.h
include/uid.h
include/usermanager.h
include/users.h
include/xline.h
make/calcdep.pl
make/check_epoll.cpp [deleted file]
make/check_eventfd.cpp [deleted file]
make/configure.pm
make/gnutlscert.pm [deleted file]
make/opensslcert.pm [deleted file]
make/template/main.mk
make/test/clock_gettime.cpp [new file with mode: 0644]
make/test/eventfd.cpp [new file with mode: 0644]
make/test/kqueue.cpp [new file with mode: 0644]
make/test/so_acceptfilter.cpp [new file with mode: 0644]
make/test/tcp_defer_accept.cpp [new file with mode: 0644]
src/bancache.cpp
src/base.cpp
src/channels.cpp
src/command_parse.cpp
src/commands.cpp
src/commands/cmd_clearcache.cpp [deleted file]
src/commands/cmd_die.cpp
src/commands/cmd_dns.cpp [new file with mode: 0644]
src/commands/cmd_eline.cpp
src/commands/cmd_gline.cpp
src/commands/cmd_hostname_lookup.cpp [new file with mode: 0644]
src/commands/cmd_invite.cpp
src/commands/cmd_join.cpp
src/commands/cmd_kick.cpp
src/commands/cmd_kill.cpp
src/commands/cmd_kline.cpp
src/commands/cmd_lusers.cpp
src/commands/cmd_map.cpp
src/commands/cmd_nick.cpp
src/commands/cmd_notice.cpp
src/commands/cmd_oper.cpp
src/commands/cmd_privmsg.cpp
src/commands/cmd_qline.cpp
src/commands/cmd_rehash.cpp
src/commands/cmd_restart.cpp
src/commands/cmd_stats.cpp
src/commands/cmd_time.cpp
src/commands/cmd_unloadmodule.cpp
src/commands/cmd_userhost.cpp
src/commands/cmd_version.cpp
src/commands/cmd_wallops.cpp
src/commands/cmd_who.cpp
src/commands/cmd_whois.cpp
src/commands/cmd_whowas.cpp
src/commands/cmd_zline.cpp
src/configparser.cpp
src/configreader.cpp
src/cull_list.cpp
src/dns.cpp [deleted file]
src/filelogger.cpp
src/hashcomp.cpp
src/helperfuncs.cpp
src/inspircd.cpp
src/inspsocket.cpp
src/inspstring.cpp
src/listensocket.cpp
src/listmode.cpp [new file with mode: 0644]
src/logger.cpp
src/mode.cpp
src/modes/cmode_b.cpp [deleted file]
src/modes/cmode_k.cpp
src/modes/cmode_l.cpp
src/modes/cmode_o.cpp
src/modes/cmode_v.cpp
src/modes/umode_o.cpp
src/modes/umode_s.cpp
src/modmanager_dynamic.cpp
src/modmanager_static.cpp
src/modules.cpp
src/modules/account.h [deleted file]
src/modules/extra/m_geoip.cpp
src/modules/extra/m_ldapauth.cpp
src/modules/extra/m_ldapoper.cpp
src/modules/extra/m_mssql.cpp
src/modules/extra/m_mysql.cpp
src/modules/extra/m_pgsql.cpp
src/modules/extra/m_regex_pcre.cpp
src/modules/extra/m_regex_posix.cpp
src/modules/extra/m_regex_stdlib.cpp
src/modules/extra/m_regex_tre.cpp
src/modules/extra/m_sqlite3.cpp
src/modules/extra/m_ssl_gnutls.cpp
src/modules/extra/m_ssl_openssl.cpp
src/modules/hash.h [deleted file]
src/modules/httpd.h [deleted file]
src/modules/m_abbreviation.cpp
src/modules/m_alias.cpp
src/modules/m_allowinvite.cpp
src/modules/m_alltime.cpp
src/modules/m_auditorium.cpp
src/modules/m_autoop.cpp
src/modules/m_banexception.cpp
src/modules/m_banredirect.cpp
src/modules/m_blockamsg.cpp
src/modules/m_blockcaps.cpp
src/modules/m_blockcolor.cpp
src/modules/m_botmode.cpp
src/modules/m_callerid.cpp
src/modules/m_cap.cpp
src/modules/m_cap.h [deleted file]
src/modules/m_cban.cpp
src/modules/m_censor.cpp
src/modules/m_cgiirc.cpp
src/modules/m_chancreate.cpp
src/modules/m_chanfilter.cpp
src/modules/m_chanhistory.cpp
src/modules/m_chanlog.cpp
src/modules/m_channames.cpp
src/modules/m_channelban.cpp
src/modules/m_chanprotect.cpp [deleted file]
src/modules/m_check.cpp
src/modules/m_chghost.cpp
src/modules/m_chgident.cpp
src/modules/m_chgname.cpp
src/modules/m_cloaking.cpp
src/modules/m_clones.cpp
src/modules/m_close.cpp
src/modules/m_commonchans.cpp
src/modules/m_conn_join.cpp
src/modules/m_conn_umodes.cpp
src/modules/m_conn_waitpong.cpp
src/modules/m_connectban.cpp
src/modules/m_connflood.cpp
src/modules/m_customprefix.cpp
src/modules/m_customtitle.cpp
src/modules/m_cycle.cpp
src/modules/m_dccallow.cpp
src/modules/m_deaf.cpp
src/modules/m_delayjoin.cpp
src/modules/m_delaymsg.cpp
src/modules/m_denychans.cpp
src/modules/m_devoice.cpp
src/modules/m_dnsbl.cpp
src/modules/m_exemptchanops.cpp
src/modules/m_filter.cpp
src/modules/m_gecosban.cpp
src/modules/m_globalload.cpp
src/modules/m_globops.cpp
src/modules/m_halfop.cpp [deleted file]
src/modules/m_helpop.cpp
src/modules/m_hidechans.cpp
src/modules/m_hideoper.cpp
src/modules/m_hostchange.cpp
src/modules/m_httpd.cpp
src/modules/m_httpd_acl.cpp
src/modules/m_httpd_config.cpp
src/modules/m_httpd_stats.cpp
src/modules/m_ident.cpp
src/modules/m_inviteexception.cpp
src/modules/m_ircv3.cpp
src/modules/m_joinflood.cpp
src/modules/m_jumpserver.cpp
src/modules/m_kicknorejoin.cpp
src/modules/m_knock.cpp
src/modules/m_lockserv.cpp
src/modules/m_maphide.cpp
src/modules/m_md5.cpp
src/modules/m_messageflood.cpp
src/modules/m_mlock.cpp
src/modules/m_muteban.cpp
src/modules/m_namedmodes.cpp
src/modules/m_namesx.cpp
src/modules/m_nationalchars.cpp
src/modules/m_nickflood.cpp
src/modules/m_nicklock.cpp
src/modules/m_noctcp.cpp
src/modules/m_nokicks.cpp
src/modules/m_nonicks.cpp
src/modules/m_nonotice.cpp
src/modules/m_nopartmsg.cpp
src/modules/m_ojoin.cpp
src/modules/m_operchans.cpp
src/modules/m_operjoin.cpp
src/modules/m_operlevels.cpp
src/modules/m_operlog.cpp
src/modules/m_opermodes.cpp
src/modules/m_opermotd.cpp
src/modules/m_operprefix.cpp
src/modules/m_override.cpp
src/modules/m_passforward.cpp
src/modules/m_password_hash.cpp
src/modules/m_permchannels.cpp
src/modules/m_randquote.cpp
src/modules/m_redirect.cpp
src/modules/m_regex.h [deleted file]
src/modules/m_regex_glob.cpp
src/modules/m_regonlycreate.cpp
src/modules/m_remove.cpp
src/modules/m_restrictchans.cpp
src/modules/m_restrictmsg.cpp
src/modules/m_ripemd160.cpp
src/modules/m_rline.cpp
src/modules/m_rmode.cpp [new file with mode: 0644]
src/modules/m_sajoin.cpp
src/modules/m_sakick.cpp
src/modules/m_samode.cpp
src/modules/m_sanick.cpp
src/modules/m_sapart.cpp
src/modules/m_saquit.cpp
src/modules/m_sasl.cpp
src/modules/m_satopic.cpp
src/modules/m_securelist.cpp
src/modules/m_seenicks.cpp
src/modules/m_serverban.cpp
src/modules/m_services_account.cpp
src/modules/m_servprotect.cpp
src/modules/m_sethost.cpp
src/modules/m_setident.cpp
src/modules/m_setidle.cpp
src/modules/m_setname.cpp
src/modules/m_sha256.cpp
src/modules/m_showwhois.cpp
src/modules/m_shun.cpp
src/modules/m_silence.cpp
src/modules/m_spanningtree/addline.cpp
src/modules/m_spanningtree/away.cpp
src/modules/m_spanningtree/cachetimer.cpp [deleted file]
src/modules/m_spanningtree/cachetimer.h
src/modules/m_spanningtree/capab.cpp
src/modules/m_spanningtree/commands.h
src/modules/m_spanningtree/compat.cpp
src/modules/m_spanningtree/encap.cpp
src/modules/m_spanningtree/fjoin.cpp
src/modules/m_spanningtree/fmode.cpp
src/modules/m_spanningtree/ftopic.cpp
src/modules/m_spanningtree/hmac.cpp
src/modules/m_spanningtree/idle.cpp
src/modules/m_spanningtree/ijoin.cpp [new file with mode: 0644]
src/modules/m_spanningtree/link.h
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_spanningtree/metadata.cpp
src/modules/m_spanningtree/netburst.cpp
src/modules/m_spanningtree/nickcollide.cpp
src/modules/m_spanningtree/operquit.cpp
src/modules/m_spanningtree/opertype.cpp
src/modules/m_spanningtree/override_map.cpp
src/modules/m_spanningtree/override_squit.cpp
src/modules/m_spanningtree/override_stats.cpp
src/modules/m_spanningtree/override_whois.cpp
src/modules/m_spanningtree/ping.cpp
src/modules/m_spanningtree/pong.cpp
src/modules/m_spanningtree/postcommand.cpp
src/modules/m_spanningtree/precommand.cpp
src/modules/m_spanningtree/protocolinterface.cpp
src/modules/m_spanningtree/protocolinterface.h
src/modules/m_spanningtree/push.cpp
src/modules/m_spanningtree/rconnect.cpp
src/modules/m_spanningtree/resolvers.cpp
src/modules/m_spanningtree/resolvers.h
src/modules/m_spanningtree/rsquit.cpp
src/modules/m_spanningtree/save.cpp
src/modules/m_spanningtree/server.cpp
src/modules/m_spanningtree/svsjoin.cpp
src/modules/m_spanningtree/svsnick.cpp
src/modules/m_spanningtree/svspart.cpp
src/modules/m_spanningtree/treeserver.cpp
src/modules/m_spanningtree/treeserver.h
src/modules/m_spanningtree/treesocket.h
src/modules/m_spanningtree/treesocket1.cpp
src/modules/m_spanningtree/treesocket2.cpp
src/modules/m_spanningtree/uid.cpp
src/modules/m_spanningtree/utils.cpp
src/modules/m_spanningtree/utils.h
src/modules/m_spanningtree/version.cpp
src/modules/m_sqlauth.cpp
src/modules/m_sqloper.cpp
src/modules/m_sslinfo.cpp
src/modules/m_sslmodes.cpp
src/modules/m_stripcolor.cpp
src/modules/m_svshold.cpp
src/modules/m_swhois.cpp
src/modules/m_testnet.cpp
src/modules/m_timedbans.cpp
src/modules/m_tline.cpp
src/modules/m_topiclock.cpp
src/modules/m_uhnames.cpp
src/modules/m_uninvite.cpp
src/modules/m_userip.cpp
src/modules/m_vhost.cpp
src/modules/m_watch.cpp
src/modules/m_xline_db.cpp
src/modules/sasl.h [deleted file]
src/modules/spanningtree.h [deleted file]
src/modules/sql.h [deleted file]
src/modules/ssl.h [deleted file]
src/modules/u_listmode.h [deleted file]
src/server.cpp
src/snomasks.cpp
src/socket.cpp
src/socketengine.cpp
src/socketengines/socketengine_epoll.cpp
src/socketengines/socketengine_kqueue.cpp
src/socketengines/socketengine_poll.cpp
src/socketengines/socketengine_ports.cpp
src/socketengines/socketengine_select.cpp
src/testsuite.cpp
src/timer.cpp
src/user_resolver.cpp [deleted file]
src/usermanager.cpp
src/userprocess.cpp
src/users.cpp
src/version.sh
src/whois.cpp [deleted file]
src/wildcard.cpp
src/xline.cpp
tools/create_templates.pl [deleted file]
tools/genssl [new file with mode: 0755]
win/.gitignore
win/CMakeLists.txt
win/config.h.cmake [new file with mode: 0644]
win/inspircd_config.h.cmake [deleted file]
win/inspircd_memory_functions.cpp
win/inspircd_version.h.cmake [deleted file]
win/inspircd_win32wrapper.cpp
win/inspircd_win32wrapper.h
win/win32service.cpp
win/win32service.h

index 3a5fef871f2a5cad3eb88952845a95ca4dffdd9a..4e53a077a57a0d90a1eb639bfde1d3715b2bee55 100644 (file)
@@ -11,8 +11,7 @@
 /run
 /bin
 
-/include/inspircd_config.h
-/include/inspircd_version.h
+/include/config.h
 
 /src/modules/m_geoip.cpp
 /src/modules/m_ldapauth.cpp
index f738a65a068602cbfff5fe9d3212e2a16cdd1096..ed301c988b684b49db0ba1a1c519090dd82d2b37 100755 (executable)
--- a/configure
+++ b/configure
@@ -40,15 +40,12 @@ BEGIN {
 };
 
 use File::Copy ();
-use Socket;
 use Cwd;
 use Getopt::Long;
 
 # Utility functions for our buildsystem
 use make::utilities;
 use make::configure;
-use make::gnutlscert;
-use make::opensslcert;
 
 ###############################################################################################
 #
@@ -56,10 +53,8 @@ use make::opensslcert;
 #
 ###############################################################################################
 
-our ($opt_use_gnutls, $opt_rebuild, $opt_use_openssl, $opt_nointeractive, $opt_ports,
-    $opt_epoll, $opt_kqueue, $opt_noports, $opt_noepoll, $opt_nokqueue,
-    $opt_noipv6, $opt_maxbuf, $opt_disable_debug, $opt_freebsd_port,
-       $opt_system, $opt_uid);
+our ($opt_use_gnutls, $opt_use_openssl, $opt_nointeractive, $opt_ports, $opt_epoll, $opt_kqueue,
+     $opt_noports, $opt_noepoll, $opt_nokqueue, $opt_maxbuf, $opt_freebsd_port, $opt_system, $opt_uid);
 
 our ($opt_cc, $opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir, $opt_data_dir, $opt_log_dir);
 
@@ -74,7 +69,6 @@ my @opt_disableextras;
 
 GetOptions (
        'enable-gnutls' => \$opt_use_gnutls,
-       'rebuild' => \$opt_rebuild,
        'system' => \$opt_system,
        'uid=s' => \$opt_uid,
        'enable-openssl' => \$opt_use_openssl,
@@ -85,7 +79,6 @@ GetOptions (
        'disable-ports' => \$opt_noports,
        'disable-epoll' => \$opt_noepoll,
        'disable-kqueue' => \$opt_nokqueue,
-       'disable-ipv6' => \$opt_noipv6,
        'with-cc=s' => \$opt_cc,
        'with-maxbuf=i' => \$opt_maxbuf,
        'enable-freebsd-ports-openssl' => \$opt_freebsd_port,
@@ -95,15 +88,12 @@ GetOptions (
        'binary-dir=s' => \$opt_binary_dir,
        'data-dir=s' => \$opt_data_dir,
        'log-dir=s' => \$opt_log_dir,
-       'disable-debuginfo' => sub { $opt_disable_debug = 1 },
        'help'  => sub { showhelp(); },
        'update' => sub { update(); },
        'clean' => sub { clean(); },
        'list-extras' => sub { list_extras; exit 0; }, # This, --enable-extras, and --disable-extras are for non-interactive managing.
        'enable-extras=s@' => \@opt_enableextras, # ^
        'disable-extras=s@' => \@opt_disableextras, # ^
-       'generate-openssl-cert' => sub { make_openssl_cert(); exit(0); },
-       'generate-gnutls-cert' => sub { make_gnutls_cert(); exit(0); }
 );
 
 if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
@@ -126,7 +116,6 @@ our $interactive = !(
        (defined $opt_log_dir) ||
        (defined $opt_nointeractive) ||
        (defined $opt_cc) ||
-       (defined $opt_noipv6) ||
        (defined $opt_kqueue) ||
        (defined $opt_epoll) ||
        (defined $opt_ports) ||
@@ -225,13 +214,6 @@ if (defined $opt_use_openssl)
        $config{USE_OPENSSL} = "y";
 }
 
-if (!defined $opt_disable_debug) {
-       $config{OPTIMISATI}      = "-g1";                               # Optimisation Flag
-} else {
-       $config{OPTIMISATI}      = "-O2";
-}
-
-$config{HAS_STRLCPY}   = "false";                                      # strlcpy Check.
 $config{HAS_STDINT}     = "false";                                     # stdint.h check
 $config{USE_KQUEUE}     = "y";                                         # kqueue enabled
 if (defined $opt_nokqueue) {
@@ -248,14 +230,11 @@ if (defined $opt_noports)
 {
        $config{USE_PORTS} = "n";
 }
-$config{_SOMAXCONN} = SOMAXCONN;                                       # Max connections in accept queue
 $config{OSNAME}            = $^O;                                      # Operating System Name
-$config{IS_DARWIN}       = "NO";                                       # Is OSX?
 $config{STARTSCRIPT}     = "inspircd";                 # start script?
 $config{DESTINATION}     = "BASE";                             # Is target path.
 if ($config{OSNAME} =~ /darwin/i)
 {
-       $config{IS_DARWIN} = "YES";
        $config{STARTSCRIPT}      = "org.inspircd.plist";               # start script for OSX.
        $config{CC}                 = "xcrun clang++";                                  # C++ compiler for OSX.
 }
@@ -280,7 +259,7 @@ if ($config{HAS_OPENSSL} =~ /^([-[:digit:].]+)(?:[a-z])?(?:\-[a-z][0-9])?/) {
 }
 
 if (($config{GCCVER} eq "") || ($config{GCCMINOR} eq "")) {
-       if ($config{IS_DARWIN} eq "YES") {
+       if ($config{OSNAME} eq 'darwin') {
                print $config{CC} . " was not found! You require clang++ (the LLVM C++ compiler, part of the OSX developer tools) to build InspIRCd!\n";
        } else {
                print $config{CC} . " was not found! You require g++ (the GNU C++ compiler, part of GCC) to build InspIRCd!\n";         
@@ -312,11 +291,6 @@ sub update
                } else {
                        # We've Loaded the cache file and all our variables..
                        print "Updating files...\n";
-                       if (defined($opt_disable_debug) && $opt_disable_debug == 1)
-                       {
-                               print "Disabling debug information (-g).\n";
-                               $config{OPTIMISATI} = "";
-                       }
                        $has_epoll = $config{HAS_EPOLL};
                        $has_ports = $config{HAS_PORTS};
                        $has_kqueue = $config{HAS_KQUEUE};
@@ -333,16 +307,6 @@ sub update
        exit;
 }
 
-
-sub test_compile {
-       my $feature = shift;
-       my $fail = 0;
-       $fail ||= system "$config{CC} -o test_$feature make/check_$feature.cpp >/dev/null 2>&1";
-       $fail ||= system "./test_$feature";
-       unlink "test_$feature";
-       return !$fail;
-}
-
 print "Running non-interactive configure...\n" unless $interactive;
 print "Checking for cache from previous configure... ";
 print ($cache_loaded ? "found\n" : "not found\n");
@@ -354,76 +318,57 @@ chomp($config{GCCVER}             = `$exec`);                             # Major GCC Version
 $exec = $config{CC} . " -dumpversion | cut -c 3";
 chomp($config{GCCMINOR}                = `$exec`);
 
-printf "Checking if stdint.h exists... ";
-$config{HAS_STDINT} = "true";
-our $fail = 0;
-open(STDINT, "</usr/include/stdint.h") or $config{HAS_STDINT} = "false";
-if ($config{HAS_STDINT} eq "true") {
-       close(STDINT);
+
+print "Checking whether <stdint.h> exists... ";
+if (test_header($config{CC}, "stdint.h")) {
+       $config{HAS_STDINT} = "true";
+       print "yes\n";
+} else {
+       $config{HAS_STDINT} = "false";
+       print "no\n";
 }
-print "yes\n" if $config{HAS_STDINT} eq "true";
-print "no\n" if $config{HAS_STDINT} eq "false";
-
-printf "Checking if strlcpy exists... ";
-# Perform the strlcpy() test..
-$config{HAS_STRLCPY} = "false";
-$fail = 0;
-open(STRLCPY, "</usr/include/string.h") or $fail = 1;
-if (!$fail) {
-       while (defined(my $line = <STRLCPY>)) {
-               chomp($line);
-               # try and find the delcaration of:
-               # size_t strlcpy(...)
-               if ($line =~ /size_t(\0x9|\s)+strlcpy/) {
-                       $config{HAS_STRLCPY} = "true";
-               }
-       }
-       close(STRLCPY);
+
+printf "Checking whether clock_gettime() exists... ";
+if (test_file($config{CC}, "clock_gettime.cpp", "-lrt")) {
+       $config{HAS_CLOCK_GETTIME} = "true";
+       print "yes\n";
+} else {
+       $config{HAS_CLOCK_GETTIME} = "false";
+       print "no\n";
 }
-print "yes\n" if $config{HAS_STRLCPY} eq "true";
-print "no\n" if $config{HAS_STRLCPY} eq "false";
-
-printf "Checking if kqueue exists... ";
-$has_kqueue = 0;
-$fail = 0;
-open(KQUEUE, "</usr/include/sys/event.h") or $fail = 1;
-if (!$fail) {
-       while (defined(my $line = <KQUEUE>)) {
-               chomp($line);
-               # try and find the delcaration of:
-               # int kqueue(void);
-               if ($line =~ /int(\0x9|\s)+kqueue/) {
-                       $has_kqueue = 1;
-               }
-       }
-       close(KQUEUE);
+
+printf "Checking whether eventfd() exists... ";
+if (test_file($config{CC}, "eventfd.cpp")) {
+       $config{HAS_EVENTFD} = "true";
+       print "yes\n";
+} else {
+       $config{HAS_EVENTFD} = "false";
+       print "no\n";
+}
+
+printf "Checking if a TCP deferring mechanism is available... ";
+if (test_file($config{CC}, "tcp_defer_accept.cpp")) {
+       $config{HAS_DEFER} = "TCP_DEFER_ACCEPT";
+       print "yes (TCP_DEFER_ACCEPT)\n";
+} elsif (test_file($config{CC}, "so_acceptfilter.cpp")) {
+       $config{HAS_DEFER} = "SO_ACCEPTFILTER";
+       print "yes (SO_ACCEPTFILTER)\n";
+} else {
+       $config{HAS_DEFER} = "false";
+       print "no\n";
 }
-print "yes\n" if $has_kqueue == 1;
-print "no\n" if $has_kqueue == 0;
 
-printf "Checking for epoll support... ";
-$has_epoll = test_compile('epoll');
+print "Checking whether epoll is available... ";
+$has_epoll = test_header($config{CC}, "sys/epoll.h");
 print $has_epoll ? "yes\n" : "no\n";
 
-printf "Checking for eventfd support... ";
-$config{HAS_EVENTFD} = test_compile('eventfd') ? 'true' : 'false';
-print $config{HAS_EVENTFD} eq 'true' ? "yes\n" : "no\n";
-
-printf "Checking if Solaris I/O completion ports are available... ";
-$has_ports = 0;
-our $system = `uname -s`;
-chomp ($system);
-$has_ports = 1 if ($system eq "SunOS");
-
-if ($has_ports) {
-       my $kernel = `uname -r`;
-       chomp($kernel);
-       if (($kernel !~ /^5\.1./)) {
-               $has_ports = 0;
-       }
-}
-print "yes\n" if $has_ports == 1;
-print "no\n" if $has_ports == 0;
+print "Checking whether Kqueue is available... ";
+$has_kqueue = test_file($config{CC}, "kqueue.cpp");
+print $has_kqueue ? "yes\n" : "no\n";
+
+print 'Checking whether Solaris IOCP is available... ';
+$has_ports = test_header($config{CC}, 'port.h');
+print $has_ports ? "yes\n" : "no\n";
 
 $config{HAS_EPOLL} = $has_epoll;
 $config{HAS_KQUEUE} = $has_kqueue;
@@ -528,8 +473,8 @@ should NOT be used. You should probably specify a newer compiler.\n\n";
                                chomp($config{GCCVER}       = `$config{CC} -dumpversion | cut -c 1`); # we must redo these if we change compilers
                                chomp($config{GCCMINOR}     = `$config{CC} -dumpversion | cut -c 3`);
                                print "Queried compiler: \e[1;32m$config{CC}\e[0m (version \e[1;32m$config{GCCVER}.$config{GCCMINOR}\e[0m)\n";
-                               if ($config{GCCVER} < 3) {
-                                       print "\e[1;32mGCC 2.x WILL NOT WORK!\e[0m. Let's try that again, shall we?\n";
+                               if ($config{GCCVER} < 4 || $config{GCCVER} == 4 && $config{GCCMINOR} < 1) {
+                                       print "\e[1;32mGCC 4.1 and earlier WILL NOT WORK!\e[0m. Let's try that again, shall we?\n";
                                }
                        }
                        else {
@@ -692,7 +637,7 @@ if ($config{USE_GNUTLS} eq "y") {
 * few times and get that HD going :) Then answer the        *
 * Questions which follow. If you are unsure, just hit enter *
 *************************************************************\n\n";
-                       $failed = make_gnutls_cert();
+                       $failed = system "./tools/genssl gnutls";
                        if ($failed) {
                                print "\n\e[1;32mCertificate generation failed!\e[0m\n\n";
                        } else {
@@ -726,7 +671,7 @@ if ($config{USE_OPENSSL} eq "y") {
 * Generating the certificates may take some time, go grab a *
 * coffee, or something.                                            *
 *************************************************************\n\n";
-                       make_openssl_cert();
+                       system "./tools/genssl openssl";
                        print "\nCertificate generation complete, copying to config directory... ";
                        File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
                        File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
@@ -863,7 +808,7 @@ my ($mliflags, $mfrules, $mobjs, $mfcount) = ("", "", "", 0);
 
 sub writefiles {
        my($writeheader) = @_;
-       # First File.. inspircd_config.h
+       # First File.. config.h
        chomp(my $incos = `uname -n -s -r`);
        chomp(my $version = `sh src/version.sh`);
        chomp(my $revision2 = getrevision());
@@ -874,23 +819,21 @@ sub writefiles {
        }
        if ($writeheader == 1)
        {
-               print "Writing \e[1;32minspircd_config.h\e[0m\n";
-               open(FILEHANDLE, ">include/inspircd_config.h.tmp");
+               print "Writing \e[1;32mconfig.h\e[0m\n";
+               open(FILEHANDLE, ">include/config.h.tmp");
                print FILEHANDLE <<EOF;
 /* Auto generated by configure, do not modify! */
-#ifndef __CONFIGURATION_AUTO__
-#define __CONFIGURATION_AUTO__
+#pragma once
 
-/* this is for windows support. */
-#define CoreExport /**/
-#define DllExport /**/
+#define BRANCH "$branch"
+#define VERSION "$version"
+#define REVISION "$revision2"
+#define SYSTEM "$incos"
 
 #define CONFIG_PATH "$config{CONFIG_DIR}"
 #define DATA_PATH "$config{DATA_DIR}"
 #define LOG_PATH "$config{LOG_DIR}"
 #define MOD_PATH "$config{MODULE_DIR}"
-#define SOMAXCONN_S "$config{_SOMAXCONN}"
-#define ENTRYPOINT int main(int argc, char** argv)
 
 EOF
 print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
@@ -904,16 +847,13 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
                if ($config{GCCVER} >= 3) {
                        print FILEHANDLE "#define GCC3\n";
                }
-               if ($config{HAS_STRLCPY} eq "true") {
-                       print FILEHANDLE "#define HAS_STRLCPY\n";
-               }
                if ($config{HAS_STDINT} eq "true") {
                        print FILEHANDLE "#define HAS_STDINT\n";
                }
                if ($config{HAS_EVENTFD} eq 'true') {
                        print FILEHANDLE "#define HAS_EVENTFD\n";
                }
-               if ($config{OSNAME} !~ /DARWIN/i) {
+               if ($config{HAS_CLOCK_GETTIME} eq 'true') {
                        print FILEHANDLE "#define HAS_CLOCK_GETTIME\n";
                }
                my $use_hiperf = 0;
@@ -947,40 +887,37 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
                                $config{SOCKETENGINE} = "socketengine_select";
                        }
                }
-               print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n\n#endif\n";
-               close(FILEHANDLE);
 
-               open(FILEHANDLE, ">include/inspircd_version.h.tmp");
-               print FILEHANDLE <<EOF;
-#define BRANCH "$branch"
-#define VERSION "$version"
-#define REVISION "$revision2"
-#define SYSTEM "$incos"
-EOF
-               close FILEHANDLE;
-
-               for my $file (qw(include/inspircd_config.h include/inspircd_version.h)) {
-                       my $diff = 0;
-                       open my $fh1, $file or $diff = 1;
-                       open my $fh2, $file.'.tmp' or die "Can't read $file.tmp that we just wrote: $!";
-                       while (!$diff) {
-                               my $line1 = <$fh1>;
-                               my $line2 = <$fh2>;
-                               if (defined($line1) != defined($line2)) {
-                                       $diff = 1;
-                               } elsif (!defined $line1) {
-                                       last;
-                               } else {
-                                       $diff = ($line1 ne $line2);
-                               }
-                       }
-                       if ($diff) {
-                               unlink $file;
-                               rename "$file.tmp", $file;
+               if ($config{HAS_DEFER} eq "TCP_DEFER_ACCEPT") {
+                       print FILEHANDLE "#define USE_TCP_DEFER_ACCEPT";
+               } elsif ($config{HAS_DEFER} eq "SO_ACCEPTFILTER") {
+                       print FILEHANDLE "#define USE_SO_ACCEPTFILTER"
+               }
+
+               print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n";
+               close(FILEHANDLE);
+               
+               my $file = 'include/config.h';
+               my $diff = 0;
+               open my $fh1, $file or $diff = 1;
+               open my $fh2, $file.'.tmp' or die "Can't read $file.tmp that we just wrote: $!";
+               while (!$diff) {
+                       my $line1 = <$fh1>;
+                       my $line2 = <$fh2>;
+                       if (defined($line1) != defined($line2)) {
+                               $diff = 1;
+                       } elsif (!defined $line1) {
+                               last;
                        } else {
-                               unlink "$file.tmp";
+                               $diff = ($line1 ne $line2);
                        }
                }
+               if ($diff) {
+                       unlink $file;
+                       rename "$file.tmp", $file;
+               } else {
+                       unlink "$file.tmp";
+               }
        }
 
        # Write all .in files.
index bc9326e62b03e2a61b31279d0ffbca3be2dda6e3..c972d04ddde8dd3d102fdf3047da19b328c155c3 100644 (file)
@@ -97,6 +97,11 @@ Removes a user from a channel you specify. You must be at least a
 channel halfoperator to remove a user. A removed user will part with
 a message stating they were removed from the channel and by whom.">
 
+<helpop key="rmode" value="/RMODE [channel] [modeletter] {[pattern]}
+
+Removes listmodes from a channel.
+E.g. /RMODE #Chan b m:* will remove all mute extbans.">
+
 <helpop key="fpart" value="/FPART [channel] [nick] {[reason]}
 
 This behaves identically to /REMOVE, the only difference is that that
@@ -804,15 +809,15 @@ Closes all unregistered connections to the local server.">
 
  v [nickname]       Gives voice to [nickname], allowing them to speak
                     while the channel is +m.
- h [nickname]       Gives halfop status to [nickname] (this mode can
-                    be disabled).
+ h [nickname]       Gives halfop status to [nickname] (requires
+                    customprefix module).
  o [nickname]       Gives op status to [nickname].
  a [nickname]       Gives protected status to [nickname], preventing
                     them from them from being kicked (+q only,
-                    requires chanprotect module).
+                    requires customprefix module).
  q [nickname]       Gives owner status to [nickname], preventing them
                     from being kicked (Services or only, requires
-                    chanprotect module).
+                    customprefix module).
 
  b [hostmask]       Bans [hostmask] from the channel.
  e [hostmask]       Excepts [hostmask] from bans (requires
index 02ddff8a2077733227f880cbdd1ace1a071d50c3..d54752cfb79275228199563224a6fe8f472853bf 100644 (file)
@@ -117,15 +117,15 @@ LOCKSERV       UNLOCKSERV   JUMPSERVER">
 
  v [nickname]       Gives voice to [nickname], allowing them to speak
                     while the channel is +m.
- h [nickname]       Gives halfop status to [nickname] (this mode can
-                    be disabled).
+ h [nickname]       Gives halfop status to [nickname] (requires
+                    customprefix module).
  o [nickname]       Gives op status to [nickname].
  a [nickname]       Gives protected status to [nickname], preventing
                     them from them from being kicked (+q only,
-                    requires chanprotect module).
+                    requires customprefix module).
  q [nickname]       Gives owner status to [nickname], preventing them
                     from being kicked (Services or only, requires
-                    chanprotect module).
+                    customprefix module).
 
  b [hostmask]       Bans [hostmask] from the channel.
  e [hostmask]       Excepts [hostmask] from bans (requires
index ca61bb416d75f8dbb89865d88b79081ff8b93f2a..f6dc96ecd3bb2f474441e03bfc6c4953a0411bd3 100644 (file)
 #                                                                      #
 ########################################################################
 
+#-#-#-#-#-#-#-#-#-#  CONFIGURATION FORMAT  #-#-#-#-#-#-#-#-#-#-#-#-#-#-
+#                                                                     #
+# In order to maintain compatibility with older configuration files,  #
+# you can change the configuration parser to parse as it did in       #
+# previous releases. When using the "compat" format, you need to use  #
+# C++ escape sequences (e.g. \n) instead of XML ones (e.g. &nl;) and  #
+# can not use <define> to create macros.                              #
+#<config format="compat">
+
 #-#-#-#-#-#-#-#-#-#  INCLUDE CONFIGURATION  #-#-#-#-#-#-#-#-#-#-#-#-#-#
 #                                                                     #
 # This optional tag allows you to include another config file         #
 #                                                                     #
 # Variables may be redefined and may reference other variables.       #
 # Value expansion happens at the time the tag is read.                #
-#                                                                     #
-# Using variable definitions REQUIRES that the config format be       #
-# changed to "xml" from the default "compat" that uses escape         #
-# sequences such as "\"" and "\n", and does not support <define>      #
-<config format="xml">
 <define name="bindip" value="1.2.2.3">
 <define name="localips" value="&bindip;/24">
 
       # for ssl to work. If you do not want this bind section to support ssl,
       # just remove or comment out this option.
       ssl="gnutls"
+
+      # defer: When this is non-zero, connections will not be handed over to
+      # the daemon from the operating system before data is ready.
+      # In Linux, the value indicates the number of seconds we'll wait for a
+      # connection to come up with data. Don't set it too low!
+      # In BSD the value is ignored; only zero and non-zero is possible.
+      # Windows ignores this parameter completely.
+      # Note: This does not take effect on rehash.
+      # To change it on a running bind, you'll have to comment it out,
+      # rehash, comment it in and rehash again.
+      defer="0"
 >
 
 <bind address="" port="6660-6669" type="clients">
          # maxconnwarn: Enable warnings when localmax or globalmax is hit (defaults to on)
          maxconnwarn="off"
 
+         # nouserdns: If enabled, no DNS lookups will be performed on connecting users
+         # in this class. This can save a lot of resources on very busy servers.
+         nouserdns="no"
+
          # usednsbl: Defines whether or not users in this class are subject to DNSBL. Default is yes.
          # This setting only has effect when m_dnsbl is loaded.
          #usednsbl="yes"
          # globalmax: Maximum global (network-wide) connections per IP.
          globalmax="3"
 
+         # nouserdns: If enabled, no DNS lookups will be performed on connecting users
+         # in this class. This can save a lot of resources on very busy servers.
+         nouserdns="no"
+
          # useident: Defines if users in this class must respond to a ident query or not.
          useident="no"
 
          # cyclehosts: If enabled, when a user gets a host set, it will cycle
          # them in all their channels. If not, it will simply change their host
          # without cycling them.
-         cyclehosts="yes"
+         cyclehosts="no"
 
          # cyclehostsfromuser: If enabled, the source of the mode change for
          # cyclehosts will be the user who cycled. This can look nicer, but
 
          # nosnoticestack: This prevents snotices from 'stacking' and giving you
          # the message saying '(last message repeated X times)'. Defaults to no.
-         nosnoticestack="no"
-
-         # welcomenotice: When turned on, this sends a NOTICE to connecting users 
-         # with the text Welcome to <networkname>! after successful registration.
-         # Defaults to yes.
-         welcomenotice="yes">
+         nosnoticestack="no">
 
 
 #-#-#-#-#-#-#-#-#-#-#-# PERFORMANCE CONFIGURATION #-#-#-#-#-#-#-#-#-#-#
              # +C and +Q snomasks. Setting this to yes squelches those messages,
              # which makes it easier for opers, but degrades the functionality of
              # bots like BOPM during netsplits.
-             quietbursts="yes"
-
-             # nouserdns: If enabled, no DNS lookups will be performed on
-             # connecting users. This can save a lot of resources on very busy servers.
-             nouserdns="no">
+             quietbursts="yes">
 
 #-#-#-#-#-#-#-#-#-#-#-# SECURITY CONFIGURATION  #-#-#-#-#-#-#-#-#-#-#-#
 #                                                                     #
 
 <security
+          # allowcoreunload: If this value is set to yes, Opers will be able to
+          # unload core modules (e.g. cmd_privmsg.so).
+          allowcoreunload="no"
 
           # announceinvites: This option controls which members of the channel
           # receive an announcement when someone is INVITEd. Available values:
index 7a6c478f133759a542a912626ae3f648b9a44c3a..d5a5d24c131d18f85b52f79053c92dea390422df 100644 (file)
 # in a channel matching a mask like +b j:#channel*mask from joining.
 #<module name="m_channelban.so">
 
-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
-# Chanprotect module: gives +q and +a channel modes
-#<module name="m_chanprotect.so">
-
-<chanprotect
-       # noservices: With this set to yes, when a user joins a empty channel,
-       # the server will set +q on them. If set to no, it will only set +o
-       # on them until they register the channel.
-       noservices="no"
-
-       # qprefix: Prefix (symbol) to use for +q users.
-       qprefix="~"
-
-       # aprefix: Prefix (symbol) to use for +a users.
-       aprefix="&amp;"
-
-       # deprotectself: If this value is set (true, yes or 1), it will allow
-       # +a and +q users to remove the +a and +q from themselves, otherwise,
-       # the status will have to be removed by services.
-       deprotectself="yes"
-
-       # deprotectothers: If this value is set to yes, true, or 1, then any
-       # user with +q or +a may remove the +q or +a from other users.
-       deprotectothers="yes">
-
-
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # Check module: gives /check
 # Check is useful for looking up information on channels,
 # cloak prefix as shown below. The cloak key must be shared across    #
 # the network for correct cloaking.                                   #
 #                                                                     #
-# There are four methods of cloaking:                                 #
+# There are two methods of cloaking:                                  #
 #                                                                     #
 #   half           Cloak only the "unique" portion of a host; show    #
 #                  the last 2 parts of the domain, /16 subnet of IPv4 #
 #   full           Cloak the users completely, using three slices for #
 #                  common CIDR bans (IPv4: /16, /24; IPv6: /48, /64)  #
 #                                                                     #
-# These methods use a single key that can be any length of text.      #
+# The methods use a single key that can be any length of text.        #
 # An optional prefix may be specified to mark cloaked hosts.          #
-#                                                                     #
-# The following methods are maintained for backwards compatibility;   #
-# they are slightly less secure, and always hide unresolved IPs       #
-#                                                                     #
-#   compat-host    InspIRCd 1.2-compatible host-based cloaking        #
-#   compat-ip      InspIRCd 1.2-compatible ip-always cloaking         #
-#                                                                     #
-# If you use a compat cloaking mode then you must specify key1, key2, #
-# key3, key4; the values must be less than 0x80000000 and should be   #
-# picked at random. Prefix is mandatory, will default to network name #
-# if not specified, and will always have a "-" appended.              #
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 #
 #<cloak mode="half"
 #   quitmsg="Throttled" bootwait="10">
 
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
-# Custom prefixes: allows for channel prefixes to be added. 
-# This can replace m_chanprotect and m_halfop, except for services that
-# recognise those modules by name
+# Custom prefixes: allows for channel prefixes to be added.
 #<module name="m_customprefix.so">
 #
 # name       The name of the mode, must be unique from other modes
 # ranktoset  The numeric rank required to set/unset this mode. Defaults to rank.
 # depriv     Can you remove the mode from yourself? Defaults to yes.
 #<customprefix name="founder" letter="q" prefix="~" rank="50000" ranktoset="50000">
-#<customprefix name="admin" letter="a" prefix="&" rank="40000" ranktoset="50000">
+#<customprefix name="admin" letter="a" prefix="&amp;" rank="40000" ranktoset="50000">
 #<customprefix name="halfop" letter="h" prefix="%" rank="20000" ranktoset="30000">
 #<customprefix name="halfvoice" letter="V" prefix="-" rank="1" ranktoset="20000">
 
 # must be in one of your oper class blocks.
 #<module name="m_globalload.so">
 
-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
-# Halfop module: Provides the +h (halfops) channel status mode.
-#<module name="m_halfop.so">
-
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # HELPOP module: Provides the /HELPOP command
 #<module name="m_helpop.so">
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # Anti-Auto-Rejoin: Adds support for prevention of auto-rejoin (+J)
 #<module name="m_kicknorejoin.so">
-# Set the maximum time that is accepted as a parameter for +J here.
-#<kicknorejoin maxtime="1m">
 
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # Knock module: adds the /KNOCK command and +K channel mode
 # use glob. For this reason, is recommended to use a real regex engine
 # so that at least \s or [[:space:]] is available.
 
+#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
+# RMODE module: Adds the /RMODE command
+# Allows channel mods to remove list modes en masse.
+# Syntax: /rmode <channel> <mode> [pattern]
+# E.g. '/rmode #Channel b m:*' will remove all mute-extbans on the channel.
+#<module name="m_rmode.so">
+
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # SAJOIN module: Adds the /SAJOIN command
 # This module is oper-only.
index fa5d652f160c7141f1541e250af472d3e7239a59..2d27b43a0b33e940f778bce732f25d8d34aa72d2 100644 (file)
 <module name="m_chanfilter.so">
 <chanfilter hidemask="yes">
 
-<module name="m_chanprotect.so">
-
-<chanprotect
-       noservices="no"
-       qprefix="~"
-       aprefix="&amp;"
-       deprotectself="yes"
-       deprotectothers="yes">
-
 <module name="m_check.so">
 <module name="m_chghost.so">
 <hostname charmap="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_/0123456789">
index 1e5abefa57fc8b2ee41a591e2840221fcd86aa50..c62de0e55fa1550a7ef15646f1f0dfe78a0e9221 100644 (file)
@@ -24,6 +24,7 @@
      #   - servers/auspex: allows opers with this priv to see more detail about server information than normal users.
      # ACTIONS:
      #   - users/mass-message: allows opers with this priv to PRIVMSG and NOTICE to a server mask (e.g. NOTICE $*)
+     #   - users/samode-usermodes: allows opers with this priv to change the user modes of any other user using /SAMODE
      #   - channels/high-join-limit: allows opers with this priv to join <channels:opers> total channels instead of <channels:users> total channels.
      # PERMISSIONS:
      #   - users/flood/no-throttle: allows opers with this priv to send commands without being throttled (*NOTE)
index a7aac7f17c8ed0e72beef72f4562b74243a6ea76..7f51ca75e673e187dccf9d4089a3ac3b68aa27e9 100644 (file)
@@ -18,8 +18,7 @@
  */
 
 
-#ifndef BANCACHE_H
-#define BANCACHE_H
+#pragma once
 
 /** Stores a cached ban entry.
  * Each ban has one of these hashed in a hash_map to make for faster removal
@@ -37,68 +36,50 @@ class CoreExport BanCacheHit
        /** Reason, shown as quit message
         */
        std::string Reason;
-       /** IP to match against, no wildcards here (of course)
-        */
-       std::string IP;
        /** Time that the ban expires at
         */
        time_t Expiry;
 
-       BanCacheHit(const std::string &ip, const std::string &type, const std::string &reason)
+       BanCacheHit(const std::string &type, const std::string &reason, time_t seconds)
+               : Type(type), Reason(reason), Expiry(ServerInstance->Time() + seconds)
        {
-               this->Type = type;
-               this->Reason = reason;
-               this->IP = ip;
-               this->Expiry = ServerInstance->Time() + 86400; // a day. this might seem long, but entries will be removed as glines/etc expire.
        }
 
-       // overridden to allow custom time
-       BanCacheHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
-       {
-               this->Type = type;
-               this->Reason = reason;
-               this->IP = ip;
-               this->Expiry = ServerInstance->Time() + seconds;
-       }
+       bool IsPositive() const { return (!Reason.empty()); }
 };
 
 /* A container of ban cache items.
  * must be defined after class BanCacheHit.
  */
-typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash<std::string> > BanCacheHash;
+typedef TR1NS::unordered_map<std::string, BanCacheHit*, TR1NS::hash<std::string> > BanCacheHash;
 
 /** A manager for ban cache, which allocates and deallocates and checks cached bans.
  */
 class CoreExport BanCacheManager
 {
- private:
        BanCacheHash* BanHash;
+       bool RemoveIfExpired(BanCacheHash::iterator& it);
+
  public:
 
        /** Creates and adds a Ban Cache item.
         * @param ip The IP the item is for.
         * @param type The type of ban cache item. std::string. .empty() means it's a negative match (user is allowed freely).
         * @param reason The reason for the ban. Left .empty() if it's a negative match.
+        * @param seconds Number of seconds before nuking the bancache entry, the default is a day. This might seem long, but entries will be removed as glines/etc expire.
         */
-       BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
-
-       // Overridden to allow an optional number of seconds before expiry
-       BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds);
+       BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds = 0);
        BanCacheHit *GetHit(const std::string &ip);
-       bool RemoveHit(BanCacheHit *b);
 
        /** Removes all entries of a given type, either positive or negative. Returns the number of hits removed.
         * @param type The type of bancache entries to remove (e.g. 'G')
         * @param positive Remove either positive (true) or negative (false) hits.
         */
-       unsigned int RemoveEntries(const std::string &type, bool positive);
+       void RemoveEntries(const std::string& type, bool positive);
 
        BanCacheManager()
        {
                this->BanHash = new BanCacheHash();
        }
        ~BanCacheManager();
-       void RehashCache();
 };
-
-#endif
index 5308ed655af9d0e167efa4da5f0b84912bc86bb7..117ffab762c2317d09154138353652553caf8b5a 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef BASE_H
-#define BASE_H
+#pragma once
 
 #include <map>
 #include <deque>
@@ -255,5 +254,3 @@ class CoreExport ServiceProvider : public classbase
        virtual ~ServiceProvider();
 };
 
-
-#endif
diff --git a/include/builtinmodes.h b/include/builtinmodes.h
new file mode 100644 (file)
index 0000000..ba34a3d
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "mode.h"
+#include "channels.h"
+#include "listmode.h"
+
+/** Channel mode +b
+ */
+class ModeChannelBan : public ListModeBase
+{
+ public:
+       ModeChannelBan()
+               : ListModeBase(NULL, "ban", 'b', "End of channel ban list", 367, 368, true, "maxbans")
+       {
+       }
+};
+
+/** Channel mode +i
+ */
+class ModeChannelInviteOnly : public SimpleChannelModeHandler
+{
+ public:
+       ModeChannelInviteOnly() : SimpleChannelModeHandler(NULL, "inviteonly", 'i')
+       {
+       }
+};
+
+/** Channel mode +k
+ */
+class ModeChannelKey : public ModeHandler
+{
+ public:
+       ModeChannelKey();
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
+};
+
+/** Channel mode +l
+ */
+class ModeChannelLimit : public ParamChannelModeHandler
+{
+ public:
+       ModeChannelLimit();
+       bool ParamValidate(std::string& parameter);
+       bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
+};
+
+/** Channel mode +m
+ */
+class ModeChannelModerated : public SimpleChannelModeHandler
+{
+ public:
+       ModeChannelModerated() : SimpleChannelModeHandler(NULL, "moderated", 'm')
+       {
+       }
+};
+
+/** Channel mode +n
+ */
+class ModeChannelNoExternal : public SimpleChannelModeHandler
+{
+ public:
+       ModeChannelNoExternal() : SimpleChannelModeHandler(NULL, "noextmsg", 'n')
+       {
+       }
+};
+
+/** Channel mode +o
+ */
+class ModeChannelOp : public ModeHandler
+{
+ private:
+ public:
+       ModeChannelOp();
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
+       unsigned int GetPrefixRank();
+};
+
+/** Channel mode +p
+ */
+class ModeChannelPrivate : public SimpleChannelModeHandler
+{
+ public:
+       ModeChannelPrivate() : SimpleChannelModeHandler(NULL, "private", 'p')
+       {
+       }
+};
+
+/** Channel mode +s
+ */
+class ModeChannelSecret : public SimpleChannelModeHandler
+{
+ public:
+       ModeChannelSecret() : SimpleChannelModeHandler(NULL, "secret", 's')
+       {
+       }
+};
+
+/** Channel mode +t
+ */
+class ModeChannelTopicOps : public SimpleChannelModeHandler
+{
+ public:
+       ModeChannelTopicOps() : SimpleChannelModeHandler(NULL, "topiclock", 't')
+       {
+       }
+};
+
+/** Channel mode +v
+ */
+class ModeChannelVoice : public ModeHandler
+{
+ private:
+ public:
+       ModeChannelVoice();
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
+       unsigned int GetPrefixRank();
+};
+
+/** User mode +i
+ */
+class ModeUserInvisible : public SimpleUserModeHandler
+{
+ public:
+       ModeUserInvisible() : SimpleUserModeHandler(NULL, "invisible", 'i')
+       {
+       }
+};
+
+/** User mode +n
+ */
+class ModeUserServerNoticeMask : public ModeHandler
+{
+ public:
+       ModeUserServerNoticeMask();
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
+       void OnParameterMissing(User* user, User* dest, Channel* channel);
+       std::string GetUserParameter(User* user);
+};
+
+/** User mode +o
+ */
+class ModeUserOperator : public ModeHandler
+{
+ public:
+       ModeUserOperator();
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
+};
+
+/** User mode +w
+ */
+class ModeUserWallops : public SimpleUserModeHandler
+{
+ public:
+       ModeUserWallops() : SimpleUserModeHandler(NULL, "wallops", 'w')
+       {
+       }
+};
index 64b37611f04d4512e879322b5efae1ca8359c6c5..c3a29e8c2c0333d57412c7ccf0b053ddb18b797b 100644 (file)
@@ -3,6 +3,7 @@
  *
  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
  *   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2012 Adam <Adam@anope.org>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
  */
 
 
-#ifndef CALLER_H
-#define CALLER_H
+#pragma once
+
+#if defined HAS_CXX11_VARIADIC_TEMPLATES
+
+template<typename ReturnType, typename... Args> class CoreExport Handler : public classbase
+{
+ public:
+       virtual ~Handler() { }
+       virtual ReturnType Call(Args...) = 0;
+};
+
+template<typename ReturnType, typename... Args> class CoreExport Caller
+{
+ public:
+       Handler<ReturnType, Args...>* target;
+
+       Caller(Handler<ReturnType, Args...>* initial) : target(initial) { }
+       virtual ~Caller() { }
+
+       virtual ReturnType operator()(const Args&... params)
+       {
+               return this->target->Call(params...);
+       }
+};
+
+/* Below here is compat with the old API */
+#define HandlerBase0 Handler
+#define HandlerBase1 Handler
+#define HandlerBase2 Handler
+#define HandlerBase3 Handler
+#define HandlerBase4 Handler
+#define HandlerBase5 Handler
+#define HandlerBase6 Handler
+#define HandlerBase7 Handler
+#define HandlerBase8 Handler
+
+#define caller1 Caller
+#define caller2 Caller
+#define caller3 Caller
+#define caller4 Caller
+#define caller5 Caller
+#define caller6 Caller
+#define caller7 Caller
+#define caller8 Caller
+
+#define DEFINE_HANDLER0(NAME, RETURN) \
+       class CoreExport NAME : public Handler<RETURN> { public: NAME() { } virtual RETURN Call(); }
+
+#define DEFINE_HANDLER1(NAME, RETURN, V1) \
+       class CoreExport NAME : public Handler<RETURN, V1> { public: NAME() { } virtual RETURN Call(V1); }
+
+#define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \
+       class CoreExport NAME : public Handler<RETURN, V1, V2> { public: NAME() { } virtual RETURN Call(V1, V2); }
+
+#define DEFINE_HANDLER3(NAME, RETURN, V1, V2, V3) \
+       class CoreExport NAME : public Handler<RETURN, V1, V2, V3> { public: NAME() { } virtual RETURN Call(V1, V2, V3); }
+
+#define DEFINE_HANDLER4(NAME, RETURN, V1, V2, V3, V4) \
+       class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4); }
+
+#define DEFINE_HANDLER5(NAME, RETURN, V1, V2, V3, V4, V5) \
+       class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5); }
+
+#define DEFINE_HANDLER6(NAME, RETURN, V1, V2, V3, V4, V5, V6) \
+       class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6); }
+
+#define DEFINE_HANDLER7(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7) \
+       class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6, V7> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7); }
+
+#define DEFINE_HANDLER8(NAME, RETURN, V1, V2, V3, V4, V5, V6, V7, V8) \
+       class CoreExport NAME : public Handler<RETURN, V1, V2, V3, V4, V5, V6, V7, V8> { public: NAME() { } virtual RETURN Call(V1, V2, V3, V4, V5, V6, V7, V8); }
+
+#else
 
 /** The templates below can be auto generated by tools/create_templates.pl.
  * They are used to represent a functor with a given number of parameters and
index dda53f69da0b0be756bbcd9d5de59d76aaca4c50..2aff3f7a87f5f9e6da81b5da30bda0077ab62988 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef CHANNELS_H
-#define CHANNELS_H
+#pragma once
 
 #include "membership.h"
 #include "mode.h"
 /** Holds an entry for a ban list, exemption list, or invite list.
  * This class contains a single element in a channel list, such as a banlist.
  */
-class HostItem
-{
- public:
-       /** Time the item was added
-        */
-       time_t set_time;
-       /** Who added the item
-        */
-       std::string set_by;
-       /** The actual item data
-        */
-       std::string data;
-
-       HostItem() { /* stub */ }
-       virtual ~HostItem() { /* stub */ }
-};
-
-/** A subclass of HostItem designed to hold channel bans (+b)
- */
-class BanItem : public HostItem
-{
-};
 
 /** Holds all relevent information for a channel.
  * This class represents a channel, and contains its name, modes, topic, topic set time,
@@ -58,18 +35,10 @@ class BanItem : public HostItem
  */
 class CoreExport Channel : public Extensible, public InviteBase
 {
-       /** Connect a Channel to a User
-        */
-       static Channel* ForceChan(Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created);
-
        /** Set default modes for the channel on creation
         */
        void SetDefaultModes();
 
-       /** Maximum number of bans (cached)
-        */
-       int maxbans;
-
        /** Modes for the channel.
         * This is not a null terminated string! It is a bitset where
         * each item in it represents if a mode is set. For example
@@ -83,12 +52,32 @@ class CoreExport Channel : public Extensible, public InviteBase
         */
        CustomModeList custom_mode_params;
 
+       /** Remove the given membership from the channel's internal map of
+        * memberships and destroy the Membership object.
+        * This function does not remove the channel from User::chanlist.
+        * Since the parameter is an iterator to the target, the complexity
+        * of this function is constant.
+        * @param membiter The UserMembIter to remove, must be valid
+        */
+       void DelUser(const UserMembIter& membiter);
+
  public:
        /** Creates a channel record and initialises it with default values
         * @throw Nothing at present.
         */
        Channel(const std::string &name, time_t ts);
 
+       /** Checks whether the channel should be destroyed, and if yes, begins
+        * the teardown procedure.
+        *
+        * If there are users on the channel or a module vetoes the deletion
+        * (OnPreChannelDelete hook) then nothing else happens.
+        * Otherwise, first the OnChannelDelete event is fired, then the channel is
+        * removed from the channel list. All pending invites are destroyed and
+        * finally the channel is added to the cull list.
+        */
+       void CheckDestroy();
+
        /** The channel's name.
         */
        std::string name;
@@ -116,10 +105,6 @@ class CoreExport Channel : public Extensible, public InviteBase
         */
        std::string setby; /* 128 */
 
-       /** The list of all bans set on the channel.
-        */
-       BanList bans;
-
        /** Sets or unsets a custom mode in the channels info
         * @param mode The mode character to set or unset
         * @param value True if you want to set the mode or false if you want to remove it
@@ -164,13 +149,11 @@ class CoreExport Channel : public Extensible, public InviteBase
        int SetTopic(User *u, std::string &t, bool forceset = false);
 
        /** Obtain the channel "user counter"
-        * This returns the channel reference counter, which is initialized
-        * to 0 when the channel is created and incremented/decremented
-        * upon joins, parts quits and kicks.
+        * This returns the number of users on this channel
         *
         * @return The number of users on this channel
         */
-       long GetUserCounter();
+       long GetUserCounter() const { return userlist.size(); }
 
        /** Add a user pointer to the internal reference list
         * @param user The user to add
@@ -196,7 +179,7 @@ class CoreExport Channel : public Extensible, public InviteBase
         *
         * @return This function returns pointer to a map of User pointers (CUList*).
         */
-       const UserMembList* GetUsers();
+       const UserMembList* GetUsers() const { return &userlist; }
 
        /** Returns true if the user given is on the given channel.
         * @param user The user to look for
@@ -210,8 +193,9 @@ class CoreExport Channel : public Extensible, public InviteBase
         * @param src The source of the kick
         * @param user The user being kicked (must be on this channel)
         * @param reason The reason for the kick
+        * @param srcmemb The membership of the user who does the kick, can be NULL
         */
-       void KickUser(User *src, User *user, const char* reason);
+       void KickUser(User* src, User* user, const std::string& reason, Membership* srcmemb = NULL);
 
        /** Part a user from this channel with the given reason.
         * If the reason field is NULL, no reason will be sent.
@@ -220,16 +204,24 @@ class CoreExport Channel : public Extensible, public InviteBase
         */
        void PartUser(User *user, std::string &reason);
 
-       /* Join a user to a channel. May be a channel that doesnt exist yet.
+       /** Join a local user to a channel, with or without permission checks. May be a channel that doesn't exist yet.
         * @param user The user to join to the channel.
-        * @param cn The channel name to join to. Does not have to exist.
+        * @param channame The channel name to join to. Does not have to exist.
         * @param key The key of the channel, if given
         * @param override If true, override all join restrictions such as +bkil
         * @return A pointer to the Channel the user was joined to. A new Channel may have
         * been created if the channel did not exist before the user was joined to it.
-        * If the user could not be joined to a channel, the return value may be NULL.
+        * If the user could not be joined to a channel, the return value is NULL.
+        */
+       static Channel* JoinUser(LocalUser* user, std::string channame, bool override = false, const std::string& key = "");
+
+       /** Join a user to an existing channel, without doing any permission checks
+        * @param user The user to join to the channel
+        * @param privs Priviliges (prefix mode letters) to give to this user, may be NULL
+        * @param bursting True if this join is the result of a netburst (passed to modules in the OnUserJoin hook)
+        * @param created True if this channel was just created by a local user (passed to modules in the OnUserJoin hook)
         */
-       static Channel* JoinUser(User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS = 0);
+       void ForceJoin(User* user, const std::string* privs = NULL, bool bursting = false, bool created_by_local = false);
 
        /** Write to a channel, from a user, using va_args for text
         * @param user User whos details to prefix the line with
@@ -301,28 +293,18 @@ class CoreExport Channel : public Extensible, public InviteBase
        /** Write a line of text that already includes the source */
        void RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
 
-       /** Returns the maximum number of bans allowed to be set on this channel
-        * @return The maximum number of bans allowed
-        */
-       long GetMaxBans();
-
        /** Return the channel's modes with parameters.
         * @param showkey If this is set to true, the actual key is shown,
         * otherwise it is replaced with '&lt;KEY&gt;'
         * @return The channel mode string
         */
-       char* ChanModes(bool showkey);
+       const char* ChanModes(bool showkey);
 
        /** Spool the NAMES list for this channel to the given user
         * @param user The user to spool the NAMES list to
         */
        void UserList(User *user);
 
-       /** Get the number of invisible users on this channel
-        * @return Number of invisible users
-        */
-       int CountInvisible();
-
        /** Get a users prefix on this channel in a string.
         * @param user The user to look up
         * @return A character array containing the prefix string.
@@ -357,13 +339,6 @@ class CoreExport Channel : public Extensible, public InviteBase
         */
        unsigned int GetPrefixValue(User* user);
 
-       /** This method removes all prefix characters from a user.
-        * It will not inform the user or the channel of the removal of prefixes,
-        * and should be used when the user parts or quits.
-        * @param user The user to remove all prefixes from
-        */
-       void RemoveAllPrefixes(User* user);
-
        /** Add a prefix character to a user.
         * Only the core should call this method, usually  from
         * within the mode parser or when the first user joins
@@ -388,10 +363,9 @@ class CoreExport Channel : public Extensible, public InviteBase
        /** Get the status of an "action" type extban
         */
        ModResult GetExtBanStatus(User *u, char type);
-
-       /** Clears the cached max bans value
-        */
-       void ResetMaxBans();
 };
 
-#endif
+inline bool Channel::HasUser(User* user)
+{
+       return (userlist.find(user) != userlist.end());
+}
index f9e3a740c3012bc3e955f2b6da841600707cdde7..4a88a8ec8ca29cb0220e4b82b2809bf738a7bcdf 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef COMMAND_PARSE_H
-#define COMMAND_PARSE_H
+#pragma once
 
 /** This class handles command management and parsing.
  * It allows you to add and remove commands from the map,
@@ -42,7 +41,7 @@ class CoreExport CommandParser
         * @param user The user to parse the command for
         * @param cmd The command string to process
         */
-       bool ProcessCommand(LocalUser *user, std::string &cmd);
+       void ProcessCommand(LocalUser* user, std::string& cmd);
 
  public:
        /** Command list, a hash_map of command names to Command*
@@ -108,7 +107,7 @@ class CoreExport CommandParser
         * @param buffer The buffer line to process
         * @param user The user to whom this line belongs
         */
-       bool ProcessBuffer(std::string &buffer,LocalUser *user);
+       void ProcessBuffer(std::string &buffer,LocalUser *user);
 
        /** Add a new command to the commands hash
         * @param f The new Command to add to the list
@@ -165,5 +164,3 @@ const int duration_multi[] =
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
 };
-
-#endif
index d333541228903ae722d7d58d9f9928093bd10053..7e1eeefc9384771f759524a8fdc804be6ea7af22 100644 (file)
  */
 
 
-#ifndef CMD_WHOWAS_H
-#define CMD_WHOWAS_H
-#include "modules.h"
-
-struct WhowasRequest : public Request
-{
-       /* list of available internal commands */
-       enum Internals
-       {
-               WHOWAS_ADD = 1,
-               WHOWAS_STATS = 2,
-               WHOWAS_PRUNE = 3,
-               WHOWAS_MAINTAIN = 4
-       };
-
-       const Internals type;
-       std::string value;
-       User* user;
-
-       WhowasRequest(Module* src, Module* whowas, Internals Type) : Request(src, whowas, "WHOWAS"), type(Type)
-       {}
-};
+#pragma once
 
-/* Forward ref for timer */
-class WhoWasMaintainTimer;
+#include "modules.h"
 
 /* Forward ref for typedefs */
 class WhoWasGroup;
 
-/** Timer that is used to maintain the whowas list, called once an hour
- */
-extern WhoWasMaintainTimer* timer;
-
 /** A group of users related by nickname
  */
 typedef std::deque<WhoWasGroup*> whowas_set;
@@ -81,6 +55,19 @@ class CommandWhowas : public Command
        whowas_users_fifo whowas_fifo;
 
   public:
+       /** Max number of WhoWas entries per user.
+        */
+       int WhoWasGroupSize;
+
+       /** Max number of cumulative user-entries in WhoWas.
+        *  When max reached and added to, push out oldest entry FIFO style.
+        */
+       int WhoWasMaxGroups;
+
+       /** Max seconds a user is kept in WhoWas before being pruned.
+        */
+       int WhoWasMaxKeep;
+
        CommandWhowas(Module* parent);
        /** Handle command.
         * @param parameters The parameters to the comamnd
@@ -127,15 +114,3 @@ class WhoWasGroup
         */
        ~WhoWasGroup();
 };
-
-class WhoWasMaintainTimer : public Timer
-{
-  public:
-       WhoWasMaintainTimer(long interval)
-       : Timer(interval, ServerInstance->Time(), true)
-       {
-       }
-       virtual void Tick(time_t TIME);
-};
-
-#endif
diff --git a/include/compat.h b/include/compat.h
new file mode 100644 (file)
index 0000000..1cdad06
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/**
+ * Some implementations of the C++11 standard library are incomplete so we use
+ * the implementation of the same types from C++ Technical Report 1 instead.
+ */
+#if defined _LIBCPP_VERSION || defined _WIN32
+# define TR1NS std
+# include <unordered_map>
+#else
+# define TR1NS std::tr1
+# include <tr1/unordered_map>
+#endif
+
+/**
+ * This macro enables the compile-time checking of printf format strings. This
+ * makes the compiler show a warning if the format of a printf arguments are
+ * incorrect.
+ */
+#if defined __clang__ || defined __GNUC__
+# define CUSTOM_PRINTF(stringpos, firstpos) __attribute__((format(printf, stringpos, firstpos)))
+#else
+# pragma message ("Warning! CUSTOM_PRINTF() does not work on your compiler!")
+# define CUSTOM_PRINTF(stringpos, firstpos)
+#endif
+
+/**
+ * These macros enable the use of the C++11 override control keywords in
+ * compilers which support them.
+ */
+#if __cplusplus >= 201103L
+# define HAS_CXX11_FINAL_OVERRIDE
+#elif defined __clang__
+# if __has_feature(cxx_override_control)
+#  define HAS_CXX11_FINAL_OVERRIDE
+# endif
+#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
+# if defined __GXX_EXPERIMENTAL_CXX0X__
+#  define HAS_CXX11_FINAL_OVERRIDE
+# endif
+#elif _MSC_VER >= 1700
+# define HAS_CXX11_FINAL_OVERRIDE
+#endif
+
+#if defined HAS_CXX11_FINAL_OVERRIDE
+# define CXX11_FINAL final
+# define CXX11_OVERRIDE override
+#else
+# define CXX11_FINAL
+# define CXX11_OVERRIDE
+#endif
+
+/**
+ * These macros enable the detection of the C++11 variadic templates in
+ * compilers which support them.
+ */
+#if __cplusplus >= 201103L
+# define HAS_CXX11_VARIADIC_TEMPLATES
+#elif defined __clang__
+# if __has_feature(cxx_variadic_templates)
+#  define HAS_CXX11_VARIADIC_TEMPLATES
+# endif
+#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# if defined __GXX_EXPERIMENTAL_CXX0X__
+#  define HAS_CXX11_VARIADIC_TEMPLATES
+# endif
+#elif _MSC_FULL_VER >= 170051025
+# define HAS_CXX11_VARIADIC_TEMPLATES
+#endif
+
+/**
+ * This macro allows methods to be marked as deprecated. To use this, wrap the
+ * method declaration in the header file with the macro.
+ */
+#if defined __clang__ || defined __GNUC__
+# define DEPRECATED_METHOD(function) function __attribute__((deprecated))
+#elif defined _MSC_VER
+# define DEPRECATED_METHOD(function) __declspec(deprecated) function
+#else
+# pragma message ("Warning! DEPRECATED_METHOD() does not work on your compiler!")
+# define DEPRECATED_METHOD(function) function
+#endif
+
+/**
+ * Windows is very different to UNIX so we have to wrap certain features in
+ * order to build on Windows correctly.
+ */
+#if defined _WIN32
+# include "inspircd_win32wrapper.h"
+#else
+# include <unistd.h>
+# define ENTRYPOINT int main(int argc, char** argv)
+# define DllExport
+# define CoreExport
+#endif
index 999d79e2460d452122e290e2c82f47c6fdded4c1..8292fdda5c6207182cd4129bdf6b27bcc41d4f2a 100644 (file)
@@ -17,6 +17,8 @@
  */
 
 
+#pragma once
+
 struct fpos
 {
        std::string filename;
@@ -31,7 +33,7 @@ struct fpos
 
 enum ParseFlags
 {
-       FLAG_USE_XML = 1,
+       FLAG_USE_COMPAT = 1,
        FLAG_NO_EXEC = 2,
        FLAG_NO_INC = 4
 };
@@ -76,5 +78,3 @@ struct FileWrapper
                }
        }
 };
-
-
index 09d4e619d4aaa35e64004607f0db019f11fbeaaf..cc14120963d8ccf5e080ca6ebea78303b6d6820d 100644 (file)
@@ -21,8 +21,7 @@
  */
 
 
-#ifndef INSPIRCD_CONFIGREADER
-#define INSPIRCD_CONFIGREADER
+#pragma once
 
 #include <sstream>
 #include <string>
@@ -143,8 +142,6 @@ struct CommandLineConf
        /** Saved argv from startup
         */
        char** argv;
-
-       std::string startup_log;
 };
 
 class CoreExport OperInfo : public refcountbase
@@ -171,11 +168,6 @@ class CoreExport OperInfo : public refcountbase
        /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */
        std::string getConfig(const std::string& key);
        void init();
-
-       inline const char* NameStr()
-       {
-               return irc::Spacify(name.c_str());
-       }
 };
 
 /** This class holds the bulk of the runtime configuration for the ircd.
@@ -240,19 +232,6 @@ class CoreExport ServerConfig
         */
        int c_ipv6_range;
 
-       /** Max number of WhoWas entries per user.
-        */
-       int WhoWasGroupSize;
-
-       /** Max number of cumulative user-entries in WhoWas.
-        *  When max reached and added to, push out oldest entry FIFO style.
-        */
-       int WhoWasMaxGroups;
-
-       /** Max seconds a user is kept in WhoWas before being pruned.
-        */
-       int WhoWasMaxKeep;
-
        /** Holds the server name of the local server
         * as defined by the administrator.
         */
@@ -334,10 +313,6 @@ class CoreExport ServerConfig
         */
        std::string FixedPart;
 
-       /** The DNS server to use for DNS queries
-        */
-       std::string DNSServer;
-
        /** Pretend disabled commands don't exist.
         */
        bool DisabledDontExist;
@@ -445,16 +420,6 @@ class CoreExport ServerConfig
         */
        ClassVector Classes;
 
-       /** The 005 tokens of this server (ISUPPORT)
-        * populated/repopulated upon loading or unloading
-        * modules.
-        */
-       std::string data005;
-
-       /** isupport strings
-        */
-       std::vector<std::string> isupport;
-
        /** STATS characters in this list are available
         * only to operators.
         */
@@ -472,14 +437,6 @@ class CoreExport ServerConfig
         */
        std::map<irc::string, bool> ulines;
 
-       /** Max banlist sizes for channels (the std::string is a glob)
-        */
-       std::map<std::string, int> maxbans;
-
-       /** If set to true, no user DNS lookups are to be performed
-        */
-       bool NoUserDns;
-
        /** If set to true, provide syntax hints for unknown commands
         */
        bool SyntaxHints;
@@ -530,15 +487,7 @@ class CoreExport ServerConfig
 
        /** Get server ID as string with required leading zeroes
         */
-       const std::string& GetSID();
-
-       /** Update the 005 vector
-        */
-       void Update005();
-
-       /** Send the 005 numerics (ISUPPORT) to a user
-        */
-       void Send005(User* user);
+       const std::string& GetSID() const { return sid; }
 
        /** Read the entire configuration into memory
         * and initialize this class. All other methods
@@ -578,11 +527,6 @@ class CoreExport ServerConfig
        /** If this value is true, snotices will not stack when repeats are sent
         */
        bool NoSnoticeStack;
-
-       /** If true, a "Welcome to <networkname>!" NOTICE will be sent to
-        * connecting users
-        */
-       bool WelcomeNotice;
 };
 
 /** The background thread for config reading, so that reading from executable includes
@@ -609,5 +553,3 @@ class CoreExport ConfigReaderThread : public Thread
        void Finish();
        bool IsDone() { return done; }
 };
-
-#endif
index f7ca1335ed244f16514d457d4fa035971fab2996..9b7e0670afae1c68df0659e83ca870e50ca76272 100644 (file)
@@ -14,8 +14,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef CONSOLECOLORS_H
-#define CONSOLECOLORS_H
+
+#pragma once
 
 #include <ostream>
 
@@ -96,5 +96,3 @@ inline std::ostream& con_reset(std::ostream &s)
 }
 
 #endif
-
-#endif
index f9cd08cb3ae9dc8b209770bb05d1de4d6d7c468c..6ead8081f96a3cf65a8fb0fac7b49468c7baf4d3 100644 (file)
@@ -21,8 +21,7 @@
  */
 
 
-#ifndef CTABLES_H
-#define CTABLES_H
+#pragma once
 
 /** Used to indicate command success codes
  */
@@ -120,10 +119,6 @@ class CoreExport Command : public ServiceProvider
         */
        unsigned long use_count;
 
-       /** used by /stats m
-        */
-       unsigned long total_bytes;
-
        /** True if the command is disabled to non-opers
         */
        bool disabled;
@@ -164,7 +159,7 @@ class CoreExport Command : public ServiceProvider
         */
        Command(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) :
                ServiceProvider(me, cmd, SERVICE_COMMAND), flags_needed(0), min_params(minpara), max_params(maxpara),
-               use_count(0), total_bytes(0), disabled(false), works_before_reg(false), allow_empty_last_param(true),
+               use_count(0), disabled(false), works_before_reg(false), allow_empty_last_param(true),
                Penalty(1)
        {
        }
@@ -252,5 +247,3 @@ class CoreExport SplitCommand : public Command
        translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
 #define TRANSLATE8(x1,x2,x3,x4,x5,x6,x7,x8)  translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
        translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);
-
-#endif
index 75b08b7a373d686e0c51993908a6d0525e44417e..ac64dced284341805081c6e78c0b33927a1af9d3 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef CULL_LIST_H
-#define CULL_LIST_H
+#pragma once
 
 /**
  * The CullList class is used to delete objects at the end of the main loop to
@@ -58,6 +57,3 @@ class CoreExport ActionList
        void Run();
 
 };
-
-#endif
-
diff --git a/include/dns.h b/include/dns.h
deleted file mode 100644 (file)
index 27c3c88..0000000
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2005-2008 Craig Edwards <craigedwards@brainbox.cc>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/*
-dns.h - dns library very very loosely based on
-firedns, Copyright (C) 2002 Ian Gulliver
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of version 2 of the GNU General Public License as
-published by the Free Software Foundation.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-#ifndef DNS_H
-#define DNS_H
-
-#include "socket.h"
-#include "hashcomp.h"
-
-/**
- * Result status, used internally
- */
-class CoreExport DNSResult
-{
- public:
-       /** Result ID
-        */
-       int id;
-       /** Result body, a hostname or IP address
-        */
-       std::string result;
-       /** Time-to-live value of the result
-        */
-       unsigned long ttl;
-       /** The original request, a hostname or IP address
-        */
-       std::string original;
-
-       /** Build a DNS result.
-        * @param i The request ID
-        * @param res The request result, a hostname or IP
-        * @param timetolive The request time-to-live
-        * @param orig The original request, a hostname or IP
-        */
-       DNSResult(int i, const std::string &res, unsigned long timetolive, const std::string &orig) : id(i), result(res), ttl(timetolive), original(orig) { }
-};
-
-/**
- * Information on a completed lookup, used internally
- */
-typedef std::pair<unsigned char*, std::string> DNSInfo;
-
-/** Cached item stored in the query cache.
- */
-class CoreExport CachedQuery
-{
- public:
-       /** The cached result data, an IP or hostname
-        */
-       std::string data;
-       /** The time when the item is due to expire
-        */
-       time_t expires;
-
-       /** Build a cached query
-        * @param res The result data, an IP or hostname
-        * @param ttl The time-to-live value of the query result
-        */
-       CachedQuery(const std::string &res, unsigned int ttl);
-
-       /** Returns the number of seconds remaining before this
-        * cache item has expired and should be removed.
-        */
-       int CalcTTLRemaining();
-};
-
-/** DNS cache information. Holds IPs mapped to hostnames, and hostnames mapped to IPs.
- */
-typedef nspace::hash_map<irc::string, CachedQuery, irc::hash> dnscache;
-
-/**
- * Error types that class Resolver can emit to its error method.
- */
-enum ResolverError
-{
-       RESOLVER_NOERROR        =       0,
-       RESOLVER_NSDOWN         =       1,
-       RESOLVER_NXDOMAIN       =       2,
-       RESOLVER_BADIP          =       3,
-       RESOLVER_TIMEOUT        =       4,
-       RESOLVER_FORCEUNLOAD    =       5
-};
-
-/**
- * Query and resource record types
- */
-enum QueryType
-{
-       /** Uninitialized Query */
-       DNS_QUERY_NONE  = 0,
-       /** 'A' record: an ipv4 address */
-       DNS_QUERY_A     = 1,
-       /** 'CNAME' record: An alias */
-       DNS_QUERY_CNAME = 5,
-       /** 'PTR' record: a hostname */
-       DNS_QUERY_PTR   = 12,
-       /** 'AAAA' record: an ipv6 address */
-       DNS_QUERY_AAAA  = 28,
-
-       /** Force 'PTR' to use IPV4 scemantics */
-       DNS_QUERY_PTR4  = 0xFFFD,
-       /** Force 'PTR' to use IPV6 scemantics */
-       DNS_QUERY_PTR6  = 0xFFFE
-};
-
-/**
- * Used internally to force PTR lookups to use a certain protocol scemantics,
- * e.g. x.x.x.x.in-addr.arpa for v4, and *.ip6.arpa for v6.
- */
-enum ForceProtocol
-{
-       /** Forced to use ipv4 */
-       PROTOCOL_IPV4 = 0,
-       /** Forced to use ipv6 */
-       PROTOCOL_IPV6 = 1
-};
-
-/**
- * The Resolver class is a high-level abstraction for resolving DNS entries.
- * It can do forward and reverse IPv4 lookups, and where IPv6 is supported, will
- * also be able to do those, transparent of protocols. Module developers must
- * extend this class via inheritence, and then insert a pointer to their derived
- * class into the core using Server::AddResolver(). Once you have done this,
- * the class will be able to receive callbacks. There are two callbacks which
- * can occur by calling virtual methods, one is a success situation, and the other
- * an error situation.
- */
-class CoreExport Resolver
-{
- protected:
-       /**
-        * Pointer to creator module (if any, or NULL)
-        */
-       ModuleRef Creator;
-       /**
-        * The input data, either a host or an IP address
-        */
-       std::string input;
-       /**
-        * True if a forward lookup is being performed, false if otherwise
-        */
-       QueryType querytype;
-       /**
-        * The DNS erver being used for lookups. If this is an empty string,
-        * the value of ServerConfig::DNSServer is used instead.
-        */
-       std::string server;
-       /**
-        * The ID allocated to your lookup. This is a pseudo-random number
-        * between 0 and 65535, a value of -1 indicating a failure.
-        * The core uses this to route results to the correct objects.
-        */
-       int myid;
-
-       /**
-        * Cached result, if there is one
-        */
-       CachedQuery *CQ;
-
-       /**
-        * Time left before cache expiry
-        */
-       int time_left;
-
- public:
-       /**
-        * Initiate DNS lookup. Your class should not attempt to delete or free these
-        * objects, as the core will do this for you. They must always be created upon
-        * the heap using new, as you cannot be sure at what time they will be deleted.
-        * Allocating them on the stack or attempting to delete them yourself could cause
-        * the object to go 'out of scope' and cause a segfault in the core if the result
-        * arrives at a later time.
-        * @param source The IP or hostname to resolve
-        * @param qt The query type to perform. Resolution of 'A', 'AAAA', 'PTR' and 'CNAME' records
-        * is supported. Use one of the QueryType enum values to initiate this type of
-        * lookup. Resolution of 'AAAA' ipv6 records is always supported, regardless of
-        * wether InspIRCd is built with ipv6 support.
-        * To look up reverse records, specify one of DNS_QUERY_PTR4 or DNS_QUERY_PTR6 depending
-        * on the type of address you are looking up.
-        * @param cached The constructor will set this boolean to true or false depending
-        * on whether the DNS lookup you are attempting is cached (and not expired) or not.
-        * If the value is cached, upon return this will be set to true, otherwise it will
-        * be set to false. You should pass this value to InspIRCd::AddResolver(), which
-        * will then influence the behaviour of the method and determine whether a cached
-        * or non-cached result is obtained. The value in this variable is always correct
-        * for the given request when the constructor exits.
-        * @param creator See the note below.
-        * @throw ModuleException This class may throw an instance of ModuleException, in the
-        * event a lookup could not be allocated, or a similar hard error occurs such as
-        * the network being down. This will also be thrown if an invalid IP address is
-        * passed when resolving a 'PTR' record.
-        *
-        * NOTE: If you are instantiating your DNS lookup from a module, you should set the
-        * value of creator to point at your Module class. This way if your module is unloaded
-        * whilst lookups are in progress, they can be safely removed and your module will not
-        * crash the server.
-        */
-       Resolver(const std::string &source, QueryType qt, bool &cached, Module* creator);
-
-       /**
-        * The default destructor does nothing.
-        */
-       virtual ~Resolver();
-
-       /**
-        * When your lookup completes, this method will be called.
-        * @param result The resulting DNS lookup, either an IP address or a hostname.
-        * @param ttl The time-to-live value of the result, in the instance of a cached
-        * result, this is the number of seconds remaining before refresh/expiry.
-        * @param cached True if the result is a cached result, false if it was requested
-        * from the DNS server.
-        */
-       virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached) = 0;
-
-       /**
-        * If an error occurs (such as NXDOMAIN, no domain name found) then this method
-        * will be called.
-        * @param e A ResolverError enum containing the error type which has occured.
-        * @param errormessage The error text of the error that occured.
-        */
-       virtual void OnError(ResolverError e, const std::string &errormessage);
-
-       /**
-        * Returns the id value of this class. This is primarily used by the core
-        * to determine where in various tables to place a pointer to your class, but it
-        * is safe to call and use this method.
-        * As specified in RFC1035, each dns request has a 16 bit ID value, ranging
-        * from 0 to 65535. If there is an issue and the core cannot send your request,
-        * this method will return -1.
-        */
-       int GetId();
-
-       /**
-        * Returns the creator module, or NULL
-        */
-       Module* GetCreator();
-
-       /**
-        * If the result is a cached result, this triggers the objects
-        * OnLookupComplete. This is done because it is not safe to call
-        * the abstract virtual method from the constructor.
-        */
-       void TriggerCachedResult();
-};
-
-/** DNS is a singleton class used by the core to dispatch dns
- * requests to the dns server, and route incoming dns replies
- * back to Resolver objects, based upon the request ID. You
- * should never use this class yourself.
- */
-class CoreExport DNS : public EventHandler
-{
- private:
-
-       /**
-        * The maximum value of a dns request id,
-        * 16 bits wide, 0xFFFF.
-        */
-       static const int MAX_REQUEST_ID = 0xFFFF;
-
-       /**
-        * Currently cached items
-        */
-       dnscache* cache;
-
-       /** A timer which ticks every hour to remove expired
-        * items from the DNS cache.
-        */
-       class CacheTimer* PruneTimer;
-
-       /**
-        * Build a dns packet payload
-        */
-       int MakePayload(const char* name, const QueryType rr, const unsigned short rr_class, unsigned char* payload);
-
- public:
-
-       irc::sockets::sockaddrs myserver;
-
-       /**
-        * Currently active Resolver classes
-        */
-       Resolver* Classes[MAX_REQUEST_ID];
-
-       /**
-        * Requests that are currently 'in flight'
-        */
-       DNSRequest* requests[MAX_REQUEST_ID];
-
-       /**
-        * The port number DNS requests are made on,
-        * and replies have as a source-port number.
-        */
-       static const int QUERY_PORT = 53;
-
-       /**
-        * Fill an rr (resource record) with data from input
-        */
-       static void FillResourceRecord(ResourceRecord* rr, const unsigned char* input);
-
-       /**
-        * Fill a header with data from input limited by a length
-        */
-       static void FillHeader(DNSHeader *header, const unsigned char *input, const int length);
-
-       /**
-        * Empty out a header into a data stream ready for transmission "on the wire"
-        */
-       static void EmptyHeader(unsigned char *output, const DNSHeader *header, const int length);
-
-       /**
-        * Start the lookup of an ipv4 from a hostname
-        */
-       int GetIP(const char* name);
-
-       /**
-        * Start lookup of a hostname from an ip, but
-        * force a specific protocol to be used for the lookup
-        * for example to perform an ipv6 reverse lookup.
-        */
-       int GetNameForce(const char *ip, ForceProtocol fp);
-
-       /**
-        * Start lookup of an ipv6 from a hostname
-        */
-       int GetIP6(const char *name);
-
-       /**
-        * Start lookup of a CNAME from another hostname
-        */
-       int GetCName(const char* alias);
-
-       /**
-        * Fetch the result string (an ip or host)
-        * and/or an error message to go with it.
-        */
-       DNSResult GetResult();
-
-       /**
-        * Handle a SocketEngine read event
-        * Inherited from EventHandler
-        */
-       void HandleEvent(EventType et, int errornum = 0);
-
-       /**
-        * Add a Resolver* to the list of active classes
-        */
-       bool AddResolverClass(Resolver* r);
-
-       /**
-        * Add a query to the list to be sent
-        */
-       DNSRequest* AddQuery(DNSHeader *header, int &id, const char* original);
-
-       /**
-        * The constructor initialises the dns socket,
-        * and clears the request lists.
-        */
-       DNS();
-
-       /**
-        * Re-initialize the DNS subsystem.
-        */
-       void Rehash();
-
-       /**
-        * Destructor
-        */
-       ~DNS();
-
-       /**
-        * Turn an in6_addr into a .ip6.arpa domain
-        */
-       static void MakeIP6Int(char* query, const in6_addr *ip);
-
-       /**
-        * Clean out all dns resolvers owned by a particular
-        * module, to make unloading a module safe if there
-        * are dns requests currently in progress.
-        */
-       void CleanResolvers(Module* module);
-
-       /** Return the cached value of an IP or hostname
-        * @param source An IP or hostname to find in the cache.
-        * @return A pointer to a CachedQuery if the item exists,
-        * otherwise NULL.
-        */
-       CachedQuery* GetCache(const std::string &source);
-
-       /** Delete a cached item from the DNS cache.
-        * @param source An IP or hostname to remove
-        */
-       void DelCache(const std::string &source);
-
-       /** Clear all items from the DNS cache immediately.
-        */
-       int ClearCache();
-
-       /** Prune the DNS cache, e.g. remove all expired
-        * items and rehash the cache buckets, but leave
-        * items in the hash which are still valid.
-        */
-       int PruneCache();
-};
-
-#endif
-
index 5e66ddbb0493938a440eb42afcabf1f3c0447833..d42cf61bf965855dbbb8231e374543f1b5b04ada 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef DLL_H
-#define DLL_H
+#pragma once
 
 /** The DLLManager class is able to load a module file by filename,
  * and locate its init_module symbol.
@@ -65,6 +64,3 @@ class CoreExport DLLManager : public classbase
        /** Get detailed version information from the module file */
        std::string GetVersion();
 };
-
-#endif
-
index d4890c94d5bcf24ae877d949525c28725651b7ad..888431969e871e6e3cb794234895bfd63d9fcf2f 100644 (file)
@@ -19,8 +19,7 @@
  */
 
 
-#ifndef EXITCODE_H
-#define EXITCODE_H
+#pragma once
 
 /** Valid exit codes to be used with InspIRCd::Exit()
  */
@@ -52,6 +51,3 @@ enum ExitStatus
  * human-readable strings to be shown on shutdown.
  */
 extern const char * ExitCodes[];
-
-#endif
-
index bcc4992bb4867cf1fcad7923ecb8a4750a23b9a3..e062f66a5131aab399d72a6fb219e4370fdb7524 100644 (file)
@@ -17,8 +17,7 @@
  */
 
 
-#ifndef EXTENSIBLE_H
-#define EXTENSIBLE_H
+#pragma once
 
 #include <stdint.h>
 
@@ -190,5 +189,3 @@ class CoreExport StringExtItem : public ExtensionItem
        void unset(Extensible* container);
        void free(void* item);
 };
-
-#endif
index 22a94c934cd3c288c4ea320e34dde0587d649437..ce571c3aeb303ad7d9fee7f9697e70780a7c6430 100644 (file)
  */
 
 
-#ifndef FILELOGGER_H
-#define FILELOGGER_H
+#pragma once
 
 #include "logger.h"
 
-/** Debug levels for use with InspIRCd::Log()
- *  */
-enum DebugLevel
-{
-    RAWIO       =   5,
-    DEBUG       =   10,
-    VERBOSE     =   20,
-    DEFAULT     =   30,
-    SPARSE      =   40,
-    NONE        =   50
-};
-
-
-/* Forward declaration -- required */
-class InspIRCd;
-
 /** A logging class which logs to a streamed file.
  */
 class CoreExport FileLogStream : public LogStream
@@ -46,12 +29,9 @@ class CoreExport FileLogStream : public LogStream
  private:
        FileWriter *f;
  public:
-       FileLogStream(int loglevel, FileWriter *fw);
+       FileLogStream(LogLevel loglevel, FileWriter *fw);
 
        virtual ~FileLogStream();
 
-       virtual void OnLog(int loglevel, const std::string &type, const std::string &msg);
+       virtual void OnLog(LogLevel loglevel, const std::string &type, const std::string &msg);
 };
-
-#endif
-
diff --git a/include/hash_map.h b/include/hash_map.h
deleted file mode 100644 (file)
index 1b43f01..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef INSPIRCD_HASHMAP_H
-#define INSPIRCD_HASHMAP_H
-       /** Where hash_map is varies from compiler to compiler
-        * as it is not standard unless we have tr1.
-        *
-        * TODO: in 2.2 if we drop support for libstdc++ older than 3.4.7 and GCC older
-        *       than 4.1 this can be cleaned up massively.
-        */
-       #ifndef _WIN32
-               #if __GLIBCXX__ > 20060309
-                       // GCC4+ has deprecated hash_map and uses tr1. But of course, uses a different include to MSVC. FOR FUCKS SAKE.
-                       #include <tr1/unordered_map>
-                       #define HAS_TR1_UNORDERED
-                       #define HASHMAP_DEPRECATED
-               #else
-                       #include <ext/hash_map>
-                       /** Oddball linux namespace for hash_map */
-                       #define nspace __gnu_cxx
-                       #define BEGIN_HASHMAP_NAMESPACE namespace nspace {
-                       #define END_HASHMAP_NAMESPACE }
-               #endif
-       #else
-               #include <unordered_map>
-               #define HAS_TR1_UNORDERED
-               #define HASHMAP_DEPRECATED
-       #endif
-
-       // tr1: restoring sanity to our headers. now if only compiler vendors could agree on a FUCKING INCLUDE FILE.
-       #ifdef HAS_TR1_UNORDERED
-               #define hash_map unordered_map
-               #define nspace std::tr1
-               #define BEGIN_HASHMAP_NAMESPACE namespace std { namespace tr1 {
-               #define END_HASHMAP_NAMESPACE } }
-       #endif
-
-#endif
index 78d7ee878d230719ca692ff9b13fe2f9ac674023..0d3857d56c1a1d8204fafeea28a30192877c10a7 100644 (file)
@@ -22,8 +22,7 @@
  */
 
 
-#ifndef HASHCOMP_H
-#define HASHCOMP_H
+#pragma once
 
 #include <cstring>
 #include <string>
@@ -31,7 +30,7 @@
 #include <deque>
 #include <map>
 #include <set>
-#include "hash_map.h"
+#include "inspircd.h"
 
 /*******************************************************
  * This file contains classes and templates that deal
@@ -110,6 +109,11 @@ namespace irc
                bool operator()(const std::string& s1, const std::string& s2) const;
        };
 
+       struct insensitive
+       {
+               size_t CoreExport operator()(const std::string &s) const;
+       };
+
        /** The irc_char_traits class is used for RFC-style comparison of strings.
         * This class is used to implement irc::string, a case-insensitive, RFC-
         * comparing string class.
@@ -155,19 +159,12 @@ namespace irc
                static CoreExport const char* find(const char* s1, int  n, char c);
        };
 
-       /** Compose a hex string from raw data.
-        * @param raw The raw data to compose hex from
-        * @param rawsz The size of the raw data buffer
-        * @return The hex string.
-        */
-       CoreExport std::string hex(const unsigned char *raw, size_t rawsz);
-
        /** This typedef declares irc::string based upon irc_char_traits.
         */
        typedef std::basic_string<char, irc_char_traits, std::allocator<char> > string;
 
        /** irc::stringjoiner joins string lists into a string, using
-        * the given seperator string.
+        * the given separator string.
         * This class can join a vector of std::string, a deque of
         * std::string, or a const char* const* array, using overloaded
         * constructors.
@@ -183,33 +180,17 @@ namespace irc
         public:
 
                /** Join elements of a vector, between (and including) begin and end
-                * @param seperator The string to seperate values with
-                * @param sequence One or more items to seperate
-                * @param begin The starting element in the sequence to be joined
-                * @param end The ending element in the sequence to be joined
-                */
-               stringjoiner(const std::string &seperator, const std::vector<std::string> &sequence, int begin, int end);
-
-               /** Join elements of a deque, between (and including) begin and end
-                * @param seperator The string to seperate values with
-                * @param sequence One or more items to seperate
-                * @param begin The starting element in the sequence to be joined
-                * @param end The ending element in the sequence to be joined
-                */
-               stringjoiner(const std::string &seperator, const std::deque<std::string> &sequence, int begin, int end);
-
-               /** Join elements of an array of char arrays, between (and including) begin and end
-                * @param seperator The string to seperate values with
+                * @param separator The string to seperate values with
                 * @param sequence One or more items to seperate
                 * @param begin The starting element in the sequence to be joined
                 * @param end The ending element in the sequence to be joined
                 */
-               stringjoiner(const std::string &seperator, const char* const* sequence, int begin, int end);
+               stringjoiner(const std::string& separator, const std::vector<std::string>& sequence, unsigned int begin, unsigned int end);
 
                /** Get the joined sequence
-                * @return A reference to the joined string
+                * @return A constant reference to the joined string
                 */
-               std::string& GetJoined();
+               const std::string& GetJoined() const { return joined; }
        };
 
        /** irc::modestacker stacks mode sequences into a list.
@@ -281,80 +262,6 @@ namespace irc
                 */
                int GetStackedLine(std::vector<std::string> &result, int max_line_size = 360);
 
-               /** deprecated compatability interface - TODO remove */
-               int GetStackedLine(std::deque<std::string> &result, int max_line_size = 360) {
-                       std::vector<std::string> r;
-                       int n = GetStackedLine(r, max_line_size);
-                       result.clear();
-                       result.insert(result.end(), r.begin(), r.end());
-                       return n;
-               }
-       };
-
-       /** irc::tokenstream reads a string formatted as per RFC1459 and RFC2812.
-        * It will split the string into 'tokens' each containing one parameter
-        * from the string.
-        * For instance, if it is instantiated with the string:
-        * "PRIVMSG #test :foo bar baz qux"
-        * then each successive call to tokenstream::GetToken() will return
-        * "PRIVMSG", "#test", "foo bar baz qux", "".
-        * Note that if the whole string starts with a colon this is not taken
-        * to mean the string is all one parameter, and the first item in the
-        * list will be ":item". This is to allow for parsing 'source' fields
-        * from data.
-        */
-       class CoreExport tokenstream
-       {
-        private:
-
-               /** Original string
-                */
-               std::string tokens;
-
-               /** Last position of a seperator token
-                */
-               std::string::iterator last_starting_position;
-
-               /** Current string position
-                */
-               std::string::iterator n;
-
-               /** True if the last value was an ending value
-                */
-               bool last_pushed;
-        public:
-
-               /** Create a tokenstream and fill it with the provided data
-                */
-               tokenstream(const std::string &source);
-
-               /** Destructor
-                */
-               ~tokenstream();
-
-               /** Fetch the next token from the stream as a std::string
-                * @param token The next token available, or an empty string if none remain
-                * @return True if tokens are left to be read, false if the last token was just retrieved.
-                */
-               bool GetToken(std::string &token);
-
-               /** Fetch the next token from the stream as an irc::string
-                * @param token The next token available, or an empty string if none remain
-                * @return True if tokens are left to be read, false if the last token was just retrieved.
-                */
-               bool GetToken(irc::string &token);
-
-               /** Fetch the next token from the stream as an integer
-                * @param token The next token available, or undefined if none remain
-                * @return True if tokens are left to be read, false if the last token was just retrieved.
-                */
-               bool GetToken(int &token);
-
-               /** Fetch the next token from the stream as a long integer
-                * @param token The next token available, or undefined if none remain
-                * @return True if tokens are left to be read, false if the last token was just retrieved.
-                */
-               bool GetToken(long &token);
        };
 
        /** irc::sepstream allows for splitting token seperated lists.
@@ -364,43 +271,39 @@ namespace irc
         */
        class CoreExport sepstream
        {
-        private:
+        protected:
                /** Original string.
                 */
                std::string tokens;
-               /** Last position of a seperator token
+               /** Separator value
                 */
-               std::string::iterator last_starting_position;
+               char sep;
                /** Current string position
                 */
-               std::string::iterator n;
-               /** Seperator value
+               size_t pos;
+               /** If set then GetToken() can return an empty string
                 */
-               char sep;
+               bool allow_empty;
         public:
                /** Create a sepstream and fill it with the provided data
                 */
-               sepstream(const std::string &source, char seperator);
-
-               /** Destructor
-                */
-               virtual ~sepstream();
+               sepstream(const std::string &source, char separator, bool allowempty = false);
 
                /** Fetch the next token from the stream
                 * @param token The next token from the stream is placed here
                 * @return True if tokens still remain, false if there are none left
                 */
-               virtual bool GetToken(std::string &token);
+               bool GetToken(std::string& token);
 
                /** Fetch the entire remaining stream, without tokenizing
                 * @return The remaining part of the stream
                 */
-               virtual const std::string GetRemaining();
+               const std::string GetRemaining();
 
                /** Returns true if the end of the stream has been reached
                 * @return True if the end of the stream has been reached, otherwise false
                 */
-               virtual bool StreamEnd();
+               bool StreamEnd();
        };
 
        /** A derived form of sepstream, which seperates on commas
@@ -408,9 +311,9 @@ namespace irc
        class CoreExport commasepstream : public sepstream
        {
         public:
-               /** Initialize with comma seperator
+               /** Initialize with comma separator
                 */
-               commasepstream(const std::string &source) : sepstream(source, ',')
+               commasepstream(const std::string &source, bool allowempty = false) : sepstream(source, ',', allowempty)
                {
                }
        };
@@ -420,13 +323,57 @@ namespace irc
        class CoreExport spacesepstream : public sepstream
        {
         public:
-               /** Initialize with space seperator
+               /** Initialize with space separator
                 */
-               spacesepstream(const std::string &source) : sepstream(source, ' ')
+               spacesepstream(const std::string &source, bool allowempty = false) : sepstream(source, ' ', allowempty)
                {
                }
        };
 
+       /** irc::tokenstream reads a string formatted as per RFC1459 and RFC2812.
+        * It will split the string into 'tokens' each containing one parameter
+        * from the string.
+        * For instance, if it is instantiated with the string:
+        * "PRIVMSG #test :foo bar baz qux"
+        * then each successive call to tokenstream::GetToken() will return
+        * "PRIVMSG", "#test", "foo bar baz qux", "".
+        * Note that if the whole string starts with a colon this is not taken
+        * to mean the string is all one parameter, and the first item in the
+        * list will be ":item". This is to allow for parsing 'source' fields
+        * from data.
+        */
+       class CoreExport tokenstream : private spacesepstream
+       {
+        public:
+               /** Create a tokenstream and fill it with the provided data
+                */
+               tokenstream(const std::string &source);
+
+               /** Fetch the next token from the stream as a std::string
+                * @param token The next token available, or an empty string if none remain
+                * @return True if tokens are left to be read, false if the last token was just retrieved.
+                */
+               bool GetToken(std::string &token);
+
+               /** Fetch the next token from the stream as an irc::string
+                * @param token The next token available, or an empty string if none remain
+                * @return True if tokens are left to be read, false if the last token was just retrieved.
+                */
+               bool GetToken(irc::string &token);
+
+               /** Fetch the next token from the stream as an integer
+                * @param token The next token available, or undefined if none remain
+                * @return True if tokens are left to be read, false if the last token was just retrieved.
+                */
+               bool GetToken(int &token);
+
+               /** Fetch the next token from the stream as a long integer
+                * @param token The next token available, or undefined if none remain
+                * @return True if tokens are left to be read, false if the last token was just retrieved.
+                */
+               bool GetToken(long &token);
+       };
+
        /** The portparser class seperates out a port range into integers.
         * A port range may be specified in the input string in the form
         * "6660,6661,6662-6669,7020". The end of the stream is indicated by
@@ -481,12 +428,6 @@ namespace irc
                long GetToken();
        };
 
-       /** Turn _ characters in a string into spaces
-        * @param n String to translate
-        * @return The new value with _ translated to space.
-        */
-       CoreExport const char* Spacify(const char* n);
-
        struct hash
        {
                /** Hash an irc::string using RFC1459 case sensitivity rules
@@ -590,72 +531,3 @@ inline std::string& trim(std::string &str)
 
        return str;
 }
-
-/** Hashing stuff is totally different on vc++'s hash_map implementation, so to save a buttload of
- * \#ifdefs we'll just do it all at once. Except, of course, with TR1, when it's the same as GCC.
- */
-BEGIN_HASHMAP_NAMESPACE
-
-       /** Hashing function to hash irc::string
-        */
-#if defined(_WIN32) && !defined(HAS_TR1_UNORDERED)
-       template<> class CoreExport hash_compare<irc::string, std::less<irc::string> >
-       {
-       public:
-               enum { bucket_size = 4, min_buckets = 8 }; /* Got these numbers from the CRT source, if anyone wants to change them feel free. */
-
-               /** Compare two irc::string values for hashing in hash_map
-                */
-               bool operator()(const irc::string & s1, const irc::string & s2) const
-               {
-                       if(s1.length() != s2.length()) return true;
-                       return (irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), (size_t)s1.length()) < 0);
-               }
-
-               /** Hash an irc::string value for hash_map
-                */
-               size_t operator()(const irc::string & s) const;
-       };
-
-       template<> class CoreExport hash_compare<std::string, std::less<std::string> >
-       {
-       public:
-               enum { bucket_size = 4, min_buckets = 8 }; /* Again, from the CRT source */
-
-               /** Compare two std::string values for hashing in hash_map
-                */
-               bool operator()(const std::string & s1, const std::string & s2) const
-               {
-                       if(s1.length() != s2.length()) return true;
-                       return (irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), (size_t)s1.length()) < 0);
-               }
-
-               /** Hash a std::string using RFC1459 case sensitivity rules
-               * @param s A string to hash
-               * @return The hash value
-               */
-               size_t operator()(const std::string & s) const;
-       };
-#else
-
-       /* XXX FIXME: Implement a hash function overriding std::string's that works with TR1! */
-
-#ifdef HASHMAP_DEPRECATED
-       struct insensitive
-#else
-       CoreExport template<> struct hash<std::string>
-#endif
-       {
-               size_t CoreExport operator()(const std::string &s) const;
-       };
-
-#endif
-
-       /** Convert a string to lower case respecting RFC1459
-       * @param n A string to lowercase
-       */
-       void strlower(char *n);
-
-END_HASHMAP_NAMESPACE
-
-#endif
index 86853a94f3cebdc41ac8381ca50a4ec8e132110b..957032da2f227c23a51d7d1c32dc9b0d6ac232d9 100644 (file)
  */
 
 
-#ifndef INSPIRCD_H
-#define INSPIRCD_H
+#pragma once
 
-#define _FILE_OFFSET_BITS 64
-#ifndef _LARGEFILE_SOURCE
-#define _LARGEFILE_SOURCE
-#endif
-
-#ifndef _WIN32
-#define DllExport
-#define CoreExport
-#else
-#include "inspircd_win32wrapper.h"
-/** Windows defines these already */
-#undef ERROR
-#endif
-
-#ifdef __GNUC__
-#define CUSTOM_PRINTF(STRING, FIRST) __attribute__((format(printf, STRING, FIRST)))
-#else
-#define CUSTOM_PRINTF(STRING, FIRST)
-#endif
-
-// Required system headers.
-#include <ctime>
-#include <cstdarg>
-#include <algorithm>
-#include <cmath>
-#include <cstring>
 #include <climits>
+#include <cmath>
+#include <csignal>
+#include <cstdarg>
 #include <cstdio>
-#ifndef _WIN32
-#include <unistd.h>
-#endif
+#include <cstring>
+#include <ctime>
 
-#include <sstream>
-#include <string>
-#include <vector>
-#include <list>
+#include <algorithm>
+#include <bitset>
 #include <deque>
+#include <list>
 #include <map>
-#include <bitset>
 #include <set>
-#include <time.h>
-#include "inspircd_config.h"
-#include "inspircd_version.h"
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "compat.h"
 #include "typedefs.h"
-#include "consolecolors.h"
 
 CoreExport extern InspIRCd* ServerInstance;
 
+#include "config.h"
+#include "consolecolors.h"
 #include "caller.h"
 #include "cull_list.h"
 #include "extensible.h"
@@ -98,25 +74,10 @@ CoreExport extern InspIRCd* ServerInstance;
 #include "inspstring.h"
 #include "protocol.h"
 
-#ifndef PATH_MAX
-#warning Potentially broken system, PATH_MAX undefined
-#define PATH_MAX 4096
-#endif
-
-/**
- * Used to define the maximum number of parameters a command may have.
- */
-#define MAXPARAMETERS 127
-
 /** Returned by some functions to indicate failure.
  */
 #define ERROR -1
 
-/** Support for librodent -
- * see http://www.chatspike.net/index.php?z=64
- */
-#define ETIREDHAMSTERS EAGAIN
-
 /** Template function to convert any input type to std::string
  */
 template<typename T> inline std::string ConvNumeric(const T &in)
@@ -259,17 +220,34 @@ class serverstats
        }
 };
 
-DEFINE_HANDLER2(IsNickHandler, bool, const char*, size_t);
+/** This class manages the generation and transmission of ISUPPORT. */
+class CoreExport ISupportManager
+{
+private:
+       /** The generated lines which are sent to clients. */
+       std::vector<std::string> Lines;
+
+public:
+       /** (Re)build the ISUPPORT vector. */
+       void Build();
+
+       /** Returns the std::vector of ISUPPORT lines. */
+       const std::vector<std::string>& GetLines()
+       {
+               return this->Lines;
+       }
+
+       /** Send the 005 numerics (ISUPPORT) to a user. */
+       void SendTo(LocalUser* user);
+};
+
+DEFINE_HANDLER1(IsNickHandler, bool, const std::string&);
 DEFINE_HANDLER2(GenRandomHandler, void, char*, size_t);
-DEFINE_HANDLER1(IsIdentHandler, bool, const char*);
-DEFINE_HANDLER1(FloodQuitUserHandler, void, User*);
-DEFINE_HANDLER2(IsChannelHandler, bool, const char*, size_t);
-DEFINE_HANDLER1(IsSIDHandler, bool, const std::string&);
+DEFINE_HANDLER1(IsIdentHandler, bool, const std::string&);
+DEFINE_HANDLER1(IsChannelHandler, bool, const std::string&);
 DEFINE_HANDLER1(RehashHandler, void, const std::string&);
 DEFINE_HANDLER3(OnCheckExemptionHandler, ModResult, User*, Channel*, const std::string&);
 
-class TestSuite;
-
 /** The main class of the irc server.
  * This class contains instances of all the other classes in this software.
  * Amongst other things, it contains a ModeParser, a DNS object, a CommandParser
@@ -279,10 +257,6 @@ class TestSuite;
 class CoreExport InspIRCd
 {
  private:
-       /** Holds the current UID. Used to generate the next one.
-        */
-       char current_uid[UUID_LENGTH];
-
        /** Set up the signal handlers
         */
        void SetSignals();
@@ -297,10 +271,6 @@ class CoreExport InspIRCd
         */
        void DoSocketTimeouts(time_t TIME);
 
-       /** Increments the current UID by one.
-        */
-       void IncrementUID(int pos);
-
        /** Perform background user events such as PING checks
         */
        void DoBackgroundUserStuff();
@@ -322,6 +292,8 @@ class CoreExport InspIRCd
 
  public:
 
+       UIDGenerator UIDGen;
+
        /** Global cull list, will be processed on next iteration
         */
        CullList GlobalCulls;
@@ -332,10 +304,8 @@ class CoreExport InspIRCd
 
        IsNickHandler HandleIsNick;
        IsIdentHandler HandleIsIdent;
-       FloodQuitUserHandler HandleFloodQuitUser;
        OnCheckExemptionHandler HandleOnCheckExemption;
        IsChannelHandler HandleIsChannel;
-       IsSIDHandler HandleIsSID;
        RehashHandler HandleRehash;
        GenRandomHandler HandleGenRandom;
 
@@ -349,28 +319,12 @@ class CoreExport InspIRCd
         */
        FakeUser* FakeClient;
 
-       /** Returns the next available UID for this server.
-        */
-       std::string GetUID();
-
-       static const char LogHeader[];
-
        /** Find a user in the UUID hash
         * @param uid The UUID to find
         * @return A pointer to the user, or NULL if the user does not exist
         */
        User* FindUUID(const std::string &uid);
 
-       /** Find a user in the UUID hash
-        * @param uid The UUID to find
-        * @return A pointer to the user, or NULL if the user does not exist
-        */
-       User* FindUUID(const char *uid);
-
-       /** Build the ISUPPORT string by triggering all modules On005Numeric events
-        */
-       void BuildISupport();
-
        /** Time this ircd was booted
         */
        time_t startup_time;
@@ -428,10 +382,6 @@ class CoreExport InspIRCd
         */
        SnomaskManager* SNO;
 
-       /** DNS class, provides resolver facilities to the core and modules
-        */
-       DNS* Res;
-
        /** Timer manager class, triggers Timer timer events
         */
        TimerManager* Timers;
@@ -454,20 +404,19 @@ class CoreExport InspIRCd
 
        /** Set to the current signal recieved
         */
-       int s_signal;
+       static sig_atomic_t s_signal;
 
        /** Protocol interface, overridden by server protocol modules
         */
        ProtocolInterface* PI;
 
-       /** Holds extensible for user nickforced
-        */
-       LocalIntExt NICKForced;
-
        /** Holds extensible for user operquit
         */
        LocalStringExt OperQuit;
 
+       /** Manages the generation and transmission of ISUPPORT. */
+       ISupportManager ISupport;
+
        /** Get the current time
         * Because this only calls time() once every time around the mainloop,
         * it is much faster than calling time() directly.
@@ -523,17 +472,6 @@ class CoreExport InspIRCd
         */
        User* FindNick(const std::string &nick);
 
-       /** Find a user in the nick hash.
-        * If the user cant be found in the nick hash check the uuid hash
-        * @param nick The nickname to find
-        * @return A pointer to the user, or NULL if the user does not exist
-        */
-       User* FindNick(const char* nick);
-
-       /** Find a user in the nick hash ONLY
-        */
-       User* FindNickOnly(const char* nick);
-
        /** Find a user in the nick hash ONLY
         */
        User* FindNickOnly(const std::string &nick);
@@ -544,34 +482,21 @@ class CoreExport InspIRCd
         */
        Channel* FindChan(const std::string &chan);
 
-       /** Find a channel in the channels hash
-        * @param chan The channel to find
-        * @return A pointer to the channel, or NULL if the channel does not exist
-        */
-       Channel* FindChan(const char* chan);
-
        /** Check we aren't running as root, and exit if we are
         * @return Depending on the configuration, this function may never return
         */
        void CheckRoot();
 
-       /** Determine the right path for, and open, the logfile
-        * @param argv The argv passed to main() initially, used to calculate program path
-        * @param argc The argc passed to main() initially, used to calculate program path
-        * @return True if the log could be opened, false if otherwise
-        */
-       bool OpenLog(char** argv, int argc);
-
        /** Return true if a channel name is valid
         * @param chname A channel name to verify
         * @return True if the name is valid
         */
-       caller2<bool, const char*, size_t> IsChannel;
+       caller1<bool, const std::string&> IsChannel;
 
        /** Return true if str looks like a server ID
         * @param string to check against
         */
-       caller1<bool, const std::string&> IsSID;
+       static bool IsSID(const std::string& sid);
 
        /** Rehash the local server
         */
@@ -598,12 +523,21 @@ class CoreExport InspIRCd
        /** Causes the server to exit immediately with exit code 0.
         * The status code is required for signal handlers, and ignored.
         */
+
+       /** Printf-wrapper.
+       * @param How you want it formatted
+       * @param ...
+       * @return The formatted string
+       */
+       static const char* Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2);
+       static const char* Format(va_list &vaList, const char* formatString) CUSTOM_PRINTF(2, 0);
+
        static void QuickExit(int status);
 
        /** Return a count of channels on the network
         * @return The number of channels
         */
-       long ChannelCount();
+       long ChannelCount() const { return chanlist->size(); }
 
        /** Send an error notice to all local users, opered and unopered
         * @param s The error string to send
@@ -614,31 +548,13 @@ class CoreExport InspIRCd
         * @param n A nickname to verify
         * @return True if the nick is valid
         */
-       caller2<bool, const char*, size_t> IsNick;
+       caller1<bool, const std::string&> IsNick;
 
        /** Return true if an ident is valid
         * @param An ident to verify
         * @return True if the ident is valid
         */
-       caller1<bool, const char*> IsIdent;
-
-       /** Add a dns Resolver class to this server's active set
-        * @param r The resolver to add
-        * @param cached If this value is true, then the cache will
-        * be searched for the DNS result, immediately. If the value is
-        * false, then a request will be sent to the nameserver, and the
-        * result will not be immediately available. You should usually
-        * use the boolean value which you passed to the Resolver
-        * constructor, which Resolver will set appropriately depending
-        * on if cached results are available and haven't expired. It is
-        * however safe to force this value to false, forcing a remote DNS
-        * lookup, but not an update of the cache.
-        * @return True if the operation completed successfully. Note that
-        * if this method returns true, you should not attempt to access
-        * the resolver class you pass it after this call, as depending upon
-        * the request given, the object may be deleted!
-        */
-       bool AddResolver(Resolver* r, bool cached);
+       caller1<bool, const std::string&> IsIdent;
 
        /** Add a command to this server's command parser
         * @param f A Command command handler object to add
@@ -672,7 +588,7 @@ class CoreExport InspIRCd
         * @param map The character map to use when matching.
         */
        static bool Match(const std::string &str, const std::string &mask, unsigned const char *map = NULL);
-       static bool Match(const  char *str, const char *mask, unsigned const char *map = NULL);
+       static bool Match(const char *str, const char *mask, unsigned const char *map = NULL);
 
        /** Match two strings using pattern matching, optionally, with a map
         * to check case against (may be NULL). If map is null, match will be case insensitive.
@@ -682,23 +598,14 @@ class CoreExport InspIRCd
         * @param map The character map to use when matching.
         */
        static bool MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map = NULL);
-       static bool MatchCIDR(const  char *str, const char *mask, unsigned const char *map = NULL);
-
-       /** Call the handler for a given command.
-        * @param commandname The command whos handler you wish to call
-        * @param parameters The mode parameters
-        * @param user The user to execute the command as
-        * @return True if the command handler was called successfully
-        */
-       CmdResult CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user);
+       static bool MatchCIDR(const char *str, const char *mask, unsigned const char *map = NULL);
 
-       /** Return true if the command is a module-implemented command and the given parameters are valid for it
-        * @param commandname The command name to check
-        * @param pcnt The parameter count
-        * @param user The user to test-execute the command as
-        * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
+       /** Matches a hostname and IP against a space delimited list of hostmasks.
+        * @param masks The space delimited masks to match against.
+        * @param hostname The hostname to try and match.
+        * @param ipaddr The IP address to try and match.
         */
-       bool IsValidModuleCommand(const std::string &commandname, int pcnt, User* user);
+       static bool MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr);
 
        /** Return true if the given parameter is a valid nick!user\@host mask
         * @param mask A nick!user\@host masak to match against
@@ -746,7 +653,7 @@ class CoreExport InspIRCd
         * (one year, two weeks, three days, four hours, six minutes and five seconds)
         * @return The total number of seconds
         */
-       long Duration(const std::string &str);
+       static unsigned long Duration(const std::string& str);
 
        /** Attempt to compare a password to a string from the config file.
         * This will be passed to handling modules which will compare the data
@@ -774,7 +681,7 @@ class CoreExport InspIRCd
        /** Returns the full version string of this ircd
         * @return The version string
         */
-       std::string GetVersionString(bool rawversion = false);
+       std::string GetVersionString(bool getFullVersion = false);
 
        /** Attempt to write the process id to a given file
         * @param filename The PID file to attempt to write to
@@ -808,16 +715,6 @@ class CoreExport InspIRCd
         */
        void SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...) CUSTOM_PRINTF(5, 6);
 
-       /** Handle /WHOIS
-        */
-       void DoWhois(User* user, User* dest,unsigned long signon, unsigned long idle, const char* nick);
-
-       /** Quit a user for excess flood, and if they are not
-        * fully registered yet, temporarily zline their IP.
-        * @param current user to quit
-        */
-       caller1<void, User*> FloodQuitUser;
-
        /** Called to check whether a channel restriction mode applies to a user
         * @param User that is attempting some action
         * @param Channel that the action is being performed on
@@ -839,17 +736,6 @@ class CoreExport InspIRCd
         */
        void Cleanup();
 
-       /** This copies the user and channel hash_maps into new hash maps.
-        * This frees memory used by the hash_map allocator (which it neglects
-        * to free, most of the time, using tons of ram)
-        */
-       void RehashUsersAndChans();
-
-       /** Resets the cached max bans value on all channels.
-        * Called by rehash.
-        */
-       void ResetMaxBans();
-
        /** Return a time_t as a human-readable string.
         */
        std::string TimeString(time_t curtime);
@@ -861,16 +747,10 @@ class CoreExport InspIRCd
         */
        int Run();
 
-       /** Adds an extban char to the 005 token.
-        */
-       void AddExtBanChar(char c);
-
        char* GetReadBuffer()
        {
                return this->ReadBuffer;
        }
-
-       friend class TestSuite;
 };
 
 ENTRYPOINT;
@@ -895,4 +775,7 @@ class CommandModule : public Module
        }
 };
 
-#endif
+inline void InspIRCd::SendMode(const std::vector<std::string>& parameters, User* user)
+{
+       this->Modes->Process(parameters, user);
+}
index c62c5a25099375193622b4331963256ef2e819ea..ccc2301ed463e98d9654cb56088468179b10d361 100644 (file)
@@ -21,8 +21,7 @@
  */
 
 
-#ifndef INSPSOCKET_H
-#define INSPSOCKET_H
+#pragma once
 
 #include "timer.h"
 
@@ -93,7 +92,7 @@ class CoreExport SocketTimeout : public Timer
 
        /** Handle tick event
         */
-       virtual void Tick(time_t now);
+       virtual bool Tick(time_t now);
 };
 
 /**
@@ -234,4 +233,3 @@ class CoreExport BufferedSocket : public StreamSocket
 inline Module* StreamSocket::GetIOHook() { return IOHook; }
 inline void StreamSocket::AddIOHook(Module* m) { IOHook = m; }
 inline void StreamSocket::DelIOHook() { IOHook = NULL; }
-#endif
index a6ef5e552869da601f05ecd8bbbad0eb6b8bf63c..ccc77da663156644b8723c34d6b998408ab07987 100644 (file)
  */
 
 
-#ifndef INSPSTRING_H
-#define INSPSTRING_H
+#pragma once
 
-// This (inspircd_config) is needed as inspstring doesn't pull in the central header
-#include "inspircd_config.h"
+// This (config) is needed as inspstring doesn't pull in the central header
+#include "config.h"
 #include <cstring>
-//#include <cstddef>
 
-#ifndef HAS_STRLCPY
-/** strlcpy() implementation for systems that don't have it (linux) */
-CoreExport size_t strlcpy(char *dst, const char *src, size_t siz);
-/** strlcat() implementation for systems that don't have it (linux) */
-CoreExport size_t strlcat(char *dst, const char *src, size_t siz);
-#endif
-
-/** charlcat() will append one character to a string using the same
- * safety scemantics as strlcat().
- * @param x The string to operate on
- * @param y the character to append to the end of x
- * @param z The maximum allowed length for z including null terminator
- */
-CoreExport int charlcat(char* x,char y,int z);
-/** charremove() will remove all instances of a character from a string
- * @param mp The string to operate on
- * @param remove The character to remove
+/** Sets ret to the formated string. last is the last parameter before ..., and format is the format in printf-style */
+#define VAFORMAT(ret, last, format) \
+       do { \
+       va_list _vaList; \
+       va_start(_vaList, last); \
+       ret = InspIRCd::Format(_vaList, format); \
+       va_end(_vaList); \
+       } while (false);
+
+/** Compose a hex string from raw data.
+ * @param raw The raw data to compose hex from (can be NULL if rawsize is 0)
+ * @param rawsize The size of the raw data buffer
+ * @return The hex string
  */
-CoreExport bool charremove(char* mp, char remove);
+CoreExport std::string BinToHex(const void* raw, size_t rawsize);
 
-/** Binary to hexadecimal conversion */
-CoreExport std::string BinToHex(const std::string& data);
 /** Base64 encode */
 CoreExport std::string BinToBase64(const std::string& data, const char* table = NULL, char pad = 0);
 /** Base64 decode */
 CoreExport std::string Base64ToBin(const std::string& data, const char* table = NULL);
 
-#endif
-
+/** Compose a hex string from the data in a std::string.
+ * @param data The data to compose hex from
+ * @return The hex string.
+ */
+inline std::string BinToHex(const std::string& data)
+{
+       return BinToHex(data.data(), data.size());
+}
diff --git a/include/listmode.h b/include/listmode.h
new file mode 100644 (file)
index 0000000..149f415
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/** The base class for list modes, should be inherited.
+ */
+class CoreExport ListModeBase : public ModeHandler
+{
+ public:
+       /** An item in a listmode's list
+        */
+       struct ListItem
+       {
+               std::string setter;
+               std::string mask;
+               time_t time;
+               ListItem(const std::string& Mask, const std::string& Setter, time_t Time)
+                       : setter(Setter), mask(Mask), time(Time) { }
+       };
+
+       /** Items stored in the channel's list
+        */
+       typedef std::list<ListItem> ModeList;
+
+ private:
+       class ChanData
+       {
+       public:
+               ModeList list;
+               int maxitems;
+
+               ChanData() : maxitems(-1) { }
+       };
+
+       /** The number of items a listmode's list may contain
+        */
+       struct ListLimit
+       {
+               std::string mask;
+               unsigned int limit;
+               ListLimit(const std::string& Mask, unsigned int Limit) : mask(Mask), limit(Limit) { }
+               bool operator==(const ListLimit& other) const { return (this->mask == other.mask && this->limit == other.limit); }
+       };
+
+       /** Max items per channel by name
+        */
+       typedef std::vector<ListLimit> limitlist;
+
+       /** Finds the limit of modes that can be placed on the given channel name according to the config
+        * @param channame The channel name to find the limit for
+        * @return The maximum number of modes of this type that we allow to be set on the given channel name
+        */
+       unsigned int FindLimit(const std::string& channame);
+
+       /** Returns the limit on the given channel for this mode.
+        * If the limit is cached then the cached value is returned,
+        * otherwise the limit is determined using FindLimit() and cached
+        * for later queries before it is returned
+        * @param channame The channel name to find the limit for
+        * @param cd The ChanData associated with channel channame
+        * @return The maximum number of modes of this type that we allow to be set on the given channel
+        */
+       unsigned int GetLimitInternal(const std::string& channame, ChanData* cd);
+
+ protected:
+       /** Numeric to use when outputting the list
+        */
+       unsigned int listnumeric;
+       /** Numeric to indicate end of list
+        */
+       unsigned int endoflistnumeric;
+       /** String to send for end of list
+        */
+       std::string endofliststring;
+       /** Automatically tidy up entries
+        */
+       bool tidy;
+       /** Config tag to check for max items per channel
+        */
+       std::string configtag;
+       /** Limits on a per-channel basis read from the tag
+        * specified in ListModeBase::configtag
+        */
+       limitlist chanlimits;
+
+       /** Storage key
+        */
+       SimpleExtItem<ChanData> extItem;
+
+ public:
+       /** Constructor.
+        * @param Instance The creator of this class
+        * @param modechar Mode character
+        * @param eolstr End of list string
+        * @param lnum List numeric
+        * @param eolnum End of list numeric
+        * @param autotidy Automatically tidy list entries on add
+        * @param ctag Configuration tag to get limits from
+        */
+       ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag = "banlist");
+
+       /** Get limit of this mode on a channel
+        * @param channel The channel to inspect
+        * @return Maximum number of modes of this type that can be placed on the given channel
+        */
+       unsigned int GetLimit(Channel* channel);
+
+       /** Retrieves the list of all modes set on the given channel
+        * @param channel Channel to get the list from
+        * @return A list with all modes of this type set on the given channel, can be NULL
+        */
+       ModeList* GetList(Channel* channel);
+
+       /** Display the list for this mode
+        * See mode.h
+        * @param user The user to send the list to
+        * @param channel The channel the user is requesting the list for
+        */
+       virtual void DisplayList(User* user, Channel* channel);
+
+       /** Tell a user that a list contains no elements.
+        * Sends 'eolnum' numeric with text 'eolstr', unless overridden (see constructor)
+        * @param user The user issuing the command
+        * @param channel The channel that has the empty list
+        * See mode.h
+        */
+       virtual void DisplayEmptyList(User* user, Channel* channel);
+
+       /** Remove all instances of the mode from a channel.
+        * Populates the given modestack with modes that remove every instance of
+        * this mode from the channel.
+        * See mode.h for more details.
+        * @param channel The channel to remove all instances of the mode from
+        * @param stack The mode stack to add the mode change to
+        */
+       virtual void RemoveMode(Channel* channel, irc::modestacker& stack);
+
+       /** Perform a rehash of this mode's configuration data
+        */
+       virtual void DoRehash();
+
+       /** Populate the Implements list with the correct events for a List Mode
+        */
+       virtual void DoImplements(Module* m);
+
+       /** Handle the list mode.
+        * See mode.h
+        */
+       virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding);
+
+       /** Syncronize channel item list with another server.
+        * See modules.h
+        * @param chan Channel to syncronize
+        * @param proto Protocol module pointer
+        * @param opaque Opaque connection handle
+        */
+       virtual void DoSyncChannel(Channel* chan, Module* proto, void* opaque);
+
+       /** Validate parameters.
+        * Overridden by implementing module.
+        * @param source Source user adding the parameter
+        * @param channel Channel the parameter is being added to
+        * @param parameter The actual parameter being added
+        * @return true if the parameter is valid
+        */
+       virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
+
+       /** Tell the user the list is too long.
+        * Overridden by implementing module.
+        * @param source Source user adding the parameter
+        * @param channel Channel the parameter is being added to
+        * @param parameter The actual parameter being added
+        */
+       virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
+
+       /** Tell the user an item is already on the list.
+        * Overridden by implementing module.
+        * @param source Source user adding the parameter
+        * @param channel Channel the parameter is being added to
+        * @param parameter The actual parameter being added
+        */
+       virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
+
+       /** Tell the user that the parameter is not in the list.
+        * Overridden by implementing module.
+        * @param source Source user removing the parameter
+        * @param channel Channel the parameter is being removed from
+        * @param parameter The actual parameter being removed
+        */
+       virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
+};
+
+inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
+{
+       ChanData* cd = extItem.get(channel);
+       if (!cd)
+               return NULL;
+
+       return &cd->list;
+}
index 0fa4bc7cd029ce7374b3548128c61276d767089f..2ea280be8b429cf596fe3ba6e129ea5c3d930313 100644 (file)
  */
 
 
-#ifndef LOGGER_H
-#define LOGGER_H
+#pragma once
+
+/** Levels at which messages can be logged. */
+enum LogLevel
+{
+       LOG_RAWIO   = 5,
+       LOG_DEBUG   = 10,
+       LOG_VERBOSE = 20,
+       LOG_DEFAULT = 30,
+       LOG_SPARSE  = 40,
+       LOG_NONE    = 50
+};
 
 /** Simple wrapper providing periodic flushing to a disk-backed file.
  */
@@ -77,9 +87,11 @@ class CoreExport FileWriter
 class CoreExport LogStream : public classbase
 {
  protected:
-       int loglvl;
+       LogLevel loglvl;
  public:
-       LogStream(int loglevel) : loglvl(loglevel)
+       static const char LogHeader[];
+
+       LogStream(LogLevel loglevel) : loglvl(loglevel)
        {
        }
 
@@ -91,13 +103,13 @@ class CoreExport LogStream : public classbase
        /** Changes the loglevel for this LogStream on-the-fly.
         * This is needed for -nofork. But other LogStreams could use it to change loglevels.
         */
-       void ChangeLevel(int lvl) { this->loglvl = lvl; }
+       void ChangeLevel(LogLevel lvl) { this->loglvl = lvl; }
 
        /** Called when there is stuff to log for this particular logstream. The derived class may take no action with it, or do what it
         * wants with the output, basically. loglevel and type are primarily for informational purposes (the level and type of the event triggered)
         * and msg is, of course, the actual message to log.
         */
-       virtual void OnLog(int loglevel, const std::string &type, const std::string &msg) = 0;
+       virtual void OnLog(LogLevel loglevel, const std::string &type, const std::string &msg) = 0;
 };
 
 typedef std::map<FileWriter*, int> FileLogMap;
@@ -127,7 +139,6 @@ class CoreExport LogManager
        FileLogMap FileLogs;
 
  public:
-
        LogManager();
        ~LogManager();
 
@@ -199,17 +210,15 @@ class CoreExport LogManager
 
        /** Logs an event, sending it to all LogStreams registered for the type.
         * @param type Log message type (ex: "USERINPUT", "MODULE", ...)
-        * @param loglevel Log message level (DEBUG, VERBOSE, DEFAULT, SPARSE, NONE)
+        * @param loglevel Log message level (LOG_DEBUG, LOG_VERBOSE, LOG_DEFAULT, LOG_SPARSE, LOG_NONE)
         * @param msg The message to be logged (literal).
         */
-       void Log(const std::string &type, int loglevel, const std::string &msg);
+       void Log(const std::string &type, LogLevel loglevel, const std::string &msg);
 
        /** Logs an event, sending it to all LogStreams registered for the type.
         * @param type Log message type (ex: "USERINPUT", "MODULE", ...)
-        * @param loglevel Log message level (DEBUG, VERBOSE, DEFAULT, SPARSE, NONE)
+        * @param loglevel Log message level (LOG_DEBUG, LOG_VERBOSE, LOG_DEFAULT, LOG_SPARSE, LOG_NONE)
         * @param fmt The format of the message to be logged. See your C manual on printf() for details.
         */
-       void Log(const std::string &type, int loglevel, const char *fmt, ...) CUSTOM_PRINTF(4, 5);
+       void Log(const std::string &type, LogLevel loglevel, const char *fmt, ...) CUSTOM_PRINTF(4, 5);
 };
-
-#endif
index 436a9371c5c30ef60505d3be81026d9b4aec016a..5850e0ae0d8e265d46f8bd48e94fa5ecff16048c 100644 (file)
@@ -17,8 +17,7 @@
  */
 
 
-#ifndef MEMBERSHIP_H
-#define MEMBERSHIP_H
+#pragma once
 
 class CoreExport Membership : public Extensible
 {
@@ -46,7 +45,7 @@ class CoreExport InviteBase
        friend class Invitation;
 };
 
-class Invitation : public classbase
+class CoreExport Invitation : public classbase
 {
        Invitation(Channel* c, LocalUser* u, time_t timeout) : user(u), chan(c), expiry(timeout) {}
 
@@ -59,5 +58,3 @@ class Invitation : public classbase
        static void Create(Channel* c, LocalUser* u, time_t timeout);
        static Invitation* Find(Channel* c, LocalUser* u, bool check_expired = true);
 };
-
-#endif
index 1dab442d40ac6d993ae8c8787a89fc93c66e83a1..172b014deb166e4078bb931cb74fc2bd9b8a5bb7 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef MODE_H
-#define MODE_H
+#pragma once
 
 #include "ctables.h"
 
@@ -101,6 +100,13 @@ enum ParamSpec
  */
 class CoreExport ModeHandler : public ServiceProvider
 {
+       /**
+        * Removes this prefix mode from all users on the given channel
+        * @param channel The channel which the server wants to remove your mode from
+        * @param stack The mode stack to add the mode change to
+        */
+       void RemovePrefixMode(Channel* chan, irc::modestacker& stack);
+
  protected:
        /**
         * The mode parameter translation type
@@ -166,7 +172,7 @@ class CoreExport ModeHandler : public ServiceProvider
        /**
         * Returns true if the mode is a list mode
         */
-       bool IsListMode();
+       bool IsListMode() const { return list; }
        /**
         * Mode prefix or 0. If this is defined, you should
         * also implement GetPrefixRank() to return an integer
@@ -269,26 +275,23 @@ class CoreExport ModeHandler : public ServiceProvider
        virtual bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
 
        /**
-        * When a MODETYPE_USER mode handler is being removed, the server will call this method for every user on the server.
-        * Your mode handler should remove its user mode from the user by sending the appropriate server modes using
-        * InspIRCd::SendMode(). The default implementation of this method can remove simple modes which have no parameters,
-        * and can be used when your mode is of this type, otherwise you must implement a more advanced version of it to remove
-        * your mode properly from each user.
+        * When a MODETYPE_USER mode handler is being removed, the core will call this method for every user on the server.
+        * The usermode will be removed using the appropiate server mode using InspIRCd::SendMode().
         * @param user The user which the server wants to remove your mode from
-        * @param stack The mode stack to add the mode change to
         */
-       virtual void RemoveMode(User* user, irc::modestacker* stack = NULL);
+       void RemoveMode(User* user);
 
        /**
         * When a MODETYPE_CHANNEL mode handler is being removed, the server will call this method for every channel on the server.
-        * Your mode handler should remove its user mode from the channel by sending the appropriate server modes using
-        * InspIRCd::SendMode(). The default implementation of this method can remove simple modes which have no parameters,
-        * and can be used when your mode is of this type, otherwise you must implement a more advanced version of it to remove
-        * your mode properly from each channel. Note that in the case of listmodes, you should remove the entire list of items.
+        * The mode handler has to populate the given modestacker with mode changes that remove the mode from the channel.
+        * The default implementation of this method can remove all kinds of channel modes except listmodes.
+        * In the case of listmodes, the entire list of items must be added to the modestacker (which is handled by ListModeBase,
+        * so if you inherit from it or your mode can be removed by the default implementation then you do not have to implement
+        * this function).
         * @param channel The channel which the server wants to remove your mode from
         * @param stack The mode stack to add the mode change to
         */
-       virtual void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
+       virtual void RemoveMode(Channel* channel, irc::modestacker& stack);
 
        inline unsigned int GetLevelRequired() const { return levelrequired; }
 };
@@ -339,11 +342,12 @@ class CoreExport ParamChannelModeHandler : public ModeHandler
  */
 class CoreExport ModeWatcher : public classbase
 {
- protected:
+ private:
        /**
-        * The mode letter this class is watching
+        * The mode name this class is watching
         */
-       char mode;
+       const std::string mode;
+
        /**
         * The mode type being watched (user or channel)
         */
@@ -354,17 +358,18 @@ class CoreExport ModeWatcher : public classbase
        /**
         * The constructor initializes the mode and the mode type
         */
-       ModeWatcher(Module* creator, char modeletter, ModeType type);
+       ModeWatcher(Module* creator, const std::string& modename, ModeType type);
        /**
         * The default destructor does nothing.
         */
        virtual ~ModeWatcher();
 
        /**
-        * Get the mode character being watched
-        * @return The mode character being watched
+        * Get the mode name being watched
+        * @return The mode name being watched
         */
-       char GetModeChar();
+       const std::string& GetModeName() const { return mode; }
+
        /**
         * Get the mode type being watched
         * @return The mode type being watched (user or channel)
@@ -380,11 +385,10 @@ class CoreExport ModeWatcher : public classbase
         * If you alter the parameter you are given, the mode handler will see your atered version
         * when it handles the mode.
         * @param adding True if the mode is being added and false if it is being removed
-        * @param type The mode type, either MODETYPE_USER or MODETYPE_CHANNEL
         * @return True to allow the mode change to go ahead, false to abort it. If you abort the
         * change, the mode handler (and ModeWatcher::AfterMode()) will never see the mode change.
         */
-       virtual bool BeforeMode(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, ModeType type);
+       virtual bool BeforeMode(User* source, User* dest, Channel* channel, std::string& parameter, bool adding);
        /**
         * After the mode character has been processed by the ModeHandler, this method will be called.
         * @param source The sender of the mode
@@ -393,12 +397,11 @@ class CoreExport ModeWatcher : public classbase
         * @param parameter The parameter of the mode, if the mode is supposed to have a parameter.
         * You cannot alter the parameter here, as the mode handler has already processed it.
         * @param adding True if the mode is being added and false if it is being removed
-        * @param type The mode type, either MODETYPE_USER or MODETYPE_CHANNEL
         */
-       virtual void AfterMode(User* source, User* dest, Channel* channel, const std::string &parameter, bool adding, ModeType type);
+       virtual void AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding);
 };
 
-typedef std::vector<ModeWatcher*>::iterator ModeWatchIter;
+typedef std::multimap<std::string, ModeWatcher*>::iterator ModeWatchIter;
 
 /** The mode parser handles routing of modes and handling of mode strings.
  * It marshalls, controls and maintains both ModeWatcher and ModeHandler classes,
@@ -414,11 +417,11 @@ class CoreExport ModeParser
         * or a channel mode, so we have 256 of them not 64.
         */
        ModeHandler* modehandlers[256];
-       /** Mode watcher classes arranged in the same way as the
-        * mode handlers, except for instead of having 256 of them
-        * we have 256 lists of them.
+
+       /** Mode watcher classes
         */
-       std::vector<ModeWatcher*> modewatchers[256];
+       std::multimap<std::string, ModeWatcher*> modewatchermap;
+
        /** Displays the current modes of a channel or user.
         * Used by ModeParser::Process.
         */
@@ -433,6 +436,20 @@ class CoreExport ModeParser
         */
        ModeAction TryMode(User* user, User* targu, Channel* targc, bool adding, unsigned char mode, std::string &param, bool SkipACL);
 
+       /** Returns a list of user or channel mode characters.
+        * Used for constructing the parts of the mode list in the 004 numeric.
+        * @param mt Controls whether to list user modes or channel modes
+        * @param needparam Return modes only if they require a parameter to be set
+        * @return The available mode letters that satisfy the given conditions
+        */
+       std::string CreateModeList(ModeType mt, bool needparam = false);
+
+       /** Recreate the cached mode list that is displayed in the 004 numeric
+        * in Cached004ModeList.
+        * Called when a mode handler is added or removed.
+        */
+       void RecreateModeListFor004Numeric();
+
        /** The string representing the last set of modes to be parsed.
         * Use GetLastParse() to get this value, to be used for  display purposes.
         */
@@ -444,17 +461,18 @@ class CoreExport ModeParser
 
        unsigned int seq;
 
- public:
-
-       /** The constructor initializes all the RFC basic modes by using ModeParserAddMode().
+       /** Cached mode list for use in 004 numeric
         */
+       std::string Cached004ModeList;
+
+ public:
        ModeParser();
        ~ModeParser();
 
-       /** Used to check if user 'd' should be allowed to do operation 'MASK' on channel 'chan'.
-        * for example, should 'user A' be able to 'op' on 'channel B'.
+       /** Initialize all built-in modes
         */
-       User* SanityChecks(User *user,const char *dest,Channel *chan,int status);
+       static void InitBuiltinModes();
+
        /** Tidy a banmask. This makes a banmask 'acceptable' if fields are left out.
         * E.g.
         *
@@ -474,7 +492,7 @@ class CoreExport ModeParser
         * may be different to what you sent after it has been 'cleaned up' by the parser.
         * @return Last parsed string, as seen by users.
         */
-       const std::string& GetLastParse();
+       const std::string& GetLastParse() const { return LastParse; }
        const std::vector<std::string>& GetLastParseParams() { return LastParseParams; }
        const std::vector<TranslateType>& GetLastParseTranslate() { return LastParseTranslate; }
        /** Add a mode to the mode parser.
@@ -496,9 +514,9 @@ class CoreExport ModeParser
         * triggered. See the documentation of class ModeWatcher for more
         * information.
         * @param mw The ModeWatcher you want to add
-        * @return True if the ModeWatcher was added correctly
         */
-       bool AddModeWatcher(ModeWatcher* mw);
+       void AddModeWatcher(ModeWatcher* mw);
+
        /** Delete a mode watcher.
         * A mode watcher is triggered before and after a mode handler is
         * triggered. See the documentation of class ModeWatcher for more
@@ -531,20 +549,13 @@ class CoreExport ModeParser
         */
        ModeHandler* FindPrefix(unsigned const char pfxletter);
 
-       /** Returns a list of mode characters which are usermodes.
-        * This is used in the 004 numeric when users connect.
-        */
-       std::string UserModeList();
-
-       /** Returns a list of channel mode characters which are listmodes.
-        * This is used in the 004 numeric when users connect.
+       /** Returns a list of modes, space seperated by type:
+        * 1. User modes
+        * 2. Channel modes
+        * 3. Channel modes that require a parameter when set
+        * This is sent to users as the last part of the 004 numeric
         */
-       std::string ChannelModeList();
-
-       /** Returns a list of channel mode characters which take parameters.
-        * This is used in the 004 numeric when users connect.
-        */
-       std::string ParaModeList();
+       const std::string& GetModeListFor004Numeric();
 
        /** Generates a list of modes, comma seperated by type:
         *  1; Listmodes EXCEPT those with a prefix
@@ -554,12 +565,13 @@ class CoreExport ModeParser
         */
        std::string GiveModeList(ModeMasks m);
 
-       static bool PrefixComparison(ModeHandler* one, ModeHandler* two);
-
        /** This returns the PREFIX=(ohv)@%+ section of the 005 numeric, or
         * just the "@%+" part if the parameter false
         */
        std::string BuildPrefixes(bool lettersAndModes = true);
 };
 
-#endif
+inline const std::string& ModeParser::GetModeListFor004Numeric()
+{
+       return Cached004ModeList;
+}
diff --git a/include/modes/cmode_b.h b/include/modes/cmode_b.h
deleted file mode 100644 (file)
index afd5cd1..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "mode.h"
-#include "channels.h"
-
-class InspIRCd;
-
-/** Channel mode +b
- */
-class ModeChannelBan : public ModeHandler
-{
- private:
-       BanItem b;
- public:
-       ModeChannelBan();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
-       std::string& AddBan(User *user,std::string& dest,Channel *chan,int status);
-       std::string& DelBan(User *user,std::string& dest,Channel *chan,int status);
-       void DisplayList(User* user, Channel* channel);
-       void DisplayEmptyList(User* user, Channel* channel);
-       void RemoveMode(User* user, irc::modestacker* stack = NULL);
-       void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
-};
-
diff --git a/include/modes/cmode_k.h b/include/modes/cmode_k.h
deleted file mode 100644 (file)
index 000667f..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "mode.h"
-
-class InspIRCd;
-
-/** Channel mode +k
- */
-class ModeChannelKey : public ModeHandler
-{
- public:
-       ModeChannelKey();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
-       void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
-       void RemoveMode(User* user, irc::modestacker* stack = NULL);
-};
diff --git a/include/modes/cmode_l.h b/include/modes/cmode_l.h
deleted file mode 100644 (file)
index 3018a0d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "mode.h"
-
-/** Channel mode +l
- */
-class ModeChannelLimit : public ParamChannelModeHandler
-{
- public:
-       ModeChannelLimit();
-       bool ParamValidate(std::string& parameter);
-       bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
-};
diff --git a/include/modes/cmode_o.h b/include/modes/cmode_o.h
deleted file mode 100644 (file)
index c5f1764..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "mode.h"
-#include "channels.h"
-
-class InspIRCd;
-
-/** Channel mode +o
- */
-class ModeChannelOp : public ModeHandler
-{
- private:
- public:
-       ModeChannelOp();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
-       unsigned int GetPrefixRank();
-       void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
-       void RemoveMode(User* user, irc::modestacker* stack = NULL);
-};
-
diff --git a/include/modes/cmode_v.h b/include/modes/cmode_v.h
deleted file mode 100644 (file)
index ab037f3..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "mode.h"
-#include "channels.h"
-
-class InspIRCd;
-
-/** Channel mode +v
- */
-class ModeChannelVoice : public ModeHandler
-{
- private:
- public:
-       ModeChannelVoice();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
-       unsigned int GetPrefixRank();
-       void RemoveMode(User* user, irc::modestacker* stack = NULL);
-       void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
-};
-
diff --git a/include/modes/simplemodes.h b/include/modes/simplemodes.h
deleted file mode 100644 (file)
index 661bba4..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "mode.h"
-
-/** Channel mode +i
- */
-class ModeChannelInviteOnly : public SimpleChannelModeHandler
-{
- public:
-       ModeChannelInviteOnly() : SimpleChannelModeHandler(NULL, "inviteonly", 'i')
-       {
-       }
-};
-
-/** Channel mode +m
- */
-class ModeChannelModerated : public SimpleChannelModeHandler
-{
- public:
-       ModeChannelModerated() : SimpleChannelModeHandler(NULL, "moderated", 'm')
-       {
-       }
-};
-
-/** Channel mode +n
- */
-class ModeChannelNoExternal : public SimpleChannelModeHandler
-{
- public:
-       ModeChannelNoExternal() : SimpleChannelModeHandler(NULL, "noextmsg", 'n')
-       {
-       }
-};
-
-/** Channel mode +p
- */
-class ModeChannelPrivate : public SimpleChannelModeHandler
-{
- public:
-       ModeChannelPrivate() : SimpleChannelModeHandler(NULL, "private", 'p')
-       {
-       }
-};
-
-/** Channel mode +s
- */
-class ModeChannelSecret : public SimpleChannelModeHandler
-{
- public:
-       ModeChannelSecret() : SimpleChannelModeHandler(NULL, "secret", 's')
-       {
-       }
-};
-
-/** Channel mode +t
- */
-class ModeChannelTopicOps : public SimpleChannelModeHandler
-{
- public:
-       ModeChannelTopicOps() : SimpleChannelModeHandler(NULL, "topiclock", 't')
-       {
-       }
-};
-      
-/** User mode +i
- */
-class ModeUserInvisible : public SimpleUserModeHandler
-{
- public:
-       ModeUserInvisible() : SimpleUserModeHandler(NULL, "invisible", 'i')
-       {
-       }
-};
-
-/** User mode +w
- */
-class ModeUserWallops : public SimpleUserModeHandler
-{
- public:
-       ModeUserWallops() : SimpleUserModeHandler(NULL, "wallops", 'w')
-       {
-       }
-};
diff --git a/include/modes/umode_o.h b/include/modes/umode_o.h
deleted file mode 100644 (file)
index f9644a0..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "mode.h"
-
-class InspIRCd;
-
-/** User mode +o
- */
-class ModeUserOperator : public ModeHandler
-{
- public:
-       ModeUserOperator();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
-};
diff --git a/include/modes/umode_s.h b/include/modes/umode_s.h
deleted file mode 100644 (file)
index 8ac8fa3..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "mode.h"
-
-class InspIRCd;
-
-/** User mode +n
- */
-class ModeUserServerNoticeMask : public ModeHandler
-{
- public:
-       ModeUserServerNoticeMask();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
-       void OnParameterMissing(User* user, User* dest, Channel* channel);
-       std::string GetUserParameter(User* user);
-};
index 00f2cbb62f45cff1b4e4fd259ff2be2af938d2d6..95902536736de7ccee4b7f61a166a4ee6408b7d7 100644 (file)
@@ -23,8 +23,7 @@
  */
 
 
-#ifndef MODULES_H
-#define MODULES_H
+#pragma once
 
 #include "dynamic.h"
 #include "base.h"
@@ -35,7 +34,6 @@
 #include <sstream>
 #include "timer.h"
 #include "mode.h"
-#include "dns.h"
 
 /** Used to define a set of behavior bits for a module
  */
@@ -109,14 +107,14 @@ struct ModResult {
 /** InspIRCd major version.
  * 1.2 -> 102; 2.1 -> 201; 2.12 -> 212
  */
-#define INSPIRCD_VERSION_MAJ 200
+#define INSPIRCD_VERSION_MAJ 202
 /** InspIRCd API version.
  * If you change any API elements, increment this value. This counter should be
  * reset whenever the major version is changed. Modules can use these two values
  * and numerical comparisons in preprocessor macros if they wish to support
  * multiple versions of InspIRCd in one file.
  */
-#define INSPIRCD_VERSION_API 6
+#define INSPIRCD_VERSION_API 1
 
 /**
  * This #define allows us to call a method in all
@@ -135,7 +133,7 @@ struct ModResult {
                } \
                catch (CoreException& modexcept) \
                { \
-                       ServerInstance->Logs->Log("MODULE",DEFAULT,"Exception caught: %s",modexcept.GetReason()); \
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s",modexcept.GetReason()); \
                } \
                _i = safei; \
        } \
@@ -162,7 +160,7 @@ do { \
                } \
                catch (CoreException& except_ ## n) \
                { \
-                       ServerInstance->Logs->Log("MODULE",DEFAULT,"Exception caught: %s", (except_ ## n).GetReason()); \
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s", (except_ ## n).GetReason()); \
                        (void) mod_ ## n; /* catch mismatched pairs */ \
                } \
        } \
@@ -286,32 +284,68 @@ class CoreExport dynamic_reference_base : public interfacebase
 {
  private:
        std::string name;
+       void resolve();
  protected:
-       DataProvider* value;
+       ServiceProvider* value;
  public:
        ModuleRef creator;
        dynamic_reference_base(Module* Creator, const std::string& Name);
        ~dynamic_reference_base();
-       inline void ClearCache() { value = NULL; }
        inline const std::string& GetProvider() { return name; }
        void SetProvider(const std::string& newname);
-       void lookup();
-       operator bool();
+       void check();
+       operator bool() { return (value != NULL); }
        static void reset_all();
 };
 
+inline void dynamic_reference_base::check()
+{
+       if (!value)
+               throw ModuleException("Dynamic reference to '" + name + "' failed to resolve");
+}
+
 template<typename T>
 class dynamic_reference : public dynamic_reference_base
 {
  public:
        dynamic_reference(Module* Creator, const std::string& Name)
                : dynamic_reference_base(Creator, Name) {}
+
        inline T* operator->()
        {
-               if (!value)
-                       lookup();
+               check();
                return static_cast<T*>(value);
        }
+
+       T* operator*()
+       {
+               return operator->();
+       }
+};
+
+template<typename T>
+class dynamic_reference_nocheck : public dynamic_reference_base
+{
+ public:
+       dynamic_reference_nocheck(Module* Creator, const std::string& Name)
+               : dynamic_reference_base(Creator, Name) {}
+
+       T* operator->()
+       {
+               return static_cast<T*>(value);
+       }
+
+       T* operator*()
+       {
+               return operator->();
+       }
+};
+
+class ModeReference : public dynamic_reference_nocheck<ModeHandler>
+{
+ public:
+       ModeReference(Module* mod, const std::string& modename)
+               : dynamic_reference_nocheck<ModeHandler>(mod, "mode/" + modename) {}
 };
 
 /** Priority types which can be used by Module::Prioritize()
@@ -325,16 +359,16 @@ enum Implementation
        I_BEGIN,
        I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnRehash,
        I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois,
-       I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreNick,
-       I_OnUserMessage, I_OnUserNotice, I_OnMode, I_OnGetServerDescription, I_OnSyncUser,
-       I_OnSyncChannel, I_OnDecodeMetaData, I_OnWallops, I_OnAcceptConnection, I_OnUserInit,
+       I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNick,
+       I_OnUserMessage, I_OnMode, I_OnGetServerDescription, I_OnSyncUser,
+       I_OnSyncChannel, I_OnDecodeMetaData, I_OnAcceptConnection, I_OnUserInit,
        I_OnChangeHost, I_OnChangeName, I_OnAddLine, I_OnDelLine, I_OnExpireLine,
        I_OnUserPostNick, I_OnPreMode, I_On005Numeric, I_OnKill, I_OnRemoteKill, I_OnLoadModule,
        I_OnUnloadModule, I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnCheckInvite,
        I_OnRawMode, I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnCheckChannelBan, I_OnExtBanCheck,
        I_OnStats, I_OnChangeLocalUserHost, I_OnPreTopicChange,
-       I_OnPostTopicChange, I_OnEvent, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan,
-       I_OnDelBan, I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete,
+       I_OnPostTopicChange, I_OnEvent, I_OnGlobalOper, I_OnPostConnect,
+       I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete,
        I_OnPostOper, I_OnSyncNetwork, I_OnSetAway, I_OnPostCommand, I_OnPostJoin,
        I_OnWhoisLine, I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass,
        I_OnText, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookIO,
@@ -514,7 +548,7 @@ class CoreExport Module : public classbase, public usecountbase
         * @param keygiven The key given to join the channel, or an empty string if none was provided
         * @return 1 To prevent the join, 0 to allow it.
         */
-       virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven);
+       virtual ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven);
 
        /** Called whenever a user is about to be kicked.
         * Returning a value of 1 from this function stops the process immediately, causing no
@@ -611,30 +645,10 @@ class CoreExport Module : public classbase, public usecountbase
         * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
         * @param exempt_list A list of users not to send to. For channel messages, this will usually contain just the sender.
         * It will be ignored for private messages.
+        * @param msgtype The message type, MSG_PRIVMSG for PRIVMSGs, MSG_NOTICE for NOTICEs
         * @return 1 to deny the message, 0 to allow it
         */
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list);
-
-       /** Called whenever a user is about to NOTICE A user or a channel, before any processing is done.
-        * Returning any nonzero value from this function stops the process immediately, causing no
-        * output to be sent to the user by the core. If you do this you must produce your own numerics,
-        * notices etc. This is useful for modules which may want to filter or redirect messages.
-        * target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user,
-        * you must cast dest to a User* otherwise you must cast it to a Channel*, this is the details
-        * of where the message is destined to be sent.
-        * You may alter the message text as you wish before relinquishing control to the next module
-        * in the chain, and if no other modules block the text this altered form of the text will be sent out
-        * to the user and possibly to other servers.
-        * @param user The user sending the message
-        * @param dest The target of the message (Channel* or User*)
-        * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
-        * @param text Changeable text being sent by the user
-        * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
-        * @param exempt_list A list of users not to send to. For channel notices, this will usually contain just the sender.
-        * It will be ignored for private notices.
-        * @return 1 to deny the NOTICE, 0 to allow it
-        */
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list);
+       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list, MessageType msgtype);
 
        /** Called when sending a message to all "neighbors" of a given user -
         * that is, all users that share a common channel. This is used in
@@ -668,25 +682,14 @@ class CoreExport Module : public classbase, public usecountbase
         * @param text the text being sent by the user
         * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone.
         * @param exempt_list A list of users to not send to.
+        * @param msgtype The message type, MSG_PRIVMSG for PRIVMSGs, MSG_NOTICE for NOTICEs
         */
-       virtual void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list);
-
-       /** Called after any NOTICE sent from a user.
-        * The dest variable contains a User* if target_type is TYPE_USER and a Channel*
-        * if target_type is TYPE_CHANNEL.
-        * @param user The user sending the message
-        * @param dest The target of the message
-        * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL)
-        * @param text the text being sent by the user
-        * @param status The status being used, e.g. NOTICE @#chan has status== '@', 0 to send to everyone.
-        * @param exempt_list A list of users to not send to.
-        */
-       virtual void OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list);
+       virtual void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, MessageType msgtype);
 
        /** Called immediately before any NOTICE or PRIVMSG sent from a user, local or remote.
         * The dest variable contains a User* if target_type is TYPE_USER and a Channel*
         * if target_type is TYPE_CHANNEL.
-        * The difference between this event and OnUserPreNotice/OnUserPreMessage is that delivery is gauranteed,
+        * The difference between this event and OnUserPreMessage is that delivery is gauranteed,
         * the message has already been vetted. In the case of the other two methods, a later module may stop your
         * message. This also differs from OnUserMessage which occurs AFTER the message has been sent.
         * @param user The user sending the message
@@ -741,8 +744,6 @@ class CoreExport Module : public classbase, public usecountbase
         * (see below). This function will be called for every user visible on your side
         * of the burst, allowing you to for example set modes, etc.
         *
-        * For a good example of how to use this function, please see src/modules/m_chanprotect.cpp
-        *
         * @param chan The channel being syncronized
         * @param proto A pointer to the module handling network protocol
         * @param opaque An opaque pointer set by the protocol module, should not be modified!
@@ -775,9 +776,6 @@ class CoreExport Module : public classbase, public usecountbase
         * down the network link as a broadcast, without a module calling it having to know the format
         * of the MODE command before the actual mode string.
         *
-        * More documentation to follow soon. Please see src/modules/m_chanprotect.cpp for examples
-        * of how to use this function.
-        *
         * @param opaque An opaque pointer set by the protocol module, should not be modified!
         * @param target_type The type of item to decode data for, TYPE_USER or TYPE_CHANNEL
         * @param target The Channel* or User* that modes should be sent for
@@ -801,12 +799,6 @@ class CoreExport Module : public classbase, public usecountbase
         */
        virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
 
-       /** Called after every WALLOPS command.
-        * @param user The user sending the WALLOPS
-        * @param text The content of the WALLOPS message
-        */
-       virtual void OnWallops(User* user, const std::string &text);
-
        /** Called whenever a user's hostname is changed.
         * This event triggers after the host has been set.
         * @param user The user whos host is being changed
@@ -885,9 +877,9 @@ class CoreExport Module : public classbase, public usecountbase
 
        /** Called when a 005 numeric is about to be output.
         * The module should modify the 005 numeric if needed to indicate its features.
-        * @param output The 005 string to be modified if neccessary.
-        */
-       virtual void On005Numeric(std::string &output);
+       * @param output The 005 map to be modified if neccessary.
+       */
+       virtual void On005Numeric(std::map<std::string, std::string>& tokens);
 
        /** Called when a client is disconnected by KILL.
         * If a client is killed by a server, e.g. a nickname collision or protocol error,
@@ -1162,24 +1154,6 @@ class CoreExport Module : public classbase, public usecountbase
         */
        virtual void OnPostConnect(User* user);
 
-       /** Called whenever a ban is added to a channel's list.
-        * Return a non-zero value to 'eat' the mode change and prevent the ban from being added.
-        * @param source The user adding the ban
-        * @param channel The channel the ban is being added to
-        * @param banmask The ban mask being added
-        * @return 1 to block the ban, 0 to continue as normal
-        */
-       virtual ModResult OnAddBan(User* source, Channel* channel,const std::string &banmask);
-
-       /** Called whenever a ban is removed from a channel's list.
-        * Return a non-zero value to 'eat' the mode change and prevent the ban from being removed.
-        * @param source The user deleting the ban
-        * @param channel The channel the ban is being deleted from
-        * @param banmask The ban mask being deleted
-        * @return 1 to block the unban, 0 to continue as normal
-        */
-       virtual ModResult OnDelBan(User* source, Channel* channel,const std::string &banmask);
-
        /** Called to install an I/O hook on an event handler
         * @param user The socket to possibly install the I/O hook on
         * @param via The port that the user connected on
@@ -1301,171 +1275,42 @@ class CoreExport Module : public classbase, public usecountbase
        virtual void OnSetUserIP(LocalUser* user);
 };
 
-
-#define CONF_NO_ERROR          0x000000
-#define CONF_NOT_A_NUMBER      0x000010
-#define CONF_INT_NEGATIVE      0x000080
-#define CONF_VALUE_NOT_FOUND   0x000100
-#define CONF_FILE_NOT_FOUND    0x000200
-
-
-/** Allows reading of values from configuration files
- * This class allows a module to read from either the main configuration file (inspircd.conf) or from
- * a module-specified configuration file. It may either be instantiated with one parameter or none.
- * Constructing the class using one parameter allows you to specify a path to your own configuration
- * file, otherwise, inspircd.conf is read.
- */
-class CoreExport ConfigReader : public interfacebase
-{
-  protected:
-       /** Error code
-        */
-       long error;
-
-  public:
-       /** Default constructor.
-        * This constructor initialises the ConfigReader class to read the inspircd.conf file
-        * as specified when running ./configure.
-        */
-       ConfigReader();
-       /** Default destructor.
-        * This method destroys the ConfigReader class.
-        */
-       ~ConfigReader();
-
-       /** Retrieves a value from the config file.
-        * This method retrieves a value from the config file. Where multiple copies of the tag
-        * exist in the config file, index indicates which of the values to retrieve.
-        */
-       std::string ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds = false);
-       /** Retrieves a value from the config file.
-        * This method retrieves a value from the config file. Where multiple copies of the tag
-        * exist in the config file, index indicates which of the values to retrieve. If the
-        * tag is not found the default value is returned instead.
-        */
-       std::string ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds = false);
-
-       /** Retrieves a boolean value from the config file.
-        * This method retrieves a boolean value from the config file. Where multiple copies of the tag
-        * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes"
-        * and "true" in the config file count as true to ReadFlag, and any other value counts as false.
-        */
-       bool ReadFlag(const std::string &tag, const std::string &name, int index);
-       /** Retrieves a boolean value from the config file.
-        * This method retrieves a boolean value from the config file. Where multiple copies of the tag
-        * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes"
-        * and "true" in the config file count as true to ReadFlag, and any other value counts as false.
-        * If the tag is not found, the default value is used instead.
-        */
-       bool ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index);
-
-       /** Retrieves an integer value from the config file.
-        * This method retrieves an integer value from the config file. Where multiple copies of the tag
-        * exist in the config file, index indicates which of the values to retrieve. Any invalid integer
-        * values in the tag will cause the objects error value to be set, and any call to GetError() will
-        * return CONF_INVALID_NUMBER to be returned. need_positive is set if the number must be non-negative.
-        * If a negative number is placed into a tag which is specified positive, 0 will be returned and GetError()
-        * will return CONF_INT_NEGATIVE. Note that need_positive is not suitable to get an unsigned int - you
-        * should cast the result to achieve that effect.
-        */
-       int ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive);
-       /** Retrieves an integer value from the config file.
-        * This method retrieves an integer value from the config file. Where multiple copies of the tag
-        * exist in the config file, index indicates which of the values to retrieve. Any invalid integer
-        * values in the tag will cause the objects error value to be set, and any call to GetError() will
-        * return CONF_INVALID_NUMBER to be returned. needs_unsigned is set if the number must be unsigned.
-        * If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError()
-        * will return CONF_NOT_UNSIGNED. If the tag is not found, the default value is used instead.
-        */
-       int ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive);
-
-       /** Returns the last error to occur.
-        * Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition.
-        * A call to GetError() resets the error flag back to 0.
-        */
-       long GetError();
-
-       /** Counts the number of times a given tag appears in the config file.
-        * This method counts the number of times a tag appears in a config file, for use where
-        * there are several tags of the same kind, e.g. with opers and connect types. It can be
-        * used with the index value of ConfigReader::ReadValue to loop through all copies of a
-        * multiple instance tag.
-        */
-       int Enumerate(const std::string &tag);
-};
-
-
-
-/** Caches a text file into memory and can be used to retrieve lines from it.
- * This class contains methods for read-only manipulation of a text file in memory.
- * Either use the constructor type with one parameter to load a file into memory
- * at construction, or use the LoadFile method to load a file.
- */
+/** Provides an easy method of reading a text file into memory. */
 class CoreExport FileReader : public classbase
 {
-       /** The file contents
+       /** The lines of text in the file.
         */
-       std::vector<std::string> fc;
+       std::vector<std::string> lines;
 
        /** Content size in bytes
         */
-       unsigned long contentsize;
-
-       /** Calculate content size in bytes
-        */
-       void CalcSize();
+       unsigned long totalSize;
 
  public:
-       /** Default constructor.
-        * This method does not load any file into memory, you must use the LoadFile method
-        * after constructing the class this way.
+       /** Initializes a new file reader.
         */
-       FileReader();
+       FileReader() : totalSize(0) { }
 
-       /** Secondary constructor.
-        * This method initialises the class with a file loaded into it ready for GetLine and
-        * and other methods to be called. If the file could not be loaded, FileReader::FileSize
-        * returns 0.
+       /** Initializes a new file reader and reads the specified file.
+        * @param file The file to read into memory.
         */
-       FileReader(const std::string &filename);
+       FileReader(const std::stringfilename);
 
-       /** Default destructor.
-        * This deletes the memory allocated to the file.
-        */
-       ~FileReader();
-
-       /** Used to load a file.
-        * This method loads a file into the class ready for GetLine and
-        * and other methods to be called. If the file could not be loaded, FileReader::FileSize
-        * returns 0.
-        */
-       void LoadFile(const std::string &filename);
-
-       /** Returns the whole content of the file as std::string
+       /** Loads a text file from disk.
+        * @param filename The file to read into memory.
+        * @throw CoreException The file can not be loaded.
         */
-       std::string Contents();
+       void Load(const std::string& filename);
 
-       /** Returns the entire size of the file as std::string
+       /** Retrieves the entire contents of the file cache as a single string.
         */
-       unsigned long ContentSize();
+       std::string GetString();
 
-       /** Returns true if the file exists
-        * This function will return false if the file could not be opened.
+       /** Retrieves the entire contents of the file cache as a vector of strings.
         */
-       bool Exists();
+       const std::vector<std::string>& GetVector() { return lines; }
 
-       /** Retrieve one line from the file.
-        * This method retrieves one line from the text file. If an empty non-NULL string is returned,
-        * the index was out of bounds, or the line had no data on it.
-        */
-       std::string GetLine(int x);
-
-       /** Returns the size of the file in lines.
-        * This method returns the number of lines in the read file. If it is 0, no lines have been
-        * read into memory, either because the file is empty or it does not exist, or cannot be
-        * opened due to permission problems.
-        */
-       int FileSize();
+       unsigned long TotalSize() { return totalSize; }
 };
 
 /** A list of modules
@@ -1732,5 +1577,3 @@ struct AllModuleList {
 #define COMMAND_INIT(c) MODULE_INIT(CommandModule<c>)
 
 #endif
-
-#endif
diff --git a/include/modules/account.h b/include/modules/account.h
new file mode 100644 (file)
index 0000000..c00b044
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include <map>
+#include <string>
+
+class AccountEvent : public Event
+{
+ public:
+       User* const user;
+       const std::string account;
+       AccountEvent(Module* me, User* u, const std::string& name)
+               : Event(me, "account_login"), user(u), account(name)
+       {
+       }
+};
+
+typedef StringExtItem AccountExtItem;
+
+inline AccountExtItem* GetAccountExtItem()
+{
+       return static_cast<AccountExtItem*>(ServerInstance->Extensions.GetItem("accountname"));
+}
diff --git a/include/modules/cap.h b/include/modules/cap.h
new file mode 100644 (file)
index 0000000..2ed8df4
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+class CapEvent : public Event
+{
+ public:
+       enum CapEventType
+       {
+               CAPEVENT_REQ,
+               CAPEVENT_LS,
+               CAPEVENT_LIST,
+               CAPEVENT_CLEAR
+       };
+
+       CapEventType type;
+       std::vector<std::string> wanted;
+       std::vector<std::string> ack;
+       User* user;
+       CapEvent(Module* sender, User* u, CapEventType capevtype) : Event(sender, "cap_request"), type(capevtype), user(u) {}
+};
+
+class GenericCap
+{
+ public:
+       LocalIntExt ext;
+       const std::string cap;
+       GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
+       {
+               ServerInstance->Modules->AddService(ext);
+       }
+
+       void HandleEvent(Event& ev)
+       {
+               if (ev.id != "cap_request")
+                       return;
+
+               CapEvent *data = static_cast<CapEvent*>(&ev);
+               if (data->type == CapEvent::CAPEVENT_REQ)
+               {
+                       for (std::vector<std::string>::iterator it = data->wanted.begin(); it != data->wanted.end(); ++it)
+                       {
+                               if (it->empty())
+                                       continue;
+                               bool enablecap = ((*it)[0] != '-');
+                               if (((enablecap) && (*it == cap)) || (*it == "-" + cap))
+                               {
+                                       // we can handle this, so ACK it, and remove it from the wanted list
+                                       data->ack.push_back(*it);
+                                       data->wanted.erase(it);
+                                       ext.set(data->user, enablecap ? 1 : 0);
+                                       break;
+                               }
+                       }
+               }
+               else if (data->type == CapEvent::CAPEVENT_LS)
+               {
+                       data->wanted.push_back(cap);
+               }
+               else if (data->type == CapEvent::CAPEVENT_LIST)
+               {
+                       if (ext.get(data->user))
+                               data->wanted.push_back(cap);
+               }
+               else if (data->type == CapEvent::CAPEVENT_CLEAR)
+               {
+                       data->ack.push_back("-" + cap);
+                       ext.set(data->user, 0);
+               }
+       }
+};
+
diff --git a/include/modules/dns.h b/include/modules/dns.h
new file mode 100644 (file)
index 0000000..65a1762
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2013 Adam <Adam@anope.org>
+ *   Copyright (C) 2003-2013 Anope Team <team@anope.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+namespace DNS
+{
+       /** Valid query types
+        */
+       enum QueryType
+       {
+               /* Nothing */
+               QUERY_NONE,
+               /* A simple A lookup */
+               QUERY_A = 1,
+               /* A CNAME lookup */
+               QUERY_CNAME = 5,
+               /* Reverse DNS lookup */
+               QUERY_PTR = 12,
+               /* IPv6 AAAA lookup */
+               QUERY_AAAA = 28
+       };
+
+       /** Flags that can be AND'd into DNSPacket::flags to receive certain values
+        */
+       enum
+       {
+               QUERYFLAGS_QR = 0x8000,
+               QUERYFLAGS_OPCODE = 0x7800,
+               QUERYFLAGS_AA = 0x400,
+               QUERYFLAGS_TC = 0x200,
+               QUERYFLAGS_RD = 0x100,
+               QUERYFLAGS_RA = 0x80,
+               QUERYFLAGS_Z = 0x70,
+               QUERYFLAGS_RCODE = 0xF
+       };
+
+       enum Error
+       {
+               ERROR_NONE,
+               ERROR_UNKNOWN,
+               ERROR_UNLOADED,
+               ERROR_TIMEDOUT,
+               ERROR_NOT_AN_ANSWER,
+               ERROR_NONSTANDARD_QUERY,
+               ERROR_FORMAT_ERROR,
+               ERROR_SERVER_FAILURE,
+               ERROR_DOMAIN_NOT_FOUND,
+               ERROR_NOT_IMPLEMENTED,
+               ERROR_REFUSED,
+               ERROR_NO_RECORDS,
+               ERROR_INVALIDTYPE
+       };
+
+       const int PORT = 53;
+
+       /**
+        * The maximum value of a dns request id,
+        * 16 bits wide, 0xFFFF.
+        */
+       const int MAX_REQUEST_ID = 0xFFFF;
+
+       class Exception : public ModuleException
+       {
+        public:
+               Exception(const std::string& message) : ModuleException(message) { }
+       };
+
+       struct Question
+       {
+               std::string name;
+               QueryType type;
+               unsigned short qclass;
+
+               Question() : type(QUERY_NONE), qclass(0) { }
+               Question(const std::string& n, QueryType t, unsigned short c = 1) : name(n), type(t), qclass(c) { }
+               inline bool operator==(const Question& other) const { return name == other.name && type == other.type && qclass == other.qclass; }
+
+               struct hash
+               {
+                       size_t operator()(const Question& question) const
+                       {
+                               return irc::insensitive()(question.name);
+                       }
+               };
+       };
+
+       struct ResourceRecord : Question
+       {
+               unsigned int ttl;
+               std::string rdata;
+               time_t created;
+
+               ResourceRecord(const std::string& n, QueryType t, unsigned short c = 1) : Question(n, t, c), ttl(0), created(ServerInstance->Time()) { }
+               ResourceRecord(const Question& question) : Question(question), ttl(0), created(ServerInstance->Time()) { }
+       };
+
+       struct Query
+       {
+               std::vector<Question> questions;
+               std::vector<ResourceRecord> answers;
+               Error error;
+               bool cached;
+
+               Query() : error(ERROR_NONE), cached(false) { }
+               Query(const Question& question) : error(ERROR_NONE), cached(false) { questions.push_back(question); }
+       };
+
+       class ReplySocket;
+       class Request;
+
+       /** DNS manager
+        */
+       class Manager : public DataProvider
+       {
+        public:
+               Manager(Module* mod) : DataProvider(mod, "DNS") { }
+
+               virtual void Process(Request* req) = 0;
+               virtual void RemoveRequest(Request* req) = 0;
+               virtual std::string GetErrorStr(Error) = 0;
+       };
+
+       /** A DNS query.
+        */
+       class Request : public Timer, public Question
+       {
+        protected:
+               Manager* const manager;
+        public:
+               /* Use result cache if available */
+               bool use_cache;
+               /* Request id */
+               unsigned short id;
+               /* Creator of this request */
+               Module* const creator;
+
+               Request(Manager* mgr, Module* mod, const std::string& addr, QueryType qt, bool usecache = true)
+                       : Timer((ServerInstance->Config->dns_timeout ? ServerInstance->Config->dns_timeout : 5), ServerInstance->Time())
+                       , Question(addr, qt)
+                       , manager(mgr)
+                       , use_cache(usecache)
+                       , id(0)
+                       , creator(mod)
+               {
+                       ServerInstance->Timers->AddTimer(this);
+               }
+
+               virtual ~Request()
+               {
+                       manager->RemoveRequest(this);
+               }
+
+               /** Called when this request succeeds
+                * @param r The query sent back from the nameserver
+                */
+               virtual void OnLookupComplete(const Query* req) = 0;
+
+               /** Called when this request fails or times out.
+                * @param r The query sent back from the nameserver, check the error code.
+                */
+               virtual void OnError(const Query* req) { }
+
+               /** Used to time out the query, calls OnError and asks the TimerManager
+                * to delete this request
+                */
+               bool Tick(time_t now)
+               {
+                       Query rr(*this);
+                       rr.error = ERROR_TIMEDOUT;
+                       this->OnError(&rr);
+                       return false;
+               }
+       };
+
+} // namespace DNS
+
diff --git a/include/modules/hash.h b/include/modules/hash.h
new file mode 100644 (file)
index 0000000..da04c45
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include "modules.h"
+
+class HashProvider : public DataProvider
+{
+ public:
+       const unsigned int out_size;
+       const unsigned int block_size;
+       HashProvider(Module* mod, const std::string& Name, int osiz, int bsiz)
+               : DataProvider(mod, Name), out_size(osiz), block_size(bsiz) {}
+       virtual std::string sum(const std::string& data) = 0;
+       inline std::string hexsum(const std::string& data)
+       {
+               return BinToHex(sum(data));
+       }
+
+       inline std::string b64sum(const std::string& data)
+       {
+               return BinToBase64(sum(data), NULL, 0);
+       }
+
+       /** HMAC algorithm, RFC 2104 */
+       std::string hmac(const std::string& key, const std::string& msg)
+       {
+               std::string hmac1, hmac2;
+               std::string kbuf = key.length() > block_size ? sum(key) : key;
+               kbuf.resize(block_size);
+
+               for (size_t n = 0; n < block_size; n++)
+               {
+                       hmac1.push_back(static_cast<char>(kbuf[n] ^ 0x5C));
+                       hmac2.push_back(static_cast<char>(kbuf[n] ^ 0x36));
+               }
+               hmac2.append(msg);
+               hmac1.append(sum(hmac2));
+               return sum(hmac1);
+       }
+};
diff --git a/include/modules/httpd.h b/include/modules/httpd.h
new file mode 100644 (file)
index 0000000..d1746e8
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
+ *   Copyright (C) 2007 John Brooks <john.brooks@dereferenced.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include "base.h"
+
+#include <string>
+#include <sstream>
+#include <map>
+
+/** A modifyable list of HTTP header fields
+ */
+class HTTPHeaders
+{
+ protected:
+       std::map<std::string,std::string> headers;
+ public:
+
+       /** Set the value of a header
+        * Sets the value of the named header. If the header is already present, it will be replaced
+        */
+       void SetHeader(const std::string &name, const std::string &data)
+       {
+               headers[name] = data;
+       }
+
+       /** Set the value of a header, only if it doesn't exist already
+        * Sets the value of the named header. If the header is already present, it will NOT be updated
+        */
+       void CreateHeader(const std::string &name, const std::string &data)
+       {
+               if (!IsSet(name))
+                       SetHeader(name, data);
+       }
+
+       /** Remove the named header
+        */
+       void RemoveHeader(const std::string &name)
+       {
+               headers.erase(name);
+       }
+
+       /** Remove all headers
+        */
+       void Clear()
+       {
+               headers.clear();
+       }
+
+       /** Get the value of a header
+        * @return The value of the header, or an empty string
+        */
+       std::string GetHeader(const std::string &name)
+       {
+               std::map<std::string,std::string>::iterator it = headers.find(name);
+               if (it == headers.end())
+                       return std::string();
+
+               return it->second;
+       }
+
+       /** Check if the given header is specified
+        * @return true if the header is specified
+        */
+       bool IsSet(const std::string &name)
+       {
+               std::map<std::string,std::string>::iterator it = headers.find(name);
+               return (it != headers.end());
+       }
+
+       /** Get all headers, formatted by the HTTP protocol
+        * @return Returns all headers, formatted according to the HTTP protocol. There is no request terminator at the end
+        */
+       std::string GetFormattedHeaders()
+       {
+               std::string re;
+
+               for (std::map<std::string,std::string>::iterator i = headers.begin(); i != headers.end(); i++)
+                       re += i->first + ": " + i->second + "\r\n";
+
+               return re;
+       }
+};
+
+class HttpServerSocket;
+
+/** This class represents a HTTP request.
+ */
+class HTTPRequest : public Event
+{
+ protected:
+       std::string type;
+       std::string document;
+       std::string ipaddr;
+       std::string postdata;
+
+ public:
+
+       HTTPHeaders *headers;
+       int errorcode;
+
+       /** A socket pointer, which you must return in your HTTPDocument class
+        * if you reply to this request.
+        */
+       HttpServerSocket* sock;
+
+       /** Initialize HTTPRequest.
+        * This constructor is called by m_httpd.so to initialize the class.
+        * @param request_type The request type, e.g. GET, POST, HEAD
+        * @param uri The URI, e.g. /page
+        * @param hdr The headers sent with the request
+        * @param opaque An opaque pointer used internally by m_httpd, which you must pass back to the module in your reply.
+        * @param ip The IP address making the web request.
+        * @param pdata The post data (content after headers) received with the request, up to Content-Length in size
+        */
+       HTTPRequest(Module* me, const std::string &eventid, const std::string &request_type, const std::string &uri,
+               HTTPHeaders* hdr, HttpServerSocket* socket, const std::string &ip, const std::string &pdata)
+               : Event(me, eventid), type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(socket)
+       {
+       }
+
+       /** Get the post data (request content).
+        * All post data will be returned, including carriage returns and linefeeds.
+        * @return The postdata
+        */
+       std::string& GetPostData()
+       {
+               return postdata;
+       }
+
+       /** Get the request type.
+        * Any request type can be intercepted, even ones which are invalid in the HTTP/1.1 spec.
+        * @return The request type, e.g. GET, POST, HEAD
+        */
+       std::string& GetType()
+       {
+               return type;
+       }
+
+       /** Get URI.
+        * The URI string (URL minus hostname and scheme) will be provided by this function.
+        * @return The URI being requested
+        */
+       std::string& GetURI()
+       {
+               return document;
+       }
+
+       /** Get IP address of requester.
+        * The requesting system's ip address will be returned.
+        * @return The IP address as a string
+        */
+       std::string& GetIP()
+       {
+               return ipaddr;
+       }
+};
+
+/** You must return a HTTPDocument to the httpd module by using the Request class.
+ * When you initialize this class you may initialize it with all components required to
+ * form a valid HTTP response, including document data, headers, and a response code.
+ */
+class HTTPDocumentResponse : public Request
+{
+ public:
+       std::stringstream* document;
+       int responsecode;
+       HTTPHeaders headers;
+       HTTPRequest& src;
+
+       /** Initialize a HTTPRequest ready for sending to m_httpd.so.
+        * @param opaque The socket pointer you obtained from the HTTPRequest at an earlier time
+        * @param doc A stringstream containing the document body
+        * @param response A valid HTTP/1.0 or HTTP/1.1 response code. The response text will be determined for you
+        * based upon the response code.
+        * @param extra Any extra headers to include with the defaults, seperated by carriage return and linefeed.
+        */
+       HTTPDocumentResponse(Module* me, HTTPRequest& req, std::stringstream* doc, int response)
+               : Request(me, req.source, "HTTP-DOC"), document(doc), responsecode(response), src(req)
+       {
+       }
+};
diff --git a/include/modules/regex.h b/include/modules/regex.h
new file mode 100644 (file)
index 0000000..875f942
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include "inspircd.h"
+
+class Regex : public classbase
+{
+protected:
+       std::string regex_string; // The raw uncompiled regex string.
+
+       // Constructor may as well be protected, as this class is abstract.
+       Regex(const std::string& rx) : regex_string(rx)
+       {
+       }
+
+public:
+
+       virtual ~Regex()
+       {
+       }
+
+       virtual bool Matches(const std::string& text) = 0;
+
+       const std::string& GetRegexString() const
+       {
+               return regex_string;
+       }
+};
+
+class RegexFactory : public DataProvider
+{
+ public:
+       RegexFactory(Module* Creator, const std::string& Name) : DataProvider(Creator, Name) {}
+
+       virtual Regex* Create(const std::string& expr) = 0;
+};
diff --git a/include/modules/sasl.h b/include/modules/sasl.h
new file mode 100644 (file)
index 0000000..321711a
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+class SASLFallback : public Event
+{
+ public:
+       const parameterlist& params;
+       SASLFallback(Module* me, const parameterlist& p)
+               : Event(me, "sasl_fallback"), params(p)
+       {
+               Send();
+       }
+};
diff --git a/include/modules/spanningtree.h b/include/modules/spanningtree.h
new file mode 100644 (file)
index 0000000..99f4f9f
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+struct AddServerEvent : public Event
+{
+       const std::string servername;
+       AddServerEvent(Module* me, const std::string& name)
+               : Event(me, "new_server"), servername(name)
+       {
+               Send();
+       }
+};
+
+struct DelServerEvent : public Event
+{
+       const std::string servername;
+       DelServerEvent(Module* me, const std::string& name)
+               : Event(me, "lost_server"), servername(name)
+       {
+               Send();
+       }
+};
diff --git a/include/modules/sql.h b/include/modules/sql.h
new file mode 100644 (file)
index 0000000..a671cc9
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/** Defines the error types which SQLerror may be set to
+ */
+enum SQLerrorNum { SQL_NO_ERROR, SQL_BAD_DBID, SQL_BAD_CONN, SQL_QSEND_FAIL, SQL_QREPLY_FAIL };
+
+/** A list of format parameters for an SQLquery object.
+ */
+typedef std::vector<std::string> ParamL;
+
+typedef std::map<std::string, std::string> ParamM;
+
+class SQLEntry
+{
+ public:
+       std::string value;
+       bool nul;
+       SQLEntry() : nul(true) {}
+       SQLEntry(const std::string& v) : value(v), nul(false) {}
+       inline operator std::string&() { return value; }
+};
+
+typedef std::vector<SQLEntry> SQLEntries;
+
+/**
+ * Result of an SQL query. Only valid inside OnResult
+ */
+class SQLResult : public classbase
+{
+ public:
+       /**
+        * Return the number of rows in the result.
+        *
+        * Note that if you have perfomed an INSERT or UPDATE query or other
+        * query which will not return rows, this will return the number of
+        * affected rows. In this case you SHOULD NEVER access any of the result
+        * set rows, as there aren't any!
+        * @returns Number of rows in the result set.
+        */
+       virtual int Rows() = 0;
+
+       /**
+        * Return a single row (result of the query). The internal row counter
+        * is incremented by one.
+        *
+        * @param result Storage for the result data.
+        * @returns true if there was a row, false if no row exists (end of
+        * iteration)
+        */
+       virtual bool GetRow(SQLEntries& result) = 0;
+
+       /** Returns column names for the items in this row
+        */
+       virtual void GetCols(std::vector<std::string>& result) = 0;
+};
+
+/** SQLerror holds the error state of a request.
+ * The error string varies from database software to database software
+ * and should be used to display informational error messages to users.
+ */
+class SQLerror
+{
+ public:
+       /** The error id
+        */
+       SQLerrorNum id;
+
+       /** The error string
+        */
+       std::string str;
+
+       /** Initialize an SQLerror
+        * @param i The error ID to set
+        * @param s The (optional) error string to set
+        */
+       SQLerror(SQLerrorNum i, const std::string &s = "")
+       : id(i), str(s)
+       {
+       }
+
+       /** Return the error string for an error
+        */
+       const char* Str()
+       {
+               if(str.length())
+                       return str.c_str();
+
+               switch(id)
+               {
+                       case SQL_BAD_DBID:
+                               return "Invalid database ID";
+                       case SQL_BAD_CONN:
+                               return "Invalid connection";
+                       case SQL_QSEND_FAIL:
+                               return "Sending query failed";
+                       case SQL_QREPLY_FAIL:
+                               return "Getting query result failed";
+                       default:
+                               return "Unknown error";
+               }
+       }
+};
+
+/**
+ * Object representing an SQL query. This should be allocated on the heap and
+ * passed to an SQLProvider, which will free it when the query is complete or
+ * when the querying module is unloaded.
+ *
+ * You should store whatever information is needed to have the callbacks work in
+ * this object (UID of user, channel name, etc).
+ */
+class SQLQuery : public classbase
+{
+ public:
+       ModuleRef creator;
+
+       SQLQuery(Module* Creator) : creator(Creator) {}
+       virtual ~SQLQuery() {}
+
+       virtual void OnResult(SQLResult& result) = 0;
+       /**
+        * Called when the query fails
+        */
+       virtual void OnError(SQLerror& error) { }
+};
+
+/**
+ * Provider object for SQL servers
+ */
+class SQLProvider : public DataProvider
+{
+ public:
+       SQLProvider(Module* Creator, const std::string& Name) : DataProvider(Creator, Name) {}
+       /** Submit an asynchronous SQL request
+        * @param callback The result reporting point
+        * @param query The hardcoded query string. If you have parameters to substitute, see below.
+        */
+       virtual void submit(SQLQuery* callback, const std::string& query) = 0;
+
+       /** Submit an asynchronous SQL request
+        * @param callback The result reporting point
+        * @param format The simple parameterized query string ('?' parameters)
+        * @param p Parameters to fill in for the '?' entries
+        */
+       virtual void submit(SQLQuery* callback, const std::string& format, const ParamL& p) = 0;
+
+       /** Submit an asynchronous SQL request.
+        * @param callback The result reporting point
+        * @param format The parameterized query string ('$name' parameters)
+        * @param p Parameters to fill in for the '$name' entries
+        */
+       virtual void submit(SQLQuery* callback, const std::string& format, const ParamM& p) = 0;
+
+       /** Convenience function to prepare a map from a User* */
+       void PopulateUserInfo(User* user, ParamM& userinfo)
+       {
+               userinfo["nick"] = user->nick;
+               userinfo["host"] = user->host;
+               userinfo["ip"] = user->GetIPString();
+               userinfo["gecos"] = user->fullname;
+               userinfo["ident"] = user->ident;
+               userinfo["server"] = user->server;
+               userinfo["uuid"] = user->uuid;
+       }
+};
diff --git a/include/modules/ssl.h b/include/modules/ssl.h
new file mode 100644 (file)
index 0000000..a79dcc9
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include <map>
+#include <string>
+
+/** ssl_cert is a class which abstracts SSL certificate
+ * and key information.
+ *
+ * Because gnutls and openssl represent key information in
+ * wildly different ways, this class allows it to be accessed
+ * in a unified manner. These classes are attached to ssl-
+ * connected local users using SSLCertExt
+ */
+class ssl_cert : public refcountbase
+{
+ public:
+       std::string dn;
+       std::string issuer;
+       std::string error;
+       std::string fingerprint;
+       bool trusted, invalid, unknownsigner, revoked;
+
+       ssl_cert() : trusted(false), invalid(true), unknownsigner(true), revoked(false) {}
+
+       /** Get certificate distinguished name
+        * @return Certificate DN
+        */
+       const std::string& GetDN()
+       {
+               return dn;
+       }
+
+       /** Get Certificate issuer
+        * @return Certificate issuer
+        */
+       const std::string& GetIssuer()
+       {
+               return issuer;
+       }
+
+       /** Get error string if an error has occured
+        * @return The error associated with this users certificate,
+        * or an empty string if there is no error.
+        */
+       const std::string& GetError()
+       {
+               return error;
+       }
+
+       /** Get key fingerprint.
+        * @return The key fingerprint as a hex string.
+        */
+       const std::string& GetFingerprint()
+       {
+               return fingerprint;
+       }
+
+       /** Get trust status
+        * @return True if this is a trusted certificate
+        * (the certificate chain validates)
+        */
+       bool IsTrusted()
+       {
+               return trusted;
+       }
+
+       /** Get validity status
+        * @return True if the certificate itself is
+        * correctly formed.
+        */
+       bool IsInvalid()
+       {
+               return invalid;
+       }
+
+       /** Get signer status
+        * @return True if the certificate appears to be
+        * self-signed.
+        */
+       bool IsUnknownSigner()
+       {
+               return unknownsigner;
+       }
+
+       /** Get revokation status.
+        * @return True if the certificate is revoked.
+        * Note that this only works properly for GnuTLS
+        * right now.
+        */
+       bool IsRevoked()
+       {
+               return revoked;
+       }
+
+       bool IsCAVerified()
+       {
+               return trusted && !invalid && !revoked && !unknownsigner && error.empty();
+       }
+
+       std::string GetMetaLine()
+       {
+               std::stringstream value;
+               bool hasError = !error.empty();
+               value << (IsInvalid() ? "v" : "V") << (IsTrusted() ? "T" : "t") << (IsRevoked() ? "R" : "r")
+                       << (IsUnknownSigner() ? "s" : "S") << (hasError ? "E" : "e") << " ";
+               if (hasError)
+                       value << GetError();
+               else
+                       value << GetFingerprint() << " " << GetDN() << " " << GetIssuer();
+               return value.str();
+       }
+};
+
+/** Get certificate from a socket (only useful with an SSL module) */
+struct SocketCertificateRequest : public Request
+{
+       StreamSocket* const sock;
+       ssl_cert* cert;
+
+       SocketCertificateRequest(StreamSocket* ss, Module* Me)
+               : Request(Me, ss->GetIOHook(), "GET_SSL_CERT"), sock(ss), cert(NULL)
+       {
+               Send();
+       }
+
+       std::string GetFingerprint()
+       {
+               if (cert)
+                       return cert->GetFingerprint();
+               return "";
+       }
+};
+
+/** Get certificate from a user (requires m_sslinfo) */
+struct UserCertificateRequest : public Request
+{
+       User* const user;
+       ssl_cert* cert;
+
+       UserCertificateRequest(User* u, Module* Me, Module* info = ServerInstance->Modules->Find("m_sslinfo.so"))
+               : Request(Me, info, "GET_USER_CERT"), user(u), cert(NULL)
+       {
+               Send();
+       }
+
+       std::string GetFingerprint()
+       {
+               if (cert)
+                       return cert->GetFingerprint();
+               return "";
+       }
+};
index 4fce4cb6de53b746c9ef6a8e6798fdca00aa8a1b..997a71d3ae2bac678c7b64b779ff46732c45d68d 100644 (file)
@@ -18,8 +18,7 @@
  */
 
 
-#ifndef NUMERICS_H
-#define NUMERICS_H
+#pragma once
 
 /*
  * This file is aimed providing a string that is easier to use than using the numeric
@@ -157,5 +156,3 @@ enum Numerics
        ERR_CANTLOADMODULE                              =       974, // insp-specific
        RPL_LOADEDMODULE                                =       975 // insp-specific
 };
-
-#endif
index aabb5b022c7d444be244b08ffe40313f1a866c1e..4488fcea43cd80be6923f3a9133d32dc42a9b8a1 100644 (file)
@@ -18,8 +18,7 @@
  */
 
 
-#ifndef PROTOCOL_H
-#define PROTOCOL_H
+#pragma once
 
 #include "hashcomp.h"
 
@@ -135,6 +134,3 @@ class ProtocolInterface
         */
        virtual void GetServerList(ProtoServerList &sl) { }
 };
-
-#endif
-
index 85ad26f71392a7e068f35a43b7e3564cc17770cd..c5d594eebadc18575dc055901e3e60d91d473ff0 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef SNOMASKS_H
-#define SNOMASKS_H
+#pragma once
 
 class Snomask
 {
@@ -106,5 +105,3 @@ class CoreExport SnomaskManager
         */
        void FlushSnotices();
 };
-
-#endif
index 5f67051246d3dbe2017f5cab375632c58b69e016..3abbeef32a1054135cf741d5253600e0174b6b92 100644 (file)
@@ -22,8 +22,7 @@
  */
 
 
-#ifndef INSPIRCD_SOCKET_H
-#define INSPIRCD_SOCKET_H
+#pragma once
 
 #ifndef _WIN32
 
@@ -110,9 +109,6 @@ namespace irc
                 */
                CoreExport bool MatchCIDR(const std::string &address, const std::string &cidr_mask, bool match_with_username);
 
-               /** Return the size of the structure for syscall passing */
-               inline int sa_size(const irc::sockets::sockaddrs& sa) { return sa.sa_size(); }
-
                /** Convert an address-port pair into a binary sockaddr
                 * @param addr The IP address, IPv4 or IPv6
                 * @param port The port, 0 for unspecified
@@ -165,6 +161,3 @@ class CoreExport ListenSocket : public EventHandler
         */
        void AcceptInternal();
 };
-
-#endif
-
index 2fc3cdbfd4d2849c05f5a02c8b97a5802c324afa..8e4c3dfc9e3dbf5dca98ae2a86b276b63c15502e 100644 (file)
  */
 
 
-#ifndef SOCKETENGINE_H
-#define SOCKETENGINE_H
+#pragma once
 
 #include <vector>
 #include <string>
 #include <map>
-#include "inspircd_config.h"
+#include "config.h"
 #include "socket.h"
 #include "base.h"
 
@@ -128,7 +127,7 @@ enum EventMask
        /** Add a trial write. During the next DispatchEvents invocation, this
         * will call HandleEvent with EVENT_WRITE unless writes are known to be
         * blocking.
-        * 
+        *
         * This could be used to group several writes together into a single
         * send() syscall, or to ensure that writes are blocking when attempting
         * to use FD_WANT_FAST_WRITE.
@@ -137,7 +136,7 @@ enum EventMask
        /** Assert that writes are known to block. This cancels FD_ADD_TRIAL_WRITE.
         * Reset by SE before running EVENT_WRITE
         */
-       FD_WRITE_WILL_BLOCK = 0x8000, 
+       FD_WRITE_WILL_BLOCK = 0x8000,
 
        /** Mask for trial read/trial write */
        FD_TRIAL_NOTE_MASK = 0x5000
@@ -418,7 +417,7 @@ public:
         * @param buf The buffer in which the data that is sent is stored.
         * @param len The size of the buffer.
         * @param flags A flag value that controls the sending of the data.
-        * @param to The remote IP address and port.    
+        * @param to The remote IP address and port.
         * @param tolen The size of the to parameter.
         * @return This method should return exactly the same values as the system call it emulates.
         */
@@ -510,6 +509,3 @@ inline bool SocketEngine::IgnoreError()
 }
 
 SocketEngine* CreateSocketEngine();
-
-#endif
-
index f91e508c930597c0fa12bb4f2e59322370599d00..7f0b2236a43af55dcc2d712f4d21993f683e9f3c 100644 (file)
  */
 
 
-#ifndef TESTSUITE_H
-#define TESTSUITE_H
+#pragma once
 
 class TestSuite
 {
-       bool RealGenerateUIDTests();
  public:
        TestSuite();
        ~TestSuite();
@@ -32,5 +30,3 @@ class TestSuite
        bool DoSpaceSepStreamTests();
        bool DoGenerateUIDTests();
 };
-
-#endif
index 4bf5a48f38399a94d367989f405f9bff213f5936..39f150566bc17ed52dff736fa2e416147958d1f8 100644 (file)
  */
 
 
-#ifndef THREADENGINE_H
-#define THREADENGINE_H
+#pragma once
 
 #include <vector>
 #include <string>
 #include <map>
-#include "inspircd_config.h"
+#include "config.h"
 #include "base.h"
 
 class ThreadData;
@@ -172,6 +171,3 @@ class CoreExport SocketThread : public Thread
         */
        virtual void OnNotify() = 0;
 };
-
-#endif
-
index 5168ed238cb53dbb5f4862af37efa151448bece9..253e8d2237ad38c641fea684c37c14ab17acef35 100644 (file)
@@ -18,8 +18,7 @@
  */
 
 
-#ifndef THREADENGINE_PTHREAD_H
-#define THREADENGINE_PTHREAD_H
+#pragma once
 
 #include <pthread.h>
 #include "typedefs.h"
@@ -153,6 +152,3 @@ class ThreadSignalData
  public:
        ThreadSignalSocket* sock;
 };
-
-
-#endif
index f068ac70785ff35a3152bc65535b103f854fcc6f..59848bd44e3004b2c84f4c6d1aab067e5a8a7d82 100644 (file)
  */
 
 
-#ifndef THREADENGINE_WIN32_H
-#define THREADENGINE_WIN32_H
+#pragma once
 
-#include "inspircd_config.h"
+#include "config.h"
 #include "base.h"
 
 class Thread;
@@ -152,6 +151,3 @@ class ThreadSignalData
                connFD = -1;
        }
 };
-
-#endif
-
index 9bb7128b85ac7f6283ec51a0e6986fc7464a6a1d..6f1834178932dcec88f7e36b129e921d1e638209 100644 (file)
@@ -19,8 +19,9 @@
  */
 
 
-#ifndef INSPIRCD_TIMER_H
-#define INSPIRCD_TIMER_H
+#pragma once
+
+class Module;
 
 /** Timer class for one-second resolution timers
  * Timer provides a facility which allows module
  * resolution. To use Timer, inherit a class from
  * Timer, then insert your inherited class into the
  * queue using Server::AddTimer(). The Tick() method of
- * your object (which you should override) will be called
+ * your object (which you have to override) will be called
  * at the given time.
  */
 class CoreExport Timer
 {
- private:
        /** The triggering time
         */
        time_t trigger;
+
        /** Number of seconds between triggers
         */
-       long secs;
+       unsigned int secs;
+
        /** True if this is a repeating timer
         */
        bool repeat;
+
  public:
        /** Default constructor, initializes the triggering time
+        * @param mod The module that created this timer
         * @param secs_from_now The number of seconds from now to trigger the timer
         * @param now The time now
         * @param repeating Repeat this timer every secs_from_now seconds if set to true
         */
-       Timer(long secs_from_now, time_t now, bool repeating = false)
+       Timer(unsigned int secs_from_now, time_t now, bool repeating = false)
        {
                trigger = now + secs_from_now;
                secs = secs_from_now;
                repeat = repeating;
        }
 
-       /** Default destructor, does nothing.
+       /** Default destructor, removes the timer from the timer manager
         */
-       virtual ~Timer() { }
+       virtual ~Timer();
 
        /** Retrieve the current triggering time
         */
-       virtual time_t GetTimer()
+       time_t GetTrigger() const
        {
                return trigger;
        }
 
        /** Sets the trigger timeout to a new value
+        * This does not update the bookkeeping in TimerManager, use SetInterval()
+        * to change the interval between ticks while keeping TimerManager updated
         */
-       virtual void SetTimer(time_t t)
+       void SetTrigger(time_t nexttrigger)
        {
-               trigger = t;
+               trigger = nexttrigger;
        }
 
+       /** Sets the interval between two ticks.
+        */
+       void SetInterval(time_t interval);
+
        /** Called when the timer ticks.
         * You should override this method with some useful code to
         * handle the tick event.
         */
-       virtual void Tick(time_t TIME) = 0;
+       virtual bool Tick(time_t TIME) = 0;
 
        /** Returns true if this timer is set to repeat
         */
-       bool GetRepeat()
+       bool GetRepeat() const
        {
                return repeat;
        }
@@ -91,7 +101,7 @@ class CoreExport Timer
        /** Returns the interval (number of seconds between ticks)
         * of this timer object.
         */
-       long GetSecs()
+       unsigned int GetInterval() const
        {
                return secs;
        }
@@ -99,12 +109,6 @@ class CoreExport Timer
        /** Cancels the repeat state of a repeating timer.
         * If you call this method, then the next time your
         * timer ticks, it will be removed immediately after.
-        * You should use this method call to remove a recurring
-        * timer if you wish to do so within the timer's Tick
-        * event, as calling TimerManager::DelTimer() from within
-        * the Timer::Tick() method is dangerous and may
-        * cause a segmentation fault. Calling CancelRepeat()
-        * is safe in this case.
         */
        void CancelRepeat()
        {
@@ -112,6 +116,7 @@ class CoreExport Timer
        }
 };
 
+typedef std::multimap<time_t, Timer*> TimerMap;
 
 /** This class manages sets of Timers, and triggers them at their defined times.
  * This will ensure timers are not missed, as well as removing timers that have
@@ -119,17 +124,11 @@ class CoreExport Timer
  */
 class CoreExport TimerManager
 {
- protected:
        /** A list of all pending timers
         */
-       std::vector<Timer *> Timers;
+       TimerMap Timers;
 
  public:
-       /** Constructor
-        */
-       TimerManager();
-       ~TimerManager();
-
        /** Tick all pending Timers
         * @param TIME the current system time
         */
@@ -140,15 +139,8 @@ class CoreExport TimerManager
         */
        void AddTimer(Timer *T);
 
-       /** Delete an Timer
-        * @param T an Timer derived class to delete
+       /** Remove a Timer
+        * @param T an Timer derived class to remove
         */
        void DelTimer(Timer* T);
-
-       /** Compares two timers
-        */
-       static bool TimerComparison( Timer *one,  Timer*two);
 };
-
-#endif
-
index 06f704120126309a93114d0996ea20d24139e75e..404175ddb456a59a2a48607056c3f33a08ced212 100644 (file)
@@ -19,8 +19,7 @@
  */
 
 
-#ifndef TYPEDEFS_H
-#define TYPEDEFS_H
+#pragma once
 
 class BanCacheManager;
 class BanItem;
@@ -29,8 +28,6 @@ class Channel;
 class Command;
 class ConfigReader;
 class ConfigTag;
-class DNSHeader;
-class DNSRequest;
 class Extensible;
 class FakeUser;
 class InspIRCd;
@@ -45,24 +42,17 @@ class ServerConfig;
 class ServerLimits;
 class Thread;
 class User;
-class UserResolver;
 class XLine;
 class XLineManager;
 class XLineFactory;
 struct ConnectClass;
 struct ModResult;
-struct ResourceRecord;
 
 #include "hashcomp.h"
 #include "base.h"
 
-#ifdef HASHMAP_DEPRECATED
-       typedef nspace::hash_map<std::string, User*, nspace::insensitive, irc::StrHashComp> user_hash;
-       typedef nspace::hash_map<std::string, Channel*, nspace::insensitive, irc::StrHashComp> chan_hash;
-#else
-       typedef nspace::hash_map<std::string, User*, nspace::hash<std::string>, irc::StrHashComp> user_hash;
-       typedef nspace::hash_map<std::string, Channel*, nspace::hash<std::string>, irc::StrHashComp> chan_hash;
-#endif
+typedef TR1NS::unordered_map<std::string, User*, irc::insensitive, irc::StrHashComp> user_hash;
+typedef TR1NS::unordered_map<std::string, Channel*, irc::insensitive, irc::StrHashComp> chan_hash;
 
 /** A list holding local users, this is the type of UserManager::local_users
  */
@@ -120,7 +110,7 @@ typedef std::map<std::string, file_cache> ConfigFileCache;
 
 /** A hash of commands used by the core
  */
-typedef nspace::hash_map<std::string,Command*> Commandtable;
+typedef TR1NS::unordered_map<std::string, Command*> Commandtable;
 
 /** Membership list of a channel */
 typedef std::map<User*, Membership*> UserMembList;
@@ -159,7 +149,3 @@ typedef XLineContainer::iterator ContainerIter;
 /** An interator in an XLineLookup
  */
 typedef XLineLookup::iterator LookupIter;
-
-
-#endif
-
index 17061bdee972a72f296459bfad966e93f735ccd2..772c8a7165fafb9b36e35db98b4885afa1be1add 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#pragma once
 
-/**
- * This is the maximum length of a UUID (unique user identifier).
- * This length is set in compliance with TS6 protocol, and really should not be changed. Ever.
- * It allows for a lot of clients as-is. -- w00t.
- */
-#define UUID_LENGTH 10
+class TestSuite;
+
+class CoreExport UIDGenerator
+{
+       friend class TestSuite;
+
+       /** Holds the current UID. Used to generate the next one.
+        */
+       std::string current_uid;
+
+       /** Increments the current UID by one.
+        */
+       void IncrementUID(unsigned int pos);
+
+ public:
+       /**
+       * This is the maximum length of a UUID (unique user identifier).
+       * This length is set in compliance with TS6 protocol, and really should not be changed. Ever.
+       * It allows for a lot of clients as-is. -- w00t.
+       */
+       static const unsigned int UUID_LENGTH = 9;
+
+       /** Initializes this UID generator with the given SID
+        * @param sid SID that conforms to InspIRCd::IsSID()
+        */
+       void init(const std::string& sid);
 
+       /** Returns the next available UID for this server.
+        */
+       std::string GetUID();
 
+       /** Generates a pseudorandom SID based on a servername and a description
+        * Guaranteed to return the same if invoked with the same parameters
+        * @param servername The server name to use as seed
+        * @param serverdesc The server description to use as seed
+        * @return A valid SID
+        */
+       static std::string GenerateSID(const std::string& servername, const std::string& serverdesc);
+};
index ac8ae1cb3ef1b82eb12a64756dfd06da1e737559..f5df25f00a2d808f36c40d4580ad26a4d2dff41a 100644 (file)
@@ -17,8 +17,7 @@
  */
 
 
-#ifndef USERMANAGER_H
-#define USERMANAGER_H
+#pragma once
 
 #include <list>
 
@@ -76,6 +75,12 @@ class CoreExport UserManager
         */
        clonemap global_clones;
 
+       /**
+        * Reset the already_sent IDs so we don't wrap it around and drop a message
+        * Also removes all expired invites
+     */
+       void GarbageCollect();
+
        /** Add a client to the system.
         * This will create a new User, insert it into the user_hash,
         * initialize it as not yet registered, and add it to the socket engine.
@@ -149,9 +154,6 @@ class CoreExport UserManager
         */
        unsigned int LocalUserCount();
 
-
-
-
        /** Number of users with a certain mode set on them
         */
        int ModeCount(const char mode);
@@ -161,12 +163,4 @@ class CoreExport UserManager
         * @param ... The format arguments
         */
        void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
-
-       /** Send a server message (PRIVMSG) to all local users
-        * @param text The text format string to send
-        * @param ... The format arguments
-        */
-       void ServerPrivmsgAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
 };
-
-#endif
index 88abfbcd1c6dc8c682fa3a2597f7c2e15891f148..52f3e4a8897614967fd6f0708034697b9bd0064d 100644 (file)
  */
 
 
-#ifndef USERS_H
-#define USERS_H
+#pragma once
 
 #include "socket.h"
 #include "inspsocket.h"
-#include "dns.h"
 #include "mode.h"
 #include "membership.h"
 
@@ -146,6 +144,10 @@ struct CoreExport ConnectClass : public refcountbase
         */
        unsigned long limit;
 
+       /** If set to true, no user DNS lookups are to be performed
+        */
+       bool nouserdns;
+
        /** Create a new connect class with no settings.
         */
        ConnectClass(ConfigTag* tag, char type, const std::string& mask);
@@ -267,10 +269,6 @@ class CoreExport User : public Extensible
         */
        time_t signon;
 
-       /** Time that the connection last sent a message, used to calculate idle time
-        */
-       time_t idle_lastmsg;
-
        /** Client address that the user is connected from.
         * Do not modify this value directly, use SetClientIP() to change it.
         * Port is not valid for remote users.
@@ -333,7 +331,7 @@ class CoreExport User : public Extensible
        std::string awaymsg;
 
        /** Time the user last went away.
-        * This is ONLY RELIABLE if user IS_AWAY()!
+        * This is ONLY RELIABLE if user IsAway()!
         */
        time_t awaytime;
 
@@ -347,12 +345,6 @@ class CoreExport User : public Extensible
         */
        unsigned int registered:3;
 
-       /** True when DNS lookups are completed.
-        * The UserResolver classes res_forward and res_reverse will
-        * set this value once they complete.
-        */
-       unsigned int dns_done:1;
-
        /** Whether or not to send an snotice about this user's quitting
         */
        unsigned int quietquit:1;
@@ -364,27 +356,13 @@ class CoreExport User : public Extensible
         */
        unsigned int quitting:1;
 
-       /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
-        * This can't be handled normally because QuitUser itself calls Write on other
-        * users, which could trigger their SendQ to overrun.
-        */
-       unsigned int quitting_sendq:1;
-
-       /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
-        */
-       unsigned int exempt:1;
-
-       /** has the user responded to their previous ping?
-        */
-       unsigned int lastping:1;
-
        /** What type of user is this? */
        const unsigned int usertype:2;
 
        /** Get client IP string from sockaddr, using static internal buffer
         * @return The IP string
         */
-       const char* GetIPString();
+       const std::string& GetIPString();
 
        /** Get CIDR mask, using default range, for this user
         */
@@ -402,12 +380,6 @@ class CoreExport User : public Extensible
         */
        User(const std::string &uid, const std::string& srv, int objtype);
 
-       /** Check if the user matches a G or K line, and disconnect them if they do.
-        * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
-        * Returns true if the user matched a ban, false else.
-        */
-       bool CheckLines(bool doZline = false);
-
        /** Returns the full displayed host of the user
         * This member function returns the hostname of the user as seen by other users
         * on the server, in nick!ident\@host form.
@@ -441,6 +413,18 @@ class CoreExport User : public Extensible
         */
        std::string ProcessNoticeMasks(const char *sm);
 
+       /** Returns whether this user is currently away or not. If true,
+        * further information can be found in User::awaymsg and User::awaytime
+        * @return True if the user is away, false otherwise
+        */
+       bool IsAway() const { return (!awaymsg.empty()); }
+
+       /** Returns whether this user is an oper or not. If true,
+        * oper information can be obtained from User::oper
+        * @return True if the user is an oper, false otherwise
+        */
+       bool IsOper() const { return oper; }
+
        /** Returns true if a notice mask is set
         * @param sm A notice mask character to check
         * @return True if the notice mask is set
@@ -515,10 +499,6 @@ class CoreExport User : public Extensible
         */
        const std::string& MakeHostIP();
 
-       /** Add the user to WHOWAS system
-        */
-       void AddToWhoWas();
-
        /** Oper up the user using the given opertype.
         * This will also give the +o usermode.
         */
@@ -531,7 +511,7 @@ class CoreExport User : public Extensible
         * @param newnick The nickname to change to
         * @return True if the nickchange was successful.
         */
-       inline bool ForceNickChange(const char* newnick) { return ChangeNick(newnick, true); }
+       bool ForceNickChange(const std::string& newnick) { return ChangeNick(newnick, true); }
 
        /** Oper down.
         * This will clear the +o usermode and unset the user's oper type
@@ -563,6 +543,11 @@ class CoreExport User : public Extensible
         */
        void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
 
+       /** Sends a server notice to this user.
+        * @param text The contents of the message to send.
+        */
+       void WriteNotice(const std::string& text);
+
        void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
 
        void WriteNumeric(unsigned int numeric, const std::string &text);
@@ -691,20 +676,6 @@ class CoreExport User : public Extensible
         */
        void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
 
-       /** Compile a channel list for this user.  Used internally by WHOIS
-        * @param source The user to prepare the channel list for
-        * @param spy Whether to return the spy channel list rather than the normal one
-        * @return This user's channel list
-        */
-       std::string ChannelList(User* source, bool spy);
-
-       /** Split the channel list in cl which came from dest, and spool it to this user
-        * Used internally by WHOIS
-        * @param dest The user the original channel list came from
-        * @param cl The  channel list as a string obtained from User::ChannelList()
-        */
-       void SplitChanList(User* dest, const std::string &cl);
-
        /** Remove this user from all channels they are on, and delete any that are now empty.
         * This is used by QUIT, and will not send part messages!
         */
@@ -792,10 +763,28 @@ class CoreExport LocalUser : public User, public InviteBase
         */
        int GetServerPort();
 
+       /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
+        * This can't be handled normally because QuitUser itself calls Write on other
+        * users, which could trigger their SendQ to overrun.
+        */
+       unsigned int quitting_sendq:1;
+
+       /** has the user responded to their previous ping?
+        */
+       unsigned int lastping:1;
+
+       /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
+        */
+       unsigned int exempt:1;
+
        /** Used by PING checking code
         */
        time_t nping;
 
+       /** Time that the connection last sent a message, used to calculate idle time
+        */
+       time_t idle_lastmsg;
+
        /** This value contains how far into the penalty threshold the user is.
         * This is used either to enable fake lag or for excess flood quits
         */
@@ -804,15 +793,11 @@ class CoreExport LocalUser : public User, public InviteBase
        static already_sent_t already_sent_id;
        already_sent_t already_sent;
 
-       /** Stored reverse lookup from res_forward. Should not be used after resolution.
-        */
-       std::string stored_host;
-
-       /** Starts a DNS lookup of the user's IP.
-        * This will cause two UserResolver classes to be instantiated.
-        * When complete, these objects set User::dns_done to true.
+       /** Check if the user matches a G or K line, and disconnect them if they do.
+        * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
+        * Returns true if the user matched a ban, false else.
         */
-       void StartDNSLookup();
+       bool CheckLines(bool doZline = false);
 
        /** Use this method to fully connect a user.
         * This will send the message of the day, check G/K/E lines, etc.
@@ -839,23 +824,18 @@ class CoreExport LocalUser : public User, public InviteBase
        InviteList& GetInviteList();
 
        /** Returns true if a user is invited to a channel.
-        * @param channel A channel name to look up
+        * @param channel A channel to look up
         * @return True if the user is invited to the given channel
         */
-       bool IsInvited(const irc::string &channel);
-
-       /** Adds a channel to a users invite list (invites them to a channel)
-        * @param channel A channel name to add
-        * @param timeout When the invite should expire (0 == never)
-        */
-       void InviteTo(const irc::string &channel, time_t timeout);
+       bool IsInvited(Channel* chan) { return (Invitation::Find(chan, this) != NULL); }
 
        /** Removes a channel from a users invite list.
         * This member function is called on successfully joining an invite only channel
         * to which the user has previously been invited, to clear the invitation.
         * @param channel The channel to remove the invite to
+        * @return True if the user was invited to the channel and the invite was erased, false if the user wasn't invited
         */
-       void RemoveInvite(const irc::string &channel);
+       bool RemoveInvite(Channel* chan);
 
        void RemoveExpiredInvites();
 
@@ -926,42 +906,4 @@ inline FakeUser* IS_SERVER(User* u)
 {
        return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
 }
-/** Is an oper */
-#define IS_OPER(x) (x->oper)
-/** Is away */
-#define IS_AWAY(x) (!x->awaymsg.empty())
 
-/** Derived from Resolver, and performs user forward/reverse lookups.
- */
-class CoreExport UserResolver : public Resolver
-{
- private:
-       /** UUID we are looking up */
-       std::string uuid;
-       /** True if the lookup is forward, false if is a reverse lookup
-        */
-       bool fwd;
- public:
-       /** Create a resolver.
-        * @param user The user to begin lookup on
-        * @param to_resolve The IP or host to resolve
-        * @param qt The query type
-        * @param cache Modified by the constructor if the result was cached
-        */
-       UserResolver(LocalUser* user, std::string to_resolve, QueryType qt, bool &cache);
-
-       /** Called on successful lookup
-        * @param result Result string
-        * @param ttl Time to live for result
-        * @param cached True if the result was found in the cache
-        */
-       void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
-
-       /** Called on failed lookup
-        * @param e Error code
-        * @param errormessage Error message string
-        */
-       void OnError(ResolverError e, const std::string &errormessage);
-};
-
-#endif
index 2a49d8b80efe1c49230137a847a4838a049485be..5403a0933f7b117cc8cffcfdc5c5ea7d4bcf0a18 100644 (file)
@@ -20,8 +20,7 @@
  */
 
 
-#ifndef XLINE_H
-#define XLINE_H
+#pragma once
 
 /** XLine is the base class for ban lines such as G lines and K lines.
  * Modules may derive from this, and their xlines will automatically be
@@ -101,16 +100,16 @@ class CoreExport XLine : public classbase
         * line. Usually a line in the form 'expiring Xline blah, set by...'
         * see the DisplayExpiry methods of GLine, ELine etc.
         */
-       virtual void DisplayExpiry() = 0;
+       virtual void DisplayExpiry();
 
        /** Returns the displayable form of the pattern for this xline,
         * e.g. '*\@foo' or '*baz*'. This must always return the full pattern
         * in a form which can be used to construct an entire derived xline,
         * even if it is stored differently internally (e.g. GLine stores the
         * ident and host parts seperately but will still return ident\@host
-        * for its Displayable() method)
+        * for its Displayable() method).
         */
-       virtual const char* Displayable() = 0;
+       virtual const std::string& Displayable() = 0;
 
        /** Called when the xline has just been added.
         */
@@ -177,9 +176,7 @@ class CoreExport KLine : public XLine
 
        virtual void Apply(User* u);
 
-       virtual void DisplayExpiry();
-
-       virtual const char* Displayable();
+       virtual const std::string& Displayable();
 
        virtual bool IsBurstable();
 
@@ -225,9 +222,7 @@ class CoreExport GLine : public XLine
 
        virtual void Apply(User* u);
 
-       virtual void DisplayExpiry();
-
-       virtual const char* Displayable();
+       virtual const std::string& Displayable();
 
        /** Ident mask (ident part only)
         */
@@ -269,11 +264,9 @@ class CoreExport ELine : public XLine
 
        virtual void Unset();
 
-       virtual void DisplayExpiry();
-
        virtual void OnAdd();
 
-       virtual const char* Displayable();
+       virtual const std::string& Displayable();
 
        /** Ident mask (ident part only)
         */
@@ -314,9 +307,7 @@ class CoreExport ZLine : public XLine
 
        virtual void Apply(User* u);
 
-       virtual void DisplayExpiry();
-
-       virtual const char* Displayable();
+       virtual const std::string& Displayable();
 
        /** IP mask (no ident part)
         */
@@ -351,9 +342,7 @@ class CoreExport QLine : public XLine
 
        virtual void Apply(User* u);
 
-       virtual void DisplayExpiry();
-
-       virtual const char* Displayable();
+       virtual const std::string& Displayable();
 
        /** Nickname mask
         */
@@ -537,4 +526,3 @@ class CoreExport XLineManager
        void InvokeStats(const std::string &type, int numeric, User* user, string_list &results);
 };
 
-#endif
index 4a759a24a163692ca19682cad0abb44ecc7ff11c..e578f585c4ff8a35018b156bebfee32674e5f32f 100755 (executable)
@@ -199,7 +199,7 @@ sub gendep($) {
        while (<$in>) {
                if (/^\s*#\s*include\s*"([^"]+)"/) {
                        my $inc = $1;
-                       next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
+                       next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
                        my $found = 0;
                        for my $loc ("$basedir/$inc", "../include/$inc") {
                                next unless -e $loc;
diff --git a/make/check_epoll.cpp b/make/check_epoll.cpp
deleted file mode 100644 (file)
index 918d390..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include <sys/epoll.h>
-
-int main() {
-       int fd = epoll_create(1);
-       return (fd < 0);
-}
diff --git a/make/check_eventfd.cpp b/make/check_eventfd.cpp
deleted file mode 100644 (file)
index 980d044..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include <sys/eventfd.h>
-
-int main() {
-       eventfd_t efd_data;
-       int fd;
-
-       fd = eventfd(0, EFD_NONBLOCK);
-       eventfd_read(fd, &efd_data);
-
-       return (fd < 0);
-}
index 606483e98d8619656751302d0a661839c7a0b898..d76b1143d88e45029236c01f021e063bbe57d1f7 100644 (file)
@@ -31,10 +31,29 @@ use warnings FATAL => qw(all);
 use Exporter 'import';
 use POSIX;
 use make::utilities;
-our @EXPORT = qw(promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
+our @EXPORT = qw(test_file test_header promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
 
 my $no_git = 0;
 
+sub test_file($$;$) {
+       my ($cc, $file, $args) = @_;
+       my $status = 0;
+       $args ||= '';
+       $status ||= system "$cc -o __test_$file make/test/$file $args >/dev/null 2>&1";
+       $status ||= system "./__test_$file >/dev/null 2>&1";
+       unlink  "./__test_$file";
+       return !$status;
+}
+
+sub test_header($$;$) {
+       my ($cc, $header, $args) = @_;
+       $args ||= '';
+       open(CC, "| $cc -E - $args >/dev/null 2>&1") or return 0;
+       print CC "#include <$header>";
+       close(CC);
+       return !$?;
+}
+
 sub yesno {
        my ($flag,$prompt) = @_;
        print "$prompt [\e[1;32m$main::config{$flag}\e[0m] -> ";
@@ -276,7 +295,6 @@ InspIRCd 1.0.x, are also allowed.
                                to select() [not set]
   --disable-kqueue             Do not enable kqueue(), fall back
                                to select() [not set]
-  --disable-ipv6               Do not build IPv6 native InspIRCd [not set]
   --with-cc=[filename]         Use an alternative compiler to
                                build InspIRCd [g++]
   --with-maxbuf=[n]            Change the per message buffer size [512]
diff --git a/make/gnutlscert.pm b/make/gnutlscert.pm
deleted file mode 100644 (file)
index a67be0c..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-#
-# InspIRCd -- Internet Relay Chat Daemon
-#
-#   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
-#   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
-#
-# This file is part of InspIRCd.  InspIRCd is free software: you can
-# redistribute it and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation, version 2.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-
-package make::gnutlscert;
-
-require 5.8.0;
-
-use strict;
-use warnings FATAL => qw(all);
-
-use Exporter 'import';
-use make::configure;
-our @EXPORT = qw(make_gnutls_cert);
-
-
-sub make_gnutls_cert()
-{
-       open (FH, ">certtool.template");
-       my $timestr = time();
-       my $org = promptstring_s("Please enter the organization name", "My IRC Network");
-       my $unit = promptstring_s("Please enter the unit Name", "Server Admins");
-       my $state = promptstring_s("Please enter your state (two letter code)", "CA");
-       my $country = promptstring_s("Please enter your country", "Oompa Loompa Land");
-       my $commonname = promptstring_s("Please enter the certificate common name (hostname)", "irc.mynetwork.com");
-       my $email = promptstring_s("Please enter a contact email address", "oompa\@loompa.com");
-       print FH <<__END__;
-# X.509 Certificate options
-#
-# DN options
-
-# The organization of the subject.
-organization = "$org"
-
-# The organizational unit of the subject.
-unit = "$unit"
-
-# The locality of the subject.
-# locality =
-
-# The state of the certificate owner.
-state = "$state"
-
-# The country of the subject. Two letter code.
-country = $country
-
-# The common name of the certificate owner.
-cn = "$commonname"
-
-# A user id of the certificate owner.
-#uid = "clauper"
-
-# If the supported DN OIDs are not adequate you can set
-# any OID here.
-# For example set the X.520 Title and the X.520 Pseudonym
-# by using OID and string pairs.
-#dn_oid = "2.5.4.12" "Dr." "2.5.4.65" "jackal"
-
-# This is deprecated and should not be used in new
-# certificates.
-# pkcs9_email = "none\@none.org"
-
-# The serial number of the certificate
-serial = $timestr
-
-# In how many days, counting from today, this certificate will expire.
-expiration_days = 700
-
-# X.509 v3 extensions
-
-# A dnsname in case of a WWW server.
-#dns_name = "www.none.org"
-
-# An IP address in case of a server.
-#ip_address = "192.168.1.1"
-
-# An email in case of a person
-email = "$email"
-
-# An URL that has CRLs (certificate revocation lists)
-# available. Needed in CA certificates.
-#crl_dist_points = "http://www.getcrl.crl/getcrl/"
-
-# Whether this is a CA certificate or not
-#ca
-
-# Whether this certificate will be used for a TLS client
-tls_www_client
-
-# Whether this certificate will be used for a TLS server
-tls_www_server
-
-# Whether this certificate will be used to sign data (needed
-# in TLS DHE ciphersuites).
-signing_key
-
-# Whether this certificate will be used to encrypt data (needed
-# in TLS RSA ciphersuites). Note that it is prefered to use different
-# keys for encryption and signing.
-encryption_key
-
-# Whether this key will be used to sign other certificates.
-cert_signing_key
-
-# Whether this key will be used to sign CRLs.
-crl_signing_key
-
-# Whether this key will be used to sign code.
-code_signing_key
-
-# Whether this key will be used to sign OCSP data.
-ocsp_signing_key
-
-# Whether this key will be used for time stamping.
-time_stamping_key
-__END__
-close(FH);
-my $certtool = "certtool";
-if (`uname -s` eq "Darwin\n") {
-       # On OS X the certtool binary name is different to prevent
-       # collisions with the system certtool from NSS.
-       $certtool = "gnutls-certtool";
-}
-if ( (my $status = system("$certtool --generate-privkey --outfile key.pem")) ne 0) { return 1; }
-if ( (my $status = system("$certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem --template certtool.template")) ne 0) { return 1; }
-unlink("certtool.template");
-return 0;
-}
-
-1;
-
diff --git a/make/opensslcert.pm b/make/opensslcert.pm
deleted file mode 100644 (file)
index fd7bd69..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# InspIRCd -- Internet Relay Chat Daemon
-#
-#   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
-#   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
-#
-# This file is part of InspIRCd.  InspIRCd is free software: you can
-# redistribute it and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation, version 2.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-
-package make::opensslcert;
-
-require 5.8.0;
-
-use strict;
-use warnings FATAL => qw(all);
-
-use Exporter 'import';
-use make::configure;
-our @EXPORT = qw(make_openssl_cert);
-
-
-sub make_openssl_cert()
-{
-       open (FH, ">openssl.template");
-       my $org = promptstring_s("Please enter the organization name", "My IRC Network");
-       my $unit = promptstring_s("Please enter the unit Name", "Server Admins");
-       my $country = promptstring_s("Please enter your country (two letter code)", "US");
-       my $state = promptstring_s("Please enter your state or locality name", "Alaska");
-       my $city = promptstring_s("Please enter your city", "Factory Town");
-       my $email = promptstring_s("Please enter a contact email address", "oompa\@loompa.com");
-       my $commonname = promptstring_s("Please enter the common name (domain name) of the irc server", "example.inspircd.org");
-       print FH <<__END__;
-$country
-$state
-$city
-$org
-$unit
-$commonname
-$email
-__END__
-close(FH);
-
-my $time = promptstring_s("Please enter the number of days that this certificate is valid for","365");
-
-system("cat openssl.template | openssl req -x509 -nodes -newkey rsa:1024 -keyout key.pem -out cert.pem -days $time 2>/dev/null");
-system("openssl dhparam -out dhparams.pem 1024");
-unlink("openssl.template");
-}
-
-1;
index e55e36c0a2410859a3759cdfdf96ca7b984cf587..032fff5e2178caa9840f47ea2d07d2bbbb2e1005 100644 (file)
@@ -230,6 +230,7 @@ install: target
        [ $(BUILDPATH)/modules/ -ef $(MODPATH) ] || $(INSTALL) -m $(INSTMODE_LIB) $(BUILDPATH)/modules/*.so $(MODPATH)
 @ENDIF
        -$(INSTALL) -m $(INSTMODE_BIN) @STARTSCRIPT@ $(BASE) 2>/dev/null
+       -$(INSTALL) -m $(INSTMODE_BIN) tools/genssl $(BINPATH)/inspircd-genssl 2>/dev/null
        -$(INSTALL) -m $(INSTMODE_LIB) tools/gdbargs $(BASE)/.gdbargs 2>/dev/null
        -$(INSTALL) -m $(INSTMODE_LIB) docs/conf/*.example $(CONPATH)/examples
        -$(INSTALL) -m $(INSTMODE_LIB) docs/conf/aliases/*.example $(CONPATH)/examples/aliases
@@ -275,8 +276,7 @@ configureclean:
        rm -f .config.cache
        rm -f BSDmakefile
        rm -f GNUmakefile
-       rm -f include/inspircd_config.h
-       rm -f include/inspircd_version.h
+       rm -f include/config.h
        rm -f inspircd
        -rm -f org.inspircd.plist
 
diff --git a/make/test/clock_gettime.cpp b/make/test/clock_gettime.cpp
new file mode 100644 (file)
index 0000000..91d8cd4
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <time.h>
+
+int main() {
+       timespec time_spec;
+       clock_gettime(CLOCK_REALTIME, &time_spec);
+       return 0;
+}
diff --git a/make/test/eventfd.cpp b/make/test/eventfd.cpp
new file mode 100644 (file)
index 0000000..980d044
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <sys/eventfd.h>
+
+int main() {
+       eventfd_t efd_data;
+       int fd;
+
+       fd = eventfd(0, EFD_NONBLOCK);
+       eventfd_read(fd, &efd_data);
+
+       return (fd < 0);
+}
diff --git a/make/test/kqueue.cpp b/make/test/kqueue.cpp
new file mode 100644 (file)
index 0000000..a8b9882
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <sys/types.h>
+#include <sys/event.h>
+
+int main() {
+       int fd = kqueue();
+       return (fd < 0);
+}
diff --git a/make/test/so_acceptfilter.cpp b/make/test/so_acceptfilter.cpp
new file mode 100644 (file)
index 0000000..0fd4cda
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/socket.h>
+
+#ifndef SO_ACCEPTFILTER
+       #error
+#endif
+
+int main()
+{
+       return 0;
+}
diff --git a/make/test/tcp_defer_accept.cpp b/make/test/tcp_defer_accept.cpp
new file mode 100644 (file)
index 0000000..191b1ac
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <netinet/tcp.h>
+
+#ifndef TCP_DEFER_ACCEPT
+       #error
+#endif
+
+int main()
+{
+       return 0;
+}
index 52449e55e86d7995e34998a92a511547efc96ff9..5106e7270252813ffdbda38f0f4a7f04c74e44ee 100644 (file)
 #include "inspircd.h"
 #include "bancache.h"
 
-BanCacheHit *BanCacheManager::AddHit(const std::string &ip, const std::string &type, const std::string &reason)
-{
-       BanCacheHit *b;
-
-       if (this->BanHash->find(ip) != this->BanHash->end()) // can't have two cache entries on the same IP, sorry..
-               return NULL;
-
-       b = new BanCacheHit(ip, type, reason);
-
-       this->BanHash->insert(std::make_pair(ip, b));
-       return b;
-}
-
 BanCacheHit *BanCacheManager::AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
 {
-       BanCacheHit *b;
-
-       if (this->BanHash->find(ip) != this->BanHash->end()) // can't have two cache entries on the same IP, sorry..
+       BanCacheHit*& b = (*BanHash)[ip];
+       if (b != NULL) // can't have two cache entries on the same IP, sorry..
                return NULL;
 
-       b = new BanCacheHit(ip, type, reason, seconds);
-
-       this->BanHash->insert(std::make_pair(ip, b));
+       b = new BanCacheHit(type, reason, (seconds ? seconds : 86400));
        return b;
 }
 
@@ -55,113 +39,60 @@ BanCacheHit *BanCacheManager::GetHit(const std::string &ip)
 
        if (i == this->BanHash->end())
                return NULL; // free and safe
-       else
-       {
-               if (ServerInstance->Time() > i->second->Expiry)
-               {
-                       ServerInstance->Logs->Log("BANCACHE", DEBUG, "Hit on " + ip + " is out of date, removing!");
-                       RemoveHit(i->second);
-                       return NULL; // out of date
-               }
 
-               return i->second; // hit.
-       }
+       if (RemoveIfExpired(i))
+               return NULL; // expired
+
+       return i->second; // hit.
 }
 
-bool BanCacheManager::RemoveHit(BanCacheHit *b)
+bool BanCacheManager::RemoveIfExpired(BanCacheHash::iterator& it)
 {
-       BanCacheHash::iterator i;
-
-       if (!b)
-               return false; // I don't think so.
-
-       i = this->BanHash->find(b->IP);
-
-       if (i == this->BanHash->end())
-       {
-               // err..
-               ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveHit(): I got asked to remove a hit that wasn't in the hash(?)");
-       }
-       else
-       {
-               this->BanHash->erase(i);
-       }
+       if (ServerInstance->Time() < it->second->Expiry)
+               return false;
 
-       delete b;
+       ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "Hit on " + it->first + " is out of date, removing!");
+       delete it->second;
+       it = BanHash->erase(it);
        return true;
 }
 
-unsigned int BanCacheManager::RemoveEntries(const std::string &type, bool positive)
+void BanCacheManager::RemoveEntries(const std::string& type, bool positive)
 {
-       int removed = 0;
-
-       BanCacheHash::iterator safei;
-
        if (positive)
-               ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing positive hits for " + type);
+               ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCacheManager::RemoveEntries(): Removing positive hits for " + type);
        else
-               ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing negative hits for " + type);
+               ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCacheManager::RemoveEntries(): Removing all negative hits");
 
-       for (BanCacheHash::iterator n = BanHash->begin(); n != BanHash->end(); )
+       for (BanCacheHash::iterator i = BanHash->begin(); i != BanHash->end(); )
        {
-               safei = n;
-               safei++;
+               if (RemoveIfExpired(i))
+                       continue; // updates the iterator if expired
 
-               BanCacheHit *b = n->second;
+               BanCacheHit* b = i->second;
+               bool remove = false;
 
-               /* Safe to delete items here through iterator 'n' */
-               if (b->Type == type || !positive) // if removing negative hits, ignore type..
+               if (positive)
                {
-                       if ((positive && !b->Reason.empty()) || b->Reason.empty())
-                       {
-                               /* we need to remove this one. */
-                               ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing a hit on " + b->IP);
-                               delete b;
-                               BanHash->erase(n); // WORD TO THE WISE: don't use RemoveHit here, because we MUST remove the iterator in a safe way.
-                               removed++;
-                       }
+                       // when removing positive hits, remove only if the type matches
+                       remove = b->IsPositive() && (b->Type == type);
+               }
+               else
+               {
+                       // when removing negative hits, remove all of them
+                       remove = !b->IsPositive();
                }
 
-               /* End of safe section */
-               n = safei;
-       }
-
-
-       return removed;
-}
-
-void BanCacheManager::RehashCache()
-{
-       BanCacheHash* NewHash = new BanCacheHash();
-
-       BanCacheHash::iterator safei;
-       for (BanCacheHash::iterator n = BanHash->begin(); n != BanHash->end(); )
-       {
-               safei = n;
-               safei++;
-
-               /* Safe to delete items here through iterator 'n' */
-               BanCacheHit *b = n->second;
-
-               if (ServerInstance->Time() > b->Expiry)
+               if (remove)
                {
                        /* we need to remove this one. */
+                       ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCacheManager::RemoveEntries(): Removing a hit on " + i->first);
                        delete b;
-                       BanHash->erase(n); // WORD TO THE WISE: don't use RemoveHit here, because we MUST remove the iterator in a safe way.
+                       i = BanHash->erase(i);
                }
                else
-               {
-                       /* Actually inserts a std::pair */
-                       NewHash->insert(*n);
-               }
-
-               /* End of safe section */
-
-               n = safei;
+                       ++i;
        }
-
-       delete BanHash;
-       BanHash = NewHash;
 }
 
 BanCacheManager::~BanCacheManager()
index 66a3cb140076e0db326435458b98b8b7fecf8f06..db8d9f3cfe3dfd836314d41a6f1ca7677fc9090b 100644 (file)
 classbase::classbase()
 {
        if (ServerInstance && ServerInstance->Logs)
-               ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::+ @%p", (void*)this);
+               ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "classbase::+ @%p", (void*)this);
 }
 
 CullResult classbase::cull()
 {
        if (ServerInstance && ServerInstance->Logs)
-               ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::-%s @%p",
+               ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "classbase::-%s @%p",
                        typeid(*this).name(), (void*)this);
        return CullResult();
 }
@@ -42,7 +42,7 @@ CullResult classbase::cull()
 classbase::~classbase()
 {
        if (ServerInstance && ServerInstance->Logs)
-               ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::~ @%p", (void*)this);
+               ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "classbase::~ @%p", (void*)this);
 }
 
 CullResult::CullResult()
@@ -74,14 +74,14 @@ refcountbase::refcountbase() : refcount(0)
 refcountbase::~refcountbase()
 {
        if (refcount && ServerInstance && ServerInstance->Logs)
-               ServerInstance->Logs->Log("CULLLIST", DEBUG, "refcountbase::~ @%p with refcount %d",
+               ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "refcountbase::~ @%p with refcount %d",
                        (void*)this, refcount);
 }
 
 usecountbase::~usecountbase()
 {
        if (usecount && ServerInstance && ServerInstance->Logs)
-               ServerInstance->Logs->Log("CULLLIST", DEBUG, "usecountbase::~ @%p with refcount %d",
+               ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "usecountbase::~ @%p with refcount %d",
                        (void*)this, usecount);
 }
 
@@ -198,8 +198,7 @@ CullResult Extensible::cull()
 Extensible::~Extensible()
 {
        if (!extensions.empty() && ServerInstance && ServerInstance->Logs)
-               ServerInstance->Logs->Log("CULLLIST", DEBUG,
-                       "Extensible destructor called without cull @%p", (void*)this);
+               ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "Extensible destructor called without cull @%p", (void*)this);
 }
 
 LocalExtItem::LocalExtItem(const std::string& Key, Module* mod) : ExtensionItem(Key, mod)
index 4f63654a57eea9f9555e44554fa26c8c553a9348..0d43bc802e129b89151ab5935b10f62aee28682f 100644 (file)
 /* $Core */
 
 #include "inspircd.h"
+#include "listmode.h"
 #include <cstdarg>
 #include "mode.h"
 
+static ModeReference ban(NULL, "ban");
+
 Channel::Channel(const std::string &cname, time_t ts)
 {
        if (!ServerInstance->chanlist->insert(std::make_pair(cname, this)).second)
@@ -37,7 +40,7 @@ Channel::Channel(const std::string &cname, time_t ts)
        this->name = cname;
        this->age = ts ? ts : ServerInstance->Time();
 
-       maxbans = topicset = 0;
+       topicset = 0;
        modes.reset();
 }
 
@@ -91,8 +94,6 @@ std::string Channel::GetModeParameter(ModeHandler* mode)
 
 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
 {
-       if (!u)
-               u = ServerInstance->FakeClient;
        if (IS_LOCAL(u) && !forceset)
        {
                ModResult res;
@@ -116,17 +117,8 @@ int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
        }
 
        this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
-       if (u)
-       {
-               this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
-               this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
-       }
-       else
-       {
-               this->setby.assign(ServerInstance->Config->ServerName);
-               this->WriteChannelWithServ(ServerInstance->Config->ServerName, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
-       }
-
+       this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
+       this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
        this->topicset = ServerInstance->Time();
 
        FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic));
@@ -134,51 +126,54 @@ int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
        return CMD_SUCCESS;
 }
 
-long Channel::GetUserCounter()
-{
-       return userlist.size();
-}
-
 Membership* Channel::AddUser(User* user)
 {
-       Membership* memb = new Membership(user, this);
-       userlist[user] = memb;
+       Membership*& memb = userlist[user];
+       if (memb)
+               return NULL;
+
+       memb = new Membership(user, this);
        return memb;
 }
 
 void Channel::DelUser(User* user)
 {
-       UserMembIter a = userlist.find(user);
+       UserMembIter it = userlist.find(user);
+       if (it != userlist.end())
+               DelUser(it);
+}
 
-       if (a != userlist.end())
-       {
-               a->second->cull();
-               delete a->second;
-               userlist.erase(a);
-       }
+void Channel::CheckDestroy()
+{
+       if (!userlist.empty())
+               return;
 
-       if (userlist.empty())
-       {
-               ModResult res;
-               FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
-               if (res == MOD_RES_DENY)
-                       return;
-               chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
-               /* kill the record */
-               if (iter != ServerInstance->chanlist->end())
-               {
-                       FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
-                       ServerInstance->chanlist->erase(iter);
-               }
+       ModResult res;
+       FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
+       if (res == MOD_RES_DENY)
+               return;
 
-               ClearInvites();
-               ServerInstance->GlobalCulls.AddItem(this);
+       chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
+       /* kill the record */
+       if (iter != ServerInstance->chanlist->end())
+       {
+               FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
+               ServerInstance->chanlist->erase(iter);
        }
+
+       ClearInvites();
+       ServerInstance->GlobalCulls.AddItem(this);
 }
 
-bool Channel::HasUser(User* user)
+void Channel::DelUser(const UserMembIter& membiter)
 {
-       return (userlist.find(user) != userlist.end());
+       Membership* memb = membiter->second;
+       memb->cull();
+       delete memb;
+       userlist.erase(membiter);
+
+       // If this channel became empty then it should be removed
+       CheckDestroy();
 }
 
 Membership* Channel::GetUser(User* user)
@@ -189,14 +184,9 @@ Membership* Channel::GetUser(User* user)
        return i->second;
 }
 
-const UserMembList* Channel::GetUsers()
-{
-       return &userlist;
-}
-
 void Channel::SetDefaultModes()
 {
-       ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s",
+       ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "SetDefaultModes %s",
                ServerInstance->Config->DefaultModes.c_str());
        irc::spacesepstream list(ServerInstance->Config->DefaultModes);
        std::string modeseq;
@@ -223,14 +213,13 @@ void Channel::SetDefaultModes()
  * add a channel to a user, creating the record for it if needed and linking
  * it to the user record
  */
-Channel* Channel::JoinUser(User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
+Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, const std::string& key)
 {
-       // Fix: unregistered users could be joined using /SAJOIN
-       if (!user || !cn || user->registered != REG_ALL)
+       if (user->registered != REG_ALL)
+       {
+               ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join unregistered user " + user->uuid + " to channel " + cname);
                return NULL;
-
-       std::string privs;
-       Channel *Ptr;
+       }
 
        /*
         * We don't restrict the number of channels that remote users or users that are override-joining may be in.
@@ -238,13 +227,13 @@ Channel* Channel::JoinUser(User *user, const char* cn, bool override, const char
         * We restrict local operators to OperMaxChans channels.
         * This is a lot more logical than how it was formerly. -- w00t
         */
-       if (IS_LOCAL(user) && !override)
+       if (!override)
        {
                if (user->HasPrivPermission("channels/high-join-limit"))
                {
                        if (user->chans.size() >= ServerInstance->Config->OperMaxChans)
                        {
-                               user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
+                               user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cname.c_str());
                                return NULL;
                        }
                }
@@ -255,102 +244,99 @@ Channel* Channel::JoinUser(User *user, const char* cn, bool override, const char
                                maxchans = ServerInstance->Config->MaxChans;
                        if (user->chans.size() >= maxchans)
                        {
-                               user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
+                               user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cname.c_str());
                                return NULL;
                        }
                }
        }
 
-       std::string cname;
-       cname.assign(std::string(cn), 0, ServerInstance->Config->Limits.ChanMax);
-       Ptr = ServerInstance->FindChan(cname);
-       bool created_by_local = false;
+       // Crop channel name if it's too long
+       if (cname.length() > ServerInstance->Config->Limits.ChanMax)
+               cname.resize(ServerInstance->Config->Limits.ChanMax);
+
+       Channel* chan = ServerInstance->FindChan(cname);
+       bool created_by_local = (chan == NULL); // Flag that will be passed to modules in the OnUserJoin() hook later
+       std::string privs; // Prefix mode(letter)s to give to the joining user
 
-       if (!Ptr)
+       if (!chan)
        {
-               /*
-                * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
-                */
-               if (!IS_LOCAL(user))
-               {
-                       if (!TS)
-                               ServerInstance->Logs->Log("CHANNELS",DEBUG,"*** BUG *** Channel::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick.c_str(), cn);
-               }
-               else
-               {
-                       privs = "o";
-                       created_by_local = true;
-               }
+               privs = "o";
 
-               if (IS_LOCAL(user) && override == false)
+               if (override == false)
                {
+                       // Ask the modules whether they're ok with the join, pass NULL as Channel* as the channel is yet to be created
                        ModResult MOD_RESULT;
-                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname.c_str(), privs, key ? key : ""));
+                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key));
                        if (MOD_RESULT == MOD_RES_DENY)
-                               return NULL;
+                               return NULL; // A module wasn't happy with the join, abort
                }
 
-               Ptr = new Channel(cname, TS);
+               chan = new Channel(cname, ServerInstance->Time());
+               // Set the default modes on the channel (<options:defaultmodes>)
+               chan->SetDefaultModes();
        }
        else
        {
                /* Already on the channel */
-               if (Ptr->HasUser(user))
+               if (chan->HasUser(user))
                        return NULL;
 
-               /*
-                * remote users are allowed us to bypass channel modes
-                * and bans (used by servers)
-                */
-               if (IS_LOCAL(user) && override == false)
+               if (override == false)
                {
                        ModResult MOD_RESULT;
-                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, Ptr, cname.c_str(), privs, key ? key : ""));
+                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, chan, cname, privs, key));
+
+                       // A module explicitly denied the join and (hopefully) generated a message
+                       // describing the situation, so we may stop here without sending anything
                        if (MOD_RESULT == MOD_RES_DENY)
-                       {
                                return NULL;
-                       }
-                       else if (MOD_RESULT == MOD_RES_PASSTHRU)
+
+                       // If no module returned MOD_RES_DENY or MOD_RES_ALLOW (which is the case
+                       // most of the time) then proceed to check channel modes +k, +i, +l and bans,
+                       // in this order.
+                       // If a module explicitly allowed the join (by returning MOD_RES_ALLOW),
+                       // then this entire section is skipped
+                       if (MOD_RESULT == MOD_RES_PASSTHRU)
                        {
-                               std::string ckey = Ptr->GetModeParameter('k');
-                               bool invited = IS_LOCAL(user)->IsInvited(Ptr->name.c_str());
+                               std::string ckey = chan->GetModeParameter('k');
+                               bool invited = user->IsInvited(chan);
                                bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
 
                                if (!ckey.empty())
                                {
-                                       FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, Ptr, key ? key : ""));
-                                       if (!MOD_RESULT.check((key && ckey == key) || can_bypass))
+                                       FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key));
+                                       if (!MOD_RESULT.check((ckey == key) || can_bypass))
                                        {
                                                // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
-                                               user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
+                                               user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), chan->name.c_str());
                                                return NULL;
                                        }
                                }
 
-                               if (Ptr->IsModeSet('i'))
+                               if (chan->IsModeSet('i'))
                                {
-                                       FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, Ptr));
+                                       FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
                                        if (!MOD_RESULT.check(invited))
                                        {
-                                               user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
+                                               user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), chan->name.c_str());
                                                return NULL;
                                        }
                                }
 
-                               std::string limit = Ptr->GetModeParameter('l');
+                               std::string limit = chan->GetModeParameter('l');
                                if (!limit.empty())
                                {
-                                       FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, Ptr));
-                                       if (!MOD_RESULT.check((Ptr->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
+                                       FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
+                                       if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
                                        {
-                                               user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
+                                               user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), chan->name.c_str());
                                                return NULL;
                                        }
                                }
 
-                               if (Ptr->IsBanned(user) && !can_bypass)
+                               if (chan->IsBanned(user) && !can_bypass)
                                {
-                                       user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
+                                       user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), chan->name.c_str());
                                        return NULL;
                                }
 
@@ -360,67 +346,78 @@ Channel* Channel::JoinUser(User *user, const char* cn, bool override, const char
                                 */
                                if (invited)
                                {
-                                       IS_LOCAL(user)->RemoveInvite(Ptr->name.c_str());
+                                       user->RemoveInvite(chan);
                                }
                        }
                }
        }
 
-       if (created_by_local)
-       {
-               /* As spotted by jilles, dont bother to set this on remote users */
-               Ptr->SetDefaultModes();
-       }
-
-       return Channel::ForceChan(Ptr, user, privs, bursting, created_by_local);
+       // We figured that this join is allowed and also created the
+       // channel if it didn't exist before, now do the actual join
+       chan->ForceJoin(user, &privs, false, created_by_local);
+       return chan;
 }
 
-Channel* Channel::ForceChan(Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
+void Channel::ForceJoin(User* user, const std::string* privs, bool bursting, bool created_by_local)
 {
-       std::string nick = user->nick;
+       Membership* memb = this->AddUser(user);
+       if (!memb)
+               return; // Already on the channel
+
+       if (IS_SERVER(user))
+       {
+               ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join server user " + user->uuid + " to channel " + this->name);
+               return;
+       }
 
-       Membership* memb = Ptr->AddUser(user);
-       user->chans.insert(Ptr);
+       user->chans.insert(this);
 
-       for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
+       if (privs)
        {
-               const char status = *x;
-               ModeHandler* mh = ServerInstance->Modes->FindMode(status, MODETYPE_CHANNEL);
-               if (mh)
+               // If the user was granted prefix modes (in the OnUserPreJoin hook, or he's a
+               // remote user and his own server set the modes), then set them internally now
+               memb->modes = *privs;
+               for (std::string::const_iterator i = privs->begin(); i != privs->end(); ++i)
                {
-                       /* Set, and make sure that the mode handler knows this mode was now set */
-                       Ptr->SetPrefix(user, mh->GetModeChar(), true);
-                       mh->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, Ptr, nick, true);
+                       ModeHandler* mh = ServerInstance->Modes->FindMode(*i, MODETYPE_CHANNEL);
+                       if (mh)
+                       {
+                               std::string nick = user->nick;
+                               /* Set, and make sure that the mode handler knows this mode was now set */
+                               this->SetPrefix(user, mh->GetModeChar(), true);
+                               mh->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, nick, true);
+                       }
                }
        }
 
+       // Tell modules about this join, they have the chance now to populate except_list with users we won't send the JOIN (and possibly MODE) to
        CUList except_list;
-       FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created, except_list));
+       FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created_by_local, except_list));
 
-       Ptr->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", Ptr->name.c_str());
+       this->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", this->name.c_str());
 
        /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
-       if ((Ptr->GetUserCounter() > 1) && (!memb->modes.empty()))
+       if ((GetUserCounter() > 1) && (!memb->modes.empty()))
        {
                std::string ms = memb->modes;
                for(unsigned int i=0; i < memb->modes.length(); i++)
                        ms.append(" ").append(user->nick);
 
                except_list.insert(user);
-               Ptr->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
+               this->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", this->name.c_str(), ms.c_str());
        }
 
        if (IS_LOCAL(user))
        {
-               if (Ptr->topicset)
+               if (this->topicset)
                {
-                       user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
-                       user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
+                       user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), this->name.c_str(), this->topic.c_str());
+                       user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), this->name.c_str(), this->setby.c_str(), (unsigned long)this->topicset);
                }
-               Ptr->UserList(user);
+               this->UserList(user);
        }
+
        FOREACH_MOD(I_OnPostJoin,OnPostJoin(memb));
-       return Ptr;
 }
 
 bool Channel::IsBanned(User* user)
@@ -431,10 +428,15 @@ bool Channel::IsBanned(User* user)
        if (result != MOD_RES_PASSTHRU)
                return (result == MOD_RES_DENY);
 
-       for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+       ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+       const ListModeBase::ModeList* bans = banlm->GetList(this);
+       if (bans)
        {
-               if (CheckBan(user, i->data))
-                       return true;
+               for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); it++)
+               {
+                       if (CheckBan(user, it->mask))
+                               return true;
+               }
        }
        return false;
 }
@@ -454,10 +456,9 @@ bool Channel::CheckBan(User* user, const std::string& mask)
        if (at == std::string::npos)
                return false;
 
-       char tomatch[MAXBUF];
-       snprintf(tomatch, MAXBUF, "%s!%s", user->nick.c_str(), user->ident.c_str());
+       const std::string nickIdent = user->nick + "!" + user->ident;
        std::string prefix = mask.substr(0, at);
-       if (InspIRCd::Match(tomatch, prefix, NULL))
+       if (InspIRCd::Match(nickIdent, prefix, NULL))
        {
                std::string suffix = mask.substr(at + 1);
                if (InspIRCd::Match(user->host, suffix, NULL) ||
@@ -474,12 +475,15 @@ ModResult Channel::GetExtBanStatus(User *user, char type)
        FIRST_MOD_RESULT(OnExtBanCheck, rv, (user, this, type));
        if (rv != MOD_RES_PASSTHRU)
                return rv;
-       for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+
+       ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+       const ListModeBase::ModeList* bans = banlm->GetList(this);
+       if (bans)
+
        {
-               if (i->data[0] == type && i->data[1] == ':')
+               for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); ++it)
                {
-                       std::string val = i->data.substr(2);
-                       if (CheckBan(user, val))
+                       if (CheckBan(user, it->mask))
                                return MOD_RES_DENY;
                }
        }
@@ -487,61 +491,54 @@ ModResult Channel::GetExtBanStatus(User *user, char type)
 }
 
 /* Channel::PartUser
- * remove a channel from a users record, and return the number of users left.
- * Therefore, if this function returns 0 the caller should delete the Channel.
+ * Remove a channel from a users record, remove the reference to the Membership object
+ * from the channel and destroy it.
  */
 void Channel::PartUser(User *user, std::string &reason)
 {
-       if (!user)
-               return;
-
-       Membership* memb = GetUser(user);
+       UserMembIter membiter = userlist.find(user);
 
-       if (memb)
+       if (membiter != userlist.end())
        {
+               Membership* memb = membiter->second;
                CUList except_list;
                FOREACH_MOD(I_OnUserPart,OnUserPart(memb, reason, except_list));
 
                WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
 
+               // Remove this channel from the user's chanlist
                user->chans.erase(this);
-               this->RemoveAllPrefixes(user);
+               // Remove the Membership from this channel's userlist and destroy it
+               this->DelUser(membiter);
        }
-
-       this->DelUser(user);
 }
 
-void Channel::KickUser(User *src, User *user, const char* reason)
+void Channel::KickUser(User* src, User* victim, const std::string& reason, Membership* srcmemb)
 {
-       if (!src || !user || !reason)
+       UserMembIter victimiter = userlist.find(victim);
+       Membership* memb = ((victimiter != userlist.end()) ? victimiter->second : NULL);
+
+       if (!memb)
+       {
+               src->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s %s :They are not on that channel",src->nick.c_str(), victim->nick.c_str(), this->name.c_str());
                return;
+       }
 
-       Membership* memb = GetUser(user);
+       // Do the following checks only if the KICK is done by a local user;
+       // each server enforces its own rules.
        if (IS_LOCAL(src))
        {
-               if (!memb)
-               {
-                       src->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s %s :They are not on that channel",src->nick.c_str(), user->nick.c_str(), this->name.c_str());
-                       return;
-               }
-               if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
-               {
-                       src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only a u-line may kick a u-line from a channel.",src->nick.c_str(), this->name.c_str());
-                       return;
-               }
-
+               // Modules are allowed to explicitly allow or deny kicks done by local users
                ModResult res;
-               if (ServerInstance->ULine(src->server))
-                       res = MOD_RES_ALLOW;
-               else
-                       FIRST_MOD_RESULT(OnUserPreKick, res, (src,memb,reason));
-
+               FIRST_MOD_RESULT(OnUserPreKick, res, (src,memb,reason));
                if (res == MOD_RES_DENY)
                        return;
 
                if (res == MOD_RES_PASSTHRU)
                {
-                       unsigned int them = this->GetPrefixValue(src);
+                       if (!srcmemb)
+                               srcmemb = GetUser(src);
+                       unsigned int them = srcmemb ? srcmemb->getRank() : 0;
                        unsigned int req = HALFOP_VALUE;
                        for (std::string::size_type i = 0; i < memb->modes.length(); i++)
                        {
@@ -559,78 +556,48 @@ void Channel::KickUser(User *src, User *user, const char* reason)
                }
        }
 
-       if (memb)
-       {
-               CUList except_list;
-               FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
-
-               WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason);
+       CUList except_list;
+       FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
 
-               user->chans.erase(this);
-               this->RemoveAllPrefixes(user);
-       }
+       WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), victim->nick.c_str(), reason.c_str());
 
-       this->DelUser(user);
+       victim->chans.erase(this);
+       this->DelUser(victimiter);
 }
 
 void Channel::WriteChannel(User* user, const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       if (!user || !text)
-               return;
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteChannel(user, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteChannel(user, textbuffer);
 }
 
 void Channel::WriteChannel(User* user, const std::string &text)
 {
-       char tb[MAXBUF];
-
-       if (!user)
-               return;
-
-       snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
-       std::string out = tb;
+       const std::string message = ":" + user->GetFullHost() + " " + text;
 
        for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
        {
                if (IS_LOCAL(i->first))
-                       i->first->Write(out);
+                       i->first->Write(message);
        }
 }
 
 void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       if (!text)
-               return;
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteChannelWithServ(ServName, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteChannelWithServ(ServName, textbuffer);
 }
 
 void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
 {
-       char tb[MAXBUF];
-
-       snprintf(tb,MAXBUF,":%s %s", ServName.empty() ? ServerInstance->Config->ServerName.c_str() : ServName.c_str(), text.c_str());
-       std::string out = tb;
+       const std::string message = ":" + (ServName.empty() ? ServerInstance->Config->ServerName : ServName) + " " + text;
 
        for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
        {
                if (IS_LOCAL(i->first))
-                       i->first->Write(out);
+                       i->first->Write(message);
        }
 }
 
@@ -638,43 +605,23 @@ void Channel::WriteChannelWithServ(const std::string& ServName, const std::strin
  * for the sender (for privmsg etc) */
 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       if (!text)
-               return;
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteAllExceptSender(user, serversource, status, textbuffer);
 }
 
 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       if (!text)
-               return;
-
-       int offset = snprintf(textbuffer,MAXBUF,":%s ", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str());
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
-       va_end(argsPtr);
-
-       this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       textbuffer = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + textbuffer;
+       this->RawWriteAllExcept(user, serversource, status, except_list, textbuffer);
 }
 
 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
 {
-       char tb[MAXBUF];
-
-       snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str());
-
-       this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
+       const std::string message = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + text;
+       this->RawWriteAllExcept(user, serversource, status, except_list, message);
 }
 
 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
@@ -706,59 +653,37 @@ void Channel::WriteAllExceptSender(User* user, bool serversource, char status, c
        this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
 }
 
-/*
- * return a count of the users on a specific channel accounting for
- * invisible users who won't increase the count. e.g. for /LIST
- */
-int Channel::CountInvisible()
-{
-       int count = 0;
-       for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
-       {
-               if (!i->first->quitting && !i->first->IsModeSet('i'))
-                       count++;
-       }
-
-       return count;
-}
-
-char* Channel::ChanModes(bool showkey)
+const char* Channel::ChanModes(bool showkey)
 {
-       static char scratch[MAXBUF];
-       static char sparam[MAXBUF];
-       char* offset = scratch;
-       std::string extparam;
+       static std::string scratch;
+       std::string sparam;
 
-       *scratch = '\0';
-       *sparam = '\0';
+       scratch.clear();
 
        /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
        for(int n = 0; n < 64; n++)
        {
                if(this->modes[n])
                {
-                       *offset++ = n + 65;
-                       extparam.clear();
+                       scratch.push_back(n + 65);
                        if (n == 'k' - 65 && !showkey)
                        {
-                               extparam = "<key>";
+                               sparam += " <key>";
                        }
                        else
                        {
-                               extparam = this->GetModeParameter(n + 65);
-                       }
-                       if (!extparam.empty())
-                       {
-                               charlcat(sparam,' ',MAXBUF);
-                               strlcat(sparam,extparam.c_str(),MAXBUF);
+                               const std::string param = this->GetModeParameter(n + 65);
+                               if (!param.empty())
+                               {
+                                       sparam += ' ';
+                                       sparam += param;
+                               }
                        }
                }
        }
 
-       /* Null terminate scratch */
-       *offset = '\0';
-       strlcat(scratch,sparam,MAXBUF);
-       return scratch;
+       scratch += sparam;
+       return scratch.c_str();
 }
 
 /* compile a userlist of a channel into a string, each nick seperated by
@@ -766,29 +691,29 @@ char* Channel::ChanModes(bool showkey)
  */
 void Channel::UserList(User *user)
 {
-       char list[MAXBUF];
-       size_t dlen, curlen;
-
-       if (!IS_LOCAL(user))
-               return;
-
        if (this->IsModeSet('s') && !this->HasUser(user) && !user->HasPrivPermission("channels/auspex"))
        {
                user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
                return;
        }
 
-       dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=',  this->name.c_str());
+       std::string list = user->nick;
+       list.push_back(' ');
+       list.push_back(this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=');
+       list.push_back(' ');
+       list.append(this->name).append(" :");
+       std::string::size_type pos = list.size();
 
-       int numusers = 0;
-       char* ptr = list + dlen;
+       bool has_one = false;
 
        /* Improvement by Brain - this doesnt change in value, so why was it inside
         * the loop?
         */
        bool has_user = this->HasUser(user);
 
-       for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
+       std::string prefixlist;
+       std::string nick;
+       for (UserMembIter i = userlist.begin(); i != userlist.end(); ++i)
        {
                if (i->first->quitting)
                        continue;
@@ -801,8 +726,8 @@ void Channel::UserList(User *user)
                        continue;
                }
 
-               std::string prefixlist = this->GetPrefixChar(i->first);
-               std::string nick = i->first->nick;
+               prefixlist = this->GetPrefixChar(i->first);
+               nick = i->first->nick;
 
                FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->second, prefixlist, nick));
 
@@ -810,63 +735,30 @@ void Channel::UserList(User *user)
                if (nick.empty())
                        continue;
 
-               size_t ptrlen = 0;
-
-               if (curlen + prefixlist.length() + nick.length() + 1 > 480)
+               if (list.size() + prefixlist.length() + nick.length() + 1 > 480)
                {
                        /* list overflowed into multiple numerics */
-                       user->WriteNumeric(RPL_NAMREPLY, std::string(list));
-
-                       /* reset our lengths */
-                       dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
-                       ptr = list + dlen;
+                       user->WriteNumeric(RPL_NAMREPLY, list);
 
-                       numusers = 0;
+                       // Erase all nicks, keep the constant part
+                       list.erase(pos);
+                       has_one = false;
                }
 
-               ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
+               list.append(prefixlist).append(nick).push_back(' ');
 
-               curlen += ptrlen;
-               ptr += ptrlen;
-
-               numusers++;
+               has_one = true;
        }
 
        /* if whats left in the list isnt empty, send it */
-       if (numusers)
+       if (has_one)
        {
-               user->WriteNumeric(RPL_NAMREPLY, std::string(list));
+               user->WriteNumeric(RPL_NAMREPLY, list);
        }
 
        user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
 }
 
-long Channel::GetMaxBans()
-{
-       /* Return the cached value if there is one */
-       if (this->maxbans)
-               return this->maxbans;
-
-       /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
-       for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
-       {
-               if (InspIRCd::Match(this->name, n->first, NULL))
-               {
-                       this->maxbans = n->second;
-                       return n->second;
-               }
-       }
-
-       /* Screw it, just return the default of 64 */
-       this->maxbans = 64;
-       return this->maxbans;
-}
-
-void Channel::ResetMaxBans()
-{
-       this->maxbans = 0;
-}
-
 /* returns the status character for a given user on a channel, e.g. @ for op,
  * % for halfop etc. If the user has several modes set, the highest mode
  * the user has must be returned.
@@ -962,22 +854,13 @@ bool Channel::SetPrefix(User* user, char prefix, bool adding)
        return adding;
 }
 
-void Channel::RemoveAllPrefixes(User* user)
-{
-       UserMembIter m = userlist.find(user);
-       if (m != userlist.end())
-       {
-               m->second->modes.clear();
-       }
-}
-
 void Invitation::Create(Channel* c, LocalUser* u, time_t timeout)
 {
        if ((timeout != 0) && (ServerInstance->Time() >= timeout))
                // Expired, don't bother
                return;
 
-       ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Create chan=%s user=%s", c->name.c_str(), u->uuid.c_str());
+       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create chan=%s user=%s", c->name.c_str(), u->uuid.c_str());
 
        Invitation* inv = Invitation::Find(c, u, false);
        if (inv)
@@ -985,20 +868,20 @@ void Invitation::Create(Channel* c, LocalUser* u, time_t timeout)
                 if ((inv->expiry == 0) || (inv->expiry > timeout))
                        return;
                inv->expiry = timeout;
-               ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Create changed expiry in existing invitation %p", (void*) inv);
+               ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create changed expiry in existing invitation %p", (void*) inv);
        }
        else
        {
                inv = new Invitation(c, u, timeout);
                c->invites.push_back(inv);
                u->invites.push_back(inv);
-               ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Create created new invitation %p", (void*) inv);
+               ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create created new invitation %p", (void*) inv);
        }
 }
 
 Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
 {
-       ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Find chan=%s user=%s check_expired=%d", c ? c->name.c_str() : "NULL", u ? u->uuid.c_str() : "NULL", check_expired);
+       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find chan=%s user=%s check_expired=%d", c ? c->name.c_str() : "NULL", u ? u->uuid.c_str() : "NULL", check_expired);
        if (!u || u->invites.empty())
                return NULL;
 
@@ -1013,7 +896,7 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
                {
                        /* Expired invite, remove it. */
                        std::string expiration = ServerInstance->TimeString(inv->expiry);
-                       ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str());
+                       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str());
                        i = locallist.erase(i);
                        inv->cull();
                        delete inv;
@@ -1031,7 +914,7 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
        }
 
        locallist.swap(u->invites);
-       ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Find result=%p", (void*) result);
+       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find result=%p", (void*) result);
        return result;
 }
 
@@ -1048,7 +931,7 @@ Invitation::~Invitation()
 
 void InviteBase::ClearInvites()
 {
-       ServerInstance->Logs->Log("INVITEBASE", DEBUG, "InviteBase::ClearInvites %p", (void*) this);
+       ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "InviteBase::ClearInvites %p", (void*) this);
        InviteList locallist;
        locallist.swap(invites);
        for (InviteList::const_iterator i = locallist.begin(); i != locallist.end(); ++i)
index b05b34c9b5c49b756585748de05bc3431606d292..7bedcd71e39cbfed403c91ae0f1005d88246cb15 100644 (file)
@@ -181,7 +181,7 @@ CmdResult CommandParser::CallHandler(const std::string &commandname, const std::
        return CMD_INVALID;
 }
 
-bool CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
+void CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
 {
        std::vector<std::string> command_p;
        irc::tokenstream tokens(cmd);
@@ -196,29 +196,27 @@ bool CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
        if (command[0] == ':')
                tokens.GetToken(command);
 
-       while (tokens.GetToken(token) && (command_p.size() <= MAXPARAMETERS))
+       while (tokens.GetToken(token))
                command_p.push_back(token);
 
        std::transform(command.begin(), command.end(), command.begin(), ::toupper);
 
        /* find the command, check it exists */
-       Commandtable::iterator cm = cmdlist.find(command);
+       Command* handler = GetHandler(command);
 
        /* Modify the user's penalty regardless of whether or not the command exists */
-       bool do_more = true;
        if (!user->HasPrivPermission("users/flood/no-throttle"))
        {
                // If it *doesn't* exist, give it a slightly heftier penalty than normal to deter flooding us crap
-               user->CommandFloodPenalty += cm != cmdlist.end() ? cm->second->Penalty * 1000 : 2000;
+               user->CommandFloodPenalty += handler ? handler->Penalty * 1000 : 2000;
        }
 
-
-       if (cm == cmdlist.end())
+       if (!handler)
        {
                ModResult MOD_RESULT;
                FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, command_p, user, false, cmd));
                if (MOD_RESULT == MOD_RES_DENY)
-                       return true;
+                       return;
 
                /*
                 * This double lookup is in case a module (abbreviation) wishes to change a command.
@@ -227,17 +225,19 @@ bool CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
                 * Thanks dz for making me actually understand why this is necessary!
                 * -- w00t
                 */
-               cm = cmdlist.find(command);
-               if (cm == cmdlist.end())
+               handler = GetHandler(command);
+               if (!handler)
                {
                        if (user->registered == REG_ALL)
                                user->WriteNumeric(ERR_UNKNOWNCOMMAND, "%s %s :Unknown command",user->nick.c_str(),command.c_str());
                        ServerInstance->stats->statsUnknown++;
-                       return true;
+                       return;
                }
        }
 
-       if (cm->second->max_params && command_p.size() > cm->second->max_params)
+       // If we were given more parameters than max_params then append the excess parameter(s)
+       // to command_p[maxparams-1], i.e. to the last param that is still allowed
+       if (handler->max_params && command_p.size() > handler->max_params)
        {
                /*
                 * command_p input (assuming max_params 1):
@@ -246,32 +246,21 @@ bool CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
                 *      a
                 *      test
                 */
-               std::string lparam;
 
-               /*
-                * The '-1' here is a clever trick, we'll go backwards throwing everything into a temporary param
-                * and then just toss that into the array.
-                * -- w00t
-                */
-               while (command_p.size() > (cm->second->max_params - 1))
-               {
-                       // BE CAREFUL: .end() returns past the end of the vector, hence decrement.
-                       std::vector<std::string>::iterator it = --command_p.end();
+               // Iterator to the last parameter that will be kept
+               const std::vector<std::string>::iterator lastkeep = command_p.begin() + (handler->max_params - 1);
+               // Iterator to the first excess parameter
+               const std::vector<std::string>::iterator firstexcess = lastkeep + 1;
 
-                       lparam.insert(0, " " + *(it));
-                       command_p.erase(it); // remove last element
+               // Append all excess parameter(s) to the last parameter, seperated by spaces
+               for (std::vector<std::string>::const_iterator i = firstexcess; i != command_p.end(); ++i)
+               {
+                       lastkeep->push_back(' ');
+                       lastkeep->append(*i);
                }
 
-               /* we now have (each iteration):
-                *      ' test'
-                *      ' a test'
-                *      ' is a test' <-- final string
-                * ...now remove the ' ' at the start...
-                */
-               lparam.erase(lparam.begin());
-
-               /* param is now 'is a test', which is exactly what we wanted! */
-               command_p.push_back(lparam);
+               // Erase the excess parameter(s)
+               command_p.erase(firstexcess, command_p.end());
        }
 
        /*
@@ -281,26 +270,28 @@ bool CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
        ModResult MOD_RESULT;
        FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, command_p, user, false, cmd));
        if (MOD_RESULT == MOD_RES_DENY)
-               return true;
+               return;
 
        /* activity resets the ping pending timer */
        user->nping = ServerInstance->Time() + user->MyClass->GetPingTime();
 
-       if (cm->second->flags_needed)
+       if (handler->flags_needed)
        {
-               if (!user->IsModeSet(cm->second->flags_needed))
+               if (!user->IsModeSet(handler->flags_needed))
                {
                        user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - You do not have the required operator privileges",user->nick.c_str());
-                       return do_more;
+                       return;
                }
+
                if (!user->HasPermission(command))
                {
                        user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper type %s does not have access to command %s",
-                               user->nick.c_str(), user->oper->NameStr(), command.c_str());
-                       return do_more;
+                               user->nick.c_str(), user->oper->name.c_str(), command.c_str());
+                       return;
                }
        }
-       if ((user->registered == REG_ALL) && (!IS_OPER(user)) && (cm->second->IsDisabled()))
+
+       if ((user->registered == REG_ALL) && (!user->IsOper()) && (handler->IsDisabled()))
        {
                /* command is disabled! */
                if (ServerInstance->Config->DisabledDontExist)
@@ -315,42 +306,40 @@ bool CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
 
                ServerInstance->SNO->WriteToSnoMask('t', "%s denied for %s (%s@%s)",
                                command.c_str(), user->nick.c_str(), user->ident.c_str(), user->host.c_str());
-               return do_more;
+               return;
        }
 
-       if ((!command_p.empty()) && (command_p.back().empty()) && (!cm->second->allow_empty_last_param))
+       if ((!command_p.empty()) && (command_p.back().empty()) && (!handler->allow_empty_last_param))
                command_p.pop_back();
 
-       if (command_p.size() < cm->second->min_params)
+       if (command_p.size() < handler->min_params)
        {
                user->WriteNumeric(ERR_NEEDMOREPARAMS, "%s %s :Not enough parameters.", user->nick.c_str(), command.c_str());
-               if ((ServerInstance->Config->SyntaxHints) && (user->registered == REG_ALL) && (cm->second->syntax.length()))
-                       user->WriteNumeric(RPL_SYNTAX, "%s :SYNTAX %s %s", user->nick.c_str(), cm->second->name.c_str(), cm->second->syntax.c_str());
-               return do_more;
+               if ((ServerInstance->Config->SyntaxHints) && (user->registered == REG_ALL) && (handler->syntax.length()))
+                       user->WriteNumeric(RPL_SYNTAX, "%s :SYNTAX %s %s", user->nick.c_str(), handler->name.c_str(), handler->syntax.c_str());
+               return;
        }
-       if ((user->registered != REG_ALL) && (!cm->second->WorksBeforeReg()))
+
+       if ((user->registered != REG_ALL) && (!handler->WorksBeforeReg()))
        {
                user->WriteNumeric(ERR_NOTREGISTERED, "%s :You have not registered",command.c_str());
-               return do_more;
        }
        else
        {
                /* passed all checks.. first, do the (ugly) stats counters. */
-               cm->second->use_count++;
-               cm->second->total_bytes += cmd.length();
+               handler->use_count++;
 
                /* module calls too */
                FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, command_p, user, true, cmd));
                if (MOD_RESULT == MOD_RES_DENY)
-                       return do_more;
+                       return;
 
                /*
                 * WARNING: be careful, the user may be deleted soon
                 */
-               CmdResult result = cm->second->Handle(command_p, user);
+               CmdResult result = handler->Handle(command_p, user);
 
                FOREACH_MOD(I_OnPostCommand,OnPostCommand(command, command_p, user, result,cmd));
-               return do_more;
        }
 }
 
@@ -366,14 +355,14 @@ Command::~Command()
        ServerInstance->Parser->RemoveCommand(this);
 }
 
-bool CommandParser::ProcessBuffer(std::string &buffer,LocalUser *user)
+void CommandParser::ProcessBuffer(std::string &buffer,LocalUser *user)
 {
        if (!user || buffer.empty())
-               return true;
+               return;
 
-       ServerInstance->Logs->Log("USERINPUT", RAWIO, "C[%s] I :%s %s",
+       ServerInstance->Logs->Log("USERINPUT", LOG_RAWIO, "C[%s] I :%s %s",
                user->uuid.c_str(), user->nick.c_str(), buffer.c_str());
-       return ProcessCommand(user,buffer);
+       ProcessCommand(user,buffer);
 }
 
 bool CommandParser::AddCommand(Command *f)
index d805a1f6591df580feb874adf6e82b4990747f12..fda1a1734a4bf99d4f3fa1442e9167947534226d 100644 (file)
@@ -127,7 +127,7 @@ CmdResult SplitCommand::Handle(const std::vector<std::string>& parms, User* u)
                return HandleRemote(parms, IS_REMOTE(u));
        if (IS_SERVER(u))
                return HandleServer(parms, IS_SERVER(u));
-       ServerInstance->Logs->Log("COMMAND", DEFAULT, "Unknown user type in command (uuid=%s)!", u->uuid.c_str());
+       ServerInstance->Logs->Log("COMMAND", LOG_DEFAULT, "Unknown user type in command (uuid=%s)!", u->uuid.c_str());
        return CMD_INVALID;
 }
 
diff --git a/src/commands/cmd_clearcache.cpp b/src/commands/cmd_clearcache.cpp
deleted file mode 100644 (file)
index 5914f9a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "inspircd.h"
-
-/** Handle /CLEARCACHE. These command handlers can be reloaded by the core,
- * and handle basic RFC1459 commands. Commands within modules work
- * the same way, however, they can be fully unloaded, where these
- * may not.
- */
-class CommandClearcache : public Command
-{
- public:
-       /** Constructor for clearcache.
-        */
-       CommandClearcache ( Module* parent) : Command(parent,"CLEARCACHE",0) { flags_needed = 'o'; }
-       /** Handle command.
-        * @param parameters The parameters to the comamnd
-        * @param pcnt The number of parameters passed to teh command
-        * @param user The user issuing the command
-        * @return A value from CmdResult to indicate command success or failure.
-        */
-       CmdResult Handle(const std::vector<std::string>& parameters, User *user);
-};
-
-/** Handle /CLEARCACHE
- */
-CmdResult CommandClearcache::Handle (const std::vector<std::string>& parameters, User *user)
-{
-       int n = ServerInstance->Res->ClearCache();
-       user->WriteServ("NOTICE %s :*** Cleared DNS cache of %d items.", user->nick.c_str(), n);
-       return CMD_SUCCESS;
-}
-
-COMMAND_INIT(CommandClearcache)
index 1d6640213c445feab12b9429c56be25b4cb7e4fc..3ccc037b46a0144704f6f7f0c0a843046909242e 100644 (file)
@@ -50,7 +50,7 @@ CmdResult CommandDie::Handle (const std::vector<std::string>& parameters, User *
        {
                {
                        std::string diebuf = "*** DIE command from " + user->GetFullHost() + ". Terminating.";
-                       ServerInstance->Logs->Log("COMMAND",SPARSE, diebuf);
+                       ServerInstance->Logs->Log("COMMAND", LOG_SPARSE, diebuf);
                        ServerInstance->SendError(diebuf);
                }
 
@@ -58,7 +58,7 @@ CmdResult CommandDie::Handle (const std::vector<std::string>& parameters, User *
        }
        else
        {
-               ServerInstance->Logs->Log("COMMAND",SPARSE, "Failed /DIE command from %s", user->GetFullRealHost().c_str());
+               ServerInstance->Logs->Log("COMMAND", LOG_SPARSE, "Failed /DIE command from %s", user->GetFullRealHost().c_str());
                ServerInstance->SNO->WriteGlobalSno('a', "Failed DIE Command from %s.", user->GetFullRealHost().c_str());
                return CMD_FAILURE;
        }
diff --git a/src/commands/cmd_dns.cpp b/src/commands/cmd_dns.cpp
new file mode 100644 (file)
index 0000000..d10f0f9
--- /dev/null
@@ -0,0 +1,845 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2013 Adam <Adam@anope.org>
+ *   Copyright (C) 2003-2013 Anope Team <team@anope.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "inspircd.h"
+#include "modules/dns.h"
+#include <iostream>
+#include <fstream>
+
+#ifdef _WIN32
+#include <Iphlpapi.h>
+#pragma comment(lib, "Iphlpapi.lib")
+#endif
+
+using namespace DNS;
+
+/** A full packet sent or recieved to/from the nameserver
+ */
+class Packet : public Query
+{
+       void PackName(unsigned char* output, unsigned short output_size, unsigned short& pos, const std::string& name)
+       {
+               if (pos + name.length() + 2 > output_size)
+                       throw Exception("Unable to pack name");
+
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Packing name " + name);
+
+               irc::sepstream sep(name, '.');
+               std::string token;
+
+               while (sep.GetToken(token))
+               {
+                       output[pos++] = token.length();
+                       memcpy(&output[pos], token.data(), token.length());
+                       pos += token.length();
+               }
+
+               output[pos++] = 0;
+       }
+
+       std::string UnpackName(const unsigned char* input, unsigned short input_size, unsigned short& pos)
+       {
+               std::string name;
+               unsigned short pos_ptr = pos, lowest_ptr = input_size;
+               bool compressed = false;
+
+               if (pos_ptr >= input_size)
+                       throw Exception("Unable to unpack name - no input");
+
+               while (input[pos_ptr] > 0)
+               {
+                       unsigned short offset = input[pos_ptr];
+
+                       if (offset & POINTER)
+                       {
+                               if ((offset & POINTER) != POINTER)
+                                       throw Exception("Unable to unpack name - bogus compression header");
+                               if (pos_ptr + 1 >= input_size)
+                                       throw Exception("Unable to unpack name - bogus compression header");
+
+                               /* Place pos at the second byte of the first (farthest) compression pointer */
+                               if (compressed == false)
+                               {
+                                       ++pos;
+                                       compressed = true;
+                               }
+
+                               pos_ptr = (offset & LABEL) << 8 | input[pos_ptr + 1];
+
+                               /* Pointers can only go back */
+                               if (pos_ptr >= lowest_ptr)
+                                       throw Exception("Unable to unpack name - bogus compression pointer");
+                               lowest_ptr = pos_ptr;
+                       }
+                       else
+                       {
+                               if (pos_ptr + offset + 1 >= input_size)
+                                       throw Exception("Unable to unpack name - offset too large");
+                               if (!name.empty())
+                                       name += ".";
+                               for (unsigned i = 1; i <= offset; ++i)
+                                       name += input[pos_ptr + i];
+
+                               pos_ptr += offset + 1;
+                               if (compressed == false)
+                                       /* Move up pos */
+                                       pos = pos_ptr;
+                       }
+               }
+
+               /* +1 pos either to one byte after the compression pointer or one byte after the ending \0 */
+               ++pos;
+
+               if (name.empty())
+                       throw Exception("Unable to unpack name - no name");
+
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Unpack name " + name);
+
+               return name;
+       }
+
+       Question UnpackQuestion(const unsigned char* input, unsigned short input_size, unsigned short& pos)
+       {
+               Question question;
+
+               question.name = this->UnpackName(input, input_size, pos);
+
+               if (pos + 4 > input_size)
+                       throw Exception("Unable to unpack question");
+
+               question.type = static_cast<QueryType>(input[pos] << 8 | input[pos + 1]);
+               pos += 2;
+
+               question.qclass = input[pos] << 8 | input[pos + 1];
+               pos += 2;
+
+               return question;
+       }
+
+       ResourceRecord UnpackResourceRecord(const unsigned char* input, unsigned short input_size, unsigned short& pos)
+       {
+               ResourceRecord record = static_cast<ResourceRecord>(this->UnpackQuestion(input, input_size, pos));
+
+               if (pos + 6 > input_size)
+                       throw Exception("Unable to unpack resource record");
+
+               record.ttl = (input[pos] << 24) | (input[pos + 1] << 16) | (input[pos + 2] << 8) | input[pos + 3];
+               pos += 4;
+
+               //record.rdlength = input[pos] << 8 | input[pos + 1];
+               pos += 2;
+
+               switch (record.type)
+               {
+                       case QUERY_A:
+                       {
+                               if (pos + 4 > input_size)
+                                       throw Exception("Unable to unpack resource record");
+
+                               irc::sockets::sockaddrs addrs;
+                               memset(&addrs, 0, sizeof(addrs));
+
+                               addrs.in4.sin_family = AF_INET;
+                               addrs.in4.sin_addr.s_addr = input[pos] | (input[pos + 1] << 8) | (input[pos + 2] << 16)  | (input[pos + 3] << 24);
+                               pos += 4;
+
+                               record.rdata = addrs.addr();
+                               break;
+                       }
+                       case QUERY_AAAA:
+                       {
+                               if (pos + 16 > input_size)
+                                       throw Exception("Unable to unpack resource record");
+
+                               irc::sockets::sockaddrs addrs;
+                               memset(&addrs, 0, sizeof(addrs));
+
+                               addrs.in6.sin6_family = AF_INET6;
+                               for (int j = 0; j < 16; ++j)
+                                       addrs.in6.sin6_addr.s6_addr[j] = input[pos + j];
+                               pos += 16;
+
+                               record.rdata = addrs.addr();
+
+                               break;
+                       }
+                       case QUERY_CNAME:
+                       case QUERY_PTR:
+                       {
+                               record.rdata = this->UnpackName(input, input_size, pos);
+                               break;
+                       }
+                       default:
+                               break;
+               }
+
+               if (!record.name.empty() && !record.rdata.empty())
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: " + record.name + " -> " + record.rdata);
+
+               return record;
+       }
+
+ public:
+       static const int POINTER = 0xC0;
+       static const int LABEL = 0x3F;
+       static const int HEADER_LENGTH = 12;
+
+       /* ID for this packet */
+       unsigned short id;
+       /* Flags on the packet */
+       unsigned short flags;
+
+       Packet() : id(0), flags(0)
+       {
+       }
+
+       void Fill(const unsigned char* input, const unsigned short len)
+       {
+               if (len < HEADER_LENGTH)
+                       throw Exception("Unable to fill packet");
+
+               unsigned short packet_pos = 0;
+
+               this->id = (input[packet_pos] << 8) | input[packet_pos + 1];
+               packet_pos += 2;
+
+               if (this->id >= MAX_REQUEST_ID)
+                       throw Exception("Query ID too large?");
+
+               this->flags = (input[packet_pos] << 8) | input[packet_pos + 1];
+               packet_pos += 2;
+
+               unsigned short qdcount = (input[packet_pos] << 8) | input[packet_pos + 1];
+               packet_pos += 2;
+
+               unsigned short ancount = (input[packet_pos] << 8) | input[packet_pos + 1];
+               packet_pos += 2;
+
+               unsigned short nscount = (input[packet_pos] << 8) | input[packet_pos + 1];
+               packet_pos += 2;
+
+               unsigned short arcount = (input[packet_pos] << 8) | input[packet_pos + 1];
+               packet_pos += 2;
+
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: qdcount: " + ConvToStr(qdcount) + " ancount: " + ConvToStr(ancount) + " nscount: " + ConvToStr(nscount) + " arcount: " + ConvToStr(arcount));
+
+               for (unsigned i = 0; i < qdcount; ++i)
+                       this->questions.push_back(this->UnpackQuestion(input, len, packet_pos));
+
+               for (unsigned i = 0; i < ancount; ++i)
+                       this->answers.push_back(this->UnpackResourceRecord(input, len, packet_pos));
+       }
+
+       unsigned short Pack(unsigned char* output, unsigned short output_size)
+       {
+               if (output_size < HEADER_LENGTH)
+                       throw Exception("Unable to pack packet");
+
+               unsigned short pos = 0;
+
+               output[pos++] = this->id >> 8;
+               output[pos++] = this->id & 0xFF;
+               output[pos++] = this->flags >> 8;
+               output[pos++] = this->flags & 0xFF;
+               output[pos++] = this->questions.size() >> 8;
+               output[pos++] = this->questions.size() & 0xFF;
+               output[pos++] = this->answers.size() >> 8;
+               output[pos++] = this->answers.size() & 0xFF;
+               output[pos++] = 0;
+               output[pos++] = 0;
+               output[pos++] = 0;
+               output[pos++] = 0;
+
+               for (unsigned i = 0; i < this->questions.size(); ++i)
+               {
+                       Question& q = this->questions[i];
+
+                       if (q.type == QUERY_PTR)
+                       {
+                               irc::sockets::sockaddrs ip;
+                               irc::sockets::aptosa(q.name, 0, ip);
+
+                               if (q.name.find(':') != std::string::npos)
+                               {
+                                       static const char* const hex = "0123456789abcdef";
+                                       char reverse_ip[128];
+                                       unsigned reverse_ip_count = 0;
+                                       for (int j = 15; j >= 0; --j)
+                                       {
+                                               reverse_ip[reverse_ip_count++] = hex[ip.in6.sin6_addr.s6_addr[j] & 0xF];
+                                               reverse_ip[reverse_ip_count++] = '.';
+                                               reverse_ip[reverse_ip_count++] = hex[ip.in6.sin6_addr.s6_addr[j] >> 4];
+                                               reverse_ip[reverse_ip_count++] = '.';
+                                       }
+                                       reverse_ip[reverse_ip_count++] = 0;
+
+                                       q.name = reverse_ip;
+                                       q.name += "ip6.arpa";
+                               }
+                               else
+                               {
+                                       unsigned long forward = ip.in4.sin_addr.s_addr;
+                                       ip.in4.sin_addr.s_addr = forward << 24 | (forward & 0xFF00) << 8 | (forward & 0xFF0000) >> 8 | forward >> 24;
+
+                                       q.name = ip.addr() + ".in-addr.arpa";
+                               }
+                       }
+
+                       this->PackName(output, output_size, pos, q.name);
+
+                       if (pos + 4 >= output_size)
+                               throw Exception("Unable to pack packet");
+
+                       short s = htons(q.type);
+                       memcpy(&output[pos], &s, 2);
+                       pos += 2;
+
+                       s = htons(q.qclass);
+                       memcpy(&output[pos], &s, 2);
+                       pos += 2;
+               }
+
+               for (unsigned int i = 0; i < answers.size(); i++)
+               {
+                       ResourceRecord& rr = answers[i];
+
+                       this->PackName(output, output_size, pos, rr.name);
+
+                       if (pos + 8 >= output_size)
+                               throw Exception("Unable to pack packet");
+
+                       short s = htons(rr.type);
+                       memcpy(&output[pos], &s, 2);
+                       pos += 2;
+
+                       s = htons(rr.qclass);
+                       memcpy(&output[pos], &s, 2);
+                       pos += 2;
+
+                       long l = htonl(rr.ttl);
+                       memcpy(&output[pos], &l, 4);
+                       pos += 4;
+
+                       switch (rr.type)
+                       {
+                               case QUERY_A:
+                               {
+                                       if (pos + 6 > output_size)
+                                               throw Exception("Unable to pack packet");
+
+                                       irc::sockets::sockaddrs a;
+                                       irc::sockets::aptosa(rr.rdata, 0, a);
+
+                                       s = htons(4);
+                                       memcpy(&output[pos], &s, 2);
+                                       pos += 2;
+
+                                       memcpy(&output[pos], &a.in4.sin_addr, 4);
+                                       pos += 4;
+                                       break;
+                               }
+                               case QUERY_AAAA:
+                               {
+                                       if (pos + 18 > output_size)
+                                               throw Exception("Unable to pack packet");
+
+                                       irc::sockets::sockaddrs a;
+                                       irc::sockets::aptosa(rr.rdata, 0, a);
+
+                                       s = htons(16);
+                                       memcpy(&output[pos], &s, 2);
+                                       pos += 2;
+
+                                       memcpy(&output[pos], &a.in6.sin6_addr, 16);
+                                       pos += 16;
+                                       break;
+                               }
+                               case QUERY_CNAME:
+                               case QUERY_PTR:
+                               {
+                                       if (pos + 2 >= output_size)
+                                               throw Exception("Unable to pack packet");
+
+                                       unsigned short packet_pos_save = pos;
+                                       pos += 2;
+
+                                       this->PackName(output, output_size, pos, rr.rdata);
+
+                                       s = htons(pos - packet_pos_save - 2);
+                                       memcpy(&output[packet_pos_save], &s, 2);
+                                       break;
+                               }
+                               default:
+                                       break;
+                       }
+               }
+
+               return pos;
+       }
+};
+
+class MyManager : public Manager, public Timer, public EventHandler
+{
+       typedef TR1NS::unordered_map<Question, Query, Question::hash> cache_map;
+       cache_map cache;
+
+       irc::sockets::sockaddrs myserver;
+
+       static bool IsExpired(const Query& record, time_t now = ServerInstance->Time())
+       {
+               const ResourceRecord& req = record.answers[0];
+               return (req.created + static_cast<time_t>(req.ttl) < now);
+       }
+
+       /** Check the DNS cache to see if request can be handled by a cached result
+        * @return true if a cached result was found.
+        */
+       bool CheckCache(DNS::Request* req, const DNS::Question& question)
+       {
+               ServerInstance->Logs->Log("RESOLVER", LOG_SPARSE, "Resolver: cache: Checking cache for " + question.name);
+
+               cache_map::iterator it = this->cache.find(question);
+               if (it == this->cache.end())
+                       return false;
+
+               Query& record = it->second;
+               if (IsExpired(record))
+               {
+                       this->cache.erase(it);
+                       return false;
+               }
+
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: cache: Using cached result for " + question.name);
+               record.cached = true;
+               req->OnLookupComplete(&record);
+               return true;
+       }
+
+       /** Add a record to the dns cache
+        * @param r The record
+        */
+       void AddCache(Query& r)
+       {
+               const ResourceRecord& rr = r.answers[0];
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: cache: added cache for " + rr.name + " -> " + rr.rdata + " ttl: " + ConvToStr(rr.ttl));
+               this->cache[r.questions[0]] = r;
+       }
+
+ public:
+       DNS::Request* requests[MAX_REQUEST_ID];
+
+       MyManager(Module* c) : Manager(c), Timer(3600, ServerInstance->Time(), true)
+       {
+               for (int i = 0; i < MAX_REQUEST_ID; ++i)
+                       requests[i] = NULL;
+               ServerInstance->Timers->AddTimer(this);
+       }
+
+       ~MyManager()
+       {
+               for (int i = 0; i < MAX_REQUEST_ID; ++i)
+               {
+                       DNS::Request* request = requests[i];
+                       if (!request)
+                               continue;
+
+                       Query rr(*request);
+                       rr.error = ERROR_UNKNOWN;
+                       request->OnError(&rr);
+
+                       delete request;
+               }
+       }
+
+       void Process(DNS::Request* req)
+       {
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Processing request to lookup " + req->name + " of type " + ConvToStr(req->type) + " to " + this->myserver.addr());
+
+               /* Create an id */
+               unsigned int tries = 0;
+               do
+               {
+                       req->id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID);
+
+                       if (++tries == DNS::MAX_REQUEST_ID*5)
+                       {
+                               // If we couldn't find an empty slot this many times, do a sequential scan as a last
+                               // resort. If an empty slot is found that way, go on, otherwise throw an exception
+                               req->id = 0;
+                               for (int i = 1; i < DNS::MAX_REQUEST_ID; i++)
+                               {
+                                       if (!this->requests[i])
+                                       {
+                                               req->id = i;
+                                               break;
+                                       }
+                               }
+
+                               if (req->id == 0)
+                                       throw Exception("DNS: All ids are in use");
+
+                               break;
+                       }
+               }
+               while (!req->id || this->requests[req->id]);
+
+               this->requests[req->id] = req;
+
+               Packet p;
+               p.flags = QUERYFLAGS_RD;
+               p.id = req->id;
+               p.questions.push_back(*req);
+
+               unsigned char buffer[524];
+               unsigned short len = p.Pack(buffer, sizeof(buffer));
+
+               /* Note that calling Pack() above can actually change the contents of p.questions[0].name, if the query is a PTR,
+                * to contain the value that would be in the DNS cache, which is why this is here.
+                */
+               if (req->use_cache && this->CheckCache(req, p.questions[0]))
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Using cached result");
+                       delete req;
+                       return;
+               }
+
+               if (ServerInstance->SE->SendTo(this, buffer, len, 0, &this->myserver.sa, this->myserver.sa_size()) != len)
+                       throw Exception("DNS: Unable to send query");
+       }
+
+       void RemoveRequest(DNS::Request* req)
+       {
+               this->requests[req->id] = NULL;
+       }
+
+       std::string GetErrorStr(Error e)
+       {
+               switch (e)
+               {
+                       case ERROR_UNLOADED:
+                               return "Module is unloading";
+                       case ERROR_TIMEDOUT:
+                               return "Request timed out";
+                       case ERROR_NOT_AN_ANSWER:
+                       case ERROR_NONSTANDARD_QUERY:
+                       case ERROR_FORMAT_ERROR:
+                               return "Malformed answer";
+                       case ERROR_SERVER_FAILURE:
+                       case ERROR_NOT_IMPLEMENTED:
+                       case ERROR_REFUSED:
+                       case ERROR_INVALIDTYPE:
+                               return "Nameserver failure";
+                       case ERROR_DOMAIN_NOT_FOUND:
+                       case ERROR_NO_RECORDS:
+                               return "Domain not found";
+                       case ERROR_NONE:
+                       case ERROR_UNKNOWN:
+                       default:
+                               return "Unknown error";
+               }
+       }
+
+       void HandleEvent(EventType et, int)
+       {
+               if (et == EVENT_ERROR)
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: UDP socket got an error event");
+                       return;
+               }
+
+               unsigned char buffer[524];
+               irc::sockets::sockaddrs from;
+               socklen_t x = sizeof(from);
+
+               int length = ServerInstance->SE->RecvFrom(this, buffer, sizeof(buffer), 0, &from.sa, &x);
+
+               if (length < Packet::HEADER_LENGTH)
+                       return;
+
+               Packet recv_packet;
+
+               try
+               {
+                       recv_packet.Fill(buffer, length);
+               }
+               catch (Exception& ex)
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, std::string(ex.GetReason()));
+                       return;
+               }
+
+               if (myserver != from)
+               {
+                       std::string server1 = from.str();
+                       std::string server2 = myserver.str();
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Got a result from the wrong server! Bad NAT or DNS forging attempt? '%s' != '%s'",
+                               server1.c_str(), server2.c_str());
+                       return;
+               }
+
+               DNS::Request* request = this->requests[recv_packet.id];
+               if (request == NULL)
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Received an answer for something we didn't request");
+                       return;
+               }
+
+               if (recv_packet.flags & QUERYFLAGS_OPCODE)
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Received a nonstandard query");
+                       ServerInstance->stats->statsDnsBad++;
+                       recv_packet.error = ERROR_NONSTANDARD_QUERY;
+                       request->OnError(&recv_packet);
+               }
+               else if (recv_packet.flags & QUERYFLAGS_RCODE)
+               {
+                       Error error = ERROR_UNKNOWN;
+
+                       switch (recv_packet.flags & QUERYFLAGS_RCODE)
+                       {
+                               case 1:
+                                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: format error");
+                                       error = ERROR_FORMAT_ERROR;
+                                       break;
+                               case 2:
+                                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: server error");
+                                       error = ERROR_SERVER_FAILURE;
+                                       break;
+                               case 3:
+                                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: domain not found");
+                                       error = ERROR_DOMAIN_NOT_FOUND;
+                                       break;
+                               case 4:
+                                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: not implemented");
+                                       error = ERROR_NOT_IMPLEMENTED;
+                                       break;
+                               case 5:
+                                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: refused");
+                                       error = ERROR_REFUSED;
+                                       break;
+                               default:
+                                       break;
+                       }
+
+                       ServerInstance->stats->statsDnsBad++;
+                       recv_packet.error = error;
+                       request->OnError(&recv_packet);
+               }
+               else if (recv_packet.questions.empty() || recv_packet.answers.empty())
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: No resource records returned");
+                       ServerInstance->stats->statsDnsBad++;
+                       recv_packet.error = ERROR_NO_RECORDS;
+                       request->OnError(&recv_packet);
+               }
+               else
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Lookup complete for " + request->name);
+                       ServerInstance->stats->statsDnsGood++;
+                       request->OnLookupComplete(&recv_packet);
+                       this->AddCache(recv_packet);
+               }
+
+               ServerInstance->stats->statsDns++;
+
+               /* Request's destructor removes it from the request map */
+               delete request;
+       }
+
+       bool Tick(time_t now)
+       {
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: cache: purging DNS cache");
+
+               for (cache_map::iterator it = this->cache.begin(); it != this->cache.end(); )
+               {
+                       const Query& query = it->second;
+                       if (IsExpired(query, now))
+                               this->cache.erase(it++);
+                       else
+                               ++it;
+               }
+               return true;
+       }
+
+       void Rehash(const std::string& dnsserver)
+       {
+               if (this->GetFd() > -1)
+               {
+                       ServerInstance->SE->DelFd(this);
+                       ServerInstance->SE->Shutdown(this, 2);
+                       ServerInstance->SE->Close(this);
+                       this->SetFd(-1);
+
+                       /* Remove expired entries from the cache */
+                       this->Tick(ServerInstance->Time());
+               }
+
+               irc::sockets::aptosa(dnsserver, DNS::PORT, myserver);
+
+               /* Initialize mastersocket */
+               int s = socket(myserver.sa.sa_family, SOCK_DGRAM, 0);
+               this->SetFd(s);
+
+               /* Have we got a socket? */
+               if (this->GetFd() != -1)
+               {
+                       ServerInstance->SE->SetReuse(s);
+                       ServerInstance->SE->NonBlocking(s);
+
+                       irc::sockets::sockaddrs bindto;
+                       memset(&bindto, 0, sizeof(bindto));
+                       bindto.sa.sa_family = myserver.sa.sa_family;
+
+                       if (ServerInstance->SE->Bind(this->GetFd(), bindto) < 0)
+                       {
+                               /* Failed to bind */
+                               ServerInstance->Logs->Log("RESOLVER", LOG_SPARSE, "Resolver: Error binding dns socket - hostnames will NOT resolve");
+                               ServerInstance->SE->Close(this);
+                               this->SetFd(-1);
+                       }
+                       else if (!ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE))
+                       {
+                               ServerInstance->Logs->Log("RESOLVER", LOG_SPARSE, "Resolver: Internal error starting DNS - hostnames will NOT resolve.");
+                               ServerInstance->SE->Close(this);
+                               this->SetFd(-1);
+                       }
+               }
+               else
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_SPARSE, "Resolver: Error creating DNS socket - hostnames will NOT resolve");
+               }
+       }
+};
+
+class ModuleDNS : public Module
+{
+       MyManager manager;
+       std::string DNSServer;
+
+       void FindDNSServer()
+       {
+#ifdef _WIN32
+               // attempt to look up their nameserver from the system
+               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: <dns:server> not defined, attempting to find a working server in the system settings...");
+
+               PFIXED_INFO pFixedInfo;
+               DWORD dwBufferSize = sizeof(FIXED_INFO);
+               pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, sizeof(FIXED_INFO));
+
+               if (pFixedInfo)
+               {
+                       if (GetNetworkParams(pFixedInfo, &dwBufferSize) == ERROR_BUFFER_OVERFLOW)
+                       {
+                               HeapFree(GetProcessHeap(), 0, pFixedInfo);
+                               pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
+                       }
+
+                       if (pFixedInfo)
+                       {
+                               if (GetNetworkParams(pFixedInfo, &dwBufferSize) == NO_ERROR)
+                                       DNSServer = pFixedInfo->DnsServerList.IpAddress.String;
+
+                               HeapFree(GetProcessHeap(), 0, pFixedInfo);
+                       }
+
+                       if (!DNSServer.empty())
+                       {
+                               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<dns:server> set to '%s' as first active resolver in the system settings.", DNSServer.c_str());
+                               return;
+                       }
+               }
+
+               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "No viable nameserver found! Defaulting to nameserver '127.0.0.1'!");
+#else
+               // attempt to look up their nameserver from /etc/resolv.conf
+               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
+
+               std::ifstream resolv("/etc/resolv.conf");
+
+               while (resolv >> DNSServer)
+               {
+                       if (DNSServer == "nameserver")
+                       {
+                               resolv >> DNSServer;
+                               if (DNSServer.find_first_not_of("0123456789.") == std::string::npos)
+                               {
+                                       ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",DNSServer.c_str());
+                                       return;
+                               }
+                       }
+               }
+
+               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
+#endif
+               DNSServer = "127.0.0.1";
+       }
+
+ public:
+       ModuleDNS() : manager(this)
+       {
+       }
+
+       void init()
+       {
+               Implementation i[] = { I_OnRehash, I_OnUnloadModule };
+               ServerInstance->Modules->Attach(i, this, sizeof(i) / sizeof(Implementation));
+
+               ServerInstance->Modules->AddService(this->manager);
+
+               this->OnRehash(NULL);
+       }
+
+       void OnRehash(User* user)
+       {
+               std::string oldserver = DNSServer;
+               DNSServer = ServerInstance->Config->ConfValue("dns")->getString("server");
+               if (DNSServer.empty())
+                       FindDNSServer();
+
+               if (oldserver != DNSServer)
+                       this->manager.Rehash(DNSServer);
+       }
+
+       void OnUnloadModule(Module* mod)
+       {
+               for (int i = 0; i < MAX_REQUEST_ID; ++i)
+               {
+                       DNS::Request* req = this->manager.requests[i];
+                       if (!req)
+                               continue;
+
+                       if (req->creator == mod)
+                       {
+                               Query rr(*req);
+                               rr.error = ERROR_UNLOADED;
+                               req->OnError(&rr);
+
+                               delete req;
+                       }
+               }
+       }
+
+       Version GetVersion()
+       {
+               return Version("DNS support", VF_CORE|VF_VENDOR);
+       }
+};
+
+MODULE_INIT(ModuleDNS)
+
index ca39f9061dcbda1c9faa6de31da225820eba7864..67f67e9f09cdd79beb0c938454fb0e235e3e9dc2 100644 (file)
@@ -60,17 +60,16 @@ CmdResult CommandEline::Handle (const std::vector<std::string>& parameters, User
                else
                        ih = ServerInstance->XLines->IdentSplit(target);
 
-        if (ih.first.empty())
-        {
-            user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
-            return CMD_FAILURE;
-        }
+               if (ih.first.empty())
+               {
+                       user->WriteNotice("*** Target not found");
+                       return CMD_FAILURE;
+               }
 
                if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
                        return CMD_FAILURE;
 
-               long duration = ServerInstance->Duration(parameters[1].c_str());
-
+               unsigned long duration = InspIRCd::Duration(parameters[1]);
                ELine* el = new ELine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
                if (ServerInstance->XLines->AddLine(el, user))
                {
@@ -89,7 +88,7 @@ CmdResult CommandEline::Handle (const std::vector<std::string>& parameters, User
                else
                {
                        delete el;
-                       user->WriteServ("NOTICE %s :*** E-Line for %s already exists",user->nick.c_str(),target.c_str());
+                       user->WriteNotice("*** E-Line for " + target + " already exists");
                }
        }
        else
@@ -100,7 +99,7 @@ CmdResult CommandEline::Handle (const std::vector<std::string>& parameters, User
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** E-Line %s not found in list, try /stats e.",user->nick.c_str(),target.c_str());
+                       user->WriteNotice("*** E-Line " + target + " not found in list, try /stats e");
                }
        }
 
index 6505b7464615804ad272018e1e883eab12fa557b..bdb5c26b2bd3aff0585fd7acfd5c14d1b6db716d 100644 (file)
@@ -63,7 +63,7 @@ CmdResult CommandGline::Handle (const std::vector<std::string>& parameters, User
 
                if (ih.first.empty())
                {
-                       user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
+                       user->WriteNotice("*** Target not found");
                        return CMD_FAILURE;
                }
 
@@ -72,11 +72,11 @@ CmdResult CommandGline::Handle (const std::vector<std::string>& parameters, User
 
                else if (target.find('!') != std::string::npos)
                {
-                       user->WriteServ("NOTICE %s :*** G-Line cannot operate on nick!user@host masks",user->nick.c_str());
+                       user->WriteNotice("*** G-Line cannot operate on nick!user@host masks");
                        return CMD_FAILURE;
                }
 
-               long duration = ServerInstance->Duration(parameters[1].c_str());
+               unsigned long duration = InspIRCd::Duration(parameters[1]);
                GLine* gl = new GLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
                if (ServerInstance->XLines->AddLine(gl, user))
                {
@@ -97,7 +97,7 @@ CmdResult CommandGline::Handle (const std::vector<std::string>& parameters, User
                else
                {
                        delete gl;
-                       user->WriteServ("NOTICE %s :*** G-Line for %s already exists",user->nick.c_str(),target.c_str());
+                       user->WriteNotice("** G-Line for " + target + " already exists");
                }
 
        }
@@ -109,7 +109,7 @@ CmdResult CommandGline::Handle (const std::vector<std::string>& parameters, User
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** G-line %s not found in list, try /stats g.",user->nick.c_str(),target.c_str());
+                       user->WriteNotice("*** G-Line " + target + " not found in list, try /stats g.");
                }
        }
 
diff --git a/src/commands/cmd_hostname_lookup.cpp b/src/commands/cmd_hostname_lookup.cpp
new file mode 100644 (file)
index 0000000..71a32e6
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2013 Adam <Adam@anope.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+#include "modules/dns.h"
+
+namespace
+{
+       LocalIntExt* dl;
+       LocalStringExt* ph;
+}
+
+/** Derived from Resolver, and performs user forward/reverse lookups.
+ */
+class UserResolver : public DNS::Request
+{
+       /** UUID we are looking up */
+       const std::string uuid;
+
+       /** True if the lookup is forward, false if is a reverse lookup
+        */
+       const bool fwd;
+
+ public:
+       /** Create a resolver.
+        * @param mgr DNS Manager
+        * @param me this module
+        * @param user The user to begin lookup on
+        * @param to_resolve The IP or host to resolve
+        * @param qt The query type
+        */
+       UserResolver(DNS::Manager* mgr, Module* me, LocalUser* user, const std::string& to_resolve, DNS::QueryType qt)
+               : DNS::Request(mgr, me, to_resolve, qt)
+               , uuid(user->uuid)
+               , fwd(qt == DNS::QUERY_A || qt == DNS::QUERY_AAAA)
+       {
+       }
+
+       /** Called on successful lookup
+        * if a previous result has already come back.
+        * @param r The finished query
+        */
+       void OnLookupComplete(const DNS::Query* r)
+       {
+               LocalUser* bound_user = (LocalUser*)ServerInstance->FindUUID(uuid);
+               if (!bound_user)
+               {
+                       ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolution finished for user '%s' who is gone", uuid.c_str());
+                       return;
+               }
+
+               const DNS::ResourceRecord& ans_record = r->answers[0];
+
+               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "DNS result for %s: '%s' -> '%s'", uuid.c_str(), ans_record.name.c_str(), ans_record.rdata.c_str());
+
+               if (!fwd)
+               {
+                       // first half of resolution is done. We now need to verify that the host matches.
+                       ph->set(bound_user, ans_record.rdata);
+
+                       UserResolver* res_forward;
+                       if (bound_user->client_sa.sa.sa_family == AF_INET6)
+                       {
+                               /* IPV6 forward lookup */
+                               res_forward = new UserResolver(this->manager, this->creator, bound_user, ans_record.rdata, DNS::QUERY_AAAA);
+                       }
+                       else
+                       {
+                               /* IPV4 lookup */
+                               res_forward = new UserResolver(this->manager, this->creator, bound_user, ans_record.rdata, DNS::QUERY_A);
+                       }
+                       try
+                       {
+                               this->manager->Process(res_forward);
+                       }
+                       catch (DNS::Exception& e)
+                       {
+                               delete res_forward;
+                               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Error in resolver: %s",e.GetReason());
+
+                               bound_user->WriteNotice("*** There was an internal error resolving your host, using your IP address (" + bound_user->GetIPString() + ") instead.");
+                               dl->set(bound_user, 0);
+                       }
+               }
+               else
+               {
+                       /* Both lookups completed */
+
+                       irc::sockets::sockaddrs* user_ip = &bound_user->client_sa;
+                       bool rev_match = false;
+                       if (user_ip->sa.sa_family == AF_INET6)
+                       {
+                               struct in6_addr res_bin;
+                               if (inet_pton(AF_INET6, ans_record.rdata.c_str(), &res_bin))
+                               {
+                                       rev_match = !memcmp(&user_ip->in6.sin6_addr, &res_bin, sizeof(res_bin));
+                               }
+                       }
+                       else
+                       {
+                               struct in_addr res_bin;
+                               if (inet_pton(AF_INET, ans_record.rdata.c_str(), &res_bin))
+                               {
+                                       rev_match = !memcmp(&user_ip->in4.sin_addr, &res_bin, sizeof(res_bin));
+                               }
+                       }
+
+                       dl->set(bound_user, 0);
+
+                       if (rev_match)
+                       {
+                               std::string* hostname = ph->get(bound_user);
+
+                               if (hostname == NULL)
+                               {
+                                       ServerInstance->Logs->Log("RESOLVER", LOG_DEFAULT, "ERROR: User has no hostname attached when doing a forward lookup");
+                                       bound_user->WriteNotice("*** There was an internal error resolving your host, using your IP address (" + bound_user->GetIPString() + ") instead.");
+                                       return;
+                               }
+                               else if (hostname->length() < 65)
+                               {
+                                       /* Hostnames starting with : are not a good thing (tm) */
+                                       if ((*hostname)[0] == ':')
+                                               hostname->insert(0, "0");
+
+                                       bound_user->WriteNotice("*** Found your hostname (" + *hostname + (r->cached ? ") -- cached" : ")"));
+                                       bound_user->host.assign(*hostname, 0, 64);
+                                       bound_user->dhost = bound_user->host;
+
+                                       /* Invalidate cache */
+                                       bound_user->InvalidateCache();
+                               }
+                               else
+                               {
+                                       bound_user->WriteNotice("*** Your hostname is longer than the maximum of 64 characters, using your IP address (" + bound_user->GetIPString() + ") instead.");
+                               }
+
+                               ph->unset(bound_user);
+                       }
+                       else
+                       {
+                               bound_user->WriteNotice("*** Your hostname does not match up with your IP address. Sorry, using your IP address (" + bound_user->GetIPString() + ") instead.");
+                       }
+               }
+       }
+
+       /** Called on failed lookup
+        * @param query The errored query
+        */
+       void OnError(const DNS::Query* query)
+       {
+               LocalUser* bound_user = (LocalUser*)ServerInstance->FindUUID(uuid);
+               if (bound_user)
+               {
+                       bound_user->WriteNotice("*** Could not resolve your hostname: " + this->manager->GetErrorStr(query->error) + "; using your IP address (" + bound_user->GetIPString() + ") instead.");
+                       dl->set(bound_user, 0);
+                       ServerInstance->stats->statsDnsBad++;
+               }
+       }
+};
+
+class ModuleHostnameLookup : public Module
+{
+       LocalIntExt dnsLookup;
+       LocalStringExt ptrHosts;
+       dynamic_reference<DNS::Manager> DNS;
+
+ public:
+       ModuleHostnameLookup()
+               : dnsLookup("dnsLookup", this)
+               , ptrHosts("ptrHosts", this)
+               , DNS(this, "DNS")
+       {
+               dl = &dnsLookup;
+               ph = &ptrHosts;
+       }
+
+       void init()
+       {
+               OnRehash(NULL);
+               ServerInstance->Modules->AddService(this->dnsLookup);
+               ServerInstance->Modules->AddService(this->ptrHosts);
+
+               Implementation i[] = { I_OnUserInit, I_OnCheckReady };
+               ServerInstance->Modules->Attach(i, this, sizeof(i) / sizeof(Implementation));
+       }
+
+       void OnUserInit(LocalUser *user)
+       {
+               if (!DNS || user->MyClass->nouserdns)
+               {
+                       user->WriteNotice("*** Skipping host resolution (disabled by server administrator)");
+                       return;
+               }
+
+               user->WriteNotice("*** Looking up your hostname...");
+
+               UserResolver* res_reverse = new UserResolver(*this->DNS, this, user, user->GetIPString(), DNS::QUERY_PTR);
+               try
+               {
+                       /* If both the reverse and forward queries are cached, the user will be able to pass DNS completely
+                        * before Process() completes, which is why dnsLookup.set() is here, before Process()
+                        */
+                       this->dnsLookup.set(user, 1);
+                       this->DNS->Process(res_reverse);
+               }
+               catch (DNS::Exception& e)
+               {
+                       this->dnsLookup.set(user, 0);
+                       delete res_reverse;
+                       ServerInstance->Logs->Log("USERS", LOG_DEBUG, "Error in resolver: %s", e.GetReason());
+                       ServerInstance->stats->statsDnsBad++;
+               }
+       }
+
+       ModResult OnCheckReady(LocalUser* user)
+       {
+               return this->dnsLookup.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
+       }
+
+       Version GetVersion()
+       {
+               return Version("Provides support for DNS lookups on connecting clients", VF_CORE|VF_VENDOR);
+       }
+};
+
+MODULE_INIT(ModuleHostnameLookup)
index c69e6bd1be19fa2f99bf00d53401edb699fc92a6..7221521de5e1a0b145882d396d83ed3e04ecbdf3 100644 (file)
@@ -61,7 +61,7 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
                if (parameters.size() == 3)
                {
                        if (IS_LOCAL(user))
-                               timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
+                               timeout = ServerInstance->Time() + InspIRCd::Duration(parameters[1]);
                        else
                                timeout = ConvToInt(parameters[2]);
                }
@@ -107,9 +107,14 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
                }
 
                if (IS_LOCAL(u))
-                       IS_LOCAL(u)->InviteTo(c->name.c_str(), timeout);
-               u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
-               user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
+               {
+                       Invitation::Create(c, IS_LOCAL(u), timeout);
+                       u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
+               }
+
+               if (IS_LOCAL(user))
+                       user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
+
                if (ServerInstance->Config->AnnounceInvites != ServerConfig::INVITE_ANNOUNCE_NONE)
                {
                        char prefix;
index 6124fcc1c7746b5975cdf049cb0d478d5448255c..a88509bc26c00314f5a500c083facb4f8ba6199d 100644 (file)
  * the same way, however, they can be fully unloaded, where these
  * may not.
  */
-class CommandJoin : public Command
+class CommandJoin : public SplitCommand
 {
  public:
        /** Constructor for join.
         */
-       CommandJoin ( Module* parent) : Command(parent,"JOIN", 1, 2) { syntax = "<channel>{,<channel>} {<key>{,<key>}}"; Penalty = 2; }
+       CommandJoin(Module* parent)
+               : SplitCommand(parent, "JOIN", 1, 2)
+       {
+               syntax = "<channel>{,<channel>} {<key>{,<key>}}";
+               Penalty = 2;
+       }
+
        /** Handle command.
         * @param parameters The parameters to the comamnd
         * @param pcnt The number of parameters passed to teh command
         * @param user The user issuing the command
         * @return A value from CmdResult to indicate command success or failure.
         */
-       CmdResult Handle(const std::vector<std::string>& parameters, User *user);
+       CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
 };
 
 /** Handle /JOIN
  */
-CmdResult CommandJoin::Handle (const std::vector<std::string>& parameters, User *user)
+CmdResult CommandJoin::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
 {
        if (parameters.size() > 1)
        {
                if (ServerInstance->Parser->LoopCall(user, this, parameters, 0, 1, false))
                        return CMD_SUCCESS;
 
-               if (ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
+               if (ServerInstance->IsChannel(parameters[0]))
                {
-                       Channel::JoinUser(user, parameters[0].c_str(), false, parameters[1].c_str(), false);
+                       Channel::JoinUser(user, parameters[0], false, parameters[1]);
                        return CMD_SUCCESS;
                }
        }
@@ -60,9 +66,9 @@ CmdResult CommandJoin::Handle (const std::vector<std::string>& parameters, User
                if (ServerInstance->Parser->LoopCall(user, this, parameters, 0, -1, false))
                        return CMD_SUCCESS;
 
-               if (ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
+               if (ServerInstance->IsChannel(parameters[0]))
                {
-                       Channel::JoinUser(user, parameters[0].c_str(), false, "", false);
+                       Channel::JoinUser(user, parameters[0]);
                        return CMD_SUCCESS;
                }
        }
index 3c5fb00527ae8e94d73e72b6f16cb8a35e4c2c1a..016a14b2ef70d4066210d90a92c578fd6da745f3 100644 (file)
@@ -62,10 +62,21 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
                return CMD_FAILURE;
        }
 
-       if ((IS_LOCAL(user)) && (!c->HasUser(user)) && (!ServerInstance->ULine(user->server)))
+       Membership* srcmemb = NULL;
+       if (IS_LOCAL(user))
        {
-               user->WriteServ( "442 %s %s :You're not on that channel!", user->nick.c_str(), parameters[0].c_str());
-               return CMD_FAILURE;
+               srcmemb = c->GetUser(user);
+               if (!srcmemb)
+               {
+                       user->WriteServ( "442 %s %s :You're not on that channel!", user->nick.c_str(), parameters[0].c_str());
+                       return CMD_FAILURE;
+               }
+
+               if (ServerInstance->ULine(u->server))
+               {
+                       user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You may not kick a u-lined client", user->nick.c_str(), c->name.c_str());
+                       return CMD_FAILURE;
+               }
        }
 
        if (parameters.size() > 2)
@@ -77,7 +88,7 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
                reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
        }
 
-       c->KickUser(user, u, reason.c_str());
+       c->KickUser(user, u, reason, srcmemb);
 
        return CMD_SUCCESS;
 }
index 17c8a76a053479968f229916dd216ce69c9ab138..6bf657115275e658795691c7650d9cd1d719b193 100644 (file)
@@ -125,7 +125,7 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User
                                ServerInstance->SNO->WriteGlobalSno('k',"Local Kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
                        else
                                ServerInstance->SNO->WriteToSnoMask('k',"Local Kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
-                       ServerInstance->Logs->Log("KILL",DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick.c_str(), ServerInstance->Config->ServerName.c_str(), user->dhost.c_str(), user->nick.c_str(), parameters[1].c_str());
+                       ServerInstance->Logs->Log("KILL", LOG_DEFAULT, "LOCAL KILL: %s :%s!%s!%s (%s)", u->nick.c_str(), ServerInstance->Config->ServerName.c_str(), user->dhost.c_str(), user->nick.c_str(), parameters[1].c_str());
                        /* Bug #419, make sure this message can only occur once even in the case of multiple KILL messages crossing the network, and change to show
                         * hidekillsserver as source if possible
                         */
index ce3642f91a70f8be66f7bd6a09c7e8357e7fe7b3..20afae2a910ff2339b6749a3394821b36b6f9df9 100644 (file)
@@ -63,7 +63,7 @@ CmdResult CommandKline::Handle (const std::vector<std::string>& parameters, User
 
         if (ih.first.empty())
         {
-            user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
+            user->WriteNotice("*** Target not found");
             return CMD_FAILURE;
         }
 
@@ -72,11 +72,11 @@ CmdResult CommandKline::Handle (const std::vector<std::string>& parameters, User
 
                if (target.find('!') != std::string::npos)
                {
-                       user->WriteServ("NOTICE %s :*** K-Line cannot operate on nick!user@host masks",user->nick.c_str());
+                       user->WriteNotice("*** K-Line cannot operate on nick!user@host masks");
                        return CMD_FAILURE;
                }
 
-               long duration = ServerInstance->Duration(parameters[1].c_str());
+               unsigned long duration = InspIRCd::Duration(parameters[1]);
                KLine* kl = new KLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
                if (ServerInstance->XLines->AddLine(kl,user))
                {
@@ -97,7 +97,7 @@ CmdResult CommandKline::Handle (const std::vector<std::string>& parameters, User
                else
                {
                        delete kl;
-                       user->WriteServ("NOTICE %s :*** K-Line for %s already exists",user->nick.c_str(),target.c_str());
+                       user->WriteNotice("*** K-Line for " + target + " already exists");
                }
        }
        else
@@ -108,7 +108,7 @@ CmdResult CommandKline::Handle (const std::vector<std::string>& parameters, User
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick.c_str(),target.c_str());
+                       user->WriteNotice("*** K-Line " + target + " not found in list, try /stats k.");
                }
        }
 
index 91a71809034902d3cf312763eabc52ea8fd671bb..c594a0e2434144180bdda99ae1e8910c67ce3e4f 100644 (file)
@@ -110,11 +110,11 @@ class InvisibleWatcher : public ModeWatcher
        unsigned int& invisible;
 public:
        InvisibleWatcher(Module* mod, unsigned int& Invisible)
-               : ModeWatcher(mod, 'i', MODETYPE_USER), invisible(Invisible)
+               : ModeWatcher(mod, "invisible", MODETYPE_USER), invisible(Invisible)
        {
        }
 
-       void AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding, ModeType type)
+       void AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding)
        {
                if (dest->registered != REG_ALL)
                        return;
index 385a2c7522e910addbb3abb3b727740456cac18f..0698134b531114b636ee4c78c5b73f347d444b1a 100644 (file)
@@ -43,7 +43,7 @@ CmdResult CommandMap::Handle (const std::vector<std::string>&, User *user)
        // module to override its behaviour and display something
        // better.
 
-       if (IS_OPER(user))
+       if (user->IsOper())
        {
                user->WriteNumeric(006, "%s :%s [%s]", user->nick.c_str(), ServerInstance->Config->ServerName.c_str(), ServerInstance->Config->GetSID().c_str());
                user->WriteNumeric(007, "%s :End of /MAP", user->nick.c_str());
index a079e59d057880fcfd8e94d33d53a506e508ad47..e58aab98693e5645f0757de23d3bc2220e8dbc48 100644 (file)
@@ -66,7 +66,7 @@ CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User
        {
                newnick = user->uuid;
        }
-       else if (!ServerInstance->IsNick(newnick.c_str(), ServerInstance->Config->Limits.NickMax))
+       else if (!ServerInstance->IsNick(newnick))
        {
                user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),newnick.c_str());
                return CMD_FAILURE;
index d5ef7ba1d0f2cf36f97f45c3ff01605dc1e314f8..ec60127b752b21eebf274f20218b00c7c76afa31 100644 (file)
@@ -57,7 +57,9 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
 
        CUList exempt_list;
 
-       user->idle_lastmsg = ServerInstance->Time();
+       LocalUser* localuser = IS_LOCAL(user);
+       if (localuser)
+               localuser->idle_lastmsg = ServerInstance->Time();
 
        if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
                return CMD_SUCCESS;
@@ -68,7 +70,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
 
                ModResult MOD_RESULT;
                std::string temp = parameters[1];
-               FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list));
+               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list, MSG_NOTICE));
                if (MOD_RESULT == MOD_RES_DENY)
                        return CMD_FAILURE;
                const char* text = temp.c_str();
@@ -79,7 +81,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
                {
                        user->SendAll("NOTICE", "%s", text);
                }
-               FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
+               FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list, MSG_NOTICE));
                return CMD_SUCCESS;
        }
        char status = 0;
@@ -98,7 +100,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
 
                if (chan)
                {
-                       if (IS_LOCAL(user))
+                       if (localuser)
                        {
                                if ((chan->IsModeSet('n')) && (!chan->HasUser(user)))
                                {
@@ -123,7 +125,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
                        ModResult MOD_RESULT;
 
                        std::string temp = parameters[1];
-                       FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status, exempt_list));
+                       FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status, exempt_list, MSG_NOTICE));
                        if (MOD_RESULT == MOD_RES_DENY)
                                return CMD_FAILURE;
 
@@ -153,7 +155,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
                                chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text);
                        }
 
-                       FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list));
+                       FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,text,status,exempt_list,MSG_NOTICE));
                }
                else
                {
@@ -166,7 +168,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
 
        const char* destnick = parameters[0].c_str();
 
-       if (IS_LOCAL(user))
+       if (localuser)
        {
                const char* targetserver = strchr(destnick, '@');
 
@@ -199,7 +201,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
 
                ModResult MOD_RESULT;
                std::string temp = parameters[1];
-               FIRST_MOD_RESULT(OnUserPreNotice, MOD_RESULT, (user,dest,TYPE_USER,temp,0,exempt_list));
+               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, exempt_list, MSG_NOTICE));
                if (MOD_RESULT == MOD_RES_DENY) {
                        return CMD_FAILURE;
                }
@@ -213,7 +215,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
                        user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text);
                }
 
-               FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list));
+               FOREACH_MOD(I_OnUserMessage, OnUserMessage(user, dest, TYPE_USER, text, 0, exempt_list, MSG_NOTICE));
        }
        else
        {
index 1a5e7e1783a4331911d89196b3353722b151ca53..e1018f805c4f73cca58857d1275f4514fab5c61b 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "inspircd.h"
 
-bool OneOfMatches(const char* host, const char* ip, const char* hostlist);
-
 /** Handle /OPER. These command handlers can be reloaded by the core,
  * and handle basic RFC1459 commands. Commands within modules work
  * the same way, however, they can be fully unloaded, where these
@@ -43,30 +41,14 @@ class CommandOper : public SplitCommand
        CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user);
 };
 
-bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
-       std::stringstream hl(hostlist);
-       std::string xhost;
-       while (hl >> xhost)
-       {
-               if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
 CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
 {
-       char TheHost[MAXBUF];
-       char TheIP[MAXBUF];
        bool match_login = false;
        bool match_pass = false;
        bool match_hosts = false;
 
-       snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str());
-       snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString());
+       const std::string userHost = user->ident + "@" + user->host;
+       const std::string userIP = user->ident + "@" + user->GetIPString();
 
        OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
        if (i != ServerInstance->Config->oper_blocks.end())
@@ -75,7 +57,7 @@ CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, L
                ConfigTag* tag = ifo->oper_block;
                match_login = true;
                match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
-               match_hosts = OneOfMatches(TheHost,TheIP,tag->getString("host"));
+               match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
 
                if (match_pass && match_hosts)
                {
@@ -98,7 +80,7 @@ CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, L
        user->CommandFloodPenalty += 10000;
 
        ServerInstance->SNO->WriteGlobalSno('o', "WARNING! Failed oper attempt by %s using login '%s': The following fields do not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str());
-       ServerInstance->Logs->Log("OPER",DEFAULT,"OPER: Failed oper attempt by %s using login '%s': The following fields did not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str());
+       ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "OPER: Failed oper attempt by %s using login '%s': The following fields did not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str());
        return CMD_FAILURE;
 }
 
index cefdd48008b5c8d24e1685156aac99d9d0f9dc35..b04e63d0080f3dd58616ef14699c6347f65f4c63 100644 (file)
@@ -56,7 +56,9 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
        Channel *chan;
        CUList except_list;
 
-       user->idle_lastmsg = ServerInstance->Time();
+       LocalUser* localuser = IS_LOCAL(user);
+       if (localuser)
+               localuser->idle_lastmsg = ServerInstance->Time();
 
        if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
                return CMD_SUCCESS;
@@ -68,7 +70,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
 
                ModResult MOD_RESULT;
                std::string temp = parameters[1];
-               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, except_list));
+               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, except_list, MSG_PRIVMSG));
                if (MOD_RESULT == MOD_RES_DENY)
                        return CMD_FAILURE;
 
@@ -80,7 +82,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
                {
                        user->SendAll("PRIVMSG", "%s", text);
                }
-               FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
+               FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list, MSG_PRIVMSG));
                return CMD_SUCCESS;
        }
        char status = 0;
@@ -99,7 +101,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
 
                if (chan)
                {
-                       if (IS_LOCAL(user) && chan->GetPrefixValue(user) < VOICE_VALUE)
+                       if (localuser && chan->GetPrefixValue(user) < VOICE_VALUE)
                        {
                                if (chan->IsModeSet('n') && !chan->HasUser(user))
                                {
@@ -125,7 +127,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
                        ModResult MOD_RESULT;
 
                        std::string temp = parameters[1];
-                       FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user,chan,TYPE_CHANNEL,temp,status,except_list));
+                       FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, chan, TYPE_CHANNEL, temp, status, except_list, MSG_PRIVMSG));
                        if (MOD_RESULT == MOD_RES_DENY)
                                return CMD_FAILURE;
 
@@ -156,7 +158,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
                                chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %s :%s", chan->name.c_str(), text);
                        }
 
-                       FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,text,status,except_list));
+                       FOREACH_MOD(I_OnUserMessage, OnUserMessage(user,chan, TYPE_CHANNEL, text, status, except_list, MSG_PRIVMSG));
                }
                else
                {
@@ -169,7 +171,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
 
        const char* destnick = parameters[0].c_str();
 
-       if (IS_LOCAL(user))
+       if (localuser)
        {
                const char* targetserver = strchr(destnick, '@');
 
@@ -200,7 +202,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
                        return CMD_FAILURE;
                }
 
-               if (IS_AWAY(dest))
+               if (dest->IsAway())
                {
                        /* auto respond with aweh msg */
                        user->WriteNumeric(301, "%s %s :%s", user->nick.c_str(), dest->nick.c_str(), dest->awaymsg.c_str());
@@ -209,7 +211,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
                ModResult MOD_RESULT;
 
                std::string temp = parameters[1];
-               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, except_list));
+               FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, except_list, MSG_PRIVMSG));
                if (MOD_RESULT == MOD_RES_DENY)
                        return CMD_FAILURE;
 
@@ -223,7 +225,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
                        user->WriteTo(dest, "PRIVMSG %s :%s", dest->nick.c_str(), text);
                }
 
-               FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, dest, TYPE_USER, text, 0, except_list));
+               FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, dest, TYPE_USER, text, 0, except_list, MSG_PRIVMSG));
        }
        else
        {
index 3118798e6cfc2ea52b086f602a52eee419c2c597..bfc9e451948aa2841f92a7403743f1fef9f3dd68 100644 (file)
@@ -48,11 +48,11 @@ CmdResult CommandQline::Handle (const std::vector<std::string>& parameters, User
 
                if (parameters[0].find('@') != std::string::npos || parameters[0].find('!') != std::string::npos || parameters[0].find('.') != std::string::npos)
                {
-                       user->WriteServ("NOTICE %s :*** A Q-Line only bans a nick pattern, not a nick!user@host pattern.",user->nick.c_str());
+                       user->WriteNotice("*** A Q-Line only bans a nick pattern, not a nick!user@host pattern.");
                        return CMD_FAILURE;
                }
 
-               long duration = ServerInstance->Duration(parameters[1].c_str());
+               unsigned long duration = InspIRCd::Duration(parameters[1]);
                QLine* ql = new QLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
                if (ServerInstance->XLines->AddLine(ql,user))
                {
@@ -72,7 +72,7 @@ CmdResult CommandQline::Handle (const std::vector<std::string>& parameters, User
                else
                {
                        delete ql;
-                       user->WriteServ("NOTICE %s :*** Q-Line for %s already exists",user->nick.c_str(),parameters[0].c_str());
+                       user->WriteNotice("*** Q-Line for " + parameters[0] + " already exists");
                }
        }
        else
@@ -83,7 +83,7 @@ CmdResult CommandQline::Handle (const std::vector<std::string>& parameters, User
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Q-Line %s not found in list, try /stats q.",user->nick.c_str(),parameters[0].c_str());
+                       user->WriteNotice("*** Q-Line " + parameters[0] + " not found in list, try /stats q.");
                        return CMD_FAILURE;
                }
        }
index abf0b7876f88ac78a7a55f7d477908b06b5c3759..923bfe1299092edce3768eb964318d0eaccfb21d 100644 (file)
@@ -88,7 +88,6 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
                /* Don't do anything with the logs here -- logs are restarted
                 * after the config thread has completed.
                 */
-               ServerInstance->RehashUsersAndChans();
                FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
 
 
@@ -102,7 +101,7 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
                 * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
                 */
                if (IS_LOCAL(user))
-                       user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
+                       user->WriteNotice("*** Could not rehash: A rehash is already in progress.");
                else
                        ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");
        }
index bdbcfed35d314069b8355917dd0d502b960a5ae9..6711ada7decd2ef5e73b6ee31939f67bd4c41806 100644 (file)
@@ -39,7 +39,7 @@ class CommandRestart : public Command
 
 CmdResult CommandRestart::Handle (const std::vector<std::string>& parameters, User *user)
 {
-       ServerInstance->Logs->Log("COMMAND",DEFAULT,"Restart: %s",user->nick.c_str());
+       ServerInstance->Logs->Log("COMMAND", LOG_DEFAULT, "Restart: %s",user->nick.c_str());
        if (!ServerInstance->PassCompare(user, ServerInstance->Config->restartpass, parameters[0].c_str(), ServerInstance->Config->powerhash))
        {
                ServerInstance->SNO->WriteGlobalSno('a', "RESTART command from %s, restarting server.", user->GetFullRealHost().c_str());
index 898e89a7d8bbf7828694a49e02ff76bf5412219c..3145940be415d1452d3691ebbc69c40995406147 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "inspircd.h"
 #include "xline.h"
-#include "commands/cmd_whowas.h"
 
 #ifdef _WIN32
 #include <psapi.h>
@@ -60,7 +59,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
        std::string sn(ServerInstance->Config->ServerName);
 
        bool isPublic = ServerInstance->Config->UserStats.find(statschar) != std::string::npos;
-       bool isRemoteOper = IS_REMOTE(user) && IS_OPER(user);
+       bool isRemoteOper = IS_REMOTE(user) && (user->IsOper());
        bool isLocalOperWithPrivs = IS_LOCAL(user) && user->HasPrivPermission("servers/auspex");
 
        if (!isPublic && !isRemoteOper && !isLocalOperWithPrivs)
@@ -167,8 +166,9 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                                User* oper = *i;
                                if (!ServerInstance->ULine(oper->server))
                                {
+                                       LocalUser* lu = IS_LOCAL(oper);
                                        results.push_back(sn+" 249 " + user->nick + " :" + oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " +
-                                                       (IS_LOCAL(oper) ? ConvToStr(ServerInstance->Time() - oper->idle_lastmsg) + " secs" : "unavailable"));
+                                                       (lu ? ConvToStr(ServerInstance->Time() - lu->idle_lastmsg) + " secs" : "unavailable"));
                                        idx++;
                                }
                        }
@@ -205,7 +205,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                                if (i->second->use_count)
                                {
                                        /* RPL_STATSCOMMANDS */
-                                       results.push_back(sn+" 212 "+user->nick+" "+i->second->name+" "+ConvToStr(i->second->use_count)+" "+ConvToStr(i->second->total_bytes));
+                                       results.push_back(sn+" 212 "+user->nick+" "+i->second->name+" "+ConvToStr(i->second->use_count));
                                }
                        }
                break;
@@ -217,18 +217,6 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                        results.push_back(sn+" 249 "+user->nick+" :Channels: "+ConvToStr(ServerInstance->chanlist->size()));
                        results.push_back(sn+" 249 "+user->nick+" :Commands: "+ConvToStr(ServerInstance->Parser->cmdlist.size()));
 
-                       if (!ServerInstance->Config->WhoWasGroupSize == 0 && !ServerInstance->Config->WhoWasMaxGroups == 0)
-                       {
-                               Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
-                               if (whowas)
-                               {
-                                       WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_STATS);
-                                       req.user = user;
-                                       req.Send();
-                                       results.push_back(sn+" 249 "+user->nick+" :"+req.value);
-                               }
-                       }
-
                        float kbitpersec_in, kbitpersec_out, kbitpersec_total;
                        char kbitpersec_in_s[30], kbitpersec_out_s[30], kbitpersec_total_s[30];
 
@@ -295,7 +283,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                                double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
                                double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
                                double per = (n_eaten/n_elapsed);
-                               
+
                                char percent[30];
 
                                snprintf(percent, 30, "%03.5f%%", per);
@@ -357,7 +345,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                                        if (mh && mh->NeedsOper() && tag->AllowedChanModes[c - 'A'])
                                                cmodes.push_back(c);
                                }
-                               results.push_back(sn+" 243 "+user->nick+" O "+tag->NameStr() + " " + umodes + " " + cmodes);
+                               results.push_back(sn+" 243 "+user->nick+" O "+tag->name.c_str() + " " + umodes + " " + cmodes);
                        }
                }
                break;
index db452d38173f81c5779f58de84beaa0876009c1d..8c516ac424472cd890173b0a9877cdce71fc39f6 100644 (file)
@@ -50,16 +50,13 @@ CmdResult CommandTime::Handle (const std::vector<std::string>& parameters, User
 {
        if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
                return CMD_SUCCESS;
-       struct tm* timeinfo;
-       time_t local = ServerInstance->Time();
-
-       timeinfo = localtime(&local);
 
-       char tms[26];
-       snprintf(tms,26,"%s",asctime(timeinfo));
-       tms[24] = 0;
+       time_t local = ServerInstance->Time();
+       struct tm* timeinfo = localtime(&local);
+       const std::string& humanTime = asctime(timeinfo);
 
-       user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),ServerInstance->Config->ServerName.c_str(),tms);
+       user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),
+               ServerInstance->Config->ServerName.c_str(), humanTime.c_str());
 
        return CMD_SUCCESS;
 }
index 6d0f5f41c484e1722d0f76dbf8598ae77c5aaec4..29f4549873219141f037c187dd7e24e904ed0655 100644 (file)
@@ -42,12 +42,19 @@ class CommandUnloadmodule : public Command
 
 CmdResult CommandUnloadmodule::Handle (const std::vector<std::string>& parameters, User *user)
 {
+       if (!ServerInstance->Config->ConfValue("security")->getBool("allowcoreunload") &&
+               InspIRCd::Match(parameters[0], "cmd_*.so", ascii_case_insensitive_map))
+       {
+               user->WriteNumeric(972, "%s %s :You cannot unload core commands!", user->nick.c_str(), parameters[0].c_str());
+               return CMD_FAILURE;
+       }
+
        if (parameters[0] == "cmd_unloadmodule.so" || parameters[0] == "cmd_loadmodule.so")
        {
                user->WriteNumeric(972, "%s %s :You cannot unload module loading commands!", user->nick.c_str(), parameters[0].c_str());
                return CMD_FAILURE;
        }
-               
+
        Module* m = ServerInstance->Modules->Find(parameters[0]);
        if (m && ServerInstance->Modules->Unload(m))
        {
index 399de0b1a21d8dff83fbd73e4078d4bcde8045ba..933cbca041e05514cc8294d10835162889409e64 100644 (file)
@@ -54,12 +54,12 @@ CmdResult CommandUserhost::Handle (const std::vector<std::string>& parameters, U
                {
                        retbuf = retbuf + u->nick;
 
-                       if (IS_OPER(u))
+                       if (u->IsOper())
                                retbuf = retbuf + "*";
 
                        retbuf = retbuf + "=";
 
-                       if (IS_AWAY(u))
+                       if (u->IsAway())
                                retbuf += "-";
                        else
                                retbuf += "+";
index 7620197fd40053e96ecb5588d7299dece2e8063f..9fdd9c838d0d9a1c694d2c7f43e54c6b9a57f38d 100644 (file)
@@ -42,9 +42,13 @@ class CommandVersion : public Command
 
 CmdResult CommandVersion::Handle (const std::vector<std::string>&, User *user)
 {
-       std::string version = ServerInstance->GetVersionString(IS_OPER(user));
+       std::string version = ServerInstance->GetVersionString((user->IsOper()));
        user->WriteNumeric(RPL_VERSION, "%s :%s", user->nick.c_str(), version.c_str());
-       ServerInstance->Config->Send005(user);
+       LocalUser *lu = IS_LOCAL(user);
+       if (lu != NULL)
+       {
+               ServerInstance->ISupport.SendTo(lu);
+       }
        return CMD_SUCCESS;
 }
 
index 198997a950a4d09ccc45f81aeb5ad107d75d762f..3cd8abc42bb9daa628c5b6649516e5cf16fbbdd5 100644 (file)
@@ -38,6 +38,11 @@ class CommandWallops : public Command
         * @return A value from CmdResult to indicate command success or failure.
         */
        CmdResult Handle(const std::vector<std::string>& parameters, User *user);
+
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       {
+               return ROUTE_BROADCAST;
+       }
 };
 
 CmdResult CommandWallops::Handle (const std::vector<std::string>& parameters, User *user)
@@ -52,7 +57,6 @@ CmdResult CommandWallops::Handle (const std::vector<std::string>& parameters, Us
                        user->WriteTo(t,wallop);
        }
 
-       FOREACH_MOD(I_OnWallops,OnWallops(user,parameters[0]));
        return CMD_SUCCESS;
 }
 
index f8926b9f7a473e1ac5835a370cb63d5a91cb5292..82d541a2a7829802df5728fb237b06aa934755a1 100644 (file)
@@ -138,7 +138,7 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext)
                        match = InspIRCd::Match(user->awaymsg, matchtext);
                else if (opt_time)
                {
-                       long seconds = ServerInstance->Duration(matchtext);
+                       long seconds = InspIRCd::Duration(matchtext);
 
                        // Okay, so time matching, we want all users connected `seconds' ago
                        if (user->age >= ServerInstance->Time() - seconds)
@@ -197,11 +197,11 @@ void CommandWho::SendWhoLine(User* user, const std::vector<std::string>& parms,
                wholine.append(ServerInstance->Config->HideWhoisServer);
        else
                wholine.append(u->server);
-       
+
        wholine.append(" " + u->nick + " ");
 
        /* away? */
-       if (IS_AWAY(u))
+       if (u->IsAway())
        {
                wholine.append("G");
        }
@@ -211,7 +211,7 @@ void CommandWho::SendWhoLine(User* user, const std::vector<std::string>& parms,
        }
 
        /* oper? */
-       if (IS_OPER(u))
+       if (u->IsOper())
        {
                wholine.push_back('*');
        }
@@ -249,33 +249,17 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
        opt_far = false;
        opt_time = false;
 
-       Channel *ch = NULL;
        std::vector<std::string> whoresults;
        std::string initial = "352 " + user->nick + " ";
 
-       char matchtext[MAXBUF];
-       bool usingwildcards = false;
-
        /* Change '0' into '*' so the wildcard matcher can grok it */
-       if (parameters[0] == "0")
-               strlcpy(matchtext, "*", MAXBUF);
-       else
-               strlcpy(matchtext, parameters[0].c_str(), MAXBUF);
+       std::string matchtext = ((parameters[0] == "0") ? "*" : parameters[0]);
 
-       for (const char* check = matchtext; *check; check++)
-       {
-               if (*check == '*' || *check == '?' || *check == '.')
-               {
-                       usingwildcards = true;
-                       break;
-               }
-       }
+       // WHO flags count as a wildcard
+       bool usingwildcards = ((parameters.size() > 1) || (matchtext.find_first_of("*?.") != std::string::npos));
 
        if (parameters.size() > 1)
        {
-               /* Fix for bug #444, WHO flags count as a wildcard */
-               usingwildcards = true;
-
                for (std::string::const_iterator iter = parameters[1].begin(); iter != parameters[1].end(); ++iter)
                {
                        switch (*iter)
@@ -325,7 +309,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
 
 
        /* who on a channel? */
-       ch = ServerInstance->FindChan(matchtext);
+       Channel* ch = ServerInstance->FindChan(matchtext);
 
        if (ch)
        {
@@ -342,7 +326,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                if (user != i->first)
                                {
                                        /* opers only, please */
-                                       if (opt_viewopersonly && !IS_OPER(i->first))
+                                       if (opt_viewopersonly && !i->first->IsOper())
                                                continue;
 
                                        /* If we're not inside the channel, hide +i users */
@@ -364,7 +348,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                        {
                                User* oper = *i;
 
-                               if (whomatch(user, oper, matchtext))
+                               if (whomatch(user, oper, matchtext.c_str()))
                                {
                                        if (!user->SharesChannelWith(oper))
                                        {
@@ -380,7 +364,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                {
                        for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); i++)
                        {
-                               if (whomatch(user, i->second, matchtext))
+                               if (whomatch(user, i->second, matchtext.c_str()))
                                {
                                        if (!user->SharesChannelWith(i->second))
                                        {
index ba2ad9c1526e1a83b8ad8f2518333f48de66270a..fea14f375bb1c12efe85a803ac9cf6117e3e14dc 100644 (file)
  * the same way, however, they can be fully unloaded, where these
  * may not.
  */
-class CommandWhois : public Command
+class CommandWhois : public SplitCommand
 {
+       void SplitChanList(User* source, User* dest, const std::string& cl);
+       void DoWhois(User* user, User* dest, unsigned long signon, unsigned long idle);
+       std::string ChannelList(User* source, User* dest, bool spy);
+
  public:
        /** Constructor for whois.
         */
-       CommandWhois ( Module* parent) : Command(parent,"WHOIS",1) { Penalty = 2; syntax = "<nick>{,<nick>}"; }
+       CommandWhois ( Module* parent) : SplitCommand(parent,"WHOIS", 1) { Penalty = 2; syntax = "<nick>{,<nick>}"; }
        /** Handle command.
         * @param parameters The parameters to the comamnd
         * @param pcnt The number of parameters passed to teh command
         * @param user The user issuing the command
         * @return A value from CmdResult to indicate command success or failure.
         */
-       CmdResult Handle(const std::vector<std::string>& parameters, User *user);
+       CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
+       CmdResult HandleRemote(const std::vector<std::string>& parameters, RemoteUser* target);
 };
 
+std::string CommandWhois::ChannelList(User* source, User* dest, bool spy)
+{
+       std::string list;
+
+       for (UCListIter i = dest->chans.begin(); i != dest->chans.end(); i++)
+       {
+               Channel* c = *i;
+               /* If the target is the sender, neither +p nor +s is set, or
+                * the channel contains the user, it is not a spy channel
+                */
+               if (spy != (source == dest || !(c->IsModeSet('p') || c->IsModeSet('s')) || c->HasUser(source)))
+                       list.append(c->GetPrefixChar(dest)).append(c->name).append(" ");
+       }
+
+       return list;
+}
 
-CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User *user)
+void CommandWhois::SplitChanList(User* source, User* dest, const std::string& cl)
+{
+       std::string line;
+       std::ostringstream prefix;
+       std::string::size_type start, pos, length;
+
+       prefix << source->nick << " " << dest->nick << " :";
+       line = prefix.str();
+       int namelen = ServerInstance->Config->ServerName.length() + 6;
+
+       for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
+       {
+               length = (pos == std::string::npos) ? cl.length() : pos;
+
+               if (line.length() + namelen + length - start > 510)
+               {
+                       ServerInstance->SendWhoisLine(source, dest, 319, "%s", line.c_str());
+                       line = prefix.str();
+               }
+
+               if(pos == std::string::npos)
+               {
+                       line.append(cl.substr(start, length - start));
+                       break;
+               }
+               else
+               {
+                       line.append(cl.substr(start, length - start + 1));
+               }
+       }
+
+       if (line.length() != prefix.str().length())
+       {
+               ServerInstance->SendWhoisLine(source, dest, 319, "%s", line.c_str());
+       }
+}
+
+void CommandWhois::DoWhois(User* user, User* dest, unsigned long signon, unsigned long idle)
+{
+       ServerInstance->SendWhoisLine(user, dest, 311, "%s %s %s %s * :%s",user->nick.c_str(), dest->nick.c_str(), dest->ident.c_str(), dest->dhost.c_str(), dest->fullname.c_str());
+       if (user == dest || user->HasPrivPermission("users/auspex"))
+       {
+               ServerInstance->SendWhoisLine(user, dest, 378, "%s %s :is connecting from %s@%s %s", user->nick.c_str(), dest->nick.c_str(), dest->ident.c_str(), dest->host.c_str(), dest->GetIPString().c_str());
+       }
+
+       std::string cl = ChannelList(user, dest, false);
+       const ServerConfig::OperSpyWhoisState state = user->HasPrivPermission("users/auspex") ? ServerInstance->Config->OperSpyWhois : ServerConfig::SPYWHOIS_NONE;
+
+       if (state == ServerConfig::SPYWHOIS_SINGLEMSG)
+               cl.append(ChannelList(user, dest, true));
+
+       SplitChanList(user, dest, cl);
+
+       if (state == ServerConfig::SPYWHOIS_SPLITMSG)
+       {
+               std::string scl = ChannelList(user, dest, true);
+               if (scl.length())
+               {
+                       ServerInstance->SendWhoisLine(user, dest, 336, "%s %s :is on private/secret channels:",user->nick.c_str(), dest->nick.c_str());
+                       SplitChanList(user, dest, scl);
+               }
+       }
+       if (user != dest && !ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex"))
+       {
+               ServerInstance->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick.c_str(), dest->nick.c_str(), ServerInstance->Config->HideWhoisServer.c_str(), ServerInstance->Config->Network.c_str());
+       }
+       else
+       {
+               std::string serverdesc = ServerInstance->GetServerDescription(dest->server);
+               ServerInstance->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick.c_str(), dest->nick.c_str(), dest->server.c_str(), serverdesc.c_str());
+       }
+
+       if (dest->IsAway())
+       {
+               ServerInstance->SendWhoisLine(user, dest, 301, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), dest->awaymsg.c_str());
+       }
+
+       if (dest->IsOper())
+       {
+               if (ServerInstance->Config->GenericOper)
+                       ServerInstance->SendWhoisLine(user, dest, 313, "%s %s :is an IRC operator",user->nick.c_str(), dest->nick.c_str());
+               else
+                       ServerInstance->SendWhoisLine(user, dest, 313, "%s %s :is %s %s on %s",user->nick.c_str(), dest->nick.c_str(), (strchr("AEIOUaeiou",dest->oper->name[0]) ? "an" : "a"),dest->oper->name.c_str(), ServerInstance->Config->Network.c_str());
+       }
+
+       if (user == dest || user->HasPrivPermission("users/auspex"))
+       {
+               if (dest->IsModeSet('s') != 0)
+               {
+                       ServerInstance->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes(), dest->FormatNoticeMasks());
+               }
+               else
+               {
+                       ServerInstance->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes());
+               }
+       }
+
+       FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
+
+       /*
+        * We only send these if we've been provided them. That is, if hidewhois is turned off, and user is local, or
+        * if remote whois is queried, too. This is to keep the user hidden, and also since you can't reliably tell remote time. -- w00t
+        */
+       if ((idle) || (signon))
+       {
+               ServerInstance->SendWhoisLine(user, dest, 317, "%s %s %lu %lu :seconds idle, signon time",user->nick.c_str(), dest->nick.c_str(), idle, signon);
+       }
+
+       ServerInstance->SendWhoisLine(user, dest, 318, "%s %s :End of /WHOIS list.",user->nick.c_str(), dest->nick.c_str());
+}
+
+CmdResult CommandWhois::HandleRemote(const std::vector<std::string>& parameters, RemoteUser* target)
+{
+       if (parameters.size() < 2)
+               return CMD_FAILURE;
+
+       User* user = ServerInstance->FindUUID(parameters[0]);
+       if (!user)
+               return CMD_FAILURE;
+
+       unsigned long idle = ConvToInt(parameters[1]);
+       DoWhois(user, target, target->signon, idle);
+
+       return CMD_SUCCESS;
+}
+
+CmdResult CommandWhois::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
 {
        User *dest;
        int userindex = 0;
@@ -51,7 +198,6 @@ CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User
        if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
                return CMD_SUCCESS;
 
-
        /*
         * If 2 paramters are specified (/whois nick nick), ignore the first one like spanningtree
         * does, and use the second one, otherwise, use the only paramter. -- djGrrr
@@ -59,10 +205,7 @@ CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User
        if (parameters.size() > 1)
                userindex = 1;
 
-       if (IS_LOCAL(user))
-               dest = ServerInstance->FindNickOnly(parameters[userindex]);
-       else
-               dest = ServerInstance->FindNick(parameters[userindex]);
+       dest = ServerInstance->FindNickOnly(parameters[userindex]);
 
        if ((dest) && (dest->registered == REG_ALL))
        {
@@ -74,13 +217,14 @@ CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User
                 * For remote users (/w remoteuser remoteuser), spanningtree will handle calling do_whois, so we can ignore this case.
                 * Thanks to djGrrr for not being impatient while I have a crap day coding. :p -- w00t
                 */
-               if (IS_LOCAL(dest) && (ServerInstance->Config->HideWhoisServer.empty() || parameters.size() > 1))
+               LocalUser* localuser = IS_LOCAL(dest);
+               if (localuser && (ServerInstance->Config->HideWhoisServer.empty() || parameters.size() > 1))
                {
-                       idle = abs((long)((dest->idle_lastmsg)-ServerInstance->Time()));
+                       idle = abs((long)((localuser->idle_lastmsg)-ServerInstance->Time()));
                        signon = dest->signon;
                }
 
-               ServerInstance->DoWhois(user,dest,signon,idle,parameters[userindex].c_str());
+               DoWhois(user,dest,signon,idle);
        }
        else
        {
@@ -93,6 +237,4 @@ CmdResult CommandWhois::Handle (const std::vector<std::string>& parameters, User
        return CMD_SUCCESS;
 }
 
-
-
 COMMAND_INIT(CommandWhois)
index 17a779ec33df209e513a788ff3ba707b62bb11c9..a973e44ccc20b9d66b3da00ebeff3a3ecf8292d2 100644 (file)
 #include "inspircd.h"
 #include "commands/cmd_whowas.h"
 
-WhoWasMaintainTimer * timer;
-
-CommandWhowas::CommandWhowas( Module* parent) : Command(parent, "WHOWAS", 1)
+CommandWhowas::CommandWhowas( Module* parent)
+       : Command(parent, "WHOWAS", 1), WhoWasGroupSize(0), WhoWasMaxGroups(0), WhoWasMaxKeep(0)
 {
        syntax = "<nick>{,<nick>}";
        Penalty = 2;
-       timer = new WhoWasMaintainTimer(3600);
-       ServerInstance->Timers->AddTimer(timer);
 }
 
 CmdResult CommandWhowas::Handle (const std::vector<std::string>& parameters, User* user)
 {
        /* if whowas disabled in config */
-       if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
+       if (this->WhoWasGroupSize == 0 || this->WhoWasMaxGroups == 0)
        {
                user->WriteNumeric(421, "%s %s :This command has been disabled.",user->nick.c_str(),name.c_str());
                return CMD_FAILURE;
@@ -112,7 +109,7 @@ std::string CommandWhowas::GetStats()
 void CommandWhowas::AddToWhoWas(User* user)
 {
        /* if whowas disabled */
-       if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
+       if (this->WhoWasGroupSize == 0 || this->WhoWasMaxGroups == 0)
        {
                return;
        }
@@ -127,7 +124,7 @@ void CommandWhowas::AddToWhoWas(User* user)
                whowas[user->nick.c_str()] = n;
                whowas_fifo.push_back(std::make_pair(ServerInstance->Time(),user->nick.c_str()));
 
-               if ((int)(whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
+               if ((int)(whowas.size()) > this->WhoWasMaxGroups)
                {
                        whowas_users::iterator iter2 = whowas.find(whowas_fifo[0].second);
                        if (iter2 != whowas.end())
@@ -156,7 +153,7 @@ void CommandWhowas::AddToWhoWas(User* user)
                WhoWasGroup *a = new WhoWasGroup(user);
                group->push_back(a);
 
-               if ((int)(group->size()) > ServerInstance->Config->WhoWasGroupSize)
+               if ((int)(group->size()) > this->WhoWasGroupSize)
                {
                        WhoWasGroup *a2 = (WhoWasGroup*)*(group->begin());
                        delete a2;
@@ -169,9 +166,9 @@ void CommandWhowas::AddToWhoWas(User* user)
 void CommandWhowas::PruneWhoWas(time_t t)
 {
        /* config values */
-       int groupsize = ServerInstance->Config->WhoWasGroupSize;
-       int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
-       int maxkeep =   ServerInstance->Config->WhoWasMaxKeep;
+       int groupsize = this->WhoWasGroupSize;
+       int maxgroups = this->WhoWasMaxGroups;
+       int maxkeep =   this->WhoWasMaxKeep;
 
        /* first cut the list to new size (maxgroups) and also prune entries that are timed out. */
        whowas_users::iterator iter;
@@ -186,7 +183,7 @@ void CommandWhowas::PruneWhoWas(time_t t)
                        if (iter == whowas.end())
                        {
                                /* this should never happen, if it does maps are corrupt */
-                               ServerInstance->Logs->Log("WHOWAS",DEFAULT, "BUG: Whowas maps got corrupted! (1)");
+                               ServerInstance->Logs->Log("WHOWAS", LOG_DEFAULT, "BUG: Whowas maps got corrupted! (1)");
                                return;
                        }
 
@@ -219,7 +216,7 @@ void CommandWhowas::PruneWhoWas(time_t t)
                if (iter == whowas.end())
                {
                        /* this should never happen, if it does maps are corrupt */
-                       ServerInstance->Logs->Log("WHOWAS",DEFAULT, "BUG: Whowas maps got corrupted! (2)");
+                       ServerInstance->Logs->Log("WHOWAS", LOG_DEFAULT, "BUG: Whowas maps got corrupted! (2)");
                        return;
                }
                whowas_set* n = (whowas_set*)iter->second;
@@ -245,7 +242,7 @@ void CommandWhowas::MaintainWhoWas(time_t t)
                whowas_set* n = (whowas_set*)iter->second;
                if (n->size())
                {
-                       while ((n->begin() != n->end()) && ((*n->begin())->signon < t - ServerInstance->Config->WhoWasMaxKeep))
+                       while ((n->begin() != n->end()) && ((*n->begin())->signon < t - this->WhoWasMaxKeep))
                        {
                                WhoWasGroup *a = *(n->begin());
                                delete a;
@@ -257,11 +254,6 @@ void CommandWhowas::MaintainWhoWas(time_t t)
 
 CommandWhowas::~CommandWhowas()
 {
-       if (timer)
-       {
-               ServerInstance->Timers->DelTimer(timer);
-       }
-
        whowas_users::iterator iter;
        int fifosize;
        while ((fifosize = (int)whowas_fifo.size()) > 0)
@@ -272,7 +264,7 @@ CommandWhowas::~CommandWhowas()
                if (iter == whowas.end())
                {
                        /* this should never happen, if it does maps are corrupt */
-                       ServerInstance->Logs->Log("WHOWAS",DEFAULT, "BUG: Whowas maps got corrupted! (3)");
+                       ServerInstance->Logs->Log("WHOWAS", LOG_DEFAULT, "BUG: Whowas maps got corrupted! (3)");
                        return;
                }
 
@@ -303,19 +295,20 @@ WhoWasGroup::~WhoWasGroup()
 {
 }
 
-/* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
-void WhoWasMaintainTimer::Tick(time_t)
+class ModuleWhoWas : public Module
 {
-       Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
-       if (whowas)
+       CommandWhowas cmd;
+
+       void RangeCheck(int& value, int min, int max, int def, const char* msg)
        {
-               WhowasRequest(whowas, whowas, WhowasRequest::WHOWAS_MAINTAIN).Send();
+               // From ConfigReader
+               if (value >= min && value <= max)
+                       return;
+
+               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: %s value of %d is not between %d and %d; set to %d.", msg, value, min, max, def);
+               value = def;
        }
-}
 
-class ModuleWhoWas : public Module
-{
-       CommandWhowas cmd;
  public:
        ModuleWhoWas() : cmd(this)
        {
@@ -324,31 +317,53 @@ class ModuleWhoWas : public Module
        void init()
        {
                ServerInstance->Modules->AddService(cmd);
+               Implementation eventlist[] = { I_OnGarbageCollect, I_OnUserQuit, I_OnStats, I_OnRehash };
+               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+               OnRehash(NULL);
        }
 
-       void OnRequest(Request& request)
+       void OnGarbageCollect()
        {
-               WhowasRequest& req = static_cast<WhowasRequest&>(request);
-               switch (req.type)
-               {
-                       case WhowasRequest::WHOWAS_ADD:
-                               cmd.AddToWhoWas(req.user);
-                               break;
-                       case WhowasRequest::WHOWAS_STATS:
-                               req.value = cmd.GetStats();
-                               break;
-                       case WhowasRequest::WHOWAS_PRUNE:
-                               cmd.PruneWhoWas(ServerInstance->Time());
-                               break;
-                       case WhowasRequest::WHOWAS_MAINTAIN:
-                               cmd.MaintainWhoWas(ServerInstance->Time());
-                               break;
-               }
+               /* Removes all entries older than WhoWasMaxKeep */
+               cmd.MaintainWhoWas(ServerInstance->Time());
+       }
+
+       void OnUserQuit(User* user, const std::string& message, const std::string& oper_message)
+       {
+               cmd.AddToWhoWas(user);
+       }
+
+       ModResult OnStats(char symbol, User* user, string_list &results)
+       {
+               if (symbol == 'z')
+                       results.push_back(ServerInstance->Config->ServerName+" 249 "+user->nick+" :"+cmd.GetStats());
+
+               return MOD_RES_PASSTHRU;
+       }
+
+       void OnRehash(User* user)
+       {
+               ConfigTag* tag = ServerInstance->Config->ConfValue("whowas");
+               int NewGroupSize = tag->getInt("groupsize");
+               int NewMaxGroups = tag->getInt("maxgroups");
+               int NewMaxKeep = InspIRCd::Duration(tag->getString("maxkeep"));
+
+               RangeCheck(NewGroupSize, 0, 10000, 10, "<whowas:groupsize>");
+               RangeCheck(NewMaxGroups, 0, 1000000, 10240, "<whowas:maxgroups>");
+               RangeCheck(NewMaxKeep, 3600, INT_MAX, 3600, "<whowas:maxkeep>");
+
+               if ((NewGroupSize == cmd.WhoWasGroupSize) && (NewMaxGroups == cmd.WhoWasMaxGroups) && (NewMaxKeep == cmd.WhoWasMaxKeep))
+                       return;
+
+               cmd.WhoWasGroupSize = NewGroupSize;
+               cmd.WhoWasMaxGroups = NewMaxGroups;
+               cmd.WhoWasMaxKeep = NewMaxKeep;
+               cmd.PruneWhoWas(ServerInstance->Time());
        }
 
        Version GetVersion()
        {
-               return Version("WHOWAS Command", VF_VENDOR);
+               return Version("WHOWAS", VF_VENDOR);
        }
 };
 
index 91d9c6255962e1a10b6aecdbfda9e99370033e79..fdb156e0ab51a93049b4ffcd1f5f68607fe02026 100644 (file)
@@ -49,7 +49,7 @@ CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User
        {
                if (target.find('!') != std::string::npos)
                {
-                       user->WriteServ("NOTICE %s :*** You cannot include a nickname in a zline, a zline must ban only an IP mask",user->nick.c_str());
+                       user->WriteNotice("*** You cannot include a nickname in a zline, a zline must ban only an IP mask");
                        return CMD_FAILURE;
                }
 
@@ -72,8 +72,7 @@ CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User
                if (ServerInstance->IPMatchesEveryone(ipaddr,user))
                        return CMD_FAILURE;
 
-               long duration = ServerInstance->Duration(parameters[1].c_str());
-
+               unsigned long duration = InspIRCd::Duration(parameters[1]);
                ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
                if (ServerInstance->XLines->AddLine(zl,user))
                {
@@ -93,7 +92,7 @@ CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User
                else
                {
                        delete zl;
-                       user->WriteServ("NOTICE %s :*** Z-Line for %s already exists",user->nick.c_str(),ipaddr);
+                       user->WriteNotice("*** Z-Line for " + std::string(ipaddr) + " already exists");
                }
        }
        else
@@ -104,7 +103,7 @@ CmdResult CommandZline::Handle (const std::vector<std::string>& parameters, User
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick.c_str(),target.c_str());
+                       user->WriteNotice("*** Z-Line " + target + " not found in list, try /stats Z.");
                        return CMD_FAILURE;
                }
        }
index 7d9eab651a88f81719e9f4b216cc8db090652301..61cdb55fa160ded9627f7b90cc369bfc6793aaa2 100644 (file)
@@ -119,7 +119,7 @@ struct Parser
                while (1)
                {
                        ch = next();
-                       if (ch == '&' && (flags & FLAG_USE_XML))
+                       if (ch == '&' && !(flags & FLAG_USE_COMPAT))
                        {
                                std::string varname;
                                while (1)
@@ -141,7 +141,7 @@ struct Parser
                                        throw CoreException("Undefined XML entity reference '&" + varname + ";'");
                                value.append(var->second);
                        }
-                       else if (ch == '\\' && !(flags & FLAG_USE_XML))
+                       else if (ch == '\\' && (flags & FLAG_USE_COMPAT))
                        {
                                int esc = next();
                                if (esc == 'n')
@@ -211,7 +211,7 @@ struct Parser
                }
                else if (name == "define")
                {
-                       if (!(flags & FLAG_USE_XML))
+                       if (flags & FLAG_USE_COMPAT)
                                throw CoreException("<define> tags may only be used in XML-style config (add <config format=\"xml\">)");
                        std::string varname = tag->getString("name");
                        std::string value = tag->getString("value");
@@ -223,9 +223,9 @@ struct Parser
                {
                        std::string format = tag->getString("format");
                        if (format == "xml")
-                               flags |= FLAG_USE_XML;
+                               flags &= ~FLAG_USE_COMPAT;
                        else if (format == "compat")
-                               flags &= ~FLAG_USE_XML;
+                               flags |= FLAG_USE_COMPAT;
                        else if (!format.empty())
                                throw CoreException("Unknown configuration format " + format);
                }
@@ -342,7 +342,7 @@ void ParseStack::DoReadFile(const std::string& key, const std::string& name, int
 
 bool ParseStack::ParseFile(const std::string& name, int flags, const std::string& mandatory_tag)
 {
-       ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading file %s", name.c_str());
+       ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Reading file %s", name.c_str());
        for (unsigned int t = 0; t < reading.size(); t++)
        {
                if (std::string(name) == reading[t])
@@ -366,7 +366,7 @@ bool ParseStack::ParseFile(const std::string& name, int flags, const std::string
 
 bool ParseStack::ParseExec(const std::string& name, int flags, const std::string& mandatory_tag)
 {
-       ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading executable %s", name.c_str());
+       ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Reading executable %s", name.c_str());
        for (unsigned int t = 0; t < reading.size(); t++)
        {
                if (std::string(name) == reading[t])
@@ -399,7 +399,7 @@ bool ConfigTag::readString(const std::string& key, std::string& value, bool allo
                value = j->second;
                if (!allow_lf && (value.find('\n') != std::string::npos))
                {
-                       ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + key + "> at " + getTagLocation() +
+                       ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Value of <" + tag + ":" + key + "> at " + getTagLocation() +
                                " contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces.");
                        for (std::string::iterator n = value.begin(); n != value.end(); n++)
                                if (*n == '\n')
@@ -462,7 +462,7 @@ bool ConfigTag::getBool(const std::string &key, bool def)
        if (result == "no" || result == "false" || result == "0" || result == "off")
                return false;
 
-       ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + key + "> at " + getTagLocation() +
+       ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Value of <" + tag + ":" + key + "> at " + getTagLocation() +
                " is not valid, ignoring");
        return def;
 }
index e8707cc3edfa18f6192b753a00f27f8ad8edf9cf..a8c0abe89056b4ed9fc11f5d47ab81ffa3285360 100644 (file)
 
 
 #include "inspircd.h"
-#include <fstream>
 #include "xline.h"
+#include "listmode.h"
 #include "exitcodes.h"
-#include "commands/cmd_whowas.h"
 #include "configparser.h"
 #include <iostream>
-#ifdef _WIN32
-#include <Iphlpapi.h>
-#pragma comment(lib, "Iphlpapi.lib")
-#endif
 
 ServerConfig::ServerConfig()
 {
-       WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0;
-       RawLog = NoUserDns = HideBans = HideSplits = UndernetMsgPrefix = false;
+       RawLog = HideBans = HideSplits = UndernetMsgPrefix = false;
        WildcardIPv6 = CycleHosts = InvBypassModes = true;
        dns_timeout = 5;
        MaxTargets = 20;
@@ -50,60 +44,16 @@ ServerConfig::ServerConfig()
        c_ipv6_range = 128;
 }
 
-void ServerConfig::Update005()
-{
-       std::stringstream out(data005);
-       std::vector<std::string> data;
-       std::string token;
-       while (out >> token)
-               data.push_back(token);
-       sort(data.begin(), data.end());
-
-       std::string line5;
-       isupport.clear();
-       for(unsigned int i=0; i < data.size(); i++)
-       {
-               token = data[i];
-               line5 = line5 + token + " ";
-               if (i % 13 == 12)
-               {
-                       line5.append(":are supported by this server");
-                       isupport.push_back(line5);
-                       line5.clear();
-               }
-       }
-       if (!line5.empty())
-       {
-               line5.append(":are supported by this server");
-               isupport.push_back(line5);
-       }
-}
-
-void ServerConfig::Send005(User* user)
-{
-       for (std::vector<std::string>::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++)
-               user->WriteNumeric(RPL_ISUPPORT, "%s %s", user->nick.c_str(), line->c_str());
-}
-
 template<typename T, typename V>
 static void range(T& value, V min, V max, V def, const char* msg)
 {
        if (value >= (T)min && value <= (T)max)
                return;
-       ServerInstance->Logs->Log("CONFIG", DEFAULT,
-               "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.",
+       ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.",
                msg, (long)value, (long)min, (long)max, (long)def);
        value = def;
 }
 
-
-static void ValidIP(const std::string& ip, const std::string& key)
-{
-       irc::sockets::sockaddrs dummy;
-       if (!irc::sockets::aptosa(ip, 0, dummy))
-               throw CoreException("The value of "+key+" is not an IP address");
-}
-
 static void ValidHost(const std::string& p, const std::string& msg)
 {
        int num_dots = 0;
@@ -145,64 +95,6 @@ bool ServerConfig::ApplyDisabledCommands(const std::string& data)
        return true;
 }
 
-static void FindDNS(std::string& server)
-{
-       if (!server.empty())
-               return;
-#ifdef _WIN32
-       // attempt to look up their nameserver from the system
-       ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find a working server in the system settings...");
-
-       PFIXED_INFO pFixedInfo;
-       DWORD dwBufferSize = sizeof(FIXED_INFO);
-       pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, sizeof(FIXED_INFO));
-
-       if(pFixedInfo)
-       {
-               if (GetNetworkParams(pFixedInfo, &dwBufferSize) == ERROR_BUFFER_OVERFLOW) {
-                       HeapFree(GetProcessHeap(), 0, pFixedInfo);
-                       pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
-               }
-
-               if(pFixedInfo) {
-                       if (GetNetworkParams(pFixedInfo, &dwBufferSize) == NO_ERROR)
-                               server = pFixedInfo->DnsServerList.IpAddress.String;
-
-                       HeapFree(GetProcessHeap(), 0, pFixedInfo);
-               }
-
-               if(!server.empty())
-               {
-                       ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first active resolver in the system settings.", server.c_str());
-                       return;
-               }
-       }
-
-       ServerInstance->Logs->Log("CONFIG",DEFAULT,"No viable nameserver found! Defaulting to nameserver '127.0.0.1'!");
-#else
-       // attempt to look up their nameserver from /etc/resolv.conf
-       ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
-
-       std::ifstream resolv("/etc/resolv.conf");
-
-       while (resolv >> server)
-       {
-               if (server == "nameserver")
-               {
-                       resolv >> server;
-                       if (server.find_first_not_of("0123456789.") == std::string::npos)
-                       {
-                               ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",server.c_str());
-                               return;
-                       }
-               }
-       }
-
-       ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
-#endif
-       server = "127.0.0.1";
-}
-
 static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
 {
        ConfigTagList tags = conf->ConfTags(tag);
@@ -241,8 +133,6 @@ void ServerConfig::CrossCheckOperClassType()
                std::string name = tag->getString("name");
                if (name.empty())
                        throw CoreException("<type:name> is missing from tag at " + tag->getTagLocation());
-               if (!ServerInstance->IsNick(name.c_str(), Limits.NickMax))
-                       throw CoreException("<type:name> is invalid (value '" + name + "')");
                if (oper_blocks.find(" " + name) != oper_blocks.end())
                        throw CoreException("Duplicate type block with name " + name + " at " + tag->getTagLocation());
 
@@ -419,6 +309,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
                        me->maxchans = tag->getInt("maxchans", me->maxchans);
                        me->maxconnwarn = tag->getBool("maxconnwarn", me->maxconnwarn);
                        me->limit = tag->getInt("limit", me->limit);
+                       me->nouserdns = tag->getBool("nouserdns", me->nouserdns);
 
                        ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask);
                        if (oldMask != oldBlocksByMask.end())
@@ -436,42 +327,29 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
 
 /** Represents a deprecated configuration tag.
  */
-struct Deprecated
+struct DeprecatedConfig
 {
-       /** Tag name
-        */
-       const char* tag;
-       /** Tag value
-        */
-       const char* value;
-       /** Reason for deprecation
-        */
-       const char* reason;
+       /** Tag name. */
+       std::string tag;
+
+       /** Attribute key. */
+       std::string key;
+
+       /** Attribute value. */
+       std::string value;
+
+       /** Reason for deprecation. */
+       std::string reason;
 };
 
-static const Deprecated ChangedConfig[] = {
-       {"options", "hidelinks",                "has been moved to <security:hidelinks> as of 1.2a3"},
-       {"options", "hidewhois",                "has been moved to <security:hidewhois> as of 1.2a3"},
-       {"options", "userstats",                "has been moved to <security:userstats> as of 1.2a3"},
-       {"options", "customversion",    "has been moved to <security:customversion> as of 1.2a3"},
-       {"options", "hidesplits",               "has been moved to <security:hidesplits> as of 1.2a3"},
-       {"options", "hidebans",         "has been moved to <security:hidebans> as of 1.2a3"},
-       {"options", "hidekills",                "has been moved to <security:hidekills> as of 1.2a3"},
-       {"options", "operspywhois",             "has been moved to <security:operspywhois> as of 1.2a3"},
-       {"options", "announceinvites",  "has been moved to <security:announceinvites> as of 1.2a3"},
-       {"options", "hidemodes",                "has been moved to <security:hidemodes> as of 1.2a3"},
-       {"options", "maxtargets",               "has been moved to <security:maxtargets> as of 1.2a3"},
-       {"options",     "nouserdns",            "has been moved to <performance:nouserdns> as of 1.2a3"},
-       {"options",     "maxwho",               "has been moved to <performance:maxwho> as of 1.2a3"},
-       {"options",     "softlimit",            "has been moved to <performance:softlimit> as of 1.2a3"},
-       {"options", "somaxconn",                "has been moved to <performance:somaxconn> as of 1.2a3"},
-       {"options", "netbuffersize",    "has been moved to <performance:netbuffersize> as of 1.2a3"},
-       {"options", "maxwho",           "has been moved to <performance:maxwho> as of 1.2a3"},
-       {"options",     "loglevel",             "1.2+ does not use the loglevel value. Please define <log> tags instead."},
-       {"die",     "value",            "you need to reread your config"},
-       {"bind",    "transport",                "has been moved to <bind:ssl> as of 2.0a1"},
-       {"link",    "transport",                "has been moved to <link:ssl> as of 2.0a1"},
-       {"link",        "autoconnect",          "2.0+ does not use the autoconnect value. Please define <autoconnect> tags instead."},
+static const DeprecatedConfig ChangedConfig[] = {
+       { "bind",        "transport",   "",                 "has been moved to <bind:ssl> as of 2.0" },
+       { "die",         "value",       "",                 "you need to reread your config" },
+       { "link",        "autoconnect", "",                 "2.0+ does not use this attribute - define <autoconnect> tags instead" },
+       { "link",        "transport",   "",                 "has been moved to <link:ssl> as of 2.0" },
+       { "module",      "name",        "m_chanprotect.so", "has been replaced with m_customprefix as of 2.2" },
+       { "module",      "name",        "m_halfop.so",      "has been replaced with m_customprefix as of 2.2" },
+       { "performance", "nouserdns",   "",                 "has been moved to <connect:nouserdns> as of 2.2" }
 };
 
 void ServerConfig::Fill()
@@ -483,7 +361,7 @@ void ServerConfig::Fill()
                ServerName = ConfValue("server")->getString("name");
                sid = ConfValue("server")->getString("id");
                ValidHost(ServerName, "<server:name>");
-               if (!sid.empty() && !ServerInstance->IsSID(sid))
+               if (!sid.empty() && !InspIRCd::IsSID(sid))
                        throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
        }
        else
@@ -524,7 +402,6 @@ void ServerConfig::Fill()
        HideKillsServer = security->getString("hidekills");
        RestrictBannedUsers = security->getBool("restrictbannedusers", true);
        GenericOper = security->getBool("genericoper");
-       NoUserDns = ConfValue("performance")->getBool("nouserdns");
        SyntaxHints = options->getBool("syntaxhints");
        CycleHosts = options->getBool("cyclehosts");
        CycleHostsFromUser = options->getBool("cyclehostsfromuser");
@@ -533,9 +410,6 @@ void ServerConfig::Fill()
        MaxTargets = security->getInt("maxtargets", 20);
        DefaultModes = options->getString("defaultmodes", "nt");
        PID = ConfValue("pid")->getString("file");
-       WhoWasGroupSize = ConfValue("whowas")->getInt("groupsize");
-       WhoWasMaxGroups = ConfValue("whowas")->getInt("maxgroups");
-       WhoWasMaxKeep = ServerInstance->Duration(ConfValue("whowas")->getString("maxkeep"));
        MaxChans = ConfValue("channels")->getInt("users", 20);
        OperMaxChans = ConfValue("channels")->getInt("opers", 60);
        c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone", 32);
@@ -551,18 +425,12 @@ void ServerConfig::Fill()
        Limits.MaxAway = ConfValue("limits")->getInt("maxaway", 200);
        InvBypassModes = options->getBool("invitebypassmodes", true);
        NoSnoticeStack = options->getBool("nosnoticestack", false);
-       WelcomeNotice = options->getBool("welcomenotice", true);
 
        range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), "<performance:softlimit>");
        if (ConfValue("performance")->getBool("limitsomaxconn", true))
                range(MaxConn, 0, SOMAXCONN, SOMAXCONN, "<performance:somaxconn>");
        range(MaxTargets, 1, 31, 20, "<security:maxtargets>");
        range(NetBufferSize, 1024, 65534, 10240, "<performance:netbuffersize>");
-       range(WhoWasGroupSize, 0, 10000, 10, "<whowas:groupsize>");
-       range(WhoWasMaxGroups, 0, 1000000, 10240, "<whowas:maxgroups>");
-       range(WhoWasMaxKeep, 3600, INT_MAX, 3600, "<whowas:maxkeep>");
-
-       ValidIP(DNSServer, "<dns:server>");
 
        std::string defbind = options->getString("defaultbind");
        if (assign(defbind) == "ipv4")
@@ -592,16 +460,6 @@ void ServerConfig::Fill()
                ulines[assign(server)] = tag->getBool("silent");
        }
 
-       tags = ConfTags("banlist");
-       for(ConfigIter i = tags.first; i != tags.second; ++i)
-       {
-               ConfigTag* tag = i->second;
-               std::string chan;
-               if (!tag->readString("chan", chan))
-                       throw CoreException("<banlist> tag missing chan at " + tag->getTagLocation());
-               maxbans[chan] = tag->getInt("limit");
-       }
-
        ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
        ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
        ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
@@ -667,11 +525,6 @@ void ServerConfig::Read()
                valid = false;
                errstr << err.GetReason();
        }
-       if (valid)
-       {
-               DNSServer = ConfValue("dns")->getString("server");
-               FindDNS(DNSServer);
-       }
 }
 
 void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
@@ -690,16 +543,26 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
        /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
        try
        {
-               for (int Index = 0; Index * sizeof(Deprecated) < sizeof(ChangedConfig); Index++)
+               for (int index = 0; index * sizeof(DeprecatedConfig) < sizeof(ChangedConfig); index++)
                {
-                       std::string dummy;
-                       ConfigTagList tags = ConfTags(ChangedConfig[Index].tag);
+                       std::string value;
+                       ConfigTagList tags = ConfTags(ChangedConfig[index].tag);
                        for(ConfigIter i = tags.first; i != tags.second; ++i)
                        {
-                               if (i->second->readString(ChangedConfig[Index].value, dummy, true))
-                                       errstr << "Your configuration contains a deprecated value: <"
-                                               << ChangedConfig[Index].tag << ":" << ChangedConfig[Index].value << "> - " << ChangedConfig[Index].reason
-                                               << " (at " << i->second->getTagLocation() << ")\n";
+                               if (i->second->readString(ChangedConfig[index].key, value, true)
+                                       && (ChangedConfig[index].value.empty() || value == ChangedConfig[index].value))
+                               {
+                                       errstr << "Your configuration contains a deprecated value: <"  << ChangedConfig[index].tag;
+                                       if (ChangedConfig[index].value.empty())
+                                       {
+                                               errstr << ':' << ChangedConfig[index].key;
+                                       }
+                                       else
+                                       {
+                                               errstr << ' ' << ChangedConfig[index].key << "=\"" << ChangedConfig[index].value << "\"";
+                                       }
+                                       errstr << "> - " << ChangedConfig[index].reason << " (at " << i->second->getTagLocation() << ")\n";
+                               }
                        }
                }
 
@@ -728,14 +591,14 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
                ServerInstance->BindPorts(pl);
                if (pl.size())
                {
-                       errstr << "Not all your client ports could be bound.\nThe following port(s) failed to bind:\n";
+                       errstr << "Not all your client ports could be bound." << std::endl
+                               << "The following port(s) failed to bind:" << std::endl;
 
                        int j = 1;
                        for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
                        {
-                               char buf[MAXBUF];
-                               snprintf(buf, MAXBUF, "%d.   Address: %s   Reason: %s\n", j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
-                               errstr << buf;
+                               errstr << j << ".\tAddress: " << (i->first.empty() ? "<all>" : i->first.c_str()) << "\tReason: "
+                                       << i->second << std::endl;
                        }
                }
        }
@@ -743,7 +606,7 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
        User* user = useruid.empty() ? NULL : ServerInstance->FindNick(useruid);
 
        if (!valid)
-               ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file:");
+               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "There were errors in your configuration file:");
 
        while (errstr.good())
        {
@@ -807,10 +670,6 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
 
 void ServerConfig::ApplyModules(User* user)
 {
-       Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
-       if (whowas)
-               WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send();
-
        const std::vector<std::string> v = ServerInstance->Modules->GetAllModuleNames(0);
        std::vector<std::string> added_modules;
        std::set<std::string> removed_modules(v.begin(), v.end());
@@ -889,7 +748,7 @@ ConfigTag* ServerConfig::ConfValue(const std::string &tag)
        ConfigTag* rv = found.first->second;
        found.first++;
        if (found.first != found.second)
-               ServerInstance->Logs->Log("CONFIG",DEFAULT, "Multiple <" + tag + "> tags found; only first will be used "
+               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Multiple <" + tag + "> tags found; only first will be used "
                        "(first at " + rv->getTagLocation() + "; second at " + found.first->second->getTagLocation() + ")");
        return rv;
 }
@@ -925,11 +784,6 @@ const char* ServerConfig::CleanFilename(const char* name)
        return (p != name ? ++p : p);
 }
 
-const std::string& ServerConfig::GetSID()
-{
-       return sid;
-}
-
 void ConfigReaderThread::Run()
 {
        Config->Read();
@@ -939,7 +793,7 @@ void ConfigReaderThread::Run()
 void ConfigReaderThread::Finish()
 {
        ServerConfig* old = ServerInstance->Config;
-       ServerInstance->Logs->Log("CONFIG",DEBUG,"Switching to new configuration...");
+       ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Switching to new configuration...");
        ServerInstance->Config = this->Config;
        Config->Apply(old, TheUserUID);
 
@@ -953,12 +807,12 @@ void ConfigReaderThread::Finish()
                 */
                ServerInstance->XLines->CheckELines();
                ServerInstance->XLines->ApplyLines();
-               ServerInstance->Res->Rehash();
-               ServerInstance->ResetMaxBans();
+               ModeReference ban(NULL, "ban");
+               static_cast<ListModeBase*>(*ban)->DoRehash();
                Config->ApplyDisabledCommands(Config->DisabledCommands);
                User* user = ServerInstance->FindNick(TheUserUID);
                FOREACH_MOD(I_OnRehash, OnRehash(user));
-               ServerInstance->BuildISupport();
+               ServerInstance->ISupport.Build();
 
                ServerInstance->Logs->CloseLogs();
                ServerInstance->Logs->OpenFileLogs();
index 956ed34940f888b5a47d441c8eb914550648ec04..5cbe3aef3575bd3d27e23098b8a175a06056dc5a 100644 (file)
@@ -46,14 +46,14 @@ void CullList::Apply()
                classbase* c = list[i];
                if (gone.insert(c).second)
                {
-                       ServerInstance->Logs->Log("CULLLIST", DEBUG, "Deleting %s @%p", typeid(*c).name(),
+                       ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "Deleting %s @%p", typeid(*c).name(),
                                (void*)c);
                        c->cull();
                        queue.push_back(c);
                }
                else
                {
-                       ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Object @%p culled twice!",
+                       ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "WARNING: Object @%p culled twice!",
                                (void*)c);
                }
        }
@@ -65,7 +65,7 @@ void CullList::Apply()
        }
        if (list.size())
        {
-               ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Objects added to cull list in a destructor");
+               ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "WARNING: Objects added to cull list in a destructor");
                Apply();
        }
 }
diff --git a/src/dns.cpp b/src/dns.cpp
deleted file mode 100644 (file)
index 63bde0e..0000000
+++ /dev/null
@@ -1,1110 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2012 William Pitcock <nenolod@dereferenced.org>
- *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2006, 2009 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
- *   Copyright (C) 2005-2007 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* $Core */
-
-/*
-dns.cpp - Nonblocking DNS functions.
-Very very loosely based on the firedns library,
-Copyright (C) 2002 Ian Gulliver. This file is no
-longer anything like firedns, there are many major
-differences between this code and the original.
-Please do not assume that firedns works like this,
-looks like this, walks like this or tastes like this.
-*/
-
-#ifndef _WIN32
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#else
-#include "inspircd_win32wrapper.h"
-#endif
-
-#include "inspircd.h"
-#include "socketengine.h"
-#include "configreader.h"
-#include "socket.h"
-
-#define DN_COMP_BITMASK        0xC000          /* highest 6 bits in a DN label header */
-
-/** Masks to mask off the responses we get from the DNSRequest methods
- */
-enum QueryInfo
-{
-       ERROR_MASK      = 0x10000       /* Result is an error */
-};
-
-/** Flags which can be ORed into a request or reply for different meanings
- */
-enum QueryFlags
-{
-       FLAGS_MASK_RD           = 0x01, /* Recursive */
-       FLAGS_MASK_TC           = 0x02,
-       FLAGS_MASK_AA           = 0x04, /* Authoritative */
-       FLAGS_MASK_OPCODE       = 0x78,
-       FLAGS_MASK_QR           = 0x80,
-       FLAGS_MASK_RCODE        = 0x0F, /* Request */
-       FLAGS_MASK_Z            = 0x70,
-       FLAGS_MASK_RA           = 0x80
-};
-
-
-/** Represents a dns resource record (rr)
- */
-struct ResourceRecord
-{
-       QueryType       type;           /* Record type */
-       unsigned int    rr_class;       /* Record class */
-       unsigned long   ttl;            /* Time to live */
-       unsigned int    rdlength;       /* Record length */
-};
-
-/** Represents a dns request/reply header, and its payload as opaque data.
- */
-class DNSHeader
-{
- public:
-       unsigned char   id[2];          /* Request id */
-       unsigned int    flags1;         /* Flags */
-       unsigned int    flags2;         /* Flags */
-       unsigned int    qdcount;
-       unsigned int    ancount;        /* Answer count */
-       unsigned int    nscount;        /* Nameserver count */
-       unsigned int    arcount;
-       unsigned char   payload[512];   /* Packet payload */
-};
-
-class DNSRequest
-{
- public:
-       unsigned char   id[2];          /* Request id */
-       unsigned char*  res;            /* Result processing buffer */
-       unsigned int    rr_class;       /* Request class */
-       QueryType       type;           /* Request type */
-       DNS*            dnsobj;         /* DNS caller (where we get our FD from) */
-       unsigned long   ttl;            /* Time to live */
-       std::string     orig;           /* Original requested name/ip */
-
-       DNSRequest(DNS* dns, int id, const std::string &original);
-       ~DNSRequest();
-       DNSInfo ResultIsReady(DNSHeader &h, unsigned length);
-       int SendRequests(const DNSHeader *header, const int length, QueryType qt);
-};
-
-class CacheTimer : public Timer
-{
- private:
-       DNS* dns;
- public:
-       CacheTimer(DNS* thisdns)
-               : Timer(3600, ServerInstance->Time(), true), dns(thisdns) { }
-
-       virtual void Tick(time_t)
-       {
-               dns->PruneCache();
-       }
-};
-
-class RequestTimeout : public Timer
-{
-       DNSRequest* watch;
-       int watchid;
- public:
-       RequestTimeout(unsigned long n, DNSRequest* watching, int id) : Timer(n, ServerInstance->Time()), watch(watching), watchid(id)
-       {
-       }
-       ~RequestTimeout()
-       {
-               if (ServerInstance->Res)
-                       Tick(0);
-       }
-
-       void Tick(time_t)
-       {
-               if (ServerInstance->Res->requests[watchid] == watch)
-               {
-                       /* Still exists, whack it */
-                       if (ServerInstance->Res->Classes[watchid])
-                       {
-                               ServerInstance->Res->Classes[watchid]->OnError(RESOLVER_TIMEOUT, "Request timed out");
-                               delete ServerInstance->Res->Classes[watchid];
-                               ServerInstance->Res->Classes[watchid] = NULL;
-                       }
-                       ServerInstance->Res->requests[watchid] = NULL;
-                       delete watch;
-               }
-       }
-};
-
-CachedQuery::CachedQuery(const std::string &res, unsigned int ttl) : data(res)
-{
-       expires = ServerInstance->Time() + ttl;
-}
-
-int CachedQuery::CalcTTLRemaining()
-{
-       int n = expires - ServerInstance->Time();
-       return (n < 0 ? 0 : n);
-}
-
-/* Allocate the processing buffer */
-DNSRequest::DNSRequest(DNS* dns, int rid, const std::string &original) : dnsobj(dns)
-{
-       /* hardening against overflow here:  make our work buffer twice the theoretical
-        * maximum size so that hostile input doesn't screw us over.
-        */
-       res = new unsigned char[sizeof(DNSHeader) * 2];
-       *res = 0;
-       orig = original;
-       RequestTimeout* RT = new RequestTimeout(ServerInstance->Config->dns_timeout ? ServerInstance->Config->dns_timeout : 5, this, rid);
-       ServerInstance->Timers->AddTimer(RT); /* The timer manager frees this */
-}
-
-/* Deallocate the processing buffer */
-DNSRequest::~DNSRequest()
-{
-       delete[] res;
-}
-
-/** Fill a ResourceRecord class based on raw data input */
-inline void DNS::FillResourceRecord(ResourceRecord* rr, const unsigned char *input)
-{
-       rr->type = (QueryType)((input[0] << 8) + input[1]);
-       rr->rr_class = (input[2] << 8) + input[3];
-       rr->ttl = (input[4] << 24) + (input[5] << 16) + (input[6] << 8) + input[7];
-       rr->rdlength = (input[8] << 8) + input[9];
-}
-
-/** Fill a DNSHeader class based on raw data input of a given length */
-inline void DNS::FillHeader(DNSHeader *header, const unsigned char *input, const int length)
-{
-       header->id[0] = input[0];
-       header->id[1] = input[1];
-       header->flags1 = input[2];
-       header->flags2 = input[3];
-       header->qdcount = (input[4] << 8) + input[5];
-       header->ancount = (input[6] << 8) + input[7];
-       header->nscount = (input[8] << 8) + input[9];
-       header->arcount = (input[10] << 8) + input[11];
-       memcpy(header->payload,&input[12],length);
-}
-
-/** Empty a DNSHeader class out into raw data, ready for transmission */
-inline void DNS::EmptyHeader(unsigned char *output, const DNSHeader *header, const int length)
-{
-       output[0] = header->id[0];
-       output[1] = header->id[1];
-       output[2] = header->flags1;
-       output[3] = header->flags2;
-       output[4] = header->qdcount >> 8;
-       output[5] = header->qdcount & 0xFF;
-       output[6] = header->ancount >> 8;
-       output[7] = header->ancount & 0xFF;
-       output[8] = header->nscount >> 8;
-       output[9] = header->nscount & 0xFF;
-       output[10] = header->arcount >> 8;
-       output[11] = header->arcount & 0xFF;
-       memcpy(&output[12],header->payload,length);
-}
-
-/** Send requests we have previously built down the UDP socket */
-int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryType qt)
-{
-       ServerInstance->Logs->Log("RESOLVER", DEBUG,"DNSRequest::SendRequests");
-
-       unsigned char payload[sizeof(DNSHeader)];
-
-       this->rr_class = 1;
-       this->type = qt;
-
-       DNS::EmptyHeader(payload,header,length);
-
-       if (ServerInstance->SE->SendTo(dnsobj, payload, length + 12, 0, &(dnsobj->myserver.sa), sa_size(dnsobj->myserver)) != length+12)
-               return -1;
-
-       ServerInstance->Logs->Log("RESOLVER",DEBUG,"Sent OK");
-       return 0;
-}
-
-/** Add a query with a predefined header, and allocate an ID for it. */
-DNSRequest* DNS::AddQuery(DNSHeader *header, int &id, const char* original)
-{
-       /* Is the DNS connection down? */
-       if (this->GetFd() == -1)
-               return NULL;
-
-       /* Create an id */
-       unsigned int tries = 0;
-       do {
-               id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID);
-               if (++tries == DNS::MAX_REQUEST_ID*5)
-               {
-                       // If we couldn't find an empty slot this many times, do a sequential scan as a last
-                       // resort. If an empty slot is found that way, go on, otherwise throw an exception
-                       id = -1;
-                       for (int i = 0; i < DNS::MAX_REQUEST_ID; i++)
-                       {
-                               if (!requests[i])
-                               {
-                                       id = i;
-                                       break;
-                               }
-                       }
-
-                       if (id == -1)
-                               throw ModuleException("DNS: All ids are in use");
-
-                       break;
-               }
-       } while (requests[id]);
-
-       DNSRequest* req = new DNSRequest(this, id, original);
-
-       header->id[0] = req->id[0] = id >> 8;
-       header->id[1] = req->id[1] = id & 0xFF;
-       header->flags1 = FLAGS_MASK_RD;
-       header->flags2 = 0;
-       header->qdcount = 1;
-       header->ancount = 0;
-       header->nscount = 0;
-       header->arcount = 0;
-
-       /* At this point we already know the id doesnt exist,
-        * so there needs to be no second check for the ::end()
-        */
-       requests[id] = req;
-
-       /* According to the C++ spec, new never returns NULL. */
-       return req;
-}
-
-int DNS::ClearCache()
-{
-       /* This ensures the buckets are reset to sane levels */
-       int rv = this->cache->size();
-       delete this->cache;
-       this->cache = new dnscache();
-       return rv;
-}
-
-int DNS::PruneCache()
-{
-       int n = 0;
-       dnscache* newcache = new dnscache();
-       for (dnscache::iterator i = this->cache->begin(); i != this->cache->end(); i++)
-               /* Dont include expired items (theres no point) */
-               if (i->second.CalcTTLRemaining())
-                       newcache->insert(*i);
-               else
-                       n++;
-
-       delete this->cache;
-       this->cache = newcache;
-       return n;
-}
-
-void DNS::Rehash()
-{
-       if (this->GetFd() > -1)
-       {
-               ServerInstance->SE->DelFd(this);
-               ServerInstance->SE->Shutdown(this, 2);
-               ServerInstance->SE->Close(this);
-               this->SetFd(-1);
-
-               /* Rehash the cache */
-               this->PruneCache();
-       }
-       else
-       {
-               /* Create initial dns cache */
-               this->cache = new dnscache();
-       }
-
-       irc::sockets::aptosa(ServerInstance->Config->DNSServer, DNS::QUERY_PORT, myserver);
-
-       /* Initialize mastersocket */
-       int s = socket(myserver.sa.sa_family, SOCK_DGRAM, 0);
-       this->SetFd(s);
-
-       /* Have we got a socket and is it nonblocking? */
-       if (this->GetFd() != -1)
-       {
-               ServerInstance->SE->SetReuse(s);
-               ServerInstance->SE->NonBlocking(s);
-               irc::sockets::sockaddrs bindto;
-               memset(&bindto, 0, sizeof(bindto));
-               bindto.sa.sa_family = myserver.sa.sa_family;
-               if (ServerInstance->SE->Bind(this->GetFd(), bindto) < 0)
-               {
-                       /* Failed to bind */
-                       ServerInstance->Logs->Log("RESOLVER",SPARSE,"Error binding dns socket - hostnames will NOT resolve");
-                       ServerInstance->SE->Shutdown(this, 2);
-                       ServerInstance->SE->Close(this);
-                       this->SetFd(-1);
-               }
-               else if (!ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE))
-               {
-                       ServerInstance->Logs->Log("RESOLVER",SPARSE,"Internal error starting DNS - hostnames will NOT resolve.");
-                       ServerInstance->SE->Shutdown(this, 2);
-                       ServerInstance->SE->Close(this);
-                       this->SetFd(-1);
-               }
-       }
-       else
-       {
-               ServerInstance->Logs->Log("RESOLVER",SPARSE,"Error creating DNS socket - hostnames will NOT resolve");
-       }
-}
-
-/** Initialise the DNS UDP socket so that we can send requests */
-DNS::DNS()
-{
-       ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::DNS");
-       /* Clear the Resolver class table */
-       memset(Classes,0,sizeof(Classes));
-
-       /* Clear the requests class table */
-       memset(requests,0,sizeof(requests));
-
-       /* DNS::Rehash() sets this to a valid ptr
-        */
-       this->cache = NULL;
-
-       /* Again, DNS::Rehash() sets this to a
-        * valid value
-        */
-       this->SetFd(-1);
-
-       /* Actually read the settings
-        */
-       this->Rehash();
-
-       this->PruneTimer = new CacheTimer(this);
-
-       ServerInstance->Timers->AddTimer(this->PruneTimer);
-}
-
-/** Build a payload to be placed after the header, based upon input data, a resource type, a class and a pointer to a buffer */
-int DNS::MakePayload(const char * const name, const QueryType rr, const unsigned short rr_class, unsigned char * const payload)
-{
-       short payloadpos = 0;
-       const char* tempchr, *tempchr2 = name;
-       unsigned short length;
-
-       /* split name up into labels, create query */
-       while ((tempchr = strchr(tempchr2,'.')) != NULL)
-       {
-               length = tempchr - tempchr2;
-               if (payloadpos + length + 1 > 507)
-                       return -1;
-               payload[payloadpos++] = length;
-               memcpy(&payload[payloadpos],tempchr2,length);
-               payloadpos += length;
-               tempchr2 = &tempchr[1];
-       }
-       length = strlen(tempchr2);
-       if (length)
-       {
-               if (payloadpos + length + 2 > 507)
-                       return -1;
-               payload[payloadpos++] = length;
-               memcpy(&payload[payloadpos],tempchr2,length);
-               payloadpos += length;
-               payload[payloadpos++] = 0;
-       }
-       if (payloadpos > 508)
-               return -1;
-       length = htons(rr);
-       memcpy(&payload[payloadpos],&length,2);
-       length = htons(rr_class);
-       memcpy(&payload[payloadpos + 2],&length,2);
-       return payloadpos + 4;
-}
-
-/** Start lookup of an hostname to an IP address */
-int DNS::GetIP(const char *name)
-{
-       DNSHeader h;
-       int id;
-       int length;
-
-       if ((length = this->MakePayload(name, DNS_QUERY_A, 1, (unsigned char*)&h.payload)) == -1)
-               return -1;
-
-       DNSRequest* req = this->AddQuery(&h, id, name);
-
-       if ((!req) || (req->SendRequests(&h, length, DNS_QUERY_A) == -1))
-               return -1;
-
-       return id;
-}
-
-/** Start lookup of an hostname to an IPv6 address */
-int DNS::GetIP6(const char *name)
-{
-       DNSHeader h;
-       int id;
-       int length;
-
-       if ((length = this->MakePayload(name, DNS_QUERY_AAAA, 1, (unsigned char*)&h.payload)) == -1)
-               return -1;
-
-       DNSRequest* req = this->AddQuery(&h, id, name);
-
-       if ((!req) || (req->SendRequests(&h, length, DNS_QUERY_AAAA) == -1))
-               return -1;
-
-       return id;
-}
-
-/** Start lookup of a cname to another name */
-int DNS::GetCName(const char *alias)
-{
-       DNSHeader h;
-       int id;
-       int length;
-
-       if ((length = this->MakePayload(alias, DNS_QUERY_CNAME, 1, (unsigned char*)&h.payload)) == -1)
-               return -1;
-
-       DNSRequest* req = this->AddQuery(&h, id, alias);
-
-       if ((!req) || (req->SendRequests(&h, length, DNS_QUERY_CNAME) == -1))
-               return -1;
-
-       return id;
-}
-
-/** Start lookup of an IP address to a hostname */
-int DNS::GetNameForce(const char *ip, ForceProtocol fp)
-{
-       char query[128];
-       DNSHeader h;
-       int id;
-       int length;
-
-       if (fp == PROTOCOL_IPV6)
-       {
-               in6_addr i;
-               if (inet_pton(AF_INET6, ip, &i) > 0)
-               {
-                       DNS::MakeIP6Int(query, &i);
-               }
-               else
-               {
-                       ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce IPv6 bad format for '%s'", ip);
-                       /* Invalid IP address */
-                       return -1;
-               }
-       }
-       else
-       {
-               in_addr i;
-               if (inet_aton(ip, &i))
-               {
-                       unsigned char* c = (unsigned char*)&i.s_addr;
-                       sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]);
-               }
-               else
-               {
-                       ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce IPv4 bad format for '%s'", ip);
-                       /* Invalid IP address */
-                       return -1;
-               }
-       }
-
-       length = this->MakePayload(query, DNS_QUERY_PTR, 1, (unsigned char*)&h.payload);
-       if (length == -1)
-       {
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce can't query '%s' using '%s' because it's too long", ip, query);
-               return -1;
-       }
-
-       DNSRequest* req = this->AddQuery(&h, id, ip);
-
-       if (!req)
-       {
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce can't add query (resolver down?)");
-               return -1;
-       }
-
-       if (req->SendRequests(&h, length, DNS_QUERY_PTR) == -1)
-       {
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce can't send (firewall?)");
-               return -1;
-       }
-
-       return id;
-}
-
-/** Build an ipv6 reverse domain from an in6_addr
- */
-void DNS::MakeIP6Int(char* query, const in6_addr *ip)
-{
-       const char* hex = "0123456789abcdef";
-       for (int index = 31; index >= 0; index--) /* for() loop steps twice per byte */
-       {
-               if (index % 2)
-                       /* low nibble */
-                       *query++ = hex[ip->s6_addr[index / 2] & 0x0F];
-               else
-                       /* high nibble */
-                       *query++ = hex[(ip->s6_addr[index / 2] & 0xF0) >> 4];
-               *query++ = '.'; /* Seperator */
-       }
-       strcpy(query,"ip6.arpa"); /* Suffix the string */
-}
-
-/** Return the next id which is ready, and the result attached to it */
-DNSResult DNS::GetResult()
-{
-       /* Fetch dns query response and decide where it belongs */
-       DNSHeader header;
-       DNSRequest *req;
-       unsigned char buffer[sizeof(DNSHeader)];
-       irc::sockets::sockaddrs from;
-       memset(&from, 0, sizeof(from));
-       socklen_t x = sizeof(from);
-
-       int length = ServerInstance->SE->RecvFrom(this, (char*)buffer, sizeof(DNSHeader), 0, &from.sa, &x);
-
-       /* Did we get the whole header? */
-       if (length < 12)
-       {
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"GetResult didn't get a full packet (len=%d)", length);
-               /* Nope - something screwed up. */
-               return DNSResult(-1,"",0,"");
-       }
-
-       /* Check wether the reply came from a different DNS
-        * server to the one we sent it to, or the source-port
-        * is not 53.
-        * A user could in theory still spoof dns packets anyway
-        * but this is less trivial than just sending garbage
-        * to the server, which is possible without this check.
-        *
-        * -- Thanks jilles for pointing this one out.
-        */
-       if (from != myserver)
-       {
-               std::string server1 = from.str();
-               std::string server2 = myserver.str();
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"Got a result from the wrong server! Bad NAT or DNS forging attempt? '%s' != '%s'",
-                       server1.c_str(), server2.c_str());
-               return DNSResult(-1,"",0,"");
-       }
-
-       /* Put the read header info into a header class */
-       DNS::FillHeader(&header,buffer,length - 12);
-
-       /* Get the id of this request.
-        * Its a 16 bit value stored in two char's,
-        * so we use logic shifts to create the value.
-        */
-       unsigned long this_id = header.id[1] + (header.id[0] << 8);
-
-       /* Do we have a pending request matching this id? */
-       if (!requests[this_id])
-       {
-               /* Somehow we got a DNS response for a request we never made... */
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"Hmm, got a result that we didn't ask for (id=%lx). Ignoring.", this_id);
-               return DNSResult(-1,"",0,"");
-       }
-       else
-       {
-               /* Remove the query from the list of pending queries */
-               req = requests[this_id];
-               requests[this_id] = NULL;
-       }
-
-       /* Inform the DNSRequest class that it has a result to be read.
-        * When its finished it will return a DNSInfo which is a pair of
-        * unsigned char* resource record data, and an error message.
-        */
-       DNSInfo data = req->ResultIsReady(header, length);
-       std::string resultstr;
-
-       /* Check if we got a result, if we didnt, its an error */
-       if (data.first == NULL)
-       {
-               /* An error.
-                * Mask the ID with the value of ERROR_MASK, so that
-                * the dns_deal_with_classes() function knows that its
-                * an error response and needs to be treated uniquely.
-                * Put the error message in the second field.
-                */
-               std::string ro = req->orig;
-               delete req;
-               return DNSResult(this_id | ERROR_MASK, data.second, 0, ro);
-       }
-       else
-       {
-               unsigned long ttl = req->ttl;
-               char formatted[128];
-
-               /* Forward lookups come back as binary data. We must format them into ascii */
-               switch (req->type)
-               {
-                       case DNS_QUERY_A:
-                               snprintf(formatted,16,"%u.%u.%u.%u",data.first[0],data.first[1],data.first[2],data.first[3]);
-                               resultstr = formatted;
-                       break;
-
-                       case DNS_QUERY_AAAA:
-                       {
-                               inet_ntop(AF_INET6, data.first, formatted, sizeof(formatted));
-                               char* c = strstr(formatted,":0:");
-                               if (c != NULL)
-                               {
-                                       memmove(c+1,c+2,strlen(c+2) + 1);
-                                       c += 2;
-                                       while (memcmp(c,"0:",2) == 0)
-                                               memmove(c,c+2,strlen(c+2) + 1);
-                                       if (memcmp(c,"0",2) == 0)
-                                               *c = 0;
-                                       if (memcmp(formatted,"0::",3) == 0)
-                                               memmove(formatted,formatted + 1, strlen(formatted + 1) + 1);
-                               }
-                               resultstr = formatted;
-
-                               /* Special case. Sending ::1 around between servers
-                                * and to clients is dangerous, because the : on the
-                                * start makes the client or server interpret the IP
-                                * as the last parameter on the line with a value ":1".
-                                */
-                               if (*formatted == ':')
-                                       resultstr.insert(0, "0");
-                       }
-                       break;
-
-                       case DNS_QUERY_CNAME:
-                               /* Identical handling to PTR */
-
-                       case DNS_QUERY_PTR:
-                               /* Reverse lookups just come back as char* */
-                               resultstr = std::string((const char*)data.first);
-                       break;
-
-                       default:
-                       break;
-               }
-
-               /* Build the reply with the id and hostname/ip in it */
-               std::string ro = req->orig;
-               delete req;
-               return DNSResult(this_id,resultstr,ttl,ro);
-       }
-}
-
-/** A result is ready, process it */
-DNSInfo DNSRequest::ResultIsReady(DNSHeader &header, unsigned length)
-{
-       unsigned i = 0, o;
-       int q = 0;
-       int curanswer;
-       ResourceRecord rr;
-       unsigned short ptr;
-
-       /* This is just to keep _FORTIFY_SOURCE happy */
-       rr.type = DNS_QUERY_NONE;
-       rr.rdlength = 0;
-       rr.ttl = 1;     /* GCC is a whiney bastard -- see the XXX below. */
-       rr.rr_class = 0; /* Same for VC++ */
-
-       if (!(header.flags1 & FLAGS_MASK_QR))
-               return std::make_pair((unsigned char*)NULL,"Not a query result");
-
-       if (header.flags1 & FLAGS_MASK_OPCODE)
-               return std::make_pair((unsigned char*)NULL,"Unexpected value in DNS reply packet");
-
-       if (header.flags2 & FLAGS_MASK_RCODE)
-               return std::make_pair((unsigned char*)NULL,"Domain name not found");
-
-       if (header.ancount < 1)
-               return std::make_pair((unsigned char*)NULL,"No resource records returned");
-
-       /* Subtract the length of the header from the length of the packet */
-       length -= 12;
-
-       while ((unsigned int)q < header.qdcount && i < length)
-       {
-               if (header.payload[i] > 63)
-               {
-                       i += 6;
-                       q++;
-               }
-               else
-               {
-                       if (header.payload[i] == 0)
-                       {
-                               q++;
-                               i += 5;
-                       }
-                       else i += header.payload[i] + 1;
-               }
-       }
-       curanswer = 0;
-       while ((unsigned)curanswer < header.ancount)
-       {
-               q = 0;
-               while (q == 0 && i < length)
-               {
-                       if (header.payload[i] > 63)
-                       {
-                               i += 2;
-                               q = 1;
-                       }
-                       else
-                       {
-                               if (header.payload[i] == 0)
-                               {
-                                       i++;
-                                       q = 1;
-                               }
-                               else i += header.payload[i] + 1; /* skip length and label */
-                       }
-               }
-               if (static_cast<int>(length - i) < 10)
-                       return std::make_pair((unsigned char*)NULL,"Incorrectly sized DNS reply");
-
-               /* XXX: We actually initialise 'rr' here including its ttl field */
-               DNS::FillResourceRecord(&rr,&header.payload[i]);
-
-               i += 10;
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"Resolver: rr.type is %d and this.type is %d rr.class %d this.class %d", rr.type, this->type, rr.rr_class, this->rr_class);
-               if (rr.type != this->type)
-               {
-                       curanswer++;
-                       i += rr.rdlength;
-                       continue;
-               }
-               if (rr.rr_class != this->rr_class)
-               {
-                       curanswer++;
-                       i += rr.rdlength;
-                       continue;
-               }
-               break;
-       }
-       if ((unsigned int)curanswer == header.ancount)
-               return std::make_pair((unsigned char*)NULL,"No A, AAAA or PTR type answers (" + ConvToStr(header.ancount) + " answers)");
-
-       if (i + rr.rdlength > (unsigned int)length)
-               return std::make_pair((unsigned char*)NULL,"Resource record larger than stated");
-
-       if (rr.rdlength > 1023)
-               return std::make_pair((unsigned char*)NULL,"Resource record too large");
-
-       this->ttl = rr.ttl;
-
-       switch (rr.type)
-       {
-               /*
-                * CNAME and PTR are compressed.  We need to decompress them.
-                */
-               case DNS_QUERY_CNAME:
-               case DNS_QUERY_PTR:
-               {
-                       unsigned short lowest_pos = length;
-                       o = 0;
-                       q = 0;
-                       while (q == 0 && i < length && o + 256 < 1023)
-                       {
-                               /* DN label found (byte over 63) */
-                               if (header.payload[i] > 63)
-                               {
-                                       memcpy(&ptr,&header.payload[i],2);
-
-                                       i = ntohs(ptr);
-
-                                       /* check that highest two bits are set. if not, we've been had */
-                                       if ((i & DN_COMP_BITMASK) != DN_COMP_BITMASK)
-                                               return std::make_pair((unsigned char *) NULL, "DN label decompression header is bogus");
-
-                                       /* mask away the two highest bits. */
-                                       i &= ~DN_COMP_BITMASK;
-
-                                       /* and decrease length by 12 bytes. */
-                                       i -= 12;
-
-                                       if (i >= lowest_pos)
-                                               return std::make_pair((unsigned char *) NULL, "Invalid decompression pointer");
-                                       lowest_pos = i;
-                               }
-                               else
-                               {
-                                       if (header.payload[i] == 0)
-                                       {
-                                               q = 1;
-                                       }
-                                       else
-                                       {
-                                               res[o] = 0;
-                                               if (o != 0)
-                                                       res[o++] = '.';
-
-                                               if (o + header.payload[i] > sizeof(DNSHeader))
-                                                       return std::make_pair((unsigned char *) NULL, "DN label decompression is impossible -- malformed/hostile packet?");
-
-                                               memcpy(&res[o], &header.payload[i + 1], header.payload[i]);
-                                               o += header.payload[i];
-                                               i += header.payload[i] + 1;
-                                       }
-                               }
-                       }
-                       res[o] = 0;
-               }
-               break;
-               case DNS_QUERY_AAAA:
-                       if (rr.rdlength != sizeof(struct in6_addr))
-                               return std::make_pair((unsigned char *) NULL, "rr.rdlength is larger than 16 bytes for an ipv6 entry -- malformed/hostile packet?");
-
-                       memcpy(res,&header.payload[i],rr.rdlength);
-                       res[rr.rdlength] = 0;
-               break;
-               case DNS_QUERY_A:
-                       if (rr.rdlength != sizeof(struct in_addr))
-                               return std::make_pair((unsigned char *) NULL, "rr.rdlength is larger than 4 bytes for an ipv4 entry -- malformed/hostile packet?");
-
-                       memcpy(res,&header.payload[i],rr.rdlength);
-                       res[rr.rdlength] = 0;
-               break;
-               default:
-                       return std::make_pair((unsigned char *) NULL, "don't know how to handle undefined type (" + ConvToStr(rr.type) + ") -- rejecting");
-               break;
-       }
-       return std::make_pair(res,"No error");
-}
-
-/** Close the master socket */
-DNS::~DNS()
-{
-       ServerInstance->SE->Shutdown(this, 2);
-       ServerInstance->SE->Close(this);
-       ServerInstance->Timers->DelTimer(this->PruneTimer);
-       if (cache)
-               delete cache;
-}
-
-CachedQuery* DNS::GetCache(const std::string &source)
-{
-       dnscache::iterator x = cache->find(source.c_str());
-       if (x != cache->end())
-               return &(x->second);
-       else
-               return NULL;
-}
-
-void DNS::DelCache(const std::string &source)
-{
-       cache->erase(source.c_str());
-}
-
-void Resolver::TriggerCachedResult()
-{
-       if (CQ)
-               OnLookupComplete(CQ->data, time_left, true);
-}
-
-/** High level abstraction of dns used by application at large */
-Resolver::Resolver(const std::string &source, QueryType qt, bool &cached, Module* creator) : Creator(creator), input(source), querytype(qt)
-{
-       ServerInstance->Logs->Log("RESOLVER",DEBUG,"Resolver::Resolver");
-       cached = false;
-
-       CQ = ServerInstance->Res->GetCache(source);
-       if (CQ)
-       {
-               time_left = CQ->CalcTTLRemaining();
-               if (!time_left)
-               {
-                       ServerInstance->Res->DelCache(source);
-               }
-               else
-               {
-                       cached = true;
-                       return;
-               }
-       }
-
-       switch (querytype)
-       {
-               case DNS_QUERY_A:
-                       this->myid = ServerInstance->Res->GetIP(source.c_str());
-               break;
-
-               case DNS_QUERY_PTR4:
-                       querytype = DNS_QUERY_PTR;
-                       this->myid = ServerInstance->Res->GetNameForce(source.c_str(), PROTOCOL_IPV4);
-               break;
-
-               case DNS_QUERY_PTR6:
-                       querytype = DNS_QUERY_PTR;
-                       this->myid = ServerInstance->Res->GetNameForce(source.c_str(), PROTOCOL_IPV6);
-               break;
-
-               case DNS_QUERY_AAAA:
-                       this->myid = ServerInstance->Res->GetIP6(source.c_str());
-               break;
-
-               case DNS_QUERY_CNAME:
-                       this->myid = ServerInstance->Res->GetCName(source.c_str());
-               break;
-
-               default:
-                       ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS request with unknown query type %d", querytype);
-                       this->myid = -1;
-               break;
-       }
-       if (this->myid == -1)
-       {
-               throw ModuleException("Resolver: Couldn't get an id to make a request");
-       }
-       else
-       {
-               ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS request id %d", this->myid);
-       }
-}
-
-/** Called when an error occurs */
-void Resolver::OnError(ResolverError, const std::string&)
-{
-       /* Nothing in here */
-}
-
-/** Destroy a resolver */
-Resolver::~Resolver()
-{
-       /* Nothing here (yet) either */
-}
-
-/** Get the request id associated with this class */
-int Resolver::GetId()
-{
-       return this->myid;
-}
-
-Module* Resolver::GetCreator()
-{
-       return this->Creator;
-}
-
-/** Process a socket read event */
-void DNS::HandleEvent(EventType, int)
-{
-       /* Fetch the id and result of the next available packet */
-       DNSResult res(0,"",0,"");
-       res.id = 0;
-       ServerInstance->Logs->Log("RESOLVER",DEBUG,"Handle DNS event");
-
-       res = this->GetResult();
-
-       ServerInstance->Logs->Log("RESOLVER",DEBUG,"Result id %d", res.id);
-
-       /* Is there a usable request id? */
-       if (res.id != -1)
-       {
-               /* Its an error reply */
-               if (res.id & ERROR_MASK)
-               {
-                       /* Mask off the error bit */
-                       res.id -= ERROR_MASK;
-                       /* Marshall the error to the correct class */
-                       if (Classes[res.id])
-                       {
-                               if (ServerInstance && ServerInstance->stats)
-                                       ServerInstance->stats->statsDnsBad++;
-                               Classes[res.id]->OnError(RESOLVER_NXDOMAIN, res.result);
-                               delete Classes[res.id];
-                               Classes[res.id] = NULL;
-                       }
-                       return;
-               }
-               else
-               {
-                       /* It is a non-error result, marshall the result to the correct class */
-                       if (Classes[res.id])
-                       {
-                               if (ServerInstance && ServerInstance->stats)
-                                       ServerInstance->stats->statsDnsGood++;
-
-                               if (!this->GetCache(res.original.c_str()))
-                                       this->cache->insert(std::make_pair(res.original.c_str(), CachedQuery(res.result, res.ttl)));
-
-                               Classes[res.id]->OnLookupComplete(res.result, res.ttl, false);
-                               delete Classes[res.id];
-                               Classes[res.id] = NULL;
-                       }
-               }
-
-               if (ServerInstance && ServerInstance->stats)
-                       ServerInstance->stats->statsDns++;
-       }
-}
-
-/** Add a derived Resolver to the working set */
-bool DNS::AddResolverClass(Resolver* r)
-{
-       ServerInstance->Logs->Log("RESOLVER",DEBUG,"AddResolverClass 0x%08lx", (unsigned long)r);
-       /* Check the pointers validity and the id's validity */
-       if ((r) && (r->GetId() > -1))
-       {
-               /* Check the slot isnt already occupied -
-                * This should NEVER happen unless we have
-                * a severely broken DNS server somewhere
-                */
-               if (!Classes[r->GetId()])
-               {
-                       /* Set up the pointer to the class */
-                       Classes[r->GetId()] = r;
-                       return true;
-               }
-       }
-
-       /* Pointer or id not valid, or duplicate id.
-        * Free the item and return
-        */
-       delete r;
-       return false;
-}
-
-void DNS::CleanResolvers(Module* module)
-{
-       for (int i = 0; i < MAX_REQUEST_ID; i++)
-       {
-               if (Classes[i])
-               {
-                       if (Classes[i]->GetCreator() == module)
-                       {
-                               Classes[i]->OnError(RESOLVER_FORCEUNLOAD, "Parent module is unloading");
-                               delete Classes[i];
-                               Classes[i] = NULL;
-                       }
-               }
-       }
-}
index 0575256d08c8261c8b7b905dc283e2cd9c0c6cf5..acb210ecbdd03c486757b546a45315904717e425 100644 (file)
@@ -26,8 +26,7 @@
 #include "socketengine.h"
 #include "filelogger.h"
 
-FileLogStream::FileLogStream(int loglevel, FileWriter *fw)
-       : LogStream(loglevel), f(fw)
+FileLogStream::FileLogStream(LogLevel loglevel, FileWriter *fw) : LogStream(loglevel), f(fw)
 {
        ServerInstance->Logs->AddLoggerRef(f);
 }
@@ -38,9 +37,9 @@ FileLogStream::~FileLogStream()
        ServerInstance->Logs->DelLoggerRef(f);
 }
 
-void FileLogStream::OnLog(int loglevel, const std::string &type, const std::string &text)
+void FileLogStream::OnLog(LogLevel loglevel, const std::string &type, const std::string &text)
 {
-       static char TIMESTR[26];
+       static std::string TIMESTR;
        static time_t LAST = 0;
 
        if (loglevel < this->loglvl)
@@ -53,11 +52,13 @@ void FileLogStream::OnLog(int loglevel, const std::string &type, const std::stri
                time_t local = ServerInstance->Time();
                struct tm *timeinfo = localtime(&local);
 
-               strlcpy(TIMESTR,asctime(timeinfo),26);
-               TIMESTR[24] = ':';
+               TIMESTR.assign(asctime(timeinfo), 24);
+               TIMESTR += ": ";
                LAST = ServerInstance->Time();
        }
 
-       std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
+       std::string out = TIMESTR;
+       out += text;
+       out += '\n';
        this->f->WriteLogLine(out);
 }
index 3fb7f84fbf0fde09d799a6091faeca177b4e39f9..06b3ce66970e8bfba9e5e99e7227f5702b90d18c 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "inspircd.h"
 #include "hashcomp.h"
-#include "hash_map.h"
 
 /******************************************************
  *
@@ -35,7 +34,7 @@
  * scene spend a lot of time debating (arguing) about
  * the best way to write hash functions to hash irc
  * nicknames, channels etc.
- * We are lucky as C++ developers as hash_map does
+ * We are lucky as C++ developers as unordered_map does
  * a lot of this for us. It does intellegent memory
  * requests, bucketing, search functions, insertion
  * and deletion etc. All we have to do is write some
  *
  ******************************************************/
 
-/** A mapping of uppercase to lowercase, including scandinavian
- * 'oddities' as specified by RFC1459, e.g. { -> [, and | -> \
- */
-unsigned const char rfc_case_insensitive_map[256] = {
-       0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,                                   /* 0-19 */
-       20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,                         /* 20-39 */
-       40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,                         /* 40-59 */
-       60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,             /* 60-79 */
-       112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 94, 95, 96, 97, 98, 99,           /* 80-99 */
-       100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,     /* 100-119 */
-       120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,     /* 120-139 */
-       140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,     /* 140-159 */
-       160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,     /* 160-179 */
-       180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,     /* 180-199 */
-       200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,     /* 200-219 */
-       220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,     /* 220-239 */
-       240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255                          /* 240-255 */
-};
 
-/** Case insensitive map, ASCII rules.
- * That is;
- * [ != {, but A == a.
+/**
+ * A case insensitive mapping of characters from upper case to lower case for
+ * the ASCII character set.
  */
 unsigned const char ascii_case_insensitive_map[256] = {
-        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,                                   /* 0-19 */
-        20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,                         /* 20-39 */
-        40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,                         /* 40-59 */
-        60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,             /* 60-79 */
-        112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,              /* 80-99 */
-        100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,     /* 100-119 */
-        120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,     /* 120-139 */
-        140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,     /* 140-159 */
-        160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,     /* 160-179 */
-        180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,     /* 180-199 */
-        200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,     /* 200-219 */
-        220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,     /* 220-239 */
-        240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255                          /* 240-255 */
+       0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   // 0-9
+       10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  // 10-19
+       20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  // 20-29
+       30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  // 30-39
+       40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  // 40-49
+       50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  // 50-59
+       60,  61,  62,  63,  64,  97,  98,  99,  100, 101, // 60-69
+       102, 103, 104, 105, 106, 107, 108, 109, 110, 111, // 70-79
+       112, 113, 114, 115, 116, 117, 118, 119, 120, 121, // 80-89
+       122, 91,  92,  93,  94,  95,  96,  97,  98,  99,  // 90-99
+       100, 101, 102, 103, 104, 105, 106, 107, 108, 109, // 100-109
+       110, 111, 112, 113, 114, 115, 116, 117, 118, 119, // 110-119
+       120, 121, 122, 123, 124, 125, 126, 127, 128, 129, // 120-129
+       130, 131, 132, 133, 134, 135, 136, 137, 138, 139, // 130-139
+       140, 141, 142, 143, 144, 145, 146, 147, 148, 149, // 140-149
+       150, 151, 152, 153, 154, 155, 156, 157, 158, 159, // 150-159
+       160, 161, 162, 163, 164, 165, 166, 167, 168, 169, // 160-169
+       170, 171, 172, 173, 174, 175, 176, 177, 178, 179, // 170-179
+       180, 181, 182, 183, 184, 185, 186, 187, 188, 189, // 180-189
+       190, 191, 192, 193, 194, 195, 196, 197, 198, 199, // 190-199
+       200, 201, 202, 203, 204, 205, 206, 207, 208, 209, // 200-209
+       210, 211, 212, 213, 214, 215, 216, 217, 218, 219, // 210-219
+       220, 221, 222, 223, 224, 225, 226, 227, 228, 229, // 220-229
+       230, 231, 232, 233, 234, 235, 236, 237, 238, 239, // 230-249
+       240, 241, 242, 243, 244, 245, 246, 247, 248, 249, // 240-249
+       250, 251, 252, 253, 254, 255,                     // 250-255
 };
 
-/** Case sensitive map.
- * Can technically also be used for ASCII case sensitive comparisons, as [ != {, etc.
+
+
+/**
+ * A case insensitive mapping of characters from upper case to lower case for
+ * the character set of RFC 1459. This is identical to ASCII with the small
+ * exception of {}| being considered to be the lower case equivalents of the
+ * characters []\ respectively.
  */
-unsigned const char rfc_case_sensitive_map[256] = {
-       0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
-        21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
-        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
-        61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
-        81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
-        101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
-        121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
-        141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
-        161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
-        181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
-        201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
-        221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
-        241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
+unsigned const char rfc_case_insensitive_map[256] = {
+       0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   // 0-9
+       10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  // 10-19
+       20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  // 20-29
+       30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  // 30-39
+       40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  // 40-49
+       50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  // 50-59
+       60,  61,  62,  63,  64,  97,  98,  99,  100, 101, // 60-69
+       102, 103, 104, 105, 106, 107, 108, 109, 110, 111, // 70-79
+       112, 113, 114, 115, 116, 117, 118, 119, 120, 121, // 80-89
+       122, 123, 124, 125, 94,  95,  96,  97,  98,  99,  // 90-99
+       100, 101, 102, 103, 104, 105, 106, 107, 108, 109, // 100-109
+       110, 111, 112, 113, 114, 115, 116, 117, 118, 119, // 110-119
+       120, 121, 122, 123, 124, 125, 126, 127, 128, 129, // 120-129
+       130, 131, 132, 133, 134, 135, 136, 137, 138, 139, // 130-139
+       140, 141, 142, 143, 144, 145, 146, 147, 148, 149, // 140-149
+       150, 151, 152, 153, 154, 155, 156, 157, 158, 159, // 150-159
+       160, 161, 162, 163, 164, 165, 166, 167, 168, 169, // 160-169
+       170, 171, 172, 173, 174, 175, 176, 177, 178, 179, // 170-179
+       180, 181, 182, 183, 184, 185, 186, 187, 188, 189, // 180-189
+       190, 191, 192, 193, 194, 195, 196, 197, 198, 199, // 190-199
+       200, 201, 202, 203, 204, 205, 206, 207, 208, 209, // 200-209
+       210, 211, 212, 213, 214, 215, 216, 217, 218, 219, // 210-219
+       220, 221, 222, 223, 224, 225, 226, 227, 228, 229, // 220-229
+       230, 231, 232, 233, 234, 235, 236, 237, 238, 239, // 230-239
+       240, 241, 242, 243, 244, 245, 246, 247, 248, 249, // 240-249
+       250, 251, 252, 253, 254, 255,                     // 250-255
 };
 
-/* convert a string to lowercase. Note following special circumstances
- * taken from RFC 1459. Many "official" server branches still hold to this
- * rule so i will too;
- *
- *  Because of IRC's scandanavian origin, the characters {}| are
- *  considered to be the lower case equivalents of the characters []\,
- *  respectively. This is a critical issue when determining the
- *  equivalence of two nicknames.
+/**
+ * A case sensitive mapping of characters from upper case to lower case for the
+ * character set of RFC 1459. This is identical to ASCII.
  */
-void nspace::strlower(char *n)
-{
-       if (n)
-       {
-               for (char* t = n; *t; t++)
-                       *t = national_case_insensitive_map[(unsigned char)*t];
-       }
-}
-
-#ifdef HASHMAP_DEPRECATED
-       size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
-#else
-       size_t nspace::hash<std::string>::operator()(const std::string &s) const
-#endif
-
-{
-       /* XXX: NO DATA COPIES! :)
-        * The hash function here is practically
-        * a copy of the one in STL's hash_fun.h,
-        * only with *x replaced with national_case_insensitive_map[*x].
-        * This avoids a copy to use hash<const char*>
-        */
-       register size_t t = 0;
-       for (std::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
-               t = 5 * t + national_case_insensitive_map[(unsigned char)*x];
-       return t;
-}
-
+unsigned const char rfc_case_sensitive_map[256] = {
+       0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   // 0-9
+       10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  // 10-19
+       20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  // 20-29
+       30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  // 30-39
+       40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  // 40-49
+       50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  // 50-59
+       60,  61,  62,  63,  64,  65,  66,  67,  68,  69,  // 60-69
+       70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  // 70-79
+       80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  // 80-89
+       90,  91,  92,  93,  94,  95,  96,  97,  98,  99,  // 90-99
+       100, 101, 102, 103, 104, 105, 106, 107, 108, 109, // 100-109
+       110, 111, 112, 113, 114, 115, 116, 117, 118, 119, // 110-119
+       120, 121, 122, 123, 124, 125, 126, 127, 128, 129, // 120-129
+       130, 131, 132, 133, 134, 135, 136, 137, 138, 139, // 130-139
+       140, 141, 142, 143, 144, 145, 146, 147, 148, 149, // 140-149
+       150, 151, 152, 153, 154, 155, 156, 157, 158, 159, // 150-159
+       160, 161, 162, 163, 164, 165, 166, 167, 168, 169, // 160-169
+       170, 171, 172, 173, 174, 175, 176, 177, 178, 179, // 170-179
+       180, 181, 182, 183, 184, 185, 186, 187, 188, 189, // 180-189
+       190, 191, 192, 193, 194, 195, 196, 197, 198, 199, // 190-199
+       200, 201, 202, 203, 204, 205, 206, 207, 208, 209, // 200-209
+       210, 211, 212, 213, 214, 215, 216, 217, 218, 219, // 210-219
+       220, 221, 222, 223, 224, 225, 226, 227, 228, 229, // 220-229
+       230, 231, 232, 233, 234, 235, 236, 237, 238, 239, // 230-239
+       240, 241, 242, 243, 244, 245, 246, 247, 248, 249, // 240-249
+       250, 251, 252, 253, 254, 255,                     // 250-255
+};
 
 size_t CoreExport irc::hash::operator()(const irc::string &s) const
 {
@@ -165,6 +172,20 @@ bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2)
        return (national_case_insensitive_map[*n1] == national_case_insensitive_map[*n2]);
 }
 
+size_t irc::insensitive::operator()(const std::string &s) const
+{
+       /* XXX: NO DATA COPIES! :)
+        * The hash function here is practically
+        * a copy of the one in STL's hash_fun.h,
+        * only with *x replaced with national_case_insensitive_map[*x].
+        * This avoids a copy to use hash<const char*>
+        */
+       register size_t t = 0;
+       for (std::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
+               t = 5 * t + national_case_insensitive_map[(unsigned char)*x];
+       return t;
+}
+
 /******************************************************
  *
  * This is the implementation of our special irc::string
@@ -217,60 +238,30 @@ const char* irc::irc_char_traits::find(const char* s1, int  n, char c)
        return (n >= 0) ? s1 : NULL;
 }
 
-irc::tokenstream::tokenstream(const std::string &source) : tokens(source), last_pushed(false)
-{
-       /* Record starting position and current position */
-       last_starting_position = tokens.begin();
-       n = tokens.begin();
-}
-
-irc::tokenstream::~tokenstream()
+irc::tokenstream::tokenstream(const std::string &source) : spacesepstream(source)
 {
 }
 
 bool irc::tokenstream::GetToken(std::string &token)
 {
-       std::string::iterator lsp = last_starting_position;
-
-       while (n != tokens.end())
-       {
-               /** Skip multi space, converting "  " into " "
-                */
-               while ((n+1 != tokens.end()) && (*n == ' ') && (*(n+1) == ' '))
-                       n++;
-
-               if ((last_pushed) && (*n == ':'))
-               {
-                       /* If we find a token thats not the first and starts with :,
-                        * this is the last token on the line
-                        */
-                       std::string::iterator curr = ++n;
-                       n = tokens.end();
-                       token = std::string(curr, tokens.end());
-                       return true;
-               }
+       bool first = !pos;
 
-               last_pushed = false;
+       if (!spacesepstream::GetToken(token))
+               return false;
 
-               if ((*n == ' ') || (n+1 == tokens.end()))
+       /* This is the last parameter */
+       if (token[0] == ':' && !first)
+       {
+               token = token.substr(1);
+               if (!StreamEnd())
                {
-                       /* If we find a space, or end of string, this is the end of a token.
-                        */
-                       last_starting_position = n+1;
-                       last_pushed = *n == ' ';
-
-                       std::string strip(lsp, n+1 == tokens.end() ? n+1  : n++);
-                       while ((strip.length()) && (strip.find_last_of(' ') == strip.length() - 1))
-                               strip.erase(strip.end() - 1);
-
-                       token = strip;
-                       return !token.empty();
+                       token += ' ';
+                       token += GetRemaining();
                }
-
-               n++;
+               pos = tokens.length() + 1;
        }
-       token.clear();
-       return false;
+
+       return true;
 }
 
 bool irc::tokenstream::GetToken(irc::string &token)
@@ -297,85 +288,50 @@ bool irc::tokenstream::GetToken(long &token)
        return returnval;
 }
 
-irc::sepstream::sepstream(const std::string &source, char seperator) : tokens(source), sep(seperator)
+irc::sepstream::sepstream(const std::string& source, char separator, bool allowempty)
+       : tokens(source), sep(separator), pos(0), allow_empty(allowempty)
 {
-       last_starting_position = tokens.begin();
-       n = tokens.begin();
 }
 
 bool irc::sepstream::GetToken(std::string &token)
 {
-       std::string::iterator lsp = last_starting_position;
+       if (this->StreamEnd())
+       {
+               token.clear();
+               return false;
+       }
 
-       while (n != tokens.end())
+       if (!this->allow_empty)
        {
-               if ((*n == sep) || (n+1 == tokens.end()))
+               this->pos = this->tokens.find_first_not_of(this->sep, this->pos);
+               if (this->pos == std::string::npos)
                {
-                       last_starting_position = n+1;
-                       token = std::string(lsp, n+1 == tokens.end() ? n+1  : n++);
-
-                       while ((token.length()) && (token.find_last_of(sep) == token.length() - 1))
-                               token.erase(token.end() - 1);
-
-                       if (token.empty())
-                               n++;
-
-                       return n == tokens.end() ? false : true;
+                       this->pos = this->tokens.length() + 1;
+                       token.clear();
+                       return false;
                }
-
-               n++;
        }
 
-       token.clear();
-       return false;
-}
-
-const std::string irc::sepstream::GetRemaining()
-{
-       return std::string(n, tokens.end());
-}
+       size_t p = this->tokens.find(this->sep, this->pos);
+       if (p == std::string::npos)
+               p = this->tokens.length();
 
-bool irc::sepstream::StreamEnd()
-{
-       return ((n + 1) == tokens.end());
-}
+       token = this->tokens.substr(this->pos, p - this->pos);
+       this->pos = p + 1;
 
-irc::sepstream::~sepstream()
-{
+       return true;
 }
 
-std::string irc::hex(const unsigned char *raw, size_t rawsz)
+const std::string irc::sepstream::GetRemaining()
 {
-       if (!rawsz)
-               return "";
-
-       /* EWW! This used to be using sprintf, which is WAY inefficient. -Special */
-
-       const char *hex = "0123456789abcdef";
-       static char hexbuf[MAXBUF];
-
-       size_t i, j;
-       for (i = 0, j = 0; j < rawsz; ++j)
-       {
-               hexbuf[i++] = hex[raw[j] / 16];
-               hexbuf[i++] = hex[raw[j] % 16];
-       }
-       hexbuf[i] = 0;
-
-       return hexbuf;
+       return !this->StreamEnd() ? this->tokens.substr(this->pos) : "";
 }
 
-CoreExport const char* irc::Spacify(const char* n)
+bool irc::sepstream::StreamEnd()
 {
-       static char x[MAXBUF];
-       strlcpy(x,n,MAXBUF);
-       for (char* y = x; *y; y++)
-               if (*y == '_')
-                       *y = ' ';
-       return x;
+       return this->pos > this->tokens.length();
 }
 
-
 irc::modestacker::modestacker(bool add) : adding(add)
 {
        sequence.clear();
@@ -441,41 +397,16 @@ int irc::modestacker::GetStackedLine(std::vector<std::string> &result, int max_l
        return n;
 }
 
-irc::stringjoiner::stringjoiner(const std::string &seperator, const std::vector<std::string> &sequence, int begin, int end)
+irc::stringjoiner::stringjoiner(const std::string& separator, const std::vector<std::string>& sequence, unsigned int begin, unsigned int end)
 {
        if (end < begin)
                return; // nothing to do here
 
-       for (int v = begin; v < end; v++)
-               joined.append(sequence[v]).append(seperator);
+       for (unsigned int v = begin; v < end; v++)
+               joined.append(sequence[v]).append(separator);
        joined.append(sequence[end]);
 }
 
-irc::stringjoiner::stringjoiner(const std::string &seperator, const std::deque<std::string> &sequence, int begin, int end)
-{
-       if (end < begin)
-               return; // nothing to do here
-
-       for (int v = begin; v < end; v++)
-               joined.append(sequence[v]).append(seperator);
-       joined.append(sequence[end]);
-}
-
-irc::stringjoiner::stringjoiner(const std::string &seperator, const char* const* sequence, int begin, int end)
-{
-       if (end < begin)
-               return; // nothing to do here
-
-       for (int v = begin; v < end; v++)
-               joined.append(sequence[v]).append(seperator);
-       joined.append(sequence[end]);
-}
-
-std::string& irc::stringjoiner::GetJoined()
-{
-       return joined;
-}
-
 irc::portparser::portparser(const std::string &source, bool allow_overlapped)
        : sep(source), in_range(0), range_begin(0), range_end(0), overlapped(allow_overlapped)
 {
@@ -549,25 +480,3 @@ long irc::portparser::GetToken()
                return atoi(x.c_str());
        }
 }
-
-/*const std::basic_string& SearchAndReplace(std::string& text, const std::string& pattern, const std::string& replace)
-{
-       std::string replacement;
-       if ((!pattern.empty()) && (!text.empty()))
-       {
-               for (std::string::size_type n = 0; n != text.length(); ++n)
-               {
-                       if (text.length() >= pattern.length() && text.substr(n, pattern.length()) == pattern)
-                       {
-                               replacement.append(replace);
-                               n = n + pattern.length() - 1;
-                       }
-                       else
-                       {
-                               replacement += text[n];
-                       }
-               }
-       }
-       text = replacement;
-       return text;
-}*/
index 5a8f55f11f70ea12955926f7d6f18ffb65eabbe9..9ed77fb99332cfa7cd1046990bf37d408b74fbfe 100644 (file)
@@ -66,19 +66,6 @@ User* InspIRCd::FindNick(const std::string &nick)
        return iter->second;
 }
 
-User* InspIRCd::FindNick(const char* nick)
-{
-       if (isdigit(*nick))
-               return FindUUID(nick);
-
-       user_hash::iterator iter = this->Users->clientlist->find(nick);
-
-       if (iter == this->Users->clientlist->end())
-               return NULL;
-
-       return iter->second;
-}
-
 User* InspIRCd::FindNickOnly(const std::string &nick)
 {
        user_hash::iterator iter = this->Users->clientlist->find(nick);
@@ -89,16 +76,6 @@ User* InspIRCd::FindNickOnly(const std::string &nick)
        return iter->second;
 }
 
-User* InspIRCd::FindNickOnly(const char* nick)
-{
-       user_hash::iterator iter = this->Users->clientlist->find(nick);
-
-       if (iter == this->Users->clientlist->end())
-               return NULL;
-
-       return iter->second;
-}
-
 User *InspIRCd::FindUUID(const std::string &uid)
 {
        user_hash::iterator finduuid = this->Users->uuidlist->find(uid);
@@ -108,23 +85,7 @@ User *InspIRCd::FindUUID(const std::string &uid)
 
        return finduuid->second;
 }
-
-User *InspIRCd::FindUUID(const char *uid)
-{
-       return FindUUID(std::string(uid));
-}
-
 /* find a channel record by channel name and return a pointer to it */
-Channel* InspIRCd::FindChan(const char* chan)
-{
-       chan_hash::iterator iter = chanlist->find(chan);
-
-       if (iter == chanlist->end())
-               /* Couldn't find it */
-               return NULL;
-
-       return iter->second;
-}
 
 Channel* InspIRCd::FindChan(const std::string &chan)
 {
@@ -145,8 +106,8 @@ void InspIRCd::SendError(const std::string &s)
                User* u = *i;
                if (u->registered == REG_ALL)
                {
-                       u->WriteServ("NOTICE %s :%s",u->nick.c_str(),s.c_str());
-               }
+                       u->WriteNotice(s);
+               }
                else
                {
                        /* Unregistered connections receive ERROR, not a NOTICE */
@@ -155,12 +116,6 @@ void InspIRCd::SendError(const std::string &s)
        }
 }
 
-/* return channel count */
-long InspIRCd::ChannelCount()
-{
-       return chanlist->size();
-}
-
 bool InspIRCd::IsValidMask(const std::string &mask)
 {
        const char* dest = mask.c_str();
@@ -281,47 +236,35 @@ void InspIRCd::ProcessColors(file_cache& input)
 }
 
 /* true for valid channel name, false else */
-bool IsChannelHandler::Call(const char *chname, size_t max)
+bool IsChannelHandler::Call(const std::string& chname)
 {
-       const char *c = chname + 1;
+       if (chname.empty() || chname.length() > ServerInstance->Config->Limits.ChanMax)
+               return false;
 
-       /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */
-       if (!chname || *chname != '#')
-       {
+       if (chname[0] != '#')
                return false;
-       }
 
-       while (*c)
+       for (std::string::const_iterator i = chname.begin()+1; i != chname.end(); ++i)
        {
-               switch (*c)
+               switch (*i)
                {
                        case ' ':
                        case ',':
                        case 7:
                                return false;
                }
-
-               c++;
-       }
-
-       size_t len = c - chname;
-       /* too long a name - note funky pointer arithmetic here. */
-       if (len > max)
-       {
-                       return false;
        }
 
        return true;
 }
 
 /* true for valid nickname, false else */
-bool IsNickHandler::Call(const char* n, size_t max)
+bool IsNickHandler::Call(const std::string& n)
 {
-       if (!n || !*n)
+       if (n.empty() || n.length() > ServerInstance->Config->Limits.NickMax)
                return false;
 
-       unsigned int p = 0;
-       for (const char* i = n; *i; i++, p++)
+       for (std::string::const_iterator i = n.begin(); i != n.end(); ++i)
        {
                if ((*i >= 'A') && (*i <= '}'))
                {
@@ -329,7 +272,7 @@ bool IsNickHandler::Call(const char* n, size_t max)
                        continue;
                }
 
-               if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n))
+               if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i != n.begin()))
                {
                        /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
                        continue;
@@ -339,17 +282,16 @@ bool IsNickHandler::Call(const char* n, size_t max)
                return false;
        }
 
-       /* too long? or not */
-       return (p <= max);
+       return true;
 }
 
 /* return true for good ident, false else */
-bool IsIdentHandler::Call(const char* n)
+bool IsIdentHandler::Call(const std::string& n)
 {
-       if (!n || !*n)
+       if (n.empty())
                return false;
 
-       for (const char* i = n; *i; i++)
+       for (std::string::const_iterator i = n.begin(); i != n.end(); ++i)
        {
                if ((*i >= 'A') && (*i <= '}'))
                {
@@ -367,7 +309,7 @@ bool IsIdentHandler::Call(const char* n)
        return true;
 }
 
-bool IsSIDHandler::Call(const std::string &str)
+bool InspIRCd::IsSID(const std::string &str)
 {
        /* Returns true if the string given is exactly 3 characters long,
         * starts with a digit, and the other two characters are A-Z or digits
@@ -377,35 +319,13 @@ bool IsSIDHandler::Call(const std::string &str)
                         ((str[2] >= 'A' && str[2] <= 'Z') || isdigit(str[2])));
 }
 
-/* open the proper logfile */
-bool InspIRCd::OpenLog(char**, int)
-{
-       if (!Config->cmdline.writelog) return true; // Skip opening default log if -nolog
-
-       if (Config->cmdline.startup_log.empty())
-               Config->cmdline.startup_log = LOG_PATH "/startup.log";
-       FILE* startup = fopen(Config->cmdline.startup_log.c_str(), "a+");
-
-       if (!startup)
-       {
-               return false;
-       }
-
-       FileWriter* fw = new FileWriter(startup);
-       FileLogStream *f = new FileLogStream((Config->cmdline.forcedebug ? DEBUG : DEFAULT), fw);
-
-       this->Logs->AddLogType("*", f, true);
-
-       return true;
-}
-
 void InspIRCd::CheckRoot()
 {
 #ifndef _WIN32
        if (geteuid() == 0)
        {
                std::cout << "ERROR: You are running an irc server as root! DO NOT DO THIS!" << std::endl << std::endl;
-               this->Logs->Log("STARTUP",DEFAULT,"Can't start as root");
+               this->Logs->Log("STARTUP", LOG_DEFAULT, "Can't start as root");
                Exit(EXIT_STATUS_ROOT);
        }
 #endif
@@ -424,19 +344,15 @@ void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const std::str
 
 void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-       va_start (argsPtr, format);
-       vsnprintf(textbuffer, MAXBUF, format, argsPtr);
-       va_end(argsPtr);
-
-       this->SendWhoisLine(user, dest, numeric, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, format, format)
+       this->SendWhoisLine(user, dest, numeric, textbuffer);
 }
 
 /** Refactored by Brain, Jun 2009. Much faster with some clever O(1) array
  * lookups and pointer maths.
  */
-long InspIRCd::Duration(const std::string &str)
+unsigned long InspIRCd::Duration(const std::string &str)
 {
        unsigned char multiplier = 0;
        long total = 0;
@@ -476,6 +392,34 @@ long InspIRCd::Duration(const std::string &str)
        return total + subtotal;
 }
 
+const char* InspIRCd::Format(va_list &vaList, const char* formatString)
+{
+       static std::vector<char> formatBuffer(1024);
+
+       while (true)
+       {
+               va_list dst;
+               va_copy(dst, vaList);
+
+               int vsnret = vsnprintf(&formatBuffer[0], formatBuffer.size(), formatString, dst);
+               if (vsnret > 0 && static_cast<unsigned>(vsnret) < formatBuffer.size())
+               {
+                       return &formatBuffer[0];
+               }
+
+               formatBuffer.resize(formatBuffer.size() * 2);
+       }
+
+       throw CoreException();
+}
+
+const char* InspIRCd::Format(const char* formatString, ...)
+{
+       const char* ret;
+       VAFORMAT(ret, formatString, formatString);
+       return ret;
+}
+
 bool InspIRCd::ULine(const std::string& sserver)
 {
        if (sserver.empty())
@@ -498,26 +442,6 @@ std::string InspIRCd::TimeString(time_t curtime)
        return std::string(ctime(&curtime),24);
 }
 
-// You should only pass a single character to this.
-void InspIRCd::AddExtBanChar(char c)
-{
-       std::string &tok = Config->data005;
-       std::string::size_type ebpos = tok.find(" EXTBAN=,");
-
-       if (ebpos == std::string::npos)
-       {
-               tok.append(" EXTBAN=,");
-               tok.push_back(c);
-       }
-       else
-       {
-               ebpos += 9;
-               while (isalpha(tok[ebpos]) && tok[ebpos] < c)
-                       ebpos++;
-               tok.insert(ebpos, 1, c);
-       }
-}
-
 std::string InspIRCd::GenRandomStr(int length, bool printable)
 {
        char* buf = new char[length];
index 1403cdef5a5805b10b22c08810839a22cc8a58af..0e4a6646fcd921af9b86cfbfea52d1a53c0ce9bb 100644 (file)
@@ -28,7 +28,6 @@
 
 /* $Core */
 #include "inspircd.h"
-#include "inspircd_version.h"
 #include <signal.h>
 
 #ifndef _WIN32
@@ -63,7 +62,6 @@
 #include "testsuite.h"
 
 InspIRCd* ServerInstance = NULL;
-int* mysig = NULL;
 
 /** Seperate from the other casemap tables so that code *can* still exclusively rely on RFC casemapping
  * if it must.
@@ -133,8 +131,6 @@ void InspIRCd::Cleanup()
        /* Must be deleted before modes as it decrements modelines */
        if (FakeClient)
                FakeClient->cull();
-       if (Res)
-               Res->cull();
        DeleteZero(this->FakeClient);
        DeleteZero(this->Users);
        DeleteZero(this->Modes);
@@ -145,7 +141,6 @@ void InspIRCd::Cleanup()
        DeleteZero(this->BanCache);
        DeleteZero(this->SNO);
        DeleteZero(this->Config);
-       DeleteZero(this->Res);
        DeleteZero(this->chanlist);
        DeleteZero(this->PI);
        DeleteZero(this->Threads);
@@ -185,47 +180,6 @@ void InspIRCd::Restart(const std::string &reason)
        }
 }
 
-void InspIRCd::ResetMaxBans()
-{
-       for (chan_hash::const_iterator i = chanlist->begin(); i != chanlist->end(); i++)
-               i->second->ResetMaxBans();
-}
-
-/** Because hash_map doesn't free its buckets when we delete items, we occasionally
- * recreate the hash to free them up.
- * We do this by copying the entries from the old hash to a new hash, causing all
- * empty buckets to be weeded out of the hash.
- * Since this is quite expensive, it's not done very often.
- */
-void InspIRCd::RehashUsersAndChans()
-{
-       user_hash* old_users = Users->clientlist;
-       Users->clientlist = new user_hash;
-       for (user_hash::const_iterator n = old_users->begin(); n != old_users->end(); n++)
-               Users->clientlist->insert(*n);
-       delete old_users;
-
-       user_hash* old_uuid = Users->uuidlist;
-       Users->uuidlist = new user_hash;
-       for (user_hash::const_iterator n = old_uuid->begin(); n != old_uuid->end(); n++)
-               Users->uuidlist->insert(*n);
-       delete old_uuid;
-
-       chan_hash* old_chans = chanlist;
-       chanlist = new chan_hash;
-       for (chan_hash::const_iterator n = old_chans->begin(); n != old_chans->end(); n++)
-               chanlist->insert(*n);
-       delete old_chans;
-
-       // Reset the already_sent IDs so we don't wrap it around and drop a message
-       LocalUser::already_sent_id = 0;
-       for (LocalUserList::const_iterator i = Users->local_users.begin(); i != Users->local_users.end(); i++)
-       {
-               (**i).already_sent = 0;
-               (**i).RemoveExpiredInvites();
-       }
-}
-
 void InspIRCd::SetSignals()
 {
 #ifndef _WIN32
@@ -276,13 +230,13 @@ bool InspIRCd::DaemonSeed()
        rlimit rl;
        if (getrlimit(RLIMIT_CORE, &rl) == -1)
        {
-               this->Logs->Log("STARTUP",DEFAULT,"Failed to getrlimit()!");
+               this->Logs->Log("STARTUP", LOG_DEFAULT, "Failed to getrlimit()!");
                return false;
        }
        rl.rlim_cur = rl.rlim_max;
 
        if (setrlimit(RLIMIT_CORE, &rl) == -1)
-                       this->Logs->Log("STARTUP",DEFAULT,"setrlimit() failed, cannot increase coredump size.");
+                       this->Logs->Log("STARTUP", LOG_DEFAULT, "setrlimit() failed, cannot increase coredump size.");
 
        return true;
 #endif
@@ -303,7 +257,7 @@ void InspIRCd::WritePID(const std::string &filename)
        else
        {
                std::cout << "Failed to write PID-file '" << fname << "', exiting." << std::endl;
-               this->Logs->Log("STARTUP",DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
+               this->Logs->Log("STARTUP", LOG_DEFAULT, "Failed to write PID-file '%s', exiting.",fname.c_str());
                Exit(EXIT_STATUS_PID);
        }
 #endif
@@ -317,20 +271,16 @@ InspIRCd::InspIRCd(int argc, char** argv) :
          * THIS MUST MATCH THE ORDER OF DECLARATION OF THE FUNCTORS, e.g. the methods
          * themselves within the class.
          */
-        NICKForced("NICKForced", NULL),
         OperQuit("OperQuit", NULL),
         GenRandom(&HandleGenRandom),
         IsChannel(&HandleIsChannel),
-        IsSID(&HandleIsSID),
         Rehash(&HandleRehash),
         IsNick(&HandleIsNick),
         IsIdent(&HandleIsIdent),
-        FloodQuitUser(&HandleFloodQuitUser),
         OnCheckExemption(&HandleOnCheckExemption)
 {
        ServerInstance = this;
 
-       Extensions.Register(&NICKForced);
        Extensions.Register(&OperQuit);
 
        FailedPortList pl;
@@ -353,7 +303,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->Parser = 0;
        this->XLines = 0;
        this->Modes = 0;
-       this->Res = 0;
        this->ConfigThread = NULL;
        this->FakeClient = NULL;
 
@@ -370,8 +319,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        /* Default implementation does nothing */
        this->PI = new ProtocolInterface;
 
-       this->s_signal = 0;
-
        // Create base manager classes early, so nothing breaks
        this->Users = new UserManager;
 
@@ -383,6 +330,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->SNO = new SnomaskManager;
        this->BanCache = new BanCacheManager;
        this->Modules = new ModuleManager();
+       dynamic_reference_base::reset_all();
        this->stats = new serverstats();
        this->Timers = new TimerManager;
        this->Parser = new CommandParser;
@@ -414,7 +362,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        struct option longopts[] =
        {
                { "nofork",     no_argument,            &do_nofork,     1       },
-               { "logfile",    required_argument,      NULL,           'f'     },
                { "config",     required_argument,      NULL,           'c'     },
                { "debug",      no_argument,            &do_debug,      1       },
                { "nolog",      no_argument,            &do_nolog,      1       },
@@ -425,14 +372,10 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        };
 
        int index;
-       while ((c = getopt_long(argc, argv, ":c:f:", longopts, &index)) != -1)
+       while ((c = getopt_long(argc, argv, ":c:", longopts, &index)) != -1)
        {
                switch (c)
                {
-                       case 'f':
-                               /* Log filename was set */
-                               Config->cmdline.startup_log = optarg;
-                       break;
                        case 'c':
                                /* Config filename was set */
                                ConfigFileName = optarg;
@@ -445,8 +388,8 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                        default:
                                /* Fall through to handle other weird values too */
                                std::cout << "Unknown parameter '" << argv[optind-1] << "'" << std::endl;
-                               std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--debug] [--logfile <filename>] " << std::endl <<
-                                       std::string(static_cast<int>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version] [--config <config>] [--testsuite]" << std::endl;
+                               std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--debug] [--config <config>]" << std::endl <<
+                                       std::string(static_cast<int>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version] [--testsuite]" << std::endl;
                                Exit(EXIT_STATUS_ARGV);
                        break;
                }
@@ -476,14 +419,9 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        if (do_debug)
        {
                FileWriter* fw = new FileWriter(stdout);
-               FileLogStream* fls = new FileLogStream(RAWIO, fw);
+               FileLogStream* fls = new FileLogStream(LOG_RAWIO, fw);
                Logs->AddLogTypes("*", fls, true);
        }
-       else if (!this->OpenLog(argv, argc))
-       {
-               std::cout << "ERROR: Could not open initial logfile " << Config->cmdline.startup_log << ": " << strerror(errno) << std::endl << std::endl;
-               Exit(EXIT_STATUS_LOG);
-       }
 
        if (!ServerConfig::FileExists(ConfigFileName.c_str()))
        {
@@ -500,7 +438,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 #endif
                {
                        std::cout << "ERROR: Cannot open config file: " << ConfigFileName << std::endl << "Exiting..." << std::endl;
-                       this->Logs->Log("STARTUP",DEFAULT,"Unable to open config file %s", ConfigFileName.c_str());
+                       this->Logs->Log("STARTUP", LOG_DEFAULT, "Unable to open config file %s", ConfigFileName.c_str());
                        Exit(EXIT_STATUS_CONFIG);
                }
        }
@@ -509,7 +447,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        std::cout << con_green << "(C) InspIRCd Development Team." << con_reset << std::endl << std::endl;
        std::cout << "Developers:" << std::endl;
        std::cout << con_green << "\tBrain, FrostyCoolSlug, w00t, Om, Special, peavey" << std::endl;
-       std::cout << "\taquanight, psychon, dz, danieldg, jackmcbarn" << std::endl;\r
+       std::cout << "\taquanight, psychon, dz, danieldg, jackmcbarn" << std::endl;
        std::cout << "\tAttila" << con_reset << std::endl << std::endl;
        std::cout << "Others:\t\t\t" << con_green << "See /INFO Output" << con_reset << std::endl;
 
@@ -520,14 +458,14 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                this->CheckRoot();
        else
        {
-               std::cout << "* WARNING * WARNING * WARNING * WARNING * WARNING *" << std::endl\r
-               << "YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED" << std::endl\r
-               << "AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED" << std::endl\r
-               << "OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR" << std::endl\r
-               << "SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN" << std::endl\r
-               << "TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART" << std::endl\r
-               << "THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!" << std::endl << std::endl\r
-               << "InspIRCd starting in 20 seconds, ctrl+c to abort..." << std::endl;\r
+               std::cout << "* WARNING * WARNING * WARNING * WARNING * WARNING *" << std::endl
+               << "YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED" << std::endl
+               << "AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED" << std::endl
+               << "OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR" << std::endl
+               << "SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN" << std::endl
+               << "TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART" << std::endl
+               << "THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!" << std::endl << std::endl
+               << "InspIRCd starting in 20 seconds, ctrl+c to abort..." << std::endl;
                sleep(20);
        }
 #endif
@@ -539,7 +477,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                if (!this->DaemonSeed())
                {
                        std::cout << "ERROR: could not go into daemon mode. Shutting down." << std::endl;
-                       Logs->Log("STARTUP", DEFAULT, "ERROR: could not go into daemon mode. Shutting down.");
+                       Logs->Log("STARTUP", LOG_DEFAULT, "ERROR: could not go into daemon mode. Shutting down.");
                        Exit(EXIT_STATUS_FORK);
                }
        }
@@ -552,28 +490,14 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->Config->Read();
        this->Config->Apply(NULL, "");
        Logs->OpenFileLogs();
+       ModeParser::InitBuiltinModes();
 
-       this->Res = new DNS();
-
-       /*
-        * Initialise SID/UID.
-        * For an explanation as to exactly how this works, and why it works this way, see GetUID().
-        *   -- w00t
-        */
+       // If we don't have a SID, generate one based on the server name and the server description
        if (Config->sid.empty())
-       {
-               // Generate one
-               unsigned int sid = 0;
-               char sidstr[4];
-
-               for (const char* x = Config->ServerName.c_str(); *x; ++x)
-                       sid = 5 * sid + *x;
-               for (const char* y = Config->ServerDesc.c_str(); *y; ++y)
-                       sid = 5 * sid + *y;
-               sprintf(sidstr, "%03d", sid % 1000);
+               Config->sid = UIDGenerator::GenerateSID(Config->ServerName, Config->ServerDesc);
 
-               Config->sid = sidstr;
-       }
+       // Initialize the UID generator with our sid
+       this->UIDGen.init(Config->sid);
 
        /* set up fake client again this time with the correct uid */
        this->FakeClient = new FakeUser(Config->sid, Config->ServerName);
@@ -589,7 +513,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->Modules->LoadAll();
 
        /* Just in case no modules were loaded - fix for bug #101 */
-       this->BuildISupport();
+       this->ISupport.Build();
        Config->ApplyDisabledCommands(Config->DisabledCommands);
 
        if (!pl.empty())
@@ -614,7 +538,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                if (kill(getppid(), SIGTERM) == -1)
                {
                        std::cout << "Error killing parent process: " << strerror(errno) << std::endl;
-                       Logs->Log("STARTUP", DEFAULT, "Error killing parent process: %s",strerror(errno));
+                       Logs->Log("STARTUP", LOG_DEFAULT, "Error killing parent process: %s",strerror(errno));
                }
        }
 
@@ -637,16 +561,16 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                fclose(stdout);
 
                if (dup2(fd, STDIN_FILENO) < 0)
-                       Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stdin.");
+                       Logs->Log("STARTUP", LOG_DEFAULT, "Failed to dup /dev/null to stdin.");
                if (dup2(fd, STDOUT_FILENO) < 0)
-                       Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stdout.");
+                       Logs->Log("STARTUP", LOG_DEFAULT, "Failed to dup /dev/null to stdout.");
                if (dup2(fd, STDERR_FILENO) < 0)
-                       Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stderr.");
+                       Logs->Log("STARTUP", LOG_DEFAULT, "Failed to dup /dev/null to stderr.");
                close(fd);
        }
        else
        {
-               Logs->Log("STARTUP", DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
+               Logs->Log("STARTUP", LOG_DEFAULT, "Keeping pseudo-tty open as we are running in the foreground.");
        }
 #else
        /* Set win32 service as running, if we are running as a service */
@@ -661,7 +585,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        QueryPerformanceFrequency(&stats->QPFrequency);
 #endif
 
-       Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
+       Logs->Log("STARTUP", LOG_DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
 
 #ifndef _WIN32
        std::string SetUser = Config->ConfValue("security")->getString("runasuser");
@@ -675,7 +599,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 
                if (ret == -1)
                {
-                       this->Logs->Log("SETGROUPS", DEFAULT, "setgroups() failed (wtf?): %s", strerror(errno));
+                       this->Logs->Log("SETGROUPS", LOG_DEFAULT, "setgroups() failed (wtf?): %s", strerror(errno));
                        this->QuickExit(0);
                }
 
@@ -687,7 +611,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 
                if (!g)
                {
-                       this->Logs->Log("SETGUID", DEFAULT, "getgrnam() failed (bad user?): %s", strerror(errno));
+                       this->Logs->Log("SETGUID", LOG_DEFAULT, "getgrnam() failed (bad user?): %s", strerror(errno));
                        this->QuickExit(0);
                }
 
@@ -695,7 +619,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 
                if (ret == -1)
                {
-                       this->Logs->Log("SETGUID", DEFAULT, "setgid() failed (bad user?): %s", strerror(errno));
+                       this->Logs->Log("SETGUID", LOG_DEFAULT, "setgid() failed (bad user?): %s", strerror(errno));
                        this->QuickExit(0);
                }
        }
@@ -710,7 +634,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 
                if (!u)
                {
-                       this->Logs->Log("SETGUID", DEFAULT, "getpwnam() failed (bad user?): %s", strerror(errno));
+                       this->Logs->Log("SETGUID", LOG_DEFAULT, "getpwnam() failed (bad user?): %s", strerror(errno));
                        this->QuickExit(0);
                }
 
@@ -718,7 +642,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 
                if (ret == -1)
                {
-                       this->Logs->Log("SETGUID", DEFAULT, "setuid() failed (bad user?): %s", strerror(errno));
+                       this->Logs->Log("SETGUID", LOG_DEFAULT, "setuid() failed (bad user?): %s", strerror(errno));
                        this->QuickExit(0);
                }
        }
@@ -770,7 +694,7 @@ int InspIRCd::Run()
                if (this->ConfigThread && this->ConfigThread->IsDone())
                {
                        /* Rehash has completed */
-                       this->Logs->Log("CONFIG",DEBUG,"Detected ConfigThread exiting, tidying up...");
+                       this->Logs->Log("CONFIG", LOG_DEBUG, "Detected ConfigThread exiting, tidying up...");
 
                        this->ConfigThread->Finish();
 
@@ -814,12 +738,12 @@ int InspIRCd::Run()
                        {
                                SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is jumping FORWARDS! Clock skipped %lu secs.", (unsigned long)TIME.tv_sec - OLDTIME);
                        }
-\r
+
                        OLDTIME = TIME.tv_sec;
 
                        if ((TIME.tv_sec % 3600) == 0)
                        {
-                               this->RehashUsersAndChans();
+                               Users->GarbageCollect();
                                FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
                        }
 
@@ -847,10 +771,10 @@ int InspIRCd::Run()
                GlobalCulls.Apply();
                AtomicActions.Run();
 
-               if (this->s_signal)
+               if (s_signal)
                {
                        this->SignalHandler(s_signal);
-                       this->s_signal = 0;
+                       s_signal = 0;
                }
        }
 
@@ -859,10 +783,6 @@ int InspIRCd::Run()
 
 /**********************************************************************************/
 
-/**
- * An ircd in five lines! bwahahaha. ahahahahaha. ahahah *cough*.
- */
-
 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
  * registration timeout maximum seconds)
@@ -874,9 +794,11 @@ bool InspIRCd::AllModulesReportReady(LocalUser* user)
        return (res == MOD_RES_PASSTHRU);
 }
 
+sig_atomic_t InspIRCd::s_signal = 0;
+
 void InspIRCd::SetSignal(int signal)
 {
-       *mysig = signal;
+       s_signal = signal;
 }
 
 /* On posix systems, the flow of the program starts right here, with
@@ -888,7 +810,6 @@ void InspIRCd::SetSignal(int signal)
 ENTRYPOINT
 {
        new InspIRCd(argc, argv);
-       mysig = &ServerInstance->s_signal;
        ServerInstance->Run();
        delete ServerInstance;
        return 0;
index d78ace31891601d3b5d7d61179aefe8fabea2f9f..3a8a58b5fd4eba87015bb8582a22d7920fe9e81c 100644 (file)
@@ -66,7 +66,7 @@ BufferedSocketError BufferedSocket::BeginConnect(const std::string &ipaddr, int
        irc::sockets::sockaddrs addr, bind;
        if (!irc::sockets::aptosa(ipaddr, aport, addr))
        {
-               ServerInstance->Logs->Log("SOCKET", DEBUG, "BUG: Hostname passed to BufferedSocket, rather than an IP address!");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "BUG: Hostname passed to BufferedSocket, rather than an IP address!");
                return I_ERR_CONNECT;
        }
 
@@ -98,7 +98,7 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs&
 
        ServerInstance->SE->NonBlocking(fd);
 
-       if (ServerInstance->SE->Connect(this, &dest.sa, sa_size(dest)) == -1)
+       if (ServerInstance->SE->Connect(this, &dest.sa, dest.sa_size()) == -1)
        {
                if (errno != EINPROGRESS)
                        return I_ERR_CONNECT;
@@ -112,7 +112,7 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs&
        this->Timeout = new SocketTimeout(this->GetFd(), this, timeout, ServerInstance->Time());
        ServerInstance->Timers->AddTimer(this->Timeout);
 
-       ServerInstance->Logs->Log("SOCKET", DEBUG,"BufferedSocket::DoConnect success");
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "BufferedSocket::DoConnect success");
        return I_ERR_NONE;
 }
 
@@ -130,7 +130,7 @@ void StreamSocket::Close()
                        }
                        catch (CoreException& modexcept)
                        {
-                               ServerInstance->Logs->Log("SOCKET", DEFAULT,"%s threw an exception: %s",
+                               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s",
                                        modexcept.GetSource(), modexcept.GetReason());
                        }
                        IOHook = NULL;
@@ -170,7 +170,7 @@ void StreamSocket::DoRead()
                }
                catch (CoreException& modexcept)
                {
-                       ServerInstance->Logs->Log("SOCKET", DEFAULT, "%s threw an exception: %s",
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s",
                                modexcept.GetSource(), modexcept.GetReason());
                        return;
                }
@@ -225,7 +225,7 @@ void StreamSocket::DoWrite()
                return;
        if (!error.empty() || fd < 0 || fd == INT_MAX)
        {
-               ServerInstance->Logs->Log("SOCKET", DEBUG, "DoWrite on errored or closed socket");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DoWrite on errored or closed socket");
                return;
        }
 
@@ -317,7 +317,7 @@ void StreamSocket::DoWrite()
                }
                catch (CoreException& modexcept)
                {
-                       ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s",
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s",
                                modexcept.GetSource(), modexcept.GetReason());
                }
        }
@@ -419,7 +419,7 @@ void StreamSocket::WriteData(const std::string &data)
 {
        if (fd < 0)
        {
-               ServerInstance->Logs->Log("SOCKET", DEBUG, "Attempt to write data to dead socket: %s",
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Attempt to write data to dead socket: %s",
                        data.c_str());
                return;
        }
@@ -431,12 +431,12 @@ void StreamSocket::WriteData(const std::string &data)
        ServerInstance->SE->ChangeEventMask(this, FD_ADD_TRIAL_WRITE);
 }
 
-void SocketTimeout::Tick(time_t)
+bool SocketTimeout::Tick(time_t)
 {
-       ServerInstance->Logs->Log("SOCKET", DEBUG,"SocketTimeout::Tick");
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "SocketTimeout::Tick");
 
        if (ServerInstance->SE->GetRef(this->sfd) != this->sock)
-               return;
+               return false;
 
        if (this->sock->state == I_CONNECTING)
        {
@@ -452,6 +452,7 @@ void SocketTimeout::Tick(time_t)
        }
 
        this->sock->Timeout = NULL;
+       return false;
 }
 
 void BufferedSocket::OnConnected() { }
@@ -476,8 +477,8 @@ BufferedSocket::~BufferedSocket()
        this->Close();
        if (Timeout)
        {
-               ServerInstance->Timers->DelTimer(Timeout);
-               Timeout = NULL;
+               // The timer is removed from the TimerManager in Timer::~Timer()
+               delete Timeout;
        }
 }
 
@@ -528,13 +529,13 @@ void StreamSocket::HandleEvent(EventType et, int errornum)
        }
        catch (CoreException& ex)
        {
-               ServerInstance->Logs->Log("SOCKET", DEFAULT, "Caught exception in socket processing on FD %d - '%s'",
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Caught exception in socket processing on FD %d - '%s'",
                        fd, ex.GetReason());
                SetError(ex.GetReason());
        }
        if (!error.empty())
        {
-               ServerInstance->Logs->Log("SOCKET", DEBUG, "Error on FD %d - '%s'", fd, error.c_str());
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Error on FD %d - '%s'", fd, error.c_str());
                OnError(errcode);
        }
 }
index 534b7ce008558a32ac466eaa786ea1f6c1194560..7fa4762c5b1b873bfe734f4eec2d66dc060716a9 100644 (file)
 
 #include "inspircd.h"
 
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef HAS_STRLCPY
-CoreExport size_t strlcat(char *dst, const char *src, size_t siz)
-{
-       char *d = dst;
-       const char *s = src;
-       size_t n = siz, dlen;
-
-       while (n-- != 0 && *d != '\0')
-               d++;
-
-       dlen = d - dst;
-       n = siz - dlen;
-
-       if (n == 0)
-               return(dlen + strlen(s));
-
-       while (*s != '\0')
-       {
-               if (n != 1)
-               {
-                       *d++ = *s;
-                       n--;
-               }
-
-               s++;
-       }
-
-       *d = '\0';
-       return(dlen + (s - src)); /* count does not include NUL */
-}
-
-CoreExport size_t strlcpy(char *dst, const char *src, size_t siz)
-{
-       char *d = dst;
-       const char *s = src;
-       size_t n = siz;
-
-       /* Copy as many bytes as will fit */
-       if (n != 0 && --n != 0)
-       {
-               do
-               {
-                       if ((*d++ = *s++) == 0)
-                               break;
-               } while (--n != 0);
-       }
-
-       /* Not enough room in dst, add NUL and traverse rest of src */
-       if (n == 0)
-       {
-               if (siz != 0)
-                       *d = '\0'; /* NUL-terminate dst */
-               while (*s++);
-       }
-
-       return(s - src - 1); /* count does not include NUL */
-}
-#endif
-
-CoreExport int charlcat(char* x,char y,int z)
-{
-       char* x__n = x;
-       int v = 0;
-
-       while(*x__n++)
-               v++;
-
-       if (v < z - 1)
-       {
-               *--x__n = y;
-               *++x__n = 0;
-       }
-
-       return v;
-}
-
-CoreExport bool charremove(char* mp, char remove)
-{
-       char* mptr = mp;
-       bool shift_down = false;
-
-       while (*mptr)
-       {
-               if (*mptr == remove)
-               shift_down = true;
-
-               if (shift_down)
-                       *mptr = *(mptr+1);
-
-               mptr++;
-       }
-
-       return shift_down;
-}
-
 static const char hextable[] = "0123456789abcdef";
 
-std::string BinToHex(const std::string& data)
+std::string BinToHex(const void* raw, size_t l)
 {
-       int l = data.length();
+       const char* data = static_cast<const char*>(raw);
        std::string rv;
        rv.reserve(l * 2);
-       for(int i=0; i < l; i++)
+       for (size_t i = 0; i < l; i++)
        {
                unsigned char c = data[i];
-               rv.append(1, hextable[c >> 4]);
-               rv.append(1, hextable[c & 0xF]);
+               rv.push_back(hextable[c >> 4]);
+               rv.push_back(hextable[c & 0xF]);
        }
        return rv;
 }
index ae11c3b48238b3155cfb2b52c9de0f2dac97ecb2..20cbe51ac8d21098182e4b0d8ec85cee990f3433 100644 (file)
 #include "socket.h"
 #include "socketengine.h"
 
+#ifdef USE_TCP_DEFER_ACCEPT
+#include <netinet/tcp.h>
+#endif
+
 ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to)
        : bind_tag(tag)
 {
@@ -56,6 +60,19 @@ ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_t
        if (rv >= 0)
                rv = ServerInstance->SE->Listen(this->fd, ServerInstance->Config->MaxConn);
 
+       int timeout = tag->getInt("defer", 0);
+       if (timeout && !rv)
+       {
+#ifdef USE_TCP_DEFER_ACCEPT
+               setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &timeout, sizeof(timeout));
+#elif defined USE_SO_ACCEPTFILTER
+               struct accept_filter_arg afa;
+               memset(&afa, 0, sizeof(afa));
+               strcpy(afa.af_name, "dataready");
+               setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa));
+#endif
+       }
+
        if (rv < 0)
        {
                int errstore = errno;
@@ -76,10 +93,10 @@ ListenSocket::~ListenSocket()
        if (this->GetFd() > -1)
        {
                ServerInstance->SE->DelFd(this);
-               ServerInstance->Logs->Log("SOCKET", DEBUG,"Shut down listener on fd %d", this->fd);
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Shut down listener on fd %d", this->fd);
                ServerInstance->SE->Shutdown(this, 2);
                if (ServerInstance->SE->Close(this) != 0)
-                       ServerInstance->Logs->Log("SOCKET", DEBUG,"Failed to cancel listener: %s", strerror(errno));
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Failed to cancel listener: %s", strerror(errno));
                this->fd = -1;
        }
 }
@@ -93,7 +110,7 @@ void ListenSocket::AcceptInternal()
        socklen_t length = sizeof(client);
        int incomingSockfd = ServerInstance->SE->Accept(this, &client.sa, &length);
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensocket %s nfd=%d", bind_desc.c_str(), incomingSockfd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "HandleEvent for Listensocket %s nfd=%d", bind_desc.c_str(), incomingSockfd);
        if (incomingSockfd < 0)
        {
                ServerInstance->stats->statsRefused++;
@@ -103,7 +120,7 @@ void ListenSocket::AcceptInternal()
        socklen_t sz = sizeof(server);
        if (getsockname(incomingSockfd, &server.sa, &sz))
        {
-               ServerInstance->Logs->Log("SOCKET", DEBUG, "Can't get peername: %s", strerror(errno));
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Can't get peername: %s", strerror(errno));
                irc::sockets::aptosa(bind_addr, bind_port, server);
        }
 
@@ -119,7 +136,7 @@ void ListenSocket::AcceptInternal()
         */
        if (incomingSockfd >= ServerInstance->SE->GetMaxFds())
        {
-               ServerInstance->Logs->Log("SOCKET", DEBUG, "Server is full");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Server is full");
                ServerInstance->SE->Shutdown(incomingSockfd, 2);
                ServerInstance->SE->Close(incomingSockfd);
                ServerInstance->stats->statsRefused++;
@@ -176,7 +193,7 @@ void ListenSocket::AcceptInternal()
        else
        {
                ServerInstance->stats->statsRefused++;
-               ServerInstance->Logs->Log("SOCKET",DEFAULT,"Refusing connection on %s - %s",
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Refusing connection on %s - %s",
                        bind_desc.c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found");
                ServerInstance->SE->Close(incomingSockfd);
        }
@@ -187,10 +204,10 @@ void ListenSocket::HandleEvent(EventType e, int err)
        switch (e)
        {
                case EVENT_ERROR:
-                       ServerInstance->Logs->Log("SOCKET",DEFAULT,"ListenSocket::HandleEvent() received a socket engine error event! well shit! '%s'", strerror(err));
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ListenSocket::HandleEvent() received a socket engine error event! well shit! '%s'", strerror(err));
                        break;
                case EVENT_WRITE:
-                       ServerInstance->Logs->Log("SOCKET",DEBUG,"*** BUG *** ListenSocket::HandleEvent() got a WRITE event!!!");
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "*** BUG *** ListenSocket::HandleEvent() got a WRITE event!!!");
                        break;
                case EVENT_READ:
                        this->AcceptInternal();
diff --git a/src/listmode.cpp b/src/listmode.cpp
new file mode 100644 (file)
index 0000000..b7b1cbc
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "inspircd.h"
+#include "listmode.h"
+
+ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag)
+       : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL),
+       listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy),
+       configtag(ctag), extItem("listbase_mode_" + name + "_list", Creator)
+{
+       list = true;
+}
+
+void ListModeBase::DisplayList(User* user, Channel* channel)
+{
+       ChanData* cd = extItem.get(channel);
+       if (cd)
+       {
+               for (ModeList::reverse_iterator it = cd->list.rbegin(); it != cd->list.rend(); ++it)
+               {
+                       user->WriteNumeric(listnumeric, "%s %s %s %s %lu", user->nick.c_str(), channel->name.c_str(), it->mask.c_str(), (!it->setter.empty() ? it->setter.c_str() : ServerInstance->Config->ServerName.c_str()), (unsigned long) it->time);
+               }
+       }
+       user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str());
+}
+
+void ListModeBase::DisplayEmptyList(User* user, Channel* channel)
+{
+       user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str());
+}
+
+void ListModeBase::RemoveMode(Channel* channel, irc::modestacker& stack)
+{
+       ChanData* cd = extItem.get(channel);
+       if (cd)
+       {
+               for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); it++)
+               {
+                       stack.Push(this->GetModeChar(), it->mask);
+               }
+       }
+}
+
+void ListModeBase::DoRehash()
+{
+       ConfigTagList tags = ServerInstance->Config->ConfTags(configtag);
+
+       limitlist oldlimits = chanlimits;
+       chanlimits.clear();
+
+       for (ConfigIter i = tags.first; i != tags.second; i++)
+       {
+               // For each <banlist> tag
+               ConfigTag* c = i->second;
+               ListLimit limit(c->getString("chan"), c->getInt("limit"));
+
+               if (limit.mask.size() && limit.limit > 0)
+                       chanlimits.push_back(limit);
+       }
+
+       if (chanlimits.empty())
+               chanlimits.push_back(ListLimit("*", 64));
+
+       // Most of the time our settings are unchanged, so we can avoid iterating the chanlist
+       if (oldlimits == chanlimits)
+               return;
+
+       for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
+       {
+               ChanData* cd = extItem.get(i->second);
+               if (cd)
+                       cd->maxitems = -1;
+       }
+}
+
+void ListModeBase::DoImplements(Module* m)
+{
+       ServerInstance->Modules->AddService(extItem);
+       this->DoRehash();
+       Implementation eventlist[] = { I_OnSyncChannel, I_OnRehash };
+       ServerInstance->Modules->Attach(eventlist, m, sizeof(eventlist)/sizeof(Implementation));
+}
+
+unsigned int ListModeBase::FindLimit(const std::string& channame)
+{
+       for (limitlist::iterator it = chanlimits.begin(); it != chanlimits.end(); ++it)
+       {
+               if (InspIRCd::Match(channame, it->mask))
+               {
+                       // We have a pattern matching the channel
+                       return it->limit;
+               }
+       }
+       return 64;
+}
+
+unsigned int ListModeBase::GetLimitInternal(const std::string& channame, ChanData* cd)
+{
+       if (cd->maxitems < 0)
+               cd->maxitems = FindLimit(channame);
+       return cd->maxitems;
+}
+
+unsigned int ListModeBase::GetLimit(Channel* channel)
+{
+       ChanData* cd = extItem.get(channel);
+       if (!cd) // just find the limit
+               return FindLimit(channel->name);
+
+       return GetLimitInternal(channel->name, cd);
+}
+
+ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
+{
+       // Try and grab the list
+       ChanData* cd = extItem.get(channel);
+
+       if (adding)
+       {
+               if (tidy)
+                       ModeParser::CleanMask(parameter);
+
+               if (parameter.length() > 250)
+                       return MODEACTION_DENY;
+
+               // If there was no list
+               if (!cd)
+               {
+                       // Make one
+                       cd = new ChanData;
+                       extItem.set(channel, cd);
+               }
+
+               // Check if the item already exists in the list
+               for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); it++)
+               {
+                       if (parameter == it->mask)
+                       {
+                               /* Give a subclass a chance to error about this */
+                               TellAlreadyOnList(source, channel, parameter);
+
+                               // it does, deny the change
+                               return MODEACTION_DENY;
+                       }
+               }
+
+               if ((IS_LOCAL(source)) && (cd->list.size() >= GetLimitInternal(channel->name, cd)))
+               {
+                       /* List is full, give subclass a chance to send a custom message */
+                       TellListTooLong(source, channel, parameter);
+                       parameter.clear();
+                       return MODEACTION_DENY;
+               }
+
+               /* Ok, it *could* be allowed, now give someone subclassing us
+                * a chance to validate the parameter.
+                * The param is passed by reference, so they can both modify it
+                * and tell us if we allow it or not.
+                *
+                * eg, the subclass could:
+                * 1) allow
+                * 2) 'fix' parameter and then allow
+                * 3) deny
+                */
+               if (ValidateParam(source, channel, parameter))
+               {
+                       // And now add the mask onto the list...
+                       cd->list.push_back(ListItem(parameter, source->nick, ServerInstance->Time()));
+                       return MODEACTION_ALLOW;
+               }
+               else
+               {
+                       /* If they deny it they have the job of giving an error message */
+                       return MODEACTION_DENY;
+               }
+       }
+       else
+       {
+               // We're taking the mode off
+               if (cd)
+               {
+                       for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); ++it)
+                       {
+                               if (parameter == it->mask)
+                               {
+                                       cd->list.erase(it);
+                                       return MODEACTION_ALLOW;
+                               }
+                       }
+               }
+
+               /* Tried to remove something that wasn't set */
+               TellNotSet(source, channel, parameter);
+               parameter.clear();
+               return MODEACTION_DENY;
+       }
+}
+
+void ListModeBase::DoSyncChannel(Channel* chan, Module* proto, void* opaque)
+{
+       ChanData* cd = extItem.get(chan);
+       if (!cd)
+               return;
+
+       irc::modestacker modestack(true);
+       std::vector<std::string> stackresult;
+       std::vector<TranslateType> types;
+       types.push_back(TR_TEXT);
+
+       for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); it++)
+               modestack.Push(mode, it->mask);
+
+       while (modestack.GetStackedLine(stackresult))
+       {
+               types.assign(stackresult.size(), this->GetTranslateType());
+               proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, stackresult, types);
+               stackresult.clear();
+       }
+}
+
+bool ListModeBase::ValidateParam(User*, Channel*, std::string&)
+{
+       return true;
+}
+
+void ListModeBase::TellListTooLong(User* source, Channel* channel, std::string& parameter)
+{
+       source->WriteNumeric(478, "%s %s %s :Channel ban list is full", source->nick.c_str(), channel->name.c_str(), parameter.c_str());
+}
+
+void ListModeBase::TellAlreadyOnList(User*, Channel*, std::string&)
+{
+}
+
+void ListModeBase::TellNotSet(User*, Channel*, std::string&)
+{
+}
index 89b2be019721289c241b4839bb591820215b1b84..1a63499d6afaa7b01c334e2fd2b5a55589e9d1b6 100644 (file)
@@ -21,7 +21,6 @@
 
 
 #include "inspircd.h"
-
 #include "filelogger.h"
 
 /*
  *
  */
 
+const char LogStream::LogHeader[] =
+       "Log started for " VERSION " (" REVISION ", " MODULE_INIT_STR ")"
+       " - compiled on " SYSTEM;
+
 LogManager::LogManager()
 {
        Logging = false;
@@ -82,31 +85,31 @@ void LogManager::OpenFileLogs()
                }
                std::string type = tag->getString("type");
                std::string level = tag->getString("level");
-               int loglevel = DEFAULT;
+               LogLevel loglevel = LOG_DEFAULT;
                if (level == "rawio")
                {
-                       loglevel = RAWIO;
+                       loglevel = LOG_RAWIO;
                        ServerInstance->Config->RawLog = true;
                }
                else if (level == "debug")
                {
-                       loglevel = DEBUG;
+                       loglevel = LOG_DEBUG;
                }
                else if (level == "verbose")
                {
-                       loglevel = VERBOSE;
+                       loglevel = LOG_VERBOSE;
                }
                else if (level == "default")
                {
-                       loglevel = DEFAULT;
+                       loglevel = LOG_DEFAULT;
                }
                else if (level == "sparse")
                {
-                       loglevel = SPARSE;
+                       loglevel = LOG_SPARSE;
                }
                else if (level == "none")
                {
-                       loglevel = NONE;
+                       loglevel = LOG_NONE;
                }
                FileWriter* fw;
                std::string target = tag->getString("target");
@@ -126,7 +129,7 @@ void LogManager::OpenFileLogs()
                        fw = fwi->second;
                }
                FileLogStream* fls = new FileLogStream(loglevel, fw);
-               fls->OnLog(SPARSE, "HEADER", InspIRCd::LogHeader);
+               fls->OnLog(LOG_SPARSE, "HEADER", LogStream::LogHeader);
                AddLogTypes(type, fls, true);
        }
 }
@@ -135,13 +138,16 @@ void LogManager::CloseLogs()
 {
        if (ServerInstance->Config && ServerInstance->Config->cmdline.forcedebug)
                return;
-       std::map<std::string, std::vector<LogStream*> >().swap(LogStreams); /* Clear it */
-       std::map<LogStream*, std::vector<std::string> >().swap(GlobalLogStreams); /* Clear it */
+
+       LogStreams.clear();
+       GlobalLogStreams.clear();
+
        for (std::map<LogStream*, int>::iterator i = AllLogStreams.begin(); i != AllLogStreams.end(); ++i)
        {
                delete i->first;
        }
-       std::map<LogStream*, int>().swap(AllLogStreams); /* And clear it */
+
+       AllLogStreams.clear();
 }
 
 void LogManager::AddLogTypes(const std::string &types, LogStream* l, bool autoclose)
@@ -187,36 +193,13 @@ void LogManager::AddLogTypes(const std::string &types, LogStream* l, bool autocl
 
 bool LogManager::AddLogType(const std::string &type, LogStream *l, bool autoclose)
 {
-       std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
-
-       if (i != LogStreams.end())
-       {
-               i->second.push_back(l);
-       }
-       else
-       {
-               std::vector<LogStream *> v;
-               v.push_back(l);
-               LogStreams[type] = v;
-       }
+       LogStreams[type].push_back(l);
 
        if (type == "*")
-       {
                GlobalLogStreams.insert(std::make_pair(l, std::vector<std::string>()));
-       }
 
        if (autoclose)
-       {
-               std::map<LogStream*, int>::iterator ai = AllLogStreams.find(l);
-               if (ai == AllLogStreams.end())
-               {
-                       AllLogStreams.insert(std::make_pair(l, 1));
-               }
-               else
-               {
-                       ++ai->second;
-               }
-       }
+               AllLogStreams[l]++;
 
        return true;
 }
@@ -228,21 +211,18 @@ void LogManager::DelLogStream(LogStream* l)
                std::vector<LogStream*>::iterator it;
                while ((it = std::find(i->second.begin(), i->second.end(), l)) != i->second.end())
                {
-                       if (it == i->second.end())
-                               continue;
                        i->second.erase(it);
                }
        }
-       std::map<LogStream *, std::vector<std::string> >::iterator gi = GlobalLogStreams.find(l);
-       if (gi != GlobalLogStreams.end())
-       {
-               GlobalLogStreams.erase(gi);
-       }
+
+       GlobalLogStreams.erase(l);
+
        std::map<LogStream*, int>::iterator ai = AllLogStreams.begin();
        if (ai == AllLogStreams.end())
        {
                return; /* Done. */
        }
+
        delete ai->first;
        AllLogStreams.erase(ai);
 }
@@ -252,8 +232,7 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l)
        std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
        if (type == "*")
        {
-               std::map<LogStream *, std::vector<std::string> >::iterator gi = GlobalLogStreams.find(l);
-               if (gi != GlobalLogStreams.end()) GlobalLogStreams.erase(gi);
+               GlobalLogStreams.erase(l);
        }
 
        if (i != LogStreams.end())
@@ -293,24 +272,17 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l)
        return true;
 }
 
-void LogManager::Log(const std::string &type, int loglevel, const char *fmt, ...)
+void LogManager::Log(const std::string &type, LogLevel loglevel, const char *fmt, ...)
 {
        if (Logging)
-       {
                return;
-       }
-
-       va_list a;
-       static char buf[65536];
-
-       va_start(a, fmt);
-       vsnprintf(buf, 65536, fmt, a);
-       va_end(a);
 
-       this->Log(type, loglevel, std::string(buf));
+       std::string buf;
+       VAFORMAT(buf, fmt, fmt);
+       this->Log(type, loglevel, buf);
 }
 
-void LogManager::Log(const std::string &type, int loglevel, const std::string &msg)
+void LogManager::Log(const std::string &type, LogLevel loglevel, const std::string &msg)
 {
        if (Logging)
        {
@@ -354,8 +326,8 @@ void FileWriter::WriteLogLine(const std::string &line)
 // XXX: For now, just return. Don't throw an exception. It'd be nice to find out if this is happening, but I'm terrified of breaking so close to final release. -- w00t
 //             throw CoreException("FileWriter::WriteLogLine called with a closed logfile");
 
-       fprintf(log,"%s",line.c_str());
-       if (writeops++ % 20)
+       fputs(line.c_str(), log);
+       if (++writeops % 20 == 0)
        {
                fflush(log);
        }
index e2b0c2f6893f5a86dced6da289563c5a5f7e3d19..578fc2c27a518469d35db84ea721ce05bf921df7 100644 (file)
 
 
 #include "inspircd.h"
-
-/* +s (secret) */
-/* +p (private) */
-/* +m (moderated) */
-/* +t (only (half) ops can change topic) */
-/* +n (no external messages) */
-/* +i (invite only) */
-/* +w (see wallops) */
-/* +i (invisible) */
-#include "modes/simplemodes.h"
-/* +b (bans) */
-#include "modes/cmode_b.h"
-/* +k (keyed channel) */
-#include "modes/cmode_k.h"
-/* +l (channel user limit) */
-#include "modes/cmode_l.h"
-/* +o (channel op) */
-#include "modes/cmode_o.h"
-/* +v (channel voice) */
-#include "modes/cmode_v.h"
-/* +o (operator) */
-#include "modes/umode_o.h"
-/* +s (server notice masks) */
-#include "modes/umode_s.h"
+#include "builtinmodes.h"
 
 ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modeletter, ParamSpec Params, ModeType type)
        : ServiceProvider(Creator, Name, SERVICE_MODE), m_paramtype(TR_TEXT),
@@ -67,11 +44,6 @@ ModeHandler::~ModeHandler()
 {
 }
 
-bool ModeHandler::IsListMode()
-{
-       return list;
-}
-
 unsigned int ModeHandler::GetPrefixRank()
 {
        return 0;
@@ -179,8 +151,8 @@ bool ParamChannelModeHandler::ParamValidate(std::string& parameter)
        return true;
 }
 
-ModeWatcher::ModeWatcher(Module* Creator, char modeletter, ModeType type)
-       : mode(modeletter), m_type(type), creator(Creator)
+ModeWatcher::ModeWatcher(Module* Creator, const std::string& modename, ModeType type)
+       : mode(modename), m_type(type), creator(Creator)
 {
 }
 
@@ -188,41 +160,20 @@ ModeWatcher::~ModeWatcher()
 {
 }
 
-char ModeWatcher::GetModeChar()
-{
-       return mode;
-}
-
 ModeType ModeWatcher::GetModeType()
 {
        return m_type;
 }
 
-bool ModeWatcher::BeforeMode(User*, User*, Channel*, std::string&, bool, ModeType)
+bool ModeWatcher::BeforeMode(User*, User*, Channel*, std::string&, bool)
 {
        return true;
 }
 
-void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool, ModeType)
+void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool)
 {
 }
 
-User* ModeParser::SanityChecks(User *user, const char *dest, Channel *chan, int)
-{
-       User *d;
-       if ((!user) || (!dest) || (!chan) || (!*dest))
-       {
-               return NULL;
-       }
-       d = ServerInstance->FindNick(dest);
-       if (!d)
-       {
-               user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), dest);
-               return NULL;
-       }
-       return d;
-}
-
 void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text)
 {
        if (targetchannel)
@@ -238,7 +189,7 @@ void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targ
                {
                        /* Display user's current mode string */
                        user->WriteNumeric(RPL_UMODEIS, "%s :+%s",targetuser->nick.c_str(),targetuser->FormatModes());
-                       if (IS_OPER(targetuser))
+                       if ((targetuser->IsOper()))
                                user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks());
                        return;
                }
@@ -254,7 +205,6 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
                std::string &parameter, bool SkipACL)
 {
        ModeType type = chan ? MODETYPE_CHANNEL : MODETYPE_USER;
-       unsigned char mask = chan ? MASK_CHANNEL : MASK_USER;
 
        ModeHandler *mh = FindMode(modechar, type);
        int pcnt = mh->GetNumParams(adding);
@@ -308,18 +258,23 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
                }
        }
 
-       unsigned char handler_id = (modechar - 'A') | mask;
-
-       for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
+       // Ask mode watchers whether this mode change is OK
+       std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mh->name);
+       for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
        {
-               if ((*watchers)->BeforeMode(user, targetuser, chan, parameter, adding, type) == false)
-                       return MODEACTION_DENY;
-               /* A module whacked the parameter completely, and there was one. abort. */
-               if (pcnt && parameter.empty())
-                       return MODEACTION_DENY;
+               ModeWatcher* mw = i->second;
+               if (mw->GetModeType() == type)
+               {
+                       if (!mw->BeforeMode(user, targetuser, chan, parameter, adding))
+                               return MODEACTION_DENY;
+
+                       // A module whacked the parameter completely, and there was one. Abort.
+                       if (pcnt && parameter.empty())
+                               return MODEACTION_DENY;
+               }
        }
 
-       if (IS_LOCAL(user) && !IS_OPER(user))
+       if (IS_LOCAL(user) && !user->IsOper())
        {
                char* disabled = (type == MODETYPE_CHANNEL) ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes;
                if (disabled[modechar - 'A'])
@@ -333,10 +288,10 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
        if (adding && IS_LOCAL(user) && mh->NeedsOper() && !user->HasModePermission(modechar, type))
        {
                /* It's an oper only mode, and they don't have access to it. */
-               if (IS_OPER(user))
+               if (user->IsOper())
                {
                        user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper type %s does not have access to set %s mode %c",
-                                       user->nick.c_str(), user->oper->NameStr(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar);
+                                       user->nick.c_str(), user->oper->name.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar);
                }
                else
                {
@@ -370,8 +325,13 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
        if (ma != MODEACTION_ALLOW)
                return ma;
 
-       for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
-               (*watchers)->AfterMode(user, targetuser, chan, parameter, adding, type);
+       itpair = modewatchermap.equal_range(mh->name);
+       for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
+       {
+               ModeWatcher* mw = i->second;
+               if (mw->GetModeType() == type)
+                       mw->AfterMode(user, targetuser, chan, parameter, adding);
+       }
 
        return MODEACTION_ALLOW;
 }
@@ -566,15 +526,24 @@ void ModeParser::DisplayListModes(User* user, Channel* chan, std::string &mode_s
                        display = false;
                }
 
-               unsigned char handler_id = (mletter - 'A') | MASK_CHANNEL;
-
-               for(ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
+               // Ask mode watchers whether it's OK to show the list
+               std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mh->name);
+               for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
                {
-                       std::string dummyparam;
+                       ModeWatcher* mw = i->second;
+                       if (mw->GetModeType() == MODETYPE_CHANNEL)
+                       {
+                               std::string dummyparam;
 
-                       if (!((*watchers)->BeforeMode(user, NULL, chan, dummyparam, true, MODETYPE_CHANNEL)))
-                               display = false;
+                               if (!mw->BeforeMode(user, NULL, chan, dummyparam, true))
+                               {
+                                       // A mode watcher doesn't want us to show the list
+                                       display = false;
+                                       break;
+                               }
+                       }
                }
+
                if (display)
                        mh->DisplayList(user, chan);
                else
@@ -582,11 +551,6 @@ void ModeParser::DisplayListModes(User* user, Channel* chan, std::string &mode_s
        }
 }
 
-const std::string& ModeParser::GetLastParse()
-{
-       return LastParse;
-}
-
 void ModeParser::CleanMask(std::string &mask)
 {
        std::string::size_type pos_of_pling = mask.find_first_of('!');
@@ -652,6 +616,7 @@ bool ModeParser::AddMode(ModeHandler* mh)
                return false;
 
        modehandlers[pos] = mh;
+       RecreateModeListFor004Numeric();
        return true;
 }
 
@@ -688,12 +653,23 @@ bool ModeParser::DelMode(ModeHandler* mh)
                                // The channel may not be in the hash after RemoveMode(), see m_permchannels
                                Channel* chan = i->second;
                                ++i;
-                               mh->RemoveMode(chan);
+
+                               irc::modestacker stack(false);
+                               mh->RemoveMode(chan, stack);
+
+                               std::vector<std::string> stackresult;
+                               stackresult.push_back(chan->name);
+                               while (stack.GetStackedLine(stackresult))
+                               {
+                                       ServerInstance->SendMode(stackresult, ServerInstance->FakeClient);
+                                       stackresult.erase(stackresult.begin() + 1, stackresult.end());
+                               }
                        }
                break;
        }
 
        modehandlers[pos] = NULL;
+       RecreateModeListFor004Numeric();
 
        return true;
 }
@@ -712,52 +688,25 @@ ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
        return modehandlers[pos];
 }
 
-std::string ModeParser::UserModeList()
+std::string ModeParser::CreateModeList(ModeType mt, bool needparam)
 {
-       char modestr[256];
-       int pointer = 0;
+       std::string modestr;
+       unsigned char mask = ((mt == MODETYPE_CHANNEL) ? MASK_CHANNEL : MASK_USER);
 
        for (unsigned char mode = 'A'; mode <= 'z'; mode++)
        {
-               unsigned char pos = (mode-65) | MASK_USER;
+               unsigned char pos = (mode-65) | mask;
 
-               if (modehandlers[pos])
-                       modestr[pointer++] = mode;
+               if ((modehandlers[pos]) && ((!needparam) || (modehandlers[pos]->GetNumParams(true))))
+                       modestr.push_back(mode);
        }
-       modestr[pointer++] = 0;
-       return modestr;
-}
 
-std::string ModeParser::ChannelModeList()
-{
-       char modestr[256];
-       int pointer = 0;
-
-       for (unsigned char mode = 'A'; mode <= 'z'; mode++)
-       {
-               unsigned char pos = (mode-65) | MASK_CHANNEL;
-
-               if (modehandlers[pos])
-                       modestr[pointer++] = mode;
-       }
-       modestr[pointer++] = 0;
        return modestr;
 }
 
-std::string ModeParser::ParaModeList()
+void ModeParser::RecreateModeListFor004Numeric()
 {
-       char modestr[256];
-       int pointer = 0;
-
-       for (unsigned char mode = 'A'; mode <= 'z'; mode++)
-       {
-               unsigned char pos = (mode-65) | MASK_CHANNEL;
-
-               if ((modehandlers[pos]) && (modehandlers[pos]->GetNumParams(true)))
-                       modestr[pointer++] = mode;
-       }
-       modestr[pointer++] = 0;
-       return modestr;
+       Cached004ModeList = CreateModeList(MODETYPE_USER) + " " + CreateModeList(MODETYPE_CHANNEL) + " " + CreateModeList(MODETYPE_CHANNEL, true);
 }
 
 ModeHandler* ModeParser::FindPrefix(unsigned const char pfxletter)
@@ -847,91 +796,62 @@ std::string ModeParser::BuildPrefixes(bool lettersAndModes)
        return lettersAndModes ? "(" + mprefixes + ")" + mletters : mletters;
 }
 
-bool ModeParser::AddModeWatcher(ModeWatcher* mw)
+void ModeParser::AddModeWatcher(ModeWatcher* mw)
 {
-       unsigned char mask = 0;
-       unsigned char pos = 0;
-
-       if (!mw)
-               return false;
-
-       if ((mw->GetModeChar() < 'A') || (mw->GetModeChar() > 'z'))
-               return false;
-
-       mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
-       pos = (mw->GetModeChar()-65) | mask;
-
-       modewatchers[pos].push_back(mw);
-
-       return true;
+       modewatchermap.insert(std::make_pair(mw->GetModeName(), mw));
 }
 
 bool ModeParser::DelModeWatcher(ModeWatcher* mw)
 {
-       unsigned char mask = 0;
-       unsigned char pos = 0;
-
-       if (!mw)
-               return false;
-
-       if ((mw->GetModeChar() < 'A') || (mw->GetModeChar() > 'z'))
-               return false;
-
-       mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
-       pos = (mw->GetModeChar()-65) | mask;
-
-       ModeWatchIter a = find(modewatchers[pos].begin(),modewatchers[pos].end(),mw);
-
-       if (a == modewatchers[pos].end())
+       std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mw->GetModeName());
+       for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
        {
-               return false;
+               if (i->second == mw)
+               {
+                       modewatchermap.erase(i);
+                       return true;
+               }
        }
 
-       modewatchers[pos].erase(a);
-
-       return true;
+       return false;
 }
 
-/** This default implementation can remove simple user modes
- */
-void ModeHandler::RemoveMode(User* user, irc::modestacker* stack)
+void ModeHandler::RemoveMode(User* user)
 {
+       // Remove the mode if it's set on the user
        if (user->IsModeSet(this->GetModeChar()))
        {
-               if (stack)
-               {
-                       stack->Push(this->GetModeChar());
-               }
-               else
-               {
-                       std::vector<std::string> parameters;
-                       parameters.push_back(user->nick);
-                       parameters.push_back("-");
-                       parameters[1].push_back(this->GetModeChar());
-                       ServerInstance->Modes->Process(parameters, ServerInstance->FakeClient);
-               }
+               std::vector<std::string> parameters;
+               parameters.push_back(user->nick);
+               parameters.push_back("-");
+               parameters[1].push_back(this->GetModeChar());
+               ServerInstance->Modes->Process(parameters, ServerInstance->FakeClient);
        }
 }
 
-/** This default implementation can remove simple channel modes
- * (no parameters)
- */
-void ModeHandler::RemoveMode(Channel* channel, irc::modestacker* stack)
+void ModeHandler::RemoveMode(Channel* channel, irc::modestacker& stack)
 {
-       if (channel->IsModeSet(this->GetModeChar()))
+       if (this->GetPrefixRank())
        {
-               if (stack)
-               {
-                       stack->Push(this->GetModeChar());
-               }
+               RemovePrefixMode(channel, stack);
+       }
+       else if (channel->IsModeSet(this->GetModeChar()))
+       {
+               if (this->GetNumParams(false))
+                       // Removing this mode requires a parameter
+                       stack.Push(this->GetModeChar(), channel->GetModeParameter(this->GetModeChar()));
                else
-               {
-                       std::vector<std::string> parameters;
-                       parameters.push_back(channel->name);
-                       parameters.push_back("-");
-                       parameters[1].push_back(this->GetModeChar());
-                       ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
-               }
+                       stack.Push(this->GetModeChar());
+       }
+}
+
+void ModeHandler::RemovePrefixMode(Channel* chan, irc::modestacker& stack)
+{
+       const UserMembList* userlist = chan->GetUsers();
+       for (UserMembCIter i = userlist->begin(); i != userlist->end(); ++i)
+       {
+               if (i->second->hasMode(this->GetModeChar()))
+                       stack.Push(this->GetModeChar(), i->first->nick);
        }
 }
 
@@ -956,28 +876,22 @@ struct builtin_modes
        ModeUserOperator uo;
        ModeUserServerNoticeMask us;
 
-       void init(ModeParser* modes)
-       {
-               modes->AddMode(&s);
-               modes->AddMode(&p);
-               modes->AddMode(&m);
-               modes->AddMode(&t);
-               modes->AddMode(&n);
-               modes->AddMode(&i);
-               modes->AddMode(&k);
-               modes->AddMode(&l);
-               modes->AddMode(&b);
-               modes->AddMode(&o);
-               modes->AddMode(&v);
-               modes->AddMode(&uw);
-               modes->AddMode(&ui);
-               modes->AddMode(&uo);
-               modes->AddMode(&us);
+       void init()
+       {
+               ServiceProvider* modes[] = { &s, &p, &m, &t, &n, &i, &k, &l, &b, &o, &v,
+                                                                        &uw, &ui, &uo, &us };
+               ServerInstance->Modules->AddServices(modes, sizeof(modes)/sizeof(ServiceProvider*));
        }
 };
 
 static builtin_modes static_modes;
 
+void ModeParser::InitBuiltinModes()
+{
+       static_modes.init();
+       static_modes.b.DoRehash();
+}
+
 ModeParser::ModeParser()
 {
        /* Clear mode handler list */
@@ -988,8 +902,6 @@ ModeParser::ModeParser()
 
        seq = 0;
        memset(&sent, 0, sizeof(sent));
-
-       static_modes.init(this);
 }
 
 ModeParser::~ModeParser()
diff --git a/src/modes/cmode_b.cpp b/src/modes/cmode_b.cpp
deleted file mode 100644 (file)
index 09df051..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "inspircd.h"
-#include <string>
-#include <vector>
-#include "inspircd_config.h"
-#include "configreader.h"
-#include "hash_map.h"
-#include "mode.h"
-#include "channels.h"
-#include "users.h"
-#include "modules.h"
-#include "inspstring.h"
-#include "hashcomp.h"
-#include "modes/cmode_b.h"
-
-ModeChannelBan::ModeChannelBan() : ModeHandler(NULL, "ban", 'b', PARAM_ALWAYS, MODETYPE_CHANNEL)
-{
-       list = true;
-}
-
-ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
-{
-       int status = channel->GetPrefixValue(source);
-       /* Call the correct method depending on wether we're adding or removing the mode */
-       if (adding)
-       {
-               this->AddBan(source, parameter, channel, status);
-       }
-       else
-       {
-               this->DelBan(source, parameter, channel, status);
-       }
-       /* If the method above 'ate' the parameter by reducing it to an empty string, then
-        * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
-        * the return value and is always MODEACTION_DENY if the mode is supposed to have
-        * a parameter.
-        */
-       return MODEACTION_ALLOW;
-}
-
-void ModeChannelBan::RemoveMode(Channel* channel, irc::modestacker* stack)
-{
-       BanList copy;
-
-       for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
-       {
-               copy.push_back(*i);
-       }
-
-       for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
-       {
-               if (stack)
-               {
-                       stack->Push(this->GetModeChar(), i->data);
-               }
-               else
-               {
-                       std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data);
-                       ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
-               }
-       }
-}
-
-void ModeChannelBan::RemoveMode(User*, irc::modestacker* stack)
-{
-}
-
-void ModeChannelBan::DisplayList(User* user, Channel* channel)
-{
-       /* Display the channel banlist */
-       for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
-       {
-               user->WriteServ("367 %s %s %s %s %lu",user->nick.c_str(), channel->name.c_str(), i->data.c_str(), i->set_by.c_str(), (unsigned long)i->set_time);
-       }
-       user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
-       return;
-}
-
-void ModeChannelBan::DisplayEmptyList(User* user, Channel* channel)
-{
-       user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
-}
-
-std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int)
-{
-       if ((!user) || (!chan))
-       {
-               ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
-               dest.clear();
-               return dest;
-       }
-
-       /* Attempt to tidy the mask */
-       ModeParser::CleanMask(dest);
-       /* If the mask was invalid, we exit */
-       if (dest.empty() || dest.length() > 250)
-               return dest;
-
-       long maxbans = chan->GetMaxBans();
-       if (IS_LOCAL(user) && ((unsigned)chan->bans.size() >= (unsigned)maxbans))
-       {
-               user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %ld)",user->nick.c_str(), chan->name.c_str(), chan->name.c_str(), maxbans);
-               dest.clear();
-               return dest;
-       }
-
-       ModResult MOD_RESULT;
-       FIRST_MOD_RESULT(OnAddBan, MOD_RESULT, (user,chan,dest));
-       if (MOD_RESULT == MOD_RES_DENY)
-       {
-               dest.clear();
-               return dest;
-       }
-
-       for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
-       {
-               if (i->data == dest)
-               {
-                       /* dont allow a user to set the same ban twice */
-                       dest.clear();
-                       return dest;
-               }
-       }
-
-       b.set_time = ServerInstance->Time();
-       b.data.assign(dest, 0, MAXBUF);
-       b.set_by.assign(user->nick, 0, 64);
-       chan->bans.push_back(b);
-       return dest;
-}
-
-std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
-{
-       if ((!user) || (!chan))
-       {
-               ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
-               dest.clear();
-               return dest;
-       }
-
-       for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
-       {
-               if (!strcasecmp(i->data.c_str(), dest.c_str()))
-               {
-                       ModResult MOD_RESULT;
-                       FIRST_MOD_RESULT(OnDelBan, MOD_RESULT, (user, chan, dest));
-                       if (MOD_RESULT == MOD_RES_DENY)
-                       {
-                               dest.clear();
-                               return dest;
-                       }
-                       chan->bans.erase(i);
-                       return dest;
-               }
-       }
-       dest.clear();
-       return dest;
-}
-
index 400333fced175133e4b1cdac3e9b1e2921c9a4af..cb9ec5b0ec4246375f9d322b97c0d0f50e57458f 100644 (file)
 #include "mode.h"
 #include "channels.h"
 #include "users.h"
-#include "modes/cmode_k.h"
+#include "builtinmodes.h"
 
 ModeChannelKey::ModeChannelKey() : ModeHandler(NULL, "key", 'k', PARAM_ALWAYS, MODETYPE_CHANNEL)
 {
 }
 
-void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
-{
-       /** +k needs a parameter when being removed,
-        * so we have a special-case RemoveMode here for it
-        */
-
-       if (channel->IsModeSet('k'))
-       {
-               if (stack)
-               {
-                       stack->Push('k', channel->GetModeParameter('k'));
-               }
-               else
-               {
-                       std::vector<std::string> parameters;
-                       parameters.push_back(channel->name);
-                       parameters.push_back("-k");
-                       parameters.push_back(channel->GetModeParameter('k'));
-                       ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
-               }
-       }
-}
-
-void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
-{
-}
-
 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
 {
        bool exists = channel->IsModeSet('k');
index 001d058bbfab9c6b2132f2e90706a63a2b19284e..f057a75e6f000b12570569c50396a57e0f73f3b9 100644 (file)
@@ -23,7 +23,7 @@
 #include "mode.h"
 #include "channels.h"
 #include "users.h"
-#include "modes/cmode_l.h"
+#include "builtinmodes.h"
 
 ModeChannelLimit::ModeChannelLimit() : ParamChannelModeHandler(NULL, "limit", 'l')
 {
index 0a13b39ce0101cd5fb0a1afe4b39614cbd67e6f5..f0a7294800af1741816209ee12ebed5f417f3124 100644 (file)
@@ -26,7 +26,7 @@
 #include "channels.h"
 #include "users.h"
 #include "modules.h"
-#include "modes/cmode_o.h"
+#include "builtinmodes.h"
 
 ModeChannelOp::ModeChannelOp() : ModeHandler(NULL, "op", 'o', PARAM_ALWAYS, MODETYPE_CHANNEL)
 {
@@ -41,29 +41,6 @@ unsigned int ModeChannelOp::GetPrefixRank()
        return OP_VALUE;
 }
 
-void ModeChannelOp::RemoveMode(Channel* channel, irc::modestacker* stack)
-{
-       const UserMembList* clist = channel->GetUsers();
-
-       for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
-       {
-               if (stack)
-                       stack->Push(this->GetModeChar(), i->first->nick);
-               else
-               {
-                       std::vector<std::string> parameters;
-                       parameters.push_back(channel->name);
-                       parameters.push_back("-o");
-                       parameters.push_back(i->first->nick);
-                       ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
-               }
-       }
-}
-
-void ModeChannelOp::RemoveMode(User*, irc::modestacker* stack)
-{
-}
-
 ModeAction ModeChannelOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
 {
        return MODEACTION_ALLOW;
index 4a00f60f1804818574818201e0071fe0b3a41e34..867c132431d9e74107c53a71be30e5609ad2d4e9 100644 (file)
@@ -26,7 +26,7 @@
 #include "channels.h"
 #include "users.h"
 #include "modules.h"
-#include "modes/cmode_v.h"
+#include "builtinmodes.h"
 
 ModeChannelVoice::ModeChannelVoice() : ModeHandler(NULL, "voice", 'v', PARAM_ALWAYS, MODETYPE_CHANNEL)
 {
@@ -41,29 +41,6 @@ unsigned int ModeChannelVoice::GetPrefixRank()
        return VOICE_VALUE;
 }
 
-void ModeChannelVoice::RemoveMode(Channel* channel, irc::modestacker* stack)
-{
-       const UserMembList* clist = channel->GetUsers();
-
-       for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
-       {
-               if (stack)
-                       stack->Push(this->GetModeChar(), i->first->nick);
-               else
-               {
-                       std::vector<std::string> parameters;
-                       parameters.push_back(channel->name);
-                       parameters.push_back("-v");
-                       parameters.push_back(i->first->nick);
-                       ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
-               }
-       }
-}
-
-void ModeChannelVoice::RemoveMode(User*, irc::modestacker* stack)
-{
-}
-
 ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
 {
        return MODEACTION_ALLOW;
index a5f590ba03dc03c8091a276c326fe2431c6f8bd3..45b99b1d6d0ac6fc9686fcd5786cb92f64967aad 100644 (file)
@@ -22,7 +22,7 @@
 #include "mode.h"
 #include "channels.h"
 #include "users.h"
-#include "modes/umode_o.h"
+#include "builtinmodes.h"
 
 ModeUserOperator::ModeUserOperator() : ModeHandler(NULL, "oper", 'o', PARAM_NONE, MODETYPE_USER)
 {
@@ -32,7 +32,7 @@ ModeUserOperator::ModeUserOperator() : ModeHandler(NULL, "oper", 'o', PARAM_NONE
 ModeAction ModeUserOperator::OnModeChange(User* source, User* dest, Channel*, std::string&, bool adding)
 {
        /* Only opers can execute this class at all */
-       if (!ServerInstance->ULine(source->server) && !IS_OPER(source))
+       if (!ServerInstance->ULine(source->server) && !source->IsOper())
                return MODEACTION_DENY;
 
        /* Not even opers can GIVE the +o mode, only take it away */
index 1b782ae853dbd74444c61e5a087a71b2823c5b63..9473d760eace65c8b0dc48d841aa404a1747bb34 100644 (file)
@@ -23,7 +23,7 @@
 #include "mode.h"
 #include "channels.h"
 #include "users.h"
-#include "modes/umode_s.h"
+#include "builtinmodes.h"
 
 ModeUserServerNoticeMask::ModeUserServerNoticeMask() : ModeHandler(NULL, "snomask", 's', PARAM_SETONLY, MODETYPE_USER)
 {
@@ -66,7 +66,5 @@ std::string ModeUserServerNoticeMask::GetUserParameter(User* user)
 
 void ModeUserServerNoticeMask::OnParameterMissing(User* user, User* dest, Channel* channel)
 {
-       user->WriteServ("NOTICE %s :*** The user mode +s requires a parameter (server notice mask). Please provide a parameter, e.g. '+s +*'.",
-                       user->nick.c_str());
+       user->WriteNotice("*** The user mode +s requires a parameter (server notice mask). Please provide a parameter, e.g. '+s +*'.");
 }
-
index 7dae49a18dc729009a1118e503dd0d3cff603589..b9c046a8e78e67959669147072881fc39a455a42 100644 (file)
@@ -22,7 +22,6 @@
 #include "socket.h"
 #include "socketengine.h"
 #include "command_parse.h"
-#include "dns.h"
 #include "exitcodes.h"
 #include <iostream>
 
@@ -38,25 +37,24 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
        if (filename.find('/') != std::string::npos)
                return false;
 
-       char modfile[MAXBUF];
-       snprintf(modfile,MAXBUF,"%s/%s",ServerInstance->Config->ModPath.c_str(),filename.c_str());
+       const std::string moduleFile = ServerInstance->Config->ModPath + "/" + filename;
 
-       if (!ServerConfig::FileExists(modfile))
+       if (!ServerConfig::FileExists(moduleFile.c_str()))
        {
                LastModuleError = "Module file could not be found: " + filename;
-               ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                return false;
        }
 
        if (Modules.find(filename) != Modules.end())
        {
                LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
-               ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                return false;
        }
 
        Module* newmod = NULL;
-       DLLManager* newhandle = new DLLManager(modfile);
+       DLLManager* newhandle = new DLLManager(moduleFile.c_str());
 
        try
        {
@@ -71,7 +69,7 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
                        std::string version = newhandle->GetVersion();
                        if (defer)
                        {
-                               ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)",
+                               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
                                        filename.c_str(), version.c_str());
                        }
                        else
@@ -79,14 +77,14 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
                                newmod->init();
 
                                Version v = newmod->GetVersion();
-                               ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s",
+                               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
                                        filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
                        }
                }
                else
                {
                        LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                        delete newhandle;
                        return false;
                }
@@ -102,7 +100,7 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
                else
                        delete newhandle;
                LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
-               ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                return false;
        }
 
@@ -124,10 +122,10 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
                if (prioritizationState == PRIO_STATE_LAST)
                        break;
                if (tries == 19)
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected while loading " + filename);
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Hook priority dependency loop detected while loading " + filename);
        }
 
-       ServerInstance->BuildISupport();
+       ServerInstance->ISupport.Build();
        return true;
 }
 
@@ -204,7 +202,7 @@ void ModuleManager::LoadAll()
 
                                if (!Load(entry->d_name, true))
                                {
-                                       ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
+                                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
                                        std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
                                        ServerInstance->Exit(EXIT_STATUS_MODULE);
                                }
@@ -223,7 +221,7 @@ void ModuleManager::LoadAll()
 
                if (!this->Load(name, true))
                {
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
                        std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
                        ServerInstance->Exit(EXIT_STATUS_MODULE);
                }
@@ -234,13 +232,13 @@ void ModuleManager::LoadAll()
                Module* mod = i->second;
                try
                {
-                       ServerInstance->Logs->Log("MODULE", DEBUG, "Initializing %s", i->first.c_str());
+                       ServerInstance->Logs->Log("MODULE", LOG_DEBUG, "Initializing %s", i->first.c_str());
                        mod->init();
                }
                catch (CoreException& modexcept)
                {
                        LastModuleError = "Unable to initialize " + mod->ModuleSourceFile + ": " + modexcept.GetReason();
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                        std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << LastModuleError << std::endl << std::endl;
                        ServerInstance->Exit(EXIT_STATUS_MODULE);
                }
@@ -260,7 +258,7 @@ void ModuleManager::LoadAll()
                        break;
                if (tries == 19)
                {
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected");
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Hook priority dependency loop detected");
                        ServerInstance->Exit(EXIT_STATUS_MODULE);
                }
        }
index 8f532ee80c9b0077a9d49b3e009af95238f63b39..54813896e43bab568fe7f3d84dcf1448a2cf2ce1 100644 (file)
@@ -97,7 +97,7 @@ bool ModuleManager::Load(const std::string& name, bool defer)
                Modules[name] = mod;
                if (defer)
                {
-                       ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s", name.c_str());
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s", name.c_str());
                        return true;
                }
                else
@@ -109,7 +109,7 @@ bool ModuleManager::Load(const std::string& name, bool defer)
        {
                if (mod)
                        DoSafeUnload(mod);
-               ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason());
+               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason());
                return false;
        }
        FOREACH_MOD(I_OnLoadModule,OnLoadModule(mod));
@@ -126,10 +126,10 @@ bool ModuleManager::Load(const std::string& name, bool defer)
                if (prioritizationState == PRIO_STATE_LAST)
                        break;
                if (tries == 19)
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected while loading " + name);
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Hook priority dependency loop detected while loading " + name);
        }
 
-       ServerInstance->BuildISupport();
+       ServerInstance->ISupport.Build();
        return true;
 }
 
@@ -195,7 +195,7 @@ void ModuleManager::LoadAll()
 
                if (!this->Load(name, true))
                {
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
                        std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
                        ServerInstance->Exit(EXIT_STATUS_MODULE);
                }
@@ -204,14 +204,14 @@ void ModuleManager::LoadAll()
        for(std::map<std::string, Module*>::iterator i = Modules.begin(); i != Modules.end(); i++)
        {
                Module* mod = i->second;
-               try 
+               try
                {
                        mod->init();
                }
                catch (CoreException& modexcept)
                {
                        LastModuleError = "Unable to initialize " + mod->ModuleSourceFile + ": " + modexcept.GetReason();
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                        std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << LastModuleError << std::endl << std::endl;
                        ServerInstance->Exit(EXIT_STATUS_MODULE);
                }
@@ -231,7 +231,7 @@ void ModuleManager::LoadAll()
                        break;
                if (tries == 19)
                {
-                       ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected");
+                       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Hook priority dependency loop detected");
                        ServerInstance->Exit(EXIT_STATUS_MODULE);
                }
        }
index d25e145e3fdaa19ec1f61a4b312e42d68f1b3cd6..acd80323d7b18881a2b18b857b9ccb579e8d3154 100644 (file)
  */
 
 
+#include <fstream>
 #include "inspircd.h"
 #include "xline.h"
 #include "socket.h"
 #include "socketengine.h"
 #include "command_parse.h"
-#include "dns.h"
 #include "exitcodes.h"
 
 #ifndef _WIN32
 #endif
 
 static std::vector<dynamic_reference_base*>* dynrefs = NULL;
+static bool dynref_init_complete = false;
 
 void dynamic_reference_base::reset_all()
 {
+       dynref_init_complete = true;
        if (!dynrefs)
                return;
        for(unsigned int i = 0; i < dynrefs->size(); i++)
-               (*dynrefs)[i]->ClearCache();
+               (*dynrefs)[i]->resolve();
 }
 
 // Version is a simple class for holding a modules version number
@@ -95,19 +97,18 @@ void                Module::OnUserPart(Membership*, std::string&, CUList&) { }
 void           Module::OnPreRehash(User*, const std::string&) { }
 void           Module::OnModuleRehash(User*, const std::string&) { }
 void           Module::OnRehash(User*) { }
-ModResult      Module::OnUserPreJoin(User*, Channel*, const char*, std::string&, const std::string&) { return MOD_RES_PASSTHRU; }
+ModResult      Module::OnUserPreJoin(LocalUser*, Channel*, const std::string&, std::string&, const std::string&) { return MOD_RES_PASSTHRU; }
 void           Module::OnMode(User*, void*, int, const std::vector<std::string>&, const std::vector<TranslateType>&) { }
 void           Module::OnOper(User*, const std::string&) { }
 void           Module::OnPostOper(User*, const std::string&, const std::string &) { }
 void           Module::OnInfo(User*) { }
 void           Module::OnWhois(User*, User*) { }
 ModResult      Module::OnUserPreInvite(User*, User*, Channel*, time_t) { return MOD_RES_PASSTHRU; }
-ModResult      Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; }
-ModResult      Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; }
+ModResult      Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&, MessageType) { return MOD_RES_PASSTHRU; }
 ModResult      Module::OnUserPreNick(User*, const std::string&) { return MOD_RES_PASSTHRU; }
 void           Module::OnUserPostNick(User*, const std::string&) { }
 ModResult      Module::OnPreMode(User*, User*, Channel*, const std::vector<std::string>&) { return MOD_RES_PASSTHRU; }
-void           Module::On005Numeric(std::string&) { }
+void           Module::On005Numeric(std::map<std::string, std::string>&) { }
 ModResult      Module::OnKill(User*, User*, const std::string&) { return MOD_RES_PASSTHRU; }
 void           Module::OnLoadModule(Module*) { }
 void           Module::OnUnloadModule(Module*) { }
@@ -135,15 +136,12 @@ void              Module::OnRequest(Request&) { }
 ModResult      Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { return MOD_RES_PASSTHRU; }
 void           Module::OnGlobalOper(User*) { }
 void           Module::OnPostConnect(User*) { }
-ModResult      Module::OnAddBan(User*, Channel*, const std::string &) { return MOD_RES_PASSTHRU; }
-ModResult      Module::OnDelBan(User*, Channel*, const std::string &) { return MOD_RES_PASSTHRU; }
 void           Module::OnStreamSocketAccept(StreamSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { }
 int            Module::OnStreamSocketWrite(StreamSocket*, std::string&) { return -1; }
 void           Module::OnStreamSocketClose(StreamSocket*) { }
 void           Module::OnStreamSocketConnect(StreamSocket*) { }
 int            Module::OnStreamSocketRead(StreamSocket*, std::string&) { return -1; }
-void           Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&) { }
-void           Module::OnUserNotice(User*, void*, int, const std::string&, char, const CUList&) { }
+void           Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { }
 void           Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { }
 void           Module::OnUserInvite(User*, User*, Channel*, time_t) { }
 void           Module::OnPostTopicChange(User*, Channel*, const std::string&) { }
@@ -154,7 +152,6 @@ void                Module::OnSyncNetwork(Module*, void*) { }
 void           Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::vector<std::string>&, const std::vector<TranslateType>&) { }
 void           Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { }
 void           Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { }
-void           Module::OnWallops(User*, const std::string&) { }
 void           Module::OnChangeHost(User*, const std::string&) { }
 void           Module::OnChangeName(User*, const std::string&) { }
 void           Module::OnChangeIdent(User*, const std::string&) { }
@@ -331,13 +328,13 @@ bool ModuleManager::CanUnload(Module* mod)
        if ((modfind == Modules.end()) || (modfind->second != mod) || (mod->dying))
        {
                LastModuleError = "Module " + mod->ModuleSourceFile + " is not loaded, cannot unload it!";
-               ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                return false;
        }
        if (mod->GetVersion().Flags & VF_STATIC)
        {
                LastModuleError = "Module " + mod->ModuleSourceFile + " not unloadable (marked static)";
-               ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
+               ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
                return false;
        }
 
@@ -347,6 +344,11 @@ bool ModuleManager::CanUnload(Module* mod)
 
 void ModuleManager::DoSafeUnload(Module* mod)
 {
+       // First, notify all modules that a module is about to be unloaded, so in case
+       // they pass execution to the soon to be unloaded module, it will happen now,
+       // i.e. before we unregister the services of the module being unloaded
+       FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(mod));
+
        std::map<std::string, Module*>::iterator modfind = Modules.find(mod->ModuleSourceFile);
 
        std::vector<reference<ExtensionItem> > items;
@@ -370,10 +372,10 @@ void ModuleManager::DoSafeUnload(Module* mod)
                ModeHandler* mh;
                mh = ServerInstance->Modes->FindMode(m, MODETYPE_USER);
                if (mh && mh->creator == mod)
-                       ServerInstance->Modes->DelMode(mh);
+                       this->DelService(*mh);
                mh = ServerInstance->Modes->FindMode(m, MODETYPE_CHANNEL);
                if (mh && mh->creator == mod)
-                       ServerInstance->Modes->DelMode(mh);
+                       this->DelService(*mh);
        }
        for(std::multimap<std::string, ServiceProvider*>::iterator i = DataProviders.begin(); i != DataProviders.end(); )
        {
@@ -384,19 +386,14 @@ void ModuleManager::DoSafeUnload(Module* mod)
 
        dynamic_reference_base::reset_all();
 
-       /* Tidy up any dangling resolvers */
-       ServerInstance->Res->CleanResolvers(mod);
-
-       FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(mod));
-
        DetachAll(mod);
 
        Modules.erase(modfind);
        ServerInstance->GlobalCulls.AddItem(mod);
 
-       ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",mod->ModuleSourceFile.c_str());
+       ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Module %s unloaded",mod->ModuleSourceFile.c_str());
        this->ModCount--;
-       ServerInstance->BuildISupport();
+       ServerInstance->ISupport.Build();
 }
 
 void ModuleManager::UnloadAll()
@@ -427,16 +424,6 @@ std::string& ModuleManager::LastError()
        return LastModuleError;
 }
 
-CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
-{
-       return this->Parser->CallHandler(commandname, parameters, user);
-}
-
-bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, User* user)
-{
-       return this->Parser->IsValidCommand(commandname, pcnt, user);
-}
-
 void ModuleManager::AddService(ServiceProvider& item)
 {
        switch (item.service)
@@ -448,6 +435,8 @@ void ModuleManager::AddService(ServiceProvider& item)
                case SERVICE_MODE:
                        if (!ServerInstance->Modes->AddMode(static_cast<ModeHandler*>(&item)))
                                throw ModuleException("Mode "+std::string(item.name)+" already exists.");
+                       DataProviders.insert(std::make_pair("mode/" + item.name, &item));
+                       dynamic_reference_base::reset_all();
                        return;
                case SERVICE_METADATA:
                        if (!ServerInstance->Extensions.Register(static_cast<ExtensionItem*>(&item)))
@@ -456,6 +445,9 @@ void ModuleManager::AddService(ServiceProvider& item)
                case SERVICE_DATA:
                case SERVICE_IOHOOK:
                {
+                       if (item.name.substr(0, 5) == "mode/")
+                               throw ModuleException("The \"mode/\" service name prefix is reserved.");
+
                        DataProviders.insert(std::make_pair(item.name, &item));
                        std::string::size_type slash = item.name.find('/');
                        if (slash != std::string::npos)
@@ -463,6 +455,7 @@ void ModuleManager::AddService(ServiceProvider& item)
                                DataProviders.insert(std::make_pair(item.name.substr(0, slash), &item));
                                DataProviders.insert(std::make_pair(item.name.substr(slash + 1), &item));
                        }
+                       dynamic_reference_base::reset_all();
                        return;
                }
                default:
@@ -477,7 +470,7 @@ void ModuleManager::DelService(ServiceProvider& item)
                case SERVICE_MODE:
                        if (!ServerInstance->Modes->DelMode(static_cast<ModeHandler*>(&item)))
                                throw ModuleException("Mode "+std::string(item.name)+" does not exist.");
-                       return;
+                       // Fall through
                case SERVICE_DATA:
                case SERVICE_IOHOOK:
                {
@@ -519,6 +512,8 @@ dynamic_reference_base::dynamic_reference_base(Module* Creator, const std::strin
        if (!dynrefs)
                dynrefs = new std::vector<dynamic_reference_base*>;
        dynrefs->push_back(this);
+       if (dynref_init_complete)
+               resolve();
 }
 
 dynamic_reference_base::~dynamic_reference_base()
@@ -544,32 +539,18 @@ dynamic_reference_base::~dynamic_reference_base()
 void dynamic_reference_base::SetProvider(const std::string& newname)
 {
        name = newname;
-       ClearCache();
-}
-
-void dynamic_reference_base::lookup()
-{
-       if (!*this)
-               throw ModuleException("Dynamic reference to '" + name + "' failed to resolve");
-}
-
-dynamic_reference_base::operator bool()
-{
-       if (!value)
-       {
-               std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules->DataProviders.find(name);
-               if (i != ServerInstance->Modules->DataProviders.end())
-                       value = static_cast<DataProvider*>(i->second);
-       }
-       return (value != NULL);
+       resolve();
 }
 
-void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
+void dynamic_reference_base::resolve()
 {
-       this->Modes->Process(parameters, user);
+       std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules->DataProviders.find(name);
+       if (i != ServerInstance->Modules->DataProviders.end())
+               value = static_cast<DataProvider*>(i->second);
+       else
+               value = NULL;
 }
 
-
 void InspIRCd::SendGlobalMode(const std::vector<std::string>& parameters, User *user)
 {
        Modes->Process(parameters, user);
@@ -577,18 +558,6 @@ void InspIRCd::SendGlobalMode(const std::vector<std::string>& parameters, User *
                this->PI->SendMode(parameters[0], Modes->GetLastParseParams(), Modes->GetLastParseTranslate());
 }
 
-bool InspIRCd::AddResolver(Resolver* r, bool cached)
-{
-       if (!cached)
-               return this->Res->AddResolverClass(r);
-       else
-       {
-               r->TriggerCachedResult();
-               delete r;
-               return true;
-       }
-}
-
 Module* ModuleManager::Find(const std::string &name)
 {
        std::map<std::string, Module*>::iterator modfind = Modules.find(name);
@@ -608,169 +577,45 @@ const std::vector<std::string> ModuleManager::GetAllModuleNames(int filter)
        return retval;
 }
 
-ConfigReader::ConfigReader()
+FileReader::FileReader(const std::string& filename)
 {
-       this->error = 0;
-       ServerInstance->Logs->Log("MODULE", DEBUG, "ConfigReader is deprecated in 2.0; "
-               "use ServerInstance->Config->ConfValue(\"key\") or ->ConfTags(\"key\") instead");
+       Load(filename);
 }
 
-
-ConfigReader::~ConfigReader()
+void FileReader::Load(const std::string& filename)
 {
-}
-
-static ConfigTag* SlowGetTag(const std::string &tag, int index)
-{
-       ConfigTagList tags = ServerInstance->Config->ConfTags(tag);
-       while (tags.first != tags.second)
+       // If the file is stored in the file cache then we used that version instead.
+       ConfigFileCache::iterator it = ServerInstance->Config->Files.find(filename);
+       if (it != ServerInstance->Config->Files.end())
        {
-               if (!index)
-                       return tags.first->second;
-               tags.first++;
-               index--;
+               this->lines = it->second;
        }
-       return NULL;
-}
-
-std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
-{
-       std::string result = default_value;
-       if (!SlowGetTag(tag, index)->readString(name, result, allow_linefeeds))
-       {
-               this->error = CONF_VALUE_NOT_FOUND;
-       }
-       return result;
-}
-
-std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
-{
-       return ReadValue(tag, name, "", index, allow_linefeeds);
-}
-
-bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
-{
-       bool def = (default_value == "yes");
-       return SlowGetTag(tag, index)->getBool(name, def);
-}
-
-bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
-{
-       return ReadFlag(tag, name, "", index);
-}
-
-
-int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
-{
-       int v = atoi(default_value.c_str());
-       int result = SlowGetTag(tag, index)->getInt(name, v);
-
-       if ((need_positive) && (result < 0))
+       else
        {
-               this->error = CONF_INT_NEGATIVE;
-               return 0;
-       }
+               lines.clear();
 
-       return result;
-}
-
-int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive)
-{
-       return ReadInteger(tag, name, "", index, need_positive);
-}
-
-long ConfigReader::GetError()
-{
-       long olderr = this->error;
-       this->error = 0;
-       return olderr;
-}
+               std::ifstream stream(filename.c_str());
+               if (!stream.is_open())
+                       throw CoreException(filename + " does not exist or is not readable!");
 
-int ConfigReader::Enumerate(const std::string &tag)
-{
-       ServerInstance->Logs->Log("MODULE", DEBUG, "Module is using ConfigReader::Enumerate on %s; this is slow!",
-               tag.c_str());
-       int i=0;
-       while (SlowGetTag(tag, i)) i++;
-       return i;
-}
-
-FileReader::FileReader(const std::string &filename)
-{
-       LoadFile(filename);
-}
-
-FileReader::FileReader()
-{
-}
+               std::string line;
+               while (std::getline(stream, line))
+               {
+                       lines.push_back(line);
+                       totalSize += line.size() + 2;
+               }
 
-std::string FileReader::Contents()
-{
-       std::string x;
-       for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
-       {
-               x.append(*a);
-               x.append("\r\n");
+               stream.close();
        }
-       return x;
 }
 
-unsigned long FileReader::ContentSize()
+std::string FileReader::GetString()
 {
-       return this->contentsize;
-}
-
-void FileReader::CalcSize()
-{
-       unsigned long n = 0;
-       for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
-               n += (a->length() + 2);
-       this->contentsize = n;
-}
-
-void FileReader::LoadFile(const std::string &filename)
-{
-       std::map<std::string, file_cache>::iterator file = ServerInstance->Config->Files.find(filename);
-       if (file != ServerInstance->Config->Files.end())
+       std::string buffer;
+       for (file_cache::iterator it = this->lines.begin(); it != this->lines.end(); ++it)
        {
-               this->fc = file->second;
+               buffer.append(*it);
+               buffer.append("\r\n");
        }
-       else
-       {
-               fc.clear();
-               FILE* f = fopen(filename.c_str(), "r");
-               if (!f)
-                       return;
-               char linebuf[MAXBUF*10];
-               while (fgets(linebuf, sizeof(linebuf), f))
-               {
-                       int len = strlen(linebuf);
-                       if (len)
-                               fc.push_back(std::string(linebuf, len - 1));
-               }
-               fclose(f);
-       }
-       CalcSize();
-}
-
-
-FileReader::~FileReader()
-{
-}
-
-bool FileReader::Exists()
-{
-       return (!(fc.size() == 0));
-}
-
-std::string FileReader::GetLine(int x)
-{
-       if ((x<0) || ((unsigned)x>=fc.size()))
-               return "";
-       return fc[x];
-}
-
-int FileReader::FileSize()
-{
-       return fc.size();
+       return buffer;
 }
diff --git a/src/modules/account.h b/src/modules/account.h
deleted file mode 100644 (file)
index ba671ba..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef ACCOUNT_H
-#define ACCOUNT_H
-
-#include <map>
-#include <string>
-
-class AccountEvent : public Event
-{
- public:
-       User* const user;
-       const std::string account;
-       AccountEvent(Module* me, User* u, const std::string& name)
-               : Event(me, "account_login"), user(u), account(name)
-       {
-       }
-};
-
-typedef StringExtItem AccountExtItem;
-
-inline AccountExtItem* GetAccountExtItem()
-{
-       return static_cast<AccountExtItem*>(ServerInstance->Extensions.GetItem("accountname"));
-}
-
-#endif
index a36c39bc83cd3e6d078d311b4a11313df543a44f..ddc4e9a38a1ca74002a5d14ab5ff2e33377a63ea 100644 (file)
@@ -37,7 +37,7 @@ class ModuleGeoIP : public Module
 
        std::string* SetExt(LocalUser* user)
        {
-               const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString());
+               const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString().c_str());
                if (!c)
                        c = "UNK";
 
@@ -51,7 +51,7 @@ class ModuleGeoIP : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                gi = GeoIP_new(GEOIP_STANDARD);
                if (gi == NULL)
@@ -77,12 +77,12 @@ class ModuleGeoIP : public Module
                        GeoIP_delete(gi);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides a way to assign users to connect classes by country using GeoIP lookup", VF_VENDOR);
        }
 
-       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
+       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE
        {
                std::string* cc = ext.get(user);
                if (!cc)
@@ -99,7 +99,7 @@ class ModuleGeoIP : public Module
                return MOD_RES_DENY;
        }
 
-       ModResult OnStats(char symbol, User* user, string_list &out)
+       ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE
        {
                if (symbol != 'G')
                        return MOD_RES_PASSTHRU;
@@ -129,4 +129,3 @@ class ModuleGeoIP : public Module
 };
 
 MODULE_INIT(ModuleGeoIP)
-
index 5b3f1e7cc00ec0f538b87a67abf78eb060af121b..2d1551b43958536164c134f023eee45757eeb8e0 100644 (file)
@@ -119,7 +119,7 @@ public:
                conn = NULL;
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(ldapAuthed);
                ServerInstance->Modules->AddService(ldapVhost);
@@ -134,7 +134,7 @@ public:
                        ldap_unbind_ext(conn, NULL, NULL);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("ldapauth");
                whitelistedcidrs.clear();
@@ -234,7 +234,7 @@ public:
           return result;
        }
 
-       virtual void OnUserConnect(LocalUser *user)
+       void OnUserConnect(LocalUser *user) CXX11_OVERRIDE
        {
                std::string* cc = ldapVhost.get(user);
                if (cc)
@@ -244,7 +244,7 @@ public:
                }
        }
 
-       ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                if ((!allowpattern.empty()) && (InspIRCd::Match(user->nick,allowpattern)))
                {
@@ -378,7 +378,7 @@ public:
                                attr_value.bv_val = const_cast<char*>(val.c_str());
                                attr_value.bv_len = val.length();
 
-                               ServerInstance->Logs->Log("m_ldapauth", DEBUG, "LDAP compare: %s=%s", attr.c_str(), val.c_str());
+                               ServerInstance->Logs->Log("m_ldapauth", LOG_DEBUG, "LDAP compare: %s=%s", attr.c_str(), val.c_str());
 
                                authed = (ldap_compare_ext_s(conn, DN, attr.c_str(), &attr_value, NULL, NULL) == LDAP_COMPARE_TRUE);
 
@@ -421,16 +421,15 @@ public:
                return true;
        }
 
-       ModResult OnCheckReady(LocalUser* user)
+       ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
        {
                return ldapAuthed.get(user) ? MOD_RES_PASSTHRU : MOD_RES_DENY;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allow/Deny connections based upon answer from LDAP server", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleLDAPAuth)
index 53896878c5e1b255b7bf085b493091d92ba515d5..79ac13dd56b1a4d223675702b6537e8fe23eedbf 100644 (file)
 /* $ModDesc: Adds the ability to authenticate opers via LDAP */
 /* $LinkerFlags: -lldap */
 
-// Duplicated code, also found in cmd_oper and m_sqloper
-static bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
-       std::stringstream hl(hostlist);
-       std::string xhost;
-       while (hl >> xhost)
-       {
-               if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
 struct RAIILDAPString
 {
        char *str;
@@ -97,7 +82,7 @@ class ModuleLDAPAuth : public Module
 
                std::string acceptedhosts = tag->getString("host");
                std::string hostname = user->ident + "@" + user->host;
-               if (!OneOfMatches(hostname.c_str(), user->GetIPString(), acceptedhosts))
+               if (!InspIRCd::MatchMask(acceptedhosts, hostname, user->GetIPString()))
                        return false;
 
                if (!LookupOper(opername, inputpass))
@@ -113,20 +98,20 @@ public:
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnRehash, I_OnPreCommand };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
                OnRehash(NULL);
        }
 
-       virtual ~ModuleLDAPAuth()
+       ~ModuleLDAPAuth()
        {
                if (conn)
                        ldap_unbind_ext(conn, NULL, NULL);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("ldapoper");
 
@@ -168,7 +153,7 @@ public:
                return true;
        }
 
-       ModResult OnPreCommand(std::string& command, std::vector<std::string>& parameters, LocalUser* user, bool validated, const std::string& original_line)
+       ModResult OnPreCommand(std::string& command, std::vector<std::string>& parameters, LocalUser* user, bool validated, const std::string& original_line) CXX11_OVERRIDE
        {
                if (validated && command == "OPER" && parameters.size() >= 2)
                {
@@ -245,7 +230,7 @@ public:
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Adds the ability to authenticate opers via LDAP", VF_VENDOR);
        }
index 598f9aac9c88ae5ef4045a327d7ae180d5d331f8..244aa0922a006cecc04020d867ae2a71c60976c6 100644 (file)
@@ -64,8 +64,8 @@ class QueryThread : public SocketThread
   public:
        QueryThread(ModuleMsSQL* mod) : Parent(mod) { }
        ~QueryThread() { }
-       virtual void Run();
-       virtual void OnNotify();
+       void Run();
+       void OnNotify();
 };
 
 class MsSQLResult : public SQLresult
@@ -88,10 +88,6 @@ class MsSQLResult : public SQLresult
        {
        }
 
-       ~MsSQLResult()
-       {
-       }
-
        void AddRow(int colsnum, char **dat, char **colname)
        {
                colnames.clear();
@@ -111,17 +107,17 @@ class MsSQLResult : public SQLresult
                rows++;
        }
 
-       virtual int Rows()
+       int Rows()
        {
                return rows;
        }
 
-       virtual int Cols()
+       int Cols()
        {
                return cols;
        }
 
-       virtual std::string ColName(int column)
+       std::string ColName(int column)
        {
                if (column < (int)colnames.size())
                {
@@ -134,7 +130,7 @@ class MsSQLResult : public SQLresult
                return "";
        }
 
-       virtual int ColNum(const std::string &column)
+       int ColNum(const std::string &column)
        {
                for (unsigned int i = 0; i < colnames.size(); i++)
                {
@@ -145,7 +141,7 @@ class MsSQLResult : public SQLresult
                return 0;
        }
 
-       virtual SQLfield GetValue(int row, int column)
+       SQLfield GetValue(int row, int column)
        {
                if ((row >= 0) && (row < rows) && (column >= 0) && (column < Cols()))
                {
@@ -158,7 +154,7 @@ class MsSQLResult : public SQLresult
                return SQLfield("",true);
        }
 
-       virtual SQLfieldList& GetRow()
+       SQLfieldList& GetRow()
        {
                if (currentrow < rows)
                        return fieldlists[currentrow];
@@ -166,7 +162,7 @@ class MsSQLResult : public SQLresult
                        return emptyfieldlist;
        }
 
-       virtual SQLfieldMap& GetRowMap()
+       SQLfieldMap& GetRowMap()
        {
                /* In an effort to reduce overhead we don't actually allocate the map
                 * until the first time it's needed...so...
@@ -192,7 +188,7 @@ class MsSQLResult : public SQLresult
                return *fieldmap;
        }
 
-       virtual SQLfieldList* GetRowPtr()
+       SQLfieldList* GetRowPtr()
        {
                fieldlist = new SQLfieldList();
 
@@ -207,7 +203,7 @@ class MsSQLResult : public SQLresult
                return fieldlist;
        }
 
-       virtual SQLfieldMap* GetRowMapPtr()
+       SQLfieldMap* GetRowMapPtr()
        {
                fieldmap = new SQLfieldMap();
 
@@ -223,12 +219,12 @@ class MsSQLResult : public SQLresult
                return fieldmap;
        }
 
-       virtual void Free(SQLfieldMap* fm)
+       void Free(SQLfieldMap* fm)
        {
                delete fm;
        }
 
-       virtual void Free(SQLfieldList* fl)
+       void Free(SQLfieldList* fl)
        {
                delete fl;
        }
@@ -258,7 +254,7 @@ class SQLConn : public classbase
                                if (tds_process_simple_query(sock) != TDS_SUCCEED)
                                {
                                        LoggingMutex->Lock();
-                                       ServerInstance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
+                                       ServerInstance->Logs->Log("m_mssql", LOG_DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
                                        LoggingMutex->Unlock();
                                        CloseDB();
                                }
@@ -266,7 +262,7 @@ class SQLConn : public classbase
                        else
                        {
                                LoggingMutex->Lock();
-                               ServerInstance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
+                               ServerInstance->Logs->Log("m_mssql", LOG_DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
                                LoggingMutex->Unlock();
                                CloseDB();
                        }
@@ -274,7 +270,7 @@ class SQLConn : public classbase
                else
                {
                        LoggingMutex->Lock();
-                       ServerInstance->Logs->Log("m_mssql",DEFAULT, "WARNING: Could not connect to DB with id: " + host.id);
+                       ServerInstance->Logs->Log("m_mssql", LOG_DEFAULT, "WARNING: Could not connect to DB with id: " + host.id);
                        LoggingMutex->Unlock();
                        CloseDB();
                }
@@ -433,7 +429,7 @@ class SQLConn : public classbase
 
                char* msquery = strdup(req->query.q.data());
                LoggingMutex->Lock();
-               ServerInstance->Logs->Log("m_mssql",DEBUG,"doing Query: %s",msquery);
+               ServerInstance->Logs->Log("m_mssql", LOG_DEBUG, "doing Query: %s",msquery);
                LoggingMutex->Unlock();
                if (tds_submit_query(sock, msquery) != TDS_SUCCEED)
                {
@@ -449,8 +445,8 @@ class SQLConn : public classbase
                int tds_res;
                while (tds_process_tokens(sock, &tds_res, NULL, TDS_TOKEN_RESULTS) == TDS_SUCCEED)
                {
-                       //ServerInstance->Logs->Log("m_mssql",DEBUG,"<******> result type: %d", tds_res);
-                       //ServerInstance->Logs->Log("m_mssql",DEBUG,"AFFECTED ROWS: %d", sock->rows_affected);
+                       //ServerInstance->Logs->Log("m_mssql", LOG_DEBUG, "<******> result type: %d", tds_res);
+                       //ServerInstance->Logs->Log("m_mssql", LOG_DEBUG, "AFFECTED ROWS: %d", sock->rows_affected);
                        switch (tds_res)
                        {
                                case TDS_ROWFMT_RESULT:
@@ -516,7 +512,7 @@ class SQLConn : public classbase
        {
                SQLConn* sc = (SQLConn*)pContext->parent;
                LoggingMutex->Lock();
-               ServerInstance->Logs->Log("m_mssql", DEBUG, "Message for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
+               ServerInstance->Logs->Log("m_mssql", LOG_DEBUG, "Message for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                LoggingMutex->Unlock();
                return 0;
        }
@@ -525,7 +521,7 @@ class SQLConn : public classbase
        {
                SQLConn* sc = (SQLConn*)pContext->parent;
                LoggingMutex->Lock();
-               ServerInstance->Logs->Log("m_mssql", DEFAULT, "Error for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
+               ServerInstance->Logs->Log("m_mssql", LOG_DEFAULT, "Error for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                LoggingMutex->Unlock();
                return 0;
        }
@@ -657,7 +653,7 @@ class ModuleMsSQL : public Module
                queryDispatcher = new QueryThread(this);
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ReadConf();
 
@@ -668,7 +664,7 @@ class ModuleMsSQL : public Module
                ServerInstance->Modules->AddService(sqlserv);
        }
 
-       virtual ~ModuleMsSQL()
+       ~ModuleMsSQL()
        {
                queryDispatcher->join();
                delete queryDispatcher;
@@ -753,7 +749,7 @@ class ModuleMsSQL : public Module
                if (HasHost(hi))
                {
                        LoggingMutex->Lock();
-                       ServerInstance->Logs->Log("m_mssql",DEFAULT, "WARNING: A MsSQL connection with id: %s already exists. Aborting database open attempt.", hi.id.c_str());
+                       ServerInstance->Logs->Log("m_mssql", LOG_DEFAULT, "WARNING: A MsSQL connection with id: %s already exists. Aborting database open attempt.", hi.id.c_str());
                        LoggingMutex->Unlock();
                        return;
                }
@@ -787,14 +783,14 @@ class ModuleMsSQL : public Module
                connections.clear();
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                queryDispatcher->LockQueue();
                ReadConf();
                queryDispatcher->UnlockQueueWakeup();
        }
 
-       void OnRequest(Request& request)
+       void OnRequest(Request& request) CXX11_OVERRIDE
        {
                if(strcmp(SQLREQID, request.id) == 0)
                {
@@ -825,7 +821,7 @@ class ModuleMsSQL : public Module
                return ++currid;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("MsSQL provider", VF_VENDOR);
        }
index 22cf5f3f4f1a5e006560abb1968c9db207e08474..bb8f1b57387ebea56545ae8e68532ab558ca9b53 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "inspircd.h"
 #include <mysql.h>
-#include "sql.h"
+#include "modules/sql.h"
 
 #ifdef _WIN32
 # pragma comment(lib, "mysqlclient.lib")
@@ -107,11 +107,11 @@ class ModuleSQL : public Module
        ConnMap connections; // main thread only
 
        ModuleSQL();
-       void init();
+       void init() CXX11_OVERRIDE;
        ~ModuleSQL();
-       void OnRehash(User* user);
-       void OnUnloadModule(Module* mod);
-       Version GetVersion();
+       void OnRehash(User* user) CXX11_OVERRIDE;
+       void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
+       Version GetVersion() CXX11_OVERRIDE;
 };
 
 class DispatcherThread : public SocketThread
@@ -121,8 +121,8 @@ class DispatcherThread : public SocketThread
  public:
        DispatcherThread(ModuleSQL* CreatorModule) : Parent(CreatorModule) { }
        ~DispatcherThread() { }
-       virtual void Run();
-       virtual void OnNotify();
+       void Run();
+       void OnNotify();
 };
 
 #if !defined(MYSQL_VERSION_ID) || MYSQL_VERSION_ID<32224
@@ -188,21 +188,17 @@ class MySQLresult : public SQLResult
 
        }
 
-       ~MySQLresult()
-       {
-       }
-
-       virtual int Rows()
+       int Rows()
        {
                return rows;
        }
 
-       virtual void GetCols(std::vector<std::string>& result)
+       void GetCols(std::vector<std::string>& result)
        {
                result.assign(colnames.begin(), colnames.end());
        }
 
-       virtual SQLEntry GetValue(int row, int column)
+       SQLEntry GetValue(int row, int column)
        {
                if ((row >= 0) && (row < rows) && (column >= 0) && (column < (int)fieldlists[row].size()))
                {
@@ -211,7 +207,7 @@ class MySQLresult : public SQLResult
                return SQLEntry();
        }
 
-       virtual bool GetRow(SQLEntries& result)
+       bool GetRow(SQLEntries& result)
        {
                if (currentrow < rows)
                {
index ac247548ac35c303a805734c483f112bb0c3f3f5..61e8d5bbbec974e5d6eb64377f2ab46516beccc9 100644 (file)
@@ -26,7 +26,7 @@
 #include <cstdlib>
 #include <sstream>
 #include <libpq-fe.h>
-#include "sql.h"
+#include "modules/sql.h"
 
 /* $ModDesc: PostgreSQL Service Provider module for all other m_sql* modules, uses v2 of the SQL API */
 /* $CompileFlags: -Iexec("pg_config --includedir") eval("my $s = `pg_config --version`;$s =~ /^.*?(\d+)\.(\d+)\.(\d+).*?$/;my $v = hex(sprintf("0x%02x%02x%02x", $1, $2, $3));print "-DPGSQL_HAS_ESCAPECONN" if(($v >= 0x080104) || ($v >= 0x07030F && $v < 0x070400) || ($v >= 0x07040D && $v < 0x080000) || ($v >= 0x080008 && $v < 0x080100));") */
@@ -62,7 +62,7 @@ class ReconnectTimer : public Timer
        ReconnectTimer(ModulePgSQL* m) : Timer(5, ServerInstance->Time(), false), mod(m)
        {
        }
-       virtual void Tick(time_t TIME);
+       bool Tick(time_t TIME);
 };
 
 struct QueueItem
@@ -97,12 +97,12 @@ class PgSQLresult : public SQLResult
                PQclear(res);
        }
 
-       virtual int Rows()
+       int Rows()
        {
                return rows;
        }
 
-       virtual void GetCols(std::vector<std::string>& result)
+       void GetCols(std::vector<std::string>& result)
        {
                result.resize(PQnfields(res));
                for(unsigned int i=0; i < result.size(); i++)
@@ -111,7 +111,7 @@ class PgSQLresult : public SQLResult
                }
        }
 
-       virtual SQLEntry GetValue(int row, int column)
+       SQLEntry GetValue(int row, int column)
        {
                char* v = PQgetvalue(res, row, column);
                if (!v || PQgetisnull(res, row, column))
@@ -120,7 +120,7 @@ class PgSQLresult : public SQLResult
                return SQLEntry(std::string(v, PQgetlength(res, row, column)));
        }
 
-       virtual bool GetRow(SQLEntries& result)
+       bool GetRow(SQLEntries& result)
        {
                if (currentrow >= PQntuples(res))
                        return false;
@@ -152,7 +152,7 @@ class SQLConn : public SQLProvider, public EventHandler
        {
                if (!DoConnect())
                {
-                       ServerInstance->Logs->Log("m_pgsql",DEFAULT, "WARNING: Could not connect to database " + tag->getString("id"));
+                       ServerInstance->Logs->Log("m_pgsql", LOG_DEFAULT, "WARNING: Could not connect to database " + tag->getString("id"));
                        DelayReconnect();
                }
        }
@@ -180,7 +180,7 @@ class SQLConn : public SQLProvider, public EventHandler
                }
        }
 
-       virtual void HandleEvent(EventType et, int errornum)
+       void HandleEvent(EventType et, int errornum)
        {
                switch (et)
                {
@@ -244,7 +244,7 @@ class SQLConn : public SQLProvider, public EventHandler
 
                if (!ServerInstance->SE->AddFd(this, FD_WANT_NO_WRITE | FD_WANT_NO_READ))
                {
-                       ServerInstance->Logs->Log("m_pgsql",DEBUG, "BUG: Couldn't add pgsql socket to socket engine");
+                       ServerInstance->Logs->Log("m_pgsql", LOG_DEBUG, "BUG: Couldn't add pgsql socket to socket engine");
                        return false;
                }
 
@@ -417,7 +417,7 @@ restart:
                                        int error;
                                        size_t escapedsize = PQescapeStringConn(sql, &buffer[0], parm.data(), parm.length(), &error);
                                        if (error)
-                                               ServerInstance->Logs->Log("m_pgsql", DEBUG, "BUG: Apparently PQescapeStringConn() failed");
+                                               ServerInstance->Logs->Log("m_pgsql", LOG_DEBUG, "BUG: Apparently PQescapeStringConn() failed");
 #else
                                        size_t escapedsize = PQescapeString(&buffer[0], parm.data(), parm.length());
 #endif
@@ -452,7 +452,7 @@ restart:
                                        int error;
                                        size_t escapedsize = PQescapeStringConn(sql, &buffer[0], parm.data(), parm.length(), &error);
                                        if (error)
-                                               ServerInstance->Logs->Log("m_pgsql", DEBUG, "BUG: Apparently PQescapeStringConn() failed");
+                                               ServerInstance->Logs->Log("m_pgsql", LOG_DEBUG, "BUG: Apparently PQescapeStringConn() failed");
 #else
                                        size_t escapedsize = PQescapeString(&buffer[0], parm.data(), parm.length());
 #endif
@@ -505,10 +505,11 @@ class ModulePgSQL : public Module
        ReconnectTimer* retimer;
 
        ModulePgSQL()
+               : retimer(NULL)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ReadConf();
 
@@ -516,14 +517,13 @@ class ModulePgSQL : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModulePgSQL()
+       ~ModulePgSQL()
        {
-               if (retimer)
-                       ServerInstance->Timers->DelTimer(retimer);
+               delete retimer;
                ClearAllConnections();
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ReadConf();
        }
@@ -564,7 +564,7 @@ class ModulePgSQL : public Module
                connections.clear();
        }
 
-       void OnUnloadModule(Module* mod)
+       void OnUnloadModule(Module* mod) CXX11_OVERRIDE
        {
                SQLerror err(SQL_BAD_DBID);
                for(ConnMap::iterator i = connections.begin(); i != connections.end(); i++)
@@ -592,16 +592,17 @@ class ModulePgSQL : public Module
                }
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("PostgreSQL Service Provider module for all other m_sql* modules, uses v2 of the SQL API", VF_VENDOR);
        }
 };
 
-void ReconnectTimer::Tick(time_t time)
+bool ReconnectTimer::Tick(time_t time)
 {
        mod->retimer = NULL;
        mod->ReadConf();
+       return false;
 }
 
 void SQLConn::DelayReconnect()
index cba234c8cae74977c9930bbfde1a462ea63649f0..59cbb0647d9564004e58edf248c999ebb7b31b1b 100644 (file)
 
 #include "inspircd.h"
 #include <pcre.h>
-#include "m_regex.h"
+#include "modules/regex.h"
 
 /* $ModDesc: Regex Provider Module for PCRE */
-/* $ModDep: m_regex.h */
+/* $ModDep: modules/regex.h */
 /* $CompileFlags: exec("pcre-config --cflags") */
 /* $LinkerFlags: exec("pcre-config --libs") rpath("pcre-config --libs") -lpcre */
 
@@ -33,7 +33,7 @@
 
 class PCREException : public ModuleException
 {
-public:
+ public:
        PCREException(const std::string& rx, const std::string& error, int erroffset)
                : ModuleException("Error in regex " + rx + " at offset " + ConvToStr(erroffset) + ": " + error)
        {
@@ -42,10 +42,9 @@ public:
 
 class PCRERegex : public Regex
 {
-private:
        pcre* regex;
 
-public:
+ public:
        PCRERegex(const std::string& rx) : Regex(rx)
        {
                const char* error;
@@ -53,17 +52,17 @@ public:
                regex = pcre_compile(rx.c_str(), 0, &error, &erroffset, NULL);
                if (!regex)
                {
-                       ServerInstance->Logs->Log("REGEX", DEBUG, "pcre_compile failed: /%s/ [%d] %s", rx.c_str(), erroffset, error);
+                       ServerInstance->Logs->Log("REGEX", LOG_DEBUG, "pcre_compile failed: /%s/ [%d] %s", rx.c_str(), erroffset, error);
                        throw PCREException(rx, error, erroffset);
                }
        }
 
-       virtual ~PCRERegex()
+       ~PCRERegex()
        {
                pcre_free(regex);
        }
 
-       virtual bool Matches(const std::string& text)
+       bool Matches(const std::string& text)
        {
                if (pcre_exec(regex, NULL, text.c_str(), text.length(), 0, 0, NULL, 0) > -1)
                {
@@ -86,13 +85,14 @@ class PCREFactory : public RegexFactory
 
 class ModuleRegexPCRE : public Module
 {
-public:
+ public:
        PCREFactory ref;
-       ModuleRegexPCRE() : ref(this) {
+       ModuleRegexPCRE() : ref(this)
+       {
                ServerInstance->Modules->AddService(ref);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Regex Provider Module for PCRE", VF_VENDOR);
        }
index b3afd60c80b8c002ebdaa21eae3069690a775ab2..dbbc990b9ad106ee484513fd15941f6105e75a5f 100644 (file)
 
 
 #include "inspircd.h"
-#include "m_regex.h"
+#include "modules/regex.h"
 #include <sys/types.h>
 #include <regex.h>
 
 /* $ModDesc: Regex Provider Module for POSIX Regular Expressions */
-/* $ModDep: m_regex.h */
+/* $ModDep: modules/regex.h */
 
 class POSIXRegexException : public ModuleException
 {
-public:
+ public:
        POSIXRegexException(const std::string& rx, const std::string& error)
                : ModuleException("Error in regex " + rx + ": " + error)
        {
@@ -37,10 +37,9 @@ public:
 
 class POSIXRegex : public Regex
 {
-private:
        regex_t regbuf;
 
-public:
+ public:
        POSIXRegex(const std::string& rx, bool extended) : Regex(rx)
        {
                int flags = (extended ? REG_EXTENDED : 0) | REG_NOSUB;
@@ -62,12 +61,12 @@ public:
                }
        }
 
-       virtual ~POSIXRegex()
+       ~POSIXRegex()
        {
                regfree(&regbuf);
        }
 
-       virtual bool Matches(const std::string& text)
+       bool Matches(const std::string& text)
        {
                if (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0)
                {
@@ -92,20 +91,22 @@ class PosixFactory : public RegexFactory
 class ModuleRegexPOSIX : public Module
 {
        PosixFactory ref;
-public:
-       ModuleRegexPOSIX() : ref(this) {
+
+ public:
+       ModuleRegexPOSIX() : ref(this)
+       {
                ServerInstance->Modules->AddService(ref);
                Implementation eventlist[] = { I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
                OnRehash(NULL);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Regex Provider Module for POSIX Regular Expressions", VF_VENDOR);
        }
 
-       void OnRehash(User* u)
+       void OnRehash(User* u) CXX11_OVERRIDE
        {
                ref.extended = ServerInstance->Config->ConfValue("posix")->getBool("extended");
        }
index 204728b652601290c3b64e25e913dd8da721aea6..f27a98cca6eb6788076648a80280f472c7efaf0c 100644 (file)
@@ -15,9 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 #include "inspircd.h"
-#include "m_regex.h"
+#include "modules/regex.h"
 #include <regex>
 
 /* $ModDesc: Regex Provider Module for std::regex Regular Expressions */
  *  Specify the Regular Expression engine to use here. Valid settings are
  *  bre, ere, awk, grep, egrep, ecmascript (default if not specified)*/
 /* $CompileFlags: -std=c++11 */
-/* $ModDep: m_regex.h */
+/* $ModDep: modules/regex.h */
 
 class StdRegexException : public ModuleException
 {
-public:
+ public:
        StdRegexException(const std::string& rx, const std::string& error)
                : ModuleException(std::string("Error in regex ") + rx + ": " + error)
        {
@@ -38,9 +38,9 @@ public:
 
 class StdRegex : public Regex
 {
-private:
        std::regex regexcl;
-public:
+
+ public:
        StdRegex(const std::string& rx, std::regex::flag_type fltype) : Regex(rx)
        {
                try{
@@ -51,8 +51,8 @@ public:
                        throw StdRegexException(rx, rxerr.what());
                }
        }
-       
-       virtual bool Matches(const std::string& text)
+
+       bool Matches(const std::string& text)
        {
                return std::regex_search(text, regexcl);
        }
@@ -73,23 +73,24 @@ class ModuleRegexStd : public Module
 {
 public:
        StdRegexFactory ref;
-       ModuleRegexStd() : ref(this) {
+       ModuleRegexStd() : ref(this)
+       {
                ServerInstance->Modules->AddService(ref);
                Implementation eventlist[] = { I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
                OnRehash(NULL);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Regex Provider Module for std::regex", VF_VENDOR);
        }
-       
-       void OnRehash(User* u)
+
+       void OnRehash(User* u) CXX11_OVERRIDE
        {
                ConfigTag* Conf = ServerInstance->Config->ConfValue("stdregex");
                std::string regextype = Conf->getString("type", "ecmascript");
-               
+
                if(regextype == "bre")
                        ref.regextype = std::regex::basic;
                else if(regextype == "ere")
index 4b9eab472266c0dece1e10e683979981bdd9865a..0718e5bb10f05981cd6b48ad19ad7d5b8a169419 100644 (file)
 
 
 #include "inspircd.h"
-#include "m_regex.h"
+#include "modules/regex.h"
 #include <sys/types.h>
 #include <tre/regex.h>
 
 /* $ModDesc: Regex Provider Module for TRE Regular Expressions */
 /* $CompileFlags: pkgconfincludes("tre","tre/regex.h","") */
 /* $LinkerFlags: pkgconflibs("tre","/libtre.so","-ltre") rpath("pkg-config --libs tre") */
-/* $ModDep: m_regex.h */
+/* $ModDep: modules/regex.h */
 
 class TRERegexException : public ModuleException
 {
-public:
+ public:
        TRERegexException(const std::string& rx, const std::string& error)
                : ModuleException("Error in regex " + rx + ": " + error)
        {
@@ -39,7 +39,6 @@ public:
 
 class TRERegex : public Regex
 {
-private:
        regex_t regbuf;
 
 public:
@@ -64,12 +63,12 @@ public:
                }
        }
 
-       virtual ~TRERegex()
+       ~TRERegex()
        {
                regfree(&regbuf);
        }
 
-       virtual bool Matches(const std::string& text)
+       bool Matches(const std::string& text)
        {
                if (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0)
                {
@@ -80,7 +79,8 @@ public:
        }
 };
 
-class TREFactory : public RegexFactory {
+class TREFactory : public RegexFactory
+{
  public:
        TREFactory(Module* m) : RegexFactory(m, "regex/tre") {}
        Regex* Create(const std::string& expr)
@@ -92,18 +92,16 @@ class TREFactory : public RegexFactory {
 class ModuleRegexTRE : public Module
 {
        TREFactory trf;
-public:
-       ModuleRegexTRE() : trf(this) {
-               ServerInstance->Modules->AddService(trf);
-       }
 
-       Version GetVersion()
+ public:
+       ModuleRegexTRE() : trf(this)
        {
-               return Version("Regex Provider Module for TRE Regular Expressions", VF_VENDOR);
+               ServerInstance->Modules->AddService(trf);
        }
 
-       ~ModuleRegexTRE()
+       Version GetVersion() CXX11_OVERRIDE
        {
+               return Version("Regex Provider Module for TRE Regular Expressions", VF_VENDOR);
        }
 };
 
index 7f6a5335994e2a3af9c7bd73c195c1919bb9ef94..254adf1025ce98dbe3548106cfcd50c211d7837e 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "inspircd.h"
 #include <sqlite3.h>
-#include "sql.h"
+#include "modules/sql.h"
 
 #ifdef _WIN32
 # pragma comment(lib, "sqlite3.lib")
@@ -48,16 +48,12 @@ class SQLite3Result : public SQLResult
        {
        }
 
-       ~SQLite3Result()
-       {
-       }
-
-       virtual int Rows()
+       int Rows()
        {
                return rows;
        }
 
-       virtual bool GetRow(SQLEntries& result)
+       bool GetRow(SQLEntries& result)
        {
                if (currentrow < rows)
                {
@@ -72,7 +68,7 @@ class SQLite3Result : public SQLResult
                }
        }
 
-       virtual void GetCols(std::vector<std::string>& result)
+       void GetCols(std::vector<std::string>& result)
        {
                result.assign(columns.begin(), columns.end());
        }
@@ -80,7 +76,6 @@ class SQLite3Result : public SQLResult
 
 class SQLConn : public SQLProvider
 {
- private:
        sqlite3* conn;
        reference<ConfigTag> config;
 
@@ -90,7 +85,7 @@ class SQLConn : public SQLProvider
                std::string host = tag->getString("hostname");
                if (sqlite3_open_v2(host.c_str(), &conn, SQLITE_OPEN_READWRITE, 0) != SQLITE_OK)
                {
-                       ServerInstance->Logs->Log("m_sqlite3",DEFAULT, "WARNING: Could not open DB with id: " + tag->getString("id"));
+                       ServerInstance->Logs->Log("m_sqlite3", LOG_DEFAULT, "WARNING: Could not open DB with id: " + tag->getString("id"));
                        conn = NULL;
                }
        }
@@ -149,13 +144,13 @@ class SQLConn : public SQLProvider
                sqlite3_finalize(stmt);
        }
 
-       virtual void submit(SQLQuery* query, const std::string& q)
+       void submit(SQLQuery* query, const std::string& q)
        {
                Query(query, q);
                delete query;
        }
 
-       virtual void submit(SQLQuery* query, const std::string& q, const ParamL& p)
+       void submit(SQLQuery* query, const std::string& q, const ParamL& p)
        {
                std::string res;
                unsigned int param = 0;
@@ -176,7 +171,7 @@ class SQLConn : public SQLProvider
                submit(query, res);
        }
 
-       virtual void submit(SQLQuery* query, const std::string& q, const ParamM& p)
+       void submit(SQLQuery* query, const std::string& q, const ParamM& p)
        {
                std::string res;
                for(std::string::size_type i = 0; i < q.length(); i++)
@@ -206,15 +201,10 @@ class SQLConn : public SQLProvider
 
 class ModuleSQLite3 : public Module
 {
- private:
        ConnMap conns;
 
  public:
-       ModuleSQLite3()
-       {
-       }
-
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ReadConf();
 
@@ -222,7 +212,7 @@ class ModuleSQLite3 : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleSQLite3()
+       ~ModuleSQLite3()
        {
                ClearConns();
        }
@@ -252,12 +242,12 @@ class ModuleSQLite3 : public Module
                }
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ReadConf();
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("sqlite3 provider", VF_VENDOR);
        }
index 41e9d0c3d01905dfbc48eff1c8322acae40a0200..8faee2da7b710e6708ccf43f256020f73cbc9ea3 100644 (file)
@@ -25,8 +25,8 @@
 #include <gcrypt.h>
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
-#include "ssl.h"
-#include "m_cap.h"
+#include "modules/ssl.h"
+#include "modules/cap.h"
 
 #ifdef _WIN32
 # pragma comment(lib, "libgnutls.lib")
@@ -240,7 +240,6 @@ class ModuleSSLGnuTLS : public Module
        }
 
  public:
-
        ModuleSSLGnuTLS()
                : starttls(this), capHandler(this, "tls"), iohook(this, "ssl/gnutls", SERVICE_IOHOOK)
        {
@@ -260,7 +259,7 @@ class ModuleSSLGnuTLS : public Module
                dh_alloc = false;
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                // Needs the flag as it ignores a plain /rehash
                OnModuleRehash(NULL,"ssl");
@@ -277,7 +276,7 @@ class ModuleSSLGnuTLS : public Module
                ServerInstance->Modules->AddService(starttls);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                sslports.clear();
 
@@ -297,7 +296,7 @@ class ModuleSSLGnuTLS : public Module
                                        continue;
 
                                const std::string& portid = port->bind_desc;
-                               ServerInstance->Logs->Log("m_ssl_gnutls", DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %s", portid.c_str());
+                               ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %s", portid.c_str());
 
                                if (port->bind_tag->getString("type", "clients") == "clients" && port->bind_addr != "127.0.0.1")
                                {
@@ -317,7 +316,7 @@ class ModuleSSLGnuTLS : public Module
                }
        }
 
-       void OnModuleRehash(User* user, const std::string &param)
+       void OnModuleRehash(User* user, const std::string &param) CXX11_OVERRIDE
        {
                if(param != "ssl")
                        return;
@@ -377,22 +376,22 @@ class ModuleSSLGnuTLS : public Module
                ret = gnutls_certificate_allocate_credentials(&x509_cred);
                cred_alloc = (ret >= 0);
                if (!cred_alloc)
-                       ServerInstance->Logs->Log("m_ssl_gnutls",DEBUG, "m_ssl_gnutls.so: Failed to allocate certificate credentials: %s", gnutls_strerror(ret));
+                       ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEBUG, "m_ssl_gnutls.so: Failed to allocate certificate credentials: %s", gnutls_strerror(ret));
 
                if((ret =gnutls_certificate_set_x509_trust_file(x509_cred, cafile.c_str(), GNUTLS_X509_FMT_PEM)) < 0)
-                       ServerInstance->Logs->Log("m_ssl_gnutls",DEBUG, "m_ssl_gnutls.so: Failed to set X.509 trust file '%s': %s", cafile.c_str(), gnutls_strerror(ret));
+                       ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEBUG, "m_ssl_gnutls.so: Failed to set X.509 trust file '%s': %s", cafile.c_str(), gnutls_strerror(ret));
 
                if((ret = gnutls_certificate_set_x509_crl_file (x509_cred, crlfile.c_str(), GNUTLS_X509_FMT_PEM)) < 0)
-                       ServerInstance->Logs->Log("m_ssl_gnutls",DEBUG, "m_ssl_gnutls.so: Failed to set X.509 CRL file '%s': %s", crlfile.c_str(), gnutls_strerror(ret));
+                       ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEBUG, "m_ssl_gnutls.so: Failed to set X.509 CRL file '%s': %s", crlfile.c_str(), gnutls_strerror(ret));
 
                FileReader reader;
 
-               reader.LoadFile(certfile);
-               std::string cert_string = reader.Contents();
+               reader.Load(certfile);
+               std::string cert_string = reader.GetString();
                gnutls_datum_t cert_datum = { (unsigned char*)cert_string.data(), static_cast<unsigned int>(cert_string.length()) };
 
-               reader.LoadFile(keyfile);
-               std::string key_string = reader.Contents();
+               reader.Load(keyfile);
+               std::string key_string = reader.GetString();
                gnutls_datum_t key_datum = { (unsigned char*)key_string.data(), static_cast<unsigned int>(key_string.length()) };
 
                // If this fails, no SSL port will work. At all. So, do the smart thing - throw a ModuleException
@@ -432,13 +431,13 @@ class ModuleSSLGnuTLS : public Module
                if ((ret = gnutls_priority_init(&priority, priocstr, &prioerror)) < 0)
                {
                        // gnutls did not understand the user supplied string, log and fall back to the default priorities
-                       ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to set priorities to \"%s\": %s Syntax error at position %u, falling back to default (NORMAL)", priorities.c_str(), gnutls_strerror(ret), (unsigned int) (prioerror - priocstr));
+                       ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: Failed to set priorities to \"%s\": %s Syntax error at position %u, falling back to default (NORMAL)", priorities.c_str(), gnutls_strerror(ret), (unsigned int) (prioerror - priocstr));
                        gnutls_priority_init(&priority, "NORMAL", NULL);
                }
 
                #else
                if (priorities != "NORMAL")
-                       ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: You've set <gnutls:priority> to a value other than the default, but this is only supported with GnuTLS v2.1.7 or newer. Your GnuTLS version is older than that so the option will have no effect.");
+                       ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: You've set <gnutls:priority> to a value other than the default, but this is only supported with GnuTLS v2.1.7 or newer. Your GnuTLS version is older than that so the option will have no effect.");
                #endif
 
                #if(GNUTLS_VERSION_MAJOR < 2 || ( GNUTLS_VERSION_MAJOR == 2 && GNUTLS_VERSION_MINOR < 12 ) )
@@ -450,7 +449,7 @@ class ModuleSSLGnuTLS : public Module
                dh_alloc = (ret >= 0);
                if (!dh_alloc)
                {
-                       ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to initialise DH parameters: %s", gnutls_strerror(ret));
+                       ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: Failed to initialise DH parameters: %s", gnutls_strerror(ret));
                        return;
                }
 
@@ -458,14 +457,14 @@ class ModuleSSLGnuTLS : public Module
                if (!dhfile.empty())
                {
                        // Try to load DH params from file
-                       reader.LoadFile(dhfile);
-                       std::string dhstring = reader.Contents();
+                       reader.Load(dhfile);
+                       std::string dhstring = reader.GetString();
                        gnutls_datum_t dh_datum = { (unsigned char*)dhstring.data(), static_cast<unsigned int>(dhstring.length()) };
 
                        if ((ret = gnutls_dh_params_import_pkcs3(dh_params, &dh_datum, GNUTLS_X509_FMT_PEM)) < 0)
                        {
                                // File unreadable or GnuTLS was unhappy with the contents, generate the DH primes now
-                               ServerInstance->Logs->Log("m_ssl_gnutls", DEFAULT, "m_ssl_gnutls.so: Generating DH parameters because I failed to load them from file '%s': %s", dhfile.c_str(), gnutls_strerror(ret));
+                               ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: Generating DH parameters because I failed to load them from file '%s': %s", dhfile.c_str(), gnutls_strerror(ret));
                                GenerateDHParams();
                        }
                }
@@ -488,7 +487,7 @@ class ModuleSSLGnuTLS : public Module
                int ret;
 
                if((ret = gnutls_dh_params_generate2(dh_params, dh_bits)) < 0)
-                       ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to generate DH parameters (%d bits): %s", dh_bits, gnutls_strerror(ret));
+                       ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: Failed to generate DH parameters (%d bits): %s", dh_bits, gnutls_strerror(ret));
        }
 
        ~ModuleSSLGnuTLS()
@@ -511,7 +510,7 @@ class ModuleSSLGnuTLS : public Module
                ServerInstance->GenRandom = &ServerInstance->HandleGenRandom;
        }
 
-       void OnCleanup(int target_type, void* item)
+       void OnCleanup(int target_type, void* item) CXX11_OVERRIDE
        {
                if(target_type == TYPE_USER)
                {
@@ -526,21 +525,20 @@ class ModuleSSLGnuTLS : public Module
                }
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides SSL support for clients", VF_VENDOR);
        }
 
-
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
                if (!sslports.empty())
-                       output.append(" SSL=" + sslports);
+                       tokens["SSL"] = sslports;
                if (starttls.enabled)
-                       output.append(" STARTTLS");
+                       tokens["STARTTLS"];
        }
 
-       void OnHookIO(StreamSocket* user, ListenSocket* lsb)
+       void OnHookIO(StreamSocket* user, ListenSocket* lsb) CXX11_OVERRIDE
        {
                if (!user->GetIOHook() && lsb->bind_tag->getString("ssl") == "gnutls")
                {
@@ -549,7 +547,7 @@ class ModuleSSLGnuTLS : public Module
                }
        }
 
-       void OnRequest(Request& request)
+       void OnRequest(Request& request) CXX11_OVERRIDE
        {
                if (strcmp("GET_SSL_CERT", request.id) == 0)
                {
@@ -583,7 +581,7 @@ class ModuleSSLGnuTLS : public Module
                Handshake(session, user);
        }
 
-       void OnStreamSocketAccept(StreamSocket* user, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+       void OnStreamSocketAccept(StreamSocket* user, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE
        {
                issl_session* session = &sessions[user->GetFd()];
 
@@ -594,17 +592,17 @@ class ModuleSSLGnuTLS : public Module
                InitSession(user, true);
        }
 
-       void OnStreamSocketConnect(StreamSocket* user)
+       void OnStreamSocketConnect(StreamSocket* user) CXX11_OVERRIDE
        {
                InitSession(user, false);
        }
 
-       void OnStreamSocketClose(StreamSocket* user)
+       void OnStreamSocketClose(StreamSocket* user) CXX11_OVERRIDE
        {
                CloseSession(&sessions[user->GetFd()]);
        }
 
-       int OnStreamSocketRead(StreamSocket* user, std::string& recvq)
+       int OnStreamSocketRead(StreamSocket* user, std::string& recvq) CXX11_OVERRIDE
        {
                issl_session* session = &sessions[user->GetFd()];
 
@@ -662,7 +660,7 @@ class ModuleSSLGnuTLS : public Module
                return 0;
        }
 
-       int OnStreamSocketWrite(StreamSocket* user, std::string& sendq)
+       int OnStreamSocketWrite(StreamSocket* user, std::string& sendq) CXX11_OVERRIDE
        {
                issl_session* session = &sessions[user->GetFd()];
 
@@ -761,7 +759,7 @@ class ModuleSSLGnuTLS : public Module
                }
        }
 
-       void OnUserConnect(LocalUser* user)
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
        {
                if (user->eh.GetIOHook() == this)
                {
@@ -774,10 +772,10 @@ class ModuleSSLGnuTLS : public Module
 
                                ssl_cert* cert = sessions[user->eh.GetFd()].cert;
                                if (cert->fingerprint.empty())
-                                       user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick.c_str(), cipher.c_str());
+                                       user->WriteNotice("*** You are connected using SSL cipher '" + cipher + "'");
                                else
-                                       user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\""
-                                               " and your SSL fingerprint is %s", user->nick.c_str(), cipher.c_str(), cert->fingerprint.c_str());
+                                       user->WriteNotice("*** You are connected using SSL cipher '" + cipher +
+                                               "' and your SSL fingerprint is " + cert->fingerprint);
                        }
                }
        }
@@ -876,7 +874,7 @@ class ModuleSSLGnuTLS : public Module
                }
                else
                {
-                       certinfo->fingerprint = irc::hex(digest, digest_size);
+                       certinfo->fingerprint = BinToHex(digest, digest_size);
                }
 
                /* Beware here we do not check for errors.
@@ -890,7 +888,7 @@ info_done_dealloc:
                gnutls_x509_crt_deinit(cert);
        }
 
-       void OnEvent(Event& ev)
+       void OnEvent(Event& ev) CXX11_OVERRIDE
        {
                if (starttls.enabled)
                        capHandler.HandleEvent(ev);
index b63fcd3763eba4c755ffa3881a4a0251490bd084..1fa6763ce4efbc3e8951eeffe65e499379808a75 100644 (file)
 # define __AVAILABILITYMACROS__
 # define DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
 #endif
+
 #include "inspircd.h"
 #include <openssl/ssl.h>
 #include <openssl/err.h>
-#include "ssl.h"
+#include "modules/ssl.h"
 
 #ifdef _WIN32
 # pragma comment(lib, "libcrypto.lib")
@@ -134,7 +134,7 @@ class ModuleSSLOpenSSL : public Module
                SSL_CTX_set_verify(clictx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, OnVerify);
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                // Needs the flag as it ignores a plain /rehash
                OnModuleRehash(NULL,"ssl");
@@ -143,7 +143,7 @@ class ModuleSSLOpenSSL : public Module
                ServerInstance->Modules->AddService(iohook);
        }
 
-       void OnHookIO(StreamSocket* user, ListenSocket* lsb)
+       void OnHookIO(StreamSocket* user, ListenSocket* lsb) CXX11_OVERRIDE
        {
                if (!user->GetIOHook() && lsb->bind_tag->getString("ssl") == "openssl")
                {
@@ -152,7 +152,7 @@ class ModuleSSLOpenSSL : public Module
                }
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                sslports.clear();
 
@@ -171,7 +171,7 @@ class ModuleSSLOpenSSL : public Module
                                        continue;
 
                                const std::string& portid = port->bind_desc;
-                               ServerInstance->Logs->Log("m_ssl_openssl", DEFAULT, "m_ssl_openssl.so: Enabling SSL for port %s", portid.c_str());
+                               ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "m_ssl_openssl.so: Enabling SSL for port %s", portid.c_str());
 
                                if (port->bind_tag->getString("type", "clients") == "clients" && port->bind_addr != "127.0.0.1")
                                {
@@ -191,7 +191,7 @@ class ModuleSSLOpenSSL : public Module
                }
        }
 
-       void OnModuleRehash(User* user, const std::string &param)
+       void OnModuleRehash(User* user, const std::string &param) CXX11_OVERRIDE
        {
                if (param != "ssl")
                        return;
@@ -219,7 +219,7 @@ class ModuleSSLOpenSSL : public Module
                {
                        if ((!SSL_CTX_set_cipher_list(ctx, ciphers.c_str())) || (!SSL_CTX_set_cipher_list(clictx, ciphers.c_str())))
                        {
-                               ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_openssl.so: Can't set cipher list to %s.", ciphers.c_str());
+                               ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "m_ssl_openssl.so: Can't set cipher list to %s.", ciphers.c_str());
                                ERR_print_errors_cb(error_callback, this);
                        }
                }
@@ -229,20 +229,20 @@ class ModuleSSLOpenSSL : public Module
                 */
                if ((!SSL_CTX_use_certificate_chain_file(ctx, certfile.c_str())) || (!SSL_CTX_use_certificate_chain_file(clictx, certfile.c_str())))
                {
-                       ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_openssl.so: Can't read certificate file %s. %s", certfile.c_str(), strerror(errno));
+                       ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "m_ssl_openssl.so: Can't read certificate file %s. %s", certfile.c_str(), strerror(errno));
                        ERR_print_errors_cb(error_callback, this);
                }
 
                if (((!SSL_CTX_use_PrivateKey_file(ctx, keyfile.c_str(), SSL_FILETYPE_PEM))) || (!SSL_CTX_use_PrivateKey_file(clictx, keyfile.c_str(), SSL_FILETYPE_PEM)))
                {
-                       ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_openssl.so: Can't read key file %s. %s", keyfile.c_str(), strerror(errno));
+                       ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "m_ssl_openssl.so: Can't read key file %s. %s", keyfile.c_str(), strerror(errno));
                        ERR_print_errors_cb(error_callback, this);
                }
 
                /* Load the CAs we trust*/
                if (((!SSL_CTX_load_verify_locations(ctx, cafile.c_str(), 0))) || (!SSL_CTX_load_verify_locations(clictx, cafile.c_str(), 0)))
                {
-                       ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_openssl.so: Can't read CA list from %s. This is only a problem if you want to verify client certificates, otherwise it's safe to ignore this message. Error: %s", cafile.c_str(), strerror(errno));
+                       ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "m_ssl_openssl.so: Can't read CA list from %s. This is only a problem if you want to verify client certificates, otherwise it's safe to ignore this message. Error: %s", cafile.c_str(), strerror(errno));
                        ERR_print_errors_cb(error_callback, this);
                }
 
@@ -251,7 +251,7 @@ class ModuleSSLOpenSSL : public Module
 
                if (dhpfile == NULL)
                {
-                       ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_openssl.so Couldn't open DH file %s: %s", dhfile.c_str(), strerror(errno));
+                       ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "m_ssl_openssl.so Couldn't open DH file %s: %s", dhfile.c_str(), strerror(errno));
                        throw ModuleException("Couldn't open DH file " + dhfile + ": " + strerror(errno));
                }
                else
@@ -259,7 +259,7 @@ class ModuleSSLOpenSSL : public Module
                        ret = PEM_read_DHparams(dhpfile, NULL, NULL, NULL);
                        if ((SSL_CTX_set_tmp_dh(ctx, ret) < 0) || (SSL_CTX_set_tmp_dh(clictx, ret) < 0))
                        {
-                               ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "m_ssl_openssl.so: Couldn't set DH parameters %s. SSL errors follow:", dhfile.c_str());
+                               ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "m_ssl_openssl.so: Couldn't set DH parameters %s. SSL errors follow:", dhfile.c_str());
                                ERR_print_errors_cb(error_callback, this);
                        }
                }
@@ -267,10 +267,10 @@ class ModuleSSLOpenSSL : public Module
                fclose(dhpfile);
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
                if (!sslports.empty())
-                       output.append(" SSL=" + sslports);
+                       tokens["SSL"] = sslports;
        }
 
        ~ModuleSSLOpenSSL()
@@ -280,22 +280,22 @@ class ModuleSSLOpenSSL : public Module
                delete[] sessions;
        }
 
-       void OnUserConnect(LocalUser* user)
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
        {
                if (user->eh.GetIOHook() == this)
                {
                        if (sessions[user->eh.GetFd()].sess)
                        {
                                if (!sessions[user->eh.GetFd()].cert->fingerprint.empty())
-                                       user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\""
-                                               " and your SSL fingerprint is %s", user->nick.c_str(), SSL_get_cipher(sessions[user->eh.GetFd()].sess), sessions[user->eh.GetFd()].cert->fingerprint.c_str());
+                                       user->WriteNotice("*** You are connected using SSL cipher '" + std::string(SSL_get_cipher(sessions[user->eh.GetFd()].sess)) +
+                                               "' and your SSL fingerprint is " + sessions[user->eh.GetFd()].cert->fingerprint);
                                else
-                                       user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick.c_str(), SSL_get_cipher(sessions[user->eh.GetFd()].sess));
+                                       user->WriteNotice("*** You are connected using SSL cipher '" + std::string(SSL_get_cipher(sessions[user->eh.GetFd()].sess)) + "'");
                        }
                }
        }
 
-       void OnCleanup(int target_type, void* item)
+       void OnCleanup(int target_type, void* item) CXX11_OVERRIDE
        {
                if (target_type == TYPE_USER)
                {
@@ -310,12 +310,12 @@ class ModuleSSLOpenSSL : public Module
                }
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides SSL support for clients", VF_VENDOR);
        }
 
-       void OnRequest(Request& request)
+       void OnRequest(Request& request) CXX11_OVERRIDE
        {
                if (strcmp("GET_SSL_CERT", request.id) == 0)
                {
@@ -327,7 +327,7 @@ class ModuleSSLOpenSSL : public Module
                }
        }
 
-       void OnStreamSocketAccept(StreamSocket* user, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+       void OnStreamSocketAccept(StreamSocket* user, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE
        {
                int fd = user->GetFd();
 
@@ -343,14 +343,14 @@ class ModuleSSLOpenSSL : public Module
 
                if (SSL_set_fd(session->sess, fd) == 0)
                {
-                       ServerInstance->Logs->Log("m_ssl_openssl",DEBUG,"BUG: Can't set fd with SSL_set_fd: %d", fd);
+                       ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEBUG, "BUG: Can't set fd with SSL_set_fd: %d", fd);
                        return;
                }
 
                Handshake(user, session);
        }
 
-       void OnStreamSocketConnect(StreamSocket* user)
+       void OnStreamSocketConnect(StreamSocket* user) CXX11_OVERRIDE
        {
                int fd = user->GetFd();
                /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
@@ -368,14 +368,14 @@ class ModuleSSLOpenSSL : public Module
 
                if (SSL_set_fd(session->sess, fd) == 0)
                {
-                       ServerInstance->Logs->Log("m_ssl_openssl",DEBUG,"BUG: Can't set fd with SSL_set_fd: %d", fd);
+                       ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEBUG, "BUG: Can't set fd with SSL_set_fd: %d", fd);
                        return;
                }
 
                Handshake(user, session);
        }
 
-       void OnStreamSocketClose(StreamSocket* user)
+       void OnStreamSocketClose(StreamSocket* user) CXX11_OVERRIDE
        {
                int fd = user->GetFd();
                /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
@@ -385,7 +385,7 @@ class ModuleSSLOpenSSL : public Module
                CloseSession(&sessions[fd]);
        }
 
-       int OnStreamSocketRead(StreamSocket* user, std::string& recvq)
+       int OnStreamSocketRead(StreamSocket* user, std::string& recvq) CXX11_OVERRIDE
        {
                int fd = user->GetFd();
                /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
@@ -459,7 +459,7 @@ class ModuleSSLOpenSSL : public Module
                return 0;
        }
 
-       int OnStreamSocketWrite(StreamSocket* user, std::string& buffer)
+       int OnStreamSocketWrite(StreamSocket* user, std::string& buffer) CXX11_OVERRIDE
        {
                int fd = user->GetFd();
 
@@ -635,7 +635,7 @@ class ModuleSSLOpenSSL : public Module
                }
                else
                {
-                       certinfo->fingerprint = irc::hex(md, n);
+                       certinfo->fingerprint = BinToHex(md, n);
                }
 
                if ((ASN1_UTCTIME_cmp_time_t(X509_get_notAfter(cert), ServerInstance->Time()) == -1) || (ASN1_UTCTIME_cmp_time_t(X509_get_notBefore(cert), ServerInstance->Time()) == 0))
@@ -649,7 +649,7 @@ class ModuleSSLOpenSSL : public Module
 
 static int error_callback(const char *str, size_t len, void *u)
 {
-       ServerInstance->Logs->Log("m_ssl_openssl",DEFAULT, "SSL error: " + std::string(str, len - 1));
+       ServerInstance->Logs->Log("m_ssl_openssl", LOG_DEFAULT, "SSL error: " + std::string(str, len - 1));
 
        //
        // XXX: Remove this line, it causes valgrind warnings...
diff --git a/src/modules/hash.h b/src/modules/hash.h
deleted file mode 100644 (file)
index f7bf85e..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef HASH_H
-#define HASH_H
-
-#include "modules.h"
-
-class HashProvider : public DataProvider
-{
- public:
-       const unsigned int out_size;
-       const unsigned int block_size;
-       HashProvider(Module* mod, const std::string& Name, int osiz, int bsiz)
-               : DataProvider(mod, Name), out_size(osiz), block_size(bsiz) {}
-       virtual std::string sum(const std::string& data) = 0;
-       inline std::string hexsum(const std::string& data)
-       {
-               return BinToHex(sum(data));
-       }
-
-       inline std::string b64sum(const std::string& data)
-       {
-               return BinToBase64(sum(data), NULL, 0);
-       }
-
-       /** Allows the IVs for the hash to be specified. As the choice of initial IV is
-        * important for the security of a hash, this should not be used except to
-        * maintain backwards compatability. This also allows you to change the hex
-        * sequence from its default of "0123456789abcdef", which does not improve the
-        * strength of the output, but helps confuse those attempting to implement it.
-        *
-        * Example:
-        * \code
-        * unsigned int iv[] = { 0xFFFFFFFF, 0x00000000, 0xAAAAAAAA, 0xCCCCCCCC };
-        * std::string result = Hash.sumIV(iv, "fedcba9876543210", "data");
-        * \endcode
-        */
-       virtual std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata) = 0;
-
-       /** HMAC algorithm, RFC 2104 */
-       std::string hmac(const std::string& key, const std::string& msg)
-       {
-               std::string hmac1, hmac2;
-               std::string kbuf = key.length() > block_size ? sum(key) : key;
-               kbuf.resize(block_size);
-
-               for (size_t n = 0; n < block_size; n++)
-               {
-                       hmac1.push_back(static_cast<char>(kbuf[n] ^ 0x5C));
-                       hmac2.push_back(static_cast<char>(kbuf[n] ^ 0x36));
-               }
-               hmac2.append(msg);
-               hmac1.append(sum(hmac2));
-               return sum(hmac1);
-       }
-};
-
-#endif
-
diff --git a/src/modules/httpd.h b/src/modules/httpd.h
deleted file mode 100644 (file)
index 56fd22d..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
- *   Copyright (C) 2007 John Brooks <john.brooks@dereferenced.net>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "base.h"
-
-#ifndef HTTPD_H
-#define HTTPD_H
-
-#include <string>
-#include <sstream>
-#include <map>
-
-/** A modifyable list of HTTP header fields
- */
-class HTTPHeaders
-{
- protected:
-       std::map<std::string,std::string> headers;
- public:
-
-       /** Set the value of a header
-        * Sets the value of the named header. If the header is already present, it will be replaced
-        */
-       void SetHeader(const std::string &name, const std::string &data)
-       {
-               headers[name] = data;
-       }
-
-       /** Set the value of a header, only if it doesn't exist already
-        * Sets the value of the named header. If the header is already present, it will NOT be updated
-        */
-       void CreateHeader(const std::string &name, const std::string &data)
-       {
-               if (!IsSet(name))
-                       SetHeader(name, data);
-       }
-
-       /** Remove the named header
-        */
-       void RemoveHeader(const std::string &name)
-       {
-               headers.erase(name);
-       }
-
-       /** Remove all headers
-        */
-       void Clear()
-       {
-               headers.clear();
-       }
-
-       /** Get the value of a header
-        * @return The value of the header, or an empty string
-        */
-       std::string GetHeader(const std::string &name)
-       {
-               std::map<std::string,std::string>::iterator it = headers.find(name);
-               if (it == headers.end())
-                       return std::string();
-
-               return it->second;
-       }
-
-       /** Check if the given header is specified
-        * @return true if the header is specified
-        */
-       bool IsSet(const std::string &name)
-       {
-               std::map<std::string,std::string>::iterator it = headers.find(name);
-               return (it != headers.end());
-       }
-
-       /** Get all headers, formatted by the HTTP protocol
-        * @return Returns all headers, formatted according to the HTTP protocol. There is no request terminator at the end
-        */
-       std::string GetFormattedHeaders()
-       {
-               std::string re;
-
-               for (std::map<std::string,std::string>::iterator i = headers.begin(); i != headers.end(); i++)
-                       re += i->first + ": " + i->second + "\r\n";
-
-               return re;
-       }
-};
-
-class HttpServerSocket;
-
-/** This class represents a HTTP request.
- */
-class HTTPRequest : public Event
-{
- protected:
-       std::string type;
-       std::string document;
-       std::string ipaddr;
-       std::string postdata;
-
- public:
-
-       HTTPHeaders *headers;
-       int errorcode;
-
-       /** A socket pointer, which you must return in your HTTPDocument class
-        * if you reply to this request.
-        */
-       HttpServerSocket* sock;
-
-       /** Initialize HTTPRequest.
-        * This constructor is called by m_httpd.so to initialize the class.
-        * @param request_type The request type, e.g. GET, POST, HEAD
-        * @param uri The URI, e.g. /page
-        * @param hdr The headers sent with the request
-        * @param opaque An opaque pointer used internally by m_httpd, which you must pass back to the module in your reply.
-        * @param ip The IP address making the web request.
-        * @param pdata The post data (content after headers) received with the request, up to Content-Length in size
-        */
-       HTTPRequest(Module* me, const std::string &eventid, const std::string &request_type, const std::string &uri,
-               HTTPHeaders* hdr, HttpServerSocket* socket, const std::string &ip, const std::string &pdata)
-               : Event(me, eventid), type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(socket)
-       {
-       }
-
-       /** Get the post data (request content).
-        * All post data will be returned, including carriage returns and linefeeds.
-        * @return The postdata
-        */
-       std::string& GetPostData()
-       {
-               return postdata;
-       }
-
-       /** Get the request type.
-        * Any request type can be intercepted, even ones which are invalid in the HTTP/1.1 spec.
-        * @return The request type, e.g. GET, POST, HEAD
-        */
-       std::string& GetType()
-       {
-               return type;
-       }
-
-       /** Get URI.
-        * The URI string (URL minus hostname and scheme) will be provided by this function.
-        * @return The URI being requested
-        */
-       std::string& GetURI()
-       {
-               return document;
-       }
-
-       /** Get IP address of requester.
-        * The requesting system's ip address will be returned.
-        * @return The IP address as a string
-        */
-       std::string& GetIP()
-       {
-               return ipaddr;
-       }
-};
-
-/** You must return a HTTPDocument to the httpd module by using the Request class.
- * When you initialize this class you may initialize it with all components required to
- * form a valid HTTP response, including document data, headers, and a response code.
- */
-class HTTPDocumentResponse : public Request
-{
- public:
-       std::stringstream* document;
-       int responsecode;
-       HTTPHeaders headers;
-       HTTPRequest& src;
-
-       /** Initialize a HTTPRequest ready for sending to m_httpd.so.
-        * @param opaque The socket pointer you obtained from the HTTPRequest at an earlier time
-        * @param doc A stringstream containing the document body
-        * @param response A valid HTTP/1.0 or HTTP/1.1 response code. The response text will be determined for you
-        * based upon the response code.
-        * @param extra Any extra headers to include with the defaults, seperated by carriage return and linefeed.
-        */
-       HTTPDocumentResponse(Module* me, HTTPRequest& req, std::stringstream* doc, int response)
-               : Request(me, req.source, "HTTP-DOC"), document(doc), responsecode(response), src(req)
-       {
-       }
-};
-
-#endif
-
index a744f55f66a235d1dd657f01cd9a02e1bade069d..7d1f68cb60fc0419397594f1612e2793484bb2b6 100644 (file)
@@ -24,7 +24,7 @@
 class ModuleAbbreviation : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->Attach(I_OnPreCommand, this);
        }
@@ -34,12 +34,12 @@ class ModuleAbbreviation : public Module
                ServerInstance->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_FIRST);
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the ability to abbreviate commands a-la BBC BASIC keywords.",VF_VENDOR);
        }
 
-       virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                /* Command is already validated, has a length of 0, or last character is not a . */
                if (validated || command.empty() || *command.rbegin() != '.')
index 25f071bab3ded04560ae8f7e73f7afc42991d38b..118cedeea014c1b066d415df8deee77a12fc6fe1 100644 (file)
@@ -59,20 +59,18 @@ class Alias
 
 class ModuleAlias : public Module
 {
- private:
-
        char fprefix;
 
        /* We cant use a map, there may be multiple aliases with the same name.
         * We can, however, use a fancy invention: the multimap. Maps a key to one or more values.
         *              -- w00t
-   */
+     */
        std::multimap<irc::string, Alias> Aliases;
 
        /* whether or not +B users are allowed to use fantasy commands */
        bool AllowBots;
 
-       virtual void ReadAliases()
+       void ReadAliases()
        {
                ConfigTag* fantasy = ServerInstance->Config->ConfValue("fantasy");
                AllowBots = fantasy->getBool("allowbots", false);
@@ -100,19 +98,14 @@ class ModuleAlias : public Module
        }
 
  public:
-
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ReadAliases();
                Implementation eventlist[] = { I_OnPreCommand, I_OnRehash, I_OnUserMessage };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleAlias()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides aliases of commands.", VF_VENDOR);
        }
@@ -142,7 +135,7 @@ class ModuleAlias : public Module
                return word;
        }
 
-       virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                std::multimap<irc::string, Alias>::iterator i, upperbound;
 
@@ -182,9 +175,9 @@ class ModuleAlias : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnUserMessage(User *user, void *dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
+       void OnUserMessage(User *user, void *dest, int target_type, const std::string &text, char status, const CUList &exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
-               if (target_type != TYPE_CHANNEL)
+               if ((target_type != TYPE_CHANNEL) || (msgtype != MSG_PRIVMSG))
                {
                        return;
                }
@@ -270,7 +263,7 @@ class ModuleAlias : public Module
                        }
                }
 
-               if ((a->OperOnly) && (!IS_OPER(user)))
+               if ((a->OperOnly) && (!user->IsOper()))
                        return 0;
 
                if (!a->RequiredNick.empty())
@@ -367,19 +360,19 @@ class ModuleAlias : public Module
                std::string command, token;
 
                ss.GetToken(command);
-               while (ss.GetToken(token) && (pars.size() <= MAXPARAMETERS))
+               while (ss.GetToken(token))
                {
                        pars.push_back(token);
                }
                ServerInstance->Parser->CallHandler(command, pars, user);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ReadAliases();
        }
 
-       virtual void Prioritize()
+       void Prioritize()
        {
                // Prioritise after spanningtree so that channel aliases show the alias before the effects.
                Module* linkmod = ServerInstance->Modules->Find("m_spanningtree.so");
index 08a5f542aeab68ac8e36e6b469cc615e015d1989..dc6d6da89c8d4a10a1963a2a3b966ec3bd0586ea 100644 (file)
@@ -36,19 +36,19 @@ class ModuleAllowInvite : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(ni);
                Implementation eventlist[] = { I_OnUserPreInvite, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('A');
+               tokens["EXTBAN"].push_back('A');
        }
 
-       virtual ModResult OnUserPreInvite(User* user,User* dest,Channel* channel, time_t timeout)
+       ModResult OnUserPreInvite(User* user,User* dest,Channel* channel, time_t timeout) CXX11_OVERRIDE
        {
                if (IS_LOCAL(user))
                {
@@ -69,11 +69,7 @@ class ModuleAllowInvite : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleAllowInvite()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for channel mode +A, allowing /invite freely on a channel and extban A to deny specific users it",VF_VENDOR);
        }
index 38ae4b254f7c7853ab30d99d7c0d5975e8ffa02b..d0331a99457f6c940af426c01850a8132e9c5adb 100644 (file)
@@ -52,7 +52,6 @@ class CommandAlltime : public Command
        }
 };
 
-
 class Modulealltime : public Module
 {
        CommandAlltime mycommand;
@@ -62,16 +61,12 @@ class Modulealltime : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(mycommand);
        }
 
-       virtual ~Modulealltime()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Display timestamps from all servers connected to the network", VF_OPTCOMMON | VF_VENDOR);
        }
index c3e31c583275b36ebc7b035569fe46d64e4a8887..86fdad78591e2fbbf013620a22873190e7977405 100644 (file)
@@ -43,17 +43,17 @@ class AuditoriumMode : public ModeHandler
 
 class ModuleAuditorium : public Module
 {
- private:
        AuditoriumMode aum;
        bool OpsVisible;
        bool OpsCanSee;
        bool OperCanSee;
+
  public:
        ModuleAuditorium() : aum(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(aum);
 
@@ -66,11 +66,7 @@ class ModuleAuditorium : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ~ModuleAuditorium()
-       {
-       }
-
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
                OpsVisible = tag->getBool("opvisible");
@@ -78,7 +74,7 @@ class ModuleAuditorium : public Module
                OperCanSee = tag->getBool("opercansee", true);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
        }
@@ -112,7 +108,7 @@ class ModuleAuditorium : public Module
                return false;
        }
 
-       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
+       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
        {
                // Some module already hid this from being displayed, don't bother
                if (nick.empty())
@@ -141,22 +137,22 @@ class ModuleAuditorium : public Module
                }
        }
 
-       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
+       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE
        {
                BuildExcept(memb, excepts);
        }
 
-       void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
+       void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE
        {
                BuildExcept(memb, excepts);
        }
 
-       void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
+       void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
        {
                BuildExcept(memb, excepts);
        }
 
-       void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception)
+       void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception) CXX11_OVERRIDE
        {
                UCListIter i = include.begin();
                while (i != include.end())
@@ -177,7 +173,7 @@ class ModuleAuditorium : public Module
                }
        }
 
-       void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
+       void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line) CXX11_OVERRIDE
        {
                Channel* channel = ServerInstance->FindChan(params[0]);
                if (!channel)
index 07dca6929fef2f9f2aa9006a051a59262941d7c6..85b14ba7ad6dfdfb1dac8782f292635b316911ae 100644 (file)
@@ -19,7 +19,7 @@
 
 
 #include "inspircd.h"
-#include "u_listmode.h"
+#include "listmode.h"
 
 /* $ModDesc: Provides support for the +w channel mode, autoop list */
 
@@ -82,12 +82,12 @@ class ModuleAutoOp : public Module
 {
        AutoOpList mh;
 
-public:
+ public:
        ModuleAutoOp() : mh(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(mh);
                mh.DoImplements(this);
@@ -96,18 +96,18 @@ public:
                ServerInstance->Modules->Attach(list, this, sizeof(list)/sizeof(Implementation));
        }
 
-       void OnPostJoin(Membership *memb)
+       void OnPostJoin(Membership *memb) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(memb->user))
                        return;
 
-               modelist* list = mh.extItem.get(memb->chan);
+               ListModeBase::ModeList* list = mh.GetList(memb->chan);
                if (list)
                {
                        std::string modeline("+");
                        std::vector<std::string> modechange;
                        modechange.push_back(memb->chan->name);
-                       for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                       for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
                        {
                                std::string::size_type colon = it->mask.find(':');
                                if (colon == std::string::npos)
@@ -127,17 +127,17 @@ public:
                }
        }
 
-       void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
+       void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
        {
                mh.DoSyncChannel(chan, proto, opaque);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                mh.DoRehash();
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the +w channel mode", VF_VENDOR);
        }
index 1811f743de59e5dd7fc64124b1d66ba5ccb9cb32..a2fd17651ffe58d3c8a1b178f921265fd7d39846 100644 (file)
 
 
 #include "inspircd.h"
-#include "u_listmode.h"
+#include "listmode.h"
 
 /* $ModDesc: Provides support for the +e channel mode */
-/* $ModDep: ../../include/u_listmode.h */
 
 /* Written by Om<om@inspircd.org>, April 2005. */
 /* Rewritten to use the listmode utility by Om, December 2005 */
@@ -49,12 +48,12 @@ class ModuleBanException : public Module
 {
        BanException be;
 
-public:
+ public:
        ModuleBanException() : be(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(be);
 
@@ -63,21 +62,21 @@ public:
                ServerInstance->Modules->Attach(list, this, sizeof(list)/sizeof(Implementation));
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" EXCEPTS=e");
+               tokens["EXCEPTS"] = "e";
        }
 
-       ModResult OnExtBanCheck(User *user, Channel *chan, char type)
+       ModResult OnExtBanCheck(User *user, Channel *chan, char type) CXX11_OVERRIDE
        {
                if (chan != NULL)
                {
-                       modelist *list = be.extItem.get(chan);
+                       ListModeBase::ModeList *list = be.GetList(chan);
 
                        if (!list)
                                return MOD_RES_PASSTHRU;
 
-                       for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                       for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
                        {
                                if (it->mask[0] != type || it->mask[1] != ':')
                                        continue;
@@ -93,11 +92,11 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnCheckChannelBan(User* user, Channel* chan)
+       ModResult OnCheckChannelBan(User* user, Channel* chan) CXX11_OVERRIDE
        {
                if (chan)
                {
-                       modelist *list = be.extItem.get(chan);
+                       ListModeBase::ModeList *list = be.GetList(chan);
 
                        if (!list)
                        {
@@ -105,7 +104,7 @@ public:
                                return MOD_RES_PASSTHRU;
                        }
 
-                       for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                       for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
                        {
                                if (chan->CheckBan(user, it->mask))
                                {
@@ -117,17 +116,17 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
+       void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
        {
                be.DoSyncChannel(chan, proto, opaque);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                be.DoRehash();
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the +e channel mode", VF_VENDOR);
        }
index ee52a5cfbb8d058dfad23061c5872e475cf9c224..c79023ccf5f0bd85222684906ee2e974e5d49d01 100644 (file)
@@ -23,7 +23,7 @@
 
 
 #include "inspircd.h"
-#include "u_listmode.h"
+#include "listmode.h"
 
 /* $ModDesc: Allows an extended ban (+b) syntax redirecting banned users to another channel */
 
@@ -43,18 +43,20 @@ class BanRedirectEntry
 };
 
 typedef std::vector<BanRedirectEntry> BanRedirectList;
-typedef std::deque<std::string> StringDeque;
 
 class BanRedirect : public ModeWatcher
 {
+       ModeReference ban;
  public:
        SimpleExtItem<BanRedirectList> extItem;
-       BanRedirect(Module* parent) : ModeWatcher(parent, 'b', MODETYPE_CHANNEL),
-               extItem("banredirect", parent)
+       BanRedirect(Module* parent)
+               : ModeWatcher(parent, "ban", MODETYPE_CHANNEL)
+               , ban(parent, "ban")
+               , extItem("banredirect", parent)
        {
        }
 
-       bool BeforeMode(User* source, User* dest, Channel* channel, std::string &param, bool adding, ModeType type)
+       bool BeforeMode(User* source, User* dest, Channel* channel, std::string &param, bool adding)
        {
                /* nick!ident@host -> nick!ident@host
                 * nick!ident@host#chan -> nick!ident@host#chan
@@ -63,21 +65,23 @@ class BanRedirect : public ModeWatcher
                 * nick#chan -> nick!*@*#chan
                 */
 
-               if(channel && (type == MODETYPE_CHANNEL) && param.length())
+               if ((channel) && !param.empty())
                {
                        BanRedirectList* redirects;
 
                        std::string mask[4];
                        enum { NICK, IDENT, HOST, CHAN } current = NICK;
                        std::string::iterator start_pos = param.begin();
-                       long maxbans = channel->GetMaxBans();
 
                        if (param.length() >= 2 && param[1] == ':')
                                return true;
 
-                       if(adding && (channel->bans.size() > static_cast<unsigned>(maxbans)))
+                       ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+                       unsigned int maxbans = banlm->GetLimit(channel);
+                       ListModeBase::ModeList* list = banlm->GetList(channel);
+                       if ((list) && (adding) && (maxbans <= list->size()))
                        {
-                               source->WriteNumeric(478, "%s %s :Channel ban list for %s is full (maximum entries for this channel is %ld)", source->nick.c_str(), channel->name.c_str(), channel->name.c_str(), maxbans);
+                               source->WriteNumeric(478, "%s %s :Channel ban list for %s is full (maximum entries for this channel is %u)", source->nick.c_str(), channel->name.c_str(), channel->name.c_str(), maxbans);
                                return false;
                        }
 
@@ -133,7 +137,7 @@ class BanRedirect : public ModeWatcher
                        {
                                if (adding && IS_LOCAL(source))
                                {
-                                       if (!ServerInstance->IsChannel(mask[CHAN].c_str(),  ServerInstance->Config->Limits.ChanMax))
+                                       if (!ServerInstance->IsChannel(mask[CHAN]))
                                        {
                                                source->WriteNumeric(403, "%s %s :Invalid channel name in redirection (%s)", source->nick.c_str(), channel->name.c_str(), mask[CHAN].c_str());
                                                return false;
@@ -222,17 +226,15 @@ class ModuleBanRedirect : public Module
        }
 
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
-               if(!ServerInstance->Modes->AddModeWatcher(&re))
-                       throw ModuleException("Could not add mode watcher");
-
+               ServerInstance->Modes->AddModeWatcher(&re);
                ServerInstance->Modules->AddService(re.extItem);
                Implementation list[] = { I_OnUserPreJoin };
                ServerInstance->Modules->Attach(list, this, sizeof(list)/sizeof(Implementation));
        }
 
-       virtual void OnCleanup(int target_type, void* item)
+       void OnCleanup(int target_type, void* item) CXX11_OVERRIDE
        {
                if(target_type == TYPE_CHANNEL)
                {
@@ -242,7 +244,7 @@ class ModuleBanRedirect : public Module
                        if(redirects)
                        {
                                irc::modestacker modestack(false);
-                               StringDeque stackresult;
+                               std::vector<std::string> stackresult;
                                std::vector<std::string> mode_junk;
                                mode_junk.push_back(chan->name);
 
@@ -267,7 +269,7 @@ class ModuleBanRedirect : public Module
                }
        }
 
-       virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                if (chan)
                {
@@ -323,7 +325,7 @@ class ModuleBanRedirect : public Module
                                                        user->WriteNumeric(474, "%s %s :Cannot join channel (You are banned)", user->nick.c_str(), chan->name.c_str());
                                                        user->WriteNumeric(470, "%s %s %s :You are banned from this channel, so you are automatically transfered to the redirected channel.", user->nick.c_str(), chan->name.c_str(), redir->targetchan.c_str());
                                                        nofollow = true;
-                                                       Channel::JoinUser(user, redir->targetchan.c_str(), false, "", false, ServerInstance->Time());
+                                                       Channel::JoinUser(user, redir->targetchan);
                                                        nofollow = false;
                                                        return MOD_RES_DENY;
                                                }
@@ -334,14 +336,14 @@ class ModuleBanRedirect : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleBanRedirect()
+       ~ModuleBanRedirect()
        {
                /* XXX is this the best place to do this? */
                if (!ServerInstance->Modes->DelModeWatcher(&re))
-                       ServerInstance->Logs->Log("m_banredirect.so", DEBUG, "Failed to delete modewatcher!");
+                       ServerInstance->Logs->Log("m_banredirect.so", LOG_DEBUG, "Failed to delete modewatcher!");
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows an extended ban (+b) syntax redirecting banned users to another channel", VF_COMMON|VF_VENDOR);
        }
index be861447f36effcab132852d2f8e32836fe45387..18eb76775a90bf44af571645e9098eb7b021244c 100644 (file)
@@ -37,7 +37,7 @@ enum BlockAction { IBLOCK_KILL, IBLOCK_KILLOPERS, IBLOCK_NOTICE, IBLOCK_NOTICEOP
  */
 class BlockedMessage
 {
-public:
+ public:
        std::string message;
        irc::string target;
        time_t sent;
@@ -59,7 +59,7 @@ class ModuleBlockAmsg : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                this->OnRehash(NULL);
                ServerInstance->Modules->AddService(blockamsg);
@@ -67,16 +67,12 @@ class ModuleBlockAmsg : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleBlockAmsg()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Attempt to block /amsg, at least some of the irritating mIRC scripts.",VF_VENDOR);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("blockamsg");
                ForgetDelay = tag->getInt("delay", -1);
@@ -94,7 +90,7 @@ class ModuleBlockAmsg : public Module
                        action = IBLOCK_KILLOPERS;
        }
 
-       virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                // Don't do anything with unregistered users
                if (user->registered != REG_ALL)
@@ -169,5 +165,4 @@ class ModuleBlockAmsg : public Module
        }
 };
 
-
 MODULE_INIT(ModuleBlockAmsg)
index 2006936992aa333723efa750548e38acd964030a..0e1fa945ffecfdd5ef391d71b6a431d592fc1692 100644 (file)
@@ -39,31 +39,31 @@ class ModuleBlockCAPS : public Module
        int percent;
        unsigned int minlen;
        char capsmap[256];
-public:
 
+public:
        ModuleBlockCAPS() : bc(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                ServerInstance->Modules->AddService(bc);
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_On005Numeric };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_OnRehash, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('B');
+               tokens["EXTBAN"].push_back('B');
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ReadConf();
        }
 
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (target_type == TYPE_CHANNEL)
                {
@@ -105,11 +105,6 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
-       }
-
        void ReadConf()
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("blockcaps");
@@ -121,21 +116,17 @@ public:
                        capsmap[(unsigned char)*n] = 1;
                if (percent < 1 || percent > 100)
                {
-                       ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
+                       ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
                        percent = 100;
                }
                if (minlen < 1 || minlen > MAXBUF-1)
                {
-                       ServerInstance->Logs->Log("CONFIG",DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
+                       ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
                        minlen = 1;
                }
        }
 
-       virtual ~ModuleBlockCAPS()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support to block all-CAPS channel messages and notices", VF_VENDOR);
        }
index 3cc01b4c05bcc842f98f121e41da040ec5b366fa..2c7207698cbaab65c0d8f80bc54c15bb0fc7f30a 100644 (file)
@@ -42,19 +42,19 @@ class ModuleBlockColor : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(bc);
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('c');
+               tokens["EXTBAN"].push_back('c');
        }
 
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
                {
@@ -86,16 +86,7 @@ class ModuleBlockColor : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
-       }
-
-       virtual ~ModuleBlockColor()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +c to block color",VF_VENDOR);
        }
index b29c58240689be37d9e86a4d8be12193c860ef11..ca1a9d5c82a2cb0a346502c756aead935b87d00a 100644 (file)
@@ -40,31 +40,25 @@ class ModuleBotMode : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(bm);
                Implementation eventlist[] = { I_OnWhois };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleBotMode()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides user mode +B to mark the user as a bot",VF_VENDOR);
        }
 
-       virtual void OnWhois(User* src, User* dst)
+       void OnWhois(User* src, User* dst) CXX11_OVERRIDE
        {
                if (dst->IsModeSet('B'))
                {
                        ServerInstance->SendWhoisLine(src, dst, 335, src->nick+" "+dst->nick+" :is a bot on "+ServerInstance->Config->Network);
                }
        }
-
 };
 
-
 MODULE_INIT(ModuleBotMode)
index 37787b525ee5e1a504dca701b96cba852cc835cd..9cc9aaf5ecb88d717d14779b4658e097e6ec310c 100644 (file)
@@ -117,7 +117,7 @@ struct CallerIDExtInfo : public ExtensionItem
 
                        if (!targ)
                        {
-                               ServerInstance->Logs->Log("m_callerid", DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (1)");
+                               ServerInstance->Logs->Log("m_callerid", LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (1)");
                                continue; // shouldn't happen, but oh well.
                        }
 
@@ -125,7 +125,7 @@ struct CallerIDExtInfo : public ExtensionItem
                        if (it2 != targ->wholistsme.end())
                                targ->wholistsme.erase(it2);
                        else
-                               ServerInstance->Logs->Log("m_callerid", DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (2)");
+                               ServerInstance->Logs->Log("m_callerid", LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (2)");
                }
                delete dat;
        }
@@ -150,7 +150,7 @@ public:
                TRANSLATE2(TR_CUSTOM, TR_END);
        }
 
-       virtual void EncodeParameter(std::string& parameter, int index)
+       void EncodeParameter(std::string& parameter, int index)
        {
                if (index != 0)
                        return;
@@ -258,7 +258,7 @@ public:
                callerid_data *targ = extInfo.get(whotoadd, true);
                targ->wholistsme.push_back(dat);
 
-               user->WriteServ("NOTICE %s :%s is now on your accept list", user->nick.c_str(), whotoadd->nick.c_str());
+               user->WriteNotice(whotoadd->nick + " is now on your accept list");
                return true;
        }
 
@@ -285,7 +285,7 @@ public:
                if (!dat2)
                {
                        // How the fuck is this possible.
-                       ServerInstance->Logs->Log("m_callerid", DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (3)");
+                       ServerInstance->Logs->Log("m_callerid", LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (3)");
                        return false;
                }
 
@@ -294,17 +294,16 @@ public:
                        // Found me!
                        dat2->wholistsme.erase(it);
                else
-                       ServerInstance->Logs->Log("m_callerid", DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (4)");
+                       ServerInstance->Logs->Log("m_callerid", LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (4)");
 
 
-               user->WriteServ("NOTICE %s :%s is no longer on your accept list", user->nick.c_str(), whotoremove->nick.c_str());
+               user->WriteNotice(whotoremove->nick + " is no longer on your accept list");
                return true;
        }
 };
 
 class ModuleCallerID : public Module
 {
-private:
        CommandAccept cmd;
        User_g myumode;
 
@@ -334,7 +333,7 @@ private:
                        if (it2 != dat->accepting.end())
                                dat->accepting.erase(it2);
                        else
-                               ServerInstance->Logs->Log("m_callerid", DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (5)");
+                               ServerInstance->Logs->Log("m_callerid", LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (5)");
                }
 
                userdata->wholistsme.clear();
@@ -345,7 +344,7 @@ public:
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
 
@@ -353,22 +352,18 @@ public:
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->Modules->AddService(cmd.extInfo);
 
-               Implementation eventlist[] = { I_OnRehash, I_OnUserPostNick, I_OnUserQuit, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage };
+               Implementation eventlist[] = { I_OnRehash, I_OnUserPostNick, I_OnUserQuit, I_On005Numeric, I_OnUserPreMessage };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleCallerID()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implementation of callerid, usermode +g, /accept", VF_COMMON | VF_VENDOR);
        }
 
-       virtual void On005Numeric(std::string& output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output += " CALLERID=g";
+               tokens["CALLERID"] = "g";
        }
 
        ModResult PreText(User* user, User* dest, std::string& text)
@@ -376,7 +371,7 @@ public:
                if (!dest->IsModeSet('g') || (user == dest))
                        return MOD_RES_PASSTHRU;
 
-               if (operoverride && IS_OPER(user))
+               if (operoverride && user->IsOper())
                        return MOD_RES_PASSTHRU;
 
                callerid_data* dat = cmd.extInfo.get(dest, true);
@@ -399,15 +394,7 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList &exempt_list)
-       {
-               if (IS_LOCAL(user) && target_type == TYPE_USER)
-                       return PreText(user, (User*)dest, text);
-
-               return MOD_RES_PASSTHRU;
-       }
-
-       virtual ModResult OnUserPreNotice(User* user, void* dest, int target_type, std::string& text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (IS_LOCAL(user) && target_type == TYPE_USER)
                        return PreText(user, (User*)dest, text);
@@ -415,18 +402,18 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       void OnUserPostNick(User* user, const std::string& oldnick)
+       void OnUserPostNick(User* user, const std::string& oldnick) CXX11_OVERRIDE
        {
                if (!tracknick)
                        RemoveFromAllAccepts(user);
        }
 
-       void OnUserQuit(User* user, const std::string& message, const std::string& oper_message)
+       void OnUserQuit(User* user, const std::string& message, const std::string& oper_message) CXX11_OVERRIDE
        {
                RemoveFromAllAccepts(user);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("callerid");
                cmd.maxaccepts = tag->getInt("maxaccepts", 16);
@@ -437,5 +424,3 @@ public:
 };
 
 MODULE_INIT(ModuleCallerID)
-
-
index e9f4dae90e09684c37d9286e23543ca9d636817a..1d165f9355e427db5cfff61310c1b4d872eab87e 100644 (file)
@@ -19,7 +19,7 @@
 
 
 #include "inspircd.h"
-#include "m_cap.h"
+#include "modules/cap.h"
 
 /* $ModDesc: Provides the CAP negotiation mechanism seen in ratbox-derived ircds */
 
@@ -132,7 +132,7 @@ class ModuleCAP : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->Modules->AddService(cmd.reghold);
@@ -141,7 +141,7 @@ class ModuleCAP : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ModResult OnCheckReady(LocalUser* user)
+       ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
        {
                /* Users in CAP state get held until CAP END */
                if (cmd.reghold.get(user))
@@ -150,15 +150,10 @@ class ModuleCAP : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ~ModuleCAP()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Client CAP extension support", VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleCAP)
-
diff --git a/src/modules/m_cap.h b/src/modules/m_cap.h
deleted file mode 100644 (file)
index 409671f..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef M_CAP_H
-#define M_CAP_H
-
-class CapEvent : public Event
-{
- public:
-       enum CapEventType
-       {
-               CAPEVENT_REQ,
-               CAPEVENT_LS,
-               CAPEVENT_LIST,
-               CAPEVENT_CLEAR
-       };
-
-       CapEventType type;
-       std::vector<std::string> wanted;
-       std::vector<std::string> ack;
-       User* user;
-       CapEvent(Module* sender, User* u, CapEventType capevtype) : Event(sender, "cap_request"), type(capevtype), user(u) {}
-};
-
-class GenericCap
-{
- public:
-       LocalIntExt ext;
-       const std::string cap;
-       GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
-       {
-               ServerInstance->Modules->AddService(ext);
-       }
-
-       void HandleEvent(Event& ev)
-       {
-               if (ev.id != "cap_request")
-                       return;
-
-               CapEvent *data = static_cast<CapEvent*>(&ev);
-               if (data->type == CapEvent::CAPEVENT_REQ)
-               {
-                       for (std::vector<std::string>::iterator it = data->wanted.begin(); it != data->wanted.end(); ++it)
-                       {
-                               if (it->empty())
-                                       continue;
-                               bool enablecap = ((*it)[0] != '-');
-                               if (((enablecap) && (*it == cap)) || (*it == "-" + cap))
-                               {
-                                       // we can handle this, so ACK it, and remove it from the wanted list
-                                       data->ack.push_back(*it);
-                                       data->wanted.erase(it);
-                                       ext.set(data->user, enablecap ? 1 : 0);
-                                       break;
-                               }
-                       }
-               }
-               else if (data->type == CapEvent::CAPEVENT_LS)
-               {
-                       data->wanted.push_back(cap);
-               }
-               else if (data->type == CapEvent::CAPEVENT_LIST)
-               {
-                       if (ext.get(data->user))
-                               data->wanted.push_back(cap);
-               }
-               else if (data->type == CapEvent::CAPEVENT_CLEAR)
-               {
-                       data->ack.push_back("-" + cap);
-                       ext.set(data->user, 0);
-               }
-       }
-};
-
-#endif
index fb78e41b29cb45f9dede6dc908c219e94060c203..7dedb74415c214ff3511337b1dfcad3a553d27bb 100644 (file)
  */
 class CBan : public XLine
 {
-public:
+private:
+       std::string displaytext;
        irc::string matchtext;
 
+public:
        CBan(time_t s_time, long d, const std::string& src, const std::string& re, const std::string& ch)
                : XLine(s_time, d, src, re, "CBAN")
        {
+               this->displaytext = ch;
                this->matchtext = ch.c_str();
        }
 
-       ~CBan()
-       {
-       }
-
        // XXX I shouldn't have to define this
        bool Matches(User *u)
        {
@@ -55,15 +54,9 @@ public:
                return false;
        }
 
-       void DisplayExpiry()
+       const std::string& Displayable()
        {
-               ServerInstance->SNO->WriteToSnoMask('x',"Removing expired CBan %s (set by %s %ld seconds ago)",
-                       this->matchtext.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
-       }
-
-       const char* Displayable()
-       {
-               return matchtext.c_str();
+               return displaytext;
        }
 };
 
@@ -111,14 +104,14 @@ class CommandCBan : public Command
                        }
                        else
                        {
-                               user->WriteServ("NOTICE %s :*** CBan %s not found in list, try /stats C.",user->nick.c_str(),parameters[0].c_str());
+                               user->WriteNotice("*** CBan " + parameters[0] + " not found in list, try /stats C.");
                                return CMD_FAILURE;
                        }
                }
                else
                {
                        // Adding - XXX todo make this respect <insane> tag perhaps..
-                       long duration = ServerInstance->Duration(parameters[1]);
+                       unsigned long duration = InspIRCd::Duration(parameters[1]);
                        const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied";
                        CBan* r = new CBan(ServerInstance->Time(), duration, user->nick.c_str(), reason, parameters[0].c_str());
 
@@ -138,7 +131,7 @@ class CommandCBan : public Command
                        else
                        {
                                delete r;
-                               user->WriteServ("NOTICE %s :*** CBan for %s already exists", user->nick.c_str(), parameters[0].c_str());
+                               user->WriteNotice("*** CBan for " + parameters[0] + " already exists");
                                return CMD_FAILURE;
                        }
                }
@@ -164,7 +157,7 @@ class ModuleCBan : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->XLines->RegisterFactory(&f);
 
@@ -173,13 +166,13 @@ class ModuleCBan : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleCBan()
+       ~ModuleCBan()
        {
                ServerInstance->XLines->DelAll("CBAN");
                ServerInstance->XLines->UnregisterFactory(&f);
        }
 
-       virtual ModResult OnStats(char symbol, User* user, string_list &out)
+       ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE
        {
                if (symbol != 'C')
                        return MOD_RES_PASSTHRU;
@@ -188,27 +181,26 @@ class ModuleCBan : public Module
                return MOD_RES_DENY;
        }
 
-       virtual ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                XLine *rl = ServerInstance->XLines->MatchesLine("CBAN", cname);
 
                if (rl)
                {
                        // Channel is banned.
-                       user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname, rl->reason.c_str());
+                       user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname.c_str(), rl->reason.c_str());
                        ServerInstance->SNO->WriteGlobalSno('a', "%s tried to join %s which is CBANed (%s)",
-                                user->nick.c_str(), cname, rl->reason.c_str());
+                                user->nick.c_str(), cname.c_str(), rl->reason.c_str());
                        return MOD_RES_DENY;
                }
 
                return MOD_RES_PASSTHRU;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Gives /cban, aka C:lines. Think Q:lines, for channels.", VF_COMMON | VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleCBan)
-
index 50c8e22a7212d738b33075f15f74a848167f1ea5..03b99c77c88fb671470fc25836757ab931a1a4f0 100644 (file)
@@ -55,24 +55,19 @@ class ModuleCensor : public Module
  public:
        ModuleCensor() : cu(this), cc(this) { }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                /* Read the configuration file on startup.
                 */
                OnRehash(NULL);
                ServerInstance->Modules->AddService(cu);
                ServerInstance->Modules->AddService(cc);
-               Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice };
+               Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-
-       virtual ~ModuleCensor()
-       {
-       }
-
        // format of a config entry is <badword text="shit" replace="poo">
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return MOD_RES_PASSTHRU;
@@ -112,12 +107,7 @@ class ModuleCensor : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
-       }
-
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                /*
                 * reload our config file on rehash - we must destroy and re-allocate the classes
@@ -136,7 +126,7 @@ class ModuleCensor : public Module
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides user and channel +G mode",VF_VENDOR);
        }
index d4ef602b39f4edb3e3e1bd9cd76002da2ac7aa75..d2f24f9109999dd4010bcb986a37dff23e1b9cf9 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "inspircd.h"
 #include "xline.h"
+#include "modules/dns.h"
 
 /* $ModDesc: Change user's hosts connecting from known CGI:IRC hosts */
 
@@ -116,39 +117,44 @@ class CommandWebirc : public Command
 
 /** Resolver for CGI:IRC hostnames encoded in ident/GECOS
  */
-class CGIResolver : public Resolver
+class CGIResolver : public DNS::Request
 {
        std::string typ;
        std::string theiruid;
        LocalIntExt& waiting;
        bool notify;
  public:
-       CGIResolver(Module* me, bool NotifyOpers, const std::string &source, LocalUser* u,
-                       const std::string &type, bool &cached, LocalIntExt& ext)
-               : Resolver(source, DNS_QUERY_PTR4, cached, me), typ(type), theiruid(u->uuid),
+       CGIResolver(DNS::Manager *mgr, Module* me, bool NotifyOpers, const std::string &source, LocalUser* u,
+                       const std::string &ttype, LocalIntExt& ext)
+               : DNS::Request(mgr, me, source, DNS::QUERY_PTR), typ(ttype), theiruid(u->uuid),
                waiting(ext), notify(NotifyOpers)
        {
        }
 
-       virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
+       void OnLookupComplete(const DNS::Query *r) CXX11_OVERRIDE
        {
                /* Check the user still exists */
                User* them = ServerInstance->FindUUID(theiruid);
                if ((them) && (!them->quitting))
                {
-                       if (notify)
-                               ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s detected as using CGI:IRC (%s), changing real host to %s from %s", them->nick.c_str(), them->host.c_str(), result.c_str(), typ.c_str());
+                       LocalUser* lu = IS_LOCAL(them);
+                       if (!lu)
+                               return;
 
-                       if (result.length() > 64)
+                       const DNS::ResourceRecord &ans_record = r->answers[0];
+                       if (ans_record.rdata.empty() || ans_record.rdata.length() > 64)
                                return;
-                       them->host = result;
-                       them->dhost = result;
+
+                       if (notify)
+                               ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s detected as using CGI:IRC (%s), changing real host to %s from %s", them->nick.c_str(), them->host.c_str(), ans_record.rdata.c_str(), typ.c_str());
+
+                       them->host = them->dhost = ans_record.rdata;
                        them->InvalidateCache();
-                       them->CheckLines(true);
+                       lu->CheckLines(true);
                }
        }
 
-       virtual void OnError(ResolverError e, const std::string &errormessage)
+       void OnError(const DNS::Query *r) CXX11_OVERRIDE
        {
                if (!notify)
                        return;
@@ -160,7 +166,7 @@ class CGIResolver : public Resolver
                }
        }
 
-       virtual ~CGIResolver()
+       ~CGIResolver()
        {
                User* them = ServerInstance->FindUUID(theiruid);
                if (!them)
@@ -175,6 +181,7 @@ class ModuleCgiIRC : public Module
 {
        CommandWebirc cmd;
        LocalIntExt waiting;
+       dynamic_reference<DNS::Manager> DNS;
 
        static void RecheckClass(LocalUser* user)
        {
@@ -199,30 +206,37 @@ class ModuleCgiIRC : public Module
                user->host = user->dhost = user->GetIPString();
                user->InvalidateCache();
                RecheckClass(user);
+
                // Don't create the resolver if the core couldn't put the user in a connect class or when dns is disabled
-               if (user->quitting || ServerInstance->Config->NoUserDns)
+               if (user->quitting || !DNS || user->MyClass->nouserdns)
                        return;
 
+               CGIResolver* r = new CGIResolver(*this->DNS, this, cmd.notify, newip, user, (was_pass ? "PASS" : "IDENT"), waiting);
                try
                {
-                       bool cached;
-                       CGIResolver* r = new CGIResolver(this, cmd.notify, newip, user, (was_pass ? "PASS" : "IDENT"), cached, waiting);
-                       ServerInstance->AddResolver(r, cached);
                        waiting.set(user, waiting.get(user) + 1);
+                       this->DNS->Process(r);
                }
-               catch (...)
+               catch (DNS::Exception &ex)
                {
+                       int count = waiting.get(user);
+                       if (count)
+                               waiting.set(user, count - 1);
+                       delete r;
                        if (cmd.notify)
-                                ServerInstance->SNO->WriteToSnoMask('a', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname!", user->nick.c_str(), user->host.c_str());
+                                ServerInstance->SNO->WriteToSnoMask('a', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname; %s", user->nick.c_str(), user->host.c_str(), ex.GetReason());
                }
        }
 
 public:
-       ModuleCgiIRC() : cmd(this), waiting("cgiirc-delay", this)
+       ModuleCgiIRC()
+               : cmd(this)
+               , waiting("cgiirc-delay", this)
+               , DNS(this, "DNS")
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                ServiceProvider* providerlist[] = { &cmd, &cmd.realhost, &cmd.realip, &cmd.webirc_hostname, &cmd.webirc_ip, &waiting };
@@ -232,7 +246,7 @@ public:
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                cmd.Hosts.clear();
 
@@ -251,7 +265,7 @@ public:
                        {
                                if (type == "webirc" && password.empty())
                                {
-                                       ServerInstance->Logs->Log("CONFIG",DEFAULT, "m_cgiirc: Missing password in config: %s", hostmask.c_str());
+                                       ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "m_cgiirc: Missing password in config: %s", hostmask.c_str());
                                }
                                else
                                {
@@ -267,7 +281,7 @@ public:
                                        else
                                        {
                                                cgitype = PASS;
-                                               ServerInstance->Logs->Log("CONFIG",DEFAULT, "m_cgiirc.so: Invalid <cgihost:type> value in config: %s, setting it to \"pass\"", type.c_str());
+                                               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "m_cgiirc.so: Invalid <cgihost:type> value in config: %s, setting it to \"pass\"", type.c_str());
                                        }
 
                                        cmd.Hosts.push_back(CGIhost(hostmask, cgitype, password));
@@ -275,13 +289,13 @@ public:
                        }
                        else
                        {
-                               ServerInstance->Logs->Log("CONFIG",DEFAULT, "m_cgiirc.so: Invalid <cgihost:mask> value in config: %s", hostmask.c_str());
+                               ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "m_cgiirc.so: Invalid <cgihost:mask> value in config: %s", hostmask.c_str());
                                continue;
                        }
                }
        }
 
-       ModResult OnCheckReady(LocalUser *user)
+       ModResult OnCheckReady(LocalUser *user) CXX11_OVERRIDE
        {
                if (waiting.get(user))
                        return MOD_RES_DENY;
@@ -309,7 +323,7 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                for(CGIHostlist::iterator iter = cmd.Hosts.begin(); iter != cmd.Hosts.end(); iter++)
                {
@@ -406,7 +420,7 @@ public:
                return true;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Change user's hosts connecting from known CGI:IRC hosts",VF_VENDOR);
        }
index 997a926489b72e6b1e64df525a3a8885d82c36e6..473cda76980195abbc18969df084a4a81ec1e406 100644 (file)
 
 class ModuleChanCreate : public Module
 {
- private:
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->SNO->EnableSnomask('j', "CHANCREATE");
                Implementation eventlist[] = { I_OnUserJoin };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides snomasks 'j' and 'J', to which notices about newly created channels are sent",VF_VENDOR);
        }
 
-
-       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& except)
+       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& except) CXX11_OVERRIDE
        {
                if ((created) && (IS_LOCAL(memb->user)))
                {
index 651e659b59d437bfd468573ffc1a676a0d03c7f5..8e0bbd5381fa0f9d397f412837e17e1d689f6b5d 100644 (file)
@@ -29,7 +29,7 @@
 #define _SCL_SECURE_NO_DEPRECATE
 
 #include "inspircd.h"
-#include "u_listmode.h"
+#include "listmode.h"
 
 /** Handles channel mode +g
  */
@@ -38,7 +38,7 @@ class ChanFilter : public ListModeBase
  public:
        ChanFilter(Module* Creator) : ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", 941, 940, false, "chanfilter") { }
 
-       virtual bool ValidateParam(User* user, Channel* chan, std::string &word)
+       bool ValidateParam(User* user, Channel* chan, std::string &word)
        {
                if ((word.length() > 35) || (word.empty()))
                {
@@ -49,18 +49,17 @@ class ChanFilter : public ListModeBase
                return true;
        }
 
-       virtual bool TellListTooLong(User* user, Channel* chan, std::string &word)
+       void TellListTooLong(User* user, Channel* chan, std::string &word)
        {
                user->WriteNumeric(939, "%s %s %s :Channel spamfilter list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
-               return true;
        }
 
-       virtual void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
+       void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
        {
                user->WriteNumeric(937, "%s %s :The word %s is already on the spamfilter list",user->nick.c_str(), chan->name.c_str(), word.c_str());
        }
 
-       virtual void TellNotSet(User* user, Channel* chan, std::string &word)
+       void TellNotSet(User* user, Channel* chan, std::string &word)
        {
                user->WriteNumeric(938, "%s %s :No such spamfilter word is set",user->nick.c_str(), chan->name.c_str());
        }
@@ -78,35 +77,35 @@ class ModuleChanFilter : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cf);
 
                cf.DoImplements(this);
-               Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice, I_OnSyncChannel };
+               Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnSyncChannel };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
 
                OnRehash(NULL);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                hidemask = ServerInstance->Config->ConfValue("chanfilter")->getBool("hidemask");
                cf.DoRehash();
        }
 
-       virtual ModResult ProcessMessages(User* user,Channel* chan,std::string &text)
+       ModResult ProcessMessages(User* user,Channel* chan,std::string &text)
        {
                ModResult res = ServerInstance->OnCheckExemption(user,chan,"filter");
 
                if (!IS_LOCAL(user) || res == MOD_RES_ALLOW)
                        return MOD_RES_PASSTHRU;
 
-               modelist* list = cf.extItem.get(chan);
+               ListModeBase::ModeList* list = cf.GetList(chan);
 
                if (list)
                {
-                       for (modelist::iterator i = list->begin(); i != list->end(); i++)
+                       for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); i++)
                        {
                                if (InspIRCd::Match(text, i->mask))
                                {
@@ -122,7 +121,7 @@ class ModuleChanFilter : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (target_type == TYPE_CHANNEL)
                {
@@ -131,24 +130,15 @@ class ModuleChanFilter : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
-       }
-
-       virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
+       void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
        {
                cf.DoSyncChannel(chan, proto, opaque);
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel-specific censor lists (like mode +G but varies from channel to channel)", VF_VENDOR);
        }
-
-       virtual ~ModuleChanFilter()
-       {
-       }
 };
 
 MODULE_INIT(ModuleChanFilter)
index e48e67fe5557ffb601425de6dde5ceba787e3b7b..c114891bb80904a598481c1f0d8df1600362372c 100644 (file)
@@ -70,7 +70,7 @@ class HistoryMode : public ModeHandler
                                return MODEACTION_DENY;
 
                        unsigned int len = ConvToInt(parameter.substr(0, colon));
-                       int time = ServerInstance->Duration(duration);
+                       int time = InspIRCd::Duration(duration);
                        if (len == 0 || time < 0)
                                return MODEACTION_DENY;
                        if (len > maxlines && IS_LOCAL(source))
@@ -116,7 +116,7 @@ class ModuleChanHistory : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(m);
                ServerInstance->Modules->AddService(m.ext);
@@ -126,32 +126,30 @@ class ModuleChanHistory : public Module
                OnRehash(NULL);
        }
 
-       void OnRehash(User*)
+       void OnRehash(User*) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("chanhistory");
                m.maxlines = tag->getInt("maxlines", 50);
                sendnotice = tag->getBool("notice", true);
        }
 
-       void OnUserMessage(User* user,void* dest,int target_type, const std::string &text, char status, const CUList&)
+       void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList&, MessageType msgtype) CXX11_OVERRIDE
        {
-               if (target_type == TYPE_CHANNEL && status == 0)
+               if ((target_type == TYPE_CHANNEL) && (status == 0) && (msgtype == MSG_PRIVMSG))
                {
                        Channel* c = (Channel*)dest;
                        HistoryList* list = m.ext.get(c);
                        if (list)
                        {
-                               char buf[MAXBUF];
-                               snprintf(buf, MAXBUF, ":%s PRIVMSG %s :%s",
-                                       user->GetFullHost().c_str(), c->name.c_str(), text.c_str());
-                               list->lines.push_back(HistoryItem(buf));
+                               const std::string line = ":" + user->GetFullHost() + " PRIVMSG " + c->name + " :" + text;
+                               list->lines.push_back(HistoryItem(line));
                                if (list->lines.size() > list->maxlen)
                                        list->lines.pop_front();
                        }
                }
        }
 
-       void OnPostJoin(Membership* memb)
+       void OnPostJoin(Membership* memb) CXX11_OVERRIDE
        {
                if (IS_REMOTE(memb->user))
                        return;
@@ -165,8 +163,7 @@ class ModuleChanHistory : public Module
 
                if (sendnotice)
                {
-                       memb->user->WriteServ("NOTICE %s :Replaying up to %d lines of pre-join history spanning up to %d seconds",
-                               memb->chan->name.c_str(), list->maxlen, list->maxtime);
+                       memb->user->WriteNotice("Replaying up to " + ConvToStr(list->maxlen) + " lines of pre-join history spanning up to " + ConvToStr(list->maxtime) + " seconds");
                }
 
                for(std::deque<HistoryItem>::iterator i = list->lines.begin(); i != list->lines.end(); ++i)
@@ -176,7 +173,7 @@ class ModuleChanHistory : public Module
                }
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel history replayed on join", VF_VENDOR);
        }
index 6dbc0e7a860418d1154d36b00646d5bfa38040f4..fd25b38994a2d66861a104793a74c76d9216ba67 100644 (file)
@@ -24,7 +24,6 @@
 
 class ModuleChanLog : public Module
 {
- private:
        /*
         * Multimap so people can redirect a snomask to multiple channels.
         */
@@ -32,7 +31,7 @@ class ModuleChanLog : public Module
        ChanLogTargets logstreams;
 
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
@@ -40,11 +39,7 @@ class ModuleChanLog : public Module
                OnRehash(NULL);
        }
 
-       virtual ~ModuleChanLog()
-       {
-       }
-
-       virtual void OnRehash(User *user)
+       void OnRehash(User *user) CXX11_OVERRIDE
        {
                std::string snomasks;
                std::string channel;
@@ -59,100 +54,44 @@ class ModuleChanLog : public Module
 
                        if (channel.empty() || snomasks.empty())
                        {
-                               ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
+                               ServerInstance->Logs->Log("m_chanlog", LOG_DEFAULT, "Malformed chanlog tag, ignoring");
                                continue;
                        }
 
                        for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
                        {
                                logstreams.insert(std::make_pair(*it, channel));
-                               ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
+                               ServerInstance->Logs->Log("m_chanlog", LOG_DEFAULT, "Logging %c to %s", *it, channel.c_str());
                        }
                }
 
        }
 
-       virtual ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
+       ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg) CXX11_OVERRIDE
        {
                std::pair<ChanLogTargets::const_iterator, ChanLogTargets::const_iterator> itpair = logstreams.equal_range(sno);
                if (itpair.first == itpair.second)
                        return MOD_RES_PASSTHRU;
 
-               char buf[MAXBUF];
-               snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
+               const std::string snotice = "\2" + desc + "\2: " + msg;
 
                for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
                {
                        Channel *c = ServerInstance->FindChan(it->second);
                        if (c)
                        {
-                               c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
-                               ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
+                               c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), snotice.c_str());
+                               ServerInstance->PI->SendChannelPrivmsg(c, 0, snotice);
                        }
                }
 
                return MOD_RES_PASSTHRU;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Logs snomask output to channel(s).", VF_VENDOR);
        }
 };
 
-
 MODULE_INIT(ModuleChanLog)
-
-
-
-
-
-
-
-
-
-/*
- * This is for the "old" chanlog module which intercepted messages going to the logfile..
- * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
- * this is defined out but left intact in case someone wants to develop it further someday.
- *
- * -- w00t (aug 23rd, 2008)
- */
-#define OLD_CHANLOG 0
-
-#if OLD_CHANLOG
-class ChannelLogStream : public LogStream
-{
- private:
-       std::string channel;
-
- public:
-       ChannelLogStream(int loglevel, const std::string &chan) : LogStream(loglevel), channel(chan)
-       {
-       }
-
-       virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
-       {
-               Channel *c = ServerInstance->FindChan(channel);
-               static bool Logging = false;
-
-               if (loglevel < this->loglvl)
-                       return;
-
-               if (Logging)
-                       return;
-
-               if (c)
-               {
-                       Logging = true; // this avoids (rare chance) loops with logging server IO on networks
-                       char buf[MAXBUF];
-                       snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
-
-                       c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
-                       ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
-                       Logging = false;
-               }
-       }
-};
-#endif
-
index b5f5853e739bfc0acfbf7af0bf9c54d9cf6af254..52f781ae130548ec11f1387f1839750e5fb3dd67 100644 (file)
 
 static std::bitset<256> allowedmap;
 
-class NewIsChannelHandler : public HandlerBase2<bool, const char*, size_t>
+class NewIsChannelHandler : public HandlerBase1<bool, const std::string&>
 {
  public:
        NewIsChannelHandler() { }
-       virtual ~NewIsChannelHandler() { }
-       virtual bool Call(const char*, size_t);
+       ~NewIsChannelHandler() { }
+       bool Call(const std::string&);
 };
 
-bool NewIsChannelHandler::Call(const char* c, size_t max)
+bool NewIsChannelHandler::Call(const std::string& channame)
 {
-               /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */
-               if (!c || *c++ != '#')
+       if (channame.empty() || channame.length() > ServerInstance->Config->Limits.ChanMax || channame[0] != '#')
+               return false;
+
+       for (std::string::const_iterator c = channame.begin(); c != channame.end(); ++c)
+       {
+               unsigned int i = *c & 0xFF;
+               if (!allowedmap[i])
                        return false;
+       }
 
-               while (*c && --max)
-               {
-                       unsigned int i = *c++ & 0xFF;
-                       if (!allowedmap[i])
-                               return false;
-               }
-               // a name of exactly max length will have max = 1 here; the null does not trigger --max
-               return max;
+       return true;
 }
 
 class ModuleChannelNames : public Module
 {
- private:
        NewIsChannelHandler myhandler;
-       caller2<bool, const char*, size_t> rememberer;
+       caller1<bool, const std::string&> rememberer;
        bool badchan;
 
  public:
@@ -59,7 +57,7 @@ class ModuleChannelNames : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->IsChannel = &myhandler;
                Implementation eventlist[] = { I_OnRehash, I_OnUserKick };
@@ -73,7 +71,7 @@ class ModuleChannelNames : public Module
                std::vector<Channel*> chanvec;
                for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
                {
-                       if (!ServerInstance->IsChannel(i->second->name.c_str(), MAXBUF))
+                       if (!ServerInstance->IsChannel(i->second->name))
                                chanvec.push_back(i->second);
                }
                std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin();
@@ -104,7 +102,7 @@ class ModuleChannelNames : public Module
                badchan = false;
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("channames");
                std::string denyToken = tag->getString("denyrange");
@@ -128,7 +126,7 @@ class ModuleChannelNames : public Module
                ValidateChans();
        }
 
-       virtual void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except_list)
+       void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except_list) CXX11_OVERRIDE
        {
                if (badchan)
                {
@@ -139,13 +137,13 @@ class ModuleChannelNames : public Module
                }
        }
 
-       virtual ~ModuleChannelNames()
+       ~ModuleChannelNames()
        {
                ServerInstance->IsChannel = rememberer;
                ValidateChans();
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements config tags which allow changing characters allowed in channel names", VF_VENDOR);
        }
index 6eec486ea8a1a4cab6149d6e4651f5f3115b3859..1987a982eb53099d5ab9bdc961126e17873d91d7 100644 (file)
 
 class ModuleBadChannelExtban : public Module
 {
- private:
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnCheckBan, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ~ModuleBadChannelExtban()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Extban 'j' - channel status/join ban", VF_OPTCOMMON|VF_VENDOR);
        }
 
-       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
+       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
        {
                if ((mask.length() > 2) && (mask[0] == 'j') && (mask[1] == ':'))
                {
@@ -71,12 +66,10 @@ class ModuleBadChannelExtban : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('j');
+               tokens["EXTBAN"].push_back('j');
        }
 };
 
-
 MODULE_INIT(ModuleBadChannelExtban)
-
diff --git a/src/modules/m_chanprotect.cpp b/src/modules/m_chanprotect.cpp
deleted file mode 100644 (file)
index affd0c8..0000000
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2006-2009 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
- *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
- *   Copyright (C) 2004-2008 Craig Edwards <craigedwards@brainbox.cc>
- *   Copyright (C) 2007 John Brooks <john.brooks@dereferenced.net>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "inspircd.h"
-
-/* $ModDesc: Provides channel modes +a and +q */
-
-#define PROTECT_VALUE 40000
-#define FOUNDER_VALUE 50000
-
-struct ChanProtectSettings
-{
-       bool DeprivSelf;
-       bool DeprivOthers;
-       bool FirstInGetsFounder;
-       bool booting;
-       ChanProtectSettings() : booting(true) {}
-};
-
-static ChanProtectSettings settings;
-
-/** Handles basic operation of +qa channel modes
- */
-class FounderProtectBase
-{
- private:
-       const std::string type;
-       const char mode;
-       const int list;
-       const int end;
- public:
-       FounderProtectBase(char Mode, const std::string &mtype, int l, int e) :
-               type(mtype), mode(Mode), list(l), end(e)
-       {
-       }
-
-       void RemoveMode(Channel* channel, irc::modestacker* stack)
-       {
-               const UserMembList* cl = channel->GetUsers();
-               std::vector<std::string> mode_junk;
-               mode_junk.push_back(channel->name);
-               irc::modestacker modestack(false);
-               std::deque<std::string> stackresult;
-
-               for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
-               {
-                       if (i->second->hasMode(mode))
-                       {
-                               if (stack)
-                                       stack->Push(mode, i->first->nick);
-                               else
-                                       modestack.Push(mode, i->first->nick);
-                       }
-               }
-
-               if (stack)
-                       return;
-
-               while (modestack.GetStackedLine(stackresult))
-               {
-                       mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
-                       ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
-                       mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
-               }
-       }
-
-       void DisplayList(User* user, Channel* channel)
-       {
-               const UserMembList* cl = channel->GetUsers();
-               for (UserMembCIter i = cl->begin(); i != cl->end(); ++i)
-               {
-                       if (i->second->hasMode(mode))
-                       {
-                               user->WriteServ("%d %s %s %s", list, user->nick.c_str(), channel->name.c_str(), i->first->nick.c_str());
-                       }
-               }
-               user->WriteServ("%d %s %s :End of channel %s list", end, user->nick.c_str(), channel->name.c_str(), type.c_str());
-       }
-
-       bool CanRemoveOthers(User* u1, Channel* c)
-       {
-               Membership* m1 = c->GetUser(u1);
-               return (settings.DeprivOthers && m1 && m1->hasMode(mode));
-       }
-};
-
-/** Abstraction of FounderProtectBase for channel mode +q
- */
-class ChanFounder : public ModeHandler, public FounderProtectBase
-{
- public:
-       ChanFounder(Module* Creator)
-               : ModeHandler(Creator, "founder", 'q', PARAM_ALWAYS, MODETYPE_CHANNEL),
-                 FounderProtectBase('q', "founder", 386, 387)
-       {
-               ModeHandler::list = true;
-               levelrequired = FOUNDER_VALUE;
-               m_paramtype = TR_NICK;
-       }
-
-       void setPrefix(int pfx)
-       {
-               prefix = pfx;
-       }
-
-       unsigned int GetPrefixRank()
-       {
-               return FOUNDER_VALUE;
-       }
-
-       void RemoveMode(Channel* channel, irc::modestacker* stack)
-       {
-               FounderProtectBase::RemoveMode(channel, stack);
-       }
-
-       void RemoveMode(User* user, irc::modestacker* stack)
-       {
-       }
-       
-       ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding)
-       {
-               User* theuser = ServerInstance->FindNick(parameter);
-               // remove own privs?
-               if (source == theuser && !adding && settings.DeprivSelf)
-                       return MOD_RES_ALLOW;
-
-               if (!adding && FounderProtectBase::CanRemoveOthers(source, channel))
-               {
-                       return MOD_RES_PASSTHRU;
-               }
-               else
-               {
-                       source->WriteNumeric(468, "%s %s :Only servers may set channel mode +q", source->nick.c_str(), channel->name.c_str());
-                       return MOD_RES_DENY;
-               }
-       }
-
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
-       {
-               return MODEACTION_ALLOW;
-       }
-
-       void DisplayList(User* user, Channel* channel)
-       {
-               FounderProtectBase::DisplayList(user,channel);
-       }
-};
-
-/** Abstraction of FounderProtectBase for channel mode +a
- */
-class ChanProtect : public ModeHandler, public FounderProtectBase
-{
- public:
-       ChanProtect(Module* Creator)
-               : ModeHandler(Creator, "admin", 'a', PARAM_ALWAYS, MODETYPE_CHANNEL),
-                 FounderProtectBase('a',"protected user", 388, 389)
-       {
-               ModeHandler::list = true;
-               levelrequired = PROTECT_VALUE;
-               m_paramtype = TR_NICK;
-       }
-
-       void setPrefix(int pfx)
-       {
-               prefix = pfx;
-       }
-
-
-       unsigned int GetPrefixRank()
-       {
-               return PROTECT_VALUE;
-       }
-
-       void RemoveMode(Channel* channel, irc::modestacker* stack)
-       {
-               FounderProtectBase::RemoveMode(channel, stack);
-       }
-
-       void RemoveMode(User* user, irc::modestacker* stack)
-       {
-       }
-
-       ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding)
-       {
-               User* theuser = ServerInstance->FindNick(parameter);
-               // source has +q
-               if (channel->GetPrefixValue(source) > PROTECT_VALUE)
-                       return MOD_RES_ALLOW;
-
-               // removing own privs?
-               if (source == theuser && !adding && settings.DeprivSelf)
-                       return MOD_RES_ALLOW;
-
-               if (!adding && FounderProtectBase::CanRemoveOthers(source, channel))
-               {
-                       return MOD_RES_PASSTHRU;
-               }
-               else
-               {
-                       source->WriteNumeric(482, "%s %s :You are not a channel founder", source->nick.c_str(), channel->name.c_str());
-                       return MOD_RES_DENY;
-               }
-       }
-
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
-       {
-               return MODEACTION_ALLOW;
-       }
-
-       void DisplayList(User* user, Channel* channel)
-       {
-               FounderProtectBase::DisplayList(user, channel);
-       }
-
-};
-
-class ModuleChanProtect : public Module
-{
-       ChanProtect cp;
-       ChanFounder cf;
- public:
-       ModuleChanProtect() : cp(this), cf(this)
-       {
-       }
-
-       void init()
-       {
-               /* Load config stuff */
-               LoadSettings();
-               settings.booting = false;
-
-               ServerInstance->Modules->AddService(cf);
-               ServerInstance->Modules->AddService(cp);
-
-               Implementation eventlist[] = { I_OnUserPreJoin };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-       }
-
-       void LoadSettings()
-       {
-               ConfigTag* tag = ServerInstance->Config->ConfValue("chanprotect");
-
-               settings.FirstInGetsFounder = tag->getBool("noservices");
-
-               std::string qpre = tag->getString("qprefix");
-               char QPrefix = qpre.empty() ? 0 : qpre[0];
-
-               std::string apre = tag->getString("aprefix");
-               char APrefix = apre.empty() ? 0 : apre[0];
-
-               if ((APrefix && QPrefix) && APrefix == QPrefix)
-                       throw ModuleException("What the smeg, why are both your +q and +a prefixes the same character?");
-
-               if (settings.booting)
-               {
-                       if (APrefix && ServerInstance->Modes->FindPrefix(APrefix) && ServerInstance->Modes->FindPrefix(APrefix) != &cp)
-                               throw ModuleException("Looks like the +a prefix you picked for m_chanprotect is already in use. Pick another.");
-
-                       if (QPrefix && ServerInstance->Modes->FindPrefix(QPrefix) && ServerInstance->Modes->FindPrefix(QPrefix) != &cf)
-                               throw ModuleException("Looks like the +q prefix you picked for m_chanprotect is already in use. Pick another.");
-
-                       cp.setPrefix(APrefix);
-                       cf.setPrefix(QPrefix);
-               }
-               settings.DeprivSelf = tag->getBool("deprotectself", true);
-               settings.DeprivOthers = tag->getBool("deprotectothers", true);
-       }
-
-       ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
-       {
-               // if the user is the first user into the channel, mark them as the founder, but only if
-               // the config option for it is set
-
-               if (settings.FirstInGetsFounder && !chan)
-                       privs += 'q';
-
-               return MOD_RES_PASSTHRU;
-       }
-
-       Version GetVersion()
-       {
-               return Version("Founder and Protect modes (+qa)", VF_VENDOR);
-       }
-};
-
-MODULE_INIT(ModuleChanProtect)
index 07276445f220e1c29132aecf8131221486b59738..fda211cf80eb03061972ab36471cd3a51817439a 100644 (file)
 /* $ModDesc: Provides the /CHECK command to retrieve information on a user, channel, hostname or IP address */
 
 #include "inspircd.h"
+#include "listmode.h"
 
 /** Handle /CHECK
  */
 class CommandCheck : public Command
 {
+       ModeReference ban;
  public:
-       CommandCheck(Module* parent) : Command(parent,"CHECK", 1)
+       CommandCheck(Module* parent)
+               : Command(parent,"CHECK", 1)
+               , ban(parent, "ban")
        {
                flags_needed = 'o'; syntax = "<nickname>|<ip>|<hostmask>|<channel> <server>";
        }
@@ -96,20 +100,20 @@ class CommandCheck : public Command
                        user->SendText(checkstr + " signon " + timestring(targuser->signon));
                        user->SendText(checkstr + " nickts " + timestring(targuser->age));
                        if (loctarg)
-                               user->SendText(checkstr + " lastmsg " + timestring(targuser->idle_lastmsg));
+                               user->SendText(checkstr + " lastmsg " + timestring(loctarg->idle_lastmsg));
 
-                       if (IS_AWAY(targuser))
+                       if (targuser->IsAway())
                        {
                                /* user is away */
                                user->SendText(checkstr + " awaytime " + timestring(targuser->awaytime));
                                user->SendText(checkstr + " awaymsg " + targuser->awaymsg);
                        }
 
-                       if (IS_OPER(targuser))
+                       if (targuser->IsOper())
                        {
                                OperInfo* oper = targuser->oper;
                                /* user is an oper of type ____ */
-                               user->SendText(checkstr + " opertype " + oper->NameStr());
+                               user->SendText(checkstr + " opertype " + oper->name);
                                if (loctarg)
                                {
                                        std::string umodes;
@@ -198,18 +202,11 @@ class CommandCheck : public Command
                                user->SendText(checkstr + " member " + tmpbuf);
                        }
 
-                       irc::modestacker modestack(true);
-                       for(BanList::iterator b = targchan->bans.begin(); b != targchan->bans.end(); ++b)
-                       {
-                               modestack.Push('b', b->data);
-                       }
-                       std::vector<std::string> stackresult;
-                       std::vector<TranslateType> dummy;
-                       while (modestack.GetStackedLine(stackresult))
-                       {
-                               creator->ProtoSendMode(user, TYPE_CHANNEL, targchan, stackresult, dummy);
-                               stackresult.clear();
-                       }
+                       // We know that the mode handler for bans is in the core and is derived from ListModeBase
+                       ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+                       banlm->DoSyncChannel(targchan, creator, user);
+
+                       // Show other listmodes as well
                        FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(targchan,creator,user));
                        dumpExt(user, checkstr, targchan);
                }
@@ -250,25 +247,19 @@ class CommandCheck : public Command
        }
 };
 
-
 class ModuleCheck : public Module
 {
- private:
        CommandCheck mycommand;
  public:
        ModuleCheck() : mycommand(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(mycommand);
        }
 
-       ~ModuleCheck()
-       {
-       }
-
        void ProtoSendMode(void* uv, TargetTypeFlags, void*, const std::vector<std::string>& result, const std::vector<TranslateType>&)
        {
                User* user = (User*)uv;
@@ -285,7 +276,7 @@ class ModuleCheck : public Module
                user->SendText(checkstr);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("CHECK command, view user, channel, IP address or hostname information", VF_VENDOR|VF_OPTCOMMON);
        }
index 08f7f76fa5e0235ee9dc8ba84c558c2ccfd48f40..bae83f2da721e2e623b7ebb0d5e5980b2358f438 100644 (file)
@@ -27,7 +27,6 @@
  */
 class CommandChghost : public Command
 {
- private:
        char* hostmap;
  public:
        CommandChghost(Module* Creator, char* hmap) : Command(Creator,"CHGHOST", 2), hostmap(hmap)
@@ -44,7 +43,7 @@ class CommandChghost : public Command
 
                if (parameters[1].length() > 63)
                {
-                       user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick.c_str());
+                       user->WriteNotice("*** CHGHOST: Host too long");
                        return CMD_FAILURE;
                }
 
@@ -52,7 +51,7 @@ class CommandChghost : public Command
                {
                        if (!hostmap[(unsigned char)*x])
                        {
-                               user->WriteServ("NOTICE "+user->nick+" :*** CHGHOST: Invalid characters in hostname");
+                               user->WriteNotice("*** CHGHOST: Invalid characters in hostname");
                                return CMD_FAILURE;
                        }
                }
@@ -91,12 +90,13 @@ class ModuleChgHost : public Module
 {
        CommandChghost cmd;
        char hostmap[256];
+
  public:
        ModuleChgHost() : cmd(this, hostmap)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                ServerInstance->Modules->AddService(cmd);
@@ -104,7 +104,7 @@ class ModuleChgHost : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                std::string hmap = ServerInstance->Config->ConfValue("hostname")->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789");
 
@@ -113,15 +113,10 @@ class ModuleChgHost : public Module
                        hostmap[(unsigned char)*n] = 1;
        }
 
-       ~ModuleChgHost()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the CHGHOST command", VF_OPTCOMMON | VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleChgHost)
index 2112e45a3f8d298c6f0e47a4bde6e066d25d920e..f7777c24e5e7ac2c2ce974ed330e5e2916284133 100644 (file)
@@ -49,13 +49,13 @@ class CommandChgident : public Command
 
                if (parameters[1].length() > ServerInstance->Config->Limits.IdentMax)
                {
-                       user->WriteServ("NOTICE %s :*** CHGIDENT: Ident is too long", user->nick.c_str());
+                       user->WriteNotice("*** CHGIDENT: Ident is too long");
                        return CMD_FAILURE;
                }
 
                if (!ServerInstance->IsIdent(parameters[1].c_str()))
                {
-                       user->WriteServ("NOTICE %s :*** CHGIDENT: Invalid characters in ident", user->nick.c_str());
+                       user->WriteNotice("*** CHGIDENT: Invalid characters in ident");
                        return CMD_FAILURE;
                }
 
@@ -79,7 +79,6 @@ class CommandChgident : public Command
        }
 };
 
-
 class ModuleChgIdent : public Module
 {
        CommandChgident cmd;
@@ -89,16 +88,12 @@ public:
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleChgIdent()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the CHGIDENT command", VF_OPTCOMMON | VF_VENDOR);
        }
@@ -106,4 +101,3 @@ public:
 };
 
 MODULE_INIT(ModuleChgIdent)
-
index 73ae3d4870bc93d5d65d67604f7ffc3175f4e8c3..bdeb8a44bb0304eb937be05bfcdc8d1581a170dd 100644 (file)
@@ -47,13 +47,13 @@ class CommandChgname : public Command
 
                if (parameters[1].empty())
                {
-                       user->WriteServ("NOTICE %s :*** CHGNAME: GECOS must be specified", user->nick.c_str());
+                       user->WriteNotice("*** CHGNAME: GECOS must be specified");
                        return CMD_FAILURE;
                }
 
                if (parameters[1].length() > ServerInstance->Config->Limits.MaxGecos)
                {
-                       user->WriteServ("NOTICE %s :*** CHGNAME: GECOS too long", user->nick.c_str());
+                       user->WriteNotice("*** CHGNAME: GECOS too long");
                        return CMD_FAILURE;
                }
 
@@ -75,7 +75,6 @@ class CommandChgname : public Command
        }
 };
 
-
 class ModuleChgName : public Module
 {
        CommandChgname cmd;
@@ -85,16 +84,12 @@ public:
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleChgName()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the CHGNAME command", VF_OPTCOMMON | VF_VENDOR);
        }
index 105d688337d20d0afb767059815bf10ace8c5671..ccc98e557e7ca96e99ff5b26c0c4b8c6c55ca25e 100644 (file)
 
 
 #include "inspircd.h"
-#include "hash.h"
+#include "modules/hash.h"
 
 /* $ModDesc: Provides masking of user hostnames */
 
 enum CloakMode
 {
-       /** 1.2-compatible host-based cloak */
-       MODE_COMPAT_HOST,
-       /** 1.2-compatible IP-only cloak */
-       MODE_COMPAT_IPONLY,
        /** 2.0 cloak of "half" of the hostname plus the full IP hash */
        MODE_HALF_CLOAK,
        /** 2.0 cloak of IP hash, split at 2 common CIDR range points */
@@ -49,7 +45,6 @@ class CloakUser : public ModeHandler
 {
  public:
        LocalStringExt ext;
-
        std::string debounce_uid;
        time_t debounce_ts;
        int debounce_count;
@@ -123,7 +118,6 @@ class CloakUser : public ModeHandler
                        return MODEACTION_ALLOW;
                }
        }
-
 };
 
 class CommandCloak : public Command
@@ -147,7 +141,6 @@ class ModuleCloaking : public Module
        std::string prefix;
        std::string suffix;
        std::string key;
-       unsigned int compatkey[4];
        const char* xtab[4];
        dynamic_reference<HashProvider> Hash;
 
@@ -155,7 +148,7 @@ class ModuleCloaking : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
 
@@ -224,63 +217,6 @@ class ModuleCloaking : public Module
                return rv;
        }
 
-       std::string CompatCloak4(const char* ip)
-       {
-               irc::sepstream seps(ip, '.');
-               std::string octet[4];
-               int i[4];
-
-               for (int j = 0; j < 4; j++)
-               {
-                       seps.GetToken(octet[j]);
-                       i[j] = atoi(octet[j].c_str());
-               }
-
-               octet[3] = octet[0] + "." + octet[1] + "." + octet[2] + "." + octet[3];
-               octet[2] = octet[0] + "." + octet[1] + "." + octet[2];
-               octet[1] = octet[0] + "." + octet[1];
-
-               /* Reset the Hash module and send it our IV */
-
-               std::string rv;
-
-               /* Send the Hash module a different hex table for each octet group's Hash sum */
-               for (int k = 0; k < 4; k++)
-               {
-                       rv.append(Hash->sumIV(compatkey, xtab[(compatkey[k]+i[k]) % 4], octet[k]).substr(0,6));
-                       if (k < 3)
-                               rv.append(".");
-               }
-               /* Stick them all together */
-               return rv;
-       }
-
-       std::string CompatCloak6(const char* ip)
-       {
-               std::vector<std::string> hashies;
-               std::string item;
-               int rounds = 0;
-
-               /* Reset the Hash module and send it our IV */
-
-               for (const char* input = ip; *input; input++)
-               {
-                       item += *input;
-                       if (item.length() > 7)
-                       {
-                               hashies.push_back(Hash->sumIV(compatkey, xtab[(compatkey[0]+rounds) % 4], item).substr(0,8));
-                               item.clear();
-                       }
-                       rounds++;
-               }
-               if (!item.empty())
-               {
-                       hashies.push_back(Hash->sumIV(compatkey, xtab[(compatkey[0]+rounds) % 4], item).substr(0,8));
-               }
-               /* Stick them all together */
-               return irc::stringjoiner(":", hashies, 0, hashies.size() - 1).GetJoined();
-       }
-
        std::string SegmentIP(const irc::sockets::sockaddrs& ip, bool full)
        {
                std::string bindata;
@@ -348,7 +284,7 @@ class ModuleCloaking : public Module
                return rv;
        }
 
-       ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask)
+       ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) CXX11_OVERRIDE
        {
                LocalUser* lu = IS_LOCAL(user);
                if (!lu)
@@ -359,9 +295,8 @@ class ModuleCloaking : public Module
                /* Check if they have a cloaked host, but are not using it */
                if (cloak && *cloak != user->dhost)
                {
-                       char cmask[MAXBUF];
-                       snprintf(cmask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), cloak->c_str());
-                       if (InspIRCd::Match(cmask,mask))
+                       const std::string cloakMask = user->nick + "!" + user->ident + "@" + *cloak;
+                       if (InspIRCd::Match(cloakMask, mask))
                                return MOD_RES_DENY;
                }
                return MOD_RES_PASSTHRU;
@@ -375,7 +310,7 @@ class ModuleCloaking : public Module
 
        // this unsets umode +x on every host change. If we are actually doing a +x
        // mode change, we will call SetMode back to true AFTER the host change is done.
-       void OnChangeHost(User* u, const std::string& host)
+       void OnChangeHost(User* u, const std::string& host) CXX11_OVERRIDE
        {
                if(u->IsModeSet('x'))
                {
@@ -384,23 +319,13 @@ class ModuleCloaking : public Module
                }
        }
 
-       ~ModuleCloaking()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                std::string testcloak = "broken";
                if (Hash)
                {
                        switch (mode)
                        {
-                               case MODE_COMPAT_HOST:
-                                       testcloak = prefix + "-" + Hash->sumIV(compatkey, xtab[0], "*").substr(0,10);
-                                       break;
-                               case MODE_COMPAT_IPONLY:
-                                       testcloak = Hash->sumIV(compatkey, xtab[0], "*").substr(0,10);
-                                       break;
                                case MODE_HALF_CLOAK:
                                        testcloak = prefix + SegmentCloak("*", 3, 8) + suffix;
                                        break;
@@ -411,82 +336,23 @@ class ModuleCloaking : public Module
                return Version("Provides masking of user hostnames", VF_COMMON|VF_VENDOR, testcloak);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("cloak");
                prefix = tag->getString("prefix");
                suffix = tag->getString("suffix", ".IP");
 
                std::string modestr = tag->getString("mode");
-               if (modestr == "compat-host")
-                       mode = MODE_COMPAT_HOST;
-               else if (modestr == "compat-ip")
-                       mode = MODE_COMPAT_IPONLY;
-               else if (modestr == "half")
+               if (modestr == "half")
                        mode = MODE_HALF_CLOAK;
                else if (modestr == "full")
                        mode = MODE_OPAQUE;
                else
-                       throw ModuleException("Bad value for <cloak:mode>; must be one of compat-host, compat-ip, half, full");
+                       throw ModuleException("Bad value for <cloak:mode>; must be half or full");
 
-               if (mode == MODE_COMPAT_HOST || mode == MODE_COMPAT_IPONLY)
-               {
-                       bool lowercase = tag->getBool("lowercase");
-
-                       /* These are *not* using the need_positive parameter of ReadInteger -
-                        * that will limit the valid values to only the positive values in a
-                        * signed int. Instead, accept any value that fits into an int and
-                        * cast it to an unsigned int. That will, a bit oddly, give us the full
-                        * spectrum of an unsigned integer. - Special
-                        *
-                        * We must limit the keys or else we get different results on
-                        * amd64/x86 boxes. - psychon */
-                       const unsigned int limit = 0x80000000;
-                       compatkey[0] = (unsigned int) tag->getInt("key1");
-                       compatkey[1] = (unsigned int) tag->getInt("key2");
-                       compatkey[2] = (unsigned int) tag->getInt("key3");
-                       compatkey[3] = (unsigned int) tag->getInt("key4");
-
-                       if (!lowercase)
-                       {
-                               xtab[0] = "F92E45D871BCA630";
-                               xtab[1] = "A1B9D80C72E653F4";
-                               xtab[2] = "1ABC078934DEF562";
-                               xtab[3] = "ABCDEF5678901234";
-                       }
-                       else
-                       {
-                               xtab[0] = "f92e45d871bca630";
-                               xtab[1] = "a1b9d80c72e653f4";
-                               xtab[2] = "1abc078934def562";
-                               xtab[3] = "abcdef5678901234";
-                       }
-
-                       if (prefix.empty())
-                               prefix = ServerInstance->Config->Network;
-
-                       if (!compatkey[0] || !compatkey[1] || !compatkey[2] || !compatkey[3] ||
-                               compatkey[0] >= limit || compatkey[1] >= limit || compatkey[2] >= limit || compatkey[3] >= limit)
-                       {
-                               std::string detail;
-                               if (!compatkey[0] || compatkey[0] >= limit)
-                                       detail = "<cloak:key1> is not valid, it may be set to a too high/low value, or it may not exist.";
-                               else if (!compatkey[1] || compatkey[1] >= limit)
-                                       detail = "<cloak:key2> is not valid, it may be set to a too high/low value, or it may not exist.";
-                               else if (!compatkey[2] || compatkey[2] >= limit)
-                                       detail = "<cloak:key3> is not valid, it may be set to a too high/low value, or it may not exist.";
-                               else if (!compatkey[3] || compatkey[3] >= limit)
-                                       detail = "<cloak:key4> is not valid, it may be set to a too high/low value, or it may not exist.";
-
-                               throw ModuleException("You have not defined cloak keys for m_cloaking!!! THIS IS INSECURE AND SHOULD BE CHECKED! - " + detail);
-                       }
-               }
-               else
-               {
-                       key = tag->getString("key");
-                       if (key.empty() || key == "secret")
-                               throw ModuleException("You have not defined cloak keys for m_cloaking. Define <cloak:key> as a network-wide secret.");
-               }
+               key = tag->getString("key");
+               if (key.empty() || key == "secret")
+                       throw ModuleException("You have not defined cloak keys for m_cloaking. Define <cloak:key> as a network-wide secret.");
        }
 
        std::string GenCloak(const irc::sockets::sockaddrs& ip, const std::string& ipstr, const std::string& host)
@@ -495,29 +361,6 @@ class ModuleCloaking : public Module
 
                switch (mode)
                {
-                       case MODE_COMPAT_HOST:
-                       {
-                               if (ipstr != host)
-                               {
-                                       std::string tail = LastTwoDomainParts(host);
-
-                                       // xtab is not used here due to a bug in 1.2 cloaking
-                                       chost = prefix + "-" + Hash->sumIV(compatkey, "0123456789abcdef", host).substr(0,8) + tail;
-
-                                       /* Fix by brain - if the cloaked host is > the max length of a host (64 bytes
-                                        * according to the DNS RFC) then they get cloaked as an IP.
-                                        */
-                                       if (chost.length() <= 64)
-                                               break;
-                               }
-                               // fall through to IP cloak
-                       }
-                       case MODE_COMPAT_IPONLY:
-                               if (ip.sa.sa_family == AF_INET6)
-                                       chost = CompatCloak6(ipstr.c_str());
-                               else
-                                       chost = CompatCloak4(ipstr.c_str());
-                               break;
                        case MODE_HALF_CLOAK:
                        {
                                if (ipstr != host)
@@ -533,7 +376,7 @@ class ModuleCloaking : public Module
                return chost;
        }
 
-       void OnUserConnect(LocalUser* dest)
+       void OnUserConnect(LocalUser* dest) CXX11_OVERRIDE
        {
                std::string* cloak = cu.ext.get(dest);
                if (cloak)
@@ -554,7 +397,7 @@ CmdResult CommandCloak::Handle(const std::vector<std::string> &parameters, User
        else
                cloak = mod->GenCloak(sa, "", parameters[0]);
 
-       user->WriteServ("NOTICE %s :*** Cloak for %s is %s", user->nick.c_str(), parameters[0].c_str(), cloak.c_str());
+       user->WriteNotice("*** Cloak for " + parameters[0] + " is " + cloak);
 
        return CMD_SUCCESS;
 }
index 92b1bda78fb8a8d4d186a072405c1a56340294ed..e71ee8d126dfae8f09dc0f681c8f70c65e05beb8 100644 (file)
@@ -63,31 +63,23 @@ class CommandClones : public Command
        }
 };
 
-
 class ModuleClones : public Module
 {
- private:
        CommandClones cmd;
  public:
        ModuleClones() : cmd(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleClones()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the /CLONES command to retrieve information on clones.", VF_VENDOR);
        }
-
-
 };
 
 MODULE_INIT(ModuleClones)
index 8b0ea3417a081a0c5af4eaaad2d74ce354402d48..a5e61e19f9e0071220ccb06e5ee309ff3264a1c3 100644 (file)
@@ -50,13 +50,14 @@ class CommandClose : public Command
                int total = 0;
                for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
                {
-                       src->WriteServ("NOTICE %s :*** Closed %d unknown connection%s from [%s]",src->nick.c_str(),(*ci).second,((*ci).second>1)?"s":"",(*ci).first.c_str());
-                       total += (*ci).second;
+                       src->WriteNotice("*** Closed " + ConvToStr(ci->second) + " unknown " + (ci->second == 1 ? "connection" : "connections") +
+                               " from [" + ci->first + "]");
+                       total += ci->second;
                }
                if (total)
-                       src->WriteServ("NOTICE %s :*** %i unknown connection%s closed",src->nick.c_str(),total,(total>1)?"s":"");
+                       src->WriteNotice("*** " + ConvToStr(total) + " unknown " + (total == 1 ? "connection" : "connections") + " closed");
                else
-                       src->WriteServ("NOTICE %s :*** No unknown connections found",src->nick.c_str());
+                       src->WriteNotice("*** No unknown connections found");
 
                return CMD_SUCCESS;
        }
@@ -71,16 +72,12 @@ class ModuleClose : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleClose()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides /CLOSE functionality", VF_VENDOR);
        }
index afa17add4512d437f41d58ecdad182d40c9b52ad..d9ab030539e32c9fe3ca965acfd86e84d5a733b5 100644 (file)
@@ -37,28 +37,23 @@ class ModulePrivacyMode : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(pm);
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+               ServerInstance->Modules->Attach(I_OnUserPreMessage, this);
        }
 
-       virtual ~ModulePrivacyMode()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR);
        }
 
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (target_type == TYPE_USER)
                {
                        User* t = (User*)dest;
-                       if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
+                       if (!user->IsOper() && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
                        {
                                user->WriteNumeric(ERR_CANTSENDTOUSER, "%s %s :You are not permitted to send private messages to this user (+c set)", user->nick.c_str(), t->nick.c_str());
                                return MOD_RES_DENY;
@@ -66,12 +61,6 @@ class ModulePrivacyMode : public Module
                }
                return MOD_RES_PASSTHRU;
        }
-
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
-       }
 };
 
-
 MODULE_INIT(ModulePrivacyMode)
index 6b13ab1aab8da7556d193cd8249b4e394c9ef391..bfac8147d76e2f66db164b3ef6af90078911cecc 100644 (file)
@@ -27,7 +27,7 @@
 class ModuleConnJoin : public Module
 {
        public:
-               void init()
+               void init() CXX11_OVERRIDE
                {
                        Implementation eventlist[] = { I_OnPostConnect };
                        ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
@@ -38,29 +38,29 @@ class ModuleConnJoin : public Module
                        ServerInstance->Modules->SetPriority(this, I_OnPostConnect, PRIORITY_LAST);
                }
 
-               Version GetVersion()
+               Version GetVersion() CXX11_OVERRIDE
                {
                        return Version("Forces users to join the specified channel(s) on connect", VF_VENDOR);
                }
 
-               void OnPostConnect(User* user)
+               void OnPostConnect(User* user) CXX11_OVERRIDE
                {
-                       if (!IS_LOCAL(user))
+                       LocalUser* localuser = IS_LOCAL(user);
+                       if (!localuser)
                                return;
 
                        std::string chanlist = ServerInstance->Config->ConfValue("autojoin")->getString("channel");
-                       chanlist = user->GetClass()->config->getString("autojoin", chanlist);
+                       chanlist = localuser->GetClass()->config->getString("autojoin", chanlist);
 
                        irc::commasepstream chans(chanlist);
                        std::string chan;
 
                        while (chans.GetToken(chan))
                        {
-                               if (ServerInstance->IsChannel(chan.c_str(), ServerInstance->Config->Limits.ChanMax))
-                                       Channel::JoinUser(user, chan.c_str(), false, "", false, ServerInstance->Time());
+                               if (ServerInstance->IsChannel(chan))
+                                       Channel::JoinUser(localuser, chan);
                        }
                }
 };
 
-
 MODULE_INIT(ModuleConnJoin)
index a21462ddf39a79b33dc91e537f43ee2cd802d8c0..e19bb94146e21d152f8f61d51aa29fb764bfe7ff 100644 (file)
@@ -27,7 +27,7 @@
 class ModuleModesOnConnect : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->Attach(I_OnUserConnect, this);
        }
@@ -38,16 +38,12 @@ class ModuleModesOnConnect : public Module
                ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
        }
 
-       virtual ~ModuleModesOnConnect()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Sets (and unsets) modes on users when they connect", VF_VENDOR);
        }
 
-       virtual void OnUserConnect(LocalUser* user)
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
        {
                // Backup and zero out the disabled usermodes, so that we can override them here.
                char save[64];
index 1d48220a6b096330cbafecd9e077216149042f35..1367874dae2d82bd69bb4a28873d031a81815c0c 100644 (file)
@@ -38,7 +38,7 @@ class ModuleWaitPong : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(ext);
                OnRehash(NULL);
@@ -46,27 +46,27 @@ class ModuleWaitPong : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("waitpong");
                sendsnotice = tag->getBool("sendsnotice", true);
                killonbadreply = tag->getBool("killonbadreply", true);
        }
 
-       ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                std::string pingrpl = ServerInstance->GenRandomStr(10);
 
                user->Write("PING :%s", pingrpl.c_str());
 
                if(sendsnotice)
-                       user->WriteServ("NOTICE %s :*** If you are having problems connecting due to ping timeouts, please type /quote PONG %s or /raw PONG %s now.", user->nick.c_str(), pingrpl.c_str(), pingrpl.c_str());
+                       user->WriteNotice("*** If you are having problems connecting due to ping timeouts, please type /quote PONG " + pingrpl + " or /raw PONG " + pingrpl + " now.");
 
                ext.set(user, pingrpl);
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser* user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser* user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                if (command == "PONG")
                {
@@ -90,20 +90,15 @@ class ModuleWaitPong : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnCheckReady(LocalUser* user)
+       ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
        {
                return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
        }
 
-       ~ModuleWaitPong()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Require pong prior to registration", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleWaitPong)
index 26120add984381529a736bcd3af0f8b67b4e0d61..eca9352e871e452ce114b586efbf4eb9656c577b 100644 (file)
 
 class ModuleConnectBan : public Module
 {
- private:
        clonemap connects;
        unsigned int threshold;
        unsigned int banduration;
        unsigned int ipv4_cidr;
        unsigned int ipv6_cidr;
+
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnSetUserIP, I_OnGarbageCollect, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
                OnRehash(NULL);
        }
 
-       virtual ~ModuleConnectBan()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Throttles the connections of IP ranges who try to connect flood.", VF_VENDOR);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("connectban");
 
@@ -63,12 +59,12 @@ class ModuleConnectBan : public Module
                if (threshold == 0)
                        threshold = 10;
 
-               banduration = ServerInstance->Duration(tag->getString("duration", "10m"));
+               banduration = InspIRCd::Duration(tag->getString("duration", "10m"));
                if (banduration == 0)
                        banduration = 10*60;
        }
 
-       virtual void OnSetUserIP(LocalUser* u)
+       void OnSetUserIP(LocalUser* u) CXX11_OVERRIDE
        {
                if (u->exempt)
                        return;
@@ -117,9 +113,9 @@ class ModuleConnectBan : public Module
                }
        }
 
-       virtual void OnGarbageCollect()
+       void OnGarbageCollect()
        {
-               ServerInstance->Logs->Log("m_connectban",DEBUG, "Clearing map.");
+               ServerInstance->Logs->Log("m_connectban", LOG_DEBUG, "Clearing map.");
                connects.clear();
        }
 };
index f77691e3276a8efe2f6649b4da04d31a588b79fc..ac8a2af2695adb5934066f78bc6d3dd12b720cf3 100644 (file)
@@ -25,7 +25,6 @@
 
 class ModuleConnFlood : public Module
 {
-private:
        int seconds, timeout, boot_wait;
        unsigned int conns;
        unsigned int maxconns;
@@ -39,14 +38,14 @@ public:
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                InitConf();
                Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Connection throttle", VF_VENDOR);
        }
@@ -67,7 +66,7 @@ public:
                first = ServerInstance->Time();
        }
 
-       virtual ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                if (user->exempt)
                        return MOD_RES_PASSTHRU;
@@ -115,7 +114,7 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                InitConf();
        }
index dfc60e082560190d62736bc02c3bcd006d41da24..67d1d2fe98ef57f8deaa96049a77b90bb9000e9f 100644 (file)
@@ -53,40 +53,6 @@ class CustomPrefixMode : public ModeHandler
                return MOD_RES_PASSTHRU;
        }
 
-       void RemoveMode(Channel* channel, irc::modestacker* stack)
-       {
-               const UserMembList* cl = channel->GetUsers();
-               std::vector<std::string> mode_junk;
-               mode_junk.push_back(channel->name);
-               irc::modestacker modestack(false);
-               std::deque<std::string> stackresult;
-
-               for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
-               {
-                       if (i->second->hasMode(mode))
-                       {
-                               if (stack)
-                                       stack->Push(this->GetModeChar(), i->first->nick);
-                               else
-                                       modestack.Push(this->GetModeChar(), i->first->nick);
-                       }
-               }
-
-               if (stack)
-                       return;
-
-               while (modestack.GetStackedLine(stackresult))
-               {
-                       mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
-                       ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
-                       mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
-               }
-       }
-
-       void RemoveMode(User* user, irc::modestacker* stack)
-       {
-       }
-
        ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
        {
                return MODEACTION_ALLOW;
@@ -97,11 +63,7 @@ class ModuleCustomPrefix : public Module
 {
        std::vector<CustomPrefixMode*> modes;
  public:
-       ModuleCustomPrefix()
-       {
-       }
-
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
                while (tags.first != tags.second)
@@ -131,7 +93,7 @@ class ModuleCustomPrefix : public Module
                        delete *i;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides custom prefix channel modes", VF_VENDOR);
        }
index c65645bc9209426d0382f3e81cfdc2725daca441..5d088e9a6f8ca93abbf8ba194b15b94ae1534c06 100644 (file)
@@ -35,27 +35,10 @@ class CommandTitle : public Command
                syntax = "<user> <password>";
        }
 
-       bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
-       {
-               std::stringstream hl(hostlist);
-               std::string xhost;
-               while (hl >> xhost)
-               {
-                       if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-                       {
-                               return true;
-                       }
-               }
-               return false;
-       }
-
        CmdResult Handle(const std::vector<std::string> &parameters, User* user)
        {
-               char TheHost[MAXBUF];
-               char TheIP[MAXBUF];
-
-               snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
-               snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString());
+               const std::string userHost = user->ident + "@" + user->host;
+               const std::string userIP = user->ident + "@" + user->GetIPString();
 
                ConfigTagList tags = ServerInstance->Config->ConfTags("title");
                for (ConfigIter i = tags.first; i != tags.second; ++i)
@@ -67,7 +50,8 @@ class CommandTitle : public Command
                        std::string title = i->second->getString("title");
                        std::string vhost = i->second->getString("vhost");
 
-                       if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
+                       if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
+                               InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
                        {
                                ctitle.set(user, title);
 
@@ -76,13 +60,13 @@ class CommandTitle : public Command
                                if (!vhost.empty())
                                        user->ChangeDisplayedHost(vhost.c_str());
 
-                               user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick.c_str(), title.c_str());
+                               user->WriteNotice("Custom title set to '" + title + "'");
 
                                return CMD_SUCCESS;
                        }
                }
 
-               user->WriteServ("NOTICE %s :Invalid title credentials",user->nick.c_str());
+               user->WriteNotice("Invalid title credentials");
                return CMD_SUCCESS;
        }
 
@@ -97,7 +81,7 @@ class ModuleCustomTitle : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->Modules->AddService(cmd.ctitle);
@@ -105,7 +89,7 @@ class ModuleCustomTitle : public Module
        }
 
        // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
-       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
+       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
        {
                /* We use this and not OnWhois because this triggers for remote, too */
                if (numeric == 312)
@@ -121,11 +105,7 @@ class ModuleCustomTitle : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ~ModuleCustomTitle()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
        }
index 383e7b5a2d538bf2ea0a48298788543652522109..66d124eb87a272b28624dae9c2761169858eea49 100644 (file)
 
 /** Handle /CYCLE
  */
-class CommandCycle : public Command
+class CommandCycle : public SplitCommand
 {
  public:
-       CommandCycle(Module* Creator) : Command(Creator,"CYCLE", 1)
+       CommandCycle(Module* Creator)
+               : SplitCommand(Creator, "CYCLE", 1)
        {
                Penalty = 3; syntax = "<channel> :[reason]";
                TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle (const std::vector<std::string> &parameters, User *user)
+       CmdResult HandleLocal(const std::vector<std::string> &parameters, LocalUser* user)
        {
                Channel* channel = ServerInstance->FindChan(parameters[0]);
                std::string reason = ConvToStr("Cycling");
@@ -60,13 +61,12 @@ class CommandCycle : public Command
                                if (channel->GetPrefixValue(user) < VOICE_VALUE && channel->IsBanned(user))
                                {
                                        /* banned, boned. drop the message. */
-                                       user->WriteServ("NOTICE "+user->nick+" :*** You may not cycle, as you are banned on channel " + channel->name);
+                                       user->WriteNotice("*** You may not cycle, as you are banned on channel " + channel->name);
                                        return CMD_FAILURE;
                                }
 
                                channel->PartUser(user, reason);
-
-                               Channel::JoinUser(user, parameters[0].c_str(), true, "", false, ServerInstance->Time());
+                               Channel::JoinUser(user, parameters[0], true);
                        }
 
                        return CMD_SUCCESS;
@@ -84,26 +84,22 @@ class CommandCycle : public Command
 class ModuleCycle : public Module
 {
        CommandCycle cmd;
+
  public:
        ModuleCycle()
                : cmd(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleCycle()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides command CYCLE, acts as a server-side HOP command to part and rejoin a channel.", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleCycle)
index de7b6b7bfbab993e8c0e1c70da7fa8ad27e8d4d5..1024c4ab27911df71bfba3126f1d5bc8309d63e8 100644 (file)
@@ -152,10 +152,10 @@ class CommandDccallow : public Command
                                        std::string mask = target->nick+"!"+target->ident+"@"+target->dhost;
                                        std::string default_length = ServerInstance->Config->ConfValue("dccallow")->getString("length");
 
-                                       long length;
+                                       unsigned long length;
                                        if (parameters.size() < 2)
                                        {
-                                               length = ServerInstance->Duration(default_length);
+                                               length = InspIRCd::Duration(default_length);
                                        }
                                        else if (!atoi(parameters[1].c_str()))
                                        {
@@ -163,7 +163,7 @@ class CommandDccallow : public Command
                                        }
                                        else
                                        {
-                                               length = ServerInstance->Duration(parameters[1]);
+                                               length = InspIRCd::Duration(parameters[1]);
                                        }
 
                                        if (!ServerInstance->IsValidMask(mask))
@@ -247,30 +247,30 @@ class CommandDccallow : public Command
 class ModuleDCCAllow : public Module
 {
        CommandDccallow cmd;
- public:
 
+ public:
        ModuleDCCAllow()
                : cmd(this)
        {
                ext = NULL;
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ext = new SimpleExtItem<dccallowlist>("dccallow", this);
                ServerInstance->Modules->AddService(*ext);
                ServerInstance->Modules->AddService(cmd);
                ReadFileConf();
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserQuit, I_OnUserPostNick, I_OnRehash };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserQuit, I_OnUserPostNick, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ReadFileConf();
        }
 
-       virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
+       void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE
        {
                dccallowlist* udl = ext->get(user);
 
@@ -287,17 +287,12 @@ class ModuleDCCAllow : public Module
                RemoveNick(user);
        }
 
-       virtual void OnUserPostNick(User* user, const std::string &oldnick)
+       void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE
        {
                RemoveNick(user);
        }
 
-       virtual ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreNotice(user, dest, target_type, text, status, exempt_list);
-       }
-
-       virtual ModResult OnUserPreNotice(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return MOD_RES_PASSTHRU;
@@ -365,16 +360,16 @@ class ModuleDCCAllow : public Module
                                                if ((!found) && (defaultaction == "allow"))
                                                        return MOD_RES_PASSTHRU;
 
-                                               user->WriteServ("NOTICE %s :The user %s is not accepting DCC SENDs from you. Your file %s was not sent.", user->nick.c_str(), u->nick.c_str(), filename.c_str());
-                                               u->WriteServ("NOTICE %s :%s (%s@%s) attempted to send you a file named %s, which was blocked.", u->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), filename.c_str());
-                                               u->WriteServ("NOTICE %s :If you trust %s and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system.", u->nick.c_str(), user->nick.c_str());
+                                               user->WriteNotice("The user " + u->nick + " is not accepting DCC SENDs from you. Your file " + filename + " was not sent.");
+                                               u->WriteNotice(user->nick + " (" + user->ident + "@" + user->dhost + ") attempted to send you a file named " + filename + ", which was blocked.");
+                                               u->WriteNotice("If you trust " + user->nick + " and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system.");
                                                return MOD_RES_DENY;
                                        }
                                        else if ((type == "CHAT") && (blockchat))
                                        {
-                                               user->WriteServ("NOTICE %s :The user %s is not accepting DCC CHAT requests from you.", user->nick.c_str(), u->nick.c_str());
-                                               u->WriteServ("NOTICE %s :%s (%s@%s) attempted to initiate a DCC CHAT session, which was blocked.", u->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str());
-                                               u->WriteServ("NOTICE %s :If you trust %s and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system.", u->nick.c_str(), user->nick.c_str());
+                                               user->WriteNotice("The user " + u->nick + " is not accepting DCC CHAT requests from you.");
+                                               u->WriteNotice(user->nick + " (" + user->ident + "@" + user->dhost + ") attempted to initiate a DCC CHAT session, which was blocked.");
+                                               u->WriteNotice("If you trust " + user->nick + " and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system.");
                                                return MOD_RES_DENY;
                                        }
                                }
@@ -432,7 +427,7 @@ class ModuleDCCAllow : public Module
                                                if (i->nickname == user->nick)
                                                {
 
-                                                       u->WriteServ("NOTICE %s :%s left the network or changed their nickname and has been removed from your DCCALLOW list", u->nick.c_str(), i->nickname.c_str());
+                                                       u->WriteNotice(i->nickname + " left the network or changed their nickname and has been removed from your DCCALLOW list");
                                                        u->WriteNumeric(995, "%s %s :Removed %s from your DCCALLOW list", u->nick.c_str(), u->nick.c_str(), i->nickname.c_str());
                                                        dl->erase(i);
                                                        break;
@@ -475,12 +470,12 @@ class ModuleDCCAllow : public Module
                }
        }
 
-       virtual ~ModuleDCCAllow()
+       ~ModuleDCCAllow()
        {
                delete ext;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the /DCCALLOW command", VF_COMMON | VF_VENDOR);
        }
index 43b24cfae9c6dba39b0f6ce6b0a64c40164c792b..65591f07081309938890a594381ae41d005fa567 100644 (file)
@@ -36,7 +36,7 @@ class User_d : public ModeHandler
                {
                        if (!dest->IsModeSet('d'))
                        {
-                               dest->WriteServ("NOTICE %s :*** You have enabled usermode +d, deaf mode. This mode means you WILL NOT receive any messages from any channels you are in. If you did NOT mean to do this, use /mode %s -d.", dest->nick.c_str(), dest->nick.c_str());
+                               dest->WriteNotice("*** You have enabled usermode +d, deaf mode. This mode means you WILL NOT receive any messages from any channels you are in. If you did NOT mean to do this, use /mode " + dest->nick + " -d.");
                                dest->SetMode('d',true);
                                return MODEACTION_ALLOW;
                        }
@@ -56,7 +56,6 @@ class User_d : public ModeHandler
 class ModuleDeaf : public Module
 {
        User_d m1;
-
        std::string deaf_bypasschars;
        std::string deaf_bypasschars_uline;
 
@@ -66,47 +65,35 @@ class ModuleDeaf : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(m1);
 
                OnRehash(NULL);
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("deaf");
                deaf_bypasschars = tag->getString("bypasschars");
                deaf_bypasschars_uline = tag->getString("bypasscharsuline");
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (target_type == TYPE_CHANNEL)
                {
                        Channel* chan = (Channel*)dest;
                        if (chan)
-                               this->BuildDeafList(MSG_NOTICE, chan, user, status, text, exempt_list);
+                               this->BuildDeafList(msgtype, chan, user, status, text, exempt_list);
                }
 
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               if (target_type == TYPE_CHANNEL)
-               {
-                       Channel* chan = (Channel*)dest;
-                       if (chan)
-                               this->BuildDeafList(MSG_PRIVMSG, chan, user, status, text, exempt_list);
-               }
-
-               return MOD_RES_PASSTHRU;
-       }
-
-       virtual void BuildDeafList(MessageType message_type, Channel* chan, User* sender, char status, const std::string &text, CUList &exempt_list)
+       void BuildDeafList(MessageType message_type, Channel* chan, User* sender, char status, const std::string &text, CUList &exempt_list)
        {
                const UserMembList *ulist = chan->GetUsers();
                bool is_a_uline;
@@ -159,15 +146,10 @@ class ModuleDeaf : public Module
                }
        }
 
-       virtual ~ModuleDeaf()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides usermode +d to block channel messages and channel notices", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleDeaf)
index a9a92e67a9b382a65f113e30a1879b36a97d39b4..1216922ba2ac2852be3df107ca422955af1660a7 100644 (file)
@@ -27,7 +27,6 @@
 
 class DelayJoinMode : public ModeHandler
 {
- private:
        CUList empty;
  public:
        DelayJoinMode(Module* Parent) : ModeHandler(Parent, "delayjoin", 'D', PARAM_NONE, MODETYPE_CHANNEL)
@@ -47,23 +46,22 @@ class ModuleDelayJoin : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(djm);
                ServerInstance->Modules->AddService(unjoined);
                Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnBuildNeighborList, I_OnNamesListItem, I_OnText, I_OnRawMode };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
-       ~ModuleDelayJoin();
-       Version GetVersion();
-       void OnNamesListItem(User* issuer, Membership*, std::string &prefixes, std::string &nick);
-       void OnUserJoin(Membership*, bool, bool, CUList&);
+       Version GetVersion() CXX11_OVERRIDE;
+       void OnNamesListItem(User* issuer, Membership*, std::string &prefixes, std::string &nick) CXX11_OVERRIDE;
+       void OnUserJoin(Membership*, bool, bool, CUList&) CXX11_OVERRIDE;
        void CleanUser(User* user);
-       void OnUserPart(Membership*, std::string &partmessage, CUList&);
-       void OnUserKick(User* source, Membership*, const std::string &reason, CUList&);
-       void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception);
-       void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list);
-       ModResult OnRawMode(User* user, Channel* channel, const char mode, const std::string &param, bool adding, int pcnt);
+       void OnUserPart(Membership*, std::string &partmessage, CUList&) CXX11_OVERRIDE;
+       void OnUserKick(User* source, Membership*, const std::string &reason, CUList&) CXX11_OVERRIDE;
+       void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception) CXX11_OVERRIDE;
+       void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list) CXX11_OVERRIDE;
+       ModResult OnRawMode(User* user, Channel* channel, const char mode, const std::string &param, bool adding, int pcnt) CXX11_OVERRIDE;
 };
 
 ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
@@ -86,10 +84,6 @@ ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channe
        return MODEACTION_ALLOW;
 }
 
-ModuleDelayJoin::~ModuleDelayJoin()
-{
-}
-
 Version ModuleDelayJoin::GetVersion()
 {
        return Version("Allows for delay-join channels (+D) where users don't appear to join until they speak", VF_VENDOR);
index cfc06866a90996ac7991f44d66305433fffd4e46..8391dc45e55eaa006d833136340b91f6d593e8e1 100644 (file)
@@ -41,23 +41,22 @@ class DelayMsgMode : public ModeHandler
 
 class ModuleDelayMsg : public Module
 {
- private:
        DelayMsgMode djm;
  public:
        ModuleDelayMsg() : djm(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(djm);
                ServerInstance->Modules->AddService(djm.jointime);
                Implementation eventlist[] = { I_OnUserJoin, I_OnUserPreMessage};
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
-       Version GetVersion();
-       void OnUserJoin(Membership* memb, bool sync, bool created, CUList&);
-       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list);
+       Version GetVersion() CXX11_OVERRIDE;
+       void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE;
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
 };
 
 ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
@@ -105,13 +104,13 @@ void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CULis
        }
 }
 
-ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
+ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype)
 {
        /* Server origin */
        if ((!user) || (!IS_LOCAL(user)))
                return MOD_RES_PASSTHRU;
 
-       if (target_type != TYPE_CHANNEL)
+       if ((target_type != TYPE_CHANNEL) || (msgtype != MSG_PRIVMSG))
                return MOD_RES_PASSTHRU;
 
        Channel* channel = (Channel*) dest;
@@ -145,4 +144,3 @@ ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_ty
 }
 
 MODULE_INIT(ModuleDelayMsg)
-
index e774e92c82d53844b0a380ea154e619abdcd7567..b09ee7977d24d65a199db45debaef82bc988be7a 100644 (file)
 class ModuleDenyChannels : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                /* check for redirect validity and loops/chains */
                ConfigTagList tags = ServerInstance->Config->ConfTags("badchan");
@@ -45,10 +45,10 @@ class ModuleDenyChannels : public Module
                        if (!redirect.empty())
                        {
 
-                               if (!ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
+                               if (!ServerInstance->IsChannel(redirect))
                                {
                                        if (user)
-                                               user->WriteServ("NOTICE %s :Invalid badchan redirect '%s'", user->nick.c_str(), redirect.c_str());
+                                               user->WriteNotice("Invalid badchan redirect '" + redirect + "'");
                                        throw ModuleException("Invalid badchan redirect, not a channel");
                                }
 
@@ -68,7 +68,7 @@ class ModuleDenyChannels : public Module
                                                {
                                                        /* <badchan:redirect> is a badchan */
                                                        if (user)
-                                                               user->WriteServ("NOTICE %s :Badchan %s redirects to badchan %s", user->nick.c_str(), name.c_str(), redirect.c_str());
+                                                               user->WriteNotice("Badchan " + name + " redirects to badchan " + redirect);
                                                        throw ModuleException("Badchan redirect loop");
                                                }
                                        }
@@ -77,24 +77,20 @@ class ModuleDenyChannels : public Module
                }
        }
 
-       virtual ~ModuleDenyChannels()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements config tags which allow blocking of joins to channels", VF_VENDOR);
        }
 
 
-       virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                ConfigTagList tags = ServerInstance->Config->ConfTags("badchan");
                for (ConfigIter j = tags.first; j != tags.second; ++j)
                {
                        if (InspIRCd::Match(cname, j->second->getString("name")))
                        {
-                               if (IS_OPER(user) && j->second->getBool("allowopers"))
+                               if (user->IsOper() && j->second->getBool("allowopers"))
                                {
                                        return MOD_RES_PASSTHRU;
                                }
@@ -112,19 +108,19 @@ class ModuleDenyChannels : public Module
                                                }
                                        }
 
-                                       if (ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
+                                       if (ServerInstance->IsChannel(redirect))
                                        {
                                                /* simple way to avoid potential loops: don't redirect to +L channels */
                                                Channel *newchan = ServerInstance->FindChan(redirect);
                                                if ((!newchan) || (!(newchan->IsModeSet('L'))))
                                                {
-                                                       user->WriteNumeric(926, "%s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick.c_str(),cname,cname,redirect.c_str(), reason.c_str());
-                                                       Channel::JoinUser(user,redirect.c_str(),false,"",false,ServerInstance->Time());
+                                                       user->WriteNumeric(926, "%s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick.c_str(),cname.c_str(),cname.c_str(),redirect.c_str(), reason.c_str());
+                                                       Channel::JoinUser(user, redirect);
                                                        return MOD_RES_DENY;
                                                }
                                        }
 
-                                       user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname,cname,reason.c_str());
+                                       user->WriteNumeric(926, "%s %s :Channel %s is forbidden: %s",user->nick.c_str(),cname.c_str(),cname.c_str(),reason.c_str());
                                        return MOD_RES_DENY;
                                }
                        }
index 2b5de2bd66dd2d8747e6de147a829d82893ac9c2..64604e90c95b245ddf59b737d7610a70237e1074 100644 (file)
@@ -41,19 +41,13 @@ class CommandDevoice : public Command
 
        CmdResult Handle (const std::vector<std::string> &parameters, User *user)
        {
-               Channel* c = ServerInstance->FindChan(parameters[0]);
-               if (c && c->HasUser(user))
-               {
-                       std::vector<std::string> modes;
-                       modes.push_back(parameters[0]);
-                       modes.push_back("-v");
-                       modes.push_back(user->nick);
+               std::vector<std::string> modes;
+               modes.push_back(parameters[0]);
+               modes.push_back("-v");
+               modes.push_back(user->nick);
 
-                       ServerInstance->SendGlobalMode(modes, ServerInstance->FakeClient);
-                       return CMD_SUCCESS;
-               }
-
-               return CMD_FAILURE;
+               ServerInstance->SendGlobalMode(modes, ServerInstance->FakeClient);
+               return CMD_SUCCESS;
        }
 };
 
@@ -65,16 +59,12 @@ class ModuleDeVoice : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleDeVoice()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides voiced users with the ability to devoice themselves.", VF_VENDOR);
        }
index 5e02dd0a5dadc5cea64d99375285f24a5a8bb5e6..34621c732609405eaa31b79178b01cb629029ea6 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "inspircd.h"
 #include "xline.h"
+#include "modules/dns.h"
 
 /* $ModDesc: Provides handling of DNS blacklists */
 
@@ -40,13 +41,12 @@ class DNSBLConfEntry
                unsigned char records[256];
                unsigned long stats_hits, stats_misses;
                DNSBLConfEntry(): type(A_BITMASK),duration(86400),bitmask(0),stats_hits(0), stats_misses(0) {}
-               ~DNSBLConfEntry() { }
 };
 
 
 /** Resolver for CGI:IRC hostnames encoded in ident/GECOS
  */
-class DNSBLResolver : public Resolver
+class DNSBLResolver : public DNS::Request
 {
        std::string theiruid;
        LocalStringExt& nameExt;
@@ -55,161 +55,158 @@ class DNSBLResolver : public Resolver
 
  public:
 
-       DNSBLResolver(Module *me, LocalStringExt& match, LocalIntExt& ctr, const std::string &hostname, LocalUser* u, DNSBLConfEntry *conf, bool &cached)
-               : Resolver(hostname, DNS_QUERY_A, cached, me), theiruid(u->uuid), nameExt(match), countExt(ctr), ConfEntry(conf)
+       DNSBLResolver(DNS::Manager *mgr, Module *me, LocalStringExt& match, LocalIntExt& ctr, const std::string &hostname, LocalUser* u, DNSBLConfEntry *conf)
+               : DNS::Request(mgr, me, hostname, DNS::QUERY_A, true), theiruid(u->uuid), nameExt(match), countExt(ctr), ConfEntry(conf)
        {
        }
 
        /* Note: This may be called multiple times for multiple A record results */
-       virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
+       void OnLookupComplete(const DNS::Query *r) CXX11_OVERRIDE
        {
                /* Check the user still exists */
                LocalUser* them = (LocalUser*)ServerInstance->FindUUID(theiruid);
-               if (them)
+               if (!them)
+                       return;
+
+               const DNS::ResourceRecord &ans_record = r->answers[0];
+
+               int i = countExt.get(them);
+               if (i)
+                       countExt.set(them, i - 1);
+
+               // Now we calculate the bitmask: 256*(256*(256*a+b)+c)+d
+
+               unsigned int bitmask = 0, record = 0;
+               bool match = false;
+               in_addr resultip;
+
+               inet_aton(ans_record.rdata.c_str(), &resultip);
+
+               switch (ConfEntry->type)
+               {
+                       case DNSBLConfEntry::A_BITMASK:
+                               bitmask = resultip.s_addr >> 24; /* Last octet (network byte order) */
+                               bitmask &= ConfEntry->bitmask;
+                               match = (bitmask != 0);
+                       break;
+                       case DNSBLConfEntry::A_RECORD:
+                               record = resultip.s_addr >> 24; /* Last octet */
+                               match = (ConfEntry->records[record] == 1);
+                       break;
+               }
+
+               if (match)
                {
-                       int i = countExt.get(them);
-                       if (i)
-                               countExt.set(them, i - 1);
-                       // Now we calculate the bitmask: 256*(256*(256*a+b)+c)+d
-                       if(result.length())
+                       std::string reason = ConfEntry->reason;
+                       std::string::size_type x = reason.find("%ip%");
+                       while (x != std::string::npos)
                        {
-                               unsigned int bitmask = 0, record = 0;
-                               bool match = false;
-                               in_addr resultip;
+                               reason.erase(x, 4);
+                               reason.insert(x, them->GetIPString());
+                               x = reason.find("%ip%");
+                       }
 
-                               inet_aton(result.c_str(), &resultip);
+                       ConfEntry->stats_hits++;
 
-                               switch (ConfEntry->type)
+                       switch (ConfEntry->banaction)
+                       {
+                               case DNSBLConfEntry::I_KILL:
                                {
-                                       case DNSBLConfEntry::A_BITMASK:
-                                               bitmask = resultip.s_addr >> 24; /* Last octet (network byte order) */
-                                               bitmask &= ConfEntry->bitmask;
-                                               match = (bitmask != 0);
-                                       break;
-                                       case DNSBLConfEntry::A_RECORD:
-                                               record = resultip.s_addr >> 24; /* Last octet */
-                                               match = (ConfEntry->records[record] == 1);
+                                       ServerInstance->Users->QuitUser(them, "Killed (" + reason + ")");
                                        break;
                                }
-
-                               if (match)
+                               case DNSBLConfEntry::I_MARK:
                                {
-                                       std::string reason = ConfEntry->reason;
-                                       std::string::size_type x = reason.find("%ip%");
-                                       while (x != std::string::npos)
+                                       if (!ConfEntry->ident.empty())
                                        {
-                                               reason.erase(x, 4);
-                                               reason.insert(x, them->GetIPString());
-                                               x = reason.find("%ip%");
+                                               them->WriteServ("304 " + them->nick + " :Your ident has been set to " + ConfEntry->ident + " because you matched " + reason);
+                                               them->ChangeIdent(ConfEntry->ident.c_str());
                                        }
 
-                                       ConfEntry->stats_hits++;
-
-                                       switch (ConfEntry->banaction)
+                                       if (!ConfEntry->host.empty())
                                        {
-                                               case DNSBLConfEntry::I_KILL:
-                                               {
-                                                       ServerInstance->Users->QuitUser(them, "Killed (" + reason + ")");
-                                                       break;
-                                               }
-                                               case DNSBLConfEntry::I_MARK:
-                                               {
-                                                       if (!ConfEntry->ident.empty())
-                                                       {
-                                                               them->WriteServ("304 " + them->nick + " :Your ident has been set to " + ConfEntry->ident + " because you matched " + reason);
-                                                               them->ChangeIdent(ConfEntry->ident.c_str());
-                                                       }
-
-                                                       if (!ConfEntry->host.empty())
-                                                       {
-                                                               them->WriteServ("304 " + them->nick + " :Your host has been set to " + ConfEntry->host + " because you matched " + reason);
-                                                               them->ChangeDisplayedHost(ConfEntry->host.c_str());
-                                                       }
-
-                                                       nameExt.set(them, ConfEntry->name);
-                                                       break;
-                                               }
-                                               case DNSBLConfEntry::I_KLINE:
-                                               {
-                                                       KLine* kl = new KLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(),
-                                                                       "*", them->GetIPString());
-                                                       if (ServerInstance->XLines->AddLine(kl,NULL))
-                                                       {
-                                                               std::string timestr = ServerInstance->TimeString(kl->expiry);
-                                                               ServerInstance->SNO->WriteGlobalSno('x',"K:line added due to DNSBL match on *@%s to expire on %s: %s",
-                                                                       them->GetIPString(), timestr.c_str(), reason.c_str());
-                                                               ServerInstance->XLines->ApplyLines();
-                                                       }
-                                                       else
-                                                               delete kl;
-                                                       break;
-                                               }
-                                               case DNSBLConfEntry::I_GLINE:
-                                               {
-                                                       GLine* gl = new GLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(),
-                                                                       "*", them->GetIPString());
-                                                       if (ServerInstance->XLines->AddLine(gl,NULL))
-                                                       {
-                                                               std::string timestr = ServerInstance->TimeString(gl->expiry);
-                                                               ServerInstance->SNO->WriteGlobalSno('x',"G:line added due to DNSBL match on *@%s to expire on %s: %s",
-                                                                       them->GetIPString(), timestr.c_str(), reason.c_str());
-                                                               ServerInstance->XLines->ApplyLines();
-                                                       }
-                                                       else
-                                                               delete gl;
-                                                       break;
-                                               }
-                                               case DNSBLConfEntry::I_ZLINE:
-                                               {
-                                                       ZLine* zl = new ZLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(),
-                                                                       them->GetIPString());
-                                                       if (ServerInstance->XLines->AddLine(zl,NULL))
-                                                       {
-                                                               std::string timestr = ServerInstance->TimeString(zl->expiry);
-                                                               ServerInstance->SNO->WriteGlobalSno('x',"Z:line added due to DNSBL match on *@%s to expire on %s: %s",
-                                                                       them->GetIPString(), timestr.c_str(), reason.c_str());
-                                                               ServerInstance->XLines->ApplyLines();
-                                                       }
-                                                       else
-                                                               delete zl;
-                                                       break;
-                                               }
-                                               case DNSBLConfEntry::I_UNKNOWN:
-                                               {
-                                                       break;
-                                               }
-                                               break;
+                                               them->WriteServ("304 " + them->nick + " :Your host has been set to " + ConfEntry->host + " because you matched " + reason);
+                                               them->ChangeDisplayedHost(ConfEntry->host.c_str());
                                        }
 
-                                       ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s%s detected as being on a DNS blacklist (%s) with result %d", them->nick.empty() ? "<unknown>" : "", them->GetFullRealHost().c_str(), ConfEntry->domain.c_str(), (ConfEntry->type==DNSBLConfEntry::A_BITMASK) ? bitmask : record);
+                                       nameExt.set(them, ConfEntry->name);
+                                       break;
+                               }
+                               case DNSBLConfEntry::I_KLINE:
+                               {
+                                       KLine* kl = new KLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(),
+                                                       "*", them->GetIPString());
+                                       if (ServerInstance->XLines->AddLine(kl,NULL))
+                                       {
+                                               std::string timestr = ServerInstance->TimeString(kl->expiry);
+                                               ServerInstance->SNO->WriteGlobalSno('x',"K:line added due to DNSBL match on *@%s to expire on %s: %s",
+                                                       them->GetIPString().c_str(), timestr.c_str(), reason.c_str());
+                                               ServerInstance->XLines->ApplyLines();
+                                       }
+                                       else
+                                               delete kl;
+                                       break;
+                               }
+                               case DNSBLConfEntry::I_GLINE:
+                               {
+                                       GLine* gl = new GLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(),
+                                                       "*", them->GetIPString());
+                                       if (ServerInstance->XLines->AddLine(gl,NULL))
+                                       {
+                                               std::string timestr = ServerInstance->TimeString(gl->expiry);
+                                               ServerInstance->SNO->WriteGlobalSno('x',"G:line added due to DNSBL match on *@%s to expire on %s: %s",
+                                                       them->GetIPString().c_str(), timestr.c_str(), reason.c_str());
+                                               ServerInstance->XLines->ApplyLines();
+                                       }
+                                       else
+                                               delete gl;
+                                       break;
+                               }
+                               case DNSBLConfEntry::I_ZLINE:
+                               {
+                                       ZLine* zl = new ZLine(ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName.c_str(), reason.c_str(),
+                                                       them->GetIPString());
+                                       if (ServerInstance->XLines->AddLine(zl,NULL))
+                                       {
+                                               std::string timestr = ServerInstance->TimeString(zl->expiry);
+                                               ServerInstance->SNO->WriteGlobalSno('x',"Z:line added due to DNSBL match on *@%s to expire on %s: %s",
+                                                       them->GetIPString().c_str(), timestr.c_str(), reason.c_str());
+                                               ServerInstance->XLines->ApplyLines();
+                                       }
+                                       else
+                                               delete zl;
+                                       break;
                                }
-                               else
-                                       ConfEntry->stats_misses++;
+                               case DNSBLConfEntry::I_UNKNOWN:
+                               default:
+                                       break;
                        }
-                       else
-                               ConfEntry->stats_misses++;
+
+                       ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s%s detected as being on a DNS blacklist (%s) with result %d", them->nick.empty() ? "<unknown>" : "", them->GetFullRealHost().c_str(), ConfEntry->domain.c_str(), (ConfEntry->type==DNSBLConfEntry::A_BITMASK) ? bitmask : record);
                }
+               else
+                       ConfEntry->stats_misses++;
        }
 
-       virtual void OnError(ResolverError e, const std::string &errormessage)
+       void OnError(const DNS::Query *q) CXX11_OVERRIDE
        {
                LocalUser* them = (LocalUser*)ServerInstance->FindUUID(theiruid);
-               if (them)
-               {
-                       int i = countExt.get(them);
-                       if (i)
-                               countExt.set(them, i - 1);
-               }
-       }
+               if (!them)
+                       return;
 
-       virtual ~DNSBLResolver()
-       {
+               int i = countExt.get(them);
+               if (i)
+                       countExt.set(them, i - 1);
+
+               if (q->error == DNS::ERROR_NO_RECORDS || q->error == DNS::ERROR_DOMAIN_NOT_FOUND)
+                       ConfEntry->stats_misses++;
        }
 };
 
 class ModuleDNSBL : public Module
 {
        std::vector<DNSBLConfEntry *> DNSBLConfEntries;
+       dynamic_reference<DNS::Manager> DNS;
        LocalStringExt nameExt;
        LocalIntExt countExt;
 
@@ -232,9 +229,9 @@ class ModuleDNSBL : public Module
                return DNSBLConfEntry::I_UNKNOWN;
        }
  public:
-       ModuleDNSBL() : nameExt("dnsbl_match", this), countExt("dnsbl_pending", this) { }
+       ModuleDNSBL() : DNS(this, "DNS"), nameExt("dnsbl_match", this), countExt("dnsbl_pending", this) { }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ReadConf();
                ServerInstance->Modules->AddService(nameExt);
@@ -243,12 +240,12 @@ class ModuleDNSBL : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleDNSBL()
+       ~ModuleDNSBL()
        {
                ClearEntries();
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides handling of DNS blacklists", VF_VENDOR);
        }
@@ -296,7 +293,7 @@ class ModuleDNSBL : public Module
                        }
 
                        e->banaction = str2banaction(tag->getString("action"));
-                       e->duration = ServerInstance->Duration(tag->getString("duration", "60"));
+                       e->duration = InspIRCd::Duration(tag->getString("duration", "60"));
 
                        /* Use portparser for record replies */
 
@@ -345,14 +342,14 @@ class ModuleDNSBL : public Module
                }
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ReadConf();
        }
 
-       void OnSetUserIP(LocalUser* user)
+       void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE
        {
-               if ((user->exempt) || (user->client_sa.sa.sa_family != AF_INET))
+               if ((user->exempt) || (user->client_sa.sa.sa_family != AF_INET) || !DNS)
                        return;
 
                if (user->MyClass)
@@ -361,40 +358,42 @@ class ModuleDNSBL : public Module
                                return;
                }
                else
-                       ServerInstance->Logs->Log("m_dnsbl", DEBUG, "User has no connect class in OnSetUserIP");
+                       ServerInstance->Logs->Log("m_dnsbl", LOG_DEBUG, "User has no connect class in OnSetUserIP");
 
                unsigned char a, b, c, d;
-               char reversedipbuf[128];
-               std::string reversedip;
-
                d = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 24) & 0xFF;
                c = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 16) & 0xFF;
                b = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 8) & 0xFF;
                a = (unsigned char) user->client_sa.in4.sin_addr.s_addr & 0xFF;
 
-               snprintf(reversedipbuf, 128, "%d.%d.%d.%d", d, c, b, a);
-               reversedip = std::string(reversedipbuf);
+               const std::string reversedip = ConvToStr(d) + "." + ConvToStr(c) + "." + ConvToStr(b) + "." + ConvToStr(a);
 
                countExt.set(user, DNSBLConfEntries.size());
 
                // For each DNSBL, we will run through this lookup
-               unsigned int i = 0;
-               while (i < DNSBLConfEntries.size())
+               for (unsigned i = 0; i < DNSBLConfEntries.size(); ++i)
                {
                        // Fill hostname with a dnsbl style host (d.c.b.a.domain.tld)
                        std::string hostname = reversedip + "." + DNSBLConfEntries[i]->domain;
 
                        /* now we'd need to fire off lookups for `hostname'. */
-                       bool cached;
-                       DNSBLResolver *r = new DNSBLResolver(this, nameExt, countExt, hostname, user, DNSBLConfEntries[i], cached);
-                       ServerInstance->AddResolver(r, cached);
+                       DNSBLResolver *r = new DNSBLResolver(*this->DNS, this, nameExt, countExt, hostname, user, DNSBLConfEntries[i]);
+                       try
+                       {
+                               this->DNS->Process(r);
+                       }
+                       catch (DNS::Exception &ex)
+                       {
+                               delete r;
+                               ServerInstance->Logs->Log("m_dnsbl", LOG_DEBUG, std::string(ex.GetReason()));
+                       }
+
                        if (user->quitting)
                                break;
-                       i++;
                }
        }
 
-       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
+       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE
        {
                std::string dnsbl;
                if (!myclass->config->readString("dnsbl", dnsbl))
@@ -405,15 +404,15 @@ class ModuleDNSBL : public Module
                        return MOD_RES_PASSTHRU;
                return MOD_RES_DENY;
        }
-       
-       ModResult OnCheckReady(LocalUser *user)
+
+       ModResult OnCheckReady(LocalUser *user) CXX11_OVERRIDE
        {
                if (countExt.get(user))
                        return MOD_RES_DENY;
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnStats(char symbol, User* user, string_list &results)
+       ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE
        {
                if (symbol != 'd')
                        return MOD_RES_PASSTHRU;
index 9fac8e7adaea59e5af648eab22d6fb3cc16f3d3d..83a0f9d040484fc51fd703a5aa9b43602b0121cd 100644 (file)
@@ -18,7 +18,7 @@
 
 
 #include "inspircd.h"
-#include "u_listmode.h"
+#include "listmode.h"
 
 /* $ModDesc: Provides the ability to allow channel operators to be exempt from certain modes. */
 
@@ -41,10 +41,9 @@ class ExemptChanOps : public ListModeBase
                return true;
        }
 
-       bool TellListTooLong(User* user, Channel* chan, std::string &word)
+       void TellListTooLong(User* user, Channel* chan, std::string &word)
        {
                user->WriteNumeric(959, "%s %s %s :Channel exemptchanops list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
-               return true;
        }
 
        void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
@@ -63,7 +62,7 @@ class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std:
  public:
        ExemptChanOps ec;
        ExemptHandler(Module* me) : ec(me) {}
-       
+
        ModeHandler* FindMode(const std::string& mid)
        {
                if (mid.length() == 1)
@@ -82,11 +81,11 @@ class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std:
                unsigned int mypfx = chan->GetPrefixValue(user);
                std::string minmode;
 
-               modelist* list = ec.extItem.get(chan);
+               ListModeBase::ModeList* list = ec.GetList(chan);
 
                if (list)
                {
-                       for (modelist::iterator i = list->begin(); i != list->end(); ++i)
+                       for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); ++i)
                        {
                                std::string::size_type pos = (*i).mask.find(':');
                                if (pos == std::string::npos)
@@ -112,12 +111,11 @@ class ModuleExemptChanOps : public Module
        ExemptHandler eh;
 
  public:
-
        ModuleExemptChanOps() : eh(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(eh.ec);
                Implementation eventlist[] = { I_OnRehash, I_OnSyncChannel };
@@ -132,17 +130,17 @@ class ModuleExemptChanOps : public Module
                ServerInstance->OnCheckExemption = &ServerInstance->HandleOnCheckExemption;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                eh.ec.DoRehash();
        }
 
-       void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
+       void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
        {
                eh.ec.DoSyncChannel(chan, proto, opaque);
        }
index 4090f5600b4d1a9381cfd0b67c6a9106a1b7b8fd..bdf849f323729662ecbb77db27433abbbf0e851f 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "inspircd.h"
 #include "xline.h"
-#include "m_regex.h"
+#include "modules/regex.h"
 
 /* $ModDesc: Text (spam) filtering */
 
@@ -179,22 +179,21 @@ class ModuleFilter : public Module
        std::set<std::string> exemptfromfilter; // List of channel names excluded from filtering.
 
        ModuleFilter();
-       void init();
+       void init() CXX11_OVERRIDE;
        CullResult cull();
-       ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
        FilterResult* FilterMatch(User* user, const std::string &text, int flags);
        bool DeleteFilter(const std::string &freeform);
        std::pair<bool, std::string> AddFilter(const std::string &freeform, FilterAction type, const std::string &reason, long duration, const std::string &flags);
-       ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
-       void OnRehash(User* user);
-       Version GetVersion();
+       void OnRehash(User* user) CXX11_OVERRIDE;
+       Version GetVersion() CXX11_OVERRIDE;
        std::string EncodeFilter(FilterResult* filter);
        FilterResult DecodeFilter(const std::string &data);
-       void OnSyncNetwork(Module* proto, void* opaque);
-       void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata);
-       ModResult OnStats(char symbol, User* user, string_list &results);
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line);
-       void OnUnloadModule(Module* mod);
+       void OnSyncNetwork(Module* proto, void* opaque) CXX11_OVERRIDE;
+       void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata) CXX11_OVERRIDE;
+       ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE;
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE;
+       void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
        bool AppliesToMe(User* user, FilterResult* filter, int flags);
        void ReadFilters();
        static bool StringToFilterAction(const std::string& str, FilterAction& fa);
@@ -209,13 +208,13 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
                Module *me = creator;
                if (static_cast<ModuleFilter *>(me)->DeleteFilter(parameters[0]))
                {
-                       user->WriteServ("NOTICE %s :*** Removed filter '%s'", user->nick.c_str(), parameters[0].c_str());
+                       user->WriteNotice("*** Removed filter '" + parameters[0] + "'");
                        ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'a' : 'A', "FILTER: "+user->nick+" removed filter '"+parameters[0]+"'");
                        return CMD_SUCCESS;
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Filter '%s' not found in list, try /stats s.", user->nick.c_str(), parameters[0].c_str());
+                       user->WriteNotice("*** Filter '" + parameters[0] + "' not found in list, try /stats s.");
                        return CMD_FAILURE;
                }
        }
@@ -232,7 +231,7 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
 
                        if (!ModuleFilter::StringToFilterAction(parameters[1], type))
                        {
-                               user->WriteServ("NOTICE %s :*** Invalid filter type '%s'. Supported types are 'gline', 'none', 'block', 'silent' and 'kill'.", user->nick.c_str(), parameters[1].c_str());
+                               user->WriteNotice("*** Invalid filter type '" + parameters[1] + "'. Supported types are 'gline', 'none', 'block', 'silent' and 'kill'.");
                                return CMD_FAILURE;
                        }
 
@@ -240,12 +239,12 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
                        {
                                if (parameters.size() >= 5)
                                {
-                                       duration = ServerInstance->Duration(parameters[3]);
+                                       duration = InspIRCd::Duration(parameters[3]);
                                        reasonindex = 4;
                                }
                                else
                                {
-                                       user->WriteServ("NOTICE %s :*** Not enough parameters: When setting a gline type filter, a gline duration must be specified as the third parameter.", user->nick.c_str());
+                                       user->WriteNotice("*** Not enough parameters: When setting a gline type filter, a gline duration must be specified as the third parameter.");
                                        return CMD_FAILURE;
                                }
                        }
@@ -258,9 +257,9 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
                        std::pair<bool, std::string> result = static_cast<ModuleFilter *>(me)->AddFilter(freeform, type, parameters[reasonindex], duration, flags);
                        if (result.first)
                        {
-                               user->WriteServ("NOTICE %s :*** Added filter '%s', type '%s'%s%s, flags '%s', reason: '%s'", user->nick.c_str(), freeform.c_str(),
-                                               parameters[1].c_str(), (duration ? ", duration " : ""), (duration ? parameters[3].c_str() : ""),
-                                               flags.c_str(), parameters[reasonindex].c_str());
+                               user->WriteNotice("*** Added filter '" + freeform + "', type '" + parameters[1] + "'" +
+                                       (duration ? ", duration " +  parameters[3] : "") + ", flags '" + flags + "', reason: '" +
+                                       parameters[reasonindex] + "'");
 
                                ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'a' : 'A', "FILTER: "+user->nick+" added filter '"+freeform+"', type '"+parameters[1]+"', "+(duration ? "duration "+parameters[3]+", " : "")+"flags '"+flags+"', reason: "+parameters[reasonindex]);
 
@@ -268,13 +267,13 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
                        }
                        else
                        {
-                               user->WriteServ("NOTICE %s :*** Filter '%s' could not be added: %s", user->nick.c_str(), freeform.c_str(), result.second.c_str());
+                               user->WriteNotice("*** Filter '" + freeform + "' could not be added: " + result.second);
                                return CMD_FAILURE;
                        }
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Not enough parameters.", user->nick.c_str());
+                       user->WriteNotice("*** Not enough parameters.");
                        return CMD_FAILURE;
                }
 
@@ -283,7 +282,7 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
 
 bool ModuleFilter::AppliesToMe(User* user, FilterResult* filter, int iflags)
 {
-       if ((filter->flag_no_opers) && IS_OPER(user))
+       if ((filter->flag_no_opers) && user->IsOper())
                return false;
        if ((iflags & FLAG_PRIVMSG) && (!filter->flag_privmsg))
                return false;
@@ -304,7 +303,7 @@ ModuleFilter::ModuleFilter()
 void ModuleFilter::init()
 {
        ServerInstance->Modules->AddService(filtcommand);
-       Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncNetwork, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_OnUnloadModule };
+       Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncNetwork, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnRehash, I_OnUnloadModule };
        ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        OnRehash(NULL);
 }
@@ -323,23 +322,13 @@ void ModuleFilter::FreeFilters()
        filters.clear();
 }
 
-ModResult ModuleFilter::OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-{
-       if (!IS_LOCAL(user))
-               return MOD_RES_PASSTHRU;
-
-       flags = FLAG_PRIVMSG;
-       return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
-}
-
-ModResult ModuleFilter::OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype)
 {
        /* Leave ulines alone */
        if ((ServerInstance->ULine(user->server)) || (!IS_LOCAL(user)))
                return MOD_RES_PASSTHRU;
 
-       if (!flags)
-               flags = FLAG_NOTICE;
+       flags = (msgtype == MSG_PRIVMSG) ? FLAG_PRIVMSG : FLAG_NOTICE;
 
        FilterResult* f = this->FilterMatch(user, text, flags);
        if (f)
@@ -364,14 +353,14 @@ ModResult ModuleFilter::OnUserPreNotice(User* user,void* dest,int target_type, s
                        if (target_type == TYPE_CHANNEL)
                                user->WriteNumeric(404, "%s %s :Message to channel blocked and opers notified (%s)",user->nick.c_str(), target.c_str(), f->reason.c_str());
                        else
-                               user->WriteServ("NOTICE "+user->nick+" :Your message to "+target+" was blocked and opers notified: "+f->reason);
+                               user->WriteNotice("Your message to "+target+" was blocked and opers notified: "+f->reason);
                }
                else if (f->action == FA_SILENT)
                {
                        if (target_type == TYPE_CHANNEL)
                                user->WriteNumeric(404, "%s %s :Message to channel blocked (%s)",user->nick.c_str(), target.c_str(), f->reason.c_str());
                        else
-                               user->WriteServ("NOTICE "+user->nick+" :Your message to "+target+" was blocked: "+f->reason);
+                               user->WriteNotice("Your message to "+target+" was blocked: "+f->reason);
                }
                else if (f->action == FA_KILL)
                {
@@ -388,7 +377,7 @@ ModResult ModuleFilter::OnUserPreNotice(User* user,void* dest,int target_type, s
                                delete gl;
                }
 
-               ServerInstance->Logs->Log("FILTER",DEFAULT,"FILTER: "+ user->nick + " had their message filtered, target was " + target + ": " + f->reason + " Action: " + ModuleFilter::FilterActionToString(f->action));
+               ServerInstance->Logs->Log("FILTER", LOG_DEFAULT, "FILTER: "+ user->nick + " had their message filtered, target was " + target + ": " + f->reason + " Action: " + ModuleFilter::FilterActionToString(f->action));
                return MOD_RES_DENY;
        }
        return MOD_RES_PASSTHRU;
@@ -446,7 +435,7 @@ ModResult ModuleFilter::OnPreCommand(std::string &command, std::vector<std::stri
                        /* Are they parting, if so, kill is applicable */
                        if ((parting) && (f->action == FA_KILL))
                        {
-                               user->WriteServ("NOTICE %s :*** Your PART message was filtered: %s", user->nick.c_str(), f->reason.c_str());
+                               user->WriteNotice("*** Your PART message was filtered: " + f->reason);
                                ServerInstance->Users->QuitUser(user, "Filtered: " + f->reason);
                        }
                        if (f->action == FA_GLINE)
@@ -573,7 +562,7 @@ void ModuleFilter::OnDecodeMetaData(Extensible* target, const std::string &extna
                }
                catch (ModuleException& e)
                {
-                       ServerInstance->Logs->Log("m_filter", DEBUG, "Error when unserializing filter: " + std::string(e.GetReason()));
+                       ServerInstance->Logs->Log("m_filter", LOG_DEBUG, "Error when unserializing filter: " + std::string(e.GetReason()));
                }
        }
 }
@@ -605,13 +594,13 @@ FilterResult* ModuleFilter::FilterMatch(User* user, const std::string &text, int
                        InspIRCd::StripColor(stripped_text);
                }
 
-               //ServerInstance->Logs->Log("m_filter", DEBUG, "Match '%s' against '%s'", text.c_str(), index->freeform.c_str());
+               //ServerInstance->Logs->Log("m_filter", LOG_DEBUG, "Match '%s' against '%s'", text.c_str(), index->freeform.c_str());
                if (index->regex->Matches(filter->flag_strip_color ? stripped_text : text))
                {
-                       //ServerInstance->Logs->Log("m_filter", DEBUG, "MATCH");
+                       //ServerInstance->Logs->Log("m_filter", LOG_DEBUG, "MATCH");
                        return &*index;
                }
-               //ServerInstance->Logs->Log("m_filter", DEBUG, "NO MATCH");
+               //ServerInstance->Logs->Log("m_filter", LOG_DEBUG, "NO MATCH");
        }
        return NULL;
 }
@@ -646,7 +635,7 @@ std::pair<bool, std::string> ModuleFilter::AddFilter(const std::string &freeform
        }
        catch (ModuleException &e)
        {
-               ServerInstance->Logs->Log("m_filter", DEFAULT, "Error in regular expression '%s': %s", freeform.c_str(), e.GetReason());
+               ServerInstance->Logs->Log("m_filter", LOG_DEFAULT, "Error in regular expression '%s': %s", freeform.c_str(), e.GetReason());
                return std::make_pair(false, e.GetReason());
        }
        return std::make_pair(true, "");
@@ -695,7 +684,7 @@ void ModuleFilter::ReadFilters()
                std::string reason = i->second->getString("reason");
                std::string action = i->second->getString("action");
                std::string flgs = i->second->getString("flags");
-               long gline_time = ServerInstance->Duration(i->second->getString("duration"));
+               unsigned long gline_time = InspIRCd::Duration(i->second->getString("duration"));
                if (flgs.empty())
                        flgs = "*";
 
@@ -706,11 +695,11 @@ void ModuleFilter::ReadFilters()
                try
                {
                        filters.push_back(ImplFilter(this, reason, fa, gline_time, pattern, flgs));
-                       ServerInstance->Logs->Log("m_filter", DEFAULT, "Regular expression %s loaded.", pattern.c_str());
+                       ServerInstance->Logs->Log("m_filter", LOG_DEFAULT, "Regular expression %s loaded.", pattern.c_str());
                }
                catch (ModuleException &e)
                {
-                       ServerInstance->Logs->Log("m_filter", DEFAULT, "Error in regular expression '%s': %s", pattern.c_str(), e.GetReason());
+                       ServerInstance->Logs->Log("m_filter", LOG_DEFAULT, "Error in regular expression '%s': %s", pattern.c_str(), e.GetReason());
                }
        }
 }
index 1497c1b87b3f808503c80da9a03df7d22fb14669..55d02f106f75d6a4ca6c8bffb500af110288a776 100644 (file)
 class ModuleGecosBan : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnCheckBan, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ~ModuleGecosBan()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Extban 'r' - realname (gecos) ban", VF_OPTCOMMON|VF_VENDOR);
        }
 
-       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
+       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
        {
                if ((mask.length() > 2) && (mask[0] == 'r') && (mask[1] == ':'))
                {
@@ -49,9 +45,9 @@ class ModuleGecosBan : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('r');
+               tokens["EXTBAN"].push_back('r');
        }
 };
 
index 22286b950e9dead2a72f93873b440a7be4b91f4c..7ceb2811504d01ffbf2d08d578407f3440ea5a83 100644 (file)
@@ -79,6 +79,13 @@ class CommandGunloadmodule : public Command
 
        CmdResult Handle (const std::vector<std::string> &parameters, User *user)
        {
+               if (!ServerInstance->Config->ConfValue("security")->getBool("allowcoreunload") &&
+                       InspIRCd::Match(parameters[0], "cmd_*.so", ascii_case_insensitive_map))
+               {
+                       user->WriteNumeric(972, "%s %s :You cannot unload core commands!", user->nick.c_str(), parameters[0].c_str());
+                       return CMD_FAILURE;
+               }
+
                std::string servername = parameters.size() > 1 ? parameters[1] : "*";
 
                if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
@@ -180,22 +187,17 @@ class ModuleGlobalLoad : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd1);
                ServerInstance->Modules->AddService(cmd2);
                ServerInstance->Modules->AddService(cmd3);
        }
 
-       ~ModuleGlobalLoad()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows global loading of a module.", VF_COMMON | VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleGlobalLoad)
-
index 85d84252b2b11875100f7b25148f40bf221980f5..53112e39eadcc2f984dfa7e5eae652c9d93f68f5 100644 (file)
@@ -49,17 +49,16 @@ class ModuleGlobops : public Module
  public:
        ModuleGlobops() : cmd(this) {}
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->SNO->EnableSnomask('g',"GLOBOPS");
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for GLOBOPS and snomask +g", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleGlobops)
diff --git a/src/modules/m_halfop.cpp b/src/modules/m_halfop.cpp
deleted file mode 100644 (file)
index 3194fcd..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-/* $ModDesc: Channel half-operator mode provider */
-
-#include "inspircd.h"
-
-class ModeChannelHalfOp : public ModeHandler
-{
- public:
-       ModeChannelHalfOp(Module* parent);
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
-       unsigned int GetPrefixRank();
-       void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
-       void RemoveMode(User* user, irc::modestacker* stack = NULL);
-
-       ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
-       {
-               if (!adding && src->nick == value)
-                       return MOD_RES_ALLOW;
-               return MOD_RES_PASSTHRU;
-       }
-};
-
-ModeChannelHalfOp::ModeChannelHalfOp(Module* parent) : ModeHandler(parent, "halfop", 'h', PARAM_ALWAYS, MODETYPE_CHANNEL)
-{
-       list = true;
-       prefix = '%';
-       levelrequired = OP_VALUE;
-       m_paramtype = TR_NICK;
-}
-
-unsigned int ModeChannelHalfOp::GetPrefixRank()
-{
-       return HALFOP_VALUE;
-}
-
-void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
-{
-       const UserMembList* clist = channel->GetUsers();
-
-       for (UserMembCIter i = clist->begin(); i != clist->end(); i++)
-       {
-               if (stack)
-               {
-                       stack->Push(this->GetModeChar(), i->first->nick);
-               }
-               else
-               {
-                       std::vector<std::string> parameters;
-                       parameters.push_back(channel->name);
-                       parameters.push_back("-h");
-                       parameters.push_back(i->first->nick);
-                       ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
-               }
-       }
-
-}
-
-void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
-{
-}
-
-ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
-{
-       return MODEACTION_ALLOW;
-}
-
-class ModuleHalfop : public Module
-{
-       ModeChannelHalfOp mh;
- public:
-       ModuleHalfop() : mh(this)
-       {
-       }
-
-       void init()
-       {
-               ServerInstance->Modules->AddService(mh);
-       }
-
-       Version GetVersion()
-       {
-               return Version("Channel half-operator mode provider", VF_VENDOR);
-       }
-};
-
-MODULE_INIT(ModuleHalfop)
index 92abcd76f9582bb589765028a153b38ba4c8874b..1733d0455d6ce56ea1fb0b436e05c511958ef039 100644 (file)
@@ -98,7 +98,6 @@ class CommandHelpop : public Command
 
 class ModuleHelpop : public Module
 {
-       private:
                std::string  h_file;
                CommandHelpop cmd;
                Helpop ho;
@@ -109,7 +108,7 @@ class ModuleHelpop : public Module
                {
                }
 
-               void init()
+               void init() CXX11_OVERRIDE
                {
                        ReadConfig();
                        ServerInstance->Modules->AddService(ho);
@@ -151,12 +150,12 @@ class ModuleHelpop : public Module
 
                }
 
-               void OnRehash(User* user)
+               void OnRehash(User* user) CXX11_OVERRIDE
                {
                        ReadConfig();
                }
 
-               void OnWhois(User* src, User* dst)
+               void OnWhois(User* src, User* dst) CXX11_OVERRIDE
                {
                        if (dst->IsModeSet('h'))
                        {
@@ -164,7 +163,7 @@ class ModuleHelpop : public Module
                        }
                }
 
-               Version GetVersion()
+               Version GetVersion() CXX11_OVERRIDE
                {
                        return Version("Provides the /HELPOP command for useful information", VF_VENDOR);
                }
index 008c622086efc8caf14147480de27d4ef194b5df..3e2b271816cdddc4b35377fa5494aadd81ed0612 100644 (file)
@@ -39,7 +39,7 @@ class ModuleHideChans : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(hm);
                Implementation eventlist[] = { I_OnWhoisLine, I_OnRehash };
@@ -47,21 +47,17 @@ class ModuleHideChans : public Module
                OnRehash(NULL);
        }
 
-       virtual ~ModuleHideChans()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for hiding channels with user mode +I", VF_VENDOR);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                AffectsOpers = ServerInstance->Config->ConfValue("hidechans")->getBool("affectsopers");
        }
 
-       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
+       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
        {
                /* always show to self */
                if (user == dest)
@@ -88,5 +84,4 @@ class ModuleHideChans : public Module
        }
 };
 
-
 MODULE_INIT(ModuleHideChans)
index fbab9685f6c65b9909f997abf3f4829806a488aa..8c0757fe8b717585567ed36b81a30332ae67868f 100644 (file)
@@ -43,24 +43,19 @@ class ModuleHideOper : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(hm);
                Implementation eventlist[] = { I_OnWhoisLine, I_OnSendWhoLine };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-
-       virtual ~ModuleHideOper()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for hiding oper status with user mode +H", VF_VENDOR);
        }
 
-       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
+       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
        {
                /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
                 * person doing the WHOIS is not an oper
@@ -77,7 +72,7 @@ class ModuleHideOper : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
+       void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line) CXX11_OVERRIDE
        {
                if (user->IsModeSet('H') && !source->HasPrivPermission("users/auspex"))
                {
@@ -92,5 +87,4 @@ class ModuleHideOper : public Module
        }
 };
 
-
 MODULE_INIT(ModuleHideOper)
index 7433fccd3e0195953f5ae9d1ad269bc0de868872..7c25b4994ac7af7d21c63879dc0b32a7ae606b4f 100644 (file)
@@ -47,21 +47,20 @@ typedef std::vector<std::pair<std::string, Host> > hostchanges_t;
 
 class ModuleHostChange : public Module
 {
- private:
        hostchanges_t hostchanges;
        std::string MySuffix;
        std::string MyPrefix;
        std::string MySeparator;
 
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                Implementation eventlist[] = { I_OnRehash, I_OnUserConnect };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* host = ServerInstance->Config->ConfValue("host");
                MySuffix = host->getString("suffix");
@@ -97,14 +96,14 @@ class ModuleHostChange : public Module
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                // returns the version number of the module to be
                // listed in /MODULES
                return Version("Provides masking of user hostnames in a different way to m_cloaking", VF_VENDOR);
        }
 
-       virtual void OnUserConnect(LocalUser* user)
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
        {
                for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
                {
@@ -160,9 +159,9 @@ class ModuleHostChange : public Module
                                }
                                if (!newhost.empty())
                                {
-                                       user->WriteServ("NOTICE "+user->nick+" :Setting your virtual host: " + newhost);
+                                       user->WriteNotice("Setting your virtual host: " + newhost);
                                        if (!user->ChangeDisplayedHost(newhost.c_str()))
-                                               user->WriteServ("NOTICE "+user->nick+" :Could not set your virtual host: " + newhost);
+                                               user->WriteNotice("Could not set your virtual host: " + newhost);
                                        return;
                                }
                        }
index 37f715a8da221914b3d54a44c0556193e5796b93..cbee27958b5aeb4fe85fe2e246ed6a444b26cb78 100644 (file)
 
 
 #include "inspircd.h"
-#include "httpd.h"
+#include "modules/httpd.h"
 
 /* $ModDesc: Provides HTTP serving facilities to modules */
-/* $ModDep: httpd.h */
+/* $ModDep: modules/httpd.h */
 
 class ModuleHttpServer;
 
@@ -58,7 +58,6 @@ class HttpServerSocket : public BufferedSocket
        std::string http_version;
 
  public:
-
        HttpServerSocket(int newfd, const std::string& IP, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
                : BufferedSocket(newfd), ip(IP), postsize(0)
        {
@@ -69,7 +68,7 @@ class HttpServerSocket : public BufferedSocket
                        GetIOHook()->OnStreamSocketAccept(this, client, server);
        }
 
-       virtual void OnError(BufferedSocketError)
+       void OnError(BufferedSocketError) CXX11_OVERRIDE
        {
                ServerInstance->GlobalCulls.AddItem(this);
        }
@@ -217,7 +216,7 @@ class HttpServerSocket : public BufferedSocket
 
                        if (reqbuffer.length() >= 8192)
                        {
-                               ServerInstance->Logs->Log("m_httpd",DEBUG, "m_httpd dropped connection due to an oversized request buffer");
+                               ServerInstance->Logs->Log("m_httpd", LOG_DEBUG, "m_httpd dropped connection due to an oversized request buffer");
                                reqbuffer.clear();
                                SetError("Buffer");
                        }
@@ -334,15 +333,15 @@ class HttpServerSocket : public BufferedSocket
 class ModuleHttpServer : public Module
 {
        std::vector<HttpServerSocket *> httpsocks;
- public:
 
-       void init()
+ public:
+       void init() CXX11_OVERRIDE
        {
                HttpModule = this;
                ServerInstance->Modules->Attach(I_OnAcceptConnection, this);
        }
 
-       void OnRequest(Request& request)
+       void OnRequest(Request& request) CXX11_OVERRIDE
        {
                if (strcmp(request.id, "HTTP-DOC") != 0)
                        return;
@@ -351,7 +350,7 @@ class ModuleHttpServer : public Module
                resp.src.sock->Page(resp.document, resp.responsecode, &resp.headers);
        }
 
-       ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+       ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE
        {
                if (from->bind_tag->getString("type") != "httpd")
                        return MOD_RES_PASSTHRU;
@@ -362,8 +361,7 @@ class ModuleHttpServer : public Module
                return MOD_RES_ALLOW;
        }
 
-
-       virtual ~ModuleHttpServer()
+       ~ModuleHttpServer()
        {
                for (size_t i = 0; i < httpsocks.size(); i++)
                {
@@ -372,7 +370,7 @@ class ModuleHttpServer : public Module
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides HTTP serving facilities to modules", VF_VENDOR);
        }
index c25cabc0ae5eb40cc135ed4acf268718ca835914..061d56f254ec5082657e5daa75c71f073f3d1b45 100644 (file)
@@ -19,7 +19,7 @@
 
 
 #include "inspircd.h"
-#include "httpd.h"
+#include "modules/httpd.h"
 #include "protocol.h"
 
 /* $ModDesc: Provides access control lists (passwording of resources, ip restrictions etc) to m_httpd.so dependent modules */
@@ -37,18 +37,14 @@ class HTTPACL
                const std::string &set_whitelist, const std::string &set_blacklist)
                : path(set_path), username(set_username), password(set_password), whitelist(set_whitelist),
                blacklist(set_blacklist) { }
-
-       ~HTTPACL() { }
 };
 
 class ModuleHTTPAccessList : public Module
 {
-
        std::string stylesheet;
        std::vector<HTTPACL> acl_list;
 
  public:
-
        void OnRehash(User* user)
        {
                acl_list.clear();
@@ -86,14 +82,14 @@ class ModuleHTTPAccessList : public Module
                                }
                        }
 
-                       ServerInstance->Logs->Log("m_httpd_acl", DEBUG, "Read ACL: path=%s pass=%s whitelist=%s blacklist=%s", path.c_str(),
+                       ServerInstance->Logs->Log("m_httpd_acl", LOG_DEBUG, "Read ACL: path=%s pass=%s whitelist=%s blacklist=%s", path.c_str(),
                                        password.c_str(), whitelist.c_str(), blacklist.c_str());
 
                        acl_list.push_back(HTTPACL(path, username, password, whitelist, blacklist));
                }
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                Implementation eventlist[] = { I_OnEvent, I_OnRehash };
@@ -102,7 +98,7 @@ class ModuleHTTPAccessList : public Module
 
        void BlockAccess(HTTPRequest* http, int returnval, const std::string &extraheaderkey = "", const std::string &extraheaderval="")
        {
-               ServerInstance->Logs->Log("m_httpd_acl", DEBUG, "BlockAccess (%d)", returnval);
+               ServerInstance->Logs->Log("m_httpd_acl", LOG_DEBUG, "BlockAccess (%d)", returnval);
 
                std::stringstream data("Access to this resource is denied by an access control list. Please contact your IRC administrator.");
                HTTPDocumentResponse response(this, *http, &data, returnval);
@@ -112,11 +108,11 @@ class ModuleHTTPAccessList : public Module
                response.Send();
        }
 
-       void OnEvent(Event& event)
+       void OnEvent(Event& event) CXX11_OVERRIDE
        {
                if (event.id == "httpd_acl")
                {
-                       ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd acl event");
+                       ServerInstance->Logs->Log("m_http_stats", LOG_DEBUG, "Handling httpd acl event");
                        HTTPRequest* http = (HTTPRequest*)&event;
 
                        for (std::vector<HTTPACL>::const_iterator this_acl = acl_list.begin(); this_acl != acl_list.end(); ++this_acl)
@@ -133,7 +129,7 @@ class ModuleHTTPAccessList : public Module
                                                {
                                                        if (InspIRCd::Match(http->GetIP(), entry, ascii_case_insensitive_map))
                                                        {
-                                                               ServerInstance->Logs->Log("m_httpd_acl", DEBUG, "Denying access to blacklisted resource %s (matched by pattern %s) from ip %s (matched by entry %s)",
+                                                               ServerInstance->Logs->Log("m_httpd_acl", LOG_DEBUG, "Denying access to blacklisted resource %s (matched by pattern %s) from ip %s (matched by entry %s)",
                                                                                http->GetURI().c_str(), this_acl->path.c_str(), http->GetIP().c_str(), entry.c_str());
                                                                BlockAccess(http, 403);
                                                                return;
@@ -155,7 +151,7 @@ class ModuleHTTPAccessList : public Module
 
                                                if (!allow_access)
                                                {
-                                                       ServerInstance->Logs->Log("m_httpd_acl", DEBUG, "Denying access to whitelisted resource %s (matched by pattern %s) from ip %s (Not in whitelist)",
+                                                       ServerInstance->Logs->Log("m_httpd_acl", LOG_DEBUG, "Denying access to whitelisted resource %s (matched by pattern %s) from ip %s (Not in whitelist)",
                                                                        http->GetURI().c_str(), this_acl->path.c_str(), http->GetIP().c_str());
                                                        BlockAccess(http, 403);
                                                        return;
@@ -164,7 +160,7 @@ class ModuleHTTPAccessList : public Module
                                        if (!this_acl->password.empty() && !this_acl->username.empty())
                                        {
                                                /* Password auth, first look to see if we have a basic authentication header */
-                                               ServerInstance->Logs->Log("m_httpd_acl", DEBUG, "Checking HTTP auth password for resource %s (matched by pattern %s) from ip %s, against username %s",
+                                               ServerInstance->Logs->Log("m_httpd_acl", LOG_DEBUG, "Checking HTTP auth password for resource %s (matched by pattern %s) from ip %s, against username %s",
                                                                http->GetURI().c_str(), this_acl->path.c_str(), http->GetIP().c_str(), this_acl->username.c_str());
 
                                                if (http->headers->IsSet("Authorization"))
@@ -183,7 +179,7 @@ class ModuleHTTPAccessList : public Module
 
                                                                sep.GetToken(base64);
                                                                std::string userpass = Base64ToBin(base64);
-                                                               ServerInstance->Logs->Log("m_httpd_acl", DEBUG, "HTTP authorization: %s (%s)", userpass.c_str(), base64.c_str());
+                                                               ServerInstance->Logs->Log("m_httpd_acl", LOG_DEBUG, "HTTP authorization: %s (%s)", userpass.c_str(), base64.c_str());
 
                                                                irc::sepstream userpasspair(userpass, ':');
                                                                if (userpasspair.GetToken(user))
@@ -193,7 +189,7 @@ class ModuleHTTPAccessList : public Module
                                                                        /* Access granted if username and password are correct */
                                                                        if (user == this_acl->username && pass == this_acl->password)
                                                                        {
-                                                                               ServerInstance->Logs->Log("m_httpd_acl", DEBUG, "HTTP authorization: password and username match");
+                                                                               ServerInstance->Logs->Log("m_httpd_acl", LOG_DEBUG, "HTTP authorization: password and username match");
                                                                                return;
                                                                        }
                                                                        else
@@ -222,11 +218,7 @@ class ModuleHTTPAccessList : public Module
                }
        }
 
-       virtual ~ModuleHTTPAccessList()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides access control lists (passwording of resources, ip restrictions etc) to m_httpd.so dependent modules", VF_VENDOR);
        }
index 62314cd7ea0eef94282e3b4c8f94eaf8d0855f4a..a9fdd44fb3b96e3a18f172c8fcc285f461f64a01 100644 (file)
@@ -19,7 +19,7 @@
 
 
 #include "inspircd.h"
-#include "httpd.h"
+#include "modules/httpd.h"
 #include "protocol.h"
 
 /* $ModDesc: Allows for the server configuration to be viewed over HTTP via m_httpd.so */
@@ -27,7 +27,7 @@
 class ModuleHttpConfig : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnEvent };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
@@ -67,13 +67,13 @@ class ModuleHttpConfig : public Module
                return ret;
        }
 
-       void OnEvent(Event& event)
+       void OnEvent(Event& event) CXX11_OVERRIDE
        {
                std::stringstream data("");
 
                if (event.id == "httpd_url")
                {
-                       ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
+                       ServerInstance->Logs->Log("m_http_stats", LOG_DEBUG, "Handling httpd event");
                        HTTPRequest* http = (HTTPRequest*)&event;
 
                        if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
@@ -102,11 +102,7 @@ class ModuleHttpConfig : public Module
                }
        }
 
-       virtual ~ModuleHttpConfig()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows for the server configuration to be viewed over HTTP via m_httpd.so", VF_VENDOR);
        }
index 547d6032f1ebbf2e219728ed99ac8d585295084e..99909d97fac76c47fc72ad3e0f8e222f47e30bbb 100644 (file)
@@ -22,7 +22,7 @@
 
 
 #include "inspircd.h"
-#include "httpd.h"
+#include "modules/httpd.h"
 #include "xline.h"
 #include "protocol.h"
 
@@ -34,7 +34,7 @@ class ModuleHttpStats : public Module
 
  public:
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnEvent };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
@@ -55,8 +55,7 @@ class ModuleHttpStats : public Module
                                ret += it->second;
                                ret += ';';
                        }
-                       else if (*x == 0x9 ||  *x == 0xA || *x == 0xD ||
-                               (*x >= 0x20 && *x <= 0xD7FF) || (*x >= 0xE000 && *x <= 0x10FFFF))
+                       else if (*x == 0x9 ||  *x == 0xA || *x == 0xD || *x >= 0x20)
                        {
                                // The XML specification defines the following characters as valid inside an XML document:
                                // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
@@ -92,13 +91,13 @@ class ModuleHttpStats : public Module
                data << "</metadata>";
        }
 
-       void OnEvent(Event& event)
+       void OnEvent(Event& event) CXX11_OVERRIDE
        {
                std::stringstream data("");
 
                if (event.id == "httpd_url")
                {
-                       ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
+                       ServerInstance->Logs->Log("m_http_stats", LOG_DEBUG, "Handling httpd event");
                        HTTPRequest* http = (HTTPRequest*)&event;
 
                        if ((http->GetURI() == "/stats") || (http->GetURI() == "/stats/"))
@@ -120,7 +119,13 @@ class ModuleHttpStats : public Module
                                stime = gmtime(&server_uptime);
                                data << "<uptime><days>" << stime->tm_yday << "</days><hours>" << stime->tm_hour << "</hours><mins>" << stime->tm_min << "</mins><secs>" << stime->tm_sec << "</secs><boot_time_t>" << ServerInstance->startup_time << "</boot_time_t></uptime>";
 
-                               data << "<isupport>" << Sanitize(ServerInstance->Config->data005) << "</isupport></general><xlines>";
+                               data << "<isupport>";
+                               const std::vector<std::string>& isupport = ServerInstance->ISupport.GetLines();
+                               for (std::vector<std::string>::const_iterator it = isupport.begin(); it != isupport.end(); it++)
+                               {
+                                       data << Sanitize(*it) << std::endl;
+                               }
+                               data << "</isupport></general><xlines>";
                                std::vector<std::string> xltypes = ServerInstance->XLines->GetAllTypes();
                                for (std::vector<std::string>::iterator it = xltypes.begin(); it != xltypes.end(); ++it)
                                {
@@ -188,10 +193,10 @@ class ModuleHttpStats : public Module
                                        data << "<nickname>" << u->nick << "</nickname><uuid>" << u->uuid << "</uuid><realhost>"
                                                << u->host << "</realhost><displayhost>" << u->dhost << "</displayhost><gecos>"
                                                << Sanitize(u->fullname) << "</gecos><server>" << u->server << "</server>";
-                                       if (IS_AWAY(u))
+                                       if (u->IsAway())
                                                data << "<away>" << Sanitize(u->awaymsg) << "</away><awaytime>" << u->awaytime << "</awaytime>";
-                                       if (IS_OPER(u))
-                                               data << "<opertype>" << Sanitize(u->oper->NameStr()) << "</opertype>";
+                                       if (u->IsOper())
+                                               data << "<opertype>" << Sanitize(u->oper->name) << "</opertype>";
                                        data << "<modes>" << u->FormatModes() << "</modes><ident>" << Sanitize(u->ident) << "</ident>";
                                        LocalUser* lu = IS_LOCAL(u);
                                        if (lu)
@@ -233,11 +238,7 @@ class ModuleHttpStats : public Module
                }
        }
 
-       virtual ~ModuleHttpStats()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides statistics over HTTP via m_httpd.so", VF_VENDOR);
        }
index 6099e7c1411e24659a1aed30a5dbd9034612f97a..00ff75f59383df0f42a691c9ac8a558bded4d3c6 100644 (file)
@@ -142,9 +142,9 @@ class IdentRequestSocket : public EventHandler
                }
        }
 
-       virtual void OnConnected()
+       void OnConnected()
        {
-               ServerInstance->Logs->Log("m_ident",DEBUG,"OnConnected()");
+               ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "OnConnected()");
                ServerInstance->SE->ChangeEventMask(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE);
 
                char req[32];
@@ -165,7 +165,7 @@ class IdentRequestSocket : public EventHandler
                        done = true;
        }
 
-       virtual void HandleEvent(EventType et, int errornum = 0)
+       void HandleEvent(EventType et, int errornum = 0)
        {
                switch (et)
                {
@@ -179,7 +179,7 @@ class IdentRequestSocket : public EventHandler
                        break;
                        case EVENT_ERROR:
                                /* fd error event, ohshi- */
-                               ServerInstance->Logs->Log("m_ident",DEBUG,"EVENT_ERROR");
+                               ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "EVENT_ERROR");
                                /* We *must* Close() here immediately or we get a
                                 * huge storm of EVENT_ERROR events!
                                 */
@@ -196,7 +196,7 @@ class IdentRequestSocket : public EventHandler
                 */
                if (GetFd() > -1)
                {
-                       ServerInstance->Logs->Log("m_ident",DEBUG,"Close ident socket %d", GetFd());
+                       ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "Close ident socket %d", GetFd());
                        ServerInstance->SE->DelFd(this);
                        ServerInstance->SE->Close(GetFd());
                        this->SetFd(-1);
@@ -228,7 +228,7 @@ class IdentRequestSocket : public EventHandler
                if (recvresult < 3)
                        return;
 
-               ServerInstance->Logs->Log("m_ident",DEBUG,"ReadResponse()");
+               ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "ReadResponse()");
 
                /* Truncate at the first null character, but first make sure
                 * there is at least one null char (at the end of the buffer).
@@ -278,7 +278,7 @@ class ModuleIdent : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(ext);
                OnRehash(NULL);
@@ -289,29 +289,25 @@ class ModuleIdent : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ~ModuleIdent()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for RFC1413 ident lookups", VF_VENDOR);
        }
 
-       virtual void OnRehash(User *user)
+       void OnRehash(User *user) CXX11_OVERRIDE
        {
                RequestTimeout = ServerInstance->Config->ConfValue("ident")->getInt("timeout", 5);
                if (!RequestTimeout)
                        RequestTimeout = 5;
        }
 
-       void OnUserInit(LocalUser *user)
+       void OnUserInit(LocalUser *user) CXX11_OVERRIDE
        {
                ConfigTag* tag = user->MyClass->config;
                if (!tag->getBool("useident", true))
                        return;
 
-               user->WriteServ("NOTICE Auth :*** Looking up your ident...");
+               user->WriteNotice("*** Looking up your ident...");
 
                try
                {
@@ -320,7 +316,7 @@ class ModuleIdent : public Module
                }
                catch (ModuleException &e)
                {
-                       ServerInstance->Logs->Log("m_ident",DEBUG,"Ident exception: %s", e.GetReason());
+                       ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "Ident exception: %s", e.GetReason());
                }
        }
 
@@ -328,17 +324,17 @@ class ModuleIdent : public Module
         * creating a Timer object and especially better than creating a
         * Timer per ident lookup!
         */
-       virtual ModResult OnCheckReady(LocalUser *user)
+       ModResult OnCheckReady(LocalUser *user) CXX11_OVERRIDE
        {
                /* Does user have an ident socket attached at all? */
                IdentRequestSocket *isock = ext.get(user);
                if (!isock)
                {
-                       ServerInstance->Logs->Log("m_ident",DEBUG, "No ident socket :(");
+                       ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "No ident socket :(");
                        return MOD_RES_PASSTHRU;
                }
 
-               ServerInstance->Logs->Log("m_ident",DEBUG, "Has ident_socket");
+               ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "Has ident_socket");
 
                time_t compare = isock->age;
                compare += RequestTimeout;
@@ -347,28 +343,28 @@ class ModuleIdent : public Module
                if (ServerInstance->Time() >= compare)
                {
                        /* Ident timeout */
-                       user->WriteServ("NOTICE Auth :*** Ident request timed out.");
-                       ServerInstance->Logs->Log("m_ident",DEBUG, "Timeout");
+                       user->WriteNotice("*** Ident request timed out.");
+                       ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "Timeout");
                }
                else if (!isock->HasResult())
                {
                        // time still good, no result yet... hold the registration
-                       ServerInstance->Logs->Log("m_ident",DEBUG, "No result yet");
+                       ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "No result yet");
                        return MOD_RES_DENY;
                }
 
-               ServerInstance->Logs->Log("m_ident",DEBUG, "Yay, result!");
+               ServerInstance->Logs->Log("m_ident", LOG_DEBUG, "Yay, result!");
 
                /* wooo, got a result (it will be good, or bad) */
                if (isock->result.empty())
                {
                        user->ident.insert(0, 1, '~');
-                       user->WriteServ("NOTICE Auth :*** Could not find your ident, using %s instead.", user->ident.c_str());
+                       user->WriteNotice("*** Could not find your ident, using " + user->ident + " instead.");
                }
                else
                {
                        user->ident = isock->result;
-                       user->WriteServ("NOTICE Auth :*** Found your ident, '%s'", user->ident.c_str());
+                       user->WriteNotice("*** Found your ident, '" + user->ident + "'");
                }
 
                user->InvalidateCache();
@@ -377,14 +373,14 @@ class ModuleIdent : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
+       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE
        {
                if (myclass->config->getBool("requireident") && user->ident[0] == '~')
                        return MOD_RES_DENY;
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnCleanup(int target_type, void *item)
+       void OnCleanup(int target_type, void *item) CXX11_OVERRIDE
        {
                /* Module unloading, tidy up users */
                if (target_type == TYPE_USER)
@@ -395,7 +391,7 @@ class ModuleIdent : public Module
                }
        }
 
-       virtual void OnUserDisconnect(LocalUser *user)
+       void OnUserDisconnect(LocalUser *user) CXX11_OVERRIDE
        {
                /* User disconnect (generic socket detatch event) */
                IdentRequestSocket *isock = ext.get(user);
@@ -408,4 +404,3 @@ class ModuleIdent : public Module
 };
 
 MODULE_INIT(ModuleIdent)
-
index 747a3b30a53be2512bf01a80e4520ec0dea8cb8e..aeecb9a843214d34b73f6e0cb969c45b8861fd09 100644 (file)
 
 
 #include "inspircd.h"
-#include "u_listmode.h"
+#include "listmode.h"
 
 /* $ModDesc: Provides support for the +I channel mode */
-/* $ModDep: ../../include/u_listmode.h */
 
 /*
  * Written by Om <om@inspircd.org>, April 2005.
@@ -54,7 +53,7 @@ public:
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(ie);
 
@@ -64,17 +63,17 @@ public:
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" INVEX=I");
+               tokens["INVEX"] = "I";
        }
 
-       ModResult OnCheckInvite(User* user, Channel* chan)
+       ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
        {
-               modelist* list = ie.extItem.get(chan);
+               ListModeBase::ModeList* list = ie.GetList(chan);
                if (list)
                {
-                       for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                       for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
                        {
                                if (chan->CheckBan(user, it->mask))
                                {
@@ -86,25 +85,25 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnCheckKey(User* user, Channel* chan, const std::string& key)
+       ModResult OnCheckKey(User* user, Channel* chan, const std::string& key) CXX11_OVERRIDE
        {
                if (invite_bypass_key)
                        return OnCheckInvite(user, chan);
                return MOD_RES_PASSTHRU;
        }
 
-       void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
+       void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
        {
                ie.DoSyncChannel(chan, proto, opaque);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                invite_bypass_key = ServerInstance->Config->ConfValue("inviteexception")->getBool("bypasskey", true);
                ie.DoRehash();
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the +I channel mode", VF_VENDOR);
        }
index b0e020c63fa32e1d288b3dc388b6b2667db204fc..efa4ad167e9b98aacf55f8af059f9c89184c0905 100644 (file)
@@ -19,8 +19,8 @@
 /* $ModDesc: Provides support for extended-join, away-notify and account-notify CAP capabilities */
 
 #include "inspircd.h"
-#include "account.h"
-#include "m_cap.h"
+#include "modules/account.h"
+#include "modules/cap.h"
 
 class ModuleIRCv3 : public Module
 {
@@ -78,14 +78,14 @@ class ModuleIRCv3 : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                Implementation eventlist[] = { I_OnUserJoin, I_OnPostJoin, I_OnSetAway, I_OnEvent, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* conf = ServerInstance->Config->ConfValue("ircv3");
                accountnotify = conf->getBool("accoutnotify", true);
@@ -93,7 +93,7 @@ class ModuleIRCv3 : public Module
                extendedjoin = conf->getBool("extendedjoin", true);
        }
 
-       void OnEvent(Event& ev)
+       void OnEvent(Event& ev) CXX11_OVERRIDE
        {
                if (awaynotify)
                        cap_awaynotify.HandleEvent(ev);
@@ -122,10 +122,10 @@ class ModuleIRCv3 : public Module
                }
        }
 
-       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
+       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE
        {
                // Remember who is not going to see the JOIN because of other modules
-               if ((awaynotify) && (IS_AWAY(memb->user)))
+               if ((awaynotify) && (memb->user->IsAway()))
                        last_excepts = excepts;
 
                if (!extendedjoin)
@@ -195,7 +195,7 @@ class ModuleIRCv3 : public Module
                }
        }
 
-       ModResult OnSetAway(User* user, const std::string &awaymsg)
+       ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE
        {
                if (awaynotify)
                {
@@ -210,9 +210,9 @@ class ModuleIRCv3 : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnPostJoin(Membership *memb)
+       void OnPostJoin(Membership *memb) CXX11_OVERRIDE
        {
-               if ((!awaynotify) || (!IS_AWAY(memb->user)))
+               if ((!awaynotify) || (!memb->user->IsAway()))
                        return;
 
                std::string line = ":" + memb->user->GetFullHost() + " AWAY :" + memb->user->awaymsg;
@@ -236,7 +236,7 @@ class ModuleIRCv3 : public Module
                ServerInstance->Modules->SetPriority(this, I_OnUserJoin, PRIORITY_LAST);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for extended-join, away-notify and account-notify CAP capabilities", VF_VENDOR);
        }
index 0c68da1fb42445433e7777b1ef75cfe0d1190aab..fde974559bbb68f1820f5669c8d8e7fc054ae675 100644 (file)
 class joinfloodsettings
 {
  public:
-       int secs;
-       int joins;
+       unsigned int secs;
+       unsigned int joins;
        time_t reset;
        time_t unlocktime;
-       int counter;
-       bool locked;
+       unsigned int counter;
 
-       joinfloodsettings(int b, int c) : secs(b), joins(c)
+       joinfloodsettings(unsigned int b, unsigned int c)
+               : secs(b), joins(c), unlocktime(0), counter(0)
        {
                reset = ServerInstance->Time() + secs;
-               counter = 0;
-               locked = false;
-       };
+       }
 
        void addjoin()
        {
-               counter++;
                if (ServerInstance->Time() > reset)
                {
-                       counter = 0;
+                       counter = 1;
                        reset = ServerInstance->Time() + secs;
                }
+               else
+                       counter++;
        }
 
        bool shouldlock()
@@ -66,27 +65,21 @@ class joinfloodsettings
 
        bool islocked()
        {
-               if (locked)
-               {
-                       if (ServerInstance->Time() > unlocktime)
-                       {
-                               locked = false;
-                               return false;
-                       }
-                       else
-                       {
-                               return true;
-                       }
-               }
-               return false;
+               if (ServerInstance->Time() > unlocktime)
+                       unlocktime = 0;
+
+               return (unlocktime != 0);
        }
 
        void lock()
        {
-               locked = true;
                unlocktime = ServerInstance->Time() + 60;
        }
 
+       bool operator==(const joinfloodsettings& other) const
+       {
+               return ((this->secs == other.secs) && (this->joins == other.joins));
+       }
 };
 
 /** Handles channel mode +j
@@ -102,85 +95,43 @@ class JoinFlood : public ModeHandler
        {
                if (adding)
                {
-                       char ndata[MAXBUF];
-                       char* data = ndata;
-                       strlcpy(ndata,parameter.c_str(),MAXBUF);
-                       char* joins = data;
-                       char* secs = NULL;
-                       while (*data)
+                       std::string::size_type colon = parameter.find(':');
+                       if ((colon == std::string::npos) || (parameter.find('-') != std::string::npos))
                        {
-                               if (*data == ':')
-                               {
-                                       *data = 0;
-                                       data++;
-                                       secs = data;
-                                       break;
-                               }
-                               else data++;
+                               source->WriteNumeric(608, "%s %s :Invalid flood parameter",source->nick.c_str(),channel->name.c_str());
+                               return MODEACTION_DENY;
                        }
-                       if (secs)
 
-                       {
-                               /* Set up the flood parameters for this channel */
-                               int njoins = atoi(joins);
-                               int nsecs = atoi(secs);
-                               if ((njoins<1) || (nsecs<1))
-                               {
-                                       source->WriteNumeric(608, "%s %s :Invalid flood parameter",source->nick.c_str(),channel->name.c_str());
-                                       parameter.clear();
-                                       return MODEACTION_DENY;
-                               }
-                               else
-                               {
-                                       joinfloodsettings* f = ext.get(channel);
-                                       if (!f)
-                                       {
-                                               parameter = ConvToStr(njoins) + ":" +ConvToStr(nsecs);
-                                               f = new joinfloodsettings(nsecs, njoins);
-                                               ext.set(channel, f);
-                                               channel->SetModeParam('j', parameter);
-                                               return MODEACTION_ALLOW;
-                                       }
-                                       else
-                                       {
-                                               std::string cur_param = channel->GetModeParameter('j');
-                                               parameter = ConvToStr(njoins) + ":" +ConvToStr(nsecs);
-                                               if (cur_param == parameter)
-                                               {
-                                                       // mode params match
-                                                       return MODEACTION_DENY;
-                                               }
-                                               else
-                                               {
-                                                       // new mode param, replace old with new
-                                                       if ((nsecs > 0) && (njoins > 0))
-                                                       {
-                                                               f = new joinfloodsettings(nsecs, njoins);
-                                                               ext.set(channel, f);
-                                                               channel->SetModeParam('j', parameter);
-                                                               return MODEACTION_ALLOW;
-                                                       }
-                                                       else
-                                                       {
-                                                               return MODEACTION_DENY;
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-                       else
+                       /* Set up the flood parameters for this channel */
+                       unsigned int njoins = ConvToInt(parameter.substr(0, colon));
+                       unsigned int nsecs = ConvToInt(parameter.substr(colon+1));
+                       if ((njoins<1) || (nsecs<1))
                        {
                                source->WriteNumeric(608, "%s %s :Invalid flood parameter",source->nick.c_str(),channel->name.c_str());
                                return MODEACTION_DENY;
                        }
+
+                       joinfloodsettings jfs(nsecs, njoins);
+                       joinfloodsettings* f = ext.get(channel);
+                       if ((f) && (*f == jfs))
+                               // mode params match
+                               return MODEACTION_DENY;
+
+                       ext.set(channel, jfs);
+                       parameter = ConvToStr(njoins) + ":" + ConvToStr(nsecs);
+                       channel->SetModeParam(this, parameter);
+                       return MODEACTION_ALLOW;
                }
                else
                {
+                       if (!channel->IsModeSet(this))
+                               return MODEACTION_DENY;
+
                        joinfloodsettings* f = ext.get(channel);
                        if (f)
                        {
                                ext.unset(channel);
-                               channel->SetModeParam('j', "");
+                               channel->SetModeParam(this, "");
                                return MODEACTION_ALLOW;
                        }
                }
@@ -190,17 +141,15 @@ class JoinFlood : public ModeHandler
 
 class ModuleJoinFlood : public Module
 {
-
        JoinFlood jf;
 
  public:
-
        ModuleJoinFlood()
                : jf(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(jf);
                ServerInstance->Modules->AddService(jf.ext);
@@ -208,7 +157,7 @@ class ModuleJoinFlood : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                if (chan)
                {
@@ -222,7 +171,7 @@ class ModuleJoinFlood : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
+       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE
        {
                /* We arent interested in JOIN events caused by a network burst */
                if (sync)
@@ -243,11 +192,7 @@ class ModuleJoinFlood : public Module
                }
        }
 
-       ~ModuleJoinFlood()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +j (join flood protection)", VF_VENDOR);
        }
index dce8f0bd5dfcf2856f184cdb6495b244e636733a..2bcef9836d692b76b6c9dd8d566b433e38de1d39 100644 (file)
@@ -53,9 +53,9 @@ class CommandJumpserver : public Command
                if (!parameters.size())
                {
                        if (port)
-                               user->WriteServ("NOTICE %s :*** Disabled jumpserver (previously set to '%s:%d')", user->nick.c_str(), redirect_to.c_str(), port);
+                               user->WriteNotice("*** Disabled jumpserver (previously set to '" + redirect_to + ":" + ConvToStr(port) + "')");
                        else
-                               user->WriteServ("NOTICE %s :*** Jumpserver was not enabled.", user->nick.c_str());
+                               user->WriteNotice("*** Jumpserver was not enabled.");
 
                        port = 0;
                        redirect_to.clear();
@@ -84,7 +84,7 @@ class CommandJumpserver : public Command
                                                redirect_new_users = direction;
                                        break;
                                        default:
-                                               user->WriteServ("NOTICE %s :*** Invalid JUMPSERVER flag: %c", user->nick.c_str(), *n);
+                                               user->WriteNotice("*** Invalid JUMPSERVER flag: " + ConvToStr(*n));
                                                return CMD_FAILURE;
                                        break;
                                }
@@ -92,7 +92,7 @@ class CommandJumpserver : public Command
 
                        if (!atoi(parameters[1].c_str()))
                        {
-                               user->WriteServ("NOTICE %s :*** Invalid port number", user->nick.c_str());
+                               user->WriteNotice("*** Invalid port number");
                                return CMD_FAILURE;
                        }
 
@@ -102,7 +102,7 @@ class CommandJumpserver : public Command
                                for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); ++i)
                                {
                                        User* t = *i;
-                                       if (!IS_OPER(t))
+                                       if (!t->IsOper())
                                        {
                                                t->WriteNumeric(10, "%s %s %s :Please use this Server/Port instead", t->nick.c_str(), parameters[0].c_str(), parameters[1].c_str());
                                                ServerInstance->Users->QuitUser(t, reason);
@@ -121,20 +121,15 @@ class CommandJumpserver : public Command
                                port = atoi(parameters[1].c_str());
                        }
 
-                       user->WriteServ("NOTICE %s :*** Set jumpserver to server '%s' port '%s', flags '+%s%s'%s%s%s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[1].c_str(),
-                                       redirect_all_immediately ? "a" : "",
-                                       redirect_new_users ? "n" : "",
-                                       n_done ? " (" : "",
-                                       n_done ? n_done_s.c_str() : "",
-                                       n_done ? " user(s) redirected)" : "",
-                                       reason.c_str());
+                       user->WriteNotice("*** Set jumpserver to server '" + parameters[0] + "' port '" + parameters[1] + "', flags '+" +
+                               (redirect_all_immediately ? "a" : "") + (redirect_new_users ? "n'" : "'") +
+                               (n_done ? " (" + n_done_s + "user(s) redirected): " : ": ") + reason);
                }
 
                return CMD_SUCCESS;
        }
 };
 
-
 class ModuleJumpServer : public Module
 {
        CommandJumpserver js;
@@ -143,18 +138,14 @@ class ModuleJumpServer : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(js);
                Implementation eventlist[] = { I_OnUserRegister, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleJumpServer()
-       {
-       }
-
-       virtual ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                if (js.port && js.redirect_new_users)
                {
@@ -166,17 +157,16 @@ class ModuleJumpServer : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                // Emergency way to unlock
                if (!user) js.redirect_new_users = false;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the RPL_REDIR numeric and the /JUMPSERVER command.", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleJumpServer)
index a914f38693108b69d37a357d7131a92d72c6d43c..3406f4f991170b51bb4c66ed43dffd51ec64473a 100644 (file)
@@ -33,8 +33,8 @@ typedef std::map<std::string, time_t> delaylist;
  */
 class KickRejoin : public ModeHandler
 {
+       static const unsigned int max = 60;
  public:
-       unsigned int max;
        SimpleExtItem<delaylist> ext;
        KickRejoin(Module* Creator)
                : ModeHandler(Creator, "kicknorejoin", 'J', PARAM_SETONLY, MODETYPE_CHANNEL)
@@ -42,7 +42,7 @@ class KickRejoin : public ModeHandler
        {
        }
 
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding)
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
        {
                if (adding)
                {
@@ -75,29 +75,20 @@ class ModuleKickNoRejoin : public Module
        KickRejoin kr;
 
 public:
-
        ModuleKickNoRejoin()
                : kr(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(kr);
                ServerInstance->Modules->AddService(kr.ext);
-               Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick, I_OnRehash };
+               Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-               OnRehash(NULL);
-       }
-
-       void OnRehash(User* user)
-       {
-               kr.max = ServerInstance->Duration(ServerInstance->Config->ConfValue("kicknorejoin")->getString("maxtime"));
-               if (!kr.max)
-                       kr.max = 30*60;
        }
 
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                if (chan)
                {
@@ -131,7 +122,7 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
+       void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
        {
                if (memb->chan->IsModeSet(&kr) && (IS_LOCAL(memb->user)) && (source != memb->user))
                {
@@ -145,15 +136,10 @@ public:
                }
        }
 
-       ~ModuleKickNoRejoin()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Channel mode to delay rejoin after kick", VF_VENDOR);
        }
 };
 
-
 MODULE_INIT(ModuleKickNoRejoin)
index 8d2aa4543065be26e7b410ef41007c6d664cd37d..4c29fe6bc4101e1a737fbe8bd07c1bc033be7a4c 100644 (file)
@@ -70,7 +70,7 @@ class CommandKnock : public Command
                if (sendnumeric)
                        c->WriteChannelWithServ(ServerInstance->Config->ServerName, "710 %s %s %s :is KNOCKing: %s", c->name.c_str(), c->name.c_str(), user->GetFullHost().c_str(), parameters[1].c_str());
 
-               user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str());
+               user->WriteNotice("KNOCKing on " + c->name);
                return CMD_SUCCESS;
        }
 
@@ -97,7 +97,7 @@ class ModuleKnock : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(kn);
                ServerInstance->Modules->AddService(cmd);
@@ -106,7 +106,7 @@ class ModuleKnock : public Module
                OnRehash(NULL);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify");
                irc::string notify(knocknotify.c_str());
@@ -128,7 +128,7 @@ class ModuleKnock : public Module
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for /KNOCK and channel mode +K", VF_OPTCOMMON | VF_VENDOR);
        }
index 4983ae16abe3afa01eaa7022feca4fe7c2a51f7c..460f735d651a68db4a4d2ac30ffa5bc63b64d5c1 100644 (file)
 /** Adds numerics
  * 988 <nick> <servername> :Closed for new connections
  * 989 <nick> <servername> :Open for new connections
-*/
-
+ */
 
 class CommandLockserv : public Command
 {
        bool& locked;
-public:
+
+ public:
        CommandLockserv(Module* Creator, bool& lock) : Command(Creator, "LOCKSERV", 0), locked(lock)
        {
                flags_needed = 'o';
@@ -41,7 +41,7 @@ public:
        {
                if (locked)
                {
-                       user->WriteServ("NOTICE %s :The server is already locked.", user->nick.c_str());
+                       user->WriteNotice("The server is already locked.");
                        return CMD_FAILURE;
                }
 
@@ -54,10 +54,9 @@ public:
 
 class CommandUnlockserv : public Command
 {
-private:
        bool& locked;
 
-public:
+ public:
        CommandUnlockserv(Module* Creator, bool &lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
        {
                flags_needed = 'o';
@@ -67,7 +66,7 @@ public:
        {
                if (!locked)
                {
-                       user->WriteServ("NOTICE %s :The server isn't locked.", user->nick.c_str());
+                       user->WriteNotice("The server isn't locked.");
                        return CMD_FAILURE;
                }
 
@@ -80,17 +79,16 @@ public:
 
 class ModuleLockserv : public Module
 {
-private:
        bool locked;
        CommandLockserv lockcommand;
        CommandUnlockserv unlockcommand;
 
-public:
+ public:
        ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                locked = false;
                ServerInstance->Modules->AddService(lockcommand);
@@ -99,18 +97,13 @@ public:
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleLockserv()
-       {
-       }
-
-
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                // Emergency way to unlock
                if (!user) locked = false;
        }
 
-       virtual ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                if (locked)
                {
@@ -120,12 +113,12 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnCheckReady(LocalUser* user)
+       ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
        {
                return locked ? MOD_RES_DENY : MOD_RES_PASSTHRU;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows locking of the server to stop all incoming connections until unlocked again", VF_VENDOR);
        }
index 546e342ae36180d4644921501689e8b6c24b6f3f..28e8636b02d6dbfe6f11ceb6904c2249f290c350 100644 (file)
@@ -25,38 +25,33 @@ class ModuleMapHide : public Module
 {
        std::string url;
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnPreCommand, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
                OnRehash(NULL);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                url = ServerInstance->Config->ConfValue("security")->getString("maphide");
        }
 
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
-               if (validated && !IS_OPER(user) && !url.empty() && (command == "MAP" || command == "LINKS"))
+               if (validated && !user->IsOper() && !url.empty() && (command == "MAP" || command == "LINKS"))
                {
-                       user->WriteServ("NOTICE %s :/%s has been disabled; visit %s", user->nick.c_str(), command.c_str(), url.c_str());
+                       user->WriteNotice("/" + command + " has been disabled; visit " + url);
                        return MOD_RES_DENY;
                }
                else
                        return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleMapHide()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Hide /MAP and /LINKS in the same form as ircu (mostly useless)", VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleMapHide)
-
index 14ccf16a8c8ff87ae18d2088d89ccce08ac7a398..558bd68b9a5bd59fbbde3408f0b55caa2ca505a9 100644 (file)
@@ -27,7 +27,7 @@
 #ifdef HAS_STDINT
 #include <stdint.h>
 #endif
-#include "hash.h"
+#include "modules/hash.h"
 
 /* The four core functions - F1 is optimized somewhat */
 #define F1(x, y, z) (z ^ (x & (y ^ z)))
@@ -275,13 +275,6 @@ class MD5Provider : public HashProvider
                return std::string(res, 16);
        }
 
-       std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata)
-       {
-               char res[33];
-               GenHash(sdata.data(), res, HexMap, IV, sdata.length());
-               return res;
-       }
-
        MD5Provider(Module* parent) : HashProvider(parent, "hash/md5", 16, 64) {}
 };
 
@@ -294,7 +287,7 @@ class ModuleMD5 : public Module
                ServerInstance->Modules->AddService(md5);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements MD5 hashing",VF_VENDOR);
        }
index 9ff17924d1c38bbb154c4a959fa151824894a221..970087befeec85ee9db7476de7b86edb2a3a705a 100644 (file)
@@ -128,12 +128,11 @@ class ModuleMsgFlood : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(mf);
                ServerInstance->Modules->AddService(mf.ext);
-               Implementation eventlist[] = { I_OnUserPreNotice, I_OnUserPreMessage };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+               ServerInstance->Modules->Attach(I_OnUserPreMessage, this);
        }
 
        ModResult ProcessMessages(User* user,Channel* dest, const std::string &text)
@@ -160,10 +159,10 @@ class ModuleMsgFlood : public Module
                                        ServerInstance->SendGlobalMode(parameters, ServerInstance->FakeClient);
                                }
 
-                               char kickmessage[MAXBUF];
-                               snprintf(kickmessage, MAXBUF, "Channel flood triggered (limit is %u lines in %u secs)", f->lines, f->secs);
+                               const std::string kickMessage = "Channel flood triggered (limit is " + ConvToStr(f->lines) +
+                                       " in " + ConvToStr(f->secs) + " secs)";
 
-                               dest->KickUser(ServerInstance->FakeClient, user, kickmessage);
+                               dest->KickUser(ServerInstance->FakeClient, user, kickMessage);
 
                                return MOD_RES_DENY;
                        }
@@ -172,15 +171,7 @@ class ModuleMsgFlood : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserPreMessage(User *user, void *dest, int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               if (target_type == TYPE_CHANNEL)
-                       return ProcessMessages(user,(Channel*)dest,text);
-
-               return MOD_RES_PASSTHRU;
-       }
-
-       ModResult OnUserPreNotice(User *user, void *dest, int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (target_type == TYPE_CHANNEL)
                        return ProcessMessages(user,(Channel*)dest,text);
@@ -192,10 +183,9 @@ class ModuleMsgFlood : public Module
        {
                // we want to be after all modules that might deny the message (e.g. m_muteban, m_noctcp, m_blockcolor, etc.)
                ServerInstance->Modules->SetPriority(this, I_OnUserPreMessage, PRIORITY_LAST);
-               ServerInstance->Modules->SetPriority(this, I_OnUserPreNotice, PRIORITY_LAST);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +f (message flood protection)", VF_VENDOR);
        }
index 719701d02beee2018aeaeef16d01d51c84d77dd1..38feb8f6b4c3bf4138a23f79b7f7ff6db06f93d4 100644 (file)
 
 class ModuleMLock : public Module
 {
-private:
        StringExtItem mlock;
 
 public:
        ModuleMLock() : mlock("mlock", this) {};
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->Attach(I_OnPreMode, this);
                ServerInstance->Modules->AddService(this->mlock);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements the ability to have server-side MLOCK enforcement.", VF_VENDOR);
        }
@@ -45,7 +44,7 @@ public:
                ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
        }
 
-       ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters)
+       ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
        {
                if (!channel)
                        return MOD_RES_PASSTHRU;
@@ -67,7 +66,6 @@ public:
 
                return MOD_RES_PASSTHRU;
        }
-
 };
 
 MODULE_INIT(ModuleMLock)
index 767af29017b7dde4751342f3918a479e3fac4564..1b6cdff93fa821a1ff38b7cd7311287f1763fa45 100644 (file)
 
 class ModuleQuietBan : public Module
 {
- private:
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleQuietBan()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements extban +b m: - mute bans",VF_OPTCOMMON|VF_VENDOR);
        }
 
-       virtual ModResult OnUserPreMessage(User *user, void *dest, int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user) || target_type != TYPE_CHANNEL)
                        return MOD_RES_PASSTHRU;
@@ -56,17 +51,10 @@ class ModuleQuietBan : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreNotice(User *user, void *dest, int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
-       }
-
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('m');
+               tokens["EXTBAN"].push_back('m');
        }
 };
 
-
 MODULE_INIT(ModuleQuietBan)
-
index 4db1f70b92c78e9a0d5da781f99c0114a0eec90e..3e27092a7fbb1ec1e329fe5eb9117cd3859b9baf 100644 (file)
@@ -35,9 +35,8 @@ static void DisplayList(User* user, Channel* channel)
                if (mh->GetNumParams(true))
                        items << " " << channel->GetModeParameter(letter);
        }
-       char pfx[MAXBUF];
-       snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str());
-       user->SendText(std::string(pfx), items);
+       const std::string line = ":" + ServerInstance->Config->ServerName + " 961 " + user->nick + " " + channel->name;
+       user->SendText(line, items);
        user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
 }
 
@@ -106,7 +105,7 @@ class ModuleNamedModes : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->Modules->AddService(dummyZ);
@@ -115,7 +114,7 @@ class ModuleNamedModes : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
        }
@@ -125,7 +124,7 @@ class ModuleNamedModes : public Module
                ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
        }
 
-       ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters)
+       ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
        {
                if (!channel)
                        return MOD_RES_PASSTHRU;
index 82d311773c2b52ba0d7ce14b50140e65efe868dd..a890ba16f531e30704a022c1a17d4a0916b1e7ae 100644 (file)
 
 
 #include "inspircd.h"
-#include "m_cap.h"
+#include "modules/cap.h"
 
 /* $ModDesc: Provides the NAMESX (CAP multi-prefix) capability. */
 
 class ModuleNamesX : public Module
 {
- public:
        GenericCap cap;
+ public:
        ModuleNamesX() : cap(this, "multi-prefix")
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent, I_OnSendWhoLine };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-
-       ~ModuleNamesX()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the NAMESX (CAP multi-prefix) capability.",VF_VENDOR);
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" NAMESX");
+               tokens["NAMESX"];
        }
 
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                /* We don't actually create a proper command handler class for PROTOCTL,
                 * because other modules might want to have PROTOCTL hooks too.
@@ -72,7 +67,7 @@ class ModuleNamesX : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
+       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
        {
                if (!cap.ext.get(issuer))
                        return;
@@ -84,7 +79,7 @@ class ModuleNamesX : public Module
                prefixes = memb->chan->GetAllPrefixChars(memb->user);
        }
 
-       void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
+       void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line) CXX11_OVERRIDE
        {
                if (!cap.ext.get(source))
                        return;
@@ -122,7 +117,7 @@ class ModuleNamesX : public Module
                line.insert(pos, prefixes);
        }
 
-       void OnEvent(Event& ev)
+       void OnEvent(Event& ev) CXX11_OVERRIDE
        {
                cap.HandleEvent(ev);
        }
index b43b6e2b6a05e55cdc9e0efd058790caa7a0545d..a668b7a2c9e1ebe4ff9db6ba60d38bed66e0c5b1 100644 (file)
 
 /* $ModDesc: Provides an ability to have non-RFC1459 nicks & support for national CASEMAPPING */
 
-class lwbNickHandler : public HandlerBase2<bool, const char*, size_t>
+class lwbNickHandler : public HandlerBase1<bool, const std::string&>
 {
  public:
        lwbNickHandler() { }
-       virtual ~lwbNickHandler() { }
-       virtual bool Call(const char*, size_t);
+       ~lwbNickHandler() { }
+       bool Call(const std::string&);
 };
 
                                                                 /*,m_reverse_additionalUp[256];*/
@@ -71,11 +71,12 @@ char utf8size(unsigned char * mb)
 
 
 /* Conditions added */
-bool lwbNickHandler::Call(const char* n, size_t max)
+bool lwbNickHandler::Call(const std::string& nick)
 {
-       if (!n || !*n)
+       if (nick.empty())
                return false;
 
+       const char* n = nick.c_str();
        unsigned int p = 0;
        for (const char* i = n; *i; i++, p++)
        {
@@ -215,17 +216,16 @@ bool lwbNickHandler::Call(const char* n, size_t max)
        }
 
        /* too long? or not -- pointer arithmetic rocks */
-       return (p < max);
+       return (p < ServerInstance->Config->Limits.NickMax);
 }
 
 
 class ModuleNationalChars : public Module
 {
- private:
        lwbNickHandler myhandler;
        std::string charset, casemapping;
        unsigned char m_additional[256], m_additionalUp[256], m_lower[256], m_upper[256];
-       caller2<bool, const char*, size_t> rememberer;
+       caller1<bool, const std::string&> rememberer;
        bool forcequit;
        const unsigned char * lowermap_rememberer;
 
@@ -235,7 +235,7 @@ class ModuleNationalChars : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                memcpy(m_lower, rfc_case_insensitive_map, 256);
                national_case_insensitive_map = m_lower;
@@ -247,14 +247,12 @@ class ModuleNationalChars : public Module
                OnRehash(NULL);
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               std::string tmp(casemapping);
-               tmp.insert(0, "CASEMAPPING=");
-               SearchAndReplace(output, std::string("CASEMAPPING=rfc1459"), tmp);
+               tokens["CASEMAPPING"] = casemapping;
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("nationalchars");
                charset = tag->getString("file");
@@ -276,19 +274,19 @@ class ModuleNationalChars : public Module
                {
                        /* Fix by Brain: Dont quit UID users */
                        User* n = *iter;
-                       if (!isdigit(n->nick[0]) && !ServerInstance->IsNick(n->nick.c_str(), ServerInstance->Config->Limits.NickMax))
+                       if (!isdigit(n->nick[0]) && !ServerInstance->IsNick(n->nick))
                                ServerInstance->Users->QuitUser(n, message);
                }
        }
 
-       virtual ~ModuleNationalChars()
+       ~ModuleNationalChars()
        {
                ServerInstance->IsNick = rememberer;
                national_case_insensitive_map = lowermap_rememberer;
                CheckForceQuit("National characters module unloaded");
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides an ability to have non-RFC1459 nicks & support for national CASEMAPPING", VF_VENDOR | VF_COMMON, charset);
        }
@@ -307,7 +305,7 @@ class ModuleNationalChars : public Module
                std::ifstream ifs(filename.c_str());
                if (ifs.fail())
                {
-                       ServerInstance->Logs->Log("m_nationalchars",DEFAULT,"loadtables() called for missing file: %s", filename.c_str());
+                       ServerInstance->Logs->Log("m_nationalchars", LOG_DEFAULT, "loadtables() called for missing file: %s", filename.c_str());
                        return;
                }
 
@@ -322,7 +320,7 @@ class ModuleNationalChars : public Module
                {
                        if (loadtable(ifs, tables[n], 255) && (n < faillimit))
                        {
-                               ServerInstance->Logs->Log("m_nationalchars",DEFAULT,"loadtables() called for illegal file: %s (line %d)", filename.c_str(), n+1);
+                               ServerInstance->Logs->Log("m_nationalchars", LOG_DEFAULT, "loadtables() called for illegal file: %s (line %d)", filename.c_str(), n+1);
                                return;
                        }
                }
index 04d7c8b5e2cc86d28e812cf578bcc4a64639f282..de9b64f9981bd967a5f1dbd93c43fdb217b95174 100644 (file)
@@ -135,13 +135,12 @@ class ModuleNickFlood : public Module
        NickFlood nf;
 
  public:
-
        ModuleNickFlood()
                : nf(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(nf);
                ServerInstance->Modules->AddService(nf.ext);
@@ -149,11 +148,8 @@ class ModuleNickFlood : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ModResult OnUserPreNick(User* user, const std::string &newnick)
+       ModResult OnUserPreNick(User* user, const std::string &newnick) CXX11_OVERRIDE
        {
-               if (ServerInstance->NICKForced.get(user)) /* Allow forced nick changes */
-                       return MOD_RES_PASSTHRU;
-
                for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
                {
                        Channel *channel = *i;
@@ -188,7 +184,7 @@ class ModuleNickFlood : public Module
        /*
         * XXX: HACK: We do the increment on the *POST* event here (instead of all together) because we have no way of knowing whether other modules would block a nickchange.
         */
-       void OnUserPostNick(User* user, const std::string &oldnick)
+       void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE
        {
                if (isdigit(user->nick[0])) /* allow switches to UID */
                        return;
@@ -214,11 +210,7 @@ class ModuleNickFlood : public Module
                }
        }
 
-       ~ModuleNickFlood()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Channel mode F - nick flood protection", VF_VENDOR);
        }
index 4f5e5941cea5d653bb2453e19e154b4fcb68d82b..7bd2c43b21597481487ee736687bdd26152bfd03 100644 (file)
@@ -44,16 +44,16 @@ class CommandNicklock : public Command
 
                if ((!target) || (target->registered != REG_ALL))
                {
-                       user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
+                       user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
                        return CMD_FAILURE;
                }
 
                /* Do local sanity checks and bails */
                if (IS_LOCAL(user))
                {
-                       if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
+                       if (!ServerInstance->IsNick(parameters[1]))
                        {
-                               user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
+                               user->WriteNotice("*** Invalid nickname '" + parameters[1] + "'");
                                return CMD_FAILURE;
                        }
 
@@ -66,7 +66,7 @@ class CommandNicklock : public Command
                        locked.set(target, 1);
 
                        std::string oldnick = target->nick;
-                       if (target->ForceNickChange(parameters[1].c_str()))
+                       if (target->ForceNickChange(parameters[1]))
                                ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
                        else
                        {
@@ -107,7 +107,7 @@ class CommandNickunlock : public Command
 
                if (!target)
                {
-                       user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
+                       user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
                        return CMD_FAILURE;
                }
 
@@ -139,7 +139,6 @@ class CommandNickunlock : public Command
        }
 };
 
-
 class ModuleNickLock : public Module
 {
        LocalIntExt locked;
@@ -151,7 +150,7 @@ class ModuleNickLock : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd1);
                ServerInstance->Modules->AddService(cmd2);
@@ -159,23 +158,16 @@ class ModuleNickLock : public Module
                ServerInstance->Modules->Attach(I_OnUserPreNick, this);
        }
 
-       ~ModuleNickLock()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the NICKLOCK command, allows an oper to change a users nick and lock them to it until they quit", VF_OPTCOMMON | VF_VENDOR);
        }
 
-       ModResult OnUserPreNick(User* user, const std::string &newnick)
+       ModResult OnUserPreNick(User* user, const std::string &newnick) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return MOD_RES_PASSTHRU;
 
-               if (ServerInstance->NICKForced.get(user)) /* Allow forced nick changes */
-                       return MOD_RES_PASSTHRU;
-
                if (locked.get(user))
                {
                        user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
index 1dd6fe34ad467d71617f55b52316685cc9b3e9b7..29b548e1c65a399ede9f2ff23eaede3b83c43823 100644 (file)
@@ -31,38 +31,27 @@ class NoCTCP : public SimpleChannelModeHandler
 
 class ModuleNoCTCP : public Module
 {
-
        NoCTCP nc;
 
  public:
-
        ModuleNoCTCP()
                : nc(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(nc);
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleNoCTCP()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +C to block CTCPs", VF_VENDOR);
        }
 
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
-       }
-
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
                {
@@ -83,9 +72,9 @@ class ModuleNoCTCP : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('C');
+               tokens["EXTBAN"].push_back('C');
        }
 };
 
index 1f58a2e08b71a7663ef052acd14b89e92a2610b4..2b301f6c5af06e1fe8dd8f19f4e9b051074af2a8 100644 (file)
@@ -40,19 +40,19 @@ class ModuleNoKicks : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(nk);
                Implementation eventlist[] = { I_OnUserPreKick, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('Q');
+               tokens["EXTBAN"].push_back('Q');
        }
 
-       ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
+       ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
        {
                if (!memb->chan->GetExtBanStatus(source, 'Q').check(!memb->chan->IsModeSet('Q')))
                {
@@ -63,15 +63,10 @@ class ModuleNoKicks : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ~ModuleNoKicks()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +Q to prevent kicks on the channel.", VF_VENDOR);
        }
 };
 
-
 MODULE_INIT(ModuleNoKicks)
index 672a48f8d9bca45091d980ebb5290efb4f2a64ca..8981097beacd3747033ac5c3026c2e15bbf98c19 100644 (file)
@@ -38,7 +38,7 @@ class ModuleNoNickChange : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                ServerInstance->Modules->AddService(nn);
@@ -46,30 +46,21 @@ class ModuleNoNickChange : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleNoNickChange()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for channel mode +N & extban +b N: which prevents nick changes on channel", VF_VENDOR);
        }
 
-
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('N');
+               tokens["EXTBAN"].push_back('N');
        }
 
-       virtual ModResult OnUserPreNick(User* user, const std::string &newnick)
+       ModResult OnUserPreNick(User* user, const std::string &newnick) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return MOD_RES_PASSTHRU;
 
-               // Allow forced nick changes.
-               if (ServerInstance->NICKForced.get(user))
-                       return MOD_RES_PASSTHRU;
-
                for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
                {
                        Channel* curr = *i;
@@ -79,7 +70,7 @@ class ModuleNoNickChange : public Module
                        if (res == MOD_RES_ALLOW)
                                continue;
 
-                       if (override && IS_OPER(user))
+                       if (override && user->IsOper())
                                continue;
 
                        if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet('N')))
@@ -93,7 +84,7 @@ class ModuleNoNickChange : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                override = ServerInstance->Config->ConfValue("nonicks")->getBool("operoverride", false);
        }
index c5b9f3a1c784f6dd894a4ec6b6d5237705826f73..2063628451fb227def141a51e988cc09bf860caa 100644 (file)
@@ -39,22 +39,22 @@ class ModuleNoNotice : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(nt);
-               Implementation eventlist[] = { I_OnUserPreNotice, I_On005Numeric };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('T');
+               tokens["EXTBAN"].push_back('T');
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                ModResult res;
-               if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
+               if ((msgtype == MSG_NOTICE) && (target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
                {
                        Channel* c = (Channel*)dest;
                        if (!c->GetExtBanStatus(user, 'T').check(!c->IsModeSet('T')))
@@ -72,11 +72,7 @@ class ModuleNoNotice : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleNoNotice()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +T to block notices to the channel", VF_VENDOR);
        }
index ad3413101441a8f04a59a722bbd5853d0fb5813e..7f45255fdf65aeae98ce9100bd5188654c74b510 100644 (file)
 
 class ModulePartMsgBan : public Module
 {
- private:
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnUserPart, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModulePartMsgBan()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements extban +b p: - part message bans", VF_OPTCOMMON|VF_VENDOR);
        }
 
-
-       virtual void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
+       void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(memb->user))
                        return;
 
                if (memb->chan->GetExtBanStatus(memb->user, 'p') == MOD_RES_DENY)
                        partmessage.clear();
-
-               return;
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('p');
+               tokens["EXTBAN"].push_back('p');
        }
 };
 
-
 MODULE_INIT(ModulePartMsgBan)
-
index 8f8d3ca90142eefcae1c1634f93df667e01fc850..ff92f3fae8b2187cd34b9124a21e1650062c8209 100644 (file)
@@ -45,28 +45,30 @@ bool op;
 
 /** Handle /OJOIN
  */
-class CommandOjoin : public Command
+class CommandOjoin : public SplitCommand
 {
  public:
        bool active;
-       CommandOjoin(Module* parent) : Command(parent,"OJOIN", 1)
+       CommandOjoin(Module* parent) :
+               SplitCommand(parent, "OJOIN", 1)
        {
                flags_needed = 'o'; Penalty = 0; syntax = "<channel>";
                active = false;
                TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
+       CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
        {
                // Make sure the channel name is allowable.
-               if (!ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
+               if (!ServerInstance->IsChannel(parameters[0]))
                {
-                       user->WriteServ("NOTICE "+user->nick+" :*** Invalid characters in channel name or name too long");
+                       user->WriteNotice("*** Invalid characters in channel name or name too long");
                        return CMD_FAILURE;
                }
 
                active = true;
-               Channel* channel = Channel::JoinUser(user, parameters[0].c_str(), false, "", false);
+               // override is false because we want OnUserPreJoin to run
+               Channel* channel = Channel::JoinUser(user, parameters[0], false);
                active = false;
 
                if (channel)
@@ -110,45 +112,11 @@ class NetworkPrefix : public ModeHandler
                m_paramtype = TR_NICK;
        }
 
-       void RemoveMode(Channel* channel, irc::modestacker* stack)
-       {
-               const UserMembList* cl = channel->GetUsers();
-               std::vector<std::string> mode_junk;
-               mode_junk.push_back(channel->name);
-               irc::modestacker modestack(false);
-               std::deque<std::string> stackresult;
-
-               for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
-               {
-                       if (i->second->hasMode('Y'))
-                       {
-                               if (stack)
-                                       stack->Push(this->GetModeChar(), i->first->nick);
-                               else
-                                       modestack.Push(this->GetModeChar(), i->first->nick);
-                       }
-               }
-
-               if (stack)
-                       return;
-
-               while (modestack.GetStackedLine(stackresult))
-               {
-                       mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
-                       ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
-                       mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
-               }
-       }
-
        unsigned int GetPrefixRank()
        {
                return NETWORK_VALUE;
        }
 
-       void RemoveMode(User* user, irc::modestacker* stack)
-       {
-       }
-
        ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding)
        {
                User* theuser = ServerInstance->FindNick(parameter);
@@ -178,7 +146,7 @@ class ModuleOjoin : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                /* Load config stuff */
                OnRehash(NULL);
@@ -193,7 +161,7 @@ class ModuleOjoin : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                if (mycommand.active)
                {
@@ -206,7 +174,7 @@ class ModuleOjoin : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
 
@@ -224,7 +192,7 @@ class ModuleOjoin : public Module
                op = Conf->getBool("op", true);
        }
 
-       ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
+       ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
        {
                // Don't do anything if they're not +Y
                if (!memb->hasMode('Y'))
@@ -248,11 +216,10 @@ class ModuleOjoin : public Module
                ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Network Business Join", VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleOjoin)
-
index ca948d95b3c195e955ffa24bfd84d7a5aad7bc74..b3fc91e906906131e7c67a451fd3491401ba699e 100644 (file)
@@ -42,16 +42,16 @@ class ModuleOperChans : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(oc);
                Implementation eventlist[] = { I_OnCheckBan, I_On005Numeric, I_OnUserPreJoin };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
-               if (chan && chan->IsModeSet('O') && !IS_OPER(user))
+               if (chan && chan->IsModeSet('O') && !user->IsOper())
                {
                        user->WriteNumeric(ERR_CANTJOINOPERSONLY, "%s %s :Only IRC operators may join %s (+O is set)",
                                user->nick.c_str(), chan->name.c_str(), chan->name.c_str());
@@ -60,26 +60,22 @@ class ModuleOperChans : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
+       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
        {
                if ((mask.length() > 2) && (mask[0] == 'O') && (mask[1] == ':'))
                {
-                       if (IS_OPER(user) && InspIRCd::Match(user->oper->name, mask.substr(2)))
+                       if (user->IsOper() && InspIRCd::Match(user->oper->name, mask.substr(2)))
                                return MOD_RES_DENY;
                }
                return MOD_RES_PASSTHRU;
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('O');
+               tokens["EXTBAN"].push_back('O');
        }
 
-       ~ModuleOperChans()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for oper-only chans via the +O channel mode and 'O' extban", VF_VENDOR);
        }
index bd77384a604eb105d1d17fef1378f2a37c7fc2cc..e890c3afb709ad36d627165a6d35c8ee0aa19e09 100644 (file)
@@ -28,7 +28,6 @@
 
 class ModuleOperjoin : public Module
 {
-       private:
                std::string operChan;
                std::vector<std::string> operChans;
                bool override;
@@ -53,7 +52,7 @@ class ModuleOperjoin : public Module
                }
 
        public:
-               void init()
+               void init() CXX11_OVERRIDE
                {
                        OnRehash(NULL);
                        Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
@@ -61,7 +60,7 @@ class ModuleOperjoin : public Module
                }
 
 
-               virtual void OnRehash(User* user)
+               void OnRehash(User* user) CXX11_OVERRIDE
                {
                        ConfigTag* tag = ServerInstance->Config->ConfValue("operjoin");
 
@@ -72,34 +71,31 @@ class ModuleOperjoin : public Module
                                tokenize(operChan,operChans);
                }
 
-               virtual ~ModuleOperjoin()
-               {
-               }
-
-               virtual Version GetVersion()
+               Version GetVersion() CXX11_OVERRIDE
                {
                        return Version("Forces opers to join the specified channel(s) on oper-up", VF_VENDOR);
                }
 
-               virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
+               void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
                {
-                       if (!IS_LOCAL(user))
+                       LocalUser* localuser = IS_LOCAL(user);
+                       if (!localuser)
                                return;
 
-                       for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
-                               if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
-                                       Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
+                       for (std::vector<std::string>::const_iterator i = operChans.begin(); i != operChans.end(); ++i)
+                               if (ServerInstance->IsChannel(*i))
+                                       Channel::JoinUser(localuser, *i, override);
 
-                       std::string chanList = IS_OPER(user)->getConfig("autojoin");
+                       std::string chanList = localuser->oper->getConfig("autojoin");
                        if (!chanList.empty())
                        {
                                std::vector<std::string> typechans;
                                tokenize(chanList, typechans);
                                for (std::vector<std::string>::const_iterator it = typechans.begin(); it != typechans.end(); ++it)
                                {
-                                       if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
+                                       if (ServerInstance->IsChannel(*it))
                                        {
-                                               Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
+                                               Channel::JoinUser(localuser, *it, override);
                                        }
                                }
                        }
index 569defd498af9377a9dd5949bddf0b33a1dad357..5cecb15d58220e13ce7e391794e5af065d85502b 100644 (file)
 class ModuleOperLevels : public Module
 {
        public:
-               void init()
+               void init() CXX11_OVERRIDE
                {
                        ServerInstance->Modules->Attach(I_OnKill, this);
                }
 
-               virtual Version GetVersion()
+               Version GetVersion() CXX11_OVERRIDE
                {
                        return Version("Gives each oper type a 'level', cannot kill opers 'above' your level.", VF_VENDOR);
                }
 
-               virtual ModResult OnKill(User* source, User* dest, const std::string &reason)
+               ModResult OnKill(User* source, User* dest, const std::string &reason) CXX11_OVERRIDE
                {
                        // oper killing an oper?
-                       if (IS_OPER(dest) && IS_OPER(source))
+                       if (dest->IsOper() && source->IsOper())
                        {
                                std::string level = dest->oper->getConfig("level");
                                long dest_level = atol(level.c_str());
@@ -50,7 +50,7 @@ class ModuleOperLevels : public Module
                                if (dest_level > source_level)
                                {
                                        if (IS_LOCAL(source)) ServerInstance->SNO->WriteGlobalSno('a', "Oper %s (level %ld) attempted to /kill a higher oper: %s (level %ld): Reason: %s",source->nick.c_str(),source_level,dest->nick.c_str(),dest_level,reason.c_str());
-                                       dest->WriteServ("NOTICE %s :*** Oper %s attempted to /kill you!",dest->nick.c_str(),source->nick.c_str());
+                                       dest->WriteNotice("*** Oper " + source->nick + " attempted to /kill you!");
                                        source->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper %s is a higher level than you",source->nick.c_str(),dest->nick.c_str());
                                        return MOD_RES_DENY;
                                }
@@ -60,4 +60,3 @@ class ModuleOperLevels : public Module
 };
 
 MODULE_INIT(ModuleOperLevels)
-
index edb9109e89f246d0cde5089655c1ae7279d0c7c6..759a9e3b86ea85c2b5f5838daddf2f72485440c8 100644 (file)
@@ -28,7 +28,7 @@ class ModuleOperLog : public Module
        bool tosnomask;
 
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnPreCommand, I_On005Numeric, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
@@ -36,27 +36,23 @@ class ModuleOperLog : public Module
                OnRehash(NULL);
        }
 
-       virtual ~ModuleOperLog()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("A module which logs all oper commands to the ircd log at default loglevel.", VF_VENDOR);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                tosnomask = ServerInstance->Config->ConfValue("operlog")->getBool("tosnomask", false);
        }
 
-       virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                /* If the command doesnt appear to be valid, we dont want to mess with it. */
                if (!validated)
                        return MOD_RES_PASSTHRU;
 
-               if ((IS_OPER(user)) && (IS_LOCAL(user)) && (user->HasPermission(command)))
+               if ((user->IsOper()) && (IS_LOCAL(user)) && (user->HasPermission(command)))
                {
                        Command* thiscommand = ServerInstance->Parser->GetHandler(command);
                        if ((thiscommand) && (thiscommand->flags_needed == 'o'))
@@ -65,7 +61,7 @@ class ModuleOperLog : public Module
                                if (!parameters.empty())
                                        line = irc::stringjoiner(" ", parameters, 0, parameters.size() - 1).GetJoined();
                                std::string msg = "[" + user->GetFullRealHost() + "] " + command + " " + line;
-                               ServerInstance->Logs->Log("m_operlog", DEFAULT, "OPERLOG: " + msg);
+                               ServerInstance->Logs->Log("m_operlog", LOG_DEFAULT, "OPERLOG: " + msg);
                                if (tosnomask)
                                        ServerInstance->SNO->WriteGlobalSno('r', msg);
                        }
@@ -74,12 +70,11 @@ class ModuleOperLog : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" OPERLOG");
+               tokens["OPERLOG"];
        }
 
 };
 
-
 MODULE_INIT(ModuleOperLog)
index 8b49f685e73b5eef372a5f11ce031a240a57f24a..5752ff48d07f9a360de9267627842e1d4916cc7e 100644 (file)
 class ModuleModesOnOper : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->Attach(I_OnPostOper, this);
        }
 
-       virtual ~ModuleModesOnOper()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Sets (and unsets) modes on opers when they oper up", VF_VENDOR);
        }
 
-       virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
+       void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return;
index 989f97689d20c45f45aa41e8340520e52d5b2043..aa5767b4c71f789b0c755fca8f51fba51b4b73db 100644 (file)
@@ -82,7 +82,7 @@ class ModuleOpermotd : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                OnRehash(NULL);
@@ -90,26 +90,32 @@ class ModuleOpermotd : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Shows a message to opers after oper-up, adds /opermotd", VF_VENDOR | VF_OPTCOMMON);
        }
 
-       virtual void OnOper(User* user, const std::string &opertype)
+       void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE
        {
                if (onoper && IS_LOCAL(user))
                        cmd.ShowOperMOTD(user);
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                cmd.opermotd.clear();
                ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
                onoper = conf->getBool("onoper", true);
 
-               FileReader f(conf->getString("file", "opermotd"));
-               for (int i=0, filesize = f.FileSize(); i < filesize; i++)
-                       cmd.opermotd.push_back(f.GetLine(i));
+               try
+               {
+                       FileReader reader(conf->getString("file", "opermotd"));
+                       cmd.opermotd = reader.GetVector();
+               }
+               catch (CoreException&)
+               {
+                       // Nothing happens here as we do the error handling in ShowOperMOTD.
+               }
 
                if (conf->getBool("processcolors"))
                        InspIRCd::ProcessColors(cmd.opermotd);
index 25937cd6ea27cbc91b8c0dff4ac6e26bf7df9867..d061a5eab677f9c2384b0c5b8c6c46cc52b1cc8c 100644 (file)
@@ -64,28 +64,28 @@ class ModuleOperPrefixMode;
 class HideOperWatcher : public ModeWatcher
 {
        ModuleOperPrefixMode* parentmod;
+
  public:
-       HideOperWatcher(ModuleOperPrefixMode* parent) : ModeWatcher((Module*) parent, 'H', MODETYPE_USER), parentmod(parent) {}
-       void AfterMode(User* source, User* dest, Channel* channel, const std::string &parameter, bool adding, ModeType type);
+       HideOperWatcher(ModuleOperPrefixMode* parent);
+       void AfterMode(User* source, User* dest, Channel* channel, const std::string &parameter, bool adding);
 };
 
 class ModuleOperPrefixMode : public Module
 {
- private:
        OperPrefixMode opm;
-       bool mw_added;
        HideOperWatcher hideoperwatcher;
+
  public:
        ModuleOperPrefixMode()
-               : opm(this), mw_added(false), hideoperwatcher(this)
+               : opm(this), hideoperwatcher(this)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(opm);
 
-               Implementation eventlist[] = { I_OnUserPreJoin, I_OnPostOper, I_OnLoadModule, I_OnUnloadModule };
+               Implementation eventlist[] = { I_OnUserPreJoin, I_OnPostOper };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
 
                /* To give clients a chance to learn about the new prefix we don't give +y to opers
@@ -93,19 +93,12 @@ class ModuleOperPrefixMode : public Module
                 * they need to rejoin them in order to get the oper prefix.
                 */
 
-               if (ServerInstance->Modules->Find("m_hideoper.so"))
-                       mw_added = ServerInstance->Modes->AddModeWatcher(&hideoperwatcher);
+               ServerInstance->Modes->AddModeWatcher(&hideoperwatcher);
        }
 
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string& privs, const std::string& keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
-               /* The user may have the +H umode on himself, but +H does not necessarily correspond
-                * to the +H of m_hideoper.
-                * However we only add the modewatcher when m_hideoper is loaded, so these
-                * conditions (mw_added and the user being +H) together mean the user is a hidden oper.
-                */
-
-               if (IS_OPER(user) && (!mw_added || !user->IsModeSet('H')))
+               if ((user->IsOper()) && (user->IsModeSet('H')))
                        privs.push_back('y');
                return MOD_RES_PASSTHRU;
        }
@@ -123,31 +116,19 @@ class ModuleOperPrefixMode : public Module
                }
        }
 
-       void OnPostOper(User* user, const std::string& opername, const std::string& opertype)
+       void OnPostOper(User* user, const std::string& opername, const std::string& opertype) CXX11_OVERRIDE
        {
-               if (IS_LOCAL(user) && (!mw_added || !user->IsModeSet('H')))
+               if (IS_LOCAL(user) && (!user->IsModeSet('H')))
                        SetOperPrefix(user, true);
        }
 
-       void OnLoadModule(Module* mod)
-       {
-               if ((!mw_added) && (mod->ModuleSourceFile == "m_hideoper.so"))
-                       mw_added = ServerInstance->Modes->AddModeWatcher(&hideoperwatcher);
-       }
-
-       void OnUnloadModule(Module* mod)
-       {
-               if ((mw_added) && (mod->ModuleSourceFile == "m_hideoper.so") && (ServerInstance->Modes->DelModeWatcher(&hideoperwatcher)))
-                       mw_added = false;
-       }
 
        ~ModuleOperPrefixMode()
        {
-               if (mw_added)
-                       ServerInstance->Modes->DelModeWatcher(&hideoperwatcher);
+               ServerInstance->Modes->DelModeWatcher(&hideoperwatcher);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Gives opers cmode +y which provides a staff prefix.", VF_VENDOR);
        }
@@ -160,7 +141,13 @@ class ModuleOperPrefixMode : public Module
        }
 };
 
-void HideOperWatcher::AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding, ModeType type)
+HideOperWatcher::HideOperWatcher(ModuleOperPrefixMode* parent)
+       : ModeWatcher(parent, "hideoper", MODETYPE_USER)
+       , parentmod(parent)
+{
+}
+
+void HideOperWatcher::AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding)
 {
        if (IS_LOCAL(dest))
                parentmod->SetOperPrefix(dest, !adding);
index 1d9447fc46a1679c4a4d34a4da062007bd9e3a0c..a653dd33eef84416bc000a58f4fb08d71392b17e 100644 (file)
@@ -35,7 +35,7 @@ class ModuleOverride : public Module
 
  public:
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                // read our config options (main config file)
                OnRehash(NULL);
@@ -44,7 +44,7 @@ class ModuleOverride : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                // re-read our config options on a rehash
                ConfigTag* tag = ServerInstance->Config->ConfValue("override");
@@ -52,9 +52,9 @@ class ModuleOverride : public Module
                RequireKey = tag->getBool("requirekey");
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" OVERRIDE");
+               tokens["OVERRIDE"];
        }
 
        bool CanOverride(User* source, const char* token)
@@ -66,9 +66,9 @@ class ModuleOverride : public Module
        }
 
 
-       ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
+       ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic) CXX11_OVERRIDE
        {
-               if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
+               if (IS_LOCAL(source) && source->IsOper() && CanOverride(source, "TOPIC"))
                {
                        if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
                        {
@@ -82,9 +82,9 @@ class ModuleOverride : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
+       ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
        {
-               if (IS_OPER(source) && CanOverride(source,"KICK"))
+               if (source->IsOper() && CanOverride(source,"KICK"))
                {
                        // If the kicker's status is less than the target's,                    or      the kicker's status is less than or equal to voice
                        if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
@@ -96,11 +96,11 @@ class ModuleOverride : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
+       ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
        {
                if (!source || !channel)
                        return MOD_RES_PASSTHRU;
-               if (!IS_OPER(source) || !IS_LOCAL(source))
+               if (!source->IsOper() || !IS_LOCAL(source))
                        return MOD_RES_PASSTHRU;
 
                unsigned int mode = channel->GetPrefixValue(source);
@@ -116,27 +116,26 @@ class ModuleOverride : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
-               if (IS_LOCAL(user) && IS_OPER(user))
+               if (user->IsOper())
                {
                        if (chan)
                        {
                                if (chan->IsModeSet('i') && (CanOverride(user,"INVITE")))
                                {
-                                       irc::string x(chan->name.c_str());
-                                       if (!IS_LOCAL(user)->IsInvited(x))
+                                       if (!IS_LOCAL(user)->IsInvited(chan))
                                        {
                                                if (RequireKey && keygiven != "override")
                                                {
                                                        // Can't join normally -- must use a special key to bypass restrictions
-                                                       user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
+                                                       user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
                                                        return MOD_RES_PASSTHRU;
                                                }
 
                                                if (NoisyOverride)
-                                                       chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
-                                               ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +i on "+std::string(cname));
+                                                       chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname.c_str(), user->nick.c_str());
+                                               ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +i on " + cname);
                                        }
                                        return MOD_RES_ALLOW;
                                }
@@ -146,13 +145,13 @@ class ModuleOverride : public Module
                                        if (RequireKey && keygiven != "override")
                                        {
                                                // Can't join normally -- must use a special key to bypass restrictions
-                                               user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
+                                               user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
                                                return MOD_RES_PASSTHRU;
                                        }
 
                                        if (NoisyOverride)
-                                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
-                                       ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +k on "+std::string(cname));
+                                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname.c_str(), user->nick.c_str());
+                                       ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +k on " + cname);
                                        return MOD_RES_ALLOW;
                                }
 
@@ -161,13 +160,13 @@ class ModuleOverride : public Module
                                        if (RequireKey && keygiven != "override")
                                        {
                                                // Can't join normally -- must use a special key to bypass restrictions
-                                               user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
+                                               user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
                                                return MOD_RES_PASSTHRU;
                                        }
 
                                        if (NoisyOverride)
-                                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
-                                       ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +l on "+std::string(cname));
+                                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname.c_str(), user->nick.c_str());
+                                       ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +l on " + cname);
                                        return MOD_RES_ALLOW;
                                }
 
@@ -176,13 +175,13 @@ class ModuleOverride : public Module
                                        if (RequireKey && keygiven != "override")
                                        {
                                                // Can't join normally -- must use a special key to bypass restrictions
-                                               user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
+                                               user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
                                                return MOD_RES_PASSTHRU;
                                        }
 
                                        if (NoisyOverride)
-                                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
-                                       ServerInstance->SNO->WriteGlobalSno('v',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
+                                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname.c_str(), user->nick.c_str());
+                                       ServerInstance->SNO->WriteGlobalSno('v',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname.c_str());
                                        return MOD_RES_ALLOW;
                                }
                        }
@@ -190,7 +189,7 @@ class ModuleOverride : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for allowing opers to override certain things",VF_VENDOR);
        }
index c04b306b1b8482ed0155cd801d8b85a11e932f59..64c7df51942333a05fa06177ebe8abd377087ff8 100644 (file)
 
 class ModulePassForward : public Module
 {
- private:
        std::string nickrequired, forwardmsg, forwardcmd;
 
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                Implementation eventlist[] = { I_OnPostConnect, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Sends server password to NickServ", VF_VENDOR);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("passforward");
                nickrequired = tag->getString("nick", "NickServ");
@@ -82,7 +81,7 @@ class ModulePassForward : public Module
                }
        }
 
-       virtual void OnPostConnect(User* ruser)
+       void OnPostConnect(User* ruser) CXX11_OVERRIDE
        {
                LocalUser* user = IS_LOCAL(ruser);
                if (!user || user->password.empty())
index 98462780b09a7fda288759b029d0a9bd327ca845..6c4145c4edd3bcd02c4255fe5fb4c25cb2a6bfd7 100644 (file)
@@ -21,7 +21,7 @@
 /* $ModDesc: Allows for hashed oper passwords */
 
 #include "inspircd.h"
-#include "hash.h"
+#include "modules/hash.h"
 
 /* Handle /MKPASSWD
  */
@@ -42,15 +42,14 @@ class CommandMkpasswd : public Command
                        HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + type);
                        if (!hp)
                        {
-                               user->WriteServ("NOTICE %s :Unknown hash type", user->nick.c_str());
+                               user->WriteNotice("Unknown hash type");
                                return;
                        }
                        std::string salt = ServerInstance->GenRandomStr(6, false);
                        std::string target = hp->hmac(salt, stuff);
                        std::string str = BinToBase64(salt) + "$" + BinToBase64(target, NULL, 0);
 
-                       user->WriteServ("NOTICE %s :%s hashed password for %s is %s",
-                               user->nick.c_str(), algo.c_str(), stuff.c_str(), str.c_str());
+                       user->WriteNotice(algo + " hashed password for " + stuff + " is " + str);
                        return;
                }
                HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + algo);
@@ -58,12 +57,11 @@ class CommandMkpasswd : public Command
                {
                        /* Now attempt to generate a hash */
                        std::string hexsum = hp->hexsum(stuff);
-                       user->WriteServ("NOTICE %s :%s hashed password for %s is %s",
-                               user->nick.c_str(), algo.c_str(), stuff.c_str(), hexsum.c_str());
+                       user->WriteNotice(algo + " hashed password for " + stuff + " is " + hexsum);
                }
                else
                {
-                       user->WriteServ("NOTICE %s :Unknown hash type", user->nick.c_str());
+                       user->WriteNotice("Unknown hash type");
                }
        }
 
@@ -84,7 +82,7 @@ class ModuleOperHash : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                /* Read the config file first */
                OnRehash(NULL);
@@ -94,7 +92,7 @@ class ModuleOperHash : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ModResult OnPassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype)
+       ModResult OnPassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype) CXX11_OVERRIDE
        {
                if (hashtype.substr(0,5) == "hmac-")
                {
@@ -132,7 +130,7 @@ class ModuleOperHash : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows for hashed oper passwords",VF_VENDOR);
        }
index a59518b28d7acb750b47a4bf1c6ef493b087da97..41477ba35000246c0949f4a4467a483f5c90bd4d 100644 (file)
@@ -44,7 +44,7 @@ static bool WriteDatabase()
        f = fopen(tempname.c_str(), "w");
        if (!f)
        {
-               ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot create database! %s (%d)", strerror(errno), errno);
+               ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot create database! %s (%d)", strerror(errno), errno);
                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot create new db: %s (%d)", strerror(errno), errno);
                return false;
        }
@@ -95,7 +95,7 @@ static bool WriteDatabase()
        write_error |= fclose(f);
        if (write_error)
        {
-               ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno);
+               ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno);
                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
                return false;
        }
@@ -103,7 +103,7 @@ static bool WriteDatabase()
 #ifdef _WIN32
        if (remove(permchannelsconf.c_str()))
        {
-               ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot remove old database! %s (%d)", strerror(errno), errno);
+               ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot remove old database! %s (%d)", strerror(errno), errno);
                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot remove old database: %s (%d)", strerror(errno), errno);
                return false;
        }
@@ -111,7 +111,7 @@ static bool WriteDatabase()
        // Use rename to move temporary to new db - this is guarenteed not to fuck up, even in case of a crash.
        if (rename(tempname.c_str(), permchannelsconf.c_str()) < 0)
        {
-               ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno);
+               ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno);
                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
                return false;
        }
@@ -143,10 +143,7 @@ class PermChannel : public ModeHandler
                        if (channel->IsModeSet('P'))
                        {
                                channel->SetMode(this,false);
-                               if (channel->GetUserCounter() == 0)
-                               {
-                                       channel->DelUser(ServerInstance->FakeClient);
-                               }
+                               channel->CheckDestroy();
                                return MODEACTION_ALLOW;
                        }
                }
@@ -165,7 +162,7 @@ public:
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(p);
                Implementation eventlist[] = { I_OnChannelPreDelete, I_OnPostTopicChange, I_OnRawMode, I_OnRehash, I_OnBackgroundTimer };
@@ -200,7 +197,7 @@ public:
                return Module::cull();
        }
 
-       virtual void OnRehash(User *user)
+       void OnRehash(User *user) CXX11_OVERRIDE
        {
                permchannelsconf = ServerInstance->Config->ConfValue("permchanneldb")->getString("filename");
        }
@@ -221,7 +218,7 @@ public:
 
                        if (channel.empty())
                        {
-                               ServerInstance->Logs->Log("m_permchannels", DEBUG, "Malformed permchannels tag with empty channel name.");
+                               ServerInstance->Logs->Log("m_permchannels", LOG_DEBUG, "Malformed permchannels tag with empty channel name.");
                                continue;
                        }
 
@@ -232,7 +229,7 @@ public:
                                c = new Channel(channel, ServerInstance->Time());
                                if (!topic.empty())
                                {
-                                       c->SetTopic(NULL, topic, true);
+                                       c->SetTopic(ServerInstance->FakeClient, topic, true);
 
                                        /*
                                         * Due to the way protocol works in 1.2, we need to hack the topic TS in such a way that this
@@ -242,7 +239,7 @@ public:
                                         */
                                        c->topicset = 42;
                                }
-                               ServerInstance->Logs->Log("m_permchannels", DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str());
+                               ServerInstance->Logs->Log("m_permchannels", LOG_DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str());
 
                                if (modes.empty())
                                        continue;
@@ -271,7 +268,7 @@ public:
                }
        }
 
-       virtual ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt)
+       ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt) CXX11_OVERRIDE
        {
                if (chan && (chan->IsModeSet('P') || mode == 'P'))
                        dirty = true;
@@ -279,13 +276,13 @@ public:
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnPostTopicChange(User*, Channel *c, const std::string&)
+       void OnPostTopicChange(User*, Channel *c, const std::string&) CXX11_OVERRIDE
        {
                if (c->IsModeSet('P'))
                        dirty = true;
        }
 
-       void OnBackgroundTimer(time_t)
+       void OnBackgroundTimer(time_t) CXX11_OVERRIDE
        {
                if (dirty)
                        WriteDatabase();
@@ -319,17 +316,17 @@ public:
                        }
                        catch (CoreException& e)
                        {
-                               ServerInstance->Logs->Log("m_permchannels", DEFAULT, "Error loading permchannels database: " + std::string(e.GetReason()));
+                               ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "Error loading permchannels database: " + std::string(e.GetReason()));
                        }
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for channel mode +P to provide permanent channels",VF_VENDOR);
        }
 
-       virtual ModResult OnChannelPreDelete(Channel *c)
+       ModResult OnChannelPreDelete(Channel *c) CXX11_OVERRIDE
        {
                if (c->IsModeSet('P'))
                        return MOD_RES_DENY;
index 668eea0e5cc0e8a2d1ae8fa83b247b3150c23b9a..8b9ffd6e9a966ac08970dff0848b5b7f831c6129 100644 (file)
 
 #include "inspircd.h"
 
-static FileReader *quotes = NULL;
-
-std::string prefix;
-std::string suffix;
-
-/** Handle /RANDQUOTE
- */
-class CommandRandquote : public Command
-{
- public:
-       CommandRandquote(Module* Creator) : Command(Creator,"RANDQUOTE", 0)
-       {
-       }
-
-       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
-       {
-               int fsize = quotes->FileSize();
-               if (fsize)
-               {
-                       std::string str = quotes->GetLine(ServerInstance->GenRandomInt(fsize));
-                       if (!str.empty())
-                               user->WriteServ("NOTICE %s :%s%s%s",user->nick.c_str(),prefix.c_str(),str.c_str(),suffix.c_str());
-               }
-
-               return CMD_SUCCESS;
-       }
-};
-
 class ModuleRandQuote : public Module
 {
  private:
-       CommandRandquote cmd;
- public:
-       ModuleRandQuote()
-               : cmd(this)
-       {
-       }
+       std::string prefix;
+       std::string suffix;
+       std::vector<std::string> quotes;
 
-       void init()
+ public:
+       void init() CXX11_OVERRIDE
        {
                ConfigTag* conf = ServerInstance->Config->ConfValue("randquote");
-
-               std::string q_file = conf->getString("file","quotes");
                prefix = conf->getString("prefix");
                suffix = conf->getString("suffix");
+               FileReader reader(conf->getString("file", "quotes"));
+               quotes = reader.GetVector();
 
-               quotes = new FileReader(q_file);
-               if (!quotes->Exists())
-               {
-                       throw ModuleException("m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
-               }
-               ServerInstance->Modules->AddService(cmd);
                Implementation eventlist[] = { I_OnUserConnect };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-
-       virtual ~ModuleRandQuote()
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
        {
-               delete quotes;
-       }
-
-       virtual Version GetVersion()
-       {
-               return Version("Provides random quotes on connect.",VF_VENDOR);
+               if (!quotes.empty())
+               {
+                       unsigned long random = ServerInstance->GenRandomInt(quotes.size());
+                       user->WriteNotice(prefix + quotes[random] + suffix);
+               }
        }
 
-       virtual void OnUserConnect(LocalUser* user)
+       Version GetVersion() CXX11_OVERRIDE
        {
-               cmd.Handle(std::vector<std::string>(), user);
+               return Version("Provides random quotes on connect.", VF_VENDOR);
        }
 };
 
index 26d6b162b9ec7009daae11c3f8645eeb4df5c6b7..000d53a2e21055d5aa57a57dbc5bb91ebf9e242e 100644 (file)
@@ -39,7 +39,7 @@ class Redirect : public ModeHandler
                {
                        if (IS_LOCAL(source))
                        {
-                               if (!ServerInstance->IsChannel(parameter.c_str(), ServerInstance->Config->Limits.ChanMax))
+                               if (!ServerInstance->IsChannel(parameter))
                                {
                                        source->WriteNumeric(403, "%s %s :Invalid channel name", source->nick.c_str(), parameter.c_str());
                                        parameter.clear();
@@ -47,7 +47,7 @@ class Redirect : public ModeHandler
                                }
                        }
 
-                       if (IS_LOCAL(source) && !IS_OPER(source))
+                       if (IS_LOCAL(source) && !source->IsOper())
                        {
                                Channel* c = ServerInstance->FindChan(parameter);
                                if (!c)
@@ -109,7 +109,7 @@ class ModuleRedirect : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                /* Setting this here so it isn't changable by rehasing the config later. */
                UseUsermode = ServerInstance->Config->ConfValue("redirect")->getBool("antiredirect");
@@ -121,7 +121,7 @@ class ModuleRedirect : public Module
                if (UseUsermode)
                {
                        /* Log noting that this breaks compatability. */
-                       ServerInstance->Logs->Log("m_redirect", DEFAULT, "REDIRECT: Enabled usermode +L. This breaks linking with servers that do not have this enabled. This is disabled by default in the 2.0 branch but will be enabled in the next version.");
+                       ServerInstance->Logs->Log("m_redirect", LOG_DEFAULT, "REDIRECT: Enabled usermode +L. This breaks linking with servers that do not have this enabled. This is disabled by default in the 2.0 branch but will be enabled in the next version.");
 
                        /* Try to add the usermode */
                        ServerInstance->Modules->AddService(re_u);
@@ -131,7 +131,7 @@ class ModuleRedirect : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                if (chan)
                {
@@ -142,25 +142,23 @@ class ModuleRedirect : public Module
                                        std::string channel = chan->GetModeParameter('L');
 
                                        /* sometimes broken ulines can make circular or chained +L, avoid this */
-                                       Channel* destchan = NULL;
-                                       destchan = ServerInstance->FindChan(channel);
+                                       Channel* destchan = ServerInstance->FindChan(channel);
                                        if (destchan && destchan->IsModeSet('L'))
                                        {
-                                               user->WriteNumeric(470, "%s %s * :You may not join this channel. A redirect is set, but you may not be redirected as it is a circular loop.", user->nick.c_str(), cname);
+                                               user->WriteNumeric(470, "%s %s * :You may not join this channel. A redirect is set, but you may not be redirected as it is a circular loop.", user->nick.c_str(), cname.c_str());
                                                return MOD_RES_DENY;
                                        }
                                        /* We check the bool value here to make sure we have it enabled, if we don't then
                                                usermode +L might be assigned to something else. */
                                        if (UseUsermode && user->IsModeSet('L'))
                                        {
-                                               user->WriteNumeric(470, "%s %s %s :Force redirection stopped.",
-                                               user->nick.c_str(), cname, channel.c_str());
+                                               user->WriteNumeric(470, "%s %s %s :Force redirection stopped.", user->nick.c_str(), cname.c_str(), channel.c_str());
                                                return MOD_RES_DENY;
                                        }
                                        else
                                        {
-                                               user->WriteNumeric(470, "%s %s %s :You may not join this channel, so you are automatically being transferred to the redirect channel.", user->nick.c_str(), cname, channel.c_str());
-                                               Channel::JoinUser(user, channel.c_str(), false, "", false, ServerInstance->Time());
+                                               user->WriteNumeric(470, "%s %s %s :You may not join this channel, so you are automatically being transferred to the redirect channel.", user->nick.c_str(), cname.c_str(), channel.c_str());
+                                               Channel::JoinUser(user, channel);
                                                return MOD_RES_DENY;
                                        }
                                }
@@ -169,11 +167,7 @@ class ModuleRedirect : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleRedirect()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +L (limit redirection) and user mode +L (no forced redirection)", VF_VENDOR);
        }
diff --git a/src/modules/m_regex.h b/src/modules/m_regex.h
deleted file mode 100644 (file)
index 0233f93..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef M_REGEX_H
-#define M_REGEX_H
-
-#include "inspircd.h"
-
-class Regex : public classbase
-{
-protected:
-       std::string regex_string; // The raw uncompiled regex string.
-
-       // Constructor may as well be protected, as this class is abstract.
-       Regex(const std::string& rx) : regex_string(rx)
-       {
-       }
-
-public:
-
-       virtual ~Regex()
-       {
-       }
-
-       virtual bool Matches(const std::string& text) = 0;
-
-       const std::string& GetRegexString() const
-       {
-               return regex_string;
-       }
-};
-
-class RegexFactory : public DataProvider
-{
- public:
-       RegexFactory(Module* Creator, const std::string& Name) : DataProvider(Creator, Name) {}
-
-       virtual Regex* Create(const std::string& expr) = 0;
-};
-
-#endif
index 44d1a5898c7987091d72fd239b26248c1e02cf12..970b3a842e3ad226e9314cfa624a1f0dd2edb0cd 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 
-#include "m_regex.h"
+#include "modules/regex.h"
 #include "inspircd.h"
 
 /* $ModDesc: Regex module using plain wildcard matching. */
@@ -30,11 +30,7 @@ public:
        {
        }
 
-       virtual ~GlobRegex()
-       {
-       }
-
-       virtual bool Matches(const std::string& text)
+       bool Matches(const std::string& text)
        {
                return InspIRCd::Match(text, this->regex_string);
        }
@@ -59,7 +55,7 @@ public:
                ServerInstance->Modules->AddService(gf);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Regex module using plain wildcard matching.", VF_VENDOR);
        }
index 61f94c0bd1b81f26bc4cf9ea2bcdb10d8d84c0c2..96a2cbab756d32a4d19f117e6c10d051aa2d1893 100644 (file)
 
 
 #include "inspircd.h"
-#include "account.h"
+#include "modules/account.h"
 
 /* $ModDesc: Prevents users whose nicks are not registered from creating new channels */
 
 class ModuleRegOnlyCreate : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnUserPreJoin };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                if (chan)
                        return MOD_RES_PASSTHRU;
 
-               if (IS_OPER(user))
+               if (user->IsOper())
                        return MOD_RES_PASSTHRU;
 
                if (user->IsModeSet('r'))
@@ -50,15 +50,11 @@ class ModuleRegOnlyCreate : public Module
                        return MOD_RES_PASSTHRU;
 
                // XXX. there may be a better numeric for this..
-               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have a registered nickname to create a new channel", user->nick.c_str(), cname);
+               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have a registered nickname to create a new channel", user->nick.c_str(), cname.c_str());
                return MOD_RES_DENY;
        }
 
-       ~ModuleRegOnlyCreate()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Prevents users whose nicks are not registered from creating new channels", VF_VENDOR);
        }
index 86f50ad625d9ad351dda7687f9e982c6063aabab..d4b7ca42fcefa22579cd6536b93644f63bff603c 100644 (file)
@@ -36,7 +36,6 @@
  */
 class RemoveBase : public Command
 {
- private:
        bool& supportnokicks;
 
  public:
@@ -118,7 +117,7 @@ class RemoveBase : public Command
                                reason = "Removed by " + user->nick + ": " + reasonparam;
 
                                channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name.c_str(), user->nick.c_str(), target->nick.c_str());
-                               target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick.c_str(), user->nick.c_str(), channel->name.c_str(), reasonparam.c_str());
+                               target->WriteNotice("*** " + user->nick + " removed you from " + channel->name + " with the message: " + reasonparam);
 
                                channel->PartUser(target, reason);
                        }
@@ -137,7 +136,7 @@ class RemoveBase : public Command
 
                return CMD_SUCCESS;
        }
-       virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) = 0;
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) = 0;
 };
 
 /** Handle /REMOVE
@@ -198,13 +197,12 @@ class ModuleRemove : public Module
        CommandFpart cmd2;
        bool supportnokicks;
 
-
  public:
        ModuleRemove() : cmd1(this, supportnokicks), cmd2(this, supportnokicks)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd1);
                ServerInstance->Modules->AddService(cmd2);
@@ -213,25 +211,20 @@ class ModuleRemove : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" REMOVE");
+               tokens["REMOVE"];
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                supportnokicks = ServerInstance->Config->ConfValue("remove")->getBool("supportnokicks");
        }
 
-       virtual ~ModuleRemove()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel", VF_OPTCOMMON | VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleRemove)
index c76b0e79fc2317ed49bfc377dd1650c8379d502b..2415e02379c3b0965af45f3a7743644336ccc6ff 100644 (file)
@@ -41,43 +41,36 @@ class ModuleRestrictChans : public Module
        }
 
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ReadConfig();
                Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ReadConfig();
        }
 
-
-       virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
-               irc::string x = cname;
-               if (!IS_LOCAL(user))
-                       return MOD_RES_PASSTHRU;
+               irc::string x(cname.c_str());
 
                // channel does not yet exist (record is null, about to be created IF we were to allow it)
                if (!chan)
                {
                        // user is not an oper and its not in the allow list
-                       if ((!IS_OPER(user)) && (allowchans.find(x) == allowchans.end()))
+                       if ((!user->IsOper()) && (allowchans.find(x) == allowchans.end()))
                        {
-                               user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Only IRC operators may create new channels",user->nick.c_str(),cname);
+                               user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Only IRC operators may create new channels",user->nick.c_str(),cname.c_str());
                                return MOD_RES_DENY;
                        }
                }
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleRestrictChans()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Only opers may create new channels if this module is loaded",VF_VENDOR);
        }
index e814f3b161d2db6bd7570e546686f25ebb9de6d9..e4dbb1d434502a6785065aeccde4164556e3efad 100644 (file)
 
 /* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
 
-
 class ModuleRestrictMsg : public Module
 {
-
  public:
-
-       void init()
+       void init() CXX11_OVERRIDE
        {
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+               ServerInstance->Modules->Attach(I_OnUserPreMessage, this);
        }
 
-
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
                {
@@ -46,7 +41,7 @@ class ModuleRestrictMsg : public Module
                        // (1) the sender is opered
                        // (2) the recipient is opered
                        // anything else, blocked.
-                       if (IS_OPER(u) || IS_OPER(user))
+                       if (u->IsOper() || user->IsOper())
                        {
                                return MOD_RES_PASSTHRU;
                        }
@@ -58,16 +53,7 @@ class ModuleRestrictMsg : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return this->OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
-       }
-
-       virtual ~ModuleRestrictMsg()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Forbids users from messaging each other. Users may still message opers and opers may message other opers.",VF_VENDOR);
        }
index 6ceb4b481bb80790045316a610ad390947947570..8df079e8fe7a4a3bcbc0d5c5ea2eaae4c9f68112 100644 (file)
@@ -64,7 +64,7 @@
 #ifdef HAS_STDINT
 #include <stdint.h>
 #endif
-#include "hash.h"
+#include "modules/hash.h"
 
 #define RMDsize 160
 
@@ -164,7 +164,7 @@ class RIProv : public HashProvider
        {
                if (key)
                {
-                       ServerInstance->Logs->Log("m_ripemd160.so", DEBUG, "initialize with custom mdbuf");
+                       ServerInstance->Logs->Log("m_ripemd160.so", LOG_DEBUG, "initialize with custom mdbuf");
                        MDbuf[0] = key[0];
                        MDbuf[1] = key[1];
                        MDbuf[2] = key[2];
@@ -173,7 +173,7 @@ class RIProv : public HashProvider
                }
                else
                {
-                       ServerInstance->Logs->Log("m_ripemd160.so", DEBUG, "initialize with default mdbuf");
+                       ServerInstance->Logs->Log("m_ripemd160.so", LOG_DEBUG, "initialize with default mdbuf");
                        MDbuf[0] = 0x67452301UL;
                        MDbuf[1] = 0xefcdab89UL;
                        MDbuf[2] = 0x98badcfeUL;
@@ -414,7 +414,7 @@ class RIProv : public HashProvider
 
        byte *RMD(byte *message, dword length, unsigned int* key)
        {
-               ServerInstance->Logs->Log("m_ripemd160", DEBUG, "RMD: '%s' length=%u", (const char*)message, length);
+               ServerInstance->Logs->Log("m_ripemd160", LOG_DEBUG, "RMD: '%s' length=%u", (const char*)message, length);
                dword         MDbuf[RMDsize/32];   /* contains (A, B, C, D(E))   */
                static byte   hashcode[RMDsize/8]; /* for final hash-value         */
                dword         X[16];               /* current 16-word chunk        */
@@ -451,11 +451,6 @@ public:
                return std::string(rv, RMDsize / 8);
        }
 
-       std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata)
-       {
-               return "";
-       }
-
        RIProv(Module* m) : HashProvider(m, "hash/ripemd160", 20, 64) {}
 };
 
@@ -468,12 +463,10 @@ class ModuleRIPEMD160 : public Module
                ServerInstance->Modules->AddService(mr);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides RIPEMD-160 hashing", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleRIPEMD160)
-
index d1ab5d9ba42cc35645ca77b54170a315f4319046..ca123cc11578f400eae45dc721bd1d8b0c7cb417 100644 (file)
@@ -23,7 +23,7 @@
 /* $ModDesc: RLINE: Regexp user banning. */
 
 #include "inspircd.h"
-#include "m_regex.h"
+#include "modules/regex.h"
 #include "xline.h"
 
 static bool ZlineOnMatch = false;
@@ -60,7 +60,8 @@ class RLine : public XLine
 
        bool Matches(User *u)
        {
-               if (u->exempt)
+               LocalUser* lu = IS_LOCAL(u);
+               if (lu && lu->exempt)
                        return false;
 
                std::string compare = u->nick + "!" + u->ident + "@" + u->host + " " + u->fullname;
@@ -90,15 +91,9 @@ class RLine : public XLine
                DefaultApply(u, "R", false);
        }
 
-       void DisplayExpiry()
+       const std::string& Displayable()
        {
-               ServerInstance->SNO->WriteToSnoMask('x',"Removing expired R-line %s (set by %s %ld seconds ago)",
-                       this->matchtext.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
-       }
-
-       const char* Displayable()
-       {
-               return matchtext.c_str();
+               return matchtext;
        }
 
        std::string matchtext;
@@ -116,7 +111,7 @@ class RLineFactory : public XLineFactory
        RLineFactory(dynamic_reference<RegexFactory>& rx) : XLineFactory("R"), rxfactory(rx)
        {
        }
-       
+
        /** Generate a RLine
         */
        XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
@@ -129,10 +124,6 @@ class RLineFactory : public XLineFactory
 
                return new RLine(set_time, duration, source, reason, xline_specific_mask, rxfactory);
        }
-
-       ~RLineFactory()
-       {
-       }
 };
 
 /** Handle /RLINE
@@ -156,7 +147,7 @@ class CommandRLine : public Command
                {
                        // Adding - XXX todo make this respect <insane> tag perhaps..
 
-                       long duration = ServerInstance->Duration(parameters[1]);
+                       unsigned long duration = InspIRCd::Duration(parameters[1]);
                        XLine *r = NULL;
 
                        try
@@ -188,7 +179,7 @@ class CommandRLine : public Command
                                else
                                {
                                        delete r;
-                                       user->WriteServ("NOTICE %s :*** R-Line for %s already exists", user->nick.c_str(), parameters[0].c_str());
+                                       user->WriteNotice("*** R-Line for " + parameters[0] + " already exists");
                                }
                        }
                }
@@ -200,7 +191,7 @@ class CommandRLine : public Command
                        }
                        else
                        {
-                               user->WriteServ("NOTICE %s :*** R-Line %s not found in list, try /stats R.",user->nick.c_str(),parameters[0].c_str());
+                               user->WriteNotice("*** R-Line " + parameters[0] + " not found in list, try /stats R.");
                        }
                }
 
@@ -218,7 +209,6 @@ class CommandRLine : public Command
 
 class ModuleRLine : public Module
 {
- private:
        dynamic_reference<RegexFactory> rxfactory;
        RLineFactory f;
        CommandRLine r;
@@ -233,7 +223,7 @@ class ModuleRLine : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
 
@@ -244,18 +234,18 @@ class ModuleRLine : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleRLine()
+       ~ModuleRLine()
        {
                ServerInstance->XLines->DelAll("R");
                ServerInstance->XLines->UnregisterFactory(&f);
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("RLINE: Regexp user banning.", VF_COMMON | VF_VENDOR, rxfactory ? rxfactory->name : "");
        }
 
-       ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                // Apply lines on user connect
                XLine *rl = ServerInstance->XLines->MatchesLine("R", user);
@@ -269,7 +259,7 @@ class ModuleRLine : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnRehash(User *user)
+       void OnRehash(User *user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("rline");
 
@@ -302,7 +292,7 @@ class ModuleRLine : public Module
                initing = false;
        }
 
-       virtual ModResult OnStats(char symbol, User* user, string_list &results)
+       ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE
        {
                if (symbol != 'R')
                        return MOD_RES_PASSTHRU;
@@ -311,7 +301,7 @@ class ModuleRLine : public Module
                return MOD_RES_DENY;
        }
 
-       virtual void OnUserPostNick(User *user, const std::string &oldnick)
+       void OnUserPostNick(User *user, const std::string &oldnick) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return;
@@ -328,7 +318,7 @@ class ModuleRLine : public Module
                }
        }
 
-       virtual void OnBackgroundTimer(time_t curtime)
+       void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE
        {
                if (added_zline)
                {
@@ -337,7 +327,7 @@ class ModuleRLine : public Module
                }
        }
 
-       void OnUnloadModule(Module* mod)
+       void OnUnloadModule(Module* mod) CXX11_OVERRIDE
        {
                // If the regex engine became unavailable or has changed, remove all rlines
                if (!rxfactory)
diff --git a/src/modules/m_rmode.cpp b/src/modules/m_rmode.cpp
new file mode 100644 (file)
index 0000000..8259d40
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+#include "listmode.h"
+
+/* $ModDesc: Provides support for the RMODE command - Makes mass removal of chan listmodes by glob pattern possible */
+
+/** Handle /RMODE
+ */
+class CommandRMode : public Command
+{
+ public:
+       CommandRMode(Module* Creator) : Command(Creator,"RMODE", 2, 3)
+       {
+               allow_empty_last_param = false;
+               syntax = "<channel> <mode> [pattern]";
+       }
+
+       CmdResult Handle(const std::vector<std::string> &parameters, User *user)
+       {
+               ModeHandler* mh;
+               Channel* chan = ServerInstance->FindChan(parameters[0]);
+               char modeletter = parameters[1][0];
+
+               if (chan == NULL)
+               {
+                       user->WriteNotice("The channel " + parameters[0] + " does not exist.");
+                       return CMD_FAILURE;
+               }
+
+               mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
+               if (mh == NULL || parameters[1].size() > 1)
+               {
+                       user->WriteNotice(parameters[1] + " is not a valid channel mode.");
+                       return CMD_FAILURE;
+               }
+
+               if (chan->GetPrefixValue(user) < mh->GetLevelRequired())
+               {
+                       user->WriteNotice("You do not have access to unset " + ConvToStr(modeletter) + " on " +  chan->name + ".");
+                       return CMD_FAILURE;
+               }
+
+               unsigned int prefixrank;
+               char prefixchar;
+               std::string pattern = parameters.size() > 2 ? parameters[2] : "*";
+               ListModeBase* lm;
+               ListModeBase::ModeList* ml;
+               irc::modestacker modestack(false);
+
+               if (!mh->IsListMode())
+               {
+                       if (chan->IsModeSet(modeletter))
+                               modestack.Push(modeletter);
+               }
+               else if (((prefixrank = mh->GetPrefixRank()) && (prefixchar = mh->GetPrefix())))
+               {
+                       // As user prefix modes don't have a GetList() method, let's iterate through the channel's users.
+                       for (UserMembIter it = chan->userlist.begin(); it != chan->userlist.end(); ++it)
+                       {
+                               if (!InspIRCd::Match(it->first->nick, pattern))
+                                       continue;
+                               if (((strchr(chan->GetAllPrefixChars(user), prefixchar)) != NULL) && !(it->first == user && prefixrank > VOICE_VALUE))
+                                       modestack.Push(modeletter, it->first->nick);
+                       }
+               }
+               else if (((lm = dynamic_cast<ListModeBase*>(mh)) != NULL) && ((ml = lm->GetList(chan)) != NULL))
+               {
+                       for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
+                       {
+                               if (!InspIRCd::Match(it->mask, pattern))
+                                       continue;
+                               modestack.Push(modeletter, it->mask);
+                       }
+               }
+               else
+               {
+                       user->WriteNotice("Could not remove channel mode " + ConvToStr(modeletter));
+                       return CMD_FAILURE;
+               }
+
+               parameterlist stackresult;
+               stackresult.push_back(chan->name);
+               while (modestack.GetStackedLine(stackresult))
+               {
+                       ServerInstance->SendMode(stackresult, user);
+                       stackresult.erase(stackresult.begin() + 1, stackresult.end());
+               }
+
+               return CMD_SUCCESS;
+       }
+};
+
+class ModuleRMode : public Module
+{
+       CommandRMode cmd;
+
+ public:
+       ModuleRMode() : cmd(this) { }
+
+       void init() CXX11_OVERRIDE
+       {
+               ServerInstance->Modules->AddService(cmd);
+       }
+
+       Version GetVersion() CXX11_OVERRIDE
+       {
+               return Version("Allows glob-based removal of list modes", VF_VENDOR);
+       }
+};
+
+MODULE_INIT(ModuleRMode)
index 932b564fa5e27e31c1ff9b609637b38a6ed10c1b..205cd656976c7e3ee331bd99331fe26113184c56 100644 (file)
@@ -45,22 +45,21 @@ class CommandSajoin : public Command
                                user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
                                return CMD_FAILURE;
                        }
-                       if (IS_LOCAL(user) && !ServerInstance->IsChannel(parameters[1].c_str(), ServerInstance->Config->Limits.ChanMax))
+                       if (IS_LOCAL(user) && !ServerInstance->IsChannel(parameters[1]))
                        {
                                /* we didn't need to check this for each character ;) */
-                               user->WriteServ("NOTICE "+user->nick+" :*** Invalid characters in channel name or name too long");
+                               user->WriteNotice("*** Invalid characters in channel name or name too long");
                                return CMD_FAILURE;
                        }
 
-                       /* For local users, we send the JoinUser which may create a channel and set its TS.
+                       /* For local users, we call Channel::JoinUser which may create a channel and set its TS.
                         * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
-                        * and then that server will generate the users JOIN or FJOIN instead.
+                        * and then that server will handle the command.
                         */
-                       if (IS_LOCAL(dest))
+                       LocalUser* localuser = IS_LOCAL(dest);
+                       if (localuser)
                        {
-                               Channel::JoinUser(dest, parameters[1].c_str(), true, "", false, ServerInstance->Time());
-                               /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propagate */
-                               Channel* n = ServerInstance->FindChan(parameters[1]);
+                               Channel* n = Channel::JoinUser(localuser, parameters[1], true);
                                if (n)
                                {
                                        if (n->HasUser(dest))
@@ -70,13 +69,13 @@ class CommandSajoin : public Command
                                        }
                                        else
                                        {
-                                               user->WriteServ("NOTICE "+user->nick+" :*** Could not join "+dest->nick+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
+                                               user->WriteNotice("*** Could not join "+dest->nick+" to "+parameters[1]+" (User is probably banned, or blocking modes)");
                                                return CMD_FAILURE;
                                        }
                                }
                                else
                                {
-                                       user->WriteServ("NOTICE "+user->nick+" :*** Could not join "+dest->nick+" to "+parameters[1]);
+                                       user->WriteNotice("*** Could not join "+dest->nick+" to "+parameters[1]);
                                        return CMD_FAILURE;
                                }
                        }
@@ -88,7 +87,7 @@ class CommandSajoin : public Command
                }
                else
                {
-                       user->WriteServ("NOTICE "+user->nick+" :*** No such nickname "+parameters[0]);
+                       user->WriteNotice("*** No such nickname "+parameters[0]);
                        return CMD_FAILURE;
                }
        }
@@ -111,20 +110,15 @@ class ModuleSajoin : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSajoin()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides command SAJOIN to allow opers to force-join users to channels", VF_OPTCOMMON | VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSajoin)
index 7dfcd8904db3b7e8531059e270274a6eac547cb5..0d36ca8aeb309c45ea6ade6be6d5db1b48fb5a3f 100644 (file)
@@ -68,7 +68,7 @@ class CommandSakick : public Command
                                if (n && n->HasUser(dest))
                                {
                                        /* Sort-of-bug: If the command was issued remotely, this message won't be sent */
-                                       user->WriteServ("NOTICE %s :*** Unable to kick %s from %s", user->nick.c_str(), dest->nick.c_str(), parameters[0].c_str());
+                                       user->WriteNotice("*** Unable to kick " + dest->nick + " from " + parameters[0]);
                                        return CMD_FAILURE;
                                }
                        }
@@ -83,7 +83,7 @@ class CommandSakick : public Command
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
+                       user->WriteNotice("*** Invalid nickname or channel");
                }
 
                return CMD_FAILURE;
@@ -107,21 +107,15 @@ class ModuleSakick : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSakick()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides a SAKICK command", VF_OPTCOMMON|VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSakick)
-
index 9b71992a60888f04f8b27652d7b0e77b725e9048..b24becb97c1ae80f2a571b5b94d031f2ee0827ee 100644 (file)
@@ -39,6 +39,12 @@ class CommandSamode : public Command
 
        CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
+               User* target = ServerInstance->FindNick(parameters[0]);
+               if ((target) && (target != user))
+               {
+                       if (!user->HasPrivPermission("users/samode-usermodes", true))
+                               return CMD_FAILURE;
+               }
                this->active = true;
                ServerInstance->Parser->CallHandler("MODE", parameters, user);
                if (ServerInstance->Modes->GetLastParse().length())
@@ -57,22 +63,18 @@ class ModuleSaMode : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->Modules->Attach(I_OnPreMode, this);
        }
 
-       ~ModuleSaMode()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides command SAMODE to allow opers to change modes on channels and users", VF_VENDOR);
        }
 
-       ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
+       ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
        {
                if (cmd.active)
                        return MOD_RES_ALLOW;
index 4e4be77ae635c6e7f6d73d452dee4c6e88057e81..01899dd0add2b31e746c451b1313287898080162 100644 (file)
@@ -50,13 +50,13 @@ class CommandSanick : public Command
 
                        if ((!target) || (target->registered != REG_ALL))
                        {
-                               user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
+                               user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
                                return CMD_FAILURE;
                        }
 
-                       if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
+                       if (!ServerInstance->IsNick(parameters[1]))
                        {
-                               user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
+                               user->WriteNotice("*** Invalid nickname '" + parameters[1] + "'");
                                return CMD_FAILURE;
                        }
                }
@@ -98,20 +98,16 @@ class ModuleSanick : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSanick()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for SANICK command", VF_OPTCOMMON | VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSanick)
+
index 89256e0e480bfc5cc9811e69a27f4a12d66b545e..e8cd2b5d1019a23b0578c2d9d1a7e5f653f74165 100644 (file)
@@ -74,7 +74,7 @@ class CommandSapart : public Command
                                        }
                                        else
                                        {
-                                               user->WriteServ("NOTICE %s :*** Unable to make %s part %s",user->nick.c_str(), dest->nick.c_str(), parameters[1].c_str());
+                                               user->WriteNotice("*** Unable to make " + dest->nick + " part " + parameters[1]);
                                                return CMD_FAILURE;
                                        }
                                }
@@ -84,7 +84,7 @@ class CommandSapart : public Command
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
+                       user->WriteNotice("*** Invalid nickname or channel");
                }
 
                return CMD_FAILURE;
@@ -109,21 +109,15 @@ class ModuleSapart : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSapart()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides command SAPART to force-part users from a channel.", VF_OPTCOMMON | VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSapart)
-
index 3b7bdc8245743ec5fc3868473de8bbad862fb74f..b7466048795668240c2363798c4e3b640fbe6be5 100644 (file)
@@ -48,7 +48,7 @@ class CommandSaquit : public Command
                        // Pass the command on, so the client's server can quit it properly.
                        if (!IS_LOCAL(dest))
                                return CMD_SUCCESS;
-                       
+
                        ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SAQUIT to make "+dest->nick+" quit with a reason of "+parameters[1]);
 
                        ServerInstance->Users->QuitUser(dest, parameters[1]);
@@ -56,7 +56,7 @@ class CommandSaquit : public Command
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[0].c_str());
+                       user->WriteNotice("*** Invalid nickname '" + parameters[0] + "'");
                        return CMD_FAILURE;
                }
        }
@@ -79,20 +79,16 @@ class ModuleSaquit : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSaquit()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for an SAQUIT command, exits user with a reason", VF_OPTCOMMON | VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSaquit)
+
index b67111987bdaed4312e0b63739cc4e944c8533f4..322a726ce2814971f16e1572d96296ff726475a5 100644 (file)
 
 
 #include "inspircd.h"
-#include "m_cap.h"
-#include "account.h"
-#include "sasl.h"
-#include "ssl.h"
+#include "modules/cap.h"
+#include "modules/account.h"
+#include "modules/sasl.h"
+#include "modules/ssl.h"
 
 /* $ModDesc: Provides support for IRC Authentication Layer (aka: atheme SASL) via AUTHENTICATE. */
 
@@ -112,7 +112,7 @@ class SaslAuthenticator
                 case SASL_DONE:
                        break;
                 default:
-                       ServerInstance->Logs->Log("m_sasl", DEFAULT, "WTF: SaslState is not a known state (%d)", this->state);
+                       ServerInstance->Logs->Log("m_sasl", LOG_DEFAULT, "WTF: SaslState is not a known state (%d)", this->state);
                        break;
                }
 
@@ -220,7 +220,7 @@ class CommandSASL : public Command
                User* target = ServerInstance->FindNick(parameters[1]);
                if ((!target) || (IS_SERVER(target)))
                {
-                       ServerInstance->Logs->Log("m_sasl", DEBUG,"User not found in sasl ENCAP event: %s", parameters[1].c_str());
+                       ServerInstance->Logs->Log("m_sasl", LOG_DEBUG, "User not found in sasl ENCAP event: %s", parameters[1].c_str());
                        return CMD_FAILURE;
                }
 
@@ -249,13 +249,14 @@ class ModuleSASL : public Module
        GenericCap cap;
        CommandAuthenticate auth;
        CommandSASL sasl;
+
  public:
        ModuleSASL()
                : authExt("sasl_auth", this), cap(this, "sasl"), auth(this, authExt, cap), sasl(this, authExt)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                Implementation eventlist[] = { I_OnEvent, I_OnUserRegister, I_OnRehash };
@@ -265,15 +266,15 @@ class ModuleSASL : public Module
                ServerInstance->Modules->AddServices(providelist, 3);
 
                if (!ServerInstance->Modules->Find("m_services_account.so") || !ServerInstance->Modules->Find("m_cap.so"))
-                       ServerInstance->Logs->Log("m_sasl", DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!");
+                       ServerInstance->Logs->Log("m_sasl", LOG_DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!");
        }
 
-       void OnRehash(User*)
+       void OnRehash(User*) CXX11_OVERRIDE
        {
                sasl_target = ServerInstance->Config->ConfValue("sasl")->getString("target", "*");
        }
 
-       ModResult OnUserRegister(LocalUser *user)
+       ModResult OnUserRegister(LocalUser *user) CXX11_OVERRIDE
        {
                SaslAuthenticator *sasl_ = authExt.get(user);
                if (sasl_)
@@ -285,12 +286,12 @@ class ModuleSASL : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for IRC Authentication Layer (aka: atheme SASL) via AUTHENTICATE.",VF_VENDOR);
        }
 
-       void OnEvent(Event &ev)
+       void OnEvent(Event &ev) CXX11_OVERRIDE
        {
                cap.HandleEvent(ev);
        }
index ae1c19d9148022e2324d27ba96ec19182b051f99..c15c9e91bcb4e2e911e509c108f36b5d3240fc21 100644 (file)
@@ -65,16 +65,12 @@ class ModuleSATopic : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSATopic()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides a SATOPIC command", VF_VENDOR);
        }
index 6013d1fd7543400bfcadf0a4f55f1269f8b058ad..875e7fb75652641ac6364f9b5134692edb4b1e9b 100644 (file)
 
 class ModuleSecureList : public Module
 {
- private:
        std::vector<std::string> allowlist;
        time_t WaitTime;
+
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                Implementation eventlist[] = { I_OnRehash, I_OnPreCommand, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleSecureList()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Disallows /LIST for recently connected clients to hinder spam bots", VF_VENDOR);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                allowlist.clear();
 
@@ -61,13 +57,13 @@ class ModuleSecureList : public Module
         * OnPreCommand()
         *   Intercept the LIST command.
         */
-       virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                /* If the command doesnt appear to be valid, we dont want to mess with it. */
                if (!validated)
                        return MOD_RES_PASSTHRU;
 
-               if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!IS_OPER(user)))
+               if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!user->IsOper()))
                {
                        /* Normally wouldnt be allowed here, are they exempt? */
                        for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
@@ -75,7 +71,7 @@ class ModuleSecureList : public Module
                                        return MOD_RES_PASSTHRU;
 
                        /* Not exempt, BOOK EM DANNO! */
-                       user->WriteServ("NOTICE %s :*** You cannot list within the first %lu seconds of connecting. Please try again later.",user->nick.c_str(), (unsigned long) WaitTime);
+                       user->WriteNotice("*** You cannot list within the first " + ConvToStr(WaitTime) + " seconds of connecting. Please try again later.");
                        /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
                         * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
                         */
@@ -86,9 +82,9 @@ class ModuleSecureList : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" SECURELIST");
+               tokens["SECURELIST"];
        }
 };
 
index 95872b5b27dba2af1dcb2bd068ff580721991f72..d652aaaa7ce48dfc37136548d3a58f147eb890d5 100644 (file)
 class ModuleSeeNicks : public Module
 {
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->SNO->EnableSnomask('n',"NICK");
                Implementation eventlist[] = { I_OnUserPostNick };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for seeing local and remote nickchanges via snomasks", VF_VENDOR);
        }
 
-       virtual void OnUserPostNick(User* user, const std::string &oldnick)
+       void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE
        {
                ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'n' : 'N',"User %s changed their nickname to %s", oldnick.c_str(), user->nick.c_str());
        }
index cf77ae9ba75ac99b5cce271eb71e82608c7b7fbd..b87197ffdd8de8fa710154e86e618b8f41dd3647 100644 (file)
 
 class ModuleServerBan : public Module
 {
- private:
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnCheckBan, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ~ModuleServerBan()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Extban 's' - server ban",VF_OPTCOMMON|VF_VENDOR);
        }
 
-       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
+       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
        {
                if ((mask.length() > 2) && (mask[0] == 's') && (mask[1] == ':'))
                {
@@ -50,12 +45,10 @@ class ModuleServerBan : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('s');
+               tokens["EXTBAN"].push_back('s');
        }
 };
 
-
 MODULE_INIT(ModuleServerBan)
-
index cb3f089c6c6c7376a957135021172f3b885be262..e42c02ff2b63a523049450cf6fadc5784bdcc737 100644 (file)
@@ -25,7 +25,7 @@
 /* $ModDesc: Provides support for ircu-style services accounts, including chmode +R, etc. */
 
 #include "inspircd.h"
-#include "account.h"
+#include "modules/account.h"
 
 /** Channel mode +r - mark a channel as identified
  */
@@ -118,24 +118,24 @@ class ModuleServicesAccount : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServiceProvider* providerlist[] = { &m1, &m2, &m3, &m4, &m5, &accountname };
                ServerInstance->Modules->AddServices(providerlist, sizeof(providerlist)/sizeof(ServiceProvider*));
-               Implementation eventlist[] = { I_OnWhois, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin, I_OnCheckBan,
+               Implementation eventlist[] = { I_OnWhois, I_OnUserPreMessage, I_OnUserPreJoin, I_OnCheckBan,
                        I_OnDecodeMetaData, I_On005Numeric, I_OnUserPostNick, I_OnSetConnectClass };
 
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void On005Numeric(std::string &t)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               ServerInstance->AddExtBanChar('R');
-               ServerInstance->AddExtBanChar('U');
+               tokens["EXTBAN"].push_back('R');
+               tokens["EXTBAN"].push_back('U');
        }
 
        /* <- :twisted.oscnet.org 330 w00t2 w00t2 w00t :is logged in as */
-       void OnWhois(User* source, User* dest)
+       void OnWhois(User* source, User* dest) CXX11_OVERRIDE
        {
                std::string *account = accountname.get(dest);
 
@@ -151,7 +151,7 @@ class ModuleServicesAccount : public Module
                }
        }
 
-       void OnUserPostNick(User* user, const std::string &oldnick)
+       void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE
        {
                /* On nickchange, if they have +r, remove it */
                if (user->IsModeSet('r') && assign(user->nick) != oldnick)
@@ -163,7 +163,7 @@ class ModuleServicesAccount : public Module
                }
        }
 
-       ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return MOD_RES_PASSTHRU;
@@ -197,7 +197,7 @@ class ModuleServicesAccount : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask)
+       ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) CXX11_OVERRIDE
        {
                static bool checking = false;
                if (checking)
@@ -234,16 +234,8 @@ class ModuleServicesAccount : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
-               return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
-       }
-
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
-       {
-               if (!IS_LOCAL(user))
-                       return MOD_RES_PASSTHRU;
-
                std::string *account = accountname.get(user);
                bool is_registered = account && !account->empty();
 
@@ -269,7 +261,7 @@ class ModuleServicesAccount : public Module
        // In our case we're only sending a single string around, so we just construct a std::string.
        // Some modules will probably get much more complex and format more detailed structs and classes
        // in a textual way for sending over the link.
-       void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
+       void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata) CXX11_OVERRIDE
        {
                User* dest = dynamic_cast<User*>(target);
                // check if its our metadata key, and its associated with a user
@@ -293,17 +285,18 @@ class ModuleServicesAccount : public Module
                }
        }
 
-       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
+       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE
        {
                if (myclass->config->getBool("requireaccount") && !accountname.get(user))
                        return MOD_RES_DENY;
                return MOD_RES_PASSTHRU;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for ircu-style services accounts, including chmode +R, etc.",VF_OPTCOMMON|VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleServicesAccount)
+
index b4f2b5bbd5ae5ba5a42ac78a9db2587e8a7c4ec9..82ad0920bb143a61cd95a23e9f8554c38c93a3c1 100644 (file)
@@ -53,32 +53,27 @@ class ModuleServProtectMode : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(bm);
                Implementation eventlist[] = { I_OnWhois, I_OnKill, I_OnWhoisLine, I_OnRawMode, I_OnUserPreKick };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-
-       ~ModuleServProtectMode()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides usermode +k to protect services from kicks, kills, and mode changes.", VF_VENDOR);
        }
 
-       void OnWhois(User* src, User* dst)
+       void OnWhois(User* user, User* dest) CXX11_OVERRIDE
        {
-               if (dst->IsModeSet('k'))
+               if (dest->IsModeSet('k'))
                {
-                       ServerInstance->SendWhoisLine(src, dst, 310, src->nick+" "+dst->nick+" :is an "+ServerInstance->Config->Network+" Service");
+                       ServerInstance->SendWhoisLine(user, dest, 310, user->nick+" "+dest->nick+" :is a Network Service on "+ServerInstance->Config->Network);
                }
        }
 
-       ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt)
+       ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt) CXX11_OVERRIDE
        {
                /* Check that the mode is not a server mode, it is being removed, the user making the change is local, there is a parameter,
                 * and the user making the change is not a uline
@@ -107,7 +102,7 @@ class ModuleServProtectMode : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnKill(User* src, User* dst, const std::string &reason)
+       ModResult OnKill(User* src, User* dst, const std::string &reason) CXX11_OVERRIDE
        {
                if (src == NULL)
                        return MOD_RES_PASSTHRU;
@@ -121,7 +116,7 @@ class ModuleServProtectMode : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserPreKick(User *src, Membership* memb, const std::string &reason)
+       ModResult OnUserPreKick(User *src, Membership* memb, const std::string &reason) CXX11_OVERRIDE
        {
                if (memb->user->IsModeSet('k'))
                {
@@ -133,7 +128,7 @@ class ModuleServProtectMode : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnWhoisLine(User* src, User* dst, int &numeric, std::string &text)
+       ModResult OnWhoisLine(User* src, User* dst, int &numeric, std::string &text) CXX11_OVERRIDE
        {
                return ((src != dst) && (numeric == 319) && dst->IsModeSet('k')) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
        }
index 2ef0c054865a6fcf9a19ee5b1631f6324e0c4938..e3e02fbe80f2d40de20d102ea1c169d99b63ba1b 100644 (file)
@@ -27,8 +27,8 @@
  */
 class CommandSethost : public Command
 {
- private:
        char* hostmap;
+
  public:
        CommandSethost(Module* Creator, char* hmap) : Command(Creator,"SETHOST", 1), hostmap(hmap)
        {
@@ -44,14 +44,14 @@ class CommandSethost : public Command
                {
                        if (!hostmap[(const unsigned char)*x])
                        {
-                               user->WriteServ("NOTICE "+user->nick+" :*** SETHOST: Invalid characters in hostname");
+                               user->WriteNotice("*** SETHOST: Invalid characters in hostname");
                                return CMD_FAILURE;
                        }
                }
 
                if (len > 64)
                {
-                       user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick.c_str());
+                       user->WriteNotice("*** SETHOST: Host too long");
                        return CMD_FAILURE;
                }
 
@@ -70,13 +70,14 @@ class ModuleSetHost : public Module
 {
        CommandSethost cmd;
        char hostmap[256];
+
  public:
        ModuleSetHost()
                : cmd(this, hostmap)
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                ServerInstance->Modules->AddService(cmd);
@@ -84,7 +85,7 @@ class ModuleSetHost : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                std::string hmap = ServerInstance->Config->ConfValue("hostname")->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789");
 
@@ -93,15 +94,10 @@ class ModuleSetHost : public Module
                        hostmap[(unsigned char)*n] = 1;
        }
 
-       virtual ~ModuleSetHost()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the SETHOST command", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSetHost)
index f63be1381bb2ecee0ebc61142ac4916922280b55..2ad886fcda9e9e6b322f1c7a585ed407bee49179 100644 (file)
@@ -40,13 +40,13 @@ class CommandSetident : public Command
        {
                if (parameters[0].size() > ServerInstance->Config->Limits.IdentMax)
                {
-                       user->WriteServ("NOTICE %s :*** SETIDENT: Ident is too long", user->nick.c_str());
+                       user->WriteNotice("*** SETIDENT: Ident is too long");
                        return CMD_FAILURE;
                }
 
                if (!ServerInstance->IsIdent(parameters[0].c_str()))
                {
-                       user->WriteServ("NOTICE %s :*** SETIDENT: Invalid characters in ident", user->nick.c_str());
+                       user->WriteNotice("*** SETIDENT: Invalid characters in ident");
                        return CMD_FAILURE;
                }
 
@@ -57,7 +57,6 @@ class CommandSetident : public Command
        }
 };
 
-
 class ModuleSetIdent : public Module
 {
        CommandSetident cmd;
@@ -67,21 +66,15 @@ class ModuleSetIdent : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSetIdent()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the SETIDENT command", VF_VENDOR);
        }
-
 };
 
-
 MODULE_INIT(ModuleSetIdent)
index fdb29d14fe7904233bb573950207283ebdb79d13..90943f9ef70aabdfcdea0884ffe8d1d57a8e2754 100644 (file)
 
 /** Handle /SETIDLE
  */
-class CommandSetidle : public Command
+class CommandSetidle : public SplitCommand
 {
  public:
-       CommandSetidle(Module* Creator) : Command(Creator,"SETIDLE", 1)
+       CommandSetidle(Module* Creator) : SplitCommand(Creator,"SETIDLE", 1)
        {
                flags_needed = 'o'; syntax = "<duration>";
                TRANSLATE2(TR_TEXT, TR_END);
        }
 
-       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
+       CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
        {
-               time_t idle = ServerInstance->Duration(parameters[0]);
+               int idle = InspIRCd::Duration(parameters[0]);
                if (idle < 1)
                {
                        user->WriteNumeric(948, "%s :Invalid idle time.",user->nick.c_str());
@@ -63,16 +63,12 @@ class ModuleSetIdle : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSetIdle()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows opers to set their idle time", VF_VENDOR);
        }
index d0610853bc4ce7e1308d01616473136b25c8eb98..ee42d38520f4bd54319c24778bd396d0f9aeee04 100644 (file)
@@ -39,7 +39,7 @@ class CommandSetname : public Command
        {
                if (parameters[0].size() > ServerInstance->Config->Limits.MaxGecos)
                {
-                       user->WriteServ("NOTICE %s :*** SETNAME: GECOS too long", user->nick.c_str());
+                       user->WriteNotice("*** SETNAME: GECOS too long");
                        return CMD_FAILURE;
                }
 
@@ -62,16 +62,12 @@ class ModuleSetName : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleSetName()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the SETNAME command", VF_VENDOR);
        }
index 86970968a80740c43ef31204426e2e141854123c..129dc891cdd84cbf715ab30000f321b4f38c5f7f 100644 (file)
@@ -62,7 +62,7 @@
 #ifdef HAS_STDINT
 #include <stdint.h>
 #endif
-#include "hash.h"
+#include "modules/hash.h"
 
 #ifndef HAS_STDINT
 typedef unsigned int uint32_t;
@@ -263,11 +263,6 @@ class HashSHA256 : public HashProvider
                return std::string((char*)bytes, SHA256_DIGEST_SIZE);
        }
 
-       std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata)
-       {
-               return "";
-       }
-
        HashSHA256(Module* parent) : HashProvider(parent, "hash/sha256", 32, 64) {}
 };
 
@@ -280,7 +275,7 @@ class ModuleSHA256 : public Module
                ServerInstance->Modules->AddService(sha);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements SHA-256 hashing", VF_VENDOR);
        }
index 434d1b07fdc0e50d9bde39efa211930700eb17f9..57d496f1f363651990a6c0d919de4310e32dd8e7 100644 (file)
@@ -46,9 +46,9 @@ class WhoisNoticeCmd : public Command
 
        void HandleFast(User* dest, User* src)
        {
-               dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
-                       dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
-                       dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
+               dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" +
+                       (dest->HasPrivPermission("users/auspex") ? src->host : src->dhost) +
+                       ") did a /whois on you");
        }
 
        CmdResult Handle(const std::vector<std::string> &parameters, User *user)
@@ -79,7 +79,7 @@ class ModuleShowwhois : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois");
 
@@ -98,17 +98,17 @@ class ModuleShowwhois : public Module
                delete sw;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
        }
 
-       void OnWhois(User* source, User* dest)
+       void OnWhois(User* source, User* dest) CXX11_OVERRIDE
        {
                if (!dest->IsModeSet('W') || source == dest)
                        return;
 
-               if (!ShowWhoisFromOpers && IS_OPER(source))
+               if (!ShowWhoisFromOpers && source->IsOper())
                        return;
 
                if (IS_LOCAL(dest))
@@ -125,7 +125,7 @@ class ModuleShowwhois : public Module
                        ServerInstance->PI->SendEncapsulatedData(params);
                }
        }
-
 };
 
 MODULE_INIT(ModuleShowwhois)
+
index 8bf4d30e7bf341d4d6ce773bc7c1734455bb586e..a06149b62d2c13cae70df5721664a6c9daed4eeb 100644 (file)
@@ -36,14 +36,11 @@ public:
        {
        }
 
-       ~Shun()
-       {
-       }
-
        bool Matches(User *u)
        {
                // E: overrides shun
-               if (u->exempt)
+               LocalUser* lu = IS_LOCAL(u);
+               if (lu && lu->exempt)
                        return false;
 
                if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext) || InspIRCd::Match(u->nick+"!"+u->ident+"@"+u->GetIPString(), matchtext))
@@ -59,15 +56,9 @@ public:
                return false;
        }
 
-       void DisplayExpiry()
-       {
-               ServerInstance->SNO->WriteToSnoMask('x',"Removing expired shun %s (set by %s %ld seconds ago)",
-                       this->matchtext.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
-       }
-
-       const char* Displayable()
+       const std::string& Displayable()
        {
-               return matchtext.c_str();
+               return matchtext;
        }
 };
 
@@ -107,7 +98,7 @@ class CommandShun : public Command
                /* 'time' is a human-readable timestring, like 2d3h2s. */
 
                std::string target = parameters[0];
-               
+
                User *find = ServerInstance->FindNick(target);
                if ((find) && (find->registered == REG_ALL))
                        target = std::string("*!*@") + find->GetIPString();
@@ -120,18 +111,18 @@ class CommandShun : public Command
                        }
                        else
                        {
-                               user->WriteServ("NOTICE %s :*** Shun %s not found in list, try /stats H.",user->nick.c_str(),target.c_str());
+                               user->WriteNotice("*** Shun " + target + " not found in list, try /stats H.");
                                return CMD_FAILURE;
                        }
                }
                else
                {
                        // Adding - XXX todo make this respect <insane> tag perhaps..
-                       long duration;
+                       unsigned long duration;
                        std::string expr;
                        if (parameters.size() > 2)
                        {
-                               duration = ServerInstance->Duration(parameters[1]);
+                               duration = InspIRCd::Duration(parameters[1]);
                                expr = parameters[2];
                        }
                        else
@@ -159,7 +150,7 @@ class CommandShun : public Command
                        else
                        {
                                delete r;
-                               user->WriteServ("NOTICE %s :*** Shun for %s already exists", user->nick.c_str(), target.c_str());
+                               user->WriteNotice("*** Shun for " + target + " already exists");
                                return CMD_FAILURE;
                        }
                }
@@ -188,7 +179,7 @@ class ModuleShun : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->XLines->RegisterFactory(&f);
                ServerInstance->Modules->AddService(cmd);
@@ -198,7 +189,7 @@ class ModuleShun : public Module
                OnRehash(NULL);
        }
 
-       virtual ~ModuleShun()
+       ~ModuleShun()
        {
                ServerInstance->XLines->DelAll("SHUN");
                ServerInstance->XLines->UnregisterFactory(&f);
@@ -210,7 +201,7 @@ class ModuleShun : public Module
                ServerInstance->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_BEFORE, &alias);
        }
 
-       virtual ModResult OnStats(char symbol, User* user, string_list& out)
+       ModResult OnStats(char symbol, User* user, string_list& out) CXX11_OVERRIDE
        {
                if (symbol != 'H')
                        return MOD_RES_PASSTHRU;
@@ -219,7 +210,7 @@ class ModuleShun : public Module
                return MOD_RES_DENY;
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("shun");
                std::string cmds = tag->getString("enabledcommands");
@@ -242,7 +233,7 @@ class ModuleShun : public Module
                affectopers = tag->getBool("affectopers", false);
        }
 
-       virtual ModResult OnPreCommand(std::string &command, std::vector<std::string>& parameters, LocalUser* user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string>& parameters, LocalUser* user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                if (validated)
                        return MOD_RES_PASSTHRU;
@@ -253,7 +244,7 @@ class ModuleShun : public Module
                        return MOD_RES_PASSTHRU;
                }
 
-               if (!affectopers && IS_OPER(user))
+               if (!affectopers && user->IsOper())
                {
                        /* Don't do anything if the user is an operator and affectopers isn't set */
                        return MOD_RES_PASSTHRU;
@@ -264,7 +255,7 @@ class ModuleShun : public Module
                if (i == ShunEnabledCommands.end())
                {
                        if (NotifyOfShun)
-                               user->WriteServ("NOTICE %s :*** Command %s not processed, as you have been blocked from issuing commands (SHUN)", user->nick.c_str(), command.c_str());
+                               user->WriteNotice("*** Command " + command + " not processed, as you have been blocked from issuing commands (SHUN)");
                        return MOD_RES_DENY;
                }
 
@@ -283,11 +274,10 @@ class ModuleShun : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the /SHUN command, which stops a user from executing all except configured commands.",VF_VENDOR|VF_COMMON);
        }
 };
 
 MODULE_INIT(ModuleShun)
-
index 817c8ffcfe2e91aae18974c75cca988d1d2fc009..0e9a45720b3b99bfc3f41a0be938621db388fd19 100644 (file)
@@ -149,7 +149,7 @@ class CommandSilence : public Command
 
                        if (pattern == 0)
                        {
-                               user->WriteServ("NOTICE %s :Bad SILENCE pattern",user->nick.c_str());
+                               user->WriteNotice("Bad SILENCE pattern");
                                return CMD_INVALID;
                        }
 
@@ -302,28 +302,28 @@ class ModuleSilence : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                ServerInstance->Modules->AddService(cmdsilence);
                ServerInstance->Modules->AddService(cmdsvssilence);
                ServerInstance->Modules->AddService(cmdsilence.ext);
 
-               Implementation eventlist[] = { I_OnRehash, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage, I_OnUserPreInvite };
+               Implementation eventlist[] = { I_OnRehash, I_On005Numeric, I_OnUserPreMessage, I_OnUserPreInvite };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                maxsilence = ServerInstance->Config->ConfValue("showwhois")->getInt("maxentries", 32);
                if (!maxsilence)
                        maxsilence = 32;
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               // we don't really have a limit...
-               output = output + " ESILENCE SILENCE=" + ConvToStr(maxsilence);
+               tokens["ESILENCE"];
+               tokens["SILENCE"] = ConvToStr(maxsilence);
        }
 
        void OnBuildExemptList(MessageType message_type, Channel* chan, User* sender, char status, CUList &exempt_list, const std::string &text)
@@ -343,34 +343,24 @@ class ModuleSilence : public Module
                }
        }
 
-       ModResult PreText(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list, int silence_type)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (target_type == TYPE_USER && IS_LOCAL(((User*)dest)))
                {
-                       return MatchPattern((User*)dest, user, silence_type);
+                       return MatchPattern((User*)dest, user, ((msgtype == MSG_PRIVMSG) ? SILENCE_PRIVATE : SILENCE_NOTICE));
                }
                else if (target_type == TYPE_CHANNEL)
                {
                        Channel* chan = (Channel*)dest;
                        if (chan)
                        {
-                               this->OnBuildExemptList((silence_type == SILENCE_PRIVATE ? MSG_PRIVMSG : MSG_NOTICE), chan, user, status, exempt_list, "");
+                               this->OnBuildExemptList(msgtype, chan, user, status, exempt_list, "");
                        }
                }
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return PreText(user, dest, target_type, text, status, exempt_list, SILENCE_PRIVATE);
-       }
-
-       ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return PreText(user, dest, target_type, text, status, exempt_list, SILENCE_NOTICE);
-       }
-
-       ModResult OnUserPreInvite(User* source,User* dest,Channel* channel, time_t timeout)
+       ModResult OnUserPreInvite(User* source,User* dest,Channel* channel, time_t timeout) CXX11_OVERRIDE
        {
                return MatchPattern(dest, source, SILENCE_INVITE);
        }
@@ -393,11 +383,7 @@ class ModuleSilence : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ~ModuleSilence()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the /SILENCE command", VF_OPTCOMMON | VF_VENDOR);
        }
index 7ee1a7ef1b0d5d57882d50aa1b2da96957d35f13..a43112ce97e0316be0b11c6c7816f5debe13769e 100644 (file)
@@ -57,14 +57,14 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist &params)
        XLine* xl = NULL;
        try
        {
-               xl = xlf->Generate(ServerInstance->Time(), atoi(params[4].c_str()), params[2], params[5], params[1]);
+               xl = xlf->Generate(ServerInstance->Time(), ConvToInt(params[4]), params[2], params[5], params[1]);
        }
        catch (ModuleException &e)
        {
                ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason());
                return true;
        }
-       xl->SetCreateTime(atoi(params[3].c_str()));
+       xl->SetCreateTime(ConvToInt(params[3]));
        if (ServerInstance->XLines->AddLine(xl, NULL))
        {
                if (xl->duration)
index ed97c48cdfe7c9e49b055cd8c943fa9d79d0935b..f2cabadd536d2dab52baa2203b0ae892e818d51b 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "main.h"
 #include "utils.h"
-#include "treeserver.h"
 #include "treesocket.h"
 
 bool TreeSocket::Away(const std::string &prefix, parameterlist &params)
@@ -34,7 +33,7 @@ bool TreeSocket::Away(const std::string &prefix, parameterlist &params)
                FOREACH_MOD(I_OnSetAway, OnSetAway(u, params[params.size() - 1]));
 
                if (params.size() > 1)
-                       u->awaytime = atoi(params[0].c_str());
+                       u->awaytime = ConvToInt(params[0]);
                else
                        u->awaytime = ServerInstance->Time();
 
diff --git a/src/modules/m_spanningtree/cachetimer.cpp b/src/modules/m_spanningtree/cachetimer.cpp
deleted file mode 100644 (file)
index be43865..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-
-#include "cachetimer.h"
-#include "main.h"
-#include "utils.h"
-#include "treeserver.h"
-#include "link.h"
-#include "treesocket.h"
-
-/* $ModDep: m_spanningtree/cachetimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
-
-CacheRefreshTimer::CacheRefreshTimer(SpanningTreeUtilities *Util) : Timer(3600, ServerInstance->Time(), true), Utils(Util)
-{
-}
-
-void CacheRefreshTimer::Tick(time_t TIME)
-{
-       Utils->RefreshIPCache();
-}
-
index bad1b7419e5649250484007463c0d2954df4a64d..ab6dcdf0923534a4300b30018c9a3224a16f6782 100644 (file)
  */
 
 
-#ifndef M_SPANNINGTREE_CACHETIMER_H
-#define M_SPANNINGTREE_CACHETIMER_H
+#pragma once
 
-#include "timer.h"
-
-class ModuleSpanningTree;
 class SpanningTreeUtilities;
 
 /** Create a timer which recurs every second, we inherit from Timer.
@@ -35,7 +31,5 @@ class CacheRefreshTimer : public Timer
        SpanningTreeUtilities *Utils;
  public:
        CacheRefreshTimer(SpanningTreeUtilities* Util);
-       virtual void Tick(time_t TIME);
+       bool Tick(time_t TIME);
 };
-
-#endif
index 62afe5974b6262b36458dec598543626dcee4c8c..fa10c79fe9a57714188bc66fa0c40d372c2e4daa 100644 (file)
@@ -20,9 +20,7 @@
 
 
 #include "inspircd.h"
-#include "xline.h"
 
-#include "treesocket.h"
 #include "treeserver.h"
 #include "utils.h"
 #include "link.h"
@@ -32,25 +30,19 @@ std::string TreeSocket::MyModules(int filter)
 {
        std::vector<std::string> modlist = ServerInstance->Modules->GetAllModuleNames(filter);
 
-       if (filter == VF_COMMON && proto_version != ProtocolVersion)
-               CompatAddModules(modlist);
-
        std::string capabilities;
        sort(modlist.begin(),modlist.end());
        for (std::vector<std::string>::const_iterator i = modlist.begin(); i != modlist.end(); ++i)
        {
                if (i != modlist.begin())
-                       capabilities.push_back(proto_version > 1201 ? ' ' : ',');
+                       capabilities.push_back(');
                capabilities.append(*i);
                Module* m = ServerInstance->Modules->Find(*i);
-               if (m && proto_version > 1201)
+               Version v = m->GetVersion();
+               if (!v.link_data.empty())
                {
-                       Version v = m->GetVersion();
-                       if (!v.link_data.empty())
-                       {
-                               capabilities.push_back('=');
-                               capabilities.append(v.link_data);
-                       }
+                       capabilities.push_back('=');
+                       capabilities.append(v.link_data);
                }
        }
        return capabilities;
@@ -90,7 +82,7 @@ void TreeSocket::SendCapabilities(int phase)
        if (phase < 2)
                return;
 
-       char sep = proto_version > 1201 ? ' ' : ',';
+       const char sep = ' ';
        irc::sepstream modulelist(MyModules(VF_COMMON), sep);
        irc::sepstream optmodulelist(MyModules(VF_OPTCOMMON), sep);
        /* Send module names, split at 509 length */
@@ -139,8 +131,10 @@ void TreeSocket::SendCapabilities(int phase)
                SetOurChallenge(ServerInstance->GenRandomStr(20));
                extra = " CHALLENGE=" + this->GetOurChallenge();
        }
-       if (proto_version < 1202)
-               extra += ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL) ? " HALFOP=1" : " HALFOP=0";
+
+       // 2.0 needs this key
+       if (proto_version == 1202)
+               extra.append(" PROTOCOL="+ConvToStr(ProtocolVersion));
 
        this->WriteLine("CAPAB CAPABILITIES " /* Preprocessor does this one. */
                        ":NICKMAX="+ConvToStr(ServerInstance->Config->Limits.NickMax)+
@@ -152,12 +146,11 @@ void TreeSocket::SendCapabilities(int phase)
                        " MAXKICK="+ConvToStr(ServerInstance->Config->Limits.MaxKick)+
                        " MAXGECOS="+ConvToStr(ServerInstance->Config->Limits.MaxGecos)+
                        " MAXAWAY="+ConvToStr(ServerInstance->Config->Limits.MaxAway)+
-                       " IP6SUPPORT=1"+
-                       " PROTOCOL="+ConvToStr(ProtocolVersion)+extra+
+                       extra+
                        " PREFIX="+ServerInstance->Modes->BuildPrefixes()+
                        " CHANMODES="+ServerInstance->Modes->GiveModeList(MASK_CHANNEL)+
-                       " USERMODES="+ServerInstance->Modes->GiveModeList(MASK_USER)+
-                       " SVSPART=1");
+                       " USERMODES="+ServerInstance->Modes->GiveModeList(MASK_USER)
+                       );
 
        this->WriteLine("CAPAB END");
 }
@@ -202,7 +195,23 @@ bool TreeSocket::Capab(const parameterlist &params)
                capab->OptModuleList.clear();
                capab->CapKeys.clear();
                if (params.size() > 1)
-                       proto_version = atoi(params[1].c_str());
+                       proto_version = ConvToInt(params[1]);
+
+               if (proto_version < MinCompatProtocol)
+               {
+                       SendError("CAPAB negotiation failed: Server is using protocol version " + (proto_version ? ConvToStr(proto_version) : "1201 or older")
+                               + " which is too old to link with this server (version " + ConvToStr(ProtocolVersion)
+                               + (ProtocolVersion != MinCompatProtocol ? ", links with " + ConvToStr(MinCompatProtocol) + " and above)" : ")"));
+                       return false;
+               }
+
+               // Special case, may be removed in the future
+               if (proto_version == 1203 || proto_version == 1204)
+               {
+                       SendError("CAPAB negotiation failed: InspIRCd 2.1 beta is not supported");
+                       return false;
+               }
+
                SendCapabilities(2);
        }
        else if (params[0] == "END")
@@ -212,7 +221,7 @@ bool TreeSocket::Capab(const parameterlist &params)
                if ((this->capab->ModuleList != this->MyModules(VF_COMMON)) && (this->capab->ModuleList.length()))
                {
                        std::string diffIneed, diffUneed;
-                       ListDifference(this->capab->ModuleList, this->MyModules(VF_COMMON), proto_version > 1201 ? ' ' : ',', diffIneed, diffUneed);
+                       ListDifference(this->capab->ModuleList, this->MyModules(VF_COMMON), ', diffIneed, diffUneed);
                        if (diffIneed.length() || diffUneed.length())
                        {
                                reason = "Modules incorrectly matched on these servers.";
@@ -250,21 +259,6 @@ bool TreeSocket::Capab(const parameterlist &params)
                        }
                }
 
-               if (this->capab->CapKeys.find("PROTOCOL") == this->capab->CapKeys.end())
-               {
-                       reason = "Protocol version not specified";
-               }
-               else
-               {
-                       proto_version = atoi(capab->CapKeys.find("PROTOCOL")->second.c_str());
-                       if (proto_version < MinCompatProtocol)
-                       {
-                               reason = "Server is using protocol version " + ConvToStr(proto_version) +
-                                       " which is too old to link with this server (version " + ConvToStr(ProtocolVersion)
-                                       + (ProtocolVersion != MinCompatProtocol ? ", links with " + ConvToStr(MinCompatProtocol) + " and above)" : ")");
-                       }
-               }
-
                if(this->capab->CapKeys.find("PREFIX") != this->capab->CapKeys.end() && this->capab->CapKeys.find("PREFIX")->second != ServerInstance->Modes->BuildPrefixes())
                        reason = "One or more of the prefixes on the remote server are invalid on this server.";
 
@@ -348,7 +342,7 @@ bool TreeSocket::Capab(const parameterlist &params)
                }
                else
                {
-                       capab->ModuleList.push_back(proto_version > 1201 ? ' ' : ',');
+                       capab->ModuleList.push_back(');
                        capab->ModuleList.append(params[1]);
                }
        }
index 3b5b499c11d8cf8d3f3c83e2a6c9060f88720e22..dd54b5b6bd2bad3117d6d9690be544751ad3fb5e 100644 (file)
@@ -17,8 +17,7 @@
  */
 
 
-#ifndef M_SPANNINGTREE_COMMANDS_H
-#define M_SPANNINGTREE_COMMANDS_H
+#pragma once
 
 #include "main.h"
 
@@ -40,7 +39,6 @@ class CommandRSQuit : public Command
         CommandRSQuit(Module* Callback, SpanningTreeUtilities* Util);
         CmdResult Handle (const std::vector<std::string>& parameters, User *user);
                RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
-        void NoticeUser(User* user, const std::string &msg);
 };
 
 class CommandSVSJoin : public Command
@@ -85,16 +83,19 @@ class CommandOpertype : public Command
        CmdResult Handle (const std::vector<std::string>& parameters, User *user);
        RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_BROADCAST; }
 };
+class TreeSocket;
 class CommandFJoin : public Command
 {
+       /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
+        * This does not update the timestamp of the target channel, this must be done seperately.
+        */
+       static void RemoveStatus(Channel* c);
+       static void ApplyModeStack(User* srcuser, Channel* c, irc::modestacker& stack);
+       bool ProcessModeUUIDPair(const std::string& item, TreeSocket* src_socket, Channel* chan, irc::modestacker* modestack);
  public:
        CommandFJoin(Module* Creator) : Command(Creator, "FJOIN", 3) { flags_needed = FLAG_SERVERONLY; }
        CmdResult Handle (const std::vector<std::string>& parameters, User *user);
        RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_BROADCAST; }
-       /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
-        * This does not update the timestamp of the target channel, this must be done seperately.
-        */
-       void RemoveStatus(User* source, parameterlist &params);
 };
 class CommandFMode : public Command
 {
@@ -106,7 +107,7 @@ class CommandFMode : public Command
 class CommandFTopic : public Command
 {
  public:
-       CommandFTopic(Module* Creator) : Command(Creator, "FTOPIC", 4) { flags_needed = FLAG_SERVERONLY; }
+       CommandFTopic(Module* Creator) : Command(Creator, "FTOPIC", 5) { flags_needed = FLAG_SERVERONLY; }
        CmdResult Handle (const std::vector<std::string>& parameters, User *user);
        RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_BROADCAST; }
 };
@@ -132,6 +133,21 @@ class CommandFName : public Command
        RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_BROADCAST; }
 };
 
+class CommandIJoin : public SplitCommand
+{
+ public:
+       CommandIJoin(Module* Creator) : SplitCommand(Creator, "IJOIN", 1) { flags_needed = FLAG_SERVERONLY; }
+       CmdResult HandleRemote(const std::vector<std::string>& parameters, RemoteUser* user);
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_BROADCAST; }
+};
+
+class CommandResync : public SplitCommand
+{
+ public:
+       CommandResync(Module* Creator) : SplitCommand(Creator, "RESYNC", 1) { flags_needed = FLAG_SERVERONLY; }
+       CmdResult HandleServer(const std::vector<std::string>& parameters, FakeUser* user);
+};
+
 class SpanningTreeCommands
 {
  public:
@@ -144,6 +160,8 @@ class SpanningTreeCommands
        CommandUID uid;
        CommandOpertype opertype;
        CommandFJoin fjoin;
+       CommandIJoin ijoin;
+       CommandResync resync;
        CommandFMode fmode;
        CommandFTopic ftopic;
        CommandFHost fhost;
@@ -151,5 +169,3 @@ class SpanningTreeCommands
        CommandFName fname;
        SpanningTreeCommands(ModuleSpanningTree* module);
 };
-
-#endif
index ec0cdb03661d3e99a45d15a6487828d0e59bded1..17266afe9a6a933c7bc8332e544cae16a744f5da 100644 (file)
 #include "inspircd.h"
 #include "main.h"
 #include "treesocket.h"
+#include "treeserver.h"
 
-static const char* const forge_common_1201[] = {
-       "m_allowinvite.so",
-       "m_alltime.so",
-       "m_auditorium.so",
-       "m_banexception.so",
-       "m_blockcaps.so",
-       "m_blockcolor.so",
-       "m_botmode.so",
-       "m_censor.so",
-       "m_chanfilter.so",
-       "m_chanhistory.so",
-       "m_channelban.so",
-       "m_chanprotect.so",
-       "m_chghost.so",
-       "m_chgname.so",
-       "m_commonchans.so",
-       "m_customtitle.so",
-       "m_deaf.so",
-       "m_delayjoin.so",
-       "m_delaymsg.so",
-       "m_exemptchanops.so",
-       "m_gecosban.so",
-       "m_globops.so",
-       "m_helpop.so",
-       "m_hidechans.so",
-       "m_hideoper.so",
-       "m_invisible.so",
-       "m_inviteexception.so",
-       "m_joinflood.so",
-       "m_kicknorejoin.so",
-       "m_knock.so",
-       "m_messageflood.so",
-       "m_muteban.so",
-       "m_nickflood.so",
-       "m_nicklock.so",
-       "m_noctcp.so",
-       "m_nokicks.so",
-       "m_nonicks.so",
-       "m_nonotice.so",
-       "m_nopartmsg.so",
-       "m_ojoin.so",
-       "m_operprefix.so",
-       "m_permchannels.so",
-       "m_redirect.so",
-       "m_regex_glob.so",
-       "m_regex_pcre.so",
-       "m_regex_posix.so",
-       "m_regex_tre.so",
-       "m_remove.so",
-       "m_sajoin.so",
-       "m_sakick.so",
-       "m_sanick.so",
-       "m_sapart.so",
-       "m_saquit.so",
-       "m_serverban.so",
-       "m_services_account.so",
-       "m_servprotect.so",
-       "m_setident.so",
-       "m_showwhois.so",
-       "m_silence.so",
-       "m_sslmodes.so",
-       "m_stripcolor.so",
-       "m_swhois.so",
-       "m_uninvite.so",
-       "m_watch.so"
-};
-
-static std::string wide_newline("\r\n");
 static std::string newline("\n");
 
-void TreeSocket::CompatAddModules(std::vector<std::string>& modlist)
-{
-       if (proto_version < 1202)
-       {
-               // you MUST have chgident loaded in order to be able to translate FIDENT
-               modlist.push_back("m_chgident.so");
-               for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++)
-               {
-                       if (ServerInstance->Modules->Find(forge_common_1201[i]))
-                               modlist.push_back(forge_common_1201[i]);
-               }
-               // module was merged
-               if (ServerInstance->Modules->Find("m_operchans.so"))
-               {
-                       modlist.push_back("m_operchans.so");
-                       modlist.push_back("m_operinvex.so");
-               }
-       }
-}
-
 void TreeSocket::WriteLine(std::string line)
 {
        if (LinkState == CONNECTED)
        {
                if (line[0] != ':')
                {
-                       ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!");
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Sending line without server prefix!");
                        line = ":" + ServerInstance->Config->GetSID() + " " + line;
                }
                if (proto_version != ProtocolVersion)
@@ -127,70 +40,185 @@ void TreeSocket::WriteLine(std::string line)
                        std::string command = line.substr(a + 1, b-a-1);
                        // now try to find a translation entry
                        // TODO a more efficient lookup method will be needed later
-                       if (proto_version < 1202 && command == "FIDENT")
-                       {
-                               ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server");
-                               line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " +  line.substr(1,a-1) + line.substr(b);
-                       }
-                       else if (proto_version < 1202 && command == "SAVE")
-                       {
-                               ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting SAVE for 1201-protocol server");
-                               std::string::size_type c = line.find(' ', b + 1);
-                               std::string uid = line.substr(b, c - b);
-                               line = ":" + ServerInstance->Config->GetSID() + " SVSNICK" + uid + line.substr(b);
-                       }
-                       else if (proto_version < 1202 && command == "AWAY")
+                       if (proto_version < 1205)
                        {
-                               if (b != std::string::npos)
+                               if (command == "IJOIN")
                                {
-                                       ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Stripping AWAY timestamp for 1201-protocol server");
+                                       // Convert
+                                       // :<uid> IJOIN <chan> [<ts> [<flags>]]
+                                       // to
+                                       // :<sid> FJOIN <chan> <ts> + [<flags>],<uuid>
                                        std::string::size_type c = line.find(' ', b + 1);
-                                       line.erase(b,c-b);
+                                       if (c == std::string::npos)
+                                       {
+                                               // No TS or modes in the command
+                                               // :22DAAAAAB IJOIN #chan
+                                               const std::string channame = line.substr(b+1, c-b-1);
+                                               Channel* chan = ServerInstance->FindChan(channame);
+                                               if (!chan)
+                                                       return;
+
+                                               line.push_back(' ');
+                                               line.append(ConvToStr(chan->age));
+                                               line.append(" + ,");
+                                       }
+                                       else
+                                       {
+                                               std::string::size_type d = line.find(' ', c + 1);
+                                               if (d == std::string::npos)
+                                               {
+                                                       // TS present, no modes
+                                                       // :22DAAAAAC IJOIN #chan 12345
+                                                       line.append(" + ,");
+                                               }
+                                               else
+                                               {
+                                                       // Both TS and modes are present
+                                                       // :22DAAAAAC IJOIN #chan 12345 ov
+                                                       std::string::size_type e = line.find(' ', d + 1);
+                                                       if (e != std::string::npos)
+                                                               line.erase(e);
+
+                                                       line.insert(d, " +");
+                                                       line.push_back(',');
+                                               }
+                                       }
+
+                                       // Move the uuid to the end and replace the I with an F
+                                       line.append(line.substr(1, 9));
+                                       line.erase(4, 6);
+                                       line[5] = 'F';
                                }
-                       }
-                       else if (proto_version < 1202 && command == "ENCAP")
-                       {
-                               // :src ENCAP target command [args...]
-                               //     A     B      C       D
-                               // Therefore B and C cannot be npos in a valid command
-                               if (b == std::string::npos)
+                               else if (command == "RESYNC")
                                        return;
-                               std::string::size_type c = line.find(' ', b + 1);
-                               if (c == std::string::npos)
-                                       return;
-                               std::string::size_type d = line.find(' ', c + 1);
-                               std::string subcmd = line.substr(c + 1, d - c - 1);
+                               else if (command == "METADATA")
+                               {
+                                       // Drop TS for channel METADATA
+                                       // :sid METADATA #target TS extname ...
+                                       //     A        B       C  D
+                                       if (b == std::string::npos)
+                                               return;
 
-                               if (subcmd == "CHGIDENT" && d != std::string::npos)
+                                       std::string::size_type c = line.find(' ', b + 1);
+                                       if (c == std::string::npos)
+                                               return;
+
+                                       if (line[b + 1] == '#')
+                                       {
+                                               // We're sending channel metadata
+                                               std::string::size_type d = line.find(' ', c + 1);
+                                               if (d == std::string::npos)
+                                                       return;
+
+                                               line.erase(c, d-c);
+                                       }
+                               }
+                               else if (command == "FTOPIC")
                                {
-                                       std::string::size_type e = line.find(' ', d + 1);
-                                       if (e == std::string::npos)
-                                               return; // not valid
-                                       std::string target = line.substr(d + 1, e - d - 1);
+                                       // Drop channel TS for FTOPIC
+                                       // :sid FTOPIC #target TS TopicTS ...
+                                       //     A      B       C  D
+                                       if (b == std::string::npos)
+                                               return;
 
-                                       ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Forging acceptance of CHGIDENT from 1201-protocol server");
-                                       recvq.insert(0, ":" + target + " FIDENT " + line.substr(e) + "\n");
+                                       std::string::size_type c = line.find(' ', b + 1);
+                                       if (c == std::string::npos)
+                                               return;
+
+                                       std::string::size_type d = line.find(' ', c + 1);
+                                       if (d == std::string::npos)
+                                               return;
+
+                                       line.erase(c, d-c);
                                }
+                               else if ((command == "PING") || (command == "PONG"))
+                               {
+                                       // :22D PING 20D
+                                       if (line.length() < 13)
+                                               return;
 
-                               Command* thiscmd = ServerInstance->Parser->GetHandler(subcmd);
-                               if (thiscmd && subcmd != "WHOISNOTICE")
+                                       // Insert the source SID (and a space) between the command and the first parameter
+                                       line.insert(10, line.substr(1, 4));
+                               }
+                               else if (command == "OPERTYPE")
                                {
-                                       Version ver = thiscmd->creator->GetVersion();
-                                       if (ver.Flags & VF_OPTCOMMON)
+                                       std::string::size_type colon = line.find(':', b);
+                                       if (colon != std::string::npos)
                                        {
-                                               ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Removing ENCAP on '%s' for 1201-protocol server",
-                                                       subcmd.c_str());
-                                               line.erase(a, c-a);
+                                               for (std::string::iterator i = line.begin()+colon; i != line.end(); ++i)
+                                               {
+                                                       if (*i == ' ')
+                                                               *i = '_';
+                                               }
+                                               line.erase(colon, 1);
                                        }
                                }
                        }
                }
        }
 
-       ServerInstance->Logs->Log("m_spanningtree", RAWIO, "S[%d] O %s", this->GetFd(), line.c_str());
+       ServerInstance->Logs->Log("m_spanningtree", LOG_RAWIO, "S[%d] O %s", this->GetFd(), line.c_str());
        this->WriteData(line);
-       if (proto_version < 1202)
-               this->WriteData(wide_newline);
-       else
-               this->WriteData(newline);
+       this->WriteData(newline);
+}
+
+namespace
+{
+       bool InsertCurrentChannelTS(std::vector<std::string>& params)
+       {
+               Channel* chan = ServerInstance->FindChan(params[0]);
+               if (!chan)
+                       return false;
+
+               // Insert the current TS of the channel between the first and the second parameters
+               params.insert(params.begin()+1, ConvToStr(chan->age));
+               return true;
+       }
+}
+
+bool TreeSocket::PreProcessOldProtocolMessage(User*& who, std::string& cmd, std::vector<std::string>& params)
+{
+       if ((cmd == "METADATA") && (params.size() >= 3))
+       {
+               // :20D METADATA #channel extname :extdata
+               return InsertCurrentChannelTS(params);
+       }
+       else if ((cmd == "FTOPIC") && (params.size() >= 4))
+       {
+               // :20D FTOPIC #channel 100 Attila :topic text
+               return InsertCurrentChannelTS(params);
+       }
+       else if ((cmd == "PING") || (cmd == "PONG"))
+       {
+               if (params.size() == 1)
+               {
+                       // If it's a PING with 1 parameter, reply with a PONG now, if it's a PONG with 1 parameter (weird), do nothing
+                       if (cmd[1] == 'I')
+                               this->WriteData(":" + ServerInstance->Config->GetSID() + " PONG " + params[0] + newline);
+
+                       // Don't process this message further
+                       return false;
+               }
+
+               // :20D PING 20D 22D
+               // :20D PONG 20D 22D
+               // Drop the first parameter
+               params.erase(params.begin());
+
+               // If the target is a server name, translate it to a SID
+               if (!InspIRCd::IsSID(params[0]))
+               {
+                       TreeServer* server = Utils->FindServer(params[0]);
+                       if (!server)
+                       {
+                               // We've no idea what this is, log and stop processing
+                               ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Received a " + cmd + " with an unknown target: \"" + params[0] + "\", command dropped");
+                               return false;
+                       }
+
+                       params[0] = server->GetID();
+               }
+       }
+
+       return true; // Passthru
 }
index dabfc086bce5542b138d4638b074b8edbfd0acfe..fedadedb5d9ce60970e98c613969e9fe3fa3d35d 100644 (file)
@@ -21,7 +21,6 @@
 #include "xline.h"
 
 #include "treesocket.h"
-#include "treeserver.h"
 #include "utils.h"
 
 /** ENCAP */
@@ -35,7 +34,7 @@ void TreeSocket::Encap(User* who, parameterlist &params)
                        ServerInstance->Parser->CallHandler(params[1], plist, who);
                        // discard return value, ENCAP shall succeed even if the command does not exist
                }
-               
+
                params[params.size() - 1] = ":" + params[params.size() - 1];
 
                if (params[0].find_first_of("*?") != std::string::npos)
index c0475613afece31941cd93a2f9766bdc2d2ab5de..b25444cdacc657878566c602c4f607e602311eda 100644 (file)
@@ -29,7 +29,7 @@
 CmdResult CommandFJoin::Handle(const std::vector<std::string>& params, User *srcuser)
 {
        SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
-       /* 1.1 FJOIN works as follows:
+       /* 1.1+ FJOIN works as follows:
         *
         * Each FJOIN is sent along with a timestamp, and the side with the lowest
         * timestamp 'wins'. From this point on we will refer to this side as the
@@ -54,184 +54,175 @@ CmdResult CommandFJoin::Handle(const std::vector<std::string>& params, User *src
         * The winning side on the other hand will ignore all user modes from the
         * losing side, so only its own modes get applied. Life is simple for those
         * who succeed at internets. :-)
+        *
+        * Syntax:
+        * :<sid> FJOIN <chan> <TS> <modes> :[[modes,]<uuid> [[modes,]<uuid> ... ]]
+        * The last parameter is a list consisting of zero or more (modelist, uuid)
+        * pairs (permanent channels may have zero users). The mode list for each
+        * user is a concatenation of the mode letters the user has on the channel
+        * (e.g.: "ov" if the user is opped and voiced). The order of the mode letters
+        * are not important but if a server ecounters an unknown mode letter, it will
+        * drop the link to avoid desync.
+        *
+        * InspIRCd 2.0 and older required a comma before the uuid even if the user
+        * had no prefix modes on the channel, InspIRCd 2.2 and later does not require
+        * a comma in this case anymore.
+        *
         */
 
-       irc::modestacker modestack(true);                       /* Modes to apply from the users in the user list */
-       User* who = NULL;                                               /* User we are currently checking */
-       std::string channel = params[0];                                /* Channel name, as a string */
-       time_t TS = atoi(params[1].c_str());                            /* Timestamp given to us for remote side */
-       irc::tokenstream users((params.size() > 3) ? params[params.size() - 1] : "");   /* users from the user list */
-       bool apply_other_sides_modes = true;                            /* True if we are accepting the other side's modes */
-       Channel* chan = ServerInstance->FindChan(channel);              /* The channel we're sending joins to */
-       bool created = !chan;                                           /* True if the channel doesnt exist here yet */
-       std::string item;                                               /* One item in the list of nicks */
-
-       TreeSocket* src_socket = Utils->FindServer(srcuser->server)->GetRoute()->GetSocket();
-
+       time_t TS = ConvToInt(params[1]);
        if (!TS)
        {
-               ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"*** BUG? *** TS of 0 sent to FJOIN. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "*** BUG? *** TS of 0 sent to FJOIN. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
                ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FJOIN with a TS of zero. Total craq. Command was dropped.", srcuser->server.c_str());
                return CMD_INVALID;
        }
 
-       if (created)
+       const std::string& channel = params[0];
+       Channel* chan = ServerInstance->FindChan(channel);
+       bool apply_other_sides_modes = true;
+
+       if (!chan)
        {
                chan = new Channel(channel, TS);
-               ServerInstance->SNO->WriteToSnoMask('d', "Creation FJOIN received for %s, timestamp: %lu", chan->name.c_str(), (unsigned long)TS);
        }
        else
        {
                time_t ourTS = chan->age;
-
                if (TS != ourTS)
+               {
                        ServerInstance->SNO->WriteToSnoMask('d', "Merge FJOIN received for %s, ourTS: %lu, TS: %lu, difference: %lu",
                                chan->name.c_str(), (unsigned long)ourTS, (unsigned long)TS, (unsigned long)(ourTS - TS));
-               /* If our TS is less than theirs, we dont accept their modes */
-               if (ourTS < TS)
-               {
-                       ServerInstance->SNO->WriteToSnoMask('d', "NOT Applying modes from other side");
-                       apply_other_sides_modes = false;
-               }
-               else if (ourTS > TS)
-               {
-                       /* Our TS greater than theirs, clear all our modes from the channel, accept theirs. */
-                       ServerInstance->SNO->WriteToSnoMask('d', "Removing our modes, accepting remote");
-                       parameterlist param_list;
-                       if (Utils->AnnounceTSChange)
-                               chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :TS for %s changed from %lu to %lu", chan->name.c_str(), channel.c_str(), (unsigned long) ourTS, (unsigned long) TS);
-                       // while the name is equal in case-insensitive compare, it might differ in case; use the remote version
-                       chan->name = channel;
-                       chan->age = TS;
-                       chan->ClearInvites();
-                       param_list.push_back(channel);
-                       this->RemoveStatus(ServerInstance->FakeClient, param_list);
-
-                       // XXX: If the channel does not exist in the chan hash at this point, create it so the remote modes can be applied on it.
-                       // This happens to 0-user permanent channels on the losing side, because those are removed (from the chan hash, then
-                       // deleted later) as soon as the permchan mode is removed from them.
-                       if (ServerInstance->FindChan(channel) == NULL)
+                       /* If our TS is less than theirs, we dont accept their modes */
+                       if (ourTS < TS)
                        {
-                               chan = new Channel(channel, TS);
+                               apply_other_sides_modes = false;
+                       }
+                       else if (ourTS > TS)
+                       {
+                               /* Our TS greater than theirs, clear all our modes from the channel, accept theirs. */
+                               if (Utils->AnnounceTSChange)
+                                       chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :TS for %s changed from %lu to %lu", chan->name.c_str(), channel.c_str(), (unsigned long) ourTS, (unsigned long) TS);
+
+                               // while the name is equal in case-insensitive compare, it might differ in case; use the remote version
+                               chan->name = channel;
+                               chan->age = TS;
+                               chan->ClearInvites();
+
+                               CommandFJoin::RemoveStatus(chan);
+
+                               // XXX: If the channel does not exist in the chan hash at this point, create it so the remote modes can be applied on it.
+                               // This happens to 0-user permanent channels on the losing side, because those are removed (from the chan hash, then
+                               // deleted later) as soon as the permchan mode is removed from them.
+                               if (ServerInstance->FindChan(channel) == NULL)
+                               {
+                                       chan = new Channel(channel, TS);
+                               }
                        }
                }
-               // The silent case here is ourTS == TS, we don't need to remove modes here, just to merge them later on.
        }
 
-       /* First up, apply their modes if they won the TS war */
+       /* First up, apply their channel modes if they won the TS war */
        if (apply_other_sides_modes)
        {
-               unsigned int idx = 2;
                std::vector<std::string> modelist;
+               modelist.push_back(channel);
 
-               // Mode parser needs to know what channel to act on.
-               modelist.push_back(params[0]);
-
-               /* Remember, params[params.size() - 1] is nicklist, and we don't want to apply *that* */
-               for (idx = 2; idx != (params.size() - 1); idx++)
-               {
-                       modelist.push_back(params[idx]);
-               }
-
+               /* Remember, params[params.size() - 1] is userlist, and we don't want to apply *that* */
+               modelist.insert(modelist.end(), params.begin()+2, params.end()-1);
                ServerInstance->SendMode(modelist, srcuser);
        }
 
-       /* Now, process every 'modes,nick' pair */
+       irc::modestacker modestack(true);
+       TreeSocket* src_socket = Utils->FindServer(srcuser->server)->GetRoute()->GetSocket();
+
+       /* Now, process every 'modes,uuid' pair */
+       irc::tokenstream users(*params.rbegin());
+       std::string item;
+       irc::modestacker* modestackptr = (apply_other_sides_modes ? &modestack : NULL);
        while (users.GetToken(item))
        {
-               const char* usr = item.c_str();
-               if (usr && *usr)
-               {
-                       const char* unparsedmodes = usr;
-                       std::string modes;
-
-
-                       /* Iterate through all modes for this user and check they are valid. */
-                       while ((*unparsedmodes) && (*unparsedmodes != ','))
-                       {
-                               ModeHandler *mh = ServerInstance->Modes->FindMode(*unparsedmodes, MODETYPE_CHANNEL);
-                               if (!mh)
-                               {
-                                       ServerInstance->Logs->Log("m_spanningtree", SPARSE, "Unrecognised mode %c, dropping link", *unparsedmodes);
-                                       return CMD_INVALID;
-                               }
-
-                               modes += *unparsedmodes;
-                               usr++;
-                               unparsedmodes++;
-                       }
+               if (!ProcessModeUUIDPair(item, src_socket, chan, modestackptr))
+                       return CMD_INVALID;
+       }
 
-                       /* Advance past the comma, to the nick */
-                       usr++;
+       /* Flush mode stacker if we lost the FJOIN or had equal TS */
+       if (apply_other_sides_modes)
+               CommandFJoin::ApplyModeStack(srcuser, chan, modestack);
 
-                       /* Check the user actually exists */
-                       who = ServerInstance->FindUUID(usr);
-                       if (who)
-                       {
-                               /* Check that the user's 'direction' is correct */
-                               TreeServer* route_back_again = Utils->BestRouteTo(who->server);
-                               if ((!route_back_again) || (route_back_again->GetSocket() != src_socket))
-                                       continue;
+       return CMD_SUCCESS;
+}
 
-                               /* Add any modes this user had to the mode stack */
-                               for (std::string::iterator x = modes.begin(); x != modes.end(); ++x)
-                                       modestack.Push(*x, who->nick);
+bool CommandFJoin::ProcessModeUUIDPair(const std::string& item, TreeSocket* src_socket, Channel* chan, irc::modestacker* modestack)
+{
+       std::string::size_type comma = item.find(',');
 
-                               Channel::JoinUser(who, channel.c_str(), true, "", route_back_again->bursting, TS);
-                       }
-                       else
-                       {
-                               ServerInstance->Logs->Log("m_spanningtree",SPARSE, "Ignored nonexistant user %s in fjoin to %s (probably quit?)", usr, channel.c_str());
-                               continue;
-                       }
-               }
+       // Comma not required anymore if the user has no modes
+       std::string uuid = ((comma == std::string::npos) ? item : item.substr(comma+1));
+       User* who = ServerInstance->FindUUID(uuid);
+       if (!who)
+       {
+               // Probably KILLed, ignore
+               return true;
        }
 
-       /* Flush mode stacker if we lost the FJOIN or had equal TS */
-       if (apply_other_sides_modes)
+       /* Check that the user's 'direction' is correct */
+       SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
+       TreeServer* route_back_again = Utils->BestRouteTo(who->server);
+       if ((!route_back_again) || (route_back_again->GetSocket() != src_socket))
        {
-               parameterlist stackresult;
-               stackresult.push_back(channel);
+               return true;
+       }
 
-               while (modestack.GetStackedLine(stackresult))
+       /* Check if the user received at least one mode */
+       if ((modestack) && (comma > 0) && (comma != std::string::npos))
+       {
+               /* Iterate through the modes and see if they are valid here, if so, apply */
+               std::string::const_iterator commait = item.begin()+comma;
+               for (std::string::const_iterator i = item.begin(); i != commait; ++i)
                {
-                       ServerInstance->SendMode(stackresult, srcuser);
-                       stackresult.erase(stackresult.begin() + 1, stackresult.end());
+                       if (!ServerInstance->Modes->FindMode(*i, MODETYPE_CHANNEL))
+                       {
+                               ServerInstance->SNO->WriteToSnoMask('d', "Unrecognised mode '%c' for a user in FJOIN, dropping link", *i);
+                               return false;
+                       }
+
+                       /* Add any modes this user had to the mode stack */
+                       modestack->Push(*i, who->nick);
                }
        }
-       return CMD_SUCCESS;
+
+       chan->ForceJoin(who, NULL, route_back_again->bursting);
+       return true;
 }
 
-void CommandFJoin::RemoveStatus(User* srcuser, parameterlist &params)
+void CommandFJoin::RemoveStatus(Channel* c)
 {
-       if (params.size() < 1)
-               return;
-
-       Channel* c = ServerInstance->FindChan(params[0]);
+       irc::modestacker stack(false);
 
-       if (c)
+       for (char modeletter = 'A'; modeletter <= 'z'; ++modeletter)
        {
-               irc::modestacker stack(false);
-               parameterlist stackresult;
-               stackresult.push_back(c->name);
+               ModeHandler* mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
+
+               /* Passing a pointer to a modestacker here causes the mode to be put onto the mode stack,
+                * rather than applied immediately. Module unloads require this to be done immediately,
+                * for this function we require tidyness instead. Fixes bug #493
+                */
+               if (mh)
+                       mh->RemoveMode(c, stack);
+       }
 
-               for (char modeletter = 'A'; modeletter <= 'z'; ++modeletter)
-               {
-                       ModeHandler* mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
-
-                       /* Passing a pointer to a modestacker here causes the mode to be put onto the mode stack,
-                        * rather than applied immediately. Module unloads require this to be done immediately,
-                        * for this function we require tidyness instead. Fixes bug #493
-                        */
-                       if (mh)
-                               mh->RemoveMode(c, &stack);
-               }
+       ApplyModeStack(ServerInstance->FakeClient, c, stack);
+}
 
-               while (stack.GetStackedLine(stackresult))
-               {
-                       ServerInstance->SendMode(stackresult, srcuser);
-                       stackresult.erase(stackresult.begin() + 1, stackresult.end());
-               }
+void CommandFJoin::ApplyModeStack(User* srcuser, Channel* c, irc::modestacker& stack)
+{
+       parameterlist stackresult;
+       stackresult.push_back(c->name);
+
+       while (stack.GetStackedLine(stackresult))
+       {
+               ServerInstance->SendMode(stackresult, srcuser);
+               stackresult.erase(stackresult.begin() + 1, stackresult.end());
        }
 }
-
index c1e452db627bd28d0a647609536eb75d396c8248..7be904faf7552bb10b2185cc25989f507f2c2b9f 100644 (file)
 #include "inspircd.h"
 #include "commands.h"
 
-#include "treesocket.h"
-#include "treeserver.h"
-#include "utils.h"
-
 /** FMODE command - server mode with timestamp checks */
 CmdResult CommandFMode::Handle(const std::vector<std::string>& params, User *who)
 {
-       std::string sourceserv = who->server;
-
-       std::vector<std::string> modelist;
-       time_t TS = 0;
-       for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
+       time_t TS = ConvToInt(params[1]);
+       if (!TS)
        {
-               if (q == 1)
-               {
-                       /* The timestamp is in this position.
-                        * We don't want to pass that up to the
-                        * server->client protocol!
-                        */
-                       TS = atoi(params[q].c_str());
-               }
-               else
-               {
-                       /* Everything else is fine to append to the modelist */
-                       modelist.push_back(params[q]);
-               }
-
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "*** BUG? *** TS of 0 sent to FMODE. Are some services authors smoking craq, or is it 1970 again?. Dropping link.");
+               ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq, dropping link.", who->server.c_str());
+               return CMD_INVALID;
        }
-       /* Extract the TS value of the object, either User or Channel */
-       User* dst = ServerInstance->FindNick(params[0]);
-       Channel* chan = NULL;
-       time_t ourTS = 0;
 
-       if (dst)
+       /* Extract the TS value of the object, either User or Channel */
+       time_t ourTS;
+       if (params[0][0] == '#')
        {
-               ourTS = dst->age;
+               Channel* chan = ServerInstance->FindChan(params[0]);
+               if (!chan)
+                       /* Oops, channel doesn't exist! */
+                       return CMD_FAILURE;
+
+               ourTS = chan->age;
        }
        else
        {
-               chan = ServerInstance->FindChan(params[0]);
-               if (chan)
-               {
-                       ourTS = chan->age;
-               }
-               else
-                       /* Oops, channel doesnt exist! */
+               User* user = ServerInstance->FindUUID(params[0]);
+               if (!user)
                        return CMD_FAILURE;
-       }
 
-       if (!TS)
-       {
-               ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"*** BUG? *** TS of 0 sent to FMODE. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
-               ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
-               return CMD_INVALID;
+               if (IS_SERVER(user))
+                       return CMD_INVALID;
+
+               ourTS = user->age;
        }
 
        /* TS is equal or less: Merge the mode changes into ours and pass on.
         */
        if (TS <= ourTS)
        {
+               std::vector<std::string> modelist;
+               modelist.reserve(params.size()-1);
+               /* Insert everything into modelist except the TS (params[1]) */
+               modelist.push_back(params[0]);
+               modelist.insert(modelist.end(), params.begin()+2, params.end());
+
                bool merge = (TS == ourTS) && IS_SERVER(who);
                ServerInstance->Modes->Process(modelist, who, merge);
                return CMD_SUCCESS;
index d559c6ae5c642bb3ba8f23bd9f03c489a390f443..69d3af56520c7e72f3601799b28073e49bbfd056 100644 (file)
 #include "inspircd.h"
 #include "commands.h"
 
-#include "treesocket.h"
-#include "treeserver.h"
-#include "utils.h"
-
 /** FTOPIC command */
 CmdResult CommandFTopic::Handle(const std::vector<std::string>& params, User *user)
 {
-       time_t ts = atoi(params[1].c_str());
        Channel* c = ServerInstance->FindChan(params[0]);
-       if (c)
+       if (!c)
+               return CMD_FAILURE;
+
+       time_t ChanTS = ConvToInt(params[1]);
+       if (!ChanTS)
+               return CMD_INVALID;
+
+       if (c->age < ChanTS)
+               // Our channel TS is older, nothing to do
+               return CMD_FAILURE;
+
+       time_t ts = ConvToInt(params[2]);
+       if (!ts)
+               return CMD_INVALID;
+
+       // Channel::topicset is initialized to 0 on channel creation, so their ts will always win if we never had a topic
+       if (ts < c->topicset)
+               return CMD_FAILURE;
+
+       /*
+        * If the topics were updated at the exact same second, accept
+        * the remote only when it's "bigger" than ours as defined by
+        * string comparision, so non-empty topics always overridde
+        * empty topics if their timestamps are equal
+        */
+       if ((ts == c->topicset) && (c->topic > params[4]))
+               return CMD_FAILURE; // Topics were set at the exact same time, keep our topic and setter
+
+       if (c->topic != params[4])
        {
-               if ((ts >= c->topicset) || (c->topic.empty()))
-               {
-                       if (c->topic != params[3])
-                       {
-                               // Update topic only when it differs from current topic
-                               c->topic.assign(params[3], 0, ServerInstance->Config->Limits.MaxTopic);
-                               c->WriteChannel(user, "TOPIC %s :%s", c->name.c_str(), c->topic.c_str());
-                       }
-
-                       // Always update setter and settime.
-                       c->setby.assign(params[2], 0, 127);
-                       c->topicset = ts;
-               }
+               // Update topic only when it differs from current topic
+               c->topic.assign(params[4], 0, ServerInstance->Config->Limits.MaxTopic);
+               c->WriteChannel(user, "TOPIC %s :%s", c->name.c_str(), c->topic.c_str());
        }
+
+       // Update setter and settime
+       c->setby.assign(params[3], 0, 127);
+       c->topicset = ts;
+
        return CMD_SUCCESS;
 }
 
index d990e1fbf4dfa1c680fbbc9640660e7896ccdfd2..ad632dbc7057c3c4bcf491619cfd71cff12f590f 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "../hash.h"
-#include "../ssl.h"
-#include "socketengine.h"
+#include "modules/hash.h"
+#include "modules/ssl.h"
 
 #include "main.h"
-#include "utils.h"
-#include "treeserver.h"
 #include "link.h"
 #include "treesocket.h"
-#include "resolvers.h"
 
 const std::string& TreeSocket::GetOurChallenge()
 {
@@ -62,39 +56,10 @@ std::string TreeSocket::MakePass(const std::string &password, const std::string
         */
        HashProvider* sha256 = ServerInstance->Modules->FindDataService<HashProvider>("hash/sha256");
        if (Utils->ChallengeResponse && sha256 && !challenge.empty())
-       {
-               if (proto_version < 1202)
-               {
-                       /* This is how HMAC is done in InspIRCd 1.2:
-                        *
-                        * sha256( (pass xor 0x5c) + sha256((pass xor 0x36) + m) )
-                        *
-                        * 5c and 36 were chosen as part of the HMAC standard, because they
-                        * flip the bits in a way likely to strengthen the function.
-                        */
-                       std::string hmac1, hmac2;
-
-                       for (size_t n = 0; n < password.length(); n++)
-                       {
-                               hmac1.push_back(static_cast<char>(password[n] ^ 0x5C));
-                               hmac2.push_back(static_cast<char>(password[n] ^ 0x36));
-                       }
-
-                       hmac2.append(challenge);
-                       hmac2 = sha256->hexsum(hmac2);
-               
-                       std::string hmac = hmac1 + hmac2;
-                       hmac = sha256->hexsum(hmac);
+               return "AUTH:" + BinToBase64(sha256->hmac(password, challenge));
 
-                       return "HMAC-SHA256:"+ hmac;
-               }
-               else
-               {
-                       return "AUTH:" + BinToBase64(sha256->hmac(password, challenge));
-               }
-       }
-       else if (!challenge.empty() && !sha256)
-               ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Not authenticating to server using SHA256/HMAC because we don't have m_sha256 loaded!");
+       if (!challenge.empty() && !sha256)
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Not authenticating to server using SHA256/HMAC because we don't have m_sha256 loaded!");
 
        return password;
 }
index 8bc0cd2bbfff9b5a65d5128deb4df1e2cad1cb81..bf074bf7fcfc91a5e449ae8dc21b06a8d5a268fb 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
-
-#include "main.h"
 #include "utils.h"
-#include "treeserver.h"
 #include "treesocket.h"
 
 bool TreeSocket::Whois(const std::string &prefix, parameterlist &params)
 {
        if (params.size() < 1)
                return true;
-       User* u = ServerInstance->FindNick(prefix);
-       if (u)
+
+       /* If this is a request, this user did the /whois
+        * If this is a reply, this user's information is in params[1] and params[2]
+        */
+       User* issuer = ServerInstance->FindUUID(prefix);
+       if ((!issuer) || (IS_SERVER(issuer)))
+               return true;
+
+       /* If this is a request, this is the user whose idle information was requested
+        * If this is a reply, this user did the /whois
+        */
+       User* target = ServerInstance->FindUUID(params[0]);
+       if ((!target) || (IS_SERVER(target)))
+               return true;
+
+       LocalUser* localtarget = IS_LOCAL(target);
+       if (!localtarget)
        {
-               // an incoming request
-               if (params.size() == 1)
-               {
-                       User* x = ServerInstance->FindNick(params[0]);
-                       if ((x) && (IS_LOCAL(x)))
-                       {
-                               long idle = abs((long)((x->idle_lastmsg) - ServerInstance->Time()));
-                               parameterlist par;
-                               par.push_back(prefix);
-                               par.push_back(ConvToStr(x->signon));
-                               par.push_back(ConvToStr(idle));
-                               // ours, we're done, pass it BACK
-                               Utils->DoOneToOne(params[0], "IDLE", par, u->server);
-                       }
-                       else
-                       {
-                               // not ours pass it on
-                               if (x)
-                                       Utils->DoOneToOne(prefix, "IDLE", params, x->server);
-                       }
-               }
-               else if (params.size() == 3)
-               {
-                       std::string who_did_the_whois = params[0];
-                       User* who_to_send_to = ServerInstance->FindNick(who_did_the_whois);
-                       if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
-                       {
-                               // an incoming reply to a whois we sent out
-                               std::string nick_whoised = prefix;
-                               unsigned long signon = atoi(params[1].c_str());
-                               unsigned long idle = atoi(params[2].c_str());
-                               if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
-                               {
-                                       ServerInstance->DoWhois(who_to_send_to, u, signon, idle, nick_whoised.c_str());
-                               }
-                       }
-                       else
-                       {
-                               // not ours, pass it on
-                               if (who_to_send_to)
-                                       Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
-                       }
-               }
+               // Forward to target's server
+               Utils->DoOneToOne(prefix, "IDLE", params, target->server);
+               return true;
        }
-       return true;
-}
 
+       if (params.size() >= 2)
+       {
+               ServerInstance->Parser->CallHandler("WHOIS", params, issuer);
+       }
+       else
+       {
+               // A server is asking us the idle time of our user
+               unsigned int idle;
+               if (localtarget->idle_lastmsg >= ServerInstance->Time())
+                       // Possible case when our clock ticked backwards
+                       idle = 0;
+               else
+                       idle = ((unsigned int) (localtarget->idle_lastmsg - ServerInstance->Time()));
+
+               parameterlist reply;
+               reply.push_back(prefix);
+               reply.push_back(ConvToStr(target->signon));
+               reply.push_back(ConvToStr(idle));
+               Utils->DoOneToOne(params[0], "IDLE", reply, issuer->server);
+       }
 
+       return true;
+}
diff --git a/src/modules/m_spanningtree/ijoin.cpp b/src/modules/m_spanningtree/ijoin.cpp
new file mode 100644 (file)
index 0000000..2f71ffe
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+#include "commands.h"
+#include "utils.h"
+#include "treeserver.h"
+#include "treesocket.h"
+
+CmdResult CommandIJoin::HandleRemote(const std::vector<std::string>& params, RemoteUser* user)
+{
+       Channel* chan = ServerInstance->FindChan(params[0]);
+       if (!chan)
+       {
+               // Desync detected, recover
+               // Ignore the join and send RESYNC, this will result in the remote server sending all channel data to us
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Received IJOIN for non-existant channel: " + params[0]);
+
+               parameterlist p;
+               p.push_back(params[0]);
+               SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
+               Utils->DoOneToOne(ServerInstance->Config->GetSID(), "RESYNC", p, user->server);
+
+               return CMD_FAILURE;
+       }
+
+       bool apply_modes;
+       if (params.size() > 1)
+       {
+               time_t RemoteTS = ConvToInt(params[1]);
+               if (!RemoteTS)
+               {
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Invalid TS in IJOIN: " + params[1]);
+                       return CMD_INVALID;
+               }
+
+               if (RemoteTS < chan->age)
+               {
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Attempted to lower TS via IJOIN. Channel=" + params[0] + " RemoteTS=" + params[1] + " LocalTS=" + ConvToStr(chan->age));
+                       return CMD_INVALID;
+               }
+               apply_modes = ((params.size() > 2) && (RemoteTS == chan->age));
+       }
+       else
+               apply_modes = false;
+
+       chan->ForceJoin(user, apply_modes ? &params[2] : NULL);
+       return CMD_SUCCESS;
+}
+
+CmdResult CommandResync::HandleServer(const std::vector<std::string>& params, FakeUser* user)
+{
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Resyncing " + params[0]);
+       Channel* chan = ServerInstance->FindChan(params[0]);
+       if (!chan)
+       {
+               // This can happen for a number of reasons, safe to ignore
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Channel does not exist");
+               return CMD_FAILURE;
+       }
+
+       SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
+       TreeServer* server = Utils->FindServer(user->server);
+       if (!server)
+               return CMD_FAILURE;
+
+       TreeSocket* socket = server->GetSocket();
+       if (!socket)
+       {
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Received RESYNC with a source that is not directly connected: " + user->uuid);
+               return CMD_INVALID;
+       }
+
+       // Send all known information about the channel
+       socket->SyncChannel(chan);
+       return CMD_SUCCESS;
+}
index 797f108d86588ca3efe3f0495e66c3eb0073481e..b318c9bf2d65b2ab3ad564db5bdb00cfa45eb316 100644 (file)
@@ -18,8 +18,7 @@
  */
 
 
-#ifndef M_SPANNINGTREE_LINK_H
-#define M_SPANNINGTREE_LINK_H
+#pragma once
 
 class Link : public refcountbase
 {
@@ -51,5 +50,3 @@ class Autoconnect : public refcountbase
        int position;
        Autoconnect(ConfigTag* Tag) : tag(Tag) {}
 };
-
-#endif
index 7c93e7d45555054967de8c8d03e41bf5449c598b..aafda7eeaf640b9776b3f79b8e1d7e83395a8a5f 100644 (file)
@@ -27,7 +27,6 @@
 #include "socket.h"
 #include "xline.h"
 
-#include "cachetimer.h"
 #include "resolvers.h"
 #include "main.h"
 #include "utils.h"
 #include "protocolinterface.h"
 
 ModuleSpanningTree::ModuleSpanningTree()
+       : commands(NULL), DNS(this, "DNS"), Utils(NULL)
 {
-       Utils = new SpanningTreeUtilities(this);
-       commands = new SpanningTreeCommands(this);
-       RefreshTimer = NULL;
 }
 
 SpanningTreeCommands::SpanningTreeCommands(ModuleSpanningTree* module)
        : rconnect(module, module->Utils), rsquit(module, module->Utils),
        svsjoin(module), svspart(module), svsnick(module), metadata(module),
-       uid(module), opertype(module), fjoin(module), fmode(module), ftopic(module),
-       fhost(module), fident(module), fname(module)
+       uid(module), opertype(module), fjoin(module), ijoin(module), resync(module),
+       fmode(module), ftopic(module), fhost(module), fident(module), fname(module)
 {
 }
 
 void ModuleSpanningTree::init()
 {
+       Utils = new SpanningTreeUtilities(this);
+       commands = new SpanningTreeCommands(this);
        ServerInstance->Modules->AddService(commands->rconnect);
        ServerInstance->Modules->AddService(commands->rsquit);
        ServerInstance->Modules->AddService(commands->svsjoin);
@@ -63,18 +62,18 @@ void ModuleSpanningTree::init()
        ServerInstance->Modules->AddService(commands->uid);
        ServerInstance->Modules->AddService(commands->opertype);
        ServerInstance->Modules->AddService(commands->fjoin);
+       ServerInstance->Modules->AddService(commands->ijoin);
+       ServerInstance->Modules->AddService(commands->resync);
        ServerInstance->Modules->AddService(commands->fmode);
        ServerInstance->Modules->AddService(commands->ftopic);
        ServerInstance->Modules->AddService(commands->fhost);
        ServerInstance->Modules->AddService(commands->fident);
        ServerInstance->Modules->AddService(commands->fname);
-       RefreshTimer = new CacheRefreshTimer(Utils);
-       ServerInstance->Timers->AddTimer(RefreshTimer);
 
        Implementation eventlist[] =
        {
                I_OnPreCommand, I_OnGetServerDescription, I_OnUserInvite, I_OnPostTopicChange,
-               I_OnWallops, I_OnUserNotice, I_OnUserMessage, I_OnBackgroundTimer, I_OnUserJoin,
+               I_OnUserMessage, I_OnBackgroundTimer, I_OnUserJoin,
                I_OnChangeHost, I_OnChangeName, I_OnChangeIdent, I_OnUserPart, I_OnUnloadModule,
                I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash, I_OnPreRehash,
                I_OnOper, I_OnAddLine, I_OnDelLine, I_OnMode, I_OnLoadModule, I_OnStats,
@@ -87,7 +86,7 @@ void ModuleSpanningTree::init()
        loopCall = false;
 
        // update our local user count
-       Utils->TreeRoot->SetUserCount(ServerInstance->Users->local_users.size());
+       Utils->TreeRoot->UserCount = ServerInstance->Users->local_users.size();
 }
 
 void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
@@ -101,7 +100,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
        {
                if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName()))))
                {
-                       if (IS_OPER(user))
+                       if (user->IsOper())
                        {
                                 ShowLinks(Current->GetChild(q),user,hops+1);
                        }
@@ -112,16 +111,16 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
                }
        }
        /* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */
-       if ((Utils->HideULines) && (ServerInstance->ULine(Current->GetName())) && (!IS_OPER(user)))
+       if ((Utils->HideULines) && (ServerInstance->ULine(Current->GetName())) && (!user->IsOper()))
                return;
        /* Or if the server is hidden and they're not an oper */
-       else if ((Current->Hidden) && (!IS_OPER(user)))
+       else if ((Current->Hidden) && (!user->IsOper()))
                return;
 
        std::string servername = Current->GetName();
        user->WriteNumeric(364, "%s %s %s :%d %s",      user->nick.c_str(), servername.c_str(),
-                       (Utils->FlatLinks && (!IS_OPER(user))) ? ServerInstance->Config->ServerName.c_str() : Parent.c_str(),
-                       (Utils->FlatLinks && (!IS_OPER(user))) ? 0 : hops,
+                       (Utils->FlatLinks && (!user->IsOper())) ? ServerInstance->Config->ServerName.c_str() : Parent.c_str(),
+                       (Utils->FlatLinks && (!user->IsOper())) ? 0 : hops,
                        Current->GetDesc().c_str());
 }
 
@@ -194,8 +193,7 @@ restart:
                                        // ... if we can find a proper route to them
                                        if (tsock)
                                        {
-                                               tsock->WriteLine(":" + ServerInstance->Config->GetSID() + " PING " +
-                                                               ServerInstance->Config->GetSID() + " " + s->GetID());
+                                               tsock->WriteLine(":" + ServerInstance->Config->GetSID() + " PING " + s->GetID());
                                                s->LastPingMsec = ts;
                                        }
                                }
@@ -271,7 +269,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
                return;
        }
 
-       QueryType start_type = DNS_QUERY_AAAA;
+       DNS::QueryType start_type = DNS::QUERY_AAAA;
        if (strchr(x->IPAddr.c_str(),':'))
        {
                in6_addr n;
@@ -301,16 +299,20 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
                        ServerInstance->GlobalCulls.AddItem(newsocket);
                }
        }
+       else if (!DNS)
+       {
+               ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Hostname given and m_dns.so is not loaded, unable to resolve.", x->Name.c_str());
+       }
        else
        {
+               ServernameResolver* snr = new ServernameResolver(Utils, *DNS, x->IPAddr, x, start_type, y);
                try
                {
-                       bool cached = false;
-                       ServernameResolver* snr = new ServernameResolver(Utils, x->IPAddr, x, cached, start_type, y);
-                       ServerInstance->AddResolver(snr, cached);
+                       DNS->Process(snr);
                }
-               catch (ModuleException& e)
+               catch (DNS::Exception& e)
                {
+                       delete snr;
                        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
                        ConnectServer(y, false);
                }
@@ -359,12 +361,13 @@ ModResult ModuleSpanningTree::HandleVersion(const std::vector<std::string>& para
        TreeServer* found = Utils->FindServerMask(parameters[0]);
        if (found)
        {
-               std::string Version = found->GetVersion();
-               user->WriteNumeric(351, "%s :%s",user->nick.c_str(),Version.c_str());
                if (found == Utils->TreeRoot)
                {
-                       ServerInstance->Config->Send005(user);
+                       // Pass to default VERSION handler.
+                       return MOD_RES_PASSTHRU;
                }
+               std::string Version = found->GetVersion();
+               user->WriteNumeric(351, "%s :%s",user->nick.c_str(),Version.c_str());
        }
        else
        {
@@ -377,15 +380,11 @@ ModResult ModuleSpanningTree::HandleVersion(const std::vector<std::string>& para
  */
 void ModuleSpanningTree::RemoteMessage(User* user, const char* format, ...)
 {
-       char text[MAXBUF];
-       va_list argsPtr;
-
-       va_start(argsPtr, format);
-       vsnprintf(text, MAXBUF, format, argsPtr);
-       va_end(argsPtr);
+       std::string text;
+       VAFORMAT(text, format, format);
 
        if (IS_LOCAL(user))
-               user->WriteServ("NOTICE %s :%s", user->nick.c_str(), text);
+               user->WriteNotice(text);
        else
                ServerInstance->PI->SendUserNotice(user, text);
 }
@@ -455,118 +454,40 @@ void ModuleSpanningTree::OnPostTopicChange(User* user, Channel* chan, const std:
        Utils->DoOneToMany(user->uuid,"TOPIC",params);
 }
 
-void ModuleSpanningTree::OnWallops(User* user, const std::string &text)
+void ModuleSpanningTree::LocalMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, const char* message_type)
 {
-       if (IS_LOCAL(user))
-       {
-               parameterlist params;
-               params.push_back(":"+text);
-               Utils->DoOneToMany(user->uuid,"WALLOPS",params);
-       }
-}
-
-void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
-{
-       /* Server origin */
-       if (user == NULL)
+       /* Server or remote origin, dest should always be non-null */
+       if ((!user) || (!IS_LOCAL(user)) || (!dest))
                return;
 
        if (target_type == TYPE_USER)
        {
-               User* d = (User*)dest;
-               if (!IS_LOCAL(d) && IS_LOCAL(user))
+               User* d = (User*) dest;
+               if (!IS_LOCAL(d))
                {
                        parameterlist params;
                        params.push_back(d->uuid);
                        params.push_back(":"+text);
-                       Utils->DoOneToOne(user->uuid,"NOTICE",params,d->server);
+                       Utils->DoOneToOne(user->uuid, message_type, params, d->server);
                }
        }
        else if (target_type == TYPE_CHANNEL)
        {
-               if (IS_LOCAL(user))
-               {
-                       Channel *c = (Channel*)dest;
-                       if (c)
-                       {
-                               std::string cname = c->name;
-                               if (status)
-                                       cname = status + cname;
-                               TreeServerList list;
-                               Utils->GetListOfServersForChannel(c,list,status,exempt_list);
-                               for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
-                               {
-                                       TreeSocket* Sock = i->second->GetSocket();
-                                       if (Sock)
-                                               Sock->WriteLine(":"+std::string(user->uuid)+" NOTICE "+cname+" :"+text);
-                               }
-                       }
-               }
+               Utils->SendChannelMessage(user->uuid, (Channel*)dest, text, status, exempt_list, message_type);
        }
        else if (target_type == TYPE_SERVER)
        {
-               if (IS_LOCAL(user))
-               {
-                       char* target = (char*)dest;
-                       parameterlist par;
-                       par.push_back(target);
-                       par.push_back(":"+text);
-                       Utils->DoOneToMany(user->uuid,"NOTICE",par);
-               }
+               char* target = (char*) dest;
+               parameterlist par;
+               par.push_back(target);
+               par.push_back(":"+text);
+               Utils->DoOneToMany(user->uuid, message_type, par);
        }
 }
 
-void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
+void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string& text, char status, const CUList& exempt_list, MessageType msgtype)
 {
-       /* Server origin */
-       if (user == NULL)
-               return;
-
-       if (target_type == TYPE_USER)
-       {
-               // route private messages which are targetted at clients only to the server
-               // which needs to receive them
-               User* d = (User*)dest;
-               if (!IS_LOCAL(d) && (IS_LOCAL(user)))
-               {
-                       parameterlist params;
-                       params.push_back(d->uuid);
-                       params.push_back(":"+text);
-                       Utils->DoOneToOne(user->uuid,"PRIVMSG",params,d->server);
-               }
-       }
-       else if (target_type == TYPE_CHANNEL)
-       {
-               if (IS_LOCAL(user))
-               {
-                       Channel *c = (Channel*)dest;
-                       if (c)
-                       {
-                               std::string cname = c->name;
-                               if (status)
-                                       cname = status + cname;
-                               TreeServerList list;
-                               Utils->GetListOfServersForChannel(c,list,status,exempt_list);
-                               for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
-                               {
-                                       TreeSocket* Sock = i->second->GetSocket();
-                                       if (Sock)
-                                               Sock->WriteLine(":"+std::string(user->uuid)+" PRIVMSG "+cname+" :"+text);
-                               }
-                       }
-               }
-       }
-       else if (target_type == TYPE_SERVER)
-       {
-               if (IS_LOCAL(user))
-               {
-                       char* target = (char*)dest;
-                       parameterlist par;
-                       par.push_back(target);
-                       par.push_back(":"+text);
-                       Utils->DoOneToMany(user->uuid,"PRIVMSG",par);
-               }
-       }
+       LocalMessage(user, dest, target_type, text, status, exempt_list, (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE"));
 }
 
 void ModuleSpanningTree::OnBackgroundTimer(time_t curtime)
@@ -594,10 +515,11 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user)
        params.push_back(":"+user->fullname);
        Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params);
 
-       if (IS_OPER(user))
+       if (user->IsOper())
        {
                params.clear();
-               params.push_back(user->oper->name);
+               params.push_back(":");
+               params[0].append(user->oper->name);
                Utils->DoOneToMany(user->uuid,"OPERTYPE",params);
        }
 
@@ -609,23 +531,32 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user)
                        ServerInstance->PI->SendMetaData(user, item->name, value);
        }
 
-       Utils->TreeRoot->SetUserCount(1); // increment by 1
+       Utils->TreeRoot->UserCount++;
 }
 
-void ModuleSpanningTree::OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
+void ModuleSpanningTree::OnUserJoin(Membership* memb, bool sync, bool created_by_local, CUList& excepts)
 {
        // Only do this for local users
        if (IS_LOCAL(memb->user))
        {
                parameterlist params;
-               // set up their permissions and the channel TS with FJOIN.
-               // All users are FJOINed now, because a module may specify
-               // new joining permissions for the user.
                params.push_back(memb->chan->name);
-               params.push_back(ConvToStr(memb->chan->age));
-               params.push_back(std::string("+") + memb->chan->ChanModes(true));
-               params.push_back(memb->modes+","+memb->user->uuid);
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params);
+               if (created_by_local)
+               {
+                       params.push_back(ConvToStr(memb->chan->age));
+                       params.push_back(std::string("+") + memb->chan->ChanModes(true));
+                       params.push_back(memb->modes+","+memb->user->uuid);
+                       Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params);
+               }
+               else
+               {
+                       if (!memb->modes.empty())
+                       {
+                               params.push_back(ConvToStr(memb->chan->age));
+                               params.push_back(memb->modes);
+                       }
+                       Utils->DoOneToMany(memb->user->uuid, "IJOIN", params);
+               }
        }
 }
 
@@ -691,7 +622,7 @@ void ModuleSpanningTree::OnUserQuit(User* user, const std::string &reason, const
        TreeServer* SourceServer = Utils->FindServer(user->server);
        if (SourceServer)
        {
-               SourceServer->SetUserCount(-1); // decrement by 1
+               SourceServer->UserCount--;
        }
 }
 
@@ -755,7 +686,7 @@ void ModuleSpanningTree::OnPreRehash(User* user, const std::string &parameter)
        if (loopCall)
                return; // Don't generate a REHASH here if we're in the middle of processing a message that generated this one
 
-       ServerInstance->Logs->Log("remoterehash", DEBUG, "called with param %s", parameter.c_str());
+       ServerInstance->Logs->Log("remoterehash", LOG_DEBUG, "called with param %s", parameter.c_str());
 
        // Send out to other servers
        if (!parameter.empty() && parameter[0] != '-')
@@ -825,7 +756,8 @@ void ModuleSpanningTree::OnOper(User* user, const std::string &opertype)
        if (user->registered != REG_ALL || !IS_LOCAL(user))
                return;
        parameterlist params;
-       params.push_back(opertype);
+       params.push_back(":");
+       params[0].append(opertype);
        Utils->DoOneToMany(user->uuid,"OPERTYPE",params);
 }
 
@@ -948,7 +880,7 @@ void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, con
        if (u)
                s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
        else if (c)
-               s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata);
+               s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+ConvToStr(c->age)+" "+extname+" :"+extdata);
        else if (!target)
                s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
 }
@@ -956,7 +888,6 @@ void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, con
 CullResult ModuleSpanningTree::cull()
 {
        Utils->cull();
-       ServerInstance->Timers->DelTimer(RefreshTimer);
        return this->Module::cull();
 }
 
index ae6e2e602d1b08432598665773bccf4078f3ff0a..21e4e156a0392d46f929adf3b73ab02bf944404f 100644 (file)
  */
 
 
-#ifndef M_SPANNINGTREE_MAIN_H
-#define M_SPANNINGTREE_MAIN_H
+#pragma once
 
 #include "inspircd.h"
-#include <stdarg.h>
 
+#include "modules/dns.h"
 /** If you make a change which breaks the protocol, increment this.
  * If you  completely change the protocol, completely change the number.
  *
@@ -36,8 +35,8 @@
  * Failure to document your protocol changes will result in a painfully
  * painful death by pain. You have been warned.
  */
-const long ProtocolVersion = 1202;
-const long MinCompatProtocol = 1201;
+const long ProtocolVersion = 1205;
+const long MinCompatProtocol = 1202;
 
 /** Forward declarations
  */
@@ -53,11 +52,13 @@ class Autoconnect;
 class ModuleSpanningTree : public Module
 {
        SpanningTreeCommands* commands;
+       void LocalMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, const char* message_type);
 
  public:
+       dynamic_reference<DNS::Manager> DNS;
+
        SpanningTreeUtilities* Utils;
 
-       CacheRefreshTimer *RefreshTimer;
        /** Set to true if inside a spanningtree call, to prevent sending
         * xlines and other things back to their source
         */
@@ -66,7 +67,7 @@ class ModuleSpanningTree : public Module
        /** Constructor
         */
        ModuleSpanningTree();
-       void init();
+       void init() CXX11_OVERRIDE;
 
        /** Shows /LINKS
         */
@@ -140,43 +141,39 @@ class ModuleSpanningTree : public Module
         ** *** MODULE EVENTS ***
         **/
 
-       ModResult OnPreCommand(std::string &command, std::vector<std::string>& parameters, LocalUser *user, bool validated, const std::string &original_line);
-       void OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, LocalUser *user, CmdResult result, const std::string &original_line);
-       void OnGetServerDescription(const std::string &servername,std::string &description);
-       void OnUserConnect(LocalUser* source);
-       void OnUserInvite(User* source,User* dest,Channel* channel, time_t);
-       void OnPostTopicChange(User* user, Channel* chan, const std::string &topic);
-       void OnWallops(User* user, const std::string &text);
-       void OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list);
-       void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list);
-       void OnBackgroundTimer(time_t curtime);
-       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts);
-       void OnChangeHost(User* user, const std::string &newhost);
-       void OnChangeName(User* user, const std::string &gecos);
-       void OnChangeIdent(User* user, const std::string &ident);
-       void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts);
-       void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message);
-       void OnUserPostNick(User* user, const std::string &oldnick);
-       void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts);
-       void OnRemoteKill(User* source, User* dest, const std::string &reason, const std::string &operreason);
-       void OnPreRehash(User* user, const std::string &parameter);
-       void OnRehash(User* user);
-       void OnOper(User* user, const std::string &opertype);
+       ModResult OnPreCommand(std::string &command, std::vector<std::string>& parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE;
+       void OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, LocalUser *user, CmdResult result, const std::string &original_line) CXX11_OVERRIDE;
+       void OnGetServerDescription(const std::string &servername,std::string &description) CXX11_OVERRIDE;
+       void OnUserConnect(LocalUser* source) CXX11_OVERRIDE;
+       void OnUserInvite(User* source,User* dest,Channel* channel, time_t) CXX11_OVERRIDE;
+       void OnPostTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE;
+       void OnUserMessage(User* user, void* dest, int target_type, const std::string& text, char status, const CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
+       void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE;
+       void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE;
+       void OnChangeHost(User* user, const std::string &newhost) CXX11_OVERRIDE;
+       void OnChangeName(User* user, const std::string &gecos) CXX11_OVERRIDE;
+       void OnChangeIdent(User* user, const std::string &ident) CXX11_OVERRIDE;
+       void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE;
+       void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE;
+       void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE;
+       void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE;
+       void OnRemoteKill(User* source, User* dest, const std::string &reason, const std::string &operreason) CXX11_OVERRIDE;
+       void OnPreRehash(User* user, const std::string &parameter) CXX11_OVERRIDE;
+       void OnRehash(User* user) CXX11_OVERRIDE;
+       void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE;
        void OnLine(User* source, const std::string &host, bool adding, char linetype, long duration, const std::string &reason);
-       void OnAddLine(User *u, XLine *x);
-       void OnDelLine(User *u, XLine *x);
-       void OnMode(User* user, void* dest, int target_type, const std::vector<std::string> &text, const std::vector<TranslateType> &translate);
-       ModResult OnStats(char statschar, User* user, string_list &results);
-       ModResult OnSetAway(User* user, const std::string &awaymsg);
+       void OnAddLine(User *u, XLine *x) CXX11_OVERRIDE;
+       void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
+       void OnMode(User* user, void* dest, int target_type, const std::vector<std::string> &text, const std::vector<TranslateType> &translate) CXX11_OVERRIDE;
+       ModResult OnStats(char statschar, User* user, string_list &results) CXX11_OVERRIDE;
+       ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE;
        void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::vector<std::string> &modeline, const std::vector<TranslateType> &translate);
        void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
-       void OnLoadModule(Module* mod);
-       void OnUnloadModule(Module* mod);
-       ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
+       void OnLoadModule(Module* mod) CXX11_OVERRIDE;
+       void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
+       ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;
        CullResult cull();
        ~ModuleSpanningTree();
-       Version GetVersion();
+       Version GetVersion() CXX11_OVERRIDE;
        void Prioritize();
 };
-
-#endif
index a584f8fa8b6fcd8494d3c44537e8a324617e5184..9709ca54cb1752ae7cac9ef246d4a03890c019a7 100644 (file)
 #include "inspircd.h"
 #include "commands.h"
 
-#include "treesocket.h"
-#include "treeserver.h"
-#include "utils.h"
-
 CmdResult CommandMetadata::Handle(const std::vector<std::string>& params, User *srcuser)
 {
-       std::string value = params.size() < 3 ? "" : params[2];
-       ExtensionItem* item = ServerInstance->Extensions.GetItem(params[1]);
        if (params[0] == "*")
        {
+               std::string value = params.size() < 3 ? "" : params[2];
                FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(NULL,params[1],value));
+               return CMD_SUCCESS;
        }
-       else if (*(params[0].c_str()) == '#')
+
+       if (params[0][0] == '#')
        {
+               // Channel METADATA has an additional parameter: the channel TS
+               // :22D METADATA #channel 12345 extname :extdata
+               if (params.size() < 3)
+                       return CMD_INVALID;
+
                Channel* c = ServerInstance->FindChan(params[0]);
-               if (c)
-               {
-                       if (item)
-                               item->unserialize(FORMAT_NETWORK, c, value);
-                       FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(c,params[1],value));
-               }
+               if (!c)
+                       return CMD_FAILURE;
+
+               time_t ChanTS = ConvToInt(params[1]);
+               if (!ChanTS)
+                       return CMD_INVALID;
+
+               if (c->age < ChanTS)
+                       // Their TS is newer than ours, discard this command and do not propagate
+                       return CMD_FAILURE;
+
+               std::string value = params.size() < 4 ? "" : params[3];
+
+               ExtensionItem* item = ServerInstance->Extensions.GetItem(params[2]);
+               if (item)
+                       item->unserialize(FORMAT_NETWORK, c, value);
+               FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(c,params[2],value));
        }
-       else if (*(params[0].c_str()) != '#')
+       else
        {
                User* u = ServerInstance->FindUUID(params[0]);
                if ((u) && (!IS_SERVER(u)))
                {
+                       ExtensionItem* item = ServerInstance->Extensions.GetItem(params[1]);
+                       std::string value = params.size() < 3 ? "" : params[2];
+
                        if (item)
                                item->unserialize(FORMAT_NETWORK, u, value);
                        FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(u,params[1],value));
index d508c092dd00fea08c6fb87a365fb8b64e6da736..8daaefd8ad489eac1467971f7c1ff1d144b5a454 100644 (file)
 
 #include "inspircd.h"
 #include "xline.h"
+#include "listmode.h"
 
 #include "treesocket.h"
 #include "treeserver.h"
-#include "utils.h"
 #include "main.h"
 
 /** This function is called when we want to send a netburst to a local
@@ -44,27 +44,27 @@ void TreeSocket::DoBurst(TreeServer* s)
        /* send our version string */
        this->WriteLine(":" + ServerInstance->Config->GetSID() + " VERSION :"+ServerInstance->GetVersionString());
        /* Send server tree */
-       this->SendServers(Utils->TreeRoot,s,1);
+       this->SendServers(Utils->TreeRoot, s);
        /* Send users and their oper status */
        this->SendUsers();
-       /* Send everything else (channel modes, xlines etc) */
-       this->SendChannelModes();
+
+       for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
+               SyncChannel(i->second);
+
        this->SendXLines();
        FOREACH_MOD(I_OnSyncNetwork,OnSyncNetwork(Utils->Creator,(void*)this));
        this->WriteLine(":" + ServerInstance->Config->GetSID() + " ENDBURST");
        ServerInstance->SNO->WriteToSnoMask('l',"Finished bursting to \2"+ s->GetName()+"\2.");
 }
 
-/** Recursively send the server tree with distances as hops.
+/** Recursively send the server tree.
  * This is used during network burst to inform the other server
  * (and any of ITS servers too) of what servers we know about.
  * If at any point any of these servers already exist on the other
- * end, our connection may be terminated. The hopcounts given
- * by this function are relative, this doesn't matter so long as
- * they are all >1, as all the remote servers re-calculate them
- * to be relative too, with themselves as hop 0.
+ * end, our connection may be terminated.
+ * The hopcount parameter (3rd) is deprecated, and is always 0.
  */
-void TreeSocket::SendServers(TreeServer* Current, TreeServer* s, int hops)
+void TreeSocket::SendServers(TreeServer* Current, TreeServer* s)
 {
        char command[MAXBUF];
        for (unsigned int q = 0; q < Current->ChildCount(); q++)
@@ -73,13 +73,13 @@ void TreeSocket::SendServers(TreeServer* Current, TreeServer* s, int hops)
                if (recursive_server != s)
                {
                        std::string recursive_servername = recursive_server->GetName();
-                       snprintf(command, MAXBUF, ":%s SERVER %s * %d %s :%s", Current->GetID().c_str(), recursive_servername.c_str(), hops,
+                       snprintf(command, MAXBUF, ":%s SERVER %s * 0 %s :%s", Current->GetID().c_str(), recursive_servername.c_str(),
                                        recursive_server->GetID().c_str(),
                                        recursive_server->GetDesc().c_str());
                        this->WriteLine(command);
                        this->WriteLine(":"+recursive_server->GetID()+" VERSION :"+recursive_server->GetVersion());
                        /* down to next level */
-                       this->SendServers(recursive_server, s, hops+1);
+                       this->SendServers(recursive_server, s);
                }
        }
 }
@@ -87,101 +87,48 @@ void TreeSocket::SendServers(TreeServer* Current, TreeServer* s, int hops)
 /** Send one or more FJOINs for a channel of users.
  * If the length of a single line is more than 480-NICKMAX
  * in length, it is split over multiple lines.
+ * Send one or more FMODEs for a channel with the
+ * channel bans, if there's any.
  */
 void TreeSocket::SendFJoins(Channel* c)
 {
-       std::string buffer;
-       char list[MAXBUF];
-
-       size_t curlen, headlen;
-       curlen = headlen = snprintf(list,MAXBUF,":%s FJOIN %s %lu +%s :",
-               ServerInstance->Config->GetSID().c_str(), c->name.c_str(), (unsigned long)c->age, c->ChanModes(true));
-       int numusers = 0;
-       char* ptr = list + curlen;
-       bool looped_once = false;
+       std::string line(":");
+       line.append(ServerInstance->Config->GetSID()).append(" FJOIN ").append(c->name).append(1, ' ').append(ConvToStr(c->age)).append(" +");
+       std::string::size_type erase_from = line.length();
+       line.append(c->ChanModes(true)).append(" :");
 
        const UserMembList *ulist = c->GetUsers();
-       std::string modes;
-       std::string params;
-
-       for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
-       {
-               size_t ptrlen = 0;
-               std::string modestr = i->second->modes;
-
-               if ((curlen + modestr.length() + i->first->uuid.length() + 4) > 480)
-               {
-                       // remove the final space
-                       if (ptr[-1] == ' ')
-                               ptr[-1] = '\0';
-                       buffer.append(list).append("\r\n");
-                       curlen = headlen;
-                       ptr = list + headlen;
-                       numusers = 0;
-               }
-
-               ptrlen = snprintf(ptr, MAXBUF-curlen, "%s,%s ", modestr.c_str(), i->first->uuid.c_str());
-
-               looped_once = true;
-
-               curlen += ptrlen;
-               ptr += ptrlen;
-
-               numusers++;
-       }
-
-       // Okay, permanent channels will (of course) need this \r\n anyway, numusers check is if there
-       // actually were people in the channel (looped_once == true)
-       if (!looped_once || numusers > 0)
-       {
-               // remove the final space
-               if (ptr[-1] == ' ')
-                       ptr[-1] = '\0';
-               buffer.append(list).append("\r\n");
-       }
 
-       int linesize = 1;
-       for (BanList::iterator b = c->bans.begin(); b != c->bans.end(); b++)
+       for (UserMembCIter i = ulist->begin(); i != ulist->end(); ++i)
        {
-               int size = b->data.length() + 2;
-               int currsize = linesize + size;
-               if (currsize <= 350)
-               {
-                       modes.append("b");
-                       params.append(" ").append(b->data);
-                       linesize += size;
-               }
-               if ((modes.length() >= ServerInstance->Config->Limits.MaxModes) || (currsize > 350))
+               const std::string& modestr = i->second->modes;
+               if ((line.length() + modestr.length() + UIDGenerator::UUID_LENGTH + 2) > 480)
                {
-                       /* Wrap at MAXMODES */
-                       buffer.append(":").append(ServerInstance->Config->GetSID()).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params).append("\r\n");
-                       modes.clear();
-                       params.clear();
-                       linesize = 1;
+                       this->WriteLine(line);
+                       line.erase(erase_from);
+                       line.append(" :");
                }
+               line.append(modestr).append(1, ',').append(i->first->uuid).push_back(' ');
        }
+       this->WriteLine(line);
 
-       /* Only send these if there are any */
-       if (!modes.empty())
-               buffer.append(":").append(ServerInstance->Config->GetSID()).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params);
-
-       this->WriteLine(buffer);
+       ModeReference ban(NULL, "ban");
+       static_cast<ListModeBase*>(*ban)->DoSyncChannel(c, Utils->Creator, this);
 }
 
 /** Send all XLines we know about */
 void TreeSocket::SendXLines()
 {
        char data[MAXBUF];
-       std::string n = ServerInstance->Config->GetSID();
-       const char* sn = n.c_str();
 
        std::vector<std::string> types = ServerInstance->XLines->GetAllTypes();
-       time_t current = ServerInstance->Time();
 
-       for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); ++it)
+       for (std::vector<std::string>::const_iterator it = types.begin(); it != types.end(); ++it)
        {
+               /* Expired lines are removed in XLineManager::GetAll() */
                XLineLookup* lookup = ServerInstance->XLines->GetAll(*it);
 
+               /* lookup cannot be NULL in this case but a check won't hurt */
                if (lookup)
                {
                        for (LookupIter i = lookup->begin(); i != lookup->end(); ++i)
@@ -192,12 +139,10 @@ void TreeSocket::SendXLines()
                                if (!i->second->IsBurstable())
                                        break;
 
-                               /* If it's expired, don't bother to burst it
-                                */
-                               if (i->second->duration && current > i->second->expiry)
-                                       continue;
-
-                               snprintf(data,MAXBUF,":%s ADDLINE %s %s %s %lu %lu :%s",sn, it->c_str(), i->second->Displayable(),
+                               snprintf(data, MAXBUF, ":%s ADDLINE %s %s %s %lu %lu :%s",
+                                               ServerInstance->Config->GetSID().c_str(),
+                                               it->c_str(),
+                                               i->second->Displayable().c_str(),
                                                i->second->source.c_str(),
                                                (unsigned long)i->second->set_time,
                                                (unsigned long)i->second->duration,
@@ -209,31 +154,29 @@ void TreeSocket::SendXLines()
 }
 
 /** Send channel topic, modes and metadata */
-void TreeSocket::SendChannelModes()
+void TreeSocket::SyncChannel(Channel* chan)
 {
        char data[MAXBUF];
-       std::string n = ServerInstance->Config->GetSID();
-       const char* sn = n.c_str();
 
-       for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++)
-       {
-               SendFJoins(c->second);
-               if (!c->second->topic.empty())
-               {
-                       snprintf(data,MAXBUF,":%s FTOPIC %s %lu %s :%s", sn, c->second->name.c_str(), (unsigned long)c->second->topicset, c->second->setby.c_str(), c->second->topic.c_str());
-                       this->WriteLine(data);
-               }
+       SendFJoins(chan);
 
-               for(Extensible::ExtensibleStore::const_iterator i = c->second->GetExtList().begin(); i != c->second->GetExtList().end(); i++)
-               {
-                       ExtensionItem* item = i->first;
-                       std::string value = item->serialize(FORMAT_NETWORK, c->second, i->second);
-                       if (!value.empty())
-                               Utils->Creator->ProtoSendMetaData(this, c->second, item->name, value);
-               }
+       // If the topic was ever set, send it, even if it's empty now
+       // because a new empty topic should override an old non-empty topic
+       if (chan->topicset != 0)
+       {
+               snprintf(data,MAXBUF,":%s FTOPIC %s %lu %lu %s :%s", ServerInstance->Config->GetSID().c_str(), chan->name.c_str(), (unsigned long) chan->age, (unsigned long)chan->topicset, chan->setby.c_str(), chan->topic.c_str());
+               this->WriteLine(data);
+       }
 
-               FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(c->second,Utils->Creator,this));
+       for (Extensible::ExtensibleStore::const_iterator i = chan->GetExtList().begin(); i != chan->GetExtList().end(); i++)
+       {
+               ExtensionItem* item = i->first;
+               std::string value = item->serialize(FORMAT_NETWORK, chan, i->second);
+               if (!value.empty())
+                       Utils->Creator->ProtoSendMetaData(this, chan, item->name, value);
        }
+
+       FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(chan, Utils->Creator, this));
 }
 
 /** send all users and their oper state/modes */
@@ -255,17 +198,17 @@ void TreeSocket::SendUsers()
                                                u->second->host.c_str(),        /* 3: Displayed Host */
                                                u->second->dhost.c_str(),       /* 4: Real host */
                                                u->second->ident.c_str(),       /* 5: Ident */
-                                               u->second->GetIPString(),       /* 6: IP string */
+                                               u->second->GetIPString().c_str(),       /* 6: IP string */
                                                (unsigned long)u->second->signon, /* 7: Signon time for WHOWAS */
                                                u->second->FormatModes(true),   /* 8...n: Modes and params */
                                                u->second->fullname.c_str());   /* size-1: GECOS */
                                this->WriteLine(data);
-                               if (IS_OPER(u->second))
+                               if (u->second->IsOper())
                                {
-                                       snprintf(data,MAXBUF,":%s OPERTYPE %s", u->second->uuid.c_str(), u->second->oper->name.c_str());
+                                       snprintf(data,MAXBUF,":%s OPERTYPE :%s", u->second->uuid.c_str(), u->second->oper->name.c_str());
                                        this->WriteLine(data);
                                }
-                               if (IS_AWAY(u->second))
+                               if (u->second->IsAway())
                                {
                                        snprintf(data,MAXBUF,":%s AWAY %ld :%s", u->second->uuid.c_str(), (long)u->second->awaytime, u->second->awaymsg.c_str());
                                        this->WriteLine(data);
index 38d59affb401e530fa5daddf722e25b595a22461..2acce9fdce548db607149e95df5251706fb2018e 100644 (file)
 
 
 #include "inspircd.h"
-#include "xline.h"
 
 #include "treesocket.h"
-#include "treeserver.h"
 #include "utils.h"
 
-/* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/utils.h m_spanningtree/treesocket.h */
 
 
 /*
@@ -114,7 +112,7 @@ int TreeSocket::DoCollision(User *u, time_t remotets, const std::string &remotei
                params.push_back(ConvToStr(u->age));
                Utils->DoOneToMany(ServerInstance->Config->GetSID(),"SAVE",params);
 
-               u->ForceNickChange(u->uuid.c_str());
+               u->ForceNickChange(u->uuid);
 
                if (!bChangeRemote)
                        return 1;
@@ -132,7 +130,7 @@ int TreeSocket::DoCollision(User *u, time_t remotets, const std::string &remotei
                if (remote)
                {
                        /* nick change collide. Force change their nick. */
-                       remote->ForceNickChange(remoteuid.c_str());
+                       remote->ForceNickChange(remoteuid);
                }
 
                if (!bChangeLocal)
index af2e04ebc8c0bf4bc9409e2045ad5201e863a931..634a0845ac509b6e4856cef2631e265ff4db5cec 100644 (file)
 
 
 #include "inspircd.h"
-#include "xline.h"
-
 #include "treesocket.h"
-#include "treeserver.h"
 #include "utils.h"
 
 /* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
index 97a4de8c20ee5fc53f6534c691dd0c8ced78eaa7..021100870e7dcfe12b9d4b1f834aaea81f3ef998 100644 (file)
@@ -29,8 +29,8 @@
 CmdResult CommandOpertype::Handle(const std::vector<std::string>& params, User *u)
 {
        SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
-       std::string opertype = params[0];
-       if (!IS_OPER(u))
+       const std::string& opertype = params[0];
+       if (!u->IsOper())
                ServerInstance->Users->all_opers.push_back(u);
        u->modes[UM_OPERATOR] = 1;
        OperIndex::iterator iter = ServerInstance->Config->oper_blocks.find(" " + opertype);
@@ -53,7 +53,7 @@ CmdResult CommandOpertype::Handle(const std::vector<std::string>& params, User *
                        return CMD_SUCCESS;
        }
 
-       ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server.c_str(), u->nick.c_str(),u->ident.c_str(), u->host.c_str(), irc::Spacify(opertype.c_str()));
+       ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server.c_str(), u->nick.c_str(),u->ident.c_str(), u->host.c_str(), opertype.c_str());
        return CMD_SUCCESS;
 }
 
index 04fa4bcab31b53a61aaaab3b6b5e9abd3c25c102..72128a1c390ae1ed01788f83fdd1a86d2f36a93d 100644 (file)
  */
 
 
-/* $ModDesc: Provides a spanning tree server link protocol */
-
 #include "inspircd.h"
 
 #include "main.h"
 #include "utils.h"
 #include "treeserver.h"
-#include "treesocket.h"
 
-/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h */
 
 const std::string ModuleSpanningTree::MapOperInfo(TreeServer* Current)
 {
@@ -38,7 +35,7 @@ const std::string ModuleSpanningTree::MapOperInfo(TreeServer* Current)
 
 void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats)
 {
-       ServerInstance->Logs->Log("map",DEBUG,"ShowMap depth %d on line %d", depth, line);
+       ServerInstance->Logs->Log("map", LOG_DEBUG, "ShowMap depth %d on line %d", depth, line);
        float percent;
 
        if (ServerInstance->Users->clientlist->size() == 0)
@@ -48,10 +45,10 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int
        }
        else
        {
-               percent = Current->GetUserCount() * 100.0 / ServerInstance->Users->clientlist->size();
+               percent = Current->UserCount * 100.0 / ServerInstance->Users->clientlist->size();
        }
 
-       const std::string operdata = IS_OPER(user) ? MapOperInfo(Current) : "";
+       const std::string operdata = user->IsOper() ? MapOperInfo(Current) : "";
 
        char* myname = names + 100 * line;
        char* mystat = stats + 50 * line;
@@ -59,7 +56,7 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int
        int w = depth;
 
        std::string servername = Current->GetName();
-       if (IS_OPER(user))
+       if (user->IsOper())
        {
                w += snprintf(myname + depth, 99 - depth, "%s (%s)", servername.c_str(), Current->GetID().c_str());
        }
@@ -70,16 +67,16 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int
        memset(myname + w, ' ', 100 - w);
        if (w > maxnamew)
                maxnamew = w;
-       snprintf(mystat, 49, "%5d [%5.2f%%]%s", Current->GetUserCount(), percent, operdata.c_str());
+       snprintf(mystat, 49, "%5d [%5.2f%%]%s", Current->UserCount, percent, operdata.c_str());
 
        line++;
 
-       if (IS_OPER(user) || !Utils->FlatLinks)
+       if (user->IsOper() || !Utils->FlatLinks)
                depth = depth + 2;
        for (unsigned int q = 0; q < Current->ChildCount(); q++)
        {
                TreeServer* child = Current->GetChild(q);
-               if (!IS_OPER(user)) {
+               if (!user->IsOper()) {
                        if (child->Hidden)
                                continue;
                        if ((Utils->HideULines) && (ServerInstance->ULine(child->GetName())))
@@ -174,7 +171,7 @@ bool ModuleSpanningTree::HandleMap(const std::vector<std::string>& parameters, U
 
        float avg_users = totusers * 1.0 / line;
 
-       ServerInstance->Logs->Log("map",DEBUG,"local");
+       ServerInstance->Logs->Log("map", LOG_DEBUG, "local");
        for (int t = 0; t < line; t++)
        {
                // terminate the string at maxnamew characters
index 7d01c8149bf62fbf5b2e0d0d5e633a6df40b68c4..6d82f43dba7a5bd8b5cab61f0e483277ef1f8566 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "inspircd.h"
 #include "socket.h"
-#include "xline.h"
 
 #include "main.h"
 #include "utils.h"
@@ -37,7 +36,7 @@ ModResult ModuleSpanningTree::HandleSquit(const std::vector<std::string>& parame
        {
                if (s == Utils->TreeRoot)
                {
-                       user->WriteServ("NOTICE %s :*** SQUIT: Foolish mortal, you cannot make a server SQUIT itself! (%s matches local server name)",user->nick.c_str(),parameters[0].c_str());
+                       user->WriteNotice("*** SQUIT: Foolish mortal, you cannot make a server SQUIT itself! (" + parameters[0] + " matches local server name)");
                        return MOD_RES_DENY;
                }
 
@@ -52,12 +51,12 @@ ModResult ModuleSpanningTree::HandleSquit(const std::vector<std::string>& parame
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** SQUIT may not be used to remove remote servers. Please use RSQUIT instead.",user->nick.c_str());
+                       user->WriteNotice("*** SQUIT may not be used to remove remote servers. Please use RSQUIT instead.");
                }
        }
        else
        {
-                user->WriteServ("NOTICE %s :*** SQUIT: The server \002%s\002 does not exist on the network.",user->nick.c_str(),parameters[0].c_str());
+                user->WriteNotice("*** SQUIT: The server \002" + parameters[0] + "\002 does not exist on the network.");
        }
        return MOD_RES_DENY;
 }
index 688661b8039c4c6a13182a7b01fd7edcf9e24d1f..9762ecf4e3b9c202180e58e4883b1df6998a312c 100644 (file)
  */
 
 
-/* $ModDesc: Provides a spanning tree server link protocol */
-
 #include "inspircd.h"
-#include "socket.h"
 
 #include "main.h"
 #include "utils.h"
-#include "treeserver.h"
 #include "link.h"
-#include "treesocket.h"
 
 ModResult ModuleSpanningTree::OnStats(char statschar, User* user, string_list &results)
 {
index ad8c6a6ef1388afa7151d3657e0be96088e3d5a6..45a7399bfe1b27f2b698bd68b5cdbfa0fdca58b3 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-/* $ModDesc: Provides a spanning tree server link protocol */
-
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
 
 #include "main.h"
 #include "utils.h"
-#include "treeserver.h"
-#include "treesocket.h"
 
-/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h */
 
 ModResult ModuleSpanningTree::HandleRemoteWhois(const std::vector<std::string>& parameters, User* user)
 {
index aec680b231c1cdb75971919a1e6583cdd2990816..badcc340162ed1f09645745ee8ec1637bc522463 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
 #include "utils.h"
-#include "treeserver.h"
 #include "treesocket.h"
 
-/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/utils.h m_spanningtree/treesocket.h */
 
 bool TreeSocket::LocalPing(const std::string &prefix, parameterlist &params)
 {
        if (params.size() < 1)
                return true;
-       if (params.size() == 1)
+
+       const std::string& forwardto = params[0];
+       if (forwardto == ServerInstance->Config->GetSID())
        {
-               std::string stufftobounce = params[0];
-               this->WriteLine(":"+ServerInstance->Config->GetSID()+" PONG "+stufftobounce);
-               return true;
+               // PING for us, reply with a PONG
+               std::string reply = ":" + forwardto + " PONG " + prefix;
+               if (params.size() >= 2)
+                       // If there is a second parameter, append it
+                       reply.append(" :").append(params[1]);
+
+               this->WriteLine(reply);
        }
        else
        {
-               std::string forwardto = params[1];
-               if (forwardto == ServerInstance->Config->ServerName || forwardto == ServerInstance->Config->GetSID())
-               {
-                       // this is a ping for us, send back PONG to the requesting server
-                       params[1] = params[0];
-                       params[0] = forwardto;
-                       Utils->DoOneToOne(ServerInstance->Config->GetSID(),"PONG",params,params[1]);
-               }
-               else
-               {
-                       // not for us, pass it on :)
-                       Utils->DoOneToOne(prefix,"PING",params,forwardto);
-               }
-               return true;
+               // not for us, pass it on :)
+               Utils->DoOneToOne(prefix,"PING",params,forwardto);
        }
+       return true;
 }
 
 
index 5966d05d9f953ed90b7667fc67bfcdabf2da92eb..daf53096db1d15d974314f2b8a0b1f8f33b0b038 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
 #include "utils.h"
 #include "treeserver.h"
 #include "treesocket.h"
@@ -34,49 +30,23 @@ bool TreeSocket::LocalPong(const std::string &prefix, parameterlist &params)
        if (params.size() < 1)
                return true;
 
-       if (params.size() == 1)
+       const std::string& forwardto = params[0];
+       if (forwardto == ServerInstance->Config->GetSID())
        {
+               // PONG for us
                TreeServer* ServerSource = Utils->FindServer(prefix);
                if (ServerSource)
                {
-                       ServerSource->SetPingFlag();
                        long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000);
                        ServerSource->rtt = ts - ServerSource->LastPingMsec;
+                       ServerSource->SetPingFlag();
                }
        }
        else
        {
-               std::string forwardto = params[1];
-               if (forwardto == ServerInstance->Config->GetSID() || forwardto == ServerInstance->Config->ServerName)
-               {
-                       /*
-                        * this is a PONG for us
-                        * if the prefix is a user, check theyre local, and if they are,
-                        * dump the PONG reply back to their fd. If its a server, do nowt.
-                        * Services might want to send these s->s, but we dont need to yet.
-                        */
-                       User* u = ServerInstance->FindNick(prefix);
-                       if (u)
-                       {
-                               u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str());
-                       }
-
-                       TreeServer *ServerSource = Utils->FindServer(params[0]);
-
-                       if (ServerSource)
-                       {
-                               long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000);
-                               ServerSource->rtt = ts - ServerSource->LastPingMsec;
-                               ServerSource->SetPingFlag();
-                       }
-               }
-               else
-               {
-                       // not for us, pass it on :)
-                       Utils->DoOneToOne(prefix,"PONG",params,forwardto);
-               }
+               // not for us, pass it on :)
+               Utils->DoOneToOne(prefix,"PONG",params,forwardto);
        }
-
        return true;
 }
 
index 471bbfcb970670c895ec304df5e30bcef15c44d2..551ce06d5aa96319a2186358de64d05c9c67f839 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-/* $ModDesc: Provides a spanning tree server link protocol */
-
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
 
 #include "main.h"
 #include "utils.h"
 #include "treeserver.h"
-#include "treesocket.h"
 
-/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h */
 
 void ModuleSpanningTree::OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, LocalUser *user, CmdResult result, const std::string &original_line)
 {
@@ -73,7 +67,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, const std::string &
                TreeServer* sdest = FindServer(routing.serverdest);
                if (!sdest)
                {
-                       ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Trying to route ENCAP to nonexistant server %s",
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Trying to route ENCAP to nonexistant server %s",
                                routing.serverdest.c_str());
                        return;
                }
@@ -88,7 +82,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, const std::string &
 
                if (!(ver.Flags & (VF_COMMON | VF_CORE)) && srcmodule != Creator)
                {
-                       ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Routed command %s from non-VF_COMMON module %s",
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Routed command %s from non-VF_COMMON module %s",
                                command.c_str(), srcmodule->ModuleSourceFile.c_str());
                        return;
                }
@@ -121,7 +115,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, const std::string &
                                data += " " + params[x];
                        for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
                        {
-                               TreeSocket* Sock = i->second->GetSocket();
+                               TreeSocket* Sock = (*i)->GetSocket();
                                if (origin && origin->GetSocket() == Sock)
                                        continue;
                                if (Sock)
index b331571ca3d2de721e15eea2bff9de8cea3230ec..428e6ab28c14e90f332c077499923db06c7ca2e2 100644 (file)
  */
 
 
-/* $ModDesc: Provides a spanning tree server link protocol */
-
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
 
 #include "main.h"
-#include "utils.h"
-#include "treeserver.h"
-#include "treesocket.h"
 
-/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/main.h */
 
 ModResult ModuleSpanningTree::OnPreCommand(std::string &command, std::vector<std::string>& parameters, LocalUser *user, bool validated, const std::string &original_line)
 {
@@ -64,8 +57,7 @@ ModResult ModuleSpanningTree::OnPreCommand(std::string &command, std::vector<std
        }
        else if ((command == "VERSION") && (parameters.size() > 0))
        {
-               this->HandleVersion(parameters,user);
-               return MOD_RES_DENY;
+               return this->HandleVersion(parameters,user);
        }
        return MOD_RES_PASSTHRU;
 }
index 3ab5dae9df0c9aa5b54fed4fc8c53e4f244bb10d..93a1387580c909322bb2073df7d3fb74dbae9942 100644 (file)
 
 
 #include "inspircd.h"
-#include "main.h"
 #include "utils.h"
 #include "treeserver.h"
-#include "treesocket.h"
 #include "protocolinterface.h"
 
 /*
@@ -38,8 +36,8 @@ void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
                ps.servername = i->second->GetName();
                TreeServer* s = i->second->GetParent();
                ps.parentname = s ? s->GetName() : "";
-               ps.usercount = i->second->GetUserCount();
-               ps.opercount = i->second->GetOperCount();
+               ps.usercount = i->second->UserCount;
+               ps.opercount = i->second->OperCount;
                ps.gecos = i->second->GetDesc();
                ps.latencyms = i->second->rtt;
                sl.push_back(ps);
@@ -65,7 +63,10 @@ void SpanningTreeProtocolInterface::SendMetaData(Extensible* target, const std::
        if (u)
                params.push_back(u->uuid);
        else if (c)
+       {
                params.push_back(c->name);
+               params.push_back(ConvToStr(c->age));
+       }
        else
                params.push_back("*");
 
@@ -80,6 +81,7 @@ void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &top
        parameterlist params;
 
        params.push_back(channel->name);
+       params.push_back(ConvToStr(channel->age));
        params.push_back(ConvToStr(ServerInstance->Time()));
        params.push_back(ServerInstance->Config->ServerName);
        params.push_back(":" + topic);
@@ -135,31 +137,16 @@ void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string
        Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server);
 }
 
-void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text)
-{
-       std::string cname = target->name;
-       if (status)
-               cname = status + cname;
-       TreeServerList list;
-       CUList exempt_list;
-       Utils->GetListOfServersForChannel(target,list,status,exempt_list);
-       for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
-       {
-               TreeSocket* Sock = i->second->GetSocket();
-               if (Sock)
-                       Sock->WriteLine(text);
-       }
-}
-
-
 void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text)
 {
-       SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text);
+       CUList exempt_list;
+       Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "PRIVMSG");
 }
 
 void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text)
 {
-       SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text);
+       CUList exempt_list;
+       Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "NOTICE");
 }
 
 void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text)
index 297366893d3f86c191d547dafa0a39533586da32..80a21c49b34c7a11631386ceb5b6fb55ea0c22c0 100644 (file)
@@ -17,8 +17,7 @@
  */
 
 
-#ifndef M_SPANNINGTREE_PROTOCOLINTERFACE_H
-#define M_SPANNINGTREE_PROTOCOLINTERFACE_H
+#pragma once
 
 class SpanningTreeUtilities;
 class ModuleSpanningTree;
@@ -29,20 +28,16 @@ class SpanningTreeProtocolInterface : public ProtocolInterface
        void SendChannel(Channel* target, char status, const std::string &text);
  public:
        SpanningTreeProtocolInterface(SpanningTreeUtilities* util) : Utils(util) { }
-       virtual ~SpanningTreeProtocolInterface() { }
 
-       virtual bool SendEncapsulatedData(const parameterlist &encap);
-       virtual void SendMetaData(Extensible* target, const std::string &key, const std::string &data);
-       virtual void SendTopic(Channel* channel, std::string &topic);
-       virtual void SendMode(const std::string &target, const parameterlist &modedata, const std::vector<TranslateType> &types);
-       virtual void SendSNONotice(const std::string &snomask, const std::string &text);
-       virtual void PushToClient(User* target, const std::string &rawline);
-       virtual void SendChannelPrivmsg(Channel* target, char status, const std::string &text);
-       virtual void SendChannelNotice(Channel* target, char status, const std::string &text);
-       virtual void SendUserPrivmsg(User* target, const std::string &text);
-       virtual void SendUserNotice(User* target, const std::string &text);
-       virtual void GetServerList(ProtoServerList &sl);
+       bool SendEncapsulatedData(const parameterlist &encap);
+       void SendMetaData(Extensible* target, const std::string &key, const std::string &data);
+       void SendTopic(Channel* channel, std::string &topic);
+       void SendMode(const std::string &target, const parameterlist &modedata, const std::vector<TranslateType> &types);
+       void SendSNONotice(const std::string &snomask, const std::string &text);
+       void PushToClient(User* target, const std::string &rawline);
+       void SendChannelPrivmsg(Channel* target, char status, const std::string &text);
+       void SendChannelNotice(Channel* target, char status, const std::string &text);
+       void SendUserPrivmsg(User* target, const std::string &text);
+       void SendUserNotice(User* target, const std::string &text);
+       void GetServerList(ProtoServerList &sl);
 };
-
-#endif
-
index b791376ea9e65823e555badc4fc1f1817f549a07..496a711bf79b9e26662801e5beb4fd704baf6994 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
 #include "utils.h"
-#include "treeserver.h"
 #include "treesocket.h"
 
-/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/utils.h m_spanningtree/treesocket.h */
 
 bool TreeSocket::Push(const std::string &prefix, parameterlist &params)
 {
index d4254cac67f951a3cb20e1551a5f206a2c38437d..7398f6e9a2e150f6cf4668950704e49d2b0fc0f3 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
 
-#include "resolvers.h"
 #include "main.h"
 #include "utils.h"
-#include "treeserver.h"
-#include "link.h"
-#include "treesocket.h"
 #include "commands.h"
 
 CommandRConnect::CommandRConnect (Module* Creator, SpanningTreeUtilities* Util)
@@ -39,14 +33,11 @@ CommandRConnect::CommandRConnect (Module* Creator, SpanningTreeUtilities* Util)
 
 CmdResult CommandRConnect::Handle (const std::vector<std::string>& parameters, User *user)
 {
-       if (IS_LOCAL(user))
+       /* First see if the server which is being asked to connect to another server in fact exists */
+       if (!Utils->FindServerMask(parameters[0]))
        {
-               if (!Utils->FindServerMask(parameters[0]))
-               {
-                       user->WriteServ("NOTICE %s :*** RCONNECT: Server \002%s\002 isn't connected to the network!", user->nick.c_str(), parameters[0].c_str());
-                       return CMD_FAILURE;
-               }
-               user->WriteServ("NOTICE %s :*** RCONNECT: Sending remote connect to \002%s\002 to connect server \002%s\002.",user->nick.c_str(),parameters[0].c_str(),parameters[1].c_str());
+               ((ModuleSpanningTree*)(Module*)creator)->RemoteMessage(user, "*** RCONNECT: Server \002%s\002 isn't connected to the network!", parameters[0].c_str());
+               return CMD_FAILURE;
        }
 
        /* Is this aimed at our server? */
@@ -58,6 +49,21 @@ CmdResult CommandRConnect::Handle (const std::vector<std::string>& parameters, U
                para.push_back(parameters[1]);
                ((ModuleSpanningTree*)(Module*)creator)->HandleConnect(para, user);
        }
+       else
+       {
+               /* It's not aimed at our server, but if the request originates from our user
+                * acknowledge that we sent the request.
+                *
+                * It's possible that we're asking a server for something that makes no sense
+                * (e.g. connect to itself or to an already connected server), but we don't check
+                * for those conditions here, as ModuleSpanningTree::HandleConnect() (which will run
+                * on the target) does all the checking and error reporting.
+                */
+               if (IS_LOCAL(user))
+               {
+                       user->WriteNotice("*** RCONNECT: Sending remote connect to \002 " + parameters[0] + "\002 to connect server \002" + parameters[1] + "\002.");
+               }
+       }
        return CMD_SUCCESS;
 }
 
index d7c4c52274c02a2dfe51c16eabee2db5aa51dfff..a7ad9767842e2e1084cb2712be4b9a8a69197d3d 100644 (file)
@@ -19,9 +19,8 @@
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
 
+#include "cachetimer.h"
 #include "resolvers.h"
 #include "main.h"
 #include "utils.h"
  * callback to OnLookupComplete or OnError when completed. Once it has completed we
  * will have an IP address which we can then use to continue our connection.
  */
-ServernameResolver::ServernameResolver(SpanningTreeUtilities* Util, const std::string &hostname, Link* x, bool &cached, QueryType qt, Autoconnect* myac)
-       : Resolver(hostname, qt, cached, Util->Creator), Utils(Util), query(qt), host(hostname), MyLink(x), myautoconnect(myac)
+ServernameResolver::ServernameResolver(SpanningTreeUtilities* Util, DNS::Manager *mgr, const std::string &hostname, Link* x, DNS::QueryType qt, Autoconnect* myac)
+       : DNS::Request(mgr, Util->Creator, hostname, qt), Utils(Util), query(qt), host(hostname), MyLink(x), myautoconnect(myac)
 {
 }
 
-void ServernameResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
+void ServernameResolver::OnLookupComplete(const DNS::Query *r)
 {
+       const DNS::ResourceRecord &ans_record = r->answers[0];
+
        /* Initiate the connection, now that we have an IP to use.
         * Passing a hostname directly to BufferedSocket causes it to
         * just bail and set its FD to -1.
@@ -51,7 +52,7 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in
        TreeServer* CheckDupe = Utils->FindServer(MyLink->Name.c_str());
        if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
        {
-               TreeSocket* newsocket = new TreeSocket(Utils, MyLink, myautoconnect, result);
+               TreeSocket* newsocket = new TreeSocket(Utils, MyLink, myautoconnect, ans_record.rdata);
                if (newsocket->GetFd() > -1)
                {
                        /* We're all OK */
@@ -66,47 +67,73 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in
        }
 }
 
-void ServernameResolver::OnError(ResolverError e, const std::string &errormessage)
+void ServernameResolver::OnError(const DNS::Query *r)
 {
        /* Ooops! */
-       if (query == DNS_QUERY_AAAA)
+       if (query == DNS::QUERY_AAAA)
        {
-               bool cached = false;
-               ServernameResolver* snr = new ServernameResolver(Utils, host, MyLink, cached, DNS_QUERY_A, myautoconnect);
-               ServerInstance->AddResolver(snr, cached);
-               return;
+               ServernameResolver* snr = new ServernameResolver(Utils, this->manager, host, MyLink, DNS::QUERY_A, myautoconnect);
+               try
+               {
+                       this->manager->Process(snr);
+                       return;
+               }
+               catch (DNS::Exception &)
+               {
+                       delete snr;
+               }
        }
-       ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s", MyLink->Name.c_str(), errormessage.c_str() );
+
+       ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s", MyLink->Name.c_str(), this->manager->GetErrorStr(r->error).c_str());
        Utils->Creator->ConnectServer(myautoconnect, false);
 }
 
-SecurityIPResolver::SecurityIPResolver(Module* me, SpanningTreeUtilities* U, const std::string &hostname, Link* x, bool &cached, QueryType qt)
-               : Resolver(hostname, qt, cached, me), MyLink(x), Utils(U), mine(me), host(hostname), query(qt)
+SecurityIPResolver::SecurityIPResolver(Module* me, SpanningTreeUtilities* U, DNS::Manager *mgr, const std::string &hostname, Link* x, DNS::QueryType qt)
+               : DNS::Request(mgr, me, hostname, qt), MyLink(x), Utils(U), mine(me), host(hostname), query(qt)
 {
 }
 
-void SecurityIPResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
+void SecurityIPResolver::OnLookupComplete(const DNS::Query *r)
 {
+       const DNS::ResourceRecord &ans_record = r->answers[0];
+
        for (std::vector<reference<Link> >::iterator i = Utils->LinkBlocks.begin(); i != Utils->LinkBlocks.end(); ++i)
        {
                Link* L = *i;
                if (L->IPAddr == host)
                {
-                       Utils->ValidIPs.push_back(result);
+                       Utils->ValidIPs.push_back(ans_record.rdata);
                        break;
                }
        }
 }
 
-void SecurityIPResolver::OnError(ResolverError e, const std::string &errormessage)
+void SecurityIPResolver::OnError(const DNS::Query *r)
 {
-       if (query == DNS_QUERY_AAAA)
+       if (query == DNS::QUERY_AAAA)
        {
-               bool cached = false;
-               SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, host, MyLink, cached, DNS_QUERY_A);
-               ServerInstance->AddResolver(res, cached);
-               return;
+               SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, this->manager, host, MyLink, DNS::QUERY_A);
+               try
+               {
+                       this->manager->Process(res);
+                       return;
+               }
+               catch (DNS::Exception &)
+               {
+                       delete res;
+               }
        }
-       ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Could not resolve IP associated with Link '%s': %s",
-               MyLink->Name.c_str(),errormessage.c_str());
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Could not resolve IP associated with Link '%s': %s",
+               MyLink->Name.c_str(), this->manager->GetErrorStr(r->error).c_str());
+}
+
+CacheRefreshTimer::CacheRefreshTimer(SpanningTreeUtilities* Util)
+       : Timer(3600, ServerInstance->Time(), true), Utils(Util)
+{
+}
+
+bool CacheRefreshTimer::Tick(time_t TIME)
+{
+       Utils->RefreshIPCache();
+       return true;
 }
index 65b9e72495db121e2a5359e8c51c1110404a612c..249414617c85c3e933b01fd514eb89599f0ce69e 100644 (file)
  */
 
 
-#ifndef M_SPANNINGTREE_RESOLVERS_H
-#define M_SPANNINGTREE_RESOLVERS_H
+#pragma once
 
-#include "socket.h"
 #include "inspircd.h"
-#include "xline.h"
+#include "modules/dns.h"
 
 #include "utils.h"
 #include "link.h"
 
 /** Handle resolving of server IPs for the cache
  */
-class SecurityIPResolver : public Resolver
+class SecurityIPResolver : public DNS::Request
 {
  private:
        reference<Link> MyLink;
        SpanningTreeUtilities* Utils;
        Module* mine;
        std::string host;
-       QueryType query;
+       DNS::QueryType query;
  public:
-       SecurityIPResolver(Module* me, SpanningTreeUtilities* U, const std::string &hostname, Link* x, bool &cached, QueryType qt);
-       void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
-       void OnError(ResolverError e, const std::string &errormessage);
+       SecurityIPResolver(Module* me, SpanningTreeUtilities* U, DNS::Manager *mgr, const std::string &hostname, Link* x, DNS::QueryType qt);
+       void OnLookupComplete(const DNS::Query *r) CXX11_OVERRIDE;
+       void OnError(const DNS::Query *q) CXX11_OVERRIDE;
 };
 
 /** This class is used to resolve server hostnames during /connect and autoconnect.
@@ -50,18 +48,16 @@ class SecurityIPResolver : public Resolver
  * callback to OnLookupComplete or OnError when completed. Once it has completed we
  * will have an IP address which we can then use to continue our connection.
  */
-class ServernameResolver : public Resolver
+class ServernameResolver : public DNS::Request
 {
  private:
        SpanningTreeUtilities* Utils;
-       QueryType query;
+       DNS::QueryType query;
        std::string host;
        reference<Link> MyLink;
        reference<Autoconnect> myautoconnect;
  public:
-       ServernameResolver(SpanningTreeUtilities* Util, const std::string &hostname, Link* x, bool &cached, QueryType qt, Autoconnect* myac);
-       void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
-       void OnError(ResolverError e, const std::string &errormessage);
+       ServernameResolver(SpanningTreeUtilities* Util, DNS::Manager *mgr, const std::string &hostname, Link* x, DNS::QueryType qt, Autoconnect* myac);
+       void OnLookupComplete(const DNS::Query *r) CXX11_OVERRIDE;
+       void OnError(const DNS::Query *q) CXX11_OVERRIDE;
 };
-
-#endif
index 027ae02ab78dc45dab25cf4496c44a49148b75d9..be658120b3056f0b10e1c93c34ff89701f569d8e 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
 
-#include "main.h"
 #include "utils.h"
 #include "treeserver.h"
-#include "treesocket.h"
 #include "commands.h"
 
 CommandRSQuit::CommandRSQuit (Module* Creator, SpanningTreeUtilities* Util)
@@ -43,13 +39,13 @@ CmdResult CommandRSQuit::Handle (const std::vector<std::string>& parameters, Use
        server_target = Utils->FindServerMask(parameters[0]);
        if (!server_target)
        {
-               user->WriteServ("NOTICE %s :*** RSQUIT: Server \002%s\002 isn't connected to the network!", user->nick.c_str(), parameters[0].c_str());
+               ((ModuleSpanningTree*)(Module*)creator)->RemoteMessage(user, "*** RSQUIT: Server \002%s\002 isn't connected to the network!", parameters[0].c_str());
                return CMD_FAILURE;
        }
 
        if (server_target == Utils->TreeRoot)
        {
-               NoticeUser(user, "*** RSQUIT: Foolish mortal, you cannot make a server SQUIT itself! ("+parameters[0]+" matches local server name)");
+               ((ModuleSpanningTree*)(Module*)creator)->RemoteMessage(user, "*** RSQUIT: Foolish mortal, you cannot make a server SQUIT itself! (%s matches local server name)", parameters[0].c_str());
                return CMD_FAILURE;
        }
 
@@ -75,20 +71,3 @@ RouteDescriptor CommandRSQuit::GetRouting(User* user, const std::vector<std::str
 {
        return ROUTE_UNICAST(parameters[0]);
 }
-
-// XXX use protocol interface instead of rolling our own :)
-void CommandRSQuit::NoticeUser(User* user, const std::string &msg)
-{
-       if (IS_LOCAL(user))
-       {
-               user->WriteServ("NOTICE %s :%s",user->nick.c_str(),msg.c_str());
-       }
-       else
-       {
-               parameterlist params;
-               params.push_back(user->nick);
-               params.push_back("NOTICE "+ConvToStr(user->nick)+" :"+msg);
-               Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", params, user->server);
-       }
-}
-
index 92999b422bb852d663132367f89d91dc1dd96b0e..216a7e5f1e96fc556e133a898f886d010f4fbd60 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
 #include "utils.h"
-#include "treeserver.h"
 #include "treesocket.h"
 
-/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
+/* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
 
 /**
  * SAVE command - force nick change to UID on timestamp match
@@ -44,7 +39,7 @@ bool TreeSocket::ForceNick(const std::string &prefix, parameterlist &params)
        {
                Utils->DoOneToAllButSender(prefix,"SAVE",params,prefix);
 
-               if (!u->ForceNickChange(u->uuid.c_str()))
+               if (!u->ForceNickChange(u->uuid))
                {
                        ServerInstance->Users->QuitUser(u, "Nickname collision");
                }
index 05441da0c8780b27def709d5fcbc75ea252dbe33..85204ccaac035b652e723ed56bd0e9ecbb147208 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
 #include "utils.h"
 #include "link.h"
 #include "treeserver.h"
@@ -55,7 +51,7 @@ bool TreeSocket::RemoteServer(const std::string &prefix, parameterlist &params)
                this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
                return false;
        }
-       if (!ServerInstance->IsSID(sid))
+       if (!InspIRCd::IsSID(sid))
        {
                this->SendError("Invalid format server ID: "+sid+"!");
                return false;
@@ -105,17 +101,9 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist &params)
        std::string password = params[1];
        std::string sid = params[3];
        std::string description = params[4];
-       int hops = atoi(params[2].c_str());
 
        this->SendCapabilities(2);
 
-       if (hops)
-       {
-               this->SendError("Server too far away for authentication");
-               ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
-               return false;
-       }
-
        if (!ServerInstance->IsSID(sid))
        {
                this->SendError("Invalid format server ID: "+sid+"!");
@@ -194,7 +182,7 @@ bool TreeSocket::CheckDuplicate(const std::string& sname, const std::string& sid
        }
 
        /* Check for fully initialized instances of the server by id */
-       ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Looking for dupe SID %s", sid.c_str());
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Looking for dupe SID %s", sid.c_str());
        CheckDupe = Utils->FindServerID(sid);
 
        if (CheckDupe)
@@ -225,17 +213,9 @@ bool TreeSocket::Inbound_Server(parameterlist &params)
        std::string password = params[1];
        std::string sid = params[3];
        std::string description = params[4];
-       int hops = atoi(params[2].c_str());
 
        this->SendCapabilities(2);
 
-       if (hops)
-       {
-               this->SendError("Server too far away for authentication");
-               ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
-               return false;
-       }
-
        if (!ServerInstance->IsSID(sid))
        {
                this->SendError("Invalid format server ID: "+sid+"!");
index 416502369c7856312afe3d34fc43283a15b21c8f..032633416851e0dd4a5a71d0f84911985ce4cbcd 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
-#include "utils.h"
-#include "treeserver.h"
 #include "commands.h"
 
 CmdResult CommandSVSJoin::Handle(const std::vector<std::string>& parameters, User *user)
 {
        // Check for valid channel name
-       if (!ServerInstance->IsChannel(parameters[1].c_str(), ServerInstance->Config->Limits.ChanMax))
+       if (!ServerInstance->IsChannel(parameters[1]))
                return CMD_FAILURE;
 
        // Check target exists
@@ -40,8 +34,9 @@ CmdResult CommandSVSJoin::Handle(const std::vector<std::string>& parameters, Use
                return CMD_FAILURE;
 
        /* only join if it's local, otherwise just pass it on! */
-       if (IS_LOCAL(u))
-               Channel::JoinUser(u, parameters[1].c_str(), false, "", false, ServerInstance->Time());
+       LocalUser* localuser = IS_LOCAL(u);
+       if (localuser)
+               Channel::JoinUser(localuser, parameters[1]);
        return CMD_SUCCESS;
 }
 
index 79dc27ea32bad0d277031352459389b8168ef65d..6490626afb4ba0e1e44abcc556fad0cc34aac75f 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "inspircd.h"
 
-#include "main.h"
-#include "utils.h"
 #include "commands.h"
 
 CmdResult CommandSVSNick::Handle(const std::vector<std::string>& parameters, User *user)
@@ -34,17 +32,17 @@ CmdResult CommandSVSNick::Handle(const std::vector<std::string>& parameters, Use
                if (isdigit(nick[0]))
                        nick = u->uuid;
 
-               if (!u->ForceNickChange(nick.c_str()))
+               if (!u->ForceNickChange(nick))
                {
                        /* buh. UID them */
-                       if (!u->ForceNickChange(u->uuid.c_str()))
+                       if (!u->ForceNickChange(u->uuid))
                        {
                                ServerInstance->Users->QuitUser(u, "Nickname collision");
                                return CMD_SUCCESS;
                        }
                }
 
-               u->age = atoi(parameters[2].c_str());
+               u->age = ConvToInt(parameters[2]);
        }
 
        return CMD_SUCCESS;
index 3bdf13b25ca1e03ee8cc0859e5f8047404f08314..b966da2820297ec58b16749849f2135160ddb362 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
-#include "utils.h"
-#include "treeserver.h"
 #include "commands.h"
 
 CmdResult CommandSVSPart::Handle(const std::vector<std::string>& parameters, User *user)
index 493b05ebf78f6dda096e3c8b3ab04f86200dc16e..c9956c7781654e09b856c41c2bd28901b740c44e 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
 #include "xline.h"
 #include "main.h"
-#include "../spanningtree.h"
+#include "modules/spanningtree.h"
 
 #include "utils.h"
 #include "treeserver.h"
@@ -42,7 +41,7 @@ TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::strin
        bursting = false;
        Parent = NULL;
        VersionString.clear();
-       ServerUserCount = ServerOperCount = 0;
+       UserCount = OperCount = 0;
        VersionString = ServerInstance->GetVersionString();
        Route = NULL;
        Socket = NULL; /* Fix by brain */
@@ -62,7 +61,7 @@ TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::strin
        age = ServerInstance->Time();
        bursting = true;
        VersionString.clear();
-       ServerUserCount = ServerOperCount = 0;
+       UserCount = OperCount = 0;
        SetNextPingTime(ServerInstance->Time() + Utils->PingFreq);
        SetPingFlag();
        Warned = false;
@@ -70,7 +69,7 @@ TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::strin
 
        long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000);
        this->StartBurst = ts;
-       ServerInstance->Logs->Log("m_spanningtree",DEBUG, "Started bursting at time %lu", ts);
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Started bursting at time %lu", ts);
 
        /* find the 'route' for this server (e.g. the one directly connected
         * to the local server, which we can use to reach it)
@@ -158,7 +157,7 @@ void TreeServer::FinishBurst()
 
 void TreeServer::SetID(const std::string &id)
 {
-       ServerInstance->Logs->Log("m_spanningtree",DEBUG, "Setting SID to " + id);
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Setting SID to " + id);
        sid = id;
        Utils->sidlist[sid] = this;
 }
@@ -257,26 +256,6 @@ void TreeServer::SetPingFlag()
        LastPingWasGood = true;
 }
 
-unsigned int TreeServer::GetUserCount()
-{
-       return ServerUserCount;
-}
-
-void TreeServer::SetUserCount(int diff)
-{
-       ServerUserCount += diff;
-}
-
-void TreeServer::SetOperCount(int diff)
-{
-       ServerOperCount += diff;
-}
-
-unsigned int TreeServer::GetOperCount()
-{
-       return ServerOperCount;
-}
-
 TreeSocket* TreeServer::GetSocket()
 {
        return Socket;
index 60b6d1defc9d7e1dc8e10c45fe1d2a35a61f4466..460231502a76c532a7da5ff9567ed848882a9ab2 100644 (file)
@@ -19,8 +19,7 @@
  */
 
 
-#ifndef M_SPANNINGTREE_TREESERVER_H
-#define M_SPANNINGTREE_TREESERVER_H
+#pragma once
 
 #include "treesocket.h"
 
@@ -46,8 +45,6 @@ class TreeServer : public classbase
        irc::string ServerName;                 /* Server's name */
        std::string ServerDesc;                 /* Server's description */
        std::string VersionString;              /* Version string or empty string */
-       unsigned int ServerUserCount;           /* How many users are on this server? [note: doesn't care about +i] */
-       unsigned int ServerOperCount;           /* How many opers are on this server? */
        TreeSocket* Socket;                     /* For directly connected servers this points at the socket object */
        time_t NextPing;                        /* After this time, the server should be PINGed*/
        bool LastPingWasGood;                   /* True if the server responded to the last PING with a PONG */
@@ -67,6 +64,9 @@ class TreeServer : public classbase
        bool Warned;                            /* True if we've warned opers about high latency on this server */
        bool bursting;                          /* whether or not this server is bursting */
 
+       unsigned int UserCount;                 /* How many users are on this server? [note: doesn't care about +i] */
+       unsigned int OperCount;                 /* How many opers are on this server? */
+
        /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
         * represents our own server. Therefore, it has no route, no parent, and
         * no socket associated with it. Its version string is our own local version.
@@ -143,22 +143,6 @@ class TreeServer : public classbase
         */
        void SetPingFlag();
 
-       /** Get the number of users on this server.
-        */
-       unsigned int GetUserCount();
-
-       /** Increment or decrement the user count by diff.
-        */
-       void SetUserCount(int diff);
-
-       /** Gets the numbers of opers on this server.
-        */
-       unsigned int GetOperCount();
-
-       /** Increment or decrement the oper count by diff.
-        */
-       void SetOperCount(int diff);
-
        /** Get the TreeSocket pointer for local servers.
         * For remote servers, this returns NULL.
         */
@@ -210,5 +194,3 @@ class TreeServer : public classbase
         */
        ~TreeServer();
 };
-
-#endif
index d8445572bf0c405b51f4aed800a7cc4ad6307ba1..0dcdc830e105a59df281e65efc82bbe440a7d1b3 100644 (file)
  */
 
 
-#ifndef M_SPANNINGTREE_TREESOCKET_H
-#define M_SPANNINGTREE_TREESOCKET_H
+#pragma once
 
-#include "socket.h"
 #include "inspircd.h"
-#include "xline.h"
 
 #include "utils.h"
 
@@ -166,11 +163,11 @@ class TreeSocket : public BufferedSocket
         * to server docs on the inspircd.org site, the other side
         * will then send back its own server string.
         */
-       virtual void OnConnected();
+       void OnConnected();
 
        /** Handle socket error event
         */
-       virtual void OnError(BufferedSocketError e);
+       void OnError(BufferedSocketError e) CXX11_OVERRIDE;
 
        /** Sends an error to the remote server, and displays it locally to show
         * that it was sent.
@@ -180,13 +177,8 @@ class TreeSocket : public BufferedSocket
        /** Recursively send the server tree with distances as hops.
         * This is used during network burst to inform the other server
         * (and any of ITS servers too) of what servers we know about.
-        * If at any point any of these servers already exist on the other
-        * end, our connection may be terminated. The hopcounts given
-        * by this function are relative, this doesn't matter so long as
-        * they are all >1, as all the remote servers re-calculate them
-        * to be relative too, with themselves as hop 0.
         */
-       void SendServers(TreeServer* Current, TreeServer* s, int hops);
+       void SendServers(TreeServer* Current, TreeServer* s);
 
        /** Returns module list as a string, filtered by filter
         * @param filter a module version bitmask, such as VF_COMMON or VF_OPTCOMMON
@@ -197,9 +189,6 @@ class TreeSocket : public BufferedSocket
         */
        void SendCapabilities(int phase);
 
-       /** Add modules to VF_COMMON list for backwards compatability */
-       void CompatAddModules(std::vector<std::string>& modlist);
-
        /* Isolate and return the elements that are different between two lists */
        void ListDifference(const std::string &one, const std::string &two, char sep,
                std::string& mleft, std::string& mright);
@@ -232,8 +221,8 @@ class TreeSocket : public BufferedSocket
        /** Send G, Q, Z and E lines */
        void SendXLines();
 
-       /** Send channel modes and topics */
-       void SendChannelModes();
+       /** Send all known information about a channel */
+       void SyncChannel(Channel* chan);
 
        /** send all users and their oper state/modes */
        void SendUsers();
@@ -323,15 +312,16 @@ class TreeSocket : public BufferedSocket
 
        /** Handle socket timeout from connect()
         */
-       virtual void OnTimeout();
+       void OnTimeout();
        /** Handle server quit on close
         */
-       virtual void Close();
+       void Close();
 
        /** Returns true if this server was introduced to the rest of the network
         */
        bool Introduced();
-};
-
-#endif
 
+       /** Fixes messages coming from old servers so the new command handlers understand them
+        */
+       bool PreProcessOldProtocolMessage(User*& who, std::string& cmd, std::vector<std::string>& params);
+};
index 6582ba0606d599ab18e2e30aafdd16342c861630..dc81842b142b47a6b57d401d92cbb299965bf3e3 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
 #include "main.h"
-#include "../spanningtree.h"
+#include "modules/spanningtree.h"
 #include "utils.h"
 #include "treeserver.h"
 #include "link.h"
 #include "treesocket.h"
-#include "resolvers.h"
 
 /** Because most of the I/O gubbins are encapsulated within
  * BufferedSocket, we just call the superclass constructor for
@@ -158,7 +154,7 @@ void TreeSocket::SendError(const std::string &errormessage)
 void TreeSocket::SquitServer(std::string &from, TreeServer* Current, int& num_lost_servers, int& num_lost_users)
 {
        std::string servername = Current->GetName();
-       ServerInstance->Logs->Log("m_spanningtree",DEBUG,"SquitServer for %s from %s",
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "SquitServer for %s from %s",
                servername.c_str(), from.c_str());
        /* recursively squit the servers attached to 'Current'.
         * We're going backwards so we don't remove users
@@ -189,9 +185,9 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason)
                if (!Current->GetSocket() || Current->GetSocket()->Introduced())
                {
                        parameterlist params;
-                       params.push_back(Current->GetName());
+                       params.push_back(Current->GetID());
                        params.push_back(":"+reason);
-                       Utils->DoOneToAllButSender(Current->GetParent()->GetName(),"SQUIT",params,Current->GetName());
+                       Utils->DoOneToAllButSender(Current->GetParent()->GetID(),"SQUIT",params,Current->GetName());
                }
 
                if (Current->GetParent() == Utils->TreeRoot)
@@ -220,7 +216,7 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason)
                }
        }
        else
-               ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Squit from unknown server");
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Squit from unknown server");
 }
 
 /** This function is called when we receive data from a remote
index 5007fe921b64340353ecd1a2e1deaa821458d4c1..1b3b9dae2e8bba907a04097e4f0367cbf099ee29 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
 #include "main.h"
 #include "utils.h"
 #include "treeserver.h"
-#include "link.h"
 #include "treesocket.h"
 #include "resolvers.h"
 
@@ -47,7 +43,7 @@ void TreeSocket::Split(const std::string& line, std::string& prefix, std::string
 
        if (!tokens.GetToken(prefix))
                return;
-       
+
        if (prefix[0] == ':')
        {
                prefix = prefix.substr(1);
@@ -84,7 +80,7 @@ void TreeSocket::ProcessLine(std::string &line)
        std::string command;
        parameterlist params;
 
-       ServerInstance->Logs->Log("m_spanningtree", RAWIO, "S[%d] I %s", this->GetFd(), line.c_str());
+       ServerInstance->Logs->Log("m_spanningtree", LOG_RAWIO, "S[%d] I %s", this->GetFd(), line.c_str());
 
        Split(line, prefix, command, params);
 
@@ -151,7 +147,7 @@ void TreeSocket::ProcessLine(std::string &line)
                        {
                                if (params.size())
                                {
-                                       time_t them = atoi(params[0].c_str());
+                                       time_t them = ConvToInt(params[0]);
                                        time_t delta = them - ServerInstance->Time();
                                        if ((delta < -600) || (delta > 600))
                                        {
@@ -257,7 +253,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                         * crossing the users QUIT further upstream from the server. Thanks jilles!
                         */
 
-                       if ((prefix.length() == UUID_LENGTH-1) && (isdigit(prefix[0])) &&
+                       if ((prefix.length() == UIDGenerator::UUID_LENGTH) && (isdigit(prefix[0])) &&
                                ((command == "FMODE") || (command == "MODE") || (command == "KICK") || (command == "TOPIC") || (command == "KILL") || (command == "ADDLINE") || (command == "DELLINE")))
                        {
                                /* Special case, we cannot drop these commands as they've been committed already on a
@@ -271,7 +267,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                        }
                        else
                        {
-                               ServerInstance->Logs->Log("m_spanningtree", DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.",
+                               ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.",
                                        command.c_str(), prefix.c_str());
                                return;
                        }
@@ -302,7 +298,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        if ((!route_back_again) || (route_back_again->GetSocket() != this))
        {
                if (route_back_again)
-                       ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Protocol violation: Fake direction '%s' from connection '%s'",
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'",
                                prefix.c_str(),linkID.c_str());
                return;
        }
@@ -314,6 +310,12 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        if (command == "SVSMODE") // This isn't in an "else if" so we still force FMODE for changes on channels.
                command = "MODE";
 
+       if (proto_version < ProtocolVersion)
+       {
+               if (!PreProcessOldProtocolMessage(who, command, params))
+                       return;
+       }
+
        // TODO move all this into Commands
        if (command == "MAP")
        {
@@ -439,7 +441,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                }
 
                /* Update timestamp on user when they change nicks */
-               who->age = atoi(params[1].c_str());
+               who->age = ConvToInt(params[1]);
 
                /*
                 * On nick messages, check that the nick doesnt already exist here.
@@ -461,17 +463,17 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                                return;
                        }
                }
-               who->ForceNickChange(params[0].c_str());
+               who->ForceNickChange(params[0]);
                Utils->RouteCommand(route_back_again, command, params, who);
        }
        else
        {
                Command* cmd = ServerInstance->Parser->GetHandler(command);
-               
+
                if (!cmd)
                {
                        irc::stringjoiner pmlist(" ", params, 0, params.size() - 1);
-                       ServerInstance->Logs->Log("m_spanningtree", SPARSE, "Unrecognised S2S command :%s %s %s",
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_SPARSE, "Unrecognised S2S command :%s %s %s",
                                who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
                        SendError("Unrecognised command '" + command + "' -- possibly loaded mismatched modules");
                        return;
@@ -480,7 +482,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                if (params.size() < cmd->min_params)
                {
                        irc::stringjoiner pmlist(" ", params, 0, params.size() - 1);
-                       ServerInstance->Logs->Log("m_spanningtree", SPARSE, "Insufficient parameters for S2S command :%s %s %s",
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_SPARSE, "Insufficient parameters for S2S command :%s %s %s",
                                who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
                        SendError("Insufficient parameters for command '" + command + "'");
                        return;
@@ -499,7 +501,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                if (res == CMD_INVALID)
                {
                        irc::stringjoiner pmlist(" ", params, 0, params.size() - 1);
-                       ServerInstance->Logs->Log("m_spanningtree", SPARSE, "Error handling S2S command :%s %s %s",
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_SPARSE, "Error handling S2S command :%s %s %s",
                                who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
                        SendError("Error handling '" + command + "' -- possibly loaded mismatched modules");
                }
index f33cb038d772f8554f1289f943b7e1d53e53743c..4bcc2d9b2bae7690faa783032c747ef0e5bcac47 100644 (file)
 #include "commands.h"
 
 #include "utils.h"
-#include "link.h"
-#include "treesocket.h"
 #include "treeserver.h"
-#include "resolvers.h"
 
 CmdResult CommandUID::Handle(const parameterlist &params, User* serversrc)
 {
@@ -38,7 +35,7 @@ CmdResult CommandUID::Handle(const parameterlist &params, User* serversrc)
        time_t age_t = ConvToInt(params[1]);
        time_t signon = ConvToInt(params[7]);
        std::string empty;
-       std::string modestr(params[8]);
+       const std::string& modestr = params[8];
 
        TreeServer* remoteserver = Utils->FindServer(serversrc->server);
 
@@ -65,7 +62,7 @@ CmdResult CommandUID::Handle(const parameterlist &params, User* serversrc)
                 * Nick collision.
                 */
                int collide = sock->DoCollision(iter->second, age_t, params[5], params[6], params[0]);
-               ServerInstance->Logs->Log("m_spanningtree",DEBUG,"*** Collision on %s, collide=%d", params[2].c_str(), collide);
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "*** Collision on %s, collide=%d", params[2].c_str(), collide);
 
                if (collide != 1)
                {
@@ -88,7 +85,7 @@ CmdResult CommandUID::Handle(const parameterlist &params, User* serversrc)
        }
        catch (...)
        {
-               ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Duplicate UUID %s in client introduction", params[0].c_str());
+               ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Duplicate UUID %s in client introduction", params[0].c_str());
                return CMD_INVALID;
        }
        (*(ServerInstance->Users->clientlist))[params[2]] = _new;
@@ -101,49 +98,47 @@ CmdResult CommandUID::Handle(const parameterlist &params, User* serversrc)
        _new->signon = signon;
        _new->age = age_t;
 
-       /* we need to remove the + from the modestring, so we can do our stuff */
-       std::string::size_type pos_after_plus = modestr.find_first_not_of('+');
-       if (pos_after_plus != std::string::npos)
-       modestr = modestr.substr(pos_after_plus);
-
        unsigned int paramptr = 9;
-       for (std::string::iterator v = modestr.begin(); v != modestr.end(); v++)
+
+       for (std::string::const_iterator v = modestr.begin(); v != modestr.end(); ++v)
        {
-               /* For each mode thats set, increase counter */
+               // Accept more '+' chars, for now
+               if (*v == '+')
+                       continue;
+
+               /* For each mode thats set, find the mode handler and set it on the new user */
                ModeHandler* mh = ServerInstance->Modes->FindMode(*v, MODETYPE_USER);
+               if (!mh)
+               {
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Unrecognised mode '%c' for a user in UID, dropping link", *v);
+                       return CMD_INVALID;
+               }
 
-               if (mh)
+               if (mh->GetNumParams(true))
                {
-                       if (mh->GetNumParams(true))
-                       {
-                               if (paramptr >= params.size() - 1)
-                                       return CMD_INVALID;
-                               std::string mp = params[paramptr++];
-                               /* IMPORTANT NOTE:
-                                * All modes are assumed to succeed here as they are being set by a remote server.
-                                * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
-                                * to note as all but one modules currently cannot ever fail in this situation, except for
-                                * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
-                                * but here, at client introduction. You may safely assume this behaviour is standard and
-                                * will not change in future versions if you want to make use of this protective behaviour
-                                * yourself.
-                                */
-                               mh->OnModeChange(_new, _new, NULL, mp, true);
-                       }
-                       else
-                               mh->OnModeChange(_new, _new, NULL, empty, true);
-                       _new->SetMode(*v, true);
+                       if (paramptr >= params.size() - 1)
+                               return CMD_INVALID;
+                       std::string mp = params[paramptr++];
+                       /* IMPORTANT NOTE:
+                        * All modes are assumed to succeed here as they are being set by a remote server.
+                        * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
+                        * to note as all but one modules currently cannot ever fail in this situation, except for
+                        * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
+                        * but here, at client introduction. You may safely assume this behaviour is standard and
+                        * will not change in future versions if you want to make use of this protective behaviour
+                        * yourself.
+                        */
+                       mh->OnModeChange(_new, _new, NULL, mp, true);
                }
+               else
+                       mh->OnModeChange(_new, _new, NULL, empty, true);
+               _new->SetMode(*v, true);
        }
 
-       /* now we've done with modes processing, put the + back for remote servers */
-       if (modestr[0] != '+')
-               modestr = "+" + modestr;
-
        _new->SetClientIP(params[6].c_str());
 
        ServerInstance->Users->AddGlobalClone(_new);
-       remoteserver->SetUserCount(1); // increment by 1
+       remoteserver->UserCount++;
 
        bool dosend = true;
 
@@ -151,7 +146,7 @@ CmdResult CommandUID::Handle(const parameterlist &params, User* serversrc)
                dosend = false;
 
        if (dosend)
-               ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s (%s) [%s]", _new->server.c_str(), _new->GetFullRealHost().c_str(), _new->GetIPString(), _new->fullname.c_str());
+               ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s (%s) [%s]", _new->server.c_str(), _new->GetFullRealHost().c_str(), _new->GetIPString().c_str(), _new->fullname.c_str());
 
        FOREACH_MOD(I_OnPostConnect,OnPostConnect(_new));
 
index 1879d711112deaa4458f5c5c2c5a2e852aa0368a..157679ed7f2adda19bbe8add6e33ef9d39597d45 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
 #include "main.h"
 #include "utils.h"
 #include "treeserver.h"
-#include "link.h"
 #include "treesocket.h"
 #include "resolvers.h"
 
@@ -61,7 +57,7 @@ ModResult ModuleSpanningTree::OnAcceptConnection(int newsock, ListenSocket* from
  */
 TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
 {
-       if (ServerInstance->IsSID(ServerName))
+       if (InspIRCd::IsSID(ServerName))
                return this->FindServerID(ServerName);
 
        server_hash::iterator iter = serverlist.find(ServerName.c_str());
@@ -130,9 +126,11 @@ TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id)
                return NULL;
 }
 
-SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C) : Creator(C)
+SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C)
+       : RefreshTimer(this), Creator(C)
 {
-       ServerInstance->Logs->Log("m_spanningtree",DEBUG,"***** Using SID for hash: %s *****", ServerInstance->Config->GetSID().c_str());
+       ServerInstance->Timers->AddTimer(&RefreshTimer);
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "***** Using SID for hash: %s *****", ServerInstance->Config->GetSID().c_str());
 
        this->TreeRoot = new TreeServer(this, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID());
        this->ReadConfiguration();
@@ -165,12 +163,6 @@ SpanningTreeUtilities::~SpanningTreeUtilities()
        delete TreeRoot;
 }
 
-void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
-{
-       if (list.find(server) == list.end())
-               list[server] = server;
-}
-
 /* returns a list of DIRECT servernames for a specific channel */
 void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list)
 {
@@ -196,21 +188,30 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerLis
                {
                        TreeServer* best = this->BestRouteTo(i->first->server);
                        if (best)
-                               AddThisServer(best,list);
+                               list.insert(best);
                }
        }
        return;
 }
 
-bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, const parameterlist &params, const std::string& omit)
+std::string SpanningTreeUtilities::ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params)
 {
-       TreeServer* omitroute = this->BestRouteTo(omit);
-       std::string FullLine = ":" + prefix + " " + command;
-       unsigned int words = params.size();
-       for (unsigned int x = 0; x < words; x++)
+       std::string FullLine;
+       FullLine.reserve(MAXBUF);
+       FullLine = ":" + prefix + " " + command;
+       for (parameterlist::const_iterator x = params.begin(); x != params.end(); ++x)
        {
-               FullLine = FullLine + " " + params[x];
+               FullLine.push_back(' ');
+               FullLine.append(*x);
        }
+       return FullLine;
+}
+
+bool SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& omit)
+{
+       TreeServer* omitroute = this->BestRouteTo(omit);
+       std::string FullLine = ConstructLine(prefix, command, params);
+
        unsigned int items = this->TreeRoot->ChildCount();
        for (unsigned int x = 0; x < items; x++)
        {
@@ -231,12 +232,8 @@ bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const
 
 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, const parameterlist &params)
 {
-       std::string FullLine = ":" + prefix + " " + command;
-       unsigned int words = params.size();
-       for (unsigned int x = 0; x < words; x++)
-       {
-               FullLine = FullLine + " " + params[x];
-       }
+       std::string FullLine = ConstructLine(prefix, command, params);
+
        unsigned int items = this->TreeRoot->ChildCount();
        for (unsigned int x = 0; x < items; x++)
        {
@@ -251,22 +248,16 @@ bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::st
        return true;
 }
 
-bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, const parameterlist &params, const std::string& target)
+bool SpanningTreeUtilities::DoOneToOne(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& target)
 {
        TreeServer* Route = this->BestRouteTo(target);
        if (Route)
        {
-               std::string FullLine = ":" + prefix + " " + command;
-               unsigned int words = params.size();
-               for (unsigned int x = 0; x < words; x++)
-               {
-                       FullLine = FullLine + " " + params[x];
-               }
                if (Route && Route->GetSocket())
                {
                        TreeSocket* Sock = Route->GetSocket();
                        if (Sock)
-                               Sock->WriteLine(FullLine);
+                               Sock->WriteLine(ConstructLine(prefix, command, params));
                }
                return true;
        }
@@ -284,7 +275,7 @@ void SpanningTreeUtilities::RefreshIPCache()
                Link* L = *i;
                if (!L->Port)
                {
-                       ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Ignoring a link block without a port.");
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "m_spanningtree: Ignoring a link block without a port.");
                        /* Invalid link block */
                        continue;
                }
@@ -296,16 +287,16 @@ void SpanningTreeUtilities::RefreshIPCache()
                bool ipvalid = irc::sockets::aptosa(L->IPAddr, L->Port, dummy);
                if ((L->IPAddr == "*") || (ipvalid))
                        ValidIPs.push_back(L->IPAddr);
-               else
+               else if (this->Creator->DNS)
                {
+                       SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, *this->Creator->DNS, L->IPAddr, L, DNS::QUERY_AAAA);
                        try
                        {
-                               bool cached = false;
-                               SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L->IPAddr, L, cached, DNS_QUERY_AAAA);
-                               ServerInstance->AddResolver(sr, cached);
+                               this->Creator->DNS->Process(sr);
                        }
-                       catch (...)
+                       catch (DNS::Exception &)
                        {
+                               delete sr;
                        }
                }
        }
@@ -375,11 +366,11 @@ void SpanningTreeUtilities::ReadConfiguration()
                if (L->IPAddr.empty())
                {
                        L->IPAddr = "*";
-                       ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Configuration warning: Link block '" + assign(L->Name) + "' has no IP defined! This will allow any IP to connect as this server, and MAY not be what you want.");
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Configuration warning: Link block '" + assign(L->Name) + "' has no IP defined! This will allow any IP to connect as this server, and MAY not be what you want.");
                }
 
                if (!L->Port)
-                       ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Configuration warning: Link block '" + assign(L->Name) + "' has no port defined, you will not be able to /connect it.");
+                       ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Configuration warning: Link block '" + assign(L->Name) + "' has no port defined, you will not be able to /connect it.");
 
                L->Fingerprint.erase(std::remove(L->Fingerprint.begin(), L->Fingerprint.end(), ':'), L->Fingerprint.end());
                LinkBlocks.push_back(L);
@@ -428,3 +419,21 @@ Link* SpanningTreeUtilities::FindLink(const std::string& name)
        }
        return NULL;
 }
+
+void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const char* message_type)
+{
+       std::string raw(":");
+       raw.append(prefix).append(1, ' ').append(message_type).push_back(' ');
+       if (status)
+               raw.push_back(status);
+       raw.append(target->name).append(" :").append(text);
+
+       TreeServerList list;
+       this->GetListOfServersForChannel(target, list, status, exempt_list);
+       for (TreeServerList::iterator i = list.begin(); i != list.end(); ++i)
+       {
+               TreeSocket* Sock = (*i)->GetSocket();
+               if (Sock)
+                       Sock->WriteLine(raw);
+       }
+}
index 92a03428f16898331508c6a52047a8e626f58dfc..e97df38393db593ca6e742457559a548a52d57bc 100644 (file)
  */
 
 
-#ifndef M_SPANNINGTREE_UTILS_H
-#define M_SPANNINGTREE_UTILS_H
+#pragma once
 
 #include "inspircd.h"
+#include "cachetimer.h"
 
 /* Foward declarations */
 class TreeServer;
@@ -36,19 +36,21 @@ class SpanningTreeUtilities;
 /* This hash_map holds the hash equivalent of the server
  * tree, used for rapid linear lookups.
  */
-#ifdef HASHMAP_DEPRECATED
-       typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
-#else
-       typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
-#endif
+typedef TR1NS::unordered_map<std::string, TreeServer*, irc::insensitive, irc::StrHashComp> server_hash;
 
-typedef std::map<TreeServer*,TreeServer*> TreeServerList;
+typedef std::set<TreeServer*> TreeServerList;
 
 /** Contains helper functions and variables for this module,
  * and keeps them out of the global namespace
  */
 class SpanningTreeUtilities : public classbase
 {
+       /** Creates a line in the :<prefix> <command> [<params>] format
+        */
+       std::string ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params);
+
+       CacheRefreshTimer RefreshTimer;
+
  public:
        /** Creator module
         */
@@ -126,11 +128,11 @@ class SpanningTreeUtilities : public classbase
 
        /** Send a message from this server to one other local or remote
         */
-       bool DoOneToOne(const std::string &prefix, const std::string &command, const parameterlist &params, const std::string& target);
+       bool DoOneToOne(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& target);
 
        /** Send a message from this server to all but one other, local or remote
         */
-       bool DoOneToAllButSender(const std::string &prefix, const std::string &command, const parameterlist &params, const std::string& omit);
+       bool DoOneToAllButSender(const std::string &prefix, const std::string &command, const parameterlistparams, const std::string& omit);
 
        /** Send a message from this server to all others
         */
@@ -140,10 +142,6 @@ class SpanningTreeUtilities : public classbase
         */
        void ReadConfiguration();
 
-       /** Add a server to the server list for GetListOfServersForChannel
-        */
-       void AddThisServer(TreeServer* server, TreeServerList &list);
-
        /** Compile a list of servers which contain members of channel c
         */
        void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
@@ -171,6 +169,8 @@ class SpanningTreeUtilities : public classbase
        /** Refresh the IP cache used for allowing inbound connections
         */
        void RefreshIPCache();
-};
 
-#endif
+       /** Sends a PRIVMSG or a NOTICE to a channel obeying an exempt list and an optional prefix
+        */
+       void SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const char* message_type);
+};
index e08d13e6e4a348a49f00acc0fc4582662ad60d43..9d76dea9aea0f637899f13fc67333925e3ec1ada 100644 (file)
@@ -18,9 +18,6 @@
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
 #include "main.h"
 #include "utils.h"
index df97145be95d51744ae1588b127e0bd38a521e6e..4e8b178b94e65ea67855e1d8ca451a33172a362f 100644 (file)
@@ -18,8 +18,8 @@
 
 
 #include "inspircd.h"
-#include "sql.h"
-#include "hash.h"
+#include "modules/sql.h"
+#include "modules/hash.h"
 
 /* $ModDesc: Allow/Deny connections based upon an arbitrary SQL table */
 
@@ -39,8 +39,8 @@ class AuthQuery : public SQLQuery
                : SQLQuery(me), uid(u), pendingExt(e), verbose(v)
        {
        }
-       
-       void OnResult(SQLResult& res)
+
+       void OnResult(SQLResult& res) CXX11_OVERRIDE
        {
                User* user = ServerInstance->FindNick(uid);
                if (!user)
@@ -57,7 +57,7 @@ class AuthQuery : public SQLQuery
                }
        }
 
-       void OnError(SQLerror& error)
+       void OnError(SQLerror& error) CXX11_OVERRIDE
        {
                User* user = ServerInstance->FindNick(uid);
                if (!user)
@@ -83,7 +83,7 @@ class ModuleSQLAuth : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(pendingExt);
                OnRehash(NULL);
@@ -91,7 +91,7 @@ class ModuleSQLAuth : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* conf = ServerInstance->Config->ConfValue("sqlauth");
                std::string dbid = conf->getString("dbid");
@@ -105,7 +105,7 @@ class ModuleSQLAuth : public Module
                verbose = conf->getBool("verbose");
        }
 
-       ModResult OnUserRegister(LocalUser* user)
+       ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
        {
                // Note this is their initial (unresolved) connect block
                ConfigTag* tag = user->MyClass->config;
@@ -144,7 +144,7 @@ class ModuleSQLAuth : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnCheckReady(LocalUser* user)
+       ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
        {
                switch (pendingExt.get(user))
                {
@@ -159,7 +159,7 @@ class ModuleSQLAuth : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allow/Deny connections based upon an arbitrary SQL table", VF_VENDOR);
        }
index ae581cc4b61e3b36a98962291c41243545ff77f9..0ae468576ef1c75a0d76aa213cf445886aa3a469 100644 (file)
 
 
 #include "inspircd.h"
-#include "sql.h"
-#include "hash.h"
+#include "modules/sql.h"
+#include "modules/hash.h"
 
 /* $ModDesc: Allows storage of oper credentials in an SQL table */
 
-static bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
-       std::stringstream hl(hostlist);
-       std::string xhost;
-       while (hl >> xhost)
-       {
-               if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
 class OpMeQuery : public SQLQuery
 {
  public:
@@ -46,9 +32,9 @@ class OpMeQuery : public SQLQuery
        {
        }
 
-       void OnResult(SQLResult& res)
+       void OnResult(SQLResult& res) CXX11_OVERRIDE
        {
-               ServerInstance->Logs->Log("m_sqloper",DEBUG, "SQLOPER: result for %s", uid.c_str());
+               ServerInstance->Logs->Log("m_sqloper", LOG_DEBUG, "SQLOPER: result for %s", uid.c_str());
                User* user = ServerInstance->FindNick(uid);
                if (!user)
                        return;
@@ -57,30 +43,17 @@ class OpMeQuery : public SQLQuery
                SQLEntries row;
                while (res.GetRow(row))
                {
-#if 0
-                       parameterlist cols;
-                       res.GetCols(cols);
-
-                       std::vector<KeyVal>* items;
-                       reference<ConfigTag> tag = ConfigTag::create("oper", "<m_sqloper>", 0, items);
-                       for(unsigned int i=0; i < cols.size(); i++)
-                       {
-                               if (!row[i].nul)
-                                       items->insert(std::make_pair(cols[i], row[i]));
-                       }
-#else
                        if (OperUser(user, row[0], row[1]))
                                return;
-#endif
                }
-               ServerInstance->Logs->Log("m_sqloper",DEBUG, "SQLOPER: no matches for %s (checked %d rows)", uid.c_str(), res.Rows());
+               ServerInstance->Logs->Log("m_sqloper", LOG_DEBUG, "SQLOPER: no matches for %s (checked %d rows)", uid.c_str(), res.Rows());
                // nobody succeeded... fall back to OPER
                fallback();
        }
 
-       void OnError(SQLerror& error)
+       void OnError(SQLerror& error) CXX11_OVERRIDE
        {
-               ServerInstance->Logs->Log("m_sqloper",DEFAULT, "SQLOPER: query failed (%s)", error.Str());
+               ServerInstance->Logs->Log("m_sqloper", LOG_DEFAULT, "SQLOPER: query failed (%s)", error.Str());
                fallback();
        }
 
@@ -101,7 +74,7 @@ class OpMeQuery : public SQLQuery
                }
                else
                {
-                       ServerInstance->Logs->Log("m_sqloper",SPARSE, "BUG: WHAT?! Why do we have no OPER command?!");
+                       ServerInstance->Logs->Log("m_sqloper", LOG_SPARSE, "BUG: WHAT?! Why do we have no OPER command?!");
                }
        }
 
@@ -110,7 +83,7 @@ class OpMeQuery : public SQLQuery
                OperIndex::iterator iter = ServerInstance->Config->oper_blocks.find(" " + type);
                if (iter == ServerInstance->Config->oper_blocks.end())
                {
-                       ServerInstance->Logs->Log("m_sqloper",DEFAULT, "SQLOPER: bad type '%s' in returned row for oper %s", type.c_str(), username.c_str());
+                       ServerInstance->Logs->Log("m_sqloper", LOG_DEFAULT, "SQLOPER: bad type '%s' in returned row for oper %s", type.c_str(), username.c_str());
                        return false;
                }
                OperInfo* ifo = iter->second;
@@ -119,7 +92,7 @@ class OpMeQuery : public SQLQuery
 
                hostname.append("@").append(user->host);
 
-               if (OneOfMatches(hostname.c_str(), user->GetIPString(), pattern))
+               if (InspIRCd::MatchMask(pattern, hostname, user->GetIPString()))
                {
                        /* Opertype and host match, looks like this is it. */
 
@@ -140,7 +113,7 @@ class ModuleSQLOper : public Module
 public:
        ModuleSQLOper() : SQL(this, "SQL") {}
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
 
@@ -148,7 +121,7 @@ public:
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("sqloper");
 
@@ -162,7 +135,7 @@ public:
                query = tag->getString("query", "SELECT hostname as host, type FROM ircd_opers WHERE username='$username' AND password='$password'");
        }
 
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                if (validated && command == "OPER" && parameters.size() >= 2)
                {
@@ -172,7 +145,7 @@ public:
                                /* Query is in progress, it will re-invoke OPER if needed */
                                return MOD_RES_DENY;
                        }
-                       ServerInstance->Logs->Log("m_sqloper",DEFAULT, "SQLOPER: database not present");
+                       ServerInstance->Logs->Log("m_sqloper", LOG_DEFAULT, "SQLOPER: database not present");
                }
                return MOD_RES_PASSTHRU;
        }
@@ -189,11 +162,10 @@ public:
                SQL->submit(new OpMeQuery(this, user->uuid, username, password), query, userinfo);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Allows storage of oper credentials in an SQL table", VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSQLOper)
index 2bfe0e1c4e0ca285727789b722d48a4056790e6e..8cdaa1cde0c0cad53ae194ae71af5b13edfcef13 100644 (file)
@@ -18,7 +18,7 @@
 
 
 #include "inspircd.h"
-#include "ssl.h"
+#include "modules/ssl.h"
 
 /* $ModDesc: Provides SSL metadata, including /WHOIS information and /SSLINFO command */
 
@@ -97,25 +97,25 @@ class CommandSSLInfo : public Command
                        return CMD_FAILURE;
                }
                bool operonlyfp = ServerInstance->Config->ConfValue("sslinfo")->getBool("operonly");
-               if (operonlyfp && !IS_OPER(user) && target != user)
+               if (operonlyfp && !user->IsOper() && target != user)
                {
-                       user->WriteServ("NOTICE %s :*** You cannot view SSL certificate information for other users", user->nick.c_str());
+                       user->WriteNotice("*** You cannot view SSL certificate information for other users");
                        return CMD_FAILURE;
                }
                ssl_cert* cert = CertExt.get(target);
                if (!cert)
                {
-                       user->WriteServ("NOTICE %s :*** No SSL certificate for this user", user->nick.c_str());
+                       user->WriteNotice("*** No SSL certificate for this user");
                }
                else if (cert->GetError().length())
                {
-                       user->WriteServ("NOTICE %s :*** No SSL certificate information for this user (%s).", user->nick.c_str(), cert->GetError().c_str());
+                       user->WriteNotice("*** No SSL certificate information for this user (" + cert->GetError() + ").");
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Distinguished Name: %s", user->nick.c_str(), cert->GetDN().c_str());
-                       user->WriteServ("NOTICE %s :*** Issuer:             %s", user->nick.c_str(), cert->GetIssuer().c_str());
-                       user->WriteServ("NOTICE %s :*** Key Fingerprint:    %s", user->nick.c_str(), cert->GetFingerprint().c_str());
+                       user->WriteNotice("*** Distinguished Name: " + cert->GetDN());
+                       user->WriteNotice("*** Issuer:             " + cert->GetIssuer());
+                       user->WriteNotice("*** Key Fingerprint:    " + cert->GetFingerprint());
                }
                return CMD_SUCCESS;
        }
@@ -130,7 +130,7 @@ class ModuleSSLInfo : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
 
@@ -140,39 +140,25 @@ class ModuleSSLInfo : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("SSL Certificate Utilities", VF_VENDOR);
        }
 
-       void OnWhois(User* source, User* dest)
+       void OnWhois(User* source, User* dest) CXX11_OVERRIDE
        {
                ssl_cert* cert = cmd.CertExt.get(dest);
                if (cert)
                {
                        ServerInstance->SendWhoisLine(source, dest, 671, "%s %s :is using a secure connection", source->nick.c_str(), dest->nick.c_str());
                        bool operonlyfp = ServerInstance->Config->ConfValue("sslinfo")->getBool("operonly");
-                       if ((!operonlyfp || source == dest || IS_OPER(source)) && !cert->fingerprint.empty())
+                       if ((!operonlyfp || source == dest || source->IsOper()) && !cert->fingerprint.empty())
                                ServerInstance->SendWhoisLine(source, dest, 276, "%s %s :has client certificate fingerprint %s",
                                        source->nick.c_str(), dest->nick.c_str(), cert->fingerprint.c_str());
                }
        }
 
-       bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
-       {
-               std::stringstream hl(hostlist);
-               std::string xhost;
-               while (hl >> xhost)
-               {
-                       if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-                       {
-                               return true;
-                       }
-               }
-               return false;
-       }
-
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                if ((command == "OPER") && (validated))
                {
@@ -203,7 +189,7 @@ class ModuleSSLInfo : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnUserConnect(LocalUser* user)
+       void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
        {
                SocketCertificateRequest req(&user->eh, this);
                if (!req.cert)
@@ -211,7 +197,7 @@ class ModuleSSLInfo : public Module
                cmd.CertExt.set(user, req.cert);
        }
 
-       void OnPostConnect(User* user)
+       void OnPostConnect(User* user) CXX11_OVERRIDE
        {
                ssl_cert *cert = cmd.CertExt.get(user);
                if (!cert || cert->fingerprint.empty())
@@ -226,7 +212,7 @@ class ModuleSSLInfo : public Module
                }
        }
 
-       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
+       ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE
        {
                SocketCertificateRequest req(&user->eh, this);
                bool ok = true;
@@ -244,7 +230,7 @@ class ModuleSSLInfo : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnRequest(Request& request)
+       void OnRequest(Request& request) CXX11_OVERRIDE
        {
                if (strcmp("GET_USER_CERT", request.id) == 0)
                {
@@ -255,4 +241,3 @@ class ModuleSSLInfo : public Module
 };
 
 MODULE_INIT(ModuleSSLInfo)
-
index c81c7420783747b7d0d560b475224a5a5a925a5c..360f63bc9cf8cb6b489bdf407bf864febc4db145 100644 (file)
@@ -22,7 +22,7 @@
 
 
 #include "inspircd.h"
-#include "ssl.h"
+#include "modules/ssl.h"
 
 /* $ModDesc: Provides channel mode +z to allow for Secure/SSL only channels */
 
@@ -85,14 +85,14 @@ class ModuleSSLModes : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(sslm);
                Implementation eventlist[] = { I_OnUserPreJoin, I_OnCheckBan, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
                if(chan && chan->IsModeSet('z'))
                {
@@ -106,7 +106,7 @@ class ModuleSSLModes : public Module
                        else
                        {
                                // Deny
-                               user->WriteServ( "489 %s %s :Cannot join channel; SSL users only (+z)", user->nick.c_str(), cname);
+                               user->WriteServ( "489 %s %s :Cannot join channel; SSL users only (+z)", user->nick.c_str(), cname.c_str());
                                return MOD_RES_DENY;
                        }
                }
@@ -114,7 +114,7 @@ class ModuleSSLModes : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
+       ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
        {
                if ((mask.length() > 2) && (mask[0] == 'z') && (mask[1] == ':'))
                {
@@ -126,21 +126,15 @@ class ModuleSSLModes : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       ~ModuleSSLModes()
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
+               tokens["EXTBAN"].push_back('z');
        }
 
-       void On005Numeric(std::string &output)
-       {
-               ServerInstance->AddExtBanChar('z');
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel mode +z to allow for Secure/SSL only channels", VF_VENDOR);
        }
 };
 
-
 MODULE_INIT(ModuleSSLModes)
-
index f1504edaf329a6bf270c4441742a7a4eddb7a8bd..b7e26afd5bbf3d97119786062f5193cad7f2ec69 100644 (file)
@@ -50,24 +50,20 @@ class ModuleStripColor : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(usc);
                ServerInstance->Modules->AddService(csc);
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
+               Implementation eventlist[] = { I_OnUserPreMessage, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ~ModuleStripColor()
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
+               tokens["EXTBAN"].push_back('S');
        }
 
-       virtual void On005Numeric(std::string &output)
-       {
-               ServerInstance->AddExtBanChar('S');
-       }
-
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return MOD_RES_PASSTHRU;
@@ -97,12 +93,7 @@ class ModuleStripColor : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
-       {
-               return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel +S mode (strip ansi color)", VF_VENDOR);
        }
index d8176043e8929244fa3b9f80066a0f285170867c..a53298126646c48b5c4f55c4a8a75b68f7a61ce7 100644 (file)
 class SVSHold : public XLine
 {
 public:
-       irc::string nickname;
+       std::string nickname;
 
        SVSHold(time_t s_time, long d, const std::string& src, const std::string& re, const std::string& nick)
                : XLine(s_time, d, src, re, "SVSHOLD")
        {
-               this->nickname = nick.c_str();
-       }
-
-       ~SVSHold()
-       {
+               this->nickname = nick;
        }
 
        bool Matches(User *u)
@@ -51,20 +47,12 @@ public:
 
        bool Matches(const std::string &s)
        {
-               if (nickname == s)
-                       return true;
-               return false;
-       }
-
-       void DisplayExpiry()
-       {
-               ServerInstance->SNO->WriteToSnoMask('x',"Removing expired SVSHOLD %s (set by %s %ld seconds ago)",
-                       this->nickname.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
+               return InspIRCd::Match(s, nickname);
        }
 
-       const char* Displayable()
+       const std::string& Displayable()
        {
-               return nickname.c_str();
+               return nickname;
        }
 };
 
@@ -118,7 +106,7 @@ class CommandSvshold : public Command
                        }
                        else
                        {
-                               user->WriteServ("NOTICE %s :*** SVSHOLD %s not found in list, try /stats S.",user->nick.c_str(),parameters[0].c_str());
+                               user->WriteNotice("*** SVSHOLD " + parameters[0] + " not found in list, try /stats S.");
                        }
                }
                else
@@ -126,8 +114,7 @@ class CommandSvshold : public Command
                        if (parameters.size() < 3)
                                return CMD_FAILURE;
 
-                       // Adding - XXX todo make this respect <insane> tag perhaps..
-                       long duration = ServerInstance->Duration(parameters[1]);
+                       unsigned long duration = InspIRCd::Duration(parameters[1]);
                        SVSHold* r = new SVSHold(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
 
                        if (ServerInstance->XLines->AddLine(r, user))
@@ -170,7 +157,7 @@ class ModuleSVSHold : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->XLines->RegisterFactory(&s);
                ServerInstance->Modules->AddService(cmd);
@@ -178,7 +165,7 @@ class ModuleSVSHold : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual ModResult OnStats(char symbol, User* user, string_list &out)
+       ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE
        {
                if(symbol != 'S')
                        return MOD_RES_PASSTHRU;
@@ -187,7 +174,7 @@ class ModuleSVSHold : public Module
                return MOD_RES_DENY;
        }
 
-       virtual ModResult OnUserPreNick(User *user, const std::string &newnick)
+       ModResult OnUserPreNick(User *user, const std::string &newnick) CXX11_OVERRIDE
        {
                XLine *rl = ServerInstance->XLines->MatchesLine("SVSHOLD", newnick);
 
@@ -200,13 +187,13 @@ class ModuleSVSHold : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleSVSHold()
+       ~ModuleSVSHold()
        {
                ServerInstance->XLines->DelAll("SVSHOLD");
                ServerInstance->XLines->UnregisterFactory(&s);
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services.", VF_COMMON | VF_VENDOR);
        }
index 742781747f4e091de5e9848da2ac8b80095ee52c..a00d60960c1345cfa3dd853f599b73e936437581 100644 (file)
@@ -90,7 +90,7 @@ class ModuleSWhois : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->Modules->AddService(cmd.swhois);
@@ -99,7 +99,7 @@ class ModuleSWhois : public Module
        }
 
        // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
-       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
+       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
        {
                /* We use this and not OnWhois because this triggers for remote, too */
                if (numeric == 312)
@@ -116,7 +116,7 @@ class ModuleSWhois : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
+       void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
        {
                if (!IS_LOCAL(user))
                        return;
@@ -130,11 +130,7 @@ class ModuleSWhois : public Module
                ServerInstance->PI->SendMetaData(user, "swhois", swhois);
        }
 
-       ~ModuleSWhois()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the SWHOIS command which allows setting of arbitrary WHOIS lines", VF_OPTCOMMON | VF_VENDOR);
        }
index 401766d8a2eaa358f7833545da6f15e0cc3eac6c..d32f26a4bdd3bed04269fd1bcb9e3e060136d880 100644 (file)
@@ -112,16 +112,13 @@ static void checkall(Module* noimpl)
        CHK(OnUserPreInvite);
        CHK(OnUserInvite);
        CHK(OnUserPreMessage);
-       CHK(OnUserPreNotice);
        CHK(OnUserPreNick);
        CHK(OnUserMessage);
-       CHK(OnUserNotice);
        CHK(OnMode);
        CHK(OnGetServerDescription);
        CHK(OnSyncUser);
        CHK(OnSyncChannel);
        CHK(OnDecodeMetaData);
-       CHK(OnWallops);
        CHK(OnAcceptConnection);
        CHK(OnChangeHost);
        CHK(OnChangeName);
@@ -152,8 +149,6 @@ static void checkall(Module* noimpl)
        CHK(OnEvent);
        CHK(OnGlobalOper);
        CHK(OnPostConnect);
-       CHK(OnAddBan);
-       CHK(OnDelBan);
        CHK(OnChangeLocalUserGECOS);
        CHK(OnUserRegister);
        CHK(OnChannelPreDelete);
@@ -216,18 +211,17 @@ class ModuleTest : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                if (!strstr(ServerInstance->Config->ServerName.c_str(), ".test"))
                        throw ModuleException("Don't load modules without reading their descriptions!");
                ServerInstance->Modules->AddService(cmd);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides a module for testing the server while linked in a network", VF_VENDOR|VF_OPTCOMMON);
        }
 };
 
 MODULE_INIT(ModuleTest)
-
index 497ac2569d94ad80528656a1c4a1de345ab339d4..a76d89c827d0efc5bf36cdad4001fb82162e8832 100644 (file)
@@ -62,15 +62,15 @@ class CommandTban : public Command
                        user->WriteNumeric(482, "%s %s :You do not have permission to set bans on this channel",
                                user->nick.c_str(), channel->name.c_str());
                        return CMD_FAILURE;
-               }               
+               }
 
                TimedBan T;
                std::string channelname = parameters[0];
-               long duration = ServerInstance->Duration(parameters[1]);
+               unsigned long duration = InspIRCd::Duration(parameters[1]);
                unsigned long expire = duration + ServerInstance->Time();
                if (duration < 1)
                {
-                       user->WriteServ("NOTICE "+user->nick+" :Invalid ban time");
+                       user->WriteNotice("Invalid ban time");
                        return CMD_FAILURE;
                }
                std::string mask = parameters[2];
@@ -80,20 +80,17 @@ class CommandTban : public Command
                bool isextban = ((mask.size() > 2) && (mask[1] == ':'));
                if (!isextban && !ServerInstance->IsValidMask(mask))
                        mask.append("!*@*");
-               if ((mask.length() > 250) || (!ServerInstance->IsValidMask(mask) && !isextban))
-               {
-                       user->WriteServ("NOTICE "+user->nick+" :Invalid ban mask");
-                       return CMD_FAILURE;
-               }
+
                setban.push_back(mask);
                // use CallHandler to make it so that the user sets the mode
                // themselves
                ServerInstance->Parser->CallHandler("MODE",setban,user);
-               for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
-                       if (!strcasecmp(i->data.c_str(), mask.c_str()))
-                               goto found;
-               return CMD_FAILURE;
-found:
+               if (ServerInstance->Modes->GetLastParse().empty())
+               {
+                       user->WriteNotice("Invalid ban mask");
+                       return CMD_FAILURE;
+               }
+
                CUList tmp;
                T.channel = channelname;
                T.mask = mask;
@@ -114,27 +111,22 @@ found:
        }
 };
 
-class ModuleTimedBans : public Module
+class BanWatcher : public ModeWatcher
 {
-       CommandTban cmd;
  public:
-       ModuleTimedBans()
-               : cmd(this)
+       BanWatcher(Module* parent)
+               : ModeWatcher(parent, "ban", MODETYPE_CHANNEL)
        {
        }
 
-       void init()
+       void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding)
        {
-               ServerInstance->Modules->AddService(cmd);
-               Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-       }
+               if (adding)
+                       return;
 
-       virtual ModResult OnDelBan(User* source, Channel* chan, const std::string &banmask)
-       {
                irc::string listitem = banmask.c_str();
                irc::string thischan = chan->name.c_str();
-               for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); i++)
+               for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); ++i)
                {
                        irc::string target = i->mask.c_str();
                        irc::string tchan = i->channel.c_str();
@@ -144,10 +136,35 @@ class ModuleTimedBans : public Module
                                break;
                        }
                }
-               return MOD_RES_PASSTHRU;
        }
+};
 
-       virtual void OnBackgroundTimer(time_t curtime)
+class ModuleTimedBans : public Module
+{
+       CommandTban cmd;
+       BanWatcher banwatcher;
+
+ public:
+       ModuleTimedBans()
+               : cmd(this)
+               , banwatcher(this)
+       {
+       }
+
+       void init() CXX11_OVERRIDE
+       {
+               ServerInstance->Modules->AddService(cmd);
+               Implementation eventlist[] = { I_OnBackgroundTimer };
+               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+               ServerInstance->Modes->AddModeWatcher(&banwatcher);
+       }
+
+       ~ModuleTimedBans()
+       {
+               ServerInstance->Modes->DelModeWatcher(&banwatcher);
+       }
+
+       void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE
        {
                timedbans expired;
                for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();)
@@ -183,11 +200,10 @@ class ModuleTimedBans : public Module
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Adds timed bans", VF_COMMON | VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleTimedBans)
-
index b4e7e5a995941e829ef33ca38969504f84b46b0e..6e0ebca3d0897f214dd872140f514d6bc98e315f 100644 (file)
@@ -75,20 +75,15 @@ class ModuleTLine : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleTLine()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides /tline command used to test who a mask matches", VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleTLine)
-
index 3e8a846e76ba60e62ba7a7db0f5e6fc169a51e14..563fa6caa47be91437417b21762aa19a86d347ff 100644 (file)
@@ -47,7 +47,7 @@ class CommandSVSTOPIC : public Command
                        time_t topicts = ConvToInt(parameters[1]);
                        if (!topicts)
                        {
-                               ServerInstance->Logs->Log("m_topiclock", DEFAULT, "Received SVSTOPIC with a 0 topicts, dropped.");
+                               ServerInstance->Logs->Log("m_topiclock", LOG_DEFAULT, "Received SVSTOPIC with a 0 topicts, dropped.");
                                return CMD_INVALID;
                        }
 
@@ -96,7 +96,7 @@ class FlagExtItem : public ExtensionItem
        {
        }
 
-       virtual ~FlagExtItem()
+       ~FlagExtItem()
        {
        }
 
@@ -151,14 +151,14 @@ class ModuleTopicLock : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                ServerInstance->Modules->AddService(topiclock);
                ServerInstance->Modules->Attach(I_OnPreTopicChange, this);
        }
 
-       ModResult OnPreTopicChange(User* user, Channel* chan, const std::string &topic)
+       ModResult OnPreTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE
        {
                // Only fired for local users currently, but added a check anyway
                if ((IS_LOCAL(user)) && (topiclock.get(chan)))
@@ -170,7 +170,7 @@ class ModuleTopicLock : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Implements server-side topic locks and the server-to-server command SVSTOPIC", VF_COMMON | VF_VENDOR);
        }
index 2cd090f977de7b7cfbef310794ac5821ddf05080..3e504b8e52a353f25c32c8b21dd3a3c33d3a1e99 100644 (file)
@@ -20,7 +20,7 @@
 
 
 #include "inspircd.h"
-#include "m_cap.h"
+#include "modules/cap.h"
 
 /* $ModDesc: Provides the UHNAMES facility. */
 
@@ -33,27 +33,23 @@ class ModuleUHNames : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnEvent, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       ~ModuleUHNames()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the UHNAMES facility.",VF_VENDOR);
        }
 
-       void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output.append(" UHNAMES");
+               tokens["UHNAMES"];
        }
 
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
                /* We don't actually create a proper command handler class for PROTOCTL,
                 * because other modules might want to have PROTOCTL hooks too.
@@ -71,7 +67,7 @@ class ModuleUHNames : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
+       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
        {
                if (!cap.ext.get(issuer))
                        return;
@@ -82,7 +78,7 @@ class ModuleUHNames : public Module
                nick = memb->user->GetFullHost();
        }
 
-       void OnEvent(Event& ev)
+       void OnEvent(Event& ev) CXX11_OVERRIDE
        {
                cap.HandleEvent(ev);
        }
index 10fd7c7b63605ef7eb04bb3e441b0b589434c2e2..79a0d8eecac8048e8ce1e2f2612a09c3fd7646c6 100644 (file)
@@ -70,15 +70,13 @@ class CommandUninvite : public Command
                LocalUser* lu = IS_LOCAL(u);
                if (lu)
                {
-                       irc::string xname(c->name.c_str());
-                       if (!lu->IsInvited(xname))
+                       if (!lu->RemoveInvite(c))
                        {
                                user->SendText(":%s 505 %s %s %s :Is not invited to channel %s", user->server.c_str(), user->nick.c_str(), u->nick.c_str(), c->name.c_str(), c->name.c_str());
                                return CMD_FAILURE;
                        }
 
                        user->SendText(":%s 494 %s %s %s :Uninvited", user->server.c_str(), user->nick.c_str(), c->name.c_str(), u->nick.c_str());
-                       lu->RemoveInvite(xname);
                        lu->WriteNumeric(493, "%s :You were uninvited from %s by %s", u->nick.c_str(), c->name.c_str(), user->nick.c_str());
 
                        std::string msg = "*** " + user->nick + " uninvited " + u->nick + ".";
@@ -106,20 +104,15 @@ class ModuleUninvite : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleUninvite()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the UNINVITE command which lets users un-invite other users from channels", VF_VENDOR | VF_OPTCOMMON);
        }
 };
 
 MODULE_INIT(ModuleUninvite)
-
index bfac36b1a5ce2534e0a1c6a5a5b48ba616f63669..670e9a9d7a7c9a6f25634c5dd3f8f3fa6b22dd2e 100644 (file)
@@ -61,8 +61,8 @@ class CommandUserip : public Command
                                                continue;
                                }
 
-                               retbuf = retbuf + u->nick + (IS_OPER(u) ? "*" : "") + "=";
-                               if (IS_AWAY(u))
+                               retbuf = retbuf + u->nick + (u->IsOper() ? "*" : "") + "=";
+                               if (u->IsAway())
                                        retbuf += "-";
                                else
                                        retbuf += "+";
@@ -87,28 +87,22 @@ class ModuleUserIP : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
                Implementation eventlist[] = { I_On005Numeric };
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               output = output + " USERIP";
+               tokens["USERIP"];
        }
 
-       virtual ~ModuleUserIP()
-       {
-       }
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for USERIP command",VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleUserIP)
-
index 31c504af8df7084a4ec713af73d631991eeb6dbd..965dbb35f8f38b4d97c677e0d593e3030decc385 100644 (file)
@@ -49,21 +49,20 @@ class CommandVhost : public Command
                        {
                                if (!mask.empty())
                                {
-                                       user->WriteServ("NOTICE "+user->nick+" :Setting your VHost: " + mask);
+                                       user->WriteNotice("Setting your VHost: " + mask);
                                        user->ChangeDisplayedHost(mask.c_str());
                                        return CMD_SUCCESS;
                                }
                        }
                }
 
-               user->WriteServ("NOTICE "+user->nick+" :Invalid username or password.");
+               user->WriteNotice("Invalid username or password.");
                return CMD_FAILURE;
        }
 };
 
 class ModuleVHost : public Module
 {
- private:
        CommandVhost cmd;
 
  public:
@@ -71,22 +70,15 @@ class ModuleVHost : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                ServerInstance->Modules->AddService(cmd);
        }
 
-       virtual ~ModuleVHost()
-       {
-       }
-
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides masking of user hostnames via traditional /VHOST command",VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleVHost)
-
index ec38edc31b8727b55e922234bc31078af72a64d8..712699775e318396bfa23d1eb547f56ecede8f23 100644 (file)
  * of users using WATCH.
  */
 
-/*
- * Before you start screaming, this definition is only used here, so moving it to a header is pointless.
- * Yes, it's horrid. Blame cl for being different. -- w00t
- */
-
-typedef nspace::hash_map<irc::string, std::deque<User*>, irc::hash> watchentries;
+typedef TR1NS::unordered_map<irc::string, std::deque<User*>, irc::hash> watchentries;
 typedef std::map<irc::string, std::string> watchlist;
 
 /* Who's watching each nickname.
@@ -151,7 +146,7 @@ class CommandWatch : public Command
        CmdResult remove_watch(User* user, const char* nick)
        {
                // removing an item from the list
-               if (!ServerInstance->IsNick(nick, ServerInstance->Config->Limits.NickMax))
+               if (!ServerInstance->IsNick(nick))
                {
                        user->WriteNumeric(942, "%s %s :Invalid nickname", user->nick.c_str(), nick);
                        return CMD_FAILURE;
@@ -201,7 +196,7 @@ class CommandWatch : public Command
 
        CmdResult add_watch(User* user, const char* nick)
        {
-               if (!ServerInstance->IsNick(nick, ServerInstance->Config->Limits.NickMax))
+               if (!ServerInstance->IsNick(nick))
                {
                        user->WriteNumeric(942, "%s %s :Invalid nickname",user->nick.c_str(),nick);
                        return CMD_FAILURE;
@@ -242,7 +237,7 @@ class CommandWatch : public Command
                        {
                                (*wl)[nick] = std::string(target->ident).append(" ").append(target->dhost).append(" ").append(ConvToStr(target->age));
                                user->WriteNumeric(604, "%s %s %s :is online",user->nick.c_str(), nick, (*wl)[nick].c_str());
-                               if (IS_AWAY(target))
+                               if (target->IsAway())
                                {
                                        user->WriteNumeric(609, "%s %s %s %s %lu :is away", user->nick.c_str(), target->nick.c_str(), target->ident.c_str(), target->dhost.c_str(), (unsigned long) target->awaytime);
                                }
@@ -320,7 +315,7 @@ class CommandWatch : public Command
                                                        {
                                                                user->WriteNumeric(604, "%s %s %s :is online", user->nick.c_str(), q->first.c_str(), q->second.c_str());
                                                                User *targ = ServerInstance->FindNick(q->first.c_str());
-                                                               if (IS_AWAY(targ))
+                                                               if (targ->IsAway())
                                                                {
                                                                        user->WriteNumeric(609, "%s %s %s %s %lu :is away", user->nick.c_str(), targ->nick.c_str(), targ->ident.c_str(), targ->dhost.c_str(), (unsigned long) targ->awaytime);
                                                                }
@@ -382,7 +377,7 @@ class Modulewatch : public Module
                whos_watching_me = new watchentries();
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
                ServerInstance->Modules->AddService(cmdw);
@@ -392,14 +387,14 @@ class Modulewatch : public Module
                ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
-       virtual void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                maxwatch = ServerInstance->Config->ConfValue("watch")->getInt("maxentries", 32);
                if (!maxwatch)
                        maxwatch = 32;
        }
 
-       virtual ModResult OnSetAway(User *user, const std::string &awaymsg)
+       ModResult OnSetAway(User *user, const std::string &awaymsg) CXX11_OVERRIDE
        {
                std::string numeric;
                int inum;
@@ -427,7 +422,7 @@ class Modulewatch : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
+       void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE
        {
                watchentries::iterator x = whos_watching_me->find(user->nick.c_str());
                if (x != whos_watching_me->end())
@@ -467,7 +462,7 @@ class Modulewatch : public Module
                }
        }
 
-       virtual void OnGarbageCollect()
+       void OnGarbageCollect()
        {
                watchentries* old_watch = whos_watching_me;
                whos_watching_me = new watchentries();
@@ -478,7 +473,7 @@ class Modulewatch : public Module
                delete old_watch;
        }
 
-       virtual void OnPostConnect(User* user)
+       void OnPostConnect(User* user) CXX11_OVERRIDE
        {
                watchentries::iterator x = whos_watching_me->find(user->nick.c_str());
                if (x != whos_watching_me->end())
@@ -495,7 +490,7 @@ class Modulewatch : public Module
                }
        }
 
-       virtual void OnUserPostNick(User* user, const std::string &oldnick)
+       void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE
        {
                watchentries::iterator new_offline = whos_watching_me->find(oldnick.c_str());
                watchentries::iterator new_online = whos_watching_me->find(user->nick.c_str());
@@ -527,22 +522,20 @@ class Modulewatch : public Module
                }
        }
 
-       virtual void On005Numeric(std::string &output)
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
        {
-               // we don't really have a limit...
-               output = output + " WATCH=" + ConvToStr(maxwatch);
+               tokens["WATCH"] = ConvToStr(maxwatch);
        }
 
-       virtual ~Modulewatch()
+       ~Modulewatch()
        {
                delete whos_watching_me;
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides support for the /WATCH command", VF_OPTCOMMON | VF_VENDOR);
        }
 };
 
 MODULE_INIT(Modulewatch)
-
index 5e83478c34d5c10c39b91639f7258c1740e93ca0..e325fc088558d7953abdf8bdf6b28f7dfcf47d7e 100644 (file)
@@ -30,7 +30,7 @@ class ModuleXLineDB : public Module
        bool dirty;
        std::string xlinedbpath;
  public:
-       void init()
+       void init() CXX11_OVERRIDE
        {
                /* Load the configuration
                 * Note:
@@ -49,16 +49,12 @@ class ModuleXLineDB : public Module
                dirty = false;
        }
 
-       virtual ~ModuleXLineDB()
-       {
-       }
-
        /** Called whenever an xline is added by a local user.
         * This method is triggered after the line is added.
         * @param source The sender of the line or NULL for local server
         * @param line The xline being added
         */
-       void OnAddLine(User* source, XLine* line)
+       void OnAddLine(User* source, XLine* line) CXX11_OVERRIDE
        {
                dirty = true;
        }
@@ -68,17 +64,17 @@ class ModuleXLineDB : public Module
         * @param source The user removing the line or NULL for local server
         * @param line the line being deleted
         */
-       void OnDelLine(User* source, XLine* line)
+       void OnDelLine(User* source, XLine* line) CXX11_OVERRIDE
        {
                dirty = true;
        }
 
-       void OnExpireLine(XLine *line)
+       void OnExpireLine(XLine *line) CXX11_OVERRIDE
        {
                dirty = true;
        }
 
-       void OnBackgroundTimer(time_t now)
+       void OnBackgroundTimer(time_t now) CXX11_OVERRIDE
        {
                if (dirty)
                {
@@ -97,17 +93,17 @@ class ModuleXLineDB : public Module
                 * Technically, that means that this can block, but I have *never* seen that.
                 *              -- w00t
                 */
-               ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Opening temporary database");
+               ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Opening temporary database");
                std::string xlinenewdbpath = xlinedbpath + ".new";
                f = fopen(xlinenewdbpath.c_str(), "w");
                if (!f)
                {
-                       ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Cannot create database! %s (%d)", strerror(errno), errno);
+                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot create database! %s (%d)", strerror(errno), errno);
                        ServerInstance->SNO->WriteToSnoMask('a', "database: cannot create new db: %s (%d)", strerror(errno), errno);
                        return false;
                }
 
-               ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Opened. Writing..");
+               ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Opened. Writing..");
 
                /*
                 * Now, much as I hate writing semi-unportable formats, additional
@@ -129,19 +125,23 @@ class ModuleXLineDB : public Module
                        for (LookupIter i = lookup->begin(); i != lookup->end(); ++i)
                        {
                                XLine* line = i->second;
-                               fprintf(f, "LINE %s %s %s %lu %lu :%s\n", line->type.c_str(), line->Displayable(),
-                                       ServerInstance->Config->ServerName.c_str(), (unsigned long)line->set_time, (unsigned long)line->duration, line->reason.c_str());
+                               fprintf(f, "LINE %s %s %s %lu %lu :%s\n",
+                                       line->type.c_str(),
+                                       line->Displayable().c_str(),
+                                       ServerInstance->Config->ServerName.c_str(),
+                                       (unsigned long)line->set_time,
+                                       (unsigned long)line->duration, line->reason.c_str());
                        }
                }
 
-               ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Finished writing XLines. Checking for error..");
+               ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Finished writing XLines. Checking for error..");
 
                int write_error = 0;
                write_error = ferror(f);
                write_error |= fclose(f);
                if (write_error)
                {
-                       ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Cannot write to new database! %s (%d)", strerror(errno), errno);
+                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot write to new database! %s (%d)", strerror(errno), errno);
                        ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
                        return false;
                }
@@ -149,7 +149,7 @@ class ModuleXLineDB : public Module
 #ifdef _WIN32
                if (remove(xlinedbpath.c_str()))
                {
-                       ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Cannot remove old database! %s (%d)", strerror(errno), errno);
+                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot remove old database! %s (%d)", strerror(errno), errno);
                        ServerInstance->SNO->WriteToSnoMask('a', "database: cannot remove old database: %s (%d)", strerror(errno), errno);
                        return false;
                }
@@ -157,7 +157,7 @@ class ModuleXLineDB : public Module
                // Use rename to move temporary to new db - this is guarenteed not to fuck up, even in case of a crash.
                if (rename(xlinenewdbpath.c_str(), xlinedbpath.c_str()) < 0)
                {
-                       ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Cannot move new to old database! %s (%d)", strerror(errno), errno);
+                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot move new to old database! %s (%d)", strerror(errno), errno);
                        ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
                        return false;
                }
@@ -181,7 +181,7 @@ class ModuleXLineDB : public Module
                        else
                        {
                                /* this might be slightly more problematic. */
-                               ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Cannot read database! %s (%d)", strerror(errno), errno);
+                               ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot read database! %s (%d)", strerror(errno), errno);
                                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot read db: %s (%d)", strerror(errno), errno);
                                return false;
                        }
@@ -213,18 +213,18 @@ class ModuleXLineDB : public Module
                                items++;
                        }
 
-                       ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Processing %s", linebuf);
+                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Processing %s", linebuf);
 
                        if (command_p[0] == "VERSION")
                        {
                                if (command_p[1] == "1")
                                {
-                                       ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: Reading db version %s", command_p[1].c_str());
+                                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Reading db version %s", command_p[1].c_str());
                                }
                                else
                                {
                                        fclose(f);
-                                       ServerInstance->Logs->Log("m_xline_db",DEBUG, "xlinedb: I got database version %s - I don't understand it", command_p[1].c_str());
+                                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: I got database version %s - I don't understand it", command_p[1].c_str());
                                        ServerInstance->SNO->WriteToSnoMask('a', "database: I got a database version (%s) I don't understand", command_p[1].c_str());
                                        return false;
                                }
@@ -256,13 +256,10 @@ class ModuleXLineDB : public Module
                return true;
        }
 
-
-
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Keeps a dynamic log of all XLines created, and stores them in a separate conf file (xline.db).", VF_VENDOR);
        }
 };
 
 MODULE_INIT(ModuleXLineDB)
-
diff --git a/src/modules/sasl.h b/src/modules/sasl.h
deleted file mode 100644 (file)
index f673511..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef SASL_H
-#define SASL_H
-
-class SASLFallback : public Event
-{
- public:
-       const parameterlist& params;
-       SASLFallback(Module* me, const parameterlist& p)
-               : Event(me, "sasl_fallback"), params(p)
-       {
-               Send();
-       }
-};
-
-#endif
diff --git a/src/modules/spanningtree.h b/src/modules/spanningtree.h
deleted file mode 100644 (file)
index 212f35f..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef SPANNINGTREE_H
-#define SPANNINGTREE_H
-
-struct AddServerEvent : public Event
-{
-       const std::string servername;
-       AddServerEvent(Module* me, const std::string& name)
-               : Event(me, "new_server"), servername(name)
-       {
-               Send();
-       }
-};
-
-struct DelServerEvent : public Event
-{
-       const std::string servername;
-       DelServerEvent(Module* me, const std::string& name)
-               : Event(me, "lost_server"), servername(name)
-       {
-               Send();
-       }
-};
-
-#endif
diff --git a/src/modules/sql.h b/src/modules/sql.h
deleted file mode 100644 (file)
index 436cd1d..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef INSPIRCD_SQLAPI_3
-#define INSPIRCD_SQLAPI_3
-
-/** Defines the error types which SQLerror may be set to
- */
-enum SQLerrorNum { SQL_NO_ERROR, SQL_BAD_DBID, SQL_BAD_CONN, SQL_QSEND_FAIL, SQL_QREPLY_FAIL };
-
-/** A list of format parameters for an SQLquery object.
- */
-typedef std::vector<std::string> ParamL;
-
-typedef std::map<std::string, std::string> ParamM;
-
-class SQLEntry
-{
- public:
-       std::string value;
-       bool nul;
-       SQLEntry() : nul(true) {}
-       SQLEntry(const std::string& v) : value(v), nul(false) {}
-       inline operator std::string&() { return value; }
-};
-
-typedef std::vector<SQLEntry> SQLEntries;
-
-/**
- * Result of an SQL query. Only valid inside OnResult
- */
-class SQLResult : public classbase
-{
- public:
-       /**
-        * Return the number of rows in the result.
-        *
-        * Note that if you have perfomed an INSERT or UPDATE query or other
-        * query which will not return rows, this will return the number of
-        * affected rows. In this case you SHOULD NEVER access any of the result
-        * set rows, as there aren't any!
-        * @returns Number of rows in the result set.
-        */
-       virtual int Rows() = 0;
-
-       /**
-        * Return a single row (result of the query). The internal row counter
-        * is incremented by one.
-        *
-        * @param result Storage for the result data.
-        * @returns true if there was a row, false if no row exists (end of
-        * iteration)
-        */
-       virtual bool GetRow(SQLEntries& result) = 0;
-
-       /** Returns column names for the items in this row
-        */
-       virtual void GetCols(std::vector<std::string>& result) = 0;
-};
-
-/** SQLerror holds the error state of a request.
- * The error string varies from database software to database software
- * and should be used to display informational error messages to users.
- */
-class SQLerror
-{
- public:
-       /** The error id
-        */
-       SQLerrorNum id;
-
-       /** The error string
-        */
-       std::string str;
-
-       /** Initialize an SQLerror
-        * @param i The error ID to set
-        * @param s The (optional) error string to set
-        */
-       SQLerror(SQLerrorNum i, const std::string &s = "")
-       : id(i), str(s)
-       {
-       }
-
-       /** Return the error string for an error
-        */
-       const char* Str()
-       {
-               if(str.length())
-                       return str.c_str();
-
-               switch(id)
-               {
-                       case SQL_BAD_DBID:
-                               return "Invalid database ID";
-                       case SQL_BAD_CONN:
-                               return "Invalid connection";
-                       case SQL_QSEND_FAIL:
-                               return "Sending query failed";
-                       case SQL_QREPLY_FAIL:
-                               return "Getting query result failed";
-                       default:
-                               return "Unknown error";
-               }
-       }
-};
-
-/**
- * Object representing an SQL query. This should be allocated on the heap and
- * passed to an SQLProvider, which will free it when the query is complete or
- * when the querying module is unloaded.
- *
- * You should store whatever information is needed to have the callbacks work in
- * this object (UID of user, channel name, etc).
- */
-class SQLQuery : public classbase
-{
- public:
-       ModuleRef creator;
-
-       SQLQuery(Module* Creator) : creator(Creator) {}
-       virtual ~SQLQuery() {}
-
-       virtual void OnResult(SQLResult& result) = 0;
-       /**
-        * Called when the query fails
-        */
-       virtual void OnError(SQLerror& error) { }
-};
-
-/**
- * Provider object for SQL servers
- */
-class SQLProvider : public DataProvider
-{
- public:
-       SQLProvider(Module* Creator, const std::string& Name) : DataProvider(Creator, Name) {}
-       /** Submit an asynchronous SQL request
-        * @param callback The result reporting point
-        * @param query The hardcoded query string. If you have parameters to substitute, see below.
-        */
-       virtual void submit(SQLQuery* callback, const std::string& query) = 0;
-
-       /** Submit an asynchronous SQL request
-        * @param callback The result reporting point
-        * @param format The simple parameterized query string ('?' parameters)
-        * @param p Parameters to fill in for the '?' entries
-        */
-       virtual void submit(SQLQuery* callback, const std::string& format, const ParamL& p) = 0;
-
-       /** Submit an asynchronous SQL request.
-        * @param callback The result reporting point
-        * @param format The parameterized query string ('$name' parameters)
-        * @param p Parameters to fill in for the '$name' entries
-        */
-       virtual void submit(SQLQuery* callback, const std::string& format, const ParamM& p) = 0;
-
-       /** Convenience function to prepare a map from a User* */
-       void PopulateUserInfo(User* user, ParamM& userinfo)
-       {
-               userinfo["nick"] = user->nick;
-               userinfo["host"] = user->host;
-               userinfo["ip"] = user->GetIPString();
-               userinfo["gecos"] = user->fullname;
-               userinfo["ident"] = user->ident;
-               userinfo["server"] = user->server;
-               userinfo["uuid"] = user->uuid;
-       }
-};
-
-#endif
diff --git a/src/modules/ssl.h b/src/modules/ssl.h
deleted file mode 100644 (file)
index 9deafb8..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef SSL_H
-#define SSL_H
-
-#include <map>
-#include <string>
-
-/** ssl_cert is a class which abstracts SSL certificate
- * and key information.
- *
- * Because gnutls and openssl represent key information in
- * wildly different ways, this class allows it to be accessed
- * in a unified manner. These classes are attached to ssl-
- * connected local users using SSLCertExt
- */
-class ssl_cert : public refcountbase
-{
- public:
-       std::string dn;
-       std::string issuer;
-       std::string error;
-       std::string fingerprint;
-       bool trusted, invalid, unknownsigner, revoked;
-
-       ssl_cert() : trusted(false), invalid(true), unknownsigner(true), revoked(false) {}
-
-       /** Get certificate distinguished name
-        * @return Certificate DN
-        */
-       const std::string& GetDN()
-       {
-               return dn;
-       }
-
-       /** Get Certificate issuer
-        * @return Certificate issuer
-        */
-       const std::string& GetIssuer()
-       {
-               return issuer;
-       }
-
-       /** Get error string if an error has occured
-        * @return The error associated with this users certificate,
-        * or an empty string if there is no error.
-        */
-       const std::string& GetError()
-       {
-               return error;
-       }
-
-       /** Get key fingerprint.
-        * @return The key fingerprint as a hex string.
-        */
-       const std::string& GetFingerprint()
-       {
-               return fingerprint;
-       }
-
-       /** Get trust status
-        * @return True if this is a trusted certificate
-        * (the certificate chain validates)
-        */
-       bool IsTrusted()
-       {
-               return trusted;
-       }
-
-       /** Get validity status
-        * @return True if the certificate itself is
-        * correctly formed.
-        */
-       bool IsInvalid()
-       {
-               return invalid;
-       }
-
-       /** Get signer status
-        * @return True if the certificate appears to be
-        * self-signed.
-        */
-       bool IsUnknownSigner()
-       {
-               return unknownsigner;
-       }
-
-       /** Get revokation status.
-        * @return True if the certificate is revoked.
-        * Note that this only works properly for GnuTLS
-        * right now.
-        */
-       bool IsRevoked()
-       {
-               return revoked;
-       }
-
-       bool IsCAVerified()
-       {
-               return trusted && !invalid && !revoked && !unknownsigner && error.empty();
-       }
-
-       std::string GetMetaLine()
-       {
-               std::stringstream value;
-               bool hasError = !error.empty();
-               value << (IsInvalid() ? "v" : "V") << (IsTrusted() ? "T" : "t") << (IsRevoked() ? "R" : "r")
-                       << (IsUnknownSigner() ? "s" : "S") << (hasError ? "E" : "e") << " ";
-               if (hasError)
-                       value << GetError();
-               else
-                       value << GetFingerprint() << " " << GetDN() << " " << GetIssuer();
-               return value.str();
-       }
-};
-
-/** Get certificate from a socket (only useful with an SSL module) */
-struct SocketCertificateRequest : public Request
-{
-       StreamSocket* const sock;
-       ssl_cert* cert;
-
-       SocketCertificateRequest(StreamSocket* ss, Module* Me)
-               : Request(Me, ss->GetIOHook(), "GET_SSL_CERT"), sock(ss), cert(NULL)
-       {
-               Send();
-       }
-
-       std::string GetFingerprint()
-       {
-               if (cert)
-                       return cert->GetFingerprint();
-               return "";
-       }
-};
-
-/** Get certificate from a user (requires m_sslinfo) */
-struct UserCertificateRequest : public Request
-{
-       User* const user;
-       ssl_cert* cert;
-
-       UserCertificateRequest(User* u, Module* Me, Module* info = ServerInstance->Modules->Find("m_sslinfo.so"))
-               : Request(Me, info, "GET_USER_CERT"), user(u), cert(NULL)
-       {
-               Send();
-       }
-
-       std::string GetFingerprint()
-       {
-               if (cert)
-                       return cert->GetFingerprint();
-               return "";
-       }
-};
-
-#endif
diff --git a/src/modules/u_listmode.h b/src/modules/u_listmode.h
deleted file mode 100644 (file)
index 0f5903e..0000000
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef INSPIRCD_LISTMODE_PROVIDER
-#define INSPIRCD_LISTMODE_PROVIDER
-
-/** Get the time as a string
- */
-inline std::string stringtime()
-{
-       std::ostringstream TIME;
-       TIME << ServerInstance->Time();
-       return TIME.str();
-}
-
-/** An item in a listmode's list
- */
-class ListItem
-{
-public:
-       std::string nick;
-       std::string mask;
-       std::string time;
-};
-
-/** The number of items a listmode's list may contain
- */
-class ListLimit
-{
-public:
-       std::string mask;
-       unsigned int limit;
-};
-
-/** Items stored in the channel's list
- */
-typedef std::list<ListItem> modelist;
-/** Max items per channel by name
- */
-typedef std::list<ListLimit> limitlist;
-
-/** The base class for list modes, should be inherited.
- */
-class ListModeBase : public ModeHandler
-{
- protected:
-       /** Numeric to use when outputting the list
-        */
-       unsigned int listnumeric;
-       /** Numeric to indicate end of list
-        */
-       unsigned int endoflistnumeric;
-       /** String to send for end of list
-        */
-       std::string endofliststring;
-       /** Automatically tidy up entries
-        */
-       bool tidy;
-       /** Config tag to check for max items per channel
-        */
-       std::string configtag;
-       /** Limits on a per-channel basis read from the tag
-        * specified in ListModeBase::configtag
-        */
-       limitlist chanlimits;
-
- public:
-       /** Storage key
-        */
-       SimpleExtItem<modelist> extItem;
-
-       /** Constructor.
-        * @param Instance The creator of this class
-        * @param modechar Mode character
-        * @param eolstr End of list string
-        * @pram lnum List numeric
-        * @param eolnum End of list numeric
-        * @param autotidy Automatically tidy list entries on add
-        * @param ctag Configuration tag to get limits from
-        */
-       ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag = "banlist")
-               : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL), 
-               listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy),
-               configtag(ctag), extItem("listbase_mode_" + name + "_list", Creator)
-       {
-               list = true;
-       }
-
-       /** See mode.h
-        */
-       std::pair<bool,std::string> ModeSet(User*, User*, Channel* channel, const std::string &parameter)
-       {
-               modelist* el = extItem.get(channel);
-               if (el)
-               {
-                       for (modelist::iterator it = el->begin(); it != el->end(); it++)
-                       {
-                               if(parameter == it->mask)
-                               {
-                                       return std::make_pair(true, parameter);
-                               }
-                       }
-               }
-               return std::make_pair(false, parameter);
-       }
-
-       /** Display the list for this mode
-        * @param user The user to send the list to
-        * @param channel The channel the user is requesting the list for
-        */
-       virtual void DisplayList(User* user, Channel* channel)
-       {
-               modelist* el = extItem.get(channel);
-               if (el)
-               {
-                       for (modelist::reverse_iterator it = el->rbegin(); it != el->rend(); ++it)
-                       {
-                               user->WriteNumeric(listnumeric, "%s %s %s %s %s", user->nick.c_str(), channel->name.c_str(), it->mask.c_str(), (it->nick.length() ? it->nick.c_str() : ServerInstance->Config->ServerName.c_str()), it->time.c_str());
-                       }
-               }
-               user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str());
-       }
-
-       virtual void DisplayEmptyList(User* user, Channel* channel)
-       {
-               user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str());
-       }
-
-       /** Remove all instances of the mode from a channel.
-        * See mode.h
-        * @param channel The channel to remove all instances of the mode from
-        */
-       virtual void RemoveMode(Channel* channel, irc::modestacker* stack)
-       {
-               modelist* el = extItem.get(channel);
-               if (el)
-               {
-                       irc::modestacker modestack(false);
-
-                       for (modelist::iterator it = el->begin(); it != el->end(); it++)
-                       {
-                               if (stack)
-                                       stack->Push(this->GetModeChar(), it->mask);
-                               else
-                                       modestack.Push(this->GetModeChar(), it->mask);
-                       }
-
-                       if (stack)
-                               return;
-
-                       std::vector<std::string> stackresult;
-                       stackresult.push_back(channel->name);
-                       while (modestack.GetStackedLine(stackresult))
-                       {
-                               ServerInstance->SendMode(stackresult, ServerInstance->FakeClient);
-                               stackresult.clear();
-                               stackresult.push_back(channel->name);
-                       }
-               }
-       }
-
-       /** See mode.h
-        */
-       virtual void RemoveMode(User*, irc::modestacker* stack)
-       {
-               /* Listmodes dont get set on users */
-       }
-
-       /** Perform a rehash of this mode's configuration data
-        */
-       virtual void DoRehash()
-       {
-               ConfigTagList tags = ServerInstance->Config->ConfTags(configtag);
-
-               chanlimits.clear();
-
-               for (ConfigIter i = tags.first; i != tags.second; i++)
-               {
-                       // For each <banlist> tag
-                       ConfigTag* c = i->second;
-                       ListLimit limit;
-                       limit.mask = c->getString("chan");
-                       limit.limit = c->getInt("limit");
-
-                       if (limit.mask.size() && limit.limit > 0)
-                               chanlimits.push_back(limit);
-               }
-               if (chanlimits.empty())
-               {
-                       ListLimit limit;
-                       limit.mask = "*";
-                       limit.limit = 64;
-                       chanlimits.push_back(limit);
-               }
-       }
-
-       /** Populate the Implements list with the correct events for a List Mode
-        */
-       virtual void DoImplements(Module* m)
-       {
-               ServerInstance->Modules->AddService(extItem);
-               this->DoRehash();
-               Implementation eventlist[] = { I_OnSyncChannel, I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, m, sizeof(eventlist)/sizeof(Implementation));
-       }
-
-       /** Handle the list mode.
-        * See mode.h
-        */
-       virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
-       {
-               // Try and grab the list
-               modelist* el = extItem.get(channel);
-
-               if (adding)
-               {
-                       if (tidy)
-                               ModeParser::CleanMask(parameter);
-
-                       if (parameter.length() > 250)
-                               return MODEACTION_DENY;
-
-                       // If there was no list
-                       if (!el)
-                       {
-                               // Make one
-                               el = new modelist;
-                               extItem.set(channel, el);
-                       }
-
-                       // Check if the item already exists in the list
-                       for (modelist::iterator it = el->begin(); it != el->end(); it++)
-                       {
-                               if (parameter == it->mask)
-                               {
-                                       /* Give a subclass a chance to error about this */
-                                       TellAlreadyOnList(source, channel, parameter);
-
-                                       // it does, deny the change
-                                       return MODEACTION_DENY;
-                               }
-                       }
-
-                       unsigned int maxsize = 0;
-
-                       for (limitlist::iterator it = chanlimits.begin(); it != chanlimits.end(); it++)
-                       {
-                               if (InspIRCd::Match(channel->name, it->mask))
-                               {
-                                       // We have a pattern matching the channel...
-                                       maxsize = el->size();
-                                       if (!IS_LOCAL(source) || (maxsize < it->limit))
-                                       {
-                                               /* Ok, it *could* be allowed, now give someone subclassing us
-                                                * a chance to validate the parameter.
-                                                * The param is passed by reference, so they can both modify it
-                                                * and tell us if we allow it or not.
-                                                *
-                                                * eg, the subclass could:
-                                                * 1) allow
-                                                * 2) 'fix' parameter and then allow
-                                                * 3) deny
-                                                */
-                                               if (ValidateParam(source, channel, parameter))
-                                               {
-                                                       // And now add the mask onto the list...
-                                                       ListItem e;
-                                                       e.mask = parameter;
-                                                       e.nick = source->nick;
-                                                       e.time = stringtime();
-
-                                                       el->push_back(e);
-                                                       return MODEACTION_ALLOW;
-                                               }
-                                               else
-                                               {
-                                                       /* If they deny it they have the job of giving an error message */
-                                                       return MODEACTION_DENY;
-                                               }
-                                       }
-                               }
-                       }
-
-                       /* List is full, give subclass a chance to send a custom message */
-                       if (!TellListTooLong(source, channel, parameter))
-                       {
-                               source->WriteNumeric(478, "%s %s %s :Channel ban/ignore list is full", source->nick.c_str(), channel->name.c_str(), parameter.c_str());
-                       }
-
-                       parameter.clear();
-                       return MODEACTION_DENY;
-               }
-               else
-               {
-                       // We're taking the mode off
-                       if (el)
-                       {
-                               for (modelist::iterator it = el->begin(); it != el->end(); it++)
-                               {
-                                       if (parameter == it->mask)
-                                       {
-                                               el->erase(it);
-                                               if (el->empty())
-                                               {
-                                                       extItem.unset(channel);
-                                               }
-                                               return MODEACTION_ALLOW;
-                                       }
-                               }
-                               /* Tried to remove something that wasn't set */
-                               TellNotSet(source, channel, parameter);
-                               parameter.clear();
-                               return MODEACTION_DENY;
-                       }
-                       else
-                       {
-                               /* Hmm, taking an exception off a non-existant list, DIE */
-                               TellNotSet(source, channel, parameter);
-                               parameter.clear();
-                               return MODEACTION_DENY;
-                       }
-               }
-               return MODEACTION_DENY;
-       }
-
-       /** Syncronize channel item list with another server.
-        * See modules.h
-        * @param chan Channel to syncronize
-        * @param proto Protocol module pointer
-        * @param opaque Opaque connection handle
-        */
-       virtual void DoSyncChannel(Channel* chan, Module* proto, void* opaque)
-       {
-               modelist* mlist = extItem.get(chan);
-               irc::modestacker modestack(true);
-               std::vector<std::string> stackresult;
-               std::vector<TranslateType> types;
-               types.push_back(TR_TEXT);
-               if (mlist)
-               {
-                       for (modelist::iterator it = mlist->begin(); it != mlist->end(); it++)
-                       {
-                               modestack.Push(std::string(1, mode)[0], it->mask);
-                       }
-               }
-               while (modestack.GetStackedLine(stackresult))
-               {
-                       types.assign(stackresult.size(), this->GetTranslateType());
-                       proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, stackresult, types);
-                       stackresult.clear();
-               }
-       }
-
-       /** Clean up module on unload
-        * @param target_type Type of target to clean
-        * @param item Item to clean
-        */
-       virtual void DoCleanup(int, void*)
-       {
-       }
-
-       /** Validate parameters.
-        * Overridden by implementing module.
-        * @param source Source user adding the parameter
-        * @param channel Channel the parameter is being added to
-        * @param parameter The actual parameter being added
-        * @return true if the parameter is valid
-        */
-       virtual bool ValidateParam(User*, Channel*, std::string&)
-       {
-               return true;
-       }
-
-       /** Tell the user the list is too long.
-        * Overridden by implementing module.
-        * @param source Source user adding the parameter
-        * @param channel Channel the parameter is being added to
-        * @param parameter The actual parameter being added
-        * @return Ignored
-        */
-       virtual bool TellListTooLong(User*, Channel*, std::string&)
-       {
-               return false;
-       }
-
-       /** Tell the user an item is already on the list.
-        * Overridden by implementing module.
-        * @param source Source user adding the parameter
-        * @param channel Channel the parameter is being added to
-        * @param parameter The actual parameter being added
-        */
-       virtual void TellAlreadyOnList(User*, Channel*, std::string&)
-       {
-       }
-
-       /** Tell the user that the parameter is not in the list.
-        * Overridden by implementing module.
-        * @param source Source user removing the parameter
-        * @param channel Channel the parameter is being removed from
-        * @param parameter The actual parameter being removed
-        */
-       virtual void TellNotSet(User*, Channel*, std::string&)
-       {
-       }
-};
-
-#endif
index 4741f942d53d2b5e838ddf52f1f16f5a435aeb92..55c230f9694af47cf289c0bda502cc1520fa85fb 100644 (file)
@@ -23,7 +23,6 @@
 #include <signal.h>
 #include "exitcodes.h"
 #include "inspircd.h"
-#include "inspircd_version.h"
 
 void InspIRCd::SignalHandler(int signal)
 {
@@ -59,7 +58,6 @@ void InspIRCd::Exit(int status)
 void RehashHandler::Call(const std::string &reason)
 {
        ServerInstance->SNO->WriteToSnoMask('a', "Rehashing config file %s %s",ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()), reason.c_str());
-       ServerInstance->RehashUsersAndChans();
        FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
        if (!ServerInstance->ConfigThread)
        {
@@ -68,36 +66,28 @@ void RehashHandler::Call(const std::string &reason)
        }
 }
 
-std::string InspIRCd::GetVersionString(bool operstring)
+std::string InspIRCd::GetVersionString(bool getFullVersion)
 {
-       char versiondata[MAXBUF];
-       if (operstring)
-       {
-               std::string sename = SE->GetName();
-               snprintf(versiondata,MAXBUF,"%s %s :%s [%s,%s,%s]",VERSION, Config->ServerName.c_str(), SYSTEM,REVISION, sename.c_str(), Config->sid.c_str());
-       }
-       else
-               snprintf(versiondata,MAXBUF,"%s %s :%s",BRANCH,Config->ServerName.c_str(),Config->CustomVersion.c_str());
-       return versiondata;
+       if (getFullVersion)
+               return VERSION " " + Config->ServerName + " :" SYSTEM " [" REVISION "," + SE->GetName() + "," + Config->sid + "]";
+       return BRANCH " " + Config->ServerName + " :" + Config->CustomVersion;
 }
 
-const char InspIRCd::LogHeader[] =
-       "Log started for " VERSION " (" REVISION ", " MODULE_INIT_STR ")"
-       " - compiled on " SYSTEM;
-
-void InspIRCd::BuildISupport()
+std::string UIDGenerator::GenerateSID(const std::string& servername, const std::string& serverdesc)
 {
-       // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
-       std::stringstream v;
-       v << "WALLCHOPS WALLVOICES MODES=" << Config->Limits.MaxModes << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << Config->Limits.NickMax;
-       v << " CASEMAPPING=rfc1459 STATUSMSG=" << Modes->BuildPrefixes(false) << " CHARSET=ascii TOPICLEN=" << Config->Limits.MaxTopic << " KICKLEN=" << Config->Limits.MaxKick << " MAXTARGETS=" << Config->MaxTargets;
-       v << " AWAYLEN=" << Config->Limits.MaxAway << " CHANMODES=" << this->Modes->GiveModeList(MASK_CHANNEL) << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU" << " CHANNELLEN=" << Config->Limits.ChanMax;
-       Config->data005 = v.str();
-       FOREACH_MOD(I_On005Numeric,On005Numeric(Config->data005));
-       Config->Update005();
+       unsigned int sid = 0;
+
+       for (std::string::const_iterator i = servername.begin(); i != servername.end(); ++i)
+               sid = 5 * sid + *i;
+       for (std::string::const_iterator i = serverdesc.begin(); i != serverdesc.end(); ++i)
+               sid = 5 * sid + *i;
+
+       std::string sidstr = ConvToStr(sid % 1000);
+       sidstr.insert(0, 3 - sidstr.length(), '0');
+       return sidstr;
 }
 
-void InspIRCd::IncrementUID(int pos)
+void UIDGenerator::IncrementUID(unsigned int pos)
 {
        /*
         * Okay. The rules for generating a UID go like this...
@@ -106,85 +96,141 @@ void InspIRCd::IncrementUID(int pos)
         * A again, in an iterative fashion.. so..
         * AAA9 -> AABA, and so on. -- w00t
         */
-       if ((pos == 3) && (current_uid[3] == '9'))
+
+       // If we hit Z, wrap around to 0.
+       if (current_uid[pos] == 'Z')
+       {
+               current_uid[pos] = '0';
+       }
+       else if (current_uid[pos] == '9')
        {
-               // At pos 3, if we hit '9', we've run out of available UIDs, and need to reset to AAA..AAA.
-               for (int i = 3; i < UUID_LENGTH-1; i++)
+               /*
+                * Or, if we hit 9, wrap around to pos = 'A' and (pos - 1)++,
+                * e.g. A9 -> BA -> BB ..
+                */
+               current_uid[pos] = 'A';
+               if (pos == 3)
                {
-                       current_uid[i] = 'A';
+                       // At pos 3, if we hit '9', we've run out of available UIDs, and reset to AAA..AAA.
+                       return;
                }
+               this->IncrementUID(pos - 1);
        }
        else
        {
-               // If we hit Z, wrap around to 0.
-               if (current_uid[pos] == 'Z')
-               {
-                       current_uid[pos] = '0';
-               }
-               else if (current_uid[pos] == '9')
-               {
-                       /*
-                        * Or, if we hit 9, wrap around to pos = 'A' and (pos - 1)++,
-                        * e.g. A9 -> BA -> BB ..
-                        */
-                       current_uid[pos] = 'A';
-                       this->IncrementUID(pos - 1);
-               }
-               else
-               {
-                       // Anything else, nobody gives a shit. Just increment.
-                       current_uid[pos]++;
-               }
+               // Anything else, nobody gives a shit. Just increment.
+               current_uid[pos]++;
        }
 }
 
-/*
- * Retrieve the next valid UUID that is free for this server.
- */
-std::string InspIRCd::GetUID()
+void UIDGenerator::init(const std::string& sid)
 {
-       static bool inited = false;
-
        /*
-        * If we're setting up, copy SID into the first three digits, 9's to the rest, null term at the end
+        * Copy SID into the first three digits, 9's to the rest, null term at the end
         * Why 9? Well, we increment before we find, otherwise we have an unnecessary copy, and I want UID to start at AAA..AA
         * and not AA..AB. So by initialising to 99999, we force it to rollover to AAAAA on the first IncrementUID call.
         * Kind of silly, but I like how it looks.
         *              -- w
         */
-       if (!inited)
-       {
-               inited = true;
-               current_uid[0] = Config->sid[0];
-               current_uid[1] = Config->sid[1];
-               current_uid[2] = Config->sid[2];
 
-               for (int i = 3; i < (UUID_LENGTH - 1); i++)
-                       current_uid[i] = '9';
-
-               // Null terminator. Important.
-               current_uid[UUID_LENGTH - 1] = '\0';
-       }
+       current_uid.resize(UUID_LENGTH, '9');
+       current_uid[0] = sid[0];
+       current_uid[1] = sid[1];
+       current_uid[2] = sid[2];
+}
 
+/*
+ * Retrieve the next valid UUID that is free for this server.
+ */
+std::string UIDGenerator::GetUID()
+{
        while (1)
        {
                // Add one to the last UID
-               this->IncrementUID(UUID_LENGTH - 2);
+               this->IncrementUID(UUID_LENGTH - 1);
 
-               if (this->FindUUID(current_uid))
-               {
-                       /*
-                        * It's in use. We need to try the loop again.
-                        */
-                       continue;
-               }
+               if (!ServerInstance->FindUUID(current_uid))
+                       break;
 
-               return current_uid;
+               /*
+                * It's in use. We need to try the loop again.
+                */
        }
 
-       /* not reached. */
-       return "";
+       return current_uid;
 }
 
+void ISupportManager::Build()
+{
+       /**
+        * This is currently the neatest way we can build the initial ISUPPORT map. In
+        * the future we can use an initializer list here.
+        */
+       std::map<std::string, std::string> tokens;
+
+       tokens["AWAYLEN"] = ConvToStr(ServerInstance->Config->Limits.MaxAway);
+       tokens["CASEMAPPING"] = "rfc1459";
+       tokens["CHANMODES"] = ServerInstance->Modes->GiveModeList(MASK_CHANNEL);
+       tokens["CHANNELLEN"] = ConvToStr(ServerInstance->Config->Limits.ChanMax);
+       tokens["CHANTYPES"] = "#";
+       tokens["CHARSET"] = "ascii";
+       tokens["ELIST"] = "MU";
+       tokens["KICKLEN"] = ConvToStr(ServerInstance->Config->Limits.MaxKick);
+       tokens["MAXBANS"] = "64"; // TODO: make this a config setting.
+       tokens["MAXCHANNELS"] = ConvToStr(ServerInstance->Config->MaxChans);
+       tokens["MAXTARGETS"] = ConvToStr(ServerInstance->Config->MaxTargets);
+       tokens["MODES"] = ConvToStr(ServerInstance->Config->Limits.MaxModes);
+       tokens["NETWORK"] = ServerInstance->Config->Network;
+       tokens["NICKLEN"] = ConvToStr(ServerInstance->Config->Limits.NickMax);
+       tokens["PREFIX"] = ServerInstance->Modes->BuildPrefixes();
+       tokens["STATUSMSG"] = ServerInstance->Modes->BuildPrefixes(false);
+       tokens["TOPICLEN"] = ConvToStr(ServerInstance->Config->Limits.MaxTopic);
+
+       tokens["FNC"] = tokens["MAP"] = tokens["VBANLIST"] =
+               tokens["WALLCHOPS"] = tokens["WALLVOICES"];
+
+       // Modules can add new tokens and also edit or remove existing tokens
+       FOREACH_MOD(I_On005Numeric, On005Numeric(tokens));
+
+       // EXTBAN is a special case as we need to sort it and prepend a comma.
+       std::map<std::string, std::string>::iterator extban = tokens.find("EXTBAN");
+       if (extban != tokens.end())
+       {
+               sort(extban->second.begin(), extban->second.end());
+               extban->second.insert(0, ",");
+       }
+
+       // Transform the map into a list of lines, ready to be sent to clients
+       std::vector<std::string>& lines = this->Lines;
+       std::string line;
+       unsigned int token_count = 0;
+       lines.clear();
+
+       for (std::map<std::string, std::string>::const_iterator it = tokens.begin(); it != tokens.end(); ++it)
+       {
+               line.append(it->first);
+
+               // If this token has a value then append a '=' char after the name and then the value itself
+               if (!it->second.empty())
+                       line.append(1, '=').append(it->second);
 
+               // Always append a space, even if it's the last token because all lines will be suffixed
+               line.push_back(' ');
+               token_count++;
 
+               if (token_count % 13 == 12 || it == --tokens.end())
+               {
+                       // Reached maximum number of tokens for this line or the current token
+                       // is the last one; finalize the line and store it for later use
+                       line.append(":are supported by this server");
+                       lines.push_back(line);
+                       line.clear();
+               }
+       }
+}
+
+void ISupportManager::SendTo(LocalUser* user)
+{
+       for (std::vector<std::string>::const_iterator i = this->Lines.begin(); i != this->Lines.end(); ++i)
+               user->WriteNumeric(RPL_ISUPPORT, "%s %s", user->nick.c_str(), i->c_str());
+}
index 4b9c9d86b29194162eff736b61bee1da848af5c9..820f65e4bb81fbfacd0819c998c85a163e2e8375 100644 (file)
@@ -52,26 +52,16 @@ void SnomaskManager::WriteGlobalSno(char letter, const std::string& text)
 
 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteToSnoMask(letter, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteToSnoMask(letter, textbuffer);
 }
 
 void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteGlobalSno(letter, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteGlobalSno(letter, textbuffer);
 }
 
 SnomaskManager::SnomaskManager()
@@ -104,7 +94,7 @@ void Snomask::SendMessage(const std::string &message, char mysnomask)
                if (isupper(mysnomask))
                        desc = "REMOTE" + desc;
                ModResult MOD_RESULT;
-               ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), message.c_str());
+               ServerInstance->Logs->Log("snomask", LOG_DEFAULT, "%s: %s", desc.c_str(), message.c_str());
 
                FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (mysnomask, desc, message));
 
@@ -120,7 +110,7 @@ void Snomask::SendMessage(const std::string &message, char mysnomask)
                                User* a = *i;
                                if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
                                {
-                                       a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), message.c_str());
+                                       a->WriteNotice("*** " + desc + ": " + message);
                                }
 
                                i++;
@@ -141,7 +131,7 @@ void Snomask::Flush()
                        desc = "REMOTE" + desc;
                std::string mesg = "(last message repeated "+ConvToStr(Count)+" times)";
 
-               ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
+               ServerInstance->Logs->Log("snomask", LOG_DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
 
                FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(LastLetter, desc, mesg));
 
@@ -155,7 +145,7 @@ void Snomask::Flush()
                                User* a = *i;
                                if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(LastLetter) && !a->quitting)
                                {
-                                       a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), mesg.c_str());
+                                       a->WriteNotice("*** " + desc + ": " + mesg);
                                }
 
                                i++;
index 6fc7b13f8fc967e25bf248d8c08137ac9dd1b187..12fb632a756598fbcf0284d248362c3b5c9387e7 100644 (file)
@@ -58,19 +58,19 @@ bool InspIRCd::BindSocket(int sockfd, int port, const char* addr, bool dolisten)
                {
                        if (SE->Listen(sockfd, Config->MaxConn) == -1)
                        {
-                               this->Logs->Log("SOCKET",DEFAULT,"ERROR in listen(): %s",strerror(errno));
+                               this->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR in listen(): %s",strerror(errno));
                                return false;
                        }
                        else
                        {
-                               this->Logs->Log("SOCKET",DEBUG,"New socket binding for %d with listen: %s:%d", sockfd, addr, port);
+                               this->Logs->Log("SOCKET", LOG_DEBUG, "New socket binding for %d with listen: %s:%d", sockfd, addr, port);
                                SE->NonBlocking(sockfd);
                                return true;
                        }
                }
                else
                {
-                       this->Logs->Log("SOCKET",DEBUG,"New socket binding for %d without listen: %s:%d", sockfd, addr, port);
+                       this->Logs->Log("SOCKET", LOG_DEBUG, "New socket binding for %d without listen: %s:%d", sockfd, addr, port);
                        return true;
                }
        }
@@ -89,7 +89,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
                std::string Addr = tag->getString("address");
 
                if (strncasecmp(Addr.c_str(), "::ffff:", 7) == 0)
-                       this->Logs->Log("SOCKET",DEFAULT, "Using 4in6 (::ffff:) isn't recommended. You should bind IPv4 addresses directly instead.");
+                       this->Logs->Log("SOCKET", LOG_DEFAULT, "Using 4in6 (::ffff:) isn't recommended. You should bind IPv4 addresses directly instead.");
 
                irc::portparser portrange(porttag, false);
                int portno = -1;
@@ -136,11 +136,11 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
                        n++;
                if (n == ports.end())
                {
-                       this->Logs->Log("SOCKET",DEFAULT,"Port bindings slipped out of vector, aborting close!");
+                       this->Logs->Log("SOCKET", LOG_DEFAULT, "Port bindings slipped out of vector, aborting close!");
                        break;
                }
 
-               this->Logs->Log("SOCKET",DEFAULT, "Port binding %s was removed from the config file, closing.",
+               this->Logs->Log("SOCKET", LOG_DEFAULT, "Port binding %s was removed from the config file, closing.",
                        (**n).bind_desc.c_str());
                delete *n;
 
index 6c99edc95a789b34c83104507b8b538b17d8c1d0..80e9eaed97309ac1b4726e9364d35b7c6c99971f 100644 (file)
@@ -60,7 +60,7 @@ void SocketEngine::ChangeEventMask(EventHandler* eh, int change)
                new_m &= ~FD_WANT_READ_MASK;
        if (change & FD_WANT_WRITE_MASK)
                new_m &= ~FD_WANT_WRITE_MASK;
-       
+
        // if adding a trial read/write, insert it into the set
        if (change & FD_TRIAL_NOTE_MASK && !(old_m & FD_TRIAL_NOTE_MASK))
                trials.insert(eh->GetFd());
index f7e107e7b028cd4db4301b21b56f533117d8d432..68f14cc3840e7a5878097514cd28c50ed60f728f 100644 (file)
@@ -61,7 +61,7 @@ EPollEngine::EPollEngine()
        }
        else
        {
-               ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets!");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets!");
                std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl;
                ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
        }
@@ -71,8 +71,8 @@ EPollEngine::EPollEngine()
 
        if (EngineHandle == -1)
        {
-               ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: Could not initialize socket engine: %s", strerror(errno));
-               ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now.");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Could not initialize socket engine: %s", strerror(errno));
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now.");
                std::cout << "ERROR: Could not initialize epoll socket engine: " << strerror(errno) << std::endl;
                std::cout << "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now." << std::endl;
                ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
@@ -119,13 +119,13 @@ bool EPollEngine::AddFd(EventHandler* eh, int event_mask)
        int fd = eh->GetFd();
        if ((fd < 0) || (fd > GetMaxFds() - 1))
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
                return false;
        }
 
        if (ref[fd])
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"Attempt to add duplicate fd: %d", fd);
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Attempt to add duplicate fd: %d", fd);
                return false;
        }
 
@@ -136,11 +136,11 @@ bool EPollEngine::AddFd(EventHandler* eh, int event_mask)
        int i = epoll_ctl(EngineHandle, EPOLL_CTL_ADD, fd, &ev);
        if (i < 0)
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"Error adding fd: %d to socketengine: %s", fd, strerror(errno));
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Error adding fd: %d to socketengine: %s", fd, strerror(errno));
                return false;
        }
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
 
        ref[fd] = eh;
        SocketEngine::SetEventMask(eh, event_mask);
@@ -168,7 +168,7 @@ void EPollEngine::DelFd(EventHandler* eh)
        int fd = eh->GetFd();
        if ((fd < 0) || (fd > GetMaxFds() - 1))
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
                return;
        }
 
@@ -179,12 +179,12 @@ void EPollEngine::DelFd(EventHandler* eh)
 
        if (i < 0)
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"epoll_ctl can't remove socket: %s", strerror(errno));
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "epoll_ctl can't remove socket: %s", strerror(errno));
        }
 
        ref[fd] = NULL;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
        CurrentSetSize--;
 }
 
@@ -202,7 +202,7 @@ int EPollEngine::DispatchEvents()
                EventHandler* eh = ref[events[j].data.fd];
                if (!eh)
                {
-                       ServerInstance->Logs->Log("SOCKET",DEBUG,"Got event on unknown fd: %d", events[j].data.fd);
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Got event on unknown fd: %d", events[j].data.fd);
                        epoll_ctl(EngineHandle, EPOLL_CTL_DEL, events[j].data.fd, &events[j]);
                        continue;
                }
index e24146943d931b73780a844c04a5cc3a51332efa..a6c84133a10d52c5db6b97eb768db44556d9cd00 100644 (file)
@@ -72,7 +72,7 @@ KQueueEngine::KQueueEngine()
        sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0);
        if (MAX_DESCRIPTORS <= 0)
        {
-               ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets!");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets!");
                std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl;
                ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
        }
@@ -93,8 +93,8 @@ void KQueueEngine::RecoverFromFork()
        EngineHandle = kqueue();
        if (EngineHandle == -1)
        {
-               ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
-               ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: this is a fatal error, exiting now.");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: this is a fatal error, exiting now.");
                std::cout << "ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features." << std::endl;
                std::cout << "ERROR: this is a fatal error, exiting now." << std::endl;
                ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
@@ -126,7 +126,7 @@ bool KQueueEngine::AddFd(EventHandler* eh, int event_mask)
        int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
        if (i == -1)
        {
-               ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to add fd: %d %s",
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to add fd: %d %s",
                                          fd, strerror(errno));
                return false;
        }
@@ -136,7 +136,7 @@ bool KQueueEngine::AddFd(EventHandler* eh, int event_mask)
        OnSetEvent(eh, 0, event_mask);
        CurrentSetSize++;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
        return true;
 }
 
@@ -146,7 +146,7 @@ void KQueueEngine::DelFd(EventHandler* eh)
 
        if ((fd < 0) || (fd > GetMaxFds() - 1))
        {
-               ServerInstance->Logs->Log("SOCKET",DEFAULT,"DelFd() on invalid fd: %d", fd);
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "DelFd() on invalid fd: %d", fd);
                return;
        }
 
@@ -163,14 +163,14 @@ void KQueueEngine::DelFd(EventHandler* eh)
 
        if (j < 0)
        {
-               ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to remove fd: %d %s",
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to remove fd: %d %s",
                                          fd, strerror(errno));
        }
 
        CurrentSetSize--;
        ref[fd] = NULL;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
 }
 
 void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
@@ -182,7 +182,7 @@ void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
                EV_SET(&ke, eh->GetFd(), EVFILT_WRITE, EV_ADD, 0, 0, NULL);
                int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
                if (i < 0) {
-                       ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to mark for writing: %d %s",
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to mark for writing: %d %s",
                                                  eh->GetFd(), strerror(errno));
                }
        }
@@ -193,7 +193,7 @@ void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
                EV_SET(&ke, eh->GetFd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
                int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
                if (i < 0) {
-                       ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to mark for writing: %d %s",
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to mark for writing: %d %s",
                                                  eh->GetFd(), strerror(errno));
                }
        }
@@ -204,7 +204,7 @@ void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
                EV_SET(&ke, eh->GetFd(), EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, NULL);
                int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
                if (i < 0) {
-                       ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to mark for writing: %d %s",
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to mark for writing: %d %s",
                                                  eh->GetFd(), strerror(errno));
                }
        }
index 5c361a0cbded453bd9a913f957f4ff31ff02ad73..37f4b6836a09038d3b3abd3199c187a4608c9716 100644 (file)
@@ -20,9 +20,6 @@
  */
 
 
-#include "inspircd.h"
-#include "exitcodes.h"
-
 #ifndef SOCKETENGINE_POLL
 #define SOCKETENGINE_POLL
 
@@ -30,7 +27,7 @@
 #include <vector>
 #include <string>
 #include <map>
-#include "inspircd_config.h"
+#include "exitcodes.h"
 #include "inspircd.h"
 #include "socketengine.h"
 
@@ -105,7 +102,7 @@ PollEngine::PollEngine()
        }
        else
        {
-               ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets: %s", strerror(errno));
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets: %s", strerror(errno));
                std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl;
                ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
        }
@@ -140,13 +137,13 @@ bool PollEngine::AddFd(EventHandler* eh, int event_mask)
        int fd = eh->GetFd();
        if ((fd < 0) || (fd > GetMaxFds() - 1))
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
                return false;
        }
 
        if (fd_mappings.find(fd) != fd_mappings.end())
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"Attempt to add duplicate fd: %d", fd);
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Attempt to add duplicate fd: %d", fd);
                return false;
        }
 
@@ -157,7 +154,7 @@ bool PollEngine::AddFd(EventHandler* eh, int event_mask)
        events[index].fd = fd;
        events[index].events = mask_to_poll(event_mask);
 
-       ServerInstance->Logs->Log("SOCKET", DEBUG,"New file descriptor: %d (%d; index %d)", fd, events[fd].events, index);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d (%d; index %d)", fd, events[fd].events, index);
        SocketEngine::SetEventMask(eh, event_mask);
        CurrentSetSize++;
        return true;
@@ -176,7 +173,7 @@ void PollEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
        std::map<int, unsigned int>::iterator it = fd_mappings.find(eh->GetFd());
        if (it == fd_mappings.end())
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"SetEvents() on unknown fd: %d", eh->GetFd());
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "SetEvents() on unknown fd: %d", eh->GetFd());
                return;
        }
 
@@ -188,14 +185,14 @@ void PollEngine::DelFd(EventHandler* eh)
        int fd = eh->GetFd();
        if ((fd < 0) || (fd > MAX_DESCRIPTORS))
        {
-               ServerInstance->Logs->Log("SOCKET", DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
                return;
        }
 
        std::map<int, unsigned int>::iterator it = fd_mappings.find(fd);
        if (it == fd_mappings.end())
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd() on unknown fd: %d", fd);
+               ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd() on unknown fd: %d", fd);
                return;
        }
 
@@ -226,7 +223,7 @@ void PollEngine::DelFd(EventHandler* eh)
 
        CurrentSetSize--;
 
-       ServerInstance->Logs->Log("SOCKET", DEBUG, "Remove file descriptor: %d (index: %d) "
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d (index: %d) "
                        "(Filled gap with: %d (index: %d))", fd, index, last_fd, last_index);
 }
 
@@ -275,7 +272,7 @@ int PollEngine::DispatchEvents()
                                        // whoops, deleted out from under us
                                        continue;
                        }
-                       
+
                        if (events[index].revents & POLLOUT)
                        {
                                int mask = eh->GetEventMask();
index 52d799ddf286d2689d33879b383e6ff90d2e5c8f..8a2fb87f409ced96fd8ffa7b178f2f5901cb14e5 100644 (file)
@@ -32,7 +32,6 @@
 #include <vector>
 #include <string>
 #include <map>
-#include "inspircd_config.h"
 #include "inspircd.h"
 #include "socketengine.h"
 #include <port.h>
@@ -75,7 +74,7 @@ PortsEngine::PortsEngine()
        }
        else
        {
-               ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets!");
+               ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets!");
                std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl;
                ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
        }
@@ -83,8 +82,8 @@ PortsEngine::PortsEngine()
 
        if (EngineHandle == -1)
        {
-               ServerInstance->Logs->Log("SOCKET",SPARSE,"ERROR: Could not initialize socket engine: %s", strerror(errno));
-               ServerInstance->Logs->Log("SOCKET",SPARSE,"ERROR: This is a fatal error, exiting now.");
+               ServerInstance->Logs->Log("SOCKET", LOG_SPARSE, "ERROR: Could not initialize socket engine: %s", strerror(errno));
+               ServerInstance->Logs->Log("SOCKET", LOG_SPARSE, "ERROR: This is a fatal error, exiting now.");
                std::cout << "ERROR: Could not initialize socket engine: " << strerror(errno) << std::endl;
                std::cout << "ERROR: This is a fatal error, exiting now." << std::endl;
                ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
@@ -126,7 +125,7 @@ bool PortsEngine::AddFd(EventHandler* eh, int event_mask)
        SocketEngine::SetEventMask(eh, event_mask);
        port_associate(EngineHandle, PORT_SOURCE_FD, fd, mask_to_events(event_mask), eh);
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
        CurrentSetSize++;
        return true;
 }
@@ -148,7 +147,7 @@ void PortsEngine::DelFd(EventHandler* eh)
        CurrentSetSize--;
        ref[fd] = NULL;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
 }
 
 int PortsEngine::DispatchEvents()
index eba54a7cb27b1dd8e42dfa82faf8e6ffe225532e..de366266ff1133f40e3cd8d3cc320b93c626b324 100644 (file)
@@ -18,8 +18,6 @@
  */
 
 
-#include "inspircd_config.h"
-
 #include "inspircd.h"
 #include "socketengine.h"
 
@@ -86,7 +84,7 @@ bool SelectEngine::AddFd(EventHandler* eh, int event_mask)
 
        CurrentSetSize++;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
        return true;
 }
 
@@ -106,7 +104,7 @@ void SelectEngine::DelFd(EventHandler* eh)
        if (fd == MaxFD)
                --MaxFD;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
 }
 
 void SelectEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
index 58b72ee3efc8c3b47d64764b85bba05962ca983b..539827cf8d484d0d586d367e643b61df1bc0ee4a 100644 (file)
@@ -331,36 +331,25 @@ bool TestSuite::DoThreadTests()
 
 bool TestSuite::DoGenerateUIDTests()
 {
-       bool success = RealGenerateUIDTests();
+       const unsigned int UUID_LENGTH = UIDGenerator::UUID_LENGTH;
+       UIDGenerator uidgen;
+       uidgen.init(ServerInstance->Config->GetSID());
+       std::string first_uid = uidgen.GetUID();
 
-       // Reset the UID generation state so running the tests multiple times won't mess things up
-       for (unsigned int i = 0; i < 3; i++)
-               ServerInstance->current_uid[i] = ServerInstance->Config->sid[i];
-       for (unsigned int i = 3; i < UUID_LENGTH-1; i++)
-               ServerInstance->current_uid[i] = '9';
-
-       ServerInstance->current_uid[UUID_LENGTH-1] = '\0';
-
-       return success;
-}
-
-bool TestSuite::RealGenerateUIDTests()
-{
-       std::string first_uid = ServerInstance->GetUID();
-       if (first_uid.length() != UUID_LENGTH-1)
+       if (first_uid.length() != UUID_LENGTH)
        {
                std::cout << "GENERATEUID: Generated UID is " << first_uid.length() << " characters long instead of " << UUID_LENGTH-1 << std::endl;
                return false;
        }
 
-       if (ServerInstance->current_uid[UUID_LENGTH-1] != '\0')
+       if (uidgen.current_uid.c_str()[UUID_LENGTH] != '\0')
        {
                std::cout << "GENERATEUID: The null terminator is missing from the end of current_uid" << std::endl;
                return false;
        }
 
        // The correct UID when generating one for the first time is ...AAAAAA
-       std::string correct_uid = ServerInstance->Config->sid + std::string(UUID_LENGTH - 4, 'A');
+       std::string correct_uid = ServerInstance->Config->sid + std::string(UUID_LENGTH - 3, 'A');
        if (first_uid != correct_uid)
        {
                std::cout << "GENERATEUID: Generated an invalid first UID: " << first_uid << " instead of " << correct_uid << std::endl;
@@ -368,16 +357,16 @@ bool TestSuite::RealGenerateUIDTests()
        }
 
        // Set current_uid to be ...Z99999
-       ServerInstance->current_uid[3] = 'Z';
-       for (unsigned int i = 4; i < UUID_LENGTH-1; i++)
-               ServerInstance->current_uid[i] = '9';
+       uidgen.current_uid[3] = 'Z';
+       for (unsigned int i = 4; i < UUID_LENGTH; i++)
+               uidgen.current_uid[i] = '9';
 
        // Store the UID we'll be incrementing so we can display what's wrong later if necessary
-       std::string before_increment(ServerInstance->current_uid);
-       std::string generated_uid = ServerInstance->GetUID();
+       std::string before_increment(uidgen.current_uid);
+       std::string generated_uid = uidgen.GetUID();
 
        // Correct UID after incrementing ...Z99999 is ...0AAAAA
-       correct_uid = ServerInstance->Config->sid + "0" + std::string(UUID_LENGTH - 5, 'A');
+       correct_uid = ServerInstance->Config->sid + "0" + std::string(UUID_LENGTH - 4, 'A');
 
        if (generated_uid != correct_uid)
        {
@@ -386,11 +375,11 @@ bool TestSuite::RealGenerateUIDTests()
        }
 
        // Set current_uid to be ...999999 to see if it rolls over correctly
-       for (unsigned int i = 3; i < UUID_LENGTH-1; i++)
-               ServerInstance->current_uid[i] = '9';
+       for (unsigned int i = 3; i < UUID_LENGTH; i++)
+               uidgen.current_uid[i] = '9';
 
-       before_increment.assign(ServerInstance->current_uid);
-       generated_uid = ServerInstance->GetUID();
+       before_increment.assign(uidgen.current_uid);
+       generated_uid = uidgen.GetUID();
 
        // Correct UID after rolling over is the first UID we've generated (...AAAAAA)
        if (generated_uid != first_uid)
index a1ee0b488cd98ec77d5de426ca0e52e68827cec2..f098a5e6b5f78b6ea6285c58c9bad657ceb11530 100644 (file)
 #include "inspircd.h"
 #include "timer.h"
 
-TimerManager::TimerManager()
+void Timer::SetInterval(time_t newinterval)
 {
+       ServerInstance->Timers->DelTimer(this);
+       secs = newinterval;
+       SetTrigger(ServerInstance->Time() + newinterval);
+       ServerInstance->Timers->AddTimer(this);
 }
 
-TimerManager::~TimerManager()
+Timer::~Timer()
 {
-       for(std::vector<Timer *>::iterator i = Timers.begin(); i != Timers.end(); i++)
-               delete *i;
+       ServerInstance->Timers->DelTimer(this);
 }
 
 void TimerManager::TickTimers(time_t TIME)
 {
-       while ((Timers.size()) && (TIME > (*Timers.begin())->GetTimer()))
+       for (TimerMap::iterator i = Timers.begin(); i != Timers.end(); )
        {
-               std::vector<Timer *>::iterator i = Timers.begin();
-               Timer *t = (*i);
+               Timer* t = i->second;
+               if (t->GetTrigger() > TIME)
+                       break;
 
-               // Probable fix: move vector manipulation to *before* we modify the vector.
-               Timers.erase(i);
+               Timers.erase(i++);
 
-               t->Tick(TIME);
-               if (t->GetRepeat())
+               if (!t->Tick(TIME))
+                       delete t;
+               else if (t->GetRepeat())
                {
-                       t->SetTimer(TIME + t->GetSecs());
+                       t->SetTrigger(TIME + t->GetInterval());
                        AddTimer(t);
                }
-               else
-                       delete t;
        }
 }
 
-void TimerManager::DelTimer(Timer* T)
+void TimerManager::DelTimer(Timer* t)
 {
-       std::vector<Timer *>::iterator i = std::find(Timers.begin(), Timers.end(), T);
+       std::pair<TimerMap::iterator, TimerMap::iterator> itpair = Timers.equal_range(t->GetTrigger());
 
-       if (i != Timers.end())
+       for (TimerMap::iterator i = itpair.first; i != itpair.second; ++i)
        {
-               delete (*i);
-               Timers.erase(i);
+               if (i->second == t)
+               {
+                       Timers.erase(i);
+                       break;
+               }
        }
 }
 
-void TimerManager::AddTimer(Timer* T)
-{
-       Timers.push_back(T);
-       sort(Timers.begin(), Timers.end(), TimerManager::TimerComparison);
-}
-
-bool TimerManager::TimerComparison( Timer *one, Timer *two)
+void TimerManager::AddTimer(Timer* t)
 {
-       return (one->GetTimer()) < (two->GetTimer());
+       Timers.insert(std::make_pair(t->GetTrigger(), t));
 }
diff --git a/src/user_resolver.cpp b/src/user_resolver.cpp
deleted file mode 100644 (file)
index f18fc9a..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "inspircd.h"
-UserResolver::UserResolver(LocalUser* user, std::string to_resolve, QueryType qt, bool &cache) :
-       Resolver(to_resolve, qt, cache, NULL), uuid(user->uuid)
-{
-       this->fwd = (qt == DNS_QUERY_A || qt == DNS_QUERY_AAAA);
-}
-
-void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
-{
-       UserResolver *res_forward; // for forward-resolution
-       LocalUser* bound_user = (LocalUser*)ServerInstance->FindUUID(uuid);
-       if (!bound_user)
-       {
-               ServerInstance->Logs->Log("RESOLVER", DEBUG, "Resolution finished for user '%s' who is gone", uuid.c_str());
-               return;
-       }
-
-       ServerInstance->Logs->Log("RESOLVER", DEBUG, "DNS result for %s: '%s' -> '%s'", uuid.c_str(), input.c_str(), result.c_str());
-
-       if (!fwd)
-       {
-               // first half of resolution is done. We now need to verify that the host matches.
-               bound_user->stored_host = result;
-               try
-               {
-                       /* Check we didnt time out */
-                       if (bound_user->registered != REG_ALL)
-                       {
-                               bool lcached = false;
-                               if (bound_user->client_sa.sa.sa_family == AF_INET6)
-                               {
-                                       /* IPV6 forward lookup */
-                                       res_forward = new UserResolver(bound_user, result, DNS_QUERY_AAAA, lcached);
-                               }
-                               else
-                               {
-                                       /* IPV4 lookup */
-                                       res_forward = new UserResolver(bound_user, result, DNS_QUERY_A, lcached);
-                               }
-                               ServerInstance->AddResolver(res_forward, lcached);
-                       }
-               }
-               catch (CoreException& e)
-               {
-                       ServerInstance->Logs->Log("RESOLVER", DEBUG,"Error in resolver: %s",e.GetReason());
-               }
-       }
-       else
-       {
-               /* Both lookups completed */
-
-               irc::sockets::sockaddrs* user_ip = &bound_user->client_sa;
-               bool rev_match = false;
-               if (user_ip->sa.sa_family == AF_INET6)
-               {
-                       struct in6_addr res_bin;
-                       if (inet_pton(AF_INET6, result.c_str(), &res_bin))
-                       {
-                               rev_match = !memcmp(&user_ip->in6.sin6_addr, &res_bin, sizeof(res_bin));
-                       }
-               }
-               else
-               {
-                       struct in_addr res_bin;
-                       if (inet_pton(AF_INET, result.c_str(), &res_bin))
-                       {
-                               rev_match = !memcmp(&user_ip->in4.sin_addr, &res_bin, sizeof(res_bin));
-                       }
-               }
-               
-               if (rev_match)
-               {
-                       std::string hostname = bound_user->stored_host;
-                       if (hostname.length() < 65)
-                       {
-                               /* Check we didnt time out */
-                               if ((bound_user->registered != REG_ALL) && (!bound_user->dns_done))
-                               {
-                                       /* Hostnames starting with : are not a good thing (tm) */
-                                       if (hostname[0] == ':')
-                                               hostname.insert(0, "0");
-
-                                       bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname.c_str(), (cached ? " -- cached" : ""));
-                                       bound_user->dns_done = true;
-                                       bound_user->dhost.assign(hostname, 0, 64);
-                                       bound_user->host.assign(hostname, 0, 64);
-                                       /* Invalidate cache */
-                                       bound_user->InvalidateCache();
-                               }
-                       }
-                       else
-                       {
-                               if (!bound_user->dns_done)
-                               {
-                                       bound_user->WriteServ("NOTICE Auth :*** Your hostname is longer than the maximum of 64 characters, using your IP address (%s) instead.", bound_user->GetIPString());
-                                       bound_user->dns_done = true;
-                               }
-                       }
-               }
-               else
-               {
-                       if (!bound_user->dns_done)
-                       {
-                               bound_user->WriteServ("NOTICE Auth :*** Your hostname does not match up with your IP address. Sorry, using your IP address (%s) instead.", bound_user->GetIPString());
-                               bound_user->dns_done = true;
-                       }
-               }
-
-               // Save some memory by freeing this up; it's never used again in the user's lifetime.
-               bound_user->stored_host.resize(0);
-       }
-}
-
-void UserResolver::OnError(ResolverError e, const std::string &errormessage)
-{
-       LocalUser* bound_user = (LocalUser*)ServerInstance->FindUUID(uuid);
-       if (bound_user)
-       {
-               bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname: %s; using your IP address (%s) instead.", errormessage.c_str(), bound_user->GetIPString());
-               bound_user->dns_done = true;
-               bound_user->stored_host.resize(0);
-               ServerInstance->stats->statsDnsBad++;
-       }
-}
index 076277a33dcc5ffb4f22cdfe9592618237ef9bb1..d6c61d2e35dfc642075133d2794dbcaa7a26ce22 100644 (file)
@@ -42,7 +42,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
        }
        catch (...)
        {
-               ServerInstance->Logs->Log("USERS", DEFAULT,"*** WTF *** Duplicated UUID! -- Crack smoking monkeys have been unleashed.");
+               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "*** WTF *** Duplicated UUID! -- Crack smoking monkeys have been unleashed.");
                ServerInstance->SNO->WriteToSnoMask('a', "WARNING *** Duplicate UUID allocated!");
                return;
        }
@@ -59,11 +59,11 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
                }
                catch (CoreException& modexcept)
                {
-                       ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+                       ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                }
        }
 
-       ServerInstance->Logs->Log("USERS", DEBUG,"New user fd: %d", socket);
+       ServerInstance->Logs->Log("USERS", LOG_DEBUG, "New user fd: %d", socket);
 
        this->unregistered_count++;
 
@@ -114,15 +114,15 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
                if (!b->Type.empty() && !New->exempt)
                {
                        /* user banned */
-                       ServerInstance->Logs->Log("BANCACHE", DEBUG, std::string("BanCache: Positive hit for ") + New->GetIPString());
+                       ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCache: Positive hit for " + New->GetIPString());
                        if (!ServerInstance->Config->MoronBanner.empty())
-                               New->WriteServ("NOTICE %s :*** %s", New->nick.c_str(), ServerInstance->Config->MoronBanner.c_str());
+                               New->WriteNotice("*** " +  ServerInstance->Config->MoronBanner);
                        this->QuitUser(New, b->Reason);
                        return;
                }
                else
                {
-                       ServerInstance->Logs->Log("BANCACHE", DEBUG, std::string("BanCache: Negative hit for ") + New->GetIPString());
+                       ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCache: Negative hit for " + New->GetIPString());
                }
        }
        else
@@ -141,51 +141,37 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
 
        if (!ServerInstance->SE->AddFd(eh, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE))
        {
-               ServerInstance->Logs->Log("USERS", DEBUG,"Internal error on new connection");
+               ServerInstance->Logs->Log("USERS", LOG_DEBUG, "Internal error on new connection");
                this->QuitUser(New, "Internal error handling connection");
        }
 
-       /* NOTE: even if dns lookups are *off*, we still need to display this.
-        * BOPM and other stuff requires it.
-        */
-       New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
        if (ServerInstance->Config->RawLog)
-               New->WriteServ("NOTICE Auth :*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.");
+               New->WriteNotice("*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.");
 
        FOREACH_MOD(I_OnSetUserIP,OnSetUserIP(New));
        if (New->quitting)
                return;
 
        FOREACH_MOD(I_OnUserInit,OnUserInit(New));
-
-       if (ServerInstance->Config->NoUserDns)
-       {
-               New->WriteServ("NOTICE %s :*** Skipping host resolution (disabled by server administrator)", New->nick.c_str());
-               New->dns_done = true;
-       }
-       else
-       {
-               New->StartDNSLookup();
-       }
 }
 
 void UserManager::QuitUser(User *user, const std::string &quitreason, const char* operreason)
 {
        if (user->quitting)
        {
-               ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: Tried to quit quitting user: " + user->nick);
+               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: Tried to quit quitting user: " + user->nick);
                return;
        }
 
        if (IS_SERVER(user))
        {
-               ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: Tried to quit server user: " + user->nick);
+               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: Tried to quit server user: " + user->nick);
                return;
        }
 
        user->quitting = true;
 
-       ServerInstance->Logs->Log("USERS", DEBUG, "QuitUser: %s=%s '%s'", user->uuid.c_str(), user->nick.c_str(), quitreason.c_str());
+       ServerInstance->Logs->Log("USERS", LOG_DEBUG, "QuitUser: %s=%s '%s'", user->uuid.c_str(), user->nick.c_str(), quitreason.c_str());
        user->Write("ERROR :Closing link: (%s@%s) [%s]", user->ident.c_str(), user->host.c_str(), *operreason ? operreason : quitreason.c_str());
 
        std::string reason;
@@ -226,7 +212,7 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char
                        if (!user->quietquit)
                        {
                                ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s (%s) [%s]",
-                                       user->GetFullRealHost().c_str(), user->GetIPString(), oper_reason.c_str());
+                                       user->GetFullRealHost().c_str(), user->GetIPString().c_str(), oper_reason.c_str());
                        }
                }
                else
@@ -234,10 +220,9 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char
                        if ((!ServerInstance->SilentULine(user->server)) && (!user->quietquit))
                        {
                                ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s (%s) [%s]",
-                                       user->server.c_str(), user->GetFullRealHost().c_str(), user->GetIPString(), oper_reason.c_str());
+                                       user->server.c_str(), user->GetFullRealHost().c_str(), user->GetIPString().c_str(), oper_reason.c_str());
                        }
                }
-               user->AddToWhoWas();
        }
 
        user_hash::iterator iter = this->clientlist->find(user->nick);
@@ -245,7 +230,7 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char
        if (iter != this->clientlist->end())
                this->clientlist->erase(iter);
        else
-               ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: Nick not found in clientlist, cannot remove: " + user->nick);
+               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: Nick not found in clientlist, cannot remove: " + user->nick);
 
        ServerInstance->Users->uuidlist->erase(user->uuid);
 }
@@ -343,47 +328,17 @@ unsigned int UserManager::LocalUserCount()
 
 void UserManager::ServerNoticeAll(const char* text, ...)
 {
-       if (!text)
-               return;
-
-       char textbuffer[MAXBUF];
-       char formatbuffer[MAXBUF];
-       va_list argsPtr;
-       va_start (argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
+       std::string message;
+       VAFORMAT(message, text, text);
+       message = "NOTICE $" + ServerInstance->Config->ServerName + " :" + message;
 
        for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++)
        {
                User* t = *i;
-               t->WriteServ(std::string(formatbuffer));
+               t->WriteServ(message);
        }
 }
 
-void UserManager::ServerPrivmsgAll(const char* text, ...)
-{
-       if (!text)
-               return;
-
-       char textbuffer[MAXBUF];
-       char formatbuffer[MAXBUF];
-       va_list argsPtr;
-       va_start (argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
-
-       for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++)
-       {
-               User* t = *i;
-               t->WriteServ(std::string(formatbuffer));
-       }
-}
-
-
 /* return how many users have a given mode e.g. 'a' */
 int UserManager::ModeCount(const char mode)
 {
@@ -396,3 +351,14 @@ int UserManager::ModeCount(const char mode)
        }
        return c;
 }
+
+void UserManager::GarbageCollect()
+{
+       // Reset the already_sent IDs so we don't wrap it around and drop a message
+       LocalUser::already_sent_id = 0;
+       for (LocalUserList::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++)
+       {
+               (**i).already_sent = 0;
+               (**i).RemoveExpiredInvites();
+       }
+}
index 9cc2e7df7c78e215f7f4540d6ebe0ac3e6312d21..40fd35c5901e6fc8f25fd2af0a229cd52b945740 100644 (file)
 #include "socketengine.h"
 #include "command_parse.h"
 
-void FloodQuitUserHandler::Call(User* current)
-{
-       ServerInstance->Logs->Log("USERS",DEFAULT,"Excess flood from: %s@%s", current->ident.c_str(), current->host.c_str());
-       ServerInstance->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",
-                       current->registered == REG_ALL ? current->nick.c_str() : "",
-                       current->registered == REG_ALL ? "!" : "", current->ident.c_str(), current->host.c_str());
-       ServerInstance->Users->QuitUser(current, "Excess flood");
-
-       if (current->registered != REG_ALL)
-       {
-               ZLine* zl = new ZLine(ServerInstance->Time(), 0, ServerInstance->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
-               if (ServerInstance->XLines->AddLine(zl,NULL))
-                       ServerInstance->XLines->ApplyLines();
-               else
-                       delete zl;
-       }
-}
-
 /**
  * This function is called once a second from the mainloop.
  * It is intended to do background checking on all the user structs, e.g.
@@ -84,8 +66,7 @@ void InspIRCd::DoBackgroundUserStuff()
                                        if (!curr->lastping)
                                        {
                                                time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
-                                               char message[MAXBUF];
-                                               snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
+                                               const std::string message = "Ping timeout: " + ConvToStr(time) + (time == 1 ? " seconds" : " second");
                                                curr->lastping = 1;
                                                curr->nping = Time() + curr->MyClass->GetPingTime();
                                                this->Users->QuitUser(curr, message);
@@ -98,7 +79,7 @@ void InspIRCd::DoBackgroundUserStuff()
                                }
                                break;
                        case REG_NICKUSER:
-                               if (AllModulesReportReady(curr) && curr->dns_done)
+                               if (AllModulesReportReady(curr))
                                {
                                        /* User has sent NICK/USER, modules are okay, DNS finished. */
                                        curr->FullConnect();
index 2305ba8ce333cf0cf374b67e49df18abaf46c0b6..44834330b1e654d450e821686dec2983d89f57c0 100644 (file)
@@ -28,7 +28,6 @@
 #include "socketengine.h"
 #include "xline.h"
 #include "bancache.h"
-#include "commands/cmd_whowas.h"
 
 already_sent_t LocalUser::already_sent_id = 0;
 
@@ -109,27 +108,6 @@ std::string User::ProcessNoticeMasks(const char *sm)
        return output;
 }
 
-void LocalUser::StartDNSLookup()
-{
-       try
-       {
-               bool cached = false;
-               const char* sip = this->GetIPString();
-               UserResolver *res_reverse;
-
-               QueryType resolvtype = this->client_sa.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
-               res_reverse = new UserResolver(this, sip, resolvtype, cached);
-
-               ServerInstance->AddResolver(res_reverse, cached);
-       }
-       catch (CoreException& e)
-       {
-               ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
-               dns_done = true;
-               ServerInstance->stats->statsDnsBad++;
-       }
-}
-
 bool User::IsNoticeMaskSet(unsigned char sm)
 {
        if (!isalpha(sm))
@@ -175,15 +153,15 @@ void User::SetMode(unsigned char m, bool value)
 
 const char* User::FormatModes(bool showparameters)
 {
-       static char data[MAXBUF];
+       static std::string data;
        std::string params;
-       int offset = 0;
+       data.clear();
 
        for (unsigned char n = 0; n < 64; n++)
        {
                if (modes[n])
                {
-                       data[offset++] = n + 65;
+                       data.push_back(n + 65);
                        ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
                        if (showparameters && mh && mh->GetNumParams(true))
                        {
@@ -193,22 +171,20 @@ const char* User::FormatModes(bool showparameters)
                        }
                }
        }
-       data[offset] = 0;
-       strlcat(data, params.c_str(), MAXBUF);
-       return data;
+       data += params;
+       return data.c_str();
 }
 
 User::User(const std::string &uid, const std::string& sid, int type)
        : uuid(uid), server(sid), usertype(type)
 {
        age = ServerInstance->Time();
-       signon = idle_lastmsg = 0;
+       signon = 0;
        registered = 0;
-       quietquit = quitting = exempt = dns_done = false;
-       quitting_sendq = false;
+       quietquit = quitting = false;
        client_sa.sa.sa_family = AF_UNSPEC;
 
-       ServerInstance->Logs->Log("USERS", DEBUG, "New UUID for user: %s", uuid.c_str());
+       ServerInstance->Logs->Log("USERS", LOG_DEBUG, "New UUID for user: %s", uuid.c_str());
 
        user_hash::iterator finduuid = ServerInstance->Users->uuidlist->find(uuid);
        if (finduuid == ServerInstance->Users->uuidlist->end())
@@ -218,11 +194,13 @@ User::User(const std::string &uid, const std::string& sid, int type)
 }
 
 LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr)
-       : User(ServerInstance->GetUID(), ServerInstance->Config->ServerName, USERTYPE_LOCAL), eh(this),
+       : User(ServerInstance->UIDGen.GetUID(), ServerInstance->Config->ServerName, USERTYPE_LOCAL), eh(this),
        localuseriter(ServerInstance->Users->local_users.end()),
        bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0),
        already_sent(0)
 {
+       exempt = quitting_sendq = false;
+       idle_lastmsg = 0;
        ident = "unknown";
        lastping = 0;
        eh.SetFd(myfd);
@@ -234,7 +212,7 @@ LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::so
 User::~User()
 {
        if (ServerInstance->Users->uuidlist->find(uuid) != ServerInstance->Users->uuidlist->end())
-               ServerInstance->Logs->Log("USERS", DEFAULT, "User destructor for %s called without cull", uuid.c_str());
+               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "User destructor for %s called without cull", uuid.c_str());
 }
 
 const std::string& User::MakeHost()
@@ -268,7 +246,7 @@ const std::string& User::MakeHostIP()
        for(const char* n = ident.c_str(); *n; n++)
                *t++ = *n;
        *t++ = '@';
-       for(const char* n = this->GetIPString(); *n; n++)
+       for(const char* n = this->GetIPString().c_str(); *n; n++)
                *t++ = *n;
        *t = 0;
 
@@ -333,40 +311,22 @@ const std::string& User::GetFullRealHost()
        return this->cached_fullrealhost;
 }
 
-bool LocalUser::IsInvited(const irc::string &channel)
-{
-       Channel* chan = ServerInstance->FindChan(channel.c_str());
-       if (!chan)
-               return false;
-
-       return (Invitation::Find(chan, this) != NULL);
-}
-
 InviteList& LocalUser::GetInviteList()
 {
        RemoveExpiredInvites();
        return invites;
 }
 
-void LocalUser::InviteTo(const irc::string &channel, time_t invtimeout)
-{
-       Channel* chan = ServerInstance->FindChan(channel.c_str());
-       if (chan)
-               Invitation::Create(chan, this, invtimeout);
-}
-
-void LocalUser::RemoveInvite(const irc::string &channel)
+bool LocalUser::RemoveInvite(Channel* chan)
 {
-       Channel* chan = ServerInstance->FindChan(channel.c_str());
-       if (chan)
+       Invitation* inv = Invitation::Find(chan, this);
+       if (inv)
        {
-               Invitation* inv = Invitation::Find(chan, this);
-               if (inv)
-               {
-                       inv->cull();
-                       delete inv;
-               }
+               inv->cull();
+               delete inv;
+               return true;
        }
+       return false;
 }
 
 void LocalUser::RemoveExpiredInvites()
@@ -381,7 +341,7 @@ bool User::HasModePermission(unsigned char, ModeType)
 
 bool LocalUser::HasModePermission(unsigned char mode, ModeType type)
 {
-       if (!IS_OPER(this))
+       if (!this->IsOper())
                return false;
 
        if (mode < 'A' || mode > ('A' + 64)) return false;
@@ -404,7 +364,7 @@ bool User::HasPermission(const std::string&)
 bool LocalUser::HasPermission(const std::string &command)
 {
        // are they even an oper at all?
-       if (!IS_OPER(this))
+       if (!this->IsOper())
        {
                return false;
        }
@@ -424,10 +384,10 @@ bool User::HasPrivPermission(const std::string &privstr, bool noisy)
 
 bool LocalUser::HasPrivPermission(const std::string &privstr, bool noisy)
 {
-       if (!IS_OPER(this))
+       if (!this->IsOper())
        {
                if (noisy)
-                       this->WriteServ("NOTICE %s :You are not an oper", this->nick.c_str());
+                       this->WriteNotice("You are not an oper");
                return false;
        }
 
@@ -441,7 +401,8 @@ bool LocalUser::HasPrivPermission(const std::string &privstr, bool noisy)
        }
 
        if (noisy)
-               this->WriteServ("NOTICE %s :Oper type %s does not have access to priv %s", this->nick.c_str(), oper->NameStr(), privstr.c_str());
+               this->WriteNotice("Oper type " + oper->name + " does not have access to priv " + privstr);
+
        return false;
 }
 
@@ -550,7 +511,7 @@ CullResult LocalUser::cull()
                ServerInstance->Users->local_users.erase(localuseriter);
        }
        else
-               ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: LocalUserIter does not point to a valid entry for " + this->nick);
+               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: LocalUserIter does not point to a valid entry for " + this->nick);
 
        ClearInvites();
        eh.cull();
@@ -592,10 +553,10 @@ void User::Oper(OperInfo* info)
        }
 
        ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')",
-               nick.c_str(), ident.c_str(), host.c_str(), oper->NameStr(), opername.c_str());
-       this->WriteNumeric(381, "%s :You are now %s %s", nick.c_str(), strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->NameStr());
+               nick.c_str(), ident.c_str(), host.c_str(), oper->name.c_str(), opername.c_str());
+       this->WriteNumeric(381, "%s :You are now %s %s", nick.c_str(), strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->name.c_str());
 
-       ServerInstance->Logs->Log("OPER", DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->NameStr());
+       ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->name.c_str());
        ServerInstance->Users->all_opers.push_back(this);
 
        // Expand permissions from config for faster lookup
@@ -660,7 +621,7 @@ void OperInfo::init()
 
 void User::UnOper()
 {
-       if (!IS_OPER(this))
+       if (!this->IsOper())
                return;
 
        /*
@@ -694,18 +655,6 @@ void User::UnOper()
        this->modes[UM_OPERATOR] = 0;
 }
 
-/* adds or updates an entry in the whowas list */
-void User::AddToWhoWas()
-{
-       Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
-       if (whowas)
-       {
-               WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_ADD);
-               req.user = this;
-               req.Send();
-       }
-}
-
 /*
  * Check class restrictions
  */
@@ -727,21 +676,21 @@ void LocalUser::CheckClass()
        {
                ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
                if (a->maxconnwarn)
-                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
+                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString().c_str());
                return;
        }
        else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
        {
                ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
                if (a->maxconnwarn)
-                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
+                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString().c_str());
                return;
        }
 
        this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
 }
 
-bool User::CheckLines(bool doZline)
+bool LocalUser::CheckLines(bool doZline)
 {
        const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
 
@@ -781,18 +730,14 @@ void LocalUser::FullConnect()
        if (quitting)
                return;
 
-       if (ServerInstance->Config->WelcomeNotice)
-               this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network.c_str());
        this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s",this->nick.c_str(), ServerInstance->Config->Network.c_str(), GetFullRealHost().c_str());
        this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version %s",this->nick.c_str(),ServerInstance->Config->ServerName.c_str(),BRANCH);
        this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
 
-       std::string umlist = ServerInstance->Modes->UserModeList();
-       std::string cmlist = ServerInstance->Modes->ChannelModeList();
-       std::string pmlist = ServerInstance->Modes->ParaModeList();
-       this->WriteNumeric(RPL_SERVERVERSION, "%s %s %s %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName.c_str(), BRANCH, umlist.c_str(), cmlist.c_str(), pmlist.c_str());
+       const std::string& modelist = ServerInstance->Modes->GetModeListFor004Numeric();
+       this->WriteNumeric(RPL_SERVERVERSION, "%s %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName.c_str(), BRANCH, modelist.c_str());
 
-       ServerInstance->Config->Send005(this);
+       ServerInstance->ISupport.SendTo(this);
        this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
 
        /* Now registered */
@@ -801,14 +746,14 @@ void LocalUser::FullConnect()
 
        /* Trigger MOTD and LUSERS output, give modules a chance too */
        ModResult MOD_RESULT;
-       std::string command("MOTD");
+       std::string command("LUSERS");
        std::vector<std::string> parameters;
        FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
        if (!MOD_RESULT)
                ServerInstance->Parser->CallHandler(command, parameters, this);
 
        MOD_RESULT = MOD_RES_PASSTHRU;
-       command = "LUSERS";
+       command = "MOTD";
        FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
        if (!MOD_RESULT)
                ServerInstance->Parser->CallHandler(command, parameters, this);
@@ -827,8 +772,8 @@ void LocalUser::FullConnect()
        FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
 
        ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d (class %s): %s (%s) [%s]",
-               this->GetServerPort(), this->MyClass->name.c_str(), GetFullRealHost().c_str(), this->GetIPString(), this->fullname.c_str());
-       ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
+               this->GetServerPort(), this->MyClass->name.c_str(), GetFullRealHost().c_str(), this->GetIPString().c_str(), this->fullname.c_str());
+       ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCache: Adding NEGATIVE hit for " + this->GetIPString());
        ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
        // reset the flood penalty (which could have been raised due to things like auto +x)
        CommandFloodPenalty = 0;
@@ -847,21 +792,20 @@ bool User::ChangeNick(const std::string& newnick, bool force)
 {
        if (quitting)
        {
-               ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: Attempted to change nick of a quitting user: " + this->nick);
+               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: Attempted to change nick of a quitting user: " + this->nick);
                return false;
        }
 
-       ModResult MOD_RESULT;
-
-       if (force)
-               ServerInstance->NICKForced.set(this, 1);
-       FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (this, newnick));
-       ServerInstance->NICKForced.set(this, 0);
-
-       if (MOD_RESULT == MOD_RES_DENY)
+       if (!force)
        {
-               ServerInstance->stats->statsCollisions++;
-               return false;
+               ModResult MOD_RESULT;
+               FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (this, newnick));
+
+               if (MOD_RESULT == MOD_RES_DENY)
+               {
+                       ServerInstance->stats->statsCollisions++;
+                       return false;
+               }
        }
 
        if (assign(newnick) == assign(nick))
@@ -970,18 +914,18 @@ int LocalUser::GetServerPort()
        return 0;
 }
 
-const char* User::GetIPString()
+const std::string& User::GetIPString()
 {
        int port;
        if (cachedip.empty())
        {
                irc::sockets::satoap(client_sa, cachedip, port);
                /* IP addresses starting with a : on irc are a Bad Thing (tm) */
-               if (cachedip.c_str()[0] == ':')
+               if (cachedip[0] == ':')
                        cachedip.insert(0,1,'0');
        }
 
-       return cachedip.c_str();
+       return cachedip;
 }
 
 irc::sockets::cidr_mask User::GetCIDRMask()
@@ -1059,7 +1003,7 @@ void LocalUser::Write(const std::string& text)
                return;
        }
 
-       ServerInstance->Logs->Log("USEROUTPUT", RAWIO, "C[%s] O %s", uuid.c_str(), text.c_str());
+       ServerInstance->Logs->Log("USEROUTPUT", LOG_RAWIO, "C[%s] O %s", uuid.c_str(), text.c_str());
 
        eh.AddWriteBuf(text);
        eh.AddWriteBuf(wide_newline);
@@ -1073,14 +1017,9 @@ void LocalUser::Write(const std::string& text)
  */
 void LocalUser::Write(const char *text, ...)
 {
-       va_list argsPtr;
-       char textbuffer[MAXBUF];
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->Write(std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->Write(textbuffer);
 }
 
 void User::WriteServ(const std::string& text)
@@ -1093,27 +1032,21 @@ void User::WriteServ(const std::string& text)
  */
 void User::WriteServ(const char* text, ...)
 {
-       va_list argsPtr;
-       char textbuffer[MAXBUF];
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteServ(std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteServ(textbuffer);
 }
 
+void User::WriteNotice(const std::string& text)
+{
+       this->WriteServ("NOTICE " + (this->registered == REG_ALL ? this->nick : "*") + " :" + text);
+}
 
 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
 {
-       va_list argsPtr;
-       char textbuffer[MAXBUF];
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteNumeric(numeric, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteNumeric(numeric, textbuffer);
 }
 
 void User::WriteNumeric(unsigned int numeric, const std::string &text)
@@ -1132,11 +1065,8 @@ void User::WriteNumeric(unsigned int numeric, const std::string &text)
 
 void User::WriteFrom(User *user, const std::string &text)
 {
-       char tb[MAXBUF];
-
-       snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
-
-       this->Write(std::string(tb));
+       const std::string message = ":" + user->GetFullHost() + " " + text;
+       this->Write(message);
 }
 
 
@@ -1144,14 +1074,9 @@ void User::WriteFrom(User *user, const std::string &text)
 
 void User::WriteFrom(User *user, const char* text, ...)
 {
-       va_list argsPtr;
-       char textbuffer[MAXBUF];
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteFrom(user, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       this->WriteFrom(user, textbuffer);
 }
 
 
@@ -1159,14 +1084,9 @@ void User::WriteFrom(User *user, const char* text, ...)
 
 void User::WriteTo(User *dest, const char *data, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       va_start(argsPtr, data);
-       vsnprintf(textbuffer, MAXBUF, data, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteTo(dest, std::string(textbuffer));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, data, data);
+       this->WriteTo(dest, textbuffer);
 }
 
 void User::WriteTo(User *dest, const std::string &data)
@@ -1176,36 +1096,24 @@ void User::WriteTo(User *dest, const std::string &data)
 
 void User::WriteCommon(const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
        if (this->registered != REG_ALL || quitting)
                return;
 
-       int len = snprintf(textbuffer,MAXBUF,":%s ",this->GetFullHost().c_str());
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer + len, MAXBUF - len, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteCommonRaw(std::string(textbuffer), true);
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
+       this->WriteCommonRaw(textbuffer, true);
 }
 
 void User::WriteCommonExcept(const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
        if (this->registered != REG_ALL || quitting)
                return;
 
-       int len = snprintf(textbuffer,MAXBUF,":%s ",this->GetFullHost().c_str());
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer + len, MAXBUF - len, text, argsPtr);
-       va_end(argsPtr);
-
-       this->WriteCommonRaw(std::string(textbuffer), false);
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
+       this->WriteCommonRaw(textbuffer, false);
 }
 
 void User::WriteCommonRaw(const std::string &line, bool include_self)
@@ -1250,18 +1158,13 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
 
 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
 {
-       char tb1[MAXBUF];
-       char tb2[MAXBUF];
-
        if (this->registered != REG_ALL)
                return;
 
        already_sent_t uniq_id = ++LocalUser::already_sent_id;
 
-       snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
-       snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
-       std::string out1 = tb1;
-       std::string out2 = tb2;
+       const std::string normalMessage = ":" + this->GetFullHost() + " QUIT :" + normal_text;
+       const std::string operMessage = ":" + this->GetFullHost() + " QUIT :" + oper_text;
 
        UserChanList include_c(chans);
        std::map<User*,bool> exceptions;
@@ -1275,7 +1178,7 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
                {
                        u->already_sent = uniq_id;
                        if (i->second)
-                               u->Write(IS_OPER(u) ? out2 : out1);
+                               u->Write(u->IsOper() ? operMessage : normalMessage);
                }
        }
        for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
@@ -1287,7 +1190,7 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
                        if (u && !u->quitting && (u->already_sent != uniq_id))
                        {
                                u->already_sent = uniq_id;
-                               u->Write(IS_OPER(u) ? out2 : out1);
+                               u->Write(u->IsOper() ? operMessage : normalMessage);
                        }
                }
        }
@@ -1309,14 +1212,9 @@ void FakeUser::SendText(const std::string& line)
 
 void User::SendText(const char *text, ...)
 {
-       va_list argsPtr;
-       char line[MAXBUF];
-
-       va_start(argsPtr, text);
-       vsnprintf(line, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       SendText(std::string(line));
+       std::string line;
+       VAFORMAT(line, text, text);
+       SendText(line);
 }
 
 void User::SendText(const std::string &LinePrefix, std::stringstream &TextStream)
@@ -1392,8 +1290,6 @@ bool User::ChangeName(const char* gecos)
 
 void User::DoHostCycle(const std::string &quitline)
 {
-       char buffer[MAXBUF];
-
        if (!ServerInstance->Config->CycleHosts)
                return;
 
@@ -1424,18 +1320,17 @@ void User::DoHostCycle(const std::string &quitline)
        for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
        {
                Channel* c = *v;
-               snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
-               std::string joinline(buffer);
                Membership* memb = c->GetUser(this);
-               std::string modeline = memb->modes;
-               if (modeline.length() > 0)
+               const std::string joinline = ":" + GetFullHost() + " JOIN " + c->name;
+               std::string modeline;
+
+               if (!memb->modes.empty())
                {
-                       for(unsigned int i=0; i < memb->modes.length(); i++)
+                       modeline = ":" + (ServerInstance->Config->CycleHostsFromUser ? GetFullHost() : ServerInstance->Config->ServerName)
+                               + " MODE " + c->name + " +" + memb->modes;
+
+                       for (size_t i = 0; i < memb->modes.length(); i++)
                                modeline.append(" ").append(nick);
-                       snprintf(buffer, MAXBUF, ":%s MODE %s +%s",
-                               ServerInstance->Config->CycleHostsFromUser ? GetFullHost().c_str() : ServerInstance->Config->ServerName.c_str(),
-                               c->name.c_str(), modeline.c_str());
-                       modeline = buffer;
                }
 
                const UserMembList *ulist = c->GetUsers();
@@ -1453,7 +1348,7 @@ void User::DoHostCycle(const std::string &quitline)
                                u->already_sent = seen_id;
                        }
                        u->Write(joinline);
-                       if (modeline.length() > 0)
+                       if (!memb->modes.empty())
                                u->Write(modeline);
                }
        }
@@ -1509,76 +1404,14 @@ bool User::ChangeIdent(const char* newident)
 
 void User::SendAll(const char* command, const char* text, ...)
 {
-       char textbuffer[MAXBUF];
-       char formatbuffer[MAXBUF];
-       va_list argsPtr;
-
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
-       std::string fmt = formatbuffer;
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       const std::string message = ":" + this->GetFullHost() + " " + command + " $* :" + textbuffer;
 
        for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
        {
                if ((*i)->registered == REG_ALL)
-                       (*i)->Write(fmt);
-       }
-}
-
-
-std::string User::ChannelList(User* source, bool spy)
-{
-       std::string list;
-
-       for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
-       {
-               Channel* c = *i;
-               /* If the target is the sender, neither +p nor +s is set, or
-                * the channel contains the user, it is not a spy channel
-                */
-               if (spy != (source == this || !(c->IsModeSet('p') || c->IsModeSet('s')) || c->HasUser(source)))
-                       list.append(c->GetPrefixChar(this)).append(c->name).append(" ");
-       }
-
-       return list;
-}
-
-void User::SplitChanList(User* dest, const std::string &cl)
-{
-       std::string line;
-       std::ostringstream prefix;
-       std::string::size_type start, pos, length;
-
-       prefix << this->nick << " " << dest->nick << " :";
-       line = prefix.str();
-       int namelen = ServerInstance->Config->ServerName.length() + 6;
-
-       for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
-       {
-               length = (pos == std::string::npos) ? cl.length() : pos;
-
-               if (line.length() + namelen + length - start > 510)
-               {
-                       ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
-                       line = prefix.str();
-               }
-
-               if(pos == std::string::npos)
-               {
-                       line.append(cl.substr(start, length - start));
-                       break;
-               }
-               else
-               {
-                       line.append(cl.substr(start, length - start + 1));
-               }
-       }
-
-       if (line.length() != prefix.str().length())
-       {
-               ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
+                       (*i)->Write(message);
        }
 }
 
@@ -1593,7 +1426,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
 {
        ConnectClass *found = NULL;
 
-       ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
+       ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
 
        if (!explicit_name.empty())
        {
@@ -1603,7 +1436,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
 
                        if (explicit_name == c->name)
                        {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
+                               ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Explicitly set to %s", explicit_name.c_str());
                                found = c;
                        }
                }
@@ -1613,7 +1446,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
                for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
                {
                        ConnectClass* c = *i;
-                       ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Checking %s", c->GetName().c_str());
+                       ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Checking %s", c->GetName().c_str());
 
                        ModResult MOD_RESULT;
                        FIRST_MOD_RESULT(OnSetConnectClass, MOD_RESULT, (this,c));
@@ -1621,7 +1454,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
                                continue;
                        if (MOD_RESULT == MOD_RES_ALLOW)
                        {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Class forced by module to %s", c->GetName().c_str());
+                               ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Class forced by module to %s", c->GetName().c_str());
                                found = c;
                                break;
                        }
@@ -1637,7 +1470,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
                        if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
                            !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
                        {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
+                               ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "No host match (for %s)", c->GetHost().c_str());
                                continue;
                        }
 
@@ -1647,7 +1480,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
                         */
                        if (c->limit && (c->GetReferenceCount() >= c->limit))
                        {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
+                               ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
                                continue;
                        }
 
@@ -1655,7 +1488,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
                        int port = c->config->getInt("port");
                        if (port)
                        {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", port);
+                               ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Requires port (%d)", port);
 
                                /* and our port doesn't match, fail. */
                                if (this->GetServerPort() != port)
@@ -1666,7 +1499,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
                        {
                                if (ServerInstance->PassCompare(this, c->config->getString("password"), password, c->config->getString("hash")))
                                {
-                                       ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Bad password, skipping");
+                                       ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Bad password, skipping");
                                        continue;
                                }
                        }
@@ -1730,7 +1563,8 @@ const std::string& FakeUser::GetFullRealHost()
 ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask)
        : config(tag), type(t), fakelag(true), name("unnamed"), registration_timeout(0), host(mask),
        pingtime(0), softsendqmax(0), hardsendqmax(0), recvqmax(0),
-       penaltythreshold(0), commandrate(0), maxlocal(0), maxglobal(0), maxconnwarn(true), maxchans(0), limit(0)
+       penaltythreshold(0), commandrate(0), maxlocal(0), maxglobal(0), maxconnwarn(true), maxchans(0),
+       limit(0), nouserdns(false)
 {
 }
 
@@ -1740,7 +1574,7 @@ ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask, cons
        softsendqmax(parent.softsendqmax), hardsendqmax(parent.hardsendqmax), recvqmax(parent.recvqmax),
        penaltythreshold(parent.penaltythreshold), commandrate(parent.commandrate),
        maxlocal(parent.maxlocal), maxglobal(parent.maxglobal), maxconnwarn(parent.maxconnwarn), maxchans(parent.maxchans),
-       limit(parent.limit)
+       limit(parent.limit), nouserdns(parent.nouserdns)
 {
 }
 
@@ -1763,4 +1597,5 @@ void ConnectClass::Update(const ConnectClass* src)
        maxconnwarn = src->maxconnwarn;
        maxchans = src->maxchans;
        limit = src->limit;
+       nouserdns = src->nouserdns;
 }
index 44624663318082030aea5787b51656ee17de8e60..d307082f464cf015b79b2fddcd11b83c9e86d164 100755 (executable)
@@ -1,2 +1,2 @@
 #!/bin/sh
-echo "InspIRCd-2.0.13"
+echo "InspIRCd-2.2.0+pre"
diff --git a/src/whois.cpp b/src/whois.cpp
deleted file mode 100644 (file)
index bec9c7e..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "inspircd.h"
-
-void InspIRCd::DoWhois(User* user, User* dest,unsigned long signon, unsigned long idle, const char* nick)
-{
-       this->SendWhoisLine(user, dest, 311, "%s %s %s %s * :%s",user->nick.c_str(), dest->nick.c_str(), dest->ident.c_str(), dest->dhost.c_str(), dest->fullname.c_str());
-       if (user == dest || user->HasPrivPermission("users/auspex"))
-       {
-               this->SendWhoisLine(user, dest, 378, "%s %s :is connecting from %s@%s %s", user->nick.c_str(), dest->nick.c_str(), dest->ident.c_str(), dest->host.c_str(), dest->GetIPString());
-       }
-
-       std::string cl = dest->ChannelList(user, false);
-       const ServerConfig::OperSpyWhoisState state = user->HasPrivPermission("users/auspex") ? ServerInstance->Config->OperSpyWhois : ServerConfig::SPYWHOIS_NONE;
-
-       if (state == ServerConfig::SPYWHOIS_SINGLEMSG)
-               cl.append(dest->ChannelList(user, true));
-
-       user->SplitChanList(dest,cl);
-
-       if (state == ServerConfig::SPYWHOIS_SPLITMSG)
-       {
-               std::string scl = dest->ChannelList(user, true);
-               if (scl.length())
-               {
-                       SendWhoisLine(user, dest, 336, "%s %s :is on private/secret channels:",user->nick.c_str(), dest->nick.c_str());
-                       user->SplitChanList(dest,scl);
-               }
-       }
-       if (user != dest && !this->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex"))
-       {
-               this->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick.c_str(), dest->nick.c_str(), this->Config->HideWhoisServer.c_str(), this->Config->Network.c_str());
-       }
-       else
-       {
-               std::string serverdesc = GetServerDescription(dest->server);
-               this->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick.c_str(), dest->nick.c_str(), dest->server.c_str(), serverdesc.c_str());
-       }
-
-       if (IS_AWAY(dest))
-       {
-               this->SendWhoisLine(user, dest, 301, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), dest->awaymsg.c_str());
-       }
-
-       if (IS_OPER(dest))
-       {
-               if (this->Config->GenericOper)
-                       this->SendWhoisLine(user, dest, 313, "%s %s :is an IRC operator",user->nick.c_str(), dest->nick.c_str());
-               else
-                       this->SendWhoisLine(user, dest, 313, "%s %s :is %s %s on %s",user->nick.c_str(), dest->nick.c_str(), (strchr("AEIOUaeiou",dest->oper->name[0]) ? "an" : "a"),dest->oper->NameStr(), this->Config->Network.c_str());
-       }
-
-       if (user == dest || user->HasPrivPermission("users/auspex"))
-       {
-               if (dest->IsModeSet('s') != 0)
-               {
-                       this->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes(), dest->FormatNoticeMasks());
-               }
-               else
-               {
-                       this->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes());
-               }
-       }
-
-       FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
-
-       /*
-        * We only send these if we've been provided them. That is, if hidewhois is turned off, and user is local, or
-        * if remote whois is queried, too. This is to keep the user hidden, and also since you can't reliably tell remote time. -- w00t
-        */
-       if ((idle) || (signon))
-       {
-               this->SendWhoisLine(user, dest, 317, "%s %s %lu %lu :seconds idle, signon time",user->nick.c_str(), dest->nick.c_str(), idle, signon);
-       }
-
-       this->SendWhoisLine(user, dest, 318, "%s %s :End of /WHOIS list.",user->nick.c_str(), dest->nick.c_str());
-}
-
-
-
index eb9151293d8e185747de8ba4a3caaa729a5b1588..b64d2d6e89b633f21e30e8748a6d5f48f038a8b2 100644 (file)
@@ -78,7 +78,7 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask,
  * Below here is all wrappers around match_internal
  ********************************************************************/
 
-CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
 {
        if (!map)
                map = national_case_insensitive_map;
@@ -86,14 +86,14 @@ CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask,
        return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
 }
 
-CoreExport bool InspIRCd::Match(const  char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
 {
        if (!map)
                map = national_case_insensitive_map;
        return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
 }
 
-CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
 {
        if (irc::sockets::MatchCIDR(str, mask, true))
                return true;
@@ -105,7 +105,7 @@ CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &m
        return InspIRCd::Match(str, mask, map);
 }
 
-CoreExport bool InspIRCd::MatchCIDR(const  char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
 {
        if (irc::sockets::MatchCIDR(str, mask, true))
                return true;
@@ -117,3 +117,17 @@ CoreExport bool InspIRCd::MatchCIDR(const  char *str, const char *mask, unsigned
        return InspIRCd::Match(str, mask, map);
 }
 
+bool InspIRCd::MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr)
+{
+       std::stringstream masklist(masks);
+       std::string mask;
+       while (masklist >> mask)
+       {
+               if (InspIRCd::Match(hostname, mask, ascii_case_insensitive_map) || 
+                       InspIRCd::MatchCIDR(ipaddr, mask, ascii_case_insensitive_map))
+               {
+                       return true;
+               }
+       }
+       return false;
+}
index 66d24f439a6b12b600033a17bf40ef3b72ba6efd..4bb9551ecc6d8c1006f6b70459ec936004c78047 100644 (file)
@@ -158,7 +158,7 @@ void XLineManager::CheckELines()
 
        for (LocalUserList::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
        {
-               User* u = (User*)(*u2);
+               LocalUser* u = *u2;
 
                /* This uses safe iteration to ensure that if a line expires here, it doenst trash the iterator */
                LookupIter safei;
@@ -259,7 +259,7 @@ bool XLineManager::AddLine(XLine* line, User* user)
        ContainerIter x = lookup_lines.find(line->type);
        if (x != lookup_lines.end())
        {
-               LookupIter i = x->second.find(line->Displayable());
+               LookupIter i = x->second.find(line->Displayable().c_str());
                if (i != x->second.end())
                {
                        // XLine propagation bug was here, if the line to be added already exists and
@@ -281,7 +281,7 @@ bool XLineManager::AddLine(XLine* line, User* user)
        if (xlf->AutoApplyToUserList(line))
                pending_lines.push_back(line);
 
-       lookup_lines[line->type][line->Displayable()] = line;
+       lookup_lines[line->type][line->Displayable().c_str()] = line;
        line->OnAdd();
 
        FOREACH_MOD(I_OnAddLine,OnAddLine(user, line));
@@ -328,7 +328,7 @@ void ELine::Unset()
        /* remove exempt from everyone and force recheck after deleting eline */
        for (LocalUserList::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
        {
-               User* u = (User*)(*u2);
+               LocalUser* u = *u2;
                u->exempt = false;
        }
 
@@ -433,7 +433,7 @@ void XLineManager::ApplyLines()
        LocalUserList::reverse_iterator u2 = ServerInstance->Users->local_users.rbegin();
        while (u2 != ServerInstance->Users->local_users.rend())
        {
-               User* u = *u2++;
+               LocalUser* u = *u2++;
 
                // Don't ban people who are exempt.
                if (u->exempt)
@@ -531,30 +531,28 @@ bool XLine::IsBurstable()
 
 void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
 {
-       char sreason[MAXBUF];
-       snprintf(sreason, MAXBUF, "%s-Lined: %s", line.c_str(), this->reason.c_str());
+       const std::string banReason = line + "-Lined: " + reason;
+
        if (!ServerInstance->Config->MoronBanner.empty())
-               u->WriteServ("NOTICE %s :*** %s", u->nick.c_str(), ServerInstance->Config->MoronBanner.c_str());
+               u->WriteNotice("*** " + ServerInstance->Config->MoronBanner);
 
        if (ServerInstance->Config->HideBans)
-               ServerInstance->Users->QuitUser(u, line + "-Lined", sreason);
+               ServerInstance->Users->QuitUser(u, line + "-Lined", banReason.c_str());
        else
-               ServerInstance->Users->QuitUser(u, sreason);
+               ServerInstance->Users->QuitUser(u, banReason);
 
 
        if (bancache)
        {
-               ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding positive hit (" + line + ") for " + u->GetIPString());
-               if (this->duration > 0)
-                       ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason, this->duration);
-               else
-                       ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason);
+               ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCache: Adding positive hit (" + line + ") for " + u->GetIPString());
+               ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason, this->duration);
        }
 }
 
 bool KLine::Matches(User *u)
 {
-       if (u->exempt)
+       LocalUser* lu = IS_LOCAL(u);
+       if (lu && lu->exempt)
                return false;
 
        if (InspIRCd::Match(u->ident, this->identmask, ascii_case_insensitive_map))
@@ -576,7 +574,8 @@ void KLine::Apply(User* u)
 
 bool GLine::Matches(User *u)
 {
-       if (u->exempt)
+       LocalUser* lu = IS_LOCAL(u);
+       if (lu && lu->exempt)
                return false;
 
        if (InspIRCd::Match(u->ident, this->identmask, ascii_case_insensitive_map))
@@ -598,7 +597,8 @@ void GLine::Apply(User* u)
 
 bool ELine::Matches(User *u)
 {
-       if (u->exempt)
+       LocalUser* lu = IS_LOCAL(u);
+       if (lu && lu->exempt)
                return false;
 
        if (InspIRCd::Match(u->ident, this->identmask, ascii_case_insensitive_map))
@@ -615,7 +615,8 @@ bool ELine::Matches(User *u)
 
 bool ZLine::Matches(User *u)
 {
-       if (u->exempt)
+       LocalUser* lu = IS_LOCAL(u);
+       if (lu && lu->exempt)
                return false;
 
        if (InspIRCd::MatchCIDR(u->GetIPString(), this->ipaddr))
@@ -641,7 +642,7 @@ bool QLine::Matches(User *u)
 void QLine::Apply(User* u)
 {
        /* Force to uuid on apply of qline, no need to disconnect any more :) */
-       u->ForceNickChange(u->uuid.c_str());
+       u->ForceNickChange(u->uuid);
 }
 
 
@@ -681,65 +682,42 @@ void ELine::OnAdd()
        /* When adding one eline, only check the one eline */
        for (LocalUserList::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++)
        {
-               User* u = (User*)(*u2);
+               LocalUser* u = *u2;
                if (this->Matches(u))
                        u->exempt = true;
        }
 }
 
-void ELine::DisplayExpiry()
-{
-       ServerInstance->SNO->WriteToSnoMask('x',"Removing expired E-Line %s@%s (set by %s %ld seconds ago)",
-               identmask.c_str(),hostmask.c_str(),source.c_str(),(long)(ServerInstance->Time() - this->set_time));
-}
-
-void QLine::DisplayExpiry()
-{
-       ServerInstance->SNO->WriteToSnoMask('x',"Removing expired Q-Line %s (set by %s %ld seconds ago)",
-               nick.c_str(),source.c_str(),(long)(ServerInstance->Time() - this->set_time));
-}
-
-void ZLine::DisplayExpiry()
-{
-       ServerInstance->SNO->WriteToSnoMask('x',"Removing expired Z-Line %s (set by %s %ld seconds ago)",
-               ipaddr.c_str(),source.c_str(),(long)(ServerInstance->Time() - this->set_time));
-}
-
-void KLine::DisplayExpiry()
-{
-       ServerInstance->SNO->WriteToSnoMask('x',"Removing expired K-Line %s@%s (set by %s %ld seconds ago)",
-               identmask.c_str(),hostmask.c_str(),source.c_str(),(long)(ServerInstance->Time() - this->set_time));
-}
-
-void GLine::DisplayExpiry()
+void XLine::DisplayExpiry()
 {
-       ServerInstance->SNO->WriteToSnoMask('x',"Removing expired G-Line %s@%s (set by %s %ld seconds ago)",
-               identmask.c_str(),hostmask.c_str(),source.c_str(),(long)(ServerInstance->Time() - this->set_time));
+       bool onechar = (type.length() == 1);
+       ServerInstance->SNO->WriteToSnoMask('x', "Removing expired %s%s %s (set by %s %ld seconds ago)",
+               type.c_str(), (onechar ? "-Line" : ""), Displayable().c_str(), source.c_str(), (long)(ServerInstance->Time() - set_time));
 }
 
-const char* ELine::Displayable()
+const std::string& ELine::Displayable()
 {
-       return matchtext.c_str();
+       return matchtext;
 }
 
-const char* KLine::Displayable()
+const std::string& KLine::Displayable()
 {
-       return matchtext.c_str();
+       return matchtext;
 }
 
-const char* GLine::Displayable()
+const std::string& GLine::Displayable()
 {
-       return matchtext.c_str();
+       return matchtext;
 }
 
-const char* ZLine::Displayable()
+const std::string& ZLine::Displayable()
 {
-       return ipaddr.c_str();
+       return ipaddr;
 }
 
-const char* QLine::Displayable()
+const std::string& QLine::Displayable()
 {
-       return nick.c_str();
+       return nick;
 }
 
 bool KLine::IsBurstable()
diff --git a/tools/create_templates.pl b/tools/create_templates.pl
deleted file mode 100755 (executable)
index dfdaa29..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/perl
-
-#
-# InspIRCd -- Internet Relay Chat Daemon
-#
-#   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
-#
-# This file is part of InspIRCd.  InspIRCd is free software: you can
-# redistribute it and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation, version 2.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-
-use strict;
-use warnings;
-
-my $maxparams = shift;
-
-die "You must supply a number of parameters to generate headers allowing for!" unless(defined $maxparams);
-die "You must request a non-negative parameter limit!" unless($maxparams >= 0);
-
-print STDERR "Generating headerfile for a maximium of $maxparams parameters\n";
-
-# First generate the HanderBase family
-
-my @templatetypes = ('ReturnType');
-for(my $i = 0; $i <= $maxparams; $i++)
-{
-       push @templatetypes, "Param" . $i if($i > 0);
-       print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport HandlerBase" . $i . "\n";
-       print "{\n";
-       print " public:\n";
-       print " virtual ReturnType Call(" . join(', ', @templatetypes[1..$#templatetypes]) . ") = 0;\n";
-       print " virtual ~HandlerBase" . $i . "() { }\n";
-       print "};\n\n";
-}
-
-# And now the caller family
-
-print "template <typename HandlerType> class CoreExport caller\n";
-print "{\n";
-print " public:\n";
-print "        HandlerType* target;\n\n";
-print "        caller(HandlerType* initial)\n";
-print "        : target(initial)\n";
-print "        { }\n\n";
-print "        virtual ~caller() { }\n\n";
-print "        caller& operator=(HandlerType* newtarget)\n";
-print "        {\n";
-print "                target = newtarget;\n";
-print "                return *this;\n";
-print "        }\n";
-print "};\n\n";
-
-
-
-
-@templatetypes = ('ReturnType');
-for(my $i = 0; $i <= $maxparams; $i++)
-{
-       push @templatetypes, "Param" . $i if($i > 0);
-       
-       my $handlertype = "HandlerBase" . $i . "<" . join(', ', @templatetypes) . ">";
-       my @templatetypepairs = map { $_ . " " . lc($_) }  @templatetypes;
-       my @lctemplatetypes = map(lc, @templatetypes);
-       
-       print "template <typename " . join(', typename ', @templatetypes) . "> class CoreExport caller" . $i . " : public caller< " . $handlertype . " >\n";
-       print "{\n";
-       print " public:\n";
-       print " caller" . $i . "(" . $handlertype . "* initial)\n";
-       print " : caller< " . $handlertype. " >::caller(initial)\n";
-       print " { }\n\n";
-       print " virtual ReturnType operator() (" . join(', ', @templatetypepairs[1..$#templatetypepairs]) . ")\n";
-       print " {\n";
-       print "         return this->target->Call(" . join(', ', @lctemplatetypes[1..$#lctemplatetypes]) . ");\n";
-       print " }\n";
-       print "};\n\n";
-}
-
diff --git a/tools/genssl b/tools/genssl
new file mode 100755 (executable)
index 0000000..b658efb
--- /dev/null
@@ -0,0 +1,110 @@
+#!/usr/bin/env perl
+#
+# InspIRCd -- Internet Relay Chat Daemon
+#
+#   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+#   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
+#   Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
+#
+# This file is part of InspIRCd.  InspIRCd is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation, version 2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+BEGIN {
+       require 5.8.0;
+}
+
+use strict;
+use warnings FATAL => qw(all);
+
+use File::Temp();
+
+# IMPORTANT: This script has to be able to run by itself so that it can be used
+#            by binary distributions where the make/utilities.pm module will not
+#            be available!
+
+sub prompt($$) {
+       my ($question, $default) = @_;
+       print "$question\n";
+       print "[$default] => ";
+       chomp(my $answer = <STDIN>);
+       print "\n";
+       return $answer ? $answer : $default;
+}
+
+if ($#ARGV != 0 || $ARGV[0] !~ /gnutls|openssl/i) {
+       print "Syntax: genssl <gnutls|openssl>\n";
+       exit 1;
+}
+
+my $common_name = prompt('What is the hostname of your server?', 'irc.example.com');
+my $email = prompt('What email address can you be contacted at?', 'example@example.com');
+my $unit = prompt('What is the name of your unit?', 'Server Admins');
+my $organization = prompt('What is the name of your organization?', 'Example IRC Network');
+my $city = prompt('What city are you located in?', 'Example City');
+my $state = prompt('What state are you located in?', 'Example State');
+my $country = prompt('What is the ISO 3166-1 code for the country you are located in?', 'XZ');
+my $days = prompt('How many days do you want your certificate to be valid for?', '365');
+
+# Contains the exit code of openssl/gnutls-certtool.
+my $status = 0;
+
+if (lc $ARGV[0] eq 'gnutls') {
+       my $tmp = new File::Temp();
+       print $tmp <<__GNUTLS_END__;
+cn              = "$common_name"
+email           = "$email"
+unit            = "$unit"
+organization    = "$organization"
+locality        = "$city"
+state           = "$state"
+country         = "$country"
+expiration_days = $days
+tls_www_client
+tls_www_server
+signing_key
+encryption_key
+cert_signing_key
+crl_signing_key
+code_signing_key
+ocsp_signing_key
+time_stamping_key
+__GNUTLS_END__
+       close($tmp);
+       my $certtool = `uname -s` eq "Darwin\n" ? 'gnutls-certtool' : 'certtool';
+       $status ||= system "$certtool --version  >/dev/null 2>&1";
+       $status ||= system "$certtool --generate-privkey --outfile key.pem";
+       $status ||= system "$certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem --template $tmp";
+       $status ||= system "$certtool --generate-dh-params --bits 2048 --outfile dhparams.pem";
+} elsif (lc $ARGV[0] eq 'openssl') {
+       my $tmp = new File::Temp();
+       print $tmp <<__OPENSSL_END__;
+$country
+$state
+$city
+$organization
+$unit
+$common_name
+$email
+__OPENSSL_END__
+       close($tmp);
+       $status ||= system 'openssl version >/dev/null 2>&1';
+       $status ||= system "cat $tmp | openssl req -x509 -nodes -newkey rsa:2048 -keyout key.pem -out cert.pem -days $days 2>/dev/null";
+       $status ||= system 'openssl dhparam -out dhparams.pem 2048';
+}
+
+if ($status) {
+       print "SSL generation failed! Are you missing an $ARGV[0] binary package?\n";
+       exit 1;
+}
+
index f53ca0701fdc963b535f866175d9cceeea720fd6..4b875ca61c70ba738b164be0eb573c4120cdd36c 100644 (file)
@@ -1,3 +1,2 @@
-inspircd_version.h\r
-inspircd_config.h\r
+config.h\r
 inspircd.rc\r
index e6a854d998539cbbb98cd42e0857429e269c1eb7..ca7e9eb184c651ac77c7e3c494c9ff21aa4fa712 100644 (file)
@@ -56,8 +56,7 @@ if(MSVC)
 endif(MSVC)
 
 configure_file("${INSPIRCD_BASE}/win/inspircd.rc.cmake" "${INSPIRCD_BASE}/win/inspircd.rc")
-configure_file("${INSPIRCD_BASE}/win/inspircd_version.h.cmake" "${INSPIRCD_BASE}/win/inspircd_version.h")
-configure_file("${INSPIRCD_BASE}/win/inspircd_config.h.cmake" "${INSPIRCD_BASE}/win/inspircd_config.h")
+configure_file("${INSPIRCD_BASE}/win/config.h.cmake" "${INSPIRCD_BASE}/win/config.h")
 
 add_executable(inspircd ${INSPIRCD_SOURCES} "${INSPIRCD_BASE}/win/inspircd.rc")
 target_link_libraries(inspircd win32_memory)
diff --git a/win/config.h.cmake b/win/config.h.cmake
new file mode 100644 (file)
index 0000000..05c3ce2
--- /dev/null
@@ -0,0 +1,15 @@
+#pragma once\r
+\r
+#define BRANCH "@MAJOR_VERSION@.@MINOR_VERSION@"\r
+#define VERSION "@FULL_VERSION@"\r
+#define REVISION "0"\r
+#define SYSTEM "@CMAKE_SYSTEM@"\r
+\r
+#define CONFIG_PATH "@CONF_PATH@"\r
+#define MOD_PATH "@MODULE_PATH@"\r
+#define DATA_PATH "@DATA_PATH@"\r
+#define LOG_PATH "@LOG_PATH@"\r
+#define MAXBUF 514\r
+\r
+#include "inspircd_win32wrapper.h"\r
+#include "threadengines/threadengine_win32.h"\r
diff --git a/win/inspircd_config.h.cmake b/win/inspircd_config.h.cmake
deleted file mode 100644 (file)
index f98cd39..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef INSPIRCD_CONFIG_H\r
-#define INSPIRCD_CONFIG_H\r
-\r
-#define CONFIG_PATH "@CONF_PATH@"\r
-#define MOD_PATH "@MODULE_PATH@"\r
-#define DATA_PATH "@DATA_PATH@"\r
-#define LOG_PATH "@LOG_PATH@"\r
-#define MAXBUF 514\r
-\r
-#include "inspircd_win32wrapper.h"\r
-#include "threadengines/threadengine_win32.h"\r
-\r
-#endif
\ No newline at end of file
index 3987083172f5c2ae8c4c729f4498c95e6ed90d3b..2093bf3a8ed09d3c72e69903ac61ed8cf6aa503d 100644 (file)
@@ -16,6 +16,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include <windows.h>
 #include <exception>
 #include <new>
diff --git a/win/inspircd_version.h.cmake b/win/inspircd_version.h.cmake
deleted file mode 100644 (file)
index 1aec12b..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#define BRANCH "@MAJOR_VERSION@.@MINOR_VERSION@"\r
-#define VERSION "@FULL_VERSION@"\r
-#define REVISION "0"\r
-#define SYSTEM "@CMAKE_SYSTEM@"
\ No newline at end of file
index 4592aa5d17c2b27eee0f6e86adc3891b5cbf4be9..2836674bbdf9e70f1f38c1e98f856011db3899bd 100644 (file)
@@ -22,6 +22,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd_win32wrapper.h"
 #include "inspircd.h"
 #include "configreader.h"
@@ -85,7 +86,7 @@ CoreExport int insp_inet_pton(int af, const char *src, void *dst)
                }
                return 1;
        }
-       
+
        return 0;
 }
 
@@ -163,7 +164,7 @@ int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, cons
 //                                     optind++;               // Trash this next argument, we won't be needing it.
                                        par = ___argv[optind-1];
                                }
-                       }                       
+                       }
 
                        // increment the argument for next time
 //                     optind++;
@@ -189,9 +190,9 @@ int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, cons
                        {
                                if (__longopts[i].val == -1 || par == 0)
                                        return 1;
-                               
+
                                return __longopts[i].val;
-                       }                       
+                       }
                        break;
                }
        }
@@ -223,7 +224,7 @@ DWORD CWin32Exception::GetErrorCode()
 }
 
 #include "../src/modules/m_spanningtree/link.h"
-#include "../src/modules/ssl.h"
+#include "modules/ssl.h"
 template class reference<Link>;
 template class reference<Autoconnect>;
 template class reference<ssl_cert>;
index 75404ef8b29e170fb10230c61ae9621bbd19a97e..38754d5df4abf0bac8d5741b109ade9c8cf2c6d0 100644 (file)
  */
 
 
+#pragma once
+
 /* Windows Port
    Wrapper Functions/Definitions
    By Burlex */
-
-#ifndef INSPIRCD_WIN32WRAPPER_H
-#define INSPIRCD_WIN32WRAPPER_H
-
 /*
  * Starting with PSAPI version 2 for Windows 7 and Windows Server 2008 R2, this function is defined as K32GetProcessMemoryInfo in Psapi.h and exported
  * in Kernel32.lib and Kernel32.dll. However, you should always call this function as GetProcessMemoryInfo. To ensure correct resolution of symbols
@@ -45,9 +43,6 @@
 #define VC_EXTRALEAN
 #define WIN32_LEAN_AND_MEAN
 
-/* They just have to be *different*, don't they. */
-#define PATH_MAX MAX_PATH
-
 /* Macros for exporting symbols - dependant on what is being compiled */
 
 #ifdef DLL_BUILD
@@ -74,6 +69,9 @@
 #include <direct.h>
 #include <process.h>
 
+/* Windows defines this already. */
+#undef ERROR
+
 /* strcasecmp is not defined on windows by default */
 #define strcasecmp _stricmp
 #define strncasecmp _strnicmp
@@ -92,6 +90,10 @@ CoreExport const char * insp_inet_ntop(int af, const void * src, char * dst, soc
 #define snprintf _snprintf
 #define vsnprintf _vsnprintf
 
+#ifndef va_copy
+#define va_copy(dest, src) (dest = src)
+#endif
+
 /* Unix-style sleep (argument is in seconds) */
 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
 
@@ -200,6 +202,3 @@ private:
        char szErrorString[500];
        DWORD dwErrorCode;
 };
-
-#endif
-
index c34e9957d318d6bfaa020fbb690e856733e088d2..d06ad1838d81e9a606814d0670c3f0e94f7ff96c 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 
-#include "inspircd_config.h"
+#include "config.h"
 #include "inspircd.h"
 #include "exitcodes.h"
 #include <windows.h>
index e4500be131e897448996d6de3f5e492310f537aa..d8177eabcec3e1c8a19809a7bc4a2ed8412d9fb4 100644 (file)
@@ -15,7 +15,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #pragma once
+
 #ifdef _WIN32
 
 /* Hook for win32service.cpp to exit properly with the service specific error code */