From 90d9d02c9e30c673e6394e53e578a106e54b74fe Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 28 Feb 2025 02:28:54 +0000 Subject: Improve the consistency of duration strings. Unfortunately because of leap years we can't really make duration strings exact. Because of this we have always added 6 hours on to each year to make it correct over time. However, we did not do this in any kind of consistent way which resulted in weird roundtripped duration strings which made this very confusing for users While I'm touching the duration code I've also cleaned it up. --- src/helperfuncs.cpp | 63 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index b9ddd2767..e14f0e442 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -363,6 +363,21 @@ bool InspIRCd::IsSID(const std::string_view& str) ((str[2] >= 'A' && str[2] <= 'Z') || isdigit(str[2]))); } +namespace +{ + constexpr const auto SECONDS_PER_MINUTE = 60; + + constexpr const auto SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60; + + constexpr const auto SECONDS_PER_DAY = SECONDS_PER_HOUR * 24; + + constexpr const auto SECONDS_PER_WEEK = SECONDS_PER_DAY * 7; + + constexpr const auto SECONDS_PER_YEAR = (SECONDS_PER_DAY * 365); + + constexpr const auto SECONDS_PER_AVG_YEAR = SECONDS_PER_YEAR + (SECONDS_PER_HOUR * 6); +} + /** A lookup table of values for multiplier characters used by * Duration::{Try,}From(). In this lookup table, the indexes for * the ascii values 'm' and 'M' have the value '60', the indexes @@ -374,10 +389,10 @@ static constexpr unsigned int duration_multi[] = 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, 86400, 0, 0, 0, 3600, 0, 0, 0, 0, 60, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 604800, 0, 31557600, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 86400, 0, 0, 0, 3600, 0, 0, 0, 0, 60, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 604800, 0, 31557600, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, SECONDS_PER_DAY, 0, 0, 0, SECONDS_PER_HOUR, 0, 0, 0, 0, SECONDS_PER_MINUTE, 0, 0, + 0, 0, 0, 1, 0, 0, 0, SECONDS_PER_WEEK, 0, SECONDS_PER_AVG_YEAR, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, SECONDS_PER_DAY, 0, 0, 0, SECONDS_PER_HOUR, 0, 0, 0, 0, SECONDS_PER_MINUTE, 0, 0, + 0, 0, 0, 1, 0, 0, 0, SECONDS_PER_WEEK, 0, SECONDS_PER_AVG_YEAR, 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, @@ -449,29 +464,43 @@ std::string Duration::ToString(unsigned long duration) std::string ret; - unsigned long years = duration / 31449600; + const auto years = (duration / SECONDS_PER_YEAR); if (years) - ret += ConvToStr(years) + "y"; + { + ret = INSP_FORMAT("{}y", years); + duration -= (years * SECONDS_PER_YEAR); + } - unsigned long weeks = (duration / 604800) % 52; + const auto weeks = (duration / SECONDS_PER_WEEK); if (weeks) - ret += ConvToStr(weeks) + "w"; + { + ret += INSP_FORMAT("{}w", weeks); + duration -= (weeks * SECONDS_PER_WEEK); + } - unsigned long days = (duration / 86400) % 7; + const auto days = (duration / SECONDS_PER_DAY); if (days) - ret += ConvToStr(days) + "d"; + { + ret += INSP_FORMAT("{}d", days); + duration -= (days * SECONDS_PER_DAY); + } - unsigned long hours = (duration / 3600) % 24; + const auto hours = (duration / SECONDS_PER_HOUR); if (hours) - ret += ConvToStr(hours) + "h"; + { + ret += INSP_FORMAT("{}h", hours); + duration -= (hours * SECONDS_PER_HOUR); + } - unsigned long minutes = (duration / 60) % 60; + const auto minutes = (duration / SECONDS_PER_MINUTE); if (minutes) - ret += ConvToStr(minutes) + "m"; + { + ret += INSP_FORMAT("{}m", minutes); + duration -= (minutes * SECONDS_PER_MINUTE); + } - unsigned long seconds = duration % 60; - if (seconds) - ret += ConvToStr(seconds) + "s"; + if (duration) + ret += INSP_FORMAT("{}s", duration); return ret; } -- cgit v1.3.1-10-gc9f91 From cdd3226befacd40c07b5c987cf93d0626df8d287 Mon Sep 17 00:00:00 2001 From: InspIRCd Robot Date: Fri, 28 Feb 2025 13:42:05 +0000 Subject: Update copyright headers. --- include/inspircd.h | 2 +- include/logging.h | 2 +- include/moduledefs.h | 2 +- include/modules.h | 2 +- include/numeric.h | 2 +- include/timeutils.h | 2 +- src/bancache.cpp | 2 +- src/channels.cpp | 2 +- src/configreader.cpp | 2 +- src/coremods/core_channel/cmd_kick.cpp | 2 +- src/coremods/core_channel/extban.cpp | 2 +- src/coremods/core_dns.cpp | 2 +- src/coremods/core_hostname_lookup.cpp | 2 +- src/coremods/core_info/cmd_time.cpp | 2 +- src/coremods/core_info/core_info.cpp | 2 +- src/coremods/core_info/core_info.h | 2 +- src/coremods/core_info/isupport.cpp | 2 +- src/coremods/core_lusers.cpp | 4 ++-- src/coremods/core_xline/cmd_eline.cpp | 2 +- src/coremods/core_xline/cmd_gline.cpp | 2 +- src/coremods/core_xline/cmd_kline.cpp | 2 +- src/coremods/core_xline/cmd_qline.cpp | 2 +- src/coremods/core_xline/cmd_zline.cpp | 2 +- src/helperfuncs.cpp | 2 +- src/inspircd.cpp | 2 +- src/listmode.cpp | 2 +- src/logging.cpp | 2 +- src/modules/extra/m_mysql.cpp | 2 +- src/modules/extra/m_pgsql.cpp | 2 +- src/modules/extra/m_sqlite3.cpp | 2 +- src/modules/extra/m_ssl_gnutls.cpp | 2 +- src/modules/extra/m_ssl_openssl.cpp | 2 +- src/modules/m_alltime.cpp | 4 ++-- src/modules/m_cban.cpp | 3 +-- src/modules/m_chancreate.cpp | 2 +- src/modules/m_dnsbl.cpp | 2 +- src/modules/m_filter.cpp | 2 +- src/modules/m_httpd_stats.cpp | 2 +- src/modules/m_ident.cpp | 2 +- src/modules/m_repeat.cpp | 3 ++- src/modules/m_rline.cpp | 2 +- src/modules/m_seenicks.cpp | 2 +- src/modules/m_spanningtree/compat.cpp | 2 +- src/modules/m_spanningtree/ijoin.cpp | 2 +- src/modules/m_spanningtree/sinfo.cpp | 2 +- src/modules/m_websocket.cpp | 2 +- src/server.cpp | 2 +- src/usermanager.cpp | 2 +- src/users.cpp | 2 +- src/xline.cpp | 2 +- 50 files changed, 53 insertions(+), 53 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/include/inspircd.h b/include/inspircd.h index 08b1d80f8..7400fe717 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2012-2016, 2018 Attila Molnar - * Copyright (C) 2012-2013, 2017-2024 Sadie Powell + * Copyright (C) 2012-2013, 2017-2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/include/logging.h b/include/logging.h index e613761a7..01f9104bd 100644 --- a/include/logging.h +++ b/include/logging.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2022-2024 Sadie Powell + * Copyright (C) 2022-2025 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/include/moduledefs.h b/include/moduledefs.h index ed821da35..6489060c6 100644 --- a/include/moduledefs.h +++ b/include/moduledefs.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2020, 2024 Sadie Powell + * Copyright (C) 2020, 2025 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/include/modules.h b/include/modules.h index 50a611437..e3d4eb96b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -3,7 +3,7 @@ * * Copyright (C) 2019 iwalkalone * Copyright (C) 2012-2016, 2018 Attila Molnar - * Copyright (C) 2012-2013, 2017-2024 Sadie Powell + * Copyright (C) 2012-2013, 2017-2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2008 Thomas Stagner diff --git a/include/numeric.h b/include/numeric.h index 78d7cd7b6..476ba0e0f 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018-2022, 2024 Sadie Powell + * Copyright (C) 2018-2022, 2024-2025 Sadie Powell * Copyright (C) 2016 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/include/timeutils.h b/include/timeutils.h index 5dd10dd6e..c82138030 100644 --- a/include/timeutils.h +++ b/include/timeutils.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2023-2024 Sadie Powell + * Copyright (C) 2023-2025 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/src/bancache.cpp b/src/bancache.cpp index a26e0ab2d..81e4e72b9 100644 --- a/src/bancache.cpp +++ b/src/bancache.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2021-2022 Sadie Powell + * Copyright (C) 2021-2022, 2025 Sadie Powell * Copyright (C) 2012-2014 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf diff --git a/src/channels.cpp b/src/channels.cpp index d663ecb37..494b58003 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013-2016, 2018 Attila Molnar - * Copyright (C) 2013, 2016-2024 Sadie Powell + * Copyright (C) 2013, 2016-2025 Sadie Powell * Copyright (C) 2013 Adam * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/configreader.cpp b/src/configreader.cpp index fc01b533d..0fc7900a4 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013-2016 Attila Molnar - * Copyright (C) 2013-2014, 2016-2024 Sadie Powell + * Copyright (C) 2013-2014, 2016-2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/coremods/core_channel/cmd_kick.cpp b/src/coremods/core_channel/cmd_kick.cpp index 83916fa3b..94773223c 100644 --- a/src/coremods/core_channel/cmd_kick.cpp +++ b/src/coremods/core_channel/cmd_kick.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2017-2018, 2020, 2022-2023 Sadie Powell + * Copyright (C) 2017-2018, 2020, 2022-2023, 2025 Sadie Powell * Copyright (C) 2017 B00mX0r * Copyright (C) 2013-2014, 2016 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/coremods/core_channel/extban.cpp b/src/coremods/core_channel/extban.cpp index 721636eee..1728c2aaa 100644 --- a/src/coremods/core_channel/extban.cpp +++ b/src/coremods/core_channel/extban.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2020, 2022-2024 Sadie Powell + * Copyright (C) 2020, 2022-2025 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index 78d061ec8..d707dbd47 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2019 Robby - * Copyright (C) 2015, 2018-2023 Sadie Powell + * Copyright (C) 2015, 2018-2023, 2025 Sadie Powell * Copyright (C) 2014-2016 Attila Molnar * Copyright (C) 2013, 2015-2016, 2021 Adam * diff --git a/src/coremods/core_hostname_lookup.cpp b/src/coremods/core_hostname_lookup.cpp index f1f2e1ebc..dd8557d26 100644 --- a/src/coremods/core_hostname_lookup.cpp +++ b/src/coremods/core_hostname_lookup.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2013, 2018-2023 Sadie Powell + * Copyright (C) 2013, 2018-2023, 2025 Sadie Powell * Copyright (C) 2013, 2016 Adam * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/coremods/core_info/cmd_time.cpp b/src/coremods/core_info/cmd_time.cpp index d1aa02246..ee606e4e8 100644 --- a/src/coremods/core_info/cmd_time.cpp +++ b/src/coremods/core_info/cmd_time.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018, 2020, 2022-2023 Sadie Powell + * Copyright (C) 2018, 2020, 2022-2023, 2025 Sadie Powell * Copyright (C) 2014, 2016 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/coremods/core_info/core_info.cpp b/src/coremods/core_info/core_info.cpp index b9b196bf8..abc5fc522 100644 --- a/src/coremods/core_info/core_info.cpp +++ b/src/coremods/core_info/core_info.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2021 Herman - * Copyright (C) 2018-2024 Sadie Powell + * Copyright (C) 2018-2025 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2014, 2016, 2018 Attila Molnar * diff --git a/src/coremods/core_info/core_info.h b/src/coremods/core_info/core_info.h index 0b36014ff..7be63b430 100644 --- a/src/coremods/core_info/core_info.h +++ b/src/coremods/core_info/core_info.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018-2024 Sadie Powell + * Copyright (C) 2018-2025 Sadie Powell * Copyright (C) 2014, 2016 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/coremods/core_info/isupport.cpp b/src/coremods/core_info/isupport.cpp index 02d9e037f..b40eb2e50 100644 --- a/src/coremods/core_info/isupport.cpp +++ b/src/coremods/core_info/isupport.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2020-2024 Sadie Powell + * Copyright (C) 2020-2025 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/src/coremods/core_lusers.cpp b/src/coremods/core_lusers.cpp index 4dbb0c315..293397390 100644 --- a/src/coremods/core_lusers.cpp +++ b/src/coremods/core_lusers.cpp @@ -1,8 +1,8 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018-2024 Sadie Powell - * Copyright (C) 2012-2013, 2016 Attila Molnar + * Copyright (C) 2018-2025 Sadie Powell + * Copyright (C) 2012-2013 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2007 Dennis Friis diff --git a/src/coremods/core_xline/cmd_eline.cpp b/src/coremods/core_xline/cmd_eline.cpp index 871ac2968..c51081074 100644 --- a/src/coremods/core_xline/cmd_eline.cpp +++ b/src/coremods/core_xline/cmd_eline.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2018, 2020-2024 Sadie Powell + * Copyright (C) 2018, 2020-2023, 2025 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2014 Attila Molnar * Copyright (C) 2012, 2019 Robby diff --git a/src/coremods/core_xline/cmd_gline.cpp b/src/coremods/core_xline/cmd_gline.cpp index 16d2ebcac..bf90946e0 100644 --- a/src/coremods/core_xline/cmd_gline.cpp +++ b/src/coremods/core_xline/cmd_gline.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2018, 2020-2024 Sadie Powell + * Copyright (C) 2018, 2020-2023, 2025 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2014 Attila Molnar * Copyright (C) 2012, 2019 Robby diff --git a/src/coremods/core_xline/cmd_kline.cpp b/src/coremods/core_xline/cmd_kline.cpp index 90f830f69..46917d45f 100644 --- a/src/coremods/core_xline/cmd_kline.cpp +++ b/src/coremods/core_xline/cmd_kline.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2018, 2020-2024 Sadie Powell + * Copyright (C) 2018, 2020-2023, 2025 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2014 Attila Molnar * Copyright (C) 2012, 2019 Robby diff --git a/src/coremods/core_xline/cmd_qline.cpp b/src/coremods/core_xline/cmd_qline.cpp index 224370144..1b107d613 100644 --- a/src/coremods/core_xline/cmd_qline.cpp +++ b/src/coremods/core_xline/cmd_qline.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2018, 2020, 2022-2024 Sadie Powell + * Copyright (C) 2018, 2020, 2022-2023, 2025 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2014 Attila Molnar * Copyright (C) 2012, 2019 Robby diff --git a/src/coremods/core_xline/cmd_zline.cpp b/src/coremods/core_xline/cmd_zline.cpp index 05fe581f2..54ce96c98 100644 --- a/src/coremods/core_xline/cmd_zline.cpp +++ b/src/coremods/core_xline/cmd_zline.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2018, 2020, 2022-2024 Sadie Powell + * Copyright (C) 2018, 2020, 2022-2023, 2025 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2014 Attila Molnar * Copyright (C) 2012, 2019 Robby diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index e14f0e442..a43c4d9dd 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 Matt Schatz * Copyright (C) 2018 linuxdaemon * Copyright (C) 2012-2013 Attila Molnar - * Copyright (C) 2012, 2014, 2017-2018, 2020-2024 Sadie Powell + * Copyright (C) 2012, 2014, 2017-2018, 2020-2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/inspircd.cpp b/src/inspircd.cpp index b9018ea7d..38657b0fb 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2018 Chris Novakovic - * Copyright (C) 2013, 2017-2024 Sadie Powell + * Copyright (C) 2013, 2017-2025 Sadie Powell * Copyright (C) 2013 Adam * Copyright (C) 2012-2014, 2018 Attila Molnar * Copyright (C) 2012-2013 ChrisTX diff --git a/src/listmode.cpp b/src/listmode.cpp index b0fbd922b..99ae46374 100644 --- a/src/listmode.cpp +++ b/src/listmode.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 linuxdaemon * Copyright (C) 2018 B00mX0r - * Copyright (C) 2017-2023 Sadie Powell + * Copyright (C) 2017-2023, 2025 Sadie Powell * Copyright (C) 2013-2014 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/logging.cpp b/src/logging.cpp index ebae62019..139a1b8b3 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2022-2024 Sadie Powell + * Copyright (C) 2022-2025 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index ec3acd09a..290a862fe 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2015 Daniel Vassdal * Copyright (C) 2013-2014 Attila Molnar - * Copyright (C) 2013, 2016-2024 Sadie Powell + * Copyright (C) 2013, 2016-2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index 228e28b83..f41e1482a 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2024 Larry Williamson * Copyright (C) 2015 Daniel Vassdal - * Copyright (C) 2013, 2016-2017, 2019-2024 Sadie Powell + * Copyright (C) 2013, 2016-2017, 2019-2025 Sadie Powell * Copyright (C) 2012-2015 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index 246f65a8e..ca6e4dbc2 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Daniel Vassdal * Copyright (C) 2014, 2016 Attila Molnar - * Copyright (C) 2013-2014, 2016-2017, 2019-2024 Sadie Powell + * Copyright (C) 2013-2014, 2016-2017, 2019-2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2012 Adam diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 2b9fdfdab..b6a8a142f 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2020 Matt Schatz - * Copyright (C) 2013-2014, 2016-2024 Sadie Powell + * Copyright (C) 2013-2014, 2016-2025 Sadie Powell * Copyright (C) 2013 Daniel Vassdal * Copyright (C) 2012-2017 Attila Molnar * Copyright (C) 2012-2013, 2016 Adam diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index 5c43ad6bb..7b8edd50d 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2020 Matt Schatz * Copyright (C) 2017, 2023 Wade Cline - * Copyright (C) 2014, 2016-2017, 2019-2024 Sadie Powell + * Copyright (C) 2014, 2016-2017, 2019-2025 Sadie Powell * Copyright (C) 2014 Julien Vehent * Copyright (C) 2012-2017 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/modules/m_alltime.cpp b/src/modules/m_alltime.cpp index fadb325f4..64c6a8638 100644 --- a/src/modules/m_alltime.cpp +++ b/src/modules/m_alltime.cpp @@ -1,9 +1,9 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019-2023 Sadie Powell - * Copyright (C) 2012, 2016 Attila Molnar + * Copyright (C) 2019-2023, 2025 Sadie Powell * Copyright (C) 2012 Robby + * Copyright (C) 2012 Attila Molnar * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2007 Dennis Friis * Copyright (C) 2007 Craig Edwards diff --git a/src/modules/m_cban.cpp b/src/modules/m_cban.cpp index 746deb0a5..05c200663 100644 --- a/src/modules/m_cban.cpp +++ b/src/modules/m_cban.cpp @@ -4,10 +4,9 @@ * Copyright (C) 2020 Michael * Copyright (C) 2019 Matt Schatz * Copyright (C) 2018 linuxdaemon - * Copyright (C) 2013, 2018-2024 Sadie Powell + * Copyright (C) 2013, 2018-2023, 2025 Sadie Powell * Copyright (C) 2012, 2019 Robby * Copyright (C) 2012, 2016 Attila Molnar - * Copyright (C) 2009 John Brooks * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2007-2008 Dennis Friis * Copyright (C) 2006 Craig Edwards diff --git a/src/modules/m_chancreate.cpp b/src/modules/m_chancreate.cpp index ca64e1ae9..5e17c22d1 100644 --- a/src/modules/m_chancreate.cpp +++ b/src/modules/m_chancreate.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019-2021, 2023 Sadie Powell + * Copyright (C) 2019-2021, 2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2012 Attila Molnar * Copyright (C) 2008 Robin Burchell diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index 58f1eee23..18bd199ae 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2020 Matt Schatz * Copyright (C) 2018-2019 linuxdaemon - * Copyright (C) 2017-2024 Sadie Powell + * Copyright (C) 2017-2025 Sadie Powell * Copyright (C) 2013, 2016 Adam * Copyright (C) 2013, 2015-2016 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 35a763914..9ba0ce200 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -8,7 +8,7 @@ * Copyright (C) 2018 Michael Hazell * Copyright (C) 2017 B00mX0r * Copyright (C) 2012-2014, 2016 Attila Molnar - * Copyright (C) 2012-2013, 2017-2024 Sadie Powell + * Copyright (C) 2012-2013, 2017-2025 Sadie Powell * Copyright (C) 2012, 2018-2019 Robby * Copyright (C) 2011 Adam * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index b2d5a09e2..f1ff1548b 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2019 linuxdaemon * Copyright (C) 2016 Johanna A - * Copyright (C) 2013, 2020-2023 Sadie Powell + * Copyright (C) 2013, 2020-2023, 2025 Sadie Powell * Copyright (C) 2013, 2015 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 92723fe07..50de7865c 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2021 Dominic Hamon - * Copyright (C) 2013, 2018-2023 Sadie Powell + * Copyright (C) 2013, 2018-2023, 2025 Sadie Powell * Copyright (C) 2012-2013 Robby * Copyright (C) 2012, 2014-2015 Attila Molnar * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/m_repeat.cpp b/src/modules/m_repeat.cpp index b501369f2..3f5763096 100644 --- a/src/modules/m_repeat.cpp +++ b/src/modules/m_repeat.cpp @@ -1,11 +1,12 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2025 iwalkalone * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2021 David Schultz * Copyright (C) 2018 linuxdaemon * Copyright (C) 2018 Matt Schatz - * Copyright (C) 2017-2024 Sadie Powell + * Copyright (C) 2017-2025 Sadie Powell * Copyright (C) 2013-2014 Attila Molnar * Copyright (C) 2013 Daniel Vassdal * diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index 476419a02..96a39716f 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2019 Matt Schatz * Copyright (C) 2018 linuxdaemon - * Copyright (C) 2013, 2018-2024 Sadie Powell + * Copyright (C) 2013, 2018-2023, 2025 Sadie Powell * Copyright (C) 2012-2013, 2016 Attila Molnar * Copyright (C) 2012, 2019 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/m_seenicks.cpp b/src/modules/m_seenicks.cpp index 4407fcab7..5fe7a79c2 100644 --- a/src/modules/m_seenicks.cpp +++ b/src/modules/m_seenicks.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019-2021, 2023 Sadie Powell + * Copyright (C) 2019-2021, 2025 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2007-2008 Craig Edwards diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index 252813f60..8be5f8ec9 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2021, 2024 Sadie Powell + * Copyright (C) 2021, 2024-2025 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/src/modules/m_spanningtree/ijoin.cpp b/src/modules/m_spanningtree/ijoin.cpp index 444d7e8ed..a03f141eb 100644 --- a/src/modules/m_spanningtree/ijoin.cpp +++ b/src/modules/m_spanningtree/ijoin.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018, 2020, 2022-2024 Sadie Powell + * Copyright (C) 2018, 2020, 2022-2025 Sadie Powell * Copyright (C) 2013-2014, 2016 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/modules/m_spanningtree/sinfo.cpp b/src/modules/m_spanningtree/sinfo.cpp index 09e654b3b..ea9bfd4dc 100644 --- a/src/modules/m_spanningtree/sinfo.cpp +++ b/src/modules/m_spanningtree/sinfo.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018-2020, 2022-2023 Sadie Powell + * Copyright (C) 2018-2020, 2022-2023, 2025 Sadie Powell * Copyright (C) 2017 B00mX0r * Copyright (C) 2014 Attila Molnar * diff --git a/src/modules/m_websocket.cpp b/src/modules/m_websocket.cpp index aa6bbba0a..bbdc26eec 100644 --- a/src/modules/m_websocket.cpp +++ b/src/modules/m_websocket.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2019 iwalkalone - * Copyright (C) 2018-2024 Sadie Powell + * Copyright (C) 2018-2025 Sadie Powell * Copyright (C) 2016 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/server.cpp b/src/server.cpp index e35a666aa..d9d14d1bc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2020-2024 Sadie Powell + * Copyright (C) 2020-2025 Sadie Powell * Copyright (C) 2013-2014 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX diff --git a/src/usermanager.cpp b/src/usermanager.cpp index f2384e0a4..2a9c6e0de 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2019 iwalkalone * Copyright (C) 2013-2016, 2018 Attila Molnar - * Copyright (C) 2013, 2018-2024 Sadie Powell + * Copyright (C) 2013, 2018-2025 Sadie Powell * Copyright (C) 2013, 2015 Adam * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/users.cpp b/src/users.cpp index d565af287..7837bde36 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 linuxdaemon * Copyright (C) 2018 systocrat * Copyright (C) 2018 Dylan Frank - * Copyright (C) 2013, 2017-2024 Sadie Powell + * Copyright (C) 2013, 2017-2025 Sadie Powell * Copyright (C) 2013 Adam * Copyright (C) 2012-2016, 2018 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/xline.cpp b/src/xline.cpp index ec3178f70..99d0dee14 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2013, 2017-2023 Sadie Powell + * Copyright (C) 2013, 2017-2023, 2025 Sadie Powell * Copyright (C) 2013 Adam * Copyright (C) 2012-2014, 2016 Attila Molnar * Copyright (C) 2012, 2019 Robby -- cgit v1.3.1-10-gc9f91 From 32a127d2e0c0a624d12cf9570905fec264554550 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 1 Mar 2025 16:06:32 +0000 Subject: Avoid the use of ConvToStr in string concatenation. This function calls INSP_FORMAT in most cases nowadays so we may as well just call that manually. --- include/modules/regex.h | 4 ++-- include/timeutils.h | 6 ++++-- src/configparser.cpp | 8 ++++---- src/configreader.cpp | 2 +- src/helperfuncs.cpp | 6 +++--- src/modules/extra/m_ssl_gnutls.cpp | 3 ++- src/modules/m_chanhistory.cpp | 4 ++-- src/modules/m_cloak_md5.cpp | 4 ++-- src/modules/m_cloak_sha256.cpp | 2 +- src/modules/m_dnsbl.cpp | 6 +++--- src/modules/m_filter.cpp | 2 +- src/modules/m_pbkdf2.cpp | 3 ++- src/modules/m_permchannels.cpp | 2 +- src/modules/m_setidle.cpp | 2 +- src/modules/m_spanningtree/capab.cpp | 2 +- src/modules/m_spanningtree/override_map.cpp | 5 ++++- src/modules/m_spanningtree/treesocket2.cpp | 8 ++++---- src/modules/m_spanningtree/utils.cpp | 2 +- src/modules/m_xline_db.cpp | 2 +- src/snomasks.cpp | 2 +- src/socket.cpp | 2 +- src/usermanager.cpp | 2 +- 22 files changed, 43 insertions(+), 36 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/include/modules/regex.h b/include/modules/regex.h index d3fb71807..525990ab4 100644 --- a/include/modules/regex.h +++ b/include/modules/regex.h @@ -139,7 +139,7 @@ public: * @param error The error which occurred whilst compiling the regular expression. */ Exception(const Module* mod, const std::string& regex, const std::string& error) - : ModuleException(mod, "Error in regex '" + regex + "': " + error) + : ModuleException(mod, INSP_FORMAT("Error in regex '{}': {}", regex, error)) { } @@ -150,7 +150,7 @@ public: * @param offset The offset at which the errror occurred. */ Exception(const Module* mod, const std::string& regex, const std::string& error, size_t offset) - : ModuleException(mod, "Error in regex '" + regex + "' at offset " + ConvToStr(offset) + ": " + error) + : ModuleException(mod, INSP_FORMAT("Error in regex '{}' at offset {}: {}", regex, offset, error)) { } }; diff --git a/include/timeutils.h b/include/timeutils.h index c82138030..962c1c946 100644 --- a/include/timeutils.h +++ b/include/timeutils.h @@ -29,9 +29,10 @@ namespace Duration * seconds. If called with this duration 33,019,565 will be returned. * * @param str A string containing a duration. + * @param base The base time to use for leap year calculation. * @return Either the number of seconds in the duration or 0 on error. */ - CoreExport unsigned long From(const std::string& str); + CoreExport unsigned long From(const std::string& str, time_t base = 0); /** Determines whether a duration string is valid. * @param str The duration string to check. @@ -54,9 +55,10 @@ namespace Duration * * @param str A string containing a duration. * @param duration The location to store the resulting duration. + * @param base The base time to use for leap year calculation. * @return True if the conversion succeeded; otherwise, false. */ - CoreExport bool TryFrom(const std::string& str, unsigned long& duration); + CoreExport bool TryFrom(const std::string& str, unsigned long& duration, time_t base = 0); } namespace Time diff --git a/src/configparser.cpp b/src/configparser.cpp index 457840b71..25f97b727 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -348,7 +348,7 @@ FilePosition::FilePosition(const std::string& Name, unsigned long Line, unsigned std::string FilePosition::str() const { - return name + ":" + ConvToStr(line) + ":" + ConvToStr(column); + return INSP_FORMAT("{}:{}:{}", name, line, column); } void ParseStack::DoInclude(const std::shared_ptr& tag, int flags) @@ -588,7 +588,7 @@ std::string ConfigTag::getString(const std::string& key, const std::string& def, if (res.length() < minlen || res.length() > maxlen) { - LogMalformed(key, res, def, "not between " + ConvToStr(minlen) + " and " + ConvToStr(maxlen) + " characters in length"); + LogMalformed(key, res, def, INSP_FORMAT("not between {} and {} characters in length", minlen, maxlen)); return def; } return res; @@ -629,7 +629,7 @@ namespace default: num = def; - tag->LogMalformed(key, val, ConvToStr(def), "contains an invalid magnitude specifier (" + ConvToStr(*tail) +")"); + tag->LogMalformed(key, val, ConvToStr(def), INSP_FORMAT("contains an invalid magnitude specifier ({})", *tail)); return; } } @@ -649,7 +649,7 @@ namespace if (num >= min && num <= max) return; - tag->LogMalformed(key, ConvToStr(num), ConvToStr(def), "not between " + ConvToStr(min) + " and " + ConvToStr(max)); + tag->LogMalformed(key, ConvToStr(num), ConvToStr(def), INSP_FORMAT("not between {} and {}", min, max)); num = def; } } diff --git a/src/configreader.cpp b/src/configreader.cpp index 0fc7900a4..ac6cd7953 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -281,7 +281,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) throw CoreException("Connect class must have allow, deny, or name specified at " + tag->source.str()); if (name.empty()) - name = "unnamed-" + ConvToStr(i); + name = INSP_FORMAT("unnamed-{}", i); if (names.find(name) != names.end()) throw CoreException("Two connect classes with name \"" + name + "\" defined!"); diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index a43c4d9dd..c81a9fa0f 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -403,7 +403,7 @@ static constexpr unsigned int duration_multi[] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -bool Duration::TryFrom(const std::string& str, unsigned long& duration) +bool Duration::TryFrom(const std::string& str, unsigned long& duration, time_t base) { unsigned long total = 0; unsigned long subtotal = 0; @@ -437,10 +437,10 @@ bool Duration::TryFrom(const std::string& str, unsigned long& duration) return true; } -unsigned long Duration::From(const std::string& str) +unsigned long Duration::From(const std::string& str, time_t base) { unsigned long out = 0; - Duration::TryFrom(str, out); + Duration::TryFrom(str, out, base); return out; } diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index b6a8a142f..81db25757 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -292,7 +292,8 @@ namespace GnuTLS if (ret < 0) { // gnutls did not understand the user supplied string - throw Exception("Unable to initialize priorities to \"" + priorities + "\": " + gnutls_strerror(ret) + " Syntax error at position " + ConvToStr((unsigned int) (prioerror - priocstr))); + throw Exception(INSP_FORMAT("Unable to initialize priorities to \"{}\": {} Syntax error at position {}.", + priorities, gnutls_strerror(ret), static_cast(prioerror - priocstr))); } } diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index 290a8b2de..02d91f345 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -281,9 +281,9 @@ public: if ((prefixmsg) && (!batchcap.IsEnabled(localuser))) { - std::string message("Replaying up to " + ConvToStr(list->maxlen) + " lines of pre-join history"); + auto message = INSP_FORMAT("Replaying up to {} lines of pre-join history", list->maxlen); if (list->maxtime > 0) - message.append(" from the last " + Duration::ToString(list->maxtime)); + message += INSP_FORMAT(" from the last {}", Duration::ToString(list->maxtime)); memb->WriteNotice(message); } diff --git a/src/modules/m_cloak_md5.cpp b/src/modules/m_cloak_md5.cpp index 4cb93ea66..a8c9a5101 100644 --- a/src/modules/m_cloak_md5.cpp +++ b/src/modules/m_cloak_md5.cpp @@ -299,13 +299,13 @@ public: // Ensure that we have the parameter. const std::string key = tag->getString("key"); if (key.empty()) - throw ModuleException(creator, "You have not defined a cloaking key. Define as a " + ConvToStr(minkeylen) + "+ character network-wide secret, at " + tag->source.str()); + throw ModuleException(creator, INSP_FORMAT("You have not defined a cloaking key. Define as a {}+ character network-wide secret, at {}", minkeylen, tag->source.str())); // If we are the first cloak method then mandate a strong key. if (primary) { if (key.length() < minkeylen) - throw ModuleException(creator, "Your cloaking key is not secure. It should be at least " + ConvToStr(minkeylen) + " characters long, at " + tag->source.str()); + throw ModuleException(creator, INSP_FORMAT("Your cloaking key is not secure. It should be at least {} characters long, at {}", minkeylen, tag->source.str())); ServerInstance->Logs.Normal(MODNAME, "The {} cloak method is deprecated and will be removed in the next major version of InspIRCd. Consider migrating to cloak_sha256 instead. See " INSPIRCD_DOCS "modules/cloak_md5 for more information.", name.c_str() + 6); diff --git a/src/modules/m_cloak_sha256.cpp b/src/modules/m_cloak_sha256.cpp index dd040d0b6..4b842f615 100644 --- a/src/modules/m_cloak_sha256.cpp +++ b/src/modules/m_cloak_sha256.cpp @@ -311,7 +311,7 @@ public: // Ensure that we have the parameter. const std::string key = tag->getString("key"); if (key.length() < minkeylen) - throw ModuleException(creator, "Your cloak key should be at least " + ConvToStr(minkeylen) + " characters long, at " + tag->source.str()); + throw ModuleException(creator, INSP_FORMAT("Your cloak key should be at least {} characters long, at {}", minkeylen, tag->source.str())); psl_ctx_t* psl = nullptr; std::string psldb = tag->getString("psl"); diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index 18bd199ae..7b8e47417 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -710,9 +710,9 @@ public: dnsbl->name, dnsbl->stats_hits, dnsbl->stats_misses, dnsbl->stats_errors)); } - stats.AddGenericRow("Total DNSBL hits: " + ConvToStr(total_hits)); - stats.AddGenericRow("Total DNSBL misses: " + ConvToStr(total_misses)); - stats.AddGenericRow("Total DNSBL errors: " + ConvToStr(total_errors)); + stats.AddGenericRow(INSP_FORMAT("Total DNSBL hits: {}", total_hits)); + stats.AddGenericRow(INSP_FORMAT("Total DNSBL misses: {}", total_misses)); + stats.AddGenericRow(INSP_FORMAT("Total DNSBL errors: {}", total_errors)); return MOD_RES_DENY; } }; diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 9ba0ce200..3f2d32f7b 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -995,7 +995,7 @@ bool ModuleFilter::WriteDatabase() return true; } - const std::string newfilterconf = filterconf + ".new." + ConvToStr(ServerInstance->Time()); + const auto newfilterconf = INSP_FORMAT("{}.new.{}", filterconf, ServerInstance->Time()); std::ofstream stream(newfilterconf.c_str()); if (!stream.is_open()) // Filesystem probably not writable. { diff --git a/src/modules/m_pbkdf2.cpp b/src/modules/m_pbkdf2.cpp index d13740128..037a2863e 100644 --- a/src/modules/m_pbkdf2.cpp +++ b/src/modules/m_pbkdf2.cpp @@ -67,7 +67,8 @@ public: { if (!IsValid()) return ""; - return ConvToStr(this->iterations) + ":" + Base64::Encode(this->hash) + ":" + Base64::Encode(this->salt); + + return INSP_FORMAT("{}:{}:{}", this->iterations, Base64::Encode(this->hash), Base64::Encode(this->salt)); } bool IsValid() const diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index 5c6713c73..413ac46fc 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -74,7 +74,7 @@ static bool WriteDatabase(PermChannel& permchanmode, bool save_listmodes, unsign if (permchannelsconf.empty()) return true; - const std::string permchannelsnewconf = permchannelsconf + ".new." + ConvToStr(ServerInstance->Time()); + const auto permchannelsnewconf = INSP_FORMAT("{}.new.{}", permchannelsconf, ServerInstance->Time()); std::ofstream stream(permchannelsnewconf); if (!stream.is_open()) { diff --git a/src/modules/m_setidle.cpp b/src/modules/m_setidle.cpp index e704f345d..eab34d76c 100644 --- a/src/modules/m_setidle.cpp +++ b/src/modules/m_setidle.cpp @@ -61,7 +61,7 @@ public: if (user->signon > user->idle_lastmsg) user->signon = user->idle_lastmsg; - ServerInstance->SNO.WriteToSnoMask('a', user->nick+" used SETIDLE to set their idle time to "+ConvToStr(idle)+" seconds"); + ServerInstance->SNO.WriteToSnoMask('a', "{} used SETIDLE to set their idle time to {} seconds", user->nick, idle); noterpl.SendIfCap(user, stdrplcap, this, "IDLE_TIME_SET", user->idle_lastmsg, "Idle time set."); return CmdResult::SUCCESS; } diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 85b41f56c..43aaa5e1a 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -330,7 +330,7 @@ void TreeSocket::SendCapabilities(int phase) return; if (capab->capab_phase < 1 && phase >= 1) - WriteLine("CAPAB START " + ConvToStr(PROTO_NEWEST)); + WriteLine(INSP_FORMAT("CAPAB START {}", (uint16_t)PROTO_NEWEST)); capab->capab_phase = phase; if (phase < 2) diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index 12dbe931a..1dda7b9f8 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -100,7 +100,10 @@ static std::vector GetMap(User* user, TreeServer* current, size_t m if (user->IsOper()) { time_t secs_up = ServerInstance->Time() - current->age; - buffer += " [Up: " + Duration::ToString(secs_up) + (current->rtt == 0 ? "]" : " Lag: " + ConvToStr(current->rtt) + "ms]"); + buffer += INSP_FORMAT(" [Up: {}", Duration::ToString(secs_up)); + if (current->rtt) + buffer += INSP_FORMAT(" Lag: {}ms", current->rtt); + buffer += "]"; } std::vector map; diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index eae8cbe21..3d454eef9 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -161,11 +161,11 @@ void TreeSocket::ProcessLine(std::string& line) if (!params.empty()) { time_t them = ServerCommand::ExtractTS(params[0]); - time_t delta = them - ServerInstance->Time(); - if ((delta < -15) || (delta > 15)) + time_t delta = std::abs(them - ServerInstance->Time()); + if (delta > 15) { - ServerInstance->SNO.WriteGlobalSno('l', "\002ERROR\002: Your clocks are off by {} seconds (this is more than fifteen seconds). Link aborted, \002PLEASE SYNC YOUR CLOCKS!\002", labs((long)delta)); - SendError("Your clocks are out by "+ConvToStr(labs((long)delta))+" seconds (this is more than fifteen seconds). Link aborted, PLEASE SYNC YOUR CLOCKS!"); + ServerInstance->SNO.WriteGlobalSno('l', "\002ERROR\002: Your clocks are off by {} seconds (this is more than fifteen seconds). Link aborted, \002PLEASE SYNC YOUR CLOCKS!\002", delta); + SendError(INSP_FORMAT("Your clocks are out by {} seconds (this is more than fifteen seconds). Link aborted, PLEASE SYNC YOUR CLOCKS!", delta)); return; } else if ((delta < -5) || (delta > 5)) diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index e149db881..9a10450f9 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -301,7 +301,7 @@ void SpanningTreeUtilities::ReadConfiguration() throw ModuleException((Module*)Creator, "The link name '"+L->Name+"' is invalid as it must contain at least one '.' character"); if (L->Name.length() > ServerInstance->Config->Limits.MaxHost) - throw ModuleException((Module*)Creator, "The link name '"+L->Name+"' is invalid as it is longer than " + ConvToStr(ServerInstance->Config->Limits.MaxHost) + " characters"); + throw ModuleException((Module*)Creator, INSP_FORMAT("The link name '{}' is invalid as it is longer than {} characters", L->Name, ServerInstance->Config->Limits.MaxHost)); if (L->RecvPass.empty()) throw ModuleException((Module*)Creator, "Invalid configuration for server '"+L->Name+"', recvpass not defined"); diff --git a/src/modules/m_xline_db.cpp b/src/modules/m_xline_db.cpp index 4ccdc8279..6ef2ad815 100644 --- a/src/modules/m_xline_db.cpp +++ b/src/modules/m_xline_db.cpp @@ -124,7 +124,7 @@ public: * -- w00t */ ServerInstance->Logs.Debug(MODNAME, "Opening temporary database"); - const std::string xlinenewdbpath = xlinedbpath + ".new." + ConvToStr(ServerInstance->Time()); + const auto xlinenewdbpath = INSP_FORMAT("{}.new.{}", xlinedbpath, ServerInstance->Time()); std::ofstream stream(xlinenewdbpath); if (!stream.is_open()) { diff --git a/src/snomasks.cpp b/src/snomasks.cpp index 1285975c0..572f39d04 100644 --- a/src/snomasks.cpp +++ b/src/snomasks.cpp @@ -100,7 +100,7 @@ void Snomask::Flush() if (Count > 1) { std::string desc = GetDescription(LastLetter); - std::string msg = "(last message repeated " + ConvToStr(Count) + " times)"; + std::string msg = INSP_FORMAT("(last message repeated {} times)", Count); FOREACH_MOD(OnSendSnotice, (LastLetter, desc, msg)); Snomask::Send(LastLetter, desc, msg); diff --git a/src/socket.cpp b/src/socket.cpp index f8564b9d1..8419e1d6f 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -120,7 +120,7 @@ size_t InspIRCd::BindPorts(FailedPortList& failed_ports) // Check if the port is out of range. if (port <= std::numeric_limits::min() || port > std::numeric_limits::max()) { - failed_ports.emplace_back("Port is not valid: " + ConvToStr(port), bindspec, tag); + failed_ports.emplace_back(INSP_FORMAT("Port is not valid: {}", port), bindspec, tag); continue; } diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 2a9c6e0de..c6da619b8 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -65,7 +65,7 @@ namespace if (!user->lastping) { time_t secs = ServerInstance->Time() - (user->nextping - user->GetClass()->pingtime); - const std::string message = "Ping timeout: " + ConvToStr(secs) + (secs != 1 ? " seconds" : " second"); + const std::string message = INSP_FORMAT("Ping timeout: {} {}", secs, (secs != 1 ? "seconds" : "second")); ServerInstance->Users.QuitUser(user, message); return; } -- cgit v1.3.1-10-gc9f91