From d346d6783bc6938a634683102b288f88280138b4 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 3 Oct 2024 10:51:21 +0100 Subject: Add the Time::FromNow helper function. --- include/timeutils.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/timeutils.h b/include/timeutils.h index 59312e00d..c5c1fd2c1 100644 --- a/include/timeutils.h +++ b/include/timeutils.h @@ -63,11 +63,22 @@ namespace Time { /** Converts a UNIX timestamp to a time string. * - * e.g. * @param ts The timestamp to convert to a string. * @param format A snprintf format string to output the timestamp in. * @param utc If the timestamp is a UTC timestamp then true or false if the * timestamp is a local timestamp. */ CoreExport std::string ToString(time_t ts, const char* format = nullptr, bool utc = false); + + /** Converts a duration from now to a time string. + * + * @param duration The duration from now to convert to a string. + * @param format A snprintf format string to output the timestamp in. + * @param utc If the timestamp is a UTC timestamp then true or false if the + * timestamp is a local timestamp. + */ + inline std::string FromNow(unsigned long duration, const char* format = nullptr, bool utc = false) + { + return ToString(ServerInstance->Time() + duration, format, utc); + } } -- cgit v1.3.1-10-gc9f91 From 5eb21f239bf89b0615612cb7b7b8fa5f1e13fb73 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 10 Oct 2024 14:47:24 +0100 Subject: When a server stops being ulined remove its users from the uline list. --- include/usermanager.h | 3 +++ src/configreader.cpp | 1 + src/usermanager.cpp | 13 +++++++++++++ 3 files changed, 17 insertions(+) (limited to 'include') diff --git a/include/usermanager.h b/include/usermanager.h index bf9567d43..681c5e059 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -141,6 +141,9 @@ class CoreExport UserManager : public fakederef */ void RehashCloneCounts(); + /** Rebuilds the list of services servers. Required when \ settings change. */ + void RehashULines(); + /** Return the number of local and global clones of this user * @param user The user to get the clone counts for * @return The clone counts of this user. The returned reference is volatile - you diff --git a/src/configreader.cpp b/src/configreader.cpp index d1b55a113..f5f9f1ce8 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -733,6 +733,7 @@ void ConfigReaderThread::Finish() ServerInstance->FakeClient->server->description = Config->ServerDesc; ServerInstance->ISupport.Build(); + ServerInstance->Users.RehashULines(); ServerInstance->Logs->CloseLogs(); ServerInstance->Logs->OpenFileLogs(); diff --git a/src/usermanager.cpp b/src/usermanager.cpp index d410131f4..c20609a2c 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -353,6 +353,19 @@ void UserManager::RehashCloneCounts() } } +void UserManager::RehashULines() +{ + UserManager::ULineList newulines; + const user_hash& users = ServerInstance->Users.GetUsers(); + for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i) + { + User* user = i->second; + if (user->server->IsULine()) + newulines.push_back(user); + } + std::swap(ServerInstance->Users.all_ulines, newulines); +} + const UserManager::CloneCounts& UserManager::GetCloneCounts(User* user) const { CloneMap::const_iterator it = clonemap.find(user->GetCIDRMask()); -- cgit v1.3.1-10-gc9f91 From b21ec4e9a91b1f78b04c16ae195497f01dfe7e42 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 10 Oct 2024 15:08:31 +0100 Subject: Count services in the global user count. This behaviour was always kinda broken so lets just drop it. --- include/usermanager.h | 2 +- src/coremods/core_lusers.cpp | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/usermanager.h b/include/usermanager.h index 971f8935b..73da0e3fb 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -174,7 +174,7 @@ public: /** Return a count of fully connected connections on the network. * @return The number of fully connected users on the network. */ - size_t GlobalUserCount() const { return this->clientlist.size() - this->UnknownUserCount() - this->ServiceCount(); } + size_t GlobalUserCount() const { return this->clientlist.size() - this->UnknownUserCount(); } /** Get a hash map containing all users, keyed by their nickname * @return A hash map mapping nicknames to User pointers diff --git a/src/coremods/core_lusers.cpp b/src/coremods/core_lusers.cpp index e7ae03a6b..1d219d59b 100644 --- a/src/coremods/core_lusers.cpp +++ b/src/coremods/core_lusers.cpp @@ -50,7 +50,7 @@ struct LusersCounters final { for (const auto& [_, u] : ServerInstance->Users.GetUsers()) { - if (!u->server->IsService() && u->IsModeSet(invisiblemode)) + if (u->IsModeSet(invisiblemode)) invisible++; } } @@ -135,9 +135,6 @@ public: if (!dest->IsFullyConnected()) return; - if (dest->server->IsService()) - return; - if (change.adding) invisible++; else @@ -166,13 +163,13 @@ public: void OnPostConnect(User* user) override { counters.UpdateMaxUsers(); - if (!user->server->IsService() && user->IsModeSet(invisiblemode)) + if (user->IsModeSet(invisiblemode)) counters.invisible++; } void OnUserQuit(User* user, const std::string& message, const std::string& oper_message) override { - if (!user->server->IsService() && user->IsModeSet(invisiblemode)) + if (user->IsModeSet(invisiblemode)) counters.invisible--; } }; -- cgit v1.3.1-10-gc9f91 From a9a6411051e2c39ff17c3bf6e7b46c658505da4f Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 16 Oct 2024 11:39:59 +0100 Subject: Allow ConfigTag::getCharacter to return NUL for an empty field. --- include/configreader.h | 2 +- src/configparser.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/configreader.h b/include/configreader.h index c8fc97d06..d053d16d0 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -129,7 +129,7 @@ public: /** Get the value of an option, using def if it does not exist */ bool getBool(const std::string& key, bool def = false) const; /** Get the value of an option, using def if it does not exist */ - unsigned char getCharacter(const std::string& key, unsigned char def = '\0') const; + unsigned char getCharacter(const std::string& key, unsigned char def = '\0', bool emptynul = false) const; /** Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format, * using a default value if it does not exist or is out of bounds. diff --git a/src/configparser.cpp b/src/configparser.cpp index 8cdd1f7f5..457840b71 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -732,12 +732,15 @@ bool ConfigTag::getBool(const std::string& key, bool def) const return def; } -unsigned char ConfigTag::getCharacter(const std::string& key, unsigned char def) const +unsigned char ConfigTag::getCharacter(const std::string& key, unsigned char def, bool emptynul) const { std::string result; - if (!readString(key, result) || result.size() != 1) + if (!readString(key, result)) return def; + if (result.size() != 1) + return result.empty() && emptynul ? 0 : def; + return result[0]; } -- cgit v1.3.1-10-gc9f91 From fc9d49641f4308089abb3e61764895beb148fdff Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 16 Oct 2024 12:03:52 +0100 Subject: Add support for extbans without letters. --- include/modules/extban.h | 2 +- src/coremods/core_channel/extban.cpp | 29 ++++++++++++++++++++--------- src/modules/m_spanningtree/capab.cpp | 10 +++++----- 3 files changed, 26 insertions(+), 15 deletions(-) (limited to 'include') diff --git a/include/modules/extban.h b/include/modules/extban.h index 28f76552a..45b9ebe50 100644 --- a/include/modules/extban.h +++ b/include/modules/extban.h @@ -204,7 +204,7 @@ protected: */ Base(Module* mod, const std::string& xbname, ExtBan::Letter xbletter) : ServiceProvider(mod, xbname, SERVICE_CUSTOM) - , letter(ServerInstance->Config->ConfValue("extbans")->getCharacter(xbname, xbletter)) + , letter(ServerInstance->Config->ConfValue("extbans")->getCharacter(xbname, xbletter, true)) , manager(mod, "extbanmanager") { } diff --git a/src/coremods/core_channel/extban.cpp b/src/coremods/core_channel/extban.cpp index f3d0ba34f..57cac5835 100644 --- a/src/coremods/core_channel/extban.cpp +++ b/src/coremods/core_channel/extban.cpp @@ -22,15 +22,20 @@ void ExtBanManager::AddExtBan(ExtBan::Base* extban) { - auto lit = byletter.emplace(extban->GetLetter(), extban); - if (!lit.second) - throw ModuleException(creator, INSP_FORMAT("ExtBan letter \"{}\" is already in use by the {} extban from {}", - extban->GetLetter(), lit.first->second->GetName(), lit.first->second->creator->ModuleFile)); + if (extban->GetLetter()) + { + auto lit = byletter.emplace(extban->GetLetter(), extban); + if (!lit.second) + throw ModuleException(creator, INSP_FORMAT("ExtBan letter \"{}\" is already in use by the {} extban from {}", + extban->GetLetter(), lit.first->second->GetName(), lit.first->second->creator->ModuleFile)); + } auto nit = byname.emplace(extban->GetName(), extban); if (!nit.second) { - byletter.erase(extban->GetLetter()); + if (extban->GetLetter()) + byletter.erase(extban->GetLetter()); + throw ModuleException(creator, INSP_FORMAT("ExtBan name \"{}\" is already in use by the {} extban from {}", extban->GetName(), nit.first->second->GetLetter(), nit.first->second->creator->ModuleFile)); } @@ -63,7 +68,10 @@ bool ExtBanManager::Canonicalize(std::string& text) const break; case ExtBan::Format::LETTER: - text.append(1, extban->GetLetter()); + if (extban->GetLetter()) + text.push_back(extban->GetLetter()); + else + text.append(extban->GetName()); // ExtBan has no letter. break; default: @@ -153,9 +161,12 @@ ModResult ExtBanManager::GetStatus(ExtBan::ActingBase* extban, User* user, Chann void ExtBanManager::DelExtBan(ExtBan::Base* extban) { - auto lit = byletter.find(extban->GetLetter()); - if (lit != byletter.end() && lit->second->creator.ptr() == extban->creator.ptr()) - byletter.erase(lit); + if (extban->GetLetter()) + { + auto lit = byletter.find(extban->GetLetter()); + if (lit != byletter.end() && lit->second->creator.ptr() == extban->creator.ptr()) + byletter.erase(lit); + } auto nit = byname.find(extban->GetName()); if (nit != byname.end() && nit->second->creator.ptr() == extban->creator.ptr()) diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 363da853b..85b41f56c 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -300,8 +300,8 @@ bool TreeSocket::BuildExtBanList(std::string& out) if (!extbanmgr) return false; - const ExtBan::Manager::LetterMap& extbans = extbanmgr->GetLetterMap(); - for (ExtBan::Manager::LetterMap::const_iterator iter = extbans.begin(); iter != extbans.end(); ++iter) + const auto& extbans = extbanmgr->GetNameMap(); + for (auto iter = extbans.begin(); iter != extbans.end(); ++iter) { if (iter != extbans.begin()) out.push_back(' '); @@ -317,9 +317,9 @@ bool TreeSocket::BuildExtBanList(std::string& out) break; } - out.append(extban->GetName()) - .append("=") - .push_back(extban->GetLetter()); + out.append(extban->GetName()); + if (extban->GetLetter()) + out.append("=").push_back(extban->GetLetter()); } return true; } -- cgit v1.3.1-10-gc9f91 From 414a08644944e73338a65f8d877bfbb94c72ceb6 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 26 Oct 2024 15:26:59 +0100 Subject: All core numerics should be in numeric.h not in .cpp files. --- include/numeric.h | 9 +++++++++ src/commands.cpp | 10 ---------- src/listmode.cpp | 7 ------- src/users.cpp | 9 --------- 4 files changed, 9 insertions(+), 26 deletions(-) (limited to 'include') diff --git a/include/numeric.h b/include/numeric.h index 558f71171..fad86e316 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -39,8 +39,11 @@ enum ERR_UNKNOWNCOMMAND = 421, ERR_NONICKNAMEGIVEN = 431, ERR_ERRONEUSNICKNAME = 432, + ERR_NICKNAMEINUSE = 433, ERR_USERNOTINCHANNEL = 441, ERR_NOTONCHANNEL = 442, + ERR_NOTREGISTERED = 451, + ERR_NEEDMOREPARAMS = 461, ERR_YOUREBANNEDCREEP = 465, ERR_UNKNOWNMODE = 472, ERR_BANNEDFROMCHAN = 474, @@ -58,11 +61,17 @@ enum // From irc2? RPL_SAVENICK = 43, + // From ircu. + RPL_YOURDISPLAYEDHOST = 396, + // From UnrealIRCd. ERR_CANTCHANGENICK = 447, // InspIRCd-specific. ERR_UNKNOWNSNOMASK = 501, + RPL_SYNTAX = 650, + ERR_LISTMODEALREADYSET = 697, + ERR_LISTMODENOTSET = 698, ERR_CANTUNLOADMODULE = 972, RPL_UNLOADEDMODULE = 973, ERR_CANTLOADMODULE = 974, diff --git a/src/commands.cpp b/src/commands.cpp index b2a5b2317..43c1bcb96 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -26,16 +26,6 @@ #include "inspircd.h" -enum -{ - // From RFC 1459. - ERR_NOTREGISTERED = 451, - ERR_NEEDMOREPARAMS = 461, - - // InspIRCd-specific. - RPL_SYNTAX = 650, -}; - bool CommandParser::LoopCall(User* user, Command* handler, const CommandBase::Params& parameters, unsigned int splithere, int extra, bool usemax) { if (splithere >= parameters.size()) diff --git a/src/listmode.cpp b/src/listmode.cpp index ee581ae40..5aa58b2e5 100644 --- a/src/listmode.cpp +++ b/src/listmode.cpp @@ -23,13 +23,6 @@ #include "inspircd.h" #include "listmode.h" -enum -{ - // InspIRCd-specific. - ERR_LISTMODEALREADYSET = 697, - ERR_LISTMODENOTSET = 698, -}; - ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, unsigned int lnum, unsigned int eolnum) : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_LIST) , listnumeric(lnum) diff --git a/src/users.cpp b/src/users.cpp index d76f7f8d0..7db26cfb5 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -33,15 +33,6 @@ #include "utility/string.h" #include "xline.h" -enum -{ - // From RFC 1459. - ERR_NICKNAMEINUSE = 433, - - // From ircu. - RPL_YOURDISPLAYEDHOST = 396, -}; - ClientProtocol::MessageList LocalUser::sendmsglist; bool User::IsNoticeMaskSet(unsigned char sm) const -- cgit v1.3.1-10-gc9f91 From 11917e4c4af3bf15cd0e7d1cdb5659b084942b74 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 27 Oct 2024 14:41:27 +0000 Subject: Use fmtlib instead of iostream in ConvToStr where available. --- include/convto.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/convto.h b/include/convto.h index 15e0788a6..5c0444e47 100644 --- a/include/convto.h +++ b/include/convto.h @@ -77,11 +77,20 @@ inline std::enable_if_t, std::string> ConvToStr return std::to_string(in); } +/** Converts a type that fmtlib can format to a string. + * @param in The value to convert. + */ +template +inline std::enable_if_t && fmt::is_formattable::value, std::string> ConvToStr(const Formattable& in) +{ + return INSP_FORMAT("{}", in); +} + /** Converts any type to a string. * @param in The value to convert. */ template -inline std::enable_if_t, std::string> ConvToStr(const T& in) +inline std::enable_if_t && !fmt::is_formattable::value, std::string> ConvToStr(const T& in) { std::stringstream tmp; if (!(tmp << in)) -- cgit v1.3.1-10-gc9f91