X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fconfigreader.cpp;h=782a80080aad8e9e83cc4e741ce557c30733ad01;hb=687778b72e31322a73b2e2e17af6bd0f2a2561bc;hp=5a0ceff06b9e0462e38a5ae2dfa72fa5a4cab486;hpb=4047a143fc1d16350db70c94b9ea77d79de05714;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/configreader.cpp b/src/configreader.cpp index 5a0ceff06..782a80080 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -74,19 +74,29 @@ ServerConfig::~ServerConfig() static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make) { + insp::flat_set configlines; + ConfigTagList tags = conf->ConfTags(tag); for(ConfigIter i = tags.first; i != tags.second; ++i) { ConfigTag* ctag = i->second; - std::string mask; - if (!ctag->readString(key, mask)) - throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation()); - std::string reason = ctag->getString("reason", ""); - XLine* xl = make->Generate(ServerInstance->Time(), 0, "", reason, mask); + + const std::string mask = ctag->getString(key); + if (mask.empty()) + throw CoreException("<" + tag + ":" + key + "> missing at " + ctag->getTagLocation()); + + const std::string reason = ctag->getString("reason"); + if (reason.empty()) + throw CoreException("<" + tag + ":reason> missing at " + ctag->getTagLocation()); + + XLine* xl = make->Generate(ServerInstance->Time(), 0, ServerInstance->Config->ServerName, reason, mask); xl->from_config = true; + configlines.insert(xl->Displayable()); if (!ServerInstance->XLines->AddLine(xl, NULL)) delete xl; } + + ServerInstance->XLines->ExpireRemovedConfigLines(make->GetType(), configlines); } typedef std::map LocalIndex; @@ -309,6 +319,23 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) } } +static std::string GetServerName() +{ +#ifndef _WIN32 + char hostname[256]; + if (gethostname(hostname, sizeof(hostname)) == 0) + { + std::string name(hostname); + if (name.find('.') == std::string::npos) + name.push_back('.'); + + if (name.length() <= ServerInstance->Config->Limits.MaxHost && InspIRCd::IsHost(name)) + return name; + } +#endif + return "irc.example.com"; +} + void ServerConfig::Fill() { ConfigTag* options = ConfValue("options"); @@ -316,7 +343,7 @@ void ServerConfig::Fill() ConfigTag* server = ConfValue("server"); if (sid.empty()) { - ServerName = server->getString("name", "irc.example.com", InspIRCd::IsHost); + ServerName = server->getString("name", GetServerName(), InspIRCd::IsHost); sid = server->getString("id"); if (!sid.empty() && !InspIRCd::IsSID(sid)) @@ -388,7 +415,6 @@ void ServerConfig::Fill() SocketEngine::Close(socktest); } - ServerInstance->XLines->ClearConfigLines(); ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z")); ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q")); ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));