summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/CMakeLists.txt254
-rw-r--r--modules/botserv/botserv.cpp (renamed from modules/pseudoclients/botserv.cpp)45
-rw-r--r--modules/botserv/bs_assign.cpp (renamed from modules/commands/bs_assign.cpp)36
-rw-r--r--modules/botserv/bs_autoassign.cpp (renamed from modules/bs_autoassign.cpp)7
-rw-r--r--modules/botserv/bs_badwords.cpp (renamed from modules/commands/bs_badwords.cpp)77
-rw-r--r--modules/botserv/bs_bot.cpp (renamed from modules/commands/bs_bot.cpp)47
-rw-r--r--modules/botserv/bs_botlist.cpp (renamed from modules/commands/bs_botlist.cpp)22
-rw-r--r--modules/botserv/bs_control.cpp (renamed from modules/commands/bs_control.cpp)23
-rw-r--r--modules/botserv/bs_info.cpp (renamed from modules/commands/bs_info.cpp)38
-rw-r--r--modules/botserv/bs_kick.cpp (renamed from modules/commands/bs_kick.cpp)302
-rw-r--r--modules/botserv/bs_set.cpp (renamed from modules/commands/bs_set.cpp)54
-rw-r--r--modules/chanserv/chanserv.cpp (renamed from modules/pseudoclients/chanserv.cpp)103
-rw-r--r--modules/chanserv/cs_access.cpp (renamed from modules/commands/cs_access.cpp)168
-rw-r--r--modules/chanserv/cs_akick.cpp (renamed from modules/commands/cs_akick.cpp)57
-rw-r--r--modules/chanserv/cs_ban.cpp (renamed from modules/commands/cs_ban.cpp)37
-rw-r--r--modules/chanserv/cs_clone.cpp (renamed from modules/commands/cs_clone.cpp)37
-rw-r--r--modules/chanserv/cs_drop.cpp (renamed from modules/commands/cs_drop.cpp)41
-rw-r--r--modules/chanserv/cs_enforce.cpp (renamed from modules/commands/cs_enforce.cpp)77
-rw-r--r--modules/chanserv/cs_entrymsg.cpp (renamed from modules/commands/cs_entrymsg.cpp)78
-rw-r--r--modules/chanserv/cs_fantasy_stats.cpp (renamed from modules/extra/stats/cs_fantasy_stats.cpp)32
-rw-r--r--modules/chanserv/cs_fantasy_top.cpp (renamed from modules/extra/stats/cs_fantasy_top.cpp)44
-rw-r--r--modules/chanserv/cs_flags.cpp (renamed from modules/commands/cs_flags.cpp)108
-rw-r--r--modules/chanserv/cs_getkey.cpp (renamed from modules/commands/cs_getkey.cpp)14
-rw-r--r--modules/chanserv/cs_info.cpp (renamed from modules/commands/cs_info.cpp)20
-rw-r--r--modules/chanserv/cs_invite.cpp (renamed from modules/commands/cs_invite.cpp)14
-rw-r--r--modules/chanserv/cs_kick.cpp (renamed from modules/commands/cs_kick.cpp)20
-rw-r--r--modules/chanserv/cs_list.cpp (renamed from modules/commands/cs_list.cpp)49
-rw-r--r--modules/chanserv/cs_log.cpp (renamed from modules/commands/cs_log.cpp)67
-rw-r--r--modules/chanserv/cs_mode.cpp (renamed from modules/commands/cs_mode.cpp)173
-rw-r--r--modules/chanserv/cs_register.cpp (renamed from modules/commands/cs_register.cpp)14
-rw-r--r--modules/chanserv/cs_seen.cpp (renamed from modules/commands/cs_seen.cpp)83
-rw-r--r--modules/chanserv/cs_set.cpp (renamed from modules/commands/cs_set.cpp)281
-rw-r--r--modules/chanserv/cs_set_misc.cpp (renamed from modules/commands/cs_set_misc.cpp)39
-rw-r--r--modules/chanserv/cs_status.cpp (renamed from modules/commands/cs_status.cpp)18
-rw-r--r--modules/chanserv/cs_statusupdate.cpp (renamed from modules/cs_statusupdate.cpp)29
-rw-r--r--modules/chanserv/cs_suspend.cpp (renamed from modules/commands/cs_suspend.cpp)50
-rw-r--r--modules/chanserv/cs_sync.cpp (renamed from modules/commands/cs_sync.cpp)18
-rw-r--r--modules/chanserv/cs_topic.cpp (renamed from modules/commands/cs_topic.cpp)31
-rw-r--r--modules/chanserv/cs_unban.cpp (renamed from modules/commands/cs_unban.cpp)56
-rw-r--r--modules/chanserv/cs_updown.cpp (renamed from modules/commands/cs_updown.cpp)30
-rw-r--r--modules/chanserv/cs_xop.cpp (renamed from modules/commands/cs_xop.cpp)113
-rw-r--r--modules/chanstats.cpp (renamed from modules/extra/stats/m_chanstats.cpp)77
-rw-r--r--modules/commands/ns_access.cpp206
-rw-r--r--modules/commands/ns_getpass.cpp74
-rw-r--r--modules/commands/ns_status.cpp87
-rw-r--r--modules/commands/os_oline.cpp78
-rw-r--r--modules/database/db_atheme.cpp1429
-rw-r--r--modules/database/db_flatfile.cpp122
-rw-r--r--modules/database/db_old.cpp76
-rw-r--r--modules/database/db_redis.cpp231
-rw-r--r--modules/database/db_sql.cpp90
-rw-r--r--modules/database/db_sql_live.cpp53
-rw-r--r--modules/dns.cpp (renamed from modules/m_dns.cpp)188
-rw-r--r--modules/dnsbl.cpp (renamed from modules/m_dnsbl.cpp)46
-rw-r--r--modules/encryption/enc_bcrypt.cpp998
-rw-r--r--modules/encryption/enc_md5.cpp382
-rw-r--r--modules/encryption/enc_none.cpp55
-rw-r--r--modules/encryption/enc_old.cpp100
-rw-r--r--modules/encryption/enc_sha1.cpp109
-rw-r--r--modules/encryption/enc_sha2.cpp200
-rw-r--r--modules/encryption/enc_sha256.cpp300
-rw-r--r--modules/extra/enc_argon2.cpp199
-rw-r--r--modules/extra/ldap.cpp (renamed from modules/extra/m_ldap.cpp)176
-rw-r--r--modules/extra/m_regex_pcre.cpp83
-rw-r--r--modules/extra/mysql.cpp (renamed from modules/extra/m_mysql.cpp)189
-rw-r--r--modules/extra/regex_pcre2.cpp (renamed from modules/extra/m_regex_pcre2.cpp)28
-rw-r--r--modules/extra/regex_posix.cpp (renamed from modules/extra/m_regex_posix.cpp)26
-rw-r--r--modules/extra/regex_tre.cpp (renamed from modules/extra/m_regex_tre.cpp)26
-rw-r--r--modules/extra/sqlite.cpp (renamed from modules/extra/m_sqlite.cpp)95
-rw-r--r--modules/extra/ssl_gnutls.cpp (renamed from modules/extra/m_ssl_gnutls.cpp)113
-rw-r--r--modules/extra/ssl_openssl.cpp (renamed from modules/extra/m_ssl_openssl.cpp)101
-rw-r--r--modules/extra/stats/irc2sql/irc2sql.h84
-rw-r--r--modules/fantasy.cpp25
-rw-r--r--modules/global/gl_global.cpp (renamed from modules/commands/gl_global.cpp)14
-rw-r--r--modules/global/global.cpp (renamed from modules/pseudoclients/global.cpp)24
-rw-r--r--modules/greet.cpp (renamed from modules/commands/greet.cpp)38
-rw-r--r--modules/help.cpp (renamed from modules/commands/help.cpp)32
-rw-r--r--modules/helpchan.cpp (renamed from modules/m_helpchan.cpp)7
-rw-r--r--modules/hostserv/hostserv.cpp (renamed from modules/pseudoclients/hostserv.cpp)31
-rw-r--r--modules/hostserv/hs_del.cpp (renamed from modules/commands/hs_del.cpp)27
-rw-r--r--modules/hostserv/hs_group.cpp (renamed from modules/commands/hs_group.cpp)33
-rw-r--r--modules/hostserv/hs_list.cpp (renamed from modules/commands/hs_list.cpp)45
-rw-r--r--modules/hostserv/hs_off.cpp (renamed from modules/commands/hs_off.cpp)14
-rw-r--r--modules/hostserv/hs_on.cpp (renamed from modules/commands/hs_on.cpp)21
-rw-r--r--modules/hostserv/hs_request.cpp (renamed from modules/commands/hs_request.cpp)125
-rw-r--r--modules/hostserv/hs_set.cpp (renamed from modules/commands/hs_set.cpp)46
-rw-r--r--modules/httpd.cpp (renamed from modules/m_httpd.cpp)106
-rw-r--r--modules/irc2sql/CMakeLists.txt (renamed from modules/extra/stats/irc2sql/CMakeLists.txt)0
-rw-r--r--modules/irc2sql/irc2sql.cpp (renamed from modules/extra/stats/irc2sql/irc2sql.cpp)19
-rw-r--r--modules/irc2sql/irc2sql.h88
-rw-r--r--modules/irc2sql/tables.cpp (renamed from modules/extra/stats/irc2sql/tables.cpp)0
-rw-r--r--modules/irc2sql/utils.cpp (renamed from modules/extra/stats/irc2sql/utils.cpp)0
-rw-r--r--modules/ldap_authentication.cpp (renamed from modules/extra/m_ldap_authentication.cpp)70
-rw-r--r--modules/ldap_oper.cpp (renamed from modules/extra/m_ldap_oper.cpp)28
-rw-r--r--modules/memoserv/memoserv.cpp (renamed from modules/pseudoclients/memoserv.cpp)51
-rw-r--r--modules/memoserv/ms_cancel.cpp (renamed from modules/commands/ms_cancel.cpp)14
-rw-r--r--modules/memoserv/ms_check.cpp (renamed from modules/commands/ms_check.cpp)14
-rw-r--r--modules/memoserv/ms_del.cpp (renamed from modules/commands/ms_del.cpp)23
-rw-r--r--modules/memoserv/ms_ignore.cpp (renamed from modules/commands/ms_ignore.cpp)26
-rw-r--r--modules/memoserv/ms_info.cpp (renamed from modules/commands/ms_info.cpp)40
-rw-r--r--modules/memoserv/ms_list.cpp (renamed from modules/commands/ms_list.cpp)29
-rw-r--r--modules/memoserv/ms_read.cpp (renamed from modules/commands/ms_read.cpp)23
-rw-r--r--modules/memoserv/ms_rsend.cpp (renamed from modules/commands/ms_rsend.cpp)16
-rw-r--r--modules/memoserv/ms_send.cpp (renamed from modules/commands/ms_send.cpp)16
-rw-r--r--modules/memoserv/ms_sendall.cpp (renamed from modules/commands/ms_sendall.cpp)18
-rw-r--r--modules/memoserv/ms_set.cpp (renamed from modules/commands/ms_set.cpp)32
-rw-r--r--modules/memoserv/ms_staff.cpp (renamed from modules/commands/ms_staff.cpp)18
-rw-r--r--modules/nickserv/nickserv.cpp (renamed from modules/pseudoclients/nickserv.cpp)187
-rw-r--r--modules/nickserv/ns_ajoin.cpp (renamed from modules/commands/ns_ajoin.cpp)59
-rw-r--r--modules/nickserv/ns_alist.cpp (renamed from modules/commands/ns_alist.cpp)31
-rw-r--r--modules/nickserv/ns_cert.cpp (renamed from modules/commands/ns_cert.cpp)82
-rw-r--r--modules/nickserv/ns_drop.cpp (renamed from modules/commands/ns_drop.cpp)55
-rw-r--r--modules/nickserv/ns_getemail.cpp (renamed from modules/commands/ns_getemail.cpp)18
-rw-r--r--modules/nickserv/ns_group.cpp (renamed from modules/commands/ns_group.cpp)69
-rw-r--r--modules/nickserv/ns_identify.cpp (renamed from modules/commands/ns_identify.cpp)25
-rw-r--r--modules/nickserv/ns_info.cpp (renamed from modules/commands/ns_info.cpp)51
-rw-r--r--modules/nickserv/ns_list.cpp (renamed from modules/commands/ns_list.cpp)58
-rw-r--r--modules/nickserv/ns_logout.cpp (renamed from modules/commands/ns_logout.cpp)16
-rw-r--r--modules/nickserv/ns_maxemail.cpp (renamed from modules/ns_maxemail.cpp)18
-rw-r--r--modules/nickserv/ns_recover.cpp (renamed from modules/commands/ns_recover.cpp)49
-rw-r--r--modules/nickserv/ns_register.cpp (renamed from modules/commands/ns_register.cpp)134
-rw-r--r--modules/nickserv/ns_resetpass.cpp (renamed from modules/commands/ns_resetpass.cpp)20
-rw-r--r--modules/nickserv/ns_set.cpp (renamed from modules/commands/ns_set.cpp)562
-rw-r--r--modules/nickserv/ns_set_misc.cpp (renamed from modules/commands/ns_set_misc.cpp)46
-rw-r--r--modules/nickserv/ns_suspend.cpp (renamed from modules/commands/ns_suspend.cpp)45
-rw-r--r--modules/nickserv/ns_update.cpp (renamed from modules/commands/ns_update.cpp)14
-rw-r--r--modules/operserv/operserv.cpp (renamed from modules/pseudoclients/operserv.cpp)76
-rw-r--r--modules/operserv/os_akill.cpp (renamed from modules/commands/os_akill.cpp)52
-rw-r--r--modules/operserv/os_chankill.cpp (renamed from modules/commands/os_chankill.cpp)20
-rw-r--r--modules/operserv/os_config.cpp (renamed from modules/commands/os_config.cpp)43
-rw-r--r--modules/operserv/os_defcon.cpp (renamed from modules/commands/os_defcon.cpp)78
-rw-r--r--modules/operserv/os_dns.cpp (renamed from modules/commands/os_dns.cpp)195
-rw-r--r--modules/operserv/os_forbid.cpp (renamed from modules/commands/os_forbid.cpp)96
-rw-r--r--modules/operserv/os_ignore.cpp (renamed from modules/commands/os_ignore.cpp)63
-rw-r--r--modules/operserv/os_info.cpp (renamed from modules/commands/os_info.cpp)74
-rw-r--r--modules/operserv/os_jupe.cpp (renamed from modules/commands/os_jupe.cpp)22
-rw-r--r--modules/operserv/os_kick.cpp (renamed from modules/commands/os_kick.cpp)14
-rw-r--r--modules/operserv/os_kill.cpp (renamed from modules/commands/os_kill.cpp)14
-rw-r--r--modules/operserv/os_list.cpp (renamed from modules/commands/os_list.cpp)87
-rw-r--r--modules/operserv/os_login.cpp (renamed from modules/commands/os_login.cpp)29
-rw-r--r--modules/operserv/os_logsearch.cpp (renamed from modules/commands/os_logsearch.cpp)54
-rw-r--r--modules/operserv/os_mode.cpp (renamed from modules/commands/os_mode.cpp)34
-rw-r--r--modules/operserv/os_modinfo.cpp (renamed from modules/commands/os_modinfo.cpp)39
-rw-r--r--modules/operserv/os_module.cpp (renamed from modules/commands/os_module.cpp)32
-rw-r--r--modules/operserv/os_news.cpp (renamed from modules/commands/os_news.cpp)114
-rw-r--r--modules/operserv/os_noop.cpp (renamed from modules/commands/os_noop.cpp)22
-rw-r--r--modules/operserv/os_oper.cpp (renamed from modules/commands/os_oper.cpp)66
-rw-r--r--modules/operserv/os_reload.cpp (renamed from modules/commands/os_reload.cpp)22
-rw-r--r--modules/operserv/os_session.cpp (renamed from modules/commands/os_session.cpp)139
-rw-r--r--modules/operserv/os_set.cpp (renamed from modules/commands/os_set.cpp)34
-rw-r--r--modules/operserv/os_shutdown.cpp (renamed from modules/commands/os_shutdown.cpp)42
-rw-r--r--modules/operserv/os_stats.cpp (renamed from modules/commands/os_stats.cpp)128
-rw-r--r--modules/operserv/os_svs.cpp (renamed from modules/commands/os_svs.cpp)36
-rw-r--r--modules/operserv/os_sxline.cpp (renamed from modules/commands/os_sxline.cpp)105
-rw-r--r--modules/operserv/os_update.cpp (renamed from modules/commands/os_update.cpp)18
-rw-r--r--modules/protocol/bahamut.cpp244
-rw-r--r--modules/protocol/hybrid.cpp348
-rw-r--r--modules/protocol/inspircd.cpp (renamed from modules/protocol/inspircd3.cpp)1502
-rw-r--r--modules/protocol/inspircd12.cpp1408
-rw-r--r--modules/protocol/inspircd20.cpp1106
-rw-r--r--modules/protocol/ngircd.cpp206
-rw-r--r--modules/protocol/plexus.cpp173
-rw-r--r--modules/protocol/ratbox.cpp142
-rw-r--r--modules/protocol/solanum.cpp (renamed from modules/protocol/charybdis.cpp)266
-rw-r--r--modules/protocol/unreal.cpp1340
-rw-r--r--modules/protocol/unrealircd.cpp (renamed from modules/protocol/unreal4.cpp)703
-rw-r--r--modules/proxyscan.cpp (renamed from modules/m_proxyscan.cpp)113
-rw-r--r--modules/redis.cpp (renamed from modules/m_redis.cpp)156
-rw-r--r--modules/regex_stdlib.cpp107
-rw-r--r--modules/rewrite.cpp (renamed from modules/m_rewrite.cpp)73
-rw-r--r--modules/sasl.cpp (renamed from modules/m_sasl.cpp)125
-rw-r--r--modules/sql_authentication.cpp (renamed from modules/extra/m_sql_authentication.cpp)30
-rw-r--r--modules/sql_log.cpp (renamed from modules/extra/m_sql_log.cpp)12
-rw-r--r--modules/sql_oper.cpp (renamed from modules/extra/m_sql_oper.cpp)43
-rw-r--r--modules/third/language/CMakeLists.txt10
-rw-r--r--modules/webcpanel/pages/chanserv/access.cpp13
-rw-r--r--modules/webcpanel/pages/chanserv/access.h26
-rw-r--r--modules/webcpanel/pages/chanserv/akick.cpp11
-rw-r--r--modules/webcpanel/pages/chanserv/akick.h26
-rw-r--r--modules/webcpanel/pages/chanserv/chanserv.h72
-rw-r--r--modules/webcpanel/pages/chanserv/drop.cpp4
-rw-r--r--modules/webcpanel/pages/chanserv/drop.h25
-rw-r--r--modules/webcpanel/pages/chanserv/info.cpp1
-rw-r--r--modules/webcpanel/pages/chanserv/info.h24
-rw-r--r--modules/webcpanel/pages/chanserv/modes.cpp18
-rw-r--r--modules/webcpanel/pages/chanserv/modes.h26
-rw-r--r--modules/webcpanel/pages/chanserv/set.cpp14
-rw-r--r--modules/webcpanel/pages/chanserv/set.h26
-rw-r--r--modules/webcpanel/pages/chanserv/utils.cpp4
-rw-r--r--modules/webcpanel/pages/chanserv/utils.h18
-rw-r--r--modules/webcpanel/pages/confirm.h9
-rw-r--r--modules/webcpanel/pages/hostserv/hostserv.h (renamed from modules/webcpanel/pages/hostserv/request.h)19
-rw-r--r--modules/webcpanel/pages/hostserv/request.cpp7
-rw-r--r--modules/webcpanel/pages/index.cpp23
-rw-r--r--modules/webcpanel/pages/index.h15
-rw-r--r--modules/webcpanel/pages/logout.h9
-rw-r--r--modules/webcpanel/pages/memoserv/memos.cpp16
-rw-r--r--modules/webcpanel/pages/memoserv/memoserv.h (renamed from modules/webcpanel/pages/memoserv/memos.h)19
-rw-r--r--modules/webcpanel/pages/nickserv/access.cpp39
-rw-r--r--modules/webcpanel/pages/nickserv/access.h24
-rw-r--r--modules/webcpanel/pages/nickserv/alist.cpp8
-rw-r--r--modules/webcpanel/pages/nickserv/alist.h24
-rw-r--r--modules/webcpanel/pages/nickserv/cert.cpp4
-rw-r--r--modules/webcpanel/pages/nickserv/cert.h24
-rw-r--r--modules/webcpanel/pages/nickserv/confirm.h24
-rw-r--r--modules/webcpanel/pages/nickserv/info.cpp21
-rw-r--r--modules/webcpanel/pages/nickserv/info.h24
-rw-r--r--modules/webcpanel/pages/nickserv/nickserv.h48
-rw-r--r--modules/webcpanel/pages/operserv/akill.cpp8
-rw-r--r--modules/webcpanel/pages/operserv/operserv.h (renamed from modules/webcpanel/pages/operserv/akill.h)19
-rw-r--r--modules/webcpanel/pages/register.cpp3
-rw-r--r--modules/webcpanel/pages/register.h9
-rw-r--r--modules/webcpanel/static_fileserver.cpp2
-rw-r--r--modules/webcpanel/static_fileserver.h9
-rw-r--r--modules/webcpanel/template_fileserver.cpp24
-rw-r--r--modules/webcpanel/template_fileserver.h13
-rw-r--r--modules/webcpanel/templates/default/chanserv/set.html4
-rw-r--r--modules/webcpanel/templates/default/nickserv/access.html42
-rw-r--r--modules/webcpanel/templates/default/nickserv/info.html4
-rw-r--r--modules/webcpanel/templates/default/register.html8
-rw-r--r--modules/webcpanel/webcpanel.cpp28
-rw-r--r--modules/webcpanel/webcpanel.h59
-rw-r--r--modules/xmlrpc.cpp (renamed from modules/m_xmlrpc.cpp)47
-rw-r--r--modules/xmlrpc_main.cpp (renamed from modules/m_xmlrpc_main.cpp)104
224 files changed, 9533 insertions, 12849 deletions
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt
index 460c7b18a..c6a98df7f 100644
--- a/modules/CMakeLists.txt
+++ b/modules/CMakeLists.txt
@@ -1,7 +1,7 @@
# If using Windows, add the MODULE_COMPILE define
if(WIN32)
add_definitions(-DMODULE_COMPILE)
-endif(WIN32)
+endif()
# enable extra modules if conan is used
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../conanbuildinfo.cmake")
@@ -19,18 +19,13 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../conanbuildinfo.cmake")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/extra/${NAME}.cpp" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}")
endfunction()
- enable_extra("m_mysql" "LIBMYSQLCLIENT")
- enable_extra("m_regex_pcre2" "PCRE2")
- enable_extra("m_sqlite" "SQLITE3")
- enable_extra("m_ssl_openssl" "OPENSSL")
+ enable_extra("enc_argon2" "ARGON2")
+ enable_extra("mysql" "LIBMYSQLCLIENT")
+ enable_extra("regex_pcre2" "PCRE2")
+ enable_extra("sqlite" "SQLITE3")
+ enable_extra("ssl_openssl" "OPENSSL")
# this uses Wldap so should always be available
- copy_extra("m_ldap")
- # these don't actually have extra dependencies, but require a module which does
- copy_extra("m_sql_authentication")
- copy_extra("m_sql_log")
- copy_extra("m_sql_oper")
- copy_extra("m_ldap_authentication")
- copy_extra("m_ldap_oper")
+ copy_extra("ldap")
# Package extra dlls
file(GLOB EXTRA_DLLS "${Anope_SOURCE_DIR}/extradll/bin/*.dll" "${Anope_SOURCE_DIR}/extradll/lib/*.dll")
@@ -40,164 +35,141 @@ endif()
macro(build_modules SRC)
if(NOT ${SRC} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} AND EXISTS "${SRC}/CMakeLists.txt")
add_subdirectory("${SRC}")
- else(NOT ${SRC} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} AND EXISTS "${SRC}/CMakeLists.txt")
+ else()
file(GLOB MODULES_SRCS "${SRC}/*")
foreach(MODULE_SRC ${MODULES_SRCS})
if(IS_DIRECTORY "${MODULE_SRC}")
build_modules("${MODULE_SRC}")
- else(IS_DIRECTORY "${MODULE_SRC}")
+ else()
string(REGEX MATCH "\\.c$" ANOPE18MODULE ${MODULE_SRC})
if(ANOPE18MODULE)
message(FATAL_ERROR "Anope 1 modules are not compatible with Anope 2!\nOffending module: ${MODULE_SRC}")
- endif(ANOPE18MODULE)
+ endif()
string(REGEX MATCH "\\.cpp$" CPP ${MODULE_SRC})
if(CPP)
set_source_files_properties(${MODULE_SRC} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
file(RELATIVE_PATH FNAME ${SRC} ${MODULE_SRC})
- # Convert the real source file extension to have a .so extension
- string(REGEX REPLACE "\\.cpp$" ".so" SO ${FNAME})
- # Temporary variable for the current source's include directories
- set(TEMP_INCLUDES)
- # Calculate the header file dependencies for the given source file
- calculate_depends(${MODULE_SRC} TEMP_INCLUDES)
- # If there were some extra include directories, add them to the list
- if(TEMP_INCLUDES)
- append_to_list(EXTRA_INCLUDES ${TEMP_INCLUDES})
- endif(TEMP_INCLUDES)
-
+ # Convert the real source file extension to have a library extension
+ string(REGEX REPLACE "\\.cpp$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" SO ${FNAME})
# Reset linker flags
set(TEMP_LDFLAGS)
# Reset extra dependencies
set(TEMP_DEPENDENCIES)
# Calculate the library dependencies for the given source file
calculate_libraries(${MODULE_SRC} TEMP_LDFLAGS TEMP_DEPENDENCIES)
- # Reset has_function
- set(HAS_FUNCTION)
- # Check the function dependencies for the given source file
- check_functions(${MODULE_SRC} HAS_FUNCTION)
- # Only continue if this module has all of the required functions
- if(HAS_FUNCTION)
- # For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators
- if(MSVC)
- set(WIN32_MEMORY win32_memory)
- else(MSVC)
- set(WIN32_MEMORY)
- endif(MSVC)
- # Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand
- add_library(${SO} MODULE ${MODULE_SRC})
- # Windows requires this because it's weird
- if(WIN32)
- set(WIN32_NO_LIBS "/nodefaultlib:\"libcmt.lib\" /OPT:NOREF")
- else(WIN32)
- set(WIN32_NO_LIBS)
- endif(WIN32)
- set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON)
- add_dependencies(${SO} ${PROGRAM_NAME})
- if(GETTEXT_FOUND)
- add_dependencies(${SO} module_language)
- endif(GETTEXT_FOUND)
- target_link_libraries(${SO} ${TEMP_DEPENDENCIES})
- # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set its version
- if(WIN32)
- target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
- set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
- else(WIN32)
- if(APPLE)
- target_link_libraries(${SO} ${PROGRAM_NAME})
- endif(APPLE)
- endif(WIN32)
- # Set the module to be installed to the module directory under the data directory
- install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules)
- endif(HAS_FUNCTION)
- endif(CPP)
- endif(IS_DIRECTORY "${MODULE_SRC}")
- endforeach(MODULE_SRC ${MODULES_SRCS})
- endif(NOT ${SRC} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} AND EXISTS "${SRC}/CMakeLists.txt")
-endmacro(build_modules)
+ # For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators
+ if(MSVC)
+ set(WIN32_MEMORY win32_memory)
+ else()
+ set(WIN32_MEMORY)
+ endif()
+ # Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand
+ add_library(${SO} MODULE ${MODULE_SRC})
+ # Windows requires this because it's weird
+ if(WIN32)
+ set(WIN32_NO_LIBS "/nodefaultlib:\"libcmt.lib\" /OPT:NOREF")
+ else()
+ set(WIN32_NO_LIBS)
+ endif()
+ set_target_properties(${SO} PROPERTIES
+ BUILD_WITH_INSTALL_RPATH ON
+ FOLDER "Modules"
+ INSTALL_RPATH_USE_LINK_PATH ON
+ LINKER_LANGUAGE CXX
+ LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}"
+ PREFIX ""
+ SUFFIX ""
+ )
+ add_dependencies(${SO} ${PROGRAM_NAME})
+ if(HAVE_LOCALIZATION)
+ add_dependencies(${SO} module_language)
+ endif()
+ target_link_libraries(${SO} ${TEMP_DEPENDENCIES})
+ # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set its version
+ if(WIN32)
+ target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
+ set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
+ elseif(APPLE)
+ target_link_libraries(${SO} ${PROGRAM_NAME})
+ endif()
+ # Set the module to be installed to the module directory under the data directory
+ install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules)
+ endif()
+ endif()
+ endforeach()
+ endif()
+endmacro()
macro(build_subdir)
file(GLOB_RECURSE MODULES_SUBDIR_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
- sort_list(MODULES_SUBDIR_SRCS)
+ list(SORT MODULES_SUBDIR_SRCS)
GET_FILENAME_COMPONENT(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
- set(SO "${FOLDER_NAME}.so")
+ set(SO "${FOLDER_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
# Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though)
set_source_files_properties(${MODULES_SUBDIR_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
- set(HAS_FUNCTION TRUE)
-
# Iterate through the source files in the subdirectory
foreach(SRC ${MODULES_SUBDIR_SRCS})
- if(HAS_FUNCTION)
- # Temporary variable for the current source's include directories
- set(TEMP_INCLUDES)
- # Calculate the header file dependencies for the given source file
- calculate_depends(${SRC} TEMP_INCLUDES)
- # If there were some extra include directories, add them to the list
- if(TEMP_INCLUDES)
- include_directories(${TEMP_INCLUDES})
- endif(TEMP_INCLUDES)
-
- # Reset linker flags
- set(TEMP_LDFLAGS)
- # Reset extra dependencies
- set(TEMP_DEPENDENCIES)
- # Calculate the library dependencies for the given source file
- calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES)
- # Check the function dependencies for the given source file
- check_functions(${SRC} HAS_FUNCTION)
-
- # Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append
- if(TEMP_DEPENDENCIES)
- append_to_list(SUBDIR_EXTRA_DEPENDS ${TEMP_DEPENDENCIES})
- endif(TEMP_DEPENDENCIES)
- endif(HAS_FUNCTION)
- endforeach(SRC ${MODULES_SUBDIR_SRCS})
-
- # Continue if library and function requirements are met
- if(HAS_FUNCTION)
- # Remove duplicates from the linker flags
- if(SUBDIR_LDFLAGS)
- remove_list_duplicates(SUBDIR_LDFLAGS)
- endif(SUBDIR_LDFLAGS)
-
- # Remove duplicates from the extra dependencies
- if(SUBDIR_EXTRA_DEPENDS)
- remove_list_duplicates(SUBDIR_EXTRA_DEPENDS)
- endif(SUBDIR_EXTRA_DEPENDS)
-
- # For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators
- if(MSVC)
- set(WIN32_MEMORY win32_memory)
- else(MSVC)
- set(WIN32_MEMORY)
- endif(MSVC)
-
- # Generate the module and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand
- add_library(${SO} MODULE ${MODULES_SUBDIR_SRCS})
- set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON)
- add_dependencies(${SO} ${PROGRAM_NAME})
- if(GETTEXT_FOUND)
- add_dependencies(${SO} module_language)
- endif(GETTEXT_FOUND)
- target_link_libraries(${SO} ${SUBDIR_EXTRA_DEPENDS})
- # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set it's version
- if(WIN32)
- target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
- set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
- else(WIN32)
- if(APPLE)
- target_link_libraries(${SO} ${PROGRAM_NAME})
- endif(APPLE)
- endif(WIN32)
-
- # Set the module to be installed to the module directory under the data directory
- install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules)
-
- endif(HAS_FUNCTION)
-endmacro(build_subdir)
+ # Reset linker flags
+ set(TEMP_LDFLAGS)
+ # Reset extra dependencies
+ set(TEMP_DEPENDENCIES)
+ # Calculate the library dependencies for the given source file
+ calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES)
+
+ # Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append
+ if(TEMP_DEPENDENCIES)
+ list(APPEND SUBDIR_EXTRA_DEPENDS ${TEMP_DEPENDENCIES})
+ endif()
+ endforeach()
+
+ # Remove duplicates from the linker flags
+ if(SUBDIR_LDFLAGS)
+ list(REMOVE_DUPLICATES SUBDIR_LDFLAGS)
+ endif()
+
+ # Remove duplicates from the extra dependencies
+ if(SUBDIR_EXTRA_DEPENDS)
+ list(REMOVE_DUPLICATES SUBDIR_EXTRA_DEPENDS)
+ endif()
+
+ # For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators
+ if(MSVC)
+ set(WIN32_MEMORY win32_memory)
+ else()
+ set(WIN32_MEMORY)
+ endif()
+
+ # Generate the module and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand
+ add_library(${SO} MODULE ${MODULES_SUBDIR_SRCS})
+ set_target_properties(${SO} PROPERTIES
+ BUILD_WITH_INSTALL_RPATH ON
+ FOLDER "Modules"
+ INSTALL_RPATH_USE_LINK_PATH ON
+ LINKER_LANGUAGE CXX
+ LINK_FLAGS "${SUBDIR_LDFLAGS}"
+ PREFIX ""
+ SUFFIX ""
+ )
+ add_dependencies(${SO} ${PROGRAM_NAME})
+ if(HAVE_LOCALIZATION)
+ add_dependencies(${SO} module_language)
+ endif()
+ target_link_libraries(${SO} ${SUBDIR_EXTRA_DEPENDS})
+ # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set it's version
+ if(WIN32)
+ target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
+ set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
+ elseif(APPLE)
+ target_link_libraries(${SO} ${PROGRAM_NAME})
+ endif()
+
+ # Set the module to be installed to the module directory under the data directory
+ install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules)
+endmacro()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
build_modules(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/modules/pseudoclients/botserv.cpp b/modules/botserv/botserv.cpp
index 0d621e898..706865522 100644
--- a/modules/pseudoclients/botserv.cpp
+++ b/modules/botserv/botserv.cpp
@@ -11,35 +11,36 @@
#include "module.h"
-class BotServCore : public Module
+class BotServCore final
+ : public Module
{
Reference<BotInfo> BotServ;
ExtensibleRef<bool> persist, inhabit;
- public:
+public:
BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
persist("PERSIST"), inhabit("inhabit")
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
const Anope::string &bsnick = conf->GetModule(this)->Get<const Anope::string>("client");
BotServ = BotInfo::Find(bsnick, true);
}
- void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) anope_override
+ void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override
{
/* Do not allow removing bot modes on our service bots */
if (chan->ci && chan->ci->bi == user)
{
const Anope::string &botmodes = Config->GetModule(this)->Get<const Anope::string>("botmodes");
- for (unsigned i = 0; i < botmodes.length(); ++i)
- chan->SetMode(chan->ci->bi, ModeManager::FindChannelModeByChar(botmodes[i]), chan->ci->bi->GetUID());
+ for (auto botmode : botmodes)
+ chan->SetMode(chan->ci->bi, ModeManager::FindChannelModeByChar(botmode), chan->ci->bi->GetUID());
}
}
- void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) anope_override
+ void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) override
{
if (ci->c && ci->c->users.size() >= Config->GetModule(this)->Get<unsigned>("minusers"))
{
@@ -48,7 +49,7 @@ class BotServCore : public Module
}
}
- void OnJoinChannel(User *user, Channel *c) anope_override
+ void OnJoinChannel(User *user, Channel *c) override
{
if (!Config || !IRCD)
return;
@@ -56,24 +57,18 @@ class BotServCore : public Module
BotInfo *bi = user->server == Me ? dynamic_cast<BotInfo *>(user) : NULL;
if (bi && Config->GetModule(this)->Get<bool>("smartjoin"))
{
- std::vector<Anope::string> bans = c->GetModeList("BAN");
-
/* We check for bans */
- for (unsigned int i = 0; i < bans.size(); ++i)
+ for (const auto &entry : c->GetModeList("BAN"))
{
- Entry ban("BAN", bans[i]);
+ Entry ban("BAN", entry);
if (ban.Matches(user))
c->RemoveMode(NULL, "BAN", ban.GetMask());
}
Anope::string Limit;
unsigned limit = 0;
- try
- {
- if (c->GetParam("LIMIT", Limit))
- limit = convertTo<unsigned>(Limit);
- }
- catch (const ConvertException &) { }
+ if (c->GetParam("LIMIT", Limit))
+ limit = Anope::Convert<unsigned>(Limit, limit);
/* Should we be invited? */
if (c->HasMode("INVITE") || (limit && c->users.size() >= limit))
@@ -103,7 +98,7 @@ class BotServCore : public Module
}
}
- void OnLeaveChannel(User *u, Channel *c) anope_override
+ void OnLeaveChannel(User *u, Channel *c) override
{
/* Channel is persistent, it shouldn't be deleted and the service bot should stay */
if (c->ci && persist && persist->HasExt(c->ci))
@@ -124,7 +119,7 @@ class BotServCore : public Module
c->ci->bi->Part(c->ci->c);
}
- EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty())
return EVENT_CONTINUE;
@@ -159,7 +154,7 @@ class BotServCore : public Module
return EVENT_CONTINUE;
}
- void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *BotServ)
return;
@@ -174,7 +169,7 @@ class BotServCore : public Module
"one of the following characters: %s"), fantasycharacters.c_str());
}
- EventReturn OnChannelModeSet(Channel *c, MessageSource &source, ChannelMode *mode, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &source, ChannelMode *mode, const Anope::string &param) override
{
if (source.GetUser() && !source.GetBot() && Config->GetModule(this)->Get<bool>("smartjoin") && mode->name == "BAN" && c->ci && c->ci->bi && c->FindUser(c->ci->bi))
{
@@ -188,7 +183,7 @@ class BotServCore : public Module
return EVENT_CONTINUE;
}
- void OnCreateChan(ChannelInfo *ci) anope_override
+ void OnCreateChan(ChannelInfo *ci) override
{
/* Set default bot flags */
spacesepstream sep(Config->GetModule(this)->Get<const Anope::string>("defaults", "greet fantasy"));
@@ -196,7 +191,7 @@ class BotServCore : public Module
ci->Extend<bool>("BS_" + token.upper());
}
- void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) anope_override
+ void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) override
{
BotInfo *bi = BotInfo::Find(target->GetUID());
if (bi)
@@ -204,7 +199,7 @@ class BotServCore : public Module
bi->Join(channel, &status);
}
- void OnCreateBot(BotInfo *bi) anope_override
+ void OnCreateBot(BotInfo *bi) override
{
if (bi->botmodes.empty())
bi->botmodes = Config->GetModule(this)->Get<const Anope::string>("botumodes");
diff --git a/modules/commands/bs_assign.cpp b/modules/botserv/bs_assign.cpp
index 2b35fbf7e..43abdd55f 100644
--- a/modules/commands/bs_assign.cpp
+++ b/modules/botserv/bs_assign.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandBSAssign : public Command
+class CommandBSAssign final
+ : public Command
{
- public:
+public:
CommandBSAssign(Module *creator) : Command(creator, "botserv/assign", 2, 2)
{
this->SetDesc(_("Assigns a bot to a channel"));
this->SetSyntax(_("\037channel\037 \037nick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
const Anope::string &nick = params[1];
@@ -71,7 +72,7 @@ class CommandBSAssign : public Command
source.Reply(_("Bot \002%s\002 has been assigned to %s."), bi->nick.c_str(), ci->name.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -82,16 +83,17 @@ class CommandBSAssign : public Command
}
};
-class CommandBSUnassign : public Command
+class CommandBSUnassign final
+ : public Command
{
- public:
+public:
CommandBSUnassign(Module *creator) : Command(creator, "botserv/unassign", 1, 1)
{
this->SetDesc(_("Unassigns a bot from a channel"));
this->SetSyntax(_("\037channel\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -132,7 +134,7 @@ class CommandBSUnassign : public Command
source.Reply(_("There is no bot assigned to %s anymore."), ci->name.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -145,16 +147,17 @@ class CommandBSUnassign : public Command
}
};
-class CommandBSSetNoBot : public Command
+class CommandBSSetNoBot final
+ : public Command
{
- public:
+public:
CommandBSSetNoBot(Module *creator, const Anope::string &sname = "botserv/set/nobot") : Command(creator, sname, 2, 2)
{
this->SetDesc(_("Prevent a bot from being assigned to a channel"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
const Anope::string &value = params[1];
@@ -191,7 +194,7 @@ class CommandBSSetNoBot : public Command
this->OnSyntaxError(source, source.command);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -202,7 +205,8 @@ class CommandBSSetNoBot : public Command
}
};
-class BSAssign : public Module
+class BSAssign final
+ : public Module
{
ExtensibleItem<bool> nobot;
@@ -210,14 +214,14 @@ class BSAssign : public Module
CommandBSUnassign commandbsunassign;
CommandBSSetNoBot commandbssetnobot;
- public:
+public:
BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
nobot(this, "BS_NOBOT"),
commandbsassign(this), commandbsunassign(this), commandbssetnobot(this)
{
}
- void OnInvite(User *source, Channel *c, User *targ) anope_override
+ void OnInvite(User *source, Channel *c, User *targ) override
{
BotInfo *bi;
if (Anope::ReadOnly || !c->ci || targ->server != Me || !(bi = dynamic_cast<BotInfo *>(targ)))
@@ -246,7 +250,7 @@ class BSAssign : public Module
targ->SendMessage(bi, _("Bot \002%s\002 has been assigned to %s."), bi->nick.c_str(), c->name.c_str());
}
- void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) anope_override
+ void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) override
{
if (nobot.HasExt(ci))
info.AddOption(_("No bot"));
diff --git a/modules/bs_autoassign.cpp b/modules/botserv/bs_autoassign.cpp
index ffddd70df..a716525f9 100644
--- a/modules/bs_autoassign.cpp
+++ b/modules/botserv/bs_autoassign.cpp
@@ -9,14 +9,15 @@
#include "module.h"
-class BSAutoAssign : public Module
+class BSAutoAssign final
+ : public Module
{
- public:
+public:
BSAutoAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
{
}
- void OnChanRegistered(ChannelInfo *ci) anope_override
+ void OnChanRegistered(ChannelInfo *ci) override
{
const Anope::string &bot = Config->GetModule(this)->Get<const Anope::string>("bot");
if (bot.empty())
diff --git a/modules/commands/bs_badwords.cpp b/modules/botserv/bs_badwords.cpp
index 60e3eb6a3..09e96564b 100644
--- a/modules/commands/bs_badwords.cpp
+++ b/modules/botserv/bs_badwords.cpp
@@ -12,22 +12,25 @@
#include "module.h"
#include "modules/bs_badwords.h"
-struct BadWordImpl : BadWord, Serializable
+struct BadWordImpl final
+ : BadWord
+ , Serializable
{
BadWordImpl() : Serializable("BadWord") { }
- ~BadWordImpl();
+ ~BadWordImpl() override;
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["ci"] << this->chan;
data["word"] << this->word;
data.SetType("type", Serialize::Data::DT_INT); data["type"] << this->type;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
};
-struct BadWordsImpl : BadWords
+struct BadWordsImpl final
+ : BadWords
{
Serialize::Reference<ChannelInfo> ci;
typedef std::vector<BadWordImpl *> list;
@@ -35,11 +38,11 @@ struct BadWordsImpl : BadWords
BadWordsImpl(Extensible *obj) : ci(anope_dynamic_static_cast<ChannelInfo *>(obj)), badwords("BadWord") { }
- ~BadWordsImpl();
+ ~BadWordsImpl() override;
- BadWord* AddBadWord(const Anope::string &word, BadWordType type) anope_override
+ BadWord *AddBadWord(const Anope::string &word, BadWordType type) override
{
- BadWordImpl *bw = new BadWordImpl();
+ auto *bw = new BadWordImpl();
bw->chan = ci->name;
bw->word = word;
bw->type = type;
@@ -51,7 +54,7 @@ struct BadWordsImpl : BadWords
return bw;
}
- BadWord* GetBadWord(unsigned index) const anope_override
+ BadWord *GetBadWord(unsigned index) const override
{
if (this->badwords->empty() || index >= this->badwords->size())
return NULL;
@@ -61,12 +64,12 @@ struct BadWordsImpl : BadWords
return bw;
}
- unsigned GetBadWordCount() const anope_override
+ unsigned GetBadWordCount() const override
{
return this->badwords->size();
}
- void EraseBadWord(unsigned index) anope_override
+ void EraseBadWord(unsigned index) override
{
if (this->badwords->empty() || index >= this->badwords->size())
return;
@@ -76,13 +79,13 @@ struct BadWordsImpl : BadWords
delete this->badwords->at(index);
}
- void ClearBadWords() anope_override
+ void ClearBadWords() override
{
while (!this->badwords->empty())
delete this->badwords->back();
}
- void Check() anope_override
+ void Check() override
{
if (this->badwords->empty())
ci->Shrink<BadWords>("badwords");
@@ -114,7 +117,7 @@ BadWordImpl::~BadWordImpl()
}
}
-Serializable* BadWordImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *BadWordImpl::Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string sci, sword;
@@ -144,23 +147,24 @@ Serializable* BadWordImpl::Unserialize(Serializable *obj, Serialize::Data &data)
return bw;
}
-class BadwordsDelCallback : public NumberList
+class BadwordsDelCallback final
+ : public NumberList
{
CommandSource &source;
ChannelInfo *ci;
BadWords *bw;
Command *c;
- unsigned deleted;
- bool override;
- public:
- BadwordsDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), deleted(0), override(false)
+ unsigned deleted = 0;
+ bool override = false;
+public:
+ BadwordsDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c)
{
if (!source.AccessFor(ci).HasPriv("BADWORDS") && source.HasPriv("botserv/administration"))
this->override = true;
bw = ci->Require<BadWords>("badwords");
}
- ~BadwordsDelCallback()
+ ~BadwordsDelCallback() override
{
if (!deleted)
source.Reply(_("No matching entries on %s bad words list."), ci->name.c_str());
@@ -170,7 +174,7 @@ class BadwordsDelCallback : public NumberList
source.Reply(_("Deleted %d entries from %s bad words list."), deleted, ci->name.c_str());
}
- void HandleNumber(unsigned Number) anope_override
+ void HandleNumber(unsigned Number) override
{
if (!bw || !Number || Number > bw->GetBadWordCount())
return;
@@ -181,9 +185,10 @@ class BadwordsDelCallback : public NumberList
}
};
-class CommandBSBadwords : public Command
+class CommandBSBadwords final
+ : public Command
{
- private:
+private:
void DoList(CommandSource &source, ChannelInfo *ci, const Anope::string &word)
{
bool override = !source.AccessFor(ci).HasPriv("BADWORDS");
@@ -200,23 +205,24 @@ class CommandBSBadwords : public Command
}
else if (!word.empty() && word.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class BadwordsListCallback : public NumberList
+ class BadwordsListCallback final
+ : public NumberList
{
ListFormatter &list;
BadWords *bw;
- public:
+ public:
BadwordsListCallback(ListFormatter &_list, BadWords *_bw, const Anope::string &numlist) : NumberList(numlist, false), list(_list), bw(_bw)
{
}
- void HandleNumber(unsigned Number) anope_override
+ void HandleNumber(unsigned Number) override
{
if (!Number || Number > bw->GetBadWordCount())
return;
const BadWord *b = bw->GetBadWord(Number - 1);
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(Number);
+ entry["Number"] = Anope::ToString(Number);
entry["Word"] = b->word;
entry["Type"] = b->type == BW_SINGLE ? "(SINGLE)" : (b->type == BW_START ? "(START)" : (b->type == BW_END ? "(END)" : ""));
this->list.AddEntry(entry);
@@ -235,7 +241,7 @@ class CommandBSBadwords : public Command
continue;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Word"] = b->word;
entry["Type"] = b->type == BW_SINGLE ? "(SINGLE)" : (b->type == BW_START ? "(START)" : (b->type == BW_END ? "(END)" : ""));
list.AddEntry(entry);
@@ -251,8 +257,8 @@ class CommandBSBadwords : public Command
source.Reply(_("Bad words list for %s:"), ci->name.c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of bad words list."));
}
@@ -364,7 +370,7 @@ class CommandBSBadwords : public Command
source.Reply(_("Bad words list is now empty."));
}
- public:
+public:
CommandBSBadwords(Module *creator) : Command(creator, "botserv/badwords", 2, 3)
{
this->SetDesc(_("Maintains the bad words list"));
@@ -374,7 +380,7 @@ class CommandBSBadwords : public Command
this->SetSyntax(_("\037channel\037 CLEAR"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[1];
const Anope::string &word = params.size() > 2 ? params[2] : "";
@@ -417,7 +423,7 @@ class CommandBSBadwords : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -453,13 +459,14 @@ class CommandBSBadwords : public Command
}
};
-class BSBadwords : public Module
+class BSBadwords final
+ : public Module
{
CommandBSBadwords commandbsbadwords;
ExtensibleItem<BadWordsImpl> badwords;
Serialize::Type badword_type;
- public:
+public:
BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandbsbadwords(this), badwords(this, "badwords"), badword_type("BadWord", BadWordImpl::Unserialize)
{
diff --git a/modules/commands/bs_bot.cpp b/modules/botserv/bs_bot.cpp
index a1fe901f9..5571a82c9 100644
--- a/modules/commands/bs_bot.cpp
+++ b/modules/botserv/bs_bot.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandBSBot : public Command
+class CommandBSBot final
+ : public Command
{
- private:
+private:
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
const Anope::string &nick = params[1];
@@ -27,23 +28,21 @@ class CommandBSBot : public Command
return;
}
- Configuration::Block *networkinfo = Config->GetBlock("networkinfo");
-
- if (nick.length() > networkinfo->Get<unsigned>("nicklen"))
+ if (nick.length() > IRCD->GetMaxNick())
{
- source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen"));
+ source.Reply(_("Bot nicks may only be %zu characters long."), IRCD->GetMaxNick());
return;
}
- if (user.length() > networkinfo->Get<unsigned>("userlen"))
+ if (user.length() > IRCD->GetMaxUser())
{
- source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen"));
+ source.Reply(_("Bot idents may only be %zu characters long."), IRCD->GetMaxUser());
return;
}
- if (host.length() > networkinfo->Get<unsigned>("hostlen"))
+ if (host.length() > IRCD->GetMaxHost())
{
- source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen"));
+ source.Reply(_("Bot hosts may only be %zu characters long."), IRCD->GetMaxHost());
return;
}
@@ -82,7 +81,7 @@ class CommandBSBot : public Command
return;
}
- BotInfo *bi = new BotInfo(nick, user, host, real);
+ auto *bi = new BotInfo(nick, user, host, real);
Log(LOG_ADMIN, source, this) << "ADD " << bi->GetMask() << " " << bi->realname;
@@ -119,23 +118,22 @@ class CommandBSBot : public Command
return;
}
- Configuration::Block *networkinfo = Config->GetBlock("networkinfo");
-
- if (nick.length() > networkinfo->Get<unsigned>("nicklen"))
+ if (nick.length() > IRCD->GetMaxNick())
{
- source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen"));
+ source.Reply(_("Bot nicks may only be %zu characters long."), IRCD->GetMaxNick());
return;
}
- if (user.length() > networkinfo->Get<unsigned>("userlen"))
+ if (user.length() > IRCD->GetMaxUser())
{
- source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen"));
+ source.Reply(_("Bot idents may only be %zu characters long."), IRCD->GetMaxUser());
return;
}
- if (host.length() > networkinfo->Get<unsigned>("hostlen"))
+ if (host.length() > IRCD->GetMaxHost())
{
- source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen"));
+ source.Reply(_("Bot hosts may only be %zu characters long."), IRCD->GetMaxHost()
+ );
return;
}
@@ -263,7 +261,7 @@ class CommandBSBot : public Command
delete bi;
return;
}
- public:
+public:
CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6)
{
this->SetDesc(_("Maintains network bot list"));
@@ -272,7 +270,7 @@ class CommandBSBot : public Command
this->SetSyntax(_("\002DEL \037nick\037\002"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
@@ -345,7 +343,7 @@ class CommandBSBot : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -370,11 +368,12 @@ class CommandBSBot : public Command
}
};
-class BSBot : public Module
+class BSBot final
+ : public Module
{
CommandBSBot commandbsbot;
- public:
+public:
BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandbsbot(this)
{
diff --git a/modules/commands/bs_botlist.cpp b/modules/botserv/bs_botlist.cpp
index aafa87464..915117916 100644
--- a/modules/commands/bs_botlist.cpp
+++ b/modules/botserv/bs_botlist.cpp
@@ -11,25 +11,24 @@
#include "module.h"
-class CommandBSBotList : public Command
+class CommandBSBotList final
+ : public Command
{
- public:
+public:
CommandBSBotList(Module *creator) : Command(creator, "botserv/botlist", 0, 0)
{
this->SetDesc(_("Lists available bots"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
unsigned count = 0;
ListFormatter list(source.GetAccount());
list.AddColumn(_("Nick")).AddColumn(_("Mask"));
- for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
+ for (const auto &[_, bi] : *BotListByNick)
{
- BotInfo *bi = it->second;
-
if (source.HasPriv("botserv/administration") || !bi->oper_only)
{
++count;
@@ -50,14 +49,14 @@ class CommandBSBotList : public Command
{
source.Reply(_("Bot list:"));
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("%d bots available."), count);
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -67,11 +66,12 @@ class CommandBSBotList : public Command
}
};
-class BSBotList : public Module
+class BSBotList final
+ : public Module
{
CommandBSBotList commandbsbotlist;
- public:
+public:
BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandbsbotlist(this)
{
diff --git a/modules/commands/bs_control.cpp b/modules/botserv/bs_control.cpp
index 4dd90f45a..32101be6e 100644
--- a/modules/commands/bs_control.cpp
+++ b/modules/botserv/bs_control.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandBSSay : public Command
+class CommandBSSay final
+ : public Command
{
- public:
+public:
CommandBSSay(Module *creator) : Command(creator, "botserv/say", 2, 2)
{
this->SetDesc(_("Makes the bot say the specified text on the specified channel"));
this->SetSyntax(_("\037channel\037 \037text\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &text = params[1];
@@ -62,7 +63,7 @@ class CommandBSSay : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << text;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -71,16 +72,17 @@ class CommandBSSay : public Command
}
};
-class CommandBSAct : public Command
+class CommandBSAct final
+ : public Command
{
- public:
+public:
CommandBSAct(Module *creator) : Command(creator, "botserv/act", 2, 2)
{
this->SetDesc(_("Makes the bot do the equivalent of a \"/me\" command"));
this->SetSyntax(_("\037channel\037 \037text\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string message = params[1];
@@ -120,7 +122,7 @@ class CommandBSAct : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << message;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -130,12 +132,13 @@ class CommandBSAct : public Command
}
};
-class BSControl : public Module
+class BSControl final
+ : public Module
{
CommandBSSay commandbssay;
CommandBSAct commandbsact;
- public:
+public:
BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandbssay(this), commandbsact(this)
{
diff --git a/modules/commands/bs_info.cpp b/modules/botserv/bs_info.cpp
index 3b83ddec4..b4a5592b1 100644
--- a/modules/commands/bs_info.cpp
+++ b/modules/botserv/bs_info.cpp
@@ -11,16 +11,15 @@
#include "module.h"
-class CommandBSInfo : public Command
+class CommandBSInfo final
+ : public Command
{
- private:
- void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi)
+private:
+ static void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi)
{
Anope::string buf;
- for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
+ for (const auto &[_, ci] : *RegisteredChannelList)
{
- const ChannelInfo *ci = it->second;
-
if (ci->bi == bi)
{
buf += " " + ci->name + " ";
@@ -35,13 +34,13 @@ class CommandBSInfo : public Command
buffers.push_back(buf);
}
- public:
+public:
CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1)
{
this->SetSyntax(_("{\037channel\037 | \037nickname\037}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &query = params[0];
@@ -56,22 +55,22 @@ class CommandBSInfo : public Command
info[_("Real name")] = bi->realname;
info[_("Created")] = Anope::strftime(bi->created, source.GetAccount());
info[_("Options")] = bi->oper_only ? _("Private") : _("None");
- info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)";
+ info[_("Used on")] = Anope::ToString(bi->GetChannelCount()) + " channel(s)";
FOREACH_MOD(OnBotInfo, (source, bi, ci, info));
std::vector<Anope::string> replies;
info.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
if (source.HasPriv("botserv/administration"))
{
std::vector<Anope::string> buf;
this->send_bot_channels(buf, bi);
- for (unsigned i = 0; i < buf.size(); ++i)
- source.Reply(buf[i]);
+ for (const auto &line : buf)
+ source.Reply(line);
}
}
@@ -94,14 +93,14 @@ class CommandBSInfo : public Command
std::vector<Anope::string> replies;
info.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
else
source.Reply(_("\002%s\002 is not a valid bot or registered channel."), query.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -113,17 +112,18 @@ class CommandBSInfo : public Command
return true;
}
- const Anope::string GetDesc(CommandSource &source) const anope_override
+ const Anope::string GetDesc(CommandSource &source) const override
{
return Anope::printf(Language::Translate(source.GetAccount(), _("Allows you to see %s information about a channel or a bot")), source.service->nick.c_str());
}
};
-class BSInfo : public Module
+class BSInfo final
+ : public Module
{
CommandBSInfo commandbsinfo;
- public:
+public:
BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandbsinfo(this)
{
diff --git a/modules/commands/bs_kick.cpp b/modules/botserv/bs_kick.cpp
index 185fdaa9c..9183eae22 100644
--- a/modules/commands/bs_kick.cpp
+++ b/modules/botserv/bs_kick.cpp
@@ -15,13 +15,14 @@
static Module *me;
-struct KickerDataImpl : KickerData
+struct KickerDataImpl final
+ : KickerData
{
KickerDataImpl(Extensible *obj)
{
amsgs = badwords = bolds = caps = colors = flood = italics = repeat = reverses = underlines = false;
- for (int16_t i = 0; i < TTB_SIZE; ++i)
- ttb[i] = 0;
+ for (auto &ttbtype : ttb)
+ ttbtype = 0;
capsmin = capspercent = 0;
floodlines = floodsecs = 0;
repeattimes = 0;
@@ -29,7 +30,7 @@ struct KickerDataImpl : KickerData
dontkickops = dontkickvoices = false;
}
- void Check(ChannelInfo *ci) anope_override
+ void Check(ChannelInfo *ci) override
{
if (amsgs || badwords || bolds || caps || colors || flood || italics || repeat || reverses || underlines || dontkickops || dontkickvoices)
return;
@@ -37,11 +38,12 @@ struct KickerDataImpl : KickerData
ci->Shrink<KickerData>("kickerdata");
}
- struct ExtensibleItem : ::ExtensibleItem<KickerDataImpl>
+ struct ExtensibleItem final
+ : ::ExtensibleItem<KickerDataImpl>
{
ExtensibleItem(Module *m, const Anope::string &ename) : ::ExtensibleItem<KickerDataImpl>(m, ename) { }
- void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
+ void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
{
if (s->GetSerializableType()->GetName() != "ChannelInfo")
return;
@@ -69,11 +71,11 @@ struct KickerDataImpl : KickerData
data.SetType("repeattimes", Serialize::Data::DT_INT); data["repeattimes"] << kd->repeattimes;
data.SetType("dontkickops", Serialize::Data::DT_INT); data["dontkickops"] << kd->dontkickops;
data.SetType("dontkickvoices", Serialize::Data::DT_INT); data["dontkickvoices"] << kd->dontkickvoices;
- for (int16_t i = 0; i < TTB_SIZE; ++i)
- data["ttb"] << kd->ttb[i] << " ";
+ for (auto ttbtype : kd->ttb)
+ data["ttb"] << ttbtype << " ";
}
- void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
+ void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
{
if (s->GetSerializableType()->GetName() != "ChannelInfo")
return;
@@ -104,43 +106,40 @@ struct KickerDataImpl : KickerData
data["ttb"] >> ttb;
spacesepstream sep(ttb);
for (int i = 0; sep.GetToken(tok) && i < TTB_SIZE; ++i)
- try
- {
- kd->ttb[i] = convertTo<int16_t>(tok);
- }
- catch (const ConvertException &) { }
+ {
+ if (auto n = Anope::TryConvert<int16_t>(tok))
+ kd->ttb[i] = n.value();
+ }
kd->Check(ci);
}
};
};
-class CommandBSKick : public Command
+class CommandBSKick final
+ : public Command
{
- public:
+public:
CommandBSKick(Module *creator) : Command(creator, "botserv/kick", 0)
{
this->SetDesc(_("Configures kickers"));
this->SetSyntax(_("\037option\037 \037channel\037 {\037ON|OFF\037} [\037settings\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Configures bot kickers. \037option\037 can be one of:"));
Anope::string this_name = source.command;
- for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it)
+ for (const auto &[c_name, info] : source.service->commands)
{
- const Anope::string &c_name = it->first;
- const CommandInfo &info = it->second;
-
if (c_name.find_ci(this_name + " ") == 0)
{
ServiceReference<Command> command("Command", info.name);
@@ -162,19 +161,20 @@ class CommandBSKick : public Command
}
};
-class CommandBSKickBase : public Command
+class CommandBSKickBase
+ : public Command
{
- public:
+public:
CommandBSKickBase(Module *creator, const Anope::string &cname, int minarg, int maxarg) : Command(creator, cname, minarg, maxarg)
{
}
- virtual void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override = 0;
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override = 0;
- virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override = 0;
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override = 0;
- protected:
- bool CheckArguments(CommandSource &source, const std::vector<Anope::string> &params, ChannelInfo* &ci)
+protected:
+ bool CheckArguments(CommandSource &source, const std::vector<Anope::string> &params, ChannelInfo *&ci)
{
const Anope::string &chan = params[0];
const Anope::string &option = params[1];
@@ -205,21 +205,13 @@ class CommandBSKickBase : public Command
{
if (!ttb.empty())
{
- int16_t i;
-
- try
- {
- i = convertTo<int16_t>(ttb);
- if (i < 0)
- throw ConvertException();
- }
- catch (const ConvertException &)
+ kd->ttb[ttb_idx] = Anope::Convert<int16_t>(ttb, -1);
+ if (kd->ttb[ttb_idx] < 0)
{
+ kd->ttb[ttb_idx] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return;
}
-
- kd->ttb[ttb_idx] = i;
}
else
kd->ttb[ttb_idx] = 0;
@@ -247,16 +239,17 @@ class CommandBSKickBase : public Command
}
};
-class CommandBSKickAMSG : public CommandBSKickBase
+class CommandBSKickAMSG final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickAMSG(Module *creator) : CommandBSKickBase(creator, "botserv/kick/amsg", 2, 3)
{
this->SetDesc(_("Configures AMSG kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (CheckArguments(source, params, ci))
@@ -267,7 +260,7 @@ class CommandBSKickAMSG : public CommandBSKickBase
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -283,16 +276,17 @@ class CommandBSKickAMSG : public CommandBSKickBase
}
};
-class CommandBSKickBadwords : public CommandBSKickBase
+class CommandBSKickBadwords final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickBadwords(Module *creator) : CommandBSKickBase(creator, "botserv/kick/badwords", 2, 3)
{
this->SetDesc(_("Configures badwords kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (CheckArguments(source, params, ci))
@@ -304,7 +298,7 @@ class CommandBSKickBadwords : public CommandBSKickBase
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -322,16 +316,17 @@ class CommandBSKickBadwords : public CommandBSKickBase
}
};
-class CommandBSKickBolds : public CommandBSKickBase
+class CommandBSKickBolds final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickBolds(Module *creator) : CommandBSKickBase(creator, "botserv/kick/bolds", 2, 3)
{
this->SetDesc(_("Configures bolds kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (CheckArguments(source, params, ci))
@@ -342,7 +337,7 @@ class CommandBSKickBolds : public CommandBSKickBase
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -356,16 +351,17 @@ class CommandBSKickBolds : public CommandBSKickBase
}
};
-class CommandBSKickCaps : public CommandBSKickBase
+class CommandBSKickCaps final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickCaps(Module *creator) : CommandBSKickBase(creator, "botserv/kick/caps", 2, 5)
{
this->SetDesc(_("Configures caps kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037 [\037min\037 [\037percent\037]]]\002"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (!CheckArguments(source, params, ci))
@@ -381,13 +377,8 @@ class CommandBSKickCaps : public CommandBSKickBase
if (!ttb.empty())
{
- try
- {
- kd->ttb[TTB_CAPS] = convertTo<int16_t>(ttb);
- if (kd->ttb[TTB_CAPS] < 0)
- throw ConvertException();
- }
- catch (const ConvertException &)
+ kd->ttb[TTB_CAPS] = Anope::Convert<int16_t>(ttb, -1);
+ if (kd->ttb[TTB_CAPS] < 0)
{
kd->ttb[TTB_CAPS] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
@@ -397,21 +388,11 @@ class CommandBSKickCaps : public CommandBSKickBase
else
kd->ttb[TTB_CAPS] = 0;
- kd->capsmin = 10;
- try
- {
- kd->capsmin = convertTo<int16_t>(min);
- }
- catch (const ConvertException &) { }
+ kd->capsmin = Anope::Convert(min, 0);
if (kd->capsmin < 1)
kd->capsmin = 10;
- kd->capspercent = 25;
- try
- {
- kd->capspercent = convertTo<int16_t>(percent);
- }
- catch (const ConvertException &) { }
+ kd->capspercent = Anope::Convert(percent, 0);
if (kd->capspercent < 1 || kd->capspercent > 100)
kd->capspercent = 25;
@@ -433,7 +414,7 @@ class CommandBSKickCaps : public CommandBSKickBase
kd->Check(ci);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -452,16 +433,17 @@ class CommandBSKickCaps : public CommandBSKickBase
}
};
-class CommandBSKickColors : public CommandBSKickBase
+class CommandBSKickColors final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickColors(Module *creator) : CommandBSKickBase(creator, "botserv/kick/colors", 2, 3)
{
this->SetDesc(_("Configures color kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (CheckArguments(source, params, ci))
@@ -472,7 +454,7 @@ class CommandBSKickColors : public CommandBSKickBase
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -486,16 +468,17 @@ class CommandBSKickColors : public CommandBSKickBase
}
};
-class CommandBSKickFlood : public CommandBSKickBase
+class CommandBSKickFlood final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickFlood(Module *creator) : CommandBSKickBase(creator, "botserv/kick/flood", 2, 5)
{
this->SetDesc(_("Configures flood kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037 [\037ln\037 [\037secs\037]]]\002"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (!CheckArguments(source, params, ci))
@@ -511,42 +494,25 @@ class CommandBSKickFlood : public CommandBSKickBase
if (!ttb.empty())
{
- int16_t i;
-
- try
- {
- i = convertTo<int16_t>(ttb);
- if (i < 0)
- throw ConvertException();
- }
- catch (const ConvertException &)
+ kd->ttb[TTB_FLOOD] = Anope::Convert<int16_t>(ttb, -1);
+ if (kd->ttb[TTB_FLOOD] < 0)
{
+ kd->ttb[TTB_FLOOD] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return;
}
-
- kd->ttb[TTB_FLOOD] = i;
}
else
kd->ttb[TTB_FLOOD] = 0;
- kd->floodlines = 6;
- try
- {
- kd->floodlines = convertTo<int16_t>(lines);
- }
- catch (const ConvertException &) { }
+ kd->floodlines = Anope::Convert(lines, -1);
if (kd->floodlines < 2)
kd->floodlines = 6;
- kd->floodsecs = 10;
- try
- {
- kd->floodsecs = convertTo<int16_t>(secs);
- }
- catch (const ConvertException &) { }
+ kd->floodsecs = Anope::Convert(secs, -1);
if (kd->floodsecs < 1)
kd->floodsecs = 10;
+
if (kd->floodsecs > Config->GetModule(me)->Get<time_t>("keepdata"))
kd->floodsecs = Config->GetModule(me)->Get<time_t>("keepdata");
@@ -568,7 +534,7 @@ class CommandBSKickFlood : public CommandBSKickBase
kd->Check(ci);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -584,16 +550,17 @@ class CommandBSKickFlood : public CommandBSKickBase
}
};
-class CommandBSKickItalics : public CommandBSKickBase
+class CommandBSKickItalics final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickItalics(Module *creator) : CommandBSKickBase(creator, "botserv/kick/italics", 2, 3)
{
this->SetDesc(_("Configures italics kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (CheckArguments(source, params, ci))
@@ -604,7 +571,7 @@ class CommandBSKickItalics : public CommandBSKickBase
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -618,16 +585,17 @@ class CommandBSKickItalics : public CommandBSKickBase
}
};
-class CommandBSKickRepeat : public CommandBSKickBase
+class CommandBSKickRepeat final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickRepeat(Module *creator) : CommandBSKickBase(creator, "botserv/kick/repeat", 2, 4)
{
this->SetDesc(_("Configures repeat kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037 [\037num\037]]\002"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (!CheckArguments(source, params, ci))
@@ -642,31 +610,18 @@ class CommandBSKickRepeat : public CommandBSKickBase
if (!ttb.empty())
{
- int16_t i;
-
- try
- {
- i = convertTo<int16_t>(ttb);
- if (i < 0)
- throw ConvertException();
- }
- catch (const ConvertException &)
+ kd->ttb[TTB_REPEAT] = Anope::Convert(ttb, -1);
+ if (kd->ttb[TTB_REPEAT] < 0)
{
+ kd->ttb[TTB_REPEAT] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return;
}
-
- kd->ttb[TTB_REPEAT] = i;
}
else
kd->ttb[TTB_REPEAT] = 0;
- kd->repeattimes = 3;
- try
- {
- kd->repeattimes = convertTo<int16_t>(times);
- }
- catch (const ConvertException &) { }
+ kd->repeattimes = Anope::Convert<int16_t>(times, -1);
if (kd->repeattimes < 1)
kd->repeattimes = 3;
@@ -703,7 +658,7 @@ class CommandBSKickRepeat : public CommandBSKickBase
kd->Check(ci);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -719,16 +674,17 @@ class CommandBSKickRepeat : public CommandBSKickBase
}
};
-class CommandBSKickReverses : public CommandBSKickBase
+class CommandBSKickReverses final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickReverses(Module *creator) : CommandBSKickBase(creator, "botserv/kick/reverses", 2, 3)
{
this->SetDesc(_("Configures reverses kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (CheckArguments(source, params, ci))
@@ -739,7 +695,7 @@ class CommandBSKickReverses : public CommandBSKickBase
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -753,16 +709,17 @@ class CommandBSKickReverses : public CommandBSKickBase
}
};
-class CommandBSKickUnderlines : public CommandBSKickBase
+class CommandBSKickUnderlines final
+ : public CommandBSKickBase
{
- public:
+public:
CommandBSKickUnderlines(Module *creator) : CommandBSKickBase(creator, "botserv/kick/underlines", 2, 3)
{
this->SetDesc(_("Configures underlines kicker"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci;
if (CheckArguments(source, params, ci))
@@ -773,7 +730,7 @@ class CommandBSKickUnderlines : public CommandBSKickBase
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -787,16 +744,17 @@ class CommandBSKickUnderlines : public CommandBSKickBase
}
};
-class CommandBSSetDontKickOps : public Command
+class CommandBSSetDontKickOps final
+ : public Command
{
- public:
+public:
CommandBSSetDontKickOps(Module *creator, const Anope::string &sname = "botserv/set/dontkickops") : Command(creator, sname, 2, 2)
{
this->SetDesc(_("To protect ops against bot kicks"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
if (ci == NULL)
@@ -841,7 +799,7 @@ class CommandBSSetDontKickOps : public Command
kd->Check(ci);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -852,16 +810,17 @@ class CommandBSSetDontKickOps : public Command
}
};
-class CommandBSSetDontKickVoices : public Command
+class CommandBSSetDontKickVoices final
+ : public Command
{
- public:
+public:
CommandBSSetDontKickVoices(Module *creator, const Anope::string &sname = "botserv/set/dontkickvoices") : Command(creator, sname, 2, 2)
{
this->SetDesc(_("To protect voices against bot kicks"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
if (ci == NULL)
@@ -906,7 +865,7 @@ class CommandBSSetDontKickVoices : public Command
kd->Check(ci);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -917,9 +876,9 @@ class CommandBSSetDontKickVoices : public Command
}
};
-struct BanData
+struct BanData final
{
- struct Data
+ struct Data final
{
Anope::string mask;
time_t last_use;
@@ -928,16 +887,16 @@ struct BanData
Data()
{
last_use = 0;
- for (int i = 0; i < TTB_SIZE; ++i)
- this->ttb[i] = 0;
+ for (auto &ttbtype : this->ttb)
+ ttbtype = 0;
}
};
- private:
+private:
typedef Anope::map<Data> data_type;
data_type data_map;
- public:
+public:
BanData(Extensible *) { }
Data &get(const Anope::string &key)
@@ -965,7 +924,7 @@ struct BanData
}
};
-struct UserData
+struct UserData final
{
UserData(Extensible *)
{
@@ -988,19 +947,21 @@ struct UserData
Anope::string lastline;
};
-class BanDataPurger : public Timer
+class BanDataPurger final
+ : public Timer
{
- public:
- BanDataPurger(Module *o) : Timer(o, 300, Anope::CurTime, true) { }
+public:
+ BanDataPurger(Module *o)
+ : Timer(o, 300, true)
+ {
+ }
- void Tick(time_t) anope_override
+ void Tick() override
{
Log(LOG_DEBUG) << "bs_main: Running bandata purger";
- for (channel_map::iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
+ for (auto &[_, c] : ChannelList)
{
- Channel *c = it->second;
-
BanData *bd = c->GetExt<BanData>("bandata");
if (bd != NULL)
{
@@ -1012,7 +973,8 @@ class BanDataPurger : public Timer
}
};
-class BSKick : public Module
+class BSKick final
+ : public Module
{
ExtensibleItem<BanData> bandata;
ExtensibleItem<UserData> userdata;
@@ -1049,7 +1011,7 @@ class BSKick : public Module
UserData *ud = userdata.Require(uc);
return ud;
- }
+ }
void check_ban(ChannelInfo *ci, User *u, KickerData *kd, int ttbtype)
{
@@ -1075,7 +1037,7 @@ class BSKick : public Module
}
}
- void bot_kick(ChannelInfo *ci, User *u, const char *message, ...)
+ static void bot_kick(ChannelInfo *ci, User *u, const char *message, ...) ATTR_FORMAT(3, 4)
{
va_list args;
char buf[1024];
@@ -1088,10 +1050,10 @@ class BSKick : public Module
vsnprintf(buf, sizeof(buf), fmt.c_str(), args);
va_end(args);
- ci->c->Kick(ci->bi, u, "%s", buf);
+ ci->c->Kick(ci->bi, u, Anope::string(buf));
}
- public:
+public:
BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
bandata(this, "bandata"),
userdata(this, "userdata"),
@@ -1110,7 +1072,7 @@ class BSKick : public Module
}
- void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) anope_override
+ void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) override
{
if (!ci)
return;
@@ -1225,7 +1187,7 @@ class BSKick : public Module
info.AddOption(_("Voices protection"));
}
- void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_override
+ void OnPrivmsg(User *u, Channel *c, Anope::string &msg, const Anope::map<Anope::string> &tags) override
{
/* Now we can make kicker stuff. We try to order the checks
* from the fastest one to the slowest one, since there's
@@ -1308,11 +1270,11 @@ class BSKick : public Module
{
int i = 0, l = 0;
- for (unsigned j = 0, end = realbuf.length(); j < end; ++j)
+ for (auto chr : realbuf)
{
- if (isupper(realbuf[j]))
+ if (isupper(chr))
++i;
- else if (islower(realbuf[j]))
+ else if (islower(chr))
++l;
}
diff --git a/modules/commands/bs_set.cpp b/modules/botserv/bs_set.cpp
index cb7b296a7..3bf8184e4 100644
--- a/modules/commands/bs_set.cpp
+++ b/modules/botserv/bs_set.cpp
@@ -11,21 +11,22 @@
#include "module.h"
-class CommandBSSet : public Command
+class CommandBSSet final
+ : public Command
{
- public:
+public:
CommandBSSet(Module *creator) : Command(creator, "botserv/set", 3, 3)
{
this->SetDesc(_("Configures bot options"));
this->SetSyntax(_("\037option\037 \037(channel | bot)\037 \037settings\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -35,10 +36,8 @@ class CommandBSSet : public Command
bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"),
hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands");
Anope::string this_name = source.command;
- for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it)
+ for (const auto &[c_name, info] : source.service->commands)
{
- const Anope::string &c_name = it->first;
- const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
if (info.hide)
@@ -54,7 +53,7 @@ class CommandBSSet : public Command
if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission))
continue;
- source.command = it->first;
+ source.command = c_name;
command->OnServHelp(source);
}
}
@@ -66,18 +65,25 @@ class CommandBSSet : public Command
}
};
-class CommandBSSetBanExpire : public Command
+class CommandBSSetBanExpire final
+ : public Command
{
- public:
- class UnbanTimer : public Timer
+public:
+ class UnbanTimer final
+ : public Timer
{
Anope::string chname;
Anope::string mask;
- public:
- UnbanTimer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t) : Timer(creator, t), chname(ch), mask(bmask) { }
+ public:
+ UnbanTimer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t)
+ : Timer(creator, t)
+ , chname(ch)
+ , mask(bmask)
+ {
+ }
- void Tick(time_t) anope_override
+ void Tick() override
{
Channel *c = Channel::Find(chname);
if (c)
@@ -91,7 +97,7 @@ class CommandBSSetBanExpire : public Command
this->SetSyntax(_("\037channel\037 \037time\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
const Anope::string &arg = params[1];
@@ -141,7 +147,7 @@ class CommandBSSetBanExpire : public Command
source.Reply(_("Bot bans will automatically expire after %s."), Anope::Duration(ci->banexpire, source.GetAccount()).c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -153,16 +159,17 @@ class CommandBSSetBanExpire : public Command
}
};
-class CommandBSSetPrivate : public Command
+class CommandBSSetPrivate final
+ : public Command
{
- public:
+public:
CommandBSSetPrivate(Module *creator, const Anope::string &sname = "botserv/set/private") : Command(creator, sname, 2, 2)
{
this->SetDesc(_("Prevent a bot from being assigned by non IRC operators"));
this->SetSyntax(_("\037botname\037 {\037ON|OFF\037}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
BotInfo *bi = BotInfo::Find(params[0], true);
const Anope::string &value = params[1];
@@ -193,7 +200,7 @@ class CommandBSSetPrivate : public Command
this->OnSyntaxError(source, source.command);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -203,20 +210,21 @@ class CommandBSSetPrivate : public Command
}
};
-class BSSet : public Module
+class BSSet final
+ : public Module
{
CommandBSSet commandbsset;
CommandBSSetBanExpire commandbssetbanexpire;
CommandBSSetPrivate commandbssetprivate;
- public:
+public:
BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandbsset(this), commandbssetbanexpire(this),
commandbssetprivate(this)
{
}
- void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) anope_override
+ void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) override
{
if (!ci->banexpire)
return;
diff --git a/modules/pseudoclients/chanserv.cpp b/modules/chanserv/chanserv.cpp
index e89af3def..f04b69dab 100644
--- a/modules/pseudoclients/chanserv.cpp
+++ b/modules/chanserv/chanserv.cpp
@@ -19,36 +19,43 @@ inline static Anope::string BotModes()
);
}
-class ChanServCore : public Module, public ChanServService
+class ChanServCore final
+ : public Module
+ , public ChanServService
{
Reference<BotInfo> ChanServ;
std::vector<Anope::string> defaults;
ExtensibleItem<bool> inhabit;
ExtensibleRef<bool> persist;
- bool always_lower;
+ bool always_lower = false;
- public:
+public:
ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
- ChanServService(this), inhabit(this, "inhabit"), persist("PERSIST"), always_lower(false)
+ ChanServService(this), inhabit(this, "inhabit"), persist("PERSIST")
{
}
- void Hold(Channel *c) anope_override
+ void Hold(Channel *c) override
{
/** A timer used to keep the BotServ bot/ChanServ in the channel
* after kicking the last user in a channel
*/
- class ChanServTimer : public Timer
+ class ChanServTimer final
+ : public Timer
{
Reference<BotInfo> &ChanServ;
ExtensibleItem<bool> &inhabit;
Reference<Channel> c;
- public:
+ public:
/** Constructor
* @param chan The channel
*/
- ChanServTimer(Reference<BotInfo> &cs, ExtensibleItem<bool> &i, Module *m, Channel *chan) : Timer(m, Config->GetModule(m)->Get<time_t>("inhabit", "15s")), ChanServ(cs), inhabit(i), c(chan)
+ ChanServTimer(Reference<BotInfo> &cs, ExtensibleItem<bool> &i, Module *m, Channel *chan)
+ : Timer(m, Config->GetModule(m)->Get<time_t>("inhabit", "1m"))
+ , ChanServ(cs)
+ , inhabit(i)
+ , c(chan)
{
if (!ChanServ || !c)
return;
@@ -68,7 +75,7 @@ class ChanServCore : public Module, public ChanServService
/** Called when the delay is up
* @param The current time
*/
- void Tick(time_t) anope_override
+ void Tick() override
{
if (!c)
return;
@@ -96,7 +103,7 @@ class ChanServCore : public Module, public ChanServService
new ChanServTimer(ChanServ, inhabit, this->owner, c);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
const Anope::string &channick = conf->GetModule(this)->Get<const Anope::string>("client");
@@ -109,14 +116,13 @@ class ChanServCore : public Module, public ChanServService
ChanServ = bi;
- spacesepstream(conf->GetModule(this)->Get<const Anope::string>("defaults", "keeptopic peace cs_secure securefounder signkick")).GetTokens(defaults);
+ spacesepstream(conf->GetModule(this)->Get<const Anope::string>("defaults", "keeptopic peace securefounder signkick")).GetTokens(defaults);
if (defaults.empty())
{
- defaults.push_back("KEEPTOPIC");
- defaults.push_back("PEACE");
- defaults.push_back("CS_SECURE");
- defaults.push_back("SECUREFOUNDER");
- defaults.push_back("SIGNKICK");
+ defaults.emplace_back("KEEPTOPIC");
+ defaults.emplace_back("PEACE");
+ defaults.emplace_back("SECUREFOUNDER");
+ defaults.emplace_back("SIGNKICK");
}
else if (defaults[0].equals_ci("none"))
defaults.clear();
@@ -124,13 +130,13 @@ class ChanServCore : public Module, public ChanServService
always_lower = conf->GetModule(this)->Get<bool>("always_lower_ts");
}
- void OnBotDelete(BotInfo *bi) anope_override
+ void OnBotDelete(BotInfo *bi) override
{
if (bi == ChanServ)
ChanServ = NULL;
}
- EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) anope_override
+ EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message, const Anope::map<Anope::string> &tags) override
{
if (bi == ChanServ && Config->GetModule(this)->Get<bool>("opersonly") && !u->HasMode("OPER"))
{
@@ -141,16 +147,14 @@ class ChanServCore : public Module, public ChanServService
return EVENT_CONTINUE;
}
- void OnDelCore(NickCore *nc) anope_override
+ void OnDelCore(NickCore *nc) override
{
std::deque<ChannelInfo *> chans;
nc->GetChannelReferences(chans);
int max_reg = Config->GetModule(this)->Get<int>("maxregistered");
- for (unsigned i = 0; i < chans.size(); ++i)
+ for (auto *ci : chans)
{
- ChannelInfo *ci = chans[i];
-
if (ci->GetFounder() == nc)
{
NickCore *newowner = NULL;
@@ -214,16 +218,16 @@ class ChanServCore : public Module, public ChanServService
}
}
- void OnDelChan(ChannelInfo *ci) anope_override
+ void OnDelChan(ChannelInfo *ci) override
{
/* remove access entries that are this channel */
std::deque<Anope::string> chans;
ci->GetChannelReferences(chans);
- for (unsigned i = 0; i < chans.size(); ++i)
+ for (const auto &chan : chans)
{
- ChannelInfo *c = ChannelInfo::Find(chans[i]);
+ ChannelInfo *c = ChannelInfo::Find(chan);
if (!c)
continue;
@@ -249,7 +253,7 @@ class ChanServCore : public Module, public ChanServService
}
}
- EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *ChanServ)
return EVENT_CONTINUE;
@@ -260,20 +264,20 @@ class ChanServCore : public Module, public ChanServService
"commands are listed below; to use them, type\n"
"\002%s%s \037command\037\002. For more information on a\n"
"specific command, type \002%s%s HELP \037command\037\002.\n"),
- ChanServ->nick.c_str(), ChanServ->nick.c_str(), Config->StrictPrivmsg.c_str(), ChanServ->nick.c_str(), Config->StrictPrivmsg.c_str(), ChanServ->nick.c_str(), ChanServ->nick.c_str(), source.command.c_str());
+ ChanServ->nick.c_str(), ChanServ->nick.c_str(), Config->StrictPrivmsg.c_str(), ChanServ->nick.c_str(), Config->StrictPrivmsg.c_str(), ChanServ->nick.c_str());
return EVENT_CONTINUE;
}
- void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *ChanServ)
return;
- time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "14d");
+ time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "30d");
if (chanserv_expire >= 86400)
source.Reply(_(" \n"
- "Note that any channel which is not used for %d days\n"
+ "Note that any channel which is not used for %lu days\n"
"(i.e. which no user on the channel's access list enters\n"
- "for that period of time) will be automatically dropped."), chanserv_expire / 86400);
+ "for that period of time) will be automatically dropped."), (unsigned long)chanserv_expire / 86400);
if (source.IsServicesOper())
source.Reply(_(" \n"
"Services Operators can also, depending on their access drop\n"
@@ -281,7 +285,7 @@ class ChanServCore : public Module, public ChanServService
"lists and settings for any channel."));
}
- void OnCheckModes(Reference<Channel> &c) anope_override
+ void OnCheckModes(Reference<Channel> &c) override
{
if (!c)
return;
@@ -301,14 +305,14 @@ class ChanServCore : public Module, public ChanServService
}
}
- void OnCreateChan(ChannelInfo *ci) anope_override
+ void OnCreateChan(ChannelInfo *ci) override
{
/* Set default chan flags */
- for (unsigned i = 0; i < defaults.size(); ++i)
- ci->Extend<bool>(defaults[i].upper());
+ for (const auto &def : defaults)
+ ci->Extend<bool>(def.upper());
}
- EventReturn OnCanSet(User *u, const ChannelMode *cm) anope_override
+ EventReturn OnCanSet(User *u, const ChannelMode *cm) override
{
if (Config->GetModule(this)->Get<const Anope::string>("nomlock").find(cm->mchar) != Anope::string::npos
|| Config->GetModule(this)->Get<const Anope::string>("require").find(cm->mchar) != Anope::string::npos)
@@ -316,7 +320,7 @@ class ChanServCore : public Module, public ChanServService
return EVENT_CONTINUE;
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
bool perm = c->HasMode("PERM") || (c->ci && persist && persist->HasExt(c->ci));
if (!perm && !c->botchannel && (c->users.empty() || (c->users.size() == 1 && c->users.begin()->second->user->server == Me)))
@@ -325,15 +329,15 @@ class ChanServCore : public Module, public ChanServService
}
}
- void OnLog(Log *l) anope_override
+ void OnLog(Log *l) override
{
if (l->type == LOG_CHANNEL)
l->bi = ChanServ;
}
- void OnExpireTick() anope_override
+ void OnExpireTick() override
{
- time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "14d");
+ time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "30d");
if (!chanserv_expire || Anope::NoExpire || Anope::ReadOnly)
return;
@@ -369,7 +373,7 @@ class ChanServCore : public Module, public ChanServService
}
}
- EventReturn OnCheckDelete(Channel *c) anope_override
+ EventReturn OnCheckDelete(Channel *c) override
{
/* Do not delete this channel if ChanServ/a BotServ bot is inhabiting it */
if (inhabit.HasExt(c))
@@ -378,7 +382,7 @@ class ChanServCore : public Module, public ChanServService
return EVENT_CONTINUE;
}
- void OnPostInit() anope_override
+ void OnPostInit() override
{
if (!persist)
return;
@@ -386,9 +390,8 @@ class ChanServCore : public Module, public ChanServService
ChannelMode *perm = ModeManager::FindChannelModeByName("PERM");
/* Find all persistent channels and create them, as we are about to finish burst to our uplink */
- for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
+ for (const auto &[_, ci] : *RegisteredChannelList)
{
- ChannelInfo *ci = it->second;
if (!persist->HasExt(ci))
continue;
@@ -414,7 +417,7 @@ class ChanServCore : public Module, public ChanServService
}
- void OnChanRegistered(ChannelInfo *ci) anope_override
+ void OnChanRegistered(ChannelInfo *ci) override
{
if (!persist || !ci->c)
return;
@@ -426,7 +429,7 @@ class ChanServCore : public Module, public ChanServService
ci->c->SetMode(NULL, "PERM");
}
- void OnJoinChannel(User *u, Channel *c) anope_override
+ void OnJoinChannel(User *u, Channel *c) override
{
if (always_lower && c->ci && c->creation_time > c->ci->time_registered)
{
@@ -437,7 +440,7 @@ class ChanServCore : public Module, public ChanServService
}
}
- EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) override
{
if (!always_lower && Anope::CurTime == c->creation_time && c->ci && setter.GetUser() && !setter.GetUser()->server->IsULined())
{
@@ -456,17 +459,17 @@ class ChanServCore : public Module, public ChanServService
return EVENT_CONTINUE;
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override
{
if (!show_all)
return;
- time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "14d");
+ time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "30d");
if (!ci->HasExt("CS_NO_EXPIRE") && chanserv_expire && !Anope::NoExpire && ci->last_used != Anope::CurTime)
info[_("Expires")] = Anope::strftime(ci->last_used + chanserv_expire, source.GetAccount());
}
- void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) anope_override
+ void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override
{
if (always_lower)
// Since we always lower the TS, the other side will remove the modes if the channel ts lowers, so we don't
diff --git a/modules/commands/cs_access.cpp b/modules/chanserv/cs_access.cpp
index 0b5f7254f..f86d9f5bc 100644
--- a/modules/commands/cs_access.cpp
+++ b/modules/chanserv/cs_access.cpp
@@ -16,41 +16,37 @@ static std::map<Anope::string, int16_t, ci::less> defaultLevels;
static inline void reset_levels(ChannelInfo *ci)
{
ci->ClearLevels();
- for (std::map<Anope::string, int16_t, ci::less>::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it)
- ci->SetLevel(it->first, it->second);
+ for (auto &[priv, level] : defaultLevels)
+ ci->SetLevel(priv, level);
}
-class AccessChanAccess : public ChanAccess
+class AccessChanAccess final
+ : public ChanAccess
{
- public:
- int level;
+public:
+ int level = 0;
- AccessChanAccess(AccessProvider *p) : ChanAccess(p), level(0)
+ AccessChanAccess(AccessProvider *p) : ChanAccess(p)
{
}
- bool HasPriv(const Anope::string &name) const anope_override
+ bool HasPriv(const Anope::string &name) const override
{
return this->ci->GetLevel(name) != ACCESS_INVALID && this->level >= this->ci->GetLevel(name);
}
- Anope::string AccessSerialize() const anope_override
+ Anope::string AccessSerialize() const override
{
- return stringify(this->level);
+ return Anope::ToString(this->level);
}
- void AccessUnserialize(const Anope::string &data) anope_override
+ void AccessUnserialize(const Anope::string &data) override
{
- try
- {
- this->level = convertTo<int>(data);
- }
- catch (const ConvertException &)
- {
- }
+ if (auto l = Anope::TryConvert<int>(data))
+ this->level = l.value();
}
- bool operator>(const ChanAccess &other) const anope_override
+ bool operator>(const ChanAccess &other) const override
{
if (this->provider != other.provider)
return ChanAccess::operator>(other);
@@ -58,7 +54,7 @@ class AccessChanAccess : public ChanAccess
return this->level > anope_dynamic_static_cast<const AccessChanAccess *>(&other)->level;
}
- bool operator<(const ChanAccess &other) const anope_override
+ bool operator<(const ChanAccess &other) const override
{
if (this->provider != other.provider)
return ChanAccess::operator<(other);
@@ -67,9 +63,10 @@ class AccessChanAccess : public ChanAccess
}
};
-class AccessAccessProvider : public AccessProvider
+class AccessAccessProvider final
+ : public AccessProvider
{
- public:
+public:
static AccessAccessProvider *me;
AccessAccessProvider(Module *o) : AccessProvider(o, "access/access")
@@ -77,14 +74,15 @@ class AccessAccessProvider : public AccessProvider
me = this;
}
- ChanAccess *Create() anope_override
+ ChanAccess *Create() override
{
return new AccessChanAccess(this);
}
};
-AccessAccessProvider* AccessAccessProvider::me;
+AccessAccessProvider *AccessAccessProvider::me;
-class CommandCSAccess : public Command
+class CommandCSAccess final
+ : public Command
{
void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
@@ -92,11 +90,9 @@ class CommandCSAccess : public Command
Privilege *p = NULL;
int level = ACCESS_INVALID;
- try
- {
- level = convertTo<int>(params[3]);
- }
- catch (const ConvertException &)
+ if (auto lvl = Anope::TryConvert<int>(params[3]))
+ level = lvl.value();
+ else
{
p = PrivilegeManager::FindPrivilege(params[3]);
if (p != NULL && defaultLevels[p->name])
@@ -166,6 +162,12 @@ class CommandCSAccess : public Command
source.Reply(_("Masks and unregistered users may not be on access lists."));
return;
}
+ else if (na && na->nc->HasExt("NEVEROP"))
+ {
+ source.Reply(_("\002%s\002 does not wish to be added to channel access lists."),
+ na->nc->display.c_str());
+ return;
+ }
else if (mask.find_first_of("!*@") == Anope::string::npos && !na)
{
User *targ = User::Find(mask, true);
@@ -214,6 +216,7 @@ class CommandCSAccess : public Command
access->level = level;
access->last_seen = 0;
access->created = Anope::CurTime;
+ access->description = params.size() > 4 ? params[4] : "";
ci->AddAccess(access);
FOREACH_MOD(OnAccessAdd, (ci, source, access));
@@ -250,23 +253,24 @@ class CommandCSAccess : public Command
source.Reply(_("%s access list is empty."), ci->name.c_str());
else if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class AccessDelCallback : public NumberList
+ class AccessDelCallback final
+ : public NumberList
{
CommandSource &source;
ChannelInfo *ci;
Command *c;
- unsigned deleted;
+ unsigned deleted = 0;
Anope::string Nicks;
- bool denied;
- bool override;
- public:
- AccessDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), deleted(0), denied(false), override(false)
+ bool denied = false;
+ bool override = false;
+ public:
+ AccessDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c)
{
if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/access/modify"))
this->override = true;
}
- ~AccessDelCallback()
+ ~AccessDelCallback() override
{
if (denied && !deleted)
source.Reply(ACCESS_DENIED);
@@ -283,7 +287,7 @@ class CommandCSAccess : public Command
}
}
- void HandleNumber(unsigned Number) anope_override
+ void HandleNumber(unsigned Number) override
{
if (!Number || Number > ci->GetAccessCount())
return;
@@ -354,17 +358,18 @@ class CommandCSAccess : public Command
source.Reply(_("%s access list is empty."), ci->name.c_str());
else if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class AccessListCallback : public NumberList
+ class AccessListCallback final
+ : public NumberList
{
ListFormatter &list;
ChannelInfo *ci;
- public:
+ public:
AccessListCallback(ListFormatter &_list, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), list(_list), ci(_ci)
{
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > ci->GetAccessCount())
return;
@@ -373,12 +378,14 @@ class CommandCSAccess : public Command
Anope::string timebuf;
if (ci->c)
- for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
+ {
+ for (const auto &[_, cuc] : ci->c->users)
{
ChannelInfo *p;
- if (access->Matches(cit->second->user, cit->second->user->Account(), p))
+ if (access->Matches(cuc->user, cuc->user->Account(), p))
timebuf = "Now";
}
+ }
if (timebuf.empty())
{
if (access->last_seen == 0)
@@ -388,11 +395,12 @@ class CommandCSAccess : public Command
}
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(number);
+ entry["Number"] = Anope::ToString(number);
entry["Level"] = access->AccessSerialize();
entry["Mask"] = access->Mask();
entry["By"] = access->creator;
entry["Last seen"] = timebuf;
+ entry["Description"] = access->description;
this->list.AddEntry(entry);
}
}
@@ -410,12 +418,14 @@ class CommandCSAccess : public Command
Anope::string timebuf;
if (ci->c)
- for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
+ {
+ for (auto &[_, cuc] : ci->c->users)
{
ChannelInfo *p;
- if (access->Matches(cit->second->user, cit->second->user->Account(), p))
+ if (access->Matches(cuc->user, cuc->user->Account(), p))
timebuf = "Now";
}
+ }
if (timebuf.empty())
{
if (access->last_seen == 0)
@@ -425,11 +435,12 @@ class CommandCSAccess : public Command
}
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Level"] = access->AccessSerialize();
entry["Mask"] = access->Mask();
entry["By"] = access->creator;
entry["Last seen"] = timebuf;
+ entry["Description"] = access->description;
list.AddEntry(entry);
}
}
@@ -443,8 +454,8 @@ class CommandCSAccess : public Command
source.Reply(_("Access list for %s:"), ci->name.c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of access list"));
}
@@ -461,7 +472,7 @@ class CommandCSAccess : public Command
}
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask"));
+ list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")).AddColumn(_("Description"));
this->ProcessList(source, ci, params, list);
}
@@ -474,7 +485,7 @@ class CommandCSAccess : public Command
}
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")).AddColumn(_("By")).AddColumn(_("Last seen"));
+ list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")).AddColumn(_("By")).AddColumn(_("Last seen")).AddColumn(_("Description"));
this->ProcessList(source, ci, params, list);
}
@@ -497,18 +508,18 @@ class CommandCSAccess : public Command
return;
}
- public:
- CommandCSAccess(Module *creator) : Command(creator, "chanserv/access", 2, 4)
+public:
+ CommandCSAccess(Module *creator) : Command(creator, "chanserv/access", 2, 5)
{
this->SetDesc(_("Modify the list of privileged users"));
- this->SetSyntax(_("\037channel\037 ADD \037mask\037 \037level\037"));
+ this->SetSyntax(_("\037channel\037 ADD \037mask\037 \037level\037 [\037description\037]"));
this->SetSyntax(_("\037channel\037 DEL {\037mask\037 | \037entry-num\037 | \037list\037}"));
this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | \037list\037]"));
this->SetSyntax(_("\037channel\037 VIEW [\037mask\037 | \037list\037]"));
this->SetSyntax(_("\037channel\037 CLEAR"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[1];
const Anope::string &nick = params.size() > 2 ? params[2] : "";
@@ -566,7 +577,7 @@ class CommandCSAccess : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -620,7 +631,8 @@ class CommandCSAccess : public Command
}
};
-class CommandCSLevels : public Command
+class CommandCSLevels final
+ : public Command
{
void DoSet(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
@@ -633,11 +645,9 @@ class CommandCSLevels : public Command
level = ACCESS_FOUNDER;
else
{
- try
- {
- level = convertTo<int>(lev);
- }
- catch (const ConvertException &)
+ if (auto lvl = Anope::TryConvert<int>(lev))
+ level = lvl.value();
+ else
{
this->OnSyntaxError(source, "SET");
return;
@@ -694,7 +704,7 @@ class CommandCSLevels : public Command
source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS\002 for a list of valid settings."), what.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str());
}
- void DoList(CommandSource &source, ChannelInfo *ci)
+ static void DoList(CommandSource &source, ChannelInfo *ci)
{
source.Reply(_("Access level settings for channel %s:"), ci->name.c_str());
@@ -703,9 +713,8 @@ class CommandCSLevels : public Command
const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
- for (unsigned i = 0; i < privs.size(); ++i)
+ for (const auto &p : privs)
{
- const Privilege &p = privs[i];
int16_t j = ci->GetLevel(p.name);
ListFormatter::ListEntry entry;
@@ -716,7 +725,7 @@ class CommandCSLevels : public Command
else if (j == ACCESS_FOUNDER)
entry["Level"] = Language::Translate(source.GetAccount(), _("(founder only)"));
else
- entry["Level"] = stringify(j);
+ entry["Level"] = Anope::ToString(j);
list.AddEntry(entry);
}
@@ -724,8 +733,8 @@ class CommandCSLevels : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
void DoReset(CommandSource &source, ChannelInfo *ci)
@@ -740,7 +749,7 @@ class CommandCSLevels : public Command
return;
}
- public:
+public:
CommandCSLevels(Module *creator) : Command(creator, "chanserv/levels", 2, 4)
{
this->SetDesc(_("Redefine the meanings of access levels"));
@@ -750,7 +759,7 @@ class CommandCSLevels : public Command
this->SetSyntax(_("\037channel\037 RESET"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[1];
const Anope::string &what = params.size() > 2 ? params[2] : "";
@@ -794,7 +803,7 @@ class CommandCSLevels : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (subcommand.equals_ci("DESC"))
{
@@ -803,10 +812,8 @@ class CommandCSLevels : public Command
ListFormatter list(source.GetAccount());
list.AddColumn(_("Name")).AddColumn(_("Description"));
- const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
- for (unsigned i = 0; i < privs.size(); ++i)
+ for (const auto &p : PrivilegeManager::GetPrivileges())
{
- const Privilege &p = privs[i];
ListFormatter::ListEntry entry;
entry["Name"] = p.name;
entry["Description"] = Language::Translate(source.nc, p.desc.c_str());
@@ -816,8 +823,8 @@ class CommandCSLevels : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
else
{
@@ -847,13 +854,14 @@ class CommandCSLevels : public Command
}
};
-class CSAccess : public Module
+class CSAccess final
+ : public Module
{
AccessAccessProvider accessprovider;
CommandCSAccess commandcsaccess;
CommandCSLevels commandcslevels;
- public:
+public:
CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
accessprovider(this), commandcsaccess(this), commandcslevels(this)
{
@@ -861,7 +869,7 @@ class CSAccess : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
defaultLevels.clear();
@@ -887,12 +895,12 @@ class CSAccess : public Module
}
}
- void OnCreateChan(ChannelInfo *ci) anope_override
+ void OnCreateChan(ChannelInfo *ci) override
{
reset_levels(ci);
}
- EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) anope_override
+ EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) override
{
if (group->ci == NULL)
return EVENT_CONTINUE;
diff --git a/modules/commands/cs_akick.cpp b/modules/chanserv/cs_akick.cpp
index 0cc677310..35052e63d 100644
--- a/modules/commands/cs_akick.cpp
+++ b/modules/chanserv/cs_akick.cpp
@@ -11,7 +11,8 @@
#include "module.h"
-class CommandCSAKick : public Command
+class CommandCSAKick final
+ : public Command
{
void Enforce(CommandSource &source, ChannelInfo *ci)
{
@@ -96,10 +97,9 @@ class CommandCSAKick : public Command
/* Check excepts BEFORE we get this far */
if (ci->c)
{
- std::vector<Anope::string> modes = ci->c->GetModeList("EXCEPT");
- for (unsigned int i = 0; i < modes.size(); ++i)
+ for (const auto &mode : ci->c->GetModeList("EXCEPT"))
{
- if (Anope::Match(modes[i], mask))
+ if (Anope::Match(mode, mask))
{
source.Reply(CHAN_EXCEPTED, mask.c_str(), ci->name.c_str());
return;
@@ -129,10 +129,8 @@ class CommandCSAKick : public Command
{
/* Match against all currently online users with equal or
* higher access. - Viper */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, u2] : UserListByNick)
{
- User *u2 = it->second;
-
AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci);
Entry entry_mask("", mask);
@@ -145,9 +143,9 @@ class CommandCSAKick : public Command
/* Match against the lastusermask of all nickalias's with equal
* or higher access. - Viper */
- for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
+ for (const auto &[_, na2] : *NickAliasList)
{
- na = it->second;
+ na = na2;
AccessGroup nc_access = ci->AccessFor(na->nc), u_access = source.AccessFor(ci);
if (na->nc && (na->nc == ci->GetFounder() || nc_access >= u_access))
@@ -206,19 +204,20 @@ class CommandCSAKick : public Command
/* Special case: is it a number/list? Only do search if it isn't. */
if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class AkickDelCallback : public NumberList
+ class AkickDelCallback final
+ : public NumberList
{
CommandSource &source;
ChannelInfo *ci;
Command *c;
- unsigned deleted;
+ unsigned deleted = 0;
AccessGroup ag;
- public:
- AkickDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), deleted(0), ag(source.AccessFor(ci))
+ public:
+ AkickDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), ag(source.AccessFor(ci))
{
}
- ~AkickDelCallback()
+ ~AkickDelCallback() override
{
if (!deleted)
source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str());
@@ -228,7 +227,7 @@ class CommandCSAKick : public Command
source.Reply(_("Deleted %d entries from %s autokick list."), deleted, ci->name.c_str());
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > ci->GetAkickCount())
return;
@@ -283,17 +282,18 @@ class CommandCSAKick : public Command
if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class AkickListCallback : public NumberList
+ class AkickListCallback final
+ : public NumberList
{
ListFormatter &list;
ChannelInfo *ci;
- public:
+ public:
AkickListCallback(ListFormatter &_list, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), list(_list), ci(_ci)
{
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > ci->GetAkickCount())
return;
@@ -311,7 +311,7 @@ class CommandCSAKick : public Command
lastused = UNKNOWN;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(number);
+ entry["Number"] = Anope::ToString(number);
if (akick->nc)
entry["Mask"] = akick->nc->display;
else
@@ -351,7 +351,7 @@ class CommandCSAKick : public Command
lastused = UNKNOWN;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
if (akick->nc)
entry["Mask"] = akick->nc->display;
else
@@ -373,8 +373,8 @@ class CommandCSAKick : public Command
source.Reply(_("Autokick list for %s:"), ci->name.c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of autokick list"));
}
@@ -428,7 +428,7 @@ class CommandCSAKick : public Command
source.Reply(_("Channel %s akick list has been cleared."), ci->name.c_str());
}
- public:
+public:
CommandCSAKick(Module *creator) : Command(creator, "chanserv/akick", 2, 4)
{
this->SetDesc(_("Maintain the AutoKick list"));
@@ -440,7 +440,7 @@ class CommandCSAKick : public Command
this->SetSyntax(_("\037channel\037 CLEAR"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string chan = params[0];
Anope::string cmd = params[1];
@@ -485,7 +485,7 @@ class CommandCSAKick : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
BotInfo *bi = Config->GetClient("NickServ");
this->SendSyntax(source);
@@ -528,17 +528,18 @@ class CommandCSAKick : public Command
}
};
-class CSAKick : public Module
+class CSAKick final
+ : public Module
{
CommandCSAKick commandcsakick;
- public:
+public:
CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsakick(this)
{
}
- EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_override
+ EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
{
if (!c->ci || c->MatchesList(u, "EXCEPT"))
return EVENT_CONTINUE;
diff --git a/modules/commands/cs_ban.cpp b/modules/chanserv/cs_ban.cpp
index dcbb401ac..d400631ab 100644
--- a/modules/commands/cs_ban.cpp
+++ b/modules/chanserv/cs_ban.cpp
@@ -13,17 +13,24 @@
static Module *me;
-class TempBan : public Timer
+class TempBan final
+ : public Timer
{
- private:
+private:
Anope::string channel;
Anope::string mask;
Anope::string mode;
- public:
- TempBan(time_t seconds, Channel *c, const Anope::string &banmask, const Anope::string &mod) : Timer(me, seconds), channel(c->name), mask(banmask), mode(mod) { }
+public:
+ TempBan(time_t seconds, Channel *c, const Anope::string &banmask, const Anope::string &mod)
+ : Timer(me, seconds)
+ , channel(c->name)
+ , mask(banmask)
+ , mode(mod)
+ {
+ }
- void Tick(time_t ctime) anope_override
+ void Tick() override
{
Channel *c = Channel::Find(this->channel);
if (c)
@@ -31,16 +38,17 @@ class TempBan : public Timer
}
};
-class CommandCSBan : public Command
+class CommandCSBan final
+ : public Command
{
- public:
+public:
CommandCSBan(Module *creator) : Command(creator, "chanserv/ban", 2, 4)
{
this->SetDesc(_("Bans a given nick or mask on a channel"));
this->SetSyntax(_("\037channel\037 [+\037expiry\037] {\037nick\037 | \037mask\037} [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Configuration::Block *block = Config->GetCommand(source);
const Anope::string &mode = block->Get<Anope::string>("mode", "BAN");
@@ -153,10 +161,10 @@ class CommandCSBan : public Command
if (ci->HasExt("SIGNKICK") || (ci->HasExt("SIGNKICK_LEVEL") && !source.AccessFor(ci).HasPriv("SIGNKICK")))
{
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), u2, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), u2, signkickformat);
}
else
- c->Kick(ci->WhoSends(), u2, "%s", reason.c_str());
+ c->Kick(ci->WhoSends(), u2, reason);
}
}
}
@@ -208,7 +216,7 @@ class CommandCSBan : public Command
{
reason += " (Matches " + mask + ")";
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), uc->user, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), uc->user, signkickformat);
}
else
c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
@@ -223,7 +231,7 @@ class CommandCSBan : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -237,11 +245,12 @@ class CommandCSBan : public Command
}
};
-class CSBan : public Module
+class CSBan final
+ : public Module
{
CommandCSBan commandcsban;
- public:
+public:
CSBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsban(this)
{
me = this;
diff --git a/modules/commands/cs_clone.cpp b/modules/chanserv/cs_clone.cpp
index 1e80787da..ec8096fe9 100644
--- a/modules/commands/cs_clone.cpp
+++ b/modules/chanserv/cs_clone.cpp
@@ -12,18 +12,19 @@
#include "module.h"
#include "modules/bs_badwords.h"
-class CommandCSClone : public Command
+class CommandCSClone final
+ : public Command
{
- void CopySetting(ChannelInfo *ci, ChannelInfo *target_ci, const Anope::string &setting)
+ static void CopySetting(ChannelInfo *ci, ChannelInfo *target_ci, const Anope::string &setting)
{
if (ci->HasExt(setting))
target_ci->Extend<bool>(setting);
}
- void CopyAccess(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
+ static void CopyAccess(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
{
std::set<Anope::string> masks;
- unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
+ unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1000");
unsigned count = 0;
for (unsigned i = 0; i < target_ci->GetAccessCount(); ++i)
@@ -44,6 +45,7 @@ class CommandCSClone : public Command
ChanAccess *newaccess = provider->Create();
newaccess->SetMask(taccess->Mask(), target_ci);
newaccess->creator = taccess->creator;
+ newaccess->description = taccess->description;
newaccess->last_seen = taccess->last_seen;
newaccess->created = taccess->created;
newaccess->AccessUnserialize(taccess->AccessSerialize());
@@ -56,7 +58,7 @@ class CommandCSClone : public Command
source.Reply(_("%d access entries from \002%s\002 have been cloned to \002%s\002."), count, ci->name.c_str(), target_ci->name.c_str());
}
- void CopyAkick(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
+ static void CopyAkick(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
{
target_ci->ClearAkick();
for (unsigned i = 0; i < ci->GetAkickCount(); ++i)
@@ -71,7 +73,7 @@ class CommandCSClone : public Command
source.Reply(_("All akick entries from \002%s\002 have been cloned to \002%s\002."), ci->name.c_str(), target_ci->name.c_str());
}
- void CopyBadwords(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
+ static void CopyBadwords(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
{
BadWords *target_badwords = target_ci->Require<BadWords>("badwords"),
*badwords = ci->Require<BadWords>("badwords");
@@ -96,13 +98,11 @@ class CommandCSClone : public Command
source.Reply(_("All badword entries from \002%s\002 have been cloned to \002%s\002."), ci->name.c_str(), target_ci->name.c_str());
}
- void CopyLevels(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
+ static void CopyLevels(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
{
- const Anope::map<int16_t> &cilevels = ci->GetLevelEntries();
-
- for (Anope::map<int16_t>::const_iterator it = cilevels.begin(); it != cilevels.end(); ++it)
+ for (const auto &[priv, level] : ci->GetLevelEntries())
{
- target_ci->SetLevel(it->first, it->second);
+ target_ci->SetLevel(priv, level);
}
source.Reply(_("All level entries from \002%s\002 have been cloned into \002%s\002."), ci->name.c_str(), target_ci->name.c_str());
@@ -115,7 +115,7 @@ public:
this->SetSyntax(_("\037channel\037 \037target\037 [\037what\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &channel = params[0];
const Anope::string &target = params[1];
@@ -196,10 +196,10 @@ public:
target_ci->last_topic_setter = source.service->nick;
const Anope::string settings[] = { "NOAUTOOP", "CS_KEEP_MODES", "PEACE", "PERSIST", "RESTRICTED",
- "CS_SECURE", "SECUREFOUNDER", "SECUREOPS", "SIGNKICK", "SIGNKICK_LEVEL", "CS_NO_EXPIRE" };
+ "SECUREFOUNDER", "SECUREOPS", "SIGNKICK", "SIGNKICK_LEVEL", "CS_NO_EXPIRE" };
- for (unsigned int i = 0; i < sizeof(settings) / sizeof(Anope::string); ++i)
- CopySetting(ci, target_ci, settings[i]);
+ for (const auto &setting : settings)
+ CopySetting(ci, target_ci, setting);
CopyAccess(source, ci, target_ci);
CopyAkick(source, ci, target_ci);
@@ -235,7 +235,7 @@ public:
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clone " << (what.empty() ? "everything from it" : what) << " to " << target_ci->name;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -247,11 +247,12 @@ public:
}
};
-class CSClone : public Module
+class CSClone final
+ : public Module
{
CommandCSClone commandcsclone;
- public:
+public:
CSClone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsclone(this)
{
diff --git a/modules/commands/cs_drop.cpp b/modules/chanserv/cs_drop.cpp
index 2982a0d08..cfeeddbdb 100644
--- a/modules/commands/cs_drop.cpp
+++ b/modules/chanserv/cs_drop.cpp
@@ -11,16 +11,22 @@
#include "module.h"
-class CommandCSDrop : public Command
+class CommandCSDrop final
+ : public Command
{
- public:
- CommandCSDrop(Module *creator) : Command(creator, "chanserv/drop", 1, 2)
+private:
+ PrimitiveExtensibleItem<Anope::string> dropcode;
+
+public:
+ CommandCSDrop(Module *creator)
+ : Command(creator, "chanserv/drop", 1, 2)
+ , dropcode(creator, "channel-dropcode")
{
this->SetDesc(_("Cancel the registration of a channel"));
- this->SetSyntax(_("\037channel\037 \037channel\037"));
+ this->SetSyntax(_("\037channel\037 [\037code\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
@@ -37,22 +43,32 @@ class CommandCSDrop : public Command
return;
}
- if (params.size() < 2 || !chan.equals_ci(params[1]))
+ if ((ci->HasExt("SECUREFOUNDER") ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER")) && !source.HasCommand("chanserv/drop"))
{
- source.Reply(_("You must enter the channel name twice as a confirmation that you wish to drop \002%s\002."), chan.c_str());
+ source.Reply(ACCESS_DENIED);
return;
}
- if ((ci->HasExt("SECUREFOUNDER") ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER")) && !source.HasCommand("chanserv/drop"))
+ auto *code = dropcode.Get(ci);
+ if (params.size() < 2 || !code || !code->equals_ci(params[1]))
{
- source.Reply(ACCESS_DENIED);
+ if (!code)
+ {
+ code = ci->Extend<Anope::string>("channel-dropcode");
+ *code = Anope::Random(15);
+ }
+
+ source.Reply(CONFIRM_DROP, ci->name.c_str(), ci->name.c_str(), code->c_str());
return;
}
EventReturn MOD_RESULT;
FOREACH_RESULT(OnChanDrop, MOD_RESULT, (source, ci));
if (MOD_RESULT == EVENT_STOP)
+ {
+ dropcode.Unset(ci);
return;
+ }
bool override = (ci->HasExt("SECUREFOUNDER") ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER"));
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "(founder was: " << (ci->GetFounder() ? ci->GetFounder()->display : "none") << ")";
@@ -66,7 +82,7 @@ class CommandCSDrop : public Command
c->CheckModes();
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -81,11 +97,12 @@ class CommandCSDrop : public Command
}
};
-class CSDrop : public Module
+class CSDrop final
+ : public Module
{
CommandCSDrop commandcsdrop;
- public:
+public:
CSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsdrop(this)
{
diff --git a/modules/commands/cs_enforce.cpp b/modules/chanserv/cs_enforce.cpp
index 3a16561d5..3c0a464ef 100644
--- a/modules/commands/cs_enforce.cpp
+++ b/modules/chanserv/cs_enforce.cpp
@@ -13,9 +13,10 @@
#include "module.h"
-class CommandCSEnforce : public Command
+class CommandCSEnforce final
+ : public Command
{
- private:
+private:
void DoSecureOps(CommandSource &source, ChannelInfo *ci)
{
bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify");
@@ -29,10 +30,8 @@ class CommandCSEnforce : public Command
bool hadsecureops = ci->HasExt("SECUREOPS");
ci->Extend<bool>("SECUREOPS");
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : ci->c->users)
{
- ChanUserContainer *uc = it->second;
-
ci->c->SetCorrectModes(uc->user, false);
}
@@ -48,9 +47,9 @@ class CommandCSEnforce : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce restricted";
std::vector<User *> users;
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+
+ for (const auto &[_, uc] : ci->c->users)
{
- ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
@@ -60,14 +59,12 @@ class CommandCSEnforce : public Command
users.push_back(user);
}
- for (unsigned i = 0; i < users.size(); ++i)
+ for (auto *user : users)
{
- User *user = users[i];
-
Anope::string mask = ci->GetIdealBan(user);
Anope::string reason = Language::Translate(user, _("RESTRICTED enforced by ")) + source.GetNick();
ci->c->SetMode(NULL, "BAN", mask);
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("Restricted enforced on %s."), ci->name.c_str());
@@ -79,9 +76,8 @@ class CommandCSEnforce : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce registered only";
std::vector<User *> users;
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : ci->c->users)
{
- ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
@@ -91,15 +87,13 @@ class CommandCSEnforce : public Command
users.push_back(user);
}
- for (unsigned i = 0; i < users.size(); ++i)
+ for (auto *user : users)
{
- User *user = users[i];
-
Anope::string mask = ci->GetIdealBan(user);
Anope::string reason = Language::Translate(user, _("REGONLY enforced by ")) + source.GetNick();
if (!ci->c->HasMode("REGISTEREDONLY"))
ci->c->SetMode(NULL, "BAN", mask);
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("Registered only enforced on %s."), ci->name.c_str());
@@ -111,27 +105,24 @@ class CommandCSEnforce : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce SSL only";
std::vector<User *> users;
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ for (auto &[_, uc] : ci->c->users)
{
- ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
continue;
- if (!user->HasMode("SSL") && !user->HasExt("ssl"))
+ if (!user->IsSecurelyConnected())
users.push_back(user);
}
- for (unsigned i = 0; i < users.size(); ++i)
+ for (auto *user : users)
{
- User *user = users[i];
-
Anope::string mask = ci->GetIdealBan(user);
Anope::string reason = Language::Translate(user, _("SSLONLY enforced by ")) + source.GetNick();
if (!ci->c->HasMode("SSL"))
ci->c->SetMode(NULL, "BAN", mask);
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("SSL only enforced on %s."), ci->name.c_str());
@@ -143,9 +134,8 @@ class CommandCSEnforce : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce bans";
std::vector<User *> users;
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : ci->c->users)
{
- ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
@@ -155,12 +145,10 @@ class CommandCSEnforce : public Command
users.push_back(user);
}
- for (unsigned i = 0; i < users.size(); ++i)
+ for (auto *user : users)
{
- User *user = users[i];
-
Anope::string reason = Language::Translate(user, _("BANS enforced by ")) + source.GetNick();
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("Bans enforced on %s."), ci->name.c_str());
@@ -178,14 +166,8 @@ class CommandCSEnforce : public Command
return;
}
- int l;
- try
- {
- l = convertTo<int>(l_str);
- if (l < 0)
- throw ConvertException();
- }
- catch (const ConvertException &)
+ auto l = Anope::Convert<int>(l_str, -1);
+ if (l < 0)
{
source.Reply(_("The limit on %s is not valid."), ci->name.c_str());
return;
@@ -210,25 +192,23 @@ class CommandCSEnforce : public Command
users.push_back(user);
}
- for (unsigned i = 0; i < users.size(); ++i)
+ for (auto *user : users)
{
- User *user = users[i];
-
Anope::string reason = Language::Translate(user, _("LIMIT enforced by ")) + source.GetNick();
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
- source.Reply(_("LIMIT enforced on %s, %d users removed."), ci->name.c_str(), users.size());
+ source.Reply(_("LIMIT enforced on %s, %zu users removed."), ci->name.c_str(), users.size());
}
- public:
+public:
CommandCSEnforce(Module *creator) : Command(creator, "chanserv/enforce", 2, 2)
{
this->SetDesc(_("Enforce various channel modes and set options"));
this->SetSyntax(_("\037channel\037 \037what\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &what = params.size() > 1 ? params[1] : "";
@@ -256,7 +236,7 @@ class CommandCSEnforce : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -277,11 +257,12 @@ class CommandCSEnforce : public Command
}
};
-class CSEnforce : public Module
+class CSEnforce final
+ : public Module
{
CommandCSEnforce commandcsenforce;
- public:
+public:
CSEnforce(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsenforce(this)
{
diff --git a/modules/commands/cs_entrymsg.cpp b/modules/chanserv/cs_entrymsg.cpp
index 451d24cb3..efe13d1aa 100644
--- a/modules/commands/cs_entrymsg.cpp
+++ b/modules/chanserv/cs_entrymsg.cpp
@@ -12,7 +12,9 @@
#include "module.h"
#include "modules/cs_entrymsg.h"
-struct EntryMsgImpl : EntryMsg, Serializable
+struct EntryMsgImpl final
+ : EntryMsg
+ , Serializable
{
EntryMsgImpl() : Serializable("EntryMsg")
{
@@ -26,9 +28,9 @@ struct EntryMsgImpl : EntryMsg, Serializable
this->when = ct;
}
- ~EntryMsgImpl();
+ ~EntryMsgImpl() override;
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["ci"] << this->chan;
data["creator"] << this->creator;
@@ -36,14 +38,15 @@ struct EntryMsgImpl : EntryMsg, Serializable
data.SetType("when", Serialize::Data::DT_INT); data["when"] << this->when;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
-struct EntryMessageListImpl : EntryMessageList
+struct EntryMessageListImpl final
+ : EntryMessageList
{
EntryMessageListImpl(Extensible *) { }
- EntryMsg* Create() anope_override
+ EntryMsg *Create() override
{
return new EntryMsgImpl();
}
@@ -65,7 +68,7 @@ EntryMsgImpl::~EntryMsgImpl()
}
-Serializable* EntryMsgImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *EntryMsgImpl::Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string sci, screator, smessage;
time_t swhen;
@@ -92,15 +95,16 @@ Serializable* EntryMsgImpl::Unserialize(Serializable *obj, Serialize::Data &data
data["when"] >> swhen;
- EntryMsgImpl *m = new EntryMsgImpl(ci, screator, smessage, swhen);
+ auto *m = new EntryMsgImpl(ci, screator, smessage, swhen);
(*messages)->push_back(m);
return m;
}
-class CommandEntryMessage : public Command
+class CommandEntryMessage final
+ : public Command
{
- private:
- void DoList(CommandSource &source, ChannelInfo *ci)
+private:
+ static void DoList(CommandSource &source, ChannelInfo *ci)
{
EntryMessageList *messages = ci->Require<EntryMessageList>("entrymsg");
@@ -119,7 +123,7 @@ class CommandEntryMessage : public Command
EntryMsg *msg = (*messages)->at(i);
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Creator"] = msg->creator;
entry["Created"] = Anope::strftime(msg->when, NULL, true);
entry["Message"] = msg->message;
@@ -128,8 +132,8 @@ class CommandEntryMessage : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of entry message list."));
}
@@ -158,21 +162,16 @@ class CommandEntryMessage : public Command
source.Reply(_("Entry message list for \002%s\002 is empty."), ci->name.c_str());
else
{
- try
+ auto i = Anope::Convert<unsigned>(message, 0);
+ if (i > 0 && i <= (*messages)->size())
{
- unsigned i = convertTo<unsigned>(message);
- if (i > 0 && i <= (*messages)->size())
- {
- delete (*messages)->at(i - 1);
- if ((*messages)->empty())
- ci->Shrink<EntryMessageList>("entrymsg");
- Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove a message";
- source.Reply(_("Entry message \002%i\002 for \002%s\002 deleted."), i, ci->name.c_str());
- }
- else
- throw ConvertException();
+ delete (*messages)->at(i - 1);
+ if ((*messages)->empty())
+ ci->Shrink<EntryMessageList>("entrymsg");
+ Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove a message";
+ source.Reply(_("Entry message \002%i\002 for \002%s\002 deleted."), i, ci->name.c_str());
}
- catch (const ConvertException &)
+ else
{
source.Reply(_("Entry message \002%s\002 not found on channel \002%s\002."), message.c_str(), ci->name.c_str());
}
@@ -187,7 +186,7 @@ class CommandEntryMessage : public Command
source.Reply(_("Entry messages for \002%s\002 have been cleared."), ci->name.c_str());
}
- public:
+public:
CommandEntryMessage(Module *creator) : Command(creator, "chanserv/entrymsg", 2, 3)
{
this->SetDesc(_("Manage the channel's entry messages"));
@@ -197,7 +196,7 @@ class CommandEntryMessage : public Command
this->SetSyntax(_("\037channel\037 CLEAR"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
if (ci == NULL)
@@ -232,7 +231,7 @@ class CommandEntryMessage : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -260,28 +259,35 @@ class CommandEntryMessage : public Command
}
};
-class CSEntryMessage : public Module
+class CSEntryMessage final
+ : public Module
{
CommandEntryMessage commandentrymsg;
ExtensibleItem<EntryMessageListImpl> eml;
Serialize::Type entrymsg_type;
- public:
+public:
CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandentrymsg(this),
eml(this, "entrymsg"), entrymsg_type("EntryMsg", EntryMsgImpl::Unserialize)
{
}
- void OnJoinChannel(User *u, Channel *c) anope_override
+ void OnJoinChannel(User *u, Channel *c) override
{
if (u && c && c->ci && u->server->IsSynced())
{
EntryMessageList *messages = c->ci->GetExt<EntryMessageList>("entrymsg");
+ if (!messages)
+ return;
- if (messages != NULL)
- for (unsigned i = 0; i < (*messages)->size(); ++i)
- u->SendMessage(c->ci->WhoSends(), "[%s] %s", c->ci->name.c_str(), (*messages)->at(i)->message.c_str());
+ for (const auto &message : *(*messages))
+ {
+ if (u->ShouldPrivmsg())
+ IRCD->SendContextPrivmsg(c->ci->WhoSends(), u, c, message->message);
+ else
+ IRCD->SendContextNotice(c->ci->WhoSends(), u, c, message->message);
+ }
}
}
};
diff --git a/modules/extra/stats/cs_fantasy_stats.cpp b/modules/chanserv/cs_fantasy_stats.cpp
index c5a527a5f..516dd02b9 100644
--- a/modules/extra/stats/cs_fantasy_stats.cpp
+++ b/modules/chanserv/cs_fantasy_stats.cpp
@@ -12,16 +12,17 @@
#include "module.h"
#include "modules/sql.h"
-class MySQLInterface : public SQL::Interface
+class MySQLInterface final
+ : public SQL::Interface
{
- public:
+public:
MySQLInterface(Module *o) : SQL::Interface(o) { }
- void OnResult(const SQL::Result &r) anope_override
+ void OnResult(const SQL::Result &r) override
{
}
- void OnError(const SQL::Result &r) anope_override
+ void OnError(const SQL::Result &r) override
{
if (!r.GetQuery().query.empty())
Log(LOG_DEBUG) << "Chanstats: Error executing query " << r.finished_query << ": " << r.GetError();
@@ -31,9 +32,10 @@ class MySQLInterface : public SQL::Interface
};
-class CommandCSStats : public Command
+class CommandCSStats final
+ : public Command
{
- public:
+public:
CommandCSStats(Module *creator) : Command (creator, "chanserv/stats", 0, 2)
{
this->SetDesc(_("Displays your Channel Stats"));
@@ -43,9 +45,10 @@ class CommandCSStats : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params);
};
-class CommandCSGStats : public Command
+class CommandCSGStats final
+ : public Command
{
- public:
+public:
CommandCSGStats(Module *creator) : Command (creator, "chanserv/gstats", 0, 2)
{
this->SetDesc(_("Displays your Global Stats"));
@@ -58,14 +61,15 @@ class CommandCSGStats : public Command
class CSStats;
static CSStats *me;
-class CSStats : public Module
+class CSStats final
+ : public Module
{
CommandCSStats commandcsstats;
CommandCSGStats commandcsgstats;
ServiceReference<SQL::Provider> sql;
MySQLInterface sqlinterface;
Anope::string prefix;
- public:
+public:
CSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsstats(this), commandcsgstats(this), sql("", ""), sqlinterface(this)
{
@@ -73,16 +77,16 @@ class CSStats : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
- prefix = conf->GetModule("m_chanstats")->Get<const Anope::string>("prefix", "anope_");
- this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf->GetModule("m_chanstats")->Get<const Anope::string>("engine"));
+ prefix = conf->GetModule("chanstats")->Get<const Anope::string>("prefix", "anope_");
+ this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf->GetModule("chanstats")->Get<const Anope::string>("engine"));
}
SQL::Result RunQuery(const SQL::Query &query)
{
if (!this->sql)
- throw SQL::Exception("Unable to locate SQL reference, is m_mysql loaded and configured correctly?");
+ throw SQL::Exception("Unable to locate SQL reference, is mysql loaded and configured correctly?");
SQL::Result res = this->sql->RunQuery(query);
if (!res.GetError().empty())
diff --git a/modules/extra/stats/cs_fantasy_top.cpp b/modules/chanserv/cs_fantasy_top.cpp
index 69ed5b53c..3bc1fa261 100644
--- a/modules/extra/stats/cs_fantasy_top.cpp
+++ b/modules/chanserv/cs_fantasy_top.cpp
@@ -12,16 +12,17 @@
#include "module.h"
#include "modules/sql.h"
-class MySQLInterface : public SQL::Interface
+class MySQLInterface final
+ : public SQL::Interface
{
- public:
+public:
MySQLInterface(Module *o) : SQL::Interface(o) { }
- void OnResult(const SQL::Result &r) anope_override
+ void OnResult(const SQL::Result &r) override
{
}
- void OnError(const SQL::Result &r) anope_override
+ void OnError(const SQL::Result &r) override
{
if (!r.GetQuery().query.empty())
Log(LOG_DEBUG) << "Chanstats: Error executing query " << r.finished_query << ": " << r.GetError();
@@ -30,9 +31,10 @@ class MySQLInterface : public SQL::Interface
}
};
-class CommandCSTop : public Command
+class CommandCSTop final
+ : public Command
{
- public:
+public:
CommandCSTop(Module *creator) : Command (creator, "chanserv/top", 0, 2)
{
this->SetDesc(_("Displays the top 3 users of a channel"));
@@ -42,9 +44,10 @@ class CommandCSTop : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params);
};
-class CommandCSTop10 : public Command
+class CommandCSTop10 final
+ : public Command
{
- public:
+public:
CommandCSTop10(Module *creator) : Command (creator, "chanserv/top10", 0, 2)
{
this->SetDesc(_("Displays the top 10 users of a channel"));
@@ -54,9 +57,10 @@ class CommandCSTop10 : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params);
};
-class CommandCSGTop : public Command
+class CommandCSGTop final
+ : public Command
{
- public:
+public:
CommandCSGTop(Module *creator) : Command (creator, "chanserv/gtop", 0, 1)
{
this->SetDesc(_("Displays the top 3 users of the network"));
@@ -65,9 +69,10 @@ class CommandCSGTop : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params);
};
-class CommandCSGTop10 : public Command
+class CommandCSGTop10 final
+ : public Command
{
- public:
+public:
CommandCSGTop10(Module *creator) : Command (creator, "chanserv/gtop10", 0, 1)
{
this->SetDesc(_("Displays the top 10 users of the network"));
@@ -79,7 +84,8 @@ class CommandCSGTop10 : public Command
class CSTop;
static CSTop *me;
-class CSTop : public Module
+class CSTop final
+ : public Module
{
CommandCSTop commandcstop;
CommandCSGTop commandcsgtop;
@@ -89,7 +95,7 @@ class CSTop : public Module
MySQLInterface sqlinterface;
Anope::string prefix;
- public:
+public:
CSTop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcstop(this), commandcsgtop(this), commandcstop10(this), commandcsgtop10(this), sql("", ""),
sqlinterface(this)
@@ -98,16 +104,16 @@ class CSTop : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
- prefix = conf->GetModule("m_chanstats")->Get<const Anope::string>("prefix", "anope_");
- this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf->GetModule("m_chanstats")->Get<const Anope::string>("engine"));
+ prefix = conf->GetModule("chanstats")->Get<const Anope::string>("prefix", "anope_");
+ this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf->GetModule("chanstats")->Get<const Anope::string>("engine"));
}
SQL::Result RunQuery(const SQL::Query &query)
{
if (!this->sql)
- throw SQL::Exception("Unable to locate SQL reference, is m_mysql loaded and configured correctly?");
+ throw SQL::Exception("Unable to locate SQL reference, is mysql loaded and configured correctly?");
SQL::Result res = sql->RunQuery(query);
if (!res.GetError().empty())
@@ -149,7 +155,7 @@ class CSTop : public Module
source.Reply(_("Top %i of %s"), limit, (is_global ? "Network" : channel.c_str()));
for (int i = 0; i < res.Rows(); ++i)
{
- source.Reply(_("%2lu \002%-16s\002 letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"),
+ source.Reply(_("%2d \002%-16s\002 letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"),
i+1, res.Get(i, "nick").c_str(), res.Get(i, "letters").c_str(),
res.Get(i, "words").c_str(), res.Get(i, "line").c_str(),
res.Get(i, "smileys").c_str(), res.Get(i, "actions").c_str());
diff --git a/modules/commands/cs_flags.cpp b/modules/chanserv/cs_flags.cpp
index cbcb8eb38..7404aef57 100644
--- a/modules/commands/cs_flags.cpp
+++ b/modules/chanserv/cs_flags.cpp
@@ -13,29 +13,28 @@
static std::map<Anope::string, char> defaultFlags;
-class FlagsChanAccess : public ChanAccess
+class FlagsChanAccess final
+ : public ChanAccess
{
- public:
+public:
std::set<char> flags;
FlagsChanAccess(AccessProvider *p) : ChanAccess(p)
{
}
- bool HasPriv(const Anope::string &priv) const anope_override
+ bool HasPriv(const Anope::string &priv) const override
{
std::map<Anope::string, char>::iterator it = defaultFlags.find(priv);
- if (it != defaultFlags.end() && this->flags.count(it->second) > 0)
- return true;
- return false;
+ return it != defaultFlags.end() && this->flags.count(it->second) > 0;
}
- Anope::string AccessSerialize() const anope_override
+ Anope::string AccessSerialize() const override
{
return Anope::string(this->flags.begin(), this->flags.end());
}
- void AccessUnserialize(const Anope::string &data) anope_override
+ void AccessUnserialize(const Anope::string &data) override
{
for (unsigned i = data.length(); i > 0; --i)
this->flags.insert(data[i - 1]);
@@ -48,9 +47,9 @@ class FlagsChanAccess : public ChanAccess
std::set<char> buffer;
- for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it)
- if (access->HasPriv(it->first))
- buffer.insert(it->second);
+ for (auto &[priv, flag] : defaultFlags)
+ if (access->HasPriv(priv))
+ buffer.insert(flag);
if (buffer.empty())
return "(none)";
@@ -59,9 +58,10 @@ class FlagsChanAccess : public ChanAccess
}
};
-class FlagsAccessProvider : public AccessProvider
+class FlagsAccessProvider final
+ : public AccessProvider
{
- public:
+public:
static FlagsAccessProvider *ap;
FlagsAccessProvider(Module *o) : AccessProvider(o, "access/flags")
@@ -69,16 +69,17 @@ class FlagsAccessProvider : public AccessProvider
ap = this;
}
- ChanAccess *Create() anope_override
+ ChanAccess *Create() override
{
return new FlagsChanAccess(this);
}
};
-FlagsAccessProvider* FlagsAccessProvider::ap;
+FlagsAccessProvider *FlagsAccessProvider::ap;
-class CommandCSFlags : public Command
+class CommandCSFlags final
+ : public Command
{
- void DoModify(CommandSource &source, ChannelInfo *ci, Anope::string mask, const Anope::string &flags)
+ void DoModify(CommandSource &source, ChannelInfo *ci, Anope::string mask, const Anope::string &flags, const Anope::string &description)
{
if (flags.empty())
{
@@ -120,6 +121,12 @@ class CommandCSFlags : public Command
source.Reply(_("Masks and unregistered users may not be on access lists."));
return;
}
+ else if (na && na->nc->HasExt("NEVEROP"))
+ {
+ source.Reply(_("\002%s\002 does not wish to be added to channel access lists."),
+ na->nc->display.c_str());
+ return;
+ }
else if (mask.find_first_of("!*@") == Anope::string::npos && !na)
{
User *targ = User::Find(mask, true);
@@ -168,7 +175,7 @@ class CommandCSFlags : public Command
}
}
- unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
+ unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1000");
if (access_max && ci->GetDeepAccessCount() >= access_max)
{
source.Reply(_("Sorry, you can only have %d access entries on a channel, including access entries from other channels."), access_max);
@@ -189,14 +196,14 @@ class CommandCSFlags : public Command
add = false;
break;
case '*':
- for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it)
+ for (const auto &[priv, flag] : defaultFlags)
{
- bool has = current_flags.count(it->second);
+ bool has = current_flags.count(flag);
// If we are adding a flag they already have or removing one they don't have, don't bother
if (add == has)
continue;
- if (!u_access.HasPriv(it->first) && !u_access.founder)
+ if (!u_access.HasPriv(priv) && !u_access.founder)
{
if (source.HasPriv("chanserv/access/modify"))
override = true;
@@ -205,9 +212,9 @@ class CommandCSFlags : public Command
}
if (add)
- current_flags.insert(it->second);
+ current_flags.insert(flag);
else
- current_flags.erase(it->second);
+ current_flags.erase(flag);
}
break;
default:
@@ -218,11 +225,11 @@ class CommandCSFlags : public Command
i = flags.length();
}
- for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it)
+ for (const auto &[priv, flag] : defaultFlags)
{
- if (f != it->second)
+ if (f != flag)
continue;
- else if (!u_access.HasPriv(it->first) && !u_access.founder)
+ else if (!u_access.HasPriv(priv) && !u_access.founder)
{
if (source.HasPriv("chanserv/access/modify"))
override = true;
@@ -262,7 +269,8 @@ class CommandCSFlags : public Command
return;
FlagsChanAccess *access = anope_dynamic_static_cast<FlagsChanAccess *>(provider->Create());
access->SetMask(mask, ci);
- access->creator = source.GetNick();
+ access->creator = source.GetNick();
+ access->description = current ? current->description : description;
access->last_seen = current ? current->last_seen : 0;
access->created = Anope::CurTime;
access->flags = current_flags;
@@ -286,7 +294,7 @@ class CommandCSFlags : public Command
source.Reply(_("Flags for \002%s\002 on %s set to +\002%s\002"), access->Mask().c_str(), ci->name.c_str(), access->AccessSerialize().c_str());
}
- void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
+ static void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
const Anope::string &arg = params.size() > 2 ? params[2] : "";
@@ -298,7 +306,7 @@ class CommandCSFlags : public Command
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Flags")).AddColumn(_("Creator")).AddColumn(_("Created"));
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Flags")).AddColumn(_("Creator")).AddColumn(_("Created")).AddColumn(_("Description"));
unsigned count = 0;
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
@@ -314,7 +322,7 @@ class CommandCSFlags : public Command
for (size_t j = 1; j < arg.length(); ++j)
if (flags.find(arg[j]) == Anope::string::npos)
pass = false;
- if (pass == false)
+ if (!pass)
continue;
}
else if (!Anope::Match(access->Mask(), arg))
@@ -323,11 +331,12 @@ class CommandCSFlags : public Command
ListFormatter::ListEntry entry;
++count;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Mask"] = access->Mask();
entry["Flags"] = flags;
entry["Creator"] = access->creator;
entry["Created"] = Anope::strftime(access->created, source.nc, true);
+ entry["Description"] = access->description;
list.AddEntry(entry);
}
@@ -339,8 +348,8 @@ class CommandCSFlags : public Command
list.Process(replies);
source.Reply(_("Flags list for %s"), ci->name.c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
if (count == ci->GetAccessCount())
source.Reply(_("End of access list."));
else
@@ -367,16 +376,16 @@ class CommandCSFlags : public Command
return;
}
- public:
- CommandCSFlags(Module *creator) : Command(creator, "chanserv/flags", 1, 4)
+public:
+ CommandCSFlags(Module *creator) : Command(creator, "chanserv/flags", 1, 5)
{
this->SetDesc(_("Modify the list of privileged users"));
- this->SetSyntax(_("\037channel\037 [MODIFY] \037mask\037 \037changes\037"));
+ this->SetSyntax(_("\037channel\037 [MODIFY] \037mask\037 \037changes\037 [\037description\037]"));
this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | +\037flags\037]"));
this->SetSyntax(_("\037channel\037 CLEAR"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
const Anope::string &cmd = params.size() > 1 ? params[1] : "";
@@ -409,23 +418,25 @@ class CommandCSFlags : public Command
this->DoClear(source, ci);
else
{
- Anope::string mask, flags;
+ Anope::string mask, flags, description;
if (cmd.equals_ci("MODIFY"))
{
mask = params.size() > 2 ? params[2] : "";
flags = params.size() > 3 ? params[3] : "";
+ description = params.size() > 4 ? params[4] : "";
}
else
{
mask = cmd;
flags = params.size() > 2 ? params[2] : "";
+ description = params.size() > 3 ? params[3] : "";
}
- this->DoModify(source, ci, mask, flags);
+ this->DoModify(source, ci, mask, flags, description);
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -450,27 +461,28 @@ class CommandCSFlags : public Command
typedef std::multimap<char, Anope::string, ci::less> reverse_map;
reverse_map reverse;
- for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it)
- reverse.insert(std::make_pair(it->second, it->first));
+ for (auto &[priv, flag] : defaultFlags)
+ reverse.emplace(flag, priv);
- for (reverse_map::iterator it = reverse.begin(), it_end = reverse.end(); it != it_end; ++it)
+ for (auto &[flag, priv] : reverse)
{
- Privilege *p = PrivilegeManager::FindPrivilege(it->second);
+ Privilege *p = PrivilegeManager::FindPrivilege(priv);
if (p == NULL)
continue;
- source.Reply(" %c - %s", it->first, Language::Translate(source.nc, p->desc.c_str()));
+ source.Reply(" %c - %s", flag, Language::Translate(source.nc, p->desc.c_str()));
}
return true;
}
};
-class CSFlags : public Module
+class CSFlags final
+ : public Module
{
FlagsAccessProvider accessprovider;
CommandCSFlags commandcsflags;
- public:
+public:
CSFlags(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
accessprovider(this), commandcsflags(this)
{
@@ -478,7 +490,7 @@ class CSFlags : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
defaultFlags.clear();
diff --git a/modules/commands/cs_getkey.cpp b/modules/chanserv/cs_getkey.cpp
index 79e78a1d8..38a782bea 100644
--- a/modules/commands/cs_getkey.cpp
+++ b/modules/chanserv/cs_getkey.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandCSGetKey : public Command
+class CommandCSGetKey final
+ : public Command
{
- public:
+public:
CommandCSGetKey(Module *creator) : Command(creator, "chanserv/getkey", 1, 1)
{
this->SetDesc(_("Returns the key of the given channel"));
this->SetSyntax(_("\037channel\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
@@ -50,7 +51,7 @@ class CommandCSGetKey : public Command
source.Reply(_("Key for channel \002%s\002 is \002%s\002."), chan.c_str(), key.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -59,11 +60,12 @@ class CommandCSGetKey : public Command
}
};
-class CSGetKey : public Module
+class CSGetKey final
+ : public Module
{
CommandCSGetKey commandcsgetkey;
- public:
+public:
CSGetKey(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsgetkey(this)
{
diff --git a/modules/commands/cs_info.cpp b/modules/chanserv/cs_info.cpp
index 75c00fda9..e02660301 100644
--- a/modules/commands/cs_info.cpp
+++ b/modules/chanserv/cs_info.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandCSInfo : public Command
+class CommandCSInfo final
+ : public Command
{
- public:
+public:
CommandCSInfo(Module *creator) : Command(creator, "chanserv/info", 1, 2)
{
this->SetDesc(_("Lists information about the specified registered channel"));
@@ -21,7 +22,7 @@ class CommandCSInfo : public Command
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
@@ -57,7 +58,7 @@ class CommandCSInfo : public Command
if (show_all)
{
- info[_("Ban type")] = stringify(ci->bantype);
+ info[_("Ban type")] = Anope::ToString(ci->bantype);
}
FOREACH_MOD(OnChanInfo, (source, ci, info, show_all));
@@ -65,11 +66,11 @@ class CommandCSInfo : public Command
std::vector<Anope::string> replies;
info.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -83,11 +84,12 @@ class CommandCSInfo : public Command
}
};
-class CSInfo : public Module
+class CSInfo final
+ : public Module
{
CommandCSInfo commandcsinfo;
- public:
+public:
CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsinfo(this)
{
diff --git a/modules/commands/cs_invite.cpp b/modules/chanserv/cs_invite.cpp
index 7a07151a0..4ab4b9a83 100644
--- a/modules/commands/cs_invite.cpp
+++ b/modules/chanserv/cs_invite.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandCSInvite : public Command
+class CommandCSInvite final
+ : public Command
{
- public:
+public:
CommandCSInvite(Module *creator) : Command(creator, "chanserv/invite", 1, 3)
{
this->SetDesc(_("Invites you or an optionally specified nick into a channel"));
this->SetSyntax(_("\037channel\037 [\037nick\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
@@ -84,7 +85,7 @@ class CommandCSInvite : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -97,11 +98,12 @@ class CommandCSInvite : public Command
}
};
-class CSInvite : public Module
+class CSInvite final
+ : public Module
{
CommandCSInvite commandcsinvite;
- public:
+public:
CSInvite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsinvite(this)
{
diff --git a/modules/commands/cs_kick.cpp b/modules/chanserv/cs_kick.cpp
index 4f2bbc92b..27f4dbac9 100644
--- a/modules/commands/cs_kick.cpp
+++ b/modules/chanserv/cs_kick.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandCSKick : public Command
+class CommandCSKick final
+ : public Command
{
- public:
+public:
CommandCSKick(Module *creator) : Command(creator, "chanserv/kick", 2, 3)
{
this->SetDesc(_("Kicks a specified nick from a channel"));
@@ -21,7 +22,7 @@ class CommandCSKick : public Command
this->SetSyntax(_("\037channel\037 \037mask\037 [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
const Anope::string &target = params[1];
@@ -71,10 +72,10 @@ class CommandCSKick : public Command
if (ci->HasExt("SIGNKICK") || (ci->HasExt("SIGNKICK_LEVEL") && !u_access.HasPriv("SIGNKICK")))
{
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), u2, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), u2, signkickformat);
}
else
- c->Kick(ci->WhoSends(), u2, "%s", reason.c_str());
+ c->Kick(ci->WhoSends(), u2, reason);
}
}
else if (u_access.HasPriv("FOUNDER"))
@@ -105,7 +106,7 @@ class CommandCSKick : public Command
{
reason += " (Matches " + mask + ")";
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), uc->user, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), uc->user, signkickformat);
}
else
c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
@@ -121,7 +122,7 @@ class CommandCSKick : public Command
source.Reply(NICK_X_NOT_IN_USE, target.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -133,11 +134,12 @@ class CommandCSKick : public Command
}
};
-class CSKick : public Module
+class CSKick final
+ : public Module
{
CommandCSKick commandcskick;
- public:
+public:
CSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcskick(this)
{
diff --git a/modules/commands/cs_list.cpp b/modules/chanserv/cs_list.cpp
index 13e71f98b..c9589a268 100644
--- a/modules/commands/cs_list.cpp
+++ b/modules/chanserv/cs_list.cpp
@@ -12,16 +12,17 @@
#include "module.h"
#include "modules/cs_mode.h"
-class CommandCSList : public Command
+class CommandCSList final
+ : public Command
{
- public:
+public:
CommandCSList(Module *creator) : Command(creator, "chanserv/list", 1, 2)
{
this->SetDesc(_("Lists all registered channels matching the given pattern"));
this->SetSyntax(_("\037pattern\037 [SUSPENDED] [NOEXPIRE]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string pattern = params[0];
unsigned nchans;
@@ -35,12 +36,10 @@ class CommandCSList : public Command
sepstream(pattern.substr(1), '-').GetToken(n1, 0);
sepstream(pattern, '-').GetToken(n2, 1);
- try
- {
- from = convertTo<int>(n1);
- to = convertTo<int>(n2);
- }
- catch (const ConvertException &)
+ auto num1 = Anope::TryConvert<int>(n1);
+ auto num2 = Anope::TryConvert<int>(n2);
+
+ if (!num1.has_value() || !num2.has_value())
{
source.Reply(LIST_INCORRECT_RANGE);
source.Reply(_("To search for channels starting with #, search for the channel\n"
@@ -48,6 +47,8 @@ class CommandCSList : public Command
return;
}
+ from = num1.value();
+ to = num2.value();
pattern = "*";
}
@@ -75,13 +76,11 @@ class CommandCSList : public Command
list.AddColumn(_("Name")).AddColumn(_("Description"));
Anope::map<ChannelInfo *> ordered_map;
- for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
- ordered_map[it->first] = it->second;
+ for (const auto &[cname, ci] : *RegisteredChannelList)
+ ordered_map[cname] = ci;
- for (Anope::map<ChannelInfo *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it)
+ for (const auto &[_, ci] : ordered_map)
{
- const ChannelInfo *ci = it->second;
-
if (!is_servadmin)
{
if (ci->HasExt("CS_PRIVATE") || ci->HasExt("CS_SUSPENDED"))
@@ -124,13 +123,13 @@ class CommandCSList : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of list - %d/%d matches shown."), nchans > listmax ? listmax : nchans, nchans);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -172,16 +171,17 @@ class CommandCSList : public Command
}
};
-class CommandCSSetPrivate : public Command
+class CommandCSSetPrivate final
+ : public Command
{
- public:
+public:
CommandCSSetPrivate(Module *creator, const Anope::string &cname = "chanserv/set/private") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Hide channel from the LIST command"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -225,7 +225,7 @@ class CommandCSSetPrivate : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -240,20 +240,21 @@ class CommandCSSetPrivate : public Command
}
};
-class CSList : public Module
+class CSList final
+ : public Module
{
CommandCSList commandcslist;
CommandCSSetPrivate commandcssetprivate;
SerializableExtensibleItem<bool> priv;
- public:
+public:
CSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcslist(this), commandcssetprivate(this), priv(this, "CS_PRIVATE")
{
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override
{
if (!show_all)
return;
diff --git a/modules/commands/cs_log.cpp b/modules/chanserv/cs_log.cpp
index e2da73e4c..8c1004eeb 100644
--- a/modules/commands/cs_log.cpp
+++ b/modules/chanserv/cs_log.cpp
@@ -12,13 +12,15 @@
#include "module.h"
#include "modules/cs_log.h"
-struct LogSettingImpl : LogSetting, Serializable
+struct LogSettingImpl final
+ : LogSetting
+ , Serializable
{
LogSettingImpl() : Serializable("LogSetting")
{
}
- ~LogSettingImpl()
+ ~LogSettingImpl() override
{
ChannelInfo *ci = ChannelInfo::Find(chan);
if (ci)
@@ -33,7 +35,7 @@ struct LogSettingImpl : LogSetting, Serializable
}
}
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["ci"] << chan;
data["service_name"] << service_name;
@@ -45,7 +47,7 @@ struct LogSettingImpl : LogSetting, Serializable
data.SetType("created", Serialize::Data::DT_INT); data["created"] << created;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string sci;
data["ci"] >> sci;
@@ -77,11 +79,12 @@ struct LogSettingImpl : LogSetting, Serializable
}
};
-struct LogSettingsImpl : LogSettings
+struct LogSettingsImpl final
+ : LogSettings
{
LogSettingsImpl(Extensible *) { }
- ~LogSettingsImpl()
+ ~LogSettingsImpl() override
{
for (iterator it = (*this)->begin(); it != (*this)->end();)
{
@@ -91,13 +94,14 @@ struct LogSettingsImpl : LogSettings
}
}
- LogSetting *Create() anope_override
+ LogSetting *Create() override
{
return new LogSettingImpl();
}
};
-class CommandCSLog : public Command
+class CommandCSLog final
+ : public Command
{
public:
CommandCSLog(Module *creator) : Command(creator, "chanserv/log", 1, 4)
@@ -107,7 +111,7 @@ public:
this->SetSyntax(_("\037channel\037 \037command\037 \037method\037 [\037status\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &channel = params[0];
@@ -131,7 +135,7 @@ public:
const LogSetting *log = (*ls)->at(i);
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Service"] = log->command_service;
entry["Command"] = !log->command_name.empty() ? log->command_name : log->service_name;
entry["Method"] = log->method;
@@ -144,8 +148,8 @@ public:
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
else if (params.size() > 2)
@@ -199,12 +203,14 @@ public:
return;
}
- for (unsigned i = 0; i < extra.length(); ++i)
- if (ModeManager::GetStatusChar(extra[i]) == 0)
+ for (auto chr : extra)
+ {
+ if (ModeManager::GetStatusChar(chr) == 0)
{
- source.Reply(_("%c is an unknown status mode."), extra[i]);
+ source.Reply(_("%c is an unknown status mode."), chr);
return;
}
+ }
bool override = !source.AccessFor(ci).HasPriv("SET");
@@ -230,7 +236,7 @@ public:
}
}
- LogSetting *log = new LogSettingImpl();
+ auto *log = new LogSettingImpl();
log->chan = ci->name;
log->service_name = service_name;
if (bi)
@@ -251,7 +257,7 @@ public:
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -279,21 +285,22 @@ public:
}
};
-class CSLog : public Module
+class CSLog final
+ : public Module
{
ServiceReference<MemoServService> MSService;
CommandCSLog commandcslog;
ExtensibleItem<LogSettingsImpl> logsettings;
Serialize::Type logsetting_type;
- struct LogDefault
+ struct LogDefault final
{
Anope::string service, command, method;
};
std::vector<LogDefault> defaults;
- public:
+public:
CSLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
MSService("MemoServService", "MemoServ"), commandcslog(this),
logsettings(this, "logsettings"), logsetting_type("LogSetting", LogSettingImpl::Unserialize)
@@ -301,7 +308,7 @@ class CSLog : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
defaults.clear();
@@ -320,17 +327,15 @@ class CSLog : public Module
}
}
- void OnChanRegistered(ChannelInfo *ci) anope_override
+ void OnChanRegistered(ChannelInfo *ci) override
{
if (defaults.empty())
return;
LogSettings *ls = logsettings.Require(ci);
- for (unsigned i = 0; i < defaults.size(); ++i)
+ for (auto &d : defaults)
{
- LogDefault &d = defaults[i];
-
- LogSetting *log = new LogSettingImpl();
+ auto *log = new LogSettingImpl();
log->chan = ci->name;
if (!d.service.empty())
@@ -353,18 +358,17 @@ class CSLog : public Module
}
}
- void OnLog(Log *l) anope_override
+ void OnLog(Log *l) override
{
if (l->type != LOG_COMMAND || l->u == NULL || l->c == NULL || l->ci == NULL || !Me || !Me->IsSynced())
return;
LogSettings *ls = logsettings.Get(l->ci);
if (ls)
- for (unsigned i = 0; i < (*ls)->size(); ++i)
+ {
+ for (auto *log : *(*ls))
{
- const LogSetting *log = (*ls)->at(i);
-
- /* wrong command */
+ /* wrong command */
if (log->service_name != l->c->name)
continue;
@@ -393,6 +397,7 @@ class CSLog : public Module
else if (log->method.equals_ci("NOTICE") && l->ci->c)
IRCD->SendNotice(l->ci->WhoSends(), log->extra + l->ci->c->name, "%s", buffer.c_str());
}
+ }
}
};
diff --git a/modules/commands/cs_mode.cpp b/modules/chanserv/cs_mode.cpp
index f43361c31..8f462a3cb 100644
--- a/modules/commands/cs_mode.cpp
+++ b/modules/chanserv/cs_mode.cpp
@@ -12,13 +12,15 @@
#include "module.h"
#include "modules/cs_mode.h"
-struct ModeLockImpl : ModeLock, Serializable
+struct ModeLockImpl final
+ : ModeLock
+ , Serializable
{
ModeLockImpl() : Serializable("ModeLock")
{
}
- ~ModeLockImpl()
+ ~ModeLockImpl() override
{
ChannelInfo *chan = ChannelInfo::Find(ci);
if (chan)
@@ -29,11 +31,12 @@ struct ModeLockImpl : ModeLock, Serializable
}
}
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
-struct ModeLocksImpl : ModeLocks
+struct ModeLocksImpl final
+ : ModeLocks
{
Serialize::Reference<ChannelInfo> ci;
Serialize::Checker<ModeList> mlocks;
@@ -42,26 +45,23 @@ struct ModeLocksImpl : ModeLocks
{
}
- ~ModeLocksImpl()
+ ~ModeLocksImpl() override
{
ModeList modelist;
mlocks->swap(modelist);
- for (ModeList::iterator it = modelist.begin(); it != modelist.end(); ++it)
+ for (auto *ml : modelist)
{
- ModeLock *ml = *it;
delete ml;
}
}
- bool HasMLock(ChannelMode *mode, const Anope::string &param, bool status) const anope_override
+ bool HasMLock(ChannelMode *mode, const Anope::string &param, bool status) const override
{
if (!mode)
return false;
- for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it)
+ for (auto *ml : *this->mlocks)
{
- const ModeLock *ml = *it;
-
if (ml->name == mode->name && ml->set == status && ml->param == param)
return true;
}
@@ -69,7 +69,7 @@ struct ModeLocksImpl : ModeLocks
return false;
}
- bool SetMLock(ChannelMode *mode, bool status, const Anope::string &param, Anope::string setter, time_t created = Anope::CurTime) anope_override
+ bool SetMLock(ChannelMode *mode, bool status, const Anope::string &param, Anope::string setter, time_t created = Anope::CurTime) override
{
if (!mode)
return false;
@@ -79,7 +79,7 @@ struct ModeLocksImpl : ModeLocks
if (setter.empty())
setter = ci->GetFounder() ? ci->GetFounder()->display : "Unknown";
- ModeLock *ml = new ModeLockImpl();
+ auto *ml = new ModeLockImpl();
ml->ci = ci->name;
ml->set = status;
ml->name = mode->name;
@@ -99,15 +99,13 @@ struct ModeLocksImpl : ModeLocks
return true;
}
- bool RemoveMLock(ChannelMode *mode, bool status, const Anope::string &param = "") anope_override
+ bool RemoveMLock(ChannelMode *mode, bool status, const Anope::string &param = "") override
{
if (!mode)
return false;
- for (ModeList::iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it)
+ for (auto *m : *this->mlocks)
{
- ModeLock *m = *it;
-
if (m->name == mode->name)
{
// For list or status modes, we must check the parameter
@@ -128,44 +126,41 @@ struct ModeLocksImpl : ModeLocks
return false;
}
- void RemoveMLock(ModeLock *mlock) anope_override
+ void RemoveMLock(ModeLock *mlock) override
{
ModeList::iterator it = std::find(this->mlocks->begin(), this->mlocks->end(), mlock);
if (it != this->mlocks->end())
this->mlocks->erase(it);
}
- void ClearMLock() anope_override
+ void ClearMLock() override
{
ModeList ml;
this->mlocks->swap(ml);
- for (unsigned i = 0; i < ml.size(); ++i)
- delete ml[i];
+ for (const auto *lock : ml)
+ delete lock;
}
- const ModeList &GetMLock() const anope_override
+ const ModeList &GetMLock() const override
{
return this->mlocks;
}
- std::list<ModeLock *> GetModeLockList(const Anope::string &name) anope_override
+ std::list<ModeLock *> GetModeLockList(const Anope::string &name) override
{
std::list<ModeLock *> mlist;
- for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it)
+ for (auto *m : *this->mlocks)
{
- ModeLock *m = *it;
- if (m->name == name)
+ if (m->name == name)
mlist.push_back(m);
}
return mlist;
}
- const ModeLock *GetMLock(const Anope::string &mname, const Anope::string &param = "") anope_override
+ const ModeLock *GetMLock(const Anope::string &mname, const Anope::string &param = "") override
{
- for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it)
+ for (auto *m : *this->mlocks)
{
- ModeLock *m = *it;
-
if (m->name == mname && m->param == param)
return m;
}
@@ -173,13 +168,12 @@ struct ModeLocksImpl : ModeLocks
return NULL;
}
- Anope::string GetMLockAsString(bool complete) const anope_override
+ Anope::string GetMLockAsString(bool complete) const override
{
Anope::string pos = "+", neg = "-", params;
- for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it)
+ for (auto *ml : *this->mlocks)
{
- const ModeLock *ml = *it;
ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm || cm->type == MODE_LIST || cm->type == MODE_STATUS)
@@ -202,7 +196,7 @@ struct ModeLocksImpl : ModeLocks
return pos + neg + params;
}
- void Check() anope_override
+ void Check() override
{
if (this->mlocks->empty())
ci->Shrink<ModeLocks>("modelocks");
@@ -219,7 +213,7 @@ void ModeLockImpl::Serialize(Serialize::Data &data) const
data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created;
}
-Serializable* ModeLockImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *ModeLockImpl::Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string sci;
@@ -250,9 +244,10 @@ Serializable* ModeLockImpl::Unserialize(Serializable *obj, Serialize::Data &data
return ml;
}
-class CommandCSMode : public Command
+class CommandCSMode final
+ : public Command
{
- bool CanSet(CommandSource &source, ChannelInfo *ci, ChannelMode *cm, bool self)
+ static bool CanSet(CommandSource &source, ChannelInfo *ci, ChannelMode *cm, bool self)
{
if (!ci || !cm || cm->type != MODE_STATUS)
return false;
@@ -281,9 +276,8 @@ class CommandCSMode : public Command
if (subcommand.equals_ci("SET"))
{
const ModeLocks::ModeList mlocks = modelocks->GetMLock();
- for (ModeLocks::ModeList::const_iterator it = mlocks.begin(); it != mlocks.end(); ++it)
+ for (auto *ml : mlocks)
{
- const ModeLock *ml = *it;
ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (cm && cm->CanSet(source.GetUser()))
modelocks->RemoveMLock(cm, ml->set, ml->param);
@@ -299,9 +293,9 @@ class CommandCSMode : public Command
int adding = 1;
bool needreply = true;
- for (size_t i = 0; i < modes.length(); ++i)
+ for (auto mode : modes)
{
- switch (modes[i])
+ switch (mode)
{
case '+':
adding = 1;
@@ -311,15 +305,15 @@ class CommandCSMode : public Command
break;
default:
needreply = false;
- ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(mode);
if (!cm)
{
- source.Reply(_("Unknown mode character %c ignored."), modes[i]);
+ source.Reply(_("Unknown mode character %c ignored."), mode);
break;
}
else if (u && !cm->CanSet(u))
{
- source.Reply(_("You may not (un)lock mode %c."), modes[i]);
+ source.Reply(_("You may not (un)lock mode %c."), mode);
break;
}
@@ -342,7 +336,7 @@ class CommandCSMode : public Command
continue;
}
- if (modelocks->GetMLock().size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "32"))
+ if (modelocks->GetMLock().size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "50"))
{
source.Reply(_("The mode lock list of \002%s\002 is full."), ci->name.c_str());
continue;
@@ -391,9 +385,9 @@ class CommandCSMode : public Command
int adding = 1;
bool needreply = true;
- for (size_t i = 0; i < modes.length(); ++i)
+ for (auto mode : modes)
{
- switch (modes[i])
+ switch (mode)
{
case '+':
adding = 1;
@@ -403,15 +397,15 @@ class CommandCSMode : public Command
break;
default:
needreply = false;
- ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(mode);
if (!cm)
{
- source.Reply(_("Unknown mode character %c ignored."), modes[i]);
+ source.Reply(_("Unknown mode character %c ignored."), mode);
break;
}
else if (u && !cm->CanSet(u))
{
- source.Reply(_("You may not (un)lock mode %c."), modes[i]);
+ source.Reply(_("You may not (un)lock mode %c."), mode);
break;
}
@@ -448,9 +442,8 @@ class CommandCSMode : public Command
ListFormatter list(source.GetAccount());
list.AddColumn(_("Mode")).AddColumn(_("Param")).AddColumn(_("Creator")).AddColumn(_("Created"));
- for (ModeLocks::ModeList::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it)
+ for (auto *ml : mlocks)
{
- const ModeLock *ml = *it;
ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm)
continue;
@@ -468,8 +461,8 @@ class CommandCSMode : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
else
@@ -489,9 +482,9 @@ class CommandCSMode : public Command
bool override = !source.AccessFor(ci).HasPriv("MODE") && source.HasPriv("chanserv/administration");
int adding = -1;
- for (size_t i = 0; i < modes.length(); ++i)
+ for (auto mode : modes)
{
- switch (modes[i])
+ switch (mode)
{
case '+':
adding = 1;
@@ -521,7 +514,7 @@ class CommandCSMode : public Command
default:
if (adding == -1)
break;
- ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(mode);
if (!cm || (u && !cm->CanSet(u) && !can_override))
continue;
switch (cm->type)
@@ -665,10 +658,11 @@ class CommandCSMode : public Command
}
else
{
- std::vector<Anope::string> v = ci->c->GetModeList(cm->name);
- for (unsigned j = 0; j < v.size(); ++j)
- if (Anope::Match(v[j], param))
- ci->c->RemoveMode(NULL, cm, v[j]);
+ for (const auto &mode : ci->c->GetModeList(cm->name))
+ {
+ if (Anope::Match(mode, param))
+ ci->c->RemoveMode(NULL, cm, mode);
+ }
}
}
} // switch
@@ -685,8 +679,8 @@ class CommandCSMode : public Command
{
std::vector<Anope::string> new_params;
new_params.push_back(params[0]);
- new_params.push_back("SET");
- new_params.push_back("-*");
+ new_params.emplace_back("SET");
+ new_params.emplace_back("-*");
this->DoSet(source, ci, new_params);
return;
}
@@ -721,13 +715,13 @@ class CommandCSMode : public Command
std::vector<Anope::string> new_params;
new_params.push_back(params[0]);
- new_params.push_back("SET");
- new_params.push_back("-" + stringify(cm->mchar));
- new_params.push_back("*");
+ new_params.emplace_back("SET");
+ new_params.push_back("-" + Anope::ToString(cm->mchar));
+ new_params.emplace_back("*");
this->DoSet(source, ci, new_params);
}
- public:
+public:
CommandCSMode(Module *creator) : Command(creator, "chanserv/mode", 2, 4)
{
this->SetDesc(_("Control modes and mode locks on a channel"));
@@ -736,7 +730,7 @@ class CommandCSMode : public Command
this->SetSyntax(_("\037channel\037 CLEAR [\037what\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &subcommand = params[1];
@@ -766,7 +760,7 @@ class CommandCSMode : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -799,15 +793,16 @@ class CommandCSMode : public Command
static Anope::map<std::pair<bool, Anope::string> > modes;
-class CommandCSModes : public Command
+class CommandCSModes final
+ : public Command
{
- public:
+public:
CommandCSModes(Module *creator) : Command(creator, "chanserv/modes", 1, 2)
{
this->SetSyntax(_("\037channel\037 [\037user\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
User *u = source.GetUser(),
*targ = params.size() > 1 ? User::Find(params[1], true) : u;
@@ -879,7 +874,7 @@ class CommandCSModes : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "on " << targ->nick;
}
- const Anope::string GetDesc(CommandSource &source) const anope_override
+ const Anope::string GetDesc(CommandSource &source) const override
{
const std::pair<bool, Anope::string> &m = modes[source.command];
if (!m.second.empty())
@@ -893,7 +888,7 @@ class CommandCSModes : public Command
return "";
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
const std::pair<bool, Anope::string> &m = modes[source.command];
if (m.second.empty())
@@ -916,14 +911,15 @@ class CommandCSModes : public Command
}
};
-class CSMode : public Module
+class CSMode final
+ : public Module
{
CommandCSMode commandcsmode;
CommandCSModes commandcsmodes;
ExtensibleItem<ModeLocksImpl> modelocks;
Serialize::Type modelocks_type;
- public:
+public:
CSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsmode(this), commandcsmodes(this),
modelocks(this, "modelocks"),
@@ -932,7 +928,7 @@ class CSMode : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
modes.clear();
@@ -956,17 +952,17 @@ class CSMode : public Module
}
}
- void OnCheckModes(Reference<Channel> &c) anope_override
+ void OnCheckModes(Reference<Channel> &c) override
{
if (!c || !c->ci)
return;
ModeLocks *locks = modelocks.Get(c->ci);
if (locks)
- for (ModeLocks::ModeList::const_iterator it = locks->GetMLock().begin(), it_end = locks->GetMLock().end(); it != it_end; ++it)
+ {
+ for (auto *ml : locks->GetMLock())
{
- const ModeLock *ml = *it;
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
+ ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm)
continue;
@@ -1003,9 +999,10 @@ class CSMode : public Module
c->RemoveMode(NULL, cm, ml->param, false);
}
}
+ }
}
- void OnChanRegistered(ChannelInfo *ci) anope_override
+ void OnChanRegistered(ChannelInfo *ci) override
{
ModeLocks *ml = modelocks.Require(ci);
Anope::string mlock;
@@ -1013,21 +1010,21 @@ class CSMode : public Module
if (sep.GetToken(mlock))
{
bool add = true;
- for (unsigned i = 0; i < mlock.length(); ++i)
+ for (auto mode : mlock)
{
- if (mlock[i] == '+')
+ if (mode == '+')
{
add = true;
continue;
}
- if (mlock[i] == '-')
+ if (mode == '-')
{
add = false;
continue;
}
- ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock[i]);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(mode);
if (!cm)
continue;
@@ -1055,7 +1052,7 @@ class CSMode : public Module
ml->Check();
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) override
{
if (!show_hidden)
return;
diff --git a/modules/commands/cs_register.cpp b/modules/chanserv/cs_register.cpp
index 4ae2636de..402ae1296 100644
--- a/modules/commands/cs_register.cpp
+++ b/modules/chanserv/cs_register.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandCSRegister : public Command
+class CommandCSRegister final
+ : public Command
{
- public:
+public:
CommandCSRegister(Module *creator) : Command(creator, "chanserv/register", 1, 2)
{
this->SetDesc(_("Register a channel"));
this->SetSyntax(_("\037channel\037 [\037description\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
const Anope::string &chdesc = params.size() > 1 ? params[1] : "";
@@ -79,7 +80,7 @@ class CommandCSRegister : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -110,11 +111,12 @@ class CommandCSRegister : public Command
};
-class CSRegister : public Module
+class CSRegister final
+ : public Module
{
CommandCSRegister commandcsregister;
- public:
+public:
CSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsregister(this)
{
diff --git a/modules/commands/cs_seen.cpp b/modules/chanserv/cs_seen.cpp
index 6114d2460..183cd5e05 100644
--- a/modules/commands/cs_seen.cpp
+++ b/modules/chanserv/cs_seen.cpp
@@ -19,10 +19,11 @@ enum TypeInfo
static bool simple;
struct SeenInfo;
static SeenInfo *FindInfo(const Anope::string &nick);
-typedef Anope::hash_map<SeenInfo *> database_map;
+typedef Anope::unordered_map<SeenInfo *> database_map;
database_map database;
-struct SeenInfo : Serializable
+struct SeenInfo final
+ : Serializable
{
Anope::string nick;
Anope::string vhost;
@@ -36,14 +37,14 @@ struct SeenInfo : Serializable
{
}
- ~SeenInfo()
+ ~SeenInfo() override
{
database_map::iterator iter = database.find(nick);
if (iter != database.end() && iter->second == this)
database.erase(iter);
}
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["nick"] << nick;
data["vhost"] << vhost;
@@ -54,7 +55,7 @@ struct SeenInfo : Serializable
data.SetType("last", Serialize::Data::DT_INT); data["last"] << last;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string snick;
@@ -65,7 +66,7 @@ struct SeenInfo : Serializable
s = anope_dynamic_static_cast<SeenInfo *>(obj);
else
{
- SeenInfo* &info = database[snick];
+ SeenInfo *&info = database[snick];
if (!info)
info = new SeenInfo();
s = info;
@@ -109,9 +110,10 @@ static bool ShouldHide(const Anope::string &channel, User *u)
return false;
}
-class CommandOSSeen : public Command
+class CommandOSSeen final
+ : public Command
{
- public:
+public:
CommandOSSeen(Module *creator) : Command(creator, "operserv/seen", 1, 2)
{
this->SetDesc(_("Statistics and maintenance for seen data"));
@@ -119,20 +121,20 @@ class CommandOSSeen : public Command
this->SetSyntax(_("CLEAR \037time\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (params[0].equals_ci("STATS"))
{
size_t mem_counter;
mem_counter = sizeof(database_map);
- for (database_map::iterator it = database.begin(), it_end = database.end(); it != it_end; ++it)
+ for (auto &[nick, si] : database)
{
mem_counter += (5 * sizeof(Anope::string)) + sizeof(TypeInfo) + sizeof(time_t);
- mem_counter += it->first.capacity();
- mem_counter += it->second->vhost.capacity();
- mem_counter += it->second->nick2.capacity();
- mem_counter += it->second->channel.capacity();
- mem_counter += it->second->message.capacity();
+ mem_counter += nick.capacity();
+ mem_counter += si->vhost.capacity();
+ mem_counter += si->nick2.capacity();
+ mem_counter += si->channel.capacity();
+ mem_counter += si->message.capacity();
}
source.Reply(_("%lu nicks are stored in the database, using %.2Lf kB of memory."), database.size(), static_cast<long double>(mem_counter) / 1024);
}
@@ -165,7 +167,7 @@ class CommandOSSeen : public Command
this->SendSyntax(source);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -180,9 +182,10 @@ class CommandOSSeen : public Command
}
};
-class CommandSeen : public Command
+class CommandSeen final
+ : public Command
{
- void SimpleSeen(CommandSource &source, const std::vector<Anope::string> &params)
+ static void SimpleSeen(CommandSource &source, const std::vector<Anope::string> &params)
{
if (!source.c || !source.c->ci)
{
@@ -222,9 +225,8 @@ class CommandSeen : public Command
return;
}
- for (Channel::ChanUserList::const_iterator it = source.c->users.begin(), it_end = source.c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : source.c->users)
{
- ChanUserContainer *uc = it->second;
User *u = uc->user;
if (u->Account() == na->nc)
@@ -236,10 +238,8 @@ class CommandSeen : public Command
AccessGroup ag = source.c->ci->AccessFor(na->nc);
time_t last = 0;
- for (unsigned int i = 0; i < ag.paths.size(); ++i)
+ for (const auto &p : ag.paths)
{
- ChanAccess::Path &p = ag.paths[i];
-
if (p.empty())
continue;
@@ -255,7 +255,7 @@ class CommandSeen : public Command
source.Reply(_("%s was last seen here %s ago."), na->nick.c_str(), Anope::Duration(Anope::CurTime - last, source.GetAccount()).c_str());
}
- public:
+public:
CommandSeen(Module *creator) : Command(creator, "chanserv/seen", 1, 2)
{
this->SetDesc(_("Tells you about the last time a user was seen"));
@@ -263,16 +263,16 @@ class CommandSeen : public Command
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &target = params[0];
if (simple)
return this->SimpleSeen(source, params);
- if (target.length() > Config->GetBlock("networkinfo")->Get<unsigned>("nicklen"))
+ if (target.length() > IRCD->GetMaxNick())
{
- source.Reply(_("Nick too long, max length is %u characters."), Config->GetBlock("networkinfo")->Get<unsigned>("nicklen"));
+ source.Reply(_("Nick too long, max length is %zu characters."), IRCD->GetMaxNick());
return;
}
@@ -360,7 +360,7 @@ class CommandSeen : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -371,22 +371,23 @@ class CommandSeen : public Command
}
};
-class CSSeen : public Module
+class CSSeen final
+ : public Module
{
Serialize::Type seeninfo_type;
CommandSeen commandseen;
CommandOSSeen commandosseen;
- public:
+public:
CSSeen(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), seeninfo_type("SeenInfo", SeenInfo::Unserialize), commandseen(this), commandosseen(this)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
simple = conf->GetModule(this)->Get<bool>("simple");
}
- void OnExpireTick() anope_override
+ void OnExpireTick() override
{
size_t previous_size = database.size();
time_t purgetime = Config->GetModule(this)->Get<time_t>("purgetime");
@@ -406,45 +407,45 @@ class CSSeen : public Module
Log(LOG_DEBUG) << "cs_seen: Purged database, checked " << previous_size << " nicks and removed " << (previous_size - database.size()) << " old entries.";
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (!u->Quitting())
UpdateUser(u, NEW, u->nick, "", "", "");
}
- void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override
+ void OnUserNickChange(User *u, const Anope::string &oldnick) override
{
UpdateUser(u, NICK_TO, oldnick, u->nick, "", "");
UpdateUser(u, NICK_FROM, u->nick, oldnick, "", "");
}
- void OnUserQuit(User *u, const Anope::string &msg) anope_override
+ void OnUserQuit(User *u, const Anope::string &msg) override
{
UpdateUser(u, QUIT, u->nick, "", "", msg);
}
- void OnJoinChannel(User *u, Channel *c) anope_override
+ void OnJoinChannel(User *u, Channel *c) override
{
UpdateUser(u, JOIN, u->nick, "", c->name, "");
}
- void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) anope_override
+ void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) override
{
UpdateUser(u, PART, u->nick, "", channel, msg);
}
- void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &msg) anope_override
+ void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &msg) override
{
UpdateUser(cu->user, KICK, cu->user->nick, source.GetSource(), cu->chan->name, msg);
}
- private:
- void UpdateUser(const User *u, const TypeInfo Type, const Anope::string &nick, const Anope::string &nick2, const Anope::string &channel, const Anope::string &message)
+private:
+ static void UpdateUser(const User *u, const TypeInfo Type, const Anope::string &nick, const Anope::string &nick2, const Anope::string &channel, const Anope::string &message)
{
if (simple || !u->server->IsSynced())
return;
- SeenInfo* &info = database[nick];
+ SeenInfo *&info = database[nick];
if (!info)
info = new SeenInfo();
info->nick = nick;
diff --git a/modules/commands/cs_set.cpp b/modules/chanserv/cs_set.cpp
index 3c015d6fd..c7952baba 100644
--- a/modules/commands/cs_set.cpp
+++ b/modules/chanserv/cs_set.cpp
@@ -12,21 +12,22 @@
#include "module.h"
#include "modules/cs_mode.h"
-class CommandCSSet : public Command
+class CommandCSSet final
+ : public Command
{
- public:
+public:
CommandCSSet(Module *creator) : Command(creator, "chanserv/set", 2, 3)
{
this->SetDesc(_("Set channel options and information"));
this->SetSyntax(_("\037option\037 \037channel\037 \037parameters\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -37,10 +38,8 @@ class CommandCSSet : public Command
Anope::string this_name = source.command;
bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"),
hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands");
- for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it)
+ for (const auto &[c_name, info] : source.service->commands)
{
- const Anope::string &c_name = it->first;
- const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
if (info.hide)
@@ -56,7 +55,7 @@ class CommandCSSet : public Command
else if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission))
continue;
- source.command = it->first;
+ source.command = c_name;
c->OnServHelp(source);
}
}
@@ -66,16 +65,17 @@ class CommandCSSet : public Command
}
};
-class CommandCSSetAutoOp : public Command
+class CommandCSSetAutoOp final
+ : public Command
{
- public:
+public:
CommandCSSetAutoOp(Module *creator, const Anope::string &cname = "chanserv/set/autoop") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Should services automatically give status to users"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -117,28 +117,29 @@ class CommandCSSetAutoOp : public Command
this->OnSyntaxError(source, "AUTOOP");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Enables or disables %s's autoop feature for a\n"
"channel. When disabled, users who join the channel will\n"
"not automatically gain any status from %s."), source.service->nick.c_str(),
- source.service->nick.c_str(), this->name.c_str());
+ source.service->nick.c_str());
return true;
}
};
-class CommandCSSetBanType : public Command
+class CommandCSSetBanType final
+ : public Command
{
- public:
+public:
CommandCSSetBanType(Module *creator, const Anope::string &cname = "chanserv/set/bantype") : Command(creator, cname, 2, 2)
{
- this->SetDesc(_("Set how Services make bans on the channel"));
+ this->SetDesc(_("Set how services make bans on the channel"));
this->SetSyntax(_("\037channel\037 \037bantype\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -164,22 +165,19 @@ class CommandCSSetBanType : public Command
return;
}
- try
- {
- int16_t new_type = convertTo<int16_t>(params[1]);
- if (new_type < 0 || new_type > 3)
- throw ConvertException("Invalid range");
- Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to change the ban type to " << new_type;
- ci->bantype = new_type;
- source.Reply(_("Ban type for channel %s is now #%d."), ci->name.c_str(), ci->bantype);
- }
- catch (const ConvertException &)
+ auto new_type = Anope::Convert<int16_t>(params[1], -1);
+ if (new_type < 0 || new_type > 3)
{
source.Reply(_("\002%s\002 is not a valid ban type."), params[1].c_str());
+ return;
}
+
+ Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to change the ban type to " << new_type;
+ ci->bantype = new_type;
+ source.Reply(_("Ban type for channel %s is now #%d."), ci->name.c_str(), ci->bantype);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -191,21 +189,22 @@ class CommandCSSetBanType : public Command
"0: ban in the form *!user@host\n"
"1: ban in the form *!*user@host\n"
"2: ban in the form *!*@host\n"
- "3: ban in the form *!*user@*.domain"), this->name.c_str());
+ "3: ban in the form *!*user@*.domain"));
return true;
}
};
-class CommandCSSetDescription : public Command
+class CommandCSSetDescription final
+ : public Command
{
- public:
+public:
CommandCSSetDescription(Module *creator, const Anope::string &cname = "chanserv/set/description") : Command(creator, cname, 1, 2)
{
this->SetDesc(_("Set the channel description"));
this->SetSyntax(_("\037channel\037 [\037description\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -248,26 +247,27 @@ class CommandCSSetDescription : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Sets the description for the channel, which shows up with\n"
- "the \002LIST\002 and \002INFO\002 commands."), this->name.c_str());
+ "the \002LIST\002 and \002INFO\002 commands."));
return true;
}
};
-class CommandCSSetFounder : public Command
+class CommandCSSetFounder final
+ : public Command
{
- public:
+public:
CommandCSSetFounder(Module *creator, const Anope::string &cname = "chanserv/set/founder") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Set the founder of a channel"));
this->SetSyntax(_("\037channel\037 \037nick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -317,26 +317,27 @@ class CommandCSSetFounder : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Changes the founder of a channel. The new nickname must\n"
- "be a registered one."), this->name.c_str());
+ "be a registered one."));
return true;
}
};
-class CommandCSSetKeepModes : public Command
+class CommandCSSetKeepModes final
+ : public Command
{
- public:
+public:
CommandCSSetKeepModes(Module *creator, const Anope::string &cname = "chanserv/set/keepmodes") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Retain modes when channel is not in use"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -381,7 +382,7 @@ class CommandCSSetKeepModes : public Command
this->OnSyntaxError(source, "KEEPMODES");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -392,16 +393,17 @@ class CommandCSSetKeepModes : public Command
}
};
-class CommandCSSetPeace : public Command
+class CommandCSSetPeace final
+ : public Command
{
- public:
+public:
CommandCSSetPeace(Module *creator, const Anope::string &cname = "chanserv/set/peace") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Regulate the use of critical commands"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -445,7 +447,7 @@ class CommandCSSetPeace : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -464,16 +466,17 @@ inline static Anope::string BotModes()
);
}
-class CommandCSSetPersist : public Command
+class CommandCSSetPersist final
+ : public Command
{
- public:
+public:
CommandCSSetPersist(Module *creator, const Anope::string &cname = "chanserv/set/persist") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Set the channel as permanent"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -583,7 +586,7 @@ class CommandCSSetPersist : public Command
this->OnSyntaxError(source, "PERSIST");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
BotInfo *BotServ = Config->GetClient("BotServ");
BotInfo *ChanServ = Config->GetClient("ChanServ");
@@ -613,16 +616,17 @@ class CommandCSSetPersist : public Command
}
};
-class CommandCSSetRestricted : public Command
+class CommandCSSetRestricted final
+ : public Command
{
- public:
+public:
CommandCSSetRestricted(Module *creator, const Anope::string &cname = "chanserv/set/restricted") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Restrict access to the channel"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -664,7 +668,7 @@ class CommandCSSetRestricted : public Command
this->OnSyntaxError(source, "RESTRICTED");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -675,79 +679,17 @@ class CommandCSSetRestricted : public Command
}
};
-class CommandCSSetSecure : public Command
-{
- public:
- CommandCSSetSecure(Module *creator, const Anope::string &cname = "chanserv/set/secure") : Command(creator, cname, 2, 2)
- {
- this->SetDesc(_("Activate security features"));
- this->SetSyntax(_("\037channel\037 {ON | OFF}"));
- }
-
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (Anope::ReadOnly)
- {
- source.Reply(READ_ONLY_MODE);
- return;
- }
-
- ChannelInfo *ci = ChannelInfo::Find(params[0]);
- if (ci == NULL)
- {
- source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
- return;
- }
-
- EventReturn MOD_RESULT;
- FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1]));
- if (MOD_RESULT == EVENT_STOP)
- return;
-
- if (MOD_RESULT != EVENT_ALLOW && !source.AccessFor(ci).HasPriv("SET") && source.permission.empty() && !source.HasPriv("chanserv/administration"))
- {
- source.Reply(ACCESS_DENIED);
- return;
- }
-
- if (params[1].equals_ci("ON"))
- {
- Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to enable secure";
- ci->Extend<bool>("CS_SECURE");
- source.Reply(_("Secure option for %s is now \002on\002."), ci->name.c_str());
- }
- else if (params[1].equals_ci("OFF"))
- {
- Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to disable secure";
- ci->Shrink<bool>("CS_SECURE");
- source.Reply(_("Secure option for %s is now \002off\002."), ci->name.c_str());
- }
- else
- this->OnSyntaxError(source, "SECURE");
- }
-
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
- {
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Enables or disables security features for a\n"
- "channel. When \002SECURE\002 is set, only users who have\n"
- "identified to services, and are not only recognized, will be\n"
- "given access to channels from account-based access entries."));
- return true;
- }
-};
-
-class CommandCSSetSecureFounder : public Command
+class CommandCSSetSecureFounder final
+ : public Command
{
- public:
+public:
CommandCSSetSecureFounder(Module *creator, const Anope::string &cname = "chanserv/set/securefounder") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Stricter control of channel founder status"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -789,7 +731,7 @@ class CommandCSSetSecureFounder : public Command
this->OnSyntaxError(source, "SECUREFOUNDER");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -802,16 +744,17 @@ class CommandCSSetSecureFounder : public Command
}
};
-class CommandCSSetSecureOps : public Command
+class CommandCSSetSecureOps final
+ : public Command
{
- public:
+public:
CommandCSSetSecureOps(Module *creator, const Anope::string &cname = "chanserv/set/secureops") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Stricter control of chanop status"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -853,7 +796,7 @@ class CommandCSSetSecureOps : public Command
this->OnSyntaxError(source, "SECUREOPS");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -864,16 +807,17 @@ class CommandCSSetSecureOps : public Command
}
};
-class CommandCSSetSignKick : public Command
+class CommandCSSetSignKick final
+ : public Command
{
- public:
+public:
CommandCSSetSignKick(Module *creator, const Anope::string &cname = "chanserv/set/signkick") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Sign kicks that are done with the KICK command"));
this->SetSyntax(_("\037channel\037 {ON | LEVEL | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -925,7 +869,7 @@ class CommandCSSetSignKick : public Command
this->OnSyntaxError(source, "SIGNKICK");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -941,16 +885,17 @@ class CommandCSSetSignKick : public Command
}
};
-class CommandCSSetSuccessor : public Command
+class CommandCSSetSuccessor final
+ : public Command
{
- public:
+public:
CommandCSSetSuccessor(Module *creator, const Anope::string &cname = "chanserv/set/successor") : Command(creator, cname, 1, 2)
{
this->SetDesc(_("Set the successor for a channel"));
this->SetSyntax(_("\037channel\037 [\037nick\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -1010,7 +955,7 @@ class CommandCSSetSuccessor : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -1035,16 +980,17 @@ class CommandCSSetSuccessor : public Command
}
};
-class CommandCSSetNoexpire : public Command
+class CommandCSSetNoexpire final
+ : public Command
{
- public:
+public:
CommandCSSetNoexpire(Module *creator) : Command(creator, "chanserv/saset/noexpire", 2, 2)
{
this->SetDesc(_("Prevent the channel from expiring"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -1083,7 +1029,7 @@ class CommandCSSetNoexpire : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -1093,17 +1039,19 @@ class CommandCSSetNoexpire : public Command
}
};
-class CSSet : public Module
+class CSSet final
+ : public Module
{
SerializableExtensibleItem<bool> noautoop, peace, securefounder,
- restricted, secure, secureops, signkick, signkick_level, noexpire,
+ restricted, secureops, signkick, signkick_level, noexpire,
persist;
- struct KeepModes : SerializableExtensibleItem<bool>
+ struct KeepModes final
+ : SerializableExtensibleItem<bool>
{
KeepModes(Module *m, const Anope::string &n) : SerializableExtensibleItem<bool>(m, n) { }
- void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
+ void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
{
SerializableExtensibleItem<bool>::ExtensibleSerialize(e, s, data);
@@ -1112,18 +1060,18 @@ class CSSet : public Module
const ChannelInfo *ci = anope_dynamic_static_cast<const ChannelInfo *>(s);
Anope::string modes;
- for (Channel::ModeList::const_iterator it = ci->last_modes.begin(); it != ci->last_modes.end(); ++it)
+ for (const auto &[last_mode, last_value] : ci->last_modes)
{
if (!modes.empty())
modes += " ";
- modes += it->first;
- if (!it->second.empty())
- modes += "," + it->second;
+ modes += last_mode;
+ if (!last_value.empty())
+ modes += "," + last_value;
}
data["last_modes"] << modes;
}
- void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
+ void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
{
SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data);
@@ -1138,9 +1086,9 @@ class CSSet : public Module
{
size_t c = modes.find(',');
if (c == Anope::string::npos)
- ci->last_modes.insert(std::make_pair(modes, ""));
+ ci->last_modes.emplace(modes, "");
else
- ci->last_modes.insert(std::make_pair(modes.substr(0, c), modes.substr(c + 1)));
+ ci->last_modes.emplace(modes.substr(0, c), modes.substr(c + 1));
}
}
} keep_modes;
@@ -1154,7 +1102,6 @@ class CSSet : public Module
CommandCSSetPeace commandcssetpeace;
CommandCSSetPersist commandcssetpersist;
CommandCSSetRestricted commandcssetrestricted;
- CommandCSSetSecure commandcssetsecure;
CommandCSSetSecureFounder commandcssetsecurefounder;
CommandCSSetSecureOps commandcssetsecureops;
CommandCSSetSignKick commandcssetsignkick;
@@ -1165,11 +1112,11 @@ class CSSet : public Module
bool persist_lower_ts;
- public:
+public:
CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
noautoop(this, "NOAUTOOP"), peace(this, "PEACE"),
securefounder(this, "SECUREFOUNDER"), restricted(this, "RESTRICTED"),
- secure(this, "CS_SECURE"), secureops(this, "SECUREOPS"), signkick(this, "SIGNKICK"),
+ secureops(this, "SECUREOPS"), signkick(this, "SIGNKICK"),
signkick_level(this, "SIGNKICK_LEVEL"), noexpire(this, "CS_NO_EXPIRE"),
persist(this, "PERSIST"),
keep_modes(this, "CS_KEEP_MODES"),
@@ -1177,34 +1124,34 @@ class CSSet : public Module
commandcsset(this), commandcssetautoop(this), commandcssetbantype(this),
commandcssetdescription(this), commandcssetfounder(this), commandcssetkeepmodes(this),
commandcssetpeace(this), commandcssetpersist(this), commandcssetrestricted(this),
- commandcssetsecure(this), commandcssetsecurefounder(this), commandcssetsecureops(this), commandcssetsignkick(this),
+ commandcssetsecurefounder(this), commandcssetsecureops(this), commandcssetsignkick(this),
commandcssetsuccessor(this), commandcssetnoexpire(this),
inhabit("inhabit")
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
persist_lower_ts = conf->GetModule(this)->Get<bool>("persist_lower_ts");
}
- void OnCreateChan(ChannelInfo *ci) anope_override
+ void OnCreateChan(ChannelInfo *ci) override
{
ci->bantype = Config->GetModule(this)->Get<int>("defbantype", "2");
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (c->ci && keep_modes.HasExt(c->ci))
{
Channel::ModeList ml = c->ci->last_modes;
- for (Channel::ModeList::iterator it = ml.begin(); it != ml.end(); ++it)
- c->SetMode(c->ci->WhoSends(), it->first, it->second);
+ for (const auto &[last_mode, last_value] : c->ci->last_modes)
+ c->SetMode(c->ci->WhoSends(), last_mode, last_value);
}
}
- EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_override
+ EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
{
if (!c->ci || !restricted.HasExt(c->ci) || c->MatchesList(u, "EXCEPT"))
return EVENT_CONTINUE;
@@ -1215,14 +1162,14 @@ class CSSet : public Module
return EVENT_CONTINUE;
}
- void OnDelChan(ChannelInfo *ci) anope_override
+ void OnDelChan(ChannelInfo *ci) override
{
if (ci->c && persist.HasExt(ci))
ci->c->RemoveMode(ci->WhoSends(), "PERM", "", false);
persist.Unset(ci);
}
- EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) override
{
if (c->ci)
{
@@ -1237,7 +1184,7 @@ class CSSet : public Module
return EVENT_CONTINUE;
}
- EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override
+ EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) override
{
if (mode->name == "PERM")
{
@@ -1251,7 +1198,7 @@ class CSSet : public Module
return EVENT_CONTINUE;
}
- void OnJoinChannel(User *u, Channel *c) anope_override
+ void OnJoinChannel(User *u, Channel *c) override
{
if (u->server != Me && persist_lower_ts && c->ci && persist.HasExt(c->ci) && c->creation_time > c->ci->time_registered)
{
@@ -1262,7 +1209,7 @@ class CSSet : public Module
}
}
- void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) anope_override
+ void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override
{
if (chan->ci)
{
@@ -1274,13 +1221,13 @@ class CSSet : public Module
}
}
- void OnPreChanExpire(ChannelInfo *ci, bool &expire) anope_override
+ void OnPreChanExpire(ChannelInfo *ci, bool &expire) override
{
if (noexpire.HasExt(ci))
expire = false;
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override
{
if (!show_all)
return;
@@ -1289,8 +1236,6 @@ class CSSet : public Module
info.AddOption(_("Peace"));
if (restricted.HasExt(ci))
info.AddOption(_("Restricted access"));
- if (secure.HasExt(ci))
- info.AddOption(_("Security"));
if (securefounder.HasExt(ci))
info.AddOption(_("Secure founder"));
if (secureops.HasExt(ci))
diff --git a/modules/commands/cs_set_misc.cpp b/modules/chanserv/cs_set_misc.cpp
index bd1fbc3a4..685ab8022 100644
--- a/modules/commands/cs_set_misc.cpp
+++ b/modules/chanserv/cs_set_misc.cpp
@@ -21,7 +21,7 @@ static Anope::map<ExtensibleItem<CSMiscData> *> items;
static ExtensibleItem<CSMiscData> *GetItem(const Anope::string &name)
{
- ExtensibleItem<CSMiscData>* &it = items[name];
+ ExtensibleItem<CSMiscData> *&it = items[name];
if (!it)
try
{
@@ -31,7 +31,9 @@ static ExtensibleItem<CSMiscData> *GetItem(const Anope::string &name)
return it;
}
-struct CSMiscData : MiscData, Serializable
+struct CSMiscData final
+ : MiscData
+ , Serializable
{
CSMiscData(Extensible *obj) : Serializable("CSMiscData") { }
@@ -42,14 +44,14 @@ struct CSMiscData : MiscData, Serializable
data = d;
}
- void Serialize(Serialize::Data &sdata) const anope_override
+ void Serialize(Serialize::Data &sdata) const override
{
sdata["ci"] << this->object;
sdata["name"] << this->name;
sdata["data"] << this->data;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string sci, sname, sdata;
@@ -88,15 +90,16 @@ static Anope::string GetAttribute(const Anope::string &command)
return command;
}
-class CommandCSSetMisc : public Command
+class CommandCSSetMisc final
+ : public Command
{
- public:
+public:
CommandCSSetMisc(Module *creator, const Anope::string &cname = "chanserv/set/misc") : Command(creator, cname, 1, 2)
{
this->SetSyntax(_("\037channel\037 [\037parameters\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -143,7 +146,7 @@ class CommandCSSetMisc : public Command
}
}
- void OnServHelp(CommandSource &source) anope_override
+ void OnServHelp(CommandSource &source) override
{
if (descriptions.count(source.command))
{
@@ -152,7 +155,7 @@ class CommandCSSetMisc : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (descriptions.count(source.command))
{
@@ -164,25 +167,26 @@ class CommandCSSetMisc : public Command
}
};
-class CSSetMisc : public Module
+class CSSetMisc final
+ : public Module
{
CommandCSSetMisc commandcssetmisc;
Serialize::Type csmiscdata_type;
- public:
+public:
CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcssetmisc(this), csmiscdata_type("CSMiscData", CSMiscData::Unserialize)
{
me = this;
}
- ~CSSetMisc()
+ ~CSSetMisc() override
{
- for (Anope::map<ExtensibleItem<CSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it)
- delete it->second;
+ for (const auto &[_, item] : items)
+ delete item;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
descriptions.clear();
@@ -203,11 +207,10 @@ class CSSetMisc : public Module
}
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool) override
{
- for (Anope::map<ExtensibleItem<CSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it)
+ for (const auto &[_, e] : items)
{
- ExtensibleItem<CSMiscData> *e = it->second;
MiscData *data = e->Get(ci);
if (data != NULL)
diff --git a/modules/commands/cs_status.cpp b/modules/chanserv/cs_status.cpp
index f92a459ec..41c3590be 100644
--- a/modules/commands/cs_status.cpp
+++ b/modules/chanserv/cs_status.cpp
@@ -11,7 +11,8 @@
#include "module.h"
-class CommandCSStatus : public Command
+class CommandCSStatus final
+ : public Command
{
public:
CommandCSStatus(Module *creator) : Command(creator, "chanserv/status", 1, 2)
@@ -20,7 +21,7 @@ public:
this->SetSyntax(_("\037channel\037 [\037user\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &channel = params[0];
@@ -57,11 +58,9 @@ public:
{
source.Reply(_("Access for \002%s\002 on \002%s\002:"), nick.c_str(), ci->name.c_str());
- for (unsigned i = 0; i < ag.paths.size(); ++i)
+ for (const auto &p : ag.paths)
{
- ChanAccess::Path &p = ag.paths[i];
-
- if (p.empty())
+ if (p.empty())
continue;
if (p.size() == 1)
@@ -99,7 +98,7 @@ public:
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -112,11 +111,12 @@ public:
}
};
-class CSStatus : public Module
+class CSStatus final
+ : public Module
{
CommandCSStatus commandcsstatus;
- public:
+public:
CSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsstatus(this)
{
}
diff --git a/modules/cs_statusupdate.cpp b/modules/chanserv/cs_statusupdate.cpp
index 9b15edc84..ed7469501 100644
--- a/modules/cs_statusupdate.cpp
+++ b/modules/chanserv/cs_statusupdate.cpp
@@ -8,57 +8,60 @@
#include "module.h"
-class StatusUpdate : public Module
+class StatusUpdate final
+ : public Module
{
- public:
+public:
StatusUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
{
}
- void OnAccessAdd(ChannelInfo *ci, CommandSource &, ChanAccess *access) anope_override
+ void OnAccessAdd(ChannelInfo *ci, CommandSource &, ChanAccess *access) override
{
if (ci->c)
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ {
+ for (const auto &[_, uc] : ci->c->users)
{
- User *user = it->second->user;
+ User *user = uc->user;
ChannelInfo *next;
if (user->server != Me && access->Matches(user, user->Account(), next))
{
AccessGroup ag = ci->AccessFor(user);
- for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i)
+ for (auto *cms : ModeManager::GetStatusChannelModesByRank())
{
- ChannelModeStatus *cms = ModeManager::GetStatusChannelModesByRank()[i];
if (!ag.HasPriv("AUTO" + cms->name))
ci->c->RemoveMode(NULL, cms, user->GetUID());
}
ci->c->SetCorrectModes(user, true);
}
}
+ }
}
- void OnAccessDel(ChannelInfo *ci, CommandSource &, ChanAccess *access) anope_override
+ void OnAccessDel(ChannelInfo *ci, CommandSource &, ChanAccess *access) override
{
if (ci->c)
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ {
+ for (const auto &[_, uc] : ci->c->users)
{
- User *user = it->second->user;
+ User *user = uc->user;
ChannelInfo *next;
if (user->server != Me && access->Matches(user, user->Account(), next))
{
AccessGroup ag = ci->AccessFor(user);
- for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i)
+ for (auto *cms : ModeManager::GetStatusChannelModesByRank())
{
- ChannelModeStatus *cms = ModeManager::GetStatusChannelModesByRank()[i];
- if (!ag.HasPriv("AUTO" + cms->name))
+ if (!ag.HasPriv("AUTO" + cms->name))
ci->c->RemoveMode(NULL, cms, user->GetUID());
}
}
}
+ }
}
};
diff --git a/modules/commands/cs_suspend.cpp b/modules/chanserv/cs_suspend.cpp
index e4fc8afad..a30227d6a 100644
--- a/modules/commands/cs_suspend.cpp
+++ b/modules/chanserv/cs_suspend.cpp
@@ -12,11 +12,13 @@
#include "module.h"
#include "modules/suspend.h"
-struct CSSuspendInfo : SuspendInfo, Serializable
+struct CSSuspendInfo final
+ : SuspendInfo
+ , Serializable
{
CSSuspendInfo(Extensible *) : Serializable("CSSuspendInfo") { }
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["chan"] << what;
data["by"] << by;
@@ -25,7 +27,7 @@ struct CSSuspendInfo : SuspendInfo, Serializable
data["expires"] << expires;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string schan;
data["chan"] >> schan;
@@ -50,16 +52,17 @@ struct CSSuspendInfo : SuspendInfo, Serializable
}
};
-class CommandCSSuspend : public Command
+class CommandCSSuspend final
+ : public Command
{
- public:
+public:
CommandCSSuspend(Module *creator) : Command(creator, "chanserv/suspend", 2, 3)
{
this->SetDesc(_("Prevent a channel from being used preserving channel data and settings"));
this->SetSyntax(_("\037channel\037 [+\037expiry\037] [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
Anope::string expiry = params[1];
@@ -109,16 +112,15 @@ class CommandCSSuspend : public Command
{
std::vector<User *> users;
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : ci->c->users)
{
- ChanUserContainer *uc = it->second;
User *user = uc->user;
if (!user->HasMode("OPER") && user->server != Me)
users.push_back(user);
}
- for (unsigned i = 0; i < users.size(); ++i)
- ci->c->Kick(NULL, users[i], "%s", !reason.empty() ? reason.c_str() : Language::Translate(users[i], _("This channel has been suspended.")));
+ for (auto *user : users)
+ ci->c->Kick(NULL, user, "%s", !reason.empty() ? reason.c_str() : Language::Translate(user, _("This channel has been suspended.")));
}
Log(LOG_ADMIN, source, this, ci) << "(" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never");
@@ -127,7 +129,7 @@ class CommandCSSuspend : public Command
FOREACH_MOD(OnChanSuspend, (ci));
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -143,16 +145,17 @@ class CommandCSSuspend : public Command
}
};
-class CommandCSUnSuspend : public Command
+class CommandCSUnSuspend final
+ : public Command
{
- public:
+public:
CommandCSUnSuspend(Module *creator) : Command(creator, "chanserv/unsuspend", 1, 1)
{
this->SetDesc(_("Releases a suspended channel"));
this->SetSyntax(_("\037channel\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
@@ -184,7 +187,7 @@ class CommandCSUnSuspend : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -194,7 +197,8 @@ class CommandCSUnSuspend : public Command
}
};
-class CSSuspend : public Module
+class CSSuspend final
+ : public Module
{
CommandCSSuspend commandcssuspend;
CommandCSUnSuspend commandcsunsuspend;
@@ -202,7 +206,7 @@ class CSSuspend : public Module
Serialize::Type suspend_type;
std::vector<Anope::string> show;
- struct trim
+ struct trim final
{
Anope::string operator()(Anope::string s) const
{
@@ -215,21 +219,21 @@ class CSSuspend : public Module
return source.IsOper() || std::find(show.begin(), show.end(), what) != show.end();
}
- public:
+public:
CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcssuspend(this), commandcsunsuspend(this), suspend(this, "CS_SUSPENDED"),
suspend_type("CSSuspendInfo", CSSuspendInfo::Unserialize)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Anope::string s = conf->GetModule(this)->Get<Anope::string>("show");
commasepstream(s).GetTokens(show);
std::transform(show.begin(), show.end(), show.begin(), trim());
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) override
{
CSSuspendInfo *si = suspend.Get(ci);
if (!si)
@@ -247,7 +251,7 @@ class CSSuspend : public Module
info[_("Suspension expires")] = Anope::strftime(si->expires, source.GetAccount());
}
- void OnPreChanExpire(ChannelInfo *ci, bool &expire) anope_override
+ void OnPreChanExpire(ChannelInfo *ci, bool &expire) override
{
CSSuspendInfo *si = suspend.Get(ci);
if (!si)
@@ -267,7 +271,7 @@ class CSSuspend : public Module
}
}
- EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_override
+ EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
{
if (u->HasMode("OPER") || !c->ci || !suspend.HasExt(c->ci))
return EVENT_CONTINUE;
@@ -276,7 +280,7 @@ class CSSuspend : public Module
return EVENT_STOP;
}
- EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) anope_override
+ EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) override
{
CSSuspendInfo *si = suspend.Get(ci);
if (si && !source.HasCommand("chanserv/drop"))
diff --git a/modules/commands/cs_sync.cpp b/modules/chanserv/cs_sync.cpp
index ce139f21b..b76d2cef2 100644
--- a/modules/commands/cs_sync.cpp
+++ b/modules/chanserv/cs_sync.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandCSSync : public Command
+class CommandCSSync final
+ : public Command
{
- public:
+public:
CommandCSSync(Module *creator) : Command(creator, "chanserv/sync", 1, 1)
{
this->SetDesc(_("Sync users channel modes"));
this->SetSyntax(_("\037channel\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
@@ -35,14 +36,14 @@ class CommandCSSync : public Command
bool override = !source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/administration");
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci);
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
- ci->c->SetCorrectModes(it->second->user, true);
+ for (const auto &[_, uc] : ci->c->users)
+ ci->c->SetCorrectModes(uc->user, true);
source.Reply(_("All user modes on \002%s\002 have been synced."), ci->name.c_str());
}
}
- bool OnHelp(CommandSource &source, const Anope::string &params) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &params) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -52,10 +53,11 @@ class CommandCSSync : public Command
}
};
-class CSSync : public Module
+class CSSync final
+ : public Module
{
CommandCSSync commandcssync;
- public:
+public:
CSSync(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcssync(this)
{
diff --git a/modules/commands/cs_topic.cpp b/modules/chanserv/cs_topic.cpp
index 08e458d82..f21ea11f8 100644
--- a/modules/commands/cs_topic.cpp
+++ b/modules/chanserv/cs_topic.cpp
@@ -12,16 +12,17 @@
#include "module.h"
#include "modules/cs_mode.h"
-class CommandCSSetKeepTopic : public Command
+class CommandCSSetKeepTopic final
+ : public Command
{
- public:
+public:
CommandCSSetKeepTopic(Module *creator, const Anope::string &cname = "chanserv/set/keeptopic") : Command(creator, cname, 2, 2)
{
this->SetDesc(_("Retain topic when channel is not in use"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -63,7 +64,7 @@ class CommandCSSetKeepTopic : public Command
this->OnSyntaxError(source, "KEEPTOPIC");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -76,7 +77,8 @@ class CommandCSSetKeepTopic : public Command
}
};
-class CommandCSTopic : public Command
+class CommandCSTopic final
+ : public Command
{
ExtensibleRef<bool> topiclock;
@@ -142,7 +144,7 @@ class CommandCSTopic : public Command
this->Set(source, ci, new_topic);
}
- public:
+public:
CommandCSTopic(Module *creator) : Command(creator, "chanserv/topic", 2, 3),
topiclock("TOPICLOCK")
{
@@ -152,7 +154,7 @@ class CommandCSTopic : public Command
this->SetSyntax(_("\037channel\037 [UNLOCK|LOCK]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &subcmd = params[1];
@@ -186,7 +188,7 @@ class CommandCSTopic : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -202,21 +204,22 @@ class CommandCSTopic : public Command
}
};
-class CSTopic : public Module
+class CSTopic final
+ : public Module
{
CommandCSTopic commandcstopic;
CommandCSSetKeepTopic commandcssetkeeptopic;
SerializableExtensibleItem<bool> topiclock, keeptopic;
- public:
+public:
CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcstopic(this), commandcssetkeeptopic(this), topiclock(this, "TOPICLOCK"), keeptopic(this, "KEEPTOPIC")
{
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (c->ci)
{
@@ -228,7 +231,7 @@ class CSTopic : public Module
}
}
- void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) anope_override
+ void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) override
{
if (!c->ci)
return;
@@ -250,7 +253,7 @@ class CSTopic : public Module
}
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override
{
if (keeptopic.HasExt(ci))
info.AddOption(_("Topic retention"));
@@ -259,7 +262,7 @@ class CSTopic : public Module
ModeLocks *ml = ci->GetExt<ModeLocks>("modelocks");
const ModeLock *secret = ml ? ml->GetMLock("SECRET") : NULL;
- if (!ci->last_topic.empty() && (show_all || ((!secret || secret->set == false) && (!ci->c || !ci->c->HasMode("SECRET")))))
+ if (!ci->last_topic.empty() && (show_all || ((!secret || !secret->set) && (!ci->c || !ci->c->HasMode("SECRET")))))
{
info[_("Last topic")] = ci->last_topic;
info[_("Topic set by")] = ci->last_topic_setter;
diff --git a/modules/commands/cs_unban.cpp b/modules/chanserv/cs_unban.cpp
index 6cbbdd6e4..49495829b 100644
--- a/modules/commands/cs_unban.cpp
+++ b/modules/chanserv/cs_unban.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandCSUnban : public Command
+class CommandCSUnban final
+ : public Command
{
- public:
+public:
CommandCSUnban(Module *creator) : Command(creator, "chanserv/unban", 0, 2)
{
this->SetDesc(_("Remove all bans preventing a user from entering a channel"));
this->SetSyntax(_("\037channel\037 [\037nick\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelMode *cm = ModeManager::FindChannelModeByName("BAN");
if (!cm)
@@ -38,17 +39,20 @@ class CommandCSUnban : public Command
source.GetAccount()->GetChannelReferences(queue);
unsigned count = 0;
- for (unsigned i = 0; i < queue.size(); ++i)
+ for (auto *ci : queue)
{
- ChannelInfo *ci = queue[i];
+ if (!ci->c || !(source.AccessFor(ci).HasPriv("UNBAN") || source.AccessFor(ci).HasPriv("UNBANME")))
+ continue;
- if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN"))
+ if (IRCD->CanClearBans)
+ {
+ IRCD->SendClearBans(ci->WhoSends(), ci->c, source.GetUser());
+ count++;
continue;
-
- FOREACH_MOD(OnChannelUnban, (source.GetUser(), ci));
+ }
- for (unsigned j = 0; j < modes.size(); ++j)
- if (ci->c->Unban(source.GetUser(), modes[j]->name, true))
+ for (const auto *mode : modes)
+ if (ci->c->Unban(source.GetUser(), mode->name, true))
++count;
}
@@ -71,12 +75,6 @@ class CommandCSUnban : public Command
return;
}
- if (!source.AccessFor(ci).HasPriv("UNBAN") && !source.HasPriv("chanserv/kick"))
- {
- source.Reply(ACCESS_DENIED);
- return;
- }
-
User *u2 = source.GetUser();
if (params.size() > 1)
u2 = User::Find(params[1], true);
@@ -87,20 +85,33 @@ class CommandCSUnban : public Command
return;
}
+ if (!source.AccessFor(ci).HasPriv("UNBAN") &&
+ (u2 != source.GetUser() || !source.AccessFor(ci).HasPriv("UNBANME")) &&
+ !source.HasPriv("chanserv/kick"))
+ {
+ source.Reply(ACCESS_DENIED);
+ return;
+ }
+
bool override = !source.AccessFor(ci).HasPriv("UNBAN") && source.HasPriv("chanserv/kick");
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to unban " << u2->nick;
- FOREACH_MOD(OnChannelUnban, (u2, ci));
- for (unsigned i = 0; i < modes.size(); ++i)
- ci->c->Unban(u2, modes[i]->name, source.GetUser() == u2);
+ if (IRCD->CanClearBans)
+ IRCD->SendClearBans(ci->WhoSends(), ci->c, source.GetUser());
+ else
+ {
+ for (const auto *mode : modes)
+ ci->c->Unban(u2, mode->name, source.GetUser() == u2);
+ }
+
if (u2 == source.GetUser())
source.Reply(_("You have been unbanned from \002%s\002."), ci->c->name.c_str());
else
source.Reply(_("\002%s\002 has been unbanned from \002%s\002."), u2->nick.c_str(), ci->c->name.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -115,11 +126,12 @@ class CommandCSUnban : public Command
}
};
-class CSUnban : public Module
+class CSUnban final
+ : public Module
{
CommandCSUnban commandcsunban;
- public:
+public:
CSUnban(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsunban(this)
{
diff --git a/modules/commands/cs_updown.cpp b/modules/chanserv/cs_updown.cpp
index 2b824934e..76db3452a 100644
--- a/modules/commands/cs_updown.cpp
+++ b/modules/chanserv/cs_updown.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandCSUp : public Command
+class CommandCSUp final
+ : public Command
{
- void SetModes(User *u, Channel *c)
+ static void SetModes(User *u, Channel *c)
{
if (!c->ci)
return;
@@ -24,9 +25,8 @@ class CommandCSUp : public Command
bool given = false;
AccessGroup u_access = c->ci->AccessFor(u);
- for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i)
+ for (auto *cm : ModeManager::GetStatusChannelModesByRank())
{
- ChannelModeStatus *cm = ModeManager::GetStatusChannelModesByRank()[i];
bool has_priv = u_access.HasPriv("AUTO" + cm->name) || u_access.HasPriv(cm->name);
if (has_priv)
@@ -42,14 +42,14 @@ class CommandCSUp : public Command
}
}
}
- public:
+public:
CommandCSUp(Module *creator) : Command(creator, "chanserv/up", 0, 2)
{
this->SetDesc(_("Updates a selected nicks status on a channel"));
this->SetSyntax(_("[\037channel\037 [\037nick\037]]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (params.empty())
{
@@ -119,7 +119,7 @@ class CommandCSUp : public Command
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -130,9 +130,10 @@ class CommandCSUp : public Command
}
};
-class CommandCSDown : public Command
+class CommandCSDown final
+ : public Command
{
- void RemoveAll(User *u, Channel *c)
+ static void RemoveAll(User *u, Channel *c)
{
ChanUserContainer *cu = c->FindUser(u);
if (cu != NULL)
@@ -140,14 +141,14 @@ class CommandCSDown : public Command
c->RemoveMode(NULL, ModeManager::FindChannelModeByChar(cu->status.Modes()[--i]), u->GetUID());
}
- public:
+public:
CommandCSDown(Module *creator) : Command(creator, "chanserv/down", 0, 2)
{
this->SetDesc(_("Removes a selected nicks status from a channel"));
this->SetSyntax(_("[\037channel\037 [\037nick\037]]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (params.empty())
{
@@ -216,7 +217,7 @@ class CommandCSDown : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -227,12 +228,13 @@ class CommandCSDown : public Command
}
};
-class CSUpDown : public Module
+class CSUpDown final
+ : public Module
{
CommandCSUp commandcsup;
CommandCSDown commandcsdown;
- public:
+public:
CSUpDown(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandcsup(this), commandcsdown(this)
{
diff --git a/modules/commands/cs_xop.cpp b/modules/chanserv/cs_xop.cpp
index 72c7b686c..0ec8e8d25 100644
--- a/modules/commands/cs_xop.cpp
+++ b/modules/chanserv/cs_xop.cpp
@@ -17,16 +17,17 @@ namespace
std::map<Anope::string, std::vector<Anope::string> > permissions;
}
-class XOPChanAccess : public ChanAccess
+class XOPChanAccess final
+ : public ChanAccess
{
- public:
+public:
Anope::string type;
XOPChanAccess(AccessProvider *p) : ChanAccess(p)
{
}
- bool HasPriv(const Anope::string &priv) const anope_override
+ bool HasPriv(const Anope::string &priv) const override
{
for (std::vector<Anope::string>::iterator it = std::find(order.begin(), order.end(), this->type); it != order.end(); ++it)
{
@@ -37,12 +38,12 @@ class XOPChanAccess : public ChanAccess
return false;
}
- Anope::string AccessSerialize() const anope_override
+ Anope::string AccessSerialize() const override
{
return this->type;
}
- void AccessUnserialize(const Anope::string &data) anope_override
+ void AccessUnserialize(const Anope::string &data) override
{
this->type = data;
}
@@ -58,48 +59,54 @@ class XOPChanAccess : public ChanAccess
{
std::map<Anope::string, int> count;
- for (std::map<Anope::string, std::vector<Anope::string> >::const_iterator it = permissions.begin(), it_end = permissions.end(); it != it_end; ++it)
+ for (const auto &[name, perms] : permissions)
{
- int &c = count[it->first];
- const std::vector<Anope::string> &perms = it->second;
- for (unsigned i = 0; i < perms.size(); ++i)
- if (access->HasPriv(perms[i]))
+ int &c = count[name];
+ for (const auto &perm : perms)
+ {
+ if (access->HasPriv(perm))
++c;
+ }
}
- Anope::string max;
- int maxn = 0;
- for (std::map<Anope::string, int>::iterator it = count.begin(), it_end = count.end(); it != it_end; ++it)
- if (it->second > maxn)
+ Anope::string maxname;
+ int maxpriv = 0;
+ for (const auto &[name, priv] : count)
+ {
+ if (priv > maxpriv)
{
- maxn = it->second;
- max = it->first;
+ maxname = name;
+ maxpriv = priv;
}
+ }
- return max;
+ return maxname;
}
}
};
-class XOPAccessProvider : public AccessProvider
+class XOPAccessProvider final
+ : public AccessProvider
{
- public:
+public:
XOPAccessProvider(Module *o) : AccessProvider(o, "access/xop")
{
}
- ChanAccess *Create() anope_override
+ ChanAccess *Create() override
{
return new XOPChanAccess(this);
}
};
-class CommandCSXOP : public Command
+class CommandCSXOP final
+ : public Command
{
- private:
+private:
void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
Anope::string mask = params.size() > 2 ? params[2] : "";
+ Anope::string description = params.size() > 3 ? params[3] : "";
if (mask.empty())
{
@@ -162,6 +169,12 @@ class CommandCSXOP : public Command
source.Reply(_("Masks and unregistered users may not be on access lists."));
return;
}
+ else if (na && na->nc->HasExt("NEVEROP"))
+ {
+ source.Reply(_("\002%s\002 does not wish to be added to channel access lists."),
+ na->nc->display.c_str());
+ return;
+ }
else if (mask.find_first_of("!*@") == Anope::string::npos && !na)
{
User *targ = User::Find(mask, true);
@@ -195,7 +208,7 @@ class CommandCSXOP : public Command
}
}
- unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
+ unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1000");
if (access_max && ci->GetDeepAccessCount() >= access_max)
{
source.Reply(_("Sorry, you can only have %d access entries on a channel, including access entries from other channels."), access_max);
@@ -208,6 +221,7 @@ class CommandCSXOP : public Command
XOPChanAccess *acc = anope_dynamic_static_cast<XOPChanAccess *>(provider->Create());
acc->SetMask(mask, ci);
acc->creator = source.GetNick();
+ acc->description = description;
acc->type = source.command.upper();
acc->last_seen = 0;
acc->created = Anope::CurTime;
@@ -280,20 +294,21 @@ class CommandCSXOP : public Command
/* Special case: is it a number/list? Only do search if it isn't. */
if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class XOPDelCallback : public NumberList
+ class XOPDelCallback final
+ : public NumberList
{
CommandSource &source;
ChannelInfo *ci;
Command *c;
- unsigned deleted;
+ unsigned deleted = 0;
Anope::string nicks;
bool override;
- public:
- XOPDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, bool _override, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), deleted(0), override(_override)
+ public:
+ XOPDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, bool _override, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), override(_override)
{
}
- ~XOPDelCallback()
+ ~XOPDelCallback() override
{
if (!deleted)
source.Reply(_("No matching entries on %s %s list."), ci->name.c_str(), source.command.c_str());
@@ -308,7 +323,7 @@ class CommandCSXOP : public Command
}
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > ci->GetAccessCount())
return;
@@ -379,21 +394,22 @@ class CommandCSXOP : public Command
}
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Mask"));
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Description"));
if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class XOPListCallback : public NumberList
+ class XOPListCallback final
+ : public NumberList
{
ListFormatter &list;
ChannelInfo *ci;
CommandSource &source;
- public:
+ public:
XOPListCallback(ListFormatter &_list, ChannelInfo *_ci, const Anope::string &numlist, CommandSource &src) : NumberList(numlist, false), list(_list), ci(_ci), source(src)
{
}
- void HandleNumber(unsigned Number) anope_override
+ void HandleNumber(unsigned Number) override
{
if (!Number || Number > ci->GetAccessCount())
return;
@@ -404,8 +420,9 @@ class CommandCSXOP : public Command
return;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(Number);
+ entry["Number"] = Anope::ToString(Number);
entry["Mask"] = a->Mask();
+ entry["Description"] = a->description;
this->list.AddEntry(entry);
}
} nl_list(list, ci, nick, source);
@@ -423,8 +440,9 @@ class CommandCSXOP : public Command
continue;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Mask"] = a->Mask();
+ entry["Description"] = a->description;
list.AddEntry(entry);
}
}
@@ -437,8 +455,8 @@ class CommandCSXOP : public Command
list.Process(replies);
source.Reply(_("%s list for %s"), source.command.c_str(), ci->name.c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
@@ -480,21 +498,21 @@ class CommandCSXOP : public Command
source.Reply(_("Channel %s %s list has been cleared."), ci->name.c_str(), source.command.c_str());
}
- public:
+public:
CommandCSXOP(Module *modname) : Command(modname, "chanserv/xop", 2, 4)
{
- this->SetSyntax(_("\037channel\037 ADD \037mask\037"));
+ this->SetSyntax(_("\037channel\037 ADD \037mask\037 [\037description\037]"));
this->SetSyntax(_("\037channel\037 DEL {\037mask\037 | \037entry-num\037 | \037list\037}"));
this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | \037list\037]"));
this->SetSyntax(_("\037channel\037 CLEAR"));
}
- const Anope::string GetDesc(CommandSource &source) const anope_override
+ const Anope::string GetDesc(CommandSource &source) const override
{
return Anope::printf(Language::Translate(source.GetAccount(), _("Modify the list of %s users")), source.command.upper().c_str());
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
if (ci == NULL)
@@ -518,7 +536,7 @@ class CommandCSXOP : public Command
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
const Anope::string &cmd = source.command.upper();
@@ -529,9 +547,9 @@ class CommandCSXOP : public Command
" "), cmd.c_str(), cmd.c_str());
Anope::string buf;
- for (unsigned i = 0; i < permissions[cmd].size(); ++i)
+ for (const auto &permission : permissions[cmd])
{
- buf += ", " + permissions[cmd][i];
+ buf += ", " + permission;
if (buf.length() > 75)
{
source.Reply(" %s\n", buf.substr(2).c_str());
@@ -582,12 +600,13 @@ class CommandCSXOP : public Command
}
};
-class CSXOP : public Module
+class CSXOP final
+ : public Module
{
XOPAccessProvider accessprovider;
CommandCSXOP commandcsxop;
- public:
+public:
CSXOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
accessprovider(this), commandcsxop(this)
{
@@ -595,7 +614,7 @@ class CSXOP : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
order.clear();
permissions.clear();
diff --git a/modules/extra/stats/m_chanstats.cpp b/modules/chanstats.cpp
index b23e65859..81c826739 100644
--- a/modules/extra/stats/m_chanstats.cpp
+++ b/modules/chanstats.cpp
@@ -9,16 +9,17 @@
#include "module.h"
#include "modules/sql.h"
-class CommandCSSetChanstats : public Command
+class CommandCSSetChanstats final
+ : public Command
{
- public:
+public:
CommandCSSetChanstats(Module *creator) : Command(creator, "chanserv/set/chanstats", 2, 2)
{
this->SetDesc(_("Turn chanstats statistics on or off"));
this->SetSyntax(_("\037channel\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
if (!ci)
@@ -54,7 +55,7 @@ class CommandCSSetChanstats : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -63,9 +64,10 @@ class CommandCSSetChanstats : public Command
}
};
-class CommandNSSetChanstats : public Command
+class CommandNSSetChanstats
+ : public Command
{
- public:
+public:
CommandNSSetChanstats(Module *creator, const Anope::string &sname = "nickserv/set/chanstats", size_t min = 1 ) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Turn chanstats statistics on or off"));
@@ -107,12 +109,12 @@ class CommandNSSetChanstats : public Command
this->OnSyntaxError(source, "CHANSTATS");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -121,21 +123,22 @@ class CommandNSSetChanstats : public Command
}
};
-class CommandNSSASetChanstats : public CommandNSSetChanstats
+class CommandNSSASetChanstats final
+ : public CommandNSSetChanstats
{
- public:
+public:
CommandNSSASetChanstats(Module *creator) : CommandNSSetChanstats(creator, "nickserv/saset/chanstats", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1], true);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -144,16 +147,17 @@ class CommandNSSASetChanstats : public CommandNSSetChanstats
}
};
-class MySQLInterface : public SQL::Interface
+class MySQLInterface final
+ : public SQL::Interface
{
- public:
+public:
MySQLInterface(Module *o) : SQL::Interface(o) { }
- void OnResult(const SQL::Result &r) anope_override
+ void OnResult(const SQL::Result &r) override
{
}
- void OnError(const SQL::Result &r) anope_override
+ void OnError(const SQL::Result &r) override
{
if (!r.GetQuery().query.empty())
Log(LOG_DEBUG) << "Chanstats: Error executing query " << r.finished_query << ": " << r.GetError();
@@ -162,7 +166,8 @@ class MySQLInterface : public SQL::Interface
}
};
-class MChanstats : public Module
+class MChanstats final
+ : public Module
{
SerializableExtensibleItem<bool> cs_stats, ns_stats;
@@ -184,14 +189,14 @@ class MChanstats : public Module
sql->Run(&sqlinterface, q);
}
- size_t CountWords(const Anope::string &msg)
+ static size_t CountWords(const Anope::string &msg)
{
size_t words = 0;
for (size_t pos = 0; pos != Anope::string::npos; pos = msg.find(" ", pos+1))
words++;
return words;
}
- size_t CountSmileys(const Anope::string &msg, const Anope::string &smileylist)
+ static size_t CountSmileys(const Anope::string &msg, const Anope::string &smileylist)
{
size_t smileys = 0;
spacesepstream sep(smileylist);
@@ -205,7 +210,7 @@ class MChanstats : public Module
return smileys;
}
- const Anope::string GetDisplay(User *u)
+ Anope::string GetDisplay(User *u)
{
if (u && u->Account() && ns_stats.HasExt(u->Account()))
return u->Account()->display;
@@ -483,7 +488,7 @@ class MChanstats : public Module
}
- public:
+public:
MChanstats(const Anope::string &modname, const Anope::string &creator) :
Module(modname, creator, EXTRA | VENDOR),
cs_stats(this, "CS_STATS"), ns_stats(this, "NS_STATS"),
@@ -492,7 +497,7 @@ class MChanstats : public Module
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
prefix = block->Get<const Anope::string>("prefix", "anope_");
@@ -509,7 +514,7 @@ class MChanstats : public Module
Log(this) << "no database connection to " << engine;
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override
{
if (!show_all)
return;
@@ -517,7 +522,7 @@ class MChanstats : public Module
info.AddOption(_("Chanstats"));
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override
{
if (!show_hidden)
return;
@@ -525,7 +530,7 @@ class MChanstats : public Module
info.AddOption(_("Chanstats"));
}
- void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) anope_override
+ void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) override
{
if (!source || !source->Account() || !c->ci || !cs_stats.HasExt(c->ci))
return;
@@ -535,19 +540,19 @@ class MChanstats : public Module
this->RunQuery(query);
}
- EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) override
{
this->OnModeChange(c, setter.GetUser());
return EVENT_CONTINUE;
}
- EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *, const Anope::string &param) anope_override
+ EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *, const Anope::string &param) override
{
this->OnModeChange(c, setter.GetUser());
return EVENT_CONTINUE;
}
- private:
+private:
void OnModeChange(Channel *c, User *u)
{
if (!u || !u->Account() || !c->ci || !cs_stats.HasExt(c->ci))
@@ -559,8 +564,8 @@ class MChanstats : public Module
this->RunQuery(query);
}
- public:
- void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) anope_override
+public:
+ void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) override
{
if (!cu->chan->ci || !cs_stats.HasExt(cu->chan->ci))
return;
@@ -576,7 +581,7 @@ class MChanstats : public Module
this->RunQuery(query);
}
- void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_override
+ void OnPrivmsg(User *u, Channel *c, Anope::string &msg, const Anope::map<Anope::string> &tags) override
{
if (!c->ci || !cs_stats.HasExt(c->ci))
return;
@@ -617,14 +622,14 @@ class MChanstats : public Module
this->RunQuery(query);
}
- void OnDelCore(NickCore *nc) anope_override
+ void OnDelCore(NickCore *nc) override
{
query = "DELETE FROM `" + prefix + "chanstats` WHERE `nick` = @nick@;";
query.SetValue("nick", nc->display);
this->RunQuery(query);
}
- void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) anope_override
+ void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) override
{
query = "CALL " + prefix + "chanstats_proc_chgdisplay(@old_display@, @new_display@);";
query.SetValue("old_display", nc->display);
@@ -632,20 +637,20 @@ class MChanstats : public Module
this->RunQuery(query);
}
- void OnDelChan(ChannelInfo *ci) anope_override
+ void OnDelChan(ChannelInfo *ci) override
{
query = "DELETE FROM `" + prefix + "chanstats` WHERE `chan` = @channel@;";
query.SetValue("channel", ci->name);
this->RunQuery(query);
}
- void OnChanRegistered(ChannelInfo *ci)
+ void OnChanRegistered(ChannelInfo *ci) override
{
if (CSDefChanstats)
ci->Extend<bool>("CS_STATS");
}
- void OnNickRegister(User *user, NickAlias *na, const Anope::string &)
+ void OnNickRegister(User *user, NickAlias *na, const Anope::string &) override
{
if (NSDefChanstats)
na->nc->Extend<bool>("NS_STATS");
diff --git a/modules/commands/ns_access.cpp b/modules/commands/ns_access.cpp
deleted file mode 100644
index ad919548b..000000000
--- a/modules/commands/ns_access.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/* NickServ core functions
- *
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "module.h"
-
-class CommandNSAccess : public Command
-{
- private:
- void DoAdd(CommandSource &source, NickCore *nc, const Anope::string &mask)
- {
- if (mask.empty())
- {
- this->OnSyntaxError(source, "ADD");
- return;
- }
-
- if (Anope::ReadOnly)
- {
- source.Reply(READ_ONLY_MODE);
- return;
- }
-
- if (nc->access.size() >= Config->GetModule(this->owner)->Get<unsigned>("accessmax", "32"))
- {
- source.Reply(_("Sorry, the maximum of %d access entries has been reached."), Config->GetModule(this->owner)->Get<unsigned>("accessmax"));
- return;
- }
-
- if (nc->FindAccess(mask))
- {
- source.Reply(_("Mask \002%s\002 already present on %s's access list."), mask.c_str(), nc->display.c_str());
- return;
- }
-
- nc->AddAccess(mask);
- Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to ADD mask " << mask << " to " << nc->display;
- source.Reply(_("\002%s\002 added to %s's access list."), mask.c_str(), nc->display.c_str());
-
- return;
- }
-
- void DoDel(CommandSource &source, NickCore *nc, const Anope::string &mask)
- {
- if (mask.empty())
- {
- this->OnSyntaxError(source, "DEL");
- return;
- }
-
- if (Anope::ReadOnly)
- {
- source.Reply(READ_ONLY_MODE);
- return;
- }
-
- if (!nc->FindAccess(mask))
- {
- source.Reply(_("\002%s\002 not found on %s's access list."), mask.c_str(), nc->display.c_str());
- return;
- }
-
- nc->EraseAccess(mask);
- Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to DELETE mask " << mask << " from " << nc->display;
- source.Reply(_("\002%s\002 deleted from %s's access list."), mask.c_str(), nc->display.c_str());
-
- return;
- }
-
- void DoList(CommandSource &source, NickCore *nc, const Anope::string &mask)
- {
- unsigned i, end;
-
- if (nc->access.empty())
- {
- source.Reply(_("%s's access list is empty."), nc->display.c_str());
- return;
- }
-
- source.Reply(_("Access list for %s:"), nc->display.c_str());
- for (i = 0, end = nc->access.size(); i < end; ++i)
- {
- Anope::string access = nc->GetAccess(i);
- if (!mask.empty() && !Anope::Match(access, mask))
- continue;
- source.Reply(" %s", access.c_str());
- }
-
- return;
- }
- public:
- CommandNSAccess(Module *creator) : Command(creator, "nickserv/access", 1, 3)
- {
- this->SetDesc(_("Modify the list of authorized addresses"));
- this->SetSyntax(_("ADD [\037nickname\037] \037mask\037"));
- this->SetSyntax(_("DEL [\037nickname\037] \037mask\037"));
- this->SetSyntax(_("LIST [\037nickname\037]"));
- }
-
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
- {
- const Anope::string &cmd = params[0];
- Anope::string nick, mask;
-
- if (cmd.equals_ci("LIST"))
- nick = params.size() > 1 ? params[1] : "";
- else
- {
- nick = params.size() == 3 ? params[1] : "";
- mask = params.size() > 1 ? params[params.size() - 1] : "";
- }
-
- NickCore *nc;
- if (!nick.empty())
- {
- const NickAlias *na = NickAlias::Find(nick);
- if (na == NULL)
- {
- source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
- return;
- }
- else if (na->nc != source.GetAccount() && !source.HasPriv("nickserv/access"))
- {
- source.Reply(ACCESS_DENIED);
- return;
- }
- else if (Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && source.GetAccount() != na->nc && na->nc->IsServicesOper() && !cmd.equals_ci("LIST"))
- {
- source.Reply(_("You may view but not modify the access list of other Services Operators."));
- return;
- }
-
- nc = na->nc;
- }
- else
- nc = source.nc;
-
- if (!mask.empty() && (mask.find('@') == Anope::string::npos || mask.find('!') != Anope::string::npos))
- {
- source.Reply(BAD_USERHOST_MASK);
- source.Reply(MORE_INFO, Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), source.command.c_str());
- }
- else if (cmd.equals_ci("LIST"))
- return this->DoList(source, nc, mask);
- else if (nc->HasExt("NS_SUSPENDED"))
- source.Reply(NICK_X_SUSPENDED, nc->display.c_str());
- else if (cmd.equals_ci("ADD"))
- return this->DoAdd(source, nc, mask);
- else if (cmd.equals_ci("DEL"))
- return this->DoDel(source, nc, mask);
- else
- this->OnSyntaxError(source, "");
- }
-
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
- {
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Modifies or displays the access list for your nick. This\n"
- "is the list of addresses which will be automatically\n"
- "recognized by %s as allowed to use the nick. If\n"
- "you want to use the nick from a different address, you\n"
- "need to send an \002IDENTIFY\002 command to make %s\n"
- "recognize you. Services Operators may provide a nick\n"
- "to modify other users' access lists.\n"
- " \n"
- "Examples:\n"
- " \n"
- " \002ACCESS ADD anyone@*.bepeg.com\002\n"
- " Allows access to user \002anyone\002 from any machine in\n"
- " the \002bepeg.com\002 domain.\n"
- " \n"
- " \002ACCESS DEL anyone@*.bepeg.com\002\n"
- " Reverses the previous command.\n"
- " \n"
- " \002ACCESS LIST\002\n"
- " Displays the current access list."), source.service->nick.c_str(), source.service->nick.c_str());
- return true;
- }
-};
-
-class NSAccess : public Module
-{
- CommandNSAccess commandnsaccess;
-
- public:
- NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandnsaccess(this)
- {
- }
-
- void OnNickRegister(User *u, NickAlias *na, const Anope::string &) anope_override
- {
- if (u && Config->GetModule(this)->Get<bool>("addaccessonreg"))
- na->nc->AddAccess(u->Mask());
- }
-};
-
-MODULE_INIT(NSAccess)
diff --git a/modules/commands/ns_getpass.cpp b/modules/commands/ns_getpass.cpp
deleted file mode 100644
index 3dd8a5845..000000000
--- a/modules/commands/ns_getpass.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/* NickServ core functions
- *
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "module.h"
-
-class CommandNSGetPass : public Command
-{
- public:
- CommandNSGetPass(Module *creator) : Command(creator, "nickserv/getpass", 1, 1)
- {
- this->SetDesc(_("Retrieve the password for a nickname"));
- this->SetSyntax(_("\037nickname\037"));
- }
-
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
- {
- const Anope::string &nick = params[0];
- Anope::string tmp_pass;
- const NickAlias *na;
-
- if (!(na = NickAlias::Find(nick)))
- source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
- else if (Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && na->nc->IsServicesOper())
- source.Reply(_("You may not get the password of other Services Operators."));
- else
- {
- if (Anope::Decrypt(na->nc->pass, tmp_pass) == 1)
- {
- Log(LOG_ADMIN, source, this) << "for " << nick;
- source.Reply(_("Password for %s is \002%s\002."), nick.c_str(), tmp_pass.c_str());
- }
- else
- source.Reply(_("GETPASS command unavailable because encryption is in use."));
- }
- return;
- }
-
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
- {
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Returns the password for the given nickname. \002Note\002 that\n"
- "whenever this command is used, a message including the\n"
- "person who issued the command and the nickname it was used\n"
- "on will be logged and sent out as a WALLOPS/GLOBOPS."));
- return true;
- }
-};
-
-class NSGetPass : public Module
-{
- CommandNSGetPass commandnsgetpass;
-
- public:
- NSGetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandnsgetpass(this)
- {
-
- Anope::string tmp_pass = "plain:tmp";
- if (!Anope::Decrypt(tmp_pass, tmp_pass))
- throw ModuleException("Incompatible with the encryption module being used");
-
- }
-};
-
-MODULE_INIT(NSGetPass)
diff --git a/modules/commands/ns_status.cpp b/modules/commands/ns_status.cpp
deleted file mode 100644
index d0e15cc92..000000000
--- a/modules/commands/ns_status.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/* NickServ core functions
- *
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "module.h"
-
-class CommandNSStatus : public Command
-{
- public:
- CommandNSStatus(Module *creator) : Command(creator, "nickserv/status", 0, 16)
- {
- this->SetDesc(_("Returns the owner status of the given nickname"));
- this->SetSyntax(_("[\037nickname\037]"));
- this->AllowUnregistered(true);
- }
-
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
- {
- const Anope::string &nick = !params.empty() ? params[0] : source.GetNick();
- const NickAlias *na = NickAlias::Find(nick);
- spacesepstream sep(nick);
- Anope::string nickbuf;
-
- while (sep.GetToken(nickbuf))
- {
- User *u2 = User::Find(nickbuf, true);
- if (!u2) /* Nick is not online */
- source.Reply("STATUS %s %d %s", nickbuf.c_str(), 0, "");
- else if (u2->IsIdentified() && na && na->nc == u2->Account()) /* Nick is identified */
- source.Reply("STATUS %s %d %s", nickbuf.c_str(), 3, u2->Account()->display.c_str());
- else if (u2->IsRecognized()) /* Nick is recognised, but NOT identified */
- source.Reply("STATUS %s %d %s", nickbuf.c_str(), 2, u2->Account() ? u2->Account()->display.c_str() : "");
- else if (!na) /* Nick is online, but NOT a registered */
- source.Reply("STATUS %s %d %s", nickbuf.c_str(), 0, "");
- else
- /* Nick is not identified for the nick, but they could be logged into an account,
- * so we tell the user about it
- */
- source.Reply("STATUS %s %d %s", nickbuf.c_str(), 1, u2->Account() ? u2->Account()->display.c_str() : "");
- }
- return;
- }
-
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
- {
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Returns whether the user using the given nickname is\n"
- "recognized as the owner of the nickname. The response has\n"
- "this format:\n"
- " \n"
- " \037nickname\037 \037status-code\037 \037account\037\n"
- " \n"
- "where \037nickname\037 is the nickname sent with the command,\n"
- "\037status-code\037 is one of the following, and \037account\037\n"
- "is the account they are logged in as.\n"
- " \n"
- " 0 - no such user online \002or\002 nickname not registered\n"
- " 1 - user not recognized as nickname's owner\n"
- " 2 - user recognized as owner via access list only\n"
- " 3 - user recognized as owner via password identification\n"
- " \n"
- "If no nickname is given, your status will be returned."));
- return true;
- }
-};
-
-class NSStatus : public Module
-{
- CommandNSStatus commandnsstatus;
-
- public:
- NSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandnsstatus(this)
- {
-
- }
-};
-
-MODULE_INIT(NSStatus)
diff --git a/modules/commands/os_oline.cpp b/modules/commands/os_oline.cpp
deleted file mode 100644
index 5af590aa8..000000000
--- a/modules/commands/os_oline.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/* OperServ core functions
- *
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "module.h"
-
-class CommandOSOLine : public Command
-{
- public:
- CommandOSOLine(Module *creator) : Command(creator, "operserv/oline", 2, 2)
- {
- this->SetDesc(_("Give Operflags to a certain user"));
- this->SetSyntax(_("\037nick\037 \037flags\037"));
- }
-
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
- {
- const Anope::string &nick = params[0];
- const Anope::string &flag = params[1];
- User *u2 = NULL;
-
- /* let's check whether the user is online */
- if (!(u2 = User::Find(nick, true)))
- source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
- else if (u2 && flag[0] == '+')
- {
- IRCD->SendSVSO(source.service, nick, flag);
- u2->SetMode(source.service, "OPER");
- u2->SendMessage(source.service, _("You are now an IRC Operator."));
- source.Reply(_("Operflags \002%s\002 have been added for \002%s\002."), flag.c_str(), nick.c_str());
- Log(LOG_ADMIN, source, this) << "for " << nick;
- }
- else if (u2 && flag[0] == '-')
- {
- IRCD->SendSVSO(source.service, nick, flag);
- source.Reply(_("Operflags \002%s\002 have been removed from \002%s\002."), flag.c_str(), nick.c_str());
- Log(LOG_ADMIN, source, this) << "for " << nick;
- }
- else
- this->OnSyntaxError(source, "");
-
- return;
- }
-
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
- {
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Allows Services Operators to give Operflags to any user.\n"
- "Flags have to be prefixed with a \"+\" or a \"-\". To\n"
- "remove all flags simply type a \"-\" instead of any flags."));
- return true;
- }
-};
-
-class OSOLine : public Module
-{
- CommandOSOLine commandosoline;
-
- public:
- OSOLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandosoline(this)
- {
-
- if (!IRCD || !IRCD->CanSVSO)
- throw ModuleException("Your IRCd does not support OMODE.");
-
- }
-};
-
-MODULE_INIT(OSOLine)
diff --git a/modules/database/db_atheme.cpp b/modules/database/db_atheme.cpp
new file mode 100644
index 000000000..3f62c29ca
--- /dev/null
+++ b/modules/database/db_atheme.cpp
@@ -0,0 +1,1429 @@
+/*
+ *
+ * (C) 2003-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include <functional>
+
+#include "module.h"
+#include "modules/bs_badwords.h"
+#include "modules/bs_kick.h"
+#include "modules/cs_entrymsg.h"
+#include "modules/cs_mode.h"
+#include "modules/hs_request.h"
+#include "modules/info.h"
+#include "modules/ns_cert.h"
+#include "modules/os_forbid.h"
+#include "modules/suspend.h"
+
+// Handles reading from an Atheme database row.
+class AthemeRow final
+{
+private:
+ // The number of failed reads.
+ unsigned error = 0;
+
+ // The underlying token stream.
+ spacesepstream stream;
+
+public:
+ AthemeRow(const Anope::string &str)
+ : stream(str)
+ {
+ }
+
+ operator bool() const
+ {
+ return !error;
+ }
+
+ // Retrieves the next parameter.
+ Anope::string Get()
+ {
+ Anope::string token;
+ if (!stream.GetToken(token))
+ error++;
+ return token;
+ }
+
+ // Retrieves the next parameter as a number.
+ template<typename Numeric>
+ std::enable_if_t<std::is_arithmetic_v<Numeric>, Numeric> GetNum()
+ {
+ return Anope::Convert<Numeric>(Get(), 0);
+ }
+
+ // Retrieves the entire row.
+ Anope::string GetRow()
+ {
+ return stream.GetString();
+ }
+
+ // Retrieves the remaining data in the row.
+ Anope::string GetRemaining()
+ {
+ auto remaining = stream.GetRemaining();
+ if (remaining.empty())
+ error++;
+ return remaining;
+ }
+
+ bool LogError(Module *mod)
+ {
+ Log(mod) << "Malformed database line (expected " << error << " fields): " << GetRow();
+ return false;
+ }
+};
+
+struct ModeData final
+{
+ Anope::string name;
+ Anope::string value;
+ bool set;
+
+ ModeData(const Anope::string &n, bool s, const Anope::string &v = "")
+ : name(n)
+ , value(v)
+ , set(s)
+ {
+ }
+};
+
+struct ChannelData final
+{
+ Anope::string bot;
+ Anope::string info_adder;
+ Anope::string info_message;
+ time_t info_ts = 0;
+ std::vector<ModeData> mlocks;
+ Anope::string suspend_by;
+ Anope::string suspend_reason;
+ time_t suspend_ts = 0;
+};
+
+struct UserData final
+{
+ bool kill = false;
+ Anope::string info_adder;
+ Anope::string info_message;
+ time_t info_ts = 0;
+ Anope::string last_mask;
+ Anope::string last_quit;
+ Anope::string last_real_mask;
+ bool noexpire = false;
+ Anope::string suspend_by;
+ Anope::string suspend_reason;
+ time_t suspend_ts = 0;
+ Anope::string vhost;
+ Anope::string vhost_creator;
+ Anope::map<Anope::string> vhost_nick;
+ time_t vhost_ts = 0;
+};
+
+class DBAtheme final
+ : public Module
+{
+private:
+ ServiceReference<AccessProvider> accessprov;
+ PrimitiveExtensibleItem<ChannelData> chandata;
+ std::map<Anope::string, char> flags;
+ ServiceReference<ForbidService> forbidsvc;
+ PrimitiveExtensibleItem<UserData> userdata;
+ ServiceReference<XLineManager> sglinemgr;
+ ServiceReference<XLineManager> snlinemgr;
+ ServiceReference<XLineManager> sqlinemgr;
+
+ Anope::map<std::function<bool(DBAtheme*,AthemeRow&)>> rowhandlers = {
+ { "AC", &DBAtheme::HandleIgnore },
+ { "AR", &DBAtheme::HandleIgnore },
+ { "BE", &DBAtheme::HandleBE },
+ { "BLE", &DBAtheme::HandleIgnore },
+ { "BOT", &DBAtheme::HandleBOT },
+ { "BOT-COUNT", &DBAtheme::HandleIgnore },
+ { "BW", &DBAtheme::HandleBW },
+ { "CA", &DBAtheme::HandleCA },
+ { "CF", &DBAtheme::HandleIgnore },
+ { "CFCHAN", &DBAtheme::HandleIgnore },
+ { "CFDBV", &DBAtheme::HandleIgnore },
+ { "CFMD", &DBAtheme::HandleIgnore },
+ { "CFOP", &DBAtheme::HandleIgnore },
+ { "CLONES-CD", &DBAtheme::HandleIgnore },
+ { "CLONES-CK", &DBAtheme::HandleIgnore },
+ { "CLONES-DBV", &DBAtheme::HandleIgnore },
+ { "CLONES-EX", &DBAtheme::HandleIgnore },
+ { "CLONES-GR", &DBAtheme::HandleIgnore },
+ { "CSREQ", &DBAtheme::HandleIgnore },
+ { "CSREQ", &DBAtheme::HandleIgnore },
+ { "DBV", &DBAtheme::HandleDBV },
+ { "GACL", &DBAtheme::HandleIgnore },
+ { "GDBV", &DBAtheme::HandleIgnore },
+ { "GE", &DBAtheme::HandleIgnore },
+ { "GFA", &DBAtheme::HandleIgnore },
+ { "GRP", &DBAtheme::HandleIgnore },
+ { "GRVER", &DBAtheme::HandleGRVER },
+ { "HE", &DBAtheme::HandleIgnore },
+ { "HO", &DBAtheme::HandleIgnore },
+ { "HR", &DBAtheme::HandleHR },
+ { "JM", &DBAtheme::HandleIgnore },
+ { "KID", &DBAtheme::HandleIgnore },
+ { "KL", &DBAtheme::HandleKL },
+ { "LUID", &DBAtheme::HandleIgnore },
+ { "MC", &DBAtheme::HandleMC },
+ { "MCFP", &DBAtheme::HandleMCFP },
+ { "MDA", &DBAtheme::HandleMDA },
+ { "MDC", &DBAtheme::HandleMDC },
+ { "MDEP", &DBAtheme::HandleIgnore },
+ { "MDG", &DBAtheme::HandleIgnore },
+ { "MDN", &DBAtheme::HandleMDN },
+ { "MDU", &DBAtheme::HandleMDU },
+ { "ME", &DBAtheme::HandleME },
+ { "MI", &DBAtheme::HandleMI },
+ { "MM", &DBAtheme::HandleMM },
+ { "MN", &DBAtheme::HandleMN },
+ { "MU", &DBAtheme::HandleMU },
+ { "NAM", &DBAtheme::HandleNAM },
+ { "QID", &DBAtheme::HandleIgnore },
+ { "QL", &DBAtheme::HandleQL },
+ { "RM", &DBAtheme::HandleIgnore },
+ { "RR", &DBAtheme::HandleIgnore },
+ { "RW", &DBAtheme::HandleIgnore },
+ { "SI", &DBAtheme::HandleIgnore },
+ { "SO", &DBAtheme::HandleIgnore },
+ { "TS", &DBAtheme::HandleIgnore },
+ { "XID", &DBAtheme::HandleIgnore },
+ { "XL", &DBAtheme::HandleXL },
+ };
+
+ void ApplyAccess(Anope::string &in, char flag, Anope::string &out, std::initializer_list<const char*> privs)
+ {
+ for (const auto *priv : privs)
+ {
+ auto pos = in.find(flag);
+ if (pos != Anope::string::npos)
+ {
+ auto privchar = flags.find(priv);
+ if (privchar != flags.end())
+ {
+ out.push_back(privchar->second);
+ in.erase(pos, 1);
+ }
+ }
+ }
+ }
+
+ void ApplyFlags(Extensible *ext, Anope::string &flags, char flag, const char* extname, bool extend = true)
+ {
+ auto pos = flags.find(flag);
+ auto has_flag = (pos != Anope::string::npos);
+
+ if (has_flag == extend)
+ ext->Extend<bool>(extname);
+ else
+ ext->Shrink<bool>(extname);
+
+ if (has_flag)
+ flags.erase(pos, 1);
+ }
+
+ void ApplyLocks(ChannelInfo *ci, unsigned locks, const Anope::string &limit, const Anope::string &key, bool set)
+ {
+ auto *data = chandata.Require(ci);
+
+ // Start off with the standard mode values.
+ if (locks & 0x1u)
+ data->mlocks.emplace_back("INVITE", set);
+ if (locks & 0x2u)
+ data->mlocks.emplace_back("KEY", set, key);
+ if (locks & 0x4u)
+ data->mlocks.emplace_back("LIMIT", set, limit);
+ if (locks & 0x8u)
+ data->mlocks.emplace_back("MODERATED", set);
+ if (locks & 0x10u)
+ data->mlocks.emplace_back("NOEXTERNAL", set);
+ if (locks & 0x40u)
+ data->mlocks.emplace_back("PRIVATE", set);
+ if (locks & 0x80u)
+ data->mlocks.emplace_back("SECRET", set);
+ if (locks & 0x100u)
+ data->mlocks.emplace_back("TOPIC", set);
+ if (locks & 0x200u)
+ data->mlocks.emplace_back("REGISTERED", set);
+
+ // Atheme also supports per-ircd values here (ew).
+ if (IRCD->owner->name == "bahamut")
+ {
+ if (locks & 0x1000u)
+ data->mlocks.emplace_back("BLOCKCOLOR", set);
+ if (locks & 0x2000u)
+ data->mlocks.emplace_back("REGMODERATED", set);
+ if (locks & 0x4000u)
+ data->mlocks.emplace_back("REGISTEREDONLY", set);
+ if (locks & 0x8000u)
+ data->mlocks.emplace_back("OPERONLY", set);
+
+ // Anope doesn't recognise the following Bahamut modes currently:
+ // - 0x10000u ('A')
+ // - 0x20000u ('P')
+ }
+ else if (IRCD->owner->name == "inspircd")
+ {
+ if (locks & 0x1000u)
+ data->mlocks.emplace_back("BLOCKCOLOR", set);
+ if (locks & 0x2000u)
+ data->mlocks.emplace_back("REGMODERATED", set);
+ if (locks & 0x4000u)
+ data->mlocks.emplace_back("REGISTEREDONLY", set);
+ if (locks & 0x8000u)
+ data->mlocks.emplace_back("OPERONLY", set);
+ if (locks & 0x10000u)
+ data->mlocks.emplace_back("NONOTICE", set);
+ if (locks & 0x20000u)
+ data->mlocks.emplace_back("NOKICK", set);
+ if (locks & 0x40000u)
+ data->mlocks.emplace_back("STRIPCOLOR", set);
+ if (locks & 0x80000u)
+ data->mlocks.emplace_back("NOKNOCK", set);
+ if (locks & 0x100000u)
+ data->mlocks.emplace_back("ALLINVITE", set);
+ if (locks & 0x200000u)
+ data->mlocks.emplace_back("NOCTCP", set);
+ if (locks & 0x400000u)
+ data->mlocks.emplace_back("AUDITORIUM", set);
+ if (locks & 0x800000u)
+ data->mlocks.emplace_back("SSL", set);
+ if (locks & 0x100000u)
+ data->mlocks.emplace_back("NONICK", set);
+ if (locks & 0x200000u)
+ data->mlocks.emplace_back("CENSOR", set);
+ if (locks & 0x400000u)
+ data->mlocks.emplace_back("BLOCKCAPS", set);
+ if (locks & 0x800000u)
+ data->mlocks.emplace_back("PERM", set);
+ if (locks & 0x2000000u)
+ data->mlocks.emplace_back("DELAYEDJOIN", set);
+ }
+ else if (IRCD->owner->name == "ngircd")
+ {
+ if (locks & 0x1000u)
+ data->mlocks.emplace_back("REGISTEREDONLY", set);
+ if (locks & 0x2000u)
+ data->mlocks.emplace_back("OPERONLY", set);
+ if (locks & 0x4000u)
+ data->mlocks.emplace_back("PERM", set);
+ if (locks & 0x8000u)
+ data->mlocks.emplace_back("SSL", set);
+ }
+ else if (IRCD->owner->name == "solanum")
+ {
+ if (locks & 0x1000u)
+ data->mlocks.emplace_back("BLOCKCOLOR", set);
+ if (locks & 0x2000u)
+ data->mlocks.emplace_back("REGISTEREDONLY", set);
+ if (locks & 0x4000u)
+ data->mlocks.emplace_back("OPMODERATED", set);
+ if (locks & 0x8000u)
+ data->mlocks.emplace_back("ALLINVITE", set);
+ if (locks & 0x10000u)
+ data->mlocks.emplace_back("LBAN", set);
+ if (locks & 0x20000u)
+ data->mlocks.emplace_back("PERM", set);
+ if (locks & 0x40000u)
+ data->mlocks.emplace_back("ALLOWFORWARD", set);
+ if (locks & 0x80000u)
+ data->mlocks.emplace_back("NOFORWARD", set);
+ if (locks & 0x100000u)
+ data->mlocks.emplace_back("NOCTCP", set);
+ if (locks & 0x400000u)
+ data->mlocks.emplace_back("SSL", set);
+ if (locks & 0x800000u)
+ data->mlocks.emplace_back("OPERONLY", set);
+ if (locks & 0x1000000u)
+ data->mlocks.emplace_back("ADMINONLY", set);
+ if (locks & 0x2000000u)
+ data->mlocks.emplace_back("NONOTICE", set);
+ if (locks & 0x4000000u)
+ data->mlocks.emplace_back("PROTECTED", set);
+ if (locks & 0x8000000)
+ data->mlocks.emplace_back("NOFILTER", set);
+ if (locks & 0x10000000U)
+ data->mlocks.emplace_back("REGMODERATED", set);
+ }
+ else if (IRCD->owner->name == "unrealircd")
+ {
+ if (locks & 0x1000u)
+ data->mlocks.emplace_back("BLOCKCOLOR", set);
+ if (locks & 0x2000u)
+ data->mlocks.emplace_back("REGMODERATED", set);
+ if (locks & 0x4000u)
+ data->mlocks.emplace_back("REGISTEREDONLY", set);
+ if (locks & 0x8000u)
+ data->mlocks.emplace_back("OPERONLY", set);
+ if (locks & 0x20000u)
+ data->mlocks.emplace_back("NOKICK", set);
+ if (locks & 0x40000u)
+ data->mlocks.emplace_back("STRIPCOLOR", set);
+ if (locks & 0x80000u)
+ data->mlocks.emplace_back("NOKNOCK", set);
+ if (locks & 0x100000u)
+ data->mlocks.emplace_back("NOINVITE", set);
+ if (locks & 0x200000u)
+ data->mlocks.emplace_back("NOCTCP", set);
+ if (locks & 0x800000u)
+ data->mlocks.emplace_back("SSL", set);
+ if (locks & 0x1000000u)
+ data->mlocks.emplace_back("NONICK", set);
+ if (locks & 0x4000000u)
+ data->mlocks.emplace_back("CENSOR", set);
+ if (locks & 0x8000000u)
+ data->mlocks.emplace_back("PERM", set);
+ if (locks & 0x1000000u)
+ data->mlocks.emplace_back("NONOTICE", set);
+ if (locks & 0x2000000u)
+ data->mlocks.emplace_back("DELAYJOIN", set);
+ }
+ else if (IRCD->owner->name != "ratbox")
+ {
+ Log(this) << "Unable to import mode locks for " << IRCD->GetProtocolName();
+ }
+ }
+
+ void ApplyPassword(NickCore *nc, Anope::string &flags, const Anope::string &pass)
+ {
+ auto pos = flags.find('C');
+ if (pos == Anope::string::npos)
+ {
+ // Password is unencrypted so we can use it.
+ Anope::Encrypt(pass, nc->pass);
+ return;
+ }
+
+ // Atheme supports several password hashing methods. We can only import
+ // some of them currently.
+ //
+ // anope-enc-sha256 Converted to enc_sha256
+ // argon2 Converted to enc_argon2
+ // base64 Converted to the first encryption algorithm
+ // bcrypt Converted to enc_bcrypt
+ // crypt3-des NO
+ // crypt3-md5 NO
+ // crypt3-sha2-256 NO
+ // crypt3-sha2-512 NO
+ // ircservices Converted to enc_old
+ // pbkdf2 NO
+ // pbkdf2v2 NO
+ // rawmd5 Converted to enc_md5
+ // rawsha1 Converted to enc_sha1
+ // rawsha2-256 Converted to enc_sha2
+ // rawsha2-512 Converted to enc_sha2
+ // scrypt NO
+ if (pass.compare(0, 18, "$anope$enc_sha256$", 18) == 0)
+ {
+ auto sep = pass.find('$', 18);
+ Anope::string iv, pass;
+ Anope::B64Decode(pass.substr(18, sep - 18), iv);
+ Anope::B64Decode(pass.substr(sep + 1), pass);
+ nc->pass = "sha256:" + Anope::Hex(pass) + ":" + Anope::Hex(iv);
+ }
+
+ else if (pass.compare(0, 9, "$argon2d$", 9) == 0)
+ nc->pass = "argon2d:" + pass;
+
+ else if (pass.compare(0, 9, "$argon2i$", 9) == 0)
+ nc->pass = "argon2i:" + pass;
+
+ else if (pass.compare(0, 10, "$argon2id$", 10) == 0)
+ nc->pass = "argon2id:" + pass;
+
+ else if (pass.compare(0, 8, "$base64$", 8) == 0)
+ {
+ Anope::string rawpass;
+ Anope::B64Decode(pass.substr(8), rawpass);
+ Anope::Encrypt(rawpass, nc->pass);
+ }
+
+ else if (pass.compare(0, 13, "$ircservices$", 13) == 0)
+ nc->pass = "oldmd5:" + pass.substr(13);
+
+ else if (pass.compare(0, 8, "$rawmd5$", 8) == 0)
+ nc->pass = "md5:" + pass.substr(8);
+
+ else if (pass.compare(0, 9, "$rawsha1$", 9) == 0)
+ nc->pass = "sha1:" + pass.substr(9);
+
+ else if (pass.compare(0, 11, "$rawsha256$", 11) == 0)
+ nc->pass = "raw-sha256:" + pass.substr(11);
+
+ else if (pass.compare(0, 11, "$rawsha512$", 11) == 0)
+ nc->pass = "raw-sha512:" + pass.substr(11);
+
+ else if (pass.compare(0, 4, "$2a$", 4) == 0 || pass.compare(0, 4, "$2b$", 4) == 0)
+ nc->pass = "bcrypt:" + pass;
+
+ else
+ {
+ // Generate a new password as we can't use the old one.
+ auto maxpasslen = Config->GetModule("nickserv")->Get<unsigned>("maxpasslen", "50");
+ Anope::Encrypt(Anope::Random(maxpasslen), nc->pass);
+ Log(this) << "Unable to convert the password for " << nc->display << " as Anope does not support the format!";
+ }
+
+ }
+
+ bool HandleBE(AthemeRow &row)
+ {
+ // BE <email <created> <creator> <reason>
+ auto email = row.Get();
+ auto created = row.GetNum<time_t>();
+ auto creator = row.Get();
+ auto reason = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ if (!forbidsvc)
+ {
+ Log(this) << "Unable to convert forbidden email " << email << " as os_forbid is not loaded";
+ return true;
+ }
+
+ auto *forbid = forbidsvc->CreateForbid();
+ forbid->created = created;
+ forbid->creator = creator;
+ forbid->mask = email;
+ forbid->reason = reason;
+ forbid->type = FT_EMAIL;
+ forbidsvc->AddForbid(forbid);
+ return true;
+ }
+
+ bool HandleBOT(AthemeRow &row)
+ {
+ // BOT <nick> <user> <host> <operonly> <created> <real>
+ auto nick = row.Get();
+ auto user = row.Get();
+ auto host = row.Get();
+ auto operonly = row.GetNum<unsigned>();
+ auto created = row.GetNum<time_t>();
+ auto real = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *bi = new BotInfo(nick, user, host, real);
+ bi->oper_only = operonly;
+ bi->created = created;
+ return true;
+ }
+
+ bool HandleBW(AthemeRow &row)
+ {
+ // BW <badword> <added> <creator> <channel> <action>
+ auto badword = row.Get();
+ /* auto added = */ row.GetNum<time_t>();
+ /* auto creator = */ row.Get();
+ auto channel = row.Get();
+ /* auto action = */ row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *ci = ChannelInfo::Find(channel);
+ if (!ci)
+ {
+ Log(this) << "Missing ChannelInfo for BW: " << channel;
+ return false;
+ }
+
+ auto *bw = ci->Require<BadWords>("badwords");
+ if (!bw)
+ {
+ Log(this) << "Unable to import badwords for " << ci->name << " as bs_kick is not loaded";
+ return true;
+ }
+
+ auto *kd = ci->Require<KickerData>("kickerdata");
+ if (kd)
+ {
+ kd->badwords = true;
+ kd->ttb[TTB_BADWORDS] = 0;
+ }
+
+ bw->AddBadWord(badword, BW_ANY);
+ return true;
+ }
+
+ bool HandleCA(AthemeRow &row)
+ {
+ // CA <channel> <account/mask> <flags> <modifiedtime> <setter>
+ auto channel = row.Get();
+ auto mask = row.Get();
+ auto flags = row.Get();
+ auto modifiedtime = row.GetNum<time_t>();
+ auto setter = row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *ci = ChannelInfo::Find(channel);
+ if (!ci)
+ {
+ Log(this) << "Missing ChannelInfo for CA: " << channel;
+ return false;
+ }
+
+ auto *nc = NickCore::Find(mask);
+ if (flags.find('b') != Anope::string::npos)
+ {
+ if (nc)
+ ci->AddAkick(setter, nc, "", modifiedtime, modifiedtime);
+ else
+ ci->AddAkick(setter, mask, "", modifiedtime, modifiedtime);
+ return true;
+ }
+
+ if (!accessprov)
+ {
+ Log(this) << "Unable to import channel access for " << ci->name << " as cs_flags is not loaded";
+ return true;
+ }
+
+ Anope::string accessflags;
+ ApplyAccess(flags, 'A', accessflags, { "ACCESS_LIST" });
+ ApplyAccess(flags, 'a', accessflags, { "AUTOPROTECT", "PROTECT", "PROTECTME" });
+ ApplyAccess(flags, 'e', accessflags, { "GETKEY", "NOKICK", "UNBANME" });
+ ApplyAccess(flags, 'f', accessflags, { "ACCESS_CHANGE" });
+ ApplyAccess(flags, 'F', accessflags, { "FOUNDER" });
+ ApplyAccess(flags, 'H', accessflags, { "AUTOHALFOP" });
+ ApplyAccess(flags, 'h', accessflags, { "HALFOP", "HALFOPME" });
+ ApplyAccess(flags, 'i', accessflags, { "INVITE" });
+ ApplyAccess(flags, 'O', accessflags, { "AUTOOP" });
+ ApplyAccess(flags, 'o', accessflags, { "OP", "OPME" });
+ ApplyAccess(flags, 'q', accessflags, { "AUTOOWNER", "OWNER", "OWNERME" });
+ ApplyAccess(flags, 'r', accessflags, { "KICK" });
+ ApplyAccess(flags, 's', accessflags, { "SET" });
+ ApplyAccess(flags, 't', accessflags, { "TOPIC" });
+ ApplyAccess(flags, 'V', accessflags, { "AUTOVOICE" });
+ ApplyAccess(flags, 'v', accessflags, { "VOICE", "VOICEME" });
+ if (!accessflags.empty())
+ {
+ auto *access = accessprov->Create();
+ access->SetMask(mask, ci);
+ access->creator = setter;
+ access->description = "Imported from Atheme";
+ access->last_seen = modifiedtime;
+ access->created = modifiedtime;
+ access->AccessUnserialize(accessflags);
+ ci->AddAccess(access);
+ }
+
+ if (flags != "+")
+ Log(this) << "Unable to convert channel access flags " << flags << " for " << ci->name;
+
+ return true;
+ }
+
+ bool HandleDBV(AthemeRow &row)
+ {
+ // DBV <version>
+ unsigned version = row.GetNum<unsigned>();
+ if (version != 12)
+ {
+ Log(this) << "Database is version " << version << " which is not supported!";
+ return false;
+ }
+ return true;
+ }
+
+ bool HandleGRVER(AthemeRow &row)
+ {
+ // GRVER <version>
+ unsigned version = row.GetNum<unsigned>();
+ if (version != 1)
+ {
+ Log(this) << "Database grammar is version " << version << " which is not supported!";
+ return false;
+ }
+ return true;
+ }
+
+ bool HandleHR(AthemeRow &row)
+ {
+ // HR <nick> <host> <reqts> <creator>
+ auto nick = row.Get();
+ auto host = row.Get();
+ auto reqts = row.GetNum<time_t>();
+ /* auto creator = */ row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *na = NickAlias::Find(nick);
+ if (!na)
+ {
+ Log(this) << "Missing NickAlias for HR: " << nick;
+ return false;
+ }
+
+ auto *hr = na->Require<HostRequest>("hostrequest");
+ if (!hr)
+ {
+ Log(this) << "Unable to convert host request for " << na->nick << " as hs_request is not loaded";
+ return true;
+ }
+
+ hr->nick = na->nick;
+ hr->ident.clear();
+ hr->host = host;
+ hr->time = reqts;
+ return true;
+ }
+
+ bool HandleKL(AthemeRow &row)
+ {
+ // KL <id> <user> <host> <duration> <settime> <setby> <reason>
+ /* auto id = */ row.GetNum<unsigned>();
+ auto user = row.Get();
+ auto host = row.Get();
+ auto duration = row.GetNum<unsigned>();
+ auto settime = row.GetNum<time_t>();
+ auto setby = row.Get();
+ auto reason = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ if (!sglinemgr)
+ {
+ Log(this) << "Unable to import K-line on " << user << "@" << host << " as operserv is not loaded";
+ return true;
+ }
+
+ auto *xl = new XLine(user + "@" + host, setby, settime + duration, reason);
+ sglinemgr->AddXLine(xl);
+ return true;
+ }
+
+ bool HandleIgnore(AthemeRow &row)
+ {
+ Log(LOG_DEBUG_3) << "Intentionally ignoring Atheme database row: " << row.GetRow();
+ return true;
+ }
+
+ bool HandleMC(AthemeRow &row)
+ {
+ // MC <channel> <regtime> <used> <flags> <mlock-on> <mlock-off> <mlock-limit> [<mlock-key>]
+ auto channel = row.Get();
+ auto regtime = row.GetNum<time_t>();
+ /* auto used = */ row.GetNum<time_t>();
+ auto flags = row.Get();
+ auto mlock_on = row.GetNum<unsigned>();
+ auto mlock_off = row.GetNum<unsigned>();
+ auto mlock_limit = row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto mlock_key = row.Get(); // May not exist.
+
+ auto *ci = new ChannelInfo(channel);
+ ci->time_registered = regtime;
+
+ // No equivalent: elnv
+ ApplyFlags(ci, flags, 'h', "CS_NO_EXPIRE");
+ ApplyFlags(ci, flags, 'k', "KEEPTOPIC");
+ ApplyFlags(ci, flags, 'o', "NOAUTOOP");
+ ApplyFlags(ci, flags, 'p', "CS_PRIVATE");
+ ApplyFlags(ci, flags, 'r', "RESTRICTED");
+ ApplyFlags(ci, flags, 't', "TOPICLOCK");
+ ApplyFlags(ci, flags, 'z', "SECUREOPS");
+
+ auto pos = flags.find('a');
+ if (pos != Anope::string::npos)
+ {
+ ci->SetLevel("ACCESS_CHANGE", 0);
+ flags.erase(pos, 1);
+ }
+
+ pos = flags.find('f');
+ if (pos != Anope::string::npos)
+ {
+ auto *kd = ci->Require<KickerData>("kickerdata");
+ if (kd)
+ {
+ kd->flood = true;
+ kd->floodlines = 10;
+ kd->floodsecs = 60;
+ kd->ttb[TTB_FLOOD] = 0;
+ flags.erase(pos, 1);
+ }
+ else
+ {
+ Log(this) << "Unable to convert the 'f' flag for " << ci->name << " as bs_kick is not loaded";
+ }
+ }
+
+ pos = flags.find('g');
+ if (pos != Anope::string::npos)
+ {
+ auto *bi = Config->GetClient("ChanServ");
+ if (bi)
+ {
+ bi->Assign(nullptr, ci);
+ flags.erase(pos, 1);
+ }
+ else
+ Log(this) << "Unable to convert the 'g' flag for " << ci->name << " as chanserv is not loaded";
+ }
+
+ if (flags != "+")
+ Log(this) << "Unable to convert channel flags " << flags << " for " << ci->name;
+
+ ApplyLocks(ci, mlock_on, mlock_limit, mlock_key, true);
+ ApplyLocks(ci, mlock_off, mlock_limit, mlock_key, false);
+ return true;
+ }
+
+ bool HandleMCFP(AthemeRow &row)
+ {
+ // MCFP <display> <fingerprint>
+ auto display = row.Get();
+ auto fingerprint = row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *nc = NickCore::Find(display);
+ if (!nc)
+ {
+ Log(this) << "Missing NickCore for MCFP: " << display;
+ return false;
+ }
+
+ auto *cl = nc->Require<NSCertList>("certificates");
+ if (!cl)
+ {
+ Log(this) << "Unable to convert certificate for " << nc->display << " as ns_cert is not loaded";
+ return true;
+ }
+
+ cl->AddCert(fingerprint);
+ return true;
+ }
+
+ bool HandleMDA(AthemeRow &row)
+ {
+ // MDA <channel> <account/mask> <key> <value>
+ auto display = row.Get();
+ auto mask = row.Get();
+ auto key = row.Get();
+ auto value = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ Log(this) << "Unknown channel access metadata " << key << " = " << value;
+ return true;
+ }
+
+ bool HandleMDC(AthemeRow &row)
+ {
+ // MDC <channel> <key> <value>
+ auto channel = row.Get();
+ auto key = row.Get();
+ auto value = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *ci = ChannelInfo::Find(channel);
+ if (!ci)
+ {
+ Log(this) << "Missing ChannelInfo for MDC: " << channel;
+ return false;
+ }
+
+ auto *data = chandata.Require(ci);
+ if (key == "private:botserv:bot-assigned")
+ data->bot = value;
+ else if (key == "private:botserv:bot-handle-fantasy")
+ ci->Extend<bool>("BS_FANTASY");
+ else if (key == "private:botserv:no-bot")
+ ci->Extend<bool>("BS_NOBOT");
+ else if (key == "private:close:closer")
+ data->suspend_by = value;
+ else if (key == "private:close:reason")
+ data->suspend_reason = value;
+ else if (key == "private:close:timestamp")
+ data->suspend_ts = Anope::Convert<time_t>(value, 0);
+ else if (key == "private:entrymsg")
+ {
+ auto *eml = ci->Require<EntryMessageList>("entrymsg");
+ if (!eml)
+ {
+ Log(this) << "Unable to convert entry message for " << ci->name << " as cs_mode is not loaded";
+ return true;
+ }
+
+ auto *msg = eml->Create();
+ msg->chan = ci->name;
+ msg->creator = "Unknown";
+ msg->message = value;
+ msg->when = Anope::CurTime;
+ (*eml)->push_back(msg);
+ }
+ else if (key == "private:klinechan:closer")
+ data->suspend_by = value;
+ else if (key == "private:klinechan:reason")
+ data->suspend_reason = value;
+ else if (key == "private:klinechan:timestamp")
+ data->suspend_ts = Anope::Convert<time_t>(value, 0);
+ else if (key == "private:mark:reason")
+ data->info_message = value;
+ else if (key == "private:mark:setter")
+ data->info_adder = value;
+ else if (key == "private:mark:timestamp")
+ data->info_ts = Anope::Convert<time_t>(value, 0);
+ else if (key == "private:topic:setter")
+ ci->last_topic_setter = value;
+ else if (key == "private:topic:text")
+ ci->last_topic = value;
+ else if (key == "private:topic:ts")
+ ci->last_topic_time = Anope::Convert<time_t>(value, 0);
+ else
+ Log(this) << "Unknown channel metadata " << key << " = " << value;
+
+ return true;
+ }
+
+ bool HandleMDN(AthemeRow &row)
+ {
+ // MDN <display> <key> <value>
+ auto display = row.Get();
+ auto key = row.Get();
+ auto value = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ Log(this) << "Unknown nick metadata " << key << " = " << value;
+ return true;
+ }
+
+ bool HandleMDU(AthemeRow &row)
+ {
+ // MDU <display> <key> <value>
+ auto display = row.Get();
+ auto key = row.Get();
+ auto value = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *nc = NickCore::Find(display);
+ if (!nc)
+ {
+ Log(this) << "Missing NickCore for MDU: " << display;
+ return false;
+ }
+
+ auto *data = userdata.Require(nc);
+ if (key == "private:autojoin")
+ return true; // TODO
+ else if (key == "private:doenforce")
+ data->kill = true;
+ else if (key == "private:enforcetime")
+ {
+ if (!data->kill)
+ return true; // Don't apply this.
+
+ auto kill = Config->GetModule("nickserv")->Get<time_t>("kill", "60s");
+ auto killquick = Config->GetModule("nickserv")->Get<time_t>("killquick", "20s");
+ auto secs = Anope::Convert<time_t>(value, kill);
+ if (secs >= kill)
+ nc->Extend<bool>("KILLPROTECT");
+ else if (secs >= killquick)
+ nc->Shrink<bool>("KILL_QUICK");
+ else
+ nc->Shrink<bool>("KILL_IMMED");
+ }
+ else if (key == "private:freeze:freezer")
+ data->suspend_by = value;
+ else if (key == "private:freeze:reason")
+ data->suspend_reason = value;
+ else if (key == "private:freeze:timestamp")
+ data->suspend_ts = Anope::Convert<time_t>(value, 0);
+ else if (key == "private:host:actual")
+ data->last_real_mask = value;
+ else if (key == "private:host:vhost")
+ data->last_mask = value;
+ else if (key == "private:lastquit:message")
+ data->last_quit = value;
+ else if (key == "private:mark:reason")
+ data->info_message = value;
+ else if (key == "private:mark:setter")
+ data->info_adder = value;
+ else if (key == "private:mark:timestamp")
+ data->info_ts = Anope::Convert<time_t>(value, 0);
+ else if (key == "private:usercloak")
+ data->vhost = value;
+ else if (key == "private:usercloak-assigner")
+ data->vhost_creator = value;
+ else if (key == "private:usercloak-timestamp")
+ data->vhost_ts = Anope::Convert<time_t>(value, 0);
+ else if (key.compare(0, 18, "private:usercloak:", 18) == 0)
+ data->vhost_nick[key.substr(18)] = value;
+ else
+ Log(this) << "Unknown account metadata " << key << " = " << value;
+
+ return true;
+ }
+
+ bool HandleME(AthemeRow &row)
+ {
+ // ME <target> <source> <sent> <flags> <text>
+ auto target = row.Get();
+ auto source = row.Get();
+ auto sent = row.GetNum<time_t>();
+ auto flags = row.GetNum<unsigned>();
+ auto text = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *nc = NickCore::Find(target);
+ if (!nc)
+ {
+ Log(this) << "Missing NickCore for ME: " << source;
+ return false;
+ }
+
+ auto *m = new Memo();
+ m->mi = &nc->memos;
+ m->owner = nc->display;
+ m->sender = source;
+ m->time = sent;
+ m->text = text;
+ m->unread = flags & 0x1;
+ nc->memos.memos->push_back(m);
+ return true;
+ }
+
+ bool HandleMI(AthemeRow &row)
+ {
+ // MI <display> <ignored>
+ auto display = row.Get();
+ auto ignored = row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *nc = NickCore::Find(display);
+ if (!nc)
+ {
+ Log(this) << "Missing NickCore for MI: " << display;
+ return false;
+ }
+
+ nc->memos.ignores.push_back(ignored);
+ return true;
+ }
+
+ bool HandleMM(AthemeRow &row)
+ {
+ // MM <id> <setterid> <setteraccount> <markedid> <markedaccount> <setts> <num> <message>
+ /* auto id = */ row.Get();
+ /* auto setterid = */ row.Get();
+ auto setteraccount = row.Get();
+ /* auto markedid = */ row.Get();
+ auto markedaccount = row.Get();
+ auto setts = row.GetNum<time_t>();
+ /* auto num = */ row.Get();
+ auto message = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *nc = NickCore::Find(markedaccount);
+ if (!nc)
+ {
+ Log(this) << "Missing NickCore for MM: " << markedaccount;
+ return false;
+ }
+
+ auto *oil = nc->Require<OperInfoList>("operinfo");
+ if (oil)
+ {
+ auto *info = oil->Create();
+ info->target = nc->display;
+ info->info = message;
+ info->adder = setteraccount;
+ info->created = setts;
+ (*oil)->push_back(info);
+ }
+ else
+ {
+ Log(this) << "Unable to convert oper info for " << nc->display << " as os_info is not loaded";
+ }
+ return true;
+ }
+
+ bool HandleMN(AthemeRow &row)
+ {
+ // MU <display> <nick> <regtime> <lastseen>
+ auto display = row.Get();
+ auto nick = row.Get();
+ auto regtime = row.GetNum<time_t>();
+ auto lastseen = row.GetNum<time_t>();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *nc = NickCore::Find(display);
+ if (!nc)
+ {
+ Log(this) << "Missing NickCore for MN: " << display;
+ return false;
+ }
+
+ auto *na = new NickAlias(nick, nc);
+ na->time_registered = regtime;
+ na->last_seen = lastseen ? regtime : na->time_registered;
+
+ auto *data = userdata.Get(nc);
+ if (data)
+ {
+ if (!data->last_mask.empty())
+ na->last_usermask = data->last_mask;
+
+ if (!data->last_quit.empty())
+ na->last_quit = data->last_quit;
+
+ if (!data->last_real_mask.empty())
+ na->last_realhost = data->last_real_mask;
+
+ if (data->noexpire)
+ na->Extend<bool>("NS_NO_EXPIRE");
+
+ auto vhost = data->vhost;
+ auto nick_vhost = data->vhost_nick.find(nick);
+ if (nick_vhost != data->vhost_nick.end())
+ vhost = nick_vhost->second;
+ if (!vhost.empty())
+ na->SetVhost("", vhost, data->vhost_creator, data->vhost_ts);
+ }
+
+ return true;
+ }
+
+ bool HandleMU(AthemeRow &row)
+ {
+ // MU <id> <display> <pass> <email> <regtime> <lastlogin> <flags> <language>
+ /* auto id = */ row.Get();
+ auto display = row.Get();
+ auto pass = row.Get();
+ auto email = row.Get();
+ /* auto regtime = */ row.GetNum<time_t>();
+ /* auto lastlogin = */ row.Get();
+ auto flags = row.Get();
+ auto language = row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ auto *nc = new NickCore(display);
+ nc->email = email;
+ ApplyPassword(nc, flags, pass);
+
+ // No equivalent: bglmNQrS
+ ApplyFlags(nc, flags, 'E', "KILLPROTECT");
+ ApplyFlags(nc, flags, 'e', "MEMO_MAIL");
+ ApplyFlags(nc, flags, 'n', "NEVEROP");
+ ApplyFlags(nc, flags, 'o', "AUTOOP", false);
+ ApplyFlags(nc, flags, 'P', "MSG");
+ ApplyFlags(nc, flags, 'p', "NS_PRIVATE");
+ ApplyFlags(nc, flags, 's', "HIDE_EMAIL");
+ ApplyFlags(nc, flags, 'W', "UNCONFIRMED");
+
+ // If an Atheme account was awaiting confirmation but Anope is not
+ // configured to use confirmation then autoconfirm it.
+ const auto &nsregister = Config->GetModule("ns_register")->Get<const Anope::string>("registration");
+ if (nsregister.equals_ci("none"))
+ nc->Shrink<bool>("UNCONFIRMED");
+
+ auto pos = flags.find('h');
+ if (pos != Anope::string::npos)
+ {
+ userdata.Require(nc)->noexpire = true;
+ flags.erase(pos, 1);
+ }
+
+
+ if (flags != "+")
+ Log(this) << "Unable to convert account flags " << flags << " for " << nc->display;
+
+ // No translations yet: bg, cy, da.
+ if (language == "de")
+ nc->language = "de_DE.UTF-8";
+ else if (language == "en")
+ nc->language = "en_US.UTF-8";
+ else if (language == "es")
+ nc->language = "es_ES.UTF-8";
+ else if (language == "fr")
+ nc->language = "fr_FR.UTF-8";
+ else if (language == "ru")
+ nc->language = "ru_RU.UTF-8";
+ else if (language == "tr")
+ nc->language = "tr_TR.UTF-8";
+ else if (language != "default")
+ {
+ Log(this) << "Unable to convert language " << language << " for " << nc->display;
+ }
+
+ return true;
+ }
+
+ bool HandleNAM(AthemeRow &row)
+ {
+ // NAM <nick>
+ auto nick = row.Get();
+
+ if (!row)
+ return row.LogError(this);
+
+ if (!forbidsvc)
+ {
+ Log(this) << "Unable to convert forbidden nick " << nick << " as os_forbid is not loaded";
+ return true;
+ }
+
+ auto *forbid = forbidsvc->CreateForbid();
+ forbid->creator = "Unknown";
+ forbid->mask = nick;
+ forbid->reason = "Unknown";
+ forbid->type = FT_NICK;
+ forbidsvc->AddForbid(forbid);
+ return true;
+ }
+
+ bool HandleQL(AthemeRow &row)
+ {
+ // QL <nick> <host> <duration> <settime> <setby> <reason>
+ /* auto id = */ row.GetNum<unsigned>();
+ auto nick = row.Get();
+ auto duration = row.GetNum<unsigned>();
+ auto settime = row.GetNum<time_t>();
+ auto setby = row.Get();
+ auto reason = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ if (!sglinemgr)
+ {
+ Log(this) << "Unable to import Q-line on " << nick << " as operserv is not loaded";
+ return true;
+ }
+
+ auto *xl = new XLine(nick, setby, settime + duration, reason);
+ sqlinemgr->AddXLine(xl);
+ return true;
+ }
+
+ bool HandleXL(AthemeRow &row)
+ {
+ // XL <id> <real> <duration> <settime> <setby> <reason>
+ /* auto id = */ row.GetNum<unsigned>();
+ auto real = row.Get();
+ auto duration = row.GetNum<unsigned>();
+ auto settime = row.GetNum<time_t>();
+ auto setby = row.Get();
+ auto reason = row.GetRemaining();
+
+ if (!row)
+ return row.LogError(this);
+
+ if (!sglinemgr)
+ {
+ Log(this) << "Unable to import X-line on " << real << " as operserv is not loaded";
+ return true;
+ }
+
+ auto *xl = new XLine(real, setby, settime + duration, reason);
+ snlinemgr->AddXLine(xl);
+ return true;
+ }
+
+public:
+ DBAtheme(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, DATABASE | VENDOR)
+ , accessprov("AccessProvider", "access/flags")
+ , chandata(this, "ATHEME_CHANDATA")
+ , forbidsvc("ForbidService", "forbid")
+ , userdata(this, "ATHEME_USERDATA")
+ , sglinemgr("XLineManager","xlinemanager/sgline")
+ , snlinemgr("XLineManager","xlinemanager/snline")
+ , sqlinemgr("XLineManager","xlinemanager/sqline")
+ {
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ flags.clear();
+ for (int i = 0; i < Config->CountBlock("privilege"); ++i)
+ {
+ Configuration::Block *priv = Config->GetBlock("privilege", i);
+ const Anope::string &name = priv->Get<const Anope::string>("name");
+ const Anope::string &value = priv->Get<const Anope::string>("flag");
+ if (!name.empty() && !value.empty())
+ flags[name] = value[0];
+ }
+ }
+
+ EventReturn OnLoadDatabase() override
+ {
+ const auto dbname = Anope::DataDir + "/" + Config->GetModule(this)->Get<const Anope::string>("database", "atheme.db");
+ std::ifstream fd(dbname.str());
+ if (!fd.is_open())
+ {
+ Log(this) << "Unable to open " << dbname << " for reading!";
+ return EVENT_STOP;
+ }
+
+ for (Anope::string buf; std::getline(fd, buf.str()); )
+ {
+ AthemeRow row(buf);
+
+ auto rowtype = row.Get();
+ if (!row)
+ continue; // Empty row.
+
+ auto rowhandler = rowhandlers.find(rowtype);
+ if (rowhandler == rowhandlers.end())
+ {
+ Log(this) << "Unknown row type: " << row.GetRow();
+ continue;
+ }
+
+ if (!rowhandler->second(this, row))
+ break;
+ }
+
+ for (const auto &[_, ci] : *RegisteredChannelList)
+ {
+ auto *data = chandata.Get(ci);
+ if (!data)
+ continue;
+
+ if (!data->bot.empty())
+ {
+ auto *bi = BotInfo::Find(data->bot);
+ if (bi)
+ bi->Assign(nullptr, ci);
+ }
+
+ if (!data->info_message.empty())
+ {
+ auto *oil = ci->Require<OperInfoList>("operinfo");
+ if (oil)
+ {
+ auto *info = oil->Create();
+ info->target = ci->name;
+ info->info = data->info_message;
+ info->adder = data->info_adder.empty() ? "Unknown" : data->info_adder;
+ info->created = data->info_ts;
+ (*oil)->push_back(info);
+ }
+ else
+ {
+ Log(this) << "Unable to convert oper info for " << ci->name << " as os_info is not loaded";
+ }
+ }
+
+ if (!data->suspend_reason.empty())
+ {
+ SuspendInfo si;
+ si.by = data->suspend_by.empty() ? "Unknown" : data->suspend_by;
+ si.expires = 0;
+ si.reason = data->suspend_reason;
+ si.what = ci->name;
+ si.when = data->suspend_ts;
+ ci->Extend("CS_SUSPENDED", si);
+ }
+ }
+
+ for (const auto &[_, nc] : *NickCoreList)
+ {
+ auto *data = userdata.Get(nc);
+ if (!data)
+ continue;
+
+ if (!data->info_message.empty())
+ {
+ auto *oil = nc->Require<OperInfoList>("operinfo");
+ if (oil)
+ {
+ auto *info = oil->Create();
+ info->target = nc->display;
+ info->info = data->info_message;
+ info->adder = data->info_adder.empty() ? "Unknown" : data->info_adder;
+ info->created = data->info_ts;
+ (*oil)->push_back(info);
+ }
+ else
+ {
+ Log(this) << "Unable to convert oper info for " << nc->display << " as os_info is not loaded";
+ }
+ }
+
+ if (!data->suspend_reason.empty())
+ {
+ SuspendInfo si;
+ si.by = data->suspend_by.empty() ? "Unknown" : data->suspend_by;
+ si.expires = 0;
+ si.reason = data->suspend_reason;
+ si.what = nc->display;
+ si.when = data->suspend_ts;
+ nc->Extend("NS_SUSPENDED", si);
+ }
+ }
+
+ return EVENT_STOP;
+ }
+
+ void OnUplinkSync(Server *s) override
+ {
+ for (auto &[_, ci] : *RegisteredChannelList)
+ {
+ auto *data = chandata.Get(ci);
+ if (!data)
+ continue;
+
+ auto *ml = ci->Require<ModeLocks>("modelocks");
+ if (!ml)
+ {
+ Log(this) << "Unable to convert mode locks for " << ci->name << " as cs_mode is not loaded";
+ continue;
+ }
+
+ for (const auto &mlock : data->mlocks)
+ {
+ auto mh = ModeManager::FindChannelModeByName(mlock.name);
+ if (!mh)
+ {
+ Log(this) << "Unable to find mode while importing mode lock: " << mlock.name;
+ continue;
+ }
+
+ ml->SetMLock(mh, mlock.set, mlock.value, "Unknown");
+ }
+ }
+ }
+};
+
+MODULE_INIT(DBAtheme)
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp
index 37ee3f2ef..63c18f744 100644
--- a/modules/database/db_flatfile.cpp
+++ b/modules/database/db_flatfile.cpp
@@ -15,15 +15,14 @@
#include <sys/wait.h>
#endif
-class SaveData : public Serialize::Data
+class SaveData final
+ : public Serialize::Data
{
- public:
+public:
Anope::string last;
- std::fstream *fs;
+ std::fstream *fs = nullptr;
- SaveData() : fs(NULL) { }
-
- std::iostream& operator[](const Anope::string &key) anope_override
+ std::iostream &operator[](const Anope::string &key) override
{
if (key != last)
{
@@ -35,18 +34,17 @@ class SaveData : public Serialize::Data
}
};
-class LoadData : public Serialize::Data
+class LoadData final
+ : public Serialize::Data
{
- public:
- std::fstream *fs;
- unsigned int id;
+public:
+ std::fstream *fs = nullptr;
+ unsigned int id = 0;
std::map<Anope::string, Anope::string> data;
std::stringstream ss;
- bool read;
-
- LoadData() : fs(NULL), id(0), read(false) { }
+ bool read = false;
- std::iostream& operator[](const Anope::string &key) anope_override
+ std::iostream &operator[](const Anope::string &key) override
{
if (!read)
{
@@ -54,12 +52,7 @@ class LoadData : public Serialize::Data
{
if (token.find("ID ") == 0)
{
- try
- {
- this->id = convertTo<unsigned int>(token.substr(3));
- }
- catch (const ConvertException &) { }
-
+ this->id = Anope::Convert(token.substr(3), 0);
continue;
}
else if (token.find("DATA ") != 0)
@@ -78,20 +71,20 @@ class LoadData : public Serialize::Data
return this->ss;
}
- std::set<Anope::string> KeySet() const anope_override
+ std::set<Anope::string> KeySet() const override
{
std::set<Anope::string> keys;
- for (std::map<Anope::string, Anope::string>::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it)
- keys.insert(it->first);
+ for (const auto &[key, _]: this->data)
+ keys.insert(key);
return keys;
}
- size_t Hash() const anope_override
+ size_t Hash() const override
{
size_t hash = 0;
- for (std::map<Anope::string, Anope::string>::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it)
- if (!it->second.empty())
- hash ^= Anope::hash_cs()(it->second);
+ for (const auto &[_, value] : this->data)
+ if (!value.empty())
+ hash ^= Anope::hash_cs()(value);
return hash;
}
@@ -103,15 +96,17 @@ class LoadData : public Serialize::Data
}
};
-class DBFlatFile : public Module, public Pipe
+class DBFlatFile final
+ : public Module
+ , public Pipe
{
/* Day the last backup was on */
- int last_day;
+ int last_day = 0;
/* Backup file names */
std::map<Anope::string, std::list<Anope::string> > backups;
- bool loaded;
+ bool loaded = false;
- int child_pid;
+ int child_pid = -1;
void BackupDatabase()
{
@@ -121,69 +116,67 @@ class DBFlatFile : public Module, public Pipe
{
last_day = tm->tm_mday;
- const std::vector<Anope::string> &type_order = Serialize::Type::GetTypeOrder();
-
std::set<Anope::string> dbs;
dbs.insert(Config->GetModule(this)->Get<const Anope::string>("database", "anope.db"));
- for (unsigned i = 0; i < type_order.size(); ++i)
+ for (const auto &type_order : Serialize::Type::GetTypeOrder())
{
- Serialize::Type *stype = Serialize::Type::Find(type_order[i]);
+ Serialize::Type *stype = Serialize::Type::Find(type_order);
if (stype && stype->GetOwner())
dbs.insert("module_" + stype->GetOwner()->name + ".db");
}
- for (std::set<Anope::string>::const_iterator it = dbs.begin(), it_end = dbs.end(); it != it_end; ++it)
+ for (const auto &db : dbs)
{
- const Anope::string &oldname = Anope::DataDir + "/" + *it;
- Anope::string newname = Anope::DataDir + "/backups/" + *it + "-" + stringify(tm->tm_year + 1900) + Anope::printf("-%02i-", tm->tm_mon + 1) + Anope::printf("%02i", tm->tm_mday);
+ const Anope::string &oldname = Anope::DataDir + "/" + db;
+ Anope::string newname = Anope::DataDir + "/backups/" + db + "-" + Anope::ToString(tm->tm_year + 1900) + Anope::printf("-%02i-", tm->tm_mon + 1) + Anope::printf("%02i", tm->tm_mday);
/* Backup already exists or no database to backup */
if (Anope::IsFile(newname) || !Anope::IsFile(oldname))
continue;
- Log(LOG_DEBUG) << "db_flatfile: Attempting to rename " << *it << " to " << newname;
+ Log(LOG_DEBUG) << "db_flatfile: Attempting to rename " << db << " to " << newname;
if (rename(oldname.c_str(), newname.c_str()))
{
Anope::string err = Anope::LastError();
- Log(this) << "Unable to back up database " << *it << " (" << err << ")!";
+ Log(this) << "Unable to back up database " << db << " (" << err << ")!";
if (!Config->GetModule(this)->Get<bool>("nobackupokay"))
{
Anope::Quitting = true;
- Anope::QuitReason = "Unable to back up database " + *it + " (" + err + ")";
+ Anope::QuitReason = "Unable to back up database " + db + " (" + err + ")";
}
continue;
}
- backups[*it].push_back(newname);
+ backups[db].push_back(newname);
unsigned keepbackups = Config->GetModule(this)->Get<unsigned>("keepbackups");
- if (keepbackups > 0 && backups[*it].size() > keepbackups)
+ if (keepbackups > 0 && backups[db].size() > keepbackups)
{
- unlink(backups[*it].front().c_str());
- backups[*it].pop_front();
+ unlink(backups[db].front().c_str());
+ backups[db].pop_front();
}
}
}
}
- public:
- DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), last_day(0), loaded(false), child_pid(-1)
+public:
+ DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR)
{
}
#ifndef _WIN32
- void OnRestart() anope_override
+ void OnRestart() override
{
OnShutdown();
}
- void OnShutdown() anope_override
+ void OnShutdown() override
{
if (child_pid > -1)
{
@@ -197,7 +190,7 @@ class DBFlatFile : public Module, public Pipe
}
#endif
- void OnNotify() anope_override
+ void OnNotify() override
{
char buf[512];
int i = this->Read(buf, sizeof(buf) - 1);
@@ -219,9 +212,8 @@ class DBFlatFile : public Module, public Pipe
Anope::Quitting = true;
}
- EventReturn OnLoadDatabase() anope_override
+ EventReturn OnLoadDatabase() override
{
- const std::vector<Anope::string> &type_order = Serialize::Type::GetTypeOrder();
std::set<Anope::string> tried_dbs;
const Anope::string &db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<const Anope::string>("database", "anope.db");
@@ -242,18 +234,16 @@ class DBFlatFile : public Module, public Pipe
LoadData ld;
ld.fs = &fd;
- for (unsigned i = 0; i < type_order.size(); ++i)
+ for (const auto &type_order : Serialize::Type::GetTypeOrder())
{
- Serialize::Type *stype = Serialize::Type::Find(type_order[i]);
+ Serialize::Type *stype = Serialize::Type::Find(type_order);
if (!stype || stype->GetOwner())
continue;
- std::vector<std::streampos> &pos = positions[stype->GetName()];
-
- for (unsigned j = 0; j < pos.size(); ++j)
+ for (const auto &position : positions[stype->GetName()])
{
fd.clear();
- fd.seekg(pos[j]);
+ fd.seekg(position);
Serializable *obj = stype->Unserialize(NULL, ld);
if (obj != NULL)
@@ -269,7 +259,7 @@ class DBFlatFile : public Module, public Pipe
}
- void OnSaveDatabase() anope_override
+ void OnSaveDatabase() override
{
if (child_pid > -1)
{
@@ -299,10 +289,8 @@ class DBFlatFile : public Module, public Pipe
std::map<Module *, std::fstream *> databases;
/* First open the databases of all of the registered types. This way, if we have a type with 0 objects, that database will be properly cleared */
- for (std::map<Anope::string, Serialize::Type *>::const_iterator it = Serialize::Type::GetTypes().begin(), it_end = Serialize::Type::GetTypes().end(); it != it_end; ++it)
+ for (const auto &[_, s_type] : Serialize::Type::GetTypes())
{
- Serialize::Type *s_type = it->second;
-
if (databases[s_type->GetOwner()])
continue;
@@ -320,9 +308,8 @@ class DBFlatFile : public Module, public Pipe
SaveData data;
const std::list<Serializable *> &items = Serializable::GetItems();
- for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it)
+ for (auto *base : items)
{
- Serializable *base = *it;
Serialize::Type *s_type = base->GetSerializableType();
data.fs = databases[s_type->GetOwner()];
@@ -336,10 +323,9 @@ class DBFlatFile : public Module, public Pipe
*data.fs << "\nEND\n";
}
- for (std::map<Module *, std::fstream *>::iterator it = databases.begin(), it_end = databases.end(); it != it_end; ++it)
+ for (auto &[mod, f] : databases)
{
- std::fstream *f = it->second;
- const Anope::string &db_name = Anope::DataDir + "/" + (it->first ? (it->first->name + ".db") : Config->GetModule(this)->Get<const Anope::string>("database", "anope.db"));
+ const Anope::string &db_name = Anope::DataDir + "/" + (mod ? (mod->name + ".db") : Config->GetModule(this)->Get<const Anope::string>("database", "anope.db"));
if (!f->is_open() || !f->good())
{
@@ -374,7 +360,7 @@ class DBFlatFile : public Module, public Pipe
}
/* Load just one type. Done if a module is reloaded during runtime */
- void OnSerializeTypeCreate(Serialize::Type *stype) anope_override
+ void OnSerializeTypeCreate(Serialize::Type *stype) override
{
if (!loaded)
return;
diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp
index 7cd63716d..e95cc19ef 100644
--- a/modules/database/db_old.cpp
+++ b/modules/database/db_old.cpp
@@ -35,13 +35,12 @@ else \
#define OLD_BI_PRIVATE 0x0001
#define OLD_NI_KILLPROTECT 0x00000001 /* Kill others who take this nick */
-#define OLD_NI_SECURE 0x00000002 /* Don't recognize unless IDENTIFY'd */
#define OLD_NI_MSG 0x00000004 /* Use PRIVMSGs instead of NOTICEs */
#define OLD_NI_MEMO_HARDMAX 0x00000008 /* Don't allow user to change memo limit */
#define OLD_NI_MEMO_SIGNON 0x00000010 /* Notify of memos at signon and un-away */
#define OLD_NI_MEMO_RECEIVE 0x00000020 /* Notify of new memos when sent */
#define OLD_NI_PRIVATE 0x00000040 /* Don't show in LIST to non-servadmins */
-#define OLD_NI_HIDE_EMAIL 0x00000080 /* Don't show E-mail in INFO */
+#define OLD_NI_HIDE_EMAIL 0x00000080 /* Don't show email in INFO */
#define OLD_NI_HIDE_MASK 0x00000100 /* Don't show last seen address in INFO */
#define OLD_NI_HIDE_QUIT 0x00000200 /* Don't show last quit message in INFO */
#define OLD_NI_KILL_QUICK 0x00000400 /* Kill in 20 seconds instead of 60 */
@@ -60,7 +59,6 @@ else \
#define OLD_CI_TOPICLOCK 0x00000008
#define OLD_CI_RESTRICTED 0x00000010
#define OLD_CI_PEACE 0x00000020
-#define OLD_CI_SECURE 0x00000040
#define OLD_CI_VERBOTEN 0x00000080
#define OLD_CI_ENCRYPTEDPW 0x00000100
#define OLD_CI_NO_EXPIRE 0x00000200
@@ -94,7 +92,7 @@ else \
#define OLD_NEWS_OPER 1
#define OLD_NEWS_RANDOM 2
-static struct mlock_info
+static struct mlock_info final
{
char c;
uint32_t m;
@@ -146,20 +144,22 @@ enum
static void process_mlock(ChannelInfo *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key)
{
ModeLocks *ml = ci->Require<ModeLocks>("modelocks");
- for (unsigned i = 0; i < (sizeof(mlock_infos) / sizeof(mlock_info)); ++i)
- if (lock & mlock_infos[i].m)
+ for (auto &mlock_info : mlock_infos)
+ {
+ if (lock & mlock_info.m)
{
- ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock_infos[i].c);
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock_info.c);
if (cm && ml)
{
- if (limit && mlock_infos[i].c == 'l')
- ml->SetMLock(cm, status, stringify(*limit));
- else if (key && mlock_infos[i].c == 'k')
+ if (limit && mlock_info.c == 'l')
+ ml->SetMLock(cm, status, Anope::ToString(*limit));
+ else if (key && mlock_info.c == 'k')
ml->SetMLock(cm, status, *key);
else
ml->SetMLock(cm, status);
}
}
+ }
}
static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -307,7 +307,7 @@ static char *strscpy(char *d, const char *s, size_t len)
return d_orig;
}
-struct dbFILE
+struct dbFILE final
{
int mode; /* 'r' for reading, 'w' for writing */
FILE *fp; /* The normal file descriptor */
@@ -390,7 +390,7 @@ static int read_string(Anope::string &str, dbFILE *f)
return -1;
if (len == 0)
return 0;
- char *s = new char[len];
+ auto *s = new char[len];
if (len != fread(s, 1, len, f->fp))
{
delete [] s;
@@ -445,12 +445,12 @@ static void LoadNicks()
Anope::string buffer;
READ(read_string(buffer, f));
- NickCore *nc = new NickCore(buffer);
+ auto *nc = new NickCore(buffer);
- const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email",
+ const Anope::string settings[] = { "killprotect", "kill_quick", "ns_private", "hide_email",
"hide_mask", "hide_quit", "memo_signon", "memo_receive", "autoop", "msg", "ns_keepmodes" };
- for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j)
- nc->Shrink<bool>(settings[j].upper());
+ for (const auto &setting : settings)
+ nc->Shrink<bool>(setting.upper());
char pwbuf[32];
READ(read_buffer(pwbuf, f));
@@ -481,8 +481,6 @@ static void LoadNicks()
READ(read_uint32(&u32, f));
if (u32 & OLD_NI_KILLPROTECT)
nc->Extend<bool>("KILLPROTECT");
- if (u32 & OLD_NI_SECURE)
- nc->Extend<bool>("NS_SECURE");
if (u32 & OLD_NI_MSG)
nc->Extend<bool>("MSG");
if (u32 & OLD_NI_MEMO_HARDMAX)
@@ -569,7 +567,6 @@ static void LoadNicks()
for (uint16_t j = 0; j < u16; ++j)
{
READ(read_string(buffer, f));
- nc->access.push_back(buffer);
}
int16_t i16;
@@ -577,7 +574,7 @@ static void LoadNicks()
READ(read_int16(&nc->memos.memomax, f));
for (int16_t j = 0; j < i16; ++j)
{
- Memo *m = new Memo;
+ auto *m = new Memo;
READ(read_uint32(&u32, f));
uint16_t flags;
READ(read_uint16(&flags, f));
@@ -653,7 +650,7 @@ static void LoadNicks()
continue;
}
- NickAlias *na = new NickAlias(nick, nc);
+ auto *na = new NickAlias(nick, nc);
na->last_usermask = last_usermask;
na->last_realname = last_realname;
na->last_quit = last_quit;
@@ -748,12 +745,12 @@ static void LoadChannels()
Anope::string buffer;
char namebuf[64];
READ(read_buffer(namebuf, f));
- ChannelInfo *ci = new ChannelInfo(namebuf);
+ auto *ci = new ChannelInfo(namebuf);
- const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder",
+ const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "secureops", "securefounder",
"signkick", "signkick_level", "topiclock", "persist", "noautoop", "cs_keepmodes" };
- for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j)
- ci->Shrink<bool>(settings[j].upper());
+ for (const auto &setting : settings)
+ ci->Shrink<bool>(setting.upper());
READ(read_string(buffer, f));
ci->SetFounder(NickCore::Find(buffer));
@@ -799,8 +796,6 @@ static void LoadChannels()
ci->Extend<bool>("RESTRICTED");
if (tmpu32 & OLD_CI_PEACE)
ci->Extend<bool>("PEACE");
- if (tmpu32 & OLD_CI_SECURE)
- ci->Extend<bool>("CS_SECURE");
if (tmpu32 & OLD_CI_NO_EXPIRE)
ci->Extend<bool>("CS_NO_EXPIRE");
if (tmpu32 & OLD_CI_MEMO_HARDMAX)
@@ -894,7 +889,7 @@ static void LoadChannels()
}
}
else
- access->AccessUnserialize(stringify(level));
+ access->AccessUnserialize(Anope::ToString(level));
}
Anope::string mask;
@@ -948,7 +943,7 @@ static void LoadChannels()
{
READ(read_uint32(&tmpu32, f));
READ(read_uint16(&tmpu16, f));
- Memo *m = new Memo;
+ auto *m = new Memo;
READ(read_int32(&tmp32, f));
m->time = tmp32;
char sbuf[32];
@@ -1104,9 +1099,8 @@ static void LoadOper()
XLineManager *akill, *sqline, *snline, *szline;
akill = sqline = snline = szline = NULL;
- for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(), it_end = XLineManager::XLineManagers.end(); it != it_end; ++it)
+ for (auto *xl : XLineManager::XLineManagers)
{
- XLineManager *xl = *it;
if (xl->Type() == 'G')
akill = xl;
else if (xl->Type() == 'Q')
@@ -1138,7 +1132,7 @@ static void LoadOper()
if (!akill)
continue;
- XLine *x = new XLine(user + "@" + host, by, expires, reason, XLineManager::GenerateUID());
+ auto *x = new XLine(user + "@" + host, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
akill->AddXLine(x);
}
@@ -1158,7 +1152,7 @@ static void LoadOper()
if (!snline)
continue;
- XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
+ auto *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
snline->AddXLine(x);
}
@@ -1178,7 +1172,7 @@ static void LoadOper()
if (!sqline)
continue;
- XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
+ auto *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
sqline->AddXLine(x);
}
@@ -1198,7 +1192,7 @@ static void LoadOper()
if (!szline)
continue;
- XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
+ auto *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
szline->AddXLine(x);
}
@@ -1296,12 +1290,13 @@ static void LoadNews()
close_db(f);
}
-class DBOld : public Module
+class DBOld final
+ : public Module
{
PrimitiveExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit;
PrimitiveExtensibleItem<Anope::string> mlock_key;
- public:
+public:
DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR),
mlock_on(this, "mlock_on"), mlock_off(this, "mlock_off"), mlock_limit(this, "mlock_limit"), mlock_key(this, "mlock_key")
{
@@ -1313,7 +1308,7 @@ class DBOld : public Module
throw ModuleException("Invalid hash method");
}
- EventReturn OnLoadDatabase() anope_override
+ EventReturn OnLoadDatabase() override
{
LoadNicks();
LoadVHosts();
@@ -1326,11 +1321,10 @@ class DBOld : public Module
return EVENT_STOP;
}
- void OnUplinkSync(Server *s) anope_override
+ void OnUplinkSync(Server *s) override
{
- for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
+ for (auto &[_, ci] : *RegisteredChannelList)
{
- ChannelInfo *ci = it->second;
uint32_t *limit = mlock_limit.Get(ci);
Anope::string *key = mlock_key.Get(ci);
diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp
index 55843beac..413729887 100644
--- a/modules/database/db_redis.cpp
+++ b/modules/database/db_redis.cpp
@@ -14,116 +14,126 @@ using namespace Redis;
class DatabaseRedis;
static DatabaseRedis *me;
-class Data : public Serialize::Data
+class Data final
+ : public Serialize::Data
{
- public:
+public:
std::map<Anope::string, std::stringstream *> data;
- ~Data()
+ ~Data() override
{
- for (std::map<Anope::string, std::stringstream *>::iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- delete it->second;
+ for (auto &[_, stream] : data)
+ delete stream;
}
- std::iostream& operator[](const Anope::string &key) anope_override
+ std::iostream &operator[](const Anope::string &key) override
{
- std::stringstream* &stream = data[key];
+ std::stringstream *&stream = data[key];
if (!stream)
stream = new std::stringstream();
return *stream;
}
- std::set<Anope::string> KeySet() const anope_override
+ std::set<Anope::string> KeySet() const override
{
std::set<Anope::string> keys;
- for (std::map<Anope::string, std::stringstream *>::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it)
- keys.insert(it->first);
+ for (const auto &[key, _] : this->data)
+ keys.insert(key);
return keys;
}
- size_t Hash() const anope_override
+ size_t Hash() const override
{
size_t hash = 0;
- for (std::map<Anope::string, std::stringstream *>::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it)
- if (!it->second->str().empty())
- hash ^= Anope::hash_cs()(it->second->str());
+ for (const auto &[_, value] : this->data)
+ if (!value->str().empty())
+ hash ^= Anope::hash_cs()(value->str());
return hash;
}
};
-class TypeLoader : public Interface
+class TypeLoader final
+ : public Interface
{
Anope::string type;
- public:
+public:
TypeLoader(Module *creator, const Anope::string &t) : Interface(creator), type(t) { }
- void OnResult(const Reply &r) anope_override;
+ void OnResult(const Reply &r) override;
};
-class ObjectLoader : public Interface
+class ObjectLoader final
+ : public Interface
{
Anope::string type;
int64_t id;
- public:
+public:
ObjectLoader(Module *creator, const Anope::string &t, int64_t i) : Interface(creator), type(t), id(i) { }
- void OnResult(const Reply &r) anope_override;
+ void OnResult(const Reply &r) override;
};
-class IDInterface : public Interface
+class IDInterface final
+ : public Interface
{
Reference<Serializable> o;
- public:
+public:
IDInterface(Module *creator, Serializable *obj) : Interface(creator), o(obj) { }
- void OnResult(const Reply &r) anope_override;
+ void OnResult(const Reply &r) override;
};
-class Deleter : public Interface
+class Deleter final
+ : public Interface
{
Anope::string type;
int64_t id;
- public:
+public:
Deleter(Module *creator, const Anope::string &t, int64_t i) : Interface(creator), type(t), id(i) { }
- void OnResult(const Reply &r) anope_override;
+ void OnResult(const Reply &r) override;
};
-class Updater : public Interface
+class Updater final
+ : public Interface
{
Anope::string type;
int64_t id;
- public:
+public:
Updater(Module *creator, const Anope::string &t, int64_t i) : Interface(creator), type(t), id(i) { }
- void OnResult(const Reply &r) anope_override;
+ void OnResult(const Reply &r) override;
};
-class ModifiedObject : public Interface
+class ModifiedObject final
+ : public Interface
{
Anope::string type;
int64_t id;
- public:
+public:
ModifiedObject(Module *creator, const Anope::string &t, int64_t i) : Interface(creator), type(t), id(i) { }
- void OnResult(const Reply &r) anope_override;
+ void OnResult(const Reply &r) override;
};
-class SubscriptionListener : public Interface
+class SubscriptionListener final
+ : public Interface
{
- public:
+public:
SubscriptionListener(Module *creator) : Interface(creator) { }
- void OnResult(const Reply &r) anope_override;
+ void OnResult(const Reply &r) override;
};
-class DatabaseRedis : public Module, public Pipe
+class DatabaseRedis final
+ : public Module
+ , public Pipe
{
SubscriptionListener sl;
std::set<Serializable *> updated_items;
- public:
+public:
ServiceReference<Provider> redis;
DatabaseRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), sl(this)
@@ -151,33 +161,31 @@ class DatabaseRedis : public Module, public Pipe
obj->UpdateCache(data);
std::vector<Anope::string> args;
- args.push_back("HGETALL");
- args.push_back("hash:" + t->GetName() + ":" + stringify(obj->id));
+ args.emplace_back("HGETALL");
+ args.push_back("hash:" + t->GetName() + ":" + Anope::ToString(obj->id));
/* Get object attrs to clear before updating */
redis->SendCommand(new Updater(this, t->GetName(), obj->id), args);
}
}
- void OnNotify() anope_override
+ void OnNotify() override
{
- for (std::set<Serializable *>::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it)
+ for (auto *obj : this->updated_items)
{
- Serializable *s = *it;
-
- this->InsertObject(s);
+ this->InsertObject(obj);
}
this->updated_items.clear();
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
this->redis = ServiceReference<Provider>("Redis::Provider", block->Get<const Anope::string>("engine", "redis/main"));
}
- EventReturn OnLoadDatabase() anope_override
+ EventReturn OnLoadDatabase() override
{
if (!redis)
{
@@ -185,10 +193,9 @@ class DatabaseRedis : public Module, public Pipe
return EVENT_CONTINUE;
}
- const std::vector<Anope::string> type_order = Serialize::Type::GetTypeOrder();
- for (unsigned i = 0; i < type_order.size(); ++i)
+ for (const auto &type_order : Serialize::Type::GetTypeOrder())
{
- Serialize::Type *sb = Serialize::Type::Find(type_order[i]);
+ Serialize::Type *sb = Serialize::Type::Find(type_order);
this->OnSerializeTypeCreate(sb);
}
@@ -205,25 +212,25 @@ class DatabaseRedis : public Module, public Pipe
return EVENT_STOP;
}
- void OnSerializeTypeCreate(Serialize::Type *sb) anope_override
+ void OnSerializeTypeCreate(Serialize::Type *sb) override
{
if (!redis)
return;
std::vector<Anope::string> args;
- args.push_back("SMEMBERS");
+ args.emplace_back("SMEMBERS");
args.push_back("ids:" + sb->GetName());
redis->SendCommand(new TypeLoader(this, sb->GetName()), args);
}
- void OnSerializableConstruct(Serializable *obj) anope_override
+ void OnSerializableConstruct(Serializable *obj) override
{
this->updated_items.insert(obj);
this->Notify();
}
- void OnSerializableDestruct(Serializable *obj) anope_override
+ void OnSerializableDestruct(Serializable *obj) override
{
Serialize::Type *t = obj->GetSerializableType();
@@ -240,8 +247,8 @@ class DatabaseRedis : public Module, public Pipe
}
std::vector<Anope::string> args;
- args.push_back("HGETALL");
- args.push_back("hash:" + t->GetName() + ":" + stringify(obj->id));
+ args.emplace_back("HGETALL");
+ args.push_back("hash:" + t->GetName() + ":" + Anope::ToString(obj->id));
/* Get all of the attributes for this object */
redis->SendCommand(new Deleter(this, t->GetName(), obj->id), args);
@@ -251,7 +258,7 @@ class DatabaseRedis : public Module, public Pipe
this->Notify();
}
- void OnSerializableUpdate(Serializable *obj) anope_override
+ void OnSerializableUpdate(Serializable *obj) override
{
this->updated_items.insert(obj);
this->Notify();
@@ -266,26 +273,19 @@ void TypeLoader::OnResult(const Reply &r)
return;
}
- for (unsigned i = 0; i < r.multi_bulk.size(); ++i)
+ for (auto *reply : r.multi_bulk)
{
- const Reply *reply = r.multi_bulk[i];
-
if (reply->type != Reply::BULK)
continue;
- int64_t id;
- try
- {
- id = convertTo<int64_t>(reply->bulk);
- }
- catch (const ConvertException &)
- {
+ auto i = Anope::TryConvert<int64_t>(reply->bulk);
+ if (!i)
continue;
- }
+ auto id = i.value();
std::vector<Anope::string> args;
- args.push_back("HGETALL");
- args.push_back("hash:" + this->type + ":" + stringify(id));
+ args.emplace_back("HGETALL");
+ args.push_back("hash:" + this->type + ":" + Anope::ToString(id));
me->redis->SendCommand(new ObjectLoader(me, this->type, id), args);
}
@@ -313,7 +313,7 @@ void ObjectLoader::OnResult(const Reply &r)
data[key->bulk] << value->bulk;
}
- Serializable* &obj = st->objects[this->id];
+ Serializable *&obj = st->objects[this->id];
obj = st->Unserialize(obj, data);
if (obj)
{
@@ -332,7 +332,7 @@ void IDInterface::OnResult(const Reply &r)
return;
}
- Serializable* &obj = o->GetSerializableType()->objects[r.i];
+ Serializable *&obj = o->GetSerializableType()->objects[r.i];
if (obj)
/* This shouldn't be possible */
obj->id = 0;
@@ -358,16 +358,16 @@ void Deleter::OnResult(const Reply &r)
me->redis->StartTransaction();
std::vector<Anope::string> args;
- args.push_back("DEL");
- args.push_back("hash:" + this->type + ":" + stringify(this->id));
+ args.emplace_back("DEL");
+ args.push_back("hash:" + this->type + ":" + Anope::ToString(this->id));
/* Delete hash object */
me->redis->SendCommand(NULL, args);
args.clear();
- args.push_back("SREM");
+ args.emplace_back("SREM");
args.push_back("ids:" + this->type);
- args.push_back(stringify(this->id));
+ args.push_back(Anope::ToString(this->id));
/* Delete id from ids set */
me->redis->SendCommand(NULL, args);
@@ -378,9 +378,9 @@ void Deleter::OnResult(const Reply &r)
*value = r.multi_bulk[i + 1];
args.clear();
- args.push_back("SREM");
+ args.emplace_back("SREM");
args.push_back("value:" + this->type + ":" + key->bulk + ":" + value->bulk);
- args.push_back(stringify(this->id));
+ args.push_back(Anope::ToString(this->id));
/* Delete value -> object id */
me->redis->SendCommand(NULL, args);
@@ -421,9 +421,9 @@ void Updater::OnResult(const Reply &r)
*value = r.multi_bulk[i + 1];
std::vector<Anope::string> args;
- args.push_back("SREM");
+ args.emplace_back("SREM");
args.push_back("value:" + this->type + ":" + key->bulk + ":" + value->bulk);
- args.push_back(stringify(this->id));
+ args.push_back(Anope::ToString(this->id));
/* Delete value -> object id */
me->redis->SendCommand(NULL, args);
@@ -431,29 +431,25 @@ void Updater::OnResult(const Reply &r)
/* Add object id to id set for this type */
std::vector<Anope::string> args;
- args.push_back("SADD");
+ args.emplace_back("SADD");
args.push_back("ids:" + this->type);
- args.push_back(stringify(obj->id));
+ args.push_back(Anope::ToString(obj->id));
me->redis->SendCommand(NULL, args);
args.clear();
- args.push_back("HMSET");
- args.push_back("hash:" + this->type + ":" + stringify(obj->id));
+ args.emplace_back("HMSET");
+ args.push_back("hash:" + this->type + ":" + Anope::ToString(obj->id));
- typedef std::map<Anope::string, std::stringstream *> items;
- for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (const auto &[key, value] : data.data)
{
- const Anope::string &key = it->first;
- std::stringstream *value = it->second;
-
args.push_back(key);
- args.push_back(value->str());
+ args.emplace_back(value->str());
std::vector<Anope::string> args2;
- args2.push_back("SADD");
+ args2.emplace_back("SADD");
args2.push_back("value:" + this->type + ":" + key + ":" + value->str());
- args2.push_back(stringify(obj->id));
+ args2.push_back(Anope::ToString(obj->id));
/* Add to value -> object id set */
me->redis->SendCommand(NULL, args2);
@@ -504,16 +500,11 @@ void SubscriptionListener::OnResult(const Reply &r)
if (s_type == NULL)
return;
- uint64_t obj_id;
- try
- {
- obj_id = convertTo<uint64_t>(id);
- }
- catch (const ConvertException &)
- {
+ auto oid = Anope::TryConvert<uint64_t>(id);
+ if (!oid.has_value())
return;
- }
+ auto obj_id = oid.value();
if (op == "hset" || op == "hdel")
{
Serializable *s = s_type->objects[obj_id];
@@ -528,7 +519,7 @@ void SubscriptionListener::OnResult(const Reply &r)
Log(LOG_DEBUG) << "redis: notify: got modify for object id " << obj_id << " of type " << type;
std::vector<Anope::string> args;
- args.push_back("HGETALL");
+ args.emplace_back("HGETALL");
args.push_back("hash:" + type + ":" + id);
me->redis->SendCommand(new ModifiedObject(me, type, obj_id), args);
@@ -536,7 +527,7 @@ void SubscriptionListener::OnResult(const Reply &r)
}
else if (op == "del")
{
- Serializable* &s = s_type->objects[obj_id];
+ Serializable *&s = s_type->objects[obj_id];
if (s == NULL)
return;
@@ -549,14 +540,10 @@ void SubscriptionListener::OnResult(const Reply &r)
/* Transaction start */
me->redis->StartTransaction();
- typedef std::map<Anope::string, std::stringstream *> items;
- for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (const auto &[k, value] : data.data)
{
- const Anope::string &k = it->first;
- std::stringstream *value = it->second;
-
std::vector<Anope::string> args;
- args.push_back("SREM");
+ args.emplace_back("SREM");
args.push_back("value:" + type + ":" + k + ":" + value->str());
args.push_back(id);
@@ -565,9 +552,9 @@ void SubscriptionListener::OnResult(const Reply &r)
}
std::vector<Anope::string> args;
- args.push_back("SREM");
+ args.emplace_back("SREM");
args.push_back("ids:" + type);
- args.push_back(stringify(s->id));
+ args.push_back(Anope::ToString(s->id));
/* Delete object from id set */
me->redis->SendCommand(NULL, args);
@@ -590,7 +577,7 @@ void ModifiedObject::OnResult(const Reply &r)
return;
}
- Serializable* &obj = st->objects[this->id];
+ Serializable *&obj = st->objects[this->id];
/* Transaction start */
me->redis->StartTransaction();
@@ -602,16 +589,12 @@ void ModifiedObject::OnResult(const Reply &r)
obj->Serialize(data);
- typedef std::map<Anope::string, std::stringstream *> items;
- for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (auto &[key, value] : data.data)
{
- const Anope::string &key = it->first;
- std::stringstream *value = it->second;
-
std::vector<Anope::string> args;
- args.push_back("SREM");
+ args.emplace_back("SREM");
args.push_back("value:" + st->GetName() + ":" + key + ":" + value->str());
- args.push_back(stringify(this->id));
+ args.push_back(Anope::ToString(this->id));
/* Delete value -> object id */
me->redis->SendCommand(NULL, args);
@@ -635,25 +618,21 @@ void ModifiedObject::OnResult(const Reply &r)
obj->UpdateCache(data);
/* Insert new object values */
- typedef std::map<Anope::string, std::stringstream *> items;
- for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (const auto &[key, value] : data.data)
{
- const Anope::string &key = it->first;
- std::stringstream *value = it->second;
-
std::vector<Anope::string> args;
- args.push_back("SADD");
+ args.emplace_back("SADD");
args.push_back("value:" + st->GetName() + ":" + key + ":" + value->str());
- args.push_back(stringify(obj->id));
+ args.push_back(Anope::ToString(obj->id));
/* Add to value -> object id set */
me->redis->SendCommand(NULL, args);
}
std::vector<Anope::string> args;
- args.push_back("SADD");
+ args.emplace_back("SADD");
args.push_back("ids:" + st->GetName());
- args.push_back(stringify(obj->id));
+ args.push_back(Anope::ToString(obj->id));
/* Add to type -> id set */
me->redis->SendCommand(NULL, args);
diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp
index c02edd8aa..d8fe89972 100644
--- a/modules/database/db_sql.cpp
+++ b/modules/database/db_sql.cpp
@@ -14,17 +14,18 @@
using namespace SQL;
-class SQLSQLInterface : public Interface
+class SQLSQLInterface
+ : public Interface
{
- public:
+public:
SQLSQLInterface(Module *o) : Interface(o) { }
- void OnResult(const Result &r) anope_override
+ void OnResult(const Result &r) override
{
Log(LOG_DEBUG) << "SQL successfully executed query: " << r.finished_query;
}
- void OnError(const Result &r) anope_override
+ void OnError(const Result &r) override
{
if (!r.GetQuery().query.empty())
Log(LOG_DEBUG) << "Error executing query " << r.finished_query << ": " << r.GetError();
@@ -33,14 +34,15 @@ class SQLSQLInterface : public Interface
}
};
-class ResultSQLSQLInterface : public SQLSQLInterface
+class ResultSQLSQLInterface final
+ : public SQLSQLInterface
{
Reference<Serializable> obj;
public:
ResultSQLSQLInterface(Module *o, Serializable *ob) : SQLSQLInterface(o), obj(ob) { }
- void OnResult(const Result &r) anope_override
+ void OnResult(const Result &r) override
{
SQLSQLInterface::OnResult(r);
if (r.GetID() > 0 && this->obj)
@@ -48,14 +50,16 @@ public:
delete this;
}
- void OnError(const Result &r) anope_override
+ void OnError(const Result &r) override
{
SQLSQLInterface::OnError(r);
delete this;
}
};
-class DBSQL : public Module, public Pipe
+class DBSQL final
+ : public Module
+ , public Pipe
{
ServiceReference<Provider> sql;
SQLSQLInterface sqlinterface;
@@ -63,10 +67,10 @@ class DBSQL : public Module, public Pipe
bool import;
std::set<Serializable *> updated_items;
- bool shutting_down;
- bool loading_databases;
- bool loaded;
- bool imported;
+ bool shutting_down = false;
+ bool loading_databases = false;
+ bool loaded = false;
+ bool imported = false;
void RunBackground(const Query &q, Interface *iface = NULL)
{
@@ -89,8 +93,8 @@ class DBSQL : public Module, public Pipe
this->sql->RunQuery(q);
}
- public:
- DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), sql("", ""), sqlinterface(this), shutting_down(false), loading_databases(false), loaded(false), imported(false)
+public:
+ DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), sql("", ""), sqlinterface(this)
{
@@ -98,12 +102,10 @@ class DBSQL : public Module, public Pipe
throw ModuleException("db_sql can not be loaded after db_sql_live");
}
- void OnNotify() anope_override
+ void OnNotify() override
{
- for (std::set<Serializable *>::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it)
+ for (auto *obj : this->updated_items)
{
- Serializable *obj = *it;
-
if (this->sql)
{
Data data;
@@ -127,15 +129,15 @@ class DBSQL : public Module, public Pipe
if (this->imported)
{
- for (unsigned i = 0; i < create.size(); ++i)
- this->RunBackground(create[i]);
+ for (const auto &query : create)
+ this->RunBackground(query);
this->RunBackground(insert, new ResultSQLSQLInterface(this, obj));
}
else
{
- for (unsigned i = 0; i < create.size(); ++i)
- this->sql->RunQuery(create[i]);
+ for (const auto &query : create)
+ this->sql->RunQuery(query);
/* We are importing objects from another database module, so don't do asynchronous
* queries in case the core has to shut down, it will cut short the import
@@ -151,7 +153,7 @@ class DBSQL : public Module, public Pipe
this->imported = true;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
this->sql = ServiceReference<Provider>("SQL::Provider", block->Get<const Anope::string>("engine"));
@@ -159,18 +161,18 @@ class DBSQL : public Module, public Pipe
this->import = block->Get<bool>("import");
}
- void OnShutdown() anope_override
+ void OnShutdown() override
{
this->shutting_down = true;
this->OnNotify();
}
- void OnRestart() anope_override
+ void OnRestart() override
{
this->OnShutdown();
}
- EventReturn OnLoadDatabase() anope_override
+ EventReturn OnLoadDatabase() override
{
if (!this->sql)
{
@@ -180,10 +182,9 @@ class DBSQL : public Module, public Pipe
this->loading_databases = true;
- const std::vector<Anope::string> type_order = Serialize::Type::GetTypeOrder();
- for (unsigned i = 0; i < type_order.size(); ++i)
+ for (const auto &type_order : Serialize::Type::GetTypeOrder())
{
- Serialize::Type *sb = Serialize::Type::Find(type_order[i]);
+ Serialize::Type *sb = Serialize::Type::Find(type_order);
this->OnSerializeTypeCreate(sb);
}
@@ -193,7 +194,7 @@ class DBSQL : public Module, public Pipe
return EVENT_STOP;
}
- void OnSerializableConstruct(Serializable *obj) anope_override
+ void OnSerializableConstruct(Serializable *obj) override
{
if (this->shutting_down || this->loading_databases)
return;
@@ -202,17 +203,17 @@ class DBSQL : public Module, public Pipe
this->Notify();
}
- void OnSerializableDestruct(Serializable *obj) anope_override
+ void OnSerializableDestruct(Serializable *obj) override
{
if (this->shutting_down)
return;
Serialize::Type *s_type = obj->GetSerializableType();
if (s_type && obj->id > 0)
- this->RunBackground("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
+ this->RunBackground("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + Anope::ToString(obj->id));
this->updated_items.erase(obj);
}
- void OnSerializableUpdate(Serializable *obj) anope_override
+ void OnSerializableUpdate(Serializable *obj) override
{
if (this->shutting_down || obj->IsTSCached())
return;
@@ -223,7 +224,7 @@ class DBSQL : public Module, public Pipe
this->Notify();
}
- void OnSerializeTypeCreate(Serialize::Type *sb) anope_override
+ void OnSerializeTypeCreate(Serialize::Type *sb) override
{
if (!this->loading_databases && !this->loaded)
return;
@@ -235,23 +236,18 @@ class DBSQL : public Module, public Pipe
{
Data data;
- const std::map<Anope::string, Anope::string> &row = res.Row(j);
- for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit)
- data[rit->first] << rit->second;
+ for (const auto &[key, value] : res.Row(j))
+ data[key] << value;
Serializable *obj = sb->Unserialize(NULL, data);
- try
- {
- if (obj)
- obj->id = convertTo<unsigned int>(res.Get(j, "id"));
- }
- catch (const ConvertException &)
- {
- Log(this) << "Unable to convert id for object #" << j << " of type " << sb->GetName();
- }
-
if (obj)
{
+ auto oid = Anope::TryConvert<unsigned int>(res.Get(j, "id"));
+ if (oid.has_value())
+ obj->id = oid.value();
+ else
+ Log(this) << "Unable to convert id for object #" << j << " of type " << sb->GetName();
+
/* The Unserialize operation is destructive so rebuild the data for UpdateCache.
* Also the old data may contain columns that we don't use, so we reserialize the
* object to know for sure our cache is consistent
diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp
index 407ad6cd2..839126d41 100644
--- a/modules/database/db_sql_live.cpp
+++ b/modules/database/db_sql_live.cpp
@@ -11,9 +11,11 @@
using namespace SQL;
-class DBMySQL : public Module, public Pipe
+class DBMySQL final
+ : public Module
+ , public Pipe
{
- private:
+private:
Anope::string prefix;
ServiceReference<Provider> SQL;
time_t lastwarn;
@@ -71,7 +73,7 @@ class DBMySQL : public Module, public Pipe
throw SQL::Exception("No SQL!");
}
- public:
+public:
DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), SQL("", "")
{
this->lastwarn = 0;
@@ -83,15 +85,13 @@ class DBMySQL : public Module, public Pipe
throw ModuleException("If db_sql_live is loaded it must be the first database module loaded.");
}
- void OnNotify() anope_override
+ void OnNotify() override
{
if (!this->CheckInit())
return;
- for (std::set<Serializable *>::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it)
+ for (auto *obj : this->updated_items)
{
- Serializable *obj = *it;
-
if (obj && this->SQL)
{
Data data;
@@ -107,8 +107,8 @@ class DBMySQL : public Module, public Pipe
continue;
std::vector<Query> create = this->SQL->CreateTable(this->prefix + s_type->GetName(), data);
- for (unsigned i = 0; i < create.size(); ++i)
- this->RunQueryResult(create[i]);
+ for (const auto &query : create)
+ this->RunQueryResult(query);
Result res = this->RunQueryResult(this->SQL->BuildInsert(this->prefix + s_type->GetName(), obj->id, data));
if (res.GetID() && obj->id != res.GetID())
@@ -123,30 +123,30 @@ class DBMySQL : public Module, public Pipe
this->updated_items.clear();
}
- EventReturn OnLoadDatabase() anope_override
+ EventReturn OnLoadDatabase() override
{
init = true;
return EVENT_STOP;
}
- void OnShutdown() anope_override
+ void OnShutdown() override
{
init = false;
}
- void OnRestart() anope_override
+ void OnRestart() override
{
init = false;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
this->SQL = ServiceReference<Provider>("SQL::Provider", block->Get<const Anope::string>("engine"));
this->prefix = block->Get<const Anope::string>("prefix", "anope_db_");
}
- void OnSerializableConstruct(Serializable *obj) anope_override
+ void OnSerializableConstruct(Serializable *obj) override
{
if (!this->CheckInit())
return;
@@ -155,7 +155,7 @@ class DBMySQL : public Module, public Pipe
this->Notify();
}
- void OnSerializableDestruct(Serializable *obj) anope_override
+ void OnSerializableDestruct(Serializable *obj) override
{
if (!this->CheckInit())
return;
@@ -163,13 +163,13 @@ class DBMySQL : public Module, public Pipe
if (s_type)
{
if (obj->id > 0)
- this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
+ this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + Anope::ToString(obj->id));
s_type->objects.erase(obj->id);
}
this->updated_items.erase(obj);
}
- void OnSerializeCheck(Serialize::Type *obj) anope_override
+ void OnSerializeCheck(Serialize::Type *obj) override
{
if (!this->CheckInit() || obj->GetTimestamp() == Anope::CurTime)
return;
@@ -185,17 +185,16 @@ class DBMySQL : public Module, public Pipe
{
const std::map<Anope::string, Anope::string> &row = res.Row(i);
- unsigned int id;
- try
- {
- id = convertTo<unsigned int>(res.Get(i, "id"));
- }
- catch (const ConvertException &)
+
+
+ auto oid = Anope::TryConvert<unsigned int>(res.Get(i, "id"));
+ if (!oid.has_value())
{
Log(LOG_DEBUG) << "Unable to convert id from " << obj->GetName();
continue;
}
+ auto id = oid.value();
if (res.Get(i, "timestamp").empty())
{
clear_null = true;
@@ -207,8 +206,8 @@ class DBMySQL : public Module, public Pipe
{
Data data;
- for (std::map<Anope::string, Anope::string>::const_iterator it = row.begin(), it_end = row.end(); it != it_end; ++it)
- data[it->first] << it->second;
+ for (const auto &[key, value] : row)
+ data[key] << value;
Serializable *s = NULL;
std::map<uint64_t, Serializable *>::iterator it = obj->objects.find(id);
@@ -237,7 +236,7 @@ class DBMySQL : public Module, public Pipe
else
{
if (!s)
- this->RunQuery("UPDATE `" + prefix + obj->GetName() + "` SET `timestamp` = " + this->SQL->FromUnixtime(obj->GetTimestamp()) + " WHERE `id` = " + stringify(id));
+ this->RunQuery("UPDATE `" + prefix + obj->GetName() + "` SET `timestamp` = " + this->SQL->FromUnixtime(obj->GetTimestamp()) + " WHERE `id` = " + Anope::ToString(id));
else
delete s;
}
@@ -251,7 +250,7 @@ class DBMySQL : public Module, public Pipe
}
}
- void OnSerializableUpdate(Serializable *obj) anope_override
+ void OnSerializableUpdate(Serializable *obj) override
{
if (!this->CheckInit() || obj->IsTSCached())
return;
diff --git a/modules/m_dns.cpp b/modules/dns.cpp
index bbc8a83fe..d7eda6f9d 100644
--- a/modules/m_dns.cpp
+++ b/modules/dns.cpp
@@ -23,14 +23,15 @@ namespace
/** A full packet sent or received to/from the nameserver
*/
-class Packet : public Query
+class Packet final
+ : public Query
{
static bool IsValidName(const Anope::string &name)
{
return name.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-") == Anope::string::npos;
}
- void PackName(unsigned char *output, unsigned short output_size, unsigned short &pos, const Anope::string &name)
+ static void PackName(unsigned char *output, unsigned short output_size, unsigned short &pos, const Anope::string &name)
{
if (pos + name.length() + 2 > output_size)
throw SocketException("Unable to pack name");
@@ -50,7 +51,7 @@ class Packet : public Query
output[pos++] = 0;
}
- Anope::string UnpackName(const unsigned char *input, unsigned short input_size, unsigned short &pos)
+ static Anope::string UnpackName(const unsigned char *input, unsigned short input_size, unsigned short &pos)
{
Anope::string name;
unsigned short pos_ptr = pos, lowest_ptr = input_size;
@@ -71,7 +72,7 @@ class Packet : public Query
throw SocketException("Unable to unpack name - bogus compression header");
/* Place pos at the second byte of the first (farthest) compression pointer */
- if (compressed == false)
+ if (!compressed)
{
++pos;
compressed = true;
@@ -94,7 +95,7 @@ class Packet : public Query
name += input[pos_ptr + i];
pos_ptr += offset + 1;
- if (compressed == false)
+ if (!compressed)
/* Move up pos */
pos = pos_ptr;
}
@@ -200,7 +201,7 @@ class Packet : public Query
return record;
}
- public:
+public:
static const int POINTER = 0xC0;
static const int LABEL = 0x3F;
static const int HEADER_LENGTH = 12;
@@ -209,11 +210,11 @@ class Packet : public Query
/* Source or destination of the packet */
sockaddrs addr;
/* ID for this packet */
- unsigned short id;
+ unsigned short id = 0;
/* Flags on the packet */
- unsigned short flags;
+ unsigned short flags = 0;
- Packet(Manager *m, sockaddrs *a) : manager(m), id(0), flags(0)
+ Packet(Manager *m, sockaddrs *a) : manager(m)
{
if (a)
addr = *a;
@@ -286,10 +287,8 @@ class Packet : public Query
output[pos++] = this->additional.size() >> 8;
output[pos++] = this->additional.size() & 0xFF;
- for (unsigned i = 0; i < this->questions.size(); ++i)
+ for (auto &q : this->questions)
{
- Question &q = this->questions[i];
-
if (q.type == QUERY_PTR)
{
sockaddrs ip(q.name);
@@ -324,11 +323,10 @@ class Packet : public Query
}
std::vector<ResourceRecord> types[] = { this->answers, this->authorities, this->additional };
- for (int i = 0; i < 3; ++i)
- for (unsigned j = 0; j < types[i].size(); ++j)
+ for (auto &type : types)
+ {
+ for (const auto &rr : type)
{
- ResourceRecord &rr = types[i][j];
-
this->PackName(output, output_size, pos, rr.name);
if (pos + 8 >= output_size)
@@ -443,6 +441,7 @@ class Packet : public Query
break;
}
}
+ }
return pos;
}
@@ -450,52 +449,62 @@ class Packet : public Query
namespace DNS
{
- class ReplySocket : public virtual Socket
+ class ReplySocket
+ : public virtual Socket
{
- public:
- virtual ~ReplySocket() { }
+ public:
+ ~ReplySocket() override = default;
virtual void Reply(Packet *p) = 0;
};
}
/* Listens for TCP requests */
-class TCPSocket : public ListenSocket
+class TCPSocket final
+ : public ListenSocket
{
Manager *manager;
- public:
+public:
/* A TCP client */
- class Client : public ClientSocket, public Timer, public ReplySocket
+ class Client final
+ : public ClientSocket
+ , public Timer
+ , public ReplySocket
{
Manager *manager;
- Packet *packet;
+ Packet *packet = nullptr;
unsigned char packet_buffer[524];
- int length;
-
- public:
- Client(Manager *m, TCPSocket *l, int fd, const sockaddrs &addr) : Socket(fd, l->IsIPv6()), ClientSocket(l, addr), Timer(5),
- manager(m), packet(NULL), length(0)
+ int length = 0;
+
+ public:
+ Client(Manager *m, TCPSocket *l, int fd, const sockaddrs &addr)
+ : Socket(fd, l->GetFamily())
+ , ClientSocket(l, addr)
+ , Timer(5)
+ , manager(m)
{
Log(LOG_DEBUG_2) << "Resolver: New client from " << addr.addr();
}
- ~Client()
+ ~Client() override
{
Log(LOG_DEBUG_2) << "Resolver: Exiting client from " << clientaddr.addr();
delete packet;
}
/* Times out after a few seconds */
- void Tick(time_t) anope_override { }
+ void Tick() override
+ {
+ }
- void Reply(Packet *p) anope_override
+ void Reply(Packet *p) override
{
delete packet;
packet = p;
SocketEngine::Change(this, true, SF_WRITABLE);
}
- bool ProcessRead() anope_override
+ bool ProcessRead() override
{
Log(LOG_DEBUG_2) << "Resolver: Reading from DNS TCP socket";
@@ -515,7 +524,7 @@ class TCPSocket : public ListenSocket
return true;
}
- bool ProcessWrite() anope_override
+ bool ProcessWrite() override
{
Log(LOG_DEBUG_2) << "Resolver: Writing to DNS TCP socket";
@@ -543,30 +552,31 @@ class TCPSocket : public ListenSocket
}
};
- TCPSocket(Manager *m, const Anope::string &ip, int port) : Socket(-1, ip.find(':') != Anope::string::npos), ListenSocket(ip, port, ip.find(':') != Anope::string::npos), manager(m) { }
+ TCPSocket(Manager *m, const Anope::string &ip, int port) : Socket(-1, ip.find(':') == Anope::string::npos ? AF_INET : AF_INET6), ListenSocket(ip, port, ip.find(':') != Anope::string::npos), manager(m) { }
- ClientSocket *OnAccept(int fd, const sockaddrs &addr) anope_override
+ ClientSocket *OnAccept(int fd, const sockaddrs &addr) override
{
return new Client(this->manager, this, fd, addr);
}
};
/* Listens for UDP requests */
-class UDPSocket : public ReplySocket
+class UDPSocket final
+ : public ReplySocket
{
Manager *manager;
std::deque<Packet *> packets;
- public:
- UDPSocket(Manager *m, const Anope::string &ip, int port) : Socket(-1, ip.find(':') != Anope::string::npos, SOCK_DGRAM), manager(m) { }
+public:
+ UDPSocket(Manager *m, const Anope::string &ip, int port) : Socket(-1, ip.find(':') == Anope::string::npos ? AF_INET : AF_INET6, SOCK_DGRAM), manager(m) { }
- ~UDPSocket()
+ ~UDPSocket() override
{
- for (unsigned i = 0; i < packets.size(); ++i)
- delete packets[i];
+ for (const auto *packet : packets)
+ delete packet;
}
- void Reply(Packet *p) anope_override
+ void Reply(Packet *p) override
{
packets.push_back(p);
SocketEngine::Change(this, true, SF_WRITABLE);
@@ -574,7 +584,7 @@ class UDPSocket : public ReplySocket
std::deque<Packet *>& GetPackets() { return packets; }
- bool ProcessRead() anope_override
+ bool ProcessRead() override
{
Log(LOG_DEBUG_2) << "Resolver: Reading from DNS UDP socket";
@@ -585,7 +595,7 @@ class UDPSocket : public ReplySocket
return this->manager->HandlePacket(this, packet_buffer, length, &from_server);
}
- bool ProcessWrite() anope_override
+ bool ProcessWrite() override
{
Log(LOG_DEBUG_2) << "Resolver: Writing to DNS UDP socket";
@@ -612,17 +622,18 @@ class UDPSocket : public ReplySocket
}
};
-class NotifySocket : public Socket
+class NotifySocket final
+ : public Socket
{
Packet *packet;
- public:
- NotifySocket(bool v6, Packet *p) : Socket(-1, v6, SOCK_DGRAM), packet(p)
+public:
+ NotifySocket(int family, Packet *p) : Socket(-1, family, SOCK_DGRAM), packet(p)
{
SocketEngine::Change(this, false, SF_READABLE);
SocketEngine::Change(this, true, SF_WRITABLE);
}
- bool ProcessWrite() anope_override
+ bool ProcessWrite() override
{
if (!packet)
return false;
@@ -645,29 +656,34 @@ class NotifySocket : public Socket
}
};
-class MyManager : public Manager, public Timer
+class MyManager final
+ : public Manager
+ , public Timer
{
uint32_t serial;
- typedef TR1NS::unordered_map<Question, Query, Question::hash> cache_map;
+ typedef std::unordered_map<Question, Query, Question::hash> cache_map;
cache_map cache;
- TCPSocket *tcpsock;
- UDPSocket *udpsock;
+ TCPSocket *tcpsock = nullptr;
+ UDPSocket *udpsock = nullptr;
- bool listen;
+ bool listen = false;
sockaddrs addrs;
std::vector<std::pair<Anope::string, short> > notify;
- public:
+public:
std::map<unsigned short, Request *> requests;
- MyManager(Module *creator) : Manager(creator), Timer(300, Anope::CurTime, true), serial(Anope::CurTime), tcpsock(NULL), udpsock(NULL),
- listen(false), cur_id(rand())
+ MyManager(Module *creator)
+ : Manager(creator)
+ , Timer(300, true)
+ , serial(Anope::CurTime)
+ , cur_id(Anope::RandomNumber())
{
}
- ~MyManager()
+ ~MyManager() override
{
delete udpsock;
delete tcpsock;
@@ -717,7 +733,7 @@ class MyManager : public Manager, public Timer
notify = n;
}
- private:
+private:
unsigned short cur_id;
unsigned short GetID()
@@ -732,8 +748,8 @@ class MyManager : public Manager, public Timer
return cur_id;
}
- public:
- void Process(Request *req) anope_override
+public:
+ void Process(Request *req) override
{
Log(LOG_DEBUG_2) << "Resolver: Processing request to lookup " << req->name << ", of type " << req->type;
@@ -752,7 +768,7 @@ class MyManager : public Manager, public Timer
req->SetSecs(timeout);
- Packet *p = new Packet(this, &this->addrs);
+ auto *p = new Packet(this, &this->addrs);
p->flags = QUERYFLAGS_RD;
p->id = req->id;
p->questions.push_back(*req);
@@ -760,12 +776,12 @@ class MyManager : public Manager, public Timer
this->udpsock->Reply(p);
}
- void RemoveRequest(Request *req) anope_override
+ void RemoveRequest(Request *req) override
{
this->requests.erase(req->id);
}
- bool HandlePacket(ReplySocket *s, const unsigned char *const packet_buffer, int length, sockaddrs *from) anope_override
+ bool HandlePacket(ReplySocket *s, const unsigned char *const packet_buffer, int length, sockaddrs *from) override
{
if (length < Packet::HEADER_LENGTH)
return true;
@@ -792,7 +808,7 @@ class MyManager : public Manager, public Timer
return true;
}
- Packet *packet = new Packet(recv_packet);
+ auto *packet = new Packet(recv_packet);
packet->flags |= QUERYFLAGS_QR; /* This is a response */
packet->flags |= QUERYFLAGS_AA; /* And we are authoritative */
@@ -800,10 +816,8 @@ class MyManager : public Manager, public Timer
packet->authorities.clear();
packet->additional.clear();
- for (unsigned i = 0; i < recv_packet.questions.size(); ++i)
+ for (auto &q : recv_packet.questions)
{
- const Question& q = recv_packet.questions[i];
-
if (q.type == QUERY_AXFR || q.type == QUERY_SOA)
{
ResourceRecord rr(q.name, QUERY_SOA);
@@ -826,10 +840,8 @@ class MyManager : public Manager, public Timer
FOREACH_MOD(OnDnsRequest, (recv_packet, packet));
- for (unsigned i = 0; i < recv_packet.questions.size(); ++i)
+ for (auto &q : recv_packet.questions)
{
- const Question& q = recv_packet.questions[i];
-
if (q.type == QUERY_AXFR)
{
ResourceRecord rr(q.name, QUERY_SOA);
@@ -920,25 +932,22 @@ class MyManager : public Manager, public Timer
return true;
}
- void UpdateSerial() anope_override
+ void UpdateSerial() override
{
serial = Anope::CurTime;
}
- void Notify(const Anope::string &zone) anope_override
+ void Notify(const Anope::string &zone) override
{
/* notify slaves of the update */
- for (unsigned i = 0; i < notify.size(); ++i)
+ for (const auto &[ip, port] : notify)
{
- const Anope::string &ip = notify[i].first;
- short port = notify[i].second;
-
sockaddrs addr;
addr.pton(ip.find(':') != Anope::string::npos ? AF_INET6 : AF_INET, ip, port);
if (!addr.valid())
return;
- Packet *packet = new Packet(this, &addr);
+ auto *packet = new Packet(this, &addr);
packet->flags = QUERYFLAGS_AA | QUERYFLAGS_OPCODE_NOTIFY;
try
{
@@ -950,18 +959,18 @@ class MyManager : public Manager, public Timer
continue;
}
- packet->questions.push_back(Question(zone, QUERY_SOA));
+ packet->questions.emplace_back(zone, QUERY_SOA);
- new NotifySocket(ip.find(':') != Anope::string::npos, packet);
+ new NotifySocket(ip.find(':') == Anope::string::npos ? AF_INET : AF_INET6, packet);
}
}
- uint32_t GetSerial() const anope_override
+ uint32_t GetSerial() const override
{
return serial;
}
- void Tick(time_t now) anope_override
+ void Tick() override
{
Log(LOG_DEBUG_2) << "Resolver: Purging DNS cache";
@@ -972,12 +981,12 @@ class MyManager : public Manager, public Timer
it_next = it;
++it_next;
- if (req.created + static_cast<time_t>(req.ttl) < now)
+ if (req.created + static_cast<time_t>(req.ttl) < Anope::CurTime)
this->cache.erase(it);
}
}
- private:
+private:
/** Add a record to the dns cache
* @param r The record
*/
@@ -1007,7 +1016,8 @@ class MyManager : public Manager, public Timer
};
-class ModuleDNS : public Module
+class ModuleDNS final
+ : public Module
{
MyManager manager;
@@ -1017,13 +1027,13 @@ class ModuleDNS : public Module
std::vector<std::pair<Anope::string, short> > notify;
- public:
+public:
ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), manager(this)
{
}
- ~ModuleDNS()
+ ~ModuleDNS() override
{
for (std::map<int, Socket *>::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;)
{
@@ -1035,7 +1045,7 @@ class ModuleDNS : public Module
}
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
@@ -1053,7 +1063,7 @@ class ModuleDNS : public Module
Anope::string nip = n->Get<Anope::string>("ip");
short nport = n->Get<short>("port");
- notify.push_back(std::make_pair(nip, nport));
+ notify.emplace_back(nip, nport);
}
if (Anope::IsFile(nameserver))
@@ -1101,7 +1111,7 @@ class ModuleDNS : public Module
}
}
- void OnModuleUnload(User *u, Module *m) anope_override
+ void OnModuleUnload(User *u, Module *m) override
{
for (std::map<unsigned short, Request *>::iterator it = this->manager.requests.begin(), it_end = this->manager.requests.end(); it != it_end;)
{
diff --git a/modules/m_dnsbl.cpp b/modules/dnsbl.cpp
index 78bd9f596..af4d686e1 100644
--- a/modules/m_dnsbl.cpp
+++ b/modules/dnsbl.cpp
@@ -14,43 +14,42 @@ using namespace DNS;
static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
static ServiceReference<Manager> dnsmanager("DNS::Manager", "dns/manager");
-struct Blacklist
+struct Blacklist final
{
- struct Reply
+ struct Reply final
{
- int code;
+ int code = 0;
Anope::string reason;
- bool allow_account;
+ bool allow_account = false;
- Reply() : code(0), allow_account(false) { }
+ Reply() = default;
};
Anope::string name;
- time_t bantime;
+ time_t bantime = 0;
Anope::string reason;
std::vector<Reply> replies;
- Blacklist() : bantime(0) { }
-
- Reply *Find(int code)
+ const Reply *Find(int code)
{
- for (unsigned int i = 0; i < replies.size(); ++i)
- if (replies[i].code == code)
- return &replies[i];
+ for (const auto &reply : replies)
+ if (reply.code == code)
+ return &reply;
return NULL;
}
};
-class DNSBLResolver : public Request
+class DNSBLResolver final
+ : public Request
{
Reference<User> user;
Blacklist blacklist;
bool add_to_akill;
- public:
+public:
DNSBLResolver(Module *c, User *u, const Blacklist &b, const Anope::string &host, bool add_akill) : Request(dnsmanager, c, host, QUERY_A, true), user(u), blacklist(b), add_to_akill(add_akill) { }
- void OnLookupComplete(const Query *record) anope_override
+ void OnLookupComplete(const Query *record) override
{
if (!user || user->Quitting())
return;
@@ -64,7 +63,7 @@ class DNSBLResolver : public Request
sresult.pton(AF_INET, ans_record.rdata);
int result = sresult.sa4.sin_addr.s_addr >> 24;
- Blacklist::Reply *reply = blacklist.Find(result);
+ const Blacklist::Reply *reply = blacklist.Find(result);
if (!blacklist.replies.empty() && !reply)
return;
@@ -82,7 +81,7 @@ class DNSBLResolver : public Request
BotInfo *OperServ = Config->GetClient("OperServ");
Log(creator, "dnsbl", OperServ) << user->GetMask() << " (" << addr << ") appears in " << this->blacklist.name;
- XLine *x = new XLine("*@" + addr, OperServ ? OperServ->nick : "m_dnsbl", Anope::CurTime + this->blacklist.bantime, reason, XLineManager::GenerateUID());
+ auto *x = new XLine("*@" + addr, OperServ ? OperServ->nick : "dnsbl", Anope::CurTime + this->blacklist.bantime, reason, XLineManager::GenerateUID());
if (this->add_to_akill && akills)
{
akills->AddXLine(x);
@@ -96,7 +95,8 @@ class DNSBLResolver : public Request
}
};
-class ModuleDNSBL : public Module
+class ModuleDNSBL final
+ : public Module
{
std::vector<Blacklist> blacklists;
std::set<cidr> exempts;
@@ -104,13 +104,13 @@ class ModuleDNSBL : public Module
bool check_on_netburst;
bool add_to_akill;
- public:
+public:
ModuleDNSBL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
this->check_on_connect = block->Get<bool>("check_on_connect");
@@ -152,7 +152,7 @@ class ModuleDNSBL : public Module
}
}
- void OnUserConnect(User *user, bool &exempt) anope_override
+ void OnUserConnect(User *user, bool &exempt) override
{
if (exempt || user->Quitting() || (!this->check_on_connect && !Me->IsSynced()) || !dnsmanager)
return;
@@ -175,10 +175,8 @@ class ModuleDNSBL : public Module
Anope::string reverse = user->ip.reverse();
- for (unsigned i = 0; i < this->blacklists.size(); ++i)
+ for (const auto &b : this->blacklists)
{
- const Blacklist &b = this->blacklists[i];
-
Anope::string dnsbl_host = reverse + "." + b.name;
DNSBLResolver *res = NULL;
try
diff --git a/modules/encryption/enc_bcrypt.cpp b/modules/encryption/enc_bcrypt.cpp
index cbfc22fb6..8af775e6d 100644
--- a/modules/encryption/enc_bcrypt.cpp
+++ b/modules/encryption/enc_bcrypt.cpp
@@ -6,959 +6,177 @@
* This program is free but copyrighted software; see the file COPYING for
* details.
*
- * Most of the code in this file is taken from
- * https://www.openwall.com/crypt/crypt_blowfish-1.3.tar.gz
-*/
-
-/*
- * The crypt_blowfish homepage is:
- *
- * http://www.openwall.com/crypt/
- *
- * This code comes from John the Ripper password cracker, with reentrant
- * and crypt(3) interfaces added, but optimizations specific to password
- * cracking removed.
- *
- * Written by Solar Designer <solar at openwall.com> in 1998-2014.
- * No copyright is claimed, and the software is hereby placed in the public
- * domain. In case this attempt to disclaim copyright and place the software
- * in the public domain is deemed null and void, then the software is
- * Copyright (c) 1998-2014 Solar Designer and it is hereby released to the
- * general public under the following terms:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted.
- *
- * There's ABSOLUTELY NO WARRANTY, express or implied.
- *
- * It is my intent that you should be able to use this on your system,
- * as part of a software package, or anywhere else to improve security,
- * ensure compatibility, or for any other purpose. I would appreciate
- * it if you give credit where it is due and keep your modifications in
- * the public domain as well, but I don't require that in order to let
- * you place this code and any modifications you make under a license
- * of your choice.
- *
- * This implementation is fully compatible with OpenBSD's bcrypt.c for prefix
- * "$2b$", originally by Niels Provos <provos at citi.umich.edu>, and it uses
- * some of his ideas. The password hashing algorithm was designed by David
- * Mazieres <dm at lcs.mit.edu>. For information on the level of
- * compatibility for bcrypt hash prefixes other than "$2b$", please refer to
- * the comments in BF_set_key() below and to the included crypt(3) man page.
- *
- * There's a paper on the algorithm that explains its design decisions:
- *
- * http://www.usenix.org/events/usenix99/provos.html
- *
- * Some of the tricks in BF_ROUND might be inspired by Eric Young's
- * Blowfish library (I can't be sure if I would think of something if I
- * hadn't seen his code).
*/
-#include <string.h>
-
-#ifdef __i386__
-#define BF_SCALE 1
-#elif defined(__x86_64__) || defined(__alpha__) || defined(__hppa__)
-#define BF_SCALE 1
-#else
-#define BF_SCALE 0
-#endif
-typedef unsigned int BF_word;
-typedef signed int BF_word_signed;
+#include <climits>
+#include <random>
-/* Number of Blowfish rounds, this is also hardcoded into a few places */
-#define BF_N 16
+#include "bcrypt/crypt_blowfish.c"
-typedef BF_word BF_key[BF_N + 2];
-
-typedef struct {
- BF_word S[4][0x100];
- BF_key P;
-} BF_ctx;
+#include "module.h"
+#include "modules/encryption.h"
-/*
- * Magic IV for 64 Blowfish encryptions that we do at the end.
- * The string is "OrpheanBeholderScryDoubt" on big-endian.
- */
-static BF_word BF_magic_w[6] = {
- 0x4F727068, 0x65616E42, 0x65686F6C,
- 0x64657253, 0x63727944, 0x6F756274
-};
+class BCryptContext final
+ : public Encryption::Context
+{
+private:
+ Anope::string buffer;
-/*
- * P-box and S-box tables initialized with digits of Pi.
- */
-static BF_ctx BF_init_state = {
+ Anope::string GenerateSalt()
{
+ static std::random_device device;
+ static std::mt19937 engine(device());
+ static std::uniform_int_distribution<int> dist(CHAR_MIN, CHAR_MAX);
+ char entropy[16];
+ for (size_t i = 0; i < sizeof(entropy); ++i)
+ entropy[i] = static_cast<char>(dist(engine));
+
+ char salt[32];
+ if (!_crypt_gensalt_blowfish_rn("$2a$", rounds, entropy, sizeof(entropy), salt, sizeof(salt)))
{
- 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
- 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
- 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
- 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
- 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
- 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
- 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
- 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
- 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
- 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
- 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
- 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
- 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
- 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
- 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
- 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
- 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
- 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
- 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
- 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
- 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
- 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
- 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
- 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
- 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
- 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
- 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
- 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
- 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
- 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
- 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
- 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
- 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
- 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
- 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
- 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
- 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
- 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
- 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
- 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
- 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
- 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
- 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
- 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
- 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
- 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
- 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
- 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
- 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
- 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
- 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
- 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
- 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
- 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
- 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
- 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
- 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
- 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
- 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
- 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
- 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
- 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
- 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
- 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
- }, {
- 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
- 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
- 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
- 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
- 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
- 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
- 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
- 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
- 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
- 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
- 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
- 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
- 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
- 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
- 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
- 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
- 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
- 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
- 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
- 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
- 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
- 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
- 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
- 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
- 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
- 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
- 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
- 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
- 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
- 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
- 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
- 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
- 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
- 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
- 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
- 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
- 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
- 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
- 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
- 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
- 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
- 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
- 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
- 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
- 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
- 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
- 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
- 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
- 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
- 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
- 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
- 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
- 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
- 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
- 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
- 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
- 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
- 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
- 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
- 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
- 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
- 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
- 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
- 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
- }, {
- 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
- 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
- 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
- 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
- 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
- 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
- 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
- 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
- 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
- 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
- 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
- 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
- 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
- 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
- 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
- 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
- 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
- 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
- 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
- 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
- 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
- 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
- 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
- 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
- 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
- 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
- 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
- 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
- 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
- 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
- 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
- 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
- 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
- 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
- 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
- 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
- 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
- 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
- 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
- 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
- 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
- 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
- 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
- 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
- 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
- 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
- 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
- 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
- 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
- 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
- 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
- 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
- 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
- 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
- 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
- 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
- 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
- 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
- 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
- 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
- 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
- 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
- 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
- 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
- }, {
- 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
- 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
- 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
- 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
- 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
- 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
- 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
- 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
- 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
- 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
- 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
- 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
- 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
- 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
- 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
- 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
- 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
- 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
- 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
- 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
- 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
- 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
- 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
- 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
- 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
- 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
- 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
- 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
- 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
- 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
- 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
- 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
- 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
- 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
- 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
- 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
- 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
- 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
- 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
- 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
- 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
- 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
- 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
- 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
- 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
- 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
- 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
- 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
- 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
- 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
- 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
- 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
- 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
- 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
- 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
- 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
- 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
- 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
- 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
- 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
- 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
- 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
- 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
- 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
+ Log(LOG_DEBUG) << "Unable to generate a salt for Bcrypt: " << strerror(errno);
+ return {};
}
- }, {
- 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
- 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
- 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
- 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
- 0x9216d5d9, 0x8979fb1b
+ return salt;
}
-};
-static unsigned char BF_itoa64[64 + 1] =
- "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-
-static unsigned char BF_atoi64[0x60] = {
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1,
- 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 64, 64, 64, 64, 64,
- 64, 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, 64, 64, 64, 64, 64,
- 64, 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, 64, 64, 64, 64, 64
-};
+public:
+ static unsigned long rounds;
-#define BF_safe_atoi64(dst, src) \
-{ \
- tmp = (unsigned char)(src); \
- if ((unsigned int)(tmp -= 0x20) >= 0x60) return -1; \
- tmp = BF_atoi64[tmp]; \
- if (tmp > 63) return -1; \
- (dst) = tmp; \
-}
-
-static int BF_decode(BF_word *dst, const char *src, int size)
-{
- unsigned char *dptr = (unsigned char *)dst;
- unsigned char *end = dptr + size;
- const unsigned char *sptr = (const unsigned char *)src;
- unsigned int tmp, c1, c2, c3, c4;
-
- do {
- BF_safe_atoi64(c1, *sptr++);
- BF_safe_atoi64(c2, *sptr++);
- *dptr++ = (c1 << 2) | ((c2 & 0x30) >> 4);
- if (dptr >= end) break;
-
- BF_safe_atoi64(c3, *sptr++);
- *dptr++ = ((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2);
- if (dptr >= end) break;
-
- BF_safe_atoi64(c4, *sptr++);
- *dptr++ = ((c3 & 0x03) << 6) | c4;
- } while (dptr < end);
-
- return 0;
-}
-
-static void BF_encode(char *dst, const BF_word *src, int size)
-{
- const unsigned char *sptr = (const unsigned char *)src;
- const unsigned char *end = sptr + size;
- unsigned char *dptr = (unsigned char *)dst;
- unsigned int c1, c2;
-
- do {
- c1 = *sptr++;
- *dptr++ = BF_itoa64[c1 >> 2];
- c1 = (c1 & 0x03) << 4;
- if (sptr >= end) {
- *dptr++ = BF_itoa64[c1];
- break;
- }
-
- c2 = *sptr++;
- c1 |= c2 >> 4;
- *dptr++ = BF_itoa64[c1];
- c1 = (c2 & 0x0f) << 2;
- if (sptr >= end) {
- *dptr++ = BF_itoa64[c1];
- break;
- }
-
- c2 = *sptr++;
- c1 |= c2 >> 6;
- *dptr++ = BF_itoa64[c1];
- *dptr++ = BF_itoa64[c2 & 0x3f];
- } while (sptr < end);
-}
-
-static void BF_swap(BF_word *x, int count)
-{
- static int endianness_check = 1;
- char *is_little_endian = (char *)&endianness_check;
- BF_word tmp;
-
- if (*is_little_endian)
- do {
- tmp = *x;
- tmp = (tmp << 16) | (tmp >> 16);
- *x++ = ((tmp & 0x00FF00FF) << 8) | ((tmp >> 8) & 0x00FF00FF);
- } while (--count);
-}
-
-#if BF_SCALE
-/* Architectures which can shift addresses left by 2 bits with no extra cost */
-#define BF_ROUND(L, R, N) \
- tmp1 = L & 0xFF; \
- tmp2 = L >> 8; \
- tmp2 &= 0xFF; \
- tmp3 = L >> 16; \
- tmp3 &= 0xFF; \
- tmp4 = L >> 24; \
- tmp1 = data.ctx.S[3][tmp1]; \
- tmp2 = data.ctx.S[2][tmp2]; \
- tmp3 = data.ctx.S[1][tmp3]; \
- tmp3 += data.ctx.S[0][tmp4]; \
- tmp3 ^= tmp2; \
- R ^= data.ctx.P[N + 1]; \
- tmp3 += tmp1; \
- R ^= tmp3;
-#else
-/* Architectures with no complicated addressing modes supported */
-#define BF_INDEX(S, i) \
- (*((BF_word *)(((unsigned char *)S) + (i))))
-#define BF_ROUND(L, R, N) \
- tmp1 = L & 0xFF; \
- tmp1 <<= 2; \
- tmp2 = L >> 6; \
- tmp2 &= 0x3FC; \
- tmp3 = L >> 14; \
- tmp3 &= 0x3FC; \
- tmp4 = L >> 22; \
- tmp4 &= 0x3FC; \
- tmp1 = BF_INDEX(data.ctx.S[3], tmp1); \
- tmp2 = BF_INDEX(data.ctx.S[2], tmp2); \
- tmp3 = BF_INDEX(data.ctx.S[1], tmp3); \
- tmp3 += BF_INDEX(data.ctx.S[0], tmp4); \
- tmp3 ^= tmp2; \
- R ^= data.ctx.P[N + 1]; \
- tmp3 += tmp1; \
- R ^= tmp3;
-#endif
-
-/*
- * Encrypt one block, BF_N is hardcoded here.
- */
-#define BF_ENCRYPT \
- L ^= data.ctx.P[0]; \
- BF_ROUND(L, R, 0); \
- BF_ROUND(R, L, 1); \
- BF_ROUND(L, R, 2); \
- BF_ROUND(R, L, 3); \
- BF_ROUND(L, R, 4); \
- BF_ROUND(R, L, 5); \
- BF_ROUND(L, R, 6); \
- BF_ROUND(R, L, 7); \
- BF_ROUND(L, R, 8); \
- BF_ROUND(R, L, 9); \
- BF_ROUND(L, R, 10); \
- BF_ROUND(R, L, 11); \
- BF_ROUND(L, R, 12); \
- BF_ROUND(R, L, 13); \
- BF_ROUND(L, R, 14); \
- BF_ROUND(R, L, 15); \
- tmp4 = R; \
- R = L; \
- L = tmp4 ^ data.ctx.P[BF_N + 1];
-
-#define BF_body() \
- L = R = 0; \
- ptr = data.ctx.P; \
- do { \
- ptr += 2; \
- BF_ENCRYPT; \
- *(ptr - 2) = L; \
- *(ptr - 1) = R; \
- } while (ptr < &data.ctx.P[BF_N + 2]); \
-\
- ptr = data.ctx.S[0]; \
- do { \
- ptr += 2; \
- BF_ENCRYPT; \
- *(ptr - 2) = L; \
- *(ptr - 1) = R; \
- } while (ptr < &data.ctx.S[3][0xFF]);
-
-static void BF_set_key(const char *key, BF_key expanded, BF_key initial,
- unsigned char flags)
-{
- const char *ptr = key;
- unsigned int bug, i, j;
- BF_word safety, sign, diff, tmp[2];
-
-/*
- * There was a sign extension bug in older revisions of this function. While
- * we would have liked to simply fix the bug and move on, we have to provide
- * a backwards compatibility feature (essentially the bug) for some systems and
- * a safety measure for some others. The latter is needed because for certain
- * multiple inputs to the buggy algorithm there exist easily found inputs to
- * the correct algorithm that produce the same hash. Thus, we optionally
- * deviate from the correct algorithm just enough to avoid such collisions.
- * While the bug itself affected the majority of passwords containing
- * characters with the 8th bit set (although only a percentage of those in a
- * collision-producing way), the anti-collision safety measure affects
- * only a subset of passwords containing the '\xff' character (not even all of
- * those passwords, just some of them). This character is not found in valid
- * UTF-8 sequences and is rarely used in popular 8-bit character encodings.
- * Thus, the safety measure is unlikely to cause much annoyance, and is a
- * reasonable tradeoff to use when authenticating against existing hashes that
- * are not reliably known to have been computed with the correct algorithm.
- *
- * We use an approach that tries to minimize side-channel leaks of password
- * information - that is, we mostly use fixed-cost bitwise operations instead
- * of branches or table lookups. (One conditional branch based on password
- * length remains. It is not part of the bug aftermath, though, and is
- * difficult and possibly unreasonable to avoid given the use of C strings by
- * the caller, which results in similar timing leaks anyway.)
- *
- * For actual implementation, we set an array index in the variable "bug"
- * (0 means no bug, 1 means sign extension bug emulation) and a flag in the
- * variable "safety" (bit 16 is set when the safety measure is requested).
- * Valid combinations of settings are:
- *
- * Prefix "$2a$": bug = 0, safety = 0x10000
- * Prefix "$2b$": bug = 0, safety = 0
- * Prefix "$2x$": bug = 1, safety = 0
- * Prefix "$2y$": bug = 0, safety = 0
- */
- bug = (unsigned int)flags & 1;
- safety = ((BF_word)flags & 2) << 15;
-
- sign = diff = 0;
-
- for (i = 0; i < BF_N + 2; i++) {
- tmp[0] = tmp[1] = 0;
- for (j = 0; j < 4; j++) {
- tmp[0] <<= 8;
- tmp[0] |= (unsigned char)*ptr; /* correct */
- tmp[1] <<= 8;
- tmp[1] |= (BF_word_signed)(signed char)*ptr; /* bug */
-/*
- * Sign extension in the first char has no effect - nothing to overwrite yet,
- * and those extra 24 bits will be fully shifted out of the 32-bit word. For
- * chars 2, 3, 4 in each four-char block, we set bit 7 of "sign" if sign
- * extension in tmp[1] occurs. Once this flag is set, it remains set.
- */
- if (j)
- sign |= tmp[1] & 0x80;
- if (!*ptr)
- ptr = key;
- else
- ptr++;
+ static Anope::string Hash(const Anope::string &data, const Anope::string &salt)
+ {
+ char hash[64];
+ if (!_crypt_blowfish_rn(data.c_str(), salt.c_str(), hash, sizeof(hash)))
+ {
+ Log(LOG_DEBUG) << "Unable to generate a hash for Bcrypt: " << strerror(errno);
+ return {};
}
- diff |= tmp[0] ^ tmp[1]; /* Non-zero on any differences */
-
- expanded[i] = tmp[bug];
- initial[i] = BF_init_state.P[i] ^ tmp[bug];
- }
-
-/*
- * At this point, "diff" is zero iff the correct and buggy algorithms produced
- * exactly the same result. If so and if "sign" is non-zero, which indicates
- * that there was a non-benign sign extension, this means that we have a
- * collision between the correctly computed hash for this password and a set of
- * passwords that could be supplied to the buggy algorithm. Our safety measure
- * is meant to protect from such many-buggy to one-correct collisions, by
- * deviating from the correct algorithm in such cases. Let's check for this.
- */
- diff |= diff >> 16; /* still zero iff exact match */
- diff &= 0xffff; /* ditto */
- diff += 0xffff; /* bit 16 set iff "diff" was non-zero (on non-match) */
- sign <<= 9; /* move the non-benign sign extension flag to bit 16 */
- sign &= ~diff & safety; /* action needed? */
-
-/*
- * If we have determined that we need to deviate from the correct algorithm,
- * flip bit 16 in initial expanded key. (The choice of 16 is arbitrary, but
- * let's stick to it now. It came out of the approach we used above, and it's
- * not any worse than any other choice we could make.)
- *
- * It is crucial that we don't do the same to the expanded key used in the main
- * Eksblowfish loop. By doing it to only one of these two, we deviate from a
- * state that could be directly specified by a password to the buggy algorithm
- * (and to the fully correct one as well, but that's a side-effect).
- */
- initial[0] ^= sign;
-}
-
-static const unsigned char flags_by_subtype[26] =
- {2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0};
-
-static char *BF_crypt(const char *key, const char *setting,
- char *output, int size,
- BF_word min)
-{
- struct {
- BF_ctx ctx;
- BF_key expanded_key;
- union {
- BF_word salt[4];
- BF_word output[6];
- } binary;
- } data;
- BF_word L, R;
- BF_word tmp1, tmp2, tmp3, tmp4;
- BF_word *ptr;
- BF_word count;
- int i;
-
- if (size < 7 + 22 + 31 + 1) {
- return NULL;
- }
-
- if (setting[0] != '$' ||
- setting[1] != '2' ||
- setting[2] < 'a' || setting[2] > 'z' ||
- !flags_by_subtype[(unsigned int)(unsigned char)setting[2] - 'a'] ||
- setting[3] != '$' ||
- setting[4] < '0' || setting[4] > '3' ||
- setting[5] < '0' || setting[5] > '9' ||
- (setting[4] == '3' && setting[5] > '1') ||
- setting[6] != '$') {
- return NULL;
- }
-
- count = (BF_word)1 << ((setting[4] - '0') * 10 + (setting[5] - '0'));
- if (count < min || BF_decode(data.binary.salt, &setting[7], 16)) {
- return NULL;
+ return hash;
}
- BF_swap(data.binary.salt, 4);
-
- BF_set_key(key, data.expanded_key, data.ctx.P,
- flags_by_subtype[(unsigned int)(unsigned char)setting[2] - 'a']);
-
- memcpy(data.ctx.S, BF_init_state.S, sizeof(data.ctx.S));
- L = R = 0;
- for (i = 0; i < BF_N + 2; i += 2) {
- L ^= data.binary.salt[i & 2];
- R ^= data.binary.salt[(i & 2) + 1];
- BF_ENCRYPT;
- data.ctx.P[i] = L;
- data.ctx.P[i + 1] = R;
+ void Update(const unsigned char *data, size_t len) override
+ {
+ buffer.append(reinterpret_cast<const char *>(data), len);
}
- ptr = data.ctx.S[0];
- do {
- ptr += 4;
- L ^= data.binary.salt[(BF_N + 2) & 3];
- R ^= data.binary.salt[(BF_N + 3) & 3];
- BF_ENCRYPT;
- *(ptr - 4) = L;
- *(ptr - 3) = R;
-
- L ^= data.binary.salt[(BF_N + 4) & 3];
- R ^= data.binary.salt[(BF_N + 5) & 3];
- BF_ENCRYPT;
- *(ptr - 2) = L;
- *(ptr - 1) = R;
- } while (ptr < &data.ctx.S[3][0xFF]);
-
- do {
- int done;
-
- for (i = 0; i < BF_N + 2; i += 2) {
- data.ctx.P[i] ^= data.expanded_key[i];
- data.ctx.P[i + 1] ^= data.expanded_key[i + 1];
- }
-
- done = 0;
- do {
- BF_body();
- if (done)
- break;
- done = 1;
-
- tmp1 = data.binary.salt[0];
- tmp2 = data.binary.salt[1];
- tmp3 = data.binary.salt[2];
- tmp4 = data.binary.salt[3];
- for (i = 0; i < BF_N; i += 4) {
- data.ctx.P[i] ^= tmp1;
- data.ctx.P[i + 1] ^= tmp2;
- data.ctx.P[i + 2] ^= tmp3;
- data.ctx.P[i + 3] ^= tmp4;
- }
- data.ctx.P[16] ^= tmp1;
- data.ctx.P[17] ^= tmp2;
- } while (1);
- } while (--count);
-
- for (i = 0; i < 6; i += 2) {
- L = BF_magic_w[i];
- R = BF_magic_w[i + 1];
-
- count = 64;
- do {
- BF_ENCRYPT;
- } while (--count);
-
- data.binary.output[i] = L;
- data.binary.output[i + 1] = R;
+ Anope::string Finalize() override
+ {
+ auto salt = GenerateSalt();
+ if (salt.empty())
+ return {};
+ return Hash(this->buffer, salt);
}
+};
- memcpy(output, setting, 7 + 22 - 1);
- output[7 + 22 - 1] = BF_itoa64[(int)
- BF_atoi64[(int)setting[7 + 22 - 1] - 0x20] & 0x30];
-
-/* This has to be bug-compatible with the original implementation, so
- * only encode 23 of the 24 bytes. :-) */
- BF_swap(data.binary.output, 6);
- BF_encode(&output[7 + 22], data.binary.output, 23);
- output[7 + 22 + 31] = '\0';
-
- return output;
-}
-
-int _crypt_output_magic(const char *setting, char *output, int size)
-{
- if (size < 3)
- return -1;
-
- output[0] = '*';
- output[1] = '0';
- output[2] = '\0';
-
- if (setting[0] == '*' && setting[1] == '0')
- output[1] = '1';
-
- return 0;
-}
-
-/*
- * Please preserve the runtime self-test. It serves two purposes at once:
- *
- * 1. We really can't afford the risk of producing incompatible hashes e.g.
- * when there's something like gcc bug 26587 again, whereas an application or
- * library integrating this code might not also integrate our external tests or
- * it might not run them after every build. Even if it does, the miscompile
- * might only occur on the production build, but not on a testing build (such
- * as because of different optimization settings). It is painful to recover
- * from incorrectly-computed hashes - merely fixing whatever broke is not
- * enough. Thus, a proactive measure like this self-test is needed.
- *
- * 2. We don't want to leave sensitive data from our actual password hash
- * computation on the stack or in registers. Previous revisions of the code
- * would do explicit cleanups, but simply running the self-test after hash
- * computation is more reliable.
- *
- * The performance cost of this quick self-test is around 0.6% at the "$2a$08"
- * setting.
- */
-char *_crypt_blowfish_rn(const char *key, const char *setting,
- char *output, int size)
-{
- _crypt_output_magic(setting, output, size);
- return BF_crypt(key, setting, output, size, 16);
-}
+unsigned long BCryptContext::rounds = 10;
-char *_crypt_gensalt_blowfish_rn(const char *prefix, unsigned long count,
- const char *input, int size, char *output, int output_size)
+class BCryptProvider final
+ : public Encryption::Provider
{
- if (size < 16 || output_size < 7 + 22 + 1 ||
- (count && (count < 4 || count > 31)) ||
- prefix[0] != '$' || prefix[1] != '2' ||
- (prefix[2] != 'a' && prefix[2] != 'b' && prefix[2] != 'y')) {
- if (output_size > 0) output[0] = '\0';
- return NULL;
+public:
+ BCryptProvider(Module *creator)
+ : Encryption::Provider(creator, "bcrypt", 0, 0)
+ {
}
- if (!count) count = 5;
-
- output[0] = '$';
- output[1] = '2';
- output[2] = prefix[2];
- output[3] = '$';
- output[4] = '0' + count / 10;
- output[5] = '0' + count % 10;
- output[6] = '$';
-
- BF_encode(&output[7], (const BF_word *)input, 16);
- output[7 + 22] = '\0';
-
- return output;
-}
-
-// Start Anope-specific code
-
-#include "module.h"
-#include "modules/encryption.h"
-
-class EBCRYPT : public Module
-{
- unsigned int rounds;
-
- Anope::string Salt()
+ bool Compare(const Anope::string &hash, const Anope::string &plain) override
{
- char entropy[16];
- for (unsigned int i = 0; i < sizeof(entropy); i++)
- entropy[i] = static_cast<char>(rand() % 0xFF);
+ auto newhash = BCryptContext::Hash(plain, hash);
+ return !newhash.empty() && hash.equals_cs(newhash);
+ }
- char salt[32];
- if (!_crypt_gensalt_blowfish_rn("$2a$", rounds, entropy, sizeof(entropy), salt, sizeof(salt)))
- return "";
- return salt;
+ std::unique_ptr<Encryption::Context> CreateContext() override
+ {
+ return std::make_unique<BCryptContext>();
}
- Anope::string Generate(const Anope::string& data, const Anope::string& salt)
+ Anope::string ToPrintable(const Anope::string &hash) override
{
- char hash[64];
- _crypt_blowfish_rn(data.c_str(), salt.c_str(), hash, sizeof(hash));
+ // The crypt_blowfish library does not expose a raw form.
return hash;
}
+};
- bool Compare(const Anope::string& string, const Anope::string& hash)
- {
- Anope::string ret = Generate(string, hash);
- if (ret.empty())
- return false;
- return (ret == hash);
- }
+class EBCrypt final
+ : public Module
+{
+private:
+ BCryptProvider bcryptprovider;
- public:
- EBCRYPT(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR),
- rounds(10)
+public:
+ EBCrypt(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
+ , bcryptprovider(this)
{
- // Test a pre-calculated hash
- bool test = Compare("Test!", "$2a$10$x9AQFAQScY0v9KF2suqkEOepsHFrG.CXHbIXI.1F28SfSUb56A/7K");
-
- Anope::string salt;
- Anope::string hash;
- // Make sure it's working
- if (!test || (salt = Salt()).empty() || (hash = Generate("Test!", salt)).empty() || !Compare("Test!", hash))
- throw ModuleException("BCrypt could not load!");
+ bcryptprovider.Check({
+ { "$2a$10$c9lUAuJmTYXEfNuLOiyIp.lZTMM.Rw5qsSAyZhvGT9EC3JevkUuOu", "" },
+ { "$2a$10$YV4jDSGs0ZtQbpL6IHtNO.lt5Q.uzghIohCcnERQVBGyw7QJMfyhe", "The quick brown fox jumps over the lazy dog" },
+ });
}
- EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
+ EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) override
{
- dest = "bcrypt:" + Generate(src, Salt());
+ dest = "bcrypt:" + bcryptprovider.Encrypt(src);
Log(LOG_DEBUG_2) << "(enc_bcrypt) hashed password from [" << src << "] to [" << dest << "]";
return EVENT_ALLOW;
}
- void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
{
- const NickAlias *na = NickAlias::Find(req->GetAccount());
- if (na == NULL)
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
return;
- NickCore *nc = na->nc;
- size_t pos = nc->pass.find(':');
+ NickCore *nc = na->nc;
+ auto pos = nc->pass.find(':');
if (pos == Anope::string::npos)
return;
+
Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
- if (hash_method != "bcrypt")
+ if (!hash_method.equals_cs("bcrypt"))
return;
- if (Compare(req->GetPassword(), nc->pass.substr(7)))
+ Anope::string hash_value(nc->pass.begin() + pos + 1, nc->pass.end());
+ if (bcryptprovider.Compare(hash_value, req->GetPassword()))
{
- /* if we are NOT the first module in the list,
- * we want to re-encrypt the pass with the new encryption
- */
+ unsigned long rounds = 0;
- unsigned int hashrounds = 0;
- try
- {
- size_t roundspos = nc->pass.find('$', 11);
- if (roundspos == Anope::string::npos)
- throw ConvertException("Could not find hashrounds");
+ // Try to extract the rounds count to check if we need to
+ // re-encrypt the password.
+ pos = hash_value.find('$', 4);
+ if (pos != Anope::string::npos)
+ rounds = Anope::Convert<unsigned long>(hash_value.substr(4, pos - 4), 0);
- hashrounds = convertTo<unsigned int>(nc->pass.substr(11, roundspos - 11));
- }
- catch (const ConvertException &)
- {
- Log(this) << "Could not get the round size of a hash. This is probably a bug. Hash: " << nc->pass;
- }
+ if (!rounds)
+ Log(LOG_DEBUG) << "Unable to determine the rounds of a bcrypt hash: " << hash_value;
- if (ModuleManager::FindFirstOf(ENCRYPTION) != this || (hashrounds && hashrounds != rounds))
+ // If we are NOT the first encryption module or the Bcrypt rounds
+ // are different we want to re-encrypt the password with the primary
+ // encryption method.
+ if (ModuleManager::FindFirstOf(ENCRYPTION) != this || (rounds && rounds != BCryptContext::rounds))
Anope::Encrypt(req->GetPassword(), nc->pass);
req->Success(this);
}
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
- Configuration::Block *block = conf->GetModule(this);
- rounds = block->Get<unsigned int>("rounds", "10");
+ auto *block = conf->GetModule(this);
- if (rounds == 0)
+ auto rounds = block->Get<unsigned long>("rounds", "10");
+ if (rounds < 10 || rounds > 32)
{
- rounds = 10;
- Log(this) << "Rounds can't be 0! Setting ignored.";
- }
- else if (rounds < 10)
- {
- Log(this) << "10 to 12 rounds is recommended.";
- }
- else if (rounds >= 32)
- {
- rounds = 10;
- Log(this) << "The maximum number of rounds supported is 31. Ignoring setting and using 10.";
- }
- else if (rounds >= 14)
- {
- Log(this) << "Are you sure you want to use " << stringify(rounds) << " in your bcrypt settings? This is very CPU intensive! Recommended rounds is 10-12.";
+ Log(this) << "Bcrypt rounds MUST be between 10 and 32 inclusive; using 10 instead of " << rounds << '.';
+ BCryptContext::rounds = 10;
+ return;
}
+
+ if (rounds > 14)
+ Log(this) << "Bcrypt rounds higher than 14 are very CPU intensive; are you sure you want to use " << rounds << '?';
+ BCryptContext::rounds = rounds;
}
};
-MODULE_INIT(EBCRYPT)
+MODULE_INIT(EBCrypt)
diff --git a/modules/encryption/enc_md5.cpp b/modules/encryption/enc_md5.cpp
index 15cf2cf2e..023e04656 100644
--- a/modules/encryption/enc_md5.cpp
+++ b/modules/encryption/enc_md5.cpp
@@ -5,7 +5,7 @@
* Contact us at team@anope.org
*
* Taken from IRC Services and is copyright (c) 1996-2002 Andrew Church.
- * E-mail: <achurch@achurch.org>
+ * Email: <achurch@achurch.org>
* Parts written by Andrew Kempe and others.
* This program is free but copyrighted software; see the file COPYING for
* details.
@@ -14,377 +14,73 @@
#include "module.h"
#include "modules/encryption.h"
-/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
-rights reserved.
+#include "md5/md5.c"
-License to copy and use this software is granted provided that it
-is identified as the "RSA Data Security, Inc. MD5 Message-Digest
-Algorithm" in all material mentioning or referencing this software
-or this function.
-
-License is also granted to make and use derivative works provided
-that such works are identified as "derived from the RSA Data
-Security, Inc. MD5 Message-Digest Algorithm" in all material
-mentioning or referencing the derived work.
-
-RSA Data Security, Inc. makes no representations concerning either
-the merchantability of this software or the suitability of this
-software for any particular purpose. It is provided "as is"
-without express or implied warranty of any kind.
-
-These notices must be retained in any copies of any part of this
-documentation and/or software.
- */
-
-static unsigned char PADDING[64] = {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/* F, G, H and I are basic MD5 functions.
- */
-inline static unsigned F(unsigned x, unsigned y, unsigned z) { return (x & y) | (~x & z); }
-inline static unsigned G(unsigned x, unsigned y, unsigned z) { return (x & z) | (y & ~z); }
-inline static unsigned H(unsigned x, unsigned y, unsigned z) { return x ^ y ^ z; }
-inline static unsigned I(unsigned x, unsigned y, unsigned z) { return y ^ (x | ~z); }
-
-/* ROTATE_LEFT rotates x left n bits.
- */
-inline static unsigned ROTATE_LEFT(unsigned x, unsigned n) { return (x << n) | (x >> (32 - n)); }
-
-/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- * Rotation is separate from addition to prevent recomputation.
- */
-inline static void FF(unsigned &a, unsigned b, unsigned c, unsigned d, unsigned x, unsigned s, unsigned ac)
-{
- a += F(b, c, d) + x + ac;
- a = ROTATE_LEFT(a, s);
- a += b;
-}
-inline static void GG(unsigned &a, unsigned b, unsigned c, unsigned d, unsigned x, unsigned s, unsigned ac)
-{
- a += G(b, c, d) + x + ac;
- a = ROTATE_LEFT(a, s);
- a += b;
-}
-inline static void HH(unsigned &a, unsigned b, unsigned c, unsigned d, unsigned x, unsigned s, unsigned ac)
-{
- a += H(b, c, d) + x + ac;
- a = ROTATE_LEFT(a, s);
- a += b;
-}
-inline static void II(unsigned &a, unsigned b, unsigned c, unsigned d, unsigned x, unsigned s, unsigned ac)
-{
- a += I(b, c, d) + x + ac;
- a = ROTATE_LEFT(a, s);
- a += b;
-}
-
-static const uint32_t md5_iv[4] =
-{
- 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
-};
-
-class MD5Context : public Encryption::Context
+class MD5Context final
+ : public Encryption::Context
{
- unsigned state[4]; /* state (ABCD) */
- unsigned count[2]; /* number of bits, modulo 2^64 (lsb first) */
- unsigned char buffer[64]; /* input buffer */
- unsigned char digest[16]; /* final digest */
-
- /* Constants for MD5Transform routine.
- */
- enum
- {
- S11 = 7,
- S12 = 12,
- S13 = 17,
- S14 = 22,
- S21 = 5,
- S22 = 9,
- S23 = 14,
- S24 = 20,
- S31 = 4,
- S32 = 11,
- S33 = 16,
- S34 = 23,
- S41 = 6,
- S42 = 10,
- S43 = 15,
- S44 = 21
- };
-
- /* MD5 basic transformation. Transforms state based on block.
- */
- void Transform(const unsigned char block[64])
- {
- unsigned a = state[0], b = state[1], c = state[2], d = state[3], x[16];
-
- Decode(x, block, 64);
-
- /* Round 1 */
- FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
- FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
- FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
- FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
- FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
- FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
- FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
- FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
- FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
- FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
- FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
- FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
- FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
- FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
- FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
- FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
-
- /* Round 2 */
- GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
- GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
- GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
- GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
- GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
- GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
- GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
- GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
- GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
- GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
- GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
- GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
- GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
- GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
- GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
- GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
-
- /* Round 3 */
- HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
- HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
- HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
- HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
- HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
- HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
- HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
- HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
- HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
- HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
- HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
- HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
- HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
- HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
- HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
- HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */
-
- /* Round 4 */
- II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
- II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
- II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
- II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
- II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
- II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
- II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
- II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
- II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
- II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
- II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
- II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
- II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
- II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
- II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
- II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */
-
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
-
- /* Zeroize sensitive information. */
- memset(x, 0, sizeof(x));
- }
-
- /* Encodes input (unsigned) into output (unsigned char). Assumes len is
- * a multiple of 4.
- */
- void Encode(unsigned char *output, unsigned *input, unsigned len)
- {
- for (unsigned i = 0, j = 0; j < len; ++i, j += 4)
- {
- output[j] = static_cast<unsigned char>(input[i] & 0xff);
- output[j + 1] = static_cast<unsigned char>((input[i] >> 8) & 0xff);
- output[j + 2] = static_cast<unsigned char>((input[i] >> 16) & 0xff);
- output[j + 3] = static_cast<unsigned char>((input[i] >> 24) & 0xff);
- }
- }
-
- /* Decodes input (unsigned char) into output (unsigned). Assumes len is
- * a multiple of 4.
- */
- void Decode(unsigned *output, const unsigned char *input, unsigned len)
- {
- for (unsigned i = 0, j = 0; j < len; ++i, j += 4)
- output[i] = static_cast<unsigned>(input[j]) | (static_cast<unsigned>(input[j + 1]) << 8) | (static_cast<unsigned>(input[j + 2]) << 16) | (static_cast<unsigned>(input[j + 3]) << 24);
- }
-
- public:
- MD5Context(Encryption::IV *iv = NULL)
- {
- if (iv != NULL)
- {
- if (iv->second != 4)
- throw CoreException("Invalid IV size");
- /* Load magic initialization constants. */
- for (int i = 0; i < 4; ++i)
- this->state[i] = iv->first[i];
- }
- else
- for (int i = 0; i < 4; ++i)
- this->state[i] = md5_iv[i];
+private:
+ MD5_CTX context;
- this->count[0] = this->count[1] = 0;
- memset(this->buffer, 0, sizeof(this->buffer));
- }
-
- /* MD5 block update operation. Continues an MD5 message-digest
- * operation, processing another message block, and updating the
- * context.
- */
- void Update(const unsigned char *input, size_t len) anope_override
+public:
+ MD5Context()
{
- unsigned i, index, partLen;
-
- /* Compute number of bytes mod 64 */
- index = (this->count[0] >> 3) & 0x3F;
-
- /* Update number of bits */
- if ((this->count[0] += len << 3) < (len << 3))
- ++this->count[1];
- this->count[1] += len >> 29;
-
- partLen = 64 - index;
-
- /* Transform as many times as possible. */
- if (len >= partLen)
- {
- memcpy(&this->buffer[index], input, partLen);
- this->Transform(this->buffer);
-
- for (i = partLen; i + 63 < len; i += 64)
- this->Transform(&input[i]);
-
- index = 0;
- }
- else
- i = 0;
-
- /* Buffer remaining input */
- memcpy(&this->buffer[index], &input[i], len - i);
+ MD5_Init(&context);
}
- /* MD5 finalization. Ends an MD5 message-digest opera
- * the message digest and zeroizing the context.
- */
- void Finalize() anope_override
+ void Update(const unsigned char *input, size_t len) override
{
- unsigned char bits[8];
- unsigned index, padLen;
-
- /* Save number of bits */
- this->Encode(bits, this->count, 8);
-
- /* Pad out to 56 mod 64. */
- index = (this->count[0] >> 3) & 0x3f;
- padLen = index < 56 ? 56 - index : 120 - index;
- this->Update(PADDING, padLen);
-
- /* Append length (before padding) */
- this->Update(bits, 8);
- /* Store state in digest */
- this->Encode(digest, this->state, 16);
-
- /* Zeroize sensitive information. */
- memset(this->state, 0, sizeof(this->state));
- memset(this->count, 0, sizeof(this->count));
- memset(this->buffer, 0, sizeof(this->buffer));
+ MD5_Update(&context, input, len);
}
- Encryption::Hash GetFinalizedHash() anope_override
+ Anope::string Finalize() override
{
- Encryption::Hash hash;
- hash.first = this->digest;
- hash.second = sizeof(this->digest);
- return hash;
+ unsigned char digest[16];
+ MD5_Final(digest, &context);
+ return Anope::string(reinterpret_cast<const char *>(&digest), sizeof(digest));
}
};
-class MD5Provider : public Encryption::Provider
+class EMD5 final
+ : public Module
{
- public:
- MD5Provider(Module *creator) : Encryption::Provider(creator, "md5") { }
+private:
+ Encryption::SimpleProvider<MD5Context> md5provider;
- Encryption::Context *CreateContext(Encryption::IV *iv) anope_override
- {
- return new MD5Context(iv);
- }
-
- Encryption::IV GetDefaultIV() anope_override
- {
- Encryption::IV iv;
- iv.first = md5_iv;
- iv.second = sizeof(md5_iv) / sizeof(uint32_t);
- return iv;
- }
-};
-
-class EMD5 : public Module
-{
- MD5Provider md5provider;
-
- public:
- EMD5(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR),
- md5provider(this)
+public:
+ EMD5(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
+ , md5provider(this, "md5", 16, 64)
{
+ if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
+ throw ModuleException("enc_md5 is deprecated and can not be used as a primary encryption method");
+ md5provider.Check({
+ { "d41d8cd98f00b204e9800998ecf8427e", "" },
+ { "9e107d9d372bb6826bd81d3542a419d6", "The quick brown fox jumps over the lazy dog" },
+ });
}
- EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
{
- MD5Context context;
-
- context.Update(reinterpret_cast<const unsigned char *>(src.c_str()), src.length());
- context.Finalize();
-
- Encryption::Hash hash = context.GetFinalizedHash();
-
- Anope::string buf = "md5:" + Anope::Hex(reinterpret_cast<const char *>(hash.first), hash.second);
-
- Log(LOG_DEBUG_2) << "(enc_md5) hashed password from [" << src << "] to [" << buf << "]";
- dest = buf;
- return EVENT_ALLOW;
- }
-
- void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
- {
- const NickAlias *na = NickAlias::Find(req->GetAccount());
- if (na == NULL)
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
return;
- NickCore *nc = na->nc;
- size_t pos = nc->pass.find(':');
+ NickCore *nc = na->nc;
+ auto pos = nc->pass.find(':');
if (pos == Anope::string::npos)
return;
+
Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
if (!hash_method.equals_cs("md5"))
return;
- Anope::string buf;
- this->OnEncrypt(req->GetPassword(), buf);
- if (nc->pass.equals_cs(buf))
+ auto enc = "md5:" + Anope::Hex(md5provider.Encrypt(req->GetPassword()));
+ if (nc->pass.equals_cs(enc))
{
- /* if we are NOT the first module in the list,
- * we want to re-encrypt the pass with the new encryption
- */
+ // If we are NOT the first encryption module we want to re-encrypt
+ // the password with the primary encryption method.
if (ModuleManager::FindFirstOf(ENCRYPTION) != this)
Anope::Encrypt(req->GetPassword(), nc->pass);
req->Success(this);
diff --git a/modules/encryption/enc_none.cpp b/modules/encryption/enc_none.cpp
index 322bea0db..253ffd94c 100644
--- a/modules/encryption/enc_none.cpp
+++ b/modules/encryption/enc_none.cpp
@@ -9,56 +9,39 @@
#include "module.h"
-class ENone : public Module
+class ENone final
+ : public Module
{
- public:
- ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
+public:
+ ENone(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
{
-
- }
-
- EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
- {
- Anope::string buf = "plain:";
- Anope::string cpass;
- Anope::B64Encode(src, cpass);
- buf += cpass;
- Log(LOG_DEBUG_2) << "(enc_none) hashed password from [" << src << "] to [" << buf << "]";
- dest = buf;
- return EVENT_ALLOW;
- }
-
- EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) anope_override
- {
- if (!hashm.equals_cs("plain"))
- return EVENT_CONTINUE;
- size_t pos = src.find(':');
- Anope::string buf = src.substr(pos + 1);
- Anope::B64Decode(buf, dest);
- return EVENT_ALLOW;
+ if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
+ throw ModuleException("enc_none is deprecated and can not be used as a primary encryption method");
}
- void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
{
- const NickAlias *na = NickAlias::Find(req->GetAccount());
- if (na == NULL)
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
return;
- NickCore *nc = na->nc;
- size_t pos = nc->pass.find(':');
+ NickCore *nc = na->nc;
+ auto pos = nc->pass.find(':');
if (pos == Anope::string::npos)
return;
+
Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
if (!hash_method.equals_cs("plain"))
return;
- Anope::string buf;
- this->OnEncrypt(req->GetPassword(), buf);
- if (nc->pass.equals_cs(buf))
+ Anope::string b64pass;
+ Anope::B64Encode(req->GetPassword(), b64pass);
+ auto enc = "plain:" + b64pass;
+ if (nc->pass.equals_cs(enc))
{
- /* if we are NOT the first module in the list,
- * we want to re-encrypt the pass with the new encryption
- */
+ // If we are NOT the first encryption module we want to re-encrypt
+ // the password with the primary encryption method.
if (ModuleManager::FindFirstOf(ENCRYPTION) != this)
Anope::Encrypt(req->GetPassword(), nc->pass);
req->Success(this);
diff --git a/modules/encryption/enc_old.cpp b/modules/encryption/enc_old.cpp
index be3225175..4b6dc438a 100644
--- a/modules/encryption/enc_old.cpp
+++ b/modules/encryption/enc_old.cpp
@@ -12,94 +12,70 @@
#include "module.h"
#include "modules/encryption.h"
-static ServiceReference<Encryption::Provider> md5("Encryption::Provider", "md5");
-
-class OldMD5Provider : public Encryption::Provider
+class EOld final
+ : public Module
{
- public:
- OldMD5Provider(Module *creator) : Encryption::Provider(creator, "oldmd5") { }
+private:
+ ServiceReference<Encryption::Provider> md5;
- Encryption::Context *CreateContext(Encryption::IV *iv) anope_override
+ Anope::string EncryptInternal(const Anope::string &src)
{
- if (md5)
- return md5->CreateContext(iv);
- return NULL;
+ if (!md5)
+ return {};
+
+ char digest[32];
+ memset(digest, 0, sizeof(digest));
+
+ auto hash = md5->Encrypt(src);
+ if (hash.length() != sizeof(digest))
+ return {}; // Probably a bug?
+ memcpy(digest, hash.data(), hash.length());
+
+ char digest2[16];
+ for (size_t i = 0; i < sizeof(digest); i += 2)
+ digest2[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]);
+
+ return Anope::Hex(digest2, sizeof(digest2));
}
- Encryption::IV GetDefaultIV() anope_override
+ inline static char XTOI(char c)
{
- if (md5)
- return md5->GetDefaultIV();
- return Encryption::IV(static_cast<const uint32_t *>(NULL), 0);
+ return c > 9 ? c - 'A' + 10 : c - '0';
}
-};
-
-class EOld : public Module
-{
- OldMD5Provider oldmd5provider;
- inline static char XTOI(char c) { return c > 9 ? c - 'A' + 10 : c - '0'; }
-
- public:
- EOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR),
- oldmd5provider(this)
+public:
+ EOld(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
+ , md5("Encryption::Provider", "md5")
{
+ if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
+ throw ModuleException("enc_old is deprecated and can not be used as a primary encryption method");
ModuleManager::LoadModule("enc_md5", User::Find(creator, true));
if (!md5)
throw ModuleException("Unable to find md5 reference");
-
- }
-
- EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
- {
- if (!md5)
- return EVENT_CONTINUE;
-
- Encryption::Context *context = md5->CreateContext();
- context->Update(reinterpret_cast<const unsigned char *>(src.c_str()), src.length());
- context->Finalize();
-
- Encryption::Hash hash = context->GetFinalizedHash();
-
- char digest[32], digest2[16];
- memset(digest, 0, sizeof(digest));
- if (hash.second > sizeof(digest))
- throw CoreException("Hash too large");
- memcpy(digest, hash.first, hash.second);
-
- for (int i = 0; i < 32; i += 2)
- digest2[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]);
-
- Anope::string buf = "oldmd5:" + Anope::Hex(digest2, sizeof(digest2));
-
- Log(LOG_DEBUG_2) << "(enc_old) hashed password from [" << src << "] to [" << buf << "]";
- dest = buf;
- delete context;
- return EVENT_ALLOW;
}
- void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
{
- const NickAlias *na = NickAlias::Find(req->GetAccount());
- if (na == NULL)
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
return;
- NickCore *nc = na->nc;
+ NickCore *nc = na->nc;
size_t pos = nc->pass.find(':');
if (pos == Anope::string::npos)
return;
+
Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
if (!hash_method.equals_cs("oldmd5"))
return;
- Anope::string buf;
- this->OnEncrypt(req->GetPassword(), buf);
- if (nc->pass.equals_cs(buf))
+ auto enc = EncryptInternal(req->GetPassword());
+ if (!enc.empty() && nc->pass.equals_cs(enc))
{
- /* if we are NOT the first module in the list,
- * we want to re-encrypt the pass with the new encryption
- */
+ // If we are NOT the first encryption module we want to re-encrypt
+ // the password with the primary encryption method.
if (ModuleManager::FindFirstOf(ENCRYPTION) != this)
Anope::Encrypt(req->GetPassword(), nc->pass);
req->Success(this);
diff --git a/modules/encryption/enc_sha1.cpp b/modules/encryption/enc_sha1.cpp
index a0088f975..135a1121d 100644
--- a/modules/encryption/enc_sha1.cpp
+++ b/modules/encryption/enc_sha1.cpp
@@ -54,12 +54,12 @@ static const uint32_t sha1_iv[5] =
0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0
};
-class SHA1Context : public Encryption::Context
+class SHA1Context final
+ : public Encryption::Context
{
uint32_t state[5];
uint32_t count[2];
unsigned char buffer[64];
- unsigned char digest[20];
void Transform(const unsigned char buf[64])
{
@@ -106,26 +106,17 @@ class SHA1Context : public Encryption::Context
a = b = c = d = e = 0;
}
- public:
- SHA1Context(Encryption::IV *iv = NULL)
+public:
+ SHA1Context()
{
- if (iv != NULL)
- {
- if (iv->second != 5)
- throw CoreException("Invalid IV size");
- for (int i = 0; i < 5; ++i)
- this->state[i] = iv->first[i];
- }
- else
- for (int i = 0; i < 5; ++i)
- this->state[i] = sha1_iv[i];
+ for (int i = 0; i < 5; ++i)
+ this->state[i] = sha1_iv[i];
this->count[0] = this->count[1] = 0;
memset(this->buffer, 0, sizeof(this->buffer));
- memset(this->digest, 0, sizeof(this->digest));
}
- void Update(const unsigned char *data, size_t len) anope_override
+ void Update(const unsigned char *data, size_t len) override
{
uint32_t i, j;
@@ -146,7 +137,7 @@ class SHA1Context : public Encryption::Context
memcpy(&this->buffer[j], &data[i], len - i);
}
- void Finalize() anope_override
+ Anope::string Finalize() override
{
uint32_t i;
unsigned char finalcount[8];
@@ -157,8 +148,10 @@ class SHA1Context : public Encryption::Context
while ((this->count[0] & 504) != 448)
this->Update(reinterpret_cast<const unsigned char *>("\0"), 1);
this->Update(finalcount, 8); /* Should cause a SHA1Transform() */
+ unsigned char digest[20];
+ memset(digest, 0, sizeof(digest));
for (i = 0; i < 20; ++i)
- this->digest[i] = static_cast<unsigned char>((this->state[i>>2] >> ((3 - (i & 3)) * 8)) & 255);
+ digest[i] = static_cast<unsigned char>((this->state[i>>2] >> ((3 - (i & 3)) * 8)) & 255);
/* Wipe variables */
memset(this->buffer, 0, sizeof(this->buffer));
@@ -167,81 +160,51 @@ class SHA1Context : public Encryption::Context
memset(&finalcount, 0, sizeof(finalcount));
this->Transform(this->buffer);
- }
-
- Encryption::Hash GetFinalizedHash() anope_override
- {
- Encryption::Hash hash;
- hash.first = this->digest;
- hash.second = sizeof(this->digest);
- return hash;
- }
-};
-
-class SHA1Provider : public Encryption::Provider
-{
- public:
- SHA1Provider(Module *creator) : Encryption::Provider(creator, "sha1") { }
-
- Encryption::Context *CreateContext(Encryption::IV *iv) anope_override
- {
- return new SHA1Context(iv);
- }
- Encryption::IV GetDefaultIV() anope_override
- {
- Encryption::IV iv;
- iv.first = sha1_iv;
- iv.second = sizeof(sha1_iv) / sizeof(uint32_t);
- return iv;
+ return Anope::string(reinterpret_cast<const char *>(&digest), sizeof(digest));
}
};
-class ESHA1 : public Module
+class ESHA1 final
+ : public Module
{
- SHA1Provider sha1provider;
-
- public:
- ESHA1(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR),
- sha1provider(this)
- {
-
- }
+private:
+ Encryption::SimpleProvider<SHA1Context> sha1provider;
- EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
+public:
+ ESHA1(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
+ , sha1provider(this, "sha1", 20, 64)
{
- SHA1Context context;
+ if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
+ throw ModuleException("enc_sha1 is deprecated and can not be used as a primary encryption method");
- context.Update(reinterpret_cast<const unsigned char *>(src.c_str()), src.length());
- context.Finalize();
-
- Encryption::Hash hash = context.GetFinalizedHash();
-
- Anope::string buf = "sha1:" + Anope::Hex(reinterpret_cast<const char *>(hash.first), hash.second);
-
- Log(LOG_DEBUG_2) << "(enc_sha1) hashed password from [" << src << "] to [" << buf << "]";
- dest = buf;
- return EVENT_ALLOW;
+ sha1provider.Check({
+ { "da39a3ee5e6b4b0d3255bfef95601890afd80709", "" },
+ { "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", "The quick brown fox jumps over the lazy dog" },
+ });
}
- void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
{
- const NickAlias *na = NickAlias::Find(req->GetAccount());
- if (na == NULL)
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
return;
- NickCore *nc = na->nc;
- size_t pos = nc->pass.find(':');
+ NickCore *nc = na->nc;
+ auto pos = nc->pass.find(':');
if (pos == Anope::string::npos)
return;
+
Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
if (!hash_method.equals_cs("sha1"))
return;
- Anope::string buf;
- this->OnEncrypt(req->GetPassword(), buf);
- if (nc->pass.equals_cs(buf))
+ auto enc = "sha1:" + Anope::Hex(sha1provider.Encrypt(req->GetPassword()));
+ if (nc->pass.equals_cs(enc))
{
+ // If we are NOT the first encryption module we want to re-encrypt
+ // the password with the primary encryption method.
if (ModuleManager::FindFirstOf(ENCRYPTION) != this)
Anope::Encrypt(req->GetPassword(), nc->pass);
req->Success(this);
diff --git a/modules/encryption/enc_sha2.cpp b/modules/encryption/enc_sha2.cpp
new file mode 100644
index 000000000..4a9f12b09
--- /dev/null
+++ b/modules/encryption/enc_sha2.cpp
@@ -0,0 +1,200 @@
+/* Module for providing SHA-2 hashing
+ *
+ * (C) 2003-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * This program is free but copyrighted software; see the file COPYING for
+ * details.
+ *
+ */
+
+#include <climits>
+#include <random>
+
+#include "sha2/sha2.c"
+
+#include "module.h"
+#include "modules/encryption.h"
+
+template <typename SHAContext,
+ void (* SHAInit)(SHAContext *),
+ void (* SHAUpdate)(SHAContext *, const unsigned char *, unsigned int),
+ void (* SHAFinal)(SHAContext *, unsigned char *)>
+class SHA2Context final
+ : public Encryption::Context
+{
+private:
+ SHAContext context;
+ const size_t digest_size;
+
+public:
+ SHA2Context(size_t ds)
+ : digest_size(ds)
+ {
+ SHAInit(&context);
+ }
+
+ void Update(const unsigned char *data, size_t len) override
+ {
+ SHAUpdate(&context, data, len);
+ }
+
+ Anope::string Finalize() override
+ {
+ std::vector<unsigned char> digest(digest_size);
+ SHAFinal(&context, digest.data());
+ return Anope::string(reinterpret_cast<const char *>(digest.data()), digest.size());
+ }
+};
+
+template <typename SHAContext,
+ void (* SHAInit)(SHAContext *),
+ void (* SHAUpdate)(SHAContext *, const unsigned char *, unsigned int),
+ void (* SHAFinal)(SHAContext *, unsigned char *)>
+class SHA2Provider final
+ : public Encryption::Provider
+{
+public:
+ SHA2Provider(Module *creator, const Anope::string &algorithm, size_t bs, size_t ds)
+ : Encryption::Provider(creator, algorithm, bs, ds)
+ {
+ }
+
+ std::unique_ptr<Encryption::Context> CreateContext() override
+ {
+ return std::make_unique<SHA2Context<SHAContext, SHAInit, SHAUpdate, SHAFinal>>(this->digest_size);
+ }
+};
+
+class ESHA2 final
+ : public Module
+{
+private:
+ Encryption::Provider *defaultprovider = nullptr;
+ SHA2Provider<sha224_ctx, sha224_init, sha224_update, sha224_final> sha224provider;
+ SHA2Provider<sha256_ctx, sha256_init, sha256_update, sha256_final> sha256provider;
+ SHA2Provider<sha384_ctx, sha384_init, sha384_update, sha384_final> sha384provider;
+ SHA2Provider<sha512_ctx, sha512_init, sha512_update, sha512_final> sha512provider;
+
+ Anope::string GenerateKey(size_t keylen)
+ {
+ static std::random_device device;
+ static std::mt19937 engine(device());
+ static std::uniform_int_distribution<int> dist(CHAR_MIN, CHAR_MAX);
+ Anope::string keybuf(keylen, ' ');
+ for (size_t i = 0; i < keylen; ++i)
+ keybuf[i] = static_cast<char>(dist(engine));
+ return keybuf;
+ }
+
+ Encryption::Provider *GetAlgorithm(const Anope::string &algorithm)
+ {
+ if (algorithm == "sha224")
+ return &sha224provider;
+ if (algorithm == "sha256")
+ return &sha256provider;
+ if (algorithm == "sha384")
+ return &sha384provider;
+ if (algorithm == "sha512")
+ return &sha512provider;
+ return nullptr;
+ }
+
+public:
+ ESHA2(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
+ , sha224provider(this, "sha224", SHA224_BLOCK_SIZE, SHA224_DIGEST_SIZE)
+ , sha256provider(this, "sha256", SHA256_BLOCK_SIZE, SHA256_DIGEST_SIZE)
+ , sha384provider(this, "sha384", SHA384_BLOCK_SIZE, SHA384_DIGEST_SIZE)
+ , sha512provider(this, "sha512", SHA512_BLOCK_SIZE, SHA512_DIGEST_SIZE)
+ {
+ sha224provider.Check({
+ { "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "" },
+ { "730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525", "The quick brown fox jumps over the lazy dog" },
+ });
+ sha256provider.Check({
+ { "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "" },
+ { "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592", "The quick brown fox jumps over the lazy dog" },
+ });
+ sha384provider.Check({
+ { "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", "" },
+ { "ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1", "The quick brown fox jumps over the lazy dog" },
+ });
+ sha512provider.Check({
+ { "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", "" },
+ { "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6", "The quick brown fox jumps over the lazy dog" },
+ });
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ this->defaultprovider = GetAlgorithm(Config->GetModule(this)->Get<const Anope::string>("algorithm", "sha256"));
+ }
+
+ EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) override
+ {
+ if (!defaultprovider)
+ return EVENT_CONTINUE;
+
+ auto key = GenerateKey(defaultprovider->digest_size);
+ auto hmac = defaultprovider->HMAC(key, src);
+ auto enc = "hmac-" + defaultprovider->name + ":" + Anope::Hex(hmac) + ":" + Anope::Hex(key);
+ Log(LOG_DEBUG_2) << "(enc_sha2) hashed password from [" << src << "] to [" << enc << "]";
+ dest = enc;
+ return EVENT_ALLOW;
+ }
+
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
+ {
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
+ return;
+
+ NickCore *nc = na->nc;
+ auto apos = nc->pass.find(':');
+ if (apos == Anope::string::npos)
+ return;
+
+ Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + apos);
+ bool is_hmac = !hash_method.compare(0, 5, "hmac-", 5);
+ if (!is_hmac && hash_method.compare(0, 4, "raw-", 4))
+ return; // Not a SHA-2 password.
+
+ auto provider = GetAlgorithm(hash_method.substr(5));
+ if (!provider)
+ return; // Not a hash for this module.
+
+ auto valid = false;
+ if (is_hmac)
+ {
+ auto bpos = nc->pass.find(':', apos + 1);
+ if (bpos == Anope::string::npos)
+ return; // No HMAC key.
+
+ Anope::string pass_hex(nc->pass.begin() + apos + 1, nc->pass.begin() + bpos);
+ Anope::string key_hex(nc->pass.begin() + bpos + 1, nc->pass.end());
+ Anope::string key;
+ Anope::Unhex(key_hex, key);
+
+ auto enc = Anope::Hex(provider->HMAC(key, req->GetPassword()));
+ valid = pass_hex.equals_cs(enc);
+ }
+ else
+ {
+ Anope::string pass_hex(nc->pass.begin() + apos + 1, nc->pass.end());
+ valid = provider->Compare(pass_hex, req->GetPassword());
+ }
+
+ if (valid)
+ {
+ // If we are NOT the first encryption module, the password is a raw
+ // hash, or the algorithm is different we want to re-encrypt the
+ // password with the primary encryption method.
+ if (ModuleManager::FindFirstOf(ENCRYPTION) != this || !is_hmac || provider != defaultprovider)
+ Anope::Encrypt(req->GetPassword(), nc->pass);
+ req->Success(this);
+ }
+ }
+};
+
+MODULE_INIT(ESHA2)
diff --git a/modules/encryption/enc_sha256.cpp b/modules/encryption/enc_sha256.cpp
index 4848ec42a..f1639cf4f 100644
--- a/modules/encryption/enc_sha256.cpp
+++ b/modules/encryption/enc_sha256.cpp
@@ -1,252 +1,29 @@
/* This module generates and compares password hashes using SHA256 algorithms.
*
- * If an intruder gets access to your system or uses a brute force attack,
- * salt will not provide much value.
- * IMPORTANT: DATA HASHES CANNOT BE "DECRYPTED" BACK TO PLAIN TEXT.
- *
- * Modified for Anope.
* (C) 2003-2024 Anope Team
* Contact us at team@anope.org
*
- * Taken from InspIRCd (https://www.inspircd.org/),
- * see https://wiki.inspircd.org/Credits
+ * This program is free but copyrighted software; see the file COPYING for
+ * details.
*
- * This program is free but copyrighted software; see
- * the file COPYING for details.
*/
-/* FIPS 180-2 SHA-224/256/384/512 implementation
- * Last update: 05/23/2005
- * Issue date: 04/30/2005
- *
- * Copyright (C) 2005 Olivier Gay <olivier.gay@a3.epfl.ch>
- * 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. Neither the name of the project nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``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 PROJECT OR CONTRIBUTORS 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.
- */
+#include "sha2/sha2.c"
#include "module.h"
-#include "modules/encryption.h"
-
-static const unsigned SHA256_DIGEST_SIZE = 256 / 8;
-static const unsigned SHA256_BLOCK_SIZE = 512 / 8;
-
-inline static uint32_t SHFR(uint32_t x, uint32_t n) { return x >> n; }
-inline static uint32_t ROTR(uint32_t x, uint32_t n) { return (x >> n) | (x << ((sizeof(x) << 3) - n)); }
-inline static uint32_t CH(uint32_t x, uint32_t y, uint32_t z) { return (x & y) ^ (~x & z); }
-inline static uint32_t MAJ(uint32_t x, uint32_t y, uint32_t z) { return (x & y) ^ (x & z) ^ (y & z); }
-
-inline static uint32_t SHA256_F1(uint32_t x) { return ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22); }
-inline static uint32_t SHA256_F2(uint32_t x) { return ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25); }
-inline static uint32_t SHA256_F3(uint32_t x) { return ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3); }
-inline static uint32_t SHA256_F4(uint32_t x) { return ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10); }
-
-inline static void UNPACK32(unsigned x, unsigned char *str)
-{
- str[3] = static_cast<uint8_t>(x);
- str[2] = static_cast<uint8_t>(x >> 8);
- str[1] = static_cast<uint8_t>(x >> 16);
- str[0] = static_cast<uint8_t>(x >> 24);
-}
-
-inline static void PACK32(unsigned char *str, uint32_t &x)
-{
- x = static_cast<uint32_t>(str[3]) | static_cast<uint32_t>(str[2]) << 8 | static_cast<uint32_t>(str[1]) << 16 | static_cast<uint32_t>(str[0]) << 24;
-}
-
-/* Macros used for loops unrolling */
-
-inline static void SHA256_SCR(uint32_t w[64], int i)
-{
- w[i] = SHA256_F4(w[i - 2]) + w[i - 7] + SHA256_F3(w[i - 15]) + w[i - 16];
-}
-
-static const uint32_t sha256_h0[8] =
-{
- 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
- 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
-};
-
-static const uint32_t sha256_k[64] =
-{
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
-};
-/** An sha256 context
- */
-class SHA256Context : public Encryption::Context
+class ESHA256 final
+ : public Module
{
- void Transform(unsigned char *message, unsigned block_nb)
- {
- uint32_t w[64], wv[8];
- unsigned char *sub_block;
- for (unsigned i = 1; i <= block_nb; ++i)
- {
- int j;
- sub_block = message + ((i - 1) << 6);
-
- for (j = 0; j < 16; ++j)
- PACK32(&sub_block[j << 2], w[j]);
- for (j = 16; j < 64; ++j)
- SHA256_SCR(w, j);
- for (j = 0; j < 8; ++j)
- wv[j] = this->h[j];
- for (j = 0; j < 64; ++j)
- {
- uint32_t t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + sha256_k[j] + w[j];
- uint32_t t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]);
- wv[7] = wv[6];
- wv[6] = wv[5];
- wv[5] = wv[4];
- wv[4] = wv[3] + t1;
- wv[3] = wv[2];
- wv[2] = wv[1];
- wv[1] = wv[0];
- wv[0] = t1 + t2;
- }
- for (j = 0; j < 8; ++j)
- this->h[j] += wv[j];
- }
- }
-
- unsigned tot_len;
- unsigned len;
- unsigned char block[2 * SHA256_BLOCK_SIZE];
- uint32_t h[8];
- unsigned char digest[SHA256_DIGEST_SIZE];
-
- public:
- SHA256Context(Encryption::IV *iv)
- {
- if (iv != NULL)
- {
- if (iv->second != 8)
- throw CoreException("Invalid IV size");
- for (int i = 0; i < 8; ++i)
- this->h[i] = iv->first[i];
- }
- else
- for (int i = 0; i < 8; ++i)
- this->h[i] = sha256_h0[i];
-
- this->tot_len = 0;
- this->len = 0;
- memset(this->block, 0, sizeof(this->block));
- memset(this->digest, 0, sizeof(this->digest));
- }
-
- void Update(const unsigned char *message, size_t mlen) anope_override
- {
- unsigned tmp_len = SHA256_BLOCK_SIZE - this->len, rem_len = mlen < tmp_len ? mlen : tmp_len;
-
- memcpy(&this->block[this->len], message, rem_len);
- if (this->len + mlen < SHA256_BLOCK_SIZE)
- {
- this->len += mlen;
- return;
- }
- unsigned new_len = mlen - rem_len, block_nb = new_len / SHA256_BLOCK_SIZE;
- unsigned char *shifted_message = new unsigned char[mlen - rem_len];
- memcpy(shifted_message, message + rem_len, mlen - rem_len);
- this->Transform(this->block, 1);
- this->Transform(shifted_message, block_nb);
- rem_len = new_len % SHA256_BLOCK_SIZE;
- memcpy(this->block, &shifted_message[block_nb << 6], rem_len);
- delete [] shifted_message;
- this->len = rem_len;
- this->tot_len += (block_nb + 1) << 6;
- }
-
- void Finalize() anope_override
- {
- unsigned block_nb = 1 + ((SHA256_BLOCK_SIZE - 9) < (this->len % SHA256_BLOCK_SIZE));
- unsigned len_b = (this->tot_len + this->len) << 3;
- unsigned pm_len = block_nb << 6;
- memset(this->block + this->len, 0, pm_len - this->len);
- this->block[this->len] = 0x80;
- UNPACK32(len_b, this->block + pm_len - 4);
- this->Transform(this->block, block_nb);
- for (int i = 0 ; i < 8; ++i)
- UNPACK32(this->h[i], &this->digest[i << 2]);
- }
-
- Encryption::Hash GetFinalizedHash() anope_override
- {
- Encryption::Hash hash;
- hash.first = this->digest;
- hash.second = SHA256_DIGEST_SIZE;
- return hash;
- }
-};
-
-class SHA256Provider : public Encryption::Provider
-{
- public:
- SHA256Provider(Module *creator) : Encryption::Provider(creator, "sha256") { }
-
- Encryption::Context *CreateContext(Encryption::IV *iv) anope_override
- {
- return new SHA256Context(iv);
- }
-
- Encryption::IV GetDefaultIV() anope_override
- {
- Encryption::IV iv;
- iv.first = sha256_h0;
- iv.second = sizeof(sha256_h0) / sizeof(uint32_t);
- return iv;
- }
-};
-
-class ESHA256 : public Module
-{
- SHA256Provider sha256provider;
-
+private:
unsigned iv[8];
bool use_iv;
/* initializes the IV with a new random value */
void NewRandomIV()
{
- for (int i = 0; i < 8; ++i)
- iv[i] = static_cast<uint32_t>(rand());
+ for (auto &ivsegment : iv)
+ ivsegment = static_cast<uint32_t>(Anope::RandomNumber());
}
/* returns the IV as base64-encrypted string */
@@ -268,62 +45,59 @@ class ESHA256 : public Module
char buf2[33];
Anope::Unhex(buf, buf2, sizeof(buf2));
for (int i = 0 ; i < 8; ++i)
- PACK32(reinterpret_cast<unsigned char *>(&buf2[i << 2]), iv[i]);
- }
-
- public:
- ESHA256(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR),
- sha256provider(this)
- {
-
-
- use_iv = false;
+ PACK32(reinterpret_cast<unsigned char *>(&buf2[i << 2]), &iv[i]);
}
- EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
+ Anope::string EncryptInternal(const Anope::string &src)
{
if (!use_iv)
NewRandomIV();
else
use_iv = false;
- Encryption::IV initialization(this->iv, 8);
- SHA256Context ctx(&initialization);
- ctx.Update(reinterpret_cast<const unsigned char *>(src.c_str()), src.length());
- ctx.Finalize();
+ sha256_ctx ctx;
+ sha256_init(&ctx);
+ for (size_t i = 0; i < 8; ++i)
+ ctx.h[i] = iv[i];
+ sha256_update(&ctx, reinterpret_cast<const unsigned char *>(src.data()), src.length());
+ unsigned char digest[SHA256_DIGEST_SIZE];
+ sha256_final(&ctx, digest);
+ Anope::string hash(reinterpret_cast<const char *>(&digest), sizeof(digest));
- Encryption::Hash hash = ctx.GetFinalizedHash();
+ return "sha256:" + Anope::Hex(hash) + ":" + GetIVString();
+ }
- std::stringstream buf;
- buf << "sha256:" << Anope::Hex(reinterpret_cast<const char *>(hash.first), hash.second) << ":" << GetIVString();
- Log(LOG_DEBUG_2) << "(enc_sha256) hashed password from [" << src << "] to [" << buf.str() << " ]";
- dest = buf.str();
- return EVENT_ALLOW;
+public:
+ ESHA256(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
+ {
+ use_iv = false;
+ if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
+ throw ModuleException("enc_sha256 is deprecated and can not be used as a primary encryption method");
}
- void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
{
- const NickAlias *na = NickAlias::Find(req->GetAccount());
- if (na == NULL)
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
return;
- NickCore *nc = na->nc;
- size_t pos = nc->pass.find(':');
+ NickCore *nc = na->nc;
+ auto pos = nc->pass.find(':');
if (pos == Anope::string::npos)
return;
+
Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
if (!hash_method.equals_cs("sha256"))
return;
GetIVFromPass(nc->pass);
use_iv = true;
- Anope::string buf;
- this->OnEncrypt(req->GetPassword(), buf);
- if (nc->pass.equals_cs(buf))
+ auto enc = EncryptInternal(req->GetPassword());
+ if (nc->pass.equals_cs(enc))
{
- /* if we are NOT the first module in the list,
- * we want to re-encrypt the pass with the new encryption
- */
+ // If we are NOT the first encryption module we want to re-encrypt
+ // the password with the primary encryption method.
if (ModuleManager::FindFirstOf(ENCRYPTION) != this)
Anope::Encrypt(req->GetPassword(), nc->pass);
req->Success(this);
diff --git a/modules/extra/enc_argon2.cpp b/modules/extra/enc_argon2.cpp
new file mode 100644
index 000000000..f45a942c4
--- /dev/null
+++ b/modules/extra/enc_argon2.cpp
@@ -0,0 +1,199 @@
+/* Module for providing Argon2 hashing
+ *
+ * (C) 2003-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * This program is free but copyrighted software; see the file COPYING for
+ * details.
+ *
+ */
+
+/* RequiredLibraries: argon2 */
+/* RequiredWindowsLibraries: argon2 */
+
+#include <climits>
+#include <random>
+
+#include <argon2.h>
+
+#include "module.h"
+#include "modules/encryption.h"
+
+class Argon2Context final
+ : public Encryption::Context
+{
+private:
+ Anope::string buffer;
+ argon2_type type;
+
+ Anope::string GenerateSalt()
+ {
+ static std::random_device device;
+ static std::mt19937 engine(device());
+ static std::uniform_int_distribution<int> dist(CHAR_MIN, CHAR_MAX);
+ Anope::string saltbuf(this->salt_length, ' ');
+ for (size_t i = 0; i < this->salt_length; ++i)
+ saltbuf[i] = static_cast<char>(dist(engine));
+ return saltbuf;
+ }
+
+public:
+ static uint32_t memory_cost;
+ static uint32_t time_cost;
+ static uint32_t parallelism;
+ static uint32_t hash_length;
+ static uint32_t salt_length;
+
+ Argon2Context(argon2_type at)
+ : type(at)
+ {
+ }
+
+ void Update(const unsigned char *data, size_t len) override
+ {
+ buffer.append(reinterpret_cast<const char *>(data), len);
+ }
+
+ Anope::string Finalize() override
+ {
+ auto salt = GenerateSalt();
+
+ // Calculate the size of and allocate the output buffer.
+ auto length = argon2_encodedlen(this->time_cost, this->memory_cost, this->parallelism,
+ this->salt_length, this->hash_length, this->type);
+
+ std::vector<char> digest(length);
+ auto result = argon2_hash(this->time_cost, this->memory_cost, this->parallelism,
+ buffer.c_str(), buffer.length(), salt.c_str(), salt.length(), nullptr,
+ this->hash_length, digest.data(), digest.size(), this->type,
+ ARGON2_VERSION_NUMBER);
+
+ if (result == ARGON2_OK)
+ return Anope::string(digest.data(), digest.size());
+
+ Log(LOG_DEBUG_2) << "Argon2 error: " << argon2_error_message(result);
+ return {};
+ }
+};
+
+uint32_t Argon2Context::memory_cost;
+uint32_t Argon2Context::time_cost;
+uint32_t Argon2Context::parallelism;
+uint32_t Argon2Context::hash_length;
+uint32_t Argon2Context::salt_length;
+
+class Argon2Provider final
+ : public Encryption::Provider
+{
+private:
+ argon2_type type;
+
+public:
+ Argon2Provider(Module *creator, argon2_type at)
+ : Encryption::Provider(creator, argon2_type2string(at, 0), 0, 0)
+ , type(at)
+ {
+ }
+
+ bool Compare(const Anope::string &hash, const Anope::string &plain) override
+ {
+ return argon2_verify(hash.c_str(), plain.c_str(), plain.length(), this->type) == ARGON2_OK;
+ }
+
+ std::unique_ptr<Encryption::Context> CreateContext() override
+ {
+ return std::make_unique<Argon2Context>(this->type);
+ }
+
+ Anope::string ToPrintable(const Anope::string &hash) override
+ {
+ // We have no way to make this printable without the creating context
+ // so we always return the printed form.
+ return hash;
+ }
+};
+
+class EArgon2 final
+ : public Module
+{
+private:
+ Encryption::Provider *defaultprovider = nullptr;
+ Argon2Provider argon2dprovider;
+ Argon2Provider argon2iprovider;
+ Argon2Provider argon2idprovider;
+
+ Encryption::Provider *GetAlgorithm(const Anope::string &algorithm)
+ {
+ if (algorithm == "argon2d")
+ return &argon2dprovider;
+ if (algorithm == "argon2i")
+ return &argon2iprovider;
+ if (algorithm == "argon2id")
+ return &argon2idprovider;
+ return nullptr;
+ }
+
+public:
+ EArgon2(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, ENCRYPTION | VENDOR)
+ , argon2dprovider(this, Argon2_d)
+ , argon2iprovider(this, Argon2_i)
+ , argon2idprovider(this, Argon2_id)
+
+ {
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ const auto *block = Config->GetModule(this);
+ this->defaultprovider = GetAlgorithm(block->Get<const Anope::string>("algorithm", "argon2id"));
+ Argon2Context::memory_cost = block->Get<uint32_t>("memory_cost", "131072");
+ Argon2Context::time_cost = block->Get<uint32_t>("time_cost", "3");
+ Argon2Context::parallelism = block->Get<uint32_t>("parallelism", "1");
+ Argon2Context::hash_length = block->Get<uint32_t>("hash_length", "32");
+ Argon2Context::salt_length = block->Get<uint32_t>("salt_length", "32");
+ }
+
+ EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) override
+ {
+ if (!defaultprovider)
+ return EVENT_CONTINUE;
+
+ auto hash = defaultprovider->Encrypt(src);
+ auto enc = defaultprovider->name + ":" + hash;
+ Log(LOG_DEBUG_2) << "(enc_argon2) hashed password from [" << src << "] to [" << enc << "]";
+ dest = enc;
+ return EVENT_ALLOW;
+
+ }
+
+ void OnCheckAuthentication(User *, IdentifyRequest *req) override
+ {
+ const auto *na = NickAlias::Find(req->GetAccount());
+ if (!na)
+ return;
+
+ NickCore *nc = na->nc;
+ auto pos = nc->pass.find(':');
+ if (pos == Anope::string::npos)
+ return;
+
+ Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
+ auto provider = GetAlgorithm(hash_method);
+ if (!provider)
+ return; // Not a hash for this module.
+
+ Anope::string hash_value(nc->pass.begin() + pos + 1, nc->pass.end());
+ if (provider->Compare(hash_value, req->GetPassword()))
+ {
+ // If we are NOT the first encryption module or the algorithm is
+ // different we want to re-encrypt the password with the primary
+ // encryption method.
+ if (ModuleManager::FindFirstOf(ENCRYPTION) != this || provider != defaultprovider)
+ Anope::Encrypt(req->GetPassword(), nc->pass);
+ req->Success(this);
+ }
+ }
+};
+
+MODULE_INIT(EArgon2)
diff --git a/modules/extra/m_ldap.cpp b/modules/extra/ldap.cpp
index 7265f8ba0..bcd4b8406 100644
--- a/modules/extra/m_ldap.cpp
+++ b/modules/extra/ldap.cpp
@@ -14,6 +14,9 @@
#include "module.h"
#include "modules/ldap.h"
+#include <condition_variable>
+#include <mutex>
+
#ifdef _WIN32
# include <Winldap.h>
# include <WinBer.h>
@@ -44,21 +47,18 @@ static Pipe *me;
class LDAPRequest
{
- public:
+public:
LDAPService *service;
LDAPInterface *inter;
- LDAPMessage *message; /* message returned by ldap_ */
- LDAPResult *result; /* final result */
+ LDAPMessage *message = nullptr; /* message returned by ldap_ */
+ LDAPResult *result = nullptr; /* final result */
struct timeval tv;
- QueryType type;
+ QueryType type = QUERY_UNKNOWN;
LDAPRequest(LDAPService *s, LDAPInterface *i)
: service(s)
, inter(i)
- , message(NULL)
- , result(NULL)
{
- type = QUERY_UNKNOWN;
tv.tv_sec = 0;
tv.tv_usec = 100000;
}
@@ -75,11 +75,12 @@ class LDAPRequest
virtual int run() = 0;
};
-class LDAPBind : public LDAPRequest
+class LDAPBind final
+ : public LDAPRequest
{
Anope::string who, pass;
- public:
+public:
LDAPBind(LDAPService *s, LDAPInterface *i, const Anope::string &w, const Anope::string &p)
: LDAPRequest(s, i)
, who(w)
@@ -88,15 +89,16 @@ class LDAPBind : public LDAPRequest
type = QUERY_BIND;
}
- int run() anope_override;
+ int run() override;
};
-class LDAPSearchRequest : public LDAPRequest
+class LDAPSearchRequest final
+ : public LDAPRequest
{
Anope::string base;
Anope::string filter;
- public:
+public:
LDAPSearchRequest(LDAPService *s, LDAPInterface *i, const Anope::string &b, const Anope::string &f)
: LDAPRequest(s, i)
, base(b)
@@ -105,15 +107,16 @@ class LDAPSearchRequest : public LDAPRequest
type = QUERY_SEARCH;
}
- int run() anope_override;
+ int run() override;
};
-class LDAPAdd : public LDAPRequest
+class LDAPAdd final
+ : public LDAPRequest
{
Anope::string dn;
LDAPMods attributes;
- public:
+public:
LDAPAdd(LDAPService *s, LDAPInterface *i, const Anope::string &d, const LDAPMods &attr)
: LDAPRequest(s, i)
, dn(d)
@@ -122,14 +125,15 @@ class LDAPAdd : public LDAPRequest
type = QUERY_ADD;
}
- int run() anope_override;
+ int run() override;
};
-class LDAPDel : public LDAPRequest
+class LDAPDel final
+ : public LDAPRequest
{
Anope::string dn;
- public:
+public:
LDAPDel(LDAPService *s, LDAPInterface *i, const Anope::string &d)
: LDAPRequest(s, i)
, dn(d)
@@ -137,15 +141,16 @@ class LDAPDel : public LDAPRequest
type = QUERY_DELETE;
}
- int run() anope_override;
+ int run() override;
};
-class LDAPModify : public LDAPRequest
+class LDAPModify final
+ : public LDAPRequest
{
Anope::string base;
LDAPMods attributes;
- public:
+public:
LDAPModify(LDAPService *s, LDAPInterface *i, const Anope::string &b, const LDAPMods &attr)
: LDAPRequest(s, i)
, base(b)
@@ -154,10 +159,12 @@ class LDAPModify : public LDAPRequest
type = QUERY_MODIFY;
}
- int run() anope_override;
+ int run() override;
};
-class LDAPService : public LDAPProvider, public Thread, public Condition
+class LDAPService final
+ : public LDAPProvider
+ , public Thread
{
Anope::string server;
Anope::string admin_binddn;
@@ -165,9 +172,12 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
LDAP *con;
- time_t last_connect;
+ time_t last_connect = 0;
+
+public:
+ std::condition_variable_any condvar;
+ std::mutex mutex;
- public:
static LDAPMod **BuildMods(const LDAPMods &attributes)
{
LDAPMod **mods = new LDAPMod*[attributes.size() + 1];
@@ -207,10 +217,10 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
delete [] mods;
}
- private:
+private:
#ifdef _WIN32
// Windows LDAP does not implement this so we need to do it.
- int ldap_initialize(LDAP** ldap, const char* url)
+ int ldap_initialize(LDAP **ldap, const char *url)
{
URL_COMPONENTS urlComponents;
memset(&urlComponents, 0, sizeof(urlComponents));
@@ -296,18 +306,18 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
void QueueRequest(LDAPRequest *r)
{
- this->Lock();
+ this->mutex.lock();
this->queries.push_back(r);
- this->Wakeup();
- this->Unlock();
+ this->condvar.notify_all();
+ this->mutex.unlock();
}
- public:
+public:
typedef std::vector<LDAPRequest *> query_queue;
query_queue queries, results;
- Mutex process_mutex; /* held when processing requests not in either queue */
+ std::mutex process_mutex; /* held when processing requests not in either queue */
- LDAPService(Module *o, const Anope::string &n, const Anope::string &s, const Anope::string &b, const Anope::string &p) : LDAPProvider(o, n), server(s), admin_binddn(b), admin_pass(p), last_connect(0)
+ LDAPService(Module *o, const Anope::string &n, const Anope::string &s, const Anope::string &b, const Anope::string &p) : LDAPProvider(o, n), server(s), admin_binddn(b), admin_pass(p)
{
Connect();
}
@@ -316,12 +326,10 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
{
/* At this point the thread has stopped so we don't need to hold process_mutex */
- this->Lock();
+ this->mutex.lock();
- for (unsigned int i = 0; i < this->queries.size(); ++i)
+ for (auto *req : this->queries)
{
- LDAPRequest *req = this->queries[i];
-
/* queries have no results yet */
req->result = new LDAPResult();
req->result->type = req->type;
@@ -333,10 +341,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
}
this->queries.clear();
- for (unsigned int i = 0; i < this->results.size(); ++i)
+ for (const auto *req : this->queries)
{
- LDAPRequest *req = this->results[i];
-
/* even though this may have already finished successfully we return that it didn't */
req->result->error = "LDAP Interface is going away";
if (req->inter)
@@ -345,50 +351,50 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
delete req;
}
- this->Unlock();
+ this->mutex.unlock();
ldap_unbind_ext(this->con, NULL, NULL);
}
- void BindAsAdmin(LDAPInterface *i) anope_override
+ void BindAsAdmin(LDAPInterface *i) override
{
this->Bind(i, this->admin_binddn, this->admin_pass);
}
- void Bind(LDAPInterface *i, const Anope::string &who, const Anope::string &pass) anope_override
+ void Bind(LDAPInterface *i, const Anope::string &who, const Anope::string &pass) override
{
- LDAPBind *b = new LDAPBind(this, i, who, pass);
+ auto *b = new LDAPBind(this, i, who, pass);
QueueRequest(b);
}
- void Search(LDAPInterface *i, const Anope::string &base, const Anope::string &filter) anope_override
+ void Search(LDAPInterface *i, const Anope::string &base, const Anope::string &filter) override
{
if (i == NULL)
throw LDAPException("No interface");
- LDAPSearchRequest *s = new LDAPSearchRequest(this, i, base, filter);
+ auto *s = new LDAPSearchRequest(this, i, base, filter);
QueueRequest(s);
}
- void Add(LDAPInterface *i, const Anope::string &dn, LDAPMods &attributes) anope_override
+ void Add(LDAPInterface *i, const Anope::string &dn, LDAPMods &attributes) override
{
- LDAPAdd *add = new LDAPAdd(this, i, dn, attributes);
+ auto *add = new LDAPAdd(this, i, dn, attributes);
QueueRequest(add);
}
- void Del(LDAPInterface *i, const Anope::string &dn) anope_override
+ void Del(LDAPInterface *i, const Anope::string &dn) override
{
- LDAPDel *del = new LDAPDel(this, i, dn);
+ auto *del = new LDAPDel(this, i, dn);
QueueRequest(del);
}
- void Modify(LDAPInterface *i, const Anope::string &base, LDAPMods &attributes) anope_override
+ void Modify(LDAPInterface *i, const Anope::string &base, LDAPMods &attributes) override
{
- LDAPModify *mod = new LDAPModify(this, i, base, attributes);
+ auto *mod = new LDAPModify(this, i, base, attributes);
QueueRequest(mod);
}
- private:
+private:
void BuildReply(int res, LDAPRequest *req)
{
LDAPResult *ldap_result = req->result = new LDAPResult();
@@ -444,22 +450,21 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
void SendRequests()
{
- process_mutex.Lock();
+ process_mutex.lock();
query_queue q;
- this->Lock();
+ this->mutex.lock();
queries.swap(q);
- this->Unlock();
+ this->mutex.unlock();
if (q.empty())
{
- process_mutex.Unlock();
+ process_mutex.unlock();
return;
}
- for (unsigned int i = 0; i < q.size(); ++i)
+ for (auto *req : q)
{
- LDAPRequest *req = q[i];
int ret = req->run();
if (ret == LDAP_SERVER_DOWN || ret == LDAP_TIMEOUT)
@@ -478,42 +483,44 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
BuildReply(ret, req);
- this->Lock();
+ this->mutex.lock();
results.push_back(req);
- this->Unlock();
+ this->mutex.unlock();
}
me->Notify();
- process_mutex.Unlock();
+ process_mutex.unlock();
}
- public:
- void Run() anope_override
+public:
+ void Run() override
{
while (!this->GetExitState())
{
- this->Lock();
+ this->mutex.lock();
/* Queries can be non empty if one is pushed during SendRequests() */
if (queries.empty())
- this->Wait();
- this->Unlock();
+ this->condvar.wait(this->mutex);
+ this->mutex.unlock();
SendRequests();
}
}
- LDAP* GetConnection()
+ LDAP *GetConnection()
{
return con;
}
};
-class ModuleLDAP : public Module, public Pipe
+class ModuleLDAP final
+ : public Module
+ , public Pipe
{
std::map<Anope::string, LDAPService *> LDAPServices;
- public:
+public:
ModuleLDAP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
{
@@ -525,14 +532,14 @@ class ModuleLDAP : public Module, public Pipe
for (std::map<Anope::string, LDAPService *>::iterator it = this->LDAPServices.begin(); it != this->LDAPServices.end(); ++it)
{
it->second->SetExitState();
- it->second->Wakeup();
+ it->second->condvar.notify_all();
it->second->Join();
delete it->second;
}
LDAPServices.clear();
}
- void OnReload(Configuration::Conf *config) anope_override
+ void OnReload(Configuration::Conf *config) override
{
Configuration::Block *conf = config->GetModule(this);
@@ -553,7 +560,7 @@ class ModuleLDAP : public Module, public Pipe
Log(LOG_NORMAL, "ldap") << "LDAP: Removing server connection " << cname;
s->SetExitState();
- s->Wakeup();
+ s->condvar.notify_all();
s->Join();
delete s;
this->LDAPServices.erase(cname);
@@ -574,9 +581,9 @@ class ModuleLDAP : public Module, public Pipe
try
{
- LDAPService *ss = new LDAPService(this, connname, server, admin_binddn, admin_password);
+ auto *ss = new LDAPService(this, connname, server, admin_binddn, admin_password);
ss->Start();
- this->LDAPServices.insert(std::make_pair(connname, ss));
+ this->LDAPServices.emplace(connname, ss);
Log(LOG_NORMAL, "ldap") << "LDAP: Successfully initialized server " << connname << " (" << server << ")";
}
@@ -588,14 +595,14 @@ class ModuleLDAP : public Module, public Pipe
}
}
- void OnModuleUnload(User *, Module *m) anope_override
+ void OnModuleUnload(User *, Module *m) override
{
for (std::map<Anope::string, LDAPService *>::iterator it = this->LDAPServices.begin(); it != this->LDAPServices.end(); ++it)
{
LDAPService *s = it->second;
- s->process_mutex.Lock();
- s->Lock();
+ s->process_mutex.lock();
+ s->mutex.lock();
for (unsigned int i = s->queries.size(); i > 0; --i)
{
@@ -620,25 +627,24 @@ class ModuleLDAP : public Module, public Pipe
}
}
- s->Unlock();
- s->process_mutex.Unlock();
+ s->mutex.unlock();
+ s->process_mutex.unlock();
}
}
- void OnNotify() anope_override
+ void OnNotify() override
{
for (std::map<Anope::string, LDAPService *>::iterator it = this->LDAPServices.begin(); it != this->LDAPServices.end(); ++it)
{
LDAPService *s = it->second;
LDAPService::query_queue results;
- s->Lock();
+ s->mutex.lock();
results.swap(s->results);
- s->Unlock();
+ s->mutex.unlock();
- for (unsigned int i = 0; i < results.size(); ++i)
+ for (const auto *req : results)
{
- LDAPRequest *req = results[i];
LDAPInterface *li = req->inter;
LDAPResult *r = req->result;
diff --git a/modules/extra/m_regex_pcre.cpp b/modules/extra/m_regex_pcre.cpp
deleted file mode 100644
index 643561c7c..000000000
--- a/modules/extra/m_regex_pcre.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- *
- * (C) 2012-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-/* RequiredLibraries: pcre */
-/* RequiredWindowsLibraries: libpcre */
-
-#include "module.h"
-#include <pcre.h>
-
-class PCRERegex : public Regex
-{
- pcre *regex;
-
- public:
- PCRERegex(const Anope::string &expr) : Regex(expr)
- {
- const char *error;
- int erroffset;
- this->regex = pcre_compile(expr.c_str(), PCRE_CASELESS, &error, &erroffset, NULL);
- if (!this->regex)
- throw RegexException("Error in regex " + expr + " at offset " + stringify(erroffset) + ": " + error);
- }
-
- ~PCRERegex()
- {
- pcre_free(this->regex);
- }
-
- bool Matches(const Anope::string &str)
- {
- return pcre_exec(this->regex, NULL, str.c_str(), str.length(), 0, 0, NULL, 0) > -1;
- }
-};
-
-class PCRERegexProvider : public RegexProvider
-{
- public:
- PCRERegexProvider(Module *creator) : RegexProvider(creator, "regex/pcre") { }
-
- Regex *Compile(const Anope::string &expression) anope_override
- {
- return new PCRERegex(expression);
- }
-};
-
-class ModuleRegexPCRE : public Module
-{
- PCRERegexProvider pcre_regex_provider;
-
- public:
- ModuleRegexPCRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
- pcre_regex_provider(this)
- {
- this->SetPermanent(true);
- }
-
- ~ModuleRegexPCRE()
- {
- for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it)
- {
- XLineManager *xlm = *it;
- const std::vector<XLine *> &xlines = xlm->GetList();
-
- for (unsigned int i = 0; i < xlines.size(); ++i)
- {
- XLine *x = xlines[i];
-
- if (x->regex && dynamic_cast<PCRERegex *>(x->regex))
- {
- delete x->regex;
- x->regex = NULL;
- }
- }
- }
- }
-};
-
-MODULE_INIT(ModuleRegexPCRE)
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/mysql.cpp
index 5a2b7a5b0..72c026dad 100644
--- a/modules/extra/m_mysql.cpp
+++ b/modules/extra/mysql.cpp
@@ -11,13 +11,16 @@
#include "module.h"
#include "modules/sql.h"
-#define NO_CLIENT_LONG_LONG
+
#ifdef WIN32
# include <mysql.h>
#else
# include <mysql/mysql.h>
#endif
+#include <condition_variable>
+#include <mutex>
+
using namespace SQL;
/** Non blocking threaded MySQL API, based loosely from InspIRCd's m_mysql.cpp
@@ -34,7 +37,7 @@ class MySQLService;
/** A query request
*/
-struct QueryRequest
+struct QueryRequest final
{
/* The connection to the database */
MySQLService *service;
@@ -47,7 +50,7 @@ struct QueryRequest
};
/** A query result */
-struct QueryResult
+struct QueryResult final
{
/* The interface to send the data back on */
Interface *sqlinterface;
@@ -59,11 +62,12 @@ struct QueryResult
/** A MySQL result
*/
-class MySQLResult : public Result
+class MySQLResult final
+ : public Result
{
- MYSQL_RES *res;
+ MYSQL_RES *res = nullptr;
- public:
+public:
MySQLResult(unsigned int i, const Query &q, const Anope::string &fq, MYSQL_RES *r) : Result(i, q, fq), res(r)
{
unsigned num_fields = res ? mysql_num_fields(res) : 0;
@@ -94,7 +98,7 @@ class MySQLResult : public Result
}
}
- MySQLResult(const Query &q, const Anope::string &fq, const Anope::string &err) : Result(0, q, fq, err), res(NULL)
+ MySQLResult(const Query &q, const Anope::string &fq, const Anope::string &err) : Result(0, q, fq, err)
{
}
@@ -107,7 +111,8 @@ class MySQLResult : public Result
/** A MySQL connection, there can be multiple
*/
-class MySQLService : public Provider
+class MySQLService final
+ : public Provider
{
std::map<Anope::string, std::set<Anope::string> > active_schema;
@@ -115,35 +120,35 @@ class MySQLService : public Provider
Anope::string server;
Anope::string user;
Anope::string password;
- int port;
+ unsigned int port;
- MYSQL *sql;
+ MYSQL *sql = nullptr;
/** Escape a query.
* Note the mutex must be held!
*/
Anope::string Escape(const Anope::string &query);
- public:
+public:
/* Locked by the SQL thread when a query is pending on this database,
* prevents us from deleting a connection while a query is executing
* in the thread
*/
- Mutex Lock;
+ std::mutex Lock;
- MySQLService(Module *o, const Anope::string &n, const Anope::string &d, const Anope::string &s, const Anope::string &u, const Anope::string &p, int po);
+ MySQLService(Module *o, const Anope::string &n, const Anope::string &d, const Anope::string &s, const Anope::string &u, const Anope::string &p, unsigned int po);
~MySQLService();
- void Run(Interface *i, const Query &query) anope_override;
+ void Run(Interface *i, const Query &query) override;
- Result RunQuery(const Query &query) anope_override;
+ Result RunQuery(const Query &query) override;
- std::vector<Query> CreateTable(const Anope::string &table, const Data &data) anope_override;
+ std::vector<Query> CreateTable(const Anope::string &table, const Data &data) override;
- Query BuildInsert(const Anope::string &table, unsigned int id, Data &data) anope_override;
+ Query BuildInsert(const Anope::string &table, unsigned int id, Data &data) override;
- Query GetTables(const Anope::string &prefix) anope_override;
+ Query GetTables(const Anope::string &prefix) override;
void Connect();
@@ -151,26 +156,33 @@ class MySQLService : public Provider
Anope::string BuildQuery(const Query &q);
- Anope::string FromUnixtime(time_t);
+ Anope::string FromUnixtime(time_t) override;
};
/** The SQL thread used to execute queries
*/
-class DispatcherThread : public Thread, public Condition
+class DispatcherThread final
+ : public Thread
{
- public:
+public:
+ std::condition_variable_any condvar;
+ std::mutex mutex;
+
DispatcherThread() : Thread() { }
- void Run() anope_override;
+ void Run() override;
};
class ModuleSQL;
static ModuleSQL *me;
-class ModuleSQL : public Module, public Pipe
+
+class ModuleSQL final
+ : public Module
+ , public Pipe
{
/* SQL connections */
std::map<Anope::string, MySQLService *> MySQLServices;
- public:
+public:
/* Pending query requests */
std::deque<QueryRequest> QueryRequests;
/* Pending finished requests with results */
@@ -194,12 +206,12 @@ class ModuleSQL : public Module, public Pipe
MySQLServices.clear();
DThread->SetExitState();
- DThread->Wakeup();
+ DThread->condvar.notify_all();
DThread->Join();
delete DThread;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = conf->GetModule(this);
@@ -235,12 +247,12 @@ class ModuleSQL : public Module, public Pipe
const Anope::string &server = block->Get<const Anope::string>("server", "127.0.0.1");
const Anope::string &user = block->Get<const Anope::string>("username", "anope");
const Anope::string &password = block->Get<const Anope::string>("password");
- int port = block->Get<int>("port", "3306");
+ unsigned int port = block->Get<unsigned int>("port", "3306");
try
{
- MySQLService *ss = new MySQLService(this, connname, database, server, user, password, port);
- this->MySQLServices.insert(std::make_pair(connname, ss));
+ auto *ss = new MySQLService(this, connname, database, server, user, password, port);
+ this->MySQLServices.emplace(connname, ss);
Log(LOG_NORMAL, "mysql") << "MySQL: Successfully connected to server " << connname << " (" << server << ")";
}
@@ -252,9 +264,9 @@ class ModuleSQL : public Module, public Pipe
}
}
- void OnModuleUnload(User *, Module *m) anope_override
+ void OnModuleUnload(User *, Module *m) override
{
- this->DThread->Lock();
+ this->DThread->mutex.lock();
for (unsigned i = this->QueryRequests.size(); i > 0; --i)
{
@@ -264,30 +276,28 @@ class ModuleSQL : public Module, public Pipe
{
if (i == 1)
{
- r.service->Lock.Lock();
- r.service->Lock.Unlock();
+ r.service->Lock.lock();
+ r.service->Lock.unlock();
}
this->QueryRequests.erase(this->QueryRequests.begin() + i - 1);
}
}
- this->DThread->Unlock();
+ this->DThread->mutex.unlock();
this->OnNotify();
}
- void OnNotify() anope_override
+ void OnNotify() override
{
- this->DThread->Lock();
+ this->DThread->mutex.lock();
std::deque<QueryResult> finishedRequests = this->FinishedRequests;
this->FinishedRequests.clear();
- this->DThread->Unlock();
+ this->DThread->mutex.unlock();
- for (std::deque<QueryResult>::const_iterator it = finishedRequests.begin(), it_end = finishedRequests.end(); it != it_end; ++it)
+ for (const auto &qr : finishedRequests)
{
- const QueryResult &qr = *it;
-
if (!qr.sqlinterface)
throw SQL::Exception("NULL qr.sqlinterface in MySQLPipe::OnNotify() ?");
@@ -299,16 +309,21 @@ class ModuleSQL : public Module, public Pipe
}
};
-MySQLService::MySQLService(Module *o, const Anope::string &n, const Anope::string &d, const Anope::string &s, const Anope::string &u, const Anope::string &p, int po)
-: Provider(o, n), database(d), server(s), user(u), password(p), port(po), sql(NULL)
+MySQLService::MySQLService(Module *o, const Anope::string &n, const Anope::string &d, const Anope::string &s, const Anope::string &u, const Anope::string &p, unsigned int po)
+ : Provider(o, n)
+ , database(d)
+ , server(s)
+ , user(u)
+ , password(p)
+ , port(po)
{
Connect();
}
MySQLService::~MySQLService()
{
- me->DThread->Lock();
- this->Lock.Lock();
+ me->DThread->mutex.lock();
+ this->Lock.lock();
mysql_close(this->sql);
this->sql = NULL;
@@ -323,21 +338,21 @@ MySQLService::~MySQLService()
me->QueryRequests.erase(me->QueryRequests.begin() + i - 1);
}
}
- this->Lock.Unlock();
- me->DThread->Unlock();
+ this->Lock.unlock();
+ me->DThread->mutex.unlock();
}
void MySQLService::Run(Interface *i, const Query &query)
{
- me->DThread->Lock();
+ me->DThread->mutex.lock();
me->QueryRequests.push_back(QueryRequest(this, i, query));
- me->DThread->Unlock();
- me->DThread->Wakeup();
+ me->DThread->mutex.unlock();
+ me->DThread->condvar.notify_all();
}
Result MySQLService::RunQuery(const Query &query)
{
- this->Lock.Lock();
+ this->Lock.lock();
Anope::string real_query = this->BuildQuery(query);
@@ -355,13 +370,13 @@ Result MySQLService::RunQuery(const Query &query)
while (!mysql_next_result(this->sql))
mysql_free_result(mysql_store_result(this->sql));
- this->Lock.Unlock();
+ this->Lock.unlock();
return MySQLResult(id, query, real_query, res);
}
else
{
Anope::string error = mysql_error(this->sql);
- this->Lock.Unlock();
+ this->Lock.unlock();
return MySQLResult(query, real_query, error);
}
}
@@ -373,14 +388,14 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
if (known_cols.empty())
{
- Log(LOG_DEBUG) << "m_mysql: Fetching columns for " << table;
+ Log(LOG_DEBUG) << "mysql: Fetching columns for " << table;
Result columns = this->RunQuery("SHOW COLUMNS FROM `" + table + "`");
for (int i = 0; i < columns.Rows(); ++i)
{
const Anope::string &column = columns.Get(i, "Field");
- Log(LOG_DEBUG) << "m_mysql: Column #" << i << " for " << table << ": " << column;
+ Log(LOG_DEBUG) << "mysql: Column #" << i << " for " << table << ": " << column;
known_cols.insert(column);
}
}
@@ -389,12 +404,12 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
{
Anope::string query_text = "CREATE TABLE `" + table + "` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
" `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (const auto &[column, _] : data.data)
{
- known_cols.insert(it->first);
+ known_cols.insert(column);
- query_text += ", `" + it->first + "` ";
- if (data.GetType(it->first) == Serialize::Data::DT_INT)
+ query_text += ", `" + column + "` ";
+ if (data.GetType(column) == Serialize::Data::DT_INT)
query_text += "int(11)";
else
query_text += "text";
@@ -403,21 +418,23 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
queries.push_back(query_text);
}
else
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ {
+ for (const auto &[column, _] : data.data)
{
- if (known_cols.count(it->first) > 0)
+ if (known_cols.count(column) > 0)
continue;
- known_cols.insert(it->first);
+ known_cols.insert(column);
- Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` ";
- if (data.GetType(it->first) == Serialize::Data::DT_INT)
+ Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` ";
+ if (data.GetType(column) == Serialize::Data::DT_INT)
query_text += "int(11)";
else
query_text += "text";
queries.push_back(query_text);
}
+ }
return queries;
}
@@ -425,27 +442,29 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Data &data)
{
/* Empty columns not present in the data set */
- const std::set<Anope::string> &known_cols = this->active_schema[table];
- for (std::set<Anope::string>::iterator it = known_cols.begin(), it_end = known_cols.end(); it != it_end; ++it)
- if (*it != "id" && *it != "timestamp" && data.data.count(*it) == 0)
- data[*it] << "";
+ for (const auto &known_col : this->active_schema[table])
+ {
+ if (known_col != "id" && known_col != "timestamp" && data.data.count(known_col) == 0)
+ data[known_col] << "";
+ }
Anope::string query_text = "INSERT INTO `" + table + "` (`id`";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += ",`" + it->first + "`";
- query_text += ") VALUES (" + stringify(id);
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += ",@" + it->first + "@";
+
+ for (const auto &[field, _] : data.data)
+ query_text += ",`" + field + "`";
+ query_text += ") VALUES (" + Anope::ToString(id);
+ for (const auto &[field, _] : data.data)
+ query_text += ",@" + field + "@";
query_text += ") ON DUPLICATE KEY UPDATE ";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += "`" + it->first + "`=VALUES(`" + it->first + "`),";
+ for (const auto &[field, _] : data.data)
+ query_text += "`" + field + "`=VALUES(`" + field + "`),";
query_text.erase(query_text.end() - 1);
Query query(query_text);
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (auto &[field, value] : data.data)
{
Anope::string buf;
- *it->second >> buf;
+ *value >> buf;
bool escape = true;
if (buf.empty())
@@ -454,7 +473,7 @@ Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Dat
escape = false;
}
- query.SetValue(it->first, buf, escape);
+ query.SetValue(field, buf, escape);
}
return query;
@@ -509,31 +528,31 @@ Anope::string MySQLService::BuildQuery(const Query &q)
{
Anope::string real_query = q.query;
- for (std::map<Anope::string, QueryData>::const_iterator it = q.parameters.begin(), it_end = q.parameters.end(); it != it_end; ++it)
- real_query = real_query.replace_all_cs("@" + it->first + "@", (it->second.escape ? ("'" + this->Escape(it->second.data) + "'") : it->second.data));
+ for (const auto &[name, value] : q.parameters)
+ real_query = real_query.replace_all_cs("@" + name + "@", (value.escape ? ("'" + this->Escape(value.data) + "'") : value.data));
return real_query;
}
Anope::string MySQLService::FromUnixtime(time_t t)
{
- return "FROM_UNIXTIME(" + stringify(t) + ")";
+ return "FROM_UNIXTIME(" + Anope::ToString(t) + ")";
}
void DispatcherThread::Run()
{
- this->Lock();
+ this->mutex.lock();
while (!this->GetExitState())
{
if (!me->QueryRequests.empty())
{
QueryRequest &r = me->QueryRequests.front();
- this->Unlock();
+ this->mutex.unlock();
Result sresult = r.service->RunQuery(r.query);
- this->Lock();
+ this->mutex.lock();
if (!me->QueryRequests.empty() && me->QueryRequests.front().query == r.query)
{
if (r.sqlinterface)
@@ -545,11 +564,11 @@ void DispatcherThread::Run()
{
if (!me->FinishedRequests.empty())
me->Notify();
- this->Wait();
+ this->condvar.wait(this->mutex);
}
}
- this->Unlock();
+ this->mutex.unlock();
}
MODULE_INIT(ModuleSQL)
diff --git a/modules/extra/m_regex_pcre2.cpp b/modules/extra/regex_pcre2.cpp
index 828b5128a..991be3f6c 100644
--- a/modules/extra/m_regex_pcre2.cpp
+++ b/modules/extra/regex_pcre2.cpp
@@ -14,11 +14,12 @@
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
-class PCRERegex : public Regex
+class PCRERegex final
+ : public Regex
{
pcre2_code *regex;
- public:
+public:
PCRERegex(const Anope::string &expr) : Regex(expr)
{
int errcode;
@@ -29,7 +30,7 @@ class PCRERegex : public Regex
{
PCRE2_UCHAR error[128];
pcre2_get_error_message(errcode, error, sizeof error);
- throw RegexException("Error in regex " + expr + " at offset " + stringify(erroffset) + ": " + reinterpret_cast<const char*>(error));
+ throw RegexException("Error in regex " + expr + " at offset " + Anope::ToString(erroffset) + ": " + reinterpret_cast<const char*>(error));
}
}
@@ -47,22 +48,24 @@ class PCRERegex : public Regex
}
};
-class PCRERegexProvider : public RegexProvider
+class PCRERegexProvider final
+ : public RegexProvider
{
- public:
+public:
PCRERegexProvider(Module *creator) : RegexProvider(creator, "regex/pcre") { }
- Regex *Compile(const Anope::string &expression) anope_override
+ Regex *Compile(const Anope::string &expression) override
{
return new PCRERegex(expression);
}
};
-class ModuleRegexPCRE : public Module
+class ModuleRegexPCRE final
+ : public Module
{
PCRERegexProvider pcre_regex_provider;
- public:
+public:
ModuleRegexPCRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
pcre_regex_provider(this)
{
@@ -71,15 +74,10 @@ class ModuleRegexPCRE : public Module
~ModuleRegexPCRE()
{
- for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it)
+ for (auto *xlm : XLineManager::XLineManagers)
{
- XLineManager *xlm = *it;
- const std::vector<XLine *> &xlines = xlm->GetList();
-
- for (unsigned int i = 0; i < xlines.size(); ++i)
+ for (auto *x : xlm->GetList())
{
- XLine *x = xlines[i];
-
if (x->regex && dynamic_cast<PCRERegex *>(x->regex))
{
delete x->regex;
diff --git a/modules/extra/m_regex_posix.cpp b/modules/extra/regex_posix.cpp
index 2cd6811b8..cef4486f9 100644
--- a/modules/extra/m_regex_posix.cpp
+++ b/modules/extra/regex_posix.cpp
@@ -10,11 +10,12 @@
#include <sys/types.h>
#include <regex.h>
-class POSIXRegex : public Regex
+class POSIXRegex final
+ : public Regex
{
regex_t regbuf;
- public:
+public:
POSIXRegex(const Anope::string &expr) : Regex(expr)
{
int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE);
@@ -38,22 +39,24 @@ class POSIXRegex : public Regex
}
};
-class POSIXRegexProvider : public RegexProvider
+class POSIXRegexProvider final
+ : public RegexProvider
{
- public:
+public:
POSIXRegexProvider(Module *creator) : RegexProvider(creator, "regex/posix") { }
- Regex *Compile(const Anope::string &expression) anope_override
+ Regex *Compile(const Anope::string &expression) override
{
return new POSIXRegex(expression);
}
};
-class ModuleRegexPOSIX : public Module
+class ModuleRegexPOSIX final
+ : public Module
{
POSIXRegexProvider posix_regex_provider;
- public:
+public:
ModuleRegexPOSIX(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
posix_regex_provider(this)
{
@@ -62,15 +65,10 @@ class ModuleRegexPOSIX : public Module
~ModuleRegexPOSIX()
{
- for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it)
+ for (auto *xlm : XLineManager::XLineManagers)
{
- XLineManager *xlm = *it;
- const std::vector<XLine *> &xlines = xlm->GetList();
-
- for (unsigned int i = 0; i < xlines.size(); ++i)
+ for (auto *x : xlm->GetList())
{
- XLine *x = xlines[i];
-
if (x->regex && dynamic_cast<POSIXRegex *>(x->regex))
{
delete x->regex;
diff --git a/modules/extra/m_regex_tre.cpp b/modules/extra/regex_tre.cpp
index 3e8d8ef83..18485507a 100644
--- a/modules/extra/m_regex_tre.cpp
+++ b/modules/extra/regex_tre.cpp
@@ -11,11 +11,12 @@
#include "module.h"
#include <tre/regex.h>
-class TRERegex : public Regex
+class TRERegex final
+ : public Regex
{
regex_t regbuf;
- public:
+public:
TRERegex(const Anope::string &expr) : Regex(expr)
{
int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB);
@@ -39,22 +40,24 @@ class TRERegex : public Regex
}
};
-class TRERegexProvider : public RegexProvider
+class TRERegexProvider final
+ : public RegexProvider
{
- public:
+public:
TRERegexProvider(Module *creator) : RegexProvider(creator, "regex/tre") { }
- Regex *Compile(const Anope::string &expression) anope_override
+ Regex *Compile(const Anope::string &expression) override
{
return new TRERegex(expression);
}
};
-class ModuleRegexTRE : public Module
+class ModuleRegexTRE final
+ : public Module
{
TRERegexProvider tre_regex_provider;
- public:
+public:
ModuleRegexTRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
tre_regex_provider(this)
{
@@ -63,15 +66,10 @@ class ModuleRegexTRE : public Module
~ModuleRegexTRE()
{
- for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it)
+ for (auto *xlm : XLineManager::XLineManagers)
{
- XLineManager *xlm = *it;
- const std::vector<XLine *> &xlines = xlm->GetList();
-
- for (unsigned int i = 0; i < xlines.size(); ++i)
+ for (auto *x : xlm->GetList())
{
- XLine *x = xlines[i];
-
if (x->regex && dynamic_cast<TRERegex *>(x->regex))
{
delete x->regex;
diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/sqlite.cpp
index 1654370fc..4968e8e0d 100644
--- a/modules/extra/m_sqlite.cpp
+++ b/modules/extra/sqlite.cpp
@@ -19,9 +19,10 @@ using namespace SQL;
/** A SQLite result
*/
-class SQLiteResult : public Result
+class SQLiteResult final
+ : public Result
{
- public:
+public:
SQLiteResult(unsigned int i, const Query &q, const Anope::string &fq) : Result(i, q, fq)
{
}
@@ -38,41 +39,43 @@ class SQLiteResult : public Result
/** A SQLite database, there can be multiple
*/
-class SQLiteService : public Provider
+class SQLiteService final
+ : public Provider
{
std::map<Anope::string, std::set<Anope::string> > active_schema;
Anope::string database;
- sqlite3 *sql;
+ sqlite3 *sql = nullptr;
Anope::string Escape(const Anope::string &query);
- public:
+public:
SQLiteService(Module *o, const Anope::string &n, const Anope::string &d);
~SQLiteService();
- void Run(Interface *i, const Query &query) anope_override;
+ void Run(Interface *i, const Query &query) override;
- Result RunQuery(const Query &query);
+ Result RunQuery(const Query &query) override;
- std::vector<Query> CreateTable(const Anope::string &table, const Data &data) anope_override;
+ std::vector<Query> CreateTable(const Anope::string &table, const Data &data) override;
- Query BuildInsert(const Anope::string &table, unsigned int id, Data &data);
+ Query BuildInsert(const Anope::string &table, unsigned int id, Data &data) override;
- Query GetTables(const Anope::string &prefix);
+ Query GetTables(const Anope::string &prefix) override;
Anope::string BuildQuery(const Query &q);
- Anope::string FromUnixtime(time_t);
+ Anope::string FromUnixtime(time_t) override;
};
-class ModuleSQLite : public Module
+class ModuleSQLite final
+ : public Module
{
/* SQL connections */
std::map<Anope::string, SQLiteService *> SQLiteServices;
- public:
+public:
ModuleSQLite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
{
}
@@ -84,7 +87,7 @@ class ModuleSQLite : public Module
SQLiteServices.clear();
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = conf->GetModule(this);
@@ -119,7 +122,7 @@ class ModuleSQLite : public Module
try
{
- SQLiteService *ss = new SQLiteService(this, connname, database);
+ auto *ss = new SQLiteService(this, connname, database);
this->SQLiteServices[connname] = ss;
Log(LOG_NORMAL, "sqlite") << "SQLite: Successfully added database " << database;
@@ -134,7 +137,7 @@ class ModuleSQLite : public Module
};
SQLiteService::SQLiteService(Module *o, const Anope::string &n, const Anope::string &d)
-: Provider(o, n), database(d), sql(NULL)
+: Provider(o, n), database(d)
{
int db = sqlite3_open_v2(database.c_str(), &this->sql, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
if (db != SQLITE_OK)
@@ -200,7 +203,12 @@ Result SQLiteService::RunQuery(const Query &query)
if (err != SQLITE_DONE)
return SQLiteResult(query, real_query, sqlite3_errmsg(this->sql));
+ // GCC and clang disagree about whether this should be a move >:(
+#ifdef __clang__
+ return std::move(result);
+#else
return result;
+#endif
}
std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const Data &data)
@@ -210,14 +218,14 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const
if (known_cols.empty())
{
- Log(LOG_DEBUG) << "m_sqlite: Fetching columns for " << table;
+ Log(LOG_DEBUG) << "sqlite: Fetching columns for " << table;
Result columns = this->RunQuery("PRAGMA table_info(" + table + ")");
for (int i = 0; i < columns.Rows(); ++i)
{
const Anope::string &column = columns.Get(i, "name");
- Log(LOG_DEBUG) << "m_sqlite: Column #" << i << " for " << table << ": " << column;
+ Log(LOG_DEBUG) << "sqlite: Column #" << i << " for " << table << ": " << column;
known_cols.insert(column);
}
}
@@ -226,12 +234,12 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const
{
Anope::string query_text = "CREATE TABLE `" + table + "` (`id` INTEGER PRIMARY KEY, `timestamp` timestamp DEFAULT CURRENT_TIMESTAMP";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (const auto &[column, _] : data.data)
{
- known_cols.insert(it->first);
+ known_cols.insert(column);
- query_text += ", `" + it->first + "` ";
- if (data.GetType(it->first) == Serialize::Data::DT_INT)
+ query_text += ", `" + column + "` ";
+ if (data.GetType(column) == Serialize::Data::DT_INT)
query_text += "int(11)";
else
query_text += "text";
@@ -251,21 +259,23 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const
queries.push_back(query_text);
}
else
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ {
+ for (const auto &[column, _] : data.data)
{
- if (known_cols.count(it->first) > 0)
+ if (known_cols.count(column) > 0)
continue;
- known_cols.insert(it->first);
+ known_cols.insert(column);
- Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` ";
- if (data.GetType(it->first) == Serialize::Data::DT_INT)
+ Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` ";
+ if (data.GetType(column) == Serialize::Data::DT_INT)
query_text += "int(11)";
else
query_text += "text";
queries.push_back(query_text);
}
+ }
return queries;
}
@@ -273,31 +283,32 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const
Query SQLiteService::BuildInsert(const Anope::string &table, unsigned int id, Data &data)
{
/* Empty columns not present in the data set */
- const std::set<Anope::string> &known_cols = this->active_schema[table];
- for (std::set<Anope::string>::iterator it = known_cols.begin(), it_end = known_cols.end(); it != it_end; ++it)
- if (*it != "id" && *it != "timestamp" && data.data.count(*it) == 0)
- data[*it] << "";
+ for (const auto &known_col : this->active_schema[table])
+ {
+ if (known_col != "id" && known_col != "timestamp" && data.data.count(known_col) == 0)
+ data[known_col] << "";
+ }
Anope::string query_text = "REPLACE INTO `" + table + "` (";
if (id > 0)
query_text += "`id`,";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += "`" + it->first + "`,";
+ for (const auto &[field, _] : data.data)
+ query_text += "`" + field + "`,";
query_text.erase(query_text.length() - 1);
query_text += ") VALUES (";
if (id > 0)
- query_text += stringify(id) + ",";
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
- query_text += "@" + it->first + "@,";
+ query_text += Anope::ToString(id) + ",";
+ for (const auto &[field, _] : data.data)
+ query_text += "@" + field + "@,";
query_text.erase(query_text.length() - 1);
query_text += ")";
Query query(query_text);
- for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
+ for (auto &[field, value] : data.data)
{
Anope::string buf;
- *it->second >> buf;
- query.SetValue(it->first, buf);
+ *value >> buf;
+ query.SetValue(field, buf);
}
return query;
@@ -320,15 +331,15 @@ Anope::string SQLiteService::BuildQuery(const Query &q)
{
Anope::string real_query = q.query;
- for (std::map<Anope::string, QueryData>::const_iterator it = q.parameters.begin(), it_end = q.parameters.end(); it != it_end; ++it)
- real_query = real_query.replace_all_cs("@" + it->first + "@", (it->second.escape ? ("'" + this->Escape(it->second.data) + "'") : it->second.data));
+ for (const auto &[name, value] : q.parameters)
+ real_query = real_query.replace_all_cs("@" + name + "@", (value.escape ? ("'" + this->Escape(value.data) + "'") : value.data));
return real_query;
}
Anope::string SQLiteService::FromUnixtime(time_t t)
{
- return "datetime('" + stringify(t) + "', 'unixepoch')";
+ return "datetime('" + Anope::ToString(t) + "', 'unixepoch')";
}
MODULE_INIT(ModuleSQLite)
diff --git a/modules/extra/m_ssl_gnutls.cpp b/modules/extra/ssl_gnutls.cpp
index ef7d7c877..520f877c0 100644
--- a/modules/extra/m_ssl_gnutls.cpp
+++ b/modules/extra/ssl_gnutls.cpp
@@ -22,22 +22,24 @@ static GnuTLSModule *me;
namespace GnuTLS { class X509CertCredentials; }
-class MySSLService : public SSLService
+class MySSLService final
+ : public SSLService
{
- public:
+public:
MySSLService(Module *o, const Anope::string &n);
/** Initialize a socket to use SSL
* @param s The socket
*/
- void Init(Socket *s) anope_override;
+ void Init(Socket *s) override;
};
-class SSLSocketIO : public SocketIO
+class SSLSocketIO final
+ : public SocketIO
{
- public:
- gnutls_session_t sess;
- GnuTLS::X509CertCredentials* mycreds;
+public:
+ gnutls_session_t sess = nullptr;
+ GnuTLS::X509CertCredentials *mycreds;
/** Constructor
*/
@@ -49,61 +51,61 @@ class SSLSocketIO : public SocketIO
* @param sz How much to read
* @return Number of bytes received
*/
- int Recv(Socket *s, char *buf, size_t sz) anope_override;
+ int Recv(Socket *s, char *buf, size_t sz) override;
/** Write something to the socket
* @param s The socket
* @param buf The data to write
* @param size The length of the data
*/
- int Send(Socket *s, const char *buf, size_t sz) anope_override;
+ int Send(Socket *s, const char *buf, size_t sz) override;
/** Accept a connection from a socket
* @param s The socket
* @return The new socket
*/
- ClientSocket *Accept(ListenSocket *s) anope_override;
+ ClientSocket *Accept(ListenSocket *s) override;
/** Finished accepting a connection from a socket
* @param s The socket
* @return SF_ACCEPTED if accepted, SF_ACCEPTING if still in process, SF_DEAD on error
*/
- SocketFlag FinishAccept(ClientSocket *cs) anope_override;
+ SocketFlag FinishAccept(ClientSocket *cs) override;
/** Connect the socket
* @param s THe socket
* @param target IP to connect to
* @param port to connect to
*/
- void Connect(ConnectionSocket *s, const Anope::string &target, int port) anope_override;
+ void Connect(ConnectionSocket *s, const Anope::string &target, int port) override;
/** Called to potentially finish a pending connection
* @param s The socket
* @return SF_CONNECTED on success, SF_CONNECTING if still pending, and SF_DEAD on error.
*/
- SocketFlag FinishConnect(ConnectionSocket *s) anope_override;
+ SocketFlag FinishConnect(ConnectionSocket *s) override;
/** Called when the socket is destructing
*/
- void Destroy() anope_override;
+ void Destroy() override;
};
namespace GnuTLS
{
- class Init
+ class Init final
{
- public:
+ public:
Init() { gnutls_global_init(); }
~Init() { gnutls_global_deinit(); }
};
/** Used to create a gnutls_datum_t* from an Anope::string
*/
- class Datum
+ class Datum final
{
gnutls_datum_t datum;
- public:
+ public:
Datum(const Anope::string &dat)
{
datum.data = reinterpret_cast<unsigned char *>(const_cast<char *>(dat.data()));
@@ -113,13 +115,11 @@ namespace GnuTLS
const gnutls_datum_t *get() const { return &datum; }
};
- class DHParams
+ class DHParams final
{
- gnutls_dh_params_t dh_params;
-
- public:
- DHParams() : dh_params(NULL) { }
+ gnutls_dh_params_t dh_params = nullptr;
+ public:
void Import(const Anope::string &dhstr)
{
if (dh_params != NULL)
@@ -150,13 +150,13 @@ namespace GnuTLS
gnutls_dh_params_t get() const { return dh_params; }
};
- class X509Key
+ class X509Key final
{
/** Ensure that the key is deinited in case the constructor of X509Key throws
*/
- class RAIIKey
+ class RAIIKey final
{
- public:
+ public:
gnutls_x509_privkey_t key;
RAIIKey()
@@ -172,7 +172,7 @@ namespace GnuTLS
}
} key;
- public:
+ public:
/** Import */
X509Key(const Anope::string &keystr)
{
@@ -181,14 +181,14 @@ namespace GnuTLS
throw ConfigException("Error loading private key: " + Anope::string(gnutls_strerror(ret)));
}
- gnutls_x509_privkey_t& get() { return key.key; }
+ gnutls_x509_privkey_t &get() { return key.key; }
};
- class X509CertList
+ class X509CertList final
{
std::vector<gnutls_x509_crt_t> certs;
- public:
+ public:
/** Import */
X509CertList(const Anope::string &certstr)
{
@@ -219,13 +219,13 @@ namespace GnuTLS
gnutls_x509_crt_deinit(*i);
}
- gnutls_x509_crt_t* raw() { return &certs[0]; }
+ gnutls_x509_crt_t *raw() { return &certs[0]; }
unsigned int size() const { return certs.size(); }
};
- class X509CertCredentials
+ class X509CertCredentials final
{
- unsigned int refcount;
+ unsigned int refcount = 0;
gnutls_certificate_credentials_t cred;
DHParams dh;
@@ -236,18 +236,14 @@ namespace GnuTLS
return ret;
}
- #if (GNUTLS_VERSION_MAJOR < 2 || (GNUTLS_VERSION_MAJOR == 2 && GNUTLS_VERSION_MINOR < 12))
- static int cert_callback(gnutls_session_t sess, const gnutls_datum_t* req_ca_rdn, int nreqs, const gnutls_pk_algorithm_t* sign_algos, int sign_algos_length, gnutls_retr_st* st);
- #else
- static int cert_callback(gnutls_session_t sess, const gnutls_datum_t* req_ca_rdn, int nreqs, const gnutls_pk_algorithm_t* sign_algos, int sign_algos_length, gnutls_retr2_st* st);
- #endif
+ static int cert_callback(gnutls_session_t sess, const gnutls_datum_t *req_ca_rdn, int nreqs, const gnutls_pk_algorithm_t *sign_algos, int sign_algos_length, gnutls_retr2_st *st);
- public:
+ public:
X509CertList certs;
X509Key key;
X509CertCredentials(const Anope::string &certfile, const Anope::string &keyfile)
- : refcount(0), certs(LoadFile(certfile)), key(LoadFile(keyfile))
+ : certs(LoadFile(certfile)), key(LoadFile(keyfile))
{
if (gnutls_certificate_allocate_credentials(&cred) < 0)
throw ConfigException("Cannot allocate certificate credentials");
@@ -259,11 +255,7 @@ namespace GnuTLS
throw ConfigException("Unable to set cert/key pair");
}
- #if (GNUTLS_VERSION_MAJOR < 2 || (GNUTLS_VERSION_MAJOR == 2 && GNUTLS_VERSION_MINOR < 12))
- gnutls_certificate_client_set_retrieve_function(cred, cert_callback);
- #else
gnutls_certificate_set_retrieve_function(cred, cert_callback);
- #endif
}
~X509CertCredentials()
@@ -294,15 +286,16 @@ namespace GnuTLS
};
}
-class GnuTLSModule : public Module
+class GnuTLSModule final
+ : public Module
{
GnuTLS::Init libinit;
- public:
- GnuTLS::X509CertCredentials *cred;
+public:
+ GnuTLS::X509CertCredentials *cred = nullptr;
MySSLService service;
- GnuTLSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), cred(NULL), service(this, "ssl")
+ GnuTLSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), service(this, "ssl")
{
me = this;
this->SetPermanent(true);
@@ -332,12 +325,12 @@ class GnuTLSModule : public Module
}
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = conf->GetModule(this);
- const Anope::string certfile = config->Get<const Anope::string>("cert", "data/anope.crt");
- const Anope::string keyfile = config->Get<const Anope::string>("key", "data/anope.key");
+ const Anope::string certfile = config->Get<const Anope::string>("cert", "data/fullchain.pem");
+ const Anope::string keyfile = config->Get<const Anope::string>("key", "data/privkey.pem");
const Anope::string dhfile = config->Get<const Anope::string>("dh", "data/dhparams.pem");
CheckFile(certfile);
@@ -357,7 +350,7 @@ class GnuTLSModule : public Module
delete newcred;
throw;
}
- Log(LOG_DEBUG) << "m_ssl_gnutls: Successfully loaded DH parameters from " << dhfile;
+ Log(LOG_DEBUG) << "ssl_gnutls: Successfully loaded DH parameters from " << dhfile;
}
if (cred)
@@ -365,10 +358,10 @@ class GnuTLSModule : public Module
cred = newcred;
cred->incrref();
- Log(LOG_DEBUG) << "m_ssl_gnutls: Successfully loaded certificate " << certfile << " and private key " << keyfile;
+ Log(LOG_DEBUG) << "ssl_gnutls: Successfully loaded certificate " << certfile << " and private key " << keyfile;
}
- void OnPreServerConnect() anope_override
+ void OnPreServerConnect() override
{
Configuration::Block *config = Config->GetBlock("uplink", Anope::CurrentUplink);
@@ -535,7 +528,7 @@ void SSLSocketIO::Connect(ConnectionSocket *s, const Anope::string &target, int
s->flags[SF_CONNECTING] = s->flags[SF_CONNECTED] = false;
- s->conaddr.pton(s->IsIPv6() ? AF_INET6 : AF_INET, target, port);
+ s->conaddr.pton(s->GetFamily(), target, port);
int c = connect(s->GetFD(), &s->conaddr.sa, s->conaddr.size());
if (c == -1)
{
@@ -630,21 +623,15 @@ void SSLSocketIO::Destroy()
delete this;
}
-SSLSocketIO::SSLSocketIO() : sess(NULL), mycreds(me->cred)
+SSLSocketIO::SSLSocketIO() : mycreds(me->cred)
{
mycreds->incrref();
}
-#if (GNUTLS_VERSION_MAJOR < 2 || (GNUTLS_VERSION_MAJOR == 2 && GNUTLS_VERSION_MINOR < 12))
-int GnuTLS::X509CertCredentials::cert_callback(gnutls_session_t sess, const gnutls_datum_t* req_ca_rdn, int nreqs, const gnutls_pk_algorithm_t* sign_algos, int sign_algos_length, gnutls_retr_st* st)
-{
- st->type = GNUTLS_CRT_X509;
-#else
-int GnuTLS::X509CertCredentials::cert_callback(gnutls_session_t sess, const gnutls_datum_t* req_ca_rdn, int nreqs, const gnutls_pk_algorithm_t* sign_algos, int sign_algos_length, gnutls_retr2_st* st)
+int GnuTLS::X509CertCredentials::cert_callback(gnutls_session_t sess, const gnutls_datum_t *req_ca_rdn, int nreqs, const gnutls_pk_algorithm_t *sign_algos, int sign_algos_length, gnutls_retr2_st *st)
{
st->cert_type = GNUTLS_CRT_X509;
st->key_type = GNUTLS_PRIVKEY_X509;
-#endif
st->ncerts = me->cred->certs.size();
st->cert.x509 = me->cred->certs.raw();
st->key.x509 = me->cred->key.get();
diff --git a/modules/extra/m_ssl_openssl.cpp b/modules/extra/ssl_openssl.cpp
index 335542a76..a052752ae 100644
--- a/modules/extra/m_ssl_openssl.cpp
+++ b/modules/extra/ssl_openssl.cpp
@@ -12,7 +12,9 @@
#include "module.h"
#include "modules/ssl.h"
-#define OPENSSL_NO_SHA512
+#define OPENSSL_API_COMPAT 0x10100000L
+#define OPENSSL_NO_DEPRECATED
+
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -21,20 +23,22 @@
static SSL_CTX *server_ctx, *client_ctx;
-class MySSLService : public SSLService
+class MySSLService final
+ : public SSLService
{
- public:
+public:
MySSLService(Module *o, const Anope::string &n);
/** Initialize a socket to use SSL
* @param s The socket
*/
- void Init(Socket *s) anope_override;
+ void Init(Socket *s) override;
};
-class SSLSocketIO : public SocketIO
+class SSLSocketIO final
+ : public SocketIO
{
- public:
+public:
/* The SSL socket for this socket */
SSL *sslsock;
@@ -48,52 +52,53 @@ class SSLSocketIO : public SocketIO
* @param sz How much to read
* @return Number of bytes received
*/
- int Recv(Socket *s, char *buf, size_t sz) anope_override;
+ int Recv(Socket *s, char *buf, size_t sz) override;
/** Write something to the socket
* @param s The socket
* @param buf The data to write
* @param size The length of the data
*/
- int Send(Socket *s, const char *buf, size_t sz) anope_override;
+ int Send(Socket *s, const char *buf, size_t sz) override;
/** Accept a connection from a socket
* @param s The socket
* @return The new socket
*/
- ClientSocket *Accept(ListenSocket *s) anope_override;
+ ClientSocket *Accept(ListenSocket *s) override;
/** Finished accepting a connection from a socket
* @param s The socket
* @return SF_ACCEPTED if accepted, SF_ACCEPTING if still in process, SF_DEAD on error
*/
- SocketFlag FinishAccept(ClientSocket *cs) anope_override;
+ SocketFlag FinishAccept(ClientSocket *cs) override;
/** Connect the socket
* @param s THe socket
* @param target IP to connect to
* @param port to connect to
*/
- void Connect(ConnectionSocket *s, const Anope::string &target, int port) anope_override;
+ void Connect(ConnectionSocket *s, const Anope::string &target, int port) override;
/** Called to potentially finish a pending connection
* @param s The socket
* @return SF_CONNECTED on success, SF_CONNECTING if still pending, and SF_DEAD on error.
*/
- SocketFlag FinishConnect(ConnectionSocket *s) anope_override;
+ SocketFlag FinishConnect(ConnectionSocket *s) override;
/** Called when the socket is destructing
*/
- void Destroy() anope_override;
+ void Destroy() override;
};
class SSLModule;
static SSLModule *me;
-class SSLModule : public Module
+class SSLModule final
+ : public Module
{
Anope::string certfile, keyfile;
- public:
+public:
MySSLService service;
SSLModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), service(this, "ssl")
@@ -102,16 +107,15 @@ class SSLModule : public Module
this->SetPermanent(true);
- SSL_library_init();
- SSL_load_error_strings();
+ OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, nullptr);
- client_ctx = SSL_CTX_new(SSLv23_client_method());
- server_ctx = SSL_CTX_new(SSLv23_server_method());
+ client_ctx = SSL_CTX_new(TLS_client_method());
+ server_ctx = SSL_CTX_new(TLS_server_method());
if (!client_ctx || !server_ctx)
throw ModuleException("Error initializing SSL CTX");
- long opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_CIPHER_SERVER_PREFERENCE;
+ long opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_CIPHER_SERVER_PREFERENCE;
SSL_CTX_set_options(client_ctx, opts);
SSL_CTX_set_options(server_ctx, opts);
@@ -138,19 +142,19 @@ class SSLModule : public Module
SSL_CTX_free(server_ctx);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = conf->GetModule(this);
- this->certfile = config->Get<const Anope::string>("cert", "data/anope.crt");
- this->keyfile = config->Get<const Anope::string>("key", "data/anope.key");
+ this->certfile = config->Get<const Anope::string>("cert", "data/fullchain.pem");
+ this->keyfile = config->Get<const Anope::string>("key", "data/privkey.pem");
if (Anope::IsFile(this->certfile.c_str()))
{
if (!SSL_CTX_use_certificate_chain_file(client_ctx, this->certfile.c_str()) || !SSL_CTX_use_certificate_chain_file(server_ctx, this->certfile.c_str()))
throw ConfigException("Error loading certificate");
else
- Log(LOG_DEBUG) << "m_ssl_openssl: Successfully loaded certificate " << this->certfile;
+ Log(LOG_DEBUG) << "ssl_openssl: Successfully loaded certificate " << this->certfile;
}
else
Log() << "Unable to open certificate " << this->certfile;
@@ -160,7 +164,7 @@ class SSLModule : public Module
if (!SSL_CTX_use_PrivateKey_file(client_ctx, this->keyfile.c_str(), SSL_FILETYPE_PEM) || !SSL_CTX_use_PrivateKey_file(server_ctx, this->keyfile.c_str(), SSL_FILETYPE_PEM))
throw ConfigException("Error loading private key");
else
- Log(LOG_DEBUG) << "m_ssl_openssl: Successfully loaded private key " << this->keyfile;
+ Log(LOG_DEBUG) << "ssl_openssl: Successfully loaded private key " << this->keyfile;
}
else
{
@@ -170,23 +174,42 @@ class SSLModule : public Module
Log() << "Unable to open private key " << this->keyfile;
}
- // Allow disabling SSLv3
- if (!config->Get<Anope::string>("sslv3").empty())
+ // Allow disabling old versions of TLS
+ if (config->Get<bool>("tlsv10", "false"))
{
- if (config->Get<bool>("sslv3"))
- {
- SSL_CTX_clear_options(client_ctx, SSL_OP_NO_SSLv3);
- SSL_CTX_clear_options(server_ctx, SSL_OP_NO_SSLv3);
- }
- else
- {
- SSL_CTX_set_options(client_ctx, SSL_OP_NO_SSLv3);
- SSL_CTX_set_options(server_ctx, SSL_OP_NO_SSLv3);
- }
+ SSL_CTX_clear_options(client_ctx, SSL_OP_NO_TLSv1);
+ SSL_CTX_clear_options(server_ctx, SSL_OP_NO_TLSv1);
+ }
+ else
+ {
+ SSL_CTX_set_options(client_ctx, SSL_OP_NO_TLSv1);
+ SSL_CTX_set_options(server_ctx, SSL_OP_NO_TLSv1);
+ }
+
+ if (config->Get<bool>("tlsv11", "true"))
+ {
+ SSL_CTX_clear_options(client_ctx, SSL_OP_NO_TLSv1_1);
+ SSL_CTX_clear_options(server_ctx, SSL_OP_NO_TLSv1_1);
+ }
+ else
+ {
+ SSL_CTX_set_options(client_ctx, SSL_OP_NO_TLSv1_1);
+ SSL_CTX_set_options(server_ctx, SSL_OP_NO_TLSv1_1);
+ }
+
+ if (config->Get<bool>("tlsv12", "true"))
+ {
+ SSL_CTX_clear_options(client_ctx, SSL_OP_NO_TLSv1_2);
+ SSL_CTX_clear_options(server_ctx, SSL_OP_NO_TLSv1_2);
+ }
+ else
+ {
+ SSL_CTX_set_options(client_ctx, SSL_OP_NO_TLSv1_2);
+ SSL_CTX_set_options(server_ctx, SSL_OP_NO_TLSv1_2);
}
}
- void OnPreServerConnect() anope_override
+ void OnPreServerConnect() override
{
Configuration::Block *config = Config->GetBlock("uplink", Anope::CurrentUplink);
@@ -334,7 +357,7 @@ void SSLSocketIO::Connect(ConnectionSocket *s, const Anope::string &target, int
s->flags[SF_CONNECTING] = s->flags[SF_CONNECTED] = false;
- s->conaddr.pton(s->IsIPv6() ? AF_INET6 : AF_INET, target, port);
+ s->conaddr.pton(s->GetFamily(), target, port);
int c = connect(s->GetFD(), &s->conaddr.sa, s->conaddr.size());
if (c == -1)
{
diff --git a/modules/extra/stats/irc2sql/irc2sql.h b/modules/extra/stats/irc2sql/irc2sql.h
deleted file mode 100644
index 949c59c07..000000000
--- a/modules/extra/stats/irc2sql/irc2sql.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- *
- * (C) 2013-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-#include "module.h"
-#include "modules/sql.h"
-
-class MySQLInterface : public SQL::Interface
-{
- public:
- MySQLInterface(Module *o) : SQL::Interface(o) { }
-
- void OnResult(const SQL::Result &r) anope_override
- {
- }
-
- void OnError(const SQL::Result &r) anope_override
- {
- if (!r.GetQuery().query.empty())
- Log(LOG_DEBUG) << "m_irc2sql: Error executing query " << r.finished_query << ": " << r.GetError();
- else
- Log(LOG_DEBUG) << "m_irc2sql: Error executing query: " << r.GetError();
- }
-};
-
-class IRC2SQL : public Module
-{
- ServiceReference<SQL::Provider> sql;
- MySQLInterface sqlinterface;
- SQL::Query query;
- std::vector<Anope::string> TableList, ProcedureList, EventList;
- Anope::string prefix, GeoIPDB;
- bool quitting, introduced_myself, ctcpuser, ctcpeob, firstrun;
- BotInfo *StatServ;
- PrimitiveExtensibleItem<bool> versionreply;
-
- void RunQuery(const SQL::Query &q);
- void GetTables();
-
- bool HasTable(const Anope::string &table);
- bool HasProcedure(const Anope::string &table);
- bool HasEvent(const Anope::string &table);
-
- void CheckTables();
-
- public:
- IRC2SQL(const Anope::string &modname, const Anope::string &creator) :
- Module(modname, creator, EXTRA | VENDOR), sql("", ""), sqlinterface(this), versionreply(this, "CTCPVERSION")
- {
- firstrun = true;
- quitting = false;
- introduced_myself = false;
- }
-
- void OnShutdown() anope_override;
- void OnReload(Configuration::Conf *config) anope_override;
- void OnNewServer(Server *server) anope_override;
- void OnServerQuit(Server *server) anope_override;
- void OnUserConnect(User *u, bool &exempt) anope_override;
- void OnUserQuit(User *u, const Anope::string &msg) anope_override;
- void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override;
- void OnUserAway(User *u, const Anope::string &message) anope_override;
- void OnFingerprint(User *u) anope_override;
- void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override;
- void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_override;
- void OnUserLogin(User *u) anope_override;
- void OnNickLogout(User *u) anope_override;
- void OnSetDisplayedHost(User *u) anope_override;
-
- void OnChannelCreate(Channel *c) anope_override;
- void OnChannelDelete(Channel *c) anope_override;
- void OnLeaveChannel(User *u, Channel *c) anope_override;
- void OnJoinChannel(User *u, Channel *c) anope_override;
- EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override;
- EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override;
-
- void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) anope_override;
-
- void OnBotNotice(User *u, BotInfo *bi, Anope::string &message) anope_override;
-};
diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp
index c4dfc957e..7658c2ac7 100644
--- a/modules/fantasy.cpp
+++ b/modules/fantasy.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandBSSetFantasy : public Command
+class CommandBSSetFantasy final
+ : public Command
{
- public:
+public:
CommandBSSetFantasy(Module *creator, const Anope::string &sname = "botserv/set/fantasy") : Command(creator, sname, 2, 2)
{
this->SetDesc(_("Enable fantaisist commands"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
const Anope::string &value = params[1];
@@ -63,7 +64,7 @@ class CommandBSSetFantasy : public Command
this->OnSyntaxError(source, source.command);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -80,19 +81,20 @@ class CommandBSSetFantasy : public Command
}
};
-class Fantasy : public Module
+class Fantasy final
+ : public Module
{
SerializableExtensibleItem<bool> fantasy;
CommandBSSetFantasy commandbssetfantasy;
- public:
+public:
Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
fantasy(this, "BS_FANTASY"), commandbssetfantasy(this)
{
}
- void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_override
+ void OnPrivmsg(User *u, Channel *c, Anope::string &msg, const Anope::map<Anope::string> &tags) override
{
if (!u || !c || !c->ci || !c->ci->bi || msg.empty() || msg[0] == '\1')
return;
@@ -173,7 +175,12 @@ class Fantasy : public Module
if (params.size() < cmd->min_params)
return;
- CommandSource source(u->nick, u, u->Account(), u, c->ci->bi);
+ Anope::string msgid;
+ auto iter = tags.find("msgid");
+ if (iter != tags.end())
+ msgid = iter->second;
+
+ CommandSource source(u->nick, u, u->Account(), u, c->ci->bi, msgid);
source.c = c;
source.command = it->first;
source.permission = info.permission;
@@ -208,7 +215,7 @@ class Fantasy : public Module
FOREACH_MOD(OnPostCommand, (source, cmd, params));
}
- void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) anope_override
+ void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) override
{
if (fantasy.HasExt(ci))
info.AddOption(_("Fantasy"));
diff --git a/modules/commands/gl_global.cpp b/modules/global/gl_global.cpp
index d951756a9..edfaa21a5 100644
--- a/modules/commands/gl_global.cpp
+++ b/modules/global/gl_global.cpp
@@ -11,18 +11,19 @@
#include "module.h"
-class CommandGLGlobal : public Command
+class CommandGLGlobal final
+ : public Command
{
ServiceReference<GlobalService> GService;
- public:
+public:
CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1), GService("GlobalService", "Global")
{
this->SetDesc(_("Send a message to all users"));
this->SetSyntax(_("\037message\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &msg = params[0];
@@ -35,7 +36,7 @@ class CommandGLGlobal : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
Reference<BotInfo> sender;
if (GService)
@@ -51,11 +52,12 @@ class CommandGLGlobal : public Command
}
};
-class GLGlobal : public Module
+class GLGlobal final
+ : public Module
{
CommandGLGlobal commandglglobal;
- public:
+public:
GLGlobal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandglglobal(this)
{
diff --git a/modules/pseudoclients/global.cpp b/modules/global/global.cpp
index 193ee2a45..a5288d754 100644
--- a/modules/pseudoclients/global.cpp
+++ b/modules/global/global.cpp
@@ -11,7 +11,9 @@
#include "module.h"
-class GlobalCore : public Module, public GlobalService
+class GlobalCore final
+ : public Module
+ , public GlobalService
{
Reference<BotInfo> Global;
@@ -19,22 +21,22 @@ class GlobalCore : public Module, public GlobalService
{
if (s != Me && !s->IsJuped())
s->Notice(sender, message);
- for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
- this->ServerGlobal(sender, s->GetLinks()[i], message);
+ for (auto *link : s->GetLinks())
+ this->ServerGlobal(sender, link, message);
}
- public:
+public:
GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
GlobalService(this)
{
}
- Reference<BotInfo> GetDefaultSender() anope_override
+ Reference<BotInfo> GetDefaultSender() override
{
return Global;
}
- void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_override
+ void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) override
{
if (Me->GetLinks().empty())
return;
@@ -53,7 +55,7 @@ class GlobalCore : public Module, public GlobalService
this->ServerGlobal(sender, Servers::GetUplink(), rmessage);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
const Anope::string &glnick = conf->GetModule(this)->Get<const Anope::string>("client");
@@ -67,28 +69,28 @@ class GlobalCore : public Module, public GlobalService
Global = bi;
}
- void OnRestart() anope_override
+ void OnRestart() override
{
const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown");
if (!gl.empty())
this->SendGlobal(Global, "", gl);
}
- void OnShutdown() anope_override
+ void OnShutdown() override
{
const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown");
if (!gl.empty())
this->SendGlobal(Global, "", gl);
}
- void OnNewServer(Server *s) anope_override
+ void OnNewServer(Server *s) override
{
const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycleup");
if (!gl.empty() && !Me->IsSynced())
s->Notice(Global, gl);
}
- EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *Global)
return EVENT_CONTINUE;
diff --git a/modules/commands/greet.cpp b/modules/greet.cpp
index 7e1b5ce75..1260b3a28 100644
--- a/modules/commands/greet.cpp
+++ b/modules/greet.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandBSSetGreet : public Command
+class CommandBSSetGreet final
+ : public Command
{
- public:
+public:
CommandBSSetGreet(Module *creator, const Anope::string &sname = "botserv/set/greet") : Command(creator, sname, 2, 2)
{
this->SetDesc(_("Enable greet messages"));
this->SetSyntax(_("\037channel\037 {\037ON|OFF\037}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
ChannelInfo *ci = ChannelInfo::Find(params[0]);
const Anope::string &value = params[1];
@@ -63,7 +64,7 @@ class CommandBSSetGreet : public Command
this->OnSyntaxError(source, source.command);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(_(" \n"
@@ -75,9 +76,10 @@ class CommandBSSetGreet : public Command
}
};
-class CommandNSSetGreet : public Command
+class CommandNSSetGreet
+ : public Command
{
- public:
+public:
CommandNSSetGreet(Module *creator, const Anope::string &sname = "nickserv/set/greet", size_t min = 0) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Associate a greet message with your nickname"));
@@ -119,12 +121,12 @@ class CommandNSSetGreet : public Command
}
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params.size() > 0 ? params[0] : "");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -136,21 +138,22 @@ class CommandNSSetGreet : public Command
}
};
-class CommandNSSASetGreet : public CommandNSSetGreet
+class CommandNSSASetGreet final
+ : public CommandNSSetGreet
{
- public:
+public:
CommandNSSASetGreet(Module *creator) : CommandNSSetGreet(creator, "nickserv/saset/greet", 1)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 \037message\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params.size() > 1 ? params[1] : "");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -162,7 +165,8 @@ class CommandNSSASetGreet : public CommandNSSetGreet
}
};
-class Greet : public Module
+class Greet final
+ : public Module
{
/* channel setting for whether or not greet should be shown */
SerializableExtensibleItem<bool> bs_greet;
@@ -173,7 +177,7 @@ class Greet : public Module
CommandNSSetGreet commandnssetgreet;
CommandNSSASetGreet commandnssasetgreet;
- public:
+public:
Greet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
bs_greet(this, "BS_GREET"),
ns_greet(this, "greet"),
@@ -182,7 +186,7 @@ class Greet : public Module
{
}
- void OnJoinChannel(User *user, Channel *c) anope_override
+ void OnJoinChannel(User *user, Channel *c) override
{
/* Only display the greet if the main uplink we're connected
* to has synced, or we'll get greet-floods when the net
@@ -199,14 +203,14 @@ class Greet : public Module
}
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override
{
Anope::string *greet = ns_greet.Get(na->nc);
if (greet != NULL)
info[_("Greet")] = *greet;
}
- void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) anope_override
+ void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) override
{
if (bs_greet.HasExt(ci))
info.AddOption(_("Greet"));
diff --git a/modules/commands/help.cpp b/modules/help.cpp
index 31ee91e69..8b8542fdf 100644
--- a/modules/commands/help.cpp
+++ b/modules/help.cpp
@@ -11,15 +11,15 @@
#include "module.h"
-class CommandHelp : public Command
+class CommandHelp final
+ : public Command
{
static const unsigned help_wrap_len = 40;
static CommandGroup *FindGroup(const Anope::string &name)
{
- for (unsigned i = 0; i < Config->CommandGroups.size(); ++i)
+ for (auto &gr : Config->CommandGroups)
{
- CommandGroup &gr = Config->CommandGroups[i];
if (gr.name == name)
return &gr;
}
@@ -27,14 +27,14 @@ class CommandHelp : public Command
return NULL;
}
- public:
+public:
CommandHelp(Module *creator) : Command(creator, "generic/help", 0)
{
this->SetDesc(_("Displays this list and give information about commands"));
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
EventReturn MOD_RESULT;
FOREACH_RESULT(OnPreHelp, MOD_RESULT, (source, params));
@@ -56,18 +56,15 @@ class CommandHelp : public Command
if (all)
source.Reply(_("All available commands for \002%s\002:"), source.service->nick.c_str());
- for (CommandInfo::map::const_iterator it = map.begin(), it_end = map.end(); it != it_end; ++it)
+ for (const auto &[c_name, info] : map)
{
- const Anope::string &c_name = it->first;
- const CommandInfo &info = it->second;
-
if (info.hide)
continue;
// Smaller command exists
Anope::string cmd;
spacesepstream(c_name).GetToken(cmd, 0);
- if (cmd != it->first && map.count(cmd))
+ if (cmd != c_name && map.count(cmd))
continue;
ServiceReference<Command> c("Command", info.name);
@@ -95,18 +92,14 @@ class CommandHelp : public Command
}
- for (GroupInfo::iterator it = groups.begin(), it_end = groups.end(); it != it_end; ++it)
+ for (auto &[gr, cmds] : groups)
{
- CommandGroup *gr = it->first;
-
source.Reply(" ");
source.Reply("%s", gr->description.c_str());
Anope::string buf;
- for (std::list<Anope::string>::iterator it2 = it->second.begin(), it2_end = it->second.end(); it2 != it2_end; ++it2)
+ for (const auto &c_name : cmds)
{
- const Anope::string &c_name = *it2;
-
buf += ", " + c_name;
if (buf.length() > help_wrap_len)
@@ -180,7 +173,7 @@ class CommandHelp : public Command
break;
}
- if (helped == false)
+ if (!helped)
source.Reply(_("No help available for \002%s\002."), params[0].c_str());
}
@@ -190,11 +183,12 @@ class CommandHelp : public Command
}
};
-class Help : public Module
+class Help final
+ : public Module
{
CommandHelp commandhelp;
- public:
+public:
Help(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandhelp(this)
{
diff --git a/modules/m_helpchan.cpp b/modules/helpchan.cpp
index 7f050915a..061388dfe 100644
--- a/modules/m_helpchan.cpp
+++ b/modules/helpchan.cpp
@@ -8,14 +8,15 @@
#include "module.h"
-class HelpChannel : public Module
+class HelpChannel final
+ : public Module
{
- public:
+public:
HelpChannel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
{
}
- EventReturn OnChannelModeSet(Channel *c, MessageSource &, ChannelMode *mode, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &, ChannelMode *mode, const Anope::string &param) override
{
if (mode->name == "OP" && c && c->ci && c->name.equals_ci(Config->GetModule(this)->Get<const Anope::string>("helpchannel")))
{
diff --git a/modules/pseudoclients/hostserv.cpp b/modules/hostserv/hostserv.cpp
index 3d3ddef7b..bdd1920e1 100644
--- a/modules/pseudoclients/hostserv.cpp
+++ b/modules/hostserv/hostserv.cpp
@@ -11,17 +11,18 @@
#include "module.h"
-class HostServCore : public Module
+class HostServCore final
+ : public Module
{
Reference<BotInfo> HostServ;
- public:
+public:
HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
const Anope::string &hsnick = conf->GetModule(this)->Get<const Anope::string>("client");
@@ -35,7 +36,7 @@ class HostServCore : public Module
HostServ = bi;
}
- void OnUserLogin(User *u) anope_override
+ void OnUserLogin(User *u) override
{
if (!IRCD->CanSetVHost)
return;
@@ -58,15 +59,13 @@ class HostServCore : public Module
if (HostServ)
{
- if (!na->GetVhostIdent().empty())
- u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
- else
- u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
+ u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."),
+ na->GetVhostMask().c_str());
}
}
}
- void OnNickDrop(CommandSource &source, NickAlias *na) anope_override
+ void OnNickDrop(CommandSource &source, NickAlias *na) override
{
if (na->HasVhost())
{
@@ -75,12 +74,12 @@ class HostServCore : public Module
}
}
- void OnNickUpdate(User *u) anope_override
+ void OnNickUpdate(User *u) override
{
this->OnUserLogin(u);
}
- EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *HostServ)
return EVENT_CONTINUE;
@@ -88,7 +87,7 @@ class HostServCore : public Module
return EVENT_CONTINUE;
}
- void OnSetVhost(NickAlias *na) anope_override
+ void OnSetVhost(NickAlias *na) override
{
if (Config->GetModule(this)->Get<bool>("activate_on_set"))
{
@@ -106,16 +105,14 @@ class HostServCore : public Module
if (HostServ)
{
- if (!na->GetVhostIdent().empty())
- u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
- else
- u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
+ u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."),
+ na->GetVhostMask().c_str());
}
}
}
}
- void OnDeleteVhost(NickAlias *na) anope_override
+ void OnDeleteVhost(NickAlias *na) override
{
if (Config->GetModule(this)->Get<bool>("activate_on_set"))
{
diff --git a/modules/commands/hs_del.cpp b/modules/hostserv/hs_del.cpp
index 09e7ac12f..eb60afc00 100644
--- a/modules/commands/hs_del.cpp
+++ b/modules/hostserv/hs_del.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandHSDel : public Command
+class CommandHSDel final
+ : public Command
{
- public:
+public:
CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 1)
{
this->SetDesc(_("Delete the vhost of another user"));
this->SetSyntax(_("\037nick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -41,7 +42,7 @@ class CommandHSDel : public Command
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -51,16 +52,17 @@ class CommandHSDel : public Command
}
};
-class CommandHSDelAll : public Command
+class CommandHSDelAll final
+ : public Command
{
- public:
+public:
CommandHSDelAll(Module *creator) : Command(creator, "hostserv/delall", 1, 1)
{
this->SetDesc(_("Deletes the vhost for all nicks in a group"));
this->SetSyntax(_("\037nick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -74,9 +76,9 @@ class CommandHSDelAll : public Command
{
FOREACH_MOD(OnDeleteVhost, (na));
const NickCore *nc = na->nc;
- for (unsigned i = 0; i < nc->aliases->size(); ++i)
+ for (auto *alias : *nc->aliases)
{
- na = nc->aliases->at(i);
+ na = alias;
na->RemoveVhost();
}
Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->display;
@@ -86,7 +88,7 @@ class CommandHSDelAll : public Command
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -96,12 +98,13 @@ class CommandHSDelAll : public Command
}
};
-class HSDel : public Module
+class HSDel final
+ : public Module
{
CommandHSDel commandhsdel;
CommandHSDelAll commandhsdelall;
- public:
+public:
HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandhsdel(this), commandhsdelall(this)
{
diff --git a/modules/commands/hs_group.cpp b/modules/hostserv/hs_group.cpp
index f08c56685..2877fa16d 100644
--- a/modules/commands/hs_group.cpp
+++ b/modules/hostserv/hs_group.cpp
@@ -11,11 +11,12 @@
#include "module.h"
-class CommandHSGroup : public Command
+class CommandHSGroup final
+ : public Command
{
- bool setting;
+ bool setting = false;
- public:
+public:
void Sync(const NickAlias *na)
{
if (setting)
@@ -25,9 +26,8 @@ class CommandHSGroup : public Command
return;
setting = true;
- for (unsigned i = 0; i < na->nc->aliases->size(); ++i)
+ for (auto *nick : *na->nc->aliases)
{
- NickAlias *nick = na->nc->aliases->at(i);
if (nick)
{
nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
@@ -37,12 +37,12 @@ class CommandHSGroup : public Command
setting = false;
}
- CommandHSGroup(Module *creator) : Command(creator, "hostserv/group", 0, 0), setting(false)
+ CommandHSGroup(Module *creator) : Command(creator, "hostserv/group", 0, 0)
{
this->SetDesc(_("Syncs the vhost for all nicks in a group"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -54,10 +54,8 @@ class CommandHSGroup : public Command
if (na && source.GetAccount() == na->nc && na->HasVhost())
{
this->Sync(na);
- if (!na->GetVhostIdent().empty())
- source.Reply(_("All vhosts in the group \002%s\002 have been set to \002%s\002@\002%s\002."), source.nc->display.c_str(), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
- else
- source.Reply(_("All vhosts in the group \002%s\002 have been set to \002%s\002."), source.nc->display.c_str(), na->GetVhostHost().c_str());
+ source.Reply(_("All vhosts in the group \002%s\002 have been set to \002%s\002."),
+ source.nc->display.c_str(), na->GetVhostMask().c_str());
}
else
source.Reply(HOST_NOT_ASSIGNED);
@@ -65,7 +63,7 @@ class CommandHSGroup : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -76,13 +74,14 @@ class CommandHSGroup : public Command
}
};
-class HSGroup : public Module
+class HSGroup final
+ : public Module
{
CommandHSGroup commandhsgroup;
bool syncongroup;
bool synconset;
- public:
+public:
HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandhsgroup(this)
{
@@ -90,7 +89,7 @@ class HSGroup : public Module
throw ModuleException("Your IRCd does not support vhosts");
}
- void OnSetVhost(NickAlias *na) anope_override
+ void OnSetVhost(NickAlias *na) override
{
if (!synconset)
return;
@@ -98,7 +97,7 @@ class HSGroup : public Module
commandhsgroup.Sync(na);
}
- void OnNickGroup(User *u, NickAlias *na) anope_override
+ void OnNickGroup(User *u, NickAlias *na) override
{
if (!syncongroup)
return;
@@ -106,7 +105,7 @@ class HSGroup : public Module
commandhsgroup.Sync(na);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
syncongroup = block->Get<bool>("syncongroup");
diff --git a/modules/commands/hs_list.cpp b/modules/hostserv/hs_list.cpp
index 856fa1f31..dd459fd78 100644
--- a/modules/commands/hs_list.cpp
+++ b/modules/hostserv/hs_list.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandHSList : public Command
+class CommandHSList final
+ : public Command
{
- public:
+public:
CommandHSList(Module *creator) : Command(creator, "hostserv/list", 0, 1)
{
this->SetDesc(_("Displays one or more vhost entries"));
this->SetSyntax(_("[\037key\037|\037#X-Y\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &key = !params.empty() ? params[0] : "";
int from = 0, to = 0, counter = 1;
@@ -44,12 +45,9 @@ class CommandHSList : public Command
source.Reply(LIST_INCORRECT_RANGE);
return;
}
- try
- {
- from = convertTo<int>(key.substr(1, tmp - 1));
- to = convertTo<int>(key.substr(tmp + 1));
- }
- catch (const ConvertException &) { }
+
+ from = Anope::Convert<int>(key.substr(1, tmp - 1), 0);
+ to = Anope::Convert<int>(key.substr(tmp + 1), 0);
}
}
@@ -57,10 +55,8 @@ class CommandHSList : public Command
ListFormatter list(source.GetAccount());
list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created"));
- for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
+ for (const auto &[_, na] : *NickAliasList)
{
- const NickAlias *na = it->second;
-
if (!na->HasVhost())
continue;
@@ -71,12 +67,9 @@ class CommandHSList : public Command
++display_counter;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(display_counter);
+ entry["Number"] = Anope::ToString(display_counter);
entry["Nick"] = na->nick;
- if (!na->GetVhostIdent().empty())
- entry["Vhost"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
- else
- entry["Vhost"] = na->GetVhostHost();
+ entry["Vhost"] = na->GetVhostMask();
entry["Creator"] = na->GetVhostCreator();
entry["Created"] = Anope::strftime(na->GetVhostCreated(), NULL, true);
list.AddEntry(entry);
@@ -92,12 +85,9 @@ class CommandHSList : public Command
{
++display_counter;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(display_counter);
+ entry["Number"] = Anope::ToString(display_counter);
entry["Nick"] = na->nick;
- if (!na->GetVhostIdent().empty())
- entry["Vhost"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
- else
- entry["Vhost"] = na->GetVhostHost();
+ entry["Vhost"] = na->GetVhostMask();
entry["Creator"] = na->GetVhostCreator();
entry["Created"] = Anope::strftime(na->GetVhostCreated(), NULL, true);
list.AddEntry(entry);
@@ -125,11 +115,11 @@ class CommandHSList : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -144,11 +134,12 @@ class CommandHSList : public Command
}
};
-class HSList : public Module
+class HSList final
+ : public Module
{
CommandHSList commandhslist;
- public:
+public:
HSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandhslist(this)
{
diff --git a/modules/commands/hs_off.cpp b/modules/hostserv/hs_off.cpp
index 8128ee515..8e4036726 100644
--- a/modules/commands/hs_off.cpp
+++ b/modules/hostserv/hs_off.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandHSOff : public Command
+class CommandHSOff final
+ : public Command
{
- public:
+public:
CommandHSOff(Module *creator) : Command(creator, "hostserv/off", 0, 0)
{
this->SetDesc(_("Deactivates your assigned vhost"));
this->RequireUser(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
User *u = source.GetUser();
@@ -42,7 +43,7 @@ class CommandHSOff : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -53,11 +54,12 @@ class CommandHSOff : public Command
}
};
-class HSOff : public Module
+class HSOff final
+ : public Module
{
CommandHSOff commandhsoff;
- public:
+public:
HSOff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandhsoff(this)
{
diff --git a/modules/commands/hs_on.cpp b/modules/hostserv/hs_on.cpp
index b4dd7736c..e37b1278e 100644
--- a/modules/commands/hs_on.cpp
+++ b/modules/hostserv/hs_on.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandHSOn : public Command
+class CommandHSOn final
+ : public Command
{
- public:
+public:
CommandHSOn(Module *creator) : Command(creator, "hostserv/on", 0, 0)
{
this->SetDesc(_("Activates your assigned vhost"));
this->RequireUser(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!IRCD->CanSetVHost)
return; // HostServ wouldn't even be loaded at this point
@@ -31,11 +32,8 @@ class CommandHSOn : public Command
na = NickAlias::Find(u->Account()->display);
if (na && u->Account() == na->nc && na->HasVhost())
{
- if (!na->GetVhostIdent().empty())
- source.Reply(_("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
- else
- source.Reply(_("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
- Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!na->GetVhostIdent().empty() ? na->GetVhostIdent() + "@" : "") << na->GetVhostHost();
+ source.Reply(_("Your vhost of \002%s\002 is now activated."), na->GetVhostMask().c_str());
+ Log(LOG_COMMAND, source, this) << "to enable their vhost of " << na->GetVhostMask();
IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost());
u->vhost = na->GetVhostHost();
if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
@@ -48,7 +46,7 @@ class CommandHSOn : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -59,11 +57,12 @@ class CommandHSOn : public Command
}
};
-class HSOn : public Module
+class HSOn final
+ : public Module
{
CommandHSOn commandhson;
- public:
+public:
HSOn(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandhson(this)
{
diff --git a/modules/commands/hs_request.cpp b/modules/hostserv/hs_request.cpp
index 561ebf500..d7bc6bc34 100644
--- a/modules/commands/hs_request.cpp
+++ b/modules/hostserv/hs_request.cpp
@@ -15,21 +15,22 @@
*/
#include "module.h"
+#include "modules/hs_request.h"
static ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ");
static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost);
-struct HostRequest : Serializable
+struct HostRequestImpl final
+ : HostRequest
+ , Serializable
{
- Anope::string nick;
- Anope::string ident;
- Anope::string host;
- time_t time;
-
- HostRequest(Extensible *) : Serializable("HostRequest") { }
+ HostRequestImpl(Extensible *)
+ : Serializable("HostRequest")
+ {
+ }
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["nick"] << this->nick;
data["ident"] << this->ident;
@@ -37,7 +38,7 @@ struct HostRequest : Serializable
data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string snick;
data["nick"] >> snick;
@@ -46,11 +47,11 @@ struct HostRequest : Serializable
if (na == NULL)
return NULL;
- HostRequest *req;
+ HostRequestImpl *req;
if (obj)
- req = anope_dynamic_static_cast<HostRequest *>(obj);
+ req = anope_dynamic_static_cast<HostRequestImpl *>(obj);
else
- req = na->Extend<HostRequest>("hostrequest");
+ req = na->Extend<HostRequestImpl>("hostrequest");
if (req)
{
req->nick = na->nick;
@@ -63,23 +64,22 @@ struct HostRequest : Serializable
}
};
-class CommandHSRequest : public Command
+class CommandHSRequest final
+ : public Command
{
- bool isvalidchar(char c)
+ static bool isvalidchar(char c)
{
- if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
- return true;
- return false;
+ return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-';
}
- public:
+public:
CommandHSRequest(Module *creator) : Command(creator, "hostserv/request", 1, 1)
{
this->SetDesc(_("Request a vHost for your nick"));
this->SetSyntax(_("vhost"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -122,9 +122,9 @@ class CommandHSRequest : public Command
if (!user.empty())
{
- if (user.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
+ if (user.length() > IRCD->GetMaxUser())
{
- source.Reply(HOST_SET_IDENTTOOLONG, Config->GetBlock("networkinfo")->Get<unsigned>("userlen"));
+ source.Reply(HOST_SET_IDENTTOOLONG, IRCD->GetMaxUser());
return;
}
else if (!IRCD->CanSetVIdent)
@@ -132,17 +132,19 @@ class CommandHSRequest : public Command
source.Reply(HOST_NO_VIDENT);
return;
}
- for (Anope::string::iterator s = user.begin(), s_end = user.end(); s != s_end; ++s)
- if (!isvalidchar(*s))
+ for (const auto &chr : user)
+ {
+ if (!isvalidchar(chr))
{
source.Reply(HOST_SET_IDENT_ERROR);
return;
}
+ }
}
- if (host.length() > Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"))
+ if (host.length() > IRCD->GetMaxHost())
{
- source.Reply(HOST_SET_TOOLONG, Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"));
+ source.Reply(HOST_SET_TOOLONG, IRCD->GetMaxHost());
return;
}
@@ -155,24 +157,24 @@ class CommandHSRequest : public Command
time_t send_delay = Config->GetModule("memoserv")->Get<time_t>("senddelay");
if (Config->GetModule(this->owner)->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime)
{
- source.Reply(_("Please wait %d seconds before requesting a new vHost."), send_delay);
+ source.Reply(_("Please wait %lu seconds before requesting a new vHost."), (unsigned long)send_delay);
u->lastmemosend = Anope::CurTime;
return;
}
- HostRequest req(na);
+ HostRequestImpl req(na);
req.nick = source.GetNick();
req.ident = user;
req.host = host;
req.time = Anope::CurTime;
- na->Extend<HostRequest>("hostrequest", req);
+ na->Extend<HostRequestImpl>("hostrequest", req);
source.Reply(_("Your vHost has been requested."));
req_send_memos(owner, source, user, host);
Log(LOG_COMMAND, source, this) << "to request new vhost " << (!user.empty() ? user + "@" : "") << host;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -183,16 +185,17 @@ class CommandHSRequest : public Command
}
};
-class CommandHSActivate : public Command
+class CommandHSActivate final
+ : public Command
{
- public:
+public:
CommandHSActivate(Module *creator) : Command(creator, "hostserv/activate", 1, 1)
{
this->SetDesc(_("Approve the requested vHost of a user"));
this->SetSyntax(_("\037nick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -203,7 +206,7 @@ class CommandHSActivate : public Command
const Anope::string &nick = params[0];
NickAlias *na = NickAlias::Find(nick);
- HostRequest *req = na ? na->GetExt<HostRequest>("hostrequest") : NULL;
+ HostRequestImpl *req = na ? na->GetExt<HostRequestImpl>("hostrequest") : NULL;
if (req)
{
na->SetVhost(req->ident, req->host, source.GetNick(), req->time);
@@ -214,13 +217,13 @@ class CommandHSActivate : public Command
source.Reply(_("vHost for %s has been activated."), na->nick.c_str());
Log(LOG_COMMAND, source, this) << "for " << na->nick << " for vhost " << (!req->ident.empty() ? req->ident + "@" : "") << req->host;
- na->Shrink<HostRequest>("hostrequest");
+ na->Shrink<HostRequestImpl>("hostrequest");
}
else
source.Reply(_("No request for nick %s found."), nick.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -232,16 +235,17 @@ class CommandHSActivate : public Command
}
};
-class CommandHSReject : public Command
+class CommandHSReject final
+ : public Command
{
- public:
+public:
CommandHSReject(Module *creator) : Command(creator, "hostserv/reject", 1, 2)
{
this->SetDesc(_("Reject the requested vHost of a user"));
this->SetSyntax(_("\037nick\037 [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -253,10 +257,10 @@ class CommandHSReject : public Command
const Anope::string &reason = params.size() > 1 ? params[1] : "";
NickAlias *na = NickAlias::Find(nick);
- HostRequest *req = na ? na->GetExt<HostRequest>("hostrequest") : NULL;
+ HostRequestImpl *req = na ? na->GetExt<HostRequestImpl>("hostrequest") : NULL;
if (req)
{
- na->Shrink<HostRequest>("hostrequest");
+ na->Shrink<HostRequestImpl>("hostrequest");
if (Config->GetModule(this->owner)->Get<bool>("memouser") && memoserv)
{
@@ -276,7 +280,7 @@ class CommandHSReject : public Command
source.Reply(_("No request for nick %s found."), nick.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -288,15 +292,16 @@ class CommandHSReject : public Command
}
};
-class CommandHSWaiting : public Command
+class CommandHSWaiting final
+ : public Command
{
- public:
+public:
CommandHSWaiting(Module *creator) : Command(creator, "hostserv/waiting", 0, 0)
{
this->SetDesc(_("Retrieves the vhost requests"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
unsigned counter = 0;
unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax");
@@ -304,10 +309,9 @@ class CommandHSWaiting : public Command
list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Created"));
- for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
+ for (const auto &[nick, na] : *NickAliasList)
{
- const NickAlias *na = it->second;
- HostRequest *hr = na->GetExt<HostRequest>("hostrequest");
+ HostRequestImpl *hr = na->GetExt<HostRequestImpl>("hostrequest");
if (!hr)
continue;
@@ -316,8 +320,8 @@ class CommandHSWaiting : public Command
++display_counter;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(display_counter);
- entry["Nick"] = it->first;
+ entry["Number"] = Anope::ToString(display_counter);
+ entry["Nick"] = nick;
if (!hr->ident.empty())
entry["Vhost"] = hr->ident + "@" + hr->host;
else
@@ -331,13 +335,13 @@ class CommandHSWaiting : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("Displayed \002%d\002 records (\002%d\002 total)."), display_counter, counter);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -347,19 +351,20 @@ class CommandHSWaiting : public Command
}
};
-class HSRequest : public Module
+class HSRequest final
+ : public Module
{
CommandHSRequest commandhsrequest;
CommandHSActivate commandhsactive;
CommandHSReject commandhsreject;
CommandHSWaiting commandhswaiting;
- ExtensibleItem<HostRequest> hostrequest;
+ ExtensibleItem<HostRequestImpl> hostrequest;
Serialize::Type request_type;
- public:
+public:
HSRequest(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandhsrequest(this), commandhsactive(this),
- commandhsreject(this), commandhswaiting(this), hostrequest(this, "hostrequest"), request_type("HostRequest", HostRequest::Unserialize)
+ commandhsreject(this), commandhswaiting(this), hostrequest(this, "hostrequest"), request_type("HostRequest", HostRequestImpl::Unserialize)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
@@ -369,18 +374,15 @@ class HSRequest : public Module
static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost)
{
Anope::string host;
- std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end;
-
if (!vIdent.empty())
host = vIdent + "@" + vHost;
else
host = vHost;
if (Config->GetModule(me)->Get<bool>("memooper") && memoserv)
- for (unsigned i = 0; i < Oper::opers.size(); ++i)
+ {
+ for (auto *o : Oper::opers)
{
- Oper *o = Oper::opers[i];
-
const NickAlias *na = NickAlias::Find(o->name);
if (!na)
continue;
@@ -389,6 +391,7 @@ static void req_send_memos(Module *me, CommandSource &source, const Anope::strin
memoserv->Send(source.service->nick, na->nick, message, true);
}
+ }
}
MODULE_INIT(HSRequest)
diff --git a/modules/commands/hs_set.cpp b/modules/hostserv/hs_set.cpp
index 1a34266d7..261e1e51f 100644
--- a/modules/commands/hs_set.cpp
+++ b/modules/hostserv/hs_set.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandHSSet : public Command
+class CommandHSSet final
+ : public Command
{
- public:
+public:
CommandHSSet(Module *creator) : Command(creator, "hostserv/set", 2, 2)
{
this->SetDesc(_("Set the vhost of another user"));
this->SetSyntax(_("\037nick\037 \037hostmask\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -70,9 +71,9 @@ class CommandHSSet : public Command
}
}
- if (host.length() > Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"))
+ if (host.length() > IRCD->GetMaxHost())
{
- source.Reply(HOST_SET_TOOLONG, Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"));
+ source.Reply(HOST_SET_TOOLONG, IRCD->GetMaxHost());
return;
}
@@ -86,13 +87,10 @@ class CommandHSSet : public Command
na->SetVhost(user, host, source.GetNick());
FOREACH_MOD(OnSetVhost, (na));
- if (!user.empty())
- source.Reply(_("VHost for \002%s\002 set to \002%s\002@\002%s\002."), nick.c_str(), user.c_str(), host.c_str());
- else
- source.Reply(_("VHost for \002%s\002 set to \002%s\002."), nick.c_str(), host.c_str());
+ source.Reply(_("VHost for \002%s\002 set to \002%s\002."), nick.c_str(), na->GetVhostMask().c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -104,29 +102,29 @@ class CommandHSSet : public Command
}
};
-class CommandHSSetAll : public Command
+class CommandHSSetAll final
+ : public Command
{
- void Sync(const NickAlias *na)
+ static void Sync(const NickAlias *na)
{
if (!na || !na->HasVhost())
return;
- for (unsigned i = 0; i < na->nc->aliases->size(); ++i)
+ for (auto *nick : *na->nc->aliases)
{
- NickAlias *nick = na->nc->aliases->at(i);
if (nick)
nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
}
}
- public:
+public:
CommandHSSetAll(Module *creator) : Command(creator, "hostserv/setall", 2, 2)
{
this->SetDesc(_("Set the vhost for all nicks in a group"));
this->SetSyntax(_("\037nick\037 \037hostmask\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -176,9 +174,9 @@ class CommandHSSetAll : public Command
}
}
- if (host.length() > Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"))
+ if (host.length() > IRCD->GetMaxHost())
{
- source.Reply(HOST_SET_TOOLONG, Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"));
+ source.Reply(HOST_SET_TOOLONG, IRCD->GetMaxHost());
return;
}
@@ -193,13 +191,10 @@ class CommandHSSetAll : public Command
na->SetVhost(user, host, source.GetNick());
this->Sync(na);
FOREACH_MOD(OnSetVhost, (na));
- if (!user.empty())
- source.Reply(_("VHost for group \002%s\002 set to \002%s\002@\002%s\002."), nick.c_str(), user.c_str(), host.c_str());
- else
- source.Reply(_("VHost for group \002%s\002 set to \002%s\002."), nick.c_str(), host.c_str());
+ source.Reply(_("VHost for group \002%s\002 set to \002%s\002."), nick.c_str(), na->GetVhostMask().c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -213,12 +208,13 @@ class CommandHSSetAll : public Command
}
};
-class HSSet : public Module
+class HSSet final
+ : public Module
{
CommandHSSet commandhsset;
CommandHSSetAll commandhssetall;
- public:
+public:
HSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandhsset(this), commandhssetall(this)
{
if (!IRCD || !IRCD->CanSetVHost)
diff --git a/modules/m_httpd.cpp b/modules/httpd.cpp
index adb17c121..f784d2d32 100644
--- a/modules/m_httpd.cpp
+++ b/modules/httpd.cpp
@@ -37,23 +37,24 @@ static Anope::string GetStatusFromCode(HTTPError err)
return "501 Not Implemented";
}
-class MyHTTPClient : public HTTPClient
+class MyHTTPClient final
+ : public HTTPClient
{
HTTPProvider *provider;
HTTPMessage message;
- bool header_done, served;
+ bool header_done = false, served = false;
Anope::string page_name;
Reference<HTTPPage> page;
Anope::string ip;
- unsigned content_length;
+ unsigned content_length = 0;
enum
{
ACTION_NONE,
ACTION_GET,
ACTION_POST
- } action;
+ } action = ACTION_NONE;
void Serve()
{
@@ -69,20 +70,18 @@ class MyHTTPClient : public HTTPClient
if (std::find(this->provider->ext_ips.begin(), this->provider->ext_ips.end(), this->ip) != this->provider->ext_ips.end())
{
- for (unsigned i = 0; i < this->provider->ext_headers.size(); ++i)
+ for (auto &token : this->provider->ext_headers)
{
- const Anope::string &token = this->provider->ext_headers[i];
-
if (this->message.headers.count(token))
{
this->ip = this->message.headers[token];
- Log(LOG_DEBUG, "httpd") << "m_httpd: IP for connection " << this->GetFD() << " changed to " << this->ip;
+ Log(LOG_DEBUG, "httpd") << "httpd: IP for connection " << this->GetFD() << " changed to " << this->ip;
break;
}
}
}
- Log(LOG_DEBUG, "httpd") << "m_httpd: Serving page " << this->page_name << " to " << this->ip;
+ Log(LOG_DEBUG, "httpd") << "httpd: Serving page " << this->page_name << " to " << this->ip;
HTTPReply reply;
reply.content_type = this->page->GetContentType();
@@ -91,31 +90,31 @@ class MyHTTPClient : public HTTPClient
this->SendReply(&reply);
}
- public:
+public:
time_t created;
- MyHTTPClient(HTTPProvider *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), HTTPClient(l, f, a), provider(l), header_done(false), served(false), ip(a.addr()), content_length(0), action(ACTION_NONE), created(Anope::CurTime)
+ MyHTTPClient(HTTPProvider *l, int f, const sockaddrs &a) : Socket(f, l->GetFamily()), HTTPClient(l, f, a), provider(l), ip(a.addr()), created(Anope::CurTime)
{
Log(LOG_DEBUG, "httpd") << "Accepted connection " << f << " from " << a.addr();
}
- ~MyHTTPClient()
+ ~MyHTTPClient() override
{
Log(LOG_DEBUG, "httpd") << "Closing connection " << this->GetFD() << " from " << this->ip;
}
/* Close connection once all data is written */
- bool ProcessWrite() anope_override
+ bool ProcessWrite() override
{
- return !BinarySocket::ProcessWrite() || this->write_buffer.empty() ? false : true;
+ return !(!BinarySocket::ProcessWrite() || this->write_buffer.empty());
}
- const Anope::string GetIP() anope_override
+ const Anope::string GetIP() override
{
return this->ip;
}
- bool Read(const char *buffer, size_t l) anope_override
+ bool Read(const char *buffer, size_t l) override
{
message.content.append(buffer, l);
@@ -217,11 +216,8 @@ class MyHTTPClient : public HTTPClient
}
else if (buf.find_ci("Content-Length: ") == 0)
{
- try
- {
- this->content_length = convertTo<unsigned>(buf.substr(16));
- }
- catch (const ConvertException &ex) { }
+ if (auto len = Anope::TryConvert<unsigned>(buf.substr(16)))
+ this->content_length = len.value();
}
else if (buf.find(':') != Anope::string::npos)
{
@@ -233,7 +229,7 @@ class MyHTTPClient : public HTTPClient
return true;
}
- void SendError(HTTPError err, const Anope::string &msg) anope_override
+ void SendError(HTTPError err, const Anope::string &msg) override
{
HTTPReply h;
@@ -244,7 +240,7 @@ class MyHTTPClient : public HTTPClient
this->SendReply(&h);
}
- void SendReply(HTTPReply *msg) anope_override
+ void SendReply(HTTPReply *msg) override
{
this->WriteClient("HTTP/1.1 " + GetStatusFromCode(msg->error));
this->WriteClient("Date: " + BuildDate());
@@ -253,32 +249,29 @@ class MyHTTPClient : public HTTPClient
this->WriteClient("Content-Type: text/html");
else
this->WriteClient("Content-Type: " + msg->content_type);
- this->WriteClient("Content-Length: " + stringify(msg->length));
+ this->WriteClient("Content-Length: " + Anope::ToString(msg->length));
- for (unsigned i = 0; i < msg->cookies.size(); ++i)
+ for (const auto &cookie : msg->cookies)
{
Anope::string buf = "Set-Cookie:";
- for (HTTPReply::cookie::iterator it = msg->cookies[i].begin(), it_end = msg->cookies[i].end(); it != it_end; ++it)
- buf += " " + it->first + "=" + it->second + ";";
+ for (const auto &[name, value] : cookie)
+ buf += " " + name + "=" + value + ";";
buf.erase(buf.length() - 1);
this->WriteClient(buf);
}
- typedef std::map<Anope::string, Anope::string> map;
- for (map::iterator it = msg->headers.begin(), it_end = msg->headers.end(); it != it_end; ++it)
- this->WriteClient(it->first + ": " + it->second);
+ for (auto &[name, value] : msg->headers)
+ this->WriteClient(name + ": " + value);
this->WriteClient("Connection: Close");
this->WriteClient("");
- for (unsigned i = 0; i < msg->out.size(); ++i)
+ for (auto *d : msg->out)
{
- HTTPReply::Data* d = msg->out[i];
-
- this->Write(d->buf, d->len);
+ this->Write(d->buf, d->len);
delete d;
}
@@ -287,16 +280,24 @@ class MyHTTPClient : public HTTPClient
}
};
-class MyHTTPProvider : public HTTPProvider, public Timer
+class MyHTTPProvider final
+ : public HTTPProvider
+ , public Timer
{
int timeout;
std::map<Anope::string, HTTPPage *> pages;
std::list<Reference<MyHTTPClient> > clients;
- public:
- MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s) : Socket(-1, i.find(':') != Anope::string::npos), HTTPProvider(c, n, i, p, s), Timer(c, 10, Anope::CurTime, true), timeout(t) { }
+public:
+ MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s)
+ : Socket(-1, i.find(':') == Anope::string::npos ? AF_INET : AF_INET6)
+ , HTTPProvider(c, n, i, p, s)
+ , Timer(c, 10, true)
+ , timeout(t)
+ {
+ }
- void Tick(time_t) anope_override
+ void Tick() override
{
while (!this->clients.empty())
{
@@ -309,24 +310,24 @@ class MyHTTPProvider : public HTTPProvider, public Timer
}
}
- ClientSocket* OnAccept(int fd, const sockaddrs &addr) anope_override
+ ClientSocket *OnAccept(int fd, const sockaddrs &addr) override
{
- MyHTTPClient *c = new MyHTTPClient(this, fd, addr);
- this->clients.push_back(c);
+ auto *c = new MyHTTPClient(this, fd, addr);
+ this->clients.emplace_back(c);
return c;
}
- bool RegisterPage(HTTPPage *page) anope_override
+ bool RegisterPage(HTTPPage *page) override
{
- return this->pages.insert(std::make_pair(page->GetURL(), page)).second;
+ return this->pages.emplace(page->GetURL(), page).second;
}
- void UnregisterPage(HTTPPage *page) anope_override
+ void UnregisterPage(HTTPPage *page) override
{
this->pages.erase(page->GetURL());
}
- HTTPPage* FindPage(const Anope::string &pname) anope_override
+ HTTPPage *FindPage(const Anope::string &pname) override
{
if (this->pages.count(pname) == 0)
return NULL;
@@ -334,17 +335,18 @@ class MyHTTPProvider : public HTTPProvider, public Timer
}
};
-class HTTPD : public Module
+class HTTPD final
+ : public Module
{
ServiceReference<SSLService> sslref;
std::map<Anope::string, MyHTTPProvider *> providers;
- public:
+public:
HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), sslref("SSLService", "ssl")
{
}
- ~HTTPD()
+ ~HTTPD() override
{
for (std::map<int, Socket *>::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;)
{
@@ -358,7 +360,7 @@ class HTTPD : public Module
this->providers.clear();
}
- void OnReload(Configuration::Conf *config) anope_override
+ void OnReload(Configuration::Conf *config) override
{
Configuration::Block *conf = config->GetModule(this);
std::set<Anope::string> existing;
@@ -453,12 +455,10 @@ class HTTPD : public Module
}
}
- void OnModuleLoad(User *u, Module *m) anope_override
+ void OnModuleLoad(User *u, Module *m) override
{
- for (std::map<Anope::string, MyHTTPProvider *>::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end; ++it)
+ for (auto &[_, p] : this->providers)
{
- MyHTTPProvider *p = it->second;
-
if (p->IsSSL() && sslref)
try
{
diff --git a/modules/extra/stats/irc2sql/CMakeLists.txt b/modules/irc2sql/CMakeLists.txt
index 781f0ef1f..781f0ef1f 100644
--- a/modules/extra/stats/irc2sql/CMakeLists.txt
+++ b/modules/irc2sql/CMakeLists.txt
diff --git a/modules/extra/stats/irc2sql/irc2sql.cpp b/modules/irc2sql/irc2sql.cpp
index 8377c5d2e..fdd80cdf9 100644
--- a/modules/extra/stats/irc2sql/irc2sql.cpp
+++ b/modules/irc2sql/irc2sql.cpp
@@ -11,7 +11,7 @@
void IRC2SQL::OnShutdown()
{
// TODO: test if we really have to use blocking query here
- // (sometimes m_mysql get unloaded before the other thread executed all queries)
+ // (sometimes mysql get unloaded before the other thread executed all queries)
if (this->sql)
SQL::Result r = this->sql->RunQuery(SQL::Query("CALL " + prefix + "OnShutdown()"));
quitting = true;
@@ -47,19 +47,18 @@ void IRC2SQL::OnReload(Configuration::Conf *conf)
this->OnNewServer(it->second);
}
- for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
+ for (const auto &[_, c] : ChannelList)
{
- this->OnChannelCreate(it->second);
+ this->OnChannelCreate(c);
}
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, u] : UserListByNick)
{
- User *u = it->second;
bool exempt = false;
this->OnUserConnect(u, exempt);
- for (User::ChanUserList::const_iterator cit = u->chans.begin(), cit_end = u->chans.end(); cit != cit_end; ++cit)
+ for (const auto &[_, uc] : u->chans)
{
- this->OnJoinChannel(u, cit->second->chan);
+ this->OnJoinChannel(u, uc->chan);
}
}
}
@@ -107,7 +106,7 @@ void IRC2SQL::OnUserConnect(User *u, bool &exempt)
query.SetValue("ip", u->ip.addr());
query.SetValue("ident", u->GetIdent());
query.SetValue("vident", u->GetVIdent());
- query.SetValue("secure", u->HasMode("SSL") || u->HasExt("ssl") ? "Y" : "N");
+ query.SetValue("secure", u->IsSecurelyConnected() ? "Y" : "N");
query.SetValue("account", u->Account() ? u->Account()->display : "");
query.SetValue("fingerprint", u->fingerprint);
query.SetValue("signon", u->signon);
@@ -152,7 +151,7 @@ void IRC2SQL::OnUserAway(User *u, const Anope::string &message)
void IRC2SQL::OnFingerprint(User *u)
{
query = "UPDATE `" + prefix + "user` SET secure=@secure@, fingerprint=@fingerprint@ WHERE nick=@nick@";
- query.SetValue("secure", u->HasMode("SSL") || u->HasExt("ssl") ? "Y" : "N");
+ query.SetValue("secure", u->IsSecurelyConnected() ? "Y" : "N");
query.SetValue("fingerprint", u->fingerprint);
query.SetValue("nick", u->nick);
this->RunQuery(query);
@@ -298,7 +297,7 @@ void IRC2SQL::OnTopicUpdated(User *source, Channel *c, const Anope::string &user
this->RunQuery(query);
}
-void IRC2SQL::OnBotNotice(User *u, BotInfo *bi, Anope::string &message)
+void IRC2SQL::OnBotNotice(User *u, BotInfo *bi, Anope::string &message, const Anope::map<Anope::string> &tags)
{
Anope::string versionstr;
if (bi != StatServ)
diff --git a/modules/irc2sql/irc2sql.h b/modules/irc2sql/irc2sql.h
new file mode 100644
index 000000000..00c6f033b
--- /dev/null
+++ b/modules/irc2sql/irc2sql.h
@@ -0,0 +1,88 @@
+/*
+ *
+ * (C) 2013-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#pragma once
+
+#include "module.h"
+#include "modules/sql.h"
+
+class MySQLInterface final
+ : public SQL::Interface
+{
+public:
+ MySQLInterface(Module *o) : SQL::Interface(o) { }
+
+ void OnResult(const SQL::Result &r) override
+ {
+ }
+
+ void OnError(const SQL::Result &r) override
+ {
+ if (!r.GetQuery().query.empty())
+ Log(LOG_DEBUG) << "irc2sql: Error executing query " << r.finished_query << ": " << r.GetError();
+ else
+ Log(LOG_DEBUG) << "irc2sql: Error executing query: " << r.GetError();
+ }
+};
+
+class IRC2SQL final
+ : public Module
+{
+ ServiceReference<SQL::Provider> sql;
+ MySQLInterface sqlinterface;
+ SQL::Query query;
+ std::vector<Anope::string> TableList, ProcedureList, EventList;
+ Anope::string prefix, GeoIPDB;
+ bool quitting, introduced_myself, ctcpuser, ctcpeob, firstrun;
+ BotInfo *StatServ;
+ PrimitiveExtensibleItem<bool> versionreply;
+
+ void RunQuery(const SQL::Query &q);
+ void GetTables();
+
+ bool HasTable(const Anope::string &table);
+ bool HasProcedure(const Anope::string &table);
+ bool HasEvent(const Anope::string &table);
+
+ void CheckTables();
+
+public:
+ IRC2SQL(const Anope::string &modname, const Anope::string &creator) :
+ Module(modname, creator, EXTRA | VENDOR), sql("", ""), sqlinterface(this), versionreply(this, "CTCPVERSION")
+ {
+ firstrun = true;
+ quitting = false;
+ introduced_myself = false;
+ }
+
+ void OnShutdown() override;
+ void OnReload(Configuration::Conf *config) override;
+ void OnNewServer(Server *server) override;
+ void OnServerQuit(Server *server) override;
+ void OnUserConnect(User *u, bool &exempt) override;
+ void OnUserQuit(User *u, const Anope::string &msg) override;
+ void OnUserNickChange(User *u, const Anope::string &oldnick) override;
+ void OnUserAway(User *u, const Anope::string &message) override;
+ void OnFingerprint(User *u) override;
+ void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override;
+ void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) override;
+ void OnUserLogin(User *u) override;
+ void OnNickLogout(User *u) override;
+ void OnSetDisplayedHost(User *u) override;
+
+ void OnChannelCreate(Channel *c) override;
+ void OnChannelDelete(Channel *c) override;
+ void OnLeaveChannel(User *u, Channel *c) override;
+ void OnJoinChannel(User *u, Channel *c) override;
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) override;
+ EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) override;
+
+ void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) override;
+
+ void OnBotNotice(User *u, BotInfo *bi, Anope::string &message, const Anope::map<Anope::string> &tags) override;
+};
diff --git a/modules/extra/stats/irc2sql/tables.cpp b/modules/irc2sql/tables.cpp
index 807c7c8cd..807c7c8cd 100644
--- a/modules/extra/stats/irc2sql/tables.cpp
+++ b/modules/irc2sql/tables.cpp
diff --git a/modules/extra/stats/irc2sql/utils.cpp b/modules/irc2sql/utils.cpp
index 9c260fcaa..9c260fcaa 100644
--- a/modules/extra/stats/irc2sql/utils.cpp
+++ b/modules/irc2sql/utils.cpp
diff --git a/modules/extra/m_ldap_authentication.cpp b/modules/ldap_authentication.cpp
index 5340038dd..4f4f4f1fc 100644
--- a/modules/extra/m_ldap_authentication.cpp
+++ b/modules/ldap_authentication.cpp
@@ -17,15 +17,15 @@ static Anope::string object_class;
static Anope::string email_attribute;
static Anope::string username_attribute;
-struct IdentifyInfo
+struct IdentifyInfo final
{
Reference<User> user;
IdentifyRequest *req;
ServiceReference<LDAPProvider> lprov;
- bool admin_bind;
+ bool admin_bind = true;
Anope::string dn;
- IdentifyInfo(User *u, IdentifyRequest *r, ServiceReference<LDAPProvider> &lp) : user(u), req(r), lprov(lp), admin_bind(true)
+ IdentifyInfo(User *u, IdentifyRequest *r, ServiceReference<LDAPProvider> &lp) : user(u), req(r), lprov(lp)
{
req->Hold(me);
}
@@ -36,11 +36,12 @@ struct IdentifyInfo
}
};
-class IdentifyInterface : public LDAPInterface
+class IdentifyInterface final
+ : public LDAPInterface
{
IdentifyInfo *ii;
- public:
+public:
IdentifyInterface(Module *m, IdentifyInfo *i) : LDAPInterface(m), ii(i) { }
~IdentifyInterface()
@@ -48,12 +49,12 @@ class IdentifyInterface : public LDAPInterface
delete ii;
}
- void OnDelete() anope_override
+ void OnDelete() override
{
delete this;
}
- void OnResult(const LDAPResult &r) anope_override
+ void OnResult(const LDAPResult &r) override
{
if (!ii->lprov)
return;
@@ -68,7 +69,7 @@ class IdentifyInterface : public LDAPInterface
{
const LDAPAttributes &attr = r.get(0);
ii->dn = attr.get("dn");
- Log(LOG_DEBUG) << "m_ldap_authenticationn: binding as " << ii->dn;
+ Log(LOG_DEBUG) << "ldap_authenticationn: binding as " << ii->dn;
ii->lprov->Bind(new IdentifyInterface(this->owner, ii), ii->dn, ii->req->GetPassword());
ii = NULL;
@@ -87,7 +88,7 @@ class IdentifyInterface : public LDAPInterface
Anope::string sf = search_filter.replace_all_cs("%account", ii->req->GetAccount()).replace_all_cs("%object_class", object_class);
try
{
- Log(LOG_DEBUG) << "m_ldap_authentication: searching for " << sf;
+ Log(LOG_DEBUG) << "ldap_authentication: searching for " << sf;
ii->lprov->Search(new IdentifyInterface(this->owner, ii), basedn, sf);
ii->admin_bind = false;
ii = NULL;
@@ -112,7 +113,7 @@ class IdentifyInterface : public LDAPInterface
// encrypt and store the password in the nickcore
Anope::Encrypt(ii->req->GetPassword(), na->nc->pass);
- na->nc->Extend<Anope::string>("m_ldap_authentication_dn", ii->dn);
+ na->nc->Extend<Anope::string>("ldap_authentication_dn", ii->dn);
ii->req->Success(me);
}
break;
@@ -122,24 +123,25 @@ class IdentifyInterface : public LDAPInterface
}
}
- void OnError(const LDAPResult &r) anope_override
+ void OnError(const LDAPResult &r) override
{
}
};
-class OnIdentifyInterface : public LDAPInterface
+class OnIdentifyInterface final
+ : public LDAPInterface
{
Anope::string uid;
- public:
+public:
OnIdentifyInterface(Module *m, const Anope::string &i) : LDAPInterface(m), uid(i) { }
- void OnDelete() anope_override
+ void OnDelete() override
{
delete this;
}
- void OnResult(const LDAPResult &r) anope_override
+ void OnResult(const LDAPResult &r) override
{
User *u = User::Find(uid);
@@ -166,29 +168,31 @@ class OnIdentifyInterface : public LDAPInterface
}
}
- void OnError(const LDAPResult &r) anope_override
+ void OnError(const LDAPResult &r) override
{
Log(this->owner) << r.error;
}
};
-class OnRegisterInterface : public LDAPInterface
+class OnRegisterInterface final
+ : public LDAPInterface
{
- public:
+public:
OnRegisterInterface(Module *m) : LDAPInterface(m) { }
- void OnResult(const LDAPResult &r) anope_override
+ void OnResult(const LDAPResult &r) override
{
Log(this->owner) << "Successfully added newly created account to LDAP";
}
- void OnError(const LDAPResult &r) anope_override
+ void OnError(const LDAPResult &r) override
{
Log(this->owner) << "Error adding newly created account to LDAP: " << r.getError();
}
};
-class ModuleLDAPAuthentication : public Module
+class ModuleLDAPAuthentication final
+ : public Module
{
ServiceReference<LDAPProvider> ldap;
OnRegisterInterface orinterface;
@@ -198,20 +202,20 @@ class ModuleLDAPAuthentication : public Module
Anope::string password_attribute;
Anope::string disable_register_reason;
Anope::string disable_email_reason;
- public:
+public:
ModuleLDAPAuthentication(const Anope::string &modname, const Anope::string &creator) :
Module(modname, creator, EXTRA | VENDOR), ldap("LDAPProvider", "ldap/main"), orinterface(this),
- dn(this, "m_ldap_authentication_dn")
+ dn(this, "ldap_authentication_dn")
{
me = this;
}
- void Prioritize() anope_override
+ void Prioritize() override
{
ModuleManager::SetPriority(this, PRIORITY_FIRST);
}
- void OnReload(Configuration::Conf *config) anope_override
+ void OnReload(Configuration::Conf *config) override
{
Configuration::Block *conf = Config->GetModule(this);
@@ -223,13 +227,9 @@ class ModuleLDAPAuthentication : public Module
email_attribute = conf->Get<const Anope::string>("email_attribute");
this->disable_register_reason = conf->Get<const Anope::string>("disable_register_reason");
this->disable_email_reason = conf->Get<const Anope::string>("disable_email_reason");
-
- if (!email_attribute.empty())
- /* Don't complain to users about how they need to update their email, we will do it for them */
- config->GetModule("nickserv")->Set("forceemail", "false");
}
- EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
if (!this->disable_register_reason.empty())
{
@@ -249,16 +249,16 @@ class ModuleLDAPAuthentication : public Module
return EVENT_CONTINUE;
}
- void OnCheckAuthentication(User *u, IdentifyRequest *req) anope_override
+ void OnCheckAuthentication(User *u, IdentifyRequest *req) override
{
if (!this->ldap)
return;
- IdentifyInfo *ii = new IdentifyInfo(u, req, this->ldap);
+ auto *ii = new IdentifyInfo(u, req, this->ldap);
this->ldap->BindAsAdmin(new IdentifyInterface(this, ii));
}
- void OnNickIdentify(User *u) anope_override
+ void OnNickIdentify(User *u) override
{
if (email_attribute.empty() || !this->ldap)
return;
@@ -270,7 +270,7 @@ class ModuleLDAPAuthentication : public Module
this->ldap->Search(new OnIdentifyInterface(this, u->GetUID()), *d, "(" + email_attribute + "=*)");
}
- void OnNickRegister(User *, NickAlias *na, const Anope::string &pass) anope_override
+ void OnNickRegister(User *, NickAlias *na, const Anope::string &pass) override
{
if (!this->disable_register_reason.empty() || !this->ldap)
return;
@@ -300,7 +300,7 @@ class ModuleLDAPAuthentication : public Module
this->ldap->Add(&this->orinterface, new_dn, attributes);
}
- void OnPreNickExpire(NickAlias *na, bool &expire) anope_override
+ void OnPreNickExpire(NickAlias *na, bool &expire) override
{
// We can't let nicks expire if they still have a group or
// there will be a zombie account left over that can't be
diff --git a/modules/extra/m_ldap_oper.cpp b/modules/ldap_oper.cpp
index 469b3dd84..62749f957 100644
--- a/modules/extra/m_ldap_oper.cpp
+++ b/modules/ldap_oper.cpp
@@ -12,16 +12,17 @@
static std::set<Oper *> my_opers;
static Anope::string opertype_attribute;
-class IdentifyInterface : public LDAPInterface
+class IdentifyInterface final
+ : public LDAPInterface
{
Reference<User> u;
- public:
+public:
IdentifyInterface(Module *m, User *user) : LDAPInterface(m), u(user)
{
}
- void OnResult(const LDAPResult &r) anope_override
+ void OnResult(const LDAPResult &r) override
{
if (!u || !u->Account())
return;
@@ -65,17 +66,18 @@ class IdentifyInterface : public LDAPInterface
}
}
- void OnError(const LDAPResult &r) anope_override
+ void OnError(const LDAPResult &r) override
{
}
- void OnDelete() anope_override
+ void OnDelete() override
{
delete this;
}
};
-class LDAPOper : public Module
+class LDAPOper final
+ : public Module
{
ServiceReference<LDAPProvider> ldap;
@@ -83,14 +85,14 @@ class LDAPOper : public Module
Anope::string password;
Anope::string basedn;
Anope::string filter;
- public:
+public:
LDAPOper(const Anope::string &modname, const Anope::string &creator) :
Module(modname, creator, EXTRA | VENDOR), ldap("LDAPProvider", "ldap/main")
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = Config->GetModule(this);
@@ -100,17 +102,17 @@ class LDAPOper : public Module
this->filter = config->Get<const Anope::string>("filter");
opertype_attribute = config->Get<const Anope::string>("opertype_attribute");
- for (std::set<Oper *>::iterator it = my_opers.begin(), it_end = my_opers.end(); it != it_end; ++it)
- delete *it;
+ for (const auto *oper : my_opers)
+ delete oper;
my_opers.clear();
}
- void OnNickIdentify(User *u) anope_override
+ void OnNickIdentify(User *u) override
{
try
{
if (!this->ldap)
- throw LDAPException("No LDAP interface. Is m_ldap loaded and configured correctly?");
+ throw LDAPException("No LDAP interface. Is ldap loaded and configured correctly?");
else if (this->basedn.empty() || this->filter.empty() || opertype_attribute.empty())
throw LDAPException("Could not search LDAP for opertype settings, invalid configuration.");
@@ -124,7 +126,7 @@ class LDAPOper : public Module
}
}
- void OnDelCore(NickCore *nc) anope_override
+ void OnDelCore(NickCore *nc) override
{
if (nc->o != NULL && my_opers.count(nc->o) > 0)
{
diff --git a/modules/pseudoclients/memoserv.cpp b/modules/memoserv/memoserv.cpp
index 3fc6d203f..084650542 100644
--- a/modules/pseudoclients/memoserv.cpp
+++ b/modules/memoserv/memoserv.cpp
@@ -11,37 +11,39 @@
#include "module.h"
-class MemoServCore : public Module, public MemoServService
+class MemoServCore final
+ : public Module
+ , public MemoServService
{
Reference<BotInfo> MemoServ;
- bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m)
+ static bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m)
{
Anope::string subject = Language::Translate(nc, Config->GetBlock("mail")->Get<const Anope::string>("memo_subject").c_str()),
message = Language::Translate(Config->GetBlock("mail")->Get<const Anope::string>("memo_message").c_str());
subject = subject.replace_all_cs("%n", nc->display);
subject = subject.replace_all_cs("%s", m->sender);
- subject = subject.replace_all_cs("%d", stringify(mi->GetIndex(m) + 1));
+ subject = subject.replace_all_cs("%d", Anope::ToString(mi->GetIndex(m) + 1));
subject = subject.replace_all_cs("%t", m->text);
subject = subject.replace_all_cs("%N", Config->GetBlock("networkinfo")->Get<const Anope::string>("networkname"));
message = message.replace_all_cs("%n", nc->display);
message = message.replace_all_cs("%s", m->sender);
- message = message.replace_all_cs("%d", stringify(mi->GetIndex(m) + 1));
+ message = message.replace_all_cs("%d", Anope::ToString(mi->GetIndex(m) + 1));
message = message.replace_all_cs("%t", m->text);
message = message.replace_all_cs("%N", Config->GetBlock("networkinfo")->Get<const Anope::string>("networkname"));
return Mail::Send(nc, subject, message);
}
- public:
+public:
MemoServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
MemoServService(this)
{
}
- MemoResult Send(const Anope::string &source, const Anope::string &target, const Anope::string &message, bool force) anope_override
+ MemoResult Send(const Anope::string &source, const Anope::string &target, const Anope::string &message, bool force) override
{
bool ischan;
MemoInfo *mi = MemoInfo::GetMemoInfo(target, ischan);
@@ -77,7 +79,7 @@ class MemoServCore : public Module, public MemoServService
if (sender != NULL)
sender->lastmemosend = Anope::CurTime;
- Memo *m = new Memo();
+ auto *m = new Memo();
m->mi = mi;
mi->memos->push_back(m);
m->owner = target;
@@ -94,10 +96,8 @@ class MemoServCore : public Module, public MemoServService
if (ci->c)
{
- for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
+ for (const auto &[_, cu] : ci->c->users)
{
- ChanUserContainer *cu = it->second;
-
if (ci->AccessFor(cu->user).HasPriv("MEMO"))
{
if (cu->user->Account() && cu->user->Account()->HasExt("MEMO_RECEIVE"))
@@ -112,9 +112,8 @@ class MemoServCore : public Module, public MemoServService
if (nc->HasExt("MEMO_RECEIVE"))
{
- for (unsigned i = 0; i < nc->aliases->size(); ++i)
+ for (auto *na : *nc->aliases)
{
- const NickAlias *na = nc->aliases->at(i);
User *user = User::Find(na->nick, true);
if (user && user->IsIdentified())
user->SendMessage(MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->StrictPrivmsg.c_str(), MemoServ->nick.c_str(), mi->memos->size());
@@ -129,7 +128,7 @@ class MemoServCore : public Module, public MemoServService
return MEMO_SUCCESS;
}
- void Check(User *u) anope_override
+ void Check(User *u) override
{
const NickCore *nc = u->Account();
if (!nc)
@@ -150,7 +149,7 @@ class MemoServCore : public Module, public MemoServService
}
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
const Anope::string &msnick = conf->GetModule(this)->Get<const Anope::string>("client");
@@ -164,55 +163,55 @@ class MemoServCore : public Module, public MemoServService
MemoServ = bi;
}
- void OnNickCoreCreate(NickCore *nc) anope_override
+ void OnNickCoreCreate(NickCore *nc) override
{
nc->memos.memomax = Config->GetModule(this)->Get<int>("maxmemos");
}
- void OnCreateChan(ChannelInfo *ci) anope_override
+ void OnCreateChan(ChannelInfo *ci) override
{
ci->memos.memomax = Config->GetModule(this)->Get<int>("maxmemos");
}
- void OnBotDelete(BotInfo *bi) anope_override
+ void OnBotDelete(BotInfo *bi) override
{
if (bi == MemoServ)
MemoServ = NULL;
}
- void OnNickIdentify(User *u) anope_override
+ void OnNickIdentify(User *u) override
{
this->Check(u);
}
- void OnJoinChannel(User *u, Channel *c) anope_override
+ void OnJoinChannel(User *u, Channel *c) override
{
if (c->ci && !c->ci->memos.memos->empty() && c->ci->AccessFor(u).HasPriv("MEMO"))
{
if (c->ci->memos.memos->size() == 1)
- u->SendMessage(MemoServ, _("There is \002%d\002 memo on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str());
+ u->SendMessage(MemoServ, _("There is \002%zu\002 memo on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str());
else
- u->SendMessage(MemoServ, _("There are \002%d\002 memos on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str());
+ u->SendMessage(MemoServ, _("There are \002%zu\002 memos on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str());
}
}
- void OnUserAway(User *u, const Anope::string &message) anope_override
+ void OnUserAway(User *u, const Anope::string &message) override
{
if (message.empty())
this->Check(u);
}
- void OnNickUpdate(User *u) anope_override
+ void OnNickUpdate(User *u) override
{
this->Check(u);
}
- void OnUserConnect(User *user, bool &exempt) anope_override
+ void OnUserConnect(User *user, bool &exempt) override
{
this->Check(user);
}
- EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *MemoServ)
return EVENT_CONTINUE;
@@ -225,7 +224,7 @@ class MemoServCore : public Module, public MemoServService
return EVENT_CONTINUE;
}
- void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *MemoServ)
return;
diff --git a/modules/commands/ms_cancel.cpp b/modules/memoserv/ms_cancel.cpp
index 0293b375e..330b55926 100644
--- a/modules/commands/ms_cancel.cpp
+++ b/modules/memoserv/ms_cancel.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandMSCancel : public Command
+class CommandMSCancel final
+ : public Command
{
- public:
+public:
CommandMSCancel(Module *creator) : Command(creator, "memoserv/cancel", 1, 1)
{
this->SetDesc(_("Cancel the last memo you sent"));
this->SetSyntax(_("{\037nick\037 | \037channel\037}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -77,7 +78,7 @@ class CommandMSCancel : public Command
source.Reply(_("No memo was cancelable."));
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -87,11 +88,12 @@ class CommandMSCancel : public Command
}
};
-class MSCancel : public Module
+class MSCancel final
+ : public Module
{
CommandMSCancel commandmscancel;
- public:
+public:
MSCancel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmscancel(this)
{
diff --git a/modules/commands/ms_check.cpp b/modules/memoserv/ms_check.cpp
index 77af12a2d..d3556379d 100644
--- a/modules/commands/ms_check.cpp
+++ b/modules/memoserv/ms_check.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandMSCheck : public Command
+class CommandMSCheck final
+ : public Command
{
- public:
+public:
CommandMSCheck(Module *creator) : Command(creator, "memoserv/check", 1, 1)
{
this->SetDesc(_("Checks if last memo to a nick was read"));
this->SetSyntax(_("\037nick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &recipient = params[0];
@@ -62,7 +63,7 @@ class CommandMSCheck : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -72,11 +73,12 @@ class CommandMSCheck : public Command
}
};
-class MSCheck : public Module
+class MSCheck final
+ : public Module
{
CommandMSCheck commandmscheck;
- public:
+public:
MSCheck(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmscheck(this)
{
diff --git a/modules/commands/ms_del.cpp b/modules/memoserv/ms_del.cpp
index 4d98fa4eb..469fdf221 100644
--- a/modules/commands/ms_del.cpp
+++ b/modules/memoserv/ms_del.cpp
@@ -11,18 +11,19 @@
#include "module.h"
-class MemoDelCallback : public NumberList
+class MemoDelCallback final
+ : public NumberList
{
CommandSource &source;
Command *cmd;
ChannelInfo *ci;
MemoInfo *mi;
- public:
+public:
MemoDelCallback(CommandSource &_source, Command *c, ChannelInfo *_ci, MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), source(_source), cmd(c), ci(_ci), mi(_mi)
{
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > mi->memos->size())
return;
@@ -36,16 +37,17 @@ class MemoDelCallback : public NumberList
}
};
-class CommandMSDel : public Command
+class CommandMSDel final
+ : public Command
{
- public:
+public:
CommandMSDel(Module *creator) : Command(creator, "memoserv/del", 0, 2)
{
this->SetDesc(_("Delete a memo or memos"));
this->SetSyntax(_("[\037channel\037] {\037num\037 | \037list\037 | LAST | ALL}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -98,7 +100,7 @@ class CommandMSDel : public Command
/* Delete last memo. */
FOREACH_MOD(OnMemoDel, (ci ? ci->name : source.nc->display, mi, mi->GetMemo(mi->memos->size() - 1)));
mi->Del(mi->memos->size() - 1);
- source.Reply(_("Memo %d has been deleted."), mi->memos->size() + 1);
+ source.Reply(_("Memo %zu has been deleted."), mi->memos->size() + 1);
if (ci)
Log(LOG_COMMAND, source, this, ci) << "on LAST memo";
}
@@ -122,7 +124,7 @@ class CommandMSDel : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -144,11 +146,12 @@ class CommandMSDel : public Command
}
};
-class MSDel : public Module
+class MSDel final
+ : public Module
{
CommandMSDel commandmsdel;
- public:
+public:
MSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmsdel(this)
{
diff --git a/modules/commands/ms_ignore.cpp b/modules/memoserv/ms_ignore.cpp
index e25c92ee0..b1c14fb4a 100644
--- a/modules/commands/ms_ignore.cpp
+++ b/modules/memoserv/ms_ignore.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandMSIgnore : public Command
+class CommandMSIgnore final
+ : public Command
{
- public:
+public:
CommandMSIgnore(Module *creator) : Command(creator, "memoserv/ignore", 1, 3)
{
this->SetDesc(_("Manage the memo ignore list"));
@@ -22,7 +23,7 @@ class CommandMSIgnore : public Command
this->SetSyntax(_("[\037channel\037] LIST"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -50,7 +51,7 @@ class CommandMSIgnore : public Command
source.Reply(ACCESS_DENIED);
else if (command.equals_ci("ADD") && !param.empty())
{
- if (mi->ignores.size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "32"))
+ if (mi->ignores.size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "50"))
{
source.Reply(_("Sorry, the memo ignore list for \002%s\002 is full."), channel.c_str());
return;
@@ -58,7 +59,7 @@ class CommandMSIgnore : public Command
if (std::find(mi->ignores.begin(), mi->ignores.end(), param.ci_str()) == mi->ignores.end())
{
- mi->ignores.push_back(param.ci_str());
+ mi->ignores.emplace_back(param.ci_str());
source.Reply(_("\002%s\002 added to ignore list."), param.c_str());
}
else
@@ -84,10 +85,10 @@ class CommandMSIgnore : public Command
{
ListFormatter list(source.GetAccount());
list.AddColumn(_("Mask"));
- for (unsigned i = 0; i < mi->ignores.size(); ++i)
+ for (const auto &ignore : mi->ignores)
{
ListFormatter::ListEntry entry;
- entry["Mask"] = mi->ignores[i];
+ entry["Mask"] = ignore;
list.AddEntry(entry);
}
@@ -96,8 +97,8 @@ class CommandMSIgnore : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
else
@@ -106,7 +107,7 @@ class CommandMSIgnore : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -118,11 +119,12 @@ class CommandMSIgnore : public Command
}
};
-class MSIgnore : public Module
+class MSIgnore final
+ : public Module
{
CommandMSIgnore commandmsignore;
- public:
+public:
MSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmsignore(this)
{
diff --git a/modules/commands/ms_info.cpp b/modules/memoserv/ms_info.cpp
index 0fe165e73..c76a446cd 100644
--- a/modules/commands/ms_info.cpp
+++ b/modules/memoserv/ms_info.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandMSInfo : public Command
+class CommandMSInfo final
+ : public Command
{
- public:
+public:
CommandMSInfo(Module *creator) : Command(creator, "memoserv/info", 0, 1)
{
this->SetDesc(_("Displays information about your memos"));
this->SetSyntax(_("[\037nick\037 | \037channel\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
NickCore *nc = source.nc;
const MemoInfo *mi;
@@ -80,18 +81,19 @@ class CommandMSInfo : public Command
}
else
{
- unsigned count = 0, i, end;
- for (i = 0, end = mi->memos->size(); i < end; ++i)
+ size_t count = 0;
+ for (size_t i = 0; i < mi->memos->size(); ++i)
if (mi->GetMemo(i)->unread)
++count;
+
if (count == mi->memos->size())
- source.Reply(_("%s currently has \002%d\002 memos; all of them are unread."), nname.c_str(), count);
+ source.Reply(_("%s currently has \002%zu\002 memos; all of them are unread."), nname.c_str(), count);
else if (!count)
- source.Reply(_("%s currently has \002%d\002 memos."), nname.c_str(), mi->memos->size());
+ source.Reply(_("%s currently has \002%zu\002 memos."), nname.c_str(), mi->memos->size());
else if (count == 1)
- source.Reply(_("%s currently has \002%d\002 memos, of which \0021\002 is unread."), nname.c_str(), mi->memos->size());
+ source.Reply(_("%s currently has \002%zu\002 memos, of which \0021\002 is unread."), nname.c_str(), mi->memos->size());
else
- source.Reply(_("%s currently has \002%d\002 memos, of which \002%d\002 are unread."), nname.c_str(), mi->memos->size(), count);
+ source.Reply(_("%s currently has \002%zu\002 memos, of which \002%zu\002 are unread."), nname.c_str(), mi->memos->size(), count);
}
if (!mi->memomax)
{
@@ -137,18 +139,19 @@ class CommandMSInfo : public Command
}
else
{
- unsigned count = 0, i, end;
- for (i = 0, end = mi->memos->size(); i < end; ++i)
+ size_t count = 0;
+ for (size_t i = 0; i < mi->memos->size(); ++i)
if (mi->GetMemo(i)->unread)
++count;
+
if (count == mi->memos->size())
- source.Reply(_("You currently have \002%d\002 memos; all of them are unread."), count);
+ source.Reply(_("You currently have \002%zu\002 memos; all of them are unread."), count);
else if (!count)
- source.Reply(_("You currently have \002%d\002 memos."), mi->memos->size());
+ source.Reply(_("You currently have \002%zu\002 memos."), mi->memos->size());
else if (count == 1)
- source.Reply(_("You currently have \002%d\002 memos, of which \0021\002 is unread."), mi->memos->size());
+ source.Reply(_("You currently have \002%zu\002 memos, of which \0021\002 is unread."), mi->memos->size());
else
- source.Reply(_("You currently have \002%d\002 memos, of which \002%d\002 are unread."), mi->memos->size(), count);
+ source.Reply(_("You currently have \002%zu\002 memos, of which \002%zu\002 are unread."), mi->memos->size(), count);
}
if (!mi->memomax)
@@ -197,7 +200,7 @@ class CommandMSInfo : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -216,11 +219,12 @@ class CommandMSInfo : public Command
}
};
-class MSInfo : public Module
+class MSInfo final
+ : public Module
{
CommandMSInfo commandmsinfo;
- public:
+public:
MSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmsinfo(this)
{
diff --git a/modules/commands/ms_list.cpp b/modules/memoserv/ms_list.cpp
index 6aee9f691..a25a95ed0 100644
--- a/modules/commands/ms_list.cpp
+++ b/modules/memoserv/ms_list.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandMSList : public Command
+class CommandMSList final
+ : public Command
{
- public:
+public:
CommandMSList(Module *creator) : Command(creator, "memoserv/list", 0, 2)
{
this->SetDesc(_("List your memos"));
this->SetSyntax(_("[\037channel\037] [\037list\037 | NEW]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string param = !params.empty() ? params[0] : "", chan;
@@ -65,17 +66,18 @@ class CommandMSList : public Command
if (!param.empty() && isdigit(param[0]))
{
- class MemoListCallback : public NumberList
+ class MemoListCallback final
+ : public NumberList
{
ListFormatter &list;
CommandSource &source;
const MemoInfo *mi;
- public:
+ public:
MemoListCallback(ListFormatter &_list, CommandSource &_source, const MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), list(_list), source(_source), mi(_mi)
{
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > mi->memos->size())
return;
@@ -83,7 +85,7 @@ class CommandMSList : public Command
const Memo *m = mi->GetMemo(number - 1);
ListFormatter::ListEntry entry;
- entry["Number"] = (m->unread ? "* " : " ") + stringify(number);
+ entry["Number"] = (m->unread ? "* " : " ") + Anope::ToString(number);
entry["Sender"] = m->sender;
entry["Date/Time"] = Anope::strftime(m->time, source.GetAccount());
this->list.AddEntry(entry);
@@ -118,7 +120,7 @@ class CommandMSList : public Command
const Memo *m = mi->GetMemo(i);
ListFormatter::ListEntry entry;
- entry["Number"] = (m->unread ? "* " : " ") + stringify(i + 1);
+ entry["Number"] = (m->unread ? "* " : " ") + Anope::ToString(i + 1);
entry["Sender"] = m->sender;
entry["Date/Time"] = Anope::strftime(m->time, source.GetAccount());
list.AddEntry(entry);
@@ -129,13 +131,13 @@ class CommandMSList : public Command
list.Process(replies);
source.Reply(_("Memos for %s:"), ci ? ci->name.c_str() : source.GetNick().c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -149,11 +151,12 @@ class CommandMSList : public Command
}
};
-class MSList : public Module
+class MSList final
+ : public Module
{
CommandMSList commandmslist;
- public:
+public:
MSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmslist(this)
{
diff --git a/modules/commands/ms_read.cpp b/modules/memoserv/ms_read.cpp
index 3af0549bc..5e9c8fd83 100644
--- a/modules/commands/ms_read.cpp
+++ b/modules/memoserv/ms_read.cpp
@@ -47,25 +47,26 @@ static void rsend_notify(CommandSource &source, MemoInfo *mi, Memo *m, const Ano
m->receipt = false;
}
-class MemoListCallback : public NumberList
+class MemoListCallback final
+ : public NumberList
{
CommandSource &source;
MemoInfo *mi;
const ChannelInfo *ci;
bool found;
- public:
+public:
MemoListCallback(CommandSource &_source, MemoInfo *_mi, const ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), source(_source), mi(_mi), ci(_ci)
{
found = false;
}
- ~MemoListCallback()
+ ~MemoListCallback() override
{
if (!found)
source.Reply(_("No memos to display."));
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > mi->memos->size())
return;
@@ -104,16 +105,17 @@ class MemoListCallback : public NumberList
}
};
-class CommandMSRead : public Command
+class CommandMSRead final
+ : public Command
{
- public:
+public:
CommandMSRead(Module *creator) : Command(creator, "memoserv/read", 1, 2)
{
this->SetDesc(_("Read a memo or memos"));
this->SetSyntax(_("[\037channel\037] {\037num\037 | \037list\037 | LAST | NEW | ALL}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
MemoInfo *mi;
@@ -192,7 +194,7 @@ class CommandMSRead : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -209,11 +211,12 @@ class CommandMSRead : public Command
}
};
-class MSRead : public Module
+class MSRead final
+ : public Module
{
CommandMSRead commandmsread;
- public:
+public:
MSRead(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmsread(this)
{
diff --git a/modules/commands/ms_rsend.cpp b/modules/memoserv/ms_rsend.cpp
index b74e82bae..a5de58e56 100644
--- a/modules/commands/ms_rsend.cpp
+++ b/modules/memoserv/ms_rsend.cpp
@@ -16,16 +16,17 @@ namespace
ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ");
}
-class CommandMSRSend : public Command
+class CommandMSRSend final
+ : public Command
{
- public:
+public:
CommandMSRSend(Module *creator) : Command(creator, "memoserv/rsend", 2, 2)
{
this->SetDesc(_("Sends a memo and requests a read receipt"));
this->SetSyntax(_("{\037nick\037 | \037channel\037} \037memo-text\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!memoserv)
return;
@@ -55,7 +56,7 @@ class CommandMSRSend : public Command
if (result == MemoServService::MEMO_INVALID_TARGET)
source.Reply(_("\002%s\002 is not a registered unforbidden nick or channel."), nick.c_str());
else if (result == MemoServService::MEMO_TOO_FAST)
- source.Reply(_("Please wait %d seconds before using the %s command again."), Config->GetModule("memoserv")->Get<time_t>("senddelay"), source.command.c_str());
+ source.Reply(_("Please wait %lu seconds before using the %s command again."), Config->GetModule("memoserv")->Get<unsigned long>("senddelay"), source.command.c_str());
else if (result == MemoServService::MEMO_TARGET_FULL)
source.Reply(_("Sorry, %s currently has too many memos and cannot receive more."), nick.c_str());
else
@@ -73,7 +74,7 @@ class CommandMSRSend : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -88,11 +89,12 @@ class CommandMSRSend : public Command
}
};
-class MSRSend : public Module
+class MSRSend final
+ : public Module
{
CommandMSRSend commandmsrsend;
- public:
+public:
MSRSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmsrsend(this)
{
diff --git a/modules/commands/ms_send.cpp b/modules/memoserv/ms_send.cpp
index 37233176d..1335f1ad4 100644
--- a/modules/commands/ms_send.cpp
+++ b/modules/memoserv/ms_send.cpp
@@ -16,16 +16,17 @@ namespace
ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ");
}
-class CommandMSSend : public Command
+class CommandMSSend final
+ : public Command
{
- public:
+public:
CommandMSSend(Module *creator) : Command(creator, "memoserv/send", 2, 2)
{
this->SetDesc(_("Send a memo to a nick or channel"));
this->SetSyntax(_("{\037nick\037 | \037channel\037} \037memo-text\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!memoserv)
return;
@@ -54,12 +55,12 @@ class CommandMSSend : public Command
else if (result == MemoServService::MEMO_INVALID_TARGET)
source.Reply(_("\002%s\002 is not a registered unforbidden nick or channel."), nick.c_str());
else if (result == MemoServService::MEMO_TOO_FAST)
- source.Reply(_("Please wait %d seconds before using the %s command again."), Config->GetModule("memoserv")->Get<time_t>("senddelay"), source.command.c_str());
+ source.Reply(_("Please wait %lu seconds before using the %s command again."), Config->GetModule("memoserv")->Get<unsigned long>("senddelay"), source.command.c_str());
else if (result == MemoServService::MEMO_TARGET_FULL)
source.Reply(_("Sorry, %s currently has too many memos and cannot receive more."), nick.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -71,11 +72,12 @@ class CommandMSSend : public Command
}
};
-class MSSend : public Module
+class MSSend final
+ : public Module
{
CommandMSSend commandmssend;
- public:
+public:
MSSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmssend(this)
{
diff --git a/modules/commands/ms_sendall.cpp b/modules/memoserv/ms_sendall.cpp
index 588c69714..c04ff7a3f 100644
--- a/modules/commands/ms_sendall.cpp
+++ b/modules/memoserv/ms_sendall.cpp
@@ -16,16 +16,17 @@ namespace
ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ");
}
-class CommandMSSendAll : public Command
+class CommandMSSendAll final
+ : public Command
{
- public:
+public:
CommandMSSendAll(Module *creator) : Command(creator, "memoserv/sendall", 1, 1)
{
this->SetDesc(_("Send a memo to all registered users"));
this->SetSyntax(_("\037memo-text\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!memoserv)
return;
@@ -34,10 +35,8 @@ class CommandMSSendAll : public Command
Log(LOG_ADMIN, source, this) << "to send " << text;
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- const NickCore *nc = it->second;
-
if (nc != source.nc)
memoserv->Send(source.GetNick(), nc->display, text);
}
@@ -45,7 +44,7 @@ class CommandMSSendAll : public Command
source.Reply(_("A massmemo has been sent to all registered users."));
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -54,11 +53,12 @@ class CommandMSSendAll : public Command
}
};
-class MSSendAll : public Module
+class MSSendAll final
+ : public Module
{
CommandMSSendAll commandmssendall;
- public:
+public:
MSSendAll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmssendall(this)
{
diff --git a/modules/commands/ms_set.cpp b/modules/memoserv/ms_set.cpp
index 0ac7d7808..54ad7c252 100644
--- a/modules/commands/ms_set.cpp
+++ b/modules/memoserv/ms_set.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandMSSet : public Command
+class CommandMSSet final
+ : public Command
{
- private:
+private:
void DoNotify(CommandSource &source, const std::vector<Anope::string> &params, MemoInfo *mi)
{
const Anope::string &param = params[1];
@@ -134,12 +135,8 @@ class CommandMSSet : public Command
else
nc->Shrink<bool>("MEMO_HARDMAX");
}
- limit = -1;
- try
- {
- limit = convertTo<int16_t>(p1);
- }
- catch (const ConvertException &) { }
+
+ limit = Anope::Convert<int16_t>(p1, -1);
}
else
{
@@ -159,12 +156,8 @@ class CommandMSSet : public Command
return;
}
int max_memos = Config->GetModule("memoserv")->Get<int>("maxmemos");
- limit = -1;
- try
- {
- limit = convertTo<int16_t>(p1);
- }
- catch (const ConvertException &) { }
+ limit = Anope::Convert<int16_t>(p1, -1);
+
/* The first character is a digit, but we could still go negative
* from overflow... watch out! */
if (limit < 0 || (max_memos > 0 && limit > max_memos))
@@ -200,14 +193,14 @@ class CommandMSSet : public Command
}
return;
}
- public:
+public:
CommandMSSet(Module *creator) : Command(creator, "memoserv/set", 2, 5)
{
this->SetDesc(_("Set options related to memos"));
this->SetSyntax(_("\037option\037 \037parameters\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
MemoInfo *mi = &source.nc->memos;
@@ -226,7 +219,7 @@ class CommandMSSet : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (subcommand.empty())
{
@@ -298,12 +291,13 @@ class CommandMSSet : public Command
}
};
-class MSSet : public Module
+class MSSet final
+ : public Module
{
CommandMSSet commandmsset;
SerializableExtensibleItem<bool> memo_signon, memo_receive, memo_mail, memo_hardmax;
- public:
+public:
MSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmsset(this), memo_signon(this, "MEMO_SIGNON"), memo_receive(this, "MEMO_RECEIVE"), memo_mail(this, "MEMO_MAIL"),
memo_hardmax(this, "MEMO_HARDMAX")
diff --git a/modules/commands/ms_staff.cpp b/modules/memoserv/ms_staff.cpp
index 863c150b0..cbd27061d 100644
--- a/modules/commands/ms_staff.cpp
+++ b/modules/memoserv/ms_staff.cpp
@@ -16,32 +16,31 @@ namespace
ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ");
}
-class CommandMSStaff : public Command
+class CommandMSStaff final
+ : public Command
{
- public:
+public:
CommandMSStaff(Module *creator) : Command(creator, "memoserv/staff", 1, 1)
{
this->SetDesc(_("Send a memo to all opers/admins"));
this->SetSyntax(_("\037memo-text\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!memoserv)
return;
const Anope::string &text = params[0];
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- const NickCore *nc = it->second;
-
if (source.nc != nc && nc->IsServicesOper())
memoserv->Send(source.GetNick(), nc->display, text, true);
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -51,11 +50,12 @@ class CommandMSStaff : public Command
}
};
-class MSStaff : public Module
+class MSStaff final
+ : public Module
{
CommandMSStaff commandmsstaff;
- public:
+public:
MSStaff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandmsstaff(this)
{
diff --git a/modules/pseudoclients/nickserv.cpp b/modules/nickserv/nickserv.cpp
index 8bed39bba..f1f087163 100644
--- a/modules/pseudoclients/nickserv.cpp
+++ b/modules/nickserv/nickserv.cpp
@@ -16,20 +16,26 @@ static std::set<NickServCollide *> collides;
/** Timer for colliding nicks to force people off of nicknames
*/
-class NickServCollide : public Timer
+class NickServCollide final
+ : public Timer
{
NickServService *service;
Reference<User> u;
time_t ts;
Reference<NickAlias> na;
- public:
- NickServCollide(Module *me, NickServService *nss, User *user, NickAlias *nick, time_t delay) : Timer(me, delay), service(nss), u(user), ts(user->timestamp), na(nick)
+public:
+ NickServCollide(Module *me, NickServService *nss, User *user, NickAlias *nick, time_t delay)
+ : Timer(me, delay)
+ , service(nss)
+ , u(user)
+ , ts(user->timestamp)
+ , na(nick)
{
collides.insert(this);
}
- ~NickServCollide()
+ ~NickServCollide() override
{
collides.erase(this);
}
@@ -44,7 +50,7 @@ class NickServCollide : public Timer
return na;
}
- void Tick(time_t t) anope_override
+ void Tick() override
{
if (!u || !na)
return;
@@ -58,17 +64,21 @@ class NickServCollide : public Timer
/** Timer for removing HELD status from nicks.
*/
-class NickServHeld : public Timer
+class NickServHeld final
+ : public Timer
{
Reference<NickAlias> na;
Anope::string nick;
- public:
- NickServHeld(Module *me, NickAlias *n, long l) : Timer(me, l), na(n), nick(na->nick)
+public:
+ NickServHeld(Module *me, NickAlias *n, time_t l)
+ : Timer(me, l)
+ , na(n)
+ , nick(na->nick)
{
n->Extend<bool>("HELD");
}
- void Tick(time_t)
+ void Tick() override
{
if (na)
na->Shrink<bool>("HELD");
@@ -80,13 +90,17 @@ static Anope::map<NickServRelease *> NickServReleases;
/** Timer for releasing nicks to be available for use
*/
-class NickServRelease : public User, public Timer
+class NickServRelease final
+ : public User
+ , public Timer
{
Anope::string nick;
- public:
- NickServRelease(Module *me, NickAlias *na, time_t delay) : User(na->nick, Config->GetModule("nickserv")->Get<const Anope::string>("enforceruser", "user"),
- Config->GetModule("nickserv")->Get<const Anope::string>("enforcerhost", Me->GetName()), "", "", Me, "Services Enforcer", Anope::CurTime, "", IRCD->UID_Retrieve(), NULL), Timer(me, delay), nick(na->nick)
+public:
+ NickServRelease(Module *me, NickAlias *na, time_t delay)
+ : User(na->nick, Config->GetModule("nickserv")->Get<const Anope::string>("enforceruser", "user"), Config->GetModule("nickserv")->Get<const Anope::string>("enforcerhost", Me->GetName()), "", "", Me, "Services Enforcer", Anope::CurTime, "", IRCD->UID_Retrieve(), NULL)
+ , Timer(me, delay)
+ , nick(na->nick)
{
/* Erase the current release timer and use the new one */
Anope::map<NickServRelease *>::iterator nit = NickServReleases.find(this->nick);
@@ -96,21 +110,25 @@ class NickServRelease : public User, public Timer
delete nit->second;
}
- NickServReleases.insert(std::make_pair(this->nick, this));
+ NickServReleases.emplace(this->nick, this);
IRCD->SendClientIntroduction(this);
}
- ~NickServRelease()
+ ~NickServRelease() override
{
IRCD->SendQuit(this, "");
NickServReleases.erase(this->nick);
}
- void Tick(time_t t) anope_override { }
+ void Tick() override
+ {
+ }
};
-class NickServCore : public Module, public NickServService
+class NickServCore final
+ : public Module
+ , public NickServService
{
Reference<BotInfo> NickServ;
std::vector<Anope::string> defaults;
@@ -131,32 +149,32 @@ class NickServCore : public Module, public NickServService
}
}
- public:
+public:
NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
NickServService(this), held(this, "HELD"), collided(this, "COLLIDED")
{
}
- ~NickServCore()
+ ~NickServCore() override
{
OnShutdown();
}
- void OnShutdown() anope_override
+ void OnShutdown() override
{
/* On shutdown, restart, or mod unload, remove all of our holds for nicks (svshold or qlines)
* because some IRCds do not allow us to have these automatically expire
*/
- for (nickalias_map::const_iterator it = NickAliasList->begin(); it != NickAliasList->end(); ++it)
- this->Release(it->second);
+ for (const auto &[_, na] : *NickAliasList)
+ this->Release(na);
}
- void OnRestart() anope_override
+ void OnRestart() override
{
OnShutdown();
}
- void Validate(User *u) anope_override
+ void Validate(User *u) override
{
NickAlias *na = NickAlias::Find(u->nick);
if (!na)
@@ -172,27 +190,14 @@ class NickServCore : public Module, public NickServService
else if (MOD_RESULT == EVENT_ALLOW)
return;
- if (!na->nc->HasExt("NS_SECURE") && u->IsRecognized())
- {
- na->last_seen = Anope::CurTime;
- na->last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost();
- na->last_realname = u->realname;
- return;
- }
-
if (Config->GetModule("nickserv")->Get<bool>("nonicknameownership"))
return;
- bool on_access = u->IsRecognized(false);
-
- if (on_access || !na->nc->HasExt("KILL_IMMED"))
+ if (!na->nc->HasExt("KILL_IMMED"))
{
- if (na->nc->HasExt("NS_SECURE"))
- u->SendMessage(NickServ, NICK_IS_SECURE, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
- else
- u->SendMessage(NickServ, NICK_IS_REGISTERED, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
+ u->SendMessage(NickServ, NICK_IS_SECURE, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
}
- if (na->nc->HasExt("KILLPROTECT") && !on_access)
+ if (na->nc->HasExt("KILLPROTECT"))
{
if (na->nc->HasExt("KILL_IMMED"))
{
@@ -215,7 +220,7 @@ class NickServCore : public Module, public NickServService
}
- void OnUserLogin(User *u) anope_override
+ void OnUserLogin(User *u) override
{
NickAlias *na = NickAlias::Find(u->nick);
if (na && *na->nc == u->Account() && !Config->GetModule("nickserv")->Get<bool>("nonicknameownership") && !na->nc->HasExt("UNCONFIRMED"))
@@ -223,17 +228,17 @@ class NickServCore : public Module, public NickServService
const Anope::string &modesonid = Config->GetModule(this)->Get<Anope::string>("modesonid");
if (!modesonid.empty())
- u->SetModes(NickServ, "%s", modesonid.c_str());
+ u->SetModes(NickServ, modesonid);
}
- void Collide(User *u, NickAlias *na) anope_override
+ void Collide(User *u, NickAlias *na) override
{
if (na)
collided.Set(na);
if (IRCD->CanSVSNick)
{
- unsigned nicklen = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen");
+ unsigned nicklen = IRCD->GetMaxNick();
const Anope::string &guestprefix = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest");
Anope::string guestnick;
@@ -241,7 +246,7 @@ class NickServCore : public Module, public NickServService
int i = 0;
do
{
- guestnick = guestprefix + stringify(static_cast<uint16_t>(rand()));
+ guestnick = guestprefix + Anope::ToString(static_cast<uint16_t>(Anope::RandomNumber()));
if (guestnick.length() > nicklen)
guestnick = guestnick.substr(0, nicklen);
}
@@ -259,7 +264,7 @@ class NickServCore : public Module, public NickServService
u->Kill(*NickServ, "Services nickname-enforcer kill");
}
- void Release(NickAlias *na) anope_override
+ void Release(NickAlias *na) override
{
if (held.HasExt(na))
{
@@ -279,7 +284,7 @@ class NickServCore : public Module, public NickServService
collided.Unset(na); /* clear pending collide */
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
const Anope::string &nsnick = conf->GetModule(this)->Get<const Anope::string>("client");
@@ -292,18 +297,17 @@ class NickServCore : public Module, public NickServService
NickServ = bi;
- spacesepstream(conf->GetModule(this)->Get<const Anope::string>("defaults", "ns_secure memo_signon memo_receive")).GetTokens(defaults);
+ spacesepstream(conf->GetModule(this)->Get<const Anope::string>("defaults", "memo_signon memo_receive")).GetTokens(defaults);
if (defaults.empty())
{
- defaults.push_back("NS_SECURE");
- defaults.push_back("MEMO_SIGNON");
- defaults.push_back("MEMO_RECEIVE");
+ defaults.emplace_back("MEMO_SIGNON");
+ defaults.emplace_back("MEMO_RECEIVE");
}
else if (defaults[0].equals_ci("none"))
defaults.clear();
}
- void OnDelNick(NickAlias *na) anope_override
+ void OnDelNick(NickAlias *na) override
{
User *u = User::Find(na->nick);
if (u && u->Account() == na->nc)
@@ -314,7 +318,7 @@ class NickServCore : public Module, public NickServService
}
}
- void OnDelCore(NickCore *nc) anope_override
+ void OnDelCore(NickCore *nc) override
{
Log(NickServ, "nick") << "Deleting nickname group " << nc->display;
@@ -330,42 +334,40 @@ class NickServCore : public Module, public NickServService
nc->users.clear();
}
- void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) anope_override
+ void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) override
{
Log(LOG_NORMAL, "nick", NickServ) << "Changing " << nc->display << " nickname group display to " << newdisplay;
}
- void OnNickIdentify(User *u) anope_override
+ void OnNickIdentify(User *u) override
{
Configuration::Block *block = Config->GetModule(this);
if (block->Get<bool>("modeonid", "yes"))
-
- for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it)
+ {
+ for (const auto &[_, cc] : u->chans)
{
- ChanUserContainer *cc = it->second;
Channel *c = cc->chan;
if (c)
c->SetCorrectModes(u, true);
}
+ }
const Anope::string &modesonid = block->Get<const Anope::string>("modesonid");
if (!modesonid.empty())
- u->SetModes(NickServ, "%s", modesonid.c_str());
+ u->SetModes(NickServ, modesonid);
- if (block->Get<bool>("forceemail", "yes") && u->Account()->email.empty())
+ if (u->Account()->email.empty())
{
- u->SendMessage(NickServ, _("You must now supply an e-mail for your nick.\n"
- "This e-mail will allow you to retrieve your password in\n"
+ u->SendMessage(NickServ, _("You must now supply an email for your nick.\n"
+ "This email will allow you to retrieve your password in\n"
"case you forget it."));
- u->SendMessage(NickServ, _("Type \002%s%s SET EMAIL \037e-mail\037\002 in order to set your e-mail.\n"
- "Your privacy is respected; this e-mail won't be given to\n"
- "any third-party person."), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
+ u->SendMessage(NickServ, _("Type \002%s%s SET EMAIL \037email\037\002 in order to set your email."),
+ Config->StrictPrivmsg.c_str(), NickServ->nick.c_str());
}
- for (std::set<NickServCollide *>::iterator it = collides.begin(); it != collides.end(); ++it)
+ for (auto *c : collides)
{
- NickServCollide *c = *it;
if (c->GetUser() == u && c->GetNick() && c->GetNick()->nc == u->Account())
{
delete c;
@@ -374,24 +376,23 @@ class NickServCore : public Module, public NickServService
}
}
- void OnNickGroup(User *u, NickAlias *target) anope_override
+ void OnNickGroup(User *u, NickAlias *target) override
{
if (!target->nc->HasExt("UNCONFIRMED"))
u->SetMode(NickServ, "REGISTERED");
}
- void OnNickUpdate(User *u) anope_override
+ void OnNickUpdate(User *u) override
{
- for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it)
+ for (const auto &[_, cc] : u->chans)
{
- ChanUserContainer *cc = it->second;
Channel *c = cc->chan;
if (c)
c->SetCorrectModes(u, true);
}
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (u->Quitting() || !u->server->IsSynced() || u->server->IsULined())
return;
@@ -405,19 +406,17 @@ class NickServCore : public Module, public NickServService
this->Validate(u);
}
- void OnPostUserLogoff(User *u) anope_override
+ void OnPostUserLogoff(User *u) override
{
NickAlias *na = NickAlias::Find(u->nick);
if (na)
OnCancel(u, na);
}
- void OnServerSync(Server *s) anope_override
+ void OnServerSync(Server *s) override
{
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, u] : UserListByNick)
{
- User *u = it->second;
-
if (u->server == s)
{
if (u->HasMode("REGISTERED") && !u->IsIdentified(true))
@@ -428,7 +427,7 @@ class NickServCore : public Module, public NickServService
}
}
- void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override
+ void OnUserNickChange(User *u, const Anope::string &oldnick) override
{
NickAlias *old_na = NickAlias::Find(oldnick), *na = NickAlias::Find(u->nick);
/* If the new nick isn't registered or it's registered and not yours */
@@ -452,13 +451,13 @@ class NickServCore : public Module, public NickServService
OnCancel(u, old_na);
}
- void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
+ void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override
{
if (u->server->IsSynced() && mname == "REGISTERED" && !u->IsIdentified(true))
u->RemoveMode(NickServ, mname);
}
- EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *NickServ)
return EVENT_CONTINUE;
@@ -478,7 +477,7 @@ class NickServCore : public Module, public NickServService
return EVENT_CONTINUE;
}
- void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *NickServ)
return;
@@ -487,41 +486,41 @@ class NickServCore : public Module, public NickServService
"Services Operators can also drop any nickname without needing\n"
"to identify for the nick, and may view the access list for\n"
"any nickname."));
- time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire", "21d");
+ time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire", "90d");
if (nickserv_expire >= 86400)
source.Reply(_(" \n"
"Accounts that are not used anymore are subject to\n"
"the automatic expiration, i.e. they will be deleted\n"
- "after %d days if not used."), nickserv_expire / 86400);
+ "after %lu days if not used."), (unsigned long)nickserv_expire / 86400);
}
- void OnNickCoreCreate(NickCore *nc) anope_override
+ void OnNickCoreCreate(NickCore *nc) override
{
/* Set default flags */
- for (unsigned i = 0; i < defaults.size(); ++i)
- nc->Extend<bool>(defaults[i].upper());
+ for (const auto &def : defaults)
+ nc->Extend<bool>(def.upper());
}
- void OnUserQuit(User *u, const Anope::string &msg) anope_override
+ void OnUserQuit(User *u, const Anope::string &msg) override
{
if (u->server && !u->server->GetQuitReason().empty() && Config->GetModule(this)->Get<bool>("hidenetsplitquit"))
return;
/* Update last quit and last seen for the user */
NickAlias *na = NickAlias::Find(u->nick);
- if (na && !na->nc->HasExt("NS_SUSPENDED") && (u->IsRecognized() || u->IsIdentified(true)))
+ if (na && !na->nc->HasExt("NS_SUSPENDED") && u->IsIdentified(true))
{
na->last_seen = Anope::CurTime;
na->last_quit = msg;
}
}
- void OnExpireTick() anope_override
+ void OnExpireTick() override
{
if (Anope::NoExpire || Anope::ReadOnly)
return;
- time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire", "21d");
+ time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire", "90d");
for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; )
{
@@ -529,7 +528,7 @@ class NickServCore : public Module, public NickServService
++it;
User *u = User::Find(na->nick, true);
- if (u && (u->IsIdentified(true) || u->IsRecognized()))
+ if (u && u->IsIdentified(true))
na->last_seen = Anope::CurTime;
bool expire = false;
@@ -541,18 +540,18 @@ class NickServCore : public Module, public NickServService
if (expire)
{
- Log(LOG_NORMAL, "nickserv/expire", NickServ) << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (na->nc->email.empty() ? "none" : na->nc->email) << ")";
+ Log(LOG_NORMAL, "nickserv/expire", NickServ) << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (na->nc->email.empty() ? "none" : na->nc->email) << ")";
FOREACH_MOD(OnNickExpire, (na));
delete na;
}
}
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override
{
if (!na->nc->HasExt("UNCONFIRMED"))
{
- time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire", "21d");
+ time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire", "90d");
if (!na->HasExt("NS_NO_EXPIRE") && nickserv_expire && !Anope::NoExpire && (source.HasPriv("nickserv/auspex") || na->last_seen != Anope::CurTime))
info[_("Expires")] = Anope::strftime(na->last_seen + nickserv_expire, source.GetAccount());
}
diff --git a/modules/commands/ns_ajoin.cpp b/modules/nickserv/ns_ajoin.cpp
index 77d393f37..91e700e4a 100644
--- a/modules/commands/ns_ajoin.cpp
+++ b/modules/nickserv/ns_ajoin.cpp
@@ -13,13 +13,15 @@
struct AJoinEntry;
-struct AJoinList : Serialize::Checker<std::vector<AJoinEntry *> >
+struct AJoinList final
+ : Serialize::Checker<std::vector<AJoinEntry *> >
{
AJoinList(Extensible *) : Serialize::Checker<std::vector<AJoinEntry *> >("AJoinEntry") { }
~AJoinList();
};
-struct AJoinEntry : Serializable
+struct AJoinEntry final
+ : Serializable
{
Serialize::Reference<NickCore> owner;
Anope::string channel;
@@ -27,7 +29,7 @@ struct AJoinEntry : Serializable
AJoinEntry(Extensible *) : Serializable("AJoinEntry") { }
- ~AJoinEntry()
+ ~AJoinEntry() override
{
AJoinList *channels = owner->GetExt<AJoinList>("ajoinlist");
if (channels)
@@ -38,7 +40,7 @@ struct AJoinEntry : Serializable
}
}
- void Serialize(Serialize::Data &sd) const anope_override
+ void Serialize(Serialize::Data &sd) const override
{
if (!this->owner)
return;
@@ -48,7 +50,7 @@ struct AJoinEntry : Serializable
sd["key"] << this->key;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &sd)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &sd)
{
Anope::string sowner;
@@ -82,13 +84,14 @@ struct AJoinEntry : Serializable
AJoinList::~AJoinList()
{
- for (unsigned i = 0; i < (*this)->size(); ++i)
- delete (*this)->at(i);
+ for (const auto *ajoin : *(*this))
+ delete ajoin;
}
-class CommandNSAJoin : public Command
+class CommandNSAJoin final
+ : public Command
{
- void DoList(CommandSource &source, NickCore *nc)
+ static void DoList(CommandSource &source, NickCore *nc)
{
AJoinList *channels = nc->Require<AJoinList>("ajoinlist");
@@ -102,7 +105,7 @@ class CommandNSAJoin : public Command
{
AJoinEntry *aj = (*channels)->at(i);
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Channel"] = aj->channel;
entry["Key"] = aj->key;
list.AddEntry(entry);
@@ -113,8 +116,8 @@ class CommandNSAJoin : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
@@ -143,7 +146,7 @@ class CommandNSAJoin : public Command
}
else if (i != (*channels)->size())
alreadyadded += chan + ", ";
- else if (IRCD->IsChannelValid(chan) == false)
+ else if (!IRCD->IsChannelValid(chan))
source.Reply(CHAN_X_INVALID, chan.c_str());
else
{
@@ -155,7 +158,7 @@ class CommandNSAJoin : public Command
continue;
}
- AJoinEntry *entry = new AJoinEntry(nc);
+ auto *entry = new AJoinEntry(nc);
entry->owner = nc;
entry->channel = chan;
entry->key = key;
@@ -224,7 +227,7 @@ class CommandNSAJoin : public Command
nc->Shrink<AJoinList>("ajoinlist");
}
- public:
+public:
CommandNSAJoin(Module *creator) : Command(creator, "nickserv/ajoin", 1, 4)
{
this->SetDesc(_("Manage your auto join list"));
@@ -233,7 +236,7 @@ class CommandNSAJoin : public Command
this->SetSyntax(_("LIST [\037nickname\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
Anope::string nick, param, param2;
@@ -285,7 +288,7 @@ class CommandNSAJoin : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -297,13 +300,14 @@ class CommandNSAJoin : public Command
}
};
-class NSAJoin : public Module
+class NSAJoin final
+ : public Module
{
CommandNSAJoin commandnsajoin;
ExtensibleItem<AJoinList> ajoinlist;
Serialize::Type ajoinentry_type;
- public:
+public:
NSAJoin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsajoin(this), ajoinlist(this, "ajoinlist"),
ajoinentry_type("AJoinEntry", AJoinEntry::Unserialize)
@@ -314,7 +318,7 @@ class NSAJoin : public Module
}
- void OnUserLogin(User *u) anope_override
+ void OnUserLogin(User *u) override
{
BotInfo *NickServ = Config->GetClient("NickServ");
if (!NickServ)
@@ -327,9 +331,8 @@ class NSAJoin : public Module
/* Set +r now, so we can ajoin users into +R channels */
ModeManager::ProcessModes();
- for (unsigned i = 0; i < (*channels)->size(); ++i)
+ for (auto *entry : *(*channels))
{
- AJoinEntry *entry = (*channels)->at(i);
Channel *c = Channel::Find(entry->channel);
ChannelInfo *ci;
@@ -356,11 +359,11 @@ class NSAJoin : public Module
continue;
else if (c->HasMode("ADMINONLY") && !u->HasMode("ADMIN"))
continue;
- else if (c->HasMode("SSL") && !(u->HasMode("SSL") || u->HasExt("ssl")))
+ else if (c->HasMode("SSL") && !u->IsSecurelyConnected())
continue;
- else if (c->MatchesList(u, "BAN") == true && c->MatchesList(u, "EXCEPT") == false)
+ else if (c->MatchesList(u, "BAN") && !c->MatchesList(u, "EXCEPT"))
need_invite = true;
- else if (c->HasMode("INVITE") && c->MatchesList(u, "INVITEOVERRIDE") == false)
+ else if (c->HasMode("INVITE") && !c->MatchesList(u, "INVITEOVERRIDE"))
need_invite = true;
if (c->HasMode("KEY"))
@@ -379,13 +382,11 @@ class NSAJoin : public Module
Anope::string l;
if (c->GetParam("LIMIT", l))
{
- try
+ if (auto limit = Anope::TryConvert<unsigned>(l))
{
- unsigned limit = convertTo<unsigned>(l);
- if (c->users.size() >= limit)
+ if (c->users.size() >= limit.value())
need_invite = true;
}
- catch (const ConvertException &) { }
}
}
}
diff --git a/modules/commands/ns_alist.cpp b/modules/nickserv/ns_alist.cpp
index e34b3b2ee..0d02894af 100644
--- a/modules/commands/ns_alist.cpp
+++ b/modules/nickserv/ns_alist.cpp
@@ -11,21 +11,22 @@
#include "module.h"
-class CommandNSAList : public Command
+class CommandNSAList final
+ : public Command
{
static bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2)
{
return ci::less()(ci1->name, ci2->name);
}
- public:
+public:
CommandNSAList(Module *creator) : Command(creator, "nickserv/alist", 0, 2)
{
this->SetDesc(_("List channels you have access on"));
this->SetSyntax(_("[\037nickname\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string nick = source.GetNick();
NickCore *nc = source.nc;
@@ -51,15 +52,14 @@ class CommandNSAList : public Command
nc->GetChannelReferences(queue);
std::sort(queue.begin(), queue.end(), ChannelSort);
- for (unsigned i = 0; i < queue.size(); ++i)
+ for (auto *ci : queue)
{
- ChannelInfo *ci = queue[i];
ListFormatter::ListEntry entry;
if (ci->GetFounder() == nc)
{
++chan_count;
- entry["Number"] = stringify(chan_count);
+ entry["Number"] = Anope::ToString(chan_count);
entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
entry["Access"] = Language::Translate(source.GetAccount(), _("Founder"));
entry["Description"] = ci->desc;
@@ -70,7 +70,7 @@ class CommandNSAList : public Command
if (ci->GetSuccessor() == nc)
{
++chan_count;
- entry["Number"] = stringify(chan_count);
+ entry["Number"] = Anope::ToString(chan_count);
entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
entry["Access"] = Language::Translate(source.GetAccount(), _("Successor"));
entry["Description"] = ci->desc;
@@ -84,12 +84,10 @@ class CommandNSAList : public Command
++chan_count;
- entry["Number"] = stringify(chan_count);
+ entry["Number"] = Anope::ToString(chan_count);
entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
- for (unsigned j = 0; j < access.paths.size(); ++j)
+ for (auto &p : access.paths)
{
- ChanAccess::Path &p = access.paths[j];
-
// not interested in indirect access
if (p.size() != 1)
continue;
@@ -113,14 +111,14 @@ class CommandNSAList : public Command
{
source.Reply(_("Channels that \002%s\002 has access on:"), nc->display.c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of list - %d channels shown."), chan_count);
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -134,11 +132,12 @@ class CommandNSAList : public Command
}
};
-class NSAList : public Module
+class NSAList final
+ : public Module
{
CommandNSAList commandnsalist;
- public:
+public:
NSAList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsalist(this)
{
diff --git a/modules/commands/ns_cert.cpp b/modules/nickserv/ns_cert.cpp
index 7fe4c08be..1c9d0ae80 100644
--- a/modules/commands/ns_cert.cpp
+++ b/modules/nickserv/ns_cert.cpp
@@ -12,30 +12,32 @@
#include "module.h"
#include "modules/ns_cert.h"
-static Anope::hash_map<NickCore *> certmap;
+static Anope::unordered_map<NickCore *> certmap;
-struct CertServiceImpl : CertService
+struct CertServiceImpl final
+ : CertService
{
CertServiceImpl(Module *o) : CertService(o) { }
- NickCore* FindAccountFromCert(const Anope::string &cert) anope_override
+ NickCore *FindAccountFromCert(const Anope::string &cert) override
{
- Anope::hash_map<NickCore *>::iterator it = certmap.find(cert);
+ Anope::unordered_map<NickCore *>::iterator it = certmap.find(cert);
if (it != certmap.end())
return it->second;
return NULL;
}
};
-struct NSCertListImpl : NSCertList
+struct NSCertListImpl final
+ : NSCertList
{
Serialize::Reference<NickCore> nc;
std::vector<Anope::string> certs;
- public:
+public:
NSCertListImpl(Extensible *obj) : nc(anope_dynamic_static_cast<NickCore *>(obj)) { }
- ~NSCertListImpl()
+ ~NSCertListImpl() override
{
ClearCert();
}
@@ -46,7 +48,7 @@ struct NSCertListImpl : NSCertList
*
* Adds a new entry into the cert list.
*/
- void AddCert(const Anope::string &entry) anope_override
+ void AddCert(const Anope::string &entry) override
{
this->certs.push_back(entry);
certmap[entry] = nc;
@@ -60,14 +62,14 @@ struct NSCertListImpl : NSCertList
*
* Retrieves an entry from the certificate list corresponding to the given index.
*/
- Anope::string GetCert(unsigned entry) const anope_override
+ Anope::string GetCert(unsigned entry) const override
{
if (entry >= this->certs.size())
return "";
return this->certs[entry];
}
- unsigned GetCertCount() const anope_override
+ unsigned GetCertCount() const override
{
return this->certs.size();
}
@@ -79,7 +81,7 @@ struct NSCertListImpl : NSCertList
*
* Search for an fingerprint within the cert list.
*/
- bool FindCert(const Anope::string &entry) const anope_override
+ bool FindCert(const Anope::string &entry) const override
{
return std::find(this->certs.begin(), this->certs.end(), entry) != this->certs.end();
}
@@ -90,7 +92,7 @@ struct NSCertListImpl : NSCertList
*
* Removes the specified fingerprint from the cert list.
*/
- void EraseCert(const Anope::string &entry) anope_override
+ void EraseCert(const Anope::string &entry) override
{
std::vector<Anope::string>::iterator it = std::find(this->certs.begin(), this->certs.end(), entry);
if (it != this->certs.end())
@@ -101,29 +103,43 @@ struct NSCertListImpl : NSCertList
}
}
+ void ReplaceCert(const Anope::string &oldentry, const Anope::string &newentry) override
+ {
+ auto it = std::find(this->certs.begin(), this->certs.end(), oldentry);
+ if (it == this->certs.end())
+ return; // We can't replace a non-existent cert.
+
+ FOREACH_MOD(OnNickEraseCert, (this->nc, oldentry));
+ certmap.erase(oldentry);
+ *it = newentry;
+ certmap[newentry] = nc;
+ FOREACH_MOD(OnNickAddCert, (this->nc, newentry));
+ }
+
/** Clears the entire nick's cert list
*
* Deletes all the memory allocated in the certificate list vector and then clears the vector.
*/
- void ClearCert() anope_override
+ void ClearCert() override
{
FOREACH_MOD(OnNickClearCert, (this->nc));
- for (unsigned i = 0; i < certs.size(); ++i)
- certmap.erase(certs[i]);
+ for (const auto &cert : certs)
+ certmap.erase(cert);
this->certs.clear();
}
- void Check() anope_override
+ void Check() override
{
if (this->certs.empty())
nc->Shrink<NSCertList>("certificates");
}
- struct ExtensibleItem : ::ExtensibleItem<NSCertListImpl>
+ struct ExtensibleItem final
+ : ::ExtensibleItem<NSCertListImpl>
{
ExtensibleItem(Module *m, const Anope::string &ename) : ::ExtensibleItem<NSCertListImpl>(m, ename) { }
- void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
+ void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
{
if (s->GetSerializableType()->GetName() != "NickCore")
return;
@@ -137,7 +153,7 @@ struct NSCertListImpl : NSCertList
data["cert"] << c->GetCert(i) << " ";
}
- void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
+ void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
{
if (s->GetSerializableType()->GetName() != "NickCore")
return;
@@ -148,8 +164,8 @@ struct NSCertListImpl : NSCertList
Anope::string buf;
data["cert"] >> buf;
spacesepstream sep(buf);
- for (unsigned i = 0; i < c->certs.size(); ++i)
- certmap.erase(c->certs[i]);
+ for (const auto &cert : c->certs)
+ certmap.erase(cert);
c->certs.clear();
while (sep.GetToken(buf))
{
@@ -160,9 +176,10 @@ struct NSCertListImpl : NSCertList
};
};
-class CommandNSCert : public Command
+class CommandNSCert final
+ : public Command
{
- private:
+private:
void DoAdd(CommandSource &source, NickCore *nc, Anope::string certfp)
{
NSCertList *cl = nc->Require<NSCertList>("certificates");
@@ -233,7 +250,7 @@ class CommandNSCert : public Command
source.Reply(_("\002%s\002 deleted from %s's certificate list."), certfp.c_str(), nc->display.c_str());
}
- void DoList(CommandSource &source, const NickCore *nc)
+ static void DoList(CommandSource &source, const NickCore *nc)
{
NSCertList *cl = nc->GetExt<NSCertList>("certificates");
@@ -251,7 +268,7 @@ class CommandNSCert : public Command
}
}
- public:
+public:
CommandNSCert(Module *creator) : Command(creator, "nickserv/cert", 1, 3)
{
this->SetDesc(_("Modify the nickname client certificate list"));
@@ -260,7 +277,7 @@ class CommandNSCert : public Command
this->SetSyntax(_("LIST [\037nickname\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
Anope::string nick, certfp;
@@ -282,7 +299,7 @@ class CommandNSCert : public Command
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
return;
}
- else if (na->nc != source.GetAccount() && !source.HasPriv("nickserv/access"))
+ else if (na->nc != source.GetAccount() && !source.HasPriv("nickserv/cert"))
{
source.Reply(ACCESS_DENIED);
return;
@@ -312,7 +329,7 @@ class CommandNSCert : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -338,13 +355,14 @@ class CommandNSCert : public Command
}
};
-class NSCert : public Module
+class NSCert final
+ : public Module
{
CommandNSCert commandnscert;
NSCertListImpl::ExtensibleItem certs;
CertServiceImpl cs;
- public:
+public:
NSCert(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnscert(this), certs(this, "certificates"), cs(this)
{
@@ -352,7 +370,7 @@ class NSCert : public Module
throw ModuleException("Your IRCd does not support ssl client certificates");
}
- void OnFingerprint(User *u) anope_override
+ void OnFingerprint(User *u) override
{
BotInfo *NickServ = Config->GetClient("NickServ");
if (!NickServ || u->IsIdentified())
@@ -379,7 +397,7 @@ class NSCert : public Module
Log(NickServ) << u->GetMask() << " automatically identified for account " << nc->display << " via SSL certificate fingerprint";
}
- EventReturn OnNickValidate(User *u, NickAlias *na) anope_override
+ EventReturn OnNickValidate(User *u, NickAlias *na) override
{
NSCertList *cl = certs.Get(na->nc);
if (!u->fingerprint.empty() && cl && cl->FindCert(u->fingerprint))
diff --git a/modules/commands/ns_drop.cpp b/modules/nickserv/ns_drop.cpp
index e77ac278e..a315deab5 100644
--- a/modules/commands/ns_drop.cpp
+++ b/modules/nickserv/ns_drop.cpp
@@ -11,16 +11,22 @@
#include "module.h"
-class CommandNSDrop : public Command
+class CommandNSDrop final
+ : public Command
{
- public:
- CommandNSDrop(Module *creator) : Command(creator, "nickserv/drop", 1, 1)
+private:
+ PrimitiveExtensibleItem<Anope::string> dropcode;
+
+public:
+ CommandNSDrop(Module *creator)
+ : Command(creator, "nickserv/drop", 1, 2)
+ , dropcode(creator, "nickname-dropcode")
{
- this->SetSyntax(_("\037nickname\037"));
+ this->SetSyntax(_("\037nickname\037 [\037code\037]"));
this->SetDesc(_("Cancel the registration of a nickname"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = params[0];
@@ -40,21 +46,39 @@ class CommandNSDrop : public Command
bool is_mine = source.GetAccount() == na->nc;
if (!is_mine && !source.HasPriv("nickserv/drop"))
+ {
source.Reply(ACCESS_DENIED);
- else if (Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && !is_mine && na->nc->IsServicesOper())
- source.Reply(_("You may not drop other Services Operators' nicknames."));
- else
+ return;
+ }
+
+ if (Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && !is_mine && na->nc->IsServicesOper())
{
- FOREACH_MOD(OnNickDrop, (source, na));
+ source.Reply(_("You may not drop other Services Operators' nicknames."));
+ return;
+ }
- Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")";
- delete na;
+ auto *code = dropcode.Get(na);
+ if (params.size() < 2 || !code || !code->equals_ci(params[1]))
+ {
+ if (!code)
+ {
+ code = na->Extend<Anope::string>("nickname-dropcode");
+ *code = Anope::Random(15);
+ }
- source.Reply(_("Nickname \002%s\002 has been dropped."), nick.c_str());
+ source.Reply(CONFIRM_DROP, na->nick.c_str(), na->nick.c_str(), code->c_str());
+ return;
}
+
+ FOREACH_MOD(OnNickDrop, (source, na));
+
+ Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")";
+ delete na;
+
+ source.Reply(_("Nickname \002%s\002 has been dropped."), nick.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -71,11 +95,12 @@ class CommandNSDrop : public Command
}
};
-class NSDrop : public Module
+class NSDrop final
+ : public Module
{
CommandNSDrop commandnsdrop;
- public:
+public:
NSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsdrop(this)
{
diff --git a/modules/commands/ns_getemail.cpp b/modules/nickserv/ns_getemail.cpp
index b4589f716..e85fc12d6 100644
--- a/modules/commands/ns_getemail.cpp
+++ b/modules/nickserv/ns_getemail.cpp
@@ -15,26 +15,25 @@
#include "module.h"
-class CommandNSGetEMail : public Command
+class CommandNSGetEMail final
+ : public Command
{
- public:
+public:
CommandNSGetEMail(Module *creator) : Command(creator, "nickserv/getemail", 1, 1)
{
this->SetDesc(_("Matches and returns all users that registered using given email"));
this->SetSyntax(_("\037email\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &email = params[0];
int j = 0;
Log(LOG_ADMIN, source, this) << "on " << email;
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- const NickCore *nc = it->second;
-
if (!nc->email.empty() && Anope::Match(nc->email, email))
{
++j;
@@ -51,7 +50,7 @@ class CommandNSGetEMail : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -60,10 +59,11 @@ class CommandNSGetEMail : public Command
}
};
-class NSGetEMail : public Module
+class NSGetEMail final
+ : public Module
{
CommandNSGetEMail commandnsgetemail;
- public:
+public:
NSGetEMail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsgetemail(this)
{
diff --git a/modules/commands/ns_group.cpp b/modules/nickserv/ns_group.cpp
index 0bc49da5c..58ded41b4 100644
--- a/modules/commands/ns_group.cpp
+++ b/modules/nickserv/ns_group.cpp
@@ -12,17 +12,18 @@
#include "module.h"
#include "modules/ns_cert.h"
-class NSGroupRequest : public IdentifyRequest
+class NSGroupRequest final
+ : public IdentifyRequest
{
CommandSource source;
Command *cmd;
Anope::string nick;
Reference<NickAlias> target;
- public:
+public:
NSGroupRequest(Module *o, CommandSource &src, Command *c, const Anope::string &n, NickAlias *targ, const Anope::string &pass) : IdentifyRequest(o, targ->nc->display, pass), source(src), cmd(c), nick(n), target(targ) { }
- void OnSuccess() anope_override
+ void OnSuccess() override
{
User *u = source.GetUser();
@@ -67,7 +68,7 @@ class NSGroupRequest : public IdentifyRequest
u->lastnickreg = Anope::CurTime;
}
- void OnFail() anope_override
+ void OnFail() override
{
User *u = source.GetUser();
@@ -83,9 +84,10 @@ class NSGroupRequest : public IdentifyRequest
}
};
-class CommandNSGroup : public Command
+class CommandNSGroup final
+ : public Command
{
- public:
+public:
CommandNSGroup(Module *creator) : Command(creator, "nickserv/group", 0, 2)
{
this->SetDesc(_("Join a group"));
@@ -93,14 +95,14 @@ class CommandNSGroup : public Command
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
User *user = source.GetUser();
Anope::string nick;
if (params.empty())
{
- NickCore* core = source.GetAccount();
+ NickCore *core = source.GetAccount();
if (core)
nick = core->display;
}
@@ -128,16 +130,16 @@ class CommandNSGroup : public Command
}
if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks"))
- for (unsigned i = 0; i < Oper::opers.size(); ++i)
+ {
+ for (auto *o : Oper::opers)
{
- Oper *o = Oper::opers[i];
-
if (user != NULL && !user->HasMode("OPER") && user->nick.find_ci(o->name) != Anope::string::npos)
{
source.Reply(NICK_CANNOT_BE_REGISTERED, user->nick.c_str());
return;
}
}
+ }
NickAlias *target, *na = NickAlias::Find(source.GetNick());
const Anope::string &guestnick = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest");
@@ -146,7 +148,7 @@ class CommandNSGroup : public Command
if (!(target = NickAlias::Find(nick)))
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
else if (user && Anope::CurTime < user->lastnickreg + reg_delay)
- source.Reply(_("Please wait %d seconds before using the GROUP command again."), (reg_delay + user->lastnickreg) - Anope::CurTime);
+ source.Reply(_("Please wait %lu seconds before using the GROUP command again."), (unsigned long)(reg_delay + user->lastnickreg) - Anope::CurTime);
else if (target->nc->HasExt("NS_SUSPENDED"))
{
Log(LOG_COMMAND, source, this) << "and tried to group to SUSPENDED nick " << target->nick;
@@ -176,9 +178,9 @@ class CommandNSGroup : public Command
if (user != NULL && !user->fingerprint.empty() && cl && cl->FindCert(user->fingerprint))
ok = true;
- if (ok == false && !pass.empty())
+ if (!ok && !pass.empty())
{
- NSGroupRequest *req = new NSGroupRequest(owner, source, this, source.GetNick(), target, pass);
+ auto *req = new NSGroupRequest(owner, source, this, source.GetNick(), target, pass);
FOREACH_MOD(OnCheckAuthentication, (source.GetUser(), req));
req->Dispatch();
}
@@ -194,7 +196,7 @@ class CommandNSGroup : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -228,16 +230,17 @@ class CommandNSGroup : public Command
}
};
-class CommandNSUngroup : public Command
+class CommandNSUngroup final
+ : public Command
{
- public:
+public:
CommandNSUngroup(Module *creator) : Command(creator, "nickserv/ungroup", 0, 1)
{
this->SetDesc(_("Remove a nick from a group"));
this->SetSyntax(_("[\037nick\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string nick = !params.empty() ? params[0] : "";
NickAlias *na = NickAlias::Find(!nick.empty() ? nick : source.GetNick());
@@ -259,7 +262,7 @@ class CommandNSUngroup : public Command
if (na->nick.equals_ci(oldcore->display))
oldcore->SetDisplay(oldcore->aliases->front());
- NickCore *nc = new NickCore(na->nick);
+ auto *nc = new NickCore(na->nick);
na->nc = nc;
nc->aliases->push_back(na);
@@ -278,7 +281,7 @@ class CommandNSUngroup : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -291,15 +294,16 @@ class CommandNSUngroup : public Command
}
};
-class CommandNSGList : public Command
+class CommandNSGList final
+ : public Command
{
- public:
+public:
CommandNSGList(Module *creator) : Command(creator, "nickserv/glist", 0, 1)
{
this->SetDesc(_("Lists all nicknames in your group"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = !params.empty() ? params[0] : "";
const NickCore *nc;
@@ -325,12 +329,10 @@ class CommandNSGList : public Command
ListFormatter list(source.GetAccount());
list.AddColumn(_("Nick")).AddColumn(_("Expires"));
- time_t nickserv_expire = Config->GetModule("nickserv")->Get<time_t>("expire", "21d"),
+ time_t nickserv_expire = Config->GetModule("nickserv")->Get<time_t>("expire", "90d"),
unconfirmed_expire = Config->GetModule("ns_register")->Get<time_t>("unconfirmedexpire", "1d");
- for (unsigned i = 0; i < nc->aliases->size(); ++i)
+ for (auto *na2 : *nc->aliases)
{
- const NickAlias *na2 = nc->aliases->at(i);
-
Anope::string expires;
if (na2->HasExt("NS_NO_EXPIRE"))
expires = NO_EXPIRE;
@@ -351,13 +353,13 @@ class CommandNSGList : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
- source.Reply(_("%d nickname(s) in the group."), nc->aliases->size());
+ source.Reply(_("%zu nickname(s) in the group."), nc->aliases->size());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (source.IsServicesOper())
source.Reply(_("Syntax: \002%s [\037nickname\037]\002\n"
@@ -378,13 +380,14 @@ class CommandNSGList : public Command
}
};
-class NSGroup : public Module
+class NSGroup final
+ : public Module
{
CommandNSGroup commandnsgroup;
CommandNSUngroup commandnsungroup;
CommandNSGList commandnsglist;
- public:
+public:
NSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsgroup(this), commandnsungroup(this), commandnsglist(this)
{
diff --git a/modules/commands/ns_identify.cpp b/modules/nickserv/ns_identify.cpp
index e0d0f601a..e945c6ece 100644
--- a/modules/commands/ns_identify.cpp
+++ b/modules/nickserv/ns_identify.cpp
@@ -11,15 +11,16 @@
#include "module.h"
-class NSIdentifyRequest : public IdentifyRequest
+class NSIdentifyRequest final
+ : public IdentifyRequest
{
CommandSource source;
Command *cmd;
- public:
+public:
NSIdentifyRequest(Module *o, CommandSource &s, Command *c, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(o, acc, pass), source(s), cmd(c) { }
- void OnSuccess() anope_override
+ void OnSuccess() override
{
if (!source.GetUser())
return;
@@ -40,7 +41,7 @@ class NSIdentifyRequest : public IdentifyRequest
}
}
- void OnFail() anope_override
+ void OnFail() override
{
if (source.GetUser())
{
@@ -57,9 +58,10 @@ class NSIdentifyRequest : public IdentifyRequest
}
};
-class CommandNSIdentify : public Command
+class CommandNSIdentify final
+ : public Command
{
- public:
+public:
CommandNSIdentify(Module *creator) : Command(creator, "nickserv/identify", 1, 2)
{
this->SetDesc(_("Identify yourself with your password"));
@@ -68,7 +70,7 @@ class CommandNSIdentify : public Command
this->RequireUser(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
User *u = source.GetUser();
@@ -95,12 +97,12 @@ class CommandNSIdentify : public Command
return;
}
- NSIdentifyRequest *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass);
+ auto *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass);
FOREACH_MOD(OnCheckAuthentication, (u, req));
req->Dispatch();
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -113,11 +115,12 @@ class CommandNSIdentify : public Command
}
};
-class NSIdentify : public Module
+class NSIdentify final
+ : public Module
{
CommandNSIdentify commandnsidentify;
- public:
+public:
NSIdentify(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsidentify(this)
{
diff --git a/modules/commands/ns_info.cpp b/modules/nickserv/ns_info.cpp
index 8a01a6143..469a0c1f3 100644
--- a/modules/commands/ns_info.cpp
+++ b/modules/nickserv/ns_info.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandNSInfo : public Command
+class CommandNSInfo final
+ : public Command
{
- public:
+public:
CommandNSInfo(Module *creator) : Command(creator, "nickserv/info", 0, 2)
{
this->SetDesc(_("Displays information about a given nickname"));
@@ -21,7 +22,7 @@ class CommandNSInfo : public Command
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = params.size() ? params[0] : (source.nc ? source.nc->display : source.GetNick());
@@ -101,12 +102,7 @@ class CommandNSInfo : public Command
if (show_hidden)
{
if (na->HasVhost())
- {
- if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
- info[_("VHost")] = na->GetVhostIdent() + "@" + na->GetVhostHost();
- else
- info[_("VHost")] = na->GetVhostHost();
- }
+ info[_("VHost")] = na->GetVhostMask();
}
FOREACH_MOD(OnNickInfo, (source, na, info, show_hidden));
@@ -114,12 +110,12 @@ class CommandNSInfo : public Command
std::vector<Anope::string> replies;
info.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -134,9 +130,10 @@ class CommandNSInfo : public Command
};
-class CommandNSSetHide : public Command
+class CommandNSSetHide
+ : public Command
{
- public:
+public:
CommandNSSetHide(Module *creator, const Anope::string &sname = "nickserv/set/hide", size_t min = 2) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Hide certain pieces of nickname information"));
@@ -169,8 +166,8 @@ class CommandNSSetHide : public Command
if (param.equals_ci("EMAIL"))
{
flag = "HIDE_EMAIL";
- onmsg = _("The E-mail address of \002%s\002 will now be hidden from %s INFO displays.");
- offmsg = _("The E-mail address of \002%s\002 will now be shown in %s INFO displays.");
+ onmsg = _("The email address of \002%s\002 will now be hidden from %s INFO displays.");
+ offmsg = _("The email address of \002%s\002 will now be shown in %s INFO displays.");
}
else if (param.equals_ci("USERMASK"))
{
@@ -212,18 +209,18 @@ class CommandNSSetHide : public Command
this->OnSyntaxError(source, "HIDE");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows you to prevent certain pieces of information from\n"
"being displayed when someone does a %s \002INFO\002 on your\n"
- "nick. You can hide your E-mail address (\002EMAIL\002), last seen\n"
+ "nick. You can hide your email address (\002EMAIL\002), last seen\n"
"user@host mask (\002USERMASK\002), your services access status\n"
"(\002STATUS\002) and last quit message (\002QUIT\002).\n"
"The second parameter specifies whether the information should\n"
@@ -232,27 +229,28 @@ class CommandNSSetHide : public Command
}
};
-class CommandNSSASetHide : public CommandNSSetHide
+class CommandNSSASetHide final
+ : public CommandNSSetHide
{
- public:
+public:
CommandNSSASetHide(Module *creator) : CommandNSSetHide(creator, "nickserv/saset/hide", 3)
{
this->SetSyntax(_("\037nickname\037 {EMAIL | STATUS | USERMASK | QUIT} {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->ClearSyntax();
this->Run(source, params[0], params[1], params[2]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows you to prevent certain pieces of information from\n"
"being displayed when someone does a %s \002INFO\002 on the\n"
- "nick. You can hide the E-mail address (\002EMAIL\002), last seen\n"
+ "nick. You can hide the email address (\002EMAIL\002), last seen\n"
"user@host mask (\002USERMASK\002), the services access status\n"
"(\002STATUS\002) and last quit message (\002QUIT\002).\n"
"The second parameter specifies whether the information should\n"
@@ -261,7 +259,8 @@ class CommandNSSASetHide : public CommandNSSetHide
}
};
-class NSInfo : public Module
+class NSInfo final
+ : public Module
{
CommandNSInfo commandnsinfo;
@@ -270,7 +269,7 @@ class NSInfo : public Module
SerializableExtensibleItem<bool> hide_email, hide_usermask, hide_status, hide_quit;
- public:
+public:
NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsinfo(this), commandnssethide(this), commandnssasethide(this),
hide_email(this, "HIDE_EMAIL"), hide_usermask(this, "HIDE_MASK"), hide_status(this, "HIDE_STATUS"),
diff --git a/modules/commands/ns_list.cpp b/modules/nickserv/ns_list.cpp
index 9e4971dce..1bd4ea043 100644
--- a/modules/commands/ns_list.cpp
+++ b/modules/nickserv/ns_list.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandNSList : public Command
+class CommandNSList final
+ : public Command
{
- public:
+public:
CommandNSList(Module *creator) : Command(creator, "nickserv/list", 1, 2)
{
this->SetDesc(_("List all registered nicknames that match a given pattern"));
this->SetSyntax(_("\037pattern\037 [SUSPENDED] [NOEXPIRE] [UNCONFIRMED]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string pattern = params[0];
@@ -38,17 +39,17 @@ class CommandNSList : public Command
Anope::string n1, n2;
sepstream(pattern.substr(1), '-').GetToken(n1, 0);
sepstream(pattern, '-').GetToken(n2, 1);
- try
- {
- from = convertTo<int>(n1);
- to = convertTo<int>(n2);
- }
- catch (const ConvertException &)
+
+ auto num1 = Anope::TryConvert<int>(n1);
+ auto num2 = Anope::TryConvert<int>(n2);
+ if (!num1.has_value() || !num2.has_value())
{
source.Reply(LIST_INCORRECT_RANGE);
return;
}
+ from = num1.value();
+ to = num2.value();
pattern = "*";
}
@@ -75,13 +76,11 @@ class CommandNSList : public Command
list.AddColumn(_("Nick")).AddColumn(_("Last usermask"));
Anope::map<NickAlias *> ordered_map;
- for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
- ordered_map[it->first] = it->second;
+ for (const auto &[nick, na] : *NickAliasList)
+ ordered_map[nick] = na;
- for (Anope::map<NickAlias *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it)
+ for (const auto &[_, na] : ordered_map)
{
- const NickAlias *na = it->second;
-
/* Don't show private nicks to non-services admins. */
if (na->nc->HasExt("NS_PRIVATE") && !is_servadmin && na->nc != mync)
continue;
@@ -125,14 +124,14 @@ class CommandNSList : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of list - %d/%d matches shown."), nnicks > listmax ? listmax : nnicks, nnicks);
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -178,9 +177,10 @@ class CommandNSList : public Command
};
-class CommandNSSetPrivate : public Command
+class CommandNSSetPrivate
+ : public Command
{
- public:
+public:
CommandNSSetPrivate(Module *creator, const Anope::string &sname = "nickserv/set/private", size_t min = 1) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Prevent the nickname from appearing in the LIST command"));
@@ -224,12 +224,12 @@ class CommandNSSetPrivate : public Command
this->OnSyntaxError(source, "PRIVATE");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -243,21 +243,22 @@ class CommandNSSetPrivate : public Command
}
};
-class CommandNSSASetPrivate : public CommandNSSetPrivate
+class CommandNSSASetPrivate final
+ : public CommandNSSetPrivate
{
- public:
+public:
CommandNSSASetPrivate(Module *creator) : CommandNSSetPrivate(creator, "nickserv/saset/private", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -272,7 +273,8 @@ class CommandNSSASetPrivate : public CommandNSSetPrivate
};
-class NSList : public Module
+class NSList final
+ : public Module
{
CommandNSList commandnslist;
@@ -281,14 +283,14 @@ class NSList : public Module
SerializableExtensibleItem<bool> priv;
- public:
+public:
NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnslist(this), commandnssetprivate(this), commandnssasetprivate(this),
priv(this, "NS_PRIVATE")
{
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_all) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_all) override
{
if (!show_all)
return;
diff --git a/modules/commands/ns_logout.cpp b/modules/nickserv/ns_logout.cpp
index 6352c7f25..8b92f7558 100644
--- a/modules/commands/ns_logout.cpp
+++ b/modules/nickserv/ns_logout.cpp
@@ -13,16 +13,17 @@
static ServiceReference<NickServService> NickServService("NickServService", "NickServ");
-class CommandNSLogout : public Command
+class CommandNSLogout final
+ : public Command
{
- public:
+public:
CommandNSLogout(Module *creator) : Command(creator, "nickserv/logout", 0, 2)
{
this->SetDesc(_("Reverses the effect of the IDENTIFY command"));
this->SetSyntax(_("[\037nickname\037 [REVALIDATE]]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = !params.empty() ? params[0] : "";
@@ -59,7 +60,7 @@ class CommandNSLogout : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -69,18 +70,19 @@ class CommandNSLogout : public Command
"yourself.\n"
" \n"
"With a parameter, does the same for the given nick. If you\n"
- "specify \002REVALIDATE\002 as well, Services will ask the given nick\n"
+ "specify \002REVALIDATE\002 as well, services will ask the given nick\n"
"to re-identify. This is limited to \002Services Operators\002."));
return true;
}
};
-class NSLogout : public Module
+class NSLogout final
+ : public Module
{
CommandNSLogout commandnslogout;
- public:
+public:
NSLogout(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnslogout(this)
{
diff --git a/modules/ns_maxemail.cpp b/modules/nickserv/ns_maxemail.cpp
index f86e49b70..342ba3c3d 100644
--- a/modules/ns_maxemail.cpp
+++ b/modules/nickserv/ns_maxemail.cpp
@@ -12,12 +12,13 @@
#include "module.h"
-class NSMaxEmail : public Module
+class NSMaxEmail final
+ : public Module
{
- bool clean;
+ bool clean = false;
/* strip dots from username, and remove anything after the first + */
- Anope::string CleanMail(const Anope::string &email)
+ static Anope::string CleanMail(const Anope::string &email)
{
size_t host = email.find('@');
if (host == Anope::string::npos)
@@ -62,10 +63,8 @@ class NSMaxEmail : public Module
Anope::string cleanemail = clean ? CleanMail(email) : email;
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- const NickCore *nc = it->second;
-
Anope::string cleannc = clean ? CleanMail(nc->email) : nc->email;
if (unc != nc && cleanemail.equals_ci(cleannc))
@@ -75,18 +74,17 @@ class NSMaxEmail : public Module
return count;
}
- public:
+public:
NSMaxEmail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , clean(false)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
clean = conf->GetModule(this)->Get<bool>("remove_aliases", "true");
}
- EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
if (source.IsOper())
return EVENT_CONTINUE;
diff --git a/modules/commands/ns_recover.cpp b/modules/nickserv/ns_recover.cpp
index 28f07519d..d77dbc898 100644
--- a/modules/commands/ns_recover.cpp
+++ b/modules/nickserv/ns_recover.cpp
@@ -16,23 +16,24 @@ static ServiceReference<NickServService> nickserv("NickServService", "NickServ")
typedef std::map<Anope::string, ChannelStatus> NSRecoverInfo;
-class NSRecoverSvsnick
+class NSRecoverSvsnick final
{
- public:
+public:
Reference<User> from;
Anope::string to;
};
-class NSRecoverRequest : public IdentifyRequest
+class NSRecoverRequest final
+ : public IdentifyRequest
{
CommandSource source;
Command *cmd;
Anope::string user;
- public:
+public:
NSRecoverRequest(Module *o, CommandSource &src, Command *c, const Anope::string &nick, const Anope::string &pass) : IdentifyRequest(o, nick, pass), source(src), cmd(c), user(nick) { }
- void OnSuccess() anope_override
+ void OnSuccess() override
{
User *u = User::Find(user, true);
if (!source.GetUser() || !source.service)
@@ -58,7 +59,7 @@ class NSRecoverRequest : public IdentifyRequest
// same person that is executing the command, so kill them off (old GHOST command).
else if (u->Account() == na->nc)
{
- if (!source.GetAccount() && na->nc->HasExt("NS_SECURE"))
+ if (!source.GetAccount())
{
source.GetUser()->Login(u->Account());
Log(LOG_COMMAND, source, cmd) << "and was automatically identified to " << u->Account()->display;
@@ -69,8 +70,8 @@ class NSRecoverRequest : public IdentifyRequest
if (!u->chans.empty())
{
NSRecoverInfo *ei = source.GetUser()->Extend<NSRecoverInfo>("recover");
- for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it)
- (*ei)[it->first->name] = it->second->status;
+ for (auto &[chan, cuc] : u->chans)
+ (*ei)[chan->name] = cuc->status;
}
}
@@ -89,7 +90,7 @@ class NSRecoverRequest : public IdentifyRequest
/* User is not identified or not identified to the same account as the person using this command */
else
{
- if (!source.GetAccount() && na->nc->HasExt("NS_SECURE"))
+ if (!source.GetAccount())
{
source.GetUser()->Login(na->nc); // Identify the user using the command if they arent identified
Log(LOG_COMMAND, source, cmd) << "and was automatically identified to " << na->nick << " (" << na->nc->display << ")";
@@ -124,7 +125,7 @@ class NSRecoverRequest : public IdentifyRequest
}
}
- void OnFail() anope_override
+ void OnFail() override
{
if (NickAlias::Find(GetAccount()) != NULL)
{
@@ -141,9 +142,10 @@ class NSRecoverRequest : public IdentifyRequest
}
};
-class CommandNSRecover : public Command
+class CommandNSRecover final
+ : public Command
{
- public:
+public:
CommandNSRecover(Module *creator) : Command(creator, "nickserv/recover", 1, 2)
{
this->SetDesc(_("Regains control of your nick"));
@@ -151,7 +153,7 @@ class CommandNSRecover : public Command
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = params[0];
const Anope::string &pass = params.size() > 1 ? params[1] : "";
@@ -180,8 +182,6 @@ class CommandNSRecover : public Command
bool ok = false;
if (source.GetAccount() == na->nc)
ok = true;
- else if (!na->nc->HasExt("NS_SECURE") && source.GetUser() && na->nc->IsOnAccess(source.GetUser()))
- ok = true;
NSCertList *cl = na->nc->GetExt<NSCertList>("certificates");
if (source.GetUser() && !source.GetUser()->fingerprint.empty() && cl && cl->FindCert(source.GetUser()->fingerprint))
@@ -190,9 +190,9 @@ class CommandNSRecover : public Command
if (source.HasPriv("nickserv/recover"))
ok = true;
- if (ok == false && !pass.empty())
+ if (!ok && !pass.empty())
{
- NSRecoverRequest *req = new NSRecoverRequest(owner, source, this, na->nick, pass);
+ auto *req = new NSRecoverRequest(owner, source, this, na->nick, pass);
FOREACH_MOD(OnCheckAuthentication, (source.GetUser(), req));
req->Dispatch();
}
@@ -207,7 +207,7 @@ class CommandNSRecover : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -221,13 +221,14 @@ class CommandNSRecover : public Command
}
};
-class NSRecover : public Module
+class NSRecover final
+ : public Module
{
CommandNSRecover commandnsrecover;
PrimitiveExtensibleItem<NSRecoverInfo> recover;
PrimitiveExtensibleItem<NSRecoverSvsnick> svsnick;
- public:
+public:
NSRecover(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsrecover(this), recover(this, "recover"), svsnick(this, "svsnick")
{
@@ -237,7 +238,7 @@ class NSRecover : public Module
}
- void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override
+ void OnUserNickChange(User *u, const Anope::string &oldnick) override
{
if (Config->GetModule(this)->Get<bool>("restoreonrecover"))
{
@@ -272,7 +273,7 @@ class NSRecover : public Module
}
}
- void OnJoinChannel(User *u, Channel *c) anope_override
+ void OnJoinChannel(User *u, Channel *c) override
{
if (Config->GetModule(this)->Get<bool>("restoreonrecover"))
{
@@ -283,8 +284,8 @@ class NSRecover : public Module
NSRecoverInfo::iterator it = ei->find(c->name);
if (it != ei->end())
{
- for (size_t i = 0; i < it->second.Modes().length(); ++i)
- c->SetMode(c->WhoSends(), ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID());
+ for (auto mode : it->second.Modes())
+ c->SetMode(c->WhoSends(), ModeManager::FindChannelModeByChar(mode), u->GetUID());
ei->erase(it);
if (ei->empty())
diff --git a/modules/commands/ns_register.cpp b/modules/nickserv/ns_register.cpp
index 8b15b00d1..0f5fc5533 100644
--- a/modules/commands/ns_register.cpp
+++ b/modules/nickserv/ns_register.cpp
@@ -13,9 +13,10 @@
static bool SendRegmail(User *u, const NickAlias *na, BotInfo *bi);
-class CommandNSConfirm : public Command
+class CommandNSConfirm final
+ : public Command
{
- public:
+public:
CommandNSConfirm(Module *creator) : Command(creator, "nickserv/confirm", 1, 2)
{
this->SetDesc(_("Confirm a passcode"));
@@ -23,7 +24,7 @@ class CommandNSConfirm : public Command
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string *code = source.nc ? source.nc->GetExt<Anope::string>("passcode") : NULL;
bool confirming_other = !code || *code != params[0];
@@ -34,7 +35,7 @@ class CommandNSConfirm : public Command
NickAlias *na = NickAlias::Find(nick);
if (na == NULL)
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
- else if (na->nc->HasExt("UNCONFIRMED") == false)
+ else if (!na->nc->HasExt("UNCONFIRMED"))
source.Reply(_("Nick \002%s\002 is already confirmed."), na->nick.c_str());
else
{
@@ -90,7 +91,7 @@ class CommandNSConfirm : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -108,32 +109,30 @@ class CommandNSConfirm : public Command
return true;
}
- void OnSyntaxError(CommandSource &source, const Anope::string &subcommand) anope_override
+ void OnSyntaxError(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(NICK_CONFIRM_INVALID);
}
};
-class CommandNSRegister : public Command
+class CommandNSRegister final
+ : public Command
{
- public:
- CommandNSRegister(Module *creator) : Command(creator, "nickserv/register", 1, 2)
+public:
+ CommandNSRegister(Module *creator) : Command(creator, "nickserv/register", 2, 2)
{
this->SetDesc(_("Register a nickname"));
- if (Config->GetModule("nickserv")->Get<bool>("forceemail", "yes"))
- this->SetSyntax(_("\037password\037 \037email\037"));
- else
- this->SetSyntax(_("\037password\037 \037[email]\037"));
+ this->SetSyntax(_("\037password\037 \037email\037"));
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
User *u = source.GetUser();
Anope::string u_nick = source.GetNick();
size_t nicklen = u_nick.length();
Anope::string pass = params[0];
- Anope::string email = params.size() > 1 ? params[1] : "";
+ Anope::string email = params[1];
const Anope::string &nsregister = Config->GetModule(this->owner)->Get<const Anope::string>("registration");
if (Anope::ReadOnly)
@@ -152,7 +151,8 @@ class CommandNSRegister : public Command
time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay");
if (u && !u->HasMode("OPER") && nickregdelay && Anope::CurTime - u->timestamp < nickregdelay)
{
- source.Reply(_("You must have been using this nick for at least %d seconds to register."), nickregdelay);
+ source.Reply(_("You must have been using this nick for at least %lu seconds to register."),
+ (unsigned long)nickregdelay);
return;
}
@@ -182,10 +182,8 @@ class CommandNSRegister : public Command
if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks"))
{
- for (unsigned i = 0; i < Oper::opers.size(); ++i)
+ for (auto *o : Oper::opers)
{
- Oper *o = Oper::opers[i];
-
if (!source.IsOper() && u_nick.find_ci(o->name) != Anope::string::npos)
{
source.Reply(NICK_CANNOT_BE_REGISTERED, u_nick.c_str());
@@ -194,27 +192,36 @@ class CommandNSRegister : public Command
}
}
- unsigned int passlen = Config->GetModule("nickserv")->Get<unsigned>("passlen", "32");
-
- if (Config->GetModule("nickserv")->Get<bool>("forceemail", "yes") && email.empty())
- this->OnSyntaxError(source, "");
- else if (u && Anope::CurTime < u->lastnickreg + reg_delay)
- source.Reply(_("Please wait %d seconds before using the REGISTER command again."), (u->lastnickreg + reg_delay) - Anope::CurTime);
+ unsigned int minpasslen = Config->GetModule("nickserv")->Get<unsigned>("minpasslen", "10");
+ unsigned int maxpasslen = Config->GetModule("nickserv")->Get<unsigned>("maxpasslen", "50");
+ if (u && Anope::CurTime < u->lastnickreg + reg_delay)
+ {
+ source.Reply(_("Please wait %lu seconds before using the REGISTER command again."),
+ (unsigned long)(u->lastnickreg + reg_delay) - Anope::CurTime);
+ }
else if (NickAlias::Find(u_nick) != NULL)
source.Reply(NICK_ALREADY_REGISTERED, u_nick.c_str());
- else if (pass.equals_ci(u_nick) || (Config->GetBlock("options")->Get<bool>("strictpasswords") && pass.length() < 5))
+ else if (pass.equals_ci(u_nick))
source.Reply(MORE_OBSCURE_PASSWORD);
- else if (pass.length() > passlen)
- source.Reply(PASSWORD_TOO_LONG, passlen);
- else if (!email.empty() && !Mail::Validate(email))
+ else if (pass.length() < minpasslen)
+ source.Reply(PASSWORD_TOO_SHORT, minpasslen);
+ else if (pass.length() > maxpasslen)
+ source.Reply(PASSWORD_TOO_LONG, maxpasslen);
+ else if (!Mail::Validate(email))
source.Reply(MAIL_X_INVALID, email.c_str());
else
{
- NickCore *nc = new NickCore(u_nick);
- NickAlias *na = new NickAlias(u_nick, nc);
- Anope::Encrypt(pass, nc->pass);
- if (!email.empty())
- nc->email = email;
+ Anope::string encpass;
+ if (!Anope::Encrypt(pass, encpass))
+ {
+ source.Reply(_("Accounts can not be registered right now. Please try again later."));
+ return;
+ }
+
+ auto *nc = new NickCore(u_nick);
+ auto *na = new NickAlias(u_nick, nc);
+ nc->email = email;
+ nc->pass = encpass;
if (u)
{
@@ -224,28 +231,17 @@ class CommandNSRegister : public Command
else
na->last_realname = source.GetNick();
- Log(LOG_COMMAND, source, this) << "to register " << na->nick << " (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")";
-
- if (na->nc->GetAccessCount())
- source.Reply(_("Nickname \002%s\002 registered under your user@host-mask: %s"), u_nick.c_str(), na->nc->GetAccess(0).c_str());
- else
- source.Reply(_("Nickname \002%s\002 registered."), u_nick.c_str());
-
- Anope::string tmp_pass;
- if (Anope::Decrypt(na->nc->pass, tmp_pass) == 1)
- source.Reply(_("Your password is \002%s\002 - remember this for later use."), tmp_pass.c_str());
+ Log(LOG_COMMAND, source, this) << "to register " << na->nick << " (email: " << na->nc->email << ")";
+ source.Reply(_("Nickname \002%s\002 registered."), u_nick.c_str());
if (nsregister.equals_ci("admin"))
{
nc->Extend<bool>("UNCONFIRMED");
}
else if (nsregister.equals_ci("mail"))
{
- if (!email.empty())
- {
- nc->Extend<bool>("UNCONFIRMED");
- SendRegmail(NULL, na, source.service);
- }
+ nc->Extend<bool>("UNCONFIRMED");
+ SendRegmail(NULL, na, source.service);
}
FOREACH_MOD(OnNickRegister, (source.GetUser(), na, pass));
@@ -266,8 +262,9 @@ class CommandNSRegister : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
+ unsigned int minpasslen = Config->GetModule("nickserv")->Get<unsigned>("minpasslen", "10");
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Registers your nickname in the %s database. Once\n"
@@ -285,19 +282,10 @@ class CommandNSRegister : public Command
"your nickname as a password is a much worse idea ;) and,\n"
"in fact, %s will not allow it. Also, short\n"
"passwords are vulnerable to trial-and-error searches, so\n"
- "you should choose a password at least 5 characters long.\n"
+ "you should choose a password at least %u characters long.\n"
"Finally, the space character cannot be used in passwords."),
- source.service->nick.c_str(), source.service->nick.c_str());
-
- if (!Config->GetModule("nickserv")->Get<bool>("forceemail", "yes"))
- {
- source.Reply(" ");
- source.Reply(_("The \037email\037 parameter is optional and will set the email\n"
- "for your nick immediately.\n"
- "Your privacy is respected; this e-mail won't be given to\n"
- "any third-party person. You may also wish to \002SET HIDE\002 it\n"
- "after registering if it isn't the default setting already."));
- }
+ source.service->nick.c_str(), source.service->nick.c_str(),
+ minpasslen);
source.Reply(" ");
source.Reply(_("This command also creates a new group for your nickname,\n"
@@ -308,15 +296,16 @@ class CommandNSRegister : public Command
}
};
-class CommandNSResend : public Command
+class CommandNSResend final
+ : public Command
{
- public:
+public:
CommandNSResend(Module *creator) : Command(creator, "nickserv/resend", 0, 0)
{
this->SetDesc(_("Resend registration confirmation email"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!Config->GetModule(this->owner)->Get<const Anope::string>("registration").equals_ci("mail"))
{
@@ -347,7 +336,7 @@ class CommandNSResend : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (!Config->GetModule(this->owner)->Get<const Anope::string>("registration").equals_ci("mail"))
return false;
@@ -358,14 +347,15 @@ class CommandNSResend : public Command
return true;
}
- void OnServHelp(CommandSource &source) anope_override
+ void OnServHelp(CommandSource &source) override
{
if (Config->GetModule(this->owner)->Get<const Anope::string>("registration").equals_ci("mail"))
Command::OnServHelp(source);
}
};
-class NSRegister : public Module
+class NSRegister final
+ : public Module
{
CommandNSRegister commandnsregister;
CommandNSConfirm commandnsconfirm;
@@ -374,7 +364,7 @@ class NSRegister : public Module
SerializableExtensibleItem<bool> unconfirmed;
SerializableExtensibleItem<Anope::string> passcode;
- public:
+public:
NSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsregister(this), commandnsconfirm(this), commandnsrsend(this), unconfirmed(this, "UNCONFIRMED"),
passcode(this, "passcode")
@@ -383,7 +373,7 @@ class NSRegister : public Module
throw ModuleException("Module " + this->name + " will not load with registration disabled.");
}
- void OnNickIdentify(User *u) anope_override
+ void OnNickIdentify(User *u) override
{
BotInfo *NickServ;
if (unconfirmed.HasExt(u->Account()) && (NickServ = Config->GetClient("NickServ")))
@@ -401,7 +391,7 @@ class NSRegister : public Module
}
}
- void OnPreNickExpire(NickAlias *na, bool &expire) anope_override
+ void OnPreNickExpire(NickAlias *na, bool &expire) override
{
if (unconfirmed.HasExt(na->nc))
{
@@ -420,7 +410,7 @@ static bool SendRegmail(User *u, const NickAlias *na, BotInfo *bi)
if (code == NULL)
{
code = na->nc->Extend<Anope::string>("passcode");
- *code = Anope::Random(9);
+ *code = Anope::Random(15);
}
Anope::string subject = Language::Translate(na->nc, Config->GetBlock("mail")->Get<const Anope::string>("registration_subject").c_str()),
diff --git a/modules/commands/ns_resetpass.cpp b/modules/nickserv/ns_resetpass.cpp
index 4139e5944..889a8b933 100644
--- a/modules/commands/ns_resetpass.cpp
+++ b/modules/nickserv/ns_resetpass.cpp
@@ -13,9 +13,10 @@
static bool SendResetEmail(User *u, const NickAlias *na, BotInfo *bi);
-class CommandNSResetPass : public Command
+class CommandNSResetPass final
+ : public Command
{
- public:
+public:
CommandNSResetPass(Module *creator) : Command(creator, "nickserv/resetpass", 2, 2)
{
this->SetDesc(_("Helps you reset lost passwords"));
@@ -23,7 +24,7 @@ class CommandNSResetPass : public Command
this->AllowUnregistered(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const NickAlias *na;
@@ -45,7 +46,7 @@ class CommandNSResetPass : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -56,18 +57,19 @@ class CommandNSResetPass : public Command
}
};
-struct ResetInfo
+struct ResetInfo final
{
Anope::string code;
time_t time;
};
-class NSResetPass : public Module
+class NSResetPass final
+ : public Module
{
CommandNSResetPass commandnsresetpass;
PrimitiveExtensibleItem<ResetInfo> reset;
- public:
+public:
NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsresetpass(this), reset(this, "reset")
{
@@ -75,7 +77,7 @@ class NSResetPass : public Module
throw ModuleException("Not using mail.");
}
- EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
if (command->name == "nickserv/confirm" && params.size() > 1)
{
@@ -114,7 +116,7 @@ class NSResetPass : public Module
{
source.GetUser()->Identify(na);
}
-
+
source.Reply(_("You are now identified for your nick. Change your password now."));
}
else
diff --git a/modules/commands/ns_set.cpp b/modules/nickserv/ns_set.cpp
index a3bfb3630..ed3708d16 100644
--- a/modules/commands/ns_set.cpp
+++ b/modules/nickserv/ns_set.cpp
@@ -11,22 +11,23 @@
#include "module.h"
-class CommandNSSet : public Command
+class CommandNSSet final
+ : public Command
{
- public:
+public:
CommandNSSet(Module *creator) : Command(creator, "nickserv/set", 1, 3)
{
this->SetDesc(_("Set options, including kill protection"));
this->SetSyntax(_("\037option\037 \037parameters\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->OnSyntaxError(source, "");
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -35,11 +36,8 @@ class CommandNSSet : public Command
Anope::string this_name = source.command;
bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"),
hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands");
- for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it)
+ for (const auto &[c_name, info] : source.service->commands)
{
- const Anope::string &c_name = it->first;
- const CommandInfo &info = it->second;
-
if (c_name.find_ci(this_name + " ") == 0)
{
if (info.hide)
@@ -66,33 +64,31 @@ class CommandNSSet : public Command
}
};
-class CommandNSSASet : public Command
+class CommandNSSASet final
+ : public Command
{
- public:
+public:
CommandNSSASet(Module *creator) : Command(creator, "nickserv/saset", 2, 4)
{
this->SetDesc(_("Set SET-options on another nickname"));
this->SetSyntax(_("\037option\037 \037nickname\037 \037parameters\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->OnSyntaxError(source, "");
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Sets various nickname options. \037option\037 can be one of:"));
Anope::string this_name = source.command;
- for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it)
+ for (const auto &[c_name, info] : source.service->commands)
{
- const Anope::string &c_name = it->first;
- const CommandInfo &info = it->second;
-
if (c_name.find_ci(this_name + " ") == 0)
{
ServiceReference<Command> command("Command", info.name);
@@ -111,16 +107,17 @@ class CommandNSSASet : public Command
}
};
-class CommandNSSetPassword : public Command
+class CommandNSSetPassword final
+ : public Command
{
- public:
+public:
CommandNSSetPassword(Module *creator) : Command(creator, "nickserv/set/password", 1)
{
this->SetDesc(_("Set your nickname password"));
this->SetSyntax(_("\037new-password\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &param = params[0];
unsigned len = param.length();
@@ -131,30 +128,37 @@ class CommandNSSetPassword : public Command
return;
}
- if (source.GetNick().equals_ci(param) || (Config->GetBlock("options")->Get<bool>("strictpasswords") && len < 5))
+ if (source.GetNick().equals_ci(param))
{
source.Reply(MORE_OBSCURE_PASSWORD);
return;
}
- unsigned int passlen = Config->GetModule("nickserv")->Get<unsigned>("passlen", "32");
- if (len > passlen)
+ unsigned int minpasslen = Config->GetModule("nickserv")->Get<unsigned>("minpasslen", "10");
+ if (len < minpasslen)
{
- source.Reply(PASSWORD_TOO_LONG, passlen);
+ source.Reply(PASSWORD_TOO_SHORT, minpasslen);
return;
}
- Log(LOG_COMMAND, source, this) << "to change their password";
+ unsigned int maxpasslen = Config->GetModule("nickserv")->Get<unsigned>("maxpasslen", "50");
+ if (len > maxpasslen)
+ {
+ source.Reply(PASSWORD_TOO_LONG, maxpasslen);
+ return;
+ }
- Anope::Encrypt(param, source.nc->pass);
- Anope::string tmp_pass;
- if (Anope::Decrypt(source.nc->pass, tmp_pass) == 1)
- source.Reply(_("Password for \002%s\002 changed to \002%s\002."), source.nc->display.c_str(), tmp_pass.c_str());
- else
- source.Reply(_("Password for \002%s\002 changed."), source.nc->display.c_str());
+ if (!Anope::Encrypt(param, source.nc->pass))
+ {
+ source.Reply(_("Passwords can not be changed right now. Please try again later."));
+ return;
+ }
+
+ Log(LOG_COMMAND, source, this) << "to change their password";
+ source.Reply(_("Password for \002%s\002 changed."), source.nc->display.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -164,16 +168,17 @@ class CommandNSSetPassword : public Command
}
};
-class CommandNSSASetPassword : public Command
+class CommandNSSASetPassword final
+ : public Command
{
- public:
+public:
CommandNSSASetPassword(Module *creator) : Command(creator, "nickserv/saset/password", 2, 2)
{
this->SetDesc(_("Set the nickname password"));
this->SetSyntax(_("\037nickname\037 \037new-password\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -197,30 +202,37 @@ class CommandNSSASetPassword : public Command
return;
}
- if (nc->display.equals_ci(params[1]) || (Config->GetBlock("options")->Get<bool>("strictpasswords") && len < 5))
+ if (nc->display.equals_ci(params[1]))
{
source.Reply(MORE_OBSCURE_PASSWORD);
return;
}
- unsigned int passlen = Config->GetModule("nickserv")->Get<unsigned>("passlen", "32");
- if (len > passlen)
+ unsigned int minpasslen = Config->GetModule("nickserv")->Get<unsigned>("minpasslen", "10");
+ if (len < minpasslen)
{
- source.Reply(PASSWORD_TOO_LONG, passlen);
+ source.Reply(PASSWORD_TOO_SHORT, minpasslen);
return;
}
- Log(LOG_ADMIN, source, this) << "to change the password of " << nc->display;
+ unsigned int maxpasslen = Config->GetModule("nickserv")->Get<unsigned>("maxpasslen", "50");
+ if (len > maxpasslen)
+ {
+ source.Reply(PASSWORD_TOO_LONG, maxpasslen);
+ return;
+ }
- Anope::Encrypt(params[1], nc->pass);
- Anope::string tmp_pass;
- if (Anope::Decrypt(nc->pass, tmp_pass) == 1)
- source.Reply(_("Password for \002%s\002 changed to \002%s\002."), nc->display.c_str(), tmp_pass.c_str());
- else
- source.Reply(_("Password for \002%s\002 changed."), nc->display.c_str());
+ if (!Anope::Encrypt(params[1], nc->pass))
+ {
+ source.Reply(_("Passwords can not be changed right now. Please try again later."));
+ return;
+ }
+
+ Log(LOG_ADMIN, source, this) << "to change the password of " << nc->display;
+ source.Reply(_("Password for \002%s\002 changed."), nc->display.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -229,9 +241,10 @@ class CommandNSSASetPassword : public Command
}
};
-class CommandNSSetAutoOp : public Command
+class CommandNSSetAutoOp
+ : public Command
{
- public:
+public:
CommandNSSetAutoOp(Module *creator, const Anope::string &sname = "nickserv/set/autoop", size_t min = 1) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Sets whether services should set channel status modes on you automatically."));
@@ -275,12 +288,12 @@ class CommandNSSetAutoOp : public Command
this->OnSyntaxError(source, "AUTOOP");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
BotInfo *bi = Config->GetClient("ChanServ");
this->SendSyntax(source);
@@ -293,21 +306,22 @@ class CommandNSSetAutoOp : public Command
}
};
-class CommandNSSASetAutoOp : public CommandNSSetAutoOp
+class CommandNSSASetAutoOp final
+ : public CommandNSSetAutoOp
{
- public:
+public:
CommandNSSASetAutoOp(Module *creator) : CommandNSSetAutoOp(creator, "nickserv/saset/autoop", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
BotInfo *bi = Config->GetClient("ChanServ");
this->SendSyntax(source);
@@ -321,12 +335,98 @@ class CommandNSSASetAutoOp : public CommandNSSetAutoOp
}
};
-class CommandNSSetDisplay : public Command
+class CommandNSSetNeverOp
+ : public Command
+{
+public:
+ CommandNSSetNeverOp(Module *creator, const Anope::string &sname = "nickserv/set/neverop", size_t min = 1) : Command(creator, sname, min, min + 1)
+ {
+ this->SetDesc(_("Sets whether you can be added to a channel access list."));
+ this->SetSyntax("{ON | OFF}");
+ }
+
+ void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
+ {
+ if (Anope::ReadOnly)
+ {
+ source.Reply(READ_ONLY_MODE);
+ return;
+ }
+
+ const NickAlias *na = NickAlias::Find(user);
+ if (na == NULL)
+ {
+ source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
+ return;
+ }
+ NickCore *nc = na->nc;
+
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param));
+ if (MOD_RESULT == EVENT_STOP)
+ return;
+
+ if (param.equals_ci("ON"))
+ {
+ Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to enable neverop for " << na->nc->display;
+ nc->Extend<bool>("NEVEROP");
+ source.Reply(_("%s can no longer be added to channel access lists."), nc->display.c_str());
+ }
+ else if (param.equals_ci("OFF"))
+ {
+ Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to disable neverop for " << na->nc->display;
+ nc->Shrink<bool>("NEVEROP");
+ source.Reply(_("%s can now be added to channel access lists."), nc->display.c_str());
+ }
+ else
+ this->OnSyntaxError(source, "NEVEROP");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ this->Run(source, source.nc->display, params[0]);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &) override
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_("Sets whether you can be added to a channel access list."));
+ return true;
+ }
+};
+
+class CommandNSSASetNeverOp final
+ : public CommandNSSetNeverOp
+{
+public:
+ CommandNSSASetNeverOp(Module *creator) : CommandNSSetNeverOp(creator, "nickserv/saset/neverop", 2)
+ {
+ this->ClearSyntax();
+ this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ this->Run(source, params[0], params[1]);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &) override
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_("Sets whether the given nickname can be added to a channel access list."));
+ return true;
+ }
+};
+
+class CommandNSSetDisplay
+ : public Command
{
- public:
+public:
CommandNSSetDisplay(Module *creator, const Anope::string &sname = "nickserv/set/display", size_t min = 1) : Command(creator, sname, min, min + 1)
{
- this->SetDesc(_("Set the display of your group in Services"));
+ this->SetDesc(_("Set the display of your group in services"));
this->SetSyntax(_("\037new-display\037"));
}
@@ -375,50 +475,52 @@ class CommandNSSetDisplay : public Command
source.Reply(NICK_SET_DISPLAY_CHANGED, user_na->nc->display.c_str());
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Changes the display used to refer to your nickname group in\n"
- "Services. The new display MUST be a nick of your group."));
+ "services. The new display MUST be a nick of your group."));
return true;
}
};
-class CommandNSSASetDisplay : public CommandNSSetDisplay
+class CommandNSSASetDisplay final
+ : public CommandNSSetDisplay
{
- public:
+public:
CommandNSSASetDisplay(Module *creator) : CommandNSSetDisplay(creator, "nickserv/saset/display", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 \037new-display\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Changes the display used to refer to the nickname group in\n"
- "Services. The new display MUST be a nick of the group."));
+ "services. The new display MUST be a nick of the group."));
return true;
}
};
-class CommandNSSetEmail : public Command
+class CommandNSSetEmail
+ : public Command
{
static bool SendConfirmMail(User *u, NickCore *nc, BotInfo *bi, const Anope::string &new_email)
{
- Anope::string code = Anope::Random(9);
+ Anope::string code = Anope::Random(15);
std::pair<Anope::string, Anope::string> *n = nc->Extend<std::pair<Anope::string, Anope::string> >("ns_set_email");
n->first = new_email;
@@ -446,10 +548,10 @@ class CommandNSSetEmail : public Command
return b;
}
- public:
- CommandNSSetEmail(Module *creator, const Anope::string &cname = "nickserv/set/email", size_t min = 0) : Command(creator, cname, min, min + 1)
+public:
+ CommandNSSetEmail(Module *creator, const Anope::string &cname = "nickserv/set/email", size_t min = 1) : Command(creator, cname, min, min + 1)
{
- this->SetDesc(_("Associate an E-mail address with your nickname"));
+ this->SetDesc(_("Associate an email address with your nickname"));
this->SetSyntax(_("\037address\037"));
}
@@ -475,17 +577,12 @@ class CommandNSSetEmail : public Command
return;
}
- if (param.empty() && Config->GetModule("nickserv")->Get<bool>("forceemail", "yes"))
- {
- source.Reply(_("You cannot unset the e-mail on this network."));
- return;
- }
else if (Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && source.nc != nc && nc->IsServicesOper())
{
- source.Reply(_("You may not change the e-mail of other Services Operators."));
+ source.Reply(_("You may not change the email of other Services Operators."));
return;
}
- else if (!param.empty() && !Mail::Validate(param))
+ else if (!Mail::Validate(param))
{
source.Reply(MAIL_X_INVALID, param.c_str());
return;
@@ -496,73 +593,66 @@ class CommandNSSetEmail : public Command
if (MOD_RESULT == EVENT_STOP)
return;
- if (!param.empty() && Config->GetModule("nickserv")->Get<bool>("confirmemailchanges") && !source.IsServicesOper())
+ if (Config->GetModule("nickserv")->Get<bool>("confirmemailchanges") && !source.IsServicesOper())
{
if (SendConfirmMail(source.GetUser(), source.GetAccount(), source.service, param))
{
Log(LOG_COMMAND, source, this) << "to request changing the email of " << nc->display << " to " << param;
- source.Reply(_("A confirmation e-mail has been sent to \002%s\002. Follow the instructions in it to change your e-mail address."), param.c_str());
+ source.Reply(_("A confirmation email has been sent to \002%s\002. Follow the instructions in it to change your email address."), param.c_str());
}
}
else
{
- if (!param.empty())
- {
- Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to change the email of " << nc->display << " to " << param;
- nc->email = param;
- source.Reply(_("E-mail address for \002%s\002 changed to \002%s\002."), nc->display.c_str(), param.c_str());
- }
- else
- {
- Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to unset the email of " << nc->display;
- nc->email.clear();
- source.Reply(_("E-mail address for \002%s\002 unset."), nc->display.c_str());
- }
+ Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to change the email of " << nc->display << " to " << param;
+ nc->email = param;
+ source.Reply(_("Email address for \002%s\002 changed to \002%s\002."), nc->display.c_str(), param.c_str());
}
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
- this->Run(source, source.nc->display, params.size() ? params[0] : "");
+ this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Associates the given E-mail address with your nickname.\n"
+ source.Reply(_("Associates the given email address with your nickname.\n"
"This address will be displayed whenever someone requests\n"
"information on the nickname with the \002INFO\002 command."));
return true;
}
};
-class CommandNSSASetEmail : public CommandNSSetEmail
+class CommandNSSASetEmail final
+ : public CommandNSSetEmail
{
- public:
+public:
CommandNSSASetEmail(Module *creator) : CommandNSSetEmail(creator, "nickserv/saset/email", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 \037address\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
- this->Run(source, params[0], params.size() > 1 ? params[1] : "");
+ this->Run(source, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Associates the given E-mail address with the nickname."));
+ source.Reply(_("Associates the given email address with the nickname."));
return true;
}
};
-class CommandNSSetKeepModes : public Command
+class CommandNSSetKeepModes
+ : public Command
{
- public:
+public:
CommandNSSetKeepModes(Module *creator, const Anope::string &sname = "nickserv/set/keepmodes", size_t min = 1) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Enable or disable keep modes"));
@@ -606,12 +696,12 @@ class CommandNSSetKeepModes : public Command
this->OnSyntaxError(source, "");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -622,21 +712,22 @@ class CommandNSSetKeepModes : public Command
}
};
-class CommandNSSASetKeepModes : public CommandNSSetKeepModes
+class CommandNSSASetKeepModes final
+ : public CommandNSSetKeepModes
{
- public:
+public:
CommandNSSASetKeepModes(Module *creator) : CommandNSSetKeepModes(creator, "nickserv/saset/keepmodes", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -647,9 +738,10 @@ class CommandNSSASetKeepModes : public CommandNSSetKeepModes
}
};
-class CommandNSSetKill : public Command
+class CommandNSSetKill
+ : public Command
{
- public:
+public:
CommandNSSetKill(Module *creator, const Anope::string &sname = "nickserv/set/kill", size_t min = 1) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Turn protection on or off"));
@@ -726,12 +818,12 @@ class CommandNSSetKill : public Command
return;
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -751,21 +843,22 @@ class CommandNSSetKill : public Command
}
};
-class CommandNSSASetKill : public CommandNSSetKill
+class CommandNSSASetKill final
+ : public CommandNSSetKill
{
- public:
+public:
CommandNSSASetKill(Module *creator) : CommandNSSetKill(creator, "nickserv/saset/kill", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | QUICK | IMMED | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -785,12 +878,13 @@ class CommandNSSASetKill : public CommandNSSetKill
}
};
-class CommandNSSetLanguage : public Command
+class CommandNSSetLanguage
+ : public Command
{
- public:
+public:
CommandNSSetLanguage(Module *creator, const Anope::string &sname = "nickserv/set/language", size_t min = 1) : Command(creator, sname, min, min + 1)
{
- this->SetDesc(_("Set the language Services will use when messaging you"));
+ this->SetDesc(_("Set the language services will use when messaging you"));
this->SetSyntax(_("\037language\037"));
}
@@ -836,73 +930,75 @@ class CommandNSSetLanguage : public Command
source.Reply(_("Language for \002%s\002 changed to \002%s\002."), nc->display.c_str(), Language::Translate(param.c_str(), _("English")));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &param) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &param) override
{
this->Run(source, source.nc->display, param[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Changes the language Services uses when sending messages to\n"
+ source.Reply(_("Changes the language services uses when sending messages to\n"
"you (for example, when responding to a command you send).\n"
"\037language\037 should be chosen from the following list of\n"
"supported languages:"));
source.Reply(" en_US (English)");
- for (unsigned j = 0; j < Language::Languages.size(); ++j)
+ for (const auto &language : Language::Languages)
{
- const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English"));
+ const Anope::string &langname = Language::Translate(language.c_str(), _("English"));
if (langname == "English")
continue;
- source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str());
+ source.Reply(" %s (%s)", language.c_str(), langname.c_str());
}
return true;
}
};
-class CommandNSSASetLanguage : public CommandNSSetLanguage
+class CommandNSSASetLanguage final
+ : public CommandNSSetLanguage
{
- public:
+public:
CommandNSSASetLanguage(Module *creator) : CommandNSSetLanguage(creator, "nickserv/saset/language", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 \037language\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Changes the language Services uses when sending messages to\n"
+ source.Reply(_("Changes the language services uses when sending messages to\n"
"the given user (for example, when responding to a command they send).\n"
"\037language\037 should be chosen from the following list of\n"
"supported languages:"));
source.Reply(" en (English)");
- for (unsigned j = 0; j < Language::Languages.size(); ++j)
+ for (const auto &language : Language::Languages)
{
- const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English"));
+ const Anope::string &langname = Language::Translate(language.c_str(), _("English"));
if (langname == "English")
continue;
- source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str());
+ source.Reply(" %s (%s)", language.c_str(), langname.c_str());
}
return true;
}
};
-class CommandNSSetMessage : public Command
+class CommandNSSetMessage
+ : public Command
{
- public:
+public:
CommandNSSetMessage(Module *creator, const Anope::string &sname = "nickserv/set/message", size_t min = 1) : Command(creator, sname, min, min + 1)
{
- this->SetDesc(_("Change the communication method of Services"));
+ this->SetDesc(_("Change the communication method of services"));
this->SetSyntax("{ON | OFF}");
}
@@ -949,12 +1045,12 @@ class CommandNSSetMessage : public Command
this->OnSyntaxError(source, "MSG");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, params[0]);
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
Anope::string cmd = source.command;
size_t i = cmd.find_last_of(' ');
@@ -963,149 +1059,56 @@ class CommandNSSetMessage : public Command
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Allows you to choose the way Services are communicating with\n"
- "you. With \002%s\002 set, Services will use messages, else they'll\n"
+ source.Reply(_("Allows you to choose the way services are communicating with\n"
+ "you. With \002%s\002 set, services will use messages, else they'll\n"
"use notices."), cmd.upper().c_str());
return true;
}
- void OnServHelp(CommandSource &source) anope_override
+ void OnServHelp(CommandSource &source) override
{
if (Config->GetBlock("options")->Get<bool>("useprivmsg"))
Command::OnServHelp(source);
}
};
-class CommandNSSASetMessage : public CommandNSSetMessage
+class CommandNSSASetMessage final
+ : public CommandNSSetMessage
{
- public:
+public:
CommandNSSASetMessage(Module *creator) : CommandNSSetMessage(creator, "nickserv/saset/message", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Allows you to choose the way Services are communicating with\n"
- "the given user. With \002MSG\002 set, Services will use messages,\n"
+ source.Reply(_("Allows you to choose the way services are communicating with\n"
+ "the given user. With \002MSG\002 set, services will use messages,\n"
"else they'll use notices."));
return true;
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
- {
- this->Run(source, params[0], params[1]);
- }
-};
-
-class CommandNSSetSecure : public Command
-{
- public:
- CommandNSSetSecure(Module *creator, const Anope::string &sname = "nickserv/set/secure", size_t min = 1) : Command(creator, sname, min, min + 1)
- {
- this->SetDesc(_("Turn nickname security on or off"));
- this->SetSyntax("{ON | OFF}");
- }
-
- void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
- {
- if (Anope::ReadOnly)
- {
- source.Reply(READ_ONLY_MODE);
- return;
- }
-
- const NickAlias *na = NickAlias::Find(user);
- if (!na)
- {
- source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
- return;
- }
- NickCore *nc = na->nc;
-
- EventReturn MOD_RESULT;
- FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param));
- if (MOD_RESULT == EVENT_STOP)
- return;
-
- if (param.equals_ci("ON"))
- {
- Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to enable secure for " << nc->display;
- nc->Extend<bool>("NS_SECURE");
- source.Reply(_("Secure option is now \002on\002 for \002%s\002."), nc->display.c_str());
- }
- else if (param.equals_ci("OFF"))
- {
- Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to disable secure for " << nc->display;
- nc->Shrink<bool>("NS_SECURE");
- source.Reply(_("Secure option is now \002off\002 for \002%s\002."), nc->display.c_str());
- }
- else
- this->OnSyntaxError(source, "SECURE");
- }
-
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
- {
- this->Run(source, source.nc->display, params[0]);
- }
-
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
- {
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Turns %s's security features on or off for your\n"
- "nick. With \002SECURE\002 set, you must enter your password\n"
- "before you will be recognized as the owner of the nick,\n"
- "regardless of whether your address is on the access\n"
- "list. However, if you are on the access list, %s\n"
- "will not auto-kill you regardless of the setting of the\n"
- "\002KILL\002 option."), source.service->nick.c_str(), source.service->nick.c_str());
- return true;
- }
-};
-
-class CommandNSSASetSecure : public CommandNSSetSecure
-{
- public:
- CommandNSSASetSecure(Module *creator) : CommandNSSetSecure(creator, "nickserv/saset/secure", 2)
- {
- this->ClearSyntax();
- this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
- }
-
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params[1]);
}
-
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
- {
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("Turns %s's security features on or off for your\n"
- "nick. With \002SECURE\002 set, you must enter your password\n"
- "before you will be recognized as the owner of the nick,\n"
- "regardless of whether your address is on the access\n"
- "list. However, if you are on the access list, %s\n"
- "will not auto-kill you regardless of the setting of the\n"
- "\002KILL\002 option."), source.service->nick.c_str(), source.service->nick.c_str());
- return true;
- }
};
-class CommandNSSASetNoexpire : public Command
+class CommandNSSASetNoexpire final
+ : public Command
{
- public:
+public:
CommandNSSASetNoexpire(Module *creator) : Command(creator, "nickserv/saset/noexpire", 1, 2)
{
this->SetDesc(_("Prevent the nickname from expiring"));
this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (Anope::ReadOnly)
{
@@ -1138,7 +1141,7 @@ class CommandNSSASetNoexpire : public Command
this->OnSyntaxError(source, "NOEXPIRE");
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -1148,7 +1151,8 @@ class CommandNSSASetNoexpire : public Command
}
};
-class NSSet : public Module
+class NSSet final
+ : public Module
{
CommandNSSet commandnsset;
CommandNSSASet commandnssaset;
@@ -1156,6 +1160,9 @@ class NSSet : public Module
CommandNSSetAutoOp commandnssetautoop;
CommandNSSASetAutoOp commandnssasetautoop;
+ CommandNSSetNeverOp commandnssetneverop;
+ CommandNSSASetNeverOp commandnssasetneverop;
+
CommandNSSetDisplay commandnssetdisplay;
CommandNSSASetDisplay commandnssasetdisplay;
@@ -1177,19 +1184,17 @@ class NSSet : public Module
CommandNSSetPassword commandnssetpassword;
CommandNSSASetPassword commandnssasetpassword;
- CommandNSSetSecure commandnssetsecure;
- CommandNSSASetSecure commandnssasetsecure;
-
CommandNSSASetNoexpire commandnssasetnoexpire;
- SerializableExtensibleItem<bool> autoop, killprotect, kill_quick, kill_immed,
- message, secure, noexpire;
+ SerializableExtensibleItem<bool> autoop, neverop, killprotect, kill_quick, kill_immed,
+ message, noexpire;
- struct KeepModes : SerializableExtensibleItem<bool>
+ struct KeepModes final
+ : SerializableExtensibleItem<bool>
{
KeepModes(Module *m, const Anope::string &n) : SerializableExtensibleItem<bool>(m, n) { }
- void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
+ void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
{
SerializableExtensibleItem<bool>::ExtensibleSerialize(e, s, data);
@@ -1198,18 +1203,18 @@ class NSSet : public Module
const NickCore *nc = anope_dynamic_static_cast<const NickCore *>(s);
Anope::string modes;
- for (User::ModeList::const_iterator it = nc->last_modes.begin(); it != nc->last_modes.end(); ++it)
+ for (const auto &[last_mode, last_value] : nc->last_modes)
{
if (!modes.empty())
modes += " ";
- modes += it->first;
- if (!it->second.empty())
- modes += "," + it->second;
+ modes += last_mode;
+ if (!last_value.empty())
+ modes += "," + last_value;
}
data["last_modes"] << modes;
}
- void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
+ void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
{
SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data);
@@ -1224,9 +1229,9 @@ class NSSet : public Module
{
size_t c = modes.find(',');
if (c == Anope::string::npos)
- nc->last_modes.insert(std::make_pair(modes, ""));
+ nc->last_modes.emplace(modes, "");
else
- nc->last_modes.insert(std::make_pair(modes.substr(0, c), modes.substr(c + 1)));
+ nc->last_modes.emplace(modes.substr(0, c), modes.substr(c + 1));
}
}
} keep_modes;
@@ -1234,10 +1239,11 @@ class NSSet : public Module
/* email, passcode */
PrimitiveExtensibleItem<std::pair<Anope::string, Anope::string > > ns_set_email;
- public:
+public:
NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsset(this), commandnssaset(this),
commandnssetautoop(this), commandnssasetautoop(this),
+ commandnssetneverop(this), commandnssasetneverop(this),
commandnssetdisplay(this), commandnssasetdisplay(this),
commandnssetemail(this), commandnssasetemail(this),
commandnssetkeepmodes(this), commandnssasetkeepmodes(this),
@@ -1245,20 +1251,19 @@ class NSSet : public Module
commandnssetlanguage(this), commandnssasetlanguage(this),
commandnssetmessage(this), commandnssasetmessage(this),
commandnssetpassword(this), commandnssasetpassword(this),
- commandnssetsecure(this), commandnssasetsecure(this),
commandnssasetnoexpire(this),
- autoop(this, "AUTOOP"),
+ autoop(this, "AUTOOP"), neverop(this, "NEVEROP"),
killprotect(this, "KILLPROTECT"), kill_quick(this, "KILL_QUICK"),
kill_immed(this, "KILL_IMMED"), message(this, "MSG"),
- secure(this, "NS_SECURE"), noexpire(this, "NS_NO_EXPIRE"),
+ noexpire(this, "NS_NO_EXPIRE"),
keep_modes(this, "NS_KEEP_MODES"), ns_set_email(this, "ns_set_email")
{
}
- EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
NickCore *uac = source.nc;
@@ -1281,7 +1286,7 @@ class NSSet : public Module
return EVENT_CONTINUE;
}
- void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) anope_override
+ void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override
{
if (chan->ci)
{
@@ -1290,13 +1295,13 @@ class NSSet : public Module
}
}
- void OnPreNickExpire(NickAlias *na, bool &expire) anope_override
+ void OnPreNickExpire(NickAlias *na, bool &expire) override
{
if (noexpire.HasExt(na))
expire = false;
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override
{
if (!show_hidden)
return;
@@ -1307,41 +1312,40 @@ class NSSet : public Module
info.AddOption(_("Quick protection"));
else if (killprotect.HasExt(na->nc))
info.AddOption(_("Protection"));
- if (secure.HasExt(na->nc))
- info.AddOption(_("Security"));
if (message.HasExt(na->nc))
info.AddOption(_("Message mode"));
if (autoop.HasExt(na->nc))
info.AddOption(_("Auto-op"));
+ if (neverop.HasExt(na->nc))
+ info.AddOption(_("Never-op"));
if (noexpire.HasExt(na))
info.AddOption(_("No expire"));
if (keep_modes.HasExt(na->nc))
info.AddOption(_("Keep modes"));
}
- void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
+ void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override
{
if (u->Account() && setter.GetUser() == u)
u->Account()->last_modes = u->GetModeList();
}
- void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
+ void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) override
{
if (u->Account() && setter.GetUser() == u)
u->Account()->last_modes = u->GetModeList();
}
- void OnUserLogin(User *u) anope_override
+ void OnUserLogin(User *u) override
{
if (keep_modes.HasExt(u->Account()))
{
- User::ModeList modes = u->Account()->last_modes;
- for (User::ModeList::iterator it = modes.begin(); it != modes.end(); ++it)
+ for (const auto &[last_mode, last_value] : u->Account()->last_modes)
{
- UserMode *um = ModeManager::FindUserModeByName(it->first);
+ UserMode *um = ModeManager::FindUserModeByName(last_mode);
/* if the null user can set the mode, then it's probably safe */
if (um && um->CanSet(NULL))
- u->SetMode(NULL, it->first, it->second);
+ u->SetMode(NULL, last_mode, last_value);
}
}
}
diff --git a/modules/commands/ns_set_misc.cpp b/modules/nickserv/ns_set_misc.cpp
index 4430abd04..6f8ad0f4e 100644
--- a/modules/commands/ns_set_misc.cpp
+++ b/modules/nickserv/ns_set_misc.cpp
@@ -21,7 +21,7 @@ static Anope::map<ExtensibleItem<NSMiscData> *> items;
static ExtensibleItem<NSMiscData> *GetItem(const Anope::string &name)
{
- ExtensibleItem<NSMiscData>* &it = items[name];
+ ExtensibleItem<NSMiscData> *&it = items[name];
if (!it)
try
{
@@ -31,7 +31,9 @@ static ExtensibleItem<NSMiscData> *GetItem(const Anope::string &name)
return it;
}
-struct NSMiscData : MiscData, Serializable
+struct NSMiscData final
+ : MiscData
+ , Serializable
{
NSMiscData(Extensible *) : Serializable("NSMiscData") { }
@@ -42,14 +44,14 @@ struct NSMiscData : MiscData, Serializable
data = d;
}
- void Serialize(Serialize::Data &sdata) const anope_override
+ void Serialize(Serialize::Data &sdata) const override
{
sdata["nc"] << this->object;
sdata["name"] << this->name;
sdata["data"] << this->data;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string snc, sname, sdata;
@@ -88,9 +90,10 @@ static Anope::string GetAttribute(const Anope::string &command)
return command;
}
-class CommandNSSetMisc : public Command
+class CommandNSSetMisc
+ : public Command
{
- public:
+public:
CommandNSSetMisc(Module *creator, const Anope::string &cname = "nickserv/set/misc", size_t min = 0) : Command(creator, cname, min, min + 1)
{
this->SetSyntax(_("[\037parameter\037]"));
@@ -135,12 +138,12 @@ class CommandNSSetMisc : public Command
}
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, source.nc->display, !params.empty() ? params[0] : "");
}
- void OnServHelp(CommandSource &source) anope_override
+ void OnServHelp(CommandSource &source) override
{
if (descriptions.count(source.command))
{
@@ -149,7 +152,7 @@ class CommandNSSetMisc : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (descriptions.count(source.command))
{
@@ -161,41 +164,43 @@ class CommandNSSetMisc : public Command
}
};
-class CommandNSSASetMisc : public CommandNSSetMisc
+class CommandNSSASetMisc final
+ : public CommandNSSetMisc
{
- public:
+public:
CommandNSSASetMisc(Module *creator) : CommandNSSetMisc(creator, "nickserv/saset/misc", 1)
{
this->ClearSyntax();
this->SetSyntax(_("\037nickname\037 [\037parameter\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
this->Run(source, params[0], params.size() > 1 ? params[1] : "");
}
};
-class NSSetMisc : public Module
+class NSSetMisc final
+ : public Module
{
CommandNSSetMisc commandnssetmisc;
CommandNSSASetMisc commandnssasetmisc;
Serialize::Type nsmiscdata_type;
- public:
+public:
NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnssetmisc(this), commandnssasetmisc(this), nsmiscdata_type("NSMiscData", NSMiscData::Unserialize)
{
me = this;
}
- ~NSSetMisc()
+ ~NSSetMisc() override
{
- for (Anope::map<ExtensibleItem<NSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it)
- delete it->second;
+ for (const auto &[_, data] : items)
+ delete data;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
descriptions.clear();
@@ -218,11 +223,10 @@ class NSSetMisc : public Module
}
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool) override
{
- for (Anope::map<ExtensibleItem<NSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it)
+ for (const auto &[_, e] : items)
{
- ExtensibleItem<NSMiscData> *e = it->second;
NSMiscData *data = e->Get(na->nc);
if (data != NULL)
diff --git a/modules/commands/ns_suspend.cpp b/modules/nickserv/ns_suspend.cpp
index cf2b19834..8ce2806ca 100644
--- a/modules/commands/ns_suspend.cpp
+++ b/modules/nickserv/ns_suspend.cpp
@@ -14,11 +14,13 @@
static ServiceReference<NickServService> nickserv("NickServService", "NickServ");
-struct NSSuspendInfo : SuspendInfo, Serializable
+struct NSSuspendInfo final
+ : SuspendInfo
+ , Serializable
{
NSSuspendInfo(Extensible *) : Serializable("NSSuspendInfo") { }
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["nick"] << what;
data["by"] << by;
@@ -27,7 +29,7 @@ struct NSSuspendInfo : SuspendInfo, Serializable
data["expires"] << expires;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string snick;
data["nick"] >> snick;
@@ -52,16 +54,17 @@ struct NSSuspendInfo : SuspendInfo, Serializable
}
};
-class CommandNSSuspend : public Command
+class CommandNSSuspend final
+ : public Command
{
- public:
+public:
CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 3)
{
this->SetDesc(_("Suspend a given nick"));
this->SetSyntax(_("\037nickname\037 [+\037expiry\037] [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = params[0];
@@ -116,10 +119,8 @@ class CommandNSSuspend : public Command
si->when = Anope::CurTime;
si->expires = expiry_secs ? expiry_secs + Anope::CurTime : 0;
- for (unsigned i = 0; i < nc->aliases->size(); ++i)
+ for (auto *na2 : *nc->aliases)
{
- NickAlias *na2 = nc->aliases->at(i);
-
if (na2 && *na2->nc == *na->nc)
{
na2->last_quit = reason;
@@ -140,7 +141,7 @@ class CommandNSSuspend : public Command
FOREACH_MOD(OnNickSuspend, (na));
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -152,16 +153,17 @@ class CommandNSSuspend : public Command
}
};
-class CommandNSUnSuspend : public Command
+class CommandNSUnSuspend final
+ : public Command
{
- public:
+public:
CommandNSUnSuspend(Module *creator) : Command(creator, "nickserv/unsuspend", 1, 1)
{
this->SetDesc(_("Unsuspend a given nick"));
this->SetSyntax(_("\037nickname\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = params[0];
@@ -192,7 +194,7 @@ class CommandNSUnSuspend : public Command
FOREACH_MOD(OnNickUnsuspended, (na));
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -201,7 +203,8 @@ class CommandNSUnSuspend : public Command
}
};
-class NSSuspend : public Module
+class NSSuspend final
+ : public Module
{
CommandNSSuspend commandnssuspend;
CommandNSUnSuspend commandnsunsuspend;
@@ -209,7 +212,7 @@ class NSSuspend : public Module
Serialize::Type suspend_type;
std::vector<Anope::string> show;
- struct trim
+ struct trim final
{
Anope::string operator()(Anope::string s) const
{
@@ -222,21 +225,21 @@ class NSSuspend : public Module
return source.IsOper() || std::find(show.begin(), show.end(), what) != show.end();
}
- public:
+public:
NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnssuspend(this), commandnsunsuspend(this), suspend(this, "NS_SUSPENDED"),
suspend_type("NSSuspendInfo", NSSuspendInfo::Unserialize)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Anope::string s = conf->GetModule(this)->Get<Anope::string>("show");
commasepstream(s).GetTokens(show);
std::transform(show.begin(), show.end(), show.begin(), trim());
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override
{
NSSuspendInfo *s = suspend.Get(na->nc);
if (!s)
@@ -254,7 +257,7 @@ class NSSuspend : public Module
info[_("Suspension expires")] = Anope::strftime(s->expires, source.GetAccount());
}
- void OnPreNickExpire(NickAlias *na, bool &expire) anope_override
+ void OnPreNickExpire(NickAlias *na, bool &expire) override
{
NSSuspendInfo *s = suspend.Get(na->nc);
if (!s)
@@ -274,7 +277,7 @@ class NSSuspend : public Module
}
}
- EventReturn OnNickValidate(User *u, NickAlias *na) anope_override
+ EventReturn OnNickValidate(User *u, NickAlias *na) override
{
NSSuspendInfo *s = suspend.Get(na->nc);
if (!s)
diff --git a/modules/commands/ns_update.cpp b/modules/nickserv/ns_update.cpp
index 5f23c9127..6980a4207 100644
--- a/modules/commands/ns_update.cpp
+++ b/modules/nickserv/ns_update.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandNSUpdate : public Command
+class CommandNSUpdate final
+ : public Command
{
- public:
+public:
CommandNSUpdate(Module *creator) : Command(creator, "nickserv/update", 0, 0)
{
this->SetDesc(_("Updates your current status, i.e. it checks for new memos"));
this->RequireUser(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
User *u = source.GetUser();
NickAlias *na = NickAlias::Find(u->nick);
@@ -36,7 +37,7 @@ class CommandNSUpdate : public Command
source.Reply(_("Status updated (memos, vhost, chmodes, flags)."));
}
- bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -47,11 +48,12 @@ class CommandNSUpdate : public Command
}
};
-class NSUpdate : public Module
+class NSUpdate final
+ : public Module
{
CommandNSUpdate commandnsupdate;
- public:
+public:
NSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsupdate(this)
{
diff --git a/modules/pseudoclients/operserv.cpp b/modules/operserv/operserv.cpp
index 22a02f1e3..02866109c 100644
--- a/modules/pseudoclients/operserv.cpp
+++ b/modules/operserv/operserv.cpp
@@ -11,32 +11,33 @@
#include "module.h"
-class SGLineManager : public XLineManager
+class SGLineManager final
+ : public XLineManager
{
- public:
+public:
SGLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sgline", 'G') { }
- void OnMatch(User *u, XLine *x) anope_override
+ void OnMatch(User *u, XLine *x) override
{
this->Send(u, x);
}
- void OnExpire(const XLine *x) anope_override
+ void OnExpire(const XLine *x) override
{
Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->mask << "\002 has expired";
}
- void Send(User *u, XLine *x) anope_override
+ void Send(User *u, XLine *x) override
{
IRCD->SendAkill(u, x);
}
- void SendDel(XLine *x) anope_override
+ void SendDel(XLine *x) override
{
IRCD->SendAkillDel(x);
}
- bool Check(User *u, const XLine *x) anope_override
+ bool Check(User *u, const XLine *x) override
{
if (x->regex)
{
@@ -63,24 +64,25 @@ class SGLineManager : public XLineManager
}
};
-class SQLineManager : public XLineManager
+class SQLineManager final
+ : public XLineManager
{
ServiceReference<NickServService> nickserv;
- public:
+public:
SQLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sqline", 'Q'), nickserv("NickServService", "NickServ") { }
- void OnMatch(User *u, XLine *x) anope_override
+ void OnMatch(User *u, XLine *x) override
{
this->Send(u, x);
}
- void OnExpire(const XLine *x) anope_override
+ void OnExpire(const XLine *x) override
{
Log(Config->GetClient("OperServ"), "expire/sqline") << "SQLINE on \002" << x->mask << "\002 has expired";
}
- void Send(User *u, XLine *x) anope_override
+ void Send(User *u, XLine *x) override
{
if (!IRCD->CanSQLine)
{
@@ -105,7 +107,7 @@ class SQLineManager : public XLineManager
}
}
- void SendDel(XLine *x) anope_override
+ void SendDel(XLine *x) override
{
if (!IRCD->CanSQLine || x->IsRegex())
;
@@ -113,7 +115,7 @@ class SQLineManager : public XLineManager
IRCD->SendSQLineDel(x);
}
- bool Check(User *u, const XLine *x) anope_override
+ bool Check(User *u, const XLine *x) override
{
if (x->regex)
return x->regex->Matches(u->nick);
@@ -122,10 +124,8 @@ class SQLineManager : public XLineManager
XLine *CheckChannel(Channel *c)
{
- for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it)
+ for (auto *x : this->GetList())
{
- XLine *x = *it;
-
if (x->regex)
{
if (x->regex->Matches(c->name))
@@ -144,22 +144,23 @@ class SQLineManager : public XLineManager
}
};
-class SNLineManager : public XLineManager
+class SNLineManager final
+ : public XLineManager
{
- public:
+public:
SNLineManager(Module *creator) : XLineManager(creator, "xlinemanager/snline", 'N') { }
- void OnMatch(User *u, XLine *x) anope_override
+ void OnMatch(User *u, XLine *x) override
{
this->Send(u, x);
}
- void OnExpire(const XLine *x) anope_override
+ void OnExpire(const XLine *x) override
{
Log(Config->GetClient("OperServ"), "expire/snline") << "SNLINE on \002" << x->mask << "\002 has expired";
}
- void Send(User *u, XLine *x) anope_override
+ void Send(User *u, XLine *x) override
{
if (IRCD->CanSNLine && !x->IsRegex())
IRCD->SendSGLine(u, x);
@@ -168,13 +169,13 @@ class SNLineManager : public XLineManager
u->Kill(Config->GetClient("OperServ"), "SNLined: " + x->reason);
}
- void SendDel(XLine *x) anope_override
+ void SendDel(XLine *x) override
{
if (IRCD->CanSNLine && !x->IsRegex())
IRCD->SendSGLineDel(x);
}
- bool Check(User *u, const XLine *x) anope_override
+ bool Check(User *u, const XLine *x) override
{
if (x->regex)
return x->regex->Matches(u->realname);
@@ -182,14 +183,15 @@ class SNLineManager : public XLineManager
}
};
-class OperServCore : public Module
+class OperServCore final
+ : public Module
{
Reference<BotInfo> OperServ;
SGLineManager sglines;
SQLineManager sqlines;
SNLineManager snlines;
- public:
+public:
OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR),
sglines(this), sqlines(this), snlines(this)
{
@@ -200,7 +202,7 @@ class OperServCore : public Module
XLineManager::RegisterXLineManager(&snlines);
}
- ~OperServCore()
+ ~OperServCore() override
{
this->sglines.Clear();
this->sqlines.Clear();
@@ -211,7 +213,7 @@ class OperServCore : public Module
XLineManager::UnregisterXLineManager(&snlines);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
const Anope::string &osnick = conf->GetModule(this)->Get<const Anope::string>("client");
@@ -225,7 +227,7 @@ class OperServCore : public Module
OperServ = bi;
}
- EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) anope_override
+ EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message, const Anope::map<Anope::string> &tags) override
{
if (bi == OperServ && !u->HasMode("OPER") && Config->GetModule(this)->Get<bool>("opersonly"))
{
@@ -237,37 +239,37 @@ class OperServCore : public Module
return EVENT_CONTINUE;
}
- void OnServerQuit(Server *server) anope_override
+ void OnServerQuit(Server *server) override
{
if (server->IsJuped())
Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName();
}
- void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
+ void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override
{
if (mname == "OPER")
Log(u, "oper", OperServ) << "is now an IRC operator.";
}
- void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
+ void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) override
{
if (mname == "OPER")
Log(u, "oper", OperServ) << "is no longer an IRC operator";
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (!u->Quitting() && !exempt)
XLineManager::CheckAll(u);
}
- void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override
+ void OnUserNickChange(User *u, const Anope::string &oldnick) override
{
if (!u->HasMode("OPER"))
this->sqlines.CheckAllXLines(u);
}
- EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_override
+ EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
{
XLine *x = this->sqlines.CheckChannel(c);
if (x)
@@ -280,7 +282,7 @@ class OperServCore : public Module
return EVENT_CONTINUE;
}
- EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!params.empty() || source.c || source.service != *OperServ)
return EVENT_CONTINUE;
@@ -288,7 +290,7 @@ class OperServCore : public Module
return EVENT_CONTINUE;
}
- void OnLog(Log *l) anope_override
+ void OnLog(Log *l) override
{
if (l->type == LOG_SERVER)
l->bi = OperServ;
diff --git a/modules/commands/os_akill.cpp b/modules/operserv/os_akill.cpp
index 665b41541..7fcacd9ad 100644
--- a/modules/commands/os_akill.cpp
+++ b/modules/operserv/os_akill.cpp
@@ -13,17 +13,18 @@
static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
-class AkillDelCallback : public NumberList
+class AkillDelCallback final
+ : public NumberList
{
CommandSource &source;
- unsigned deleted;
+ unsigned deleted = 0;
Command *cmd;
- public:
- AkillDelCallback(CommandSource &_source, const Anope::string &numlist, Command *c) : NumberList(numlist, true), source(_source), deleted(0), cmd(c)
+public:
+ AkillDelCallback(CommandSource &_source, const Anope::string &numlist, Command *c) : NumberList(numlist, true), source(_source), cmd(c)
{
}
- ~AkillDelCallback()
+ ~AkillDelCallback() override
{
if (!deleted)
source.Reply(_("No matching entries on the AKILL list."));
@@ -33,7 +34,7 @@ class AkillDelCallback : public NumberList
source.Reply(_("Deleted %d entries from the AKILL list."), deleted);
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number)
return;
@@ -55,9 +56,10 @@ class AkillDelCallback : public NumberList
}
};
-class CommandOSAKill : public Command
+class CommandOSAKill final
+ : public Command
{
- private:
+private:
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
Anope::string expiry, mask;
@@ -167,13 +169,13 @@ class CommandOSAKill : public Command
return;
}
- XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ auto *x = new XLine(mask, source.GetNick(), expires, reason);
if (Config->GetModule("operserv")->Get<bool>("akillids"))
x->id = XLineManager::GenerateUID();
unsigned int affected = 0;
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (akills->Check(it->second, x))
+ for (const auto &[_, user] : UserListByNick)
+ if (akills->Check(user, x))
++affected;
float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
@@ -262,16 +264,17 @@ class CommandOSAKill : public Command
if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class ListCallback : public NumberList
+ class ListCallback final
+ : public NumberList
{
CommandSource &source;
ListFormatter &list;
- public:
+ public:
ListCallback(CommandSource &_source, ListFormatter &_list, const Anope::string &numstr) : NumberList(numstr, false), source(_source), list(_list)
{
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number)
return;
@@ -282,7 +285,7 @@ class CommandOSAKill : public Command
return;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(number);
+ entry["Number"] = Anope::ToString(number);
entry["Mask"] = x->mask;
entry["Creator"] = x->by;
entry["Created"] = Anope::strftime(x->created, NULL, true);
@@ -304,7 +307,7 @@ class CommandOSAKill : public Command
if (mask.empty() || mask.equals_ci(x->mask) || mask == x->id || Anope::Match(x->mask, mask, false, true))
{
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Mask"] = x->mask;
entry["Creator"] = x->by;
entry["Created"] = Anope::strftime(x->created, NULL, true);
@@ -325,8 +328,8 @@ class CommandOSAKill : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of AKILL list."));
}
@@ -379,7 +382,7 @@ class CommandOSAKill : public Command
if (Anope::ReadOnly)
source.Reply(READ_ONLY_MODE);
}
- public:
+public:
CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 2)
{
this->SetDesc(_("Manipulate the AKILL list"));
@@ -390,7 +393,7 @@ class CommandOSAKill : public Command
this->SetSyntax("CLEAR");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
@@ -413,12 +416,12 @@ class CommandOSAKill : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows Services Operators to manipulate the AKILL list. If\n"
- "a user matching an AKILL mask attempts to connect, Services\n"
+ "a user matching an AKILL mask attempts to connect, services\n"
"will issue a KILL for that user and, on supported server\n"
"types, will instruct all servers to add a ban for the mask\n"
"which the user matched.\n"
@@ -468,11 +471,12 @@ class CommandOSAKill : public Command
}
};
-class OSAKill : public Module
+class OSAKill final
+ : public Module
{
CommandOSAKill commandosakill;
- public:
+public:
OSAKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosakill(this)
{
diff --git a/modules/commands/os_chankill.cpp b/modules/operserv/os_chankill.cpp
index 4fff79184..311e8f3d1 100644
--- a/modules/commands/os_chankill.cpp
+++ b/modules/operserv/os_chankill.cpp
@@ -13,16 +13,17 @@
static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
-class CommandOSChanKill : public Command
+class CommandOSChanKill final
+ : public Command
{
- public:
+public:
CommandOSChanKill(Module *creator) : Command(creator, "operserv/chankill", 2, 3)
{
this->SetDesc(_("AKILL all users on a specific channel"));
this->SetSyntax(_("[+\037expiry\037] \037channel\037 \037reason\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!akills)
return;
@@ -69,10 +70,8 @@ class CommandOSChanKill : public Command
if ((c = Channel::Find(channel)))
{
- for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : c->users)
{
- ChanUserContainer *uc = it->second;
-
if (uc->user->server == Me || uc->user->HasMode("OPER"))
continue;
@@ -80,7 +79,7 @@ class CommandOSChanKill : public Command
if (akills->HasEntry(akillmask))
continue;
- XLine *x = new XLine(akillmask, source.GetNick(), expires, realreason, XLineManager::GenerateUID());
+ auto *x = new XLine(akillmask, source.GetNick(), expires, realreason, XLineManager::GenerateUID());
akills->AddXLine(x);
akills->OnMatch(uc->user, x);
}
@@ -93,7 +92,7 @@ class CommandOSChanKill : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -104,11 +103,12 @@ class CommandOSChanKill : public Command
}
};
-class OSChanKill : public Module
+class OSChanKill final
+ : public Module
{
CommandOSChanKill commandoschankill;
- public:
+public:
OSChanKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandoschankill(this)
{
diff --git a/modules/commands/os_config.cpp b/modules/operserv/os_config.cpp
index 97a8c6fff..2a9ede9e7 100644
--- a/modules/commands/os_config.cpp
+++ b/modules/operserv/os_config.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSConfig : public Command
+class CommandOSConfig final
+ : public Command
{
- public:
+public:
CommandOSConfig(Module *creator) : Command(creator, "operserv/config", 1, 4)
{
this->SetDesc(_("View and change configuration file settings"));
this->SetSyntax(_("{\037MODIFY\037|\037VIEW\037} [\037block name\037 \037item name\037 \037item value\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &what = params[0];
@@ -57,19 +58,16 @@ class CommandOSConfig : public Command
for (unsigned i = 0; !show_blocks[i].empty(); ++i)
{
Configuration::Block *block = Config->GetBlock(show_blocks[i]);
- const Configuration::Block::item_map *items = block->GetItems();
-
- if (!items)
- continue;
+ const Configuration::Block::item_map &items = block->GetItems();
ListFormatter lflist(source.GetAccount());
lflist.AddColumn(_("Name")).AddColumn(_("Value"));
- for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
+ for (const auto &[name, value] : items)
{
ListFormatter::ListEntry entry;
- entry["Name"] = it->first;
- entry["Value"] = it->second;
+ entry["Name"] = name;
+ entry["Value"] = value;
lflist.AddEntry(entry);
}
@@ -78,8 +76,8 @@ class CommandOSConfig : public Command
source.Reply(_("%s settings:"), block->GetName().c_str());
- for (unsigned j = 0; j < replies.size(); ++j)
- source.Reply(replies[j]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(" ");
}
@@ -90,18 +88,18 @@ class CommandOSConfig : public Command
for (int i = 0; i < Config->CountBlock("module"); ++i)
{
Configuration::Block *block = Config->GetBlock("module", i);
- const Configuration::Block::item_map *items = block->GetItems();
+ const Configuration::Block::item_map &items = block->GetItems();
- if (!items || items->size() <= 1)
+ if (items.size() <= 1)
continue;
ListFormatter::ListEntry entry;
entry["Module Name"] = block->Get<Anope::string>("name");
- for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
+ for (const auto &[name, value] : items)
{
- entry["Name"] = it->first;
- entry["Value"] = it->second;
+ entry["Name"] = name;
+ entry["Value"] = value;
lflist.AddEntry(entry);
}
}
@@ -111,8 +109,8 @@ class CommandOSConfig : public Command
source.Reply(_("Module settings:"));
- for (unsigned j = 0; j < replies.size(); ++j)
- source.Reply(replies[j]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of configuration."));
}
@@ -120,7 +118,7 @@ class CommandOSConfig : public Command
this->OnSyntaxError(source, what);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -135,11 +133,12 @@ class CommandOSConfig : public Command
}
};
-class OSConfig : public Module
+class OSConfig final
+ : public Module
{
CommandOSConfig commandosconfig;
- public:
+public:
OSConfig(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosconfig(this)
{
diff --git a/modules/commands/os_defcon.cpp b/modules/operserv/os_defcon.cpp
index 29cad740c..564cfec50 100644
--- a/modules/commands/os_defcon.cpp
+++ b/modules/operserv/os_defcon.cpp
@@ -28,7 +28,7 @@ enum DefconLevel
bool DefConModesSet = false;
-struct DefconConfig
+struct DefconConfig final
{
std::vector<std::bitset<32> > DefCon;
std::set<Anope::string> DefConModesOn, DefConModesOff;
@@ -72,7 +72,7 @@ struct DefconConfig
bool SetDefConParam(const Anope::string &name, const Anope::string &buf)
{
- return DefConModesOnParams.insert(std::make_pair(name, buf)).second;
+ return DefConModesOnParams.emplace(name, buf).second;
}
void UnsetDefConParam(const Anope::string &name)
@@ -105,22 +105,25 @@ static ServiceReference<GlobalService> GlobalService("GlobalService", "Global");
static Timer *timeout;
-class DefConTimeout : public Timer
+class DefConTimeout final
+ : public Timer
{
int level;
- public:
- DefConTimeout(Module *mod, int newlevel) : Timer(mod, DConfig.timeout), level(newlevel)
+public:
+ DefConTimeout(Module *mod, int newlevel)
+ : Timer(mod, DConfig.timeout)
+ , level(newlevel)
{
timeout = this;
}
- ~DefConTimeout()
+ ~DefConTimeout() override
{
timeout = NULL;
}
- void Tick(time_t) anope_override
+ void Tick() override
{
if (DConfig.defaultlevel != level)
{
@@ -144,9 +147,10 @@ class DefConTimeout : public Timer
}
};
-class CommandOSDefcon : public Command
+class CommandOSDefcon final
+ : public Command
{
- void SendLevels(CommandSource &source)
+ static void SendLevels(CommandSource &source)
{
if (DConfig.Check(DEFCON_NO_NEW_CHANNELS))
source.Reply(_("* No new channel registrations"));
@@ -170,14 +174,14 @@ class CommandOSDefcon : public Command
source.Reply(_("* No new memos sent"));
}
- public:
+public:
CommandOSDefcon(Module *creator) : Command(creator, "operserv/defcon", 1, 1)
{
this->SetDesc(_("Manipulate the DefCon system"));
this->SetSyntax(_("[\0021\002|\0022\002|\0023\002|\0024\002|\0025\002]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &lvl = params[0];
@@ -188,13 +192,7 @@ class CommandOSDefcon : public Command
return;
}
- int newLevel = 0;
- try
- {
- newLevel = convertTo<int>(lvl);
- }
- catch (const ConvertException &) { }
-
+ auto newLevel = Anope::Convert<int>(lvl, 0);
if (newLevel < 1 || newLevel > 5)
{
this->OnSyntaxError(source, "");
@@ -233,7 +231,7 @@ class CommandOSDefcon : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -244,7 +242,8 @@ class CommandOSDefcon : public Command
}
};
-class OSDefcon : public Module
+class OSDefcon final
+ : public Module
{
ServiceReference<SessionService> session_service;
ServiceReference<XLineManager> akills;
@@ -253,7 +252,6 @@ class OSDefcon : public Module
void ParseModeString()
{
int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */
- unsigned char mode;
ChannelMode *cm;
ChannelModeParam *cmp;
Anope::string modes, param;
@@ -265,10 +263,8 @@ class OSDefcon : public Module
ss.GetToken(modes);
/* Loop while there are modes to set */
- for (unsigned i = 0, end = modes.length(); i < end; ++i)
+ for (auto mode : modes)
{
- mode = modes[i];
-
switch (mode)
{
case '+':
@@ -329,13 +325,13 @@ class OSDefcon : public Module
}
}
- public:
+public:
OSDefcon(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), session_service("SessionService", "session"), akills("XLineManager", "xlinemanager/sgline"), commandosdefcon(this)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
DefconConfig dconfig;
@@ -406,7 +402,7 @@ class OSDefcon : public Module
this->ParseModeString();
}
- EventReturn OnChannelModeSet(Channel *c, MessageSource &source, ChannelMode *mode, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &source, ChannelMode *mode, const Anope::string &param) override
{
if (DConfig.Check(DEFCON_FORCE_CHAN_MODES) && DConfig.DefConModesOff.count(mode->name) && source.GetUser() && !source.GetBot())
{
@@ -418,7 +414,7 @@ class OSDefcon : public Module
return EVENT_CONTINUE;
}
- EventReturn OnChannelModeUnset(Channel *c, MessageSource &source, ChannelMode *mode, const Anope::string &) anope_override
+ EventReturn OnChannelModeUnset(Channel *c, MessageSource &source, ChannelMode *mode, const Anope::string &) override
{
if (DConfig.Check(DEFCON_FORCE_CHAN_MODES) && DConfig.DefConModesOn.count(mode->name) && source.GetUser() && !source.GetBot())
{
@@ -436,7 +432,7 @@ class OSDefcon : public Module
return EVENT_CONTINUE;
}
- EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
if (DConfig.Check(DEFCON_OPER_ONLY) && !source.IsOper())
{
@@ -483,7 +479,7 @@ class OSDefcon : public Module
return EVENT_CONTINUE;
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (exempt || u->Quitting() || !u->server->IsSynced() || u->server->IsULined())
return;
@@ -535,16 +531,16 @@ class OSDefcon : public Module
}
}
- void OnChannelModeAdd(ChannelMode *cm) anope_override
+ void OnChannelModeAdd(ChannelMode *cm) override
{
if (DConfig.chanmodes.find(cm->mchar) != Anope::string::npos)
this->ParseModeString();
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (DConfig.Check(DEFCON_FORCE_CHAN_MODES))
- c->SetModes(Config->GetClient("OperServ"), false, "%s", DConfig.chanmodes.c_str());
+ c->SetModes(Config->GetClient("OperServ"), false, DConfig.chanmodes);
}
};
@@ -559,8 +555,8 @@ static void runDefCon()
{
Log(OperServ, "operserv/defcon") << "DEFCON: setting " << DConfig.chanmodes << " on all channels";
DefConModesSet = true;
- for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
- it->second->SetModes(OperServ, false, "%s", DConfig.chanmodes.c_str());
+ for (const auto &[_, chan] : ChannelList)
+ chan->SetModes(OperServ, false, DConfig.chanmodes);
}
}
}
@@ -575,8 +571,8 @@ static void runDefCon()
if (!newmodes.empty())
{
Log(OperServ, "operserv/defcon") << "DEFCON: setting " << newmodes << " on all channels";
- for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
- it->second->SetModes(OperServ, true, "%s", newmodes.c_str());
+ for (const auto &[_, chan] : ChannelList)
+ chan->SetModes(OperServ, true, newmodes);
}
}
}
@@ -588,14 +584,14 @@ static Anope::string defconReverseModes(const Anope::string &modes)
if (modes.empty())
return "";
Anope::string newmodes;
- for (unsigned i = 0, end = modes.length(); i < end; ++i)
+ for (auto mode : modes)
{
- if (modes[i] == '+')
+ if (mode == '+')
newmodes += '-';
- else if (modes[i] == '-')
+ else if (mode == '-')
newmodes += '+';
else
- newmodes += modes[i];
+ newmodes += mode;
}
return newmodes;
}
diff --git a/modules/commands/os_dns.cpp b/modules/operserv/os_dns.cpp
index 76a2bacb3..18e53b25a 100644
--- a/modules/commands/os_dns.cpp
+++ b/modules/operserv/os_dns.cpp
@@ -19,7 +19,8 @@ static Serialize::Checker<std::vector<DNSServer *> > dns_servers("DNSServer");
static std::map<Anope::string, std::list<time_t> > server_quit_times;
-struct DNSZone : Serializable
+struct DNSZone final
+ : Serializable
{
Anope::string name;
std::set<Anope::string, ci::less> servers;
@@ -29,22 +30,22 @@ struct DNSZone : Serializable
zones->push_back(this);
}
- ~DNSZone()
+ ~DNSZone() override
{
std::vector<DNSZone *>::iterator it = std::find(zones->begin(), zones->end(), this);
if (it != zones->end())
zones->erase(it);
}
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["name"] << name;
unsigned count = 0;
- for (std::set<Anope::string, ci::less>::iterator it = servers.begin(), it_end = servers.end(); it != it_end; ++it)
- data["server" + stringify(count++)] << *it;
+ for (const auto &server : servers)
+ data["server" + Anope::ToString(count++)] << server;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
DNSZone *zone;
Anope::string zone_name;
@@ -63,7 +64,7 @@ struct DNSZone : Serializable
for (unsigned count = 0; true; ++count)
{
Anope::string server_str;
- data["server" + stringify(count)] >> server_str;
+ data["server" + Anope::ToString(count)] >> server_str;
if (server_str.empty())
break;
zone->servers.insert(server_str);
@@ -74,37 +75,39 @@ struct DNSZone : Serializable
static DNSZone *Find(const Anope::string &name)
{
- for (unsigned i = 0; i < zones->size(); ++i)
- if (zones->at(i)->name.equals_ci(name))
+ for (auto *zone : *zones)
+ {
+ if (zone->name.equals_ci(name))
{
- DNSZone *z = zones->at(i);
- z->QueueUpdate();
- return z;
+ zone->QueueUpdate();
+ return zone;
}
+ }
return NULL;
}
};
-class DNSServer : public Serializable
+class DNSServer final
+ : public Serializable
{
Anope::string server_name;
std::vector<Anope::string> ips;
- unsigned limit;
+ unsigned limit = 0;
/* wants to be in the pool */
- bool pooled;
+ bool pooled = false;
/* is actually in the pool */
- bool active;
+ bool active = false;
- public:
+public:
std::set<Anope::string, ci::less> zones;
- time_t repool;
+ time_t repool = 0;
- DNSServer(const Anope::string &sn) : Serializable("DNSServer"), server_name(sn), limit(0), pooled(false), active(false), repool(0)
+ DNSServer(const Anope::string &sn) : Serializable("DNSServer"), server_name(sn)
{
dns_servers->push_back(this);
}
- ~DNSServer()
+ ~DNSServer() override
{
std::vector<DNSServer *>::iterator it = std::find(dns_servers->begin(), dns_servers->end(), this);
if (it != dns_servers->end())
@@ -134,24 +137,24 @@ class DNSServer : public Serializable
if (dnsmanager)
{
dnsmanager->UpdateSerial();
- for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it)
- dnsmanager->Notify(*it);
+ for (const auto &zone : zones)
+ dnsmanager->Notify(zone);
}
}
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["server_name"] << server_name;
for (unsigned i = 0; i < ips.size(); ++i)
- data["ip" + stringify(i)] << ips[i];
+ data["ip" + Anope::ToString(i)] << ips[i];
data["limit"] << limit;
data["pooled"] << pooled;
unsigned count = 0;
- for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it)
- data["zone" + stringify(count++)] << *it;
+ for (const auto &zone : zones)
+ data["zone" + Anope::ToString(count++)] << zone;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
DNSServer *req;
Anope::string server_name;
@@ -169,7 +172,7 @@ class DNSServer : public Serializable
for (unsigned i = 0; true; ++i)
{
Anope::string ip_str;
- data["ip" + stringify(i)] >> ip_str;
+ data["ip" + Anope::ToString(i)] >> ip_str;
if (ip_str.empty())
break;
req->ips.push_back(ip_str);
@@ -182,7 +185,7 @@ class DNSServer : public Serializable
for (unsigned i = 0; true; ++i)
{
Anope::string zone_str;
- data["zone" + stringify(i)] >> zone_str;
+ data["zone" + Anope::ToString(i)] >> zone_str;
if (zone_str.empty())
break;
req->zones.insert(zone_str);
@@ -193,10 +196,9 @@ class DNSServer : public Serializable
static DNSServer *Find(const Anope::string &s)
{
- for (unsigned i = 0; i < dns_servers->size(); ++i)
- if (dns_servers->at(i)->GetName().equals_ci(s))
+ for (auto *serv : *dns_servers)
+ if (serv->GetName().equals_ci(s))
{
- DNSServer *serv = dns_servers->at(i);
serv->QueueUpdate();
return serv;
}
@@ -204,9 +206,10 @@ class DNSServer : public Serializable
}
};
-class CommandOSDNS : public Command
+class CommandOSDNS final
+ : public Command
{
- void DisplayPoolState(CommandSource &source)
+ static void DisplayPoolState(CommandSource &source)
{
if (dns_servers->empty())
{
@@ -216,18 +219,17 @@ class CommandOSDNS : public Command
ListFormatter lf(source.GetAccount());
lf.AddColumn(_("Server")).AddColumn(_("IP")).AddColumn(_("Limit")).AddColumn(_("State"));
- for (unsigned i = 0; i < dns_servers->size(); ++i)
+ for (auto *s : *dns_servers)
{
- DNSServer *s = dns_servers->at(i);
Server *srv = Server::Find(s->GetName(), true);
ListFormatter::ListEntry entry;
entry["Server"] = s->GetName();
- entry["Limit"] = s->GetLimit() ? stringify(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None"));
+ entry["Limit"] = s->GetLimit() ? Anope::ToString(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None"));
Anope::string ip_str;
- for (unsigned j = 0; j < s->GetIPs().size(); ++j)
- ip_str += s->GetIPs()[j] + " ";
+ for (const auto &ip : s->GetIPs())
+ ip_str += ip + " ";
ip_str.trim();
if (ip_str.empty())
ip_str = "None";
@@ -254,16 +256,14 @@ class CommandOSDNS : public Command
ListFormatter lf2(source.GetAccount());
lf2.AddColumn(_("Zone")).AddColumn(_("Servers"));
- for (unsigned i = 0; i < zones->size(); ++i)
+ for (auto *z : *zones)
{
- const DNSZone *z = zones->at(i);
-
ListFormatter::ListEntry entry;
entry["Zone"] = z->name;
Anope::string server_str;
- for (std::set<Anope::string, ci::less>::iterator it = z->servers.begin(), it_end = z->servers.end(); it != it_end; ++it)
- server_str += *it + " ";
+ for (const auto &server : z->servers)
+ server_str += server + " ";
server_str.trim();
if (server_str.empty())
@@ -277,8 +277,8 @@ class CommandOSDNS : public Command
lf2.Process(replies);
}
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
void AddZone(CommandSource &source, const std::vector<Anope::string> &params)
@@ -316,9 +316,9 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to delete zone " << z->name;
- for (std::set<Anope::string, ci::less>::iterator it = z->servers.begin(), it_end = z->servers.end(); it != it_end; ++it)
+ for (const auto &server : z->servers)
{
- DNSServer *s = DNSServer::Find(*it);
+ DNSServer *s = DNSServer::Find(server);
if (s)
s->zones.erase(z->name);
}
@@ -466,9 +466,9 @@ class CommandOSDNS : public Command
return;
}
- for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it)
+ for (const auto &zone : s->zones)
{
- DNSZone *z = DNSZone::Find(*it);
+ DNSZone *z = DNSZone::Find(zone);
if (z)
z->servers.erase(s->GetName());
}
@@ -494,12 +494,14 @@ class CommandOSDNS : public Command
return;
}
- for (unsigned i = 0; i < s->GetIPs().size(); ++i)
- if (params[2].equals_ci(s->GetIPs()[i]))
+ for (const auto &ip : s->GetIPs())
+ {
+ if (params[2].equals_ci(ip))
{
- source.Reply(_("IP %s already exists for %s."), s->GetIPs()[i].c_str(), s->GetName().c_str());
+ source.Reply(_("IP %s already exists for %s."), ip.c_str(), s->GetName().c_str());
return;
}
+ }
sockaddrs addr(params[2]);
if (!addr.valid())
@@ -518,8 +520,8 @@ class CommandOSDNS : public Command
if (s->Active() && dnsmanager)
{
dnsmanager->UpdateSerial();
- for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it)
- dnsmanager->Notify(*it);
+ for (const auto &zone : s->zones)
+ dnsmanager->Notify(zone);
}
}
@@ -552,8 +554,8 @@ class CommandOSDNS : public Command
if (s->Active() && dnsmanager)
{
dnsmanager->UpdateSerial();
- for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it)
- dnsmanager->Notify(*it);
+ for (const auto &zone : s->zones)
+ dnsmanager->Notify(zone);
}
return;
@@ -562,7 +564,7 @@ class CommandOSDNS : public Command
source.Reply(_("IP %s does not exist for %s."), params[2].c_str(), s->GetName().c_str());
}
- void OnSet(CommandSource &source, const std::vector<Anope::string> &params)
+ static void OnSet(CommandSource &source, const std::vector<Anope::string> &params)
{
DNSServer *s = DNSServer::Find(params[1]);
@@ -577,16 +579,15 @@ class CommandOSDNS : public Command
if (params[2].equals_ci("LIMIT"))
{
- try
+ if (auto l = Anope::TryConvert<unsigned>(params[3]))
{
- unsigned l = convertTo<unsigned>(params[3]);
- s->SetLimit(l);
- if (l)
- source.Reply(_("User limit for %s set to %d."), s->GetName().c_str(), l);
+ s->SetLimit(l.value());
+ if (s->GetLimit())
+ source.Reply(_("User limit for %s set to %d."), s->GetName().c_str(), s->GetLimit());
else
source.Reply(_("User limit for %s removed."), s->GetName().c_str());
}
- catch (const ConvertException &ex)
+ else
{
source.Reply(_("Invalid value for LIMIT. Must be numerical."));
}
@@ -654,7 +655,7 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to depool " << s->GetName();
}
- public:
+public:
CommandOSDNS(Module *creator) : Command(creator, "operserv/dns", 0, 4)
{
this->SetDesc(_("Manage DNS zones for this network"));
@@ -669,7 +670,7 @@ class CommandOSDNS : public Command
this->SetSyntax(_("DEPOOL \037server.name\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (params.empty())
this->DisplayPoolState(source);
@@ -695,7 +696,7 @@ class CommandOSDNS : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -717,7 +718,8 @@ class CommandOSDNS : public Command
}
};
-class ModuleDNS : public Module
+class ModuleDNS final
+ : public Module
{
Serialize::Type zone_type, dns_type;
CommandOSDNS commandosdns;
@@ -729,24 +731,20 @@ class ModuleDNS : public Module
bool remove_split_servers;
bool readd_connected_servers;
- time_t last_warn;
+ time_t last_warn = 0;
- public:
+public:
ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
- zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this),
- last_warn(0)
+ zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this)
{
-
-
- for (unsigned j = 0; j < dns_servers->size(); ++j)
+ for (auto *s : *dns_servers)
{
- DNSServer *s = dns_servers->at(j);
if (s->Pooled() && Server::Find(s->GetName(), true))
s->SetActive(true);
}
}
- ~ModuleDNS()
+ ~ModuleDNS() override
{
for (unsigned i = zones->size(); i > 0; --i)
delete zones->at(i - 1);
@@ -754,7 +752,7 @@ class ModuleDNS : public Module
delete dns_servers->at(i - 1);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
this->ttl = block->Get<time_t>("ttl");
@@ -765,7 +763,7 @@ class ModuleDNS : public Module
this->readd_connected_servers = block->Get<bool>("readd_connected_servers");
}
- void OnNewServer(Server *s) anope_override
+ void OnNewServer(Server *s) override
{
if (s == Me || s->IsJuped())
return;
@@ -780,7 +778,7 @@ class ModuleDNS : public Module
}
}
- void OnServerQuit(Server *s) anope_override
+ void OnServerQuit(Server *s) override
{
DNSServer *dns = DNSServer::Find(s->GetName());
if (remove_split_servers && dns && dns->Pooled() && dns->Active())
@@ -793,7 +791,7 @@ class ModuleDNS : public Module
}
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (!u->Quitting() && u->server)
{
@@ -807,7 +805,7 @@ class ModuleDNS : public Module
}
}
- void OnPreUserLogoff(User *u) anope_override
+ void OnPreUserLogoff(User *u) override
{
if (u && u->server)
{
@@ -852,12 +850,12 @@ class ModuleDNS : public Module
}
}
- void OnDnsRequest(DNS::Query &req, DNS::Query *packet) anope_override
+ void OnDnsRequest(DNS::Query &req, DNS::Query *packet) override
{
if (req.questions.empty())
return;
/* Currently we reply to any QR for A/AAAA */
- const DNS::Question& q = req.questions[0];
+ const DNS::Question &q = req.questions[0];
if (q.type != DNS::QUERY_A && q.type != DNS::QUERY_AAAA && q.type != DNS::QUERY_AXFR && q.type != DNS::QUERY_ANY)
return;
@@ -865,21 +863,21 @@ class ModuleDNS : public Module
size_t answer_size = packet->answers.size();
if (zone)
{
- for (std::set<Anope::string, ci::less>::iterator it = zone->servers.begin(), it_end = zone->servers.end(); it != it_end; ++it)
+ for (const auto &server : zone->servers)
{
- DNSServer *s = DNSServer::Find(*it);
+ DNSServer *s = DNSServer::Find(server);
if (!s || !s->Active())
continue;
- for (unsigned j = 0; j < s->GetIPs().size(); ++j)
+ for (const auto &ip : s->GetIPs())
{
- DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
+ DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type)
{
DNS::ResourceRecord rr(q.name, q_type);
rr.ttl = this->ttl;
- rr.rdata = s->GetIPs()[j];
+ rr.rdata = ip;
packet->answers.push_back(rr);
}
}
@@ -889,21 +887,20 @@ class ModuleDNS : public Module
if (packet->answers.size() == answer_size)
{
/* Default zone */
- for (unsigned i = 0; i < dns_servers->size(); ++i)
+ for (auto *s : *dns_servers)
{
- DNSServer *s = dns_servers->at(i);
if (!s->Active())
continue;
- for (unsigned j = 0; j < s->GetIPs().size(); ++j)
+ for (const auto &ip : s->GetIPs())
{
- DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
+ DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type)
{
DNS::ResourceRecord rr(q.name, q_type);
rr.ttl = this->ttl;
- rr.rdata = s->GetIPs()[j];
+ rr.rdata = ip;
packet->answers.push_back(rr);
}
}
@@ -919,19 +916,17 @@ class ModuleDNS : public Module
}
/* Something messed up, just return them all and hope one is available */
- for (unsigned i = 0; i < dns_servers->size(); ++i)
+ for (auto *s : *dns_servers)
{
- DNSServer *s = dns_servers->at(i);
-
- for (unsigned j = 0; j < s->GetIPs().size(); ++j)
+ for (const auto &ip : s->GetIPs())
{
- DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
+ DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type)
{
DNS::ResourceRecord rr(q.name, q_type);
rr.ttl = this->ttl;
- rr.rdata = s->GetIPs()[j];
+ rr.rdata = ip;
packet->answers.push_back(rr);
}
}
diff --git a/modules/commands/os_forbid.cpp b/modules/operserv/os_forbid.cpp
index 415f7f64e..bb014c158 100644
--- a/modules/commands/os_forbid.cpp
+++ b/modules/operserv/os_forbid.cpp
@@ -14,11 +14,13 @@
static ServiceReference<NickServService> nickserv("NickServService", "NickServ");
-struct ForbidDataImpl : ForbidData, Serializable
+struct ForbidDataImpl final
+ : ForbidData
+ , Serializable
{
ForbidDataImpl() : Serializable("ForbidData") { }
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
void ForbidDataImpl::Serialize(Serialize::Data &data) const
@@ -31,7 +33,7 @@ void ForbidDataImpl::Serialize(Serialize::Data &data) const
data["type"] << this->type;
}
-Serializable* ForbidDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *ForbidDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
{
if (!forbid_service)
return NULL;
@@ -59,28 +61,28 @@ Serializable* ForbidDataImpl::Unserialize(Serializable *obj, Serialize::Data &da
return fb;
}
-class MyForbidService : public ForbidService
+class MyForbidService final
+ : public ForbidService
{
Serialize::Checker<std::vector<ForbidData *>[FT_SIZE - 1]> forbid_data;
inline std::vector<ForbidData *>& forbids(unsigned t) { return (*this->forbid_data)[t - 1]; }
- public:
+public:
MyForbidService(Module *m) : ForbidService(m), forbid_data("ForbidData") { }
- ~MyForbidService()
+ ~MyForbidService() override
{
- std::vector<ForbidData *> f = GetForbids();
- for (unsigned i = 0; i < f.size(); ++i)
- delete f[i];
+ for (const auto *forbid : GetForbids())
+ delete forbid;
}
- void AddForbid(ForbidData *d) anope_override
+ void AddForbid(ForbidData *d) override
{
this->forbids(d->type).push_back(d);
}
- void RemoveForbid(ForbidData *d) anope_override
+ void RemoveForbid(ForbidData *d) override
{
std::vector<ForbidData *>::iterator it = std::find(this->forbids(d->type).begin(), this->forbids(d->type).end(), d);
if (it != this->forbids(d->type).end())
@@ -88,12 +90,12 @@ class MyForbidService : public ForbidService
delete d;
}
- ForbidData *CreateForbid() anope_override
+ ForbidData *CreateForbid() override
{
return new ForbidDataImpl();
}
- ForbidData *FindForbid(const Anope::string &mask, ForbidType ftype) anope_override
+ ForbidData *FindForbid(const Anope::string &mask, ForbidType ftype) override
{
for (unsigned i = this->forbids(ftype).size(); i > 0; --i)
{
@@ -105,7 +107,7 @@ class MyForbidService : public ForbidService
return NULL;
}
- ForbidData *FindForbidExact(const Anope::string &mask, ForbidType ftype) anope_override
+ ForbidData *FindForbidExact(const Anope::string &mask, ForbidType ftype) override
{
for (unsigned i = this->forbids(ftype).size(); i > 0; --i)
{
@@ -117,7 +119,7 @@ class MyForbidService : public ForbidService
return NULL;
}
- std::vector<ForbidData *> GetForbids() anope_override
+ std::vector<ForbidData *> GetForbids() override
{
std::vector<ForbidData *> f;
for (unsigned j = FT_NICK; j < FT_SIZE; ++j)
@@ -147,10 +149,11 @@ class MyForbidService : public ForbidService
}
};
-class CommandOSForbid : public Command
+class CommandOSForbid final
+ : public Command
{
ServiceReference<ForbidService> fs;
- public:
+public:
CommandOSForbid(Module *creator) : Command(creator, "operserv/forbid", 1, 5), fs("ForbidService", "forbid")
{
this->SetDesc(_("Forbid usage of nicknames, channels, and emails"));
@@ -159,7 +162,7 @@ class CommandOSForbid : public Command
this->SetSyntax("LIST [NICK|CHAN|EMAIL|REGISTER]");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!this->fs)
return;
@@ -245,8 +248,8 @@ class CommandOSForbid : public Command
{
int na_matches = 0;
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- module->OnUserNickChange(it->second, "");
+ for (const auto &[_, user] : UserListByNick)
+ module->OnUserNickChange(user, "");
for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end;)
{
@@ -282,7 +285,7 @@ class CommandOSForbid : public Command
BotInfo *OperServ = Config->GetClient("OperServ");
if (IRCD->CanSQLineChannel && OperServ)
{
- time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s");
+ time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "1m");
XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->reason);
IRCD->SendSQLine(NULL, &x);
}
@@ -303,7 +306,7 @@ class CommandOSForbid : public Command
reason = Anope::printf(Language::Translate(u, _("This channel has been forbidden: %s")), d->reason.c_str());
- c->Kick(source.service, u, "%s", reason.c_str());
+ c->Kick(source.service, u, reason);
}
}
@@ -357,32 +360,30 @@ class CommandOSForbid : public Command
ListFormatter list(source.GetAccount());
list.AddColumn(_("Mask")).AddColumn(_("Type")).AddColumn(_("Creator")).AddColumn(_("Expires")).AddColumn(_("Reason"));
- unsigned shown = 0;
- for (unsigned i = 0; i < forbids.size(); ++i)
+ size_t shown = 0;
+ for (auto *forbid : forbids)
{
- ForbidData *d = forbids[i];
-
- if (ftype != FT_SIZE && ftype != d->type)
+ if (ftype != FT_SIZE && ftype != forbid->type)
continue;
Anope::string stype;
- if (d->type == FT_NICK)
+ if (forbid->type == FT_NICK)
stype = "NICK";
- else if (d->type == FT_CHAN)
+ else if (forbid->type == FT_CHAN)
stype = "CHAN";
- else if (d->type == FT_EMAIL)
+ else if (forbid->type == FT_EMAIL)
stype = "EMAIL";
- else if (d->type == FT_REGISTER)
+ else if (forbid->type == FT_REGISTER)
stype = "REGISTER";
else
continue;
ListFormatter::ListEntry entry;
- entry["Mask"] = d->mask;
+ entry["Mask"] = forbid->mask;
entry["Type"] = stype;
- entry["Creator"] = d->creator;
- entry["Expires"] = d->expires ? Anope::strftime(d->expires, NULL, true).c_str() : Language::Translate(source.GetAccount(), _("Never"));
- entry["Reason"] = d->reason;
+ entry["Creator"] = forbid->creator;
+ entry["Expires"] = forbid->expires ? Anope::strftime(forbid->expires, NULL, true).c_str() : Language::Translate(source.GetAccount(), _("Never"));
+ entry["Reason"] = forbid->reason;
list.AddEntry(entry);
++shown;
}
@@ -398,13 +399,13 @@ class CommandOSForbid : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
if (shown >= forbids.size())
source.Reply(_("End of forbid list."));
else
- source.Reply(_("End of forbid list - %d/%d entries shown."), shown, forbids.size());
+ source.Reply(_("End of forbid list - %zu/%zu entries shown."), shown, forbids.size());
}
}
}
@@ -414,7 +415,7 @@ class CommandOSForbid : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -433,20 +434,21 @@ class CommandOSForbid : public Command
}
};
-class OSForbid : public Module
+class OSForbid final
+ : public Module
{
MyForbidService forbidService;
Serialize::Type forbiddata_type;
CommandOSForbid commandosforbid;
- public:
+public:
OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
forbidService(this), forbiddata_type("ForbidData", ForbidDataImpl::Unserialize), commandosforbid(this)
{
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (u->Quitting() || exempt)
return;
@@ -454,7 +456,7 @@ class OSForbid : public Module
this->OnUserNickChange(u, "");
}
- void OnUserNickChange(User *u, const Anope::string &) anope_override
+ void OnUserNickChange(User *u, const Anope::string &) override
{
if (u->HasMode("OPER"))
return;
@@ -472,7 +474,7 @@ class OSForbid : public Module
}
}
- EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_override
+ EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
{
BotInfo *OperServ = Config->GetClient("OperServ");
if (u->HasMode("OPER") || !OperServ)
@@ -484,7 +486,7 @@ class OSForbid : public Module
ServiceReference<ChanServService> chanserv("ChanServService", "ChanServ");
if (IRCD->CanSQLineChannel)
{
- time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s");
+ time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "1m");
XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->reason);
IRCD->SendSQLine(NULL, &x);
}
@@ -501,7 +503,7 @@ class OSForbid : public Module
return EVENT_CONTINUE;
}
- EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
if (command->name == "nickserv/info" && params.size() > 0)
{
diff --git a/modules/commands/os_ignore.cpp b/modules/operserv/os_ignore.cpp
index 3e2a95ca4..e4cff0d44 100644
--- a/modules/commands/os_ignore.cpp
+++ b/modules/operserv/os_ignore.cpp
@@ -12,12 +12,14 @@
#include "module.h"
#include "modules/os_ignore.h"
-struct IgnoreDataImpl : IgnoreData, Serializable
+struct IgnoreDataImpl final
+ : IgnoreData
+ , Serializable
{
IgnoreDataImpl() : Serializable("IgnoreData") { }
- ~IgnoreDataImpl();
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+ ~IgnoreDataImpl() override;
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
IgnoreDataImpl::~IgnoreDataImpl()
@@ -34,7 +36,7 @@ void IgnoreDataImpl::Serialize(Serialize::Data &data) const
data["time"] << this->time;
}
-Serializable* IgnoreDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *IgnoreDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
{
if (!ignore_service)
return NULL;
@@ -57,26 +59,27 @@ Serializable* IgnoreDataImpl::Unserialize(Serializable *obj, Serialize::Data &da
}
-class OSIgnoreService : public IgnoreService
+class OSIgnoreService final
+ : public IgnoreService
{
Serialize::Checker<std::vector<IgnoreData *> > ignores;
- public:
+public:
OSIgnoreService(Module *o) : IgnoreService(o), ignores("IgnoreData") { }
- void AddIgnore(IgnoreData *ign) anope_override
+ void AddIgnore(IgnoreData *ign) override
{
ignores->push_back(ign);
}
- void DelIgnore(IgnoreData *ign) anope_override
+ void DelIgnore(IgnoreData *ign) override
{
std::vector<IgnoreData *>::iterator it = std::find(ignores->begin(), ignores->end(), ign);
if (it != ignores->end())
ignores->erase(it);
}
- void ClearIgnores() anope_override
+ void ClearIgnores() override
{
for (unsigned i = ignores->size(); i > 0; --i)
{
@@ -85,12 +88,12 @@ class OSIgnoreService : public IgnoreService
}
}
- IgnoreData *Create() anope_override
+ IgnoreData *Create() override
{
return new IgnoreDataImpl();
}
- IgnoreData *Find(const Anope::string &mask) anope_override
+ IgnoreData *Find(const Anope::string &mask) override
{
User *u = User::Find(mask, true);
std::vector<IgnoreData *>::iterator ign = this->ignores->begin(), ign_end = this->ignores->end();
@@ -148,16 +151,17 @@ class OSIgnoreService : public IgnoreService
return NULL;
}
- std::vector<IgnoreData *> &GetIgnores() anope_override
+ std::vector<IgnoreData *> &GetIgnores() override
{
return *ignores;
}
};
-class CommandOSIgnore : public Command
+class CommandOSIgnore final
+ : public Command
{
- private:
- Anope::string RealMask(const Anope::string &mask)
+private:
+ static Anope::string RealMask(const Anope::string &mask)
{
/* If it s an existing user, we ignore the hostmask. */
User *u = User::Find(mask, true);
@@ -221,7 +225,7 @@ class CommandOSIgnore : public Command
if (Anope::ReadOnly)
source.Reply(READ_ONLY_MODE);
- IgnoreData *ign = new IgnoreDataImpl();
+ auto *ign = new IgnoreDataImpl();
ign->mask = mask;
ign->creator = source.GetNick();
ign->reason = reason;
@@ -241,7 +245,7 @@ class CommandOSIgnore : public Command
}
}
- void DoList(CommandSource &source)
+ static void DoList(CommandSource &source)
{
if (!ignore_service)
return;
@@ -282,8 +286,8 @@ class CommandOSIgnore : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
@@ -335,17 +339,17 @@ class CommandOSIgnore : public Command
return;
}
- public:
+public:
CommandOSIgnore(Module *creator) : Command(creator, "operserv/ignore", 1, 4)
{
- this->SetDesc(_("Modify the Services ignore list"));
+ this->SetDesc(_("Modify the services ignore list"));
this->SetSyntax(_("ADD \037expiry\037 {\037nick\037|\037mask\037} [\037reason\037]"));
this->SetSyntax(_("DEL {\037nick\037|\037mask\037}"));
this->SetSyntax("LIST");
this->SetSyntax("CLEAR");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
@@ -363,17 +367,17 @@ class CommandOSIgnore : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Allows Services Operators to make Services ignore a nick or mask\n"
+ source.Reply(_("Allows Services Operators to make services ignore a nick or mask\n"
"for a certain time or until the next restart. The default\n"
"time format is seconds. You can specify it by using units.\n"
"Valid units are: \037s\037 for seconds, \037m\037 for minutes,\n"
"\037h\037 for hours and \037d\037 for days.\n"
"Combinations of these units are not permitted.\n"
- "To make Services permanently ignore the user, type 0 as time.\n"
+ "To make services permanently ignore the user, type 0 as time.\n"
"When adding a \037mask\037, it should be in the format nick!user@host,\n"
"everything else will be considered a nick. Wildcards are permitted.\n"
" \n"
@@ -391,20 +395,21 @@ class CommandOSIgnore : public Command
}
};
-class OSIgnore : public Module
+class OSIgnore final
+ : public Module
{
Serialize::Type ignoredata_type;
OSIgnoreService osignoreservice;
CommandOSIgnore commandosignore;
- public:
+public:
OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
ignoredata_type("IgnoreData", IgnoreDataImpl::Unserialize), osignoreservice(this), commandosignore(this)
{
}
- EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) anope_override
+ EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message, const Anope::map<Anope::string> &tags) override
{
if (!u->HasMode("OPER") && this->osignoreservice.Find(u->nick))
return EVENT_STOP;
diff --git a/modules/commands/os_info.cpp b/modules/operserv/os_info.cpp
index c3f635722..6ff1089ff 100644
--- a/modules/commands/os_info.cpp
+++ b/modules/operserv/os_info.cpp
@@ -7,21 +7,26 @@
*/
#include "module.h"
+#include "modules/info.h"
-struct OperInfo : Serializable
+struct OperInfoImpl final
+ : OperInfo
+ , Serializable
{
- Anope::string target;
- Anope::string info;
- Anope::string adder;
- time_t created;
+ OperInfoImpl()
+ : Serializable("OperInfo")
+ {
+ }
- OperInfo() : Serializable("OperInfo"), created(0) { }
- OperInfo(const Anope::string &t, const Anope::string &i, const Anope::string &a, time_t c) :
- Serializable("OperInfo"), target(t), info(i), adder(a), created(c) { }
+ OperInfoImpl(const Anope::string &t, const Anope::string &i, const Anope::string &a, time_t c)
+ : OperInfo(t, i, a, c)
+ , Serializable("OperInfo")
+ {
+ }
- ~OperInfo();
+ ~OperInfoImpl() override;
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["target"] << target;
data["info"] << info;
@@ -32,14 +37,14 @@ struct OperInfo : Serializable
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
-struct OperInfos : Serialize::Checker<std::vector<OperInfo *> >
+struct OperInfos final
+ : OperInfoList
{
- OperInfos(Extensible *) : Serialize::Checker<std::vector<OperInfo *> >("OperInfo") { }
+ OperInfos(Extensible *) { }
- ~OperInfos()
+ OperInfo *Create() override
{
- for (unsigned i = (*this)->size(); i > 0; --i)
- delete (*this)->at(i - 1);
+ return new OperInfoImpl();
}
static Extensible *Find(const Anope::string &target)
@@ -51,7 +56,7 @@ struct OperInfos : Serialize::Checker<std::vector<OperInfo *> >
}
};
-OperInfo::~OperInfo()
+OperInfoImpl::~OperInfoImpl()
{
Extensible *e = OperInfos::Find(target);
if (e)
@@ -66,7 +71,7 @@ OperInfo::~OperInfo()
}
}
-Serializable *OperInfo::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *OperInfoImpl::Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string starget;
data["target"] >> starget;
@@ -76,12 +81,12 @@ Serializable *OperInfo::Unserialize(Serializable *obj, Serialize::Data &data)
return NULL;
OperInfos *oi = e->Require<OperInfos>("operinfo");
- OperInfo *o;
+ OperInfoImpl *o;
if (obj)
- o = anope_dynamic_static_cast<OperInfo *>(obj);
+ o = anope_dynamic_static_cast<OperInfoImpl *>(obj);
else
{
- o = new OperInfo();
+ o = new OperInfoImpl();
o->target = starget;
}
data["info"] >> o->info;
@@ -93,9 +98,10 @@ Serializable *OperInfo::Unserialize(Serializable *obj, Serialize::Data &data)
return o;
}
-class CommandOSInfo : public Command
+class CommandOSInfo final
+ : public Command
{
- public:
+public:
CommandOSInfo(Module *creator) : Command(creator, "operserv/info", 2, 3)
{
this->SetDesc(_("Associate oper info with a nick or channel"));
@@ -104,7 +110,7 @@ class CommandOSInfo : public Command
this->SetSyntax(_("CLEAR \037target\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0], target = params[1], info = params.size() > 2 ? params[2] : "";
@@ -148,10 +154,8 @@ class CommandOSInfo : public Command
return;
}
- for (unsigned i = 0; i < (*oi)->size(); ++i)
+ for (auto *o : *(*oi))
{
- OperInfo *o = (*oi)->at(i);
-
if (o->info.equals_ci(info))
{
source.Reply(_("The oper info already exists on \002%s\002."), target.c_str());
@@ -159,7 +163,7 @@ class CommandOSInfo : public Command
}
}
- (*oi)->push_back(new OperInfo(target, info, source.GetNick(), Anope::CurTime));
+ (*oi)->push_back(new OperInfoImpl(target, info, source.GetNick(), Anope::CurTime));
source.Reply(_("Added info to \002%s\002."), target.c_str());
Log(LOG_ADMIN, source, this) << "to add information to " << target;
@@ -236,7 +240,7 @@ class CommandOSInfo : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -247,7 +251,8 @@ class CommandOSInfo : public Command
}
};
-class OSInfo : public Module
+class OSInfo final
+ : public Module
{
CommandOSInfo commandosinfo;
ExtensibleItem<OperInfos> oinfo;
@@ -262,26 +267,25 @@ class OSInfo : public Module
if (!oi)
return;
- for (unsigned i = 0; i < (*oi)->size(); ++i)
+ for (auto *o : *(*oi))
{
- OperInfo *o = (*oi)->at(i);
info[_("Oper Info")] = Anope::printf(_("(by %s on %s) %s"), o->adder.c_str(), Anope::strftime(o->created, source.GetAccount(), true).c_str(), o->info.c_str());
}
}
- public:
+public:
OSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandosinfo(this), oinfo(this, "operinfo"), oinfo_type("OperInfo", OperInfo::Unserialize)
+ commandosinfo(this), oinfo(this, "operinfo"), oinfo_type("OperInfo", OperInfoImpl::Unserialize)
{
}
- void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_override
+ void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override
{
OnInfo(source, na->nc, info);
}
- void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) anope_override
+ void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) override
{
OnInfo(source, ci, info);
}
diff --git a/modules/commands/os_jupe.cpp b/modules/operserv/os_jupe.cpp
index 796bf03d9..5410b6905 100644
--- a/modules/commands/os_jupe.cpp
+++ b/modules/operserv/os_jupe.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSJupe : public Command
+class CommandOSJupe final
+ : public Command
{
- public:
+public:
CommandOSJupe(Module *creator) : Command(creator, "operserv/jupe", 1, 2)
{
this->SetDesc(_("\"Jupiter\" a server"));
this->SetSyntax(_("\037server\037 [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &jserver = params[0];
const Anope::string &reason = params.size() > 1 ? params[1] : "";
@@ -29,7 +30,7 @@ class CommandOSJupe : public Command
if (!IRCD->IsHostValid(jserver) || jserver.find('.') == Anope::string::npos)
source.Reply(_("Please use a valid server name when juping."));
else if (server == Me || server == Servers::GetUplink())
- source.Reply(_("You can not jupe your Services' pseudoserver or your uplink server."));
+ source.Reply(_("You can not jupe your services' pseudoserver or your uplink server."));
else if (server && server->IsJuped())
source.Reply(_("You can not jupe an already juped server."));
else
@@ -42,19 +43,19 @@ class CommandOSJupe : public Command
IRCD->SendSquit(server, rbuf);
server->Delete(rbuf);
}
- Server *juped_server = new Server(Me, jserver, 1, rbuf, sid, true);
+ auto *juped_server = new Server(Me, jserver, 1, rbuf, sid, true);
IRCD->SendServer(juped_server);
Log(LOG_ADMIN, source, this) << "on " << jserver << " (" << rbuf << ")";
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Tells Services to jupiter a server -- that is, to create\n"
- "a fake \"server\" connected to Services which prevents\n"
+ source.Reply(_("Tells services to jupiter a server -- that is, to create\n"
+ "a fake \"server\" connected to services which prevents\n"
"the real server of that name from connecting. The jupe\n"
"may be removed using a standard \002SQUIT\002. If a reason is\n"
"given, it is placed in the server information field;\n"
@@ -65,11 +66,12 @@ class CommandOSJupe : public Command
}
};
-class OSJupe : public Module
+class OSJupe final
+ : public Module
{
CommandOSJupe commandosjupe;
- public:
+public:
OSJupe(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosjupe(this)
{
diff --git a/modules/commands/os_kick.cpp b/modules/operserv/os_kick.cpp
index 81d6ee689..222756aa3 100644
--- a/modules/commands/os_kick.cpp
+++ b/modules/operserv/os_kick.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSKick : public Command
+class CommandOSKick final
+ : public Command
{
- public:
+public:
CommandOSKick(Module *creator) : Command(creator, "operserv/kick", 3, 3)
{
this->SetDesc(_("Kick a user from a channel"));
this->SetSyntax(_("\037channel\037 \037user\037 \037reason\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &chan = params[0];
const Anope::string &nick = params[1];
@@ -55,7 +56,7 @@ class CommandOSKick : public Command
Log(LOG_ADMIN, source, this) << "on " << u2->nick << " in " << c->name << " (" << s << ")";
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -69,11 +70,12 @@ class CommandOSKick : public Command
}
};
-class OSKick : public Module
+class OSKick final
+ : public Module
{
CommandOSKick commandoskick;
- public:
+public:
OSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandoskick(this)
{
diff --git a/modules/commands/os_kill.cpp b/modules/operserv/os_kill.cpp
index 4a6d9bc71..6d57387a1 100644
--- a/modules/commands/os_kill.cpp
+++ b/modules/operserv/os_kill.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSKill : public Command
+class CommandOSKill final
+ : public Command
{
- public:
+public:
CommandOSKill(Module *creator) : Command(creator, "operserv/kill", 1, 2)
{
this->SetDesc(_("Kill a user"));
this->SetSyntax(_("\037user\037 [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = params[0];
Anope::string reason = params.size() > 1 ? params[1] : "";
@@ -41,7 +42,7 @@ class CommandOSKill : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -52,11 +53,12 @@ class CommandOSKill : public Command
}
};
-class OSKill : public Module
+class OSKill final
+ : public Module
{
CommandOSKill commandoskill;
- public:
+public:
OSKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandoskill(this)
{
diff --git a/modules/commands/os_list.cpp b/modules/operserv/os_list.cpp
index fa887f275..ba1156967 100644
--- a/modules/commands/os_list.cpp
+++ b/modules/operserv/os_list.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSChanList : public Command
+class CommandOSChanList final
+ : public Command
{
- public:
+public:
CommandOSChanList(Module *creator) : Command(creator, "operserv/chanlist", 0, 2)
{
this->SetDesc(_("Lists all channel records"));
this->SetSyntax(_("[{\037pattern\037 | \037nick\037} [\037SECRET\037]]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &pattern = !params.empty() ? params[0] : "";
const Anope::string &opt = params.size() > 1 ? params[1] : "";
@@ -46,18 +47,20 @@ class CommandOSChanList : public Command
{
source.Reply(_("\002%s\002 channel list:"), u2->nick.c_str());
- for (User::ChanUserList::iterator uit = u2->chans.begin(), uit_end = u2->chans.end(); uit != uit_end; ++uit)
+ for (const auto &[_, cc]: u2->chans)
{
- ChanUserContainer *cc = uit->second;
-
if (!modes.empty())
- for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it)
- if (!cc->chan->HasMode(*it))
+ {
+ for (const auto &mode : modes)
+ {
+ if (!cc->chan->HasMode(mode))
continue;
+ }
+ }
ListFormatter::ListEntry entry;
entry["Name"] = cc->chan->name;
- entry["Users"] = stringify(cc->chan->users.size());
+ entry["Users"] = Anope::ToString(cc->chan->users.size());
entry["Modes"] = cc->chan->GetModes(true, true);
entry["Topic"] = cc->chan->topic;
list.AddEntry(entry);
@@ -69,20 +72,22 @@ class CommandOSChanList : public Command
{
source.Reply(_("Channel list:"));
- for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit)
+ for (const auto &[_, c] : ChannelList)
{
- Channel *c = cit->second;
-
if (!pattern.empty() && !Anope::Match(c->name, pattern, false, true))
continue;
if (!modes.empty())
- for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it)
- if (!c->HasMode(*it))
+ {
+ for (const auto &mode : modes)
+ {
+ if (!c->HasMode(mode))
continue;
+ }
+ }
ListFormatter::ListEntry entry;
entry["Name"] = c->name;
- entry["Users"] = stringify(c->users.size());
+ entry["Users"] = Anope::ToString(c->users.size());
entry["Modes"] = c->GetModes(true, true);
entry["Topic"] = c->topic;
list.AddEntry(entry);
@@ -94,13 +99,13 @@ class CommandOSChanList : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of channel list. \002%u\002 channels shown."), count);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -124,16 +129,17 @@ class CommandOSChanList : public Command
}
};
-class CommandOSUserList : public Command
+class CommandOSUserList final
+ : public Command
{
- public:
+public:
CommandOSUserList(Module *creator) : Command(creator, "operserv/userlist", 0, 2)
{
this->SetDesc(_("Lists all user records"));
this->SetSyntax(_("[{\037pattern\037 | \037channel\037} [\037INVISIBLE\037]]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &pattern = !params.empty() ? params[0] : "";
const Anope::string &opt = params.size() > 1 ? params[1] : "";
@@ -156,14 +162,16 @@ class CommandOSUserList : public Command
{
source.Reply(_("\002%s\002 users list:"), pattern.c_str());
- for (Channel::ChanUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit)
+ for (const auto &[_, uc] : c->users)
{
- ChanUserContainer *uc = cuit->second;
-
if (!modes.empty())
- for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it)
- if (!uc->user->HasMode(*it))
+ {
+ for (const auto &mode : modes)
+ {
+ if (!uc->user->HasMode(mode))
continue;
+ }
+ }
ListFormatter::ListEntry entry;
entry["Name"] = uc->user->nick;
@@ -178,8 +186,8 @@ class CommandOSUserList : public Command
{
/* Historically this has been ordered, so... */
Anope::map<User *> ordered_map;
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- ordered_map[it->first] = it->second;
+ for (const auto &[nick, user] : UserListByNick)
+ ordered_map[nick] = user;
source.Reply(_("Users list:"));
@@ -197,10 +205,10 @@ class CommandOSUserList : public Command
};
bool match = false;
- for (unsigned int i = 0; i < sizeof(masks) / sizeof(*masks); ++i)
+ for (const auto &mask : masks)
{
/* Check mask with realname included, too */
- if (Anope::Match(masks[i], pattern, false, true) || Anope::Match(masks[i] + "#" + u2->realname, pattern, false, true))
+ if (Anope::Match(mask, pattern, false, true) || Anope::Match(mask + "#" + u2->realname, pattern, false, true))
{
match = true;
break;
@@ -211,9 +219,13 @@ class CommandOSUserList : public Command
continue;
if (!modes.empty())
- for (std::set<Anope::string>::iterator mit = modes.begin(), mit_end = modes.end(); mit != mit_end; ++mit)
- if (!u2->HasMode(*mit))
+ {
+ for (const auto &mode : modes)
+ {
+ if (!u2->HasMode(mode))
continue;
+ }
+ }
}
ListFormatter::ListEntry entry;
@@ -229,14 +241,14 @@ class CommandOSUserList : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of users list. \002%u\002 users shown."), count);
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -260,12 +272,13 @@ class CommandOSUserList : public Command
}
};
-class OSList : public Module
+class OSList final
+ : public Module
{
CommandOSChanList commandoschanlist;
CommandOSUserList commandosuserlist;
- public:
+public:
OSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandoschanlist(this), commandosuserlist(this)
{
diff --git a/modules/commands/os_login.cpp b/modules/operserv/os_login.cpp
index d785b3543..942c14b80 100644
--- a/modules/commands/os_login.cpp
+++ b/modules/operserv/os_login.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSLogin : public Command
+class CommandOSLogin final
+ : public Command
{
- public:
+public:
CommandOSLogin(Module *creator) : Command(creator, "operserv/login", 1, 1)
{
this->SetSyntax(_("\037password\037"));
this->RequireUser(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &password = params[0];
@@ -45,7 +46,7 @@ class CommandOSLogin : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -55,21 +56,22 @@ class CommandOSLogin : public Command
return true;
}
- const Anope::string GetDesc(CommandSource &source) const anope_override
+ const Anope::string GetDesc(CommandSource &source) const override
{
return Anope::printf(Language::Translate(source.GetAccount(), _("Login to %s")), source.service->nick.c_str());
}
};
-class CommandOSLogout : public Command
+class CommandOSLogout final
+ : public Command
{
- public:
+public:
CommandOSLogout(Module *creator) : Command(creator, "operserv/logout", 0, 0)
{
this->RequireUser(true);
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
User *u = source.GetUser();
Oper *o = source.nc->o;
@@ -87,7 +89,7 @@ class CommandOSLogout : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -97,26 +99,27 @@ class CommandOSLogout : public Command
return true;
}
- const Anope::string GetDesc(CommandSource &source) const anope_override
+ const Anope::string GetDesc(CommandSource &source) const override
{
return Anope::printf(Language::Translate(source.GetAccount(), _("Logout from %s")), source.service->nick.c_str());
}
};
-class OSLogin : public Module
+class OSLogin final
+ : public Module
{
CommandOSLogin commandoslogin;
CommandOSLogout commandoslogout;
ExtensibleItem<bool> os_login;
- public:
+public:
OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandoslogin(this), commandoslogout(this), os_login(this, "os_login")
{
}
- EventReturn IsServicesOper(User *u) anope_override
+ EventReturn IsServicesOper(User *u) override
{
if (!u->Account()->o->password.empty())
{
diff --git a/modules/commands/os_logsearch.cpp b/modules/operserv/os_logsearch.cpp
index 668390ec1..0282644b2 100644
--- a/modules/commands/os_logsearch.cpp
+++ b/modules/operserv/os_logsearch.cpp
@@ -13,7 +13,8 @@
static unsigned int HARDMAX = 65536;
-class CommandOSLogSearch : public Command
+class CommandOSLogSearch final
+ : public Command
{
static inline Anope::string CreateLogName(const Anope::string &file, time_t t = Anope::CurTime)
{
@@ -26,14 +27,14 @@ class CommandOSLogSearch : public Command
return Anope::LogDir + "/" + file + "." + timestamp;
}
- public:
+public:
CommandOSLogSearch(Module *creator) : Command(creator, "operserv/logsearch", 1, 3)
{
this->SetDesc(_("Searches logs for a matching pattern"));
this->SetSyntax(_("[+\037days\037d] [+\037limit\037l] \037pattern\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
int days = 7, replies = 50;
@@ -46,32 +47,22 @@ class CommandOSLogSearch : public Command
if (params[i].length() > 2)
{
Anope::string dur = params[i].substr(1, params[i].length() - 2);
- try
- {
- days = convertTo<int>(dur);
- if (days <= 0)
- throw ConvertException();
- }
- catch (const ConvertException &)
- {
+ auto d = Anope::Convert<int>(dur, 0);
+ if (d > 0)
+ days = d;
+ else
source.Reply(_("Invalid duration %s, using %d days."), dur.c_str(), days);
- }
}
break;
case 'l':
if (params[i].length() > 2)
{
Anope::string dur = params[i].substr(1, params[i].length() - 2);
- try
- {
- replies = convertTo<int>(dur);
- if (replies <= 0)
- throw ConvertException();
- }
- catch (const ConvertException &)
- {
+ auto r = Anope::Convert<int>(dur, 0);
+ if (r > 0)
+ replies = r;
+ else
source.Reply(_("Invalid limit %s, using %d."), dur.c_str(), replies);
- }
}
break;
default:
@@ -92,7 +83,7 @@ class CommandOSLogSearch : public Command
Log(LOG_ADMIN, source, this) << "for " << search_string;
bool wildcard = search_string.find_first_of("?*") != Anope::string::npos;
- bool regex = search_string.empty() == false && search_string[0] == '/' && search_string[search_string.length() - 1] == '/';
+ bool regex = !search_string.empty() && search_string[0] == '/' && search_string[search_string.length() - 1] == '/';
const Anope::string &logfile_name = Config->GetModule(this->owner)->Get<const Anope::string>("logname");
std::vector<Anope::string> matches;
@@ -127,7 +118,7 @@ class CommandOSLogSearch : public Command
fd.close();
}
- unsigned int found = matches.size();
+ size_t found = matches.size();
if (!found)
{
source.Reply(_("No matches for \002%s\002 found."), search_string.c_str());
@@ -146,17 +137,17 @@ class CommandOSLogSearch : public Command
}
source.Reply(_("Matches for \002%s\002:"), search_string.c_str());
- unsigned int count = 0;
- for (std::vector<Anope::string>::iterator it = matches.begin(), it_end = matches.end(); it != it_end; ++it)
- source.Reply("#%d: %s", ++count, it->c_str());
- source.Reply(_("Showed %d/%d matches for \002%s\002."), matches.size(), found, search_string.c_str());
+ size_t count = 0;
+ for (const auto &match : matches)
+ source.Reply("#%zu: %s", ++count, match.c_str());
+ source.Reply(_("Showed %zu/%zu matches for \002%s\002."), matches.size(), found, search_string.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("This command searches the Services logfiles for messages\n"
+ source.Reply(_("This command searches the services logfiles for messages\n"
"that match the given pattern. The day and limit argument\n"
"may be used to specify how many days of logs to search\n"
"and the number of replies to limit to. By default this\n"
@@ -171,11 +162,12 @@ class CommandOSLogSearch : public Command
}
};
-class OSLogSearch : public Module
+class OSLogSearch final
+ : public Module
{
CommandOSLogSearch commandoslogsearch;
- public:
+public:
OSLogSearch(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandoslogsearch(this)
{
diff --git a/modules/commands/os_mode.cpp b/modules/operserv/os_mode.cpp
index 082490925..964234dac 100644
--- a/modules/commands/os_mode.cpp
+++ b/modules/operserv/os_mode.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandOSMode : public Command
+class CommandOSMode final
+ : public Command
{
- public:
+public:
CommandOSMode(Module *creator) : Command(creator, "operserv/mode", 2, 3)
{
this->SetDesc(_("Change channel modes"));
@@ -21,7 +22,7 @@ class CommandOSMode : public Command
this->SetSyntax(_("\037channel\037 CLEAR [ALL]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &target = params[0];
const Anope::string &modes = params[1];
@@ -35,9 +36,8 @@ class CommandOSMode : public Command
{
bool all = params.size() > 2 && params[2].equals_ci("ALL");
- const Channel::ModeList chmodes = c->GetModes();
- for (Channel::ModeList::const_iterator it = chmodes.begin(), it_end = chmodes.end(); it != it_end && c; ++it)
- c->RemoveMode(c->WhoSends(), it->first, it->second, false);
+ for (const auto &[mode, value] : c->GetModes())
+ c->RemoveMode(c->WhoSends(), mode, value, false);
if (!c)
{
@@ -47,10 +47,8 @@ class CommandOSMode : public Command
if (all)
{
- for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : c->users)
{
- ChanUserContainer *uc = it->second;
-
if (uc->user->HasMode("OPER"))
continue;
@@ -126,7 +124,7 @@ class CommandOSMode : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -138,16 +136,17 @@ class CommandOSMode : public Command
}
};
-class CommandOSUMode : public Command
+class CommandOSUMode final
+ : public Command
{
- public:
+public:
CommandOSUMode(Module *creator) : Command(creator, "operserv/umode", 2, 2)
{
this->SetDesc(_("Change user modes"));
this->SetSyntax(_("\037user\037 \037modes\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &target = params[0];
const Anope::string &modes = params[1];
@@ -157,7 +156,7 @@ class CommandOSUMode : public Command
source.Reply(NICK_X_NOT_IN_USE, target.c_str());
else
{
- u2->SetModes(source.service, "%s", modes.c_str());
+ u2->SetModes(source.service, modes);
source.Reply(_("Changed usermodes of \002%s\002 to %s."), u2->nick.c_str(), modes.c_str());
u2->SendMessage(source.service, _("\002%s\002 changed your usermodes to %s."), source.GetNick().c_str(), modes.c_str());
@@ -166,7 +165,7 @@ class CommandOSUMode : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -176,12 +175,13 @@ class CommandOSUMode : public Command
}
};
-class OSMode : public Module
+class OSMode final
+ : public Module
{
CommandOSMode commandosmode;
CommandOSUMode commandosumode;
- public:
+public:
OSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosmode(this), commandosumode(this)
{
diff --git a/modules/commands/os_modinfo.cpp b/modules/operserv/os_modinfo.cpp
index 66008cd57..66b8788af 100644
--- a/modules/commands/os_modinfo.cpp
+++ b/modules/operserv/os_modinfo.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSModInfo : public Command
+class CommandOSModInfo final
+ : public Command
{
- public:
+public:
CommandOSModInfo(Module *creator) : Command(creator, "operserv/modinfo", 1, 1)
{
this->SetDesc(_("Info about a loaded module"));
this->SetSyntax(_("\037modname\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &file = params[0];
@@ -34,22 +35,18 @@ class CommandOSModInfo : public Command
source.Reply(_(" Loaded at: %p"), m->handle);
std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command");
- for (unsigned i = 0; i < servicekeys.size(); ++i)
+ for (const auto &servicekey : servicekeys)
{
- ServiceReference<Command> c("Command", servicekeys[i]);
+ ServiceReference<Command> c("Command", servicekey);
if (!c || c->owner != m)
continue;
source.Reply(_(" Providing service: \002%s\002"), c->name.c_str());
- for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
+ for (const auto &[_, bi] : *BotListByNick)
{
- const BotInfo *bi = it->second;
-
- for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit)
+ for (const auto &[c_name, info] : bi->commands)
{
- const Anope::string &c_name = cit->first;
- const CommandInfo &info = cit->second;
if (info.name != c->name)
continue;
source.Reply(_(" Command \002%s\002 on \002%s\002 is linked to \002%s\002"), c_name.c_str(), bi->nick.c_str(), c->name.c_str());
@@ -63,7 +60,7 @@ class CommandOSModInfo : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -72,16 +69,17 @@ class CommandOSModInfo : public Command
}
};
-class CommandOSModList : public Command
+class CommandOSModList final
+ : public Command
{
- public:
+public:
CommandOSModList(Module *creator) : Command(creator, "operserv/modlist", 0, 1)
{
this->SetDesc(_("List loaded modules"));
this->SetSyntax("[all|third|vendor|extra|database|encryption|pseudoclient|protocol]");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &param = !params.empty() ? params[0] : "";
@@ -116,10 +114,8 @@ class CommandOSModList : public Command
source.Reply(_("Current module list:"));
int count = 0;
- for (std::list<Module *>::iterator it = ModuleManager::Modules.begin(), it_end = ModuleManager::Modules.end(); it != it_end; ++it)
+ for (auto *m : ModuleManager::Modules)
{
- Module *m = *it;
-
bool show = false;
Anope::string mtype;
@@ -189,7 +185,7 @@ class CommandOSModList : public Command
source.Reply(_("%d modules loaded."), count);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -198,12 +194,13 @@ class CommandOSModList : public Command
}
};
-class OSModInfo : public Module
+class OSModInfo final
+ : public Module
{
CommandOSModInfo commandosmodinfo;
CommandOSModList commandosmodlist;
- public:
+public:
OSModInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosmodinfo(this), commandosmodlist(this)
{
diff --git a/modules/commands/os_module.cpp b/modules/operserv/os_module.cpp
index 2deb16891..346640f50 100644
--- a/modules/commands/os_module.cpp
+++ b/modules/operserv/os_module.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSModLoad : public Command
+class CommandOSModLoad final
+ : public Command
{
- public:
+public:
CommandOSModLoad(Module *creator) : Command(creator, "operserv/modload", 1, 1)
{
this->SetDesc(_("Load a module"));
this->SetSyntax(_("\037modname\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &mname = params[0];
@@ -38,7 +39,7 @@ class CommandOSModLoad : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -48,16 +49,17 @@ class CommandOSModLoad : public Command
}
};
-class CommandOSModReLoad : public Command
+class CommandOSModReLoad final
+ : public Command
{
- public:
+public:
CommandOSModReLoad(Module *creator) : Command(creator, "operserv/modreload", 1, 1)
{
this->SetDesc(_("Reload a module"));
this->SetSyntax(_("\037modname\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &mname = params[0];
@@ -111,7 +113,7 @@ class CommandOSModReLoad : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -120,16 +122,17 @@ class CommandOSModReLoad : public Command
}
};
-class CommandOSModUnLoad : public Command
+class CommandOSModUnLoad final
+ : public Command
{
- public:
+public:
CommandOSModUnLoad(Module *creator) : Command(creator, "operserv/modunload", 1, 1)
{
this->SetDesc(_("Un-Load a module"));
this->SetSyntax(_("\037modname\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &mname = params[0];
@@ -161,7 +164,7 @@ class CommandOSModUnLoad : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -170,13 +173,14 @@ class CommandOSModUnLoad : public Command
}
};
-class OSModule : public Module
+class OSModule final
+ : public Module
{
CommandOSModLoad commandosmodload;
CommandOSModReLoad commandosmodreload;
CommandOSModUnLoad commandosmodunload;
- public:
+public:
OSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosmodload(this), commandosmodreload(this), commandosmodunload(this)
{
diff --git a/modules/commands/os_news.cpp b/modules/operserv/os_news.cpp
index 9b90a808a..2cf011c0e 100644
--- a/modules/commands/os_news.cpp
+++ b/modules/operserv/os_news.cpp
@@ -12,6 +12,11 @@
#include "module.h"
#include "modules/os_news.h"
+// TODO: msgarray breaks the format string checking
+#ifdef __GNUC__
+# pragma GCC diagnostic ignored "-Wformat-security"
+#endif
+
/* List of messages for each news type. This simplifies message sending. */
enum
@@ -59,9 +64,10 @@ struct NewsMessages msgarray[] = {
}
};
-struct MyNewsItem : NewsItem
+struct MyNewsItem final
+ : NewsItem
{
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["type"] << this->type;
data["text"] << this->text;
@@ -69,7 +75,7 @@ struct MyNewsItem : NewsItem
data["time"] << this->time;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
if (!news_service)
return NULL;
@@ -93,30 +99,33 @@ struct MyNewsItem : NewsItem
}
};
-class MyNewsService : public NewsService
+class MyNewsService final
+ : public NewsService
{
std::vector<NewsItem *> newsItems[3];
- public:
+public:
MyNewsService(Module *m) : NewsService(m) { }
- ~MyNewsService()
+ ~MyNewsService() override
{
- for (unsigned i = 0; i < 3; ++i)
- for (unsigned j = 0; j < newsItems[i].size(); ++j)
- delete newsItems[i][j];
+ for (const auto &newstype : newsItems)
+ {
+ for (const auto *newsitem : newstype)
+ delete newsitem;
+ }
}
- NewsItem *CreateNewsItem() anope_override
+ NewsItem *CreateNewsItem() override
{
return new MyNewsItem();
}
- void AddNewsItem(NewsItem *n) anope_override
+ void AddNewsItem(NewsItem *n) override
{
this->newsItems[n->type].push_back(n);
}
- void DelNewsItem(NewsItem *n) anope_override
+ void DelNewsItem(NewsItem *n) override
{
std::vector<NewsItem *> &list = this->GetNewsList(n->type);
std::vector<NewsItem *>::iterator it = std::find(list.begin(), list.end(), n);
@@ -125,7 +134,7 @@ class MyNewsService : public NewsService
delete n;
}
- std::vector<NewsItem *> &GetNewsList(NewsType t) anope_override
+ std::vector<NewsItem *> &GetNewsList(NewsType t) override
{
return this->newsItems[t];
}
@@ -134,17 +143,18 @@ class MyNewsService : public NewsService
#define lenof(a) (sizeof(a) / sizeof(*(a)))
static const char **findmsgs(NewsType type)
{
- for (unsigned i = 0; i < lenof(msgarray); ++i)
- if (msgarray[i].type == type)
- return msgarray[i].msgs;
+ for (auto &msg : msgarray)
+ if (msg.type == type)
+ return msg.msgs;
return NULL;
}
-class NewsBase : public Command
+class NewsBase
+ : public Command
{
ServiceReference<NewsService> ns;
- protected:
+protected:
void DoList(CommandSource &source, NewsType ntype, const char **msgs)
{
std::vector<NewsItem *> &list = this->ns->GetNewsList(ntype);
@@ -158,7 +168,7 @@ class NewsBase : public Command
for (unsigned i = 0, end = list.size(); i < end; ++i)
{
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Creator"] = list[i]->who;
entry["Created"] = Anope::strftime(list[i]->time, NULL, true);
entry["Text"] = list[i]->text;
@@ -170,8 +180,8 @@ class NewsBase : public Command
std::vector<Anope::string> replies;
lflist.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of news list."));
}
@@ -222,18 +232,14 @@ class NewsBase : public Command
source.Reply(READ_ONLY_MODE);
if (!text.equals_ci("ALL"))
{
- try
+ unsigned num = Anope::Convert<unsigned>(text, 0);
+ if (num > 0 && num <= list.size())
{
- unsigned num = convertTo<unsigned>(text);
- if (num > 0 && num <= list.size())
- {
- this->ns->DelNewsItem(list[num - 1]);
- source.Reply(msgs[MSG_DELETED], num);
- Log(LOG_ADMIN, source, this) << "to delete a news item";
- return;
- }
+ this->ns->DelNewsItem(list[num - 1]);
+ source.Reply(msgs[MSG_DELETED], num);
+ Log(LOG_ADMIN, source, this) << "to delete a news item";
+ return;
}
- catch (const ConvertException &) { }
source.Reply(msgs[MSG_DEL_NOT_FOUND], text.c_str());
}
@@ -272,7 +278,7 @@ class NewsBase : public Command
return;
}
- public:
+public:
NewsBase(Module *creator, const Anope::string &newstype) : Command(creator, newstype, 1, 2), ns("NewsService", "news")
{
this->SetSyntax(_("ADD \037text\037"));
@@ -280,29 +286,30 @@ class NewsBase : public Command
this->SetSyntax("LIST");
}
- virtual ~NewsBase()
+ ~NewsBase() override
{
}
- virtual void Execute(CommandSource &source, const std::vector<Anope::string> &params) = 0;
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override = 0;
- virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand) = 0;
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override = 0;
};
-class CommandOSLogonNews : public NewsBase
+class CommandOSLogonNews final
+ : public NewsBase
{
- public:
+public:
CommandOSLogonNews(Module *creator) : NewsBase(creator, "operserv/logonnews")
{
this->SetDesc(_("Define messages to be shown to users at logon"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
return this->DoNews(source, params, NEWS_LOGON);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -316,20 +323,21 @@ class CommandOSLogonNews : public NewsBase
}
};
-class CommandOSOperNews : public NewsBase
+class CommandOSOperNews final
+ : public NewsBase
{
- public:
+public:
CommandOSOperNews(Module *creator) : NewsBase(creator, "operserv/opernews")
{
this->SetDesc(_("Define messages to be shown to users who oper"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
return this->DoNews(source, params, NEWS_OPER);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -343,20 +351,21 @@ class CommandOSOperNews : public NewsBase
}
};
-class CommandOSRandomNews : public NewsBase
+class CommandOSRandomNews final
+ : public NewsBase
{
- public:
+public:
CommandOSRandomNews(Module *creator) : NewsBase(creator, "operserv/randomnews")
{
this->SetDesc(_("Define messages to be randomly shown to users at logon"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
return this->DoNews(source, params, NEWS_RANDOM);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -369,7 +378,8 @@ class CommandOSRandomNews : public NewsBase
static unsigned cur_rand_news = 0;
-class OSNews : public Module
+class OSNews final
+ : public Module
{
MyNewsService newsservice;
Serialize::Type newsitem_type;
@@ -431,27 +441,27 @@ class OSNews : public Module
cur_rand_news = 0;
}
- public:
+public:
OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
newsservice(this), newsitem_type("NewsItem", MyNewsItem::Unserialize),
commandoslogonnews(this), commandosopernews(this), commandosrandomnews(this)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
oper_announcer = conf->GetModule(this)->Get<const Anope::string>("oper_announcer", "OperServ");
announcer = conf->GetModule(this)->Get<const Anope::string>("announcer", "Global");
news_count = conf->GetModule(this)->Get<unsigned>("newscount", "3");
}
- void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override
+ void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override
{
if (mname == "OPER")
DisplayNews(u, NEWS_OPER);
}
- void OnUserConnect(User *user, bool &) anope_override
+ void OnUserConnect(User *user, bool &) override
{
if (user->Quitting() || !user->server->IsSynced())
return;
diff --git a/modules/commands/os_noop.cpp b/modules/operserv/os_noop.cpp
index 65d9164e5..d4049abd5 100644
--- a/modules/commands/os_noop.cpp
+++ b/modules/operserv/os_noop.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandOSNOOP : public Command
+class CommandOSNOOP final
+ : public Command
{
- public:
+public:
CommandOSNOOP(Module *creator) : Command(creator, "operserv/noop", 2, 2)
{
this->SetDesc(_("Remove all operators from a server remotely"));
@@ -21,7 +22,7 @@ class CommandOSNOOP : public Command
this->SetSyntax(_("REVOKE \037server\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
const Anope::string &server = params[1];
@@ -30,7 +31,7 @@ class CommandOSNOOP : public Command
if (s == NULL)
source.Reply(_("Server %s does not exist."), server.c_str());
else if (s == Me || s->IsJuped())
- source.Reply(_("You can not NOOP Services."));
+ source.Reply(_("You can not NOOP services."));
else if (cmd.equals_ci("SET"))
{
/* Remove the O:lines */
@@ -42,10 +43,8 @@ class CommandOSNOOP : public Command
Anope::string reason = "NOOP command used by " + source.GetNick();
/* Kill all the IRCops of the server */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, u2] : UserListByNick)
{
- User *u2 = it->second;
-
if (u2->server == s && u2->HasMode("OPER"))
u2->Kill(*source.service, reason);
}
@@ -61,7 +60,7 @@ class CommandOSNOOP : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -73,19 +72,20 @@ class CommandOSNOOP : public Command
}
};
-class OSNOOP : public Module
+class OSNOOP final
+ : public Module
{
CommandOSNOOP commandosnoop;
PrimitiveExtensibleItem<Anope::string> noop;
- public:
+public:
OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosnoop(this), noop(this, "noop")
{
}
- void OnUserModeSet(const MessageSource &, User *u, const Anope::string &mname) anope_override
+ void OnUserModeSet(const MessageSource &, User *u, const Anope::string &mname) override
{
Anope::string *setter;
if (mname == "OPER" && (setter = noop.Get(u->server)))
diff --git a/modules/commands/os_oper.cpp b/modules/operserv/os_oper.cpp
index dc9334eb9..d05650d7c 100644
--- a/modules/commands/os_oper.cpp
+++ b/modules/operserv/os_oper.cpp
@@ -11,17 +11,19 @@
#include "module.h"
-struct MyOper : Oper, Serializable
+struct MyOper final
+ : Oper
+ , Serializable
{
MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { }
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["name"] << this->name;
data["type"] << this->ot->GetName();
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string stype, sname;
@@ -46,24 +48,27 @@ struct MyOper : Oper, Serializable
}
};
-class CommandOSOper : public Command
+class CommandOSOper final
+ : public Command
{
- bool HasPrivs(CommandSource &source, OperType *ot) const
+ static bool HasPrivs(CommandSource &source, OperType *ot)
{
- std::list<Anope::string> commands = ot->GetCommands(), privs = ot->GetPrivs();
-
- for (std::list<Anope::string>::iterator it = commands.begin(); it != commands.end(); ++it)
- if (!source.HasCommand(*it))
+ for (const auto &command : ot->GetCommands())
+ {
+ if (!source.HasCommand(command))
return false;
+ }
- for (std::list<Anope::string>::iterator it = privs.begin(); it != privs.end(); ++it)
- if (!source.HasPriv(*it))
+ for (const auto &priv : ot->GetPrivs())
+ {
+ if (!source.HasPriv(priv))
return false;
+ }
return true;
}
- public:
+public:
CommandOSOper(Module *creator) : Command(creator, "operserv/oper", 1, 3)
{
this->SetDesc(_("View and change Services Operators"));
@@ -73,7 +78,7 @@ class CommandOSOper : public Command
this->SetSyntax("LIST");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &subcommand = params[0];
@@ -151,20 +156,17 @@ class CommandOSOper : public Command
else if (subcommand.equals_ci("LIST"))
{
source.Reply(_("Name Type"));
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- const NickCore *nc = it->second;
-
if (!nc->o)
continue;
source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str());
if (std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end())
source.Reply(_(" This oper is configured in the configuration file."));
- for (std::list<User *>::const_iterator uit = nc->users.begin(); uit != nc->users.end(); ++uit)
+ for (auto *u : nc->users)
{
- User *u = *uit;
- source.Reply(_(" %s is online using this oper block."), u->nick.c_str());
+ source.Reply(_(" %s is online using this oper block."), u->nick.c_str());
}
}
}
@@ -173,9 +175,8 @@ class CommandOSOper : public Command
if (params.size() < 2)
{
source.Reply(_("Available opertypes:"));
- for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i)
+ for (auto *ot : Config->MyOperTypes)
{
- OperType *ot = Config->MyOperTypes[i];
source.Reply("%s", ot->GetName().c_str());
}
return;
@@ -196,9 +197,9 @@ class CommandOSOper : public Command
source.Reply(_("Available commands for \002%s\002:"), ot->GetName().c_str());
Anope::string buf;
std::list<Anope::string> cmds = ot->GetCommands();
- for (std::list<Anope::string>::const_iterator it = cmds.begin(), it_end = cmds.end(); it != it_end; ++it)
+ for (const auto &cmd : cmds)
{
- buf += *it + " ";
+ buf += cmd + " ";
if (buf.length() > 400)
{
source.Reply("%s", buf.c_str());
@@ -218,9 +219,9 @@ class CommandOSOper : public Command
source.Reply(_("Available privileges for \002%s\002:"), ot->GetName().c_str());
Anope::string buf;
std::list<Anope::string> privs = ot->GetPrivs();
- for (std::list<Anope::string>::const_iterator it = privs.begin(), it_end = privs.end(); it != it_end; ++it)
+ for (const auto &priv : privs)
{
- buf += *it + " ";
+ buf += priv + " ";
if (buf.length() > 400)
{
source.Reply("%s", buf.c_str());
@@ -243,7 +244,7 @@ class CommandOSOper : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -254,23 +255,22 @@ class CommandOSOper : public Command
}
};
-class OSOper : public Module
+class OSOper final
+ : public Module
{
Serialize::Type myoper_type;
CommandOSOper commandosoper;
- public:
+public:
OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
myoper_type("Oper", MyOper::Unserialize), commandosoper(this)
{
}
- ~OSOper()
+ ~OSOper() override
{
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- NickCore *nc = it->second;
-
if (nc->o && dynamic_cast<MyOper *>(nc->o))
{
delete nc->o;
@@ -279,7 +279,7 @@ class OSOper : public Module
}
}
- void OnDelCore(NickCore *nc) anope_override
+ void OnDelCore(NickCore *nc) override
{
if (nc->o && dynamic_cast<MyOper *>(nc->o))
{
diff --git a/modules/commands/os_reload.cpp b/modules/operserv/os_reload.cpp
index 4e2fc70f8..b66e9704c 100644
--- a/modules/commands/os_reload.cpp
+++ b/modules/operserv/os_reload.cpp
@@ -11,21 +11,22 @@
#include "module.h"
-class CommandOSReload : public Command
+class CommandOSReload final
+ : public Command
{
- public:
+public:
CommandOSReload(Module *creator) : Command(creator, "operserv/reload", 0, 0)
{
this->SetDesc(_("Reload services' configuration file"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
try
{
Log(LOG_ADMIN, source, this);
- Configuration::Conf *new_config = new Configuration::Conf();
+ auto *new_config = new Configuration::Conf();
Configuration::Conf *old = Config;
Config = new_config;
Config->Post(old);
@@ -40,23 +41,24 @@ class CommandOSReload : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Causes Services to reload the configuration file. Note that\n"
- "some directives still need the restart of the Services to\n"
- "take effect (such as Services' nicknames, activation of the\n"
+ source.Reply(_("Causes services to reload the configuration file. Note that\n"
+ "some directives still need the restart of the services to\n"
+ "take effect (such as services' nicknames, activation of the\n"
"session limitation, etc.)."));
return true;
}
};
-class OSReload : public Module
+class OSReload final
+ : public Module
{
CommandOSReload commandosreload;
- public:
+public:
OSReload(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosreload(this)
{
diff --git a/modules/commands/os_session.cpp b/modules/operserv/os_session.cpp
index db853d255..1e59f7d04 100644
--- a/modules/commands/os_session.cpp
+++ b/modules/operserv/os_session.cpp
@@ -35,35 +35,35 @@ namespace
unsigned ipv6_cidr;
}
-class MySessionService : public SessionService
+class MySessionService final
+ : public SessionService
{
SessionMap Sessions;
Serialize::Checker<ExceptionVector> Exceptions;
- public:
+public:
MySessionService(Module *m) : SessionService(m), Exceptions("Exception") { }
- Exception *CreateException() anope_override
+ Exception *CreateException() override
{
return new Exception();
}
- void AddException(Exception *e) anope_override
+ void AddException(Exception *e) override
{
this->Exceptions->push_back(e);
}
- void DelException(Exception *e) anope_override
+ void DelException(Exception *e) override
{
ExceptionVector::iterator it = std::find(this->Exceptions->begin(), this->Exceptions->end(), e);
if (it != this->Exceptions->end())
this->Exceptions->erase(it);
}
- Exception *FindException(User *u) anope_override
+ Exception *FindException(User *u) override
{
- for (std::vector<Exception *>::const_iterator it = this->Exceptions->begin(), it_end = this->Exceptions->end(); it != it_end; ++it)
+ for (auto *e : *this->Exceptions)
{
- Exception *e = *it;
if (Anope::Match(u->host, e->mask) || Anope::Match(u->ip.addr(), e->mask))
return e;
@@ -73,11 +73,10 @@ class MySessionService : public SessionService
return NULL;
}
- Exception *FindException(const Anope::string &host) anope_override
+ Exception *FindException(const Anope::string &host) override
{
- for (std::vector<Exception *>::const_iterator it = this->Exceptions->begin(), it_end = this->Exceptions->end(); it != it_end; ++it)
+ for (auto *e : *this->Exceptions)
{
- Exception *e = *it;
if (Anope::Match(host, e->mask))
return e;
@@ -88,7 +87,7 @@ class MySessionService : public SessionService
return NULL;
}
- ExceptionVector &GetExceptions() anope_override
+ ExceptionVector &GetExceptions() override
{
return this->Exceptions;
}
@@ -98,7 +97,7 @@ class MySessionService : public SessionService
this->Sessions.erase(s->addr);
}
- Session *FindSession(const Anope::string &ip) anope_override
+ Session *FindSession(const Anope::string &ip) override
{
cidr c(ip, ip.find(':') != Anope::string::npos ? ipv6_cidr : ipv4_cidr);
if (!c.valid())
@@ -117,29 +116,30 @@ class MySessionService : public SessionService
return this->Sessions.find(c);
}
- Session* &FindOrCreateSession(const cidr &ip)
+ Session *&FindOrCreateSession(const cidr &ip)
{
return this->Sessions[ip];
}
- SessionMap &GetSessions() anope_override
+ SessionMap &GetSessions() override
{
return this->Sessions;
}
};
-class ExceptionDelCallback : public NumberList
+class ExceptionDelCallback final
+ : public NumberList
{
- protected:
+protected:
CommandSource &source;
- unsigned deleted;
+ unsigned deleted = 0;
Command *cmd;
- public:
- ExceptionDelCallback(CommandSource &_source, const Anope::string &numlist, Command *c) : NumberList(numlist, true), source(_source), deleted(0), cmd(c)
+public:
+ ExceptionDelCallback(CommandSource &_source, const Anope::string &numlist, Command *c) : NumberList(numlist, true), source(_source), cmd(c)
{
}
- ~ExceptionDelCallback()
+ ~ExceptionDelCallback() override
{
if (!deleted)
source.Reply(_("No matching entries on session-limit exception list."));
@@ -149,7 +149,7 @@ class ExceptionDelCallback : public NumberList
source.Reply(_("Deleted %d entries from session-limit exception list."), deleted);
}
- virtual void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > session_service->GetExceptions().size())
return;
@@ -170,20 +170,15 @@ class ExceptionDelCallback : public NumberList
}
};
-class CommandOSSession : public Command
+class CommandOSSession final
+ : public Command
{
- private:
- void DoList(CommandSource &source, const std::vector<Anope::string> &params)
+private:
+ static void DoList(CommandSource &source, const std::vector<Anope::string> &params)
{
Anope::string param = params[1];
- unsigned mincount = 0;
- try
- {
- mincount = convertTo<unsigned>(param);
- }
- catch (const ConvertException &) { }
-
+ auto mincount = Anope::Convert<unsigned>(param, 0);
if (mincount <= 1)
source.Reply(_("Invalid threshold value. It must be a valid integer greater than 1."));
else
@@ -191,14 +186,12 @@ class CommandOSSession : public Command
ListFormatter list(source.GetAccount());
list.AddColumn(_("Session")).AddColumn(_("Host"));
- for (SessionService::SessionMap::iterator it = session_service->GetSessions().begin(), it_end = session_service->GetSessions().end(); it != it_end; ++it)
+ for (const auto &[_, session] : session_service->GetSessions())
{
- Session *session = it->second;
-
if (session->count >= mincount)
{
ListFormatter::ListEntry entry;
- entry["Session"] = stringify(session->count);
+ entry["Session"] = Anope::ToString(session->count);
entry["Host"] = session->addr.mask();
list.AddEntry(entry);
}
@@ -210,14 +203,14 @@ class CommandOSSession : public Command
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
return;
}
- void DoView(CommandSource &source, const std::vector<Anope::string> &params)
+ static void DoView(CommandSource &source, const std::vector<Anope::string> &params)
{
Anope::string param = params[1];
Session *session = session_service->FindSession(param);
@@ -239,7 +232,7 @@ class CommandOSSession : public Command
else
source.Reply(_("The host \002%s\002 currently has \002%d\002 sessions with a limit of \002%d\002 because it matches entry: \002%s\002."), session->addr.mask().c_str(), session->count, limit, entry.c_str());
}
- public:
+public:
CommandOSSession(Module *creator) : Command(creator, "operserv/session", 2, 2)
{
this->SetDesc(_("View the list of host sessions"));
@@ -247,7 +240,7 @@ class CommandOSSession : public Command
this->SetSyntax(_("VIEW \037host\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
@@ -263,7 +256,7 @@ class CommandOSSession : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -285,9 +278,10 @@ class CommandOSSession : public Command
}
};
-class CommandOSException : public Command
+class CommandOSException final
+ : public Command
{
- private:
+private:
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
Anope::string mask, expiry, limitstr;
@@ -327,13 +321,7 @@ class CommandOSException : public Command
else if (expires > 0)
expires += Anope::CurTime;
- unsigned limit = -1;
- try
- {
- limit = convertTo<unsigned>(limitstr);
- }
- catch (const ConvertException &) { }
-
+ auto limit = Anope::Convert<unsigned>(limitstr, -1);
if (limit > max_exception_limit)
{
source.Reply(_("Invalid session limit. It must be a valid integer greater than or equal to zero and less than \002%d\002."), max_exception_limit);
@@ -347,9 +335,8 @@ class CommandOSException : public Command
return;
}
- for (std::vector<Exception *>::iterator it = session_service->GetExceptions().begin(), it_end = session_service->GetExceptions().end(); it != it_end; ++it)
+ for (auto *e : session_service->GetExceptions())
{
- Exception *e = *it;
if (e->mask.equals_ci(mask))
{
if (e->limit != limit)
@@ -363,7 +350,7 @@ class CommandOSException : public Command
}
}
- Exception *exception = new Exception();
+ auto *exception = new Exception();
exception->mask = mask;
exception->limit = limit;
exception->reason = reason;
@@ -436,16 +423,17 @@ class CommandOSException : public Command
if (!mask.empty() && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class ExceptionListCallback : public NumberList
+ class ExceptionListCallback final
+ : public NumberList
{
CommandSource &source;
ListFormatter &list;
- public:
+ public:
ExceptionListCallback(CommandSource &_source, ListFormatter &_list, const Anope::string &numlist) : NumberList(numlist, false), source(_source), list(_list)
{
}
- void HandleNumber(unsigned Number) anope_override
+ void HandleNumber(unsigned Number) override
{
if (!Number || Number > session_service->GetExceptions().size())
return;
@@ -453,12 +441,12 @@ class CommandOSException : public Command
Exception *e = session_service->GetExceptions()[Number - 1];
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(Number);
+ entry["Number"] = Anope::ToString(Number);
entry["Mask"] = e->mask;
entry["By"] = e->who;
entry["Created"] = Anope::strftime(e->time, NULL, true);
entry["Expires"] = Anope::Expires(e->expires, source.GetAccount());
- entry["Limit"] = stringify(e->limit);
+ entry["Limit"] = Anope::ToString(e->limit);
entry["Reason"] = e->reason;
this->list.AddEntry(entry);
}
@@ -474,12 +462,12 @@ class CommandOSException : public Command
if (mask.empty() || Anope::Match(e->mask, mask))
{
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Mask"] = e->mask;
entry["By"] = e->who;
entry["Created"] = Anope::strftime(e->time, NULL, true);
entry["Expires"] = Anope::Expires(e->expires, source.GetAccount());
- entry["Limit"] = stringify(e->limit);
+ entry["Limit"] = Anope::ToString(e->limit);
entry["Reason"] = e->reason;
list.AddEntry(entry);
}
@@ -495,8 +483,8 @@ class CommandOSException : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
@@ -516,7 +504,7 @@ class CommandOSException : public Command
this->ProcessList(source, params, list);
}
- public:
+public:
CommandOSException(Module *creator) : Command(creator, "operserv/exception", 1, 5)
{
this->SetDesc(_("Modify the session-limit exception list"));
@@ -526,7 +514,7 @@ class CommandOSException : public Command
this->SetSyntax(_("VIEW [\037mask\037 | \037list\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
@@ -544,7 +532,7 @@ class CommandOSException : public Command
this->OnSyntaxError(source, "");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -582,7 +570,8 @@ class CommandOSException : public Command
}
};
-class OSSession : public Module
+class OSSession final
+ : public Module
{
Serialize::Type exception_type;
MySessionService ss;
@@ -590,19 +579,19 @@ class OSSession : public Module
CommandOSException commandosexception;
ServiceReference<XLineManager> akills;
- public:
+public:
OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
exception_type("Exception", Exception::Unserialize), ss(this), commandossession(this), commandosexception(this), akills("XLineManager", "xlinemanager/sgline")
{
this->SetPermanent(true);
}
- void Prioritize() anope_override
+ void Prioritize() override
{
ModuleManager::SetPriority(this, PRIORITY_FIRST);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = Config->GetModule(this);
@@ -622,7 +611,7 @@ class OSSession : public Module
throw ConfigException(this->name + ": session CIDR value out of range");
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (u->Quitting() || !session_limit || exempt || !u->server || u->server->IsULined())
return;
@@ -631,7 +620,7 @@ class OSSession : public Module
if (!u_ip.valid())
return;
- Session* &session = this->ss.FindOrCreateSession(u_ip);
+ Session *&session = this->ss.FindOrCreateSession(u_ip);
if (session)
{
@@ -676,7 +665,7 @@ class OSSession : public Module
const Anope::string &akillmask = "*@" + session->addr.mask();
if (max_session_kill && session->hits >= max_session_kill && akills && !akills->HasEntry(akillmask))
{
- XLine *x = new XLine(akillmask, OperServ ? OperServ->nick : "", Anope::CurTime + session_autokill_expiry, "Session limit exceeded", XLineManager::GenerateUID());
+ auto *x = new XLine(akillmask, OperServ ? OperServ->nick : "", Anope::CurTime + session_autokill_expiry, "Session limit exceeded", XLineManager::GenerateUID());
akills->AddXLine(x);
akills->Send(NULL, x);
Log(OperServ, "akill/session") << "Added a temporary AKILL for \002" << akillmask << "\002 due to excessive connections";
@@ -693,7 +682,7 @@ class OSSession : public Module
}
}
- void OnUserQuit(User *u, const Anope::string &msg) anope_override
+ void OnUserQuit(User *u, const Anope::string &msg) override
{
if (!session_limit || !u->server || u->server->IsULined())
return;
@@ -716,7 +705,7 @@ class OSSession : public Module
sessions.erase(sit);
}
- void OnExpireTick() anope_override
+ void OnExpireTick() override
{
if (Anope::NoExpire)
return;
diff --git a/modules/commands/os_set.cpp b/modules/operserv/os_set.cpp
index 7abe0c9df..b9c948e30 100644
--- a/modules/commands/os_set.cpp
+++ b/modules/operserv/os_set.cpp
@@ -11,9 +11,10 @@
#include "module.h"
-class CommandOSSet : public Command
+class CommandOSSet final
+ : public Command
{
- private:
+private:
void DoList(CommandSource &source)
{
Log(LOG_ADMIN, source, this) << "LIST";
@@ -121,14 +122,14 @@ class CommandOSSet : public Command
}
else
{
- try
+ auto debug = Anope::TryConvert<int>(setting);
+ if (debug.has_value())
{
- Anope::Debug = convertTo<int>(setting);
+ Anope::Debug = debug.value();
Log(LOG_ADMIN, source, this) << "DEBUG " << Anope::Debug;
source.Reply(_("Services are now in \002debug\002 mode (level %d)."), Anope::Debug);
return;
}
- catch (const ConvertException &) { }
source.Reply(_("Setting for DEBUG must be \002ON\002, \002OFF\002, or a positive number."));
}
@@ -163,14 +164,14 @@ class CommandOSSet : public Command
return;
}
- public:
+public:
CommandOSSet(Module *creator) : Command(creator, "operserv/set", 1, 2)
{
- this->SetDesc(_("Set various global Services options"));
+ this->SetDesc(_("Set various global services options"));
this->SetSyntax(_("\037option\037 \037setting\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &option = params[0];
@@ -190,13 +191,13 @@ class CommandOSSet : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (subcommand.empty())
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Sets various global Services options. Option names\n"
+ source.Reply(_("Sets various global services options. Option names\n"
"currently defined are:\n"
" READONLY Set read-only or read-write mode\n"
" DEBUG Activate or deactivate debug mode\n"
@@ -212,13 +213,13 @@ class CommandOSSet : public Command
source.Reply(_("Syntax: \002READONLY {ON | OFF}\002\n"
" \n"
"Sets read-only mode on or off. In read-only mode, normal\n"
- "users will not be allowed to modify any Services data,\n"
- "including channel and nickname access lists, etc. IRCops\n"
- "with sufficient Services privileges will be able to modify\n"
+ "users will not be allowed to modify any services data,\n"
+ "including channel access lists, etc. Server operators\n"
+ "with sufficient services privileges will be able to modify\n"
"Services' AKILL, SQLINE, SNLINE and ignore lists, drop,\n"
"suspend or forbid nicknames and channels, and manage news,\n"
"oper info and DNS, but any such changes will not be saved\n"
- "unless read-only mode is deactivated before Services are\n"
+ "unless read-only mode is deactivated before services are\n"
"terminated or restarted.\n"
" \n"
"This option is equivalent to the command-line option\n"
@@ -253,11 +254,12 @@ class CommandOSSet : public Command
}
};
-class OSSet : public Module
+class OSSet final
+ : public Module
{
CommandOSSet commandosset;
- public:
+public:
OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosset(this)
{
diff --git a/modules/commands/os_shutdown.cpp b/modules/operserv/os_shutdown.cpp
index 5835d5915..585bbcd50 100644
--- a/modules/commands/os_shutdown.cpp
+++ b/modules/operserv/os_shutdown.cpp
@@ -11,15 +11,16 @@
#include "module.h"
-class CommandOSQuit : public Command
+class CommandOSQuit final
+ : public Command
{
- public:
+public:
CommandOSQuit(Module *creator) : Command(creator, "operserv/quit", 0, 0)
{
- this->SetDesc(_("Terminate Services WITHOUT saving"));
+ this->SetDesc(_("Terminate services WITHOUT saving"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Log(LOG_ADMIN, source, this);
Anope::QuitReason = source.command + " command received from " + source.GetNick();
@@ -27,11 +28,11 @@ class CommandOSQuit : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Causes Services to do an immediate shutdown; databases are\n"
+ source.Reply(_("Causes services to do an immediate shutdown; databases are\n"
"\002not\002 saved. This command should not be used unless\n"
"damage to the in-memory copies of the databases is feared\n"
"and they should not be saved."));
@@ -39,15 +40,16 @@ class CommandOSQuit : public Command
}
};
-class CommandOSRestart : public Command
+class CommandOSRestart final
+ : public Command
{
- public:
+public:
CommandOSRestart(Module *creator) : Command(creator, "operserv/restart", 0, 0)
{
- this->SetDesc(_("Save databases and restart Services"));
+ this->SetDesc(_("Save databases and restart services"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Log(LOG_ADMIN, source, this);
Anope::QuitReason = source.command + " command received from " + source.GetNick();
@@ -56,24 +58,25 @@ class CommandOSRestart : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
- source.Reply(_("Causes Services to save all databases and then restart\n"
+ source.Reply(_("Causes services to save all databases and then restart\n"
"(i.e. exit and immediately re-run the executable)."));
return true;
}
};
-class CommandOSShutdown : public Command
+class CommandOSShutdown final
+ : public Command
{
- public:
+public:
CommandOSShutdown(Module *creator) : Command(creator, "operserv/shutdown", 0, 0)
{
this->SetDesc(_("Terminate services with save"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Log(LOG_ADMIN, source, this);
Anope::QuitReason = source.command + " command received from " + source.GetNick();
@@ -82,22 +85,23 @@ class CommandOSShutdown : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Causes Services to save all databases and then shut down."));
+ source.Reply(_("Causes services to save all databases and then shut down."));
return true;
}
};
-class OSShutdown : public Module
+class OSShutdown final
+ : public Module
{
CommandOSQuit commandosquit;
CommandOSRestart commandosrestart;
CommandOSShutdown commandosshutdown;
- public:
+public:
OSShutdown(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosquit(this), commandosrestart(this), commandosshutdown(this)
{
diff --git a/modules/commands/os_stats.cpp b/modules/operserv/os_stats.cpp
index a6cedbb4a..780151916 100644
--- a/modules/commands/os_stats.cpp
+++ b/modules/operserv/os_stats.cpp
@@ -12,7 +12,8 @@
#include "module.h"
#include "modules/os_session.h"
-struct Stats : Serializable
+struct Stats final
+ : Serializable
{
static Stats *me;
@@ -21,13 +22,13 @@ struct Stats : Serializable
me = this;
}
- void Serialize(Serialize::Data &data) const anope_override
+ void Serialize(Serialize::Data &data) const override
{
data["maxusercnt"] << MaxUserCount;
data["maxusertime"] << MaxUserTime;
}
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
data["maxusercnt"] >> MaxUserCount;
data["maxusertime"] >> MaxUserTime;
@@ -50,23 +51,26 @@ static int stats_count_servers(Server *s)
int count = 1;
if (!s->GetLinks().empty())
- for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
- count += stats_count_servers(s->GetLinks()[i]);
+ {
+ for (auto *link : s->GetLinks())
+ count += stats_count_servers(link);
+ }
return count;
}
-class CommandOSStats : public Command
+class CommandOSStats final
+ : public Command
{
ServiceReference<XLineManager> akills, snlines, sqlines;
- private:
+private:
void DoStatsAkill(CommandSource &source)
{
int timeout;
if (akills)
{
/* AKILLs */
- source.Reply(_("Current number of AKILLs: \002%d\002"), akills->GetCount());
+ source.Reply(_("Current number of AKILLs: \002%zu\002"), akills->GetCount());
timeout = Config->GetModule("operserv")->Get<time_t>("autokillexpiry", "30d") + 59;
if (timeout >= 172800)
source.Reply(_("Default AKILL expiry time: \002%d days\002"), timeout / 86400);
@@ -86,7 +90,7 @@ class CommandOSStats : public Command
if (snlines)
{
/* SNLINEs */
- source.Reply(_("Current number of SNLINEs: \002%d\002"), snlines->GetCount());
+ source.Reply(_("Current number of SNLINEs: \002%zu\002"), snlines->GetCount());
timeout = Config->GetModule("operserv")->Get<time_t>("snlineexpiry", "30d") + 59;
if (timeout >= 172800)
source.Reply(_("Default SNLINE expiry time: \002%d days\002"), timeout / 86400);
@@ -106,7 +110,7 @@ class CommandOSStats : public Command
if (sqlines)
{
/* SQLINEs */
- source.Reply(_("Current number of SQLINEs: \002%d\002"), sqlines->GetCount());
+ source.Reply(_("Current number of SQLINEs: \002%zu\002"), sqlines->GetCount());
timeout = Config->GetModule("operserv")->Get<time_t>("sglineexpiry", "30d") + 59;
if (timeout >= 172800)
source.Reply(_("Default SQLINE expiry time: \002%d days\002"), timeout / 86400);
@@ -125,28 +129,28 @@ class CommandOSStats : public Command
}
}
- void DoStatsReset(CommandSource &source)
+ static void DoStatsReset(CommandSource &source)
{
MaxUserCount = UserListByNick.size();
source.Reply(_("Statistics reset."));
return;
}
- void DoStatsUptime(CommandSource &source)
+ static void DoStatsUptime(CommandSource &source)
{
time_t uptime = Anope::CurTime - Anope::StartTime;
- source.Reply(_("Current users: \002%d\002 (\002%d\002 ops)"), UserListByNick.size(), OperCount);
+ source.Reply(_("Current users: \002%zu\002 (\002%d\002 ops)"), UserListByNick.size(), OperCount);
source.Reply(_("Maximum users: \002%d\002 (%s)"), MaxUserCount, Anope::strftime(MaxUserTime, source.GetAccount()).c_str());
source.Reply(_("Services up %s."), Anope::Duration(uptime, source.GetAccount()).c_str());
return;
}
- void DoStatsUplink(CommandSource &source)
+ static void DoStatsUplink(CommandSource &source)
{
Anope::string buf;
- for (std::set<Anope::string>::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it)
- buf += " " + *it;
+ for (const auto &capab : Servers::Capab)
+ buf += " " + capab;
if (!buf.empty())
buf.erase(buf.begin());
@@ -156,7 +160,7 @@ class CommandOSStats : public Command
return;
}
- template<typename T> void GetHashStats(const T& map, size_t& entries, size_t& buckets, size_t& max_chain)
+ template<typename T> void GetHashStats(const T &map, size_t &entries, size_t &buckets, size_t &max_chain)
{
entries = map.size(), buckets = map.bucket_count(), max_chain = 0;
for (size_t i = 0; i < buckets; ++i)
@@ -169,42 +173,73 @@ class CommandOSStats : public Command
size_t entries, buckets, max_chain;
GetHashStats(UserListByNick, entries, buckets, max_chain);
- source.Reply(_("Users (nick): %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
+ source.Reply(_("Users (nick): %lu entries, %lu buckets, longest chain is %zu"), entries, buckets, max_chain);
if (!UserListByUID.empty())
{
GetHashStats(UserListByUID, entries, buckets, max_chain);
- source.Reply(_("Users (uid): %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
+ source.Reply(_("Users (uid): %lu entries, %lu buckets, longest chain is %zu"), entries, buckets, max_chain);
}
GetHashStats(ChannelList, entries, buckets, max_chain);
- source.Reply(_("Channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
+ source.Reply(_("Channels: %zu entries, %zu buckets, longest chain is %zu"), entries, buckets, max_chain);
GetHashStats(*RegisteredChannelList, entries, buckets, max_chain);
- source.Reply(_("Registered channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
+ source.Reply(_("Registered channels: %zu entries, %zu buckets, longest chain is %zu"), entries, buckets, max_chain);
GetHashStats(*NickAliasList, entries, buckets, max_chain);
- source.Reply(_("Registered nicknames: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
+ source.Reply(_("Registered nicknames: %zu entries, %zu buckets, longest chain is %zu"), entries, buckets, max_chain);
GetHashStats(*NickCoreList, entries, buckets, max_chain);
- source.Reply(_("Registered nick groups: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
+ source.Reply(_("Registered nick groups: %zu entries, %zu buckets, longest chain is %zu"), entries, buckets, max_chain);
if (session_service)
{
GetHashStats(session_service->GetSessions(), entries, buckets, max_chain);
- source.Reply(_("Sessions: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
+ source.Reply(_("Sessions: %zu entries, %zu buckets, longest chain is %zu"), entries, buckets, max_chain);
+ }
+ }
+
+ void DoStatsPassword(CommandSource &source)
+ {
+ Anope::map<size_t> counts;
+ size_t missing = 0;
+ size_t unknown = 0;
+ for (const auto &[_, nc] : *NickCoreList)
+ {
+ if (nc->pass.empty())
+ {
+ missing++;
+ continue;
+ }
+
+ auto sep = nc->pass.find(':');
+ if (sep == Anope::string::npos)
+ {
+ unknown++;
+ continue;
+ }
+
+ counts[nc->pass.substr(0, sep)]++;
}
+
+ for (const auto &[algo, count] : counts)
+ source.Reply(_("Passwords encrypted with %s: %zu"), algo.c_str(), count);
+ if (missing)
+ source.Reply(_("Missing passwords: %zu"), missing);
+ if (unknown)
+ source.Reply(_("Unknown passwords: %zu"), unknown);
}
- public:
+public:
CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1),
akills("XLineManager", "xlinemanager/sgline"), snlines("XLineManager", "xlinemanager/snline"), sqlines("XLineManager", "xlinemanager/sqline")
{
- this->SetDesc(_("Show status of Services and network"));
- this->SetSyntax("[AKILL | HASH | UPLINK | UPTIME | ALL | RESET]");
+ this->SetDesc(_("Show status of services and network"));
+ this->SetSyntax("[AKILL | HASH | PASSWORD | UPLINK | UPTIME | ALL | RESET]");
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Anope::string extra = !params.empty() ? params[0] : "";
@@ -213,29 +248,48 @@ class CommandOSStats : public Command
if (extra.equals_ci("RESET"))
return this->DoStatsReset(source);
+ bool handled = false;
if (extra.equals_ci("ALL") || extra.equals_ci("AKILL"))
+ {
this->DoStatsAkill(source);
+ handled = true;
+ }
if (extra.equals_ci("ALL") || extra.equals_ci("HASH"))
+ {
this->DoStatsHash(source);
+ handled = true;
+ }
+
+ if (extra.equals_ci("ALL") || extra.equals_ci("PASSWORD"))
+ {
+ this->DoStatsPassword(source);
+ handled = true;
+ }
if (extra.equals_ci("ALL") || extra.equals_ci("UPLINK"))
+ {
this->DoStatsUplink(source);
+ handled = true;
+ }
if (extra.empty() || extra.equals_ci("ALL") || extra.equals_ci("UPTIME"))
+ {
this->DoStatsUptime(source);
+ handled = true;
+ }
- if (!extra.empty() && !extra.equals_ci("ALL") && !extra.equals_ci("AKILL") && !extra.equals_ci("HASH") && !extra.equals_ci("UPLINK") && !extra.equals_ci("UPTIME"))
+ if (!handled)
source.Reply(_("Unknown STATS option: \002%s\002"), extra.c_str());
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Without any option, shows the current number of users online,\n"
- "and the highest number of users online since Services was\n"
- "started, and the length of time Services has been running.\n"
+ "and the highest number of users online since services was\n"
+ "started, and the length of time services has been running.\n"
" \n"
"With the \002AKILL\002 option, displays the current size of the\n"
"AKILL list and the current default expiry time.\n"
@@ -243,6 +297,9 @@ class CommandOSStats : public Command
"The \002RESET\002 option currently resets the maximum user count\n"
"to the number of users currently present on the network.\n"
" \n"
+ "The \002PASSWORD\002 option displays the encryption algorithms used\n"
+ "for user passwords.\n"
+ " \n"
"The \002UPLINK\002 option displays information about the current\n"
"server Anope uses as an uplink to the network.\n"
" \n"
@@ -253,20 +310,21 @@ class CommandOSStats : public Command
}
};
-class OSStats : public Module
+class OSStats final
+ : public Module
{
CommandOSStats commandosstats;
Serialize::Type stats_type;
Stats stats_saver;
- public:
+public:
OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosstats(this), stats_type("Stats", Stats::Unserialize)
{
}
- void OnUserConnect(User *u, bool &exempt) anope_override
+ void OnUserConnect(User *u, bool &exempt) override
{
if (UserListByNick.size() == MaxUserCount && Anope::CurTime == MaxUserTime)
stats_saver.QueueUpdate();
diff --git a/modules/commands/os_svs.cpp b/modules/operserv/os_svs.cpp
index 8458d8882..ee2131c17 100644
--- a/modules/commands/os_svs.cpp
+++ b/modules/operserv/os_svs.cpp
@@ -11,16 +11,17 @@
#include "module.h"
-class CommandOSSVSNick : public Command
+class CommandOSSVSNick final
+ : public Command
{
- public:
+public:
CommandOSSVSNick(Module *creator) : Command(creator, "operserv/svsnick", 2, 2)
{
this->SetDesc(_("Forcefully change a user's nickname"));
this->SetSyntax(_("\037nick\037 \037newnick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &nick = params[0];
Anope::string newnick = params[1];
@@ -33,10 +34,10 @@ class CommandOSSVSNick : public Command
}
/* Truncate long nicknames to nicklen characters */
- unsigned nicklen = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen");
+ size_t nicklen = IRCD->GetMaxNick();
if (newnick.length() > nicklen)
{
- source.Reply(_("Nick \002%s\002 was truncated to %d characters."), newnick.c_str(), nicklen, newnick.c_str());
+ source.Reply(_("Nick \002%s\002 was truncated to %zu characters."), newnick.c_str(), nicklen);
newnick = params[1].substr(0, nicklen);
}
@@ -61,7 +62,7 @@ class CommandOSSVSNick : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -70,16 +71,17 @@ class CommandOSSVSNick : public Command
}
};
-class CommandOSSVSJoin : public Command
+class CommandOSSVSJoin final
+ : public Command
{
- public:
+public:
CommandOSSVSJoin(Module *creator) : Command(creator, "operserv/svsjoin", 2, 2)
{
this->SetDesc(_("Forcefully join a user to a channel"));
this->SetSyntax(_("\037nick\037 \037channel\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!IRCD->CanSVSJoin)
{
@@ -105,7 +107,7 @@ class CommandOSSVSJoin : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -114,16 +116,17 @@ class CommandOSSVSJoin : public Command
}
};
-class CommandOSSVSPart : public Command
+class CommandOSSVSPart final
+ : public Command
{
- public:
+public:
CommandOSSVSPart(Module *creator) : Command(creator, "operserv/svspart", 2, 3)
{
this->SetDesc(_("Forcefully part a user from a channel"));
this->SetSyntax(_("\037nick\037 \037channel\037 [\037reason\037]"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!IRCD->CanSVSJoin)
{
@@ -153,7 +156,7 @@ class CommandOSSVSPart : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -162,13 +165,14 @@ class CommandOSSVSPart : public Command
}
};
-class OSSVS : public Module
+class OSSVS final
+ : public Module
{
CommandOSSVSNick commandossvsnick;
CommandOSSVSJoin commandossvsjoin;
CommandOSSVSPart commandossvspart;
- public:
+public:
OSSVS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandossvsnick(this), commandossvsjoin(this), commandossvspart(this)
{
diff --git a/modules/commands/os_sxline.cpp b/modules/operserv/os_sxline.cpp
index 97ad4acf9..2460a5fe8 100644
--- a/modules/commands/os_sxline.cpp
+++ b/modules/operserv/os_sxline.cpp
@@ -11,18 +11,19 @@
#include "module.h"
-class SXLineDelCallback : public NumberList
+class SXLineDelCallback final
+ : public NumberList
{
XLineManager *xlm;
Command *command;
CommandSource &source;
- unsigned deleted;
- public:
- SXLineDelCallback(XLineManager *x, Command *c, CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), xlm(x), command(c), source(_source), deleted(0)
+ unsigned deleted = 0;
+public:
+ SXLineDelCallback(XLineManager *x, Command *c, CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), xlm(x), command(c), source(_source)
{
}
- ~SXLineDelCallback()
+ ~SXLineDelCallback() override
{
if (!deleted)
source.Reply(_("No matching entries on the %s list."), source.command.c_str());
@@ -32,7 +33,7 @@ class SXLineDelCallback : public NumberList
source.Reply(_("Deleted %d entries from the %s list."), deleted, source.command.c_str());
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number)
return;
@@ -54,10 +55,11 @@ class SXLineDelCallback : public NumberList
}
};
-class CommandOSSXLineBase : public Command
+class CommandOSSXLineBase
+ : public Command
{
- private:
- virtual XLineManager* xlm() = 0;
+private:
+ virtual XLineManager *xlm() = 0;
virtual void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) = 0;
@@ -118,17 +120,18 @@ class CommandOSSXLineBase : public Command
if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
{
- class SXLineListCallback : public NumberList
+ class SXLineListCallback final
+ : public NumberList
{
XLineManager *xlm;
CommandSource &source;
ListFormatter &list;
- public:
+ public:
SXLineListCallback(XLineManager *x, CommandSource &_source, ListFormatter &_list, const Anope::string &numlist) : NumberList(numlist, false), xlm(x), source(_source), list(_list)
{
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number)
return;
@@ -139,7 +142,7 @@ class CommandOSSXLineBase : public Command
return;
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(number);
+ entry["Number"] = Anope::ToString(number);
entry["Mask"] = x->mask;
entry["By"] = x->by;
entry["Created"] = Anope::strftime(x->created, NULL, true);
@@ -161,7 +164,7 @@ class CommandOSSXLineBase : public Command
if (mask.empty() || mask.equals_ci(x->mask) || mask == x->id || Anope::Match(x->mask, mask, false, true))
{
ListFormatter::ListEntry entry;
- entry["Number"] = stringify(i + 1);
+ entry["Number"] = Anope::ToString(i + 1);
entry["Mask"] = x->mask;
entry["By"] = x->by;
entry["Created"] = Anope::strftime(x->created, NULL, true);
@@ -182,8 +185,8 @@ class CommandOSSXLineBase : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
}
@@ -223,17 +226,17 @@ class CommandOSSXLineBase : public Command
return;
}
- public:
+public:
CommandOSSXLineBase(Module *creator, const Anope::string &cmd) : Command(creator, cmd, 1, 4)
{
}
- const Anope::string GetDesc(CommandSource &source) const anope_override
+ const Anope::string GetDesc(CommandSource &source) const override
{
return Anope::printf(Language::Translate(source.GetAccount(), _("Manipulate the %s list")), source.command.upper().c_str());
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[0];
@@ -253,17 +256,18 @@ class CommandOSSXLineBase : public Command
return;
}
- virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override = 0;
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override = 0;
};
-class CommandOSSNLine : public CommandOSSXLineBase
+class CommandOSSNLine final
+ : public CommandOSSXLineBase
{
- XLineManager *xlm() anope_override
+ XLineManager *xlm() override
{
return this->snlines;
}
- void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!this->xlm())
return;
@@ -366,13 +370,13 @@ class CommandOSSNLine : public CommandOSSXLineBase
return;
}
- XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ auto *x = new XLine(mask, source.GetNick(), expires, reason);
if (Config->GetModule("operserv")->Get<bool>("akillids"))
x->id = XLineManager::GenerateUID();
unsigned int affected = 0;
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (this->xlm()->Check(it->second, x))
+ for (const auto &[_, user] : UserListByNick)
+ if (this->xlm()->Check(user, x))
++affected;
float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
@@ -401,10 +405,8 @@ class CommandOSSNLine : public CommandOSSXLineBase
{
Anope::string rreason = "G-Lined: " + reason;
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, user] : UserListByNick)
{
- User *user = it->second;
-
if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x))
user->Kill(Me, rreason);
}
@@ -419,7 +421,7 @@ class CommandOSSNLine : public CommandOSSXLineBase
}
ServiceReference<XLineManager> snlines;
- public:
+public:
CommandOSSNLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/snline"), snlines("XLineManager", "xlinemanager/snline")
{
this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037:\037reason\037"));
@@ -429,13 +431,13 @@ class CommandOSSNLine : public CommandOSSXLineBase
this->SetSyntax("CLEAR");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows Services Operators to manipulate the SNLINE list. If\n"
"a user with a realname matching an SNLINE mask attempts to\n"
- "connect, Services will not allow them to pursue their IRC\n"
+ "connect, services will not allow them to pursue their IRC\n"
"session."));
source.Reply(_(" \n"
"\002SNLINE ADD\002 adds the given realname mask to the SNLINE\n"
@@ -482,14 +484,15 @@ class CommandOSSNLine : public CommandOSSXLineBase
}
};
-class CommandOSSQLine : public CommandOSSXLineBase
+class CommandOSSQLine final
+ : public CommandOSSXLineBase
{
- XLineManager *xlm() anope_override
+ XLineManager *xlm() override
{
return this->sqlines;
}
- void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) override
{
if (!this->xlm())
return;
@@ -574,13 +577,13 @@ class CommandOSSQLine : public CommandOSSXLineBase
return;
}
- XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ auto *x = new XLine(mask, source.GetNick(), expires, reason);
if (Config->GetModule("operserv")->Get<bool>("akillids"))
x->id = XLineManager::GenerateUID();
unsigned int affected = 0;
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (this->xlm()->Check(it->second, x))
+ for (const auto &[_, user] : UserListByNick)
+ if (this->xlm()->Check(user, x))
++affected;
float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
@@ -611,33 +614,28 @@ class CommandOSSQLine : public CommandOSSXLineBase
if (mask[0] == '#')
{
- for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit)
+ for (const auto &[_, c] : ChannelList)
{
- Channel *c = cit->second;
-
if (!Anope::Match(c->name, mask, false, true))
continue;
std::vector<User *> users;
- for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
+ for (const auto &[_, uc] : c->users)
{
- ChanUserContainer *uc = it->second;
User *user = uc->user;
if (!user->HasMode("OPER") && user->server != Me)
users.push_back(user);
}
- for (unsigned i = 0; i < users.size(); ++i)
- c->Kick(NULL, users[i], "%s", reason.c_str());
+ for (auto *user : users)
+ c->Kick(NULL, user, reason);
}
}
else
{
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (const auto &[_, user] : UserListByNick)
{
- User *user = it->second;
-
if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x))
user->Kill(Me, rreason);
}
@@ -653,7 +651,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
}
ServiceReference<XLineManager> sqlines;
- public:
+public:
CommandOSSQLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/sqline"), sqlines("XLineManager", "xlinemanager/sqline")
{
this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037"));
@@ -663,13 +661,13 @@ class CommandOSSQLine : public CommandOSSXLineBase
this->SetSyntax("CLEAR");
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows Services Operators to manipulate the SQLINE list. If\n"
"a user with a nick matching an SQLINE mask attempts to\n"
- "connect, Services will not allow them to pursue their IRC\n"
+ "connect, services will not allow them to pursue their IRC\n"
"session.\n"
"If the first character of the mask is #, services will\n"
"prevent the use of matching channels. If the mask is a\n"
@@ -717,12 +715,13 @@ class CommandOSSQLine : public CommandOSSXLineBase
}
};
-class OSSXLine : public Module
+class OSSXLine final
+ : public Module
{
CommandOSSNLine commandossnline;
CommandOSSQLine commandossqline;
- public:
+public:
OSSXLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandossnline(this), commandossqline(this)
{
diff --git a/modules/commands/os_update.cpp b/modules/operserv/os_update.cpp
index b1df08e1e..b43c5f3cd 100644
--- a/modules/commands/os_update.cpp
+++ b/modules/operserv/os_update.cpp
@@ -11,15 +11,16 @@
#include "module.h"
-class CommandOSUpdate : public Command
+class CommandOSUpdate final
+ : public Command
{
- public:
+public:
CommandOSUpdate(Module *creator) : Command(creator, "operserv/update", 0, 0)
{
- this->SetDesc(_("Force the Services databases to be updated immediately"));
+ this->SetDesc(_("Force the services databases to be updated immediately"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
Log(LOG_ADMIN, source, this);
source.Reply(_("Updating databases."));
@@ -27,21 +28,22 @@ class CommandOSUpdate : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_("Causes Services to update all database files as soon as you\n"
+ source.Reply(_("Causes services to update all database files as soon as you\n"
"send the command."));
return true;
}
};
-class OSUpdate : public Module
+class OSUpdate final
+ : public Module
{
CommandOSUpdate commandosupdate;
- public:
+public:
OSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandosupdate(this)
{
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp
index 6ea52b093..8e8f321b6 100644
--- a/modules/protocol/bahamut.cpp
+++ b/modules/protocol/bahamut.cpp
@@ -11,28 +11,30 @@
#include "module.h"
-class ChannelModeFlood : public ChannelModeParam
+class ChannelModeFlood final
+ : public ChannelModeParam
{
- public:
+public:
ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { }
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
- try
- {
- Anope::string rest;
- if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
- return true;
- }
- catch (const ConvertException &) { }
+ if (value.empty() || value[0] == ':')
+ return false;
+
+ Anope::string rest;
+ auto num1 = Anope::Convert<int>(value[0] == '*' ? value.substr(1) : value, 0, &rest);
+ if (num1 <= 0 || rest[0] != ':' || rest.length() <= 1)
+ return false;
- return false;
+ return Anope::Convert<int>(rest.substr(1), 0, &rest) > 0 && rest.empty();
}
};
-class BahamutIRCdProto : public IRCDProto
+class BahamutIRCdProto final
+ : public IRCDProto
{
- public:
+public:
BahamutIRCdProto(Module *creator) : IRCDProto(creator, "Bahamut 1.8.x")
{
DefaultPseudoclientModes = "+";
@@ -45,91 +47,96 @@ class BahamutIRCdProto : public IRCDProto
MaxModes = 60;
}
- void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override
+ void SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector<Anope::string> &values) override
{
if (Servers::Capab.count("TSMODE") > 0)
{
- UplinkSocket::Message(source) << "MODE " << dest->name << " " << dest->creation_time << " " << buf;
+ auto params = values;
+ params.insert(params.begin(), { chan->name, Anope::ToString(chan->creation_time), modes });
+ Uplink::SendInternal({}, source, "MODE", params);
}
else
- IRCDProto::SendModeInternal(source, dest, buf);
+ IRCDProto::SendModeInternal(source, chan, modes, values);
}
- void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
+ void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values) override
{
- UplinkSocket::Message(source) << "SVSMODE " << u->nick << " " << u->timestamp << " " << buf;
+ auto params = values;
+ params.insert(params.begin(), { u->nick, Anope::ToString(u->timestamp), modes });
+ Uplink::SendInternal({}, source, "SVSMODE", params);
}
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg);
}
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg);
}
/* SVSHOLD - set */
- void SendSVSHold(const Anope::string &nick, time_t time) anope_override
+ void SendSVSHold(const Anope::string &nick, time_t time) override
{
- UplinkSocket::Message(Me) << "SVSHOLD " << nick << " " << time << " :Being held for registered user";
+ Uplink::Send("SVSHOLD", nick, time, "Being held for a registered user");
}
/* SVSHOLD - release */
- void SendSVSHoldDel(const Anope::string &nick) anope_override
+ void SendSVSHoldDel(const Anope::string &nick) override
{
- UplinkSocket::Message(Me) << "SVSHOLD " << nick << " 0";
+ Uplink::Send("SVSHOLD", nick, 0);
}
/* SQLINE */
- void SendSQLine(User *, const XLine *x) anope_override
+ void SendSQLine(User *, const XLine *x) override
{
- UplinkSocket::Message() << "SQLINE " << x->mask << " :" << x->GetReason();
+ Uplink::Send("SQLINE", x->mask, x->reason);
}
/* UNSLINE */
- void SendSGLineDel(const XLine *x) anope_override
+ void SendSGLineDel(const XLine *x) override
{
- UplinkSocket::Message() << "UNSGLINE 0 :" << x->mask;
+ Uplink::Send("UNSGLINE", 0, x->mask);
}
/* UNSZLINE */
- void SendSZLineDel(const XLine *x) anope_override
+ void SendSZLineDel(const XLine *x) override
{
/* this will likely fail so its only here for legacy */
- UplinkSocket::Message() << "UNSZLINE 0 " << x->GetHost();
+ Uplink::Send("UNSZLINE", 0, x->GetHost());
+
/* this is how we are supposed to deal with it */
- UplinkSocket::Message() << "RAKILL " << x->GetHost() << " *";
+ Uplink::Send("RAKILL", x->GetHost(), '*');
}
/* SZLINE */
- void SendSZLine(User *, const XLine *x) anope_override
+ void SendSZLine(User *, const XLine *x) override
{
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
+ // Calculate the time left before this would expire
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
+
/* this will likely fail so its only here for legacy */
- UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->GetReason();
+ Uplink::Send("SZLINE", x->GetHost(), x->GetReason());
+
/* this is how we are supposed to deal with it */
- UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->by << " " << Anope::CurTime << " :" << x->GetReason();
+ Uplink::Send("AKILL", x->GetHost(), '*', timeleft, x->by, Anope::CurTime, x->GetReason());
}
/* SVSNOOP */
- void SendSVSNOOP(const Server *server, bool set) anope_override
+ void SendSVSNOOP(const Server *server, bool set) override
{
- UplinkSocket::Message() << "SVSNOOP " << server->GetName() << " " << (set ? "+" : "-");
+ Uplink::Send("SVSNOOP", server->GetName(), set ? '+' : '-');
}
/* SGLINE */
- void SendSGLine(User *, const XLine *x) anope_override
+ void SendSGLine(User *, const XLine *x) override
{
- UplinkSocket::Message() << "SGLINE " << x->mask.length() << " :" << x->mask << ":" << x->GetReason();
+ Uplink::Send("SGLINE", x->mask.length(), x->mask, x->GetReason());
}
/* RAKILL */
- void SendAkillDel(const XLine *x) anope_override
+ void SendAkillDel(const XLine *x) override
{
if (x->IsRegex() || x->HasNickOrReal())
return;
@@ -145,25 +152,25 @@ class BahamutIRCdProto : public IRCDProto
}
}
- UplinkSocket::Message() << "RAKILL " << x->GetHost() << " " << x->GetUser();
+ Uplink::Send("RAKILL", x->GetHost(), x->GetUser());
}
/* TOPIC */
- void SendTopic(const MessageSource &source, Channel *c) anope_override
+ void SendTopic(const MessageSource &source, Channel *c) override
{
- UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic;
+ Uplink::Send(source, "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic);
}
/* UNSQLINE */
- void SendSQLineDel(const XLine *x) anope_override
+ void SendSQLineDel(const XLine *x) override
{
- UplinkSocket::Message() << "UNSQLINE " << x->mask;
+ Uplink::Send("UNSQLINE", x->mask);
}
/* JOIN - SJOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override
{
- UplinkSocket::Message(user) << "SJOIN " << c->creation_time << " " << c->name;
+ Uplink::Send(user, "SJOIN", c->creation_time, c->name);
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -176,24 +183,24 @@ class BahamutIRCdProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
- void SendAkill(User *u, XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) override
{
if (x->IsRegex() || x->HasNickOrReal())
{
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
@@ -220,47 +227,44 @@ class BahamutIRCdProto : public IRCDProto
}
}
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800)
- timeleft = 172800;
- UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->by << " " << Anope::CurTime << " :" << x->GetReason();
+ // Calculate the time left before this would expire
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
+ Uplink::Send("AKILL", x->GetHost(), x->GetUser(), timeleft, x->by, Anope::CurTime, x->reason);
}
/*
Note: if the stamp is null 0, the below usage is correct of Bahamut
*/
- void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
+ void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override
{
- UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf;
+ Uplink::Send(source, "SVSKILL", user->nick, buf);
}
- void SendBOB() anope_override
+ void SendBOB() override
{
- UplinkSocket::Message() << "BURST";
+ Uplink::Send("BURST");
}
- void SendEOB() anope_override
+ void SendEOB() override
{
- UplinkSocket::Message() << "BURST 0";
+ Uplink::Send("BURST", 0);
}
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message() << "NICK " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " " << u->server->GetName() << " 0 0 :" << u->realname;
+ Uplink::Send("NICK", u->nick, 1, u->timestamp, "+" + u->GetModes(), u->GetIdent(), u->host, u->server->GetName(), 0, 0, u->realname);
}
/* SERVER */
- void SendServer(const Server *server) anope_override
+ void SendServer(const Server *server) override
{
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription();
+ Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription());
}
- void SendConnect() anope_override
+ void SendConnect() override
{
- UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " :TS";
- UplinkSocket::Message() << "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3";
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS");
+ Uplink::Send("CAPAB", "SSJOIN", "NOQUIT", "BURST", "UNCONNECT", "NICKIP", "TSMODE", "TS3");
SendServer(Me);
/*
* SVINFO
@@ -270,34 +274,32 @@ class BahamutIRCdProto : public IRCDProto
* parv[3] = server is standalone or connected to non-TS only
* parv[4] = server's idea of UTC time
*/
- UplinkSocket::Message() << "SVINFO 3 1 0 :" << Anope::CurTime;
+ Uplink::Send("SVINFO", 3, 1, 0, Anope::CurTime);
this->SendBOB();
}
- void SendChannel(Channel *c) anope_override
+ void SendChannel(Channel *c) override
{
- Anope::string modes = c->GetModes(true, true);
- if (modes.empty())
- modes = "+";
- UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :";
+ Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), "");
}
- void SendLogin(User *u, NickAlias *) anope_override
+ void SendLogin(User *u, NickAlias *) override
{
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon);
+ IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", u->signon);
}
- void SendLogout(User *u) anope_override
+ void SendLogout(User *u) override
{
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 1");
+ IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", 1);
}
};
-struct IRCDMessageBurst : IRCDMessage
+struct IRCDMessageBurst final
+ : IRCDMessage
{
- IRCDMessageBurst(Module *creator) : IRCDMessage(creator, "BURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageBurst(Module *creator) : IRCDMessage(creator, "BURST", 0) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* If we found a server with the given source, that one just
* finished bursting. If there was no source, then our uplink
@@ -311,22 +313,17 @@ struct IRCDMessageBurst : IRCDMessage
}
};
-struct IRCDMessageMode : IRCDMessage
+struct IRCDMessageMode final
+ : IRCDMessage
{
- IRCDMessageMode(Module *creator, const Anope::string &sname) : IRCDMessage(creator, sname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageMode(Module *creator, const Anope::string &sname) : IRCDMessage(creator, sname, 2) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() > 2 && IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
- time_t ts = 0;
-
- try
- {
- ts = convertTo<time_t>(params[1]);
- }
- catch (const ConvertException &) { }
+ auto ts = IRCD->ExtractTimestamp(params[1]);
Anope::string modes = params[2];
for (unsigned int i = 3; i < params.size(); ++i)
@@ -339,7 +336,7 @@ struct IRCDMessageMode : IRCDMessage
{
User *u = User::Find(params[0]);
if (u)
- u->SetModesInternal(source, "%s", params[1].c_str());
+ u->SetModesInternal(source, params[1]);
}
}
};
@@ -362,11 +359,12 @@ struct IRCDMessageMode : IRCDMessage
** parv[0] = new nickname
** parv[1] = hopcount
*/
-struct IRCDMessageNick : IRCDMessage
+struct IRCDMessageNick final
+ : IRCDMessage
{
- IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() == 10)
{
@@ -378,8 +376,8 @@ struct IRCDMessageNick : IRCDMessage
}
NickAlias *na = NULL;
- time_t signon = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0,
- stamp = params[7].is_pos_number_only() ? convertTo<time_t>(params[7]) : 0;
+ auto signon = IRCD->ExtractTimestamp(params[2]);
+ auto stamp = IRCD->ExtractTimestamp(params[7]);
if (signon && signon == stamp)
na = NickAlias::Find(params[0]);
@@ -395,22 +393,24 @@ struct IRCDMessageNick : IRCDMessage
}
};
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
+ auto hops = Anope::Convert<unsigned>(params[1], 0);
new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[2]);
}
};
-struct IRCDMessageSJoin : IRCDMessage
+struct IRCDMessageSJoin final
+ : IRCDMessage
{
- IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Anope::string modes;
if (params.size() >= 4)
@@ -457,24 +457,26 @@ struct IRCDMessageSJoin : IRCDMessage
}
}
- time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
+ auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[1], ts, modes, users);
}
};
-struct IRCDMessageTopic : IRCDMessage
+struct IRCDMessageTopic final
+ : IRCDMessage
{
IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Channel *c = Channel::Find(params[0]);
if (c)
- c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime);
+ c->ChangeTopicInternal(source.GetUser(), params[1], params[3], IRCD->ExtractTimestamp(params[2]));
}
};
-class ProtoBahamut : public Module
+class ProtoBahamut final
+ : public Module
{
BahamutIRCdProto ircd_proto;
@@ -506,7 +508,7 @@ class ProtoBahamut : public Module
IRCDMessageSJoin message_sjoin;
IRCDMessageTopic message_topic;
- void AddModes()
+ static void AddModes()
{
/* Add user modes */
ModeManager::AddUserMode(new UserModeOperOnly("SERV_ADMIN", 'A'));
@@ -544,7 +546,7 @@ class ProtoBahamut : public Module
ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R'));
}
- public:
+public:
ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_away(this), message_capab(this), message_error(this), message_invite(this),
@@ -560,7 +562,7 @@ class ProtoBahamut : public Module
}
- void OnUserNickChange(User *u, const Anope::string &) anope_override
+ void OnUserNickChange(User *u, const Anope::string &) override
{
u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED"));
IRCD->SendLogout(u);
diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp
index 91b9874c9..4d2ed2e82 100644
--- a/modules/protocol/hybrid.cpp
+++ b/modules/protocol/hybrid.cpp
@@ -15,15 +15,16 @@
static Anope::string UplinkSID;
static bool UseSVSAccount = false; // Temporary backwards compatibility hack until old proto is deprecated
-class HybridProto : public IRCDProto
+class HybridProto final
+ : public IRCDProto
{
- void SendSVSKillInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
+ void SendSVSKill(const MessageSource &source, User *u, const Anope::string &buf) override
{
- IRCDProto::SendSVSKillInternal(source, u, buf);
+ IRCDProto::SendSVSKill(source, u, buf);
u->KillInternal(source, buf);
}
- public:
+public:
HybridProto(Module *creator) : IRCDProto(creator, "ircd-hybrid 8.2.23+")
{
DefaultPseudoclientModes = "+oi";
@@ -40,68 +41,64 @@ class HybridProto : public IRCDProto
MaxModes = 6;
}
- void SendInvite(const MessageSource &source, const Channel *c, User *u) anope_override
+ void SendInvite(const MessageSource &source, const Channel *c, User *u) override
{
- UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name << " " << c->creation_time;
+ Uplink::Send(source, "INVITE", u->GetUID(), c->name, c->creation_time);
}
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "NOTICE $$" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "NOTICE", "$$" + dest->GetName(), msg);
}
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "PRIVMSG $$" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "PRIVMSG", "$$" + dest->GetName(), msg);
}
- void SendSQLine(User *, const XLine *x) anope_override
+ void SendSQLine(User *, const XLine *x) override
{
- UplinkSocket::Message(Me) << "RESV * " << (x->expires ? x->expires - Anope::CurTime : 0) << " " << x->mask << " :" << x->reason;
+ Uplink::Send("RESV", '*', x->expires ? x->expires - Anope::CurTime : 0, x->mask, x->reason);
}
- void SendSGLineDel(const XLine *x) anope_override
+ void SendSGLineDel(const XLine *x) override
{
- UplinkSocket::Message(Me) << "UNXLINE * " << x->mask;
+ Uplink::Send("UNXLINE", '*', x->mask);
}
- void SendSGLine(User *, const XLine *x) anope_override
+ void SendSGLine(User *, const XLine *x) override
{
- UplinkSocket::Message(Me) << "XLINE * " << x->mask << " " << (x->expires ? x->expires - Anope::CurTime : 0) << " :" << x->GetReason();
+ Uplink::Send("XLINE", '*', x->mask, x->expires ? x->expires - Anope::CurTime : 0, x->GetReason());
}
- void SendSZLineDel(const XLine *x) anope_override
+ void SendSZLineDel(const XLine *x) override
{
- UplinkSocket::Message(Me) << "UNDLINE * " << x->GetHost();
+ Uplink::Send("UNDLINE", '*', x->GetHost());
}
- void SendSZLine(User *, const XLine *x) anope_override
+ void SendSZLine(User *, const XLine *x) override
{
- /* Calculate the time left before this would expire, capping it at 2 days */
- time_t timeleft = x->expires - Anope::CurTime;
-
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
-
- UplinkSocket::Message(Me) << "DLINE * " << timeleft << " " << x->GetHost() << " :" << x->GetReason();
+ /* Calculate the time left before this would expire */
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
+ Uplink::Send("DLINE", '*', timeleft, x->GetHost(), x->GetReason());
}
- void SendAkillDel(const XLine *x) anope_override
+ void SendAkillDel(const XLine *x) override
{
if (x->IsRegex() || x->HasNickOrReal())
return;
- UplinkSocket::Message(Me) << "UNKLINE * " << x->GetUser() << " " << x->GetHost();
+ Uplink::Send("UNKLINE", '*', x->GetUser(), x->GetHost());
}
- void SendSQLineDel(const XLine *x) anope_override
+ void SendSQLineDel(const XLine *x) override
{
- UplinkSocket::Message(Me) << "UNRESV * " << x->mask;
+ Uplink::Send("UNRESV", '*', x->mask);
}
- void SendJoin(User *u, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(User *u, Channel *c, const ChannelStatus *status) override
{
- UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << u->GetUID();
+ Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), u->GetUID());
/*
* Note that we can send this with the SJOIN but choose not to
@@ -122,15 +119,15 @@ class HybridProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(u->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), u->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), u->GetUID(), false);
if (uc)
uc->status = cs;
}
}
- void SendAkill(User *u, XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) override
{
if (x->IsRegex() || x->HasNickOrReal())
{
@@ -140,9 +137,9 @@ class HybridProto : public IRCDProto
* No user (this akill was just added), and contains nick and/or realname.
* Find users that match and ban them.
*/
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
@@ -153,7 +150,7 @@ class HybridProto : public IRCDProto
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
+ auto *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
old->manager->AddXLine(xline);
x = xline;
@@ -162,26 +159,22 @@ class HybridProto : public IRCDProto
<< u->realname << " matches " << old->mask;
}
- /* Calculate the time left before this would expire, capping it at 2 days */
- time_t timeleft = x->expires - Anope::CurTime;
-
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
-
- UplinkSocket::Message(Me) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason();
+ /* Calculate the time left before this would expire */
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
+ Uplink::Send("KLINE", '*', timeleft, x->GetUser(), x->GetHost(), x->GetReason());
}
- void SendServer(const Server *server) anope_override
+ void SendServer(const Server *server) override
{
if (server == Me)
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " +" << " :" << server->GetDescription();
+ Uplink::Send("SERVER", server->GetName(), server->GetHops() + 1, server->GetSID(), '+', server->GetDescription());
else
- UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " +" << " :" << server->GetDescription();
+ Uplink::Send("SID", server->GetName(), server->GetHops() + 1, server->GetSID(), '+', server->GetDescription());
}
- void SendConnect() anope_override
+ void SendConnect() override
{
- UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password;
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password);
/*
* TBURST - Supports topic burst
@@ -190,106 +183,104 @@ class HybridProto : public IRCDProto
* RHOST - Supports UID message with realhost information
* MLOCK - Supports MLOCK
*/
- UplinkSocket::Message() << "CAPAB :ENCAP TBURST EOB RHOST MLOCK";
+ Uplink::Send("CAPAB", "ENCAP", "TBURST", "EOB", "RHOST", "MLOCK");
SendServer(Me);
- UplinkSocket::Message(Me) << "SVINFO 6 6 0 :" << Anope::CurTime;
+ Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime);
}
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
-
- UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " "
- << u->host << " " << u->host << " 0.0.0.0 " << u->GetUID() << " * :" << u->realname;
+ Uplink::Send("UID", u->nick, 1, u->timestamp, "+" + u->GetModes(), u->GetIdent(), u->host, u->host, "0.0.0.0", u->GetUID(), '*', u->realname);
}
- void SendEOB() anope_override
+ void SendEOB() override
{
- UplinkSocket::Message(Me) << "EOB";
+ Uplink::Send("EOB");
}
- void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
+ void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values) override
{
- UplinkSocket::Message(source) << "SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf;
+ auto params = values;
+ params.insert(params.begin(), { u->GetUID(), Anope::ToString(u->timestamp), modes });
+ Uplink::SendInternal({}, source, "SVSMODE", params);
}
- void SendLogin(User *u, NickAlias *na) anope_override
+ void SendLogin(User *u, NickAlias *na) override
{
- if (UseSVSAccount == false)
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str());
+ if (!UseSVSAccount)
+ IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", na->nc->display);
else
- UplinkSocket::Message(Me) << "SVSACCOUNT " << u->GetUID() << " " << u->timestamp << " " << na->nc->display;
+ Uplink::Send("SVSACCOUNT", u->GetUID(), u->timestamp, na->nc->display);
}
- void SendLogout(User *u) anope_override
+ void SendLogout(User *u) override
{
- if (UseSVSAccount == false)
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d *");
+ if (!UseSVSAccount)
+ IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", '*');
else
- UplinkSocket::Message(Me) << "SVSACCOUNT " << u->GetUID() << " " << u->timestamp << " *";
+ Uplink::Send("SVSACCOUNT", u->GetUID(), u->timestamp, '*');
}
- void SendChannel(Channel *c) anope_override
+ void SendChannel(Channel *c) override
{
- Anope::string modes = "+" + c->GetModes(true, true);
- UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :";
+ Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), "");
}
- void SendTopic(const MessageSource &source, Channel *c) anope_override
+ void SendTopic(const MessageSource &source, Channel *c) override
{
- UplinkSocket::Message(source) << "TBURST " << c->creation_time << " " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic;
+ Uplink::Send(source, "TBURST", c->creation_time, c->name, c->topic_ts, c->topic_setter, c->topic);
}
- void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override
+ void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override
{
- UplinkSocket::Message(Me) << "SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when;
+ Uplink::Send("SVSNICK", u->GetUID(), u->timestamp, newnick, when);
}
- void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) anope_override
+ void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) override
{
- UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan;
+ Uplink::Send(source, "SVSJOIN", u->GetUID(), chan);
}
- void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) anope_override
+ void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) override
{
if (!param.empty())
- UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param;
+ Uplink::Send(source, "SVSPART", u->GetUID(), chan, param);
else
- UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan;
+ Uplink::Send(source, "SVSPART", u->GetUID(), chan);
}
- void SendSVSHold(const Anope::string &nick, time_t t) anope_override
+ void SendSVSHold(const Anope::string &nick, time_t t) override
{
- XLine x(nick, Me->GetName(), Anope::CurTime + t, "Being held for registered user");
+ XLine x(nick, Me->GetName(), Anope::CurTime + t, "Being held for a registered user");
this->SendSQLine(NULL, &x);
}
- void SendSVSHoldDel(const Anope::string &nick) anope_override
+ void SendSVSHoldDel(const Anope::string &nick) override
{
XLine x(nick);
this->SendSQLineDel(&x);
}
- void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override
+ void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override
{
- UplinkSocket::Message(Me) << "SVSHOST " << u->GetUID() << " " << u->timestamp << " " << host;
+ Uplink::Send("SVSHOST", u->GetUID(), u->timestamp, host);
}
- void SendVhostDel(User *u) anope_override
+ void SendVhostDel(User *u) override
{
- UplinkSocket::Message(Me) << "SVSHOST " << u->GetUID() << " " << u->timestamp << " " << u->host;
+ Uplink::Send("SVSHOST", u->GetUID(), u->timestamp, u->host);
}
- bool IsExtbanValid(const Anope::string &mask) anope_override
+ bool IsExtbanValid(const Anope::string &mask) override
{
return mask.length() >= 4 && mask[0] == '$' && mask[2] == ':';
}
- bool IsIdentValid(const Anope::string &ident) anope_override
+ bool IsIdentValid(const Anope::string &ident) override
{
- if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
+ if (ident.empty() || ident.length() > IRCD->GetMaxUser())
return false;
/*
@@ -305,10 +296,8 @@ class HybridProto : public IRCDProto
if (a == '-' || a == '_' || a == '.')
return false;
- for (i = 0; i < ident.length(); ++i)
+ for (const auto c : ident)
{
- const char &c = ident[i];
-
/* A tilde can only be used as the first character of a user name. */
if (c == '~' && i == 0)
continue;
@@ -325,13 +314,14 @@ class HybridProto : public IRCDProto
}
};
-struct IRCDMessageBMask : IRCDMessage
+struct IRCDMessageBMask final
+ : IRCDMessage
{
- IRCDMessageBMask(Module *creator) : IRCDMessage(creator, "BMASK", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageBMask(Module *creator) : IRCDMessage(creator, "BMASK", 4) { SetFlag(FLAG_REQUIRE_SERVER); }
/* 0 1 2 3 */
/* :0MC BMASK 1350157102 #channel b :*!*@*.test.com */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Channel *c = Channel::Find(params[1]);
ChannelMode *mode = ModeManager::FindChannelModeByChar(params[2][0]);
@@ -347,13 +337,14 @@ struct IRCDMessageBMask : IRCDMessage
}
};
-struct IRCDMessageCapab : Message::Capab
+struct IRCDMessageCapab final
+ : Message::Capab
{
- IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(FLAG_SOFT_LIMIT); }
/* 0 */
/* CAPAB :TBURST EOB MLOCK */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
spacesepstream sep(params[0]);
Anope::string capab;
@@ -368,17 +359,17 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '~', 4));
}
- Message::Capab::Run(source, params);
+ Message::Capab::Run(source, params, tags);
}
};
struct IRCDMessageCertFP: IRCDMessage
{
- IRCDMessageCertFP(Module *creator) : IRCDMessage(creator, "CERTFP", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageCertFP(Module *creator) : IRCDMessage(creator, "CERTFP", 1) { SetFlag(FLAG_REQUIRE_USER); }
/* 0 */
/* :0MCAAAAAB CERTFP 4C62287BA6776A89CD4F8FF10A62FFB35E79319F51AF6C62C674984974FCCB1D */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = source.GetUser();
@@ -387,21 +378,23 @@ struct IRCDMessageCertFP: IRCDMessage
}
};
-struct IRCDMessageEOB : IRCDMessage
+struct IRCDMessageEOB final
+ : IRCDMessage
{
- IRCDMessageEOB(Module *creator) : IRCDMessage(creator, "EOB", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageEOB(Module *creator) : IRCDMessage(creator, "EOB", 0) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
source.GetServer()->Sync(true);
}
};
-struct IRCDMessageJoin : Message::Join
+struct IRCDMessageJoin final
+ : Message::Join
{
IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() < 2)
return;
@@ -409,17 +402,18 @@ struct IRCDMessageJoin : Message::Join
std::vector<Anope::string> p = params;
p.erase(p.begin());
- Message::Join::Run(source, p);
+ Message::Join::Run(source, p, tags);
}
};
-struct IRCDMessageMetadata : IRCDMessage
+struct IRCDMessageMetadata final
+ : IRCDMessage
{
- IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
/* 0 1 2 3 */
/* :0MC METADATA client 0MCAAAAAB certfp :4C62287BA6776A89CD4F8FF10A62FFB35E79319F51AF6C62C674984974FCCB1D */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params[0].equals_cs("client"))
{
@@ -439,13 +433,14 @@ struct IRCDMessageMetadata : IRCDMessage
}
};
-struct IRCDMessageMLock : IRCDMessage
+struct IRCDMessageMLock final
+ : IRCDMessage
{
- IRCDMessageMLock(Module *creator) : IRCDMessage(creator, "MLOCK", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageMLock(Module *creator) : IRCDMessage(creator, "MLOCK", 4) { SetFlag(FLAG_REQUIRE_SERVER); }
/* 0 1 2 3 */
/* :0MC MLOCK 1350157102 #channel 1350158923 :nt */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Channel *c = Channel::Find(params[1]);
@@ -459,53 +454,57 @@ struct IRCDMessageMLock : IRCDMessage
// Mode lock string is not what we say it is?
if (modes != params[3])
- UplinkSocket::Message(Me) << "MLOCK " << c->creation_time << " " << c->name << " " << Anope::CurTime << " :" << modes;
+ Uplink::Send("MLOCK", c->creation_time, c->name, Anope::CurTime, modes);
}
}
};
-struct IRCDMessageNick : IRCDMessage
+struct IRCDMessageNick final
+ : IRCDMessage
{
- IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(FLAG_REQUIRE_USER); }
/* 0 1 */
/* :0MCAAAAAB NICK newnick 1350157102 */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- source.GetUser()->ChangeNick(params[0], convertTo<time_t>(params[1]));
+ source.GetUser()->ChangeNick(params[0], IRCD->ExtractTimestamp(params[1]));
}
};
-struct IRCDMessagePass : IRCDMessage
+struct IRCDMessagePass final
+ : IRCDMessage
{
- IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 1) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
/* 0 */
/* PASS password */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() == 4)
UplinkSID = params[3];
}
};
-struct IRCDMessagePong : IRCDMessage
+struct IRCDMessagePong final
+ : IRCDMessage
{
- IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
source.GetServer()->Sync(false);
}
};
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
/* 0 1 2 3 4 */
/* SERVER hades.arpa 1 4XY + :ircd-hybrid test server */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* Servers other than our immediate uplink are introduced via SID */
if (params[1] != "1")
@@ -523,28 +522,30 @@ struct IRCDMessageServer : IRCDMessage
}
};
-struct IRCDMessageSID : IRCDMessage
+struct IRCDMessageSID final
+ : IRCDMessage
{
- IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 5) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
/* 0 1 2 3 4 */
/* :0MC SID hades.arpa 2 4XY + :ircd-hybrid test server */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
+ auto hops = Anope::Convert(params[1], 0);
new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params.back(), params[2]);
IRCD->SendPing(Me->GetName(), params[0]);
}
};
-struct IRCDMessageSJoin : IRCDMessage
+struct IRCDMessageSJoin final
+ : IRCDMessage
{
- IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 4) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
/* 0 1 2 3 */
/* :0MC SJOIN 1654877335 #nether +nt :@0MCAAAAAB +0MCAAAAAC */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Anope::string modes;
@@ -580,42 +581,44 @@ struct IRCDMessageSJoin : IRCDMessage
users.push_back(sju);
}
- time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
+ auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[1], ts, modes, users);
}
};
-struct IRCDMessageSVSMode : IRCDMessage
+struct IRCDMessageSVSMode final
+ : IRCDMessage
{
- IRCDMessageSVSMode(Module *creator) : IRCDMessage(creator, "SVSMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageSVSMode(Module *creator) : IRCDMessage(creator, "SVSMODE", 3) { SetFlag(FLAG_SOFT_LIMIT); }
/* 0 1 2 */
/* :0MC SVSMODE 0MCAAAAAB 1350157102 +r */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = User::Find(params[0]);
if (!u)
return;
- if (!params[1].is_pos_number_only() || convertTo<time_t>(params[1]) != u->timestamp)
+ if (IRCD->ExtractTimestamp(params[1]) != u->timestamp)
return;
- u->SetModesInternal(source, "%s", params[2].c_str());
+ u->SetModesInternal(source, params[2]);
}
};
-struct IRCDMessageTBurst : IRCDMessage
+struct IRCDMessageTBurst final
+ : IRCDMessage
{
IRCDMessageTBurst(Module *creator) : IRCDMessage(creator, "TBURST", 5) { }
/* 0 1 2 3 4 */
/* :0MC TBURST 1654867975 #nether 1654877335 Steve!~steve@the.mines :Join the ghast nation */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Anope::string setter;
sepstream(params[3], '!').GetToken(setter, 0);
- time_t topic_time = Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime;
+ auto topic_time = IRCD->ExtractTimestamp(params[2]);
Channel *c = Channel::Find(params[1]);
if (c)
@@ -623,22 +626,16 @@ struct IRCDMessageTBurst : IRCDMessage
}
};
-struct IRCDMessageTMode : IRCDMessage
+struct IRCDMessageTMode final
+ : IRCDMessage
{
- IRCDMessageTMode(Module *creator) : IRCDMessage(creator, "TMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageTMode(Module *creator) : IRCDMessage(creator, "TMODE", 3) { SetFlag(FLAG_SOFT_LIMIT); }
/* 0 1 2 */
/* :0MC TMODE 1654867975 #nether +ntR */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- time_t ts = 0;
-
- try
- {
- ts = convertTo<time_t>(params[0]);
- }
- catch (const ConvertException &) { }
-
+ auto ts = IRCD->ExtractTimestamp(params[0]);
Channel *c = Channel::Find(params[1]);
Anope::string modes = params[2];
@@ -650,13 +647,14 @@ struct IRCDMessageTMode : IRCDMessage
}
};
-struct IRCDMessageUID : IRCDMessage
+struct IRCDMessageUID final
+ : IRCDMessage
{
- IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
/* 0 1 2 3 4 5 6 7 8 9 10 */
/* :0MC UID Steve 1 1350157102 +oi ~steve virtual.host real.host 10.0.0.1 0MCAAAAAB Steve :Mining all the time */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
NickAlias *na = NULL;
@@ -665,12 +663,12 @@ struct IRCDMessageUID : IRCDMessage
/* Source is always the server */
User::OnIntroduce(params[0], params[4], params[6], params[5], params[7], source.GetServer(), params[10],
- params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0,
- params[3], params[8], na ? *na->nc : NULL);
+ IRCD->ExtractTimestamp(params[2]), params[3], params[8], na ? *na->nc : NULL);
}
};
-class ProtoHybrid : public Module
+class ProtoHybrid final
+ : public Module
{
HybridProto ircd_proto;
@@ -715,7 +713,7 @@ class ProtoHybrid : public Module
bool use_server_side_mlock;
- void AddModes()
+ static void AddModes()
{
/* Add user modes */
ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a'));
@@ -773,7 +771,7 @@ class ProtoHybrid : public Module
ModeManager::AddChannelMode(new ChannelModeNoone("ISSECURE", 'Z'));
}
- public:
+public:
ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_away(this),
@@ -816,17 +814,17 @@ class ProtoHybrid : public Module
this->AddModes();
}
- void OnUserNickChange(User *u, const Anope::string &) anope_override
+ void OnUserNickChange(User *u, const Anope::string &) override
{
u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED"));
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (!c->ci)
return;
@@ -835,37 +833,37 @@ class ProtoHybrid : public Module
if (use_server_side_mlock && modelocks && Servers::Capab.count("MLOCK"))
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
- UplinkSocket::Message(Me) << "MLOCK " << c->creation_time << " " << c->ci->name << " " << Anope::CurTime << " :" << modes;
+ Uplink::Send("MLOCK", c->creation_time, c->ci->name, Anope::CurTime, modes);
}
}
- void OnDelChan(ChannelInfo *ci) anope_override
+ void OnDelChan(ChannelInfo *ci) override
{
if (use_server_side_mlock && ci->c && Servers::Capab.count("MLOCK"))
- UplinkSocket::Message(Me) << "MLOCK " << ci->c->creation_time << " " << ci->name << " " << Anope::CurTime << " :";
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, Anope::CurTime, "");
}
- EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK"))
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar;
- UplinkSocket::Message(Me) << "MLOCK " << ci->c->creation_time << " " << ci->name << " " << Anope::CurTime << " :" << modes;
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, Anope::CurTime, modes);
}
return EVENT_CONTINUE;
}
- EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK"))
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, "");
- UplinkSocket::Message(Me) << "MLOCK " << ci->c->creation_time << " " << ci->name << " " << Anope::CurTime << " :" << modes;
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, Anope::CurTime, modes);
}
return EVENT_CONTINUE;
diff --git a/modules/protocol/inspircd3.cpp b/modules/protocol/inspircd.cpp
index 16a6ba1d4..e0cf20b85 100644
--- a/modules/protocol/inspircd3.cpp
+++ b/modules/protocol/inspircd.cpp
@@ -1,4 +1,4 @@
-/* InspIRCd 3.0 functions
+/* InspIRCd functions
*
* (C) 2003-2024 Anope Team
* Contact us at team@anope.org
@@ -11,54 +11,139 @@
#include "module.h"
#include "modules/cs_mode.h"
+#include "modules/httpd.h"
#include "modules/sasl.h"
typedef std::map<char, unsigned> ListLimits;
-struct SASLUser
+struct SASLUser final
{
Anope::string uid;
Anope::string acc;
time_t created;
};
-static std::list<SASLUser> saslusers;
+namespace
+{
+ // The maximum length of a channel name.
+ size_t maxchannel = 0;
+
+ // The maximum length of a hostname.
+ size_t maxhost = 0;
+
+ // The maximum length of a nickname.
+ size_t maxnick = 0;
+
+ // The maximum length of a username.
+ size_t maxuser = 0;
+
+ // The SID of a server we are waiting to squit.
+ Anope::string rsquit_id;
+
+ // The hostname of a server we are waiting to squit.
+ Anope::string rsquit_server;
+
+ // Non-introduced users who have authenticated via SASL.
+ std::list<SASLUser> saslusers;
+
+ // The version of the InspIRCd protocol that we are using.
+ size_t spanningtree_proto_ver = 1205;
+
+ // Parses a module name in the format "m_foo.so=bar" to {foo, bar}.
+ void ParseModule(const Anope::string &module, Anope::string &modname, Anope::string &moddata)
+ {
+ size_t sep = module.find('=');
+
+ // Extract and clean up the module name.
+ modname = module.substr(0, sep);
+ if (modname.compare(0, 2, "m_", 2) == 0)
+ modname.erase(0, 2);
+
+ if (modname.length() > 3 && modname.compare(modname.length() - 3, 3, ".so", 3) == 0)
+ modname.erase(modname.length() - 3);
+
+ // Extract the module link data (if any).
+ moddata = (sep == Anope::string::npos) ? "" : module.substr(sep + 1);
+
+ if (Anope::ProtocolDebug)
+ Log(LOG_DEBUG) << "Parsed module: name=" << modname << " data=" << moddata;
+ }
+
+ void ParseModuleData(const Anope::string &moddata, Anope::map<Anope::string> &modmap)
+ {
+ sepstream datastream(moddata, '&');
+ for (Anope::string datapair; datastream.GetToken(datapair); )
+ {
+ size_t split = datapair.find('=');
+ std::pair<Anope::map<Anope::string>::iterator, bool> res;
+ if (split == Anope::string::npos)
+ res = modmap.emplace(datapair, "");
+ else
+ res = modmap.emplace(datapair.substr(0, split), HTTPUtils::URLDecode(datapair.substr(split + 1)));
-static Anope::string rsquit_server, rsquit_id;
+ if (Anope::ProtocolDebug && res.second)
+ Log(LOG_DEBUG) << "Parsed module data: key=" << res.first->first << " value=" << res.first->second;
+ }
+ }
+}
-class InspIRCd3Proto : public IRCDProto
+class InspIRCdProto final
+ : public IRCDProto
{
- private:
- void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent)
+private:
+ static Anope::string GetAccountNicks(NickAlias* na)
+ {
+ if (!na)
+ return {};
+
+ Anope::string nicks;
+ for (const auto &na : *na->nc->aliases)
+ nicks += " " + na->nick;
+ return nicks.substr(1);
+ }
+
+ static void SendChgIdentInternal(const Anope::string &uid, const Anope::string &vIdent)
{
if (!Servers::Capab.count("CHGIDENT"))
- Log() << "CHGIDENT not loaded!";
- else
- UplinkSocket::Message(Me) << "CHGIDENT " << nick << " " << vIdent;
+ {
+ Log() << "Unable to change the vident of " << uid << " as the remote server does not have the chgident module loaded.";
+ return;
+ }
+ Uplink::Send("ENCAP", uid.substr(0, 3), "CHGIDENT", uid, vIdent);
}
- void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost)
+ static void SendChgHostInternal(const Anope::string &uid, const Anope::string &vhost)
{
if (!Servers::Capab.count("CHGHOST"))
- Log() << "CHGHOST not loaded!";
- else
- UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost;
+ {
+ Log() << "Unable to change the vhost of " << uid << " as the remote server does not have the chghost module loaded.";
+ return;
+ }
+ Uplink::Send("ENCAP", uid.substr(0, 3), "CHGHOST", uid, vhost);
}
- void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason)
+ static void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason)
{
- UplinkSocket::Message(Me) << "ADDLINE " << xtype << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason;
+ Uplink::Send("ADDLINE", xtype, mask, addedby, Anope::CurTime, duration, reason);
}
- void SendDelLine(const Anope::string &xtype, const Anope::string &mask)
+ static void SendDelLine(const Anope::string &xtype, const Anope::string &mask)
{
- UplinkSocket::Message(Me) << "DELLINE " << xtype << " " << mask;
+ Uplink::Send("DELLINE", xtype, mask);
}
- public:
+ static void SendAccount(const Anope::string &uid, NickAlias *na)
+ {
+ Uplink::Send("METADATA", uid, "accountid", na ? Anope::ToString(na->nc->GetId()) : Anope::string());
+ Uplink::Send("METADATA", uid, "accountname", na ? na->nc->display : Anope::string());
+ if (spanningtree_proto_ver >= 1206)
+ Uplink::Send("METADATA", uid, "accountnicks", GetAccountNicks(na));
+ }
+
+public:
PrimitiveExtensibleItem<ListLimits> maxlist;
- InspIRCd3Proto(Module *creator) : IRCDProto(creator, "InspIRCd 3"), maxlist(creator, "maxlist")
+ InspIRCdProto(Module *creator) : IRCDProto(creator, "InspIRCd 3+"), maxlist(creator, "maxlist")
{
DefaultPseudoclientModes = "+oI";
CanSVSNick = true;
@@ -67,13 +152,24 @@ class InspIRCd3Proto : public IRCDProto
CanSetVIdent = true;
CanSQLine = true;
CanSZLine = true;
+ CanSVSLogout = true;
CanCertFP = true;
RequiresID = true;
MaxModes = 20;
MaxLine = 4096;
}
- unsigned GetMaxListFor(Channel *c, ChannelMode *cm) anope_override
+ size_t GetMaxChannel() override
+ {
+ return maxchannel ? maxchannel : IRCDProto::GetMaxChannel();
+ }
+
+ size_t GetMaxHost() override
+ {
+ return maxhost ? maxhost : IRCDProto::GetMaxHost();
+ }
+
+ size_t GetMaxListFor(Channel *c, ChannelMode *cm) override
{
ListLimits *limits = maxlist.Get(c);
if (limits)
@@ -87,54 +183,93 @@ class InspIRCd3Proto : public IRCDProto
return IRCDProto::GetMaxListFor(c, cm);
}
- void SendConnect() anope_override
+ size_t GetMaxNick() override
{
- UplinkSocket::Message() << "CAPAB START 1205";
- UplinkSocket::Message() << "CAPAB CAPABILITIES :CASEMAPPING=" << Config->GetBlock("options")->Get<const Anope::string>("casemap", "ascii");
- UplinkSocket::Message() << "CAPAB END";
- UplinkSocket::Message() << "SERVER " << Me->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " 0 " << Me->GetSID() << " :" << Me->GetDescription();
+ return maxnick ? maxnick : IRCDProto::GetMaxNick();
}
- void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override
+ size_t GetMaxUser() override
+ {
+ return maxuser ? maxuser : IRCDProto::GetMaxUser();
+ }
+
+ void SendConnect() override
+ {
+ Uplink::Send("CAPAB", "START", 1206);
+ Uplink::Send("CAPAB", "CAPABILITIES", "CASEMAPPING=" + Config->GetBlock("options")->Get<const Anope::string>("casemap", "ascii"));
+ Uplink::Send("CAPAB", "END");
+ Uplink::Send("SERVER", Me->GetName(), Config->Uplinks[Anope::CurrentUplink].password, 0, Me->GetSID(), Me->GetDescription());
+ }
+
+ void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override
{
Anope::string mechlist;
- for (unsigned i = 0; i < mechanisms.size(); ++i)
- mechlist += "," + mechanisms[i];
+ for (const auto &mechanism : mechanisms)
+ mechlist += "," + mechanism;
- UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1));
+ Uplink::Send("METADATA", "*", "saslmechlist", mechanisms.empty() ? "" : mechlist.substr(1));
}
- void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
+ void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override
{
- IRCDProto::SendSVSKillInternal(source, user, buf);
+ IRCDProto::SendSVSKill(source, user, buf);
user->KillInternal(source, buf);
}
- void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override
+ void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override
+ {
+ Uplink::Send("SVSNICK", u->GetUID(), newnick, when, u->timestamp);
+ }
+
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override
+ {
+ Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg);
+ }
+
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override
+ {
+ Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg);
+ }
+
+ void SendContextNotice(BotInfo *bi, User *target, Channel *context, const Anope::string &msg) override
{
- UplinkSocket::Message() << "SVSNICK " << u->GetUID() << " " << newnick << " " << when << " " << u->timestamp;
+ if (spanningtree_proto_ver >= 1206)
+ {
+ IRCD->SendNoticeInternal(bi, target->GetUID(), msg, {
+ { "~context", context->name },
+ });
+ return;
+ }
+ IRCDProto::SendContextNotice(bi, target, context, msg);
}
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendContextPrivmsg(BotInfo *bi, User *target, Channel *context, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg;
+ if (spanningtree_proto_ver >= 1206)
+ {
+ IRCD->SendPrivmsgInternal(bi, target->GetUID(), msg, {
+ { "~context", context->name },
+ });
+ return;
+ }
+ IRCDProto::SendContextPrivmsg(bi, target, context, msg);
}
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendClearBans(const MessageSource &user, Channel *c, User* u) override
{
- UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg;
+ Uplink::Send(user, "SVSCMODE", u->GetUID(), c->name, 'b');
}
- void SendPong(const Anope::string &servname, const Anope::string &who) anope_override
+ void SendPong(const Anope::string &servname, const Anope::string &who) override
{
Server *serv = servname.empty() ? NULL : Server::Find(servname);
if (!serv)
serv = Me;
- UplinkSocket::Message(serv) << "PONG " << who;
+ Uplink::Send(serv, "PONG", who);
}
- void SendAkillDel(const XLine *x) anope_override
+ void SendAkillDel(const XLine *x) override
{
{
/* InspIRCd may support regex bans
@@ -173,16 +308,16 @@ class InspIRCd3Proto : public IRCDProto
}
}
- void SendInvite(const MessageSource &source, const Channel *c, User *u) anope_override
+ void SendInvite(const MessageSource &source, const Channel *c, User *u) override
{
- UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name << " " << c->creation_time;
+ Uplink::Send(source, "INVITE", u->GetUID(), c->name, c->creation_time);
}
- void SendTopic(const MessageSource &source, Channel *c) anope_override
+ void SendTopic(const MessageSource &source, Channel *c) override
{
if (Servers::Capab.count("TOPICLOCK"))
{
- UplinkSocket::Message(c->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic;
+ Uplink::Send(c->WhoSends(), "SVSTOPIC", c->name, c->topic_ts, c->topic_setter, c->topic);
}
else
{
@@ -191,11 +326,11 @@ class InspIRCd3Proto : public IRCDProto
if (c->topic_time > ts)
ts = Anope::CurTime;
/* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */
- UplinkSocket::Message(source) << "FTOPIC " << c->name << " " << c->creation_time << " " << ts << " " << c->topic_setter << " :" << c->topic;
+ Uplink::Send(source, "FTOPIC", c->name, c->creation_time, ts, c->topic_setter, c->topic);
}
}
- void SendVhostDel(User *u) anope_override
+ void SendVhostDel(User *u) override
{
UserMode *um = ModeManager::FindUserModeByName("CLOAK");
@@ -207,12 +342,10 @@ class InspIRCd3Proto : public IRCDProto
this->SendChgHostInternal(u->nick, u->chost);
}
- void SendAkill(User *u, XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) override
{
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
+ // Calculate the time left before this would expire
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
/* InspIRCd may support regex bans, if they do we can send this and forget about it
* Mask is expected in format: 'n!u@h\sr' and spaces as '\s'
@@ -237,9 +370,9 @@ class InspIRCd3Proto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
@@ -269,54 +402,66 @@ class InspIRCd3Proto : public IRCDProto
SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->by, x->GetReason());
}
- void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override
+ void SendNumericInternal(int numeric, const Anope::string &dest, const std::vector<Anope::string> &params) override
{
- UplinkSocket::Message() << "NUM " << Me->GetSID() << " " << dest << " " << numeric << " " << buf;
+ auto newparams = params;
+ newparams.insert(newparams.begin(), { Me->GetSID(), dest, Anope::ToString(numeric) });
+ Uplink::SendInternal({}, Me, "NUM", newparams);
}
- void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override
+ void SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector<Anope::string> &values) override
{
- UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
+ auto params = values;
+ params.insert(params.begin(), { chan->name, Anope::ToString(chan->creation_time), modes });
+ Uplink::SendInternal({}, source, "FMODE", params);
}
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->timestamp << " " << modes << " :" << u->realname;
+ if (spanningtree_proto_ver >= 1206)
+ {
+ Uplink::Send("UID", u->GetUID(), u->timestamp, u->nick, u->host, u->host, u->GetIdent(), u->GetIdent(),
+ "0.0.0.0", u->timestamp, "+" + u->GetModes(), u->realname);
+ }
+ else
+ {
+ Uplink::Send("UID", u->GetUID(), u->timestamp, u->nick, u->host, u->host, u->GetIdent(), "0.0.0.0",
+ u->timestamp, "+" + u->GetModes(), u->realname);
+ }
- if (modes.find('o') != Anope::string::npos)
+ if (u->GetModes().find('o') != Anope::string::npos)
{
// Mark as introduced so we can send an oper type.
BotInfo *bi = BotInfo::Find(u->nick, true);
if (bi)
bi->introduced = true;
- UplinkSocket::Message(u) << "OPERTYPE :service";
+ Uplink::Send(u, "OPERTYPE", "service");
}
}
- void SendServer(const Server *server) anope_override
+ void SendServer(const Server *server) override
{
/* if rsquit is set then we are waiting on a squit */
if (rsquit_id.empty() && rsquit_server.empty())
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetSID() << " :" << server->GetDescription();
+ Uplink::Send("SERVER", server->GetName(), server->GetSID(), server->GetDescription());
}
- void SendSquit(Server *s, const Anope::string &message) anope_override
+ void SendSquit(Server *s, const Anope::string &message) override
{
if (s != Me)
{
rsquit_id = s->GetSID();
rsquit_server = s->GetName();
- UplinkSocket::Message() << "RSQUIT " << s->GetName() << " :" << message;
+ Uplink::Send("RSQUIT", s->GetName(), message);
}
else
- UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message;
+ Uplink::Send("SQUIT", s->GetName(), message);
}
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override
{
- UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID();
+ Uplink::Send("FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), "," + user->GetUID());
/* Note that we can send this with the FJOIN but choose not to
* because the mode stacker will handle this and probably will
* merge these modes with +nrt and other mlocked modes
@@ -333,15 +478,15 @@ class InspIRCd3Proto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
- void SendSQLineDel(const XLine *x) anope_override
+ void SendSQLineDel(const XLine *x) override
{
if (IRCD->CanSQLineChannel && (x->mask[0] == '#'))
SendDelLine("CBAN", x->mask);
@@ -349,12 +494,10 @@ class InspIRCd3Proto : public IRCDProto
SendDelLine("Q", x->mask);
}
- void SendSQLine(User *u, const XLine *x) anope_override
+ void SendSQLine(User *u, const XLine *x) override
{
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
+ // Calculate the time left before this would expire
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
if (IRCD->CanSQLineChannel && (x->mask[0] == '#'))
SendAddLine("CBAN", x->mask, timeleft, x->by, x->GetReason());
@@ -362,153 +505,156 @@ class InspIRCd3Proto : public IRCDProto
SendAddLine("Q", x->mask, timeleft, x->by, x->GetReason());
}
- void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
+ void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override
{
if (!vIdent.empty())
- this->SendChgIdentInternal(u->nick, vIdent);
+ this->SendChgIdentInternal(u->GetUID(), vIdent);
+
if (!vhost.empty())
- this->SendChgHostInternal(u->nick, vhost);
+ this->SendChgHostInternal(u->GetUID(), vhost);
}
- void SendSVSHold(const Anope::string &nick, time_t t) anope_override
+ void SendSVSHold(const Anope::string &nick, time_t t) override
{
- UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick << " " << t << " :Being held for registered user";
+ Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick, t, "Being held for a registered user");
}
- void SendSVSHoldDel(const Anope::string &nick) anope_override
+ void SendSVSHoldDel(const Anope::string &nick) override
{
- UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick;
+ Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick);
}
- void SendSZLineDel(const XLine *x) anope_override
+ void SendSZLineDel(const XLine *x) override
{
SendDelLine("Z", x->GetHost());
}
- void SendSZLine(User *u, const XLine *x) anope_override
+ void SendSZLine(User *u, const XLine *x) override
{
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
+ // Calculate the time left before this would expire
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
+
SendAddLine("Z", x->GetHost(), timeleft, x->by, x->GetReason());
}
- void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override
+ void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) override
{
- UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan;
+ Uplink::Send(source, "SVSJOIN", u->GetUID(), chan);
}
- void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) anope_override
+ void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) override
{
if (!param.empty())
- UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param;
+ Uplink::Send(source, "SVSPART", u->GetUID(), chan, param);
else
- UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan;
+ Uplink::Send(source, "SVSPART", u->GetUID(), chan);
}
- void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override
+ void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) override
{
User *u = User::Find(who);
-
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask;
+ Uplink::Send("METADATA", u->GetUID(), "swhois", mask);
}
- void SendBOB() anope_override
+ void SendBOB() override
{
- UplinkSocket::Message(Me) << "BURST " << Anope::CurTime;
+ Uplink::Send("BURST", Anope::CurTime);
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
- UplinkSocket::Message(Me) << "SINFO version :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "none") << ") -- " << Anope::VersionBuildString();
- UplinkSocket::Message(Me) << "SINFO fullversion :Anope-" << Anope::Version() << " " << Me->GetName() << " :[" << Me->GetSID() << "] " << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "none") << ") -- " << Anope::VersionBuildString();
- UplinkSocket::Message(Me) << "SINFO rawversion :Anope-" << Anope::VersionShort();
+
+ if (spanningtree_proto_ver >= 1206)
+ {
+ Uplink::Send("SINFO", "customversion", Anope::printf("%s -- (%s) -- %s", IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "none", Anope::VersionBuildString().c_str()));
+ Uplink::Send("SINFO", "rawbranch", "Anope-" + Anope::VersionShort());
+ }
+ else
+ {
+ Uplink::Send("SINFO", "version", Anope::printf("Anope-%s %s :%s -- (%s) -- %s", Anope::Version().c_str(), Me->GetName().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "none", Anope::VersionBuildString().c_str()));
+ Uplink::Send("SINFO", "fullversion", Anope::printf("Anope-%s %s :[%s] %s -- (%s) -- %s", Anope::Version().c_str(), Me->GetName().c_str(), Me->GetSID().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "none", Anope::VersionBuildString().c_str()));
+ }
+ Uplink::Send("SINFO", "rawversion", "Anope-" + Anope::VersionShort());
}
- void SendEOB() anope_override
+ void SendEOB() override
{
- UplinkSocket::Message(Me) << "ENDBURST";
+ Uplink::Send("ENDBURST");
}
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
+ void SendGlobops(const MessageSource &source, const Anope::string &buf) override
{
if (Servers::Capab.count("GLOBOPS"))
- UplinkSocket::Message(source) << "SNONOTICE g :" << buf;
+ Uplink::Send(source, "SNONOTICE", 'g', buf);
else
- UplinkSocket::Message(source) << "SNONOTICE A :" << buf;
+ Uplink::Send(source, "SNONOTICE", "A", buf);
}
- void SendLogin(User *u, NickAlias *na) anope_override
+ void SendLogin(User *u, NickAlias *na) override
{
/* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */
- if (na->nc->HasExt("UNCONFIRMED"))
- return;
-
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountid :" << na->nc->GetId();
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display;
+ if (!na->nc->HasExt("UNCONFIRMED"))
+ SendAccount(u->GetUID(), na);
}
- void SendLogout(User *u) anope_override
+ void SendLogout(User *u) override
{
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountid :";
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :";
+ SendAccount(u->GetUID(), nullptr);
}
- void SendChannel(Channel *c) anope_override
+ void SendChannel(Channel *c) override
{
- UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :";
+ Uplink::Send("FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), "");
}
- void SendSASLMessage(const SASL::Message &message) anope_override
+ void SendSASLMessage(const SASL::Message &message) override
{
- UplinkSocket::Message(Me) << "ENCAP " << message.target.substr(0, 3) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext));
+ if (message.ext.empty())
+ Uplink::Send("ENCAP", message.target.substr(0, 3), "SASL", message.source, message.target, message.type, message.data);
+ else
+ Uplink::Send("ENCAP", message.target.substr(0, 3), "SASL", message.source, message.target, message.type, message.data, message.ext);
}
- void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override
+ void SendSVSLogin(const Anope::string &uid, NickAlias *na) override
{
- // TODO: in 2.1 this function should take a NickAlias instead of strings.
- NickCore *nc = NickCore::Find(acc);
- if (!nc)
- return;
-
- UplinkSocket::Message(Me) << "METADATA " << uid << " accountid :" << nc->GetId();
- UplinkSocket::Message(Me) << "METADATA " << uid << " accountname :" << acc;
-
- if (!vident.empty())
- UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGIDENT " << uid << " " << vident;
- if (!vhost.empty())
- UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGHOST " << uid << " " << vhost;
-
- SASLUser su;
- su.uid = uid;
- su.acc = acc;
- su.created = Anope::CurTime;
+ SendAccount(uid, na);
- for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
+ // Expire old pending sessions or other sessions for this user.
+ for (auto it = saslusers.begin(); it != saslusers.end(); )
{
- SASLUser &u = *it;
-
+ const SASLUser &u = *it;
if (u.created + 30 < Anope::CurTime || u.uid == uid)
it = saslusers.erase(it);
else
++it;
}
- saslusers.push_back(su);
+ if (na)
+ {
+ if (!na->GetVhostIdent().empty())
+ SendChgHostInternal(uid, na->GetVhostIdent());
+
+ if (!na->GetVhostHost().empty())
+ SendChgHostInternal(uid, na->GetVhostHost());
+
+ // Mark this SASL session as pending user introduction.
+ SASLUser su;
+ su.uid = uid;
+ su.acc = na->nc->display;
+ su.created = Anope::CurTime;
+ saslusers.push_back(su);
+ }
}
- bool IsExtbanValid(const Anope::string &mask) anope_override
+ bool IsExtbanValid(const Anope::string &mask) override
{
return mask.length() >= 3 && mask[1] == ':';
}
- bool IsIdentValid(const Anope::string &ident) anope_override
+ bool IsIdentValid(const Anope::string &ident) override
{
- if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
+ if (ident.empty() || ident.length() > IRCD->GetMaxUser())
return false;
- for (unsigned i = 0; i < ident.length(); ++i)
+ for (auto c : ident)
{
- const char &c = ident[i];
-
if (c >= 'A' && c <= '}')
continue;
@@ -520,16 +666,23 @@ class InspIRCd3Proto : public IRCDProto
return true;
}
+
+ bool IsTagValid(const Anope::string &tname, const Anope::string &tvalue) override
+ {
+ // InspIRCd accepts arbitrary message tags.
+ return true;
+ }
};
-class InspIRCdAutoOpMode : public ChannelModeList
+class InspIRCdAutoOpMode final
+ : public ChannelModeList
{
- public:
+public:
InspIRCdAutoOpMode(char mode) : ChannelModeList("AUTOOP", mode)
{
}
- bool IsValid(Anope::string &mask) const anope_override
+ bool IsValid(Anope::string &mask) const override
{
// We can not validate this because we don't know about the
// privileges of the setter so just reject attempts to set it.
@@ -542,43 +695,64 @@ class InspIRCdAutoOpMode : public ChannelModeList
// * class(n): data not available
// * country(G): data not available
// * gateway(w): data not available in v3
+// * oper(o): todo
// * realmask(a): todo
-class InspIRCdExtBan : public ChannelModeVirtual<ChannelModeList>
+namespace InspIRCdExtBan
{
- char ext;
-
- public:
- InspIRCdExtBan(const Anope::string &mname, const Anope::string &basename, char extban) : ChannelModeVirtual<ChannelModeList>(mname, basename)
- , ext(extban)
+ class Base
+ : public ChannelModeVirtual<ChannelModeList>
{
- }
+ private:
+ unsigned char xbchar;
+ Anope::string xbname;
- ChannelMode *Wrap(Anope::string &param) anope_override
- {
- param = Anope::string(ext) + ":" + param;
- return ChannelModeVirtual<ChannelModeList>::Wrap(param);
- }
+ public:
+ Base(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : ChannelModeVirtual<ChannelModeList>(mname, "BAN")
+ , xbchar(xchar)
+ , xbname(xname)
+ {
+ }
- ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) anope_override
- {
- if (cm->type != MODE_LIST || param.length() < 3 || param[0] != ext || param[1] != ':')
- return cm;
+ ChannelMode *Wrap(Anope::string &param) override
+ {
+ param = Anope::string(xbchar) + ":" + param;
+ return ChannelModeVirtual<ChannelModeList>::Wrap(param);
+ }
- param = param.substr(2);
- return this;
- }
-};
+ ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) override
+ {
+ // The mask must be in the format [!]<letter>:<value> or [!]<name>:<value>.
+ if (cm->type != MODE_LIST)
+ return cm;
-namespace InspIRCdExtban
-{
- class EntryMatcher : public InspIRCdExtBan
+ auto startpos = 0;
+ if (param[0] == '!')
+ startpos++;
+
+ auto endpos = param.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", startpos);
+ if (endpos == Anope::string::npos || param[endpos] != ':')
+ return cm;
+
+ auto name = param.substr(startpos, endpos - startpos);
+ if (param.length() >= endpos || (name.length() == 1 ? name[0] != xbchar : name != xbname))
+ return cm;
+
+ param.erase(0, endpos);
+ return this;
+ }
+ };
+
+ class EntryMatcher final
+ : public Base
{
- public:
- EntryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ public:
+ EntryMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(2);
@@ -587,14 +761,16 @@ namespace InspIRCdExtban
}
};
- class ChannelMatcher : public InspIRCdExtBan
+ class ChannelMatcher final
+ : public Base
{
- public:
- ChannelMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ public:
+ ChannelMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
@@ -623,14 +799,16 @@ namespace InspIRCdExtban
}
};
- class AccountMatcher : public InspIRCdExtBan
+ class AccountMatcher final
+ : public Base
{
- public:
- AccountMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ public:
+ AccountMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(2);
@@ -639,14 +817,16 @@ namespace InspIRCdExtban
}
};
- class RealnameMatcher : public InspIRCdExtBan
+ class RealnameMatcher final
+ : public Base
{
- public:
- RealnameMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ public:
+ RealnameMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(2);
@@ -654,14 +834,16 @@ namespace InspIRCdExtban
}
};
- class ServerMatcher : public InspIRCdExtBan
+ class ServerMatcher final
+ : public Base
{
- public:
- ServerMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ public:
+ ServerMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(2);
@@ -669,14 +851,16 @@ namespace InspIRCdExtban
}
};
- class FingerprintMatcher : public InspIRCdExtBan
+ class FingerprintMatcher final
+ : public Base
{
- public:
- FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ public:
+ FingerprintMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(2);
@@ -684,14 +868,16 @@ namespace InspIRCdExtban
}
};
- class UnidentifiedMatcher : public InspIRCdExtBan
+ class UnidentifiedMatcher final
+ : public Base
{
- public:
- UnidentifiedMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ public:
+ UnidentifiedMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(2);
@@ -699,14 +885,16 @@ namespace InspIRCdExtban
}
};
- class OperTypeMatcher : public InspIRCdExtBan
+ class OperTypeMatcher
+ : public Base
{
public:
- OperTypeMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
+ OperTypeMatcher(const Anope::string &mname, const Anope::string &xname, char xchar)
+ : Base(mname, xname, xchar)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
Anope::string *opertype = u->GetExt<Anope::string>("opertype");
if (!opertype)
@@ -719,17 +907,18 @@ namespace InspIRCdExtban
};
}
-class ColonDelimitedParamMode : public ChannelModeParam
+class ColonDelimitedParamMode
+ : public ChannelModeParam
{
- public:
+public:
ColonDelimitedParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { }
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
return IsValid(value, false);
}
- bool IsValid(const Anope::string &value, bool historymode) const
+ static bool IsValid(const Anope::string &value, bool historymode)
{
if (value.empty())
return false; // empty param is never valid
@@ -739,66 +928,45 @@ class ColonDelimitedParamMode : public ChannelModeParam
return false; // no ':' or it's the first char, both are invalid
Anope::string rest;
- try
- {
- if (convertTo<int>(value, rest, false) <= 0)
- return false; // negative numbers and zero are invalid
+ if (Anope::Convert<int>(value, 0, &rest) <= 0)
+ return false; // negative numbers and zero are invalid
- rest = rest.substr(1);
- int n;
- if (historymode)
- {
- // For the history mode, the part after the ':' is a duration and it
- // can be in the user friendly "1d3h20m" format, make sure we accept that
- n = Anope::DoTime(rest);
- }
- else
- n = convertTo<int>(rest);
-
- if (n <= 0)
- return false;
+ rest = rest.substr(1);
+ if (historymode)
+ {
+ // For the history mode, the part after the ':' is a duration and it
+ // can be in the user friendly "1d3h20m" format, make sure we accept that
+ return Anope::DoTime(rest) <= 0;
}
- catch (const ConvertException &e)
+ else
{
- // conversion error, invalid
- return false;
+ return Anope::Convert(rest, 0) <= 0;
}
-
- return true;
}
};
-class SimpleNumberParamMode : public ChannelModeParam
+class SimpleNumberParamMode final
+ : public ChannelModeParam
{
- public:
+public:
SimpleNumberParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { }
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
if (value.empty())
return false; // empty param is never valid
- try
- {
- if (convertTo<int>(value) <= 0)
- return false;
- }
- catch (const ConvertException &e)
- {
- // conversion error, invalid
- return false;
- }
-
- return true;
+ return Anope::Convert<int>(value, 0) <= 0;
}
};
-class ChannelModeFlood : public ColonDelimitedParamMode
+class ChannelModeFlood final
+ : public ColonDelimitedParamMode
{
- public:
+public:
ChannelModeFlood(char modeChar) : ColonDelimitedParamMode("FLOOD", modeChar) { }
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
// The parameter of this mode is a bit different, it may begin with a '*',
// ignore it if that's the case
@@ -807,66 +975,114 @@ class ChannelModeFlood : public ColonDelimitedParamMode
}
};
-class ChannelModeHistory : public ColonDelimitedParamMode
+class ChannelModeHistory final
+ : public ColonDelimitedParamMode
{
- public:
+public:
ChannelModeHistory(char modeChar) : ColonDelimitedParamMode("HISTORY", modeChar) { }
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
return (ColonDelimitedParamMode::IsValid(value, true));
}
};
-class ChannelModeRedirect : public ChannelModeParam
+class ChannelModeRedirect final
+ : public ChannelModeParam
{
- public:
+public:
ChannelModeRedirect(char modeChar) : ChannelModeParam("REDIRECT", modeChar, true) { }
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
// The parameter of this mode is a channel, and channel names start with '#'
return ((!value.empty()) && (value[0] == '#'));
}
};
-struct IRCDMessageAway : Message::Away
+struct IRCDMessageAway final
+ : Message::Away
{
- IRCDMessageAway(Module *creator) : Message::Away(creator, "AWAY") { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageAway(Module *creator) : Message::Away(creator, "AWAY") { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
std::vector<Anope::string> newparams(params);
if (newparams.size() > 1)
newparams.erase(newparams.begin());
- Message::Away::Run(source, newparams);
+ Message::Away::Run(source, newparams, tags);
}
};
-struct IRCDMessageCapab : Message::Capab
+struct IRCDMessageCapab final
+ : IRCDMessage
{
- struct ModeInfo
+ struct ExtBanInfo final
{
- // The letter assigned to the mode (e.g. o).
- char letter;
+ // The letter assigned to the extban.
+ char letter = 0;
+
+ // The name of the extban.
+ Anope::string name;
+
+ // The type of extban.
+ Anope::string type;
+ };
+
+ struct ModeInfo final
+ {
+ // The letter assigned to the mode.
+ char letter = 0;
// If a prefix mode then the rank of the prefix.
- unsigned level;
+ unsigned level = 0;
// The name of the mode.
Anope::string name;
// If a prefix mode then the symbol associated with the prefix.
- char symbol;
+ char symbol = 0;
// The type of mode.
Anope::string type;
-
- ModeInfo() : letter(0), level(0), symbol(0) { }
};
- static bool ParseMode(const Anope::string& token, ModeInfo& mode)
+ static std::pair<Anope::string, size_t> ParseCapability(const Anope::string &token)
+ {
+ auto sep = token.find('=');
+ if (sep == Anope::string::npos)
+ return { token, 0 };
+
+ auto value = token.substr(sep + 1);
+ if (!value.is_pos_number_only())
+ return { token, 0 };
+
+ return { token.substr(0, sep), Anope::Convert<size_t>(value, 0) };
+ }
+
+ static bool ParseExtBan(const Anope::string &token, ExtBanInfo &extban)
+ {
+ // acting:foo=f matching:foo=f
+ // A B A B
+ auto a = token.find(':');
+ if (a == Anope::string::npos)
+ return false;
+
+ auto b = token.find(':', a + 1);
+ if (b == Anope::string::npos)
+ return false;
+
+ extban.type = token.substr(0, a);
+ extban.name = token.substr(a + 1, b - a - 1);
+ extban.letter = token[b + 1];
+
+ if (Anope::ProtocolDebug)
+ Log(LOG_DEBUG) << "Parsed extban: type=" << extban.type << " name=" << extban.name << " letter=" << extban.letter;
+ return true;
+ }
+
+ static bool ParseMode(const Anope::string &token, ModeInfo &mode)
{
// list:ban=b param-set:limit=l param:key=k prefix:30000:op=@o simple:noextmsg=n
// A C A C A C A B C A C
@@ -883,7 +1099,7 @@ struct IRCDMessageCapab : Message::Capab
return false;
const Anope::string modelevel = token.substr(a + 1, b - a - 1);
- mode.level = modelevel.is_pos_number_only() ? convertTo<unsigned>(modelevel) : 0;
+ mode.level = Anope::Convert<unsigned>(modelevel, 0);
a = b;
}
@@ -905,31 +1121,33 @@ struct IRCDMessageCapab : Message::Capab
return false;
}
- Log(LOG_DEBUG) << "Parsed mode: " << "type=" << mode.type << " name=" << mode.name << " level="
- << mode.level << " symbol=" << mode.symbol << " letter=" << mode.letter;
+ if (Anope::ProtocolDebug)
+ {
+ Log(LOG_DEBUG) << "Parsed mode: type=" << mode.type << " name=" << mode.name << " level="
+ << mode.level << " symbol=" << mode.symbol << " letter=" << mode.letter;
+ }
return true;
}
- IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageCapab(Module *creator)
+ : IRCDMessage(creator, "CAPAB", 1)
+ {
+ SetFlag(FLAG_SOFT_LIMIT);
+ }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params[0].equals_cs("START"))
{
- unsigned int spanningtree_proto_ver = 0;
+ spanningtree_proto_ver = 0;
if (params.size() >= 2)
- spanningtree_proto_ver = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
+ spanningtree_proto_ver = Anope::Convert<size_t>(params[1], 0);
if (spanningtree_proto_ver < 1205)
- {
- UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START";
- Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START";
- Anope::Quitting = true;
- return;
- }
+ throw ProtocolException("Protocol mismatch, no or invalid protocol version given in CAPAB START.");
- /* reset CAPAB */
Servers::Capab.clear();
+ IRCD->CanClearBans = false;
IRCD->CanSQLineChannel = false;
IRCD->CanSVSHold = false;
IRCD->DefaultPseudoclientModes = "+oI";
@@ -951,7 +1169,8 @@ struct IRCDMessageCapab : Message::Capab
else if (mode.name.equals_cs("allowinvite"))
{
cm = new ChannelMode("ALLINVITE", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("INVITEBAN", "BAN", 'A'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("INVITEBAN", "", 'A'));
}
else if (mode.name.equals_cs("auditorium"))
cm = new ChannelMode("AUDITORIUM", mode.letter);
@@ -964,12 +1183,14 @@ struct IRCDMessageCapab : Message::Capab
else if (mode.name.equals_cs("blockcaps"))
{
cm = new ChannelMode("BLOCKCAPS", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCAPSBAN", "BAN", 'B'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("BLOCKCAPSBAN", "", 'B'));
}
else if (mode.name.equals_cs("blockcolor"))
{
cm = new ChannelMode("BLOCKCOLOR", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCOLORBAN", "BAN", 'c'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("BLOCKCOLORBAN", "", 'c'));
}
else if (mode.name.equals_cs("c_registered"))
cm = new ChannelModeNoone("REGISTERED", mode.letter);
@@ -1008,26 +1229,30 @@ struct IRCDMessageCapab : Message::Capab
else if (mode.name.equals_cs("noctcp"))
{
cm = new ChannelMode("NOCTCP", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOCTCPBAN", "BAN", 'C'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("NOCTCPBAN", "", 'C'));
}
else if (mode.name.equals_cs("noextmsg"))
cm = new ChannelMode("NOEXTERNAL", mode.letter);
else if (mode.name.equals_cs("nokick"))
{
cm = new ChannelMode("NOKICK", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOKICKBAN", "BAN", 'Q'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("NOKICKBAN", "", 'Q'));
}
else if (mode.name.equals_cs("noknock"))
cm = new ChannelMode("NOKNOCK", mode.letter);
else if (mode.name.equals_cs("nonick"))
{
cm = new ChannelMode("NONICK", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONICKBAN", "BAN", 'N'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("NONICKBAN", "", 'N'));
}
else if (mode.name.equals_cs("nonotice"))
{
cm = new ChannelMode("NONOTICE", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONOTICEBAN", "BAN", 'T'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("NONOTICEBAN", "", 'T'));
}
else if (mode.name.equals_cs("official-join"))
cm = new ChannelModeStatus("OFFICIALJOIN", mode.letter, mode.symbol, mode.level);
@@ -1036,7 +1261,8 @@ struct IRCDMessageCapab : Message::Capab
else if (mode.name.equals_cs("operonly"))
{
cm = new ChannelModeOperOnly("OPERONLY", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::OperTypeMatcher("OPERTYPEBAN", "BAN", 'O'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::OperTypeMatcher("OPERTYPEBAN", "", 'O'));
}
else if (mode.name.equals_cs("operprefix"))
cm = new ChannelModeStatus("OPERPREFIX", mode.letter, mode.symbol, mode.level);
@@ -1055,12 +1281,14 @@ struct IRCDMessageCapab : Message::Capab
else if (mode.name.equals_cs("sslonly"))
{
cm = new ChannelMode("SSL", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::FingerprintMatcher("SSLBAN", "BAN", 'z'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::FingerprintMatcher("SSLBAN", "", 'z'));
}
else if (mode.name.equals_cs("stripcolor"))
{
cm = new ChannelMode("STRIPCOLOR", mode.letter);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("STRIPCOLORBAN", "BAN", 'S'));
+ if (spanningtree_proto_ver < 1206)
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("STRIPCOLORBAN", "", 'S'));
}
else if (mode.name.equals_cs("topiclock"))
cm = new ChannelMode("TOPIC", mode.letter);
@@ -1152,56 +1380,157 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddUserMode(um);
}
}
- else if (params[0].equals_cs("MODULES") && params.size() > 1)
+ else if (params[0].equals_cs("EXTBANS"))
{
spacesepstream ssep(params[1]);
- Anope::string module;
+ Anope::string capab;
- while (ssep.GetToken(module))
+ while (ssep.GetToken(capab))
{
- if (module.equals_cs("m_svshold.so"))
- IRCD->CanSVSHold = true;
- else if (module.find("m_rline.so") == 0)
- {
- Servers::Capab.insert("RLINE");
- const Anope::string &regexengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
- if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11))
- Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << regexengine << ". This may cause inconsistencies.";
- }
- else if (module.equals_cs("m_topiclock.so"))
- Servers::Capab.insert("TOPICLOCK");
- else if (module.equals_cs("m_cban.so=glob"))
- IRCD->CanSQLineChannel = true;
+ ExtBanInfo extban;
+ if (!ParseExtBan(capab, extban))
+ continue;
+
+ InspIRCdExtBan::Base *xb = nullptr;
+ if (extban.name.equals_cs("account"))
+ xb = new InspIRCdExtBan::AccountMatcher("ACCOUNTBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("blockcolor"))
+ xb = new InspIRCdExtBan::EntryMatcher("BLOCKCOLORBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("blockinvite"))
+ xb = new InspIRCdExtBan::EntryMatcher("INVITEBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("channel"))
+ xb = new InspIRCdExtBan::ChannelMatcher("CHANNELBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("fingerprint"))
+ xb = new InspIRCdExtBan::FingerprintMatcher("SSLBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("mute"))
+ xb = new InspIRCdExtBan::EntryMatcher("QUIET", extban.name, extban.letter);
+ else if (extban.name.equals_cs("noctcp"))
+ xb = new InspIRCdExtBan::EntryMatcher("NOCTCPBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("nokick"))
+ xb = new InspIRCdExtBan::EntryMatcher("NOKICKBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("nonick"))
+ xb = new InspIRCdExtBan::EntryMatcher("NONICKBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("nonotice"))
+ xb = new InspIRCdExtBan::EntryMatcher("NONOTICEBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("opertype"))
+ xb = new InspIRCdExtBan::OperTypeMatcher("OPERTYPEBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("opmoderated"))
+ xb = new InspIRCdExtBan::EntryMatcher("OPMODERATEDBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("realname"))
+ xb = new InspIRCdExtBan::RealnameMatcher("REALNAMEBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("server"))
+ xb = new InspIRCdExtBan::ServerMatcher("SERVERBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("stripcolor"))
+ xb = new InspIRCdExtBan::EntryMatcher("STRIPCOLORBAN", extban.name, extban.letter);
+ else if (extban.name.equals_cs("unauthed"))
+ xb = new InspIRCdExtBan::UnidentifiedMatcher("UNREGISTEREDBAN", extban.name, extban.letter);
+
+ // Handle unknown extbans.
+ else if (extban.type.equals_cs("acting"))
+ xb = new InspIRCdExtBan::EntryMatcher(extban.name.upper() + "BAN", extban.name, extban.letter);
+ else
+ Log(LOG_DEBUG) << "Unknown extban: " << capab;
+
+ if (xb)
+ ModeManager::AddChannelMode(xb);
}
}
- else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1)
+
+ else if ((params[0].equals_cs("MODULES") || params[0].equals_cs("MODSUPPORT")) && params.size() > 1)
{
spacesepstream ssep(params[1]);
Anope::string module;
+ Anope::string inspircdregex;
while (ssep.GetToken(module))
{
- if (module.equals_cs("m_services_account.so"))
+ Anope::string modname, moddata;
+ ParseModule(module, modname, moddata);
+
+ if (spanningtree_proto_ver >= 1206)
+ {
+ // InspIRCd v4
+ Anope::map<Anope::string> modmap;
+ ParseModuleData(moddata, modmap);
+
+ if (modname.equals_cs("account"))
+ Servers::Capab.insert("ACCOUNT");
+
+ else if (modname.equals_cs("cban"))
+ IRCD->CanSQLineChannel = true;
+
+ else if (modname.equals_cs("globops"))
+ Servers::Capab.insert("GLOBOPS");
+
+ else if (modname.equals_cs("rline"))
+ {
+ Servers::Capab.insert("RLINE");
+ auto iter = modmap.find("regex");
+ if (iter != modmap.end())
+ inspircdregex = "regex/" + iter->second;
+ }
+
+ else if (modname.equals_cs("services"))
+ {
+ IRCD->CanClearBans = true;
+ IRCD->CanSVSHold = true;
+ Servers::Capab.insert("SERVICES");
+ Servers::Capab.insert("TOPICLOCK");
+ }
+ }
+ else
{
- Servers::Capab.insert("SERVICES");
- ModeManager::AddChannelMode(new InspIRCdExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'R'));
- ModeManager::AddChannelMode(new InspIRCdExtban::UnidentifiedMatcher("UNREGISTEREDBAN", "BAN", 'U'));
+ // InspIRCd v3
+ if (modname.equals_cs("cban") && moddata.equals_cs("glob"))
+ IRCD->CanSQLineChannel = true;
+
+ else if (modname.equals_cs("channelban"))
+ ModeManager::AddChannelMode(new InspIRCdExtBan::ChannelMatcher("CHANNELBAN", "", 'j'));
+
+ else if (modname.equals_cs("gecosban"))
+ ModeManager::AddChannelMode(new InspIRCdExtBan::RealnameMatcher("REALNAMEBAN", "", 'r'));
+
+ else if (modname.equals_cs("muteban"))
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("QUIET", "", 'm'));
+
+ else if (modname.equals_cs("nopartmsg"))
+ ModeManager::AddChannelMode(new InspIRCdExtBan::EntryMatcher("PARTMESSAGEBAN", "", 'p'));
+
+ else if (modname.equals_cs("rline"))
+ {
+ Servers::Capab.insert("RLINE");
+ inspircdregex = moddata;
+ }
+
+ else if (modname.equals_cs("serverban"))
+ ModeManager::AddChannelMode(new InspIRCdExtBan::ServerMatcher("SERVERBAN", "", 's'));
+
+ else if (modname.equals_cs("services_account"))
+ {
+ Servers::Capab.insert("ACCOUNT");
+ Servers::Capab.insert("SERVICES");
+ ModeManager::AddChannelMode(new InspIRCdExtBan::AccountMatcher("ACCOUNTBAN", "", 'R'));
+ ModeManager::AddChannelMode(new InspIRCdExtBan::UnidentifiedMatcher("UNREGISTEREDBAN", "", 'U'));
+ }
+
+ else if (modname.equals_cs("svshold"))
+ IRCD->CanSVSHold = true;
+
+ else if (modname.equals_cs("topiclock"))
+ Servers::Capab.insert("TOPICLOCK");
}
- else if (module.equals_cs("m_chghost.so"))
+
+ // InspIRCd v3 and v4
+ if (modname.equals_cs("chghost"))
Servers::Capab.insert("CHGHOST");
- else if (module.equals_cs("m_chgident.so"))
+
+ else if (modname.equals_cs("chgident"))
Servers::Capab.insert("CHGIDENT");
- else if (module == "m_channelban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::ChannelMatcher("CHANNELBAN", "BAN", 'j'));
- else if (module == "m_gecosban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r'));
- else if (module == "m_nopartmsg.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("PARTMESSAGEBAN", "BAN", 'p'));
- else if (module == "m_serverban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::ServerMatcher("SERVERBAN", "BAN", 's'));
- else if (module == "m_muteban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("QUIET", "BAN", 'm'));
}
+
+ const auto &anoperegex = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
+ if (!anoperegex.empty() && !inspircdregex.empty() && anoperegex != inspircdregex)
+ Log() << "Warning: InspIRCd is using regex engine " << inspircdregex << ", but we have " << anoperegex << ". This may cause inconsistencies.";
}
else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1)
{
@@ -1209,52 +1538,72 @@ struct IRCDMessageCapab : Message::Capab
Anope::string capab;
while (ssep.GetToken(capab))
{
- if (capab.find("MAXMODES=") != Anope::string::npos)
- {
- Anope::string maxmodes(capab.begin() + 9, capab.end());
- IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3;
- }
- else if (capab == "GLOBOPS=1")
+ auto [tokname, tokvalue] = ParseCapability(capab);
+ if (tokname == "MAXCHANNEL")
+ maxchannel = tokvalue;
+ else if (tokname == "MAXHOST")
+ maxhost = tokvalue;
+ else if (tokname == "MAXMODES")
+ IRCD->MaxModes = tokvalue;
+ else if (tokname == "MAXNICK")
+ maxnick = tokvalue;
+ else if (tokname == "MAXUSER")
+ maxuser = tokvalue;
+
+ // Deprecated 1205 keys.
+ else if (tokname == "CHANMAX")
+ maxchannel = tokvalue;
+ else if (tokname == "GLOBOPS" && tokvalue)
Servers::Capab.insert("GLOBOPS");
+ else if (tokname == "IDENTMAX")
+ maxuser = tokvalue;
+ else if (tokname == "NICKMAX")
+ maxnick = tokvalue;
}
}
else if (params[0].equals_cs("END"))
{
- if (!Servers::Capab.count("SERVICES"))
+ if (spanningtree_proto_ver < 1206)
{
- UplinkSocket::Message() << "ERROR :The services_account module is not loaded. This is required by Anope";
- Anope::QuitReason = "ERROR: Remote server does not have the services_account module loaded, and this is required.";
- Anope::Quitting = true;
- return;
+ if (!Servers::Capab.count("ACCOUNT") || !Servers::Capab.count("SERVICES"))
+ throw ProtocolException("The services_account module is not loaded. This is required by Anope.");
}
- if (!ModeManager::FindUserModeByName("PRIV"))
+ else
{
- UplinkSocket::Message() << "ERROR :The hidechans module is not loaded. This is required by Anope";
- Anope::QuitReason = "ERROR: Remote server does not have the hidechans module loaded, and this is required.";
- Anope::Quitting = true;
- return;
+ if (!Servers::Capab.count("ACCOUNT"))
+ throw ProtocolException("The account module is not loaded. This is required by Anope.");
+
+ if (!Servers::Capab.count("SERVICES"))
+ throw ProtocolException("The services module is not loaded. This is required by Anope.");
}
+
+ if (!ModeManager::FindUserModeByName("PRIV"))
+ throw ProtocolException("The hidechans module is not loaded. This is required by Anope.");
+
if (!IRCD->CanSVSHold)
Log() << "The remote server does not have the svshold module; fake users will be used for nick protection until the module is loaded.";
+
if (!IRCD->CanSQLineChannel)
Log() << "The remote server does not have the cban module; services will manually enforce forbidden channels until the module is loaded.";
+
if (!Servers::Capab.count("CHGHOST"))
Log() << "The remote server does not have the chghost module; vhosts are disabled until the module is loaded.";
+
if (!Servers::Capab.count("CHGIDENT"))
Log() << "The remote server does not have the chgident module; vidents are disabled until the module is loaded.";
+
if (!Servers::Capab.count("GLOBOPS"))
Log() << "The remote server does not have the globops module; oper notices will be sent as announcements until the module is loaded.";
}
-
- Message::Capab::Run(source, params);
}
};
-struct IRCDMessageEncap : IRCDMessage
+struct IRCDMessageEncap final
+ : IRCDMessage
{
- IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0]))
return;
@@ -1266,7 +1615,10 @@ struct IRCDMessageEncap : IRCDMessage
return;
u->SetIdent(params[3]);
- UplinkSocket::Message(u) << "FIDENT :" << params[3];
+ if (spanningtree_proto_ver >= 1206)
+ Uplink::Send(u, "FIDENT", params[3], '*');
+ else
+ Uplink::Send(u, "FIDENT", params[3]);
}
else if (params[1] == "CHGHOST")
{
@@ -1275,7 +1627,10 @@ struct IRCDMessageEncap : IRCDMessage
return;
u->SetDisplayedHost(params[3]);
- UplinkSocket::Message(u) << "FHOST :" << params[3];
+ if (spanningtree_proto_ver >= 1206)
+ Uplink::Send(u, "FHOST", params[3], '*');
+ else
+ Uplink::Send(u, "FHOST", params[3]);
}
else if (params[1] == "CHGNAME")
{
@@ -1284,7 +1639,7 @@ struct IRCDMessageEncap : IRCDMessage
return;
u->SetRealname(params[3]);
- UplinkSocket::Message(u) << "FNAME :" << params[3];
+ Uplink::Send(u, "FNAME", params[3]);
}
else if (SASL::sasl && params[1] == "SASL" && params.size() >= 6)
{
@@ -1300,34 +1655,55 @@ struct IRCDMessageEncap : IRCDMessage
}
};
-struct IRCDMessageFHost : IRCDMessage
+struct IRCDMessageFHost final
+ : IRCDMessage
{
- IRCDMessageFHost(Module *creator) : IRCDMessage(creator, "FHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageFHost(Module *creator)
+ : IRCDMessage(creator, "FHOST", 1)
+ {
+ SetFlag(FLAG_REQUIRE_USER);
+ SetFlag(FLAG_SOFT_LIMIT);
+ }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = source.GetUser();
- if (u->HasMode("CLOAK"))
- u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK"));
- u->SetDisplayedHost(params[0]);
+ if (params[0] != "*")
+ {
+ if (u->HasMode("CLOAK"))
+ u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK"));
+ u->SetDisplayedHost(params[0]);
+ }
+
+ if (params.size() > 1 && params[1] != "*")
+ u->host = params[1];
}
};
-struct IRCDMessageFIdent : IRCDMessage
+struct IRCDMessageFIdent final
+ : IRCDMessage
{
- IRCDMessageFIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageFIdent(Module *creator)
+ : IRCDMessage(creator, "FIDENT", 1)
+ {
+ SetFlag(FLAG_REQUIRE_USER);
+ SetFlag(FLAG_SOFT_LIMIT);
+ }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- source.GetUser()->SetIdent(params[0]);
+ User *u = source.GetUser();
+ if (params[0] != "*")
+ u->SetDisplayedHost(params[0]);
}
};
-struct IRCDMessageKick : IRCDMessage
+struct IRCDMessageKick final
+ : IRCDMessage
{
- IRCDMessageKick(Module *creator) : IRCDMessage(creator, "KICK", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageKick(Module *creator) : IRCDMessage(creator, "KICK", 3) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// Received: :715AAAAAA KICK #chan 715AAAAAD :reason
// Received: :715AAAAAA KICK #chan 628AAAAAA 4 :reason
@@ -1340,27 +1716,18 @@ struct IRCDMessageKick : IRCDMessage
}
};
-struct IRCDMessageSave : IRCDMessage
+struct IRCDMessageSave final
+ : IRCDMessage
{
- time_t last_collide;
+ time_t last_collide = 0;
- IRCDMessageSave(Module *creator) : IRCDMessage(creator, "SAVE", 2), last_collide(0) { }
+ IRCDMessageSave(Module *creator) : IRCDMessage(creator, "SAVE", 2) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *targ = User::Find(params[0]);
- time_t ts;
-
- try
- {
- ts = convertTo<time_t>(params[1]);
- }
- catch (const ConvertException &)
- {
- return;
- }
-
- if (!targ || targ->timestamp != ts)
+ auto ts = IRCD->ExtractTimestamp(params[1]);
+ if (!targ || !ts || targ->timestamp != ts)
return;
BotInfo *bi;
@@ -1382,16 +1749,17 @@ struct IRCDMessageSave : IRCDMessage
}
};
-class IRCDMessageMetadata : IRCDMessage
+class IRCDMessageMetadata final
+ : IRCDMessage
{
const bool &do_topiclock;
const bool &do_mlock;
PrimitiveExtensibleItem<ListLimits> &maxlist;
- public:
- IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock, PrimitiveExtensibleItem<ListLimits> &listlimits) : IRCDMessage(creator, "METADATA", 3), do_topiclock(handle_topiclock), do_mlock(handle_mlock), maxlist(listlimits) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+public:
+ IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock, PrimitiveExtensibleItem<ListLimits> &listlimits) : IRCDMessage(creator, "METADATA", 3), do_topiclock(handle_topiclock), do_mlock(handle_mlock), maxlist(listlimits) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// We deliberately ignore non-bursting servers to avoid pseudoserver fights
// Channel METADATA has an additional parameter: the channel TS
@@ -1410,14 +1778,14 @@ class IRCDMessageMetadata : IRCDMessage
// Mode lock string is not what we say it is?
if (modes != params[3])
- UplinkSocket::Message(Me) << "METADATA " << c->name << " " << c->creation_time << " mlock :" << modes;
+ Uplink::Send("METADATA", c->name, c->creation_time, "mlock", modes);
}
else if ((c->ci) && (do_topiclock) && (params[2] == "topiclock"))
{
bool mystate = c->ci->HasExt("TOPICLOCK");
bool serverstate = (params[3] == "1");
if (mystate != serverstate)
- UplinkSocket::Message(Me) << "METADATA " << c->name << " " << c->creation_time << " topiclock :" << (mystate ? "1" : "");
+ Uplink::Send("METADATA", c->name, c->creation_time, "topiclock", !!mystate);
}
else if (params[2] == "maxlist")
{
@@ -1426,7 +1794,7 @@ class IRCDMessageMetadata : IRCDMessage
Anope::string modechr, modelimit;
while (limitstream.GetToken(modechr) && limitstream.GetToken(modelimit))
{
- limits.insert(std::make_pair(modechr[0], convertTo<unsigned>(modelimit)));
+ limits.emplace(modechr[0], Anope::Convert<unsigned>(modelimit, 0));
}
maxlist.Set(c, limits);
}
@@ -1437,9 +1805,22 @@ class IRCDMessageMetadata : IRCDMessage
if (params[1].equals_cs("accountname"))
{
User *u = User::Find(params[0]);
- NickCore *nc = NickCore::Find(params[2]);
- if (u && nc)
- u->Login(nc);
+ if (!u)
+ return; // Should never happen.
+
+ if (params[2].empty())
+ {
+ // The user has been logged out by the IRC server.
+ u->Logout();
+ }
+ else
+ {
+ // If we're bursting then then the user was probably logged
+ // in during a previous connection.
+ NickCore *nc = NickCore::Find(params[2]);
+ if (nc)
+ u->Login(nc);
+ }
}
/*
@@ -1470,7 +1851,7 @@ class IRCDMessageMetadata : IRCDMessage
if (params[1].equals_cs("modules") && !params[2].empty())
{
// only interested when it comes from our uplink
- Server* server = source.GetServer();
+ Server *server = source.GetServer();
if (!server || server->GetUplink() != Me)
return;
@@ -1479,33 +1860,58 @@ class IRCDMessageMetadata : IRCDMessage
return;
bool required = false;
- Anope::string capab, module = params[2].substr(1);
+ Anope::string capab, modname, moddata;
+ ParseModule(params[2].substr(1), modname, moddata);
- if (module.equals_cs("m_services_account.so"))
- required = true;
- else if (module.equals_cs("m_hidechans.so"))
+ if (modname.equals_cs("account"))
required = true;
- else if (module.equals_cs("m_cban.so=glob") && plus)
- IRCD->CanSQLineChannel = true;
- if (module.equals_cs("m_cban.so") && !plus)
- IRCD->CanSQLineChannel = false;
- else if (module.equals_cs("m_chghost.so"))
+
+ else if (modname.equals_cs("cban"))
+ {
+ if (plus && (spanningtree_proto_ver >= 1206 || moddata == "glob"))
+ IRCD->CanSQLineChannel = true;
+ else
+ IRCD->CanSQLineChannel = false;
+ }
+
+ else if (modname.equals_cs("cban") && spanningtree_proto_ver >= 1206)
+ IRCD->CanSQLineChannel = plus;
+
+ else if (modname.equals_cs("chghost"))
capab = "CHGHOST";
- else if (module.equals_cs("m_chgident.so"))
+
+ else if (modname.equals_cs("chgident"))
capab = "CHGIDENT";
- else if (module.equals_cs("m_svshold.so"))
- IRCD->CanSVSHold = plus;
- else if (module.equals_cs("m_rline.so"))
+
+ else if (modname.equals_cs("globops"))
+ capab = "GLOBOPS";
+
+ else if (modname.equals_cs("hidechans"))
+ required = true;
+
+ else if (modname.equals_cs("rline"))
capab = "RLINE";
- else if (module.equals_cs("m_topiclock.so"))
+
+ else if (modname.equals_cs("services"))
+ required = true;
+
+ // Deprecated 1205 modules.
+ else if (modname.equals_cs("services_account"))
+ required = true;
+
+ else if (modname.equals_cs("svshold"))
+ IRCD->CanSVSHold = plus;
+
+ else if (modname.equals_cs("topiclock"))
capab = "TOPICLOCK";
+
else
return;
if (required)
{
- if (!plus)
- Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it";
+ if (plus)
+ Log() << "Warning: InspIRCd unloaded the " << modname << " module. Anope won't function correctly without it.";
}
else
{
@@ -1514,7 +1920,7 @@ class IRCDMessageMetadata : IRCDMessage
else if (!capab.empty())
Servers::Capab.erase(capab);
- Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality";
+ Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " the " << modname << " module; adjusted functionality.";
}
}
@@ -1522,11 +1928,12 @@ class IRCDMessageMetadata : IRCDMessage
}
};
-struct IRCDMessageEndburst : IRCDMessage
+struct IRCDMessageEndburst final
+ : IRCDMessage
{
- IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Server *s = source.GetServer();
@@ -1536,11 +1943,12 @@ struct IRCDMessageEndburst : IRCDMessage
}
};
-struct IRCDMessageFJoin : IRCDMessage
+struct IRCDMessageFJoin final
+ : IRCDMessage
{
- IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Anope::string modes;
if (params.size() >= 3)
@@ -1587,16 +1995,17 @@ struct IRCDMessageFJoin : IRCDMessage
users.push_back(sju);
}
- time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime;
+ auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[0], ts, modes, users);
}
};
-struct IRCDMessageFMode : IRCDMessage
+struct IRCDMessageFMode final
+ : IRCDMessage
{
- IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* :source FMODE #test 12345678 +nto foo */
@@ -1605,63 +2014,57 @@ struct IRCDMessageFMode : IRCDMessage
modes += " " + params[n];
Channel *c = Channel::Find(params[0]);
- time_t ts;
-
- try
- {
- ts = convertTo<time_t>(params[1]);
- }
- catch (const ConvertException &)
- {
- ts = 0;
- }
-
+ auto ts = IRCD->ExtractTimestamp(params[1]);
if (c)
c->SetModesInternal(source, modes, ts);
}
};
-struct IRCDMessageFTopic : IRCDMessage
+struct IRCDMessageFTopic final
+ : IRCDMessage
{
- IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// :source FTOPIC channel ts topicts :topic
// :source FTOPIC channel ts topicts setby :topic (burst or RESYNC)
+ auto ts = IRCD->ExtractTimestamp(params[2]);
const Anope::string &setby = params.size() > 4 ? params[3] : source.GetName();
const Anope::string &topic = params.size() > 4 ? params[4] : params[3];
Channel *c = Channel::Find(params[0]);
if (c)
- c->ChangeTopicInternal(NULL, setby, topic, params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime);
+ c->ChangeTopicInternal(NULL, setby, topic, ts);
}
};
-struct IRCDMessageIdle : IRCDMessage
+struct IRCDMessageIdle final
+ : IRCDMessage
{
IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
BotInfo *bi = BotInfo::Find(params[0]);
if (bi)
- UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (Anope::CurTime - bi->lastmsg);
+ Uplink::Send(bi, "IDLE", source.GetSource(), Anope::StartTime, Anope::CurTime - bi->lastmsg);
else
{
User *u = User::Find(params[0]);
if (u && u->server == Me)
- UplinkSocket::Message(u) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " 0";
+ Uplink::Send(u, "IDLE", source.GetSource(), Anope::StartTime, 0);
}
}
};
-struct IRCDMessageIJoin : IRCDMessage
+struct IRCDMessageIJoin final
+ : IRCDMessage
{
- IRCDMessageIJoin(Module *creator) : IRCDMessage(creator, "IJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageIJoin(Module *creator) : IRCDMessage(creator, "IJOIN", 2) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// :<uid> IJOIN <chan> <membid> [<ts> [<flags>]]
Channel *c = Channel::Find(params[0]);
@@ -1669,7 +2072,7 @@ struct IRCDMessageIJoin : IRCDMessage
{
// When receiving an IJOIN, first check if the target channel exists. If it does not exist,
// ignore the join (that is, do not create the channel) and send a RESYNC back to the source.
- UplinkSocket::Message(Me) << "RESYNC :" << params[0];
+ Uplink::Send("RESYNC", params[0]);
return;
}
@@ -1682,9 +2085,9 @@ struct IRCDMessageIJoin : IRCDMessage
time_t chants = Anope::CurTime;
if (params.size() >= 4)
{
- chants = params[2].is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0;
- for (unsigned i = 0; i < params[3].length(); ++i)
- user.first.AddMode(params[3][i]);
+ chants = IRCD->ExtractTimestamp(params[2]);
+ for (auto mode : params[3])
+ user.first.AddMode(mode);
}
std::list<Message::Join::SJoinUser> users;
@@ -1693,11 +2096,49 @@ struct IRCDMessageIJoin : IRCDMessage
}
};
-struct IRCDMessageMode : IRCDMessage
+struct IRCDMessageLMode final
+ : IRCDMessage
{
- IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageLMode(Module *creator)
+ : IRCDMessage(creator, "LMODE", 3)
+ {
+ SetFlag(FLAG_SOFT_LIMIT);
+ }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
+ {
+ // :<sid> LMODE <chan> <chants> <modechr> [<mask> <setts> <setter>]+
+ auto *chan = Channel::Find(params[0]);
+ if (!chan)
+ return; // Channel doesn't exist.
+
+ // If the TS is greater than ours, we drop the mode and don't pass it anywhere.
+ auto chants = IRCD->ExtractTimestamp(params[1]);
+ if (chants > chan->creation_time)
+ return;
+
+ auto *cm = ModeManager::FindChannelModeByChar(params[2][0]);
+ if (!cm || cm->type != MODE_LIST)
+ return; // Mode doesn't exist or isn't a list mode.
+
+ if (params.size() % 3)
+ return; // Invalid parameter count.
+
+ for (auto it = params.begin() + 3; it != params.end(); it += 3)
+ {
+ // TODO: Anope doesn't store set time and setter for list modes yet.
+ chan->SetModeInternal(source, cm, *it);
+ }
+ }
+};
+
+
+struct IRCDMessageMode final
+ : IRCDMessage
+{
+ IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(FLAG_SOFT_LIMIT); }
+
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (IRCD->IsChannelValid(params[0]))
{
@@ -1718,28 +2159,35 @@ struct IRCDMessageMode : IRCDMessage
*/
User *u = User::Find(params[0]);
if (u)
- u->SetModesInternal(source, "%s", params[1].c_str());
+ u->SetModesInternal(source, params[1]);
}
}
};
-struct IRCDMessageNick : IRCDMessage
+struct IRCDMessageNick final
+ : IRCDMessage
{
- IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
source.GetUser()->ChangeNick(params[0]);
}
};
-struct IRCDMessageOperType : IRCDMessage
+struct IRCDMessageOperType final
+ : IRCDMessage
{
PrimitiveExtensibleItem<Anope::string> opertype;
- IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 1), opertype(creator, "opertype") { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageOperType(Module *creator)
+ : IRCDMessage(creator, "OPERTYPE", 1)
+ , opertype(creator, "opertype")
+ {
+ SetFlag(FLAG_REQUIRE_USER);
+ }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* opertype is equivalent to mode +o because servers
don't do this directly */
@@ -1751,38 +2199,41 @@ struct IRCDMessageOperType : IRCDMessage
}
};
-struct IRCDMessagePing : IRCDMessage
+struct IRCDMessagePing final
+ : IRCDMessage
{
- IRCDMessagePing(Module *creator) : IRCDMessage(creator, "PING", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessagePing(Module *creator) : IRCDMessage(creator, "PING", 1) { SetFlag(FLAG_SOFT_LIMIT); SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params[0] == Me->GetSID())
IRCD->SendPong(params[0], source.GetServer()->GetSID());
}
};
-struct IRCDMessageRSQuit : IRCDMessage
+struct IRCDMessageRSQuit final
+ : IRCDMessage
{
- IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Server *s = Server::Find(params[0]);
const Anope::string &reason = params.size() > 1 ? params[1] : "";
if (!s)
return;
- UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << reason;
+ Uplink::Send("SQUIT", s->GetSID(), reason);
s->Delete(s->GetName() + " " + s->GetUplink()->GetName());
}
};
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (!source.GetServer() && params.size() == 5)
{
@@ -1794,7 +2245,7 @@ struct IRCDMessageServer : IRCDMessage
* 3: numeric
* 4: desc
*/
- unsigned int hops = Anope::string(params[2]).is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0;
+ auto hops = Anope::Convert<unsigned>(params[2], 0);
new Server(Me, params[0], hops, params[4], params[3]);
}
else if (source.GetServer())
@@ -1811,11 +2262,12 @@ struct IRCDMessageServer : IRCDMessage
}
};
-struct IRCDMessageSQuit : Message::SQuit
+struct IRCDMessageSQuit final
+ : Message::SQuit
{
IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params[0] == rsquit_id || params[0] == rsquit_server)
{
@@ -1829,13 +2281,14 @@ struct IRCDMessageSQuit : Message::SQuit
IRCD->SendServer(s);
}
else
- Message::SQuit::Run(source, params);
+ Message::SQuit::Run(source, params, tags);
}
};
-struct IRCDMessageUID : IRCDMessage
+struct IRCDMessageUID final
+ : IRCDMessage
{
- IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
/*
* [Nov 03 22:09:58.176252 2009] debug: Received: :964 UID 964AAAAAC 1225746297 w00t2 localhost testnet.user w00t 127.0.0.1 1225746302 +iosw +ACGJKLNOQcdfgjklnoqtx :Robin Burchell <w00t@inspircd.org>
@@ -1845,17 +2298,19 @@ struct IRCDMessageUID : IRCDMessage
* 3: host
* 4: dhost
* 5: ident
- * 6: ip
- * 7: signon
- * 8+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname!
+ * 6: dident (v4 only)
+ * 7: ip
+ * 8: signon
+ * 9+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname!
* last: realname
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- time_t ts = convertTo<time_t>(params[1]);
+ size_t offset = params[8][0] == '+' ? 0 : 1;
+ auto ts = IRCD->ExtractTimestamp(params[1]);
- Anope::string modes = params[8];
- for (unsigned i = 9; i < params.size() - 1; ++i)
+ Anope::string modes = params[8+offset];
+ for (unsigned i = 9+offset; i < params.size() - 1; ++i)
modes += " " + params[i];
NickAlias *na = NULL;
@@ -1875,15 +2330,16 @@ struct IRCDMessageUID : IRCDMessage
++it;
}
- User *u = User::OnIntroduce(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? *na->nc : NULL);
+ User *u = User::OnIntroduce(params[2], params[5+offset], params[3], params[4], params[6+offset], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? *na->nc : NULL);
if (u)
- u->signon = convertTo<time_t>(params[7]);
+ u->signon = IRCD->ExtractTimestamp(params[7+offset]);
}
};
-class ProtoInspIRCd3 : public Module
+class ProtoInspIRCd final
+ : public Module
{
- InspIRCd3Proto ircd_proto;
+ InspIRCdProto ircd_proto;
ExtensibleItem<bool> ssl;
/* Core message handlers */
@@ -1895,6 +2351,7 @@ class ProtoInspIRCd3 : public Module
Message::Part message_part;
Message::Privmsg message_privmsg;
Message::Quit message_quit;
+ Message::Privmsg message_squery;
Message::Stats message_stats;
Message::Time message_time;
@@ -1911,6 +2368,7 @@ class ProtoInspIRCd3 : public Module
IRCDMessageIdle message_idle;
IRCDMessageIJoin message_ijoin;
IRCDMessageKick message_kick;
+ IRCDMessageLMode message_lmode;
IRCDMessageMetadata message_metadata;
IRCDMessageMode message_mode;
IRCDMessageNick message_nick;
@@ -1924,42 +2382,70 @@ class ProtoInspIRCd3 : public Module
bool use_server_side_topiclock, use_server_side_mlock;
- void SendChannelMetadata(Channel *c, const Anope::string &metadataname, const Anope::string &value)
- {
- UplinkSocket::Message(Me) << "METADATA " << c->name << " " << c->creation_time << " " << metadataname << " :" << value;
- }
-
- public:
- ProtoInspIRCd3(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
- ircd_proto(this), ssl(this, "ssl"),
- message_error(this), message_invite(this), message_kill(this), message_motd(this), message_notice(this),
- message_part(this), message_privmsg(this), message_quit(this), message_stats(this), message_time(this),
- message_away(this), message_capab(this), message_encap(this), message_endburst(this), message_fhost(this),
- message_fident(this), message_fjoin(this), message_fmode(this), message_ftopic(this), message_idle(this),
- message_ijoin(this), message_kick(this), message_metadata(this, use_server_side_topiclock, use_server_side_mlock, ircd_proto.maxlist),
- message_mode(this), message_nick(this), message_opertype(this), message_ping(this), message_rsquit(this),
- message_save(this), message_server(this), message_squit(this), message_uid(this)
- {
- }
-
- void OnReload(Configuration::Conf *conf) anope_override
+ static void SendChannelMetadata(Channel *c, const Anope::string &metadataname, const Anope::string &value)
+ {
+ Uplink::Send("METADATA", c->name, c->creation_time, metadataname, value);
+ }
+
+public:
+ ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, PROTOCOL | VENDOR)
+ , ircd_proto(this), ssl(this, "ssl")
+ , message_error(this)
+ , message_invite(this)
+ , message_kill(this)
+ , message_motd(this)
+ , message_notice(this)
+ , message_part(this)
+ , message_privmsg(this)
+ , message_quit(this)
+ , message_squery(this, "SQUERY")
+ , message_stats(this)
+ , message_time(this)
+ , message_away(this)
+ , message_capab(this)
+ , message_encap(this)
+ , message_endburst(this)
+ , message_fhost(this)
+ , message_fident(this)
+ , message_fjoin(this)
+ , message_fmode(this)
+ , message_ftopic(this)
+ , message_idle(this)
+ , message_ijoin(this)
+ , message_kick(this)
+ , message_lmode(this)
+ , message_metadata(this, use_server_side_topiclock, use_server_side_mlock, ircd_proto.maxlist)
+ , message_mode(this)
+ , message_nick(this)
+ , message_opertype(this)
+ , message_ping(this)
+ , message_rsquit(this)
+ , message_save(this)
+ , message_server(this)
+ , message_squit(this)
+ , message_uid(this)
+ {
+ }
+
+ void OnReload(Configuration::Conf *conf) override
{
use_server_side_topiclock = conf->GetModule(this)->Get<bool>("use_server_side_topiclock");
use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
}
- void OnUserNickChange(User *u, const Anope::string &) anope_override
+ void OnUserNickChange(User *u, const Anope::string &) override
{
u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED"));
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (c->ci)
this->OnChanRegistered(c->ci);
}
- void OnChanRegistered(ChannelInfo *ci) anope_override
+ void OnChanRegistered(ChannelInfo *ci) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
if (use_server_side_mlock && ci->c && modelocks && !modelocks->GetMLockAsString(false).empty())
@@ -1975,7 +2461,7 @@ class ProtoInspIRCd3 : public Module
}
}
- void OnDelChan(ChannelInfo *ci) anope_override
+ void OnDelChan(ChannelInfo *ci) override
{
if (use_server_side_mlock && ci->c)
SendChannelMetadata(ci->c, "mlock", "");
@@ -1984,7 +2470,7 @@ class ProtoInspIRCd3 : public Module
SendChannelMetadata(ci->c, "topiclock", "");
}
- EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
@@ -1997,7 +2483,7 @@ class ProtoInspIRCd3 : public Module
return EVENT_CONTINUE;
}
- EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
@@ -2010,7 +2496,7 @@ class ProtoInspIRCd3 : public Module
return EVENT_CONTINUE;
}
- EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) anope_override
+ EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) override
{
if (cmd->name == "chanserv/topic" && ci->c)
{
@@ -2024,4 +2510,4 @@ class ProtoInspIRCd3 : public Module
}
};
-MODULE_INIT(ProtoInspIRCd3)
+MODULE_INIT(ProtoInspIRCd)
diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp
deleted file mode 100644
index 01c7a426c..000000000
--- a/modules/protocol/inspircd12.cpp
+++ /dev/null
@@ -1,1408 +0,0 @@
-/* inspircd 1.2 functions
- *
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "module.h"
-#include "modules/sasl.h"
-
-struct SASLUser
-{
- Anope::string uid;
- Anope::string acc;
- time_t created;
-};
-
-static std::list<SASLUser> saslusers;
-
-static Anope::string rsquit_server, rsquit_id;
-
-class ChannelModeFlood : public ChannelModeParam
-{
- public:
- ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { }
-
- bool IsValid(Anope::string &value) const anope_override
- {
- try
- {
- Anope::string rest;
- if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
- return true;
- }
- catch (const ConvertException &) { }
-
- return false;
- }
-};
-
-class InspIRCd12Proto : public IRCDProto
-{
- private:
- void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
- {
- IRCDProto::SendSVSKillInternal(source, user, buf);
- user->KillInternal(source, buf);
- }
-
- void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent)
- {
- if (!Servers::Capab.count("CHGIDENT"))
- Log() << "CHGIDENT not loaded!";
- else
- UplinkSocket::Message(Me) << "CHGIDENT " << nick << " " << vIdent;
- }
-
- void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost)
- {
- if (!Servers::Capab.count("CHGHOST"))
- Log() << "CHGHOST not loaded!";
- else
- UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost;
- }
-
- void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason)
- {
- UplinkSocket::Message(Me) << "ADDLINE " << xtype << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason;
- }
-
- void SendDelLine(const Anope::string &xtype, const Anope::string &mask)
- {
- UplinkSocket::Message(Me) << "DELLINE " << xtype << " " << mask;
- }
-
- public:
- InspIRCd12Proto(Module *creator) : IRCDProto(creator, "InspIRCd 1.2")
- {
- DefaultPseudoclientModes = "+I";
- CanSVSNick = true;
- CanSVSJoin = true;
- CanSetVHost = true;
- CanSetVIdent = true;
- CanSQLine = true;
- CanSZLine = true;
- CanSVSHold = true;
- CanCertFP = true;
- RequiresID = true;
- MaxModes = 20;
- }
-
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
- {
- UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg;
- }
-
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
- {
- UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg;
- }
-
- void SendAkillDel(const XLine *x) anope_override
- {
- /* InspIRCd may support regex bans
- * Mask is expected in format: 'n!u@h\sr' and spaces as '\s'
- * We remove the '//' and replace '#' and any ' ' with '\s'
- */
- if (x->IsRegex() && Servers::Capab.count("RLINE"))
- {
- Anope::string mask = x->mask;
- if (mask.length() >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/')
- mask = mask.substr(1, mask.length() - 2);
- size_t h = mask.find('#');
- if (h != Anope::string::npos)
- {
- mask = mask.replace(h, 1, "\\s");
- mask = mask.replace_all_cs(" ", "\\s");
- }
- SendDelLine("R", mask);
- return;
- }
- else if (x->IsRegex() || x->HasNickOrReal())
- return;
-
- /* ZLine if we can instead */
- if (x->GetUser() == "*")
- {
- cidr addr(x->GetHost());
- if (addr.valid())
- {
- IRCD->SendSZLineDel(x);
- return;
- }
- }
-
- SendDelLine("G", x->GetUser() + "@" + x->GetHost());
- }
-
- void SendTopic(const MessageSource &source, Channel *c) anope_override
- {
- if (Servers::Capab.count("SVSTOPIC"))
- {
- UplinkSocket::Message(c->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic;
- }
- else
- {
- /* If the last time a topic was set is after the TS we want for this topic we must bump this topic's timestamp to now */
- time_t ts = c->topic_ts;
- if (c->topic_time > ts)
- ts = Anope::CurTime;
- /* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */
- UplinkSocket::Message(source) << "FTOPIC " << c->name << " " << ts << " " << c->topic_setter << " :" << c->topic;
- }
- }
-
- void SendVhostDel(User *u) anope_override
- {
- UserMode *um = ModeManager::FindUserModeByName("CLOAK");
-
- if (um && !u->HasMode(um->name))
- // Just set +x if we can
- u->SetMode(NULL, um);
- else
- // Try to restore cloaked host
- this->SendChgHostInternal(u->nick, u->chost);
- }
-
- void SendAkill(User *u, XLine *x) anope_override
- {
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
-
- /* InspIRCd may support regex bans, if they do we can send this and forget about it
- * Mask is expected in format: 'n!u@h\sr' and spaces as '\s'
- * We remove the '//' and replace '#' and any ' ' with '\s'
- */
- if (x->IsRegex() && Servers::Capab.count("RLINE"))
- {
- Anope::string mask = x->mask;
- if (mask.length() >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/')
- mask = mask.substr(1, mask.length() - 2);
- size_t h = mask.find('#');
- if (h != Anope::string::npos)
- {
- mask = mask.replace(h, 1, "\\s");
- mask = mask.replace_all_cs(" ", "\\s");
- }
- SendAddLine("R", mask, timeleft, x->by, x->GetReason());
- return;
- }
- else if (x->IsRegex() || x->HasNickOrReal())
- {
- if (!u)
- {
- /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
- return;
- }
-
- const XLine *old = x;
-
- if (old->manager->HasEntry("*@" + u->host))
- return;
-
- /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- x = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
- old->manager->AddXLine(x);
-
- Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask;
- }
-
- /* ZLine if we can instead */
- if (x->GetUser() == "*")
- {
- cidr addr(x->GetHost());
- if (addr.valid())
- {
- IRCD->SendSZLine(u, x);
- return;
- }
- }
-
- SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->by, x->GetReason());
- }
-
- void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override
- {
- User *u = User::Find(dest);
- UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << (u ? u->nick : dest) << " " << buf;
- }
-
- void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf;
- }
-
- void SendClientIntroduction(User *u) anope_override
- {
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->timestamp << " " << modes << " :" << u->realname;
-
- if (modes.find('o') != Anope::string::npos)
- {
- // Mark as introduced so we can send an oper type.
- BotInfo *bi = BotInfo::Find(u->nick, true);
- if (bi)
- bi->introduced = true;
-
- UplinkSocket::Message(u) << "OPERTYPE :service";
- }
- }
-
- /* SERVER services-dev.chatspike.net password 0 :Description here */
- void SendServer(const Server *server) anope_override
- {
- /* if rsquit is set then we are waiting on a squit */
- if (rsquit_id.empty() && rsquit_server.empty())
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
- }
-
- void SendSquit(Server *s, const Anope::string &message) anope_override
- {
- if (s != Me)
- {
- rsquit_id = s->GetSID();
- rsquit_server = s->GetName();
- UplinkSocket::Message() << "RSQUIT " << s->GetName() << " :" << message;
- }
- else
- UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message;
- }
-
- /* JOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
- {
- UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID();
- /* Note that we can send this with the FJOIN but choose not to
- * because the mode stacker will handle this and probably will
- * merge these modes with +nrt and other mlocked modes
- */
- if (status)
- {
- /* First save the channel status incase uc->Status == status */
- ChannelStatus cs = *status;
- /* If the user is internally on the channel with flags, kill them so that
- * the stacker will allow this.
- */
- ChanUserContainer *uc = c->FindUser(user);
- if (uc != NULL)
- uc->status.Clear();
-
- BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
-
- if (uc != NULL)
- uc->status = cs;
- }
- }
-
- /* UNSQLINE */
- void SendSQLineDel(const XLine *x) anope_override
- {
- SendDelLine("Q", x->mask);
- }
-
- /* SQLINE */
- void SendSQLine(User *, const XLine *x) anope_override
- {
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
- SendAddLine("Q", x->mask, timeleft, x->by, x->GetReason());
- }
-
- void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
- {
- if (!vIdent.empty())
- this->SendChgIdentInternal(u->nick, vIdent);
- if (!vhost.empty())
- this->SendChgHostInternal(u->nick, vhost);
- }
-
- void SendConnect() anope_override
- {
- SendServer(Me);
- }
-
- /* SVSHOLD - set */
- void SendSVSHold(const Anope::string &nick, time_t t) anope_override
- {
- UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick << " " << t << " :Being held for registered user";
- }
-
- /* SVSHOLD - release */
- void SendSVSHoldDel(const Anope::string &nick) anope_override
- {
- UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick;
- }
-
- /* UNSZLINE */
- void SendSZLineDel(const XLine *x) anope_override
- {
- SendDelLine("Z", x->GetHost());
- }
-
- /* SZLINE */
- void SendSZLine(User *, const XLine *x) anope_override
- {
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
- SendAddLine("Z", x->GetHost(), timeleft, x->by, x->GetReason());
- }
-
- void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) anope_override
- {
- UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan;
- }
-
- void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) anope_override
- {
- if (!param.empty())
- UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param;
- else
- UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan;
- }
-
- void SendSWhois(const MessageSource &, const Anope::string &who, const Anope::string &mask) anope_override
- {
- User *u = User::Find(who);
-
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask;
- }
-
- void SendBOB() anope_override
- {
- UplinkSocket::Message(Me) << "BURST " << Anope::CurTime;
- Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
- UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "none") << ") -- " << Anope::VersionBuildString();
- }
-
- void SendEOB() anope_override
- {
- UplinkSocket::Message(Me) << "ENDBURST";
- }
-
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
- {
- if (Servers::Capab.count("GLOBOPS"))
- UplinkSocket::Message(source) << "SNONOTICE g :" << buf;
- else
- UplinkSocket::Message(source) << "SNONOTICE A :" << buf;
- }
-
- void SendLogin(User *u, NickAlias *na) anope_override
- {
- /* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */
- if (na->nc->HasExt("UNCONFIRMED"))
- return;
-
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display;
- }
-
- void SendLogout(User *u) anope_override
- {
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :";
- }
-
- void SendChannel(Channel *c) anope_override
- {
- UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :";
- }
-
- void SendOper(User *u) anope_override
- {
- }
-
- void SendSASLMessage(const SASL::Message &message) anope_override
- {
- UplinkSocket::Message(Me) << "ENCAP " << message.target.substr(0, 3) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext));
- }
-
- void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override
- {
- UplinkSocket::Message(Me) << "METADATA " << uid << " accountname :" << acc;
-
- if (!vident.empty())
- UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGIDENT " << uid << " " << vident;
- if (!vhost.empty())
- UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGHOST " << uid << " " << vhost;
-
- SASLUser su;
- su.uid = uid;
- su.acc = acc;
- su.created = Anope::CurTime;
-
- for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
- {
- SASLUser &u = *it;
-
- if (u.created + 30 < Anope::CurTime || u.uid == uid)
- it = saslusers.erase(it);
- else
- ++it;
- }
-
- saslusers.push_back(su);
- }
-
- bool IsExtbanValid(const Anope::string &mask) anope_override
- {
- return mask.length() >= 3 && mask[1] == ':';
- }
-
- bool IsIdentValid(const Anope::string &ident) anope_override
- {
- if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
- return false;
-
- for (unsigned i = 0; i < ident.length(); ++i)
- {
- const char &c = ident[i];
-
- if (c >= 'A' && c <= '}')
- continue;
-
- if ((c >= '0' && c <= '9') || c == '-' || c == '.')
- continue;
-
- return false;
- }
-
- return true;
- }
-};
-
-class InspIRCdExtBan : public ChannelModeList
-{
- public:
- InspIRCdExtBan(const Anope::string &mname, char modeChar) : ChannelModeList(mname, modeChar) { }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
-
- if (mask.find("m:") == 0 || mask.find("N:") == 0)
- {
- Anope::string real_mask = mask.substr(2);
-
- Entry en(this->name, real_mask);
- if (en.Matches(u))
- return true;
- }
- else if (mask.find("j:") == 0)
- {
- Anope::string real_mask = mask.substr(2);
-
- Channel *c = Channel::Find(real_mask);
- if (c != NULL && c->FindUser(u) != NULL)
- return true;
- }
- else if (mask.find("M:") == 0 || mask.find("R:") == 0)
- {
- Anope::string real_mask = mask.substr(2);
-
- if (u->IsIdentified() && real_mask.equals_ci(u->Account()->display))
- return true;
- }
- else if (mask.find("r:") == 0)
- {
- Anope::string real_mask = mask.substr(2);
-
- if (Anope::Match(u->realname, real_mask))
- return true;
- }
- else if (mask.find("s:") == 0)
- {
- Anope::string real_mask = mask.substr(2);
-
- if (Anope::Match(u->server->GetName(), real_mask))
- return true;
- }
-
- return false;
- }
-};
-
-struct IRCDMessageCapab : Message::Capab
-{
- IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (params[0].equals_cs("START"))
- {
- /* reset CAPAB */
- Servers::Capab.clear();
- Servers::Capab.insert("NOQUIT");
- IRCD->CanSVSHold = false;
- }
- else if (params[0].equals_cs("MODULES") && params.size() > 1)
- {
- if (params[1].find("m_globops.so") != Anope::string::npos)
- Servers::Capab.insert("GLOBOPS");
- if (params[1].find("m_services_account.so") != Anope::string::npos)
- Servers::Capab.insert("SERVICES");
- if (params[1].find("m_svshold.so") != Anope::string::npos)
- IRCD->CanSVSHold = true;
- if (params[1].find("m_chghost.so") != Anope::string::npos)
- Servers::Capab.insert("CHGHOST");
- if (params[1].find("m_chgident.so") != Anope::string::npos)
- Servers::Capab.insert("CHGIDENT");
- if (params[1].find("m_hidechans.so") != Anope::string::npos)
- Servers::Capab.insert("HIDECHANS");
- if (params[1].find("m_servprotect.so") != Anope::string::npos)
- IRCD->DefaultPseudoclientModes = "+Ik";
- if (params[1].find("m_rline.so") != Anope::string::npos)
- Servers::Capab.insert("RLINE");
- }
- else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1)
- {
- spacesepstream ssep(params[1]);
- Anope::string capab;
- while (ssep.GetToken(capab))
- {
- if (capab.find("CHANMODES") != Anope::string::npos)
- {
- Anope::string modes(capab.begin() + 10, capab.end());
- commasepstream sep(modes);
- Anope::string modebuf;
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'b':
- ModeManager::AddChannelMode(new InspIRCdExtBan("BAN", 'b'));
- continue;
- case 'e':
- ModeManager::AddChannelMode(new InspIRCdExtBan("EXCEPT", 'e'));
- continue;
- case 'I':
- ModeManager::AddChannelMode(new InspIRCdExtBan("INVITEOVERRIDE", 'I'));
- continue;
- /* InspIRCd sends q and a here if they have no prefixes */
- case 'q':
- ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '@', 4));
- continue;
- case 'a':
- ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT" , 'a', '@', 3));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t]));
- }
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'k':
- ModeManager::AddChannelMode(new ChannelModeKey('k'));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t]));
- }
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'F':
- ModeManager::AddChannelMode(new ChannelModeParam("NICKFLOOD", 'F', true));
- continue;
- case 'J':
- ModeManager::AddChannelMode(new ChannelModeParam("NOREJOIN", 'J', true));
- continue;
- case 'L':
- ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L', true));
- continue;
- case 'f':
- ModeManager::AddChannelMode(new ChannelModeFlood('f', true));
- continue;
- case 'j':
- ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j', true));
- continue;
- case 'l':
- ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true));
- }
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'A':
- ModeManager::AddChannelMode(new ChannelMode("ALLINVITE", 'A'));
- continue;
- case 'B':
- ModeManager::AddChannelMode(new ChannelMode("BLOCKCAPS", 'B'));
- continue;
- case 'C':
- ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C'));
- continue;
- case 'D':
- ModeManager::AddChannelMode(new ChannelMode("DELAYEDJOIN", 'D'));
- continue;
- case 'G':
- ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G'));
- continue;
- case 'K':
- ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K'));
- continue;
- case 'M':
- ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M'));
- continue;
- case 'N':
- ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N'));
- continue;
- case 'O':
- ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O'));
- continue;
- case 'P':
- ModeManager::AddChannelMode(new ChannelMode("PERM", 'P'));
- continue;
- case 'Q':
- ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q'));
- continue;
- case 'R':
- ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R'));
- continue;
- case 'S':
- ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S'));
- continue;
- case 'T':
- ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T'));
- continue;
- case 'c':
- ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c'));
- continue;
- case 'i':
- ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i'));
- continue;
- case 'm':
- ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm'));
- continue;
- case 'n':
- ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n'));
- continue;
- case 'p':
- ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p'));
- continue;
- case 'r':
- ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r'));
- continue;
- case 's':
- ModeManager::AddChannelMode(new ChannelMode("SECRET", 's'));
- continue;
- case 't':
- ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't'));
- continue;
- case 'u':
- ModeManager::AddChannelMode(new ChannelMode("AUDITORIUM", 'u'));
- continue;
- case 'z':
- ModeManager::AddChannelMode(new ChannelMode("SSL", 'z'));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelMode("", modebuf[t]));
- }
- }
- }
- else if (capab.find("USERMODES") != Anope::string::npos)
- {
- Anope::string modes(capab.begin() + 10, capab.end());
- commasepstream sep(modes);
- Anope::string modebuf;
-
- while (sep.GetToken(modebuf))
- {
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'h':
- ModeManager::AddUserMode(new UserModeOperOnly("HELPOP", 'h'));
- continue;
- case 'B':
- ModeManager::AddUserMode(new UserMode("BOT", 'B'));
- continue;
- case 'G':
- ModeManager::AddUserMode(new UserMode("CENSOR", 'G'));
- continue;
- case 'H':
- ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H'));
- continue;
- case 'I':
- ModeManager::AddUserMode(new UserMode("PRIV", 'I'));
- continue;
- case 'Q':
- ModeManager::AddUserMode(new UserModeOperOnly("HIDDEN", 'Q'));
- continue;
- case 'R':
- ModeManager::AddUserMode(new UserMode("REGPRIV", 'R'));
- continue;
- case 'S':
- ModeManager::AddUserMode(new UserMode("STRIPCOLOR", 'S'));
- continue;
- case 'W':
- ModeManager::AddUserMode(new UserMode("WHOIS", 'W'));
- continue;
- case 'c':
- ModeManager::AddUserMode(new UserMode("COMMONCHANS", 'c'));
- continue;
- case 'g':
- ModeManager::AddUserMode(new UserMode("CALLERID", 'g'));
- continue;
- case 'i':
- ModeManager::AddUserMode(new UserMode("INVIS", 'i'));
- continue;
- case 'k':
- ModeManager::AddUserMode(new UserModeNoone("PROTECTED", 'k'));
- continue;
- case 'o':
- ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o'));
- continue;
- case 'r':
- ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r'));
- continue;
- case 'w':
- ModeManager::AddUserMode(new UserMode("WALLOPS", 'w'));
- continue;
- case 'x':
- ModeManager::AddUserMode(new UserMode("CLOAK", 'x'));
- continue;
- case 'd':
- ModeManager::AddUserMode(new UserMode("DEAF", 'd'));
- continue;
- default:
- ModeManager::AddUserMode(new UserMode("", modebuf[t]));
- }
- }
- }
- }
- else if (capab.find("PREFIX=(") != Anope::string::npos)
- {
- Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')'));
- Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end());
- unsigned short level = modes.length() - 1;
-
- for (size_t t = 0, end = modes.length(); t < end; ++t)
- {
- switch (modes[t])
- {
- case 'q':
- ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', chars[t], level--));
- continue;
- case 'a':
- ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', chars[t], level--));
- continue;
- case 'o':
- ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', chars[t], level--));
- continue;
- case 'h':
- ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', chars[t], level--));
- continue;
- case 'v':
- ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', chars[t], level--));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelModeStatus("", modes[t], chars[t], level--));
- }
- }
-
- ModeManager::RebuildStatusModes();
- }
- else if (capab.find("MAXMODES=") != Anope::string::npos)
- {
- Anope::string maxmodes(capab.begin() + 9, capab.end());
- IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3;
- }
- }
- }
- else if (params[0].equals_cs("END"))
- {
- if (!Servers::Capab.count("GLOBOPS"))
- {
- UplinkSocket::Message() << "ERROR :m_globops is not loaded. This is required by Anope";
- Anope::QuitReason = "Remote server does not have the m_globops module loaded, and this is required.";
- Anope::Quitting = true;
- return;
- }
- if (!Servers::Capab.count("SERVICES"))
- {
- UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope";
- Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required.";
- Anope::Quitting = true;
- return;
- }
- if (!Servers::Capab.count("HIDECHANS"))
- {
- UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope";
- Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required.";
- Anope::Quitting = true;
- return;
- }
- if (!IRCD->CanSVSHold)
- Log() << "SVSHOLD missing, Usage disabled until module is loaded.";
- if (!Servers::Capab.count("CHGHOST"))
- Log() << "CHGHOST missing, Usage disabled until module is loaded.";
- if (!Servers::Capab.count("CHGIDENT"))
- Log() << "CHGIDENT missing, Usage disabled until module is loaded.";
- }
-
- Message::Capab::Run(source, params);
- }
-};
-
-struct IRCDMessageChgIdent : IRCDMessage
-{
- IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = User::Find(params[0]);
- if (u)
- u->SetIdent(params[1]);
- }
-};
-
-struct IRCDMessageChgName : IRCDMessage
-{
- IRCDMessageChgName(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- source.GetUser()->SetRealname(params[0]);
- }
-};
-
-struct IRCDMessageEncap : IRCDMessage
-{
- IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0]))
- return;
-
- if (SASL::sasl && params[1] == "SASL" && params.size() >= 6)
- {
- SASL::Message m;
- m.source = params[2];
- m.target = params[3];
- m.type = params[4];
- m.data = params[5];
- m.ext = params.size() > 6 ? params[6] : "";
-
- SASL::sasl->ProcessMessage(m);
- }
- }
-};
-
-struct IRCDMessageEndburst : IRCDMessage
-{
- IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- Server *s = source.GetServer();
-
- Log(LOG_DEBUG) << "Processed ENDBURST for " << s->GetName();
-
- s->Sync(true);
- }
-};
-
-struct IRCDMessageFHost : IRCDMessage
-{
- IRCDMessageFHost(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- source.GetUser()->SetDisplayedHost(params[0]);
- }
-};
-
-struct IRCDMessageFJoin : IRCDMessage
-{
- IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- Anope::string modes;
- if (params.size() >= 3)
- {
- for (unsigned i = 2; i < params.size() - 1; ++i)
- modes += " " + params[i];
- if (!modes.empty())
- modes.erase(modes.begin());
- }
-
- std::list<Message::Join::SJoinUser> users;
-
- spacesepstream sep(params[params.size() - 1]);
- Anope::string buf;
- while (sep.GetToken(buf))
- {
- Message::Join::SJoinUser sju;
-
- /* Loop through prefixes and find modes for them */
- for (char c; (c = buf[0]) != ',' && c;)
- {
- buf.erase(buf.begin());
- sju.first.AddMode(c);
- }
- /* Erase the , */
- if (!buf.empty())
- buf.erase(buf.begin());
-
- sju.second = User::Find(buf);
- if (!sju.second)
- {
- Log(LOG_DEBUG) << "FJOIN for nonexistent user " << buf << " on " << params[0];
- continue;
- }
-
- users.push_back(sju);
- }
-
- time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime;
- Message::Join::SJoin(source, params[0], ts, modes, users);
- }
-};
-
-struct IRCDMessageFMode : IRCDMessage
-{
- IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- /* :source FMODE #test 12345678 +nto foo */
-
- Anope::string modes = params[2];
- for (unsigned n = 3; n < params.size(); ++n)
- modes += " " + params[n];
-
- Channel *c = Channel::Find(params[0]);
- time_t ts;
-
- try
- {
- ts = convertTo<time_t>(params[1]);
- }
- catch (const ConvertException &)
- {
- ts = 0;
- }
-
- if (c)
- c->SetModesInternal(source, modes, ts);
- }
-};
-
-struct IRCDMessageFTopic : IRCDMessage
-{
- IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- /* :source FTOPIC channel topicts setby :topic */
-
- Channel *c = Channel::Find(params[0]);
- if (c)
- c->ChangeTopicInternal(NULL, params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime);
- }
-};
-
-struct IRCDMessageIdle : IRCDMessage
-{
- IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- BotInfo *bi = BotInfo::Find(params[0]);
- if (bi)
- UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (Anope::CurTime - bi->lastmsg);
- else
- {
- User *u = User::Find(params[0]);
- if (u && u->server == Me)
- UplinkSocket::Message(u) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " 0";
- }
- }
-};
-
-/*
- * source = numeric of the sending server
- * params[0] = uuid
- * params[1] = metadata name
- * params[2] = data
- */
-struct IRCDMessageMetadata : IRCDMessage
-{
- IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (isdigit(params[0][0]))
- {
- if (params[1].equals_cs("accountname"))
- {
- User *u = User::Find(params[0]);
- NickCore *nc = NickCore::Find(params[2]);
- if (u && nc)
- u->Login(nc);
- }
-
- /*
- * possible incoming ssl_cert messages:
- * Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...>
- * Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0)
- */
- else if (params[1].equals_cs("ssl_cert"))
- {
- User *u = User::Find(params[0]);
- if (!u)
- return;
- u->Extend<bool>("ssl");
- Anope::string data = params[2].c_str();
- size_t pos1 = data.find(' ') + 1;
- size_t pos2 = data.find(' ', pos1);
- if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes.
- {
- u->fingerprint = data.substr(pos1, pos2 - pos1);
- }
- FOREACH_MOD(OnFingerprint, (u));
- }
- }
- else if (params[0][0] == '#')
- {
- }
- else if (params[0] == "*")
- {
- // Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so
-
- if (params[1].equals_cs("modules") && !params[2].empty())
- {
- // only interested when it comes from our uplink
- Server* server = source.GetServer();
- if (!server || server->GetUplink() != Me)
- return;
-
- bool plus = (params[2][0] == '+');
- if (!plus && params[2][0] != '-')
- return;
-
- bool required = false;
- Anope::string capab, module = params[2].substr(1);
-
- if (module.equals_cs("m_services_account.so"))
- required = true;
- else if (module.equals_cs("m_hidechans.so"))
- required = true;
- else if (module.equals_cs("m_chghost.so"))
- capab = "CHGHOST";
- else if (module.equals_cs("m_chgident.so"))
- capab = "CHGIDENT";
- else if (module.equals_cs("m_svshold.so"))
- capab = "SVSHOLD";
- else if (module.equals_cs("m_rline.so"))
- capab = "RLINE";
- else if (module.equals_cs("m_topiclock.so"))
- capab = "TOPICLOCK";
- else
- return;
-
- if (required)
- {
- if (!plus)
- Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it";
- }
- else
- {
- if (plus)
- Servers::Capab.insert(capab);
- else
- Servers::Capab.erase(capab);
-
- Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality";
- }
-
- }
- }
- }
-};
-
-struct IRCDMessageMode : IRCDMessage
-{
- IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (IRCD->IsChannelValid(params[0]))
- {
- Channel *c = Channel::Find(params[0]);
-
- Anope::string modes = params[1];
- for (unsigned n = 2; n < params.size(); ++n)
- modes += " " + params[n];
-
- if (c)
- c->SetModesInternal(source, modes);
- }
- else
- {
- /* InspIRCd lets opers change another
- users modes, we have to kludge this
- as it slightly breaks RFC1459
- */
- User *u = User::Find(params[0]);
- if (u)
- u->SetModesInternal(source, "%s", params[1].c_str());
- }
- }
-};
-
-struct IRCDMessageNick : IRCDMessage
-{
- IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- source.GetUser()->ChangeNick(params[0]);
- }
-};
-
-struct IRCDMessageOperType : IRCDMessage
-{
- IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- /* opertype is equivalent to mode +o because servers
- don't do this directly */
- User *u = source.GetUser();
- if (!u->HasMode("OPER"))
- u->SetModesInternal(source, "+o");
- }
-};
-
-struct IRCDMessageRSQuit : IRCDMessage
-{
- IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- Server *s = Server::Find(params[0]);
- const Anope::string &reason = params.size() > 1 ? params[1] : "";
- if (!s)
- return;
-
- UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << reason;
- s->Delete(s->GetName() + " " + s->GetUplink()->GetName());
- }
-};
-
-struct IRCDMessageSetIdent : IRCDMessage
-{
- IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- source.GetUser()->SetIdent(params[0]);
- }
-};
-
-struct IRCDMessageServer : IRCDMessage
-{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- /*
- * [Nov 04 00:08:46.308435 2009] debug: Received: SERVER irc.inspircd.com pass 0 964 :Testnet Central!
- * 0: name
- * 1: pass
- * 2: hops
- * 3: numeric
- * 4: desc
- */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- unsigned int hops = Anope::string(params[2]).is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0;
- new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[4], params[3]);
- }
-};
-
-struct IRCDMessageSQuit : Message::SQuit
-{
- IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (params[0] == rsquit_id || params[0] == rsquit_server)
- {
- /* squit for a recently squit server, introduce the juped server now */
- Server *s = Server::Find(rsquit_server);
-
- rsquit_id.clear();
- rsquit_server.clear();
-
- if (s && s->IsJuped())
- IRCD->SendServer(s);
- }
- else
- Message::SQuit::Run(source, params);
- }
-};
-
-struct IRCDMessageTime : IRCDMessage
-{
- IRCDMessageTime(Module *creator) : IRCDMessage(creator, "TIME", 2) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime;
- }
-};
-
-struct IRCDMessageUID : IRCDMessage
-{
- IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- /*
- * [Nov 03 22:09:58.176252 2009] debug: Received: :964 UID 964AAAAAC 1225746297 w00t2 localhost testnet.user w00t 127.0.0.1 1225746302 +iosw +ACGJKLNOQcdfgjklnoqtx :Robin Burchell <w00t@inspircd.org>
- * 0: uid
- * 1: ts
- * 2: nick
- * 3: host
- * 4: dhost
- * 5: ident
- * 6: ip
- * 7: signon
- * 8+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname!
- * last: realname
- */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- time_t ts = convertTo<time_t>(params[1]);
-
- Anope::string modes = params[8];
- for (unsigned i = 9; i < params.size() - 1; ++i)
- modes += " " + params[i];
-
- NickAlias *na = NULL;
- if (SASL::sasl)
- for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
- {
- SASLUser &u = *it;
-
- if (u.created + 30 < Anope::CurTime)
- it = saslusers.erase(it);
- else if (u.uid == params[0])
- {
- na = NickAlias::Find(u.acc);
- it = saslusers.erase(it);
- }
- else
- ++it;
- }
-
- User *u = User::OnIntroduce(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? *na->nc : NULL);
- if (u)
- u->signon = convertTo<time_t>(params[7]);
- }
-};
-
-class ProtoInspIRCd12 : public Module
-{
- InspIRCd12Proto ircd_proto;
- ExtensibleItem<bool> ssl;
-
- /* Core message handlers */
- Message::Away message_away;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Join message_join;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::Stats message_stats;
- Message::Topic message_topic;
-
- /* Our message handlers */
- IRCDMessageChgIdent message_chgident;
- IRCDMessageChgName message_setname, message_chgname;
- IRCDMessageCapab message_capab;
- IRCDMessageEncap message_encap;
- IRCDMessageEndburst message_endburst;
- IRCDMessageFHost message_fhost, message_sethost;
- IRCDMessageFJoin message_fjoin;
- IRCDMessageFMode message_fmode;
- IRCDMessageFTopic message_ftopic;
- IRCDMessageIdle message_idle;
- IRCDMessageMetadata message_metadata;
- IRCDMessageMode message_mode;
- IRCDMessageNick message_nick;
- IRCDMessageOperType message_opertype;
- IRCDMessageRSQuit message_rsquit;
- IRCDMessageSetIdent message_setident;
- IRCDMessageServer message_server;
- IRCDMessageSQuit message_squit;
- IRCDMessageTime message_time;
- IRCDMessageUID message_uid;
-
- public:
- ProtoInspIRCd12(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
- ircd_proto(this), ssl(this, "ssl"),
- message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), message_kill(this),
- message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this),
- message_stats(this), message_topic(this),
-
- message_chgident(this), message_setname(this, "SETNAME"), message_chgname(this, "FNAME"), message_capab(this), message_encap(this),
- message_endburst(this),
- message_fhost(this, "FHOST"), message_sethost(this, "SETHOST"), message_fjoin(this), message_fmode(this), message_ftopic(this),
- message_idle(this), message_metadata(this), message_mode(this), message_nick(this), message_opertype(this), message_rsquit(this),
- message_setident(this), message_server(this), message_squit(this), message_time(this), message_uid(this)
- {
- Servers::Capab.insert("NOQUIT");
- }
-
- void OnUserNickChange(User *u, const Anope::string &) anope_override
- {
- /* InspIRCd 1.2 doesn't set -r on nick change, remove -r here. Note that if we have to set +r later
- * this will cancel out this -r, resulting in no mode changes.
- *
- * Do not set -r if we don't have a NickServ loaded - DP
- */
- BotInfo *NickServ = Config->GetClient("NickServ");
- if (NickServ)
- u->RemoveMode(NickServ, "REGISTERED");
- }
-};
-
-MODULE_INIT(ProtoInspIRCd12)
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
deleted file mode 100644
index 9dbaf69c0..000000000
--- a/modules/protocol/inspircd20.cpp
+++ /dev/null
@@ -1,1106 +0,0 @@
-/* InspIRCd 2.0 functions
- *
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "module.h"
-#include "modules/cs_mode.h"
-
-static unsigned int spanningtree_proto_ver = 0;
-
-static ServiceReference<IRCDProto> insp12("IRCDProto", "inspircd12");
-
-class InspIRCd20Proto : public IRCDProto
-{
- public:
- InspIRCd20Proto(Module *creator) : IRCDProto(creator, "InspIRCd 2.0")
- {
- DefaultPseudoclientModes = "+I";
- CanSVSNick = true;
- CanSVSJoin = true;
- CanSetVHost = true;
- CanSetVIdent = true;
- CanSQLine = true;
- CanSZLine = true;
- CanSVSHold = true;
- CanCertFP = true;
- RequiresID = true;
- MaxModes = 20;
- }
-
- void SendConnect() anope_override
- {
- UplinkSocket::Message() << "CAPAB START 1202";
- UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202";
- UplinkSocket::Message() << "CAPAB END";
- insp12->SendConnect();
- }
-
- void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override
- {
- Anope::string mechlist;
- for (unsigned i = 0; i < mechanisms.size(); ++i)
- mechlist += "," + mechanisms[i];
-
- UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1));
- }
-
- void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override { insp12->SendSVSKillInternal(source, user, buf); }
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalNotice(bi, dest, msg); }
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalPrivmsg(bi, dest, msg); }
- void SendAkillDel(const XLine *x) anope_override { insp12->SendAkillDel(x); }
- void SendTopic(const MessageSource &whosets, Channel *c) anope_override { insp12->SendTopic(whosets, c); };
- void SendVhostDel(User *u) anope_override { insp12->SendVhostDel(u); }
- void SendAkill(User *u, XLine *x) anope_override { insp12->SendAkill(u, x); }
- void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override { insp12->SendNumericInternal(numeric, dest, buf); }
- void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); }
- void SendClientIntroduction(User *u) anope_override { insp12->SendClientIntroduction(u); }
- void SendServer(const Server *server) anope_override { insp12->SendServer(server); }
- void SendSquit(Server *s, const Anope::string &message) anope_override { insp12->SendSquit(s, message); }
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); }
- void SendSQLineDel(const XLine *x) anope_override { insp12->SendSQLineDel(x); }
- void SendSQLine(User *u, const XLine *x) anope_override { insp12->SendSQLine(u, x); }
- void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendVhost(u, vident, vhost); }
- void SendSVSHold(const Anope::string &nick, time_t t) anope_override { insp12->SendSVSHold(nick, t); }
- void SendSVSHoldDel(const Anope::string &nick) anope_override { insp12->SendSVSHoldDel(nick); }
- void SendSZLineDel(const XLine *x) anope_override { insp12->SendSZLineDel(x); }
- void SendSZLine(User *u, const XLine *x) anope_override { insp12->SendSZLine(u, x); }
- void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override { insp12->SendSVSJoin(source, u, chan, other); }
- void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) anope_override { insp12->SendSVSPart(source, u, chan, param); }
- void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override { insp12->SendSWhois(bi, who, mask); }
- void SendBOB() anope_override { insp12->SendBOB(); }
- void SendEOB() anope_override { insp12->SendEOB(); }
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { insp12->SendGlobopsInternal(source, buf); }
- void SendLogin(User *u, NickAlias *na) anope_override { insp12->SendLogin(u, na); }
- void SendLogout(User *u) anope_override { insp12->SendLogout(u); }
- void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); }
- void SendSASLMessage(const SASL::Message &message) anope_override { insp12->SendSASLMessage(message); }
- void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendSVSLogin(uid, acc, vident, vhost); }
- bool IsExtbanValid(const Anope::string &mask) anope_override { return insp12->IsExtbanValid(mask); }
- bool IsIdentValid(const Anope::string &ident) anope_override { return insp12->IsIdentValid(ident); }
-};
-
-class InspIRCdAutoOpMode : public ChannelModeList
-{
- public:
- InspIRCdAutoOpMode(char mode) : ChannelModeList("AUTOOP", mode)
- {
- }
-
- bool IsValid(Anope::string &mask) const anope_override
- {
- // We can not validate this because we don't know about the
- // privileges of the setter so just reject attempts to set it.
- return false;
- }
-};
-
-class InspIRCdExtBan : public ChannelModeVirtual<ChannelModeList>
-{
- char ext;
-
- public:
- InspIRCdExtBan(const Anope::string &mname, const Anope::string &basename, char extban) : ChannelModeVirtual<ChannelModeList>(mname, basename)
- , ext(extban)
- {
- }
-
- ChannelMode *Wrap(Anope::string &param) anope_override
- {
- param = Anope::string(ext) + ":" + param;
- return ChannelModeVirtual<ChannelModeList>::Wrap(param);
- }
-
- ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) anope_override
- {
- if (cm->type != MODE_LIST || param.length() < 3 || param[0] != ext || param[1] != ':')
- return cm;
-
- param = param.substr(2);
- return this;
- }
-};
-
-namespace InspIRCdExtban
-{
- class EntryMatcher : public InspIRCdExtBan
- {
- public:
- EntryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(2);
-
- return Entry(this->name, real_mask).Matches(u);
- }
- };
-
- class ChannelMatcher : public InspIRCdExtBan
- {
- public:
- ChannelMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
-
- Anope::string channel = mask.substr(2);
-
- ChannelMode *cm = NULL;
- if (channel[0] != '#')
- {
- char modeChar = ModeManager::GetStatusChar(channel[0]);
- channel.erase(channel.begin());
- cm = ModeManager::FindChannelModeByChar(modeChar);
- if (cm != NULL && cm->type != MODE_STATUS)
- cm = NULL;
- }
-
- Channel *c = Channel::Find(channel);
- if (c != NULL)
- {
- ChanUserContainer *uc = c->FindUser(u);
- if (uc != NULL)
- if (cm == NULL || uc->status.HasMode(cm->mchar))
- return true;
- }
-
- return false;
- }
- };
-
- class AccountMatcher : public InspIRCdExtBan
- {
- public:
- AccountMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(2);
-
- return u->IsIdentified() && real_mask.equals_ci(u->Account()->display);
- }
- };
-
- class RealnameMatcher : public InspIRCdExtBan
- {
- public:
- RealnameMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(2);
- return Anope::Match(u->realname, real_mask);
- }
- };
-
- class ServerMatcher : public InspIRCdExtBan
- {
- public:
- ServerMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(2);
- return Anope::Match(u->server->GetName(), real_mask);
- }
- };
-
- class FingerprintMatcher : public InspIRCdExtBan
- {
- public:
- FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(2);
- return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask);
- }
- };
-
- class UnidentifiedMatcher : public InspIRCdExtBan
- {
- public:
- UnidentifiedMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(2);
- return !u->Account() && Entry("BAN", real_mask).Matches(u);
- }
- };
-}
-
-class ColonDelimitedParamMode : public ChannelModeParam
-{
- public:
- ColonDelimitedParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { }
-
- bool IsValid(Anope::string &value) const anope_override
- {
- return IsValid(value, false);
- }
-
- bool IsValid(const Anope::string &value, bool historymode) const
- {
- if (value.empty())
- return false; // empty param is never valid
-
- Anope::string::size_type pos = value.find(':');
- if ((pos == Anope::string::npos) || (pos == 0))
- return false; // no ':' or it's the first char, both are invalid
-
- Anope::string rest;
- try
- {
- if (convertTo<int>(value, rest, false) <= 0)
- return false; // negative numbers and zero are invalid
-
- rest = rest.substr(1);
- int n;
- if (historymode)
- {
- // For the history mode, the part after the ':' is a duration and it
- // can be in the user friendly "1d3h20m" format, make sure we accept that
- n = Anope::DoTime(rest);
- }
- else
- n = convertTo<int>(rest);
-
- if (n <= 0)
- return false;
- }
- catch (const ConvertException &e)
- {
- // conversion error, invalid
- return false;
- }
-
- return true;
- }
-};
-
-class SimpleNumberParamMode : public ChannelModeParam
-{
- public:
- SimpleNumberParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { }
-
- bool IsValid(Anope::string &value) const anope_override
- {
- if (value.empty())
- return false; // empty param is never valid
-
- try
- {
- if (convertTo<int>(value) <= 0)
- return false;
- }
- catch (const ConvertException &e)
- {
- // conversion error, invalid
- return false;
- }
-
- return true;
- }
-};
-
-class ChannelModeFlood : public ColonDelimitedParamMode
-{
- public:
- ChannelModeFlood(char modeChar) : ColonDelimitedParamMode("FLOOD", modeChar) { }
-
- bool IsValid(Anope::string &value) const anope_override
- {
- // The parameter of this mode is a bit different, it may begin with a '*',
- // ignore it if that's the case
- Anope::string v = value[0] == '*' ? value.substr(1) : value;
- return ((!value.empty()) && (ColonDelimitedParamMode::IsValid(v)));
- }
-};
-
-class ChannelModeHistory : public ColonDelimitedParamMode
-{
- public:
- ChannelModeHistory(char modeChar) : ColonDelimitedParamMode("HISTORY", modeChar) { }
-
- bool IsValid(Anope::string &value) const anope_override
- {
- return (ColonDelimitedParamMode::IsValid(value, true));
- }
-};
-
-class ChannelModeRedirect : public ChannelModeParam
-{
- public:
- ChannelModeRedirect(char modeChar) : ChannelModeParam("REDIRECT", modeChar, true) { }
-
- bool IsValid(Anope::string &value) const anope_override
- {
- // The parameter of this mode is a channel, and channel names start with '#'
- return ((!value.empty()) && (value[0] == '#'));
- }
-};
-
-struct IRCDMessageAway : Message::Away
-{
- IRCDMessageAway(Module *creator) : Message::Away(creator, "AWAY") { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- std::vector<Anope::string> newparams(params);
- if (newparams.size() > 1)
- newparams.erase(newparams.begin());
-
- Message::Away::Run(source, newparams);
- }
-};
-
-struct IRCDMessageCapab : Message::Capab
-{
- std::map<char, Anope::string> chmodes, umodes;
-
- IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (params[0].equals_cs("START"))
- {
- if (params.size() >= 2)
- spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0);
-
- if (spanningtree_proto_ver < 1202)
- {
- UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START";
- Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START";
- Anope::Quitting = true;
- return;
- }
-
- /* reset CAPAB */
- chmodes.clear();
- umodes.clear();
- Servers::Capab.insert("SERVERS");
- Servers::Capab.insert("TOPICLOCK");
- IRCD->CanSVSHold = false;
- IRCD->DefaultPseudoclientModes = "+I";
- }
- else if (params[0].equals_cs("CHANMODES") && params.size() > 1)
- {
- spacesepstream ssep(params[1]);
- Anope::string capab;
-
- while (ssep.GetToken(capab))
- {
- Anope::string modename = capab.substr(0, capab.find('='));
- Anope::string modechar = capab.substr(capab.find('=') + 1);
- ChannelMode *cm = NULL;
-
- if (modename.equals_cs("admin"))
- cm = new ChannelModeStatus("PROTECT", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 3);
- else if (modename.equals_cs("allowinvite"))
- {
- cm = new ChannelMode("ALLINVITE", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("INVITEBAN", "BAN", 'A'));
- }
- else if (modename.equals_cs("auditorium"))
- cm = new ChannelMode("AUDITORIUM", modechar[0]);
- else if (modename.equals_cs("autoop"))
- cm = new InspIRCdAutoOpMode(modechar[0]);
- else if (modename.equals_cs("ban"))
- cm = new ChannelModeList("BAN", modechar[0]);
- else if (modename.equals_cs("banexception"))
- cm = new ChannelModeList("EXCEPT", modechar[0]);
- else if (modename.equals_cs("blockcaps"))
- {
- cm = new ChannelMode("BLOCKCAPS", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCAPSBAN", "BAN", 'B'));
- }
- else if (modename.equals_cs("blockcolor"))
- {
- cm = new ChannelMode("BLOCKCOLOR", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCOLORBAN", "BAN", 'c'));
- }
- else if (modename.equals_cs("c_registered"))
- cm = new ChannelModeNoone("REGISTERED", modechar[0]);
- else if (modename.equals_cs("censor"))
- cm = new ChannelMode("CENSOR", modechar[0]);
- else if (modename.equals_cs("delayjoin"))
- cm = new ChannelMode("DELAYEDJOIN", modechar[0]);
- else if (modename.equals_cs("delaymsg"))
- cm = new SimpleNumberParamMode("DELAYMSG", modechar[0]);
- else if (modename.equals_cs("filter"))
- cm = new ChannelModeList("FILTER", modechar[0]);
- else if (modename.equals_cs("flood"))
- cm = new ChannelModeFlood(modechar[0]);
- else if (modename.equals_cs("founder"))
- cm = new ChannelModeStatus("OWNER", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 4);
- else if (modename.equals_cs("halfop"))
- cm = new ChannelModeStatus("HALFOP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 1);
- else if (modename.equals_cs("history"))
- cm = new ChannelModeHistory(modechar[0]);
- else if (modename.equals_cs("invex"))
- cm = new ChannelModeList("INVITEOVERRIDE", modechar[0]);
- else if (modename.equals_cs("inviteonly"))
- cm = new ChannelMode("INVITE", modechar[0]);
- else if (modename.equals_cs("joinflood"))
- cm = new ColonDelimitedParamMode("JOINFLOOD", modechar[0]);
- else if (modename.equals_cs("key"))
- cm = new ChannelModeKey(modechar[0]);
- else if (modename.equals_cs("kicknorejoin"))
- cm = new SimpleNumberParamMode("NOREJOIN", modechar[0]);
- else if (modename.equals_cs("limit"))
- cm = new ChannelModeParam("LIMIT", modechar[0], true);
- else if (modename.equals_cs("moderated"))
- cm = new ChannelMode("MODERATED", modechar[0]);
- else if (modename.equals_cs("nickflood"))
- cm = new ColonDelimitedParamMode("NICKFLOOD", modechar[0]);
- else if (modename.equals_cs("noctcp"))
- {
- cm = new ChannelMode("NOCTCP", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOCTCPBAN", "BAN", 'C'));
- }
- else if (modename.equals_cs("noextmsg"))
- cm = new ChannelMode("NOEXTERNAL", modechar[0]);
- else if (modename.equals_cs("nokick"))
- {
- cm = new ChannelMode("NOKICK", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOKICKBAN", "BAN", 'Q'));
- }
- else if (modename.equals_cs("noknock"))
- cm = new ChannelMode("NOKNOCK", modechar[0]);
- else if (modename.equals_cs("nonick"))
- {
- cm = new ChannelMode("NONICK", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONICKBAN", "BAN", 'N'));
- }
- else if (modename.equals_cs("nonotice"))
- {
- cm = new ChannelMode("NONOTICE", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONOTICEBAN", "BAN", 'T'));
- }
- else if (modename.equals_cs("official-join"))
- cm = new ChannelModeStatus("OFFICIALJOIN", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2);
- else if (modename.equals_cs("op"))
- cm = new ChannelModeStatus("OP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2);
- else if (modename.equals_cs("operonly"))
- cm = new ChannelModeOperOnly("OPERONLY", modechar[0]);
- else if (modename.equals_cs("operprefix"))
- cm = new ChannelModeStatus("OPERPREFIX", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2);
- else if (modename.equals_cs("permanent"))
- cm = new ChannelMode("PERM", modechar[0]);
- else if (modename.equals_cs("private"))
- cm = new ChannelMode("PRIVATE", modechar[0]);
- else if (modename.equals_cs("redirect"))
- cm = new ChannelModeRedirect(modechar[0]);
- else if (modename.equals_cs("reginvite"))
- cm = new ChannelMode("REGISTEREDONLY", modechar[0]);
- else if (modename.equals_cs("regmoderated"))
- cm = new ChannelMode("REGMODERATED", modechar[0]);
- else if (modename.equals_cs("secret"))
- cm = new ChannelMode("SECRET", modechar[0]);
- else if (modename.equals_cs("sslonly"))
- {
- cm = new ChannelMode("SSL", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::FingerprintMatcher("SSLBAN", "BAN", 'z'));
- }
- else if (modename.equals_cs("stripcolor"))
- {
- cm = new ChannelMode("STRIPCOLOR", modechar[0]);
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("STRIPCOLORBAN", "BAN", 'S'));
- }
- else if (modename.equals_cs("topiclock"))
- cm = new ChannelMode("TOPIC", modechar[0]);
- else if (modename.equals_cs("voice"))
- cm = new ChannelModeStatus("VOICE", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 0);
- /* Unknown status mode, (customprefix) - add it */
- else if (modechar.length() == 2)
- cm = new ChannelModeStatus(modename.upper(), modechar[1], modechar[0], -1);
- /* Unknown non status mode, add it to our list for later */
- else
- chmodes[modechar[0]] = modename.upper();
-
- if (cm)
- ModeManager::AddChannelMode(cm);
- }
- }
- if (params[0].equals_cs("USERMODES") && params.size() > 1)
- {
- spacesepstream ssep(params[1]);
- Anope::string capab;
-
- while (ssep.GetToken(capab))
- {
- Anope::string modename = capab.substr(0, capab.find('='));
- Anope::string modechar = capab.substr(capab.find('=') + 1);
- UserMode *um = NULL;
-
- if (modename.equals_cs("bot"))
- {
- um = new UserMode("BOT", modechar[0]);
- IRCD->DefaultPseudoclientModes += modechar;
- }
- else if (modename.equals_cs("callerid"))
- um = new UserMode("CALLERID", modechar[0]);
- else if (modename.equals_cs("cloak"))
- um = new UserMode("CLOAK", modechar[0]);
- else if (modename.equals_cs("deaf"))
- um = new UserMode("DEAF", modechar[0]);
- else if (modename.equals_cs("deaf_commonchan"))
- um = new UserMode("COMMONCHANS", modechar[0]);
- else if (modename.equals_cs("helpop"))
- um = new UserModeOperOnly("HELPOP", modechar[0]);
- else if (modename.equals_cs("hidechans"))
- um = new UserMode("PRIV", modechar[0]);
- else if (modename.equals_cs("hideoper"))
- um = new UserModeOperOnly("HIDEOPER", modechar[0]);
- else if (modename.equals_cs("invisible"))
- um = new UserMode("INVIS", modechar[0]);
- else if (modename.equals_cs("invis-oper"))
- um = new UserModeOperOnly("INVISIBLE_OPER", modechar[0]);
- else if (modename.equals_cs("oper"))
- um = new UserModeOperOnly("OPER", modechar[0]);
- else if (modename.equals_cs("regdeaf"))
- um = new UserMode("REGPRIV", modechar[0]);
- else if (modename.equals_cs("servprotect"))
- {
- um = new UserModeNoone("PROTECTED", modechar[0]);
- IRCD->DefaultPseudoclientModes += modechar;
- }
- else if (modename.equals_cs("showwhois"))
- um = new UserMode("WHOIS", modechar[0]);
- else if (modename.equals_cs("u_censor"))
- um = new UserMode("CENSOR", modechar[0]);
- else if (modename.equals_cs("u_registered"))
- um = new UserModeNoone("REGISTERED", modechar[0]);
- else if (modename.equals_cs("u_stripcolor"))
- um = new UserMode("STRIPCOLOR", modechar[0]);
- else if (modename.equals_cs("wallops"))
- um = new UserMode("WALLOPS", modechar[0]);
- else
- umodes[modechar[0]] = modename.upper();
-
- if (um)
- ModeManager::AddUserMode(um);
- }
- }
- else if (params[0].equals_cs("MODULES") && params.size() > 1)
- {
- spacesepstream ssep(params[1]);
- Anope::string module;
-
- while (ssep.GetToken(module))
- {
- if (module.equals_cs("m_svshold.so"))
- IRCD->CanSVSHold = true;
- else if (module.find("m_rline.so") == 0)
- {
- Servers::Capab.insert("RLINE");
- const Anope::string &regexengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
- if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11))
- Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << regexengine << ". This may cause inconsistencies.";
- }
- else if (module.equals_cs("m_topiclock.so"))
- Servers::Capab.insert("TOPICLOCK");
- }
- }
- else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1)
- {
- spacesepstream ssep(params[1]);
- Anope::string module;
-
- while (ssep.GetToken(module))
- {
- if (module.equals_cs("m_services_account.so"))
- {
- Servers::Capab.insert("SERVICES");
- ModeManager::AddChannelMode(new InspIRCdExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'R'));
- ModeManager::AddChannelMode(new InspIRCdExtban::UnidentifiedMatcher("UNREGISTEREDBAN", "BAN", 'U'));
- }
- else if (module.equals_cs("m_chghost.so"))
- Servers::Capab.insert("CHGHOST");
- else if (module.equals_cs("m_chgident.so"))
- Servers::Capab.insert("CHGIDENT");
- else if (module == "m_channelban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::ChannelMatcher("CHANNELBAN", "BAN", 'j'));
- else if (module == "m_gecosban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r'));
- else if (module == "m_nopartmsg.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("PARTMESSAGEBAN", "BAN", 'p'));
- else if (module == "m_serverban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::ServerMatcher("SERVERBAN", "BAN", 's'));
- else if (module == "m_muteban.so")
- ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("QUIET", "BAN", 'm'));
- }
- }
- else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1)
- {
- spacesepstream ssep(params[1]);
- Anope::string capab;
- while (ssep.GetToken(capab))
- {
- if (capab.find("CHANMODES") != Anope::string::npos)
- {
- Anope::string modes(capab.begin() + 10, capab.end());
- commasepstream sep(modes, true);
- Anope::string modebuf;
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- if (ModeManager::FindChannelModeByChar(modebuf[t]))
- continue;
- ModeManager::AddChannelMode(new ChannelModeList(chmodes[modebuf[t]], modebuf[t]));
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- if (ModeManager::FindChannelModeByChar(modebuf[t]))
- continue;
- ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t]));
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- if (ModeManager::FindChannelModeByChar(modebuf[t]))
- continue;
- ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t], true));
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- if (ModeManager::FindChannelModeByChar(modebuf[t]))
- continue;
- ModeManager::AddChannelMode(new ChannelMode(chmodes[modebuf[t]], modebuf[t]));
- }
- }
- else if (capab.find("USERMODES") != Anope::string::npos)
- {
- Anope::string modes(capab.begin() + 10, capab.end());
- commasepstream sep(modes, true);
- Anope::string modebuf;
-
- sep.GetToken(modebuf);
- sep.GetToken(modebuf);
-
- if (sep.GetToken(modebuf))
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- ModeManager::AddUserMode(new UserModeParam(umodes[modebuf[t]], modebuf[t]));
-
- if (sep.GetToken(modebuf))
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- ModeManager::AddUserMode(new UserMode(umodes[modebuf[t]], modebuf[t]));
- }
- else if (capab.find("MAXMODES=") != Anope::string::npos)
- {
- Anope::string maxmodes(capab.begin() + 9, capab.end());
- IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3;
- }
- else if (capab.find("PREFIX=") != Anope::string::npos)
- {
- Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')'));
- Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end());
- short level = modes.length() - 1;
-
- for (size_t t = 0, end = modes.length(); t < end; ++t)
- {
- ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[t]);
- if (cm == NULL || cm->type != MODE_STATUS)
- {
- Log() << "CAPAB PREFIX gave unknown channel status mode " << modes[t];
- continue;
- }
-
- ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm);
- cms->level = level--;
-
- Log(LOG_DEBUG) << cms->name << " is now level " << cms->level;
- }
-
- ModeManager::RebuildStatusModes();
- }
- else if (capab == "GLOBOPS=1")
- Servers::Capab.insert("GLOBOPS");
- }
- }
- else if (params[0].equals_cs("END"))
- {
- if (!Servers::Capab.count("SERVICES"))
- {
- UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope";
- Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required.";
- Anope::Quitting = true;
- return;
- }
- if (!ModeManager::FindUserModeByName("PRIV"))
- {
- UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope";
- Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required.";
- Anope::Quitting = true;
- return;
- }
- if (!IRCD->CanSVSHold)
- Log() << "SVSHOLD missing, Usage disabled until module is loaded.";
- if (!Servers::Capab.count("CHGHOST"))
- Log() << "CHGHOST missing, Usage disabled until module is loaded.";
- if (!Servers::Capab.count("CHGIDENT"))
- Log() << "CHGIDENT missing, Usage disabled until module is loaded.";
-
- chmodes.clear();
- umodes.clear();
- }
-
- Message::Capab::Run(source, params);
- }
-};
-
-struct IRCDMessageEncap : IRCDMessage
-{
- ServiceReference<IRCDMessage> insp12_encap;
-
- IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4), insp12_encap("IRCDMessage", "inspircd12/encap") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0]))
- return;
-
- if (params[1] == "CHGIDENT")
- {
- User *u = User::Find(params[2]);
- if (!u || u->server != Me)
- return;
-
- u->SetIdent(params[3]);
- UplinkSocket::Message(u) << "FIDENT :" << params[3];
- }
- else if (params[1] == "CHGHOST")
- {
- User *u = User::Find(params[2]);
- if (!u || u->server != Me)
- return;
-
- u->SetDisplayedHost(params[3]);
- UplinkSocket::Message(u) << "FHOST :" << params[3];
- }
- else if (params[1] == "CHGNAME")
- {
- User *u = User::Find(params[2]);
- if (!u || u->server != Me)
- return;
-
- u->SetRealname(params[3]);
- UplinkSocket::Message(u) << "FNAME :" << params[3];
- }
-
- if (insp12_encap)
- insp12_encap->Run(source, params);
- }
-};
-
-struct IRCDMessageFHost : IRCDMessage
-{
- IRCDMessageFHost(Module *creator) : IRCDMessage(creator, "FHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = source.GetUser();
- if (u->HasMode("CLOAK"))
- u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK"));
- u->SetDisplayedHost(params[0]);
- }
-};
-
-struct IRCDMessageFIdent : IRCDMessage
-{
- IRCDMessageFIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- source.GetUser()->SetIdent(params[0]);
- }
-};
-
-struct IRCDMessageSave : IRCDMessage
-{
- time_t last_collide;
-
- IRCDMessageSave(Module *creator) : IRCDMessage(creator, "SAVE", 2), last_collide(0) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *targ = User::Find(params[0]);
- time_t ts;
-
- try
- {
- ts = convertTo<time_t>(params[1]);
- }
- catch (const ConvertException &)
- {
- return;
- }
-
- if (!targ || targ->timestamp != ts)
- return;
-
- BotInfo *bi;
- if (targ->server == Me && (bi = dynamic_cast<BotInfo *>(targ)))
- {
- if (last_collide == Anope::CurTime)
- {
- Anope::QuitReason = "Nick collision fight on " + targ->nick;
- Anope::Quitting = true;
- return;
- }
-
- IRCD->SendKill(Me, targ->nick, "Nick collision");
- IRCD->SendNickChange(targ, targ->nick);
- last_collide = Anope::CurTime;
- }
- else
- targ->ChangeNick(targ->GetUID());
- }
-};
-
-class IRCDMessageMetadata : IRCDMessage
-{
- ServiceReference<IRCDMessage> insp12_metadata;
- const bool &do_topiclock;
- const bool &do_mlock;
-
- public:
- IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) : IRCDMessage(creator, "METADATA", 3), insp12_metadata("IRCDMessage", "inspircd12/metadata"), do_topiclock(handle_topiclock), do_mlock(handle_mlock) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- // We deliberately ignore non-bursting servers to avoid pseudoserver fights
- if ((params[0][0] == '#') && (!source.GetServer()->IsSynced()))
- {
- Channel *c = Channel::Find(params[0]);
- if (c && c->ci)
- {
- if ((do_mlock) && (params[1] == "mlock"))
- {
- ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks");
- Anope::string modes;
- if (modelocks)
- modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
-
- // Mode lock string is not what we say it is?
- if (modes != params[2])
- UplinkSocket::Message(Me) << "METADATA " << c->name << " mlock :" << modes;
- }
- else if ((do_topiclock) && (params[1] == "topiclock"))
- {
- bool mystate = c->ci->HasExt("TOPICLOCK");
- bool serverstate = (params[2] == "1");
- if (mystate != serverstate)
- UplinkSocket::Message(Me) << "METADATA " << c->name << " topiclock :" << (mystate ? "1" : "");
- }
- }
- }
-
- if (insp12_metadata)
- insp12_metadata->Run(source, params);
- }
-};
-
-class ProtoInspIRCd20 : public Module
-{
- Module *m_insp12;
-
- InspIRCd20Proto ircd_proto;
-
- /* Core message handlers */
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Join message_join;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::Stats message_stats;
- Message::Topic message_topic;
-
- /* InspIRCd 1.2 message handlers */
- ServiceAlias message_endburst, message_fjoin, message_fmode,
- message_ftopic, message_idle, message_mode,
- message_nick, message_opertype, message_rsquit, message_server,
- message_squit, message_time, message_uid;
-
- /* Our message handlers */
- IRCDMessageAway message_away;
- IRCDMessageCapab message_capab;
- IRCDMessageEncap message_encap;
- IRCDMessageFHost message_fhost;
- IRCDMessageFIdent message_fident;
- IRCDMessageMetadata message_metadata;
- IRCDMessageSave message_save;
-
- bool use_server_side_topiclock, use_server_side_mlock;
-
- void SendChannelMetadata(Channel *c, const Anope::string &metadataname, const Anope::string &value)
- {
- UplinkSocket::Message(Me) << "METADATA " << c->name << " " << metadataname << " :" << value;
- }
-
- public:
- ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
- ircd_proto(this),
- message_error(this), message_invite(this), message_join(this), message_kick(this), message_kill(this),
- message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this),
- message_quit(this), message_stats(this), message_topic(this),
-
- message_endburst("IRCDMessage", "inspircd20/endburst", "inspircd12/endburst"),
- message_fjoin("IRCDMessage", "inspircd20/fjoin", "inspircd12/fjoin"),
- message_fmode("IRCDMessage", "inspircd20/fmode", "inspircd12/fmode"),
- message_ftopic("IRCDMessage", "inspircd20/ftopic", "inspircd12/ftopic"),
- message_idle("IRCDMessage", "inspircd20/idle", "inspircd12/idle"),
- message_mode("IRCDMessage", "inspircd20/mode", "inspircd12/mode"),
- message_nick("IRCDMessage", "inspircd20/nick", "inspircd12/nick"),
- message_opertype("IRCDMessage", "inspircd20/opertype", "inspircd12/opertype"),
- message_rsquit("IRCDMessage", "inspircd20/rsquit", "inspircd12/rsquit"),
- message_server("IRCDMessage", "inspircd20/server", "inspircd12/server"),
- message_squit("IRCDMessage", "inspircd20/squit", "inspircd12/squit"),
- message_time("IRCDMessage", "inspircd20/time", "inspircd12/time"),
- message_uid("IRCDMessage", "inspircd20/uid", "inspircd12/uid"),
-
- message_away(this), message_capab(this), message_encap(this), message_fhost(this), message_fident(this),
- message_metadata(this, use_server_side_topiclock, use_server_side_mlock), message_save(this)
- {
-
- if (ModuleManager::LoadModule("inspircd12", User::Find(creator)) != MOD_ERR_OK)
- throw ModuleException("Unable to load inspircd12");
- m_insp12 = ModuleManager::FindModule("inspircd12");
- if (!m_insp12)
- throw ModuleException("Unable to find inspircd12");
- if (!insp12)
- throw ModuleException("No protocol interface for insp12");
- ModuleManager::DetachAll(m_insp12);
-
- }
-
- ~ProtoInspIRCd20()
- {
- m_insp12 = ModuleManager::FindModule("inspircd12");
- ModuleManager::UnloadModule(m_insp12, NULL);
- }
-
- void OnReload(Configuration::Conf *conf) anope_override
- {
- use_server_side_topiclock = conf->GetModule(this)->Get<bool>("use_server_side_topiclock");
- use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
- }
-
- void OnUserNickChange(User *u, const Anope::string &) anope_override
- {
- u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED"));
- }
-
- void OnChannelSync(Channel *c) anope_override
- {
- if (c->ci)
- this->OnChanRegistered(c->ci);
- }
-
- void OnChanRegistered(ChannelInfo *ci) anope_override
- {
- ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
- if (use_server_side_mlock && ci->c && modelocks && !modelocks->GetMLockAsString(false).empty())
- {
- Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
- SendChannelMetadata(ci->c, "mlock", modes);
- }
-
- if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c)
- {
- if (ci->HasExt("TOPICLOCK"))
- SendChannelMetadata(ci->c, "topiclock", "1");
- }
- }
-
- void OnDelChan(ChannelInfo *ci) anope_override
- {
- if (use_server_side_mlock && ci->c)
- SendChannelMetadata(ci->c, "mlock", "");
-
- if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c)
- SendChannelMetadata(ci->c, "topiclock", "");
- }
-
- EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
- {
- ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
- ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
- if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM))
- {
- Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar;
- SendChannelMetadata(ci->c, "mlock", modes);
- }
-
- return EVENT_CONTINUE;
- }
-
- EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
- {
- ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
- ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
- if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM))
- {
- Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, "");
- SendChannelMetadata(ci->c, "mlock", modes);
- }
-
- return EVENT_CONTINUE;
- }
-
- EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) anope_override
- {
- if (cmd->name == "chanserv/topic" && ci->c)
- {
- if (setting == "topiclock on")
- SendChannelMetadata(ci->c, "topiclock", "1");
- else if (setting == "topiclock off")
- SendChannelMetadata(ci->c, "topiclock", "0");
- }
-
- return EVENT_CONTINUE;
- }
-};
-
-MODULE_INIT(ProtoInspIRCd20)
diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp
index 1c24e4baf..ea9d92294 100644
--- a/modules/protocol/ngircd.cpp
+++ b/modules/protocol/ngircd.cpp
@@ -10,16 +10,23 @@
*/
#include "module.h"
+#include "numeric.h"
-class ngIRCdProto : public IRCDProto
+namespace
{
- void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
+ size_t nicklen = 0;
+}
+
+class ngIRCdProto final
+ : public IRCDProto
+{
+ void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override
{
- IRCDProto::SendSVSKillInternal(source, user, buf);
+ IRCDProto::SendSVSKill(source, user, buf);
user->KillInternal(source, buf);
}
- public:
+public:
ngIRCdProto(Module *creator) : IRCDProto(creator, "ngIRCd")
{
DefaultPseudoclientModes = "+oi";
@@ -30,64 +37,68 @@ class ngIRCdProto : public IRCDProto
MaxModes = 5;
}
- void SendAkill(User *u, XLine *x) anope_override
+ size_t GetMaxNick() override
{
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
- UplinkSocket::Message(Me) << "GLINE " << x->mask << " " << timeleft << " :" << x->GetReason() << " (" << x->by << ")";
+ return nicklen ? nicklen : IRCDProto::GetMaxNick();
}
- void SendAkillDel(const XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) override
{
- UplinkSocket::Message(Me) << "GLINE " << x->mask;
+ // Calculate the time left before this would expire
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
+ Uplink::Send("GLINE", x->mask, timeleft, x->GetReason() + " (" + x->by + ")");
}
- void SendChannel(Channel *c) anope_override
+ void SendAkillDel(const XLine *x) override
{
- UplinkSocket::Message(Me) << "CHANINFO " << c->name << " +" << c->GetModes(true, true);
+ Uplink::Send("GLINE", x->mask);
+ }
+
+ void SendChannel(Channel *c) override
+ {
+ Uplink::Send("CHANINFO", c->name, "+" + c->GetModes(true, true));
}
// Received: :dev.anope.de NICK DukeP 1 ~DukePyro p57ABF9C9.dip.t-dialin.net 1 +i :DukePyrolator
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me) << "NICK " << u->nick << " 1 " << u->GetIdent() << " " << u->host << " 1 " << modes << " :" << u->realname;
+ Uplink::Send("NICK", u->nick, 1, u->GetIdent(), u->host, 1, "+" + u->GetModes(), u->realname);
}
- void SendConnect() anope_override
+ void SendConnect() override
{
- UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " 0210-IRC+ Anope|" << Anope::VersionShort() << ":CLHMSo P";
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "0210-IRC+", "Anope|" + Anope::VersionShort() + ":CLHMSo P");
+
/* Make myself known to myself in the serverlist */
SendServer(Me);
+
/* finish the enhanced server handshake and register the connection */
- this->SendNumeric(376, "*", ":End of MOTD command");
+ this->SendNumeric(RPL_ENDOFMOTD, "*", "End of MOTD command");
}
- void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override
+ void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override
{
- UplinkSocket::Message(Me) << "SVSNICK " << u->nick << " " << newnick;
+ Uplink::Send("SVSNICK", u->nick, newnick);
}
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg);
}
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg);
}
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
+ void SendGlobops(const MessageSource &source, const Anope::string &buf) override
{
- UplinkSocket::Message(source) << "WALLOPS :" << buf;
+ Uplink::Send(source, "WALLOPS", buf);
}
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override
{
- UplinkSocket::Message(user) << "JOIN " << c->name;
+ Uplink::Send(user, "JOIN", c->name);
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -100,36 +111,36 @@ class ngIRCdProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
- void SendLogin(User *u, NickAlias *na) anope_override
+ void SendLogin(User *u, NickAlias *na) override
{
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display;
+ Uplink::Send("METADATA", u->GetUID(), "accountname", na->nc->display);
}
- void SendLogout(User *u) anope_override
+ void SendLogout(User *u) override
{
- UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :";
+ Uplink::Send("METADATA", u->GetUID(), "accountname", "");
}
/* SERVER name hop descript */
- void SendServer(const Server *server) anope_override
+ void SendServer(const Server *server) override
{
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription();
+ Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription());
}
- void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
+ void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override
{
if (!vIdent.empty())
- UplinkSocket::Message(Me) << "METADATA " << u->nick << " user :" << vIdent;
+ Uplink::Send("METADATA", u->nick, "user", vIdent);
- UplinkSocket::Message(Me) << "METADATA " << u->nick << " cloakhost :" << vhost;
+ Uplink::Send("METADATA", u->nick, "cloakhost", vhost);
if (!u->HasMode("CLOAK"))
{
u->SetMode(Config->GetClient("HostServ"), "CLOAK");
@@ -137,52 +148,49 @@ class ngIRCdProto : public IRCDProto
}
}
- void SendVhostDel(User *u) anope_override
+ void SendVhostDel(User *u) override
{
this->SendVhost(u, u->GetIdent(), "");
}
- Anope::string Format(const Anope::string &source, const Anope::string &message) anope_override
+ bool Format(Anope::string &message, const Anope::map<Anope::string> &tags, const MessageSource &source, const Anope::string &command, const std::vector<Anope::string> &params) override
{
- return IRCDProto::Format(source.empty() ? Me->GetSID() : source, message);
+ return IRCDProto::Format(message, tags, source.GetSource().empty() ? Me : source, command, params);
}
};
-struct IRCDMessage005 : IRCDMessage
+struct IRCDMessage005 final
+ : IRCDMessage
{
- IRCDMessage005(Module *creator) : IRCDMessage(creator, "005", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessage005(Module *creator) : IRCDMessage(creator, "005", 1) { SetFlag(FLAG_SOFT_LIMIT); }
// Please see <http://www.irc.org/tech_docs/005.html> for details.
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
size_t pos;
Anope::string parameter, data;
- for (unsigned i = 0, end = params.size(); i < end; ++i)
+ for (const auto &param : params)
{
- pos = params[i].find('=');
+ pos = param.find('=');
if (pos != Anope::string::npos)
{
- parameter = params[i].substr(0, pos);
- data = params[i].substr(pos+1, params[i].length());
+ parameter = param.substr(0, pos);
+ data = param.substr(pos+1, param.length());
if (parameter == "MODES")
{
- unsigned maxmodes = convertTo<unsigned>(data);
- IRCD->MaxModes = maxmodes;
+ IRCD->MaxModes = Anope::Convert<unsigned>(data, IRCD->MaxModes);
}
else if (parameter == "NICKLEN")
{
- unsigned newlen = convertTo<unsigned>(data), len = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen");
- if (len != newlen)
- {
- Log() << "Warning: NICKLEN is " << newlen << " but networkinfo:nicklen is " << len;
- }
+ nicklen = Anope::Convert<size_t>(data, 0);
}
}
}
}
};
-struct IRCDMessage376 : IRCDMessage
+struct IRCDMessage376 final
+ : IRCDMessage
{
IRCDMessage376(Module *creator) : IRCDMessage(creator, "376", 2) { }
@@ -194,14 +202,15 @@ struct IRCDMessage376 : IRCDMessage
*
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
}
};
-struct IRCDMessageChaninfo : IRCDMessage
+struct IRCDMessageChaninfo final
+ : IRCDMessage
{
- IRCDMessageChaninfo(Module *creator) : IRCDMessage(creator, "CHANINFO", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageChaninfo(Module *creator) : IRCDMessage(creator, "CHANINFO", 2) { SetFlag(FLAG_SOFT_LIMIT); SetFlag(FLAG_REQUIRE_SERVER); }
/*
* CHANINFO is used by servers to inform each other about a channel: its
@@ -220,7 +229,7 @@ struct IRCDMessageChaninfo : IRCDMessage
* a channel has no user limit (the parameter <modes> doesn't list the "l"
* channel mode). In this case <limit> should be "0".
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
bool created;
Channel *c = Channel::FindOrCreate(params[0], created);
@@ -252,9 +261,10 @@ struct IRCDMessageChaninfo : IRCDMessage
}
};
-struct IRCDMessageJoin : Message::Join
+struct IRCDMessageJoin final
+ : Message::Join
{
- IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { SetFlag(FLAG_REQUIRE_USER); }
/*
* <@po||ux> DukeP: RFC 2813, 4.2.1: the JOIN command on server-server links
@@ -262,7 +272,7 @@ struct IRCDMessageJoin : Message::Join
*
* if a user joins a new channel, the ircd sends <channelname>\7<umode>
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *user = source.GetUser();
size_t pos = params[0].find('\7');
@@ -281,7 +291,7 @@ struct IRCDMessageJoin : Message::Join
std::vector<Anope::string> new_params;
new_params.push_back(channel);
- Message::Join::Run(source, new_params);
+ Message::Join::Run(source, new_params, tags);
if (!modes.empty())
{
@@ -292,9 +302,10 @@ struct IRCDMessageJoin : Message::Join
}
};
-struct IRCDMessageMetadata : IRCDMessage
+struct IRCDMessageMetadata final
+ : IRCDMessage
{
- IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
/*
* Received: :ngircd.dev.anope.de METADATA DukePyrolator host :anope-e2ee5c7d
@@ -312,7 +323,7 @@ struct IRCDMessageMetadata : IRCDMessage
* - "user": the user name (ident) of a client (can't be empty)
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = User::Find(params[0]);
if (!u)
@@ -351,9 +362,10 @@ struct IRCDMessageMetadata : IRCDMessage
}
};
-struct IRCDMessageMode : IRCDMessage
+struct IRCDMessageMode final
+ : IRCDMessage
{
- IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(FLAG_SOFT_LIMIT); }
/*
* Received: :DukeP MODE #anope +b *!*@*.aol.com
@@ -363,7 +375,7 @@ struct IRCDMessageMode : IRCDMessage
* params[n] = parameters
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Anope::string modes = params[1];
@@ -382,14 +394,15 @@ struct IRCDMessageMode : IRCDMessage
User *u = User::Find(params[0]);
if (u)
- u->SetModesInternal(source, "%s", params[1].c_str());
+ u->SetModesInternal(source, params[1]);
}
}
};
-struct IRCDMessageNick : IRCDMessage
+struct IRCDMessageNick final
+ : IRCDMessage
{
- IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 1) { SetFlag(FLAG_SOFT_LIMIT); }
/*
* NICK - NEW
@@ -410,7 +423,7 @@ struct IRCDMessageNick : IRCDMessage
* params[0] = newnick
*
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() == 1)
{
@@ -439,9 +452,10 @@ struct IRCDMessageNick : IRCDMessage
}
};
-struct IRCDMessageNJoin : IRCDMessage
+struct IRCDMessageNJoin final
+ : IRCDMessage
{
- IRCDMessageNJoin(Module *creator) : IRCDMessage(creator, "NJOIN",2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); };
+ IRCDMessageNJoin(Module *creator) : IRCDMessage(creator, "NJOIN",2) { SetFlag(FLAG_REQUIRE_SERVER); };
/*
* RFC 2813, 4.2.2: Njoin Message:
@@ -454,7 +468,7 @@ struct IRCDMessageNJoin : IRCDMessage
*
* Received: :dev.anope.de NJOIN #test :DukeP2,@DukeP,%test,+test2
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
std::list<Message::Join::SJoinUser> users;
@@ -485,25 +499,27 @@ struct IRCDMessageNJoin : IRCDMessage
}
};
-struct IRCDMessagePong : IRCDMessage
+struct IRCDMessagePong final
+ : IRCDMessage
{
- IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(FLAG_SOFT_LIMIT); SetFlag(FLAG_REQUIRE_SERVER); }
/*
* ngIRCd does not send an EOB, so we send a PING immediately
* when receiving a new server and then finish sync once we
* get a pong back from that server.
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (!source.GetServer()->IsSynced())
source.GetServer()->Sync(false);
}
};
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_SOFT_LIMIT); }
/*
* New directly linked server:
@@ -530,7 +546,7 @@ struct IRCDMessageServer : IRCDMessage
* params[3] = server description
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() == 3)
{
@@ -540,7 +556,7 @@ struct IRCDMessageServer : IRCDMessage
else
{
// our uplink is introducing a new server
- unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
+ auto hops = Anope::Convert<unsigned>(params[1], 0);
new Server(source.GetServer(), params[0], hops, params[3], params[2]);
}
/*
@@ -552,12 +568,13 @@ struct IRCDMessageServer : IRCDMessage
}
};
-struct IRCDMessageTopic : IRCDMessage
+struct IRCDMessageTopic final
+ : IRCDMessage
{
- IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 2) { SetFlag(FLAG_SOFT_LIMIT); }
// Received: :DukeP TOPIC #anope :test
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Channel *c = Channel::Find(params[0]);
if (!c)
@@ -571,7 +588,8 @@ struct IRCDMessageTopic : IRCDMessage
-class ProtongIRCd : public Module
+class ProtongIRCd final
+ : public Module
{
ngIRCdProto ircd_proto;
@@ -606,7 +624,7 @@ class ProtongIRCd : public Module
IRCDMessageServer message_server;
IRCDMessageTopic message_topic;
- void AddModes()
+ static void AddModes()
{
/* Add user modes */
ModeManager::AddUserMode(new UserMode("NOCTCP", 'b'));
@@ -651,7 +669,7 @@ class ProtongIRCd : public Module
ModeManager::AddChannelMode(new ChannelMode("SSL", 'z'));
}
- public:
+public:
ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_capab(this), message_error(this), message_invite(this), message_kick(this), message_kill(this),
@@ -670,7 +688,7 @@ class ProtongIRCd : public Module
}
- void OnUserNickChange(User *u, const Anope::string &) anope_override
+ void OnUserNickChange(User *u, const Anope::string &) override
{
u->RemoveMode(Config->GetClient("NickServ"), "REGISTERED");
}
diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp
index 62618ec82..77ab81d38 100644
--- a/modules/protocol/plexus.cpp
+++ b/modules/protocol/plexus.cpp
@@ -16,9 +16,10 @@ static Anope::string UplinkSID;
static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid");
-class PlexusProto : public IRCDProto
+class PlexusProto final
+ : public IRCDProto
{
- public:
+public:
PlexusProto(Module *creator) : IRCDProto(creator, "hybrid-7.2.3+plexus-3.0.1")
{
DefaultPseudoclientModes = "+iU";
@@ -35,28 +36,28 @@ class PlexusProto : public IRCDProto
MaxModes = 4;
}
- void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override { hybrid->SendSVSKillInternal(source, targ, reason); }
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); }
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); }
- void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); }
- void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); }
- void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); }
- void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); }
- void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); }
- void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); }
- void SendServer(const Server *server) anope_override { hybrid->SendServer(server); }
- void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); }
- void SendSVSHold(const Anope::string &nick, time_t t) anope_override { hybrid->SendSVSHold(nick, t); }
- void SendSVSHoldDel(const Anope::string &nick) anope_override { hybrid->SendSVSHoldDel(nick); }
-
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
+ void SendSVSKill(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKill(source, targ, reason); }
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); }
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); }
+ void SendSQLine(User *u, const XLine *x) override { hybrid->SendSQLine(u, x); }
+ void SendSQLineDel(const XLine *x) override { hybrid->SendSQLineDel(x); }
+ void SendSGLineDel(const XLine *x) override { hybrid->SendSGLineDel(x); }
+ void SendSGLine(User *u, const XLine *x) override { hybrid->SendSGLine(u, x); }
+ void SendAkillDel(const XLine *x) override { hybrid->SendAkillDel(x); }
+ void SendAkill(User *u, XLine *x) override { hybrid->SendAkill(u, x); }
+ void SendServer(const Server *server) override { hybrid->SendServer(server); }
+ void SendChannel(Channel *c) override { hybrid->SendChannel(c); }
+ void SendSVSHold(const Anope::string &nick, time_t t) override { hybrid->SendSVSHold(nick, t); }
+ void SendSVSHoldDel(const Anope::string &nick) override { hybrid->SendSVSHoldDel(nick); }
+
+ void SendGlobops(const MessageSource &source, const Anope::string &buf) override
{
- UplinkSocket::Message(source) << "OPERWALL :" << buf;
+ Uplink::Send(source, "OPERWALL", buf);
}
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override
{
- UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID();
+ Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), user->GetUID());
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -69,35 +70,37 @@ class PlexusProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
}
}
- void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override
+ void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override
{
- UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when;
+ Uplink::Send("ENCAP", u->server->GetName(), "SVSNICK", u->GetUID(), u->timestamp, newnick, when);
}
- void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override
+ void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override
{
if (!ident.empty())
- UplinkSocket::Message(Me) << "ENCAP * CHGIDENT " << u->GetUID() << " " << ident;
- UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " " << host;
+ Uplink::Send("ENCAP", '*', "CHGIDENT", u->GetUID(), ident);
+
+ Uplink::Send("ENCAP", '*', "CHGHOST", u->GetUID(), host);
u->SetMode(Config->GetClient("HostServ"), "CLOAK");
}
- void SendVhostDel(User *u) anope_override
+ void SendVhostDel(User *u) override
{
u->RemoveMode(Config->GetClient("HostServ"), "CLOAK");
}
- void SendConnect() anope_override
+ void SendConnect() override
{
- UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID();
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID());
+
/* CAPAB
* QS - Can handle quit storm removal
* EX - Can do channel +e exemptions
@@ -118,7 +121,8 @@ class PlexusProto : public IRCDProto
* ENCAP - Supports encapsulation of protocol messages
* SVS - Supports services protocol extensions
*/
- UplinkSocket::Message() << "CAPAB :QS EX CHW IE EOB KLN UNKLN GLN HUB KNOCK TBURST PARA ENCAP SVS";
+ Uplink::Send("CAPAB", "QS EX CHW IE EOB KLN UNKLN GLN HUB KNOCK TBURST PARA ENCAP SVS");
+
/* Make myself known to myself in the serverlist */
SendServer(Me);
/*
@@ -129,69 +133,74 @@ class PlexusProto : public IRCDProto
* parv[3] = server is standalone or connected to non-TS only
* parv[4] = server's idea of UTC time
*/
- UplinkSocket::Message() << "SVINFO 6 5 0 :" << Anope::CurTime;
+ Uplink::Send("SVINFO", 6, 5, 0, Anope::CurTime);
}
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 255.255.255.255 " << u->GetUID() << " 0 " << u->host << " :" << u->realname;
+ Uplink::Send("UID", u->nick, 1, u->timestamp, "+" + u->GetModes(), u->GetIdent(), u->host, "255.255.255.255", u->GetUID(), 0, u->host, u->realname);
}
- void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
+ void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values) override
{
- UplinkSocket::Message(source) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf;
+ auto params = values;
+ params.insert(params.begin(), { "*", "SVSMODE", u->GetUID(), Anope::ToString(u->timestamp), modes });
+ Uplink::SendInternal({}, source, "ENCAP", params);
}
- void SendLogin(User *u, NickAlias *na) anope_override
+ void SendLogin(User *u, NickAlias *na) override
{
- UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->nc->display;
+ Uplink::Send("ENCAP", '*', "SU", u->GetUID(), na->nc->display);
}
- void SendLogout(User *u) anope_override
+ void SendLogout(User *u) override
{
- UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID();
+ Uplink::Send("ENCAP", '*', "SU", u->GetUID());
}
- void SendTopic(const MessageSource &source, Channel *c) anope_override
+ void SendTopic(const MessageSource &source, Channel *c) override
{
- UplinkSocket::Message(source) << "ENCAP * TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic;
+ Uplink::Send(source, "ENCAP", '*', "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic);
}
- void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) anope_override
+ void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) override
{
- UplinkSocket::Message(source) << "ENCAP " << user->server->GetName() << " SVSJOIN " << user->GetUID() << " " << chan;
+ Uplink::Send(source, "ENCAP", '*', "SVSJOIN", user->GetUID(), chan);
}
- void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) anope_override
+ void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) override
{
- UplinkSocket::Message(source) << "ENCAP " << user->server->GetName() << " SVSPART " << user->GetUID() << " " << chan;
+ Uplink::Send(source, "ENCAP", '*', "SVSPART", user->GetUID(), chan);
}
- void SendSASLMessage(const SASL::Message &message) anope_override
+ void SendSASLMessage(const SASL::Message &message) override
{
Server *s = Server::Find(message.target.substr(0, 3));
- UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : message.target.substr(0, 3)) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext));
+ auto target = s ? s->GetName() : message.target.substr(0, 3);
+ if (message.ext.empty())
+ Uplink::Send("ENCAP", target, "SASL", message.source, message.target, message.type, message.data);
+ else
+ Uplink::Send("ENCAP", target, "SASL", message.source, message.target, message.type, message.data, message.ext);
}
- void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override
+ void SendSVSLogin(const Anope::string &uid, NickAlias *na) override
{
Server *s = Server::Find(uid.substr(0, 3));
- UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : uid.substr(0, 3)) << " SVSLOGIN " << uid << " * * "
- << (vhost.empty() ? "*" : vhost) << " " << acc;
+ Uplink::Send("ENCAP", s ? s->GetName() : uid.substr(0, 3), "SVSLOGIN", uid, '*', '*', na->GetVhostHost().empty() ? "*" : na->GetVhostHost(), na->nc->display);
}
- void SendSVSNOOP(const Server *server, bool set) anope_override
+ void SendSVSNOOP(const Server *server, bool set) override
{
- UplinkSocket::Message() << "ENCAP " << server->GetName() << " SVSNOOP " << (set ? "+" : "-");
+ Uplink::Send("ENCAP", '*', "SVSNOOP", set ? '+' : '-');
}
};
-struct IRCDMessageEncap : IRCDMessage
+struct IRCDMessageEncap final
+ : IRCDMessage
{
- IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/*
* Received: :dev.anope.de ENCAP * SU DukePyrolator DukePyrolator
@@ -243,23 +252,25 @@ struct IRCDMessageEncap : IRCDMessage
}
};
-struct IRCDMessagePass : IRCDMessage
+struct IRCDMessagePass final
+ : IRCDMessage
{
- IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
UplinkSID = params[3];
}
};
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
/* 0 1 2 */
/* SERVER hades.arpa 1 :ircd-hybrid test server */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* Servers other than our immediate uplink are introduced via SID */
if (params[1] != "1")
@@ -269,9 +280,10 @@ struct IRCDMessageServer : IRCDMessage
}
};
-struct IRCDMessageUID : IRCDMessage
+struct IRCDMessageUID final
+ : IRCDMessage
{
- IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(FLAG_REQUIRE_SERVER); }
/*
params[0] = nick
@@ -287,30 +299,18 @@ struct IRCDMessageUID : IRCDMessage
params[10] = info
*/
// :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB 0 192.168.0.5 :Adam
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* An IP of 0 means the user is spoofed */
Anope::string ip = params[6];
if (ip == "0")
ip.clear();
- time_t ts;
- try
- {
- ts = convertTo<time_t>(params[2]);
- }
- catch (const ConvertException &)
- {
- ts = Anope::CurTime;
- }
-
+ auto ts = IRCD->ExtractTimestamp(params[2]);
NickAlias *na = NULL;
- try
- {
- if (params[8].is_pos_number_only() && convertTo<time_t>(params[8]) == ts)
- na = NickAlias::Find(params[0]);
- }
- catch (const ConvertException &) { }
+ if (IRCD->ExtractTimestamp(params[8]) == ts)
+ na = NickAlias::Find(params[0]);
+
if (params[8] != "0" && !na)
na = NickAlias::Find(params[8]);
@@ -318,7 +318,8 @@ struct IRCDMessageUID : IRCDMessage
}
};
-class ProtoPlexus : public Module
+class ProtoPlexus final
+ : public Module
{
Module *m_hybrid;
@@ -355,7 +356,7 @@ class ProtoPlexus : public Module
IRCDMessageServer message_server;
IRCDMessageUID message_uid;
- void AddModes()
+ static void AddModes()
{
/* Add user modes */
ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a'));
@@ -413,7 +414,7 @@ class ProtoPlexus : public Module
ModeManager::AddChannelMode(new ChannelMode("PERM", 'z'));
}
- public:
+public:
ProtoPlexus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), message_kill(this),
@@ -441,7 +442,7 @@ class ProtoPlexus : public Module
this->AddModes();
}
- ~ProtoPlexus()
+ ~ProtoPlexus() override
{
m_hybrid = ModuleManager::FindModule("hybrid");
ModuleManager::UnloadModule(m_hybrid, NULL);
diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp
index 514079b68..5dfa6b0e2 100644
--- a/modules/protocol/ratbox.cpp
+++ b/modules/protocol/ratbox.cpp
@@ -15,23 +15,24 @@ static Anope::string UplinkSID;
static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid");
-class RatboxProto : public IRCDProto
+class RatboxProto final
+ : public IRCDProto
{
- BotInfo *FindIntroduced()
+ static BotInfo *FindIntroduced()
{
BotInfo *bi = Config->GetClient("OperServ");
if (bi && bi->introduced)
return bi;
- for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
- if (it->second->introduced)
- return it->second;
+ for (const auto &[_, bi] : *BotListByNick)
+ if (bi->introduced)
+ return bi;
return NULL;
}
- public:
+public:
RatboxProto(Module *creator) : IRCDProto(creator, "Ratbox 3.0+")
{
DefaultPseudoclientModes = "+oiS";
@@ -43,43 +44,40 @@ class RatboxProto : public IRCDProto
MaxModes = 4;
}
- void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override { hybrid->SendSVSKillInternal(source, targ, reason); }
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); }
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); }
- void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); }
- void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); }
- void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); }
- void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); }
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { hybrid->SendJoin(user, c, status); }
- void SendServer(const Server *server) anope_override { hybrid->SendServer(server); }
- void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override { hybrid->SendModeInternal(source, u, buf); }
- void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); }
- bool IsIdentValid(const Anope::string &ident) anope_override { return hybrid->IsIdentValid(ident); }
-
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
+ void SendSVSKill(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKill(source, targ, reason); }
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); }
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); }
+ void SendSGLine(User *u, const XLine *x) override { hybrid->SendSGLine(u, x); }
+ void SendSGLineDel(const XLine *x) override { hybrid->SendSGLineDel(x); }
+ void SendAkill(User *u, XLine *x) override { hybrid->SendAkill(u, x); }
+ void SendAkillDel(const XLine *x) override { hybrid->SendAkillDel(x); }
+ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { hybrid->SendJoin(user, c, status); }
+ void SendServer(const Server *server) override { hybrid->SendServer(server); }
+ void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values) override { hybrid->SendModeInternal(source, u, modes, values); }
+ void SendChannel(Channel *c) override { hybrid->SendChannel(c); }
+ bool IsIdentValid(const Anope::string &ident) override { return hybrid->IsIdentValid(ident); }
+
+ void SendGlobops(const MessageSource &source, const Anope::string &buf) override
{
- UplinkSocket::Message(source) << "OPERWALL :" << buf;
+ Uplink::Send(source, "OPERWALL", buf);
}
- void SendSQLine(User *, const XLine *x) anope_override
+ void SendSQLine(User *, const XLine *x) override
{
- /* Calculate the time left before this would expire, capping it at 2 days */
- time_t timeleft = x->expires - Anope::CurTime;
-
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
-
- UplinkSocket::Message(FindIntroduced()) << "ENCAP * RESV " << timeleft << " " << x->mask << " 0 :" << x->GetReason();
+ // Calculate the time left before this would expire
+ time_t timeleft = x->expires ? x->expires - Anope::CurTime : x->expires;
+ Uplink::Send(FindIntroduced(), "ENCAP", '*', "RESV", timeleft, x->mask, 0, x->GetReason());
}
- void SendSQLineDel(const XLine *x) anope_override
+ void SendSQLineDel(const XLine *x) override
{
- UplinkSocket::Message(Config->GetClient("OperServ")) << "ENCAP * UNRESV " << x->mask;
+ Uplink::Send(FindIntroduced(), "ENCAP", '*', "UNRESV", x->mask);
}
- void SendConnect() anope_override
+ void SendConnect() override
{
- UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID();
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID());
+
/*
QS - Can handle quit storm removal
EX - Can do channel +e exemptions
@@ -90,9 +88,11 @@ class RatboxProto : public IRCDProto
TB - supports topic burst
ENCAP - supports ENCAP
*/
- UplinkSocket::Message() << "CAPAB :QS EX CHW IE GLN TB ENCAP";
+ Uplink::Send("CAPAB", "QS EX CHW IE GLN TB ENCAP");
+
/* Make myself known to myself in the serverlist */
SendServer(Me);
+
/*
* SVINFO
* parv[0] = sender prefix
@@ -101,29 +101,28 @@ class RatboxProto : public IRCDProto
* parv[3] = server is standalone or connected to non-TS only
* parv[4] = server's idea of UTC time
*/
- UplinkSocket::Message() << "SVINFO 6 3 0 :" << Anope::CurTime;
+ Uplink::Send("SVINFO", 6, 3, 0, Anope::CurTime);
}
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname;
+ Uplink::Send("UID", u->nick, 1, u->timestamp, "+" + u->GetModes(), u->GetIdent(), u->host, 0, u->GetUID(), u->realname);
}
- void SendLogin(User *u, NickAlias *na) anope_override
+ void SendLogin(User *u, NickAlias *na) override
{
if (na->nc->HasExt("UNCONFIRMED"))
return;
- UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->nc->display;
+ Uplink::Send("ENCAP", '*', "SU", u->GetUID(), na->nc->display);
}
- void SendLogout(User *u) anope_override
+ void SendLogout(User *u) override
{
- UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID();
+ Uplink::Send("ENCAP", '*', "SU", u->GetUID());
}
- void SendTopic(const MessageSource &source, Channel *c) anope_override
+ void SendTopic(const MessageSource &source, Channel *c) override
{
BotInfo *bi = source.GetBot();
bool needjoin = c->FindUser(bi) == NULL;
@@ -143,12 +142,13 @@ class RatboxProto : public IRCDProto
}
};
-struct IRCDMessageEncap : IRCDMessage
+struct IRCDMessageEncap final
+ : IRCDMessage
{
- IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(FLAG_REQUIRE_USER); }
// Debug: Received: :00BAAAAAB ENCAP * LOGIN Adam
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params[1] == "LOGIN" || params[1] == "SU")
{
@@ -168,14 +168,15 @@ struct IRCDMessageEncap : IRCDMessage
}
};
-struct IRCDMessageJoin : Message::Join
+struct IRCDMessageJoin final
+ : Message::Join
{
IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() == 1 && params[0] == "0")
- return Message::Join::Run(source, params);
+ return Message::Join::Run(source, params, tags);
if (params.size() < 2)
return;
@@ -183,26 +184,28 @@ struct IRCDMessageJoin : Message::Join
std::vector<Anope::string> p = params;
p.erase(p.begin());
- return Message::Join::Run(source, p);
+ return Message::Join::Run(source, p, tags);
}
};
-struct IRCDMessagePass : IRCDMessage
+struct IRCDMessagePass final
+ : IRCDMessage
{
- IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
UplinkSID = params[3];
}
};
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
// SERVER hades.arpa 1 :ircd-ratbox test server
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// Servers other then our immediate uplink are introduced via SID
if (params[1] != "1")
@@ -212,9 +215,10 @@ struct IRCDMessageServer : IRCDMessage
}
};
-struct IRCDMessageTBurst : IRCDMessage
+struct IRCDMessageTBurst final
+ : IRCDMessage
{
- IRCDMessageTBurst(Module *creator) : IRCDMessage(creator, "TB", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageTBurst(Module *creator) : IRCDMessage(creator, "TB", 3) { SetFlag(FLAG_SOFT_LIMIT); }
/*
* params[0] = channel
@@ -222,9 +226,9 @@ struct IRCDMessageTBurst : IRCDMessage
* params[2] = topic OR who set the topic
* params[3] = topic if params[2] isn't the topic
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- time_t topic_time = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime;
+ auto topic_time = IRCD->ExtractTimestamp(params[1]);
Channel *c = Channel::Find(params[0]);
if (!c)
@@ -237,19 +241,21 @@ struct IRCDMessageTBurst : IRCDMessage
}
};
-struct IRCDMessageUID : IRCDMessage
+struct IRCDMessageUID final
+ : IRCDMessage
{
- IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 9) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 9) { SetFlag(FLAG_REQUIRE_SERVER); }
// :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB :Adam
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* Source is always the server */
- User::OnIntroduce(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3], params[7], NULL);
+ User::OnIntroduce(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], IRCD->ExtractTimestamp(params[2]), params[3], params[7], NULL);
}
};
-class ProtoRatbox : public Module
+class ProtoRatbox final
+ : public Module
{
Module *m_hybrid;
@@ -288,7 +294,7 @@ class ProtoRatbox : public Module
IRCDMessageTBurst message_tburst;
IRCDMessageUID message_uid;
- void AddModes()
+ static void AddModes()
{
/* user modes */
ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a'));
@@ -337,7 +343,7 @@ class ProtoRatbox : public Module
ModeManager::AddChannelMode(new ChannelMode("SSL", 'S'));
}
- public:
+public:
ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this),
@@ -363,7 +369,7 @@ class ProtoRatbox : public Module
this->AddModes();
}
- ~ProtoRatbox()
+ ~ProtoRatbox() override
{
m_hybrid = ModuleManager::FindModule("hybrid");
ModuleManager::UnloadModule(m_hybrid, NULL);
diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/solanum.cpp
index 8e27c5dc0..d0ce08d79 100644
--- a/modules/protocol/charybdis.cpp
+++ b/modules/protocol/solanum.cpp
@@ -1,4 +1,4 @@
-/* Charybdis IRCD functions
+/* Solanum functions
*
* (C) 2003-2024 Anope Team
* Contact us at team@anope.org
@@ -17,23 +17,25 @@ static Anope::string UplinkSID;
static ServiceReference<IRCDProto> ratbox("IRCDProto", "ratbox");
-class ChannelModeLargeBan : public ChannelMode
+class ChannelModeLargeBan final
+ : public ChannelMode
{
- public:
+public:
ChannelModeLargeBan(const Anope::string &mname, char modeChar) : ChannelMode(mname, modeChar) { }
- bool CanSet(User *u) const anope_override
+ bool CanSet(User *u) const override
{
return u && u->HasMode("OPER");
}
};
-class CharybdisProto : public IRCDProto
+class SolanumProto final
+ : public IRCDProto
{
- public:
+public:
- CharybdisProto(Module *creator) : IRCDProto(creator, "Charybdis 3.4+")
+ SolanumProto(Module *creator) : IRCDProto(creator, "Solanum")
{
DefaultPseudoclientModes = "+oiS";
CanCertFP = true;
@@ -43,44 +45,43 @@ class CharybdisProto : public IRCDProto
CanSZLine = true;
CanSVSNick = true;
CanSVSHold = true;
+ CanSVSLogout = true;
CanSetVHost = true;
RequiresID = true;
MaxModes = 4;
}
- void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override { ratbox->SendSVSKillInternal(source, targ, reason); }
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { ratbox->SendGlobalNotice(bi, dest, msg); }
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { ratbox->SendGlobalPrivmsg(bi, dest, msg); }
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override { ratbox->SendGlobopsInternal(source, buf); }
- void SendSGLine(User *u, const XLine *x) anope_override { ratbox->SendSGLine(u, x); }
- void SendSGLineDel(const XLine *x) anope_override { ratbox->SendSGLineDel(x); }
- void SendAkill(User *u, XLine *x) anope_override { ratbox->SendAkill(u, x); }
- void SendAkillDel(const XLine *x) anope_override { ratbox->SendAkillDel(x); }
- void SendSQLine(User *u, const XLine *x) anope_override { ratbox->SendSQLine(u, x); }
- void SendSQLineDel(const XLine *x) anope_override { ratbox->SendSQLineDel(x); }
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { ratbox->SendJoin(user, c, status); }
- void SendServer(const Server *server) anope_override { ratbox->SendServer(server); }
- void SendChannel(Channel *c) anope_override { ratbox->SendChannel(c); }
- void SendTopic(const MessageSource &source, Channel *c) anope_override { ratbox->SendTopic(source, c); }
- bool IsIdentValid(const Anope::string &ident) anope_override { return ratbox->IsIdentValid(ident); }
- void SendLogin(User *u, NickAlias *na) anope_override { ratbox->SendLogin(u, na); }
- void SendLogout(User *u) anope_override { ratbox->SendLogout(u); }
-
- void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override
+ void SendSVSKill(const MessageSource &source, User *targ, const Anope::string &reason) override { ratbox->SendSVSKill(source, targ, reason); }
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override { ratbox->SendGlobalNotice(bi, dest, msg); }
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override { ratbox->SendGlobalPrivmsg(bi, dest, msg); }
+ void SendGlobops(const MessageSource &source, const Anope::string &buf) override { ratbox->SendGlobops(source, buf); }
+ void SendSGLine(User *u, const XLine *x) override { ratbox->SendSGLine(u, x); }
+ void SendSGLineDel(const XLine *x) override { ratbox->SendSGLineDel(x); }
+ void SendAkill(User *u, XLine *x) override { ratbox->SendAkill(u, x); }
+ void SendAkillDel(const XLine *x) override { ratbox->SendAkillDel(x); }
+ void SendSQLine(User *u, const XLine *x) override { ratbox->SendSQLine(u, x); }
+ void SendSQLineDel(const XLine *x) override { ratbox->SendSQLineDel(x); }
+ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { ratbox->SendJoin(user, c, status); }
+ void SendServer(const Server *server) override { ratbox->SendServer(server); }
+ void SendChannel(Channel *c) override { ratbox->SendChannel(c); }
+ void SendTopic(const MessageSource &source, Channel *c) override { ratbox->SendTopic(source, c); }
+ bool IsIdentValid(const Anope::string &ident) override { return ratbox->IsIdentValid(ident); }
+ void SendLogin(User *u, NickAlias *na) override { ratbox->SendLogin(u, na); }
+ void SendLogout(User *u) override { ratbox->SendLogout(u); }
+
+ void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override
{
Anope::string mechlist;
+ for (const auto &mechanism : mechanisms)
+ mechlist += "," + mechanism;
- for (unsigned i = 0; i < mechanisms.size(); ++i)
- {
- mechlist += "," + mechanisms[i];
- }
-
- UplinkSocket::Message(Me) << "ENCAP * MECHLIST :" << (mechanisms.empty() ? "" : mechlist.substr(1));
+ Uplink::Send("ENCAP", '*', "MECHLIST", mechanisms.empty() ? "" : mechlist.substr(1));
}
- void SendConnect() anope_override
+ void SendConnect() override
{
- UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID();
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID());
+
/*
* Received: CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN
* KNOCK MLOCK QS RSFNC SAVE SERVICES TB UNKLN
@@ -88,6 +89,7 @@ class CharybdisProto : public IRCDProto
* BAN - Can do BAN message
* CHW - Can do channel wall @#
* CLUSTER - Supports umode +l, can send LOCOPS (encap only)
+ * ECHO - Supports sending echoed messages
* ENCAP - Can do ENCAP message
* EOPMOD - Can do channel wall =# (for cmode +z)
* EUID - Can do EUID (its similar to UID but includes the ENCAP REALHOST and ENCAP LOGIN information)
@@ -104,7 +106,7 @@ class CharybdisProto : public IRCDProto
* UNKLN - Can do UNKLINE (encap only)
* QS - Can handle quit storm removal
*/
- UplinkSocket::Message() << "CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SERVICES TB UNKLN";
+ Uplink::Send("CAPAB", "BAN CHW CLUSTER ECHO ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SERVICES TB UNKLN");
/* Make myself known to myself in the serverlist */
SendServer(Me);
@@ -116,63 +118,70 @@ class CharybdisProto : public IRCDProto
* arg[2] = '0'
* arg[3] = server's idea of UTC time
*/
- UplinkSocket::Message() << "SVINFO 6 6 0 :" << Anope::CurTime;
+ Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime);
}
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(Me) << "EUID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " * * :" << u->realname;
+ Uplink::Send("EUID", u->nick, 1, u->timestamp, "+" + u->GetModes(), u->GetIdent(), u->host, 0, u->GetUID(), '*', '*', u->realname);
}
- void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override
+ void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override
{
- UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " RSFNC " << u->GetUID()
- << " " << newnick << " " << when << " " << u->timestamp;
+ Uplink::Send("ENCAP", u->server->GetName(), "RSFNC", u->GetUID(), newnick, when, u->timestamp);
}
- void SendSVSHold(const Anope::string &nick, time_t delay) anope_override
+ void SendSVSHold(const Anope::string &nick, time_t delay) override
{
- UplinkSocket::Message(Me) << "ENCAP * NICKDELAY " << delay << " " << nick;
+ Uplink::Send("ENCAP", '*', "NICKDELAY", delay, nick);
}
- void SendSVSHoldDel(const Anope::string &nick) anope_override
+ void SendSVSHoldDel(const Anope::string &nick) override
{
- UplinkSocket::Message(Me) << "ENCAP * NICKDELAY 0 " << nick;
+ Uplink::Send("ENCAP", '*', "NICKDELAY", 0, nick);
}
- void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override
+ void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override
{
- UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " :" << host;
+ Uplink::Send("ENCAP", '*', "CHGHOST", u->GetUID(), host);
}
- void SendVhostDel(User *u) anope_override
+ void SendVhostDel(User *u) override
{
this->SendVhost(u, "", u->host);
}
- void SendSASLMessage(const SASL::Message &message) anope_override
+ void SendSASLMessage(const SASL::Message &message) override
{
Server *s = Server::Find(message.target.substr(0, 3));
- UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : message.target.substr(0, 3)) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext));
+ auto target = s ? s->GetName() : message.target.substr(0, 3);
+ if (message.ext.empty())
+ Uplink::Send("ENCAP", target, "SASL", message.source, message.target, message.type, message.data);
+ else
+ Uplink::Send("ENCAP", target, "SASL", message.source, message.target, message.type, message.data, message.ext);
}
- void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override
+ void SendSVSLogin(const Anope::string &uid, NickAlias *na) override
{
Server *s = Server::Find(uid.substr(0, 3));
- UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : uid.substr(0, 3)) << " SVSLOGIN " << uid << " * " << (!vident.empty() ? vident : '*') << " " << (!vhost.empty() ? vhost : '*') << " " << acc;
+
+ Uplink::Send("ENCAP", s ? s->GetName() : uid.substr(0, 3), "SVSLOGIN", uid, '*',
+ na && !na->GetVhostIdent().empty() ? na->GetVhostIdent() : '*',
+ na && !na->GetVhostHost().empty() ? na->GetVhostHost() : '*',
+ na ? na->nc->display : "0");
}
};
-struct IRCDMessageEncap : IRCDMessage
+struct IRCDMessageEncap final
+ : IRCDMessage
{
IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3)
{
- SetFlag(IRCDMESSAGE_SOFT_LIMIT);
+ SetFlag(FLAG_SOFT_LIMIT);
}
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// In a burst, states that the source user is logged in as the account.
if (params[1] == "LOGIN" || params[1] == "SU")
@@ -205,7 +214,7 @@ struct IRCDMessageEncap : IRCDMessage
* termination: 'A' for abort, 'F' for authentication failure, 'S' for
* authentication success).
*
- * Charybdis only accepts messages from SASL agents; these must have umode +S
+ * Solanum only accepts messages from SASL agents; these must have umode +S
*/
else if (params[1] == "SASL" && SASL::sasl && params.size() >= 6)
{
@@ -221,9 +230,10 @@ struct IRCDMessageEncap : IRCDMessage
}
};
-struct IRCDMessageEUID : IRCDMessage
+struct IRCDMessageEUID final
+ : IRCDMessage
{
- IRCDMessageEUID(Module *creator) : IRCDMessage(creator, "EUID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageEUID(Module *creator) : IRCDMessage(creator, "EUID", 11) { SetFlag(FLAG_REQUIRE_SERVER); }
/*
* :42X EUID DukePyrolator 1 1353240577 +Zi ~jens erft-5d80b00b.pool.mediaWays.net 93.128.176.11 42XAAAAAD * * :jens
@@ -238,23 +248,25 @@ struct IRCDMessageEUID : IRCDMessage
* user is not logged in with services). Hence a NICK or UID command received
* from a remote server should not be sent in EUID form to other servers.
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
NickAlias *na = NULL;
if (params[9] != "*")
na = NickAlias::Find(params[9]);
- User::OnIntroduce(params[0], params[4], (params[8] != "*" ? params[8] : params[5]), params[5], params[6], source.GetServer(), params[10], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime, params[3], params[7], na ? *na->nc : NULL);
+ User::OnIntroduce(params[0], params[4], (params[8] != "*" ? params[8] : params[5]), params[5], params[6], source.GetServer(),
+ params[10], IRCD->ExtractTimestamp(params[2]), params[3], params[7], na ? *na->nc : NULL);
}
};
// we can't use this function from ratbox because we set a local variable here
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
- // SERVER dev.anope.de 1 :charybdis test server
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ // SERVER dev.anope.de 1 :solanum test server
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// Servers other then our immediate uplink are introduced via SID
if (params[1] != "1")
@@ -265,22 +277,52 @@ struct IRCDMessageServer : IRCDMessage
};
// we can't use this function from ratbox because we set a local variable here
-struct IRCDMessagePass : IRCDMessage
+struct IRCDMessagePass final
+ : IRCDMessage
{
- IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
// UplinkSID is used in IRCDMessageServer
UplinkSID = params[3];
}
};
-class ProtoCharybdis : public Module
+struct IRCDMessageNotice final
+ : Message::Notice
+{
+ IRCDMessageNotice(Module *creator) : Message::Notice(creator) { }
+
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
+ {
+ if (Servers::Capab.count("ECHO"))
+ Uplink::Send("ECHO", 'N', source.GetSource(), params[1]);
+
+ Message::Notice::Run(source, params, tags);
+ }
+};
+
+struct IRCDMessagePrivmsg final
+ : Message::Privmsg
+{
+ IRCDMessagePrivmsg(Module *creator) : Message::Privmsg(creator) { }
+
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
+ {
+ if (Servers::Capab.count("ECHO"))
+ Uplink::Send("ECHO", 'P', source.GetSource(), params[1]);
+
+ Message::Privmsg::Run(source, params, tags);
+ }
+};
+
+class ProtoSolanum final
+ : public Module
{
Module *m_ratbox;
- CharybdisProto ircd_proto;
+ SolanumProto ircd_proto;
/* Core message handlers */
Message::Away message_away;
@@ -291,10 +333,8 @@ class ProtoCharybdis : public Module
Message::Kill message_kill;
Message::Mode message_mode;
Message::MOTD message_motd;
- Message::Notice message_notice;
Message::Part message_part;
Message::Ping message_ping;
- Message::Privmsg message_privmsg;
Message::Quit message_quit;
Message::SQuit message_squit;
Message::Stats message_stats;
@@ -310,12 +350,14 @@ class ProtoCharybdis : public Module
/* Our message handlers */
IRCDMessageEncap message_encap;
IRCDMessageEUID message_euid;
+ IRCDMessageNotice message_notice;
IRCDMessagePass message_pass;
+ IRCDMessagePrivmsg message_privmsg;
IRCDMessageServer message_server;
bool use_server_side_mlock;
- void AddModes()
+ static void AddModes()
{
/* Add user modes */
ModeManager::AddUserMode(new UserMode("NOFORWARD", 'Q'));
@@ -339,26 +381,26 @@ class ProtoCharybdis : public Module
ModeManager::AddChannelMode(new ChannelMode("OPMODERATED", 'z'));
}
- public:
- ProtoCharybdis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
+public:
+ ProtoSolanum(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this),
- message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this),
- message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this),
- message_time(this), message_topic(this), message_version(this), message_whois(this),
-
- message_bmask("IRCDMessage", "charybdis/bmask", "ratbox/bmask"),
- message_join("IRCDMessage", "charybdis/join", "ratbox/join"),
- message_nick("IRCDMessage", "charybdis/nick", "ratbox/nick"),
- message_pong("IRCDMessage", "charybdis/pong", "ratbox/pong"),
- message_sid("IRCDMessage", "charybdis/sid", "ratbox/sid"),
- message_sjoin("IRCDMessage", "charybdis/sjoin", "ratbox/sjoin"),
- message_tb("IRCDMessage", "charybdis/tb", "ratbox/tb"),
- message_tmode("IRCDMessage", "charybdis/tmode", "ratbox/tmode"),
- message_uid("IRCDMessage", "charybdis/uid", "ratbox/uid"),
-
- message_encap(this), message_euid(this), message_pass(this), message_server(this)
-
+ message_kill(this), message_mode(this), message_motd(this), message_part(this), message_ping(this),
+ message_quit(this), message_squit(this), message_stats(this), message_time(this), message_topic(this),
+ message_version(this), message_whois(this),
+
+ message_bmask("IRCDMessage", "solanum/bmask", "ratbox/bmask"),
+ message_join("IRCDMessage", "solanum/join", "ratbox/join"),
+ message_nick("IRCDMessage", "solanum/nick", "ratbox/nick"),
+ message_pong("IRCDMessage", "solanum/pong", "ratbox/pong"),
+ message_sid("IRCDMessage", "solanum/sid", "ratbox/sid"),
+ message_sjoin("IRCDMessage", "solanum/sjoin", "ratbox/sjoin"),
+ message_tb("IRCDMessage", "solanum/tb", "ratbox/tb"),
+ message_tmode("IRCDMessage", "solanum/tmode", "ratbox/tmode"),
+ message_uid("IRCDMessage", "solanum/uid", "ratbox/uid"),
+
+ message_encap(this), message_euid(this), message_notice(this), message_pass(this),
+ message_privmsg(this), message_server(this)
{
@@ -373,18 +415,42 @@ class ProtoCharybdis : public Module
this->AddModes();
}
- ~ProtoCharybdis()
+ ~ProtoSolanum() override
{
m_ratbox = ModuleManager::FindModule("ratbox");
ModuleManager::UnloadModule(m_ratbox, NULL);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnUserLogin(User *u) override
+ {
+ // If the user has logged into their current nickname then mark them as such.
+ NickAlias *na = NickAlias::Find(u->nick);
+ if (na && na->nc == u->Account())
+ Uplink::Send("ENCAP", '*', "IDENTIFIED", u->GetUID(), u->nick);
+ else
+ Uplink::Send("ENCAP", '*', "IDENTIFIED", u->GetUID(), u->nick, "OFF");
+ }
+
+ void OnNickLogout(User *u) override
+ {
+ // We don't know what account the user was logged into so send in all cases.
+ Uplink::Send("ENCAP", '*', "IDENTIFIED", u->GetUID(), u->nick, "OFF");
+ }
+
+ void OnUserNickChange(User *u, const Anope::string &) override
+ {
+ // If the user is logged into an account check if we need to mark them
+ // as not identified to their nick.
+ if (u->Account())
+ OnUserLogin(u);
+ }
+
+ void OnReload(Configuration::Conf *conf) override
{
use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (!c->ci)
return;
@@ -393,35 +459,35 @@ class ProtoCharybdis : public Module
if (use_server_side_mlock && modelocks && Servers::Capab.count("MLOCK") > 0)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes;
+ Uplink::Send("MLOCK", c->creation_time, c->ci->name, modes);
}
}
- EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar;
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, modes);
}
return EVENT_CONTINUE;
}
- EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, modes);
}
return EVENT_CONTINUE;
}
};
-MODULE_INIT(ProtoCharybdis)
+MODULE_INIT(ProtoSolanum)
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp
deleted file mode 100644
index e6654ddc9..000000000
--- a/modules/protocol/unreal.cpp
+++ /dev/null
@@ -1,1340 +0,0 @@
-/* Unreal IRCD 3.2.x functions
- *
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "module.h"
-#include "modules/cs_mode.h"
-#include "modules/sasl.h"
-
-class UnrealIRCdProto : public IRCDProto
-{
- public:
- UnrealIRCdProto(Module *creator) : IRCDProto(creator, "UnrealIRCd 3.2.x")
- {
- DefaultPseudoclientModes = "+Soiq";
- CanSVSNick = true;
- CanSVSJoin = true;
- CanSetVHost = true;
- CanSetVIdent = true;
- CanSNLine = true;
- CanSQLine = true;
- CanSZLine = true;
- CanSVSHold = true;
- CanSVSO = true;
- MaxModes = 12;
- }
-
- private:
- /* SVSNOOP */
- void SendSVSNOOP(const Server *server, bool set) anope_override
- {
- UplinkSocket::Message() << "SVSNOOP " << server->GetName() << " " << (set ? "+" : "-");
- }
-
- void SendAkillDel(const XLine *x) anope_override
- {
- if (x->IsRegex() || x->HasNickOrReal())
- return;
-
- /* ZLine if we can instead */
- if (x->GetUser() == "*")
- {
- cidr a(x->GetHost());
- if (a.valid())
- {
- IRCD->SendSZLineDel(x);
- return;
- }
- }
-
- UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << x->by;
- }
-
- void SendTopic(const MessageSource &source, Channel *c) anope_override
- {
- UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic;
- }
-
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
- {
- UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg;
- }
-
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
- {
- UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg;
- }
-
- void SendVhostDel(User *u) anope_override
- {
- BotInfo *HostServ = Config->GetClient("HostServ");
- u->RemoveMode(HostServ, "CLOAK");
- u->RemoveMode(HostServ, "VHOST");
- ModeManager::ProcessModes();
- u->SetMode(HostServ, "CLOAK");
- }
-
- void SendAkill(User *u, XLine *x) anope_override
- {
- if (x->IsRegex() || x->HasNickOrReal())
- {
- if (!u)
- {
- /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
- return;
- }
-
- const XLine *old = x;
-
- if (old->manager->HasEntry("*@" + u->host))
- return;
-
- /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
- old->manager->AddXLine(xline);
- x = xline;
-
- Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask;
- }
-
- /* ZLine if we can instead */
- if (x->GetUser() == "*")
- {
- cidr a(x->GetHost());
- if (a.valid())
- {
- IRCD->SendSZLine(u, x);
- return;
- }
- }
-
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
- UplinkSocket::Message() << "TKL + G " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason();
- }
-
- void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf;
- user->KillInternal(source, buf);
- }
-
- void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
- {
- UplinkSocket::Message(source) << "SVS2MODE " << u->nick <<" " << buf;
- }
-
- void SendClientIntroduction(User *u) anope_override
- {
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message() << "NICK " << u->nick << " 1 " << u->timestamp << " " << u->GetIdent() << " " << u->host << " " << u->server->GetName() << " 0 " << modes << " " << u->host << " * :" << u->realname;
- }
-
- /* SERVER name hop descript */
- /* Unreal 3.2 actually sends some info about itself in the descript area */
- void SendServer(const Server *server) anope_override
- {
- if (!server->GetSID().empty() && server == Me)
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :U0-*-" << server->GetSID() << " " << server->GetDescription();
- else
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription();
- }
-
- /* JOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
- {
- UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " :" << user->nick;
- if (status)
- {
- /* First save the channel status incase uc->Status == status */
- ChannelStatus cs = *status;
- /* If the user is internally on the channel with flags, kill them so that
- * the stacker will allow this.
- */
- ChanUserContainer *uc = c->FindUser(user);
- if (uc != NULL)
- uc->status.Clear();
-
- BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
-
- if (uc != NULL)
- uc->status = cs;
- }
- }
-
- /* unsqline
- */
- void SendSQLineDel(const XLine *x) anope_override
- {
- UplinkSocket::Message() << "UNSQLINE " << x->mask;
- }
-
- /* SQLINE */
- /*
- ** - Unreal will translate this to TKL for us
- **
- */
- void SendSQLine(User *, const XLine *x) anope_override
- {
- UplinkSocket::Message() << "SQLINE " << x->mask << " :" << x->GetReason();
- }
-
- /*
- ** svso
- ** parv[0] = sender prefix
- ** parv[1] = nick
- ** parv[2] = options
- */
- void SendSVSO(BotInfo *source, const Anope::string &nick, const Anope::string &flag) anope_override
- {
- UplinkSocket::Message(source) << "SVSO " << nick << " " << flag;
- }
-
- /* Functions that use serval cmd functions */
-
- void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
- {
- if (!vIdent.empty())
- UplinkSocket::Message(Me) << "CHGIDENT " << u->nick << " " << vIdent;
- if (!vhost.empty())
- UplinkSocket::Message(Me) << "CHGHOST " << u->nick << " " << vhost;
- }
-
- void SendConnect() anope_override
- {
- /*
- NICKv2 = Nick Version 2
- VHP = Sends hidden host
- UMODE2 = sends UMODE2 on user modes
- NICKIP = Sends IP on NICK
- TOKEN = Use tokens to talk
- SJ3 = Supports SJOIN
- NOQUIT = No Quit
- TKLEXT = Extended TKL we don't use it but best to have it
- SJB64 = Base64 encoded time stamps
- ESVID = Allows storing account names as services stamp
- MLOCK = Supports the MLOCK server command
- VL = Version Info
- NS = Config->Numeric Server
- */
- Anope::string protoctl = "NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT ESVID MLOCK VL";
- if (!Me->GetSID().empty())
- protoctl += " VL";
- UplinkSocket::Message() << "PROTOCTL " << protoctl;
- UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink].password;
- SendServer(Me);
- }
-
- /* SVSHOLD - set */
- void SendSVSHold(const Anope::string &nick, time_t t) anope_override
- {
- UplinkSocket::Message() << "TKL + Q H " << nick << " " << Me->GetName() << " " << Anope::CurTime + t << " " << Anope::CurTime << " :Being held for registered user";
- }
-
- /* SVSHOLD - release */
- void SendSVSHoldDel(const Anope::string &nick) anope_override
- {
- UplinkSocket::Message() << "TKL - Q * " << nick << " " << Me->GetName();
- }
-
- /* UNSGLINE */
- /*
- * SVSNLINE - :realname mask
- */
- void SendSGLineDel(const XLine *x) anope_override
- {
- UplinkSocket::Message() << "SVSNLINE - :" << x->mask;
- }
-
- /* UNSZLINE */
- void SendSZLineDel(const XLine *x) anope_override
- {
- UplinkSocket::Message() << "TKL - Z * " << x->GetHost() << " " << x->by;
- }
-
- /* SZLINE */
- void SendSZLine(User *, const XLine *x) anope_override
- {
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
- UplinkSocket::Message() << "TKL + Z * " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason();
- }
-
- /* SGLINE */
- /*
- * SVSNLINE + reason_where_is_space :realname mask with spaces
- */
- void SendSGLine(User *, const XLine *x) anope_override
- {
- Anope::string edited_reason = x->GetReason();
- edited_reason = edited_reason.replace_all_cs(" ", "_");
- UplinkSocket::Message() << "SVSNLINE + " << edited_reason << " :" << x->mask;
- }
-
- /* svsjoin
- parv[0] - sender
- parv[1] - nick to make join
- parv[2] - channel to join
- parv[3] - (optional) channel key(s)
- */
- /* In older Unreal SVSJOIN and SVSNLINE tokens were mixed so SVSJOIN and SVSNLINE are broken
- when coming from a none TOKEN'd server
- */
- void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) anope_override
- {
- if (!param.empty())
- UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan << " :" << param;
- else
- UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan;
- }
-
- void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) anope_override
- {
- if (!param.empty())
- UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan << " :" << param;
- else
- UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan;
- }
-
- void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) anope_override
- {
- UplinkSocket::Message(source) << "SWHOIS " << who << " :" << mask;
- }
-
- void SendEOB() anope_override
- {
- UplinkSocket::Message(Me) << "EOS";
- }
-
- bool IsNickValid(const Anope::string &nick) anope_override
- {
- if (nick.equals_ci("ircd") || nick.equals_ci("irc"))
- return false;
-
- return IRCDProto::IsNickValid(nick);
- }
-
- bool IsChannelValid(const Anope::string &chan) anope_override
- {
- if (chan.find(':') != Anope::string::npos)
- return false;
-
- return IRCDProto::IsChannelValid(chan);
- }
-
- bool IsExtbanValid(const Anope::string &mask) anope_override
- {
- return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':';
- }
-
- void SendLogin(User *u, NickAlias *na) anope_override
- {
- /* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */
- if (Servers::Capab.count("ESVID") > 0 && !na->nc->HasExt("UNCONFIRMED"))
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str());
- else
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon);
- }
-
- void SendLogout(User *u) anope_override
- {
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0");
- }
-
- void SendChannel(Channel *c) anope_override
- {
- /* Unreal does not support updating a channels TS without actually joining a user,
- * so we will join and part us now
- */
- BotInfo *bi = c->WhoSends();
- if (!bi)
- ;
- else if (c->FindUser(bi) == NULL)
- {
- bi->Join(c);
- bi->Part(c);
- }
- else
- {
- bi->Part(c);
- bi->Join(c);
- }
- }
-
- void SendSASLMessage(const SASL::Message &message) anope_override
- {
- size_t p = message.target.find('!');
- if (p == Anope::string::npos)
- return;
-
- UplinkSocket::Message(BotInfo::Find(message.source)) << "SASL " << message.target.substr(0, p) << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : " " + message.ext);
- }
-
- void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override
- {
- size_t p = uid.find('!');
- if (p == Anope::string::npos)
- return;
- UplinkSocket::Message(Me) << "SVSLOGIN " << uid.substr(0, p) << " " << uid << " " << acc;
- }
-
- bool IsIdentValid(const Anope::string &ident) anope_override
- {
- if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
- return false;
-
- for (unsigned i = 0; i < ident.length(); ++i)
- {
- const char &c = ident[i];
-
- if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
- continue;
-
- if (c == '-' || c == '.' || c == '_')
- continue;
-
- return false;
- }
-
- return true;
- }
-};
-
-class UnrealExtBan : public ChannelModeVirtual<ChannelModeList>
-{
- char ext;
-
- public:
- UnrealExtBan(const Anope::string &mname, const Anope::string &basename, char extban) : ChannelModeVirtual<ChannelModeList>(mname, basename)
- , ext(extban)
- {
- }
-
- ChannelMode *Wrap(Anope::string &param) anope_override
- {
- param = "~" + Anope::string(ext) + ":" + param;
- return ChannelModeVirtual<ChannelModeList>::Wrap(param);
- }
-
- ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) anope_override
- {
- if (cm->type != MODE_LIST || param.length() < 4 || param[0] != '~' || param[1] != ext || param[2] != ':')
- return cm;
-
- param = param.substr(3);
- return this;
- }
-};
-
-namespace UnrealExtban
-{
- class ChannelMatcher : public UnrealExtBan
- {
- public:
- ChannelMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string channel = mask.substr(3);
-
- ChannelMode *cm = NULL;
- if (channel[0] != '#')
- {
- char modeChar = ModeManager::GetStatusChar(channel[0]);
- channel.erase(channel.begin());
- cm = ModeManager::FindChannelModeByChar(modeChar);
- if (cm != NULL && cm->type != MODE_STATUS)
- cm = NULL;
- }
-
- Channel *c = Channel::Find(channel);
- if (c != NULL)
- {
- ChanUserContainer *uc = c->FindUser(u);
- if (uc != NULL)
- if (cm == NULL || uc->status.HasMode(cm->mchar))
- return true;
- }
-
- return false;
- }
- };
-
- class EntryMatcher : public UnrealExtBan
- {
- public:
- EntryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(3);
-
- return Entry(this->name, real_mask).Matches(u);
- }
- };
-
- class RealnameMatcher : public UnrealExtBan
- {
- public:
- RealnameMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(3);
-
- return Anope::Match(u->realname, real_mask);
- }
- };
-
- class RegisteredMatcher : public UnrealExtBan
- {
- public:
- RegisteredMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- return u->HasMode("REGISTERED") && mask.equals_ci(u->nick);
- }
- };
-
- class AccountMatcher : public UnrealExtBan
- {
- public:
- AccountMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
- {
- }
-
- bool Matches(User *u, const Entry *e) anope_override
- {
- const Anope::string &mask = e->GetMask();
- Anope::string real_mask = mask.substr(3);
-
- return u->Account() && Anope::Match(u->Account()->display, real_mask);
- }
- };
-}
-
-class ChannelModeFlood : public ChannelModeParam
-{
- public:
- ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { }
-
- /* Borrowed part of this check from UnrealIRCd */
- bool IsValid(Anope::string &value) const anope_override
- {
- if (value.empty())
- return false;
- try
- {
- Anope::string rest;
- if (value[0] != ':' && convertTo<unsigned>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<unsigned>(rest.substr(1), rest, false) > 0 && rest.empty())
- return true;
- }
- catch (const ConvertException &) { }
-
- /* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */
- size_t end_bracket = value.find(']', 1);
- if (end_bracket == Anope::string::npos)
- return false;
- Anope::string xbuf = value.substr(0, end_bracket);
- if (value[end_bracket + 1] != ':')
- return false;
- commasepstream args(xbuf.substr(1));
- Anope::string arg;
- while (args.GetToken(arg))
- {
- /* <number><1 letter>[optional: '#'+1 letter] */
- size_t p = 0;
- while (p < arg.length() && isdigit(arg[p]))
- ++p;
- if (p == arg.length() || !(arg[p] == 'c' || arg[p] == 'j' || arg[p] == 'k' || arg[p] == 'm' || arg[p] == 'n' || arg[p] == 't'))
- continue; /* continue instead of break for forward compatibility. */
- try
- {
- int v = arg.substr(0, p).is_number_only() ? convertTo<int>(arg.substr(0, p)) : 0;
- if (v < 1 || v > 999)
- return false;
- }
- catch (const ConvertException &)
- {
- return false;
- }
- }
-
- return true;
- }
-};
-
-class ChannelModeUnrealSSL : public ChannelMode
-{
- public:
- ChannelModeUnrealSSL(const Anope::string &n, char c) : ChannelMode(n, c)
- {
- }
-
- bool CanSet(User *u) const anope_override
- {
- return false;
- }
-};
-
-struct IRCDMessageCapab : Message::Capab
-{
- IRCDMessageCapab(Module *creator) : Message::Capab(creator, "PROTOCTL") { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- for (unsigned i = 0; i < params.size(); ++i)
- {
- Anope::string capab = params[i];
-
- if (capab.find("CHANMODES") != Anope::string::npos)
- {
- Anope::string modes(capab.begin() + 10, capab.end());
- commasepstream sep(modes);
- Anope::string modebuf;
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'b':
- ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b'));
-
- ModeManager::AddChannelMode(new UnrealExtban::ChannelMatcher("CHANNELBAN", "BAN", 'c'));
- ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("JOINBAN", "BAN", 'j'));
- ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("NONICKBAN", "BAN", 'n'));
- ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("QUIET", "BAN", 'q'));
- ModeManager::AddChannelMode(new UnrealExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r'));
- ModeManager::AddChannelMode(new UnrealExtban::RegisteredMatcher("REGISTEREDBAN", "BAN", 'R'));
- ModeManager::AddChannelMode(new UnrealExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'a'));
- continue;
- case 'e':
- ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e'));
- continue;
- case 'I':
- ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I'));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t]));
- }
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'k':
- ModeManager::AddChannelMode(new ChannelModeKey('k'));
- continue;
- case 'f':
- ModeManager::AddChannelMode(new ChannelModeFlood('f', false));
- continue;
- case 'L':
- ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L'));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t]));
- }
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'l':
- ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true));
- continue;
- case 'j':
- ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j', true));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true));
- }
- }
-
- sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
- {
- switch (modebuf[t])
- {
- case 'p':
- ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p'));
- continue;
- case 's':
- ModeManager::AddChannelMode(new ChannelMode("SECRET", 's'));
- continue;
- case 'm':
- ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm'));
- continue;
- case 'n':
- ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n'));
- continue;
- case 't':
- ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't'));
- continue;
- case 'i':
- ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i'));
- continue;
- case 'r':
- ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r'));
- continue;
- case 'R':
- ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R'));
- continue;
- case 'c':
- ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c'));
- continue;
- case 'O':
- ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O'));
- continue;
- case 'A':
- ModeManager::AddChannelMode(new ChannelModeOperOnly("ADMINONLY", 'A'));
- continue;
- case 'Q':
- ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q'));
- continue;
- case 'K':
- ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K'));
- continue;
- case 'V':
- ModeManager::AddChannelMode(new ChannelMode("NOINVITE", 'V'));
- continue;
- case 'C':
- ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C'));
- continue;
- case 'u':
- ModeManager::AddChannelMode(new ChannelMode("AUDITORIUM", 'u'));
- continue;
- case 'z':
- ModeManager::AddChannelMode(new ChannelMode("SSL", 'z'));
- continue;
- case 'N':
- ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N'));
- continue;
- case 'S':
- ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S'));
- continue;
- case 'M':
- ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M'));
- continue;
- case 'T':
- ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T'));
- continue;
- case 'G':
- ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G'));
- continue;
- case 'Z':
- ModeManager::AddChannelMode(new ChannelModeUnrealSSL("", 'Z'));
- continue;
- default:
- ModeManager::AddChannelMode(new ChannelMode("", modebuf[t]));
- }
- }
- }
- }
-
- Message::Capab::Run(source, params);
- }
-};
-
-struct IRCDMessageChgHost : IRCDMessage
-{
- IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = User::Find(params[0]);
- if (u)
- u->SetDisplayedHost(params[1]);
- }
-};
-
-struct IRCDMessageChgIdent : IRCDMessage
-{
- IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = User::Find(params[0]);
- if (u)
- u->SetVIdent(params[1]);
- }
-};
-
-struct IRCDMessageChgName : IRCDMessage
-{
- IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = User::Find(params[0]);
- if (u)
- u->SetRealname(params[1]);
- }
-};
-
-struct IRCDMessageMode : IRCDMessage
-{
- IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- bool server_source = source.GetServer() != NULL;
- Anope::string modes = params[1];
- for (unsigned i = 2; i < params.size() - (server_source ? 1 : 0); ++i)
- modes += " " + params[i];
-
- if (IRCD->IsChannelValid(params[0]))
- {
- Channel *c = Channel::Find(params[0]);
- time_t ts = 0;
-
- try
- {
- if (server_source)
- ts = convertTo<time_t>(params[params.size() - 1]);
- }
- catch (const ConvertException &) { }
-
- if (c)
- c->SetModesInternal(source, modes, ts);
- }
- else
- {
- User *u = User::Find(params[0]);
- if (u)
- u->SetModesInternal(source, "%s", params[1].c_str());
- }
- }
-};
-
-/* netinfo
- * argv[0] = max global count
- * argv[1] = time of end sync
- * argv[2] = unreal protocol using (numeric)
- * argv[3] = cloak-crc (> u2302)
- * argv[4] = free(**)
- * argv[5] = free(**)
- * argv[6] = free(**)
- * argv[7] = ircnet
- */
-struct IRCDMessageNetInfo : IRCDMessage
-{
- IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7];
- }
-};
-
-struct IRCDMessageNick : IRCDMessage
-{
- IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- /*
- ** NICK - new
- ** source = NULL
- ** parv[0] = nickname
- ** parv[1] = hopcount
- ** parv[2] = timestamp
- ** parv[3] = username
- ** parv[4] = hostname
- ** parv[5] = servername
- ** parv[6] = servicestamp
- ** parv[7] = umodes
- ** parv[8] = virthost, * if none
- ** parv[9] = ip
- ** parv[10] = info
- **
- ** NICK - change
- ** source = oldnick
- ** parv[0] = new nickname
- ** parv[1] = hopcount
- */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (params.size() == 11)
- {
- Anope::string ip;
- if (params[9] != "*")
- {
- Anope::string decoded_ip;
- Anope::B64Decode(params[9], decoded_ip);
-
- sockaddrs ip_addr;
- ip_addr.ntop(params[9].length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str());
- ip = ip_addr.addr();
- }
-
- Anope::string vhost = params[8];
- if (vhost.equals_cs("*"))
- vhost.clear();
-
- time_t user_ts = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime;
-
- Server *s = Server::Find(params[5]);
- if (s == NULL)
- {
- Log(LOG_DEBUG) << "User " << params[0] << " introduced from nonexistent server " << params[5] << "?";
- return;
- }
-
- NickAlias *na = NULL;
-
- if (params[6] == "0")
- ;
- else if (params[6].is_pos_number_only())
- {
- if (convertTo<time_t>(params[6]) == user_ts)
- na = NickAlias::Find(params[0]);
- }
- else
- {
- na = NickAlias::Find(params[6]);
- }
-
- User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? *na->nc : NULL);
- }
- else
- {
- User *u = source.GetUser();
- if (u)
- u->ChangeNick(params[0]);
- }
- }
-};
-
-/** This is here because:
- *
- * If we had three servers, A, B & C linked like so: A<->B<->C
- * If Anope is linked to A and B splits from A and then reconnects
- * B introduces itself, introduces C, sends EOS for C, introduces Bs clients
- * introduces Cs clients, sends EOS for B. This causes all of Cs clients to be introduced
- * with their server "not syncing". We now send a PING immediately when receiving a new server
- * and then finish sync once we get a pong back from that server.
- */
-struct IRCDMessagePong : IRCDMessage
-{
- IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- if (!source.GetServer()->IsSynced())
- source.GetServer()->Sync(false);
- }
-};
-
-struct IRCDMessageSASL : IRCDMessage
-{
- IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- size_t p = params[1].find('!');
- if (!SASL::sasl || p == Anope::string::npos)
- return;
-
- SASL::Message m;
- m.source = params[1];
- m.target = params[0];
- m.type = params[2];
- m.data = params[3];
- m.ext = params.size() > 4 ? params[4] : "";
-
- SASL::sasl->ProcessMessage(m);
- }
-};
-
-struct IRCDMessageSDesc : IRCDMessage
-{
- IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- source.GetServer()->SetDescription(params[0]);
- }
-};
-
-struct IRCDMessageSetHost : IRCDMessage
-{
- IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = source.GetUser();
-
- /* When a user sets +x we receive the new host and then the mode change */
- if (u->HasMode("CLOAK"))
- u->SetDisplayedHost(params[0]);
- else
- u->SetCloakedHost(params[0]);
- }
-};
-
-struct IRCDMessageSetIdent : IRCDMessage
-{
- IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = source.GetUser();
- u->SetVIdent(params[0]);
- }
-};
-
-struct IRCDMessageSetName : IRCDMessage
-{
- IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- User *u = source.GetUser();
- u->SetRealname(params[0]);
- }
-};
-
-struct IRCDMessageServer : IRCDMessage
-{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
-
- if (params[1].equals_cs("1"))
- {
- Anope::string desc;
- spacesepstream(params[2]).GetTokenRemainder(desc, 1);
-
- new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc);
- }
- else
- new Server(source.GetServer(), params[0], hops, params[2]);
-
- IRCD->SendPing(Me->GetName(), params[0]);
- }
-};
-
-struct IRCDMessageSJoin : IRCDMessage
-{
- IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- Anope::string modes;
- if (params.size() >= 4)
- for (unsigned i = 2; i < params.size() - 1; ++i)
- modes += " " + params[i];
- if (!modes.empty())
- modes.erase(modes.begin());
-
- std::list<Anope::string> bans, excepts, invites;
- std::list<Message::Join::SJoinUser> users;
-
- spacesepstream sep(params[params.size() - 1]);
- Anope::string buf;
- while (sep.GetToken(buf))
- {
- /* Ban */
- if (buf[0] == '&')
- {
- buf.erase(buf.begin());
- bans.push_back(buf);
- }
- /* Except */
- else if (buf[0] == '"')
- {
- buf.erase(buf.begin());
- excepts.push_back(buf);
- }
- /* Invex */
- else if (buf[0] == '\'')
- {
- buf.erase(buf.begin());
- invites.push_back(buf);
- }
- else
- {
- Message::Join::SJoinUser sju;
-
- /* Get prefixes from the nick */
- for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));)
- {
- sju.first.AddMode(ch);
- buf.erase(buf.begin());
- }
-
- sju.second = User::Find(buf);
- if (!sju.second)
- {
- Log(LOG_DEBUG) << "SJOIN for nonexistent user " << buf << " on " << params[1];
- continue;
- }
-
- users.push_back(sju);
- }
- }
-
- time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
- Message::Join::SJoin(source, params[1], ts, modes, users);
-
- if (!bans.empty() || !excepts.empty() || !invites.empty())
- {
- Channel *c = Channel::Find(params[1]);
-
- if (!c || c->creation_time != ts)
- return;
-
- ChannelMode *ban = ModeManager::FindChannelModeByName("BAN"),
- *except = ModeManager::FindChannelModeByName("EXCEPT"),
- *invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE");
-
- if (ban)
- for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it)
- c->SetModeInternal(source, ban, *it);
- if (except)
- for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it)
- c->SetModeInternal(source, except, *it);
- if (invex)
- for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it)
- c->SetModeInternal(source, invex, *it);
- }
- }
-};
-
-struct IRCDMessageTopic : IRCDMessage
-{
- IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { }
-
- /*
- ** source = sender prefix
- ** parv[0] = channel name
- ** parv[1] = topic nickname
- ** parv[2] = topic time
- ** parv[3] = topic text
- */
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- Channel *c = Channel::Find(params[0]);
- if (c)
- c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime);
- }
-};
-
-
-struct IRCDMessageUmode2 : IRCDMessage
-{
- IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
-
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
- {
- source.GetUser()->SetModesInternal(source, "%s", params[0].c_str());
- }
-};
-
-class ProtoUnreal : public Module
-{
- UnrealIRCdProto ircd_proto;
-
- /* Core message handlers */
- Message::Away message_away;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Join message_join;
- Message::Kick message_kick;
- Message::Kill message_kill, message_svskill;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Version message_version;
- Message::Whois message_whois;
-
- /* Our message handlers */
- IRCDMessageCapab message_capab;
- IRCDMessageChgHost message_chghost;
- IRCDMessageChgIdent message_chgident;
- IRCDMessageChgName message_chgname;
- IRCDMessageMode message_mode, message_svsmode, message_svs2mode;
- IRCDMessageNetInfo message_netinfo;
- IRCDMessageNick message_nick;
- IRCDMessagePong message_pong;
- IRCDMessageSASL message_sasl;
- IRCDMessageSDesc message_sdesc;
- IRCDMessageSetHost message_sethost;
- IRCDMessageSetIdent message_setident;
- IRCDMessageSetName message_setname;
- IRCDMessageServer message_server;
- IRCDMessageSJoin message_sjoin;
- IRCDMessageTopic message_topic;
- IRCDMessageUmode2 message_umode2;
-
- bool use_server_side_mlock;
-
- void AddModes()
- {
- ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0));
- ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1));
- ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2));
- /* Unreal sends +q as * and +a as ~ */
- ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', '~', 3));
- ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '*', 4));
-
- /* Add user modes */
- ModeManager::AddUserMode(new UserModeOperOnly("SERV_ADMIN", 'A'));
- ModeManager::AddUserMode(new UserMode("BOT", 'B'));
- ModeManager::AddUserMode(new UserModeOperOnly("CO_ADMIN", 'C'));
- ModeManager::AddUserMode(new UserMode("CENSOR", 'G'));
- ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H'));
- ModeManager::AddUserMode(new UserModeOperOnly("HIDEIDLE", 'I'));
- ModeManager::AddUserMode(new UserModeOperOnly("NETADMIN", 'N'));
- ModeManager::AddUserMode(new UserMode("REGPRIV", 'R'));
- ModeManager::AddUserMode(new UserModeOperOnly("PROTECTED", 'S'));
- ModeManager::AddUserMode(new UserMode("NOCTCP", 'T'));
- ModeManager::AddUserMode(new UserMode("WEBTV", 'V'));
- ModeManager::AddUserMode(new UserModeOperOnly("WHOIS", 'W'));
- ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a'));
- ModeManager::AddUserMode(new UserMode("DEAF", 'd'));
- ModeManager::AddUserMode(new UserModeOperOnly("GLOBOPS", 'g'));
- ModeManager::AddUserMode(new UserModeOperOnly("HELPOP", 'h'));
- ModeManager::AddUserMode(new UserMode("INVIS", 'i'));
- ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o'));
- ModeManager::AddUserMode(new UserMode("PRIV", 'p'));
- ModeManager::AddUserMode(new UserModeOperOnly("GOD", 'q'));
- ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r'));
- ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's'));
- ModeManager::AddUserMode(new UserModeNoone("VHOST", 't'));
- ModeManager::AddUserMode(new UserMode("WALLOPS", 'w'));
- ModeManager::AddUserMode(new UserMode("CLOAK", 'x'));
- ModeManager::AddUserMode(new UserModeNoone("SSL", 'z'));
- }
-
- public:
- ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
- ircd_proto(this),
- message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this),
- message_kill(this), message_svskill(this, "SVSKILL"), message_motd(this), message_notice(this), message_part(this), message_ping(this),
- message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), message_time(this),
- message_version(this), message_whois(this),
-
- message_capab(this), message_chghost(this), message_chgident(this), message_chgname(this), message_mode(this, "MODE"),
- message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this),
- message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this),
- message_sjoin(this), message_topic(this), message_umode2(this)
- {
-
- this->AddModes();
- }
-
- void Prioritize() anope_override
- {
- ModuleManager::SetPriority(this, PRIORITY_FIRST);
- }
-
- void OnReload(Configuration::Conf *conf) anope_override
- {
- use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
- }
-
- void OnUserNickChange(User *u, const Anope::string &) anope_override
- {
- u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED"));
- if (Servers::Capab.count("ESVID") == 0)
- IRCD->SendLogout(u);
- }
-
- void OnChannelSync(Channel *c) anope_override
- {
- if (!c->ci)
- return;
-
- ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks");
- if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && modelocks)
- {
- Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes;
- }
- }
-
- void OnChanRegistered(ChannelInfo *ci) anope_override
- {
- ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
- if (!ci->c || !use_server_side_mlock || !modelocks || !Servers::Capab.count("MLOCK"))
- return;
- Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
- }
-
- void OnDelChan(ChannelInfo *ci) anope_override
- {
- if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK"))
- return;
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " :";
- }
-
- EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
- {
- ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
- ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
- if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
- {
- Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar;
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
- }
-
- return EVENT_CONTINUE;
- }
-
- EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
- {
- ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
- ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
- if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
- {
- Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
- }
-
- return EVENT_CONTINUE;
- }
-};
-
-MODULE_INIT(ProtoUnreal)
diff --git a/modules/protocol/unreal4.cpp b/modules/protocol/unrealircd.cpp
index 939a68eea..a49adac56 100644
--- a/modules/protocol/unreal4.cpp
+++ b/modules/protocol/unrealircd.cpp
@@ -1,4 +1,4 @@
-/* Unreal IRCD 4 functions
+/* UnrealIRCd functions
*
* (C) 2003-2024 Anope Team
* Contact us at team@anope.org
@@ -16,9 +16,10 @@
typedef Anope::map<Anope::string> ModData;
static Anope::string UplinkSID;
-class UnrealIRCdProto : public IRCDProto
+class UnrealIRCdProto final
+ : public IRCDProto
{
- public:
+public:
PrimitiveExtensibleItem<ModData> ClientModData;
PrimitiveExtensibleItem<ModData> ChannelModData;
@@ -34,19 +35,21 @@ class UnrealIRCdProto : public IRCDProto
CanSQLineChannel = true;
CanSZLine = true;
CanSVSHold = true;
+ CanClearBans = true;
+ CanSVSLogout = true;
CanCertFP = true;
RequiresID = true;
MaxModes = 12;
}
- private:
+private:
/* SVSNOOP */
- void SendSVSNOOP(const Server *server, bool set) anope_override
+ void SendSVSNOOP(const Server *server, bool set) override
{
- UplinkSocket::Message() << "SVSNOOP " << server->GetSID() << " " << (set ? "+" : "-");
+ Uplink::Send("SVSNOOP", server->GetSID(), set ? '+' : '-');
}
- void SendAkillDel(const XLine *x) anope_override
+ void SendAkillDel(const XLine *x) override
{
if (x->IsRegex() || x->HasNickOrReal())
return;
@@ -62,40 +65,40 @@ class UnrealIRCdProto : public IRCDProto
}
}
- UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << x->by;
+ Uplink::Send("TKL", '-', 'G', x->GetUser(), x->GetHost(), x->by);
}
- void SendTopic(const MessageSource &source, Channel *c) anope_override
+ void SendTopic(const MessageSource &source, Channel *c) override
{
- UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic;
+ Uplink::Send(source, "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic);
}
- void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg);
}
- void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override
+ void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override
{
- UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg;
+ Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg);
}
- void SendVhostDel(User *u) anope_override
+ void SendVhostDel(User *u) override
{
BotInfo *HostServ = Config->GetClient("HostServ");
u->RemoveMode(HostServ, "VHOST");
}
- void SendAkill(User *u, XLine *x) anope_override
+ void SendAkill(User *u, XLine *x) override
{
if (x->IsRegex() || x->HasNickOrReal())
{
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
@@ -105,7 +108,7 @@ class UnrealIRCdProto : public IRCDProto
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
+ auto *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id);
old->manager->AddXLine(xline);
x = xline;
@@ -123,45 +126,40 @@ class UnrealIRCdProto : public IRCDProto
}
}
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
- UplinkSocket::Message() << "TKL + G " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason();
+ Uplink::Send("TKL", '+', 'G', x->GetUser(), x->GetHost(), x->by, x->expires, x->created, x->GetReason());
}
- void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override
+ void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override
{
- UplinkSocket::Message(source) << "SVSKILL " << user->GetUID() << " :" << buf;
+ Uplink::Send(source, "SVSKILL", user->GetUID(), buf);
user->KillInternal(source, buf);
}
- void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override
+ void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values) override
{
- UplinkSocket::Message(source) << "SVS2MODE " << u->GetUID() <<" " << buf;
- }
+ auto params = values;
+ params.insert(params.begin(), { u->GetUID(), modes });
+ Uplink::SendInternal({}, source, "SVS2MODE", params);
+}
- void SendClientIntroduction(User *u) anope_override
+ void SendClientIntroduction(User *u) override
{
- Anope::string modes = "+" + u->GetModes();
- UplinkSocket::Message(u->server) << "UID " << u->nick << " 1 " << u->timestamp << " " << u->GetIdent() << " " << u->host << " "
- << u->GetUID() << " * " << modes << " " << (!u->vhost.empty() ? u->vhost : "*") << " "
- << (!u->chost.empty() ? u->chost : "*") << " " << "*" << " :" << u->realname;
+ Uplink::Send(u->server, "UID", u->nick, 1, u->timestamp, u->GetIdent(), u->host, u->GetUID(), '*', "+" + u->GetModes(),
+ u->vhost.empty() ? "*" : u->vhost, u->chost.empty() ? "*" : u->chost, "*", u->realname);
}
- void SendServer(const Server *server) anope_override
+ void SendServer(const Server *server) override
{
if (server == Me)
- UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() + 1 << " :" << server->GetDescription();
+ Uplink::Send("SERVER", server->GetName(), server->GetHops() + 1, server->GetDescription());
else
- UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " :" << server->GetDescription();
+ Uplink::Send("SID", server->GetName(), server->GetHops() + 1, server->GetSID(), server->GetDescription());
}
/* JOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override
{
- UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name
- << " +" << c->GetModes(true, true) << " :" << user->GetUID();
+ Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), user->GetUID());
if (status)
{
/* First save the channel status incase uc->Status == status */
@@ -174,8 +172,8 @@ class UnrealIRCdProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
@@ -184,9 +182,9 @@ class UnrealIRCdProto : public IRCDProto
/* unsqline
*/
- void SendSQLineDel(const XLine *x) anope_override
+ void SendSQLineDel(const XLine *x) override
{
- UplinkSocket::Message() << "UNSQLINE " << x->mask;
+ Uplink::Send("UNSQLINE", x->mask);
}
/* SQLINE */
@@ -194,26 +192,28 @@ class UnrealIRCdProto : public IRCDProto
** - Unreal will translate this to TKL for us
**
*/
- void SendSQLine(User *, const XLine *x) anope_override
+ void SendSQLine(User *, const XLine *x) override
{
- UplinkSocket::Message() << "TKL + Q * " << x->mask << " " << x->by << " " << x->expires << " " << x->created << " :" << x->GetReason();
+ Uplink::Send("TKL", '+', 'Q', "*", x->mask, x->by, x->expires, x->created, x->GetReason());
}
/* Functions that use serval cmd functions */
- void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override
+ void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override
{
if (!vIdent.empty())
- UplinkSocket::Message(Me) << "CHGIDENT " << u->GetUID() << " " << vIdent;
+ Uplink::Send("CHGIDENT", u->GetUID(), vIdent);
+
if (!vhost.empty())
- UplinkSocket::Message(Me) << "CHGHOST " << u->GetUID() << " " << vhost;
+ Uplink::Send("CHGHOST", u->GetUID(), vhost);
+
// Internally unreal sets +xt on chghost
BotInfo *bi = Config->GetClient("HostServ");
u->SetMode(bi, "CLOAK");
u->SetMode(bi, "VHOST");
}
- void SendConnect() anope_override
+ void SendConnect() override
{
/*
NICKv2 = Nick Version 2
@@ -227,68 +227,66 @@ class UnrealIRCdProto : public IRCDProto
VL = Version Info
SID = SID/UID mode
*/
- UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink].password;
- UplinkSocket::Message() << "PROTOCTL " << "NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT MLOCK SID MTAGS";
- UplinkSocket::Message() << "PROTOCTL " << "EAUTH=" << Me->GetName() << ",,,Anope-" << Anope::VersionShort();
- UplinkSocket::Message() << "PROTOCTL " << "SID=" << Me->GetSID();
+ Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password);
+
+ Uplink::Send("PROTOCTL", "NICKv2", "VHP", "UMODE2", "NICKIP", "SJOIN", "SJOIN2", "SJ3", "NOQUIT", "TKLEXT", "MLOCK", "SID", "MTAGS");
+ Uplink::Send("PROTOCTL", "EAUTH=" + Me->GetName() + ",,,Anope-" + Anope::VersionShort());
+ Uplink::Send("PROTOCTL", "SID=" + Me->GetSID());
+
SendServer(Me);
}
- void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override
+ void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override
{
Anope::string mechlist;
- for (unsigned i = 0; i < mechanisms.size(); ++i)
- mechlist += "," + mechanisms[i];
+ for (const auto &mechanism : mechanisms)
+ mechlist += "," + mechanism;
- UplinkSocket::Message() << "MD client " << Me->GetName() << " saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1));
+ Uplink::Send("MD", "client", Me->GetName(), "saslmechlist", mechanisms.empty() ? "" : mechlist.substr(1));
}
/* SVSHOLD - set */
- void SendSVSHold(const Anope::string &nick, time_t t) anope_override
+ void SendSVSHold(const Anope::string &nick, time_t t) override
{
- UplinkSocket::Message() << "TKL + Q H " << nick << " " << Me->GetName() << " " << Anope::CurTime + t << " " << Anope::CurTime << " :Being held for registered user";
+ Uplink::Send("TKL", '+', 'Q', 'H', nick, Me->GetName(), Anope::CurTime + t, Anope::CurTime, "Being held for a registered user");
}
/* SVSHOLD - release */
- void SendSVSHoldDel(const Anope::string &nick) anope_override
+ void SendSVSHoldDel(const Anope::string &nick) override
{
- UplinkSocket::Message() << "TKL - Q * " << nick << " " << Me->GetName();
+ Uplink::Send("TKL", '-', 'Q', '*', nick, Me->GetName());
}
/* UNSGLINE */
/*
* SVSNLINE - :realname mask
*/
- void SendSGLineDel(const XLine *x) anope_override
+ void SendSGLineDel(const XLine *x) override
{
- UplinkSocket::Message() << "SVSNLINE - :" << x->mask;
+ Uplink::Send("SVSNLINE", '-', x->mask);
}
/* UNSZLINE */
- void SendSZLineDel(const XLine *x) anope_override
+ void SendSZLineDel(const XLine *x) override
{
- UplinkSocket::Message() << "TKL - Z * " << x->GetHost() << " " << x->by;
+ Uplink::Send("TKL", '-', 'Z', '*', x->GetHost(), x->by);
}
/* SZLINE */
- void SendSZLine(User *, const XLine *x) anope_override
+ void SendSZLine(User *, const XLine *x) override
{
- // Calculate the time left before this would expire, capping it at 2 days
- time_t timeleft = x->expires - Anope::CurTime;
- if (timeleft > 172800 || !x->expires)
- timeleft = 172800;
- UplinkSocket::Message() << "TKL + Z * " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason();
+ Uplink::Send("TKL", '+', 'Z', '*', x->GetHost(), x->by, x->expires, x->created, x->GetReason());
}
/* SGLINE */
/*
* SVSNLINE + reason_where_is_space :realname mask with spaces
*/
- void SendSGLine(User *, const XLine *x) anope_override
+ void SendSGLine(User *, const XLine *x) override
{
Anope::string edited_reason = x->GetReason();
edited_reason = edited_reason.replace_all_cs(" ", "_");
- UplinkSocket::Message() << "SVSNLINE + " << edited_reason << " :" << x->mask;
+ Uplink::Send("SVSNLINE", '+', edited_reason, x->mask);
}
/* svsjoin
@@ -300,38 +298,38 @@ class UnrealIRCdProto : public IRCDProto
/* In older Unreal SVSJOIN and SVSNLINE tokens were mixed so SVSJOIN and SVSNLINE are broken
when coming from a none TOKEN'd server
*/
- void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) anope_override
+ void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) override
{
if (!param.empty())
- UplinkSocket::Message() << "SVSJOIN " << user->GetUID() << " " << chan << " :" << param;
+ Uplink::Send("SVSJOIN", user->GetUID(), chan, param);
else
- UplinkSocket::Message() << "SVSJOIN " << user->GetUID() << " " << chan;
+ Uplink::Send("SVSJOIN", user->GetUID(), chan);
}
- void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) anope_override
+ void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string &param) override
{
if (!param.empty())
- UplinkSocket::Message() << "SVSPART " << user->GetUID() << " " << chan << " :" << param;
+ Uplink::Send("SVSPART", user->GetUID(), chan, param);
else
- UplinkSocket::Message() << "SVSPART " << user->GetUID() << " " << chan;
+ Uplink::Send("SVSPART", user->GetUID(), chan);
}
- void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override
+ void SendGlobops(const MessageSource &source, const Anope::string &buf) override
{
- UplinkSocket::Message(Me) << "SENDUMODE o :from " << source.GetName() << ": " << buf;
+ Uplink::Send("SENDUMODE", 'o', "From " + source.GetName() + ": " + buf);
}
- void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) anope_override
+ void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) override
{
- UplinkSocket::Message() << "SWHOIS " << who << " :" << mask;
+ Uplink::Send("SWHOIS", who, mask);
}
- void SendEOB() anope_override
+ void SendEOB() override
{
- UplinkSocket::Message(Me) << "EOS";
+ Uplink::Send("EOS");
}
- bool IsNickValid(const Anope::string &nick) anope_override
+ bool IsNickValid(const Anope::string &nick) override
{
if (nick.equals_ci("ircd") || nick.equals_ci("irc"))
return false;
@@ -339,7 +337,7 @@ class UnrealIRCdProto : public IRCDProto
return IRCDProto::IsNickValid(nick);
}
- bool IsChannelValid(const Anope::string &chan) anope_override
+ bool IsChannelValid(const Anope::string &chan) override
{
if (chan.find(':') != Anope::string::npos)
return false;
@@ -347,32 +345,31 @@ class UnrealIRCdProto : public IRCDProto
return IRCDProto::IsChannelValid(chan);
}
- bool IsExtbanValid(const Anope::string &mask) anope_override
+ bool IsExtbanValid(const Anope::string &mask) override
{
return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':';
}
- void SendLogin(User *u, NickAlias *na) anope_override
+ void SendLogin(User *u, NickAlias *na) override
{
/* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */
if (Servers::Capab.count("ESVID") > 0 && !na->nc->HasExt("UNCONFIRMED"))
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str());
+ IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", na->nc->display);
else
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon);
+ IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", u->signon);
}
- void SendLogout(User *u) anope_override
+ void SendLogout(User *u) override
{
- IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0");
+ IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", 0);
}
- void SendChannel(Channel *c) anope_override
+ void SendChannel(Channel *c) override
{
- UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name
- << " +" << c->GetModes(true, true) << " :";
+ Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), "");
}
- void SendSASLMessage(const SASL::Message &message) anope_override
+ void SendSASLMessage(const SASL::Message &message) override
{
size_t p = message.target.find('!');
Anope::string distmask;
@@ -389,10 +386,13 @@ class UnrealIRCdProto : public IRCDProto
distmask = message.target.substr(0, p);
}
- UplinkSocket::Message(BotInfo::Find(message.source)) << "SASL " << distmask << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : " " + message.ext);
+ if (message.ext.empty())
+ Uplink::Send(BotInfo::Find(message.source), "SASL", distmask, message.target, message.type, message.data);
+ else
+ Uplink::Send(BotInfo::Find(message.source), "SASL", distmask, message.target, message.type, message.data, message.ext);
}
- void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override
+ void SendSVSLogin(const Anope::string &uid, NickAlias *na) override
{
size_t p = uid.find('!');
Anope::string distmask;
@@ -409,22 +409,25 @@ class UnrealIRCdProto : public IRCDProto
distmask = uid.substr(0, p);
}
- if (!vident.empty())
- UplinkSocket::Message(Me) << "CHGIDENT " << uid << " " << vident;
- if (!vhost.empty())
- UplinkSocket::Message(Me) << "CHGHOST " << uid << " " << vhost;
- UplinkSocket::Message(Me) << "SVSLOGIN " << distmask << " " << uid << " " << acc;
+ if (na)
+ {
+ if (!na->GetVhostIdent().empty())
+ Uplink::Send("CHGIDENT", uid, na->GetVhostIdent());
+
+ if (!na->GetVhostHost().empty())
+ Uplink::Send("CHGHOST", uid, na->GetVhostHost());
+ }
+
+ Uplink::Send("SVSLOGIN", distmask, uid, na ? na->nc->display : "0");
}
- bool IsIdentValid(const Anope::string &ident) anope_override
+ bool IsIdentValid(const Anope::string &ident) override
{
- if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
+ if (ident.empty() || ident.length() > IRCD->GetMaxUser())
return false;
- for (unsigned i = 0; i < ident.length(); ++i)
+ for (auto c : ident)
{
- const char &c = ident[i];
-
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
continue;
@@ -436,25 +439,38 @@ class UnrealIRCdProto : public IRCDProto
return true;
}
+
+ void SendClearBans(const MessageSource &user, Channel *c, User* u) override
+ {
+ Uplink::Send(user, "SVS2MODE", c->name, "-b", u->GetUID());
+ }
+
+ bool IsTagValid(const Anope::string &tname, const Anope::string &tvalue) override
+ {
+ if (Servers::Capab.count("MTAGS"))
+ return true;
+ return false;
+ }
};
-class UnrealExtBan : public ChannelModeVirtual<ChannelModeList>
+class UnrealExtBan
+ : public ChannelModeVirtual<ChannelModeList>
{
char ext;
- public:
+public:
UnrealExtBan(const Anope::string &mname, const Anope::string &basename, char extban) : ChannelModeVirtual<ChannelModeList>(mname, basename)
, ext(extban)
{
}
- ChannelMode *Wrap(Anope::string &param) anope_override
+ ChannelMode *Wrap(Anope::string &param) override
{
param = "~" + Anope::string(ext) + ":" + param;
return ChannelModeVirtual<ChannelModeList>::Wrap(param);
}
- ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) anope_override
+ ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) override
{
if (cm->type != MODE_LIST || param.length() < 4 || param[0] != '~' || param[1] != ext || param[2] != ':')
return cm;
@@ -466,14 +482,15 @@ class UnrealExtBan : public ChannelModeVirtual<ChannelModeList>
namespace UnrealExtban
{
- class ChannelMatcher : public UnrealExtBan
+ class ChannelMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
ChannelMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string channel = mask.substr(3);
@@ -501,14 +518,15 @@ namespace UnrealExtban
}
};
- class EntryMatcher : public UnrealExtBan
+ class EntryMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
EntryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
@@ -517,14 +535,15 @@ namespace UnrealExtban
}
};
- class RealnameMatcher : public UnrealExtBan
+ class RealnameMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
RealnameMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
@@ -533,28 +552,30 @@ namespace UnrealExtban
}
};
- class RegisteredMatcher : public UnrealExtBan
+ class RegisteredMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
RegisteredMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
return u->HasMode("REGISTERED") && mask.equals_ci(u->nick);
}
};
- class AccountMatcher : public UnrealExtBan
+ class AccountMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
AccountMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
@@ -566,29 +587,31 @@ namespace UnrealExtban
}
};
- class FingerprintMatcher : public UnrealExtBan
+ class FingerprintMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask);
}
};
-
- class OperclassMatcher : public UnrealExtBan
+
+ class OperclassMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
OperclassMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
-
- bool Matches(User *u, const Entry *e) anope_override
+
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
@@ -596,15 +619,16 @@ namespace UnrealExtban
return moddata != NULL && moddata->find("operclass") != moddata->end() && Anope::Match((*moddata)["operclass"], real_mask);
}
};
-
- class TimedBanMatcher : public UnrealExtBan
+
+ class TimedBanMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
TimedBanMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
-
- bool Matches(User *u, const Entry *e) anope_override
+
+ bool Matches(User *u, const Entry *e) override
{
/* strip down the time (~t:1234:) and call other matchers */
const Anope::string &mask = e->GetMask();
@@ -614,14 +638,15 @@ namespace UnrealExtban
}
};
- class CountryMatcher : public UnrealExtBan
+ class CountryMatcher final
+ : public UnrealExtBan
{
- public:
+ public:
CountryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c)
{
}
-
- bool Matches(User *u, const Entry *e) anope_override
+
+ bool Matches(User *u, const Entry *e) override
{
const Anope::string &mask = e->GetMask();
Anope::string real_mask = mask.substr(3);
@@ -639,26 +664,27 @@ namespace UnrealExtban
return false;
}
};
-
}
-class ChannelModeFlood : public ChannelModeParam
+class ChannelModeFlood final
+ : public ChannelModeParam
{
- public:
+public:
ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { }
/* Borrowed part of this check from UnrealIRCd */
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
- if (value.empty())
+ if (value.empty() || value[0] == ':')
return false;
- try
- {
- Anope::string rest;
- if (value[0] != ':' && convertTo<unsigned>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<unsigned>(rest.substr(1), rest, false) > 0 && rest.empty())
- return true;
- }
- catch (const ConvertException &) { }
+
+ Anope::string rest;
+ auto num1 = Anope::Convert<unsigned>(value[0] == '*' ? value.substr(1) : value, 0, &rest);
+ if (!num1 || rest[0] != ':' || rest.length() <= 1)
+ return false;
+
+ if (Anope::Convert<int>(rest.substr(1), 0, &rest) > 0 && rest.empty())
+ return true;
/* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */
size_t end_bracket = value.find(']', 1);
@@ -675,30 +701,25 @@ class ChannelModeFlood : public ChannelModeParam
size_t p = 0;
while (p < arg.length() && isdigit(arg[p]))
++p;
- if (p == arg.length() || !(arg[p] == 'c' || arg[p] == 'j' || arg[p] == 'k' || arg[p] == 'm' || arg[p] == 'n' || arg[p] == 't'))
+ if (p == arg.length() || (arg[p] != 'c' && arg[p] != 'j' && arg[p] != 'k' && arg[p] != 'm' && arg[p] != 'n' && arg[p] != 't'))
continue; /* continue instead of break for forward compatibility. */
- try
- {
- int v = arg.substr(0, p).is_number_only() ? convertTo<int>(arg.substr(0, p)) : 0;
- if (v < 1 || v > 999)
- return false;
- }
- catch (const ConvertException &)
- {
+
+ auto v = Anope::Convert<int>(arg.substr(0, p), 0);
+ if (v < 1 || v > 999)
return false;
- }
}
return true;
}
};
-class ChannelModeHistory : public ChannelModeParam /* stolen from inspircd3's ColonDelimitedParamMode */
+class ChannelModeHistory final
+ : public ChannelModeParam
{
- public:
+public:
ChannelModeHistory(char modeChar) : ChannelModeParam("HISTORY", modeChar, true) { }
- bool IsValid(Anope::string &value) const anope_override
+ bool IsValid(Anope::string &value) const override
{
if (value.empty())
return false; // empty param is never valid
@@ -708,59 +729,46 @@ class ChannelModeHistory : public ChannelModeParam /* stolen from inspircd3's Co
return false; // no ':' or it's the first char, both are invalid
Anope::string rest;
- try
- {
- if (convertTo<int>(value, rest, false) <= 0)
- return false; // negative numbers and zero are invalid
+ if (Anope::Convert<int>(value, 0, &rest) <= 0)
+ return false; // negative numbers and zero are invalid
- rest = rest.substr(1);
- int n;
- // The part after the ':' is a duration and it
- // can be in the user friendly "1d3h20m" format, make sure we accept that
- n = Anope::DoTime(rest);
-
- if (n <= 0)
- return false;
- }
- catch (const ConvertException &e)
- {
- // conversion error, invalid
+ // The part after the ':' is a duration and it
+ // can be in the user friendly "1d3h20m" format, make sure we accept that
+ auto n = Anope::DoTime(rest.substr(1));
+ return n <= 0;
return false;
- }
-
- return true;
}
};
-class ChannelModeUnrealSSL : public ChannelMode
+class ChannelModeUnrealSSL final
+ : public ChannelMode
{
- public:
+public:
ChannelModeUnrealSSL(const Anope::string &n, char c) : ChannelMode(n, c)
{
}
- bool CanSet(User *u) const anope_override
+ bool CanSet(User *u) const override
{
return false;
}
};
-struct IRCDMessageCapab : Message::Capab
+struct IRCDMessageCapab final
+ : Message::Capab
{
IRCDMessageCapab(Module *creator) : Message::Capab(creator, "PROTOCTL") { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- for (unsigned i = 0; i < params.size(); ++i)
+ for (const auto &capab : params)
{
- Anope::string capab = params[i];
-
if (capab.find("USERMODES=") != Anope::string::npos)
{
Anope::string modebuf(capab.begin() + 10, capab.end());
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'B':
ModeManager::AddUserMode(new UserMode("BOT", 'B'));
@@ -826,7 +834,7 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddUserMode(new UserMode("SSLPRIV", 'Z'));
continue;
default:
- ModeManager::AddUserMode(new UserMode("", modebuf[t]));
+ ModeManager::AddUserMode(new UserMode("", mode));
}
}
}
@@ -837,9 +845,9 @@ struct IRCDMessageCapab : Message::Capab
Anope::string modebuf;
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'b':
ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b'));
@@ -863,14 +871,14 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t]));
+ ModeManager::AddChannelMode(new ChannelModeList("", mode));
}
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'k':
ModeManager::AddChannelMode(new ChannelModeKey('k'));
@@ -882,14 +890,14 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t]));
+ ModeManager::AddChannelMode(new ChannelModeParam("", mode));
}
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'l':
ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true));
@@ -898,14 +906,14 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeHistory('H'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true));
+ ModeManager::AddChannelMode(new ChannelModeParam("", mode, true));
}
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'p':
ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p'));
@@ -980,7 +988,7 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeOperOnly("PERM", 'P'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelMode("", modebuf[t]));
+ ModeManager::AddChannelMode(new ChannelMode("", mode));
}
}
}
@@ -995,7 +1003,7 @@ struct IRCDMessageCapab : Message::Capab
std::size_t mode_count = modes.find(')');
Anope::string mode_prefixes = modes.substr(0, mode_count);
Anope::string mode_chars = modes.substr(mode_count+1, mode_count);
-
+
for (size_t t = 0, end = mode_chars.length(); t < end; ++t)
{
Anope::string mode_name;
@@ -1026,15 +1034,16 @@ struct IRCDMessageCapab : Message::Capab
}
}
- Message::Capab::Run(source, params);
+ Message::Capab::Run(source, params, tags);
}
};
-struct IRCDMessageChgHost : IRCDMessage
+struct IRCDMessageChgHost final
+ : IRCDMessage
{
IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = User::Find(params[0]);
if (u)
@@ -1042,11 +1051,12 @@ struct IRCDMessageChgHost : IRCDMessage
}
};
-struct IRCDMessageChgIdent : IRCDMessage
+struct IRCDMessageChgIdent final
+ : IRCDMessage
{
IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = User::Find(params[0]);
if (u)
@@ -1054,11 +1064,12 @@ struct IRCDMessageChgIdent : IRCDMessage
}
};
-struct IRCDMessageChgName : IRCDMessage
+struct IRCDMessageChgName final
+ : IRCDMessage
{
IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = User::Find(params[0]);
if (u)
@@ -1066,17 +1077,18 @@ struct IRCDMessageChgName : IRCDMessage
}
};
-struct IRCDMessageMD : IRCDMessage
+struct IRCDMessageMD final
+ : IRCDMessage
{
PrimitiveExtensibleItem<ModData> &ClientModData;
PrimitiveExtensibleItem<ModData> &ChannelModData;
IRCDMessageMD(Module *creator, PrimitiveExtensibleItem<ModData> &clmoddata, PrimitiveExtensibleItem<ModData> &chmoddata) : IRCDMessage(creator, "MD", 3), ClientModData(clmoddata), ChannelModData(chmoddata)
{
- SetFlag(IRCDMESSAGE_SOFT_LIMIT);
+ SetFlag(FLAG_SOFT_LIMIT);
}
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
const Anope::string &mdtype = params[0],
&obj = params[1],
@@ -1089,9 +1101,9 @@ struct IRCDMessageMD : IRCDMessage
if (u == NULL)
return;
-
+
ModData &clientmd = *ClientModData.Require(u);
-
+
if (value.empty())
{
clientmd.erase(var);
@@ -1115,9 +1127,9 @@ struct IRCDMessageMD : IRCDMessage
if (c == NULL)
return;
-
+
ModData &channelmd = *ChannelModData.Require(c);
-
+
if (value.empty())
{
channelmd.erase(var);
@@ -1132,11 +1144,12 @@ struct IRCDMessageMD : IRCDMessage
}
};
-struct IRCDMessageMode : IRCDMessage
+struct IRCDMessageMode final
+ : IRCDMessage
{
- IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
bool server_source = source.GetServer() != NULL;
Anope::string modes = params[1];
@@ -1146,14 +1159,7 @@ struct IRCDMessageMode : IRCDMessage
if (IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
- time_t ts = 0;
-
- try
- {
- if (server_source)
- ts = convertTo<time_t>(params[params.size() - 1]);
- }
- catch (const ConvertException &) { }
+ auto ts = IRCD->ExtractTimestamp(params.back());
if (c)
c->SetModesInternal(source, modes, ts);
@@ -1162,7 +1168,7 @@ struct IRCDMessageMode : IRCDMessage
{
User *u = User::Find(params[0]);
if (u)
- u->SetModesInternal(source, "%s", params[1].c_str());
+ u->SetModesInternal(source, params[1]);
}
}
};
@@ -1177,19 +1183,21 @@ struct IRCDMessageMode : IRCDMessage
* argv[6] = free(**)
* argv[7] = ircnet
*/
-struct IRCDMessageNetInfo : IRCDMessage
+struct IRCDMessageNetInfo final
+ : IRCDMessage
{
- IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7];
+ Uplink::Send("NETINFO", MaxUserCount, Anope::CurTime, params[2], params[3], 0, 0, 0, params[7]);
}
};
-struct IRCDMessageNick : IRCDMessage
+struct IRCDMessageNick final
+ : IRCDMessage
{
- IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(FLAG_SOFT_LIMIT); }
/*
** NICK - new
@@ -1211,7 +1219,7 @@ struct IRCDMessageNick : IRCDMessage
** parv[0] = new nickname
** parv[1] = hopcount
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (params.size() == 11)
{
@@ -1230,8 +1238,7 @@ struct IRCDMessageNick : IRCDMessage
if (vhost.equals_cs("*"))
vhost.clear();
- time_t user_ts = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime;
-
+ auto user_ts = IRCD->ExtractTimestamp(params[2]);
Server *s = Server::Find(params[5]);
if (s == NULL)
{
@@ -1245,7 +1252,7 @@ struct IRCDMessageNick : IRCDMessage
;
else if (params[6].is_pos_number_only())
{
- if (convertTo<time_t>(params[6]) == user_ts)
+ if (IRCD->ExtractTimestamp(params[6]) == user_ts)
na = NickAlias::Find(params[0]);
}
else
@@ -1273,22 +1280,24 @@ struct IRCDMessageNick : IRCDMessage
* with their server "not syncing". We now send a PING immediately when receiving a new server
* and then finish sync once we get a pong back from that server.
*/
-struct IRCDMessagePong : IRCDMessage
+struct IRCDMessagePong final
+ : IRCDMessage
{
- IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(FLAG_SOFT_LIMIT); SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (!source.GetServer()->IsSynced())
source.GetServer()->Sync(false);
}
};
-struct IRCDMessageSASL : IRCDMessage
+struct IRCDMessageSASL final
+ : IRCDMessage
{
- IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(FLAG_SOFT_LIMIT); SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
if (!SASL::sasl)
return;
@@ -1304,21 +1313,23 @@ struct IRCDMessageSASL : IRCDMessage
}
};
-struct IRCDMessageSDesc : IRCDMessage
+struct IRCDMessageSDesc final
+ : IRCDMessage
{
- IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
source.GetServer()->SetDescription(params[0]);
}
};
-struct IRCDMessageSetHost : IRCDMessage
+struct IRCDMessageSetHost final
+ : IRCDMessage
{
- IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = source.GetUser();
@@ -1330,35 +1341,38 @@ struct IRCDMessageSetHost : IRCDMessage
}
};
-struct IRCDMessageSetIdent : IRCDMessage
+struct IRCDMessageSetIdent final
+ : IRCDMessage
{
- IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = source.GetUser();
u->SetVIdent(params[0]);
}
};
-struct IRCDMessageSetName : IRCDMessage
+struct IRCDMessageSetName final
+ : IRCDMessage
{
- IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *u = source.GetUser();
u->SetRealname(params[0]);
}
};
-struct IRCDMessageServer : IRCDMessage
+struct IRCDMessageServer final
+ : IRCDMessage
{
- IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
+ auto hops = Anope::Convert<unsigned>(params[1], 0);
if (params[1].equals_cs("1"))
{
@@ -1374,13 +1388,14 @@ struct IRCDMessageServer : IRCDMessage
}
};
-struct IRCDMessageSID : IRCDMessage
+struct IRCDMessageSID final
+ : IRCDMessage
{
- IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0;
+ auto hops = Anope::Convert<unsigned>(params[1], 0);
new Server(source.GetServer(), params[0], hops, params[3], params[2]);
@@ -1401,11 +1416,12 @@ static char UnrealSjoinPrefixToModeChar(char sjoin_prefix)
}
}
-struct IRCDMessageSJoin : IRCDMessage
+struct IRCDMessageSJoin final
+ : IRCDMessage
{
- IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Anope::string modes;
if (params.size() >= 4)
@@ -1461,7 +1477,7 @@ struct IRCDMessageSJoin : IRCDMessage
}
}
- time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
+ auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[1], ts, modes, users);
if (!bans.empty() || !excepts.empty() || !invites.empty())
@@ -1476,19 +1492,56 @@ struct IRCDMessageSJoin : IRCDMessage
*invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE");
if (ban)
- for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it)
- c->SetModeInternal(source, ban, *it);
+ {
+ for (const auto &entry : bans)
+ c->SetModeInternal(source, ban, entry);
+ }
if (except)
- for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it)
- c->SetModeInternal(source, except, *it);
+ {
+ for (const auto &entry : excepts)
+ c->SetModeInternal(source, except, entry);
+ }
if (invex)
- for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it)
- c->SetModeInternal(source, invex, *it);
+ {
+ for (const auto &entry : invites)
+ c->SetModeInternal(source, invex, entry);
+ }
}
}
};
-struct IRCDMessageTopic : IRCDMessage
+class IRCDMessageSVSLogin final
+ : IRCDMessage
+{
+public:
+ IRCDMessageSVSLogin(Module *creator) : IRCDMessage(creator, "SVSLOGIN", 3) { SetFlag(FLAG_REQUIRE_SERVER); }
+
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
+ {
+ // :irc.example.com SVSLOGIN <mask> <nick> <account>
+ // :irc.example.com SVSLOGIN <mask> <nick> 0
+ User *u = User::Find(params[1]);
+ if (!u)
+ return; // Should never happen.
+
+ if (params[2] == "0")
+ {
+ // The user has been logged out by the IRC server.
+ u->Logout();
+ }
+ else
+ {
+ // If we're bursting then then the user was probably logged
+ // in during a previous connection.
+ NickCore *nc = NickCore::Find(params[2]);
+ if (nc)
+ u->Login(nc);
+ }
+ }
+};
+
+struct IRCDMessageTopic final
+ : IRCDMessage
{
IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { }
@@ -1499,11 +1552,11 @@ struct IRCDMessageTopic : IRCDMessage
** parv[2] = topic time
** parv[3] = topic text
*/
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Channel *c = Channel::Find(params[0]);
if (c)
- c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime);
+ c->ChangeTopicInternal(source.GetUser(), params[1], params[3], IRCD->ExtractTimestamp(params[2]));
}
};
@@ -1521,11 +1574,12 @@ struct IRCDMessageTopic : IRCDMessage
* parv[10] = ip
* parv[11] = info
*/
-struct IRCDMessageUID : IRCDMessage
+struct IRCDMessageUID final
+ : IRCDMessage
{
- IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 12) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
+ IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 12) { SetFlag(FLAG_REQUIRE_SERVER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
Anope::string
nickname = params[0],
@@ -1557,16 +1611,7 @@ struct IRCDMessageUID : IRCDMessage
if (chost == "*")
chost.clear();
- time_t user_ts;
- try
- {
- user_ts = convertTo<time_t>(timestamp);
- }
- catch (const ConvertException &)
- {
- user_ts = Anope::CurTime;
- }
-
+ auto user_ts = IRCD->ExtractTimestamp(timestamp);
NickAlias *na = NULL;
if (account == "0")
@@ -1575,7 +1620,7 @@ struct IRCDMessageUID : IRCDMessage
}
else if (account.is_pos_number_only())
{
- if (convertTo<time_t>(account) == user_ts)
+ if (IRCD->ExtractTimestamp(account) == user_ts)
na = NickAlias::Find(nickname);
}
else
@@ -1590,17 +1635,19 @@ struct IRCDMessageUID : IRCDMessage
}
};
-struct IRCDMessageUmode2 : IRCDMessage
+struct IRCDMessageUmode2 final
+ : IRCDMessage
{
- IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- source.GetUser()->SetModesInternal(source, "%s", params[0].c_str());
+ source.GetUser()->SetModesInternal(source, params[0]);
}
};
-class ProtoUnreal : public Module
+class ProtoUnreal final
+ : public Module
{
UnrealIRCdProto ircd_proto;
@@ -1641,13 +1688,14 @@ class ProtoUnreal : public Module
IRCDMessageServer message_server;
IRCDMessageSID message_sid;
IRCDMessageSJoin message_sjoin;
+ IRCDMessageSVSLogin message_svslogin;
IRCDMessageTopic message_topic;
IRCDMessageUID message_uid;
IRCDMessageUmode2 message_umode2;
bool use_server_side_mlock;
- public:
+public:
ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this),
message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this),
@@ -1659,29 +1707,29 @@ class ProtoUnreal : public Module
message_md(this, ircd_proto.ClientModData, ircd_proto.ChannelModData),message_mode(this, "MODE"),
message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this),
message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this),
- message_sid(this), message_sjoin(this), message_topic(this), message_uid(this), message_umode2(this)
+ message_sid(this), message_sjoin(this), message_svslogin(this), message_topic(this), message_uid(this), message_umode2(this)
{
}
- void Prioritize() anope_override
+ void Prioritize() override
{
ModuleManager::SetPriority(this, PRIORITY_FIRST);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
}
- void OnUserNickChange(User *u, const Anope::string &) anope_override
+ void OnUserNickChange(User *u, const Anope::string &) override
{
u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED"));
if (Servers::Capab.count("ESVID") == 0)
IRCD->SendLogout(u);
}
- void OnChannelSync(Channel *c) anope_override
+ void OnChannelSync(Channel *c) override
{
if (!c->ci)
return;
@@ -1690,58 +1738,51 @@ class ProtoUnreal : public Module
if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && modelocks)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes;
+ Uplink::Send("MLOCK", c->creation_time, c->ci->name, modes);
}
}
- void OnChanRegistered(ChannelInfo *ci) anope_override
+ void OnChanRegistered(ChannelInfo *ci) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
if (!ci->c || !use_server_side_mlock || !modelocks || !Servers::Capab.count("MLOCK"))
return;
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, modes);
}
- void OnDelChan(ChannelInfo *ci) anope_override
+ void OnDelChan(ChannelInfo *ci) override
{
if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK"))
return;
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " :";
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, "");
}
- EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar;
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, modes);
}
return EVENT_CONTINUE;
}
- EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
+ EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override
{
ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks");
ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0)
{
Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, "");
- UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes;
+ Uplink::Send("MLOCK", ci->c->creation_time, ci->name, modes);
}
return EVENT_CONTINUE;
}
-
- void OnChannelUnban(User *u, ChannelInfo *ci) anope_override
- {
- UplinkSocket::Message(ci->WhoSends()) << "SVS2MODE " << ci->c->name << " -b " << u->GetUID();
- /* Unreal will remove all matching bans for us regardless of our internal matching.
- Don't use Message(Me) here as certain Unreal versions will always respond with TS-less MODE message. */
- }
};
MODULE_INIT(ProtoUnreal)
diff --git a/modules/m_proxyscan.cpp b/modules/proxyscan.cpp
index b9ab48678..e7c761c9f 100644
--- a/modules/m_proxyscan.cpp
+++ b/modules/proxyscan.cpp
@@ -8,7 +8,7 @@
#include "module.h"
-struct ProxyCheck
+struct ProxyCheck final
{
std::set<Anope::string, ci::less> types;
std::vector<unsigned short> ports;
@@ -21,42 +21,46 @@ static Anope::string target_ip;
static unsigned short target_port;
static bool add_to_akill;
-class ProxyCallbackListener : public ListenSocket
+class ProxyCallbackListener final
+ : public ListenSocket
{
- class ProxyCallbackClient : public ClientSocket, public BufferedSocket
+ class ProxyCallbackClient final
+ : public ClientSocket
+ , public BufferedSocket
{
- public:
- ProxyCallbackClient(ListenSocket *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), ClientSocket(l, a), BufferedSocket()
+ public:
+ ProxyCallbackClient(ListenSocket *l, int f, const sockaddrs &a) : Socket(f, l->GetFamily()), ClientSocket(l, a), BufferedSocket()
{
}
- void OnAccept() anope_override
+ void OnAccept() override
{
this->Write(ProxyCheckString);
}
- bool ProcessWrite() anope_override
+ bool ProcessWrite() override
{
- return !BufferedSocket::ProcessWrite() || this->write_buffer.empty() ? false : true;
+ return !(!BufferedSocket::ProcessWrite() || this->write_buffer.empty());
}
};
- public:
- ProxyCallbackListener(const Anope::string &b, int p) : Socket(-1, b.find(':') != Anope::string::npos), ListenSocket(b, p, false)
+public:
+ ProxyCallbackListener(const Anope::string &b, int p) : Socket(-1, b.find(':') == Anope::string::npos ? AF_INET : AF_INET6), ListenSocket(b, p, false)
{
}
- ClientSocket *OnAccept(int fd, const sockaddrs &addr) anope_override
+ ClientSocket *OnAccept(int fd, const sockaddrs &addr) override
{
return new ProxyCallbackClient(this, fd, addr);
}
};
-class ProxyConnect : public ConnectionSocket
+class ProxyConnect
+ : public ConnectionSocket
{
static ServiceReference<XLineManager> akills;
- public:
+public:
static std::set<ProxyConnect *> proxies;
ProxyCheck proxy;
@@ -69,26 +73,26 @@ class ProxyConnect : public ConnectionSocket
proxies.insert(this);
}
- ~ProxyConnect()
+ ~ProxyConnect() override
{
proxies.erase(this);
}
- virtual void OnConnect() anope_override = 0;
+ void OnConnect() override = 0;
virtual const Anope::string GetType() const = 0;
- protected:
+protected:
void Ban()
{
Anope::string reason = this->proxy.reason;
reason = reason.replace_all_cs("%t", this->GetType());
reason = reason.replace_all_cs("%i", this->conaddr.addr());
- reason = reason.replace_all_cs("%p", stringify(this->conaddr.port()));
+ reason = reason.replace_all_cs("%p", Anope::ToString(this->conaddr.port()));
BotInfo *OperServ = Config->GetClient("OperServ");
- Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.addr() << ":" << this->conaddr.port() << " (" << reason << ")";
- XLine *x = new XLine("*@" + this->conaddr.addr(), OperServ ? OperServ->nick : "", Anope::CurTime + this->proxy.duration, reason, XLineManager::GenerateUID());
+ Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.str() << " (" << reason << ")";
+ auto *x = new XLine("*@" + this->conaddr.addr(), OperServ ? OperServ->nick : "", Anope::CurTime + this->proxy.duration, reason, XLineManager::GenerateUID());
if (add_to_akill && akills)
{
akills->AddXLine(x);
@@ -107,14 +111,16 @@ class ProxyConnect : public ConnectionSocket
ServiceReference<XLineManager> ProxyConnect::akills("XLineManager", "xlinemanager/sgline");
std::set<ProxyConnect *> ProxyConnect::proxies;
-class HTTPProxyConnect : public ProxyConnect, public BufferedSocket
+class HTTPProxyConnect final
+ : public ProxyConnect
+ , public BufferedSocket
{
- public:
+public:
HTTPProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BufferedSocket()
{
}
- void OnConnect() anope_override
+ void OnConnect() override
{
this->Write("CONNECT %s:%d HTTP/1.0", target_ip.c_str(), target_port);
this->Write("Content-Length: 0");
@@ -122,12 +128,12 @@ class HTTPProxyConnect : public ProxyConnect, public BufferedSocket
this->Write("");
}
- const Anope::string GetType() const anope_override
+ const Anope::string GetType() const override
{
return "HTTP";
}
- bool ProcessRead() anope_override
+ bool ProcessRead() override
{
bool b = BufferedSocket::ProcessRead();
if (this->GetLine() == ProxyCheckString)
@@ -139,14 +145,16 @@ class HTTPProxyConnect : public ProxyConnect, public BufferedSocket
}
};
-class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket
+class SOCKS5ProxyConnect final
+ : public ProxyConnect
+ , public BinarySocket
{
- public:
+public:
SOCKS5ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BinarySocket()
{
}
- void OnConnect() anope_override
+ void OnConnect() override
{
sockaddrs target_addr;
char buf[4 + sizeof(target_addr.sa4.sin_addr.s_addr) + sizeof(target_addr.sa4.sin_port)];
@@ -173,12 +181,12 @@ class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket
this->Write(buf, ptr);
}
- const Anope::string GetType() const anope_override
+ const Anope::string GetType() const override
{
return "SOCKS5";
}
- bool Read(const char *buffer, size_t l) anope_override
+ bool Read(const char *buffer, size_t l) override
{
if (l >= ProxyCheckString.length() && !strncmp(buffer, ProxyCheckString.c_str(), ProxyCheckString.length()))
{
@@ -189,7 +197,8 @@ class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket
}
};
-class ModuleProxyScan : public Module
+class ModuleProxyScan final
+ : public Module
{
Anope::string listen_ip;
unsigned short listen_port;
@@ -198,14 +207,16 @@ class ModuleProxyScan : public Module
ProxyCallbackListener *listener;
- class ConnectionTimeout : public Timer
+ class ConnectionTimeout final
+ : public Timer
{
- public:
- ConnectionTimeout(Module *c, long timeout) : Timer(c, timeout, Anope::CurTime, true)
+ public:
+ ConnectionTimeout(Module *c, time_t timeout)
+ : Timer(c, timeout, true)
{
}
- void Tick(time_t) anope_override
+ void Tick() override
{
for (std::set<ProxyConnect *>::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;)
{
@@ -218,7 +229,7 @@ class ModuleProxyScan : public Module
}
} connectionTimeout;
- public:
+public:
ModuleProxyScan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
connectionTimeout(this, 5)
{
@@ -227,7 +238,7 @@ class ModuleProxyScan : public Module
this->listener = NULL;
}
- ~ModuleProxyScan()
+ ~ModuleProxyScan() override
{
for (std::set<ProxyConnect *>::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;)
{
@@ -249,7 +260,7 @@ class ModuleProxyScan : public Module
delete this->listener;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = Config->GetModule(this);
@@ -287,7 +298,7 @@ class ModuleProxyScan : public Module
}
catch (const SocketException &ex)
{
- throw ConfigException("m_proxyscan: " + ex.GetReason());
+ throw ConfigException("proxyscan: " + ex.GetReason());
}
this->proxyscans.clear();
@@ -310,12 +321,8 @@ class ModuleProxyScan : public Module
commasepstream sep2(block->Get<const Anope::string>("port"));
while (sep2.GetToken(token))
{
- try
- {
- unsigned short port = convertTo<unsigned short>(token);
- p.ports.push_back(port);
- }
- catch (const ConvertException &) { }
+ if (auto port = Anope::TryConvert<unsigned short>(token))
+ p.ports.push_back(port.value());
}
if (p.ports.empty())
continue;
@@ -329,7 +336,7 @@ class ModuleProxyScan : public Module
}
}
- void OnUserConnect(User *user, bool &exempt) anope_override
+ void OnUserConnect(User *user, bool &exempt) override
{
if (exempt || user->Quitting() || !Me->IsSynced() || !user->server->IsSynced())
return;
@@ -350,24 +357,24 @@ class ModuleProxyScan : public Module
{
ProxyCheck &p = this->proxyscans[i - 1];
- for (std::set<Anope::string, ci::less>::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it)
+ for (const auto &type : p.types)
{
- for (unsigned k = 0; k < p.ports.size(); ++k)
+ for (const auto port : p.ports)
{
try
{
ProxyConnect *con = NULL;
- if (it->equals_ci("HTTP"))
- con = new HTTPProxyConnect(p, p.ports[k]);
- else if (it->equals_ci("SOCKS5"))
- con = new SOCKS5ProxyConnect(p, p.ports[k]);
+ if (type.equals_ci("HTTP"))
+ con = new HTTPProxyConnect(p, port);
+ else if (type.equals_ci("SOCKS5"))
+ con = new SOCKS5ProxyConnect(p, port);
else
continue;
- con->Connect(user->ip.addr(), p.ports[k]);
+ con->Connect(user->ip.addr(), port);
}
catch (const SocketException &ex)
{
- Log(LOG_DEBUG) << "m_proxyscan: " << ex.GetReason();
+ Log(LOG_DEBUG) << "proxyscan: " << ex.GetReason();
}
}
}
diff --git a/modules/m_redis.cpp b/modules/redis.cpp
index 6982e8b2c..4e006c9ff 100644
--- a/modules/m_redis.cpp
+++ b/modules/redis.cpp
@@ -13,45 +13,46 @@ using namespace Redis;
class MyRedisService;
-class RedisSocket : public BinarySocket, public ConnectionSocket
+class RedisSocket final
+ : public BinarySocket
+ , public ConnectionSocket
{
size_t ParseReply(Reply &r, const char *buf, size_t l);
- public:
+public:
MyRedisService *provider;
std::deque<Interface *> interfaces;
std::map<Anope::string, Interface *> subinterfaces;
- RedisSocket(MyRedisService *pro, bool v6) : Socket(-1, v6), provider(pro) { }
+ RedisSocket(MyRedisService *pro, bool v6) : Socket(-1, v6 ? AF_INET6 : AF_INET), provider(pro) { }
- ~RedisSocket();
+ ~RedisSocket() override;
- void OnConnect() anope_override;
- void OnError(const Anope::string &error) anope_override;
+ void OnConnect() override;
+ void OnError(const Anope::string &error) override;
- bool Read(const char *buffer, size_t l) anope_override;
+ bool Read(const char *buffer, size_t l) override;
};
-class Transaction : public Interface
+class Transaction final
+ : public Interface
{
- public:
+public:
std::deque<Interface *> interfaces;
Transaction(Module *creator) : Interface(creator) { }
- ~Transaction()
+ ~Transaction() override
{
- for (unsigned i = 0; i < interfaces.size(); ++i)
+ for (auto *iface : interfaces)
{
- Interface *inter = interfaces[i];
-
- if (!inter)
+ if (!iface)
continue;
- inter->OnError("Interface going away");
+ iface->OnError("Interface going away");
}
}
- void OnResult(const Reply &r) anope_override
+ void OnResult(const Reply &r) override
{
/* This is a multi bulk reply of the results of the queued commands
* in this transaction
@@ -59,10 +60,8 @@ class Transaction : public Interface
Log(LOG_DEBUG_2) << "redis: transaction complete with " << r.multi_bulk.size() << " results";
- for (unsigned i = 0; i < r.multi_bulk.size(); ++i)
+ for (auto *result : r.multi_bulk)
{
- const Reply *reply = r.multi_bulk[i];
-
if (interfaces.empty())
break;
@@ -70,25 +69,25 @@ class Transaction : public Interface
interfaces.pop_front();
if (inter)
- inter->OnResult(*reply);
+ inter->OnResult(*result);
}
}
};
-class MyRedisService : public Provider
+class MyRedisService final
+ : public Provider
{
- public:
+public:
Anope::string host;
int port;
unsigned db;
- RedisSocket *sock, *sub;
+ RedisSocket *sock = nullptr, *sub = nullptr;
Transaction ti;
- bool in_transaction;
+ bool in_transaction = false;
- MyRedisService(Module *c, const Anope::string &n, const Anope::string &h, int p, unsigned d) : Provider(c, n), host(h), port(p), db(d), sock(NULL), sub(NULL),
- ti(c), in_transaction(false)
+ MyRedisService(Module *c, const Anope::string &n, const Anope::string &h, int p, unsigned d) : Provider(c, n), host(h), port(p), db(d), ti(c)
{
sock = new RedisSocket(this, host.find(':') != Anope::string::npos);
sock->Connect(host, port);
@@ -97,7 +96,7 @@ class MyRedisService : public Provider
sub->Connect(host, port);
}
- ~MyRedisService()
+ ~MyRedisService() override
{
if (sock)
{
@@ -112,8 +111,8 @@ class MyRedisService : public Provider
}
}
- private:
- inline void Pack(std::vector<char> &buffer, const char *buf, size_t sz = 0)
+private:
+ static inline void Pack(std::vector<char> &buffer, const char *buf, size_t sz = 0)
{
if (!sz)
sz = strlen(buf);
@@ -128,18 +127,16 @@ class MyRedisService : public Provider
std::vector<char> buffer;
Pack(buffer, "*");
- Pack(buffer, stringify(args.size()).c_str());
+ Pack(buffer, Anope::ToString(args.size()).c_str());
Pack(buffer, "\r\n");
- for (unsigned j = 0; j < args.size(); ++j)
+ for (const auto &[key, value] : args)
{
- const std::pair<const char *, size_t> &pair = args[j];
-
Pack(buffer, "$");
- Pack(buffer, stringify(pair.second).c_str());
+ Pack(buffer, Anope::ToString(value).c_str());
Pack(buffer, "\r\n");
- Pack(buffer, pair.first, pair.second);
+ Pack(buffer, key, value);
Pack(buffer, "\r\n");
}
@@ -156,8 +153,8 @@ class MyRedisService : public Provider
s->interfaces.push_back(i);
}
- public:
- bool IsSocketDead() anope_override
+public:
+ bool IsSocketDead() override
{
return this->sock && this->sock->flags[SF_DEAD];
}
@@ -165,8 +162,8 @@ class MyRedisService : public Provider
void SendCommand(RedisSocket *s, Interface *i, const std::vector<Anope::string> &cmds)
{
std::vector<std::pair<const char *, size_t> > args;
- for (unsigned j = 0; j < cmds.size(); ++j)
- args.push_back(std::make_pair(cmds[j].c_str(), cmds[j].length()));
+ for (const auto &cmd : cmds)
+ args.emplace_back(cmd.c_str(), cmd.length());
this->Send(s, i, args);
}
@@ -188,23 +185,23 @@ class MyRedisService : public Provider
this->Send(sock, i, args);
}
- void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) anope_override
+ void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) override
{
std::vector<std::pair<const char *, size_t> > args;
- for (unsigned j = 0; j < cmds.size(); ++j)
- args.push_back(std::make_pair(cmds[j].c_str(), cmds[j].length()));
+ for (const auto &cmd : cmds)
+ args.emplace_back(cmd.c_str(), cmd.length());
this->Send(i, args);
}
- void SendCommand(Interface *i, const Anope::string &str) anope_override
+ void SendCommand(Interface *i, const Anope::string &str) override
{
std::vector<Anope::string> args;
spacesepstream(str).GetTokens(args);
this->SendCommand(i, args);
}
- public:
- bool BlockAndProcess() anope_override
+public:
+ bool BlockAndProcess() override
{
if (!this->sock->ProcessWrite())
this->sock->flags[SF_DEAD] = true;
@@ -215,7 +212,7 @@ class MyRedisService : public Provider
return !this->sock->interfaces.empty();
}
- void Subscribe(Interface *i, const Anope::string &pattern) anope_override
+ void Subscribe(Interface *i, const Anope::string &pattern) override
{
if (sub == NULL)
{
@@ -224,20 +221,20 @@ class MyRedisService : public Provider
}
std::vector<Anope::string> args;
- args.push_back("PSUBSCRIBE");
+ args.emplace_back("PSUBSCRIBE");
args.push_back(pattern);
this->SendCommand(sub, NULL, args);
sub->subinterfaces[pattern] = i;
}
- void Unsubscribe(const Anope::string &pattern) anope_override
+ void Unsubscribe(const Anope::string &pattern) override
{
if (sub)
sub->subinterfaces.erase(pattern);
}
- void StartTransaction() anope_override
+ void StartTransaction() override
{
if (in_transaction)
throw CoreException();
@@ -246,7 +243,7 @@ class MyRedisService : public Provider
in_transaction = true;
}
- void CommitTransaction() anope_override
+ void CommitTransaction() override
{
/* The result of the transaction comes back to the reply of EXEC as a multi bulk.
* The reply to the individual commands that make up the transaction when executed
@@ -267,14 +264,12 @@ RedisSocket::~RedisSocket()
provider->sub = NULL;
}
- for (unsigned i = 0; i < interfaces.size(); ++i)
+ for (auto *iface : interfaces)
{
- Interface *inter = interfaces[i];
-
- if (!inter)
+ if (!iface)
continue;
- inter->OnError("Interface going away");
+ iface->OnError("Interface going away");
}
}
@@ -283,7 +278,7 @@ void RedisSocket::OnConnect()
Log() << "redis: Successfully connected to " << provider->name << (this == this->provider->sub ? " (sub)" : "");
this->provider->SendCommand(NULL, "CLIENT SETNAME Anope");
- this->provider->SendCommand(NULL, "SELECT " + stringify(provider->db));
+ this->provider->SendCommand(NULL, "SELECT " + Anope::ToString(provider->db));
if (this != this->provider->sub)
{
@@ -338,11 +333,8 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
size_t nl = ibuf.find("\r\n");
if (nl != Anope::string::npos)
{
- try
- {
- r.i = convertTo<int64_t>(ibuf.substr(0, nl));
- }
- catch (const ConvertException &) { }
+ if (auto i = Anope::TryConvert<int64_t>(ibuf.substr(0, nl)))
+ r.i = i.value();
r.type = Reply::INT;
used = 1 + nl + 2;
@@ -356,10 +348,9 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
size_t nl = reply.find("\r\n");
if (nl != Anope::string::npos)
{
- int len;
- try
+ if (auto l = Anope::TryConvert<int>(reply.substr(0, nl)))
{
- len = convertTo<int>(reply.substr(0, nl));
+ int len = l.value();
if (len >= 0)
{
if (1 + nl + 2 + len + 2 <= l)
@@ -375,7 +366,6 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
r.type = Reply::BULK;
}
}
- catch (const ConvertException &) { }
}
break;
}
@@ -389,12 +379,8 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
if (nl != Anope::string::npos)
{
r.type = Reply::MULTI_BULK;
- try
- {
- r.multi_bulk_size = convertTo<int>(reply.substr(0, nl));
- }
- catch (const ConvertException &) { }
-
+ if (auto size = Anope::TryConvert<int>(reply.substr(0, nl)))
+ r.multi_bulk_size = size.value();
used = 1 + nl + 2;
}
else
@@ -403,15 +389,15 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
else if (r.multi_bulk_size >= 0 && r.multi_bulk.size() == static_cast<unsigned>(r.multi_bulk_size))
{
/* This multi bulk is already complete, so check the sub bulks */
- for (unsigned i = 0; i < r.multi_bulk.size(); ++i)
- if (r.multi_bulk[i]->type == Reply::MULTI_BULK)
- ParseReply(*r.multi_bulk[i], buffer + used, l - used);
+ for (auto &bulk : r.multi_bulk)
+ if (bulk->type == Reply::MULTI_BULK)
+ ParseReply(*bulk, buffer + used, l - used);
break;
}
for (int i = r.multi_bulk.size(); i < r.multi_bulk_size; ++i)
{
- Reply *reply = new Reply();
+ auto *reply = new Reply();
size_t u = ParseReply(*reply, buffer + used, l - used);
if (!u)
{
@@ -525,23 +511,23 @@ bool RedisSocket::Read(const char *buffer, size_t l)
}
-class ModuleRedis : public Module
+class ModuleRedis final
+ : public Module
{
std::map<Anope::string, MyRedisService *> services;
- public:
+public:
ModuleRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
{
}
- ~ModuleRedis()
+ ~ModuleRedis() override
{
- for (std::map<Anope::string, MyRedisService *>::iterator it = services.begin(); it != services.end(); ++it)
+ for (auto &[_, p] : services)
{
- MyRedisService *p = it->second;
-
delete p->sock;
p->sock = NULL;
+
delete p->sub;
p->sub = NULL;
@@ -549,7 +535,7 @@ class ModuleRedis : public Module
}
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
std::vector<Anope::string> new_services;
@@ -578,12 +564,10 @@ class ModuleRedis : public Module
}
}
- void OnModuleUnload(User *, Module *m) anope_override
+ void OnModuleUnload(User *, Module *m) override
{
- for (std::map<Anope::string, MyRedisService *>::iterator it = services.begin(); it != services.end(); ++it)
+ for (auto &[_, p] : services)
{
- MyRedisService *p = it->second;
-
if (p->sock)
for (unsigned i = p->sock->interfaces.size(); i > 0; --i)
{
diff --git a/modules/regex_stdlib.cpp b/modules/regex_stdlib.cpp
new file mode 100644
index 000000000..0ef7e3f81
--- /dev/null
+++ b/modules/regex_stdlib.cpp
@@ -0,0 +1,107 @@
+/*
+ *
+ * (C) 2012-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "module.h"
+
+#include <regex>
+
+class StdLibRegex final
+ : public Regex
+{
+private:
+ std::regex regex;
+
+public:
+ StdLibRegex(const Anope::string &expr, std::regex::flag_type type)
+ : Regex(expr)
+ {
+ try
+ {
+ regex.assign(expr.str(), type | std::regex::optimize);
+ }
+ catch (const std::regex_error &error)
+ {
+ throw RegexException("Error in regex " + expr + ": " + error.what());
+ }
+ }
+
+ bool Matches(const Anope::string &str)
+ {
+ return std::regex_search(str.str(), regex);
+ }
+};
+
+class StdLibRegexProvider final
+ : public RegexProvider
+{
+public:
+ std::regex_constants::syntax_option_type type;
+
+ StdLibRegexProvider(Module *creator)
+ : RegexProvider(creator, "regex/stdlib")
+ {
+ }
+
+ Regex *Compile(const Anope::string &expression) override
+ {
+ return new StdLibRegex(expression, type);
+ }
+};
+
+class ModuleRegexStdLib final
+ : public Module
+{
+private:
+ StdLibRegexProvider stdlib_regex_provider;
+
+public:
+ ModuleRegexStdLib(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, EXTRA | VENDOR)
+ , stdlib_regex_provider(this)
+ {
+ this->SetPermanent(true);
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ Configuration::Block *block = conf->GetModule(this);
+
+ const Anope::string syntax = block->Get<const Anope::string>("syntax", "ecmascript");
+ if (syntax == "awk")
+ stdlib_regex_provider.type = std::regex::awk;
+ else if (syntax == "basic")
+ stdlib_regex_provider.type = std::regex::basic;
+ else if (syntax == "ecmascript")
+ stdlib_regex_provider.type = std::regex::ECMAScript;
+ else if (syntax == "egrep")
+ stdlib_regex_provider.type = std::regex::egrep;
+ else if (syntax == "extended")
+ stdlib_regex_provider.type = std::regex::extended;
+ else if (syntax == "grep")
+ stdlib_regex_provider.type = std::regex::grep;
+ else
+ throw ConfigException(this->name + ": syntax must be set to awk, basic, ecmascript, egrep, extended, or grep.");
+ }
+
+ ~ModuleRegexStdLib()
+ {
+ for (auto *xlm : XLineManager::XLineManagers)
+ {
+ for (auto *x : xlm->GetList())
+ {
+ if (x->regex && dynamic_cast<StdLibRegex *>(x->regex))
+ {
+ delete x->regex;
+ x->regex = NULL;
+ }
+ }
+ }
+ }
+};
+
+MODULE_INIT(ModuleRegexStdLib)
diff --git a/modules/m_rewrite.cpp b/modules/rewrite.cpp
index a8e96253a..008e3e722 100644
--- a/modules/m_rewrite.cpp
+++ b/modules/rewrite.cpp
@@ -8,7 +8,7 @@
#include "module.h"
-struct Rewrite
+struct Rewrite final
{
Anope::string client, source_message, target_message, desc;
@@ -38,28 +38,35 @@ struct Rewrite
else
{
int num = -1, end = -1;
- try
+ Anope::string num_str = token.substr(1);
+ size_t hy = num_str.find('-');
+ if (hy == Anope::string::npos)
{
- Anope::string num_str = token.substr(1);
- size_t hy = num_str.find('-');
- if (hy == Anope::string::npos)
- {
- num = convertTo<int>(num_str);
- end = num + 1;
- }
+ auto n = Anope::TryConvert<int>(num_str);
+ if (!n.has_value())
+ continue;
+
+ num = n.value();
+ end = num + 1;
+ }
+ else
+ {
+ auto n = Anope::TryConvert<int>(num_str.substr(0, hy));
+ if (!n.has_value())
+ continue;
+
+ num = n.value();
+ if (hy == num_str.length() - 1)
+ end = params.size();
else
{
- num = convertTo<int>(num_str.substr(0, hy));
- if (hy == num_str.length() - 1)
- end = params.size();
- else
- end = convertTo<int>(num_str.substr(hy + 1)) + 1;
+ n = Anope::TryConvert<int>(num_str.substr(hy + 1));
+ if (!n.has_value())
+ continue;
+
+ end = n.value() + 1;
}
}
- catch (const ConvertException &)
- {
- continue;
- }
for (int i = num; i < end && static_cast<unsigned>(i) < params.size(); ++i)
message += " " + params[i];
@@ -74,10 +81,8 @@ struct Rewrite
static Rewrite *Find(const Anope::string &client, const Anope::string &cmd)
{
- for (unsigned i = 0; i < rewrites.size(); ++i)
+ for (auto &r : rewrites)
{
- Rewrite &r = rewrites[i];
-
if ((client.empty() || r.client.equals_ci(client)) && (r.source_message.equals_ci(cmd) || r.source_message.find_ci(cmd + " ") == 0))
return &r;
}
@@ -87,10 +92,8 @@ struct Rewrite
static Rewrite *Match(const Anope::string &client, const std::vector<Anope::string> &params)
{
- for (unsigned i = 0; i < rewrites.size(); ++i)
+ for (auto &r : rewrites)
{
- Rewrite &r = rewrites[i];
-
if ((client.empty() || r.client.equals_ci(client)) && r.Matches(params))
return &r;
}
@@ -101,12 +104,13 @@ struct Rewrite
std::vector<Rewrite> Rewrite::rewrites;
-class RewriteCommand : public Command
+class RewriteCommand final
+ : public Command
{
- public:
+public:
RewriteCommand(Module *creator) : Command(creator, "rewrite", 0, 0) { }
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
std::vector<Anope::string> full_params = params;
full_params.insert(full_params.begin(), source.command);
@@ -115,17 +119,17 @@ class RewriteCommand : public Command
if (r != NULL)
{
Anope::string new_message = r->Process(source, full_params);
- Log(LOG_DEBUG) << "m_rewrite: Rewrote '" << source.command << (!params.empty() ? " " + params[0] : "") << "' to '" << new_message << "' using '" << r->source_message << "'";
+ Log(LOG_DEBUG) << "rewrite: Rewrote '" << source.command << (!params.empty() ? " " + params[0] : "") << "' to '" << new_message << "' using '" << r->source_message << "'";
source.service = BotInfo::Find(r->client, true);
if (!source.service)
return;
Command::Run(source, new_message);
}
else
- Log() << "m_rewrite: Unable to rewrite '" << source.command << (!params.empty() ? " " + params[0] : "") << "'";
+ Log() << "rewrite: Unable to rewrite '" << source.command << (!params.empty() ? " " + params[0] : "") << "'";
}
- void OnServHelp(CommandSource &source) anope_override
+ void OnServHelp(CommandSource &source) override
{
Rewrite *r = Rewrite::Find(!source.c ? source.service->nick : "", source.command);
if (r != NULL && !r->desc.empty())
@@ -135,7 +139,7 @@ class RewriteCommand : public Command
}
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
Rewrite *r = Rewrite::Find(!source.c ? source.service->nick : "", source.command);
if (r != NULL && !r->desc.empty())
@@ -149,16 +153,17 @@ class RewriteCommand : public Command
}
};
-class ModuleRewrite : public Module
+class ModuleRewrite final
+ : public Module
{
RewriteCommand cmdrewrite;
- public:
+public:
ModuleRewrite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA), cmdrewrite(this)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Rewrite::rewrites.clear();
diff --git a/modules/m_sasl.cpp b/modules/sasl.cpp
index 3eaf04412..815291166 100644
--- a/modules/m_sasl.cpp
+++ b/modules/sasl.cpp
@@ -12,12 +12,13 @@
using namespace SASL;
-class Plain : public Mechanism
+class Plain final
+ : public Mechanism
{
- public:
+public:
Plain(Module *o) : Mechanism(o, "PLAIN") { }
- void ProcessMessage(Session *sess, const SASL::Message &m) anope_override
+ void ProcessMessage(Session *sess, const SASL::Message &m) override
{
if (m.type == "S")
{
@@ -72,30 +73,32 @@ class Plain : public Mechanism
}
};
-class External : public Mechanism
+class External final
+ : public Mechanism
{
ServiceReference<CertService> certs;
- struct Session : SASL::Session
+ struct Session final
+ : SASL::Session
{
Anope::string cert;
Session(Mechanism *m, const Anope::string &u) : SASL::Session(m, u) { }
};
- public:
+public:
External(Module *o) : Mechanism(o, "EXTERNAL"), certs("CertService", "certs")
{
if (!IRCD || !IRCD->CanCertFP)
throw ModuleException("No CertFP");
}
- Session* CreateSession(const Anope::string &uid) anope_override
+ Session *CreateSession(const Anope::string &uid) override
{
return new Session(this, uid);
}
- void ProcessMessage(SASL::Session *sess, const SASL::Message &m) anope_override
+ void ProcessMessage(SASL::Session *sess, const SASL::Message &m) override
{
Session *mysess = anope_dynamic_static_cast<Session *>(sess);
@@ -134,20 +137,63 @@ class External : public Mechanism
}
};
-class SASLService : public SASL::Service, public Timer
+class Anonymous final
+ : public Mechanism
+{
+public:
+ Anonymous(Module *o) : Mechanism(o, "ANONYMOUS") { }
+
+ void ProcessMessage(Session *sess, const SASL::Message &m) override
+ {
+ if (!IRCD->CanSVSLogout && !User::Find(sess->uid))
+ {
+ // This IRCd can't log users out yet.
+ sasl->Fail(sess);
+ delete sess;
+ return;
+ }
+
+ if (m.type == "S")
+ {
+ sasl->SendMessage(sess, "C", "+");
+ }
+ else if (m.type == "C")
+ {
+ Anope::string decoded;
+ Anope::B64Decode(m.data, decoded);
+
+ Anope::string user = "A user";
+ if (!sess->hostname.empty() && !sess->ip.empty())
+ user = sess->hostname + " (" + sess->ip + ")";
+ if (!decoded.empty())
+ user += " [" + decoded + "]";
+
+ Log(this->owner, "sasl", Config->GetClient("NickServ")) << user << " unidentified using SASL ANONYMOUS";
+ sasl->Succeed(sess, nullptr);
+ }
+ }
+};
+
+class SASLService final
+ : public SASL::Service
+ , public Timer
{
std::map<Anope::string, SASL::Session *> sessions;
- public:
- SASLService(Module *o) : SASL::Service(o), Timer(o, 60, Anope::CurTime, true) { }
+public:
+ SASLService(Module *o)
+ : SASL::Service(o)
+ , Timer(o, 60, true)
+ {
+ }
- ~SASLService()
+ ~SASLService() override
{
- for (std::map<Anope::string, Session *>::iterator it = sessions.begin(); it != sessions.end(); it++)
- delete it->second;
+ for (const auto &[_, session] : sessions)
+ delete session;
}
- void ProcessMessage(const SASL::Message &m) anope_override
+ void ProcessMessage(const SASL::Message &m) override
{
if (m.target != "*")
{
@@ -160,7 +206,7 @@ class SASLService : public SASL::Service, public Timer
}
}
- Session* session = GetSession(m.source);
+ Session *session = GetSession(m.source);
if (m.type == "S")
{
@@ -212,7 +258,7 @@ class SASLService : public SASL::Service, public Timer
session->mech->ProcessMessage(session, m);
}
- Anope::string GetAgent() anope_override
+ Anope::string GetAgent() override
{
Anope::string agent = Config->GetModule(Service::owner)->Get<Anope::string>("agent", "NickServ");
BotInfo *bi = Config->GetClient(agent);
@@ -221,7 +267,7 @@ class SASLService : public SASL::Service, public Timer
return agent;
}
- Session* GetSession(const Anope::string &uid) anope_override
+ Session *GetSession(const Anope::string &uid) override
{
std::map<Anope::string, Session *>::iterator it = sessions.find(uid);
if (it != sessions.end())
@@ -229,12 +275,12 @@ class SASLService : public SASL::Service, public Timer
return NULL;
}
- void RemoveSession(Session *sess) anope_override
+ void RemoveSession(Session *sess) override
{
sessions.erase(sess->uid);
}
- void DeleteSessions(Mechanism *mech, bool da) anope_override
+ void DeleteSessions(Mechanism *mech, bool da) override
{
for (std::map<Anope::string, Session *>::iterator it = sessions.begin(); it != sessions.end();)
{
@@ -248,7 +294,7 @@ class SASLService : public SASL::Service, public Timer
}
}
- void SendMessage(Session *session, const Anope::string &mtype, const Anope::string &data) anope_override
+ void SendMessage(Session *session, const Anope::string &mtype, const Anope::string &data) override
{
SASL::Message msg;
msg.source = this->GetAgent();
@@ -259,7 +305,7 @@ class SASLService : public SASL::Service, public Timer
IRCD->SendSASLMessage(msg);
}
- void Succeed(Session *session, NickCore *nc) anope_override
+ void Succeed(Session *session, NickCore *nc) override
{
// If the user is already introduced then we log them in now.
// Otherwise, we send an SVSLOGIN to log them in later.
@@ -267,31 +313,34 @@ class SASLService : public SASL::Service, public Timer
NickAlias *na = NickAlias::Find(nc->display);
if (user)
{
- user->Identify(na);
+ if (na)
+ user->Identify(na);
+ else
+ user->Logout();
}
else
{
- IRCD->SendSVSLogin(session->uid, nc->display, na->GetVhostIdent(), na->GetVhostHost());
+ IRCD->SendSVSLogin(session->uid, na);
}
this->SendMessage(session, "D", "S");
}
- void Fail(Session *session) anope_override
+ void Fail(Session *session) override
{
this->SendMessage(session, "D", "F");
}
- void SendMechs(Session *session) anope_override
+ void SendMechs(Session *session) override
{
std::vector<Anope::string> mechs = Service::GetServiceKeys("SASL::Mechanism");
Anope::string buf;
- for (unsigned j = 0; j < mechs.size(); ++j)
- buf += "," + mechs[j];
+ for (const auto &mech : mechs)
+ buf += "," + mech;
this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1));
}
- void Tick(time_t) anope_override
+ void Tick() override
{
for (std::map<Anope::string, Session *>::iterator it = sessions.begin(); it != sessions.end();)
{
@@ -308,12 +357,14 @@ class SASLService : public SASL::Service, public Timer
}
};
-class ModuleSASL : public Module
+class ModuleSASL final
+ : public Module
{
SASLService sasl;
+ Anonymous anonymous;
Plain plain;
- External *external;
+ External *external = nullptr;
std::vector<Anope::string> mechs;
@@ -330,9 +381,9 @@ class ModuleSASL : public Module
IRCD->SendSASLMechanisms(mechs);
}
- public:
+public:
ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- sasl(this), plain(this), external(NULL)
+ sasl(this), anonymous(this), plain(this)
{
try
{
@@ -342,22 +393,22 @@ class ModuleSASL : public Module
catch (ModuleException &) { }
}
- ~ModuleSASL()
+ ~ModuleSASL() override
{
delete external;
}
- void OnModuleLoad(User *, Module *) anope_override
+ void OnModuleLoad(User *, Module *) override
{
CheckMechs();
}
- void OnModuleUnload(User *, Module *) anope_override
+ void OnModuleUnload(User *, Module *) override
{
CheckMechs();
}
- void OnPreUplinkSync(Server *) anope_override
+ void OnPreUplinkSync(Server *) override
{
// We have not yet sent a mechanism list so always do it here.
IRCD->SendSASLMechanisms(mechs);
diff --git a/modules/extra/m_sql_authentication.cpp b/modules/sql_authentication.cpp
index 623381cf1..54307496c 100644
--- a/modules/extra/m_sql_authentication.cpp
+++ b/modules/sql_authentication.cpp
@@ -11,12 +11,13 @@
static Module *me;
-class SQLAuthenticationResult : public SQL::Interface
+class SQLAuthenticationResult final
+ : public SQL::Interface
{
Reference<User> user;
IdentifyRequest *req;
- public:
+public:
SQLAuthenticationResult(User *u, IdentifyRequest *r) : SQL::Interface(me), user(u), req(r)
{
req->Hold(me);
@@ -27,16 +28,16 @@ class SQLAuthenticationResult : public SQL::Interface
req->Release(me);
}
- void OnResult(const SQL::Result &r) anope_override
+ void OnResult(const SQL::Result &r) override
{
if (r.Rows() == 0)
{
- Log(LOG_DEBUG) << "m_sql_authentication: Unsuccessful authentication for " << req->GetAccount();
+ Log(LOG_DEBUG) << "sql_authentication: Unsuccessful authentication for " << req->GetAccount();
delete this;
return;
}
- Log(LOG_DEBUG) << "m_sql_authentication: Successful authentication for " << req->GetAccount();
+ Log(LOG_DEBUG) << "sql_authentication: Successful authentication for " << req->GetAccount();
Anope::string email;
try
@@ -66,14 +67,15 @@ class SQLAuthenticationResult : public SQL::Interface
delete this;
}
- void OnError(const SQL::Result &r) anope_override
+ void OnError(const SQL::Result &r) override
{
- Log(this->owner) << "m_sql_authentication: Error executing query " << r.GetQuery().query << ": " << r.GetError();
+ Log(this->owner) << "sql_authentication: Error executing query " << r.GetQuery().query << ": " << r.GetError();
delete this;
}
};
-class ModuleSQLAuthentication : public Module
+class ModuleSQLAuthentication final
+ : public Module
{
Anope::string engine;
Anope::string query;
@@ -81,14 +83,14 @@ class ModuleSQLAuthentication : public Module
ServiceReference<SQL::Provider> SQL;
- public:
+public:
ModuleSQLAuthentication(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
{
me = this;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = conf->GetModule(this);
this->engine = config->Get<const Anope::string>("engine");
@@ -99,7 +101,7 @@ class ModuleSQLAuthentication : public Module
this->SQL = ServiceReference<SQL::Provider>("SQL::Provider", this->engine);
}
- EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) anope_override
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
if (!this->disable_reason.empty() && (command->name == "nickserv/register" || command->name == "nickserv/group"))
{
@@ -116,7 +118,7 @@ class ModuleSQLAuthentication : public Module
return EVENT_CONTINUE;
}
- void OnCheckAuthentication(User *u, IdentifyRequest *req) anope_override
+ void OnCheckAuthentication(User *u, IdentifyRequest *req) override
{
if (!this->SQL)
{
@@ -141,10 +143,10 @@ class ModuleSQLAuthentication : public Module
this->SQL->Run(new SQLAuthenticationResult(u, req), q);
- Log(LOG_DEBUG) << "m_sql_authentication: Checking authentication for " << req->GetAccount();
+ Log(LOG_DEBUG) << "sql_authentication: Checking authentication for " << req->GetAccount();
}
- void OnPreNickExpire(NickAlias *na, bool &expire) anope_override
+ void OnPreNickExpire(NickAlias *na, bool &expire) override
{
// We can't let nicks expire if they still have a group or
// there will be a zombie account left over that can't be
diff --git a/modules/extra/m_sql_log.cpp b/modules/sql_log.cpp
index 6b6ad28e0..7335a5abf 100644
--- a/modules/extra/m_sql_log.cpp
+++ b/modules/sql_log.cpp
@@ -9,30 +9,30 @@
#include "module.h"
#include "modules/sql.h"
-class SQLLog : public Module
+class SQLLog final
+ : public Module
{
std::set<Anope::string> inited;
Anope::string table;
- public:
+public:
SQLLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA)
{
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = conf->GetModule(this);
this->table = config->Get<const Anope::string>("table", "logs");
}
- void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) anope_override
+ void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) override
{
Anope::string ref_name;
ServiceReference<SQL::Provider> SQL;
- for (unsigned i = 0; i < li->targets.size(); ++i)
+ for (const auto &target : li->targets)
{
- const Anope::string &target = li->targets[i];
size_t sz = target.find("sql_log:");
if (!sz)
{
diff --git a/modules/extra/m_sql_oper.cpp b/modules/sql_oper.cpp
index 4bc75ac7b..af2b40346 100644
--- a/modules/extra/m_sql_oper.cpp
+++ b/modules/sql_oper.cpp
@@ -9,16 +9,18 @@
#include "module.h"
#include "modules/sql.h"
-struct SQLOper : Oper
+struct SQLOper final
+ : Oper
{
SQLOper(const Anope::string &n, OperType *o) : Oper(n, o) { }
};
-class SQLOperResult : public SQL::Interface
+class SQLOperResult final
+ : public SQL::Interface
{
Reference<User> user;
- struct SQLOperResultDeleter
+ struct SQLOperResultDeleter final
{
SQLOperResult *res;
SQLOperResultDeleter(SQLOperResult *r) : res(r) { }
@@ -32,17 +34,17 @@ class SQLOperResult : public SQL::Interface
delete user->Account()->o;
user->Account()->o = NULL;
- Log(this->owner) << "m_sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->display << ")";
+ Log(this->owner) << "sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->display << ")";
BotInfo *OperServ = Config->GetClient("OperServ");
user->RemoveMode(OperServ, "OPER"); // Probably not set, just incase
}
}
- public:
+public:
SQLOperResult(Module *m, User *u) : SQL::Interface(m), user(u) { }
- void OnResult(const SQL::Result &r) anope_override
+ void OnResult(const SQL::Result &r) override
{
SQLOperResultDeleter d(this);
@@ -51,7 +53,7 @@ class SQLOperResult : public SQL::Interface
if (r.Rows() == 0)
{
- Log(LOG_DEBUG) << "m_sql_oper: Got 0 rows for " << user->nick;
+ Log(LOG_DEBUG) << "sql_oper: Got 0 rows for " << user->nick;
Deoper();
return;
}
@@ -67,7 +69,7 @@ class SQLOperResult : public SQL::Interface
return;
}
- Log(LOG_DEBUG) << "m_sql_oper: Got result for " << user->nick << ", opertype " << opertype;
+ Log(LOG_DEBUG) << "sql_oper: Got result for " << user->nick << ", opertype " << opertype;
Anope::string modes;
try
@@ -89,7 +91,7 @@ class SQLOperResult : public SQL::Interface
OperType *ot = OperType::Find(opertype);
if (ot == NULL)
{
- Log(this->owner) << "m_sql_oper: Oper " << user->nick << " has type " << opertype << ", but this opertype does not exist?";
+ Log(this->owner) << "sql_oper: Oper " << user->nick << " has type " << opertype << ", but this opertype does not exist?";
return;
}
@@ -101,7 +103,7 @@ class SQLOperResult : public SQL::Interface
if (!user->Account()->o || user->Account()->o->ot != ot)
{
- Log(this->owner) << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;
+ Log(this->owner) << "sql_oper: Tieing oper " << user->nick << " to type " << opertype;
delete user->Account()->o;
user->Account()->o = new SQLOper(user->Account()->display, ot);
@@ -112,35 +114,34 @@ class SQLOperResult : public SQL::Interface
IRCD->SendOper(user);
if (!modes.empty())
- user->SetModes(OperServ, "%s", modes.c_str());
+ user->SetModes(OperServ, modes);
}
}
- void OnError(const SQL::Result &r) anope_override
+ void OnError(const SQL::Result &r) override
{
SQLOperResultDeleter d(this);
- Log(this->owner) << "m_sql_oper: Error executing query " << r.GetQuery().query << ": " << r.GetError();
+ Log(this->owner) << "sql_oper: Error executing query " << r.GetQuery().query << ": " << r.GetError();
}
};
-class ModuleSQLOper : public Module
+class ModuleSQLOper final
+ : public Module
{
Anope::string engine;
Anope::string query;
ServiceReference<SQL::Provider> SQL;
- public:
+public:
ModuleSQLOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
{
}
~ModuleSQLOper()
{
- for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ for (const auto &[_, nc] : *NickCoreList)
{
- NickCore *nc = it->second;
-
if (nc->o && dynamic_cast<SQLOper *>(nc->o))
{
delete nc->o;
@@ -149,7 +150,7 @@ class ModuleSQLOper : public Module
}
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *config = conf->GetModule(this);
@@ -159,7 +160,7 @@ class ModuleSQLOper : public Module
this->SQL = ServiceReference<SQL::Provider>("SQL::Provider", this->engine);
}
- void OnNickIdentify(User *u) anope_override
+ void OnNickIdentify(User *u) override
{
if (!this->SQL)
{
@@ -173,7 +174,7 @@ class ModuleSQLOper : public Module
this->SQL->Run(new SQLOperResult(this, u), q);
- Log(LOG_DEBUG) << "m_sql_oper: Checking authentication for " << u->Account()->display;
+ Log(LOG_DEBUG) << "sql_oper: Checking authentication for " << u->Account()->display;
}
};
diff --git a/modules/third/language/CMakeLists.txt b/modules/third/language/CMakeLists.txt
index 85278f5be..b20982cfc 100644
--- a/modules/third/language/CMakeLists.txt
+++ b/modules/third/language/CMakeLists.txt
@@ -1,8 +1,8 @@
# Only do this if gettext is installed
-if(GETTEXT_FOUND)
+if(HAVE_LOCALIZATION)
# Get all of the .po files
file(GLOB LANG_SRCS_PO RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.*.po")
- sort_list(LANG_SRCS_PO)
+ list(SORT LANG_SRCS_PO)
foreach(LANG_PO ${LANG_SRCS_PO})
# Get the domain for this language file
@@ -26,13 +26,13 @@ if(GETTEXT_FOUND)
# Add to cpack ignored files if not on Windows.
if(NOT WIN32)
add_to_cpack_ignored_files("${LANG_MO}")
- endif(NOT WIN32)
+ endif()
# Install the new language file
install(CODE "FILE(MAKE_DIRECTORY ${LOCALE_DIR}/${LANG_LANG}/LC_MESSAGES/)")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANG_MO} DESTINATION ${LOCALE_DIR}/${LANG_LANG}/LC_MESSAGES RENAME ${LANG_DOMAIN}.mo PERMISSIONS ${PERMS})
- endforeach(LANG_PO)
+ endforeach()
# Generate languages, depends on the mo files
add_custom_target(module_language DEPENDS ${LANG_SRCS_MO})
-endif(GETTEXT_FOUND)
+endif()
diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp
index 7b1caff3f..f4fdccf1f 100644
--- a/modules/webcpanel/pages/chanserv/access.cpp
+++ b/modules/webcpanel/pages/chanserv/access.cpp
@@ -6,7 +6,6 @@
*/
#include "../../webcpanel.h"
-#include "utils.h"
WebCPanel::ChanServ::Access::Access(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
@@ -48,16 +47,16 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
if (u_access.HasPriv("ACCESS_CHANGE") || has_priv)
{
- if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
+ if (!message.get_data["del"].empty() && !message.get_data["mask"].empty())
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("DEL");
+ params.emplace_back("DEL");
params.push_back(message.get_data["mask"]);
WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/access", params, replacements);
}
- else if (message.post_data["mask"].empty() == false && message.post_data["access"].empty() == false && message.post_data["provider"].empty() == false)
+ else if (!message.post_data["mask"].empty() && !message.post_data["access"].empty() && !message.post_data["provider"].empty())
{
const Anope::string &provider = message.post_data["provider"];
@@ -65,7 +64,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("ADD");
+ params.emplace_back("ADD");
params.push_back(message.post_data["mask"]);
params.push_back(message.post_data["access"]);
@@ -75,7 +74,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("ADD");
+ params.emplace_back("ADD");
params.push_back(message.post_data["mask"]);
WebPanel::RunCommandWithName(client, na->nc, "ChanServ", "chanserv/xop", message.post_data["access"], params, replacements);
@@ -84,7 +83,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("MODIFY");
+ params.emplace_back("MODIFY");
params.push_back(message.post_data["mask"]);
params.push_back(message.post_data["access"]);
diff --git a/modules/webcpanel/pages/chanserv/access.h b/modules/webcpanel/pages/chanserv/access.h
deleted file mode 100644
index d77f2a6d9..000000000
--- a/modules/webcpanel/pages/chanserv/access.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace ChanServ
-{
-
-class Access : public WebPanelProtectedPage
-{
- public:
- Access(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-
- std::set<Anope::string> GetData() anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/chanserv/akick.cpp b/modules/webcpanel/pages/chanserv/akick.cpp
index e199a188f..1c238b9ba 100644
--- a/modules/webcpanel/pages/chanserv/akick.cpp
+++ b/modules/webcpanel/pages/chanserv/akick.cpp
@@ -6,7 +6,6 @@
*/
#include "../../webcpanel.h"
-#include "utils.h"
WebCPanel::ChanServ::Akick::Akick(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
@@ -46,22 +45,22 @@ bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::st
replacements["AKICK"] = "YES";
- if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
+ if (!message.get_data["del"].empty() && !message.get_data["mask"].empty())
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("DEL");
+ params.emplace_back("DEL");
params.push_back(message.get_data["mask"]);
WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/akick", params, replacements);
}
- else if (message.post_data["mask"].empty() == false)
+ else if (!message.post_data["mask"].empty())
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("ADD");
+ params.emplace_back("ADD");
params.push_back(message.post_data["mask"]);
- if (message.post_data["reason"].empty() == false)
+ if (!message.post_data["reason"].empty())
params.push_back(message.post_data["reason"]);
WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/akick", params, replacements);
diff --git a/modules/webcpanel/pages/chanserv/akick.h b/modules/webcpanel/pages/chanserv/akick.h
deleted file mode 100644
index 765c79591..000000000
--- a/modules/webcpanel/pages/chanserv/akick.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace ChanServ
-{
-
-class Akick : public WebPanelProtectedPage
-{
- public:
- Akick(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-
- std::set<Anope::string> GetData() anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/chanserv/chanserv.h b/modules/webcpanel/pages/chanserv/chanserv.h
new file mode 100644
index 000000000..76fc30193
--- /dev/null
+++ b/modules/webcpanel/pages/chanserv/chanserv.h
@@ -0,0 +1,72 @@
+/*
+ * (C) 2003-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#pragma once
+
+namespace WebCPanel::ChanServ
+{
+ class Access;
+ class Akick;
+ class Drop;
+ class Info;
+ class Modes;
+ class Set;
+
+ extern void BuildChanList(NickAlias *, TemplateFileServer::Replacements &);
+}
+
+class WebCPanel::ChanServ::Access final
+ : public WebPanelProtectedPage
+{
+public:
+ Access(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+ std::set<Anope::string> GetData() override;
+};
+
+class WebCPanel::ChanServ::Akick final
+ : public WebPanelProtectedPage
+{
+public:
+ Akick(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+ std::set<Anope::string> GetData() override;
+};
+
+class WebCPanel::ChanServ::Drop final
+ : public WebPanelProtectedPage
+{
+public:
+ Drop(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+};
+
+class WebCPanel::ChanServ::Info final
+ : public WebPanelProtectedPage
+{
+public:
+ Info(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+};
+
+class WebCPanel::ChanServ::Modes final
+ : public WebPanelProtectedPage
+{
+public:
+ Modes(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+ std::set<Anope::string> GetData() override;
+};
+
+class WebCPanel::ChanServ::Set final
+ : public WebPanelProtectedPage
+{
+public:
+ Set(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+ std::set<Anope::string> GetData() override;
+};
diff --git a/modules/webcpanel/pages/chanserv/drop.cpp b/modules/webcpanel/pages/chanserv/drop.cpp
index c3d55d63a..743bc5d92 100644
--- a/modules/webcpanel/pages/chanserv/drop.cpp
+++ b/modules/webcpanel/pages/chanserv/drop.cpp
@@ -6,7 +6,6 @@
*/
#include "../../webcpanel.h"
-#include "utils.h"
WebCPanel::ChanServ::Drop::Drop(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage (cat, u)
{
@@ -33,9 +32,8 @@ bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::str
std::deque<ChannelInfo *> queue;
na->nc->GetChannelReferences(queue);
- for (unsigned i = 0; i < queue.size(); ++i)
+ for (auto *ci : queue)
{
- ChannelInfo *ci = queue[i];
if ((ci->HasExt("SECUREFOUNDER") ? ci->AccessFor(na->nc).founder : ci->AccessFor(na->nc).HasPriv("FOUNDER")) || (na->nc->IsServicesOper() && na->nc->o->ot->HasCommand("chanserv/drop")))
{
replacements["CHANNEL_NAMES"] = ci->name;
diff --git a/modules/webcpanel/pages/chanserv/drop.h b/modules/webcpanel/pages/chanserv/drop.h
deleted file mode 100644
index 93b853673..000000000
--- a/modules/webcpanel/pages/chanserv/drop.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
- namespace ChanServ
- {
-
- class Drop : public WebPanelProtectedPage
- {
- public:
- Drop(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-
- };
-
- }
-
-}
diff --git a/modules/webcpanel/pages/chanserv/info.cpp b/modules/webcpanel/pages/chanserv/info.cpp
index b0f70b20e..a888e2c20 100644
--- a/modules/webcpanel/pages/chanserv/info.cpp
+++ b/modules/webcpanel/pages/chanserv/info.cpp
@@ -6,7 +6,6 @@
*/
#include "../../webcpanel.h"
-#include "utils.h"
WebCPanel::ChanServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
diff --git a/modules/webcpanel/pages/chanserv/info.h b/modules/webcpanel/pages/chanserv/info.h
deleted file mode 100644
index 667830f7c..000000000
--- a/modules/webcpanel/pages/chanserv/info.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace ChanServ
-{
-
-class Info : public WebPanelProtectedPage
-{
- public:
- Info(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/chanserv/modes.cpp b/modules/webcpanel/pages/chanserv/modes.cpp
index 2e3065221..b17cc2d09 100644
--- a/modules/webcpanel/pages/chanserv/modes.cpp
+++ b/modules/webcpanel/pages/chanserv/modes.cpp
@@ -6,7 +6,6 @@
*/
#include "../../webcpanel.h"
-#include "utils.h"
WebCPanel::ChanServ::Modes::Modes(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
@@ -57,10 +56,8 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st
replacements["MODE"] = "YES";
/* build a list with the names of all listmodes */
- for (unsigned i = 0; i < ModeManager::GetChannelModes().size(); ++i)
+ for (auto *cm : ModeManager::GetChannelModes())
{
- ChannelMode *cm = ModeManager::GetChannelModes()[i];
-
if (cm->type == MODE_LIST && cm->mchar)
replacements["LISTMODES"] = cm->mchar;
}
@@ -75,28 +72,27 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st
ChannelMode *cm = ModeManager::FindChannelModeByChar(mode[0]);
if (cm)
{
- if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
+ if (!message.get_data["del"].empty() && !message.get_data["mask"].empty())
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("SET");
+ params.emplace_back("SET");
params.push_back("-" + Anope::string(cm->mchar));
params.push_back(message.get_data["mask"]);
WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements);
}
- else if (message.post_data["mask"].empty() == false)
+ else if (!message.post_data["mask"].empty())
{
std::vector<Anope::string> params;
params.push_back(ci->name);
- params.push_back("SET");
+ params.emplace_back("SET");
params.push_back("+" + Anope::string(cm->mchar));
params.push_back(message.post_data["mask"]);
WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements);
}
- std::vector<Anope::string> v = c->GetModeList(cm->name);
- for (unsigned int i = 0; i < v.size(); ++i)
- replacements["MASKS"] = v[i];
+ for (const auto &mask : c->GetModeList(cm->name))
+ replacements["MASKS"] = mask;
}
Page.Serve(server, page_name, client, message, reply, replacements);
diff --git a/modules/webcpanel/pages/chanserv/modes.h b/modules/webcpanel/pages/chanserv/modes.h
deleted file mode 100644
index a4a170299..000000000
--- a/modules/webcpanel/pages/chanserv/modes.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace ChanServ
-{
-
-class Modes : public WebPanelProtectedPage
-{
- public:
- Modes(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-
- std::set<Anope::string> GetData() anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/chanserv/set.cpp b/modules/webcpanel/pages/chanserv/set.cpp
index 101d486c1..e08a61d3b 100644
--- a/modules/webcpanel/pages/chanserv/set.cpp
+++ b/modules/webcpanel/pages/chanserv/set.cpp
@@ -6,7 +6,6 @@
*/
#include "../../webcpanel.h"
-#include "utils.h"
WebCPanel::ChanServ::Set::Set(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
@@ -42,7 +41,7 @@ bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::stri
can_set = true;
}
- if (can_set && message.post_data.empty() == false)
+ if (can_set && !message.post_data.empty())
{
if (ci->HasExt("KEEPTOPIC") != message.post_data.count("keeptopic"))
{
@@ -76,14 +75,6 @@ bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::stri
ci->Shrink<bool>("RESTRICTED");
replacements["MESSAGES"] = "Restricted updated";
}
- if (ci->HasExt("CS_SECURE") != message.post_data.count("secure"))
- {
- if (!ci->HasExt("CS_SECURE"))
- ci->Extend<bool>("CS_SECURE");
- else
- ci->Shrink<bool>("CS_SECURE");
- replacements["MESSAGES"] = "Secure updated";
- }
if (ci->HasExt("SECUREOPS") != message.post_data.count("secureops"))
{
if (!ci->HasExt("SECUREOPS"))
@@ -132,9 +123,6 @@ bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::stri
if (ci->HasExt("RESTRICTED"))
replacements["RESTRICTED"];
- if (ci->HasExt("CS_SECURE"))
- replacements["SECURE"];
-
if (ci->HasExt("SECUREOPS"))
replacements["SECUREOPS"];
diff --git a/modules/webcpanel/pages/chanserv/set.h b/modules/webcpanel/pages/chanserv/set.h
deleted file mode 100644
index e41d62197..000000000
--- a/modules/webcpanel/pages/chanserv/set.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace ChanServ
-{
-
-class Set : public WebPanelProtectedPage
-{
- public:
- Set(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-
- std::set<Anope::string> GetData() anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/chanserv/utils.cpp b/modules/webcpanel/pages/chanserv/utils.cpp
index a5b9d943b..5a6468a3c 100644
--- a/modules/webcpanel/pages/chanserv/utils.cpp
+++ b/modules/webcpanel/pages/chanserv/utils.cpp
@@ -27,10 +27,8 @@ void BuildChanList(NickAlias *na, TemplateFileServer::Replacements &replacements
na->nc->GetChannelReferences(queue);
std::sort(queue.begin(), queue.end(), ChannelSort);
- for (unsigned i = 0; i < queue.size(); ++i)
+ for (auto *ci : queue)
{
- ChannelInfo *ci = queue[i];
-
if (na->nc != ci->GetFounder() && ci->AccessFor(na->nc).empty())
continue;
diff --git a/modules/webcpanel/pages/chanserv/utils.h b/modules/webcpanel/pages/chanserv/utils.h
deleted file mode 100644
index 117647683..000000000
--- a/modules/webcpanel/pages/chanserv/utils.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace ChanServ
-{
-
-extern void BuildChanList(NickAlias *, TemplateFileServer::Replacements &);
-
-}
-
-}
diff --git a/modules/webcpanel/pages/confirm.h b/modules/webcpanel/pages/confirm.h
index 4c2a824cd..558e54217 100644
--- a/modules/webcpanel/pages/confirm.h
+++ b/modules/webcpanel/pages/confirm.h
@@ -5,17 +5,20 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
#include "modules/httpd.h"
namespace WebCPanel
{
-class Confirm : public WebPanelPage
+class Confirm final
+ : public WebPanelPage
{
- public:
+public:
Confirm(const Anope::string &u) : WebPanelPage(u) { }
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) override;
};
}
diff --git a/modules/webcpanel/pages/hostserv/request.h b/modules/webcpanel/pages/hostserv/hostserv.h
index 37164948a..8494fee14 100644
--- a/modules/webcpanel/pages/hostserv/request.h
+++ b/modules/webcpanel/pages/hostserv/hostserv.h
@@ -5,20 +5,17 @@
* Please read COPYING and README for further details.
*/
-namespace WebCPanel
-{
+#pragma once
-namespace HostServ
+namespace WebCPanel::HostServ
{
+ class Request;
+}
-class Request : public WebPanelProtectedPage
+class WebCPanel::HostServ::Request final
+ : public WebPanelProtectedPage
{
- public:
+public:
Request(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/hostserv/request.cpp b/modules/webcpanel/pages/hostserv/request.cpp
index 030999d1e..0a8513c76 100644
--- a/modules/webcpanel/pages/hostserv/request.cpp
+++ b/modules/webcpanel/pages/hostserv/request.cpp
@@ -22,12 +22,7 @@ bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope::
}
if (na->HasVhost())
- {
- if (na->GetVhostIdent().empty() == false)
- replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
- else
- replacements["VHOST"] = na->GetVhostHost();
- }
+ replacements["VHOST"] = na->GetVhostMask();
if (ServiceReference<Command>("Command", "hostserv/request"))
replacements["CAN_REQUEST"] = "YES";
TemplateFileServer page("hostserv/request.html");
diff --git a/modules/webcpanel/pages/index.cpp b/modules/webcpanel/pages/index.cpp
index 4db953bfa..831eb9996 100644
--- a/modules/webcpanel/pages/index.cpp
+++ b/modules/webcpanel/pages/index.cpp
@@ -7,7 +7,8 @@
#include "../webcpanel.h"
-class WebpanelRequest : public IdentifyRequest
+class WebpanelRequest final
+ : public IdentifyRequest
{
HTTPReply reply;
HTTPMessage message;
@@ -16,10 +17,10 @@ class WebpanelRequest : public IdentifyRequest
Reference<HTTPClient> client;
TemplateFileServer::Replacements replacements;
- public:
+public:
WebpanelRequest(Module *o, HTTPReply &r, HTTPMessage &m, HTTPProvider *s, const Anope::string &p_n, HTTPClient *c, TemplateFileServer::Replacements &re, const Anope::string &user, const Anope::string &pass) : IdentifyRequest(o, user, pass), reply(r), message(m), server(s), page_name(p_n), client(c), replacements(re) { }
- void OnSuccess() anope_override
+ void OnSuccess() override
{
if (!client || !server)
return;
@@ -49,7 +50,7 @@ class WebpanelRequest : public IdentifyRequest
{
char c;
do
- c = 48 + (rand() % 75);
+ c = 48 + (Anope::RandomNumber() % 75);
while (!isalnum(c));
id += c;
}
@@ -60,15 +61,15 @@ class WebpanelRequest : public IdentifyRequest
{
HTTPReply::cookie c;
- c.push_back(std::make_pair("account", na->nick));
- c.push_back(std::make_pair("Path", "/"));
+ c.emplace_back("account", na->nick);
+ c.emplace_back("Path", "/");
reply.cookies.push_back(c);
}
{
HTTPReply::cookie c;
- c.push_back(std::make_pair("id", id));
- c.push_back(std::make_pair("Path", "/"));
+ c.emplace_back("id", id);
+ c.emplace_back("Path", "/");
reply.cookies.push_back(c);
}
@@ -78,7 +79,7 @@ class WebpanelRequest : public IdentifyRequest
client->SendReply(&reply);
}
- void OnFail() anope_override
+ void OnFail() override
{
if (!client || !server)
return;
@@ -102,7 +103,7 @@ bool WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page
// Rate limit check.
Anope::string ip = client->clientaddr.addr();
- Anope::hash_map<time_t>::iterator it = last_login_attempt.find(ip);
+ Anope::unordered_map<time_t>::iterator it = last_login_attempt.find(ip);
if (it != last_login_attempt.end())
{
time_t last_time = it->second;
@@ -125,7 +126,7 @@ bool WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page
last_login_attempt[ip] = Anope::CurTime;
- WebpanelRequest *req = new WebpanelRequest(me, reply, message, server, page_name, client, replacements, user, pass);
+ auto *req = new WebpanelRequest(me, reply, message, server, page_name, client, replacements, user, pass);
FOREACH_MOD(OnCheckAuthentication, (NULL, req));
req->Dispatch();
return false;
diff --git a/modules/webcpanel/pages/index.h b/modules/webcpanel/pages/index.h
index 91cf93e79..e94c2061d 100644
--- a/modules/webcpanel/pages/index.h
+++ b/modules/webcpanel/pages/index.h
@@ -5,22 +5,25 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
#include "modules/httpd.h"
namespace WebCPanel
{
-class Index : public WebPanelPage
+class Index final
+ : public WebPanelPage
{
static const int FLUSH_TIME = 60;
- Anope::hash_map<time_t> last_login_attempt;
- time_t last_clear;
+ Anope::unordered_map<time_t> last_login_attempt;
+ time_t last_clear = 0;
- public:
- Index(const Anope::string &u) : WebPanelPage(u), last_clear(0) { }
+public:
+ Index(const Anope::string &u) : WebPanelPage(u) { }
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) override;
};
}
diff --git a/modules/webcpanel/pages/logout.h b/modules/webcpanel/pages/logout.h
index d3d2e9947..bfefe5ddd 100644
--- a/modules/webcpanel/pages/logout.h
+++ b/modules/webcpanel/pages/logout.h
@@ -5,15 +5,18 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
namespace WebCPanel
{
-class Logout : public WebPanelProtectedPage
+class Logout final
+ : public WebPanelProtectedPage
{
- public:
+public:
Logout(const Anope::string &u);
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
};
}
diff --git a/modules/webcpanel/pages/memoserv/memos.cpp b/modules/webcpanel/pages/memoserv/memos.cpp
index 539b33e83..d7fb76d74 100644
--- a/modules/webcpanel/pages/memoserv/memos.cpp
+++ b/modules/webcpanel/pages/memoserv/memos.cpp
@@ -18,9 +18,9 @@ bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::st
const MemoInfo *mi;
Memo *m;
- for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
+ for (const auto &[_, ci2] : *RegisteredChannelList)
{
- ci = it->second;
+ ci = ci2;
if (ci->AccessFor(na->nc).HasPriv("MEMO"))
{
@@ -73,14 +73,10 @@ bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::st
std::vector<Anope::string> params;
int number = -1;
- try
- {
- number = convertTo<int>(message.get_data["number"]);
- }
- catch (const ConvertException &ex)
- {
+ if (auto num = Anope::TryConvert<int>(message.get_data["number"]))
+ number = num.value();
+ else
replacements["MESSAGES"] = "ERROR - invalid parameter for NUMBER";
- }
if (number > 0)
{
@@ -98,7 +94,7 @@ bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::st
for (unsigned i = 0; i < mi->memos->size(); ++i)
{
m = mi->GetMemo(i);
- replacements["NUMBER"] = stringify(i+1);
+ replacements["NUMBER"] = Anope::ToString(i+1);
replacements["SENDER"] = m->sender;
replacements["TIME"] = Anope::strftime(m->time);
replacements["TEXT"] = m->text;
diff --git a/modules/webcpanel/pages/memoserv/memos.h b/modules/webcpanel/pages/memoserv/memoserv.h
index a7464d45b..a3bd11d62 100644
--- a/modules/webcpanel/pages/memoserv/memos.h
+++ b/modules/webcpanel/pages/memoserv/memoserv.h
@@ -5,20 +5,17 @@
* Please read COPYING and README for further details.
*/
-namespace WebCPanel
-{
+#pragma once
-namespace MemoServ
+namespace WebCPanel::MemoServ
{
+ class Memos;
+}
-class Memos : public WebPanelProtectedPage
+class WebCPanel::MemoServ::Memos final
+ : public WebPanelProtectedPage
{
- public:
+public:
Memos(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/nickserv/access.cpp b/modules/webcpanel/pages/nickserv/access.cpp
deleted file mode 100644
index 0801473f3..000000000
--- a/modules/webcpanel/pages/nickserv/access.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-#include "../../webcpanel.h"
-
-WebCPanel::NickServ::Access::Access(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
-{
-}
-
-bool WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
-{
- if (message.post_data.count("access") > 0)
- {
- std::vector<Anope::string> params;
- params.push_back("ADD");
- params.push_back(message.post_data["access"]);
-
- WebPanel::RunCommand(client, na->nc->display, na->nc, "NickServ", "nickserv/access", params, replacements);
- }
- else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0)
- {
- std::vector<Anope::string> params;
- params.push_back("DEL");
- params.push_back(message.get_data["mask"]);
-
- WebPanel::RunCommand(client, na->nc->display, na->nc, "NickServ", "nickserv/access", params, replacements);
- }
-
- for (unsigned i = 0; i < na->nc->access.size(); ++i)
- replacements["ACCESS"] = na->nc->access[i];
-
- TemplateFileServer page("nickserv/access.html");
- page.Serve(server, page_name, client, message, reply, replacements);
- return true;
-}
diff --git a/modules/webcpanel/pages/nickserv/access.h b/modules/webcpanel/pages/nickserv/access.h
deleted file mode 100644
index da8f7bd8e..000000000
--- a/modules/webcpanel/pages/nickserv/access.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace NickServ
-{
-
-class Access : public WebPanelProtectedPage
-{
- public:
- Access(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/nickserv/alist.cpp b/modules/webcpanel/pages/nickserv/alist.cpp
index da2ee53cb..48c61d83e 100644
--- a/modules/webcpanel/pages/nickserv/alist.cpp
+++ b/modules/webcpanel/pages/nickserv/alist.cpp
@@ -24,15 +24,13 @@ bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::st
int chan_count = 0;
- for (unsigned q = 0; q < queue.size(); ++q)
+ for (auto *ci : queue)
{
- ChannelInfo *ci = queue[q];
-
if (ci->GetFounder() == na->nc)
{
++chan_count;
- replacements["NUMBERS"] = stringify(chan_count);
+ replacements["NUMBERS"] = Anope::ToString(chan_count);
replacements["CHANNELS"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
replacements["ACCESSES"] = "Founder";
continue;
@@ -44,7 +42,7 @@ bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::st
++chan_count;
- replacements["NUMBERS"] = stringify(chan_count);
+ replacements["NUMBERS"] = Anope::ToString(chan_count);
replacements["CHANNELS"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
const ChanAccess *highest = access.Highest();
diff --git a/modules/webcpanel/pages/nickserv/alist.h b/modules/webcpanel/pages/nickserv/alist.h
deleted file mode 100644
index fe7aefe85..000000000
--- a/modules/webcpanel/pages/nickserv/alist.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace NickServ
-{
-
-class Alist : public WebPanelProtectedPage
-{
- public:
- Alist(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/nickserv/cert.cpp b/modules/webcpanel/pages/nickserv/cert.cpp
index 14608d995..d3dd3e09b 100644
--- a/modules/webcpanel/pages/nickserv/cert.cpp
+++ b/modules/webcpanel/pages/nickserv/cert.cpp
@@ -17,7 +17,7 @@ bool WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::str
if (message.post_data.count("certfp") > 0)
{
std::vector<Anope::string> params;
- params.push_back("ADD");
+ params.emplace_back("ADD");
params.push_back(message.post_data["certfp"]);
WebPanel::RunCommand(client, na->nc->display, na->nc, "NickServ", "nickserv/cert", params, replacements);
@@ -25,7 +25,7 @@ bool WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::str
else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0)
{
std::vector<Anope::string> params;
- params.push_back("DEL");
+ params.emplace_back("DEL");
params.push_back(message.get_data["mask"]);
WebPanel::RunCommand(client, na->nc->display, na->nc, "NickServ", "nickserv/cert", params, replacements);
diff --git a/modules/webcpanel/pages/nickserv/cert.h b/modules/webcpanel/pages/nickserv/cert.h
deleted file mode 100644
index b17583f4d..000000000
--- a/modules/webcpanel/pages/nickserv/cert.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace NickServ
-{
-
-class Cert : public WebPanelProtectedPage
-{
- public:
- Cert(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/nickserv/confirm.h b/modules/webcpanel/pages/nickserv/confirm.h
deleted file mode 100644
index a5c2b914a..000000000
--- a/modules/webcpanel/pages/nickserv/confirm.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace NickServ
-{
-
-class Confirm : public WebPanelProtectedPage
-{
- public:
- Confirm(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/nickserv/info.cpp b/modules/webcpanel/pages/nickserv/info.cpp
index 0a7c63f61..6a47e541c 100644
--- a/modules/webcpanel/pages/nickserv/info.cpp
+++ b/modules/webcpanel/pages/nickserv/info.cpp
@@ -13,7 +13,7 @@ WebCPanel::NickServ::Info::Info(const Anope::string &cat, const Anope::string &u
bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
{
- if (message.post_data.empty() == false)
+ if (!message.post_data.empty())
{
if (message.post_data.count("email") > 0)
{
@@ -56,14 +56,6 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str
na->nc->Shrink<bool>("NS_PRIVATE");
replacements["MESSAGES"] = "Private updated";
}
- if (na->nc->HasExt("NS_SECURE") != message.post_data.count("secure"))
- {
- if (!na->nc->HasExt("NS_SECURE"))
- na->nc->Extend<bool>("NS_SECURE");
- else
- na->nc->Shrink<bool>("NS_SECURE");
- replacements["MESSAGES"] = "Secure updated";
- }
if (message.post_data["kill"] == "on" && !na->nc->HasExt("KILLPROTECT"))
{
na->nc->Extend<bool>("KILLPROTECT");
@@ -85,16 +77,11 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str
}
replacements["DISPLAY"] = na->nc->display;
- if (na->nc->email.empty() == false)
+ if (!na->nc->email.empty())
replacements["EMAIL"] = na->nc->email;
replacements["TIME_REGISTERED"] = Anope::strftime(na->time_registered, na->nc);
if (na->HasVhost())
- {
- if (na->GetVhostIdent().empty() == false)
- replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
- else
- replacements["VHOST"] = na->GetVhostHost();
- }
+ replacements["VHOST"] = na->GetVhostMask();
Anope::string *greet = na->nc->GetExt<Anope::string>("greet");
if (greet)
replacements["GREET"] = *greet;
@@ -102,8 +89,6 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str
replacements["AUTOOP"];
if (na->nc->HasExt("NS_PRIVATE"))
replacements["PRIVATE"];
- if (na->nc->HasExt("NS_SECURE"))
- replacements["SECURE"];
if (na->nc->HasExt("KILLPROTECT"))
replacements["KILL_ON"];
if (na->nc->HasExt("KILL_QUICK"))
diff --git a/modules/webcpanel/pages/nickserv/info.h b/modules/webcpanel/pages/nickserv/info.h
deleted file mode 100644
index 995ae235d..000000000
--- a/modules/webcpanel/pages/nickserv/info.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * (C) 2003-2024 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-namespace WebCPanel
-{
-
-namespace NickServ
-{
-
-class Info : public WebPanelProtectedPage
-{
- public:
- Info(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
-};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/nickserv/nickserv.h b/modules/webcpanel/pages/nickserv/nickserv.h
new file mode 100644
index 000000000..ef6a9924a
--- /dev/null
+++ b/modules/webcpanel/pages/nickserv/nickserv.h
@@ -0,0 +1,48 @@
+/*
+ * (C) 2003-2024 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#pragma once
+
+namespace WebCPanel::NickServ
+{
+ class Alist;
+ class Cert;
+ class Confirm;
+ class Info;
+}
+
+class WebCPanel::NickServ::Alist final
+ : public WebPanelProtectedPage
+{
+public:
+ Alist(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+};
+
+class WebCPanel::NickServ::Cert final
+ : public WebPanelProtectedPage
+{
+public:
+ Cert(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+};
+
+class WebCPanel::NickServ::Confirm final
+ : public WebPanelProtectedPage
+{
+public:
+ Confirm(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+};
+
+class WebCPanel::NickServ::Info final
+ : public WebPanelProtectedPage
+{
+public:
+ Info(const Anope::string &cat, const Anope::string &u);
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
+};
diff --git a/modules/webcpanel/pages/operserv/akill.cpp b/modules/webcpanel/pages/operserv/akill.cpp
index 62ae8417c..c7cb8ab9a 100644
--- a/modules/webcpanel/pages/operserv/akill.cpp
+++ b/modules/webcpanel/pages/operserv/akill.cpp
@@ -29,18 +29,18 @@ bool WebCPanel::OperServ::Akill::OnRequest(HTTPProvider *server, const Anope::st
{
std::vector<Anope::string> params;
std::stringstream cmdstr;
- params.push_back("ADD");
+ params.emplace_back("ADD");
cmdstr << "+" << HTTPUtils::URLDecode(message.post_data["expiry"]);
cmdstr << " " << HTTPUtils::URLDecode(message.post_data["mask"]);
cmdstr << " " << HTTPUtils::URLDecode(message.post_data["reason"]);
- params.push_back(cmdstr.str());
+ params.emplace_back(cmdstr.str());
WebPanel::RunCommand(client, na->nc->display, na->nc, "OperServ", "operserv/akill", params, replacements);
}
if (message.get_data["del"] == "1" && message.get_data.count("number") > 0)
{
std::vector<Anope::string> params;
- params.push_back("DEL");
+ params.emplace_back("DEL");
params.push_back(HTTPUtils::URLDecode(message.get_data["number"]));
WebPanel::RunCommand(client, na->nc->display, na->nc, "OperServ", "operserv/akill", params, replacements);
}
@@ -48,7 +48,7 @@ bool WebCPanel::OperServ::Akill::OnRequest(HTTPProvider *server, const Anope::st
for (unsigned i = 0, end = akills->GetCount(); i < end; ++i)
{
const XLine *x = akills->GetEntry(i);
- replacements["NUMBER"] = stringify(i + 1);
+ replacements["NUMBER"] = Anope::ToString(i + 1);
replacements["HOST"] = x->mask;
replacements["SETTER"] = x->by;
replacements["TIME"] = Anope::strftime(x->created, NULL, true);
diff --git a/modules/webcpanel/pages/operserv/akill.h b/modules/webcpanel/pages/operserv/operserv.h
index 4c957f29b..28e6b3ec0 100644
--- a/modules/webcpanel/pages/operserv/akill.h
+++ b/modules/webcpanel/pages/operserv/operserv.h
@@ -5,20 +5,17 @@
* Please read COPYING and README for further details.
*/
-namespace WebCPanel
-{
+#pragma once
-namespace OperServ
+namespace WebCPanel::OperServ
{
+ class Akill;
+}
-class Akill : public WebPanelProtectedPage
+class WebCPanel::OperServ::Akill final
+ : public WebPanelProtectedPage
{
- public:
+public:
Akill(const Anope::string &cat, const Anope::string &u);
-
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override;
};
-
-}
-
-}
diff --git a/modules/webcpanel/pages/register.cpp b/modules/webcpanel/pages/register.cpp
index 7d75ea28c..53ff64d99 100644
--- a/modules/webcpanel/pages/register.cpp
+++ b/modules/webcpanel/pages/register.cpp
@@ -13,9 +13,6 @@ bool WebCPanel::Register::OnRequest(HTTPProvider *server, const Anope::string &p
replacements["TITLE"] = page_title;
- if (Config->GetModule("nickserv")->Get<bool>("forceemail", "yes"))
- replacements["FORCE_EMAIL"] = "yes";
-
TemplateFileServer page("register.html");
page.Serve(server, page_name, client, message, reply, replacements);
diff --git a/modules/webcpanel/pages/register.h b/modules/webcpanel/pages/register.h
index 2dca3af69..daf7fd735 100644
--- a/modules/webcpanel/pages/register.h
+++ b/modules/webcpanel/pages/register.h
@@ -5,17 +5,20 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
#include "modules/httpd.h"
namespace WebCPanel
{
-class Register : public WebPanelPage
+class Register final
+ : public WebPanelPage
{
- public:
+public:
Register(const Anope::string &u) : WebPanelPage(u) { }
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) override;
};
}
diff --git a/modules/webcpanel/static_fileserver.cpp b/modules/webcpanel/static_fileserver.cpp
index 4497c7b64..c27ed9e8e 100644
--- a/modules/webcpanel/static_fileserver.cpp
+++ b/modules/webcpanel/static_fileserver.cpp
@@ -6,8 +6,8 @@
*/
#include "webcpanel.h"
+#include <cerrno>
#include <fstream>
-#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/modules/webcpanel/static_fileserver.h b/modules/webcpanel/static_fileserver.h
index 991a3d043..ab9399171 100644
--- a/modules/webcpanel/static_fileserver.h
+++ b/modules/webcpanel/static_fileserver.h
@@ -5,14 +5,17 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
#include "modules/httpd.h"
/* A basic file server. Used for serving static content on disk. */
-class StaticFileServer : public HTTPPage
+class StaticFileServer final
+ : public HTTPPage
{
Anope::string file_name;
- public:
+public:
StaticFileServer(const Anope::string &f_n, const Anope::string &u, const Anope::string &c_t);
- bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+ bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) override;
};
diff --git a/modules/webcpanel/template_fileserver.cpp b/modules/webcpanel/template_fileserver.cpp
index 072139902..92b7c8cc7 100644
--- a/modules/webcpanel/template_fileserver.cpp
+++ b/modules/webcpanel/template_fileserver.cpp
@@ -6,15 +6,15 @@
*/
#include "webcpanel.h"
+#include <cerrno>
#include <fstream>
#include <stack>
-#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-struct ForLoop
+struct ForLoop final
{
static std::vector<ForLoop> Stack;
@@ -25,28 +25,24 @@ struct ForLoop
ForLoop(size_t s, TemplateFileServer::Replacements &r, const std::vector<Anope::string> &v, const std::vector<Anope::string> &r_names) : start(s), vars(v)
{
- for (unsigned i = 0; i < r_names.size(); ++i)
- ranges.push_back(r.equal_range(r_names[i]));
+ for (const auto &r_name : r_names)
+ ranges.push_back(r.equal_range(r_name));
}
void increment(const TemplateFileServer::Replacements &r)
{
- for (unsigned i = 0; i < ranges.size(); ++i)
+ for (auto &[begin, end] : ranges)
{
- range &ra = ranges[i];
-
- if (ra.first != r.end() && ra.first != ra.second)
- ++ra.first;
+ if (begin != r.end() && begin != end)
+ ++begin;
}
}
bool finished(const TemplateFileServer::Replacements &r) const
{
- for (unsigned i = 0; i < ranges.size(); ++i)
+ for (const auto &[begin, end] : ranges)
{
- const range &ra = ranges[i];
-
- if (ra.first != r.end() && ra.first != ra.second)
+ if (begin != r.end() && begin != end)
return false;
}
@@ -186,7 +182,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n
if (temp_variables.size() != real_variables.size())
Log() << "Invalid FOR in web template " << this->file_name << " variable mismatch";
else
- ForLoop::Stack.push_back(ForLoop(j + f, r, temp_variables, real_variables));
+ ForLoop::Stack.emplace_back(j + f, r, temp_variables, real_variables);
}
}
else if (content == "END FOR")
diff --git a/modules/webcpanel/template_fileserver.h b/modules/webcpanel/template_fileserver.h
index 8c0b1edf3..8466a1736 100644
--- a/modules/webcpanel/template_fileserver.h
+++ b/modules/webcpanel/template_fileserver.h
@@ -5,18 +5,21 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
#include "modules/httpd.h"
/* A basic file server. Used for serving non-static non-binary content on disk. */
-class TemplateFileServer
+class TemplateFileServer final
{
Anope::string file_name;
- public:
- struct Replacements : std::multimap<Anope::string, Anope::string>
+public:
+ struct Replacements final
+ : std::multimap<Anope::string, Anope::string>
{
- Anope::string& operator[](const Anope::string &key)
+ Anope::string &operator[](const Anope::string &key)
{
- return insert(std::make_pair(key, ""))->second;
+ return emplace(key, "")->second;
}
};
diff --git a/modules/webcpanel/templates/default/chanserv/set.html b/modules/webcpanel/templates/default/chanserv/set.html
index 9437ca71a..bc785c567 100644
--- a/modules/webcpanel/templates/default/chanserv/set.html
+++ b/modules/webcpanel/templates/default/chanserv/set.html
@@ -65,10 +65,6 @@
<td><input type="checkbox" name="restricted" value="on" {IF EXISTS RESTRICTED}checked{END IF}></td>
</tr>
<tr>
- <td>Secure</td>
- <td><input type="checkbox" name="secure" value="on" {IF EXISTS SECURE}checked{END IF}></td>
- </tr>
- <tr>
<td>Secure Ops</td>
<td><input type="checkbox" name="secureops" value="on" {IF EXISTS SECUREOPS}checked{END IF}></td>
</tr>
diff --git a/modules/webcpanel/templates/default/nickserv/access.html b/modules/webcpanel/templates/default/nickserv/access.html
deleted file mode 100644
index 6387da854..000000000
--- a/modules/webcpanel/templates/default/nickserv/access.html
+++ /dev/null
@@ -1,42 +0,0 @@
-{INCLUDE header.html}
- <div class="panel-heading">Nick access list</div>
- <div class="panel-body">
- {FOR M IN MESSAGES}
- <div class="alert alert-info">
- {M}<br>
- </div>
- {END FOR}
-
- {IF EXISTS ACCESS}
- <table id="tableNSAccess" class="table table-hover">
- <tbody>
- {FOR A IN ACCESS}
- <tr>
- <td class="col-lg-4">{A}</td>
- <td class="col-lg-8"><a href="/nickserv/access?mask={A}&del=1" class="btn btn-sm btn-danger">Delete</a></td>
- </tr>
- {END FOR}
- </tbody>
- </table>
- {ELSE}
- <em>Your access list is empty.</em>
- {END IF}
-
- <hr>
-
- <h4>Add an access entry</h4>
- <form class="form-horizontal" method="post" action="/nickserv/access">
- <div class="form-group">
- <label class="control-label col-lg-2" for="access">Hostmask:</label>
- <div class="col-lg-5">
- <input class="form-control" type="text" name="access" id="access" placeholder="Mask must be in the form user@host">
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-offset-2 col-lg-5">
- <button type="submit" class="btn btn-primary">Add</button>
- </div>
- </div>
- </form>
- </div>
-{INCLUDE footer.html}
diff --git a/modules/webcpanel/templates/default/nickserv/info.html b/modules/webcpanel/templates/default/nickserv/info.html
index 667c8b370..676e6cf76 100644
--- a/modules/webcpanel/templates/default/nickserv/info.html
+++ b/modules/webcpanel/templates/default/nickserv/info.html
@@ -49,10 +49,6 @@
<td><input type="checkbox" name="private" value="on" {IF EXISTS PRIVATE}checked{END IF}></td>
</tr>
<tr>
- <td>Secure:</td>
- <td><input type="checkbox" name="secure" value="on" {IF EXISTS SECURE}checked{END IF}></td>
- </tr>
- <tr>
<td>Kill:</td>
<td>
<select name="kill" class="form-control input-sm">
diff --git a/modules/webcpanel/templates/default/register.html b/modules/webcpanel/templates/default/register.html
index e71d763f6..311b94cf5 100644
--- a/modules/webcpanel/templates/default/register.html
+++ b/modules/webcpanel/templates/default/register.html
@@ -34,16 +34,8 @@
style="margin-bottom: -1px; border-bottom-left-radius: 0; border-bottom-right-radius: 0;">
<input type="password" name="password" class="form-control" placeholder="Password" required="required"
style="margin-bottom: -1px; border-radius: 0;">
-
- {IF EXISTS FORCE_EMAIL}
<input type="email" name="email" class="form-control" placeholder="Email" required="required"
style="margin-bottom: 15px; border-top-left-radius: 0; border-top-right-radius: 0;">
- {ELSE}
- <h4>Optional</h4>
- <input type="email" name="email" class="form-control" placeholder="Email"
- style="margin-bottom: 15px;">
- {END IF}
-
<button class="btn btn-lg btn-warning btn-block" type="submit">Register</button>
</form>
</div>
diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp
index ec7d4bcc5..1a0d22003 100644
--- a/modules/webcpanel/webcpanel.cpp
+++ b/modules/webcpanel/webcpanel.cpp
@@ -10,7 +10,8 @@
Module *me;
Anope::string provider_name, template_name, template_base, page_title;
-class ModuleWebCPanel : public Module
+class ModuleWebCPanel final
+ : public Module
{
ServiceReference<HTTPProvider> provider;
Panel panel;
@@ -26,7 +27,6 @@ class ModuleWebCPanel : public Module
WebCPanel::NickServ::Info nickserv_info;
WebCPanel::NickServ::Cert nickserv_cert;
- WebCPanel::NickServ::Access nickserv_access;
WebCPanel::NickServ::Alist nickserv_alist;
WebCPanel::NickServ::Confirm nickserv_confirm;
@@ -44,13 +44,13 @@ class ModuleWebCPanel : public Module
WebCPanel::OperServ::Akill operserv_akill;
- public:
+public:
ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
panel(this, "webcpanel"),
id(this, "webcpanel_id"), ip(this, "webcpanel_ip"), last_login(this, "webcpanel_last_login"),
style_css("style.css", "/static/style.css", "text/css"), logo_png("logo.png", "/static/logo.png", "image/png"), cubes_png("cubes.png", "/static/cubes.png", "image/png"), favicon_ico("favicon.ico", "/favicon.ico", "image/x-icon"),
index("/"), logout("/logout"), _register("/register"), confirm("/confirm"),
- nickserv_info("NickServ", "/nickserv/info"), nickserv_cert("NickServ", "/nickserv/cert"), nickserv_access("NickServ", "/nickserv/access"), nickserv_alist("NickServ", "/nickserv/alist"), nickserv_confirm("NickServ", "/nickserv/confirm"),
+ nickserv_info("NickServ", "/nickserv/info"), nickserv_cert("NickServ", "/nickserv/cert"), nickserv_alist("NickServ", "/nickserv/alist"), nickserv_confirm("NickServ", "/nickserv/confirm"),
chanserv_info("ChanServ", "/chanserv/info"), chanserv_set("ChanServ", "/chanserv/set"), chanserv_access("ChanServ", "/chanserv/access"), chanserv_akick("ChanServ", "/chanserv/akick"),
chanserv_modes("ChanServ", "/chanserv/modes"), chanserv_drop("ChanServ", "/chanserv/drop"), memoserv_memos("MemoServ", "/memoserv/memos"), hostserv_request("HostServ", "/hostserv/request"),
operserv_akill("OperServ", "/operserv/akill")
@@ -66,7 +66,7 @@ class ModuleWebCPanel : public Module
provider = ServiceReference<HTTPProvider>("HTTPProvider", provider_name);
if (!provider)
- throw ModuleException("Unable to find HTTPD provider. Is m_httpd loaded?");
+ throw ModuleException("Unable to find HTTPD provider. Is httpd loaded?");
provider->RegisterPage(&this->style_css);
provider->RegisterPage(&this->logo_png);
@@ -98,11 +98,6 @@ class ModuleWebCPanel : public Module
provider->RegisterPage(&this->nickserv_cert);
}
- ss.name = "Access";
- ss.url = "/nickserv/access";
- s.subsections.push_back(ss);
- provider->RegisterPage(&this->nickserv_access);
-
ss.name = "AList";
ss.url = "/nickserv/alist";
s.subsections.push_back(ss);
@@ -202,7 +197,7 @@ class ModuleWebCPanel : public Module
}
}
- ~ModuleWebCPanel()
+ ~ModuleWebCPanel() override
{
if (provider)
{
@@ -218,7 +213,6 @@ class ModuleWebCPanel : public Module
provider->UnregisterPage(&this->nickserv_info);
provider->UnregisterPage(&this->nickserv_cert);
- provider->UnregisterPage(&this->nickserv_access);
provider->UnregisterPage(&this->nickserv_alist);
provider->UnregisterPage(&this->nickserv_confirm);
@@ -260,14 +254,15 @@ namespace WebPanel
bi = BotListByNick->begin()->second; // Pick one...
}
- struct MyComandReply : CommandReply
+ struct MyComandReply final
+ : CommandReply
{
TemplateFileServer::Replacements &re;
const Anope::string &k;
MyComandReply(TemplateFileServer::Replacements &_r, const Anope::string &_k) : re(_r), k(_k) { }
- void SendMessage(BotInfo *source, const Anope::string &msg) anope_override
+ void SendMessage(BotInfo *source, const Anope::string &msg) override
{
re[k] = msg;
}
@@ -300,14 +295,15 @@ namespace WebPanel
if (!info)
return;
- struct MyComandReply : CommandReply
+ struct MyComandReply final
+ : CommandReply
{
TemplateFileServer::Replacements &re;
const Anope::string &k;
MyComandReply(TemplateFileServer::Replacements &_r, const Anope::string &_k) : re(_r), k(_k) { }
- void SendMessage(BotInfo *source, const Anope::string &msg) anope_override
+ void SendMessage(BotInfo *source, const Anope::string &msg) override
{
re[k] = msg;
}
diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h
index 72bd5acbe..362b5e1ac 100644
--- a/modules/webcpanel/webcpanel.h
+++ b/modules/webcpanel/webcpanel.h
@@ -5,6 +5,8 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
#include "module.h"
#include "modules/httpd.h"
@@ -15,7 +17,7 @@ extern Module *me;
extern Anope::string provider_name, template_name, template_base, page_title;
-struct SubSection
+struct SubSection final
{
Anope::string name;
Anope::string url;
@@ -28,9 +30,11 @@ struct Section
};
/* An interface for this webpanel used by other modules */
-class Panel : public Section, public Service
+class Panel final
+ : public Section
+ , public Service
{
- public:
+public:
Panel(Module *c, const Anope::string &n) : Service(c, "Panel", n) { }
std::vector<Section> sections;
@@ -61,9 +65,10 @@ class Panel : public Section, public Service
}
};
-class WebPanelPage : public HTTPPage
+class WebPanelPage
+ : public HTTPPage
{
- public:
+public:
WebPanelPage(const Anope::string &u, const Anope::string &ct = "text/html") : HTTPPage(u, ct)
{
}
@@ -71,16 +76,17 @@ class WebPanelPage : public HTTPPage
virtual bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) = 0;
};
-class WebPanelProtectedPage : public WebPanelPage
+class WebPanelProtectedPage
+ : public WebPanelPage
{
Anope::string category;
- public:
+public:
WebPanelProtectedPage(const Anope::string &cat, const Anope::string &u, const Anope::string &ct = "text/html") : WebPanelPage(u, ct), category(cat)
{
}
- bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) anope_override anope_final
+ bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) override final
{
ServiceReference<Panel> panel("Panel", "webcpanel");
NickAlias *na;
@@ -103,16 +109,17 @@ class WebPanelProtectedPage : public WebPanelPage
Anope::string sections, get;
- for (std::map<Anope::string, Anope::string>::iterator it = message.get_data.begin(), it_end = message.get_data.end(); it != it_end; ++it)
- if (this->GetData().count(it->first) > 0)
- get += "&" + it->first + "=" + HTTPUtils::URLEncode(it->second);
+ for (const auto &[key, value] : message.get_data)
+ {
+ if (this->GetData().count(key) > 0)
+ get += "&" + key + "=" + HTTPUtils::URLEncode(value);
+ }
if (get.empty() == false)
get = "?" + get.substr(1);
Section *ns = NULL;
- for (unsigned i = 0; i < panel->sections.size(); ++i)
+ for (auto &s : panel->sections)
{
- Section& s = panel->sections[i];
if (s.name == this->category)
ns = &s;
replacements["CATEGORY_URLS"] = s.subsections[0].url;
@@ -122,9 +129,8 @@ class WebPanelProtectedPage : public WebPanelPage
if (ns)
{
sections = "";
- for (unsigned i = 0; i < ns->subsections.size(); ++i)
+ for (const auto &ss : ns->subsections)
{
- SubSection& ss = ns->subsections[i];
replacements["SUBCATEGORY_URLS"] = ss.url;
replacements["SUBCATEGORY_GETS"] = get;
replacements["SUBCATEGORY_NAMES"] = ss.name;
@@ -162,21 +168,8 @@ namespace WebPanel
#include "pages/register.h"
#include "pages/confirm.h"
-#include "pages/nickserv/info.h"
-#include "pages/nickserv/cert.h"
-#include "pages/nickserv/access.h"
-#include "pages/nickserv/alist.h"
-#include "pages/nickserv/confirm.h"
-
-#include "pages/chanserv/info.h"
-#include "pages/chanserv/set.h"
-#include "pages/chanserv/access.h"
-#include "pages/chanserv/akick.h"
-#include "pages/chanserv/modes.h"
-#include "pages/chanserv/drop.h"
-
-#include "pages/memoserv/memos.h"
-
-#include "pages/hostserv/request.h"
-
-#include "pages/operserv/akill.h"
+#include "pages/chanserv/chanserv.h"
+#include "pages/hostserv/hostserv.h"
+#include "pages/memoserv/memoserv.h"
+#include "pages/nickserv/nickserv.h"
+#include "pages/operserv/operserv.h"
diff --git a/modules/m_xmlrpc.cpp b/modules/xmlrpc.cpp
index ce2aab2f0..a6844bb9a 100644
--- a/modules/m_xmlrpc.cpp
+++ b/modules/xmlrpc.cpp
@@ -10,7 +10,7 @@
#include "modules/xmlrpc.h"
#include "modules/httpd.h"
-static struct special_chars
+static struct special_chars final
{
Anope::string character;
Anope::string replace;
@@ -32,19 +32,21 @@ special[] = {
special_chars("", "")
};
-class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
+class MyXMLRPCServiceInterface final
+ : public XMLRPCServiceInterface
+ , public HTTPPage
{
std::deque<XMLRPCEvent *> events;
- public:
+public:
MyXMLRPCServiceInterface(Module *creator, const Anope::string &sname) : XMLRPCServiceInterface(creator, sname), HTTPPage("/xmlrpc", "text/xml") { }
- void Register(XMLRPCEvent *event) anope_override
+ void Register(XMLRPCEvent *event) override
{
this->events.push_back(event);
}
- void Unregister(XMLRPCEvent *event) anope_override
+ void Unregister(XMLRPCEvent *event) override
{
std::deque<XMLRPCEvent *>::iterator it = std::find(this->events.begin(), this->events.end(), event);
@@ -52,10 +54,10 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
this->events.erase(it);
}
- Anope::string Sanitize(const Anope::string &string) anope_override
+ Anope::string Sanitize(const Anope::string &string) override
{
Anope::string ret = string;
- for (int i = 0; special[i].character.empty() == false; ++i)
+ for (int i = 0; !special[i].character.empty(); ++i)
ret = ret.replace_all_cs(special[i].character, special[i].replace);
return ret;
}
@@ -63,7 +65,7 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
static Anope::string Unescape(const Anope::string &string)
{
Anope::string ret = string;
- for (int i = 0; special[i].character.empty() == false; ++i)
+ for (int i = 0; !special[i].character.empty(); ++i)
if (!special[i].replace.empty())
ret = ret.replace_all_cs(special[i].replace, special[i].character);
@@ -93,7 +95,7 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
return ret;
}
- private:
+private:
static bool GetData(Anope::string &content, Anope::string &tag, Anope::string &data)
{
if (content.empty())
@@ -144,15 +146,15 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
return !istag && !data.empty();
}
- public:
- bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) anope_override
+public:
+ bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) override
{
Anope::string content = message.content, tname, data;
XMLRPCRequest request(reply);
while (GetData(content, tname, data))
{
- Log(LOG_DEBUG) << "m_xmlrpc: Tag name: " << tname << ", data: " << data;
+ Log(LOG_DEBUG) << "xmlrpc: Tag name: " << tname << ", data: " << data;
if (tname == "methodName")
request.name = data;
else if (tname == "name" && data == "id")
@@ -164,10 +166,8 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
request.data.push_back(data);
}
- for (unsigned i = 0; i < this->events.size(); ++i)
+ for (auto *e : this->events)
{
- XMLRPCEvent *e = this->events[i];
-
if (!e->Run(this, client, request))
return false;
else if (!request.get_replies().empty())
@@ -182,24 +182,25 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
return true;
}
- void Reply(XMLRPCRequest &request) anope_override
+ void Reply(XMLRPCRequest &request) override
{
if (!request.id.empty())
request.reply("id", request.id);
Anope::string r = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<methodResponse>\n<params>\n<param>\n<value>\n<struct>\n";
- for (std::map<Anope::string, Anope::string>::const_iterator it = request.get_replies().begin(); it != request.get_replies().end(); ++it)
- r += "<member>\n<name>" + it->first + "</name>\n<value>\n<string>" + this->Sanitize(it->second) + "</string>\n</value>\n</member>\n";
+ for (const auto &[name, value] : request.get_replies())
+ r += "<member>\n<name>" + name + "</name>\n<value>\n<string>" + this->Sanitize(value) + "</string>\n</value>\n</member>\n";
r += "</struct>\n</value>\n</param>\n</params>\n</methodResponse>";
request.r.Write(r);
}
};
-class ModuleXMLRPC : public Module
+class ModuleXMLRPC final
+ : public Module
{
ServiceReference<HTTPProvider> httpref;
- public:
+public:
MyXMLRPCServiceInterface xmlrpcinterface;
ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
@@ -208,19 +209,19 @@ class ModuleXMLRPC : public Module
}
- ~ModuleXMLRPC()
+ ~ModuleXMLRPC() override
{
if (httpref)
httpref->UnregisterPage(&xmlrpcinterface);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
if (httpref)
httpref->UnregisterPage(&xmlrpcinterface);
this->httpref = ServiceReference<HTTPProvider>("HTTPProvider", conf->GetModule(this)->Get<const Anope::string>("server", "httpd/main"));
if (!httpref)
- throw ConfigException("Unable to find http reference, is m_httpd loaded?");
+ throw ConfigException("Unable to find http reference, is httpd loaded?");
httpref->RegisterPage(&xmlrpcinterface);
}
};
diff --git a/modules/m_xmlrpc_main.cpp b/modules/xmlrpc_main.cpp
index 7b4e35fe6..abf648da8 100644
--- a/modules/m_xmlrpc_main.cpp
+++ b/modules/xmlrpc_main.cpp
@@ -11,7 +11,8 @@
static Module *me;
-class XMLRPCIdentifyRequest : public IdentifyRequest
+class XMLRPCIdentifyRequest final
+ : public IdentifyRequest
{
XMLRPCRequest request;
HTTPReply repl; /* Request holds a reference to the HTTPReply, because we might exist long enough to invalidate it
@@ -19,10 +20,10 @@ class XMLRPCIdentifyRequest : public IdentifyRequest
Reference<HTTPClient> client;
Reference<XMLRPCServiceInterface> xinterface;
- public:
- XMLRPCIdentifyRequest(Module *m, XMLRPCRequest& req, HTTPClient *c, XMLRPCServiceInterface* iface, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), request(req), repl(request.r), client(c), xinterface(iface) { }
+public:
+ XMLRPCIdentifyRequest(Module *m, XMLRPCRequest &req, HTTPClient *c, XMLRPCServiceInterface *iface, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), request(req), repl(request.r), client(c), xinterface(iface) { }
- void OnSuccess() anope_override
+ void OnSuccess() override
{
if (!xinterface || !client)
return;
@@ -36,7 +37,7 @@ class XMLRPCIdentifyRequest : public IdentifyRequest
client->SendReply(&request.r);
}
- void OnFail() anope_override
+ void OnFail() override
{
if (!xinterface || !client)
return;
@@ -50,10 +51,11 @@ class XMLRPCIdentifyRequest : public IdentifyRequest
}
};
-class MyXMLRPCEvent : public XMLRPCEvent
+class MyXMLRPCEvent final
+ : public XMLRPCEvent
{
- public:
- bool Run(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) anope_override
+public:
+ bool Run(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) override
{
if (request.name == "command")
this->DoCommand(iface, client, request);
@@ -73,7 +75,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
return true;
}
- private:
+private:
void DoCommand(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
Anope::string service = request.data.size() > 0 ? request.data[0] : "";
@@ -95,13 +97,14 @@ class MyXMLRPCEvent : public XMLRPCEvent
Anope::string out;
- struct XMLRPCommandReply : CommandReply
+ struct XMLRPCommandReply final
+ : CommandReply
{
Anope::string &str;
XMLRPCommandReply(Anope::string &s) : str(s) { }
- void SendMessage(BotInfo *, const Anope::string &msg) anope_override
+ void SendMessage(BotInfo *source, const Anope::string &msg) override
{
str += msg + "\n";
};
@@ -118,7 +121,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
}
}
- bool DoCheckAuthentication(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
+ static bool DoCheckAuthentication(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
Anope::string username = request.data.size() > 0 ? request.data[0] : "";
Anope::string password = request.data.size() > 1 ? request.data[1] : "";
@@ -127,7 +130,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
request.reply("error", "Invalid parameters");
else
{
- XMLRPCIdentifyRequest *req = new XMLRPCIdentifyRequest(me, request, client, iface, username, password);
+ auto *req = new XMLRPCIdentifyRequest(me, request, client, iface, username, password);
FOREACH_MOD(OnCheckAuthentication, (NULL, req));
req->Dispatch();
return false;
@@ -136,24 +139,24 @@ class MyXMLRPCEvent : public XMLRPCEvent
return true;
}
- void DoStats(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
+ static void DoStats(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
- request.reply("uptime", stringify(Anope::CurTime - Anope::StartTime));
+ request.reply("uptime", Anope::ToString(Anope::CurTime - Anope::StartTime));
request.reply("uplinkname", Me->GetLinks().front()->GetName());
{
Anope::string buf;
- for (std::set<Anope::string>::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it)
- buf += " " + *it;
+ for (const auto &capab : Servers::Capab)
+ buf += " " + capab;
if (!buf.empty())
buf.erase(buf.begin());
request.reply("uplinkcapab", buf);
}
- request.reply("usercount", stringify(UserListByNick.size()));
- request.reply("maxusercount", stringify(MaxUserCount));
- request.reply("channelcount", stringify(ChannelList.size()));
+ request.reply("usercount", Anope::ToString(UserListByNick.size()));
+ request.reply("maxusercount", Anope::ToString(MaxUserCount));
+ request.reply("channelcount", Anope::ToString(ChannelList.size()));
}
- void DoChannel(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
+ static void DoChannel(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
if (request.data.empty())
return;
@@ -164,23 +167,20 @@ class MyXMLRPCEvent : public XMLRPCEvent
if (c)
{
- request.reply("bancount", stringify(c->HasMode("BAN")));
+ request.reply("bancount", Anope::ToString(c->HasMode("BAN")));
int count = 0;
- std::vector<Anope::string> v = c->GetModeList("BAN");
- for (unsigned int i = 0; i < v.size(); ++i)
- request.reply("ban" + stringify(++count), iface->Sanitize(v[i]));
+ for (auto &ban : c->GetModeList("BAN"))
+ request.reply("ban" + Anope::ToString(++count), iface->Sanitize(ban));
- request.reply("exceptcount", stringify(c->HasMode("EXCEPT")));
+ request.reply("exceptcount", Anope::ToString(c->HasMode("EXCEPT")));
count = 0;
- v = c->GetModeList("EXCEPT");
- for (unsigned int i = 0; i < v.size(); ++i)
- request.reply("except" + stringify(++count), iface->Sanitize(v[i]));
+ for (auto &except : c->GetModeList("EXCEPT"))
+ request.reply("except" + Anope::ToString(++count), iface->Sanitize(except));
- request.reply("invitecount", stringify(c->HasMode("INVITEOVERRIDE")));
+ request.reply("invitecount", Anope::ToString(c->HasMode("INVITEOVERRIDE")));
count = 0;
- v = c->GetModeList("INVITEOVERRIDE");
- for (unsigned int i = 0; i < v.size(); ++i)
- request.reply("invite" + stringify(++count), iface->Sanitize(v[i]));
+ for (auto &invite : c->GetModeList("INVITEOVERRIDE"))
+ request.reply("invite" + Anope::ToString(++count), iface->Sanitize(invite));
Anope::string users;
for (Channel::ChanUserList::const_iterator it = c->users.begin(); it != c->users.end(); ++it)
@@ -200,12 +200,12 @@ class MyXMLRPCEvent : public XMLRPCEvent
if (!c->topic_setter.empty())
request.reply("topicsetter", iface->Sanitize(c->topic_setter));
- request.reply("topictime", stringify(c->topic_time));
- request.reply("topicts", stringify(c->topic_ts));
+ request.reply("topictime", Anope::ToString(c->topic_time));
+ request.reply("topicts", Anope::ToString(c->topic_ts));
}
}
- void DoUser(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
+ static void DoUser(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
if (request.data.empty())
return;
@@ -224,8 +224,8 @@ class MyXMLRPCEvent : public XMLRPCEvent
if (!u->chost.empty())
request.reply("chost", iface->Sanitize(u->chost));
request.reply("ip", u->ip.addr());
- request.reply("timestamp", stringify(u->timestamp));
- request.reply("signon", stringify(u->signon));
+ request.reply("timestamp", Anope::ToString(u->timestamp));
+ request.reply("signon", Anope::ToString(u->signon));
if (u->Account())
{
request.reply("account", iface->Sanitize(u->Account()->display));
@@ -247,25 +247,20 @@ class MyXMLRPCEvent : public XMLRPCEvent
}
}
- void DoOperType(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
+ static void DoOperType(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
- for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i)
+ for (auto *ot : Config->MyOperTypes)
{
- OperType *ot = Config->MyOperTypes[i];
Anope::string perms;
-
- std::list<Anope::string> privs = ot->GetPrivs();
- for (std::list<Anope::string>::const_iterator it2 = privs.begin(), it2_end = privs.end(); it2 != it2_end; ++it2)
- perms += " " + *it2;
-
- std::list<Anope::string> commands = ot->GetCommands();
- for (std::list<Anope::string>::const_iterator it2 = commands.begin(), it2_end = commands.end(); it2 != it2_end; ++it2)
- perms += " " + *it2;
+ for (const auto &priv : ot->GetPrivs())
+ perms += " " + priv;
+ for (const auto &command : ot->GetCommands())
+ perms += " " + command;
request.reply(ot->GetName(), perms);
}
}
- void DoNotice(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
+ static void DoNotice(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
Anope::string from = request.data.size() > 0 ? request.data[0] : "";
Anope::string to = request.data.size() > 1 ? request.data[1] : "";
@@ -283,24 +278,25 @@ class MyXMLRPCEvent : public XMLRPCEvent
}
};
-class ModuleXMLRPCMain : public Module
+class ModuleXMLRPCMain final
+ : public Module
{
ServiceReference<XMLRPCServiceInterface> xmlrpc;
MyXMLRPCEvent stats;
- public:
+public:
ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), xmlrpc("XMLRPCServiceInterface", "xmlrpc")
{
me = this;
if (!xmlrpc)
- throw ModuleException("Unable to find xmlrpc reference, is m_xmlrpc loaded?");
+ throw ModuleException("Unable to find xmlrpc reference, is xmlrpc loaded?");
xmlrpc->Register(&stats);
}
- ~ModuleXMLRPCMain()
+ ~ModuleXMLRPCMain() override
{
if (xmlrpc)
xmlrpc->Unregister(&stats);