]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Add <hidechans:affectsopers>, allows networks to hide channels of a +I user even...
[user/henk/code/inspircd.git] / src / configreader.cpp
index 1e8e0a7e9d22ac4aa2d084d9dcda263fa5f2e76f..46ae6ac4ed22db9f86c67db6a4759fe9ef12dc0c 100644 (file)
@@ -21,6 +21,8 @@
 /* $CopyInstall: conf/inspircd.filter.example $(CONPATH) */
 /* $CopyInstall: conf/inspircd.conf.example $(CONPATH) */
 /* $CopyInstall: conf/modules.conf.example $(CONPATH) */
+/* $CopyInstall: conf/opers.conf.example $(CONPATH) */
+/* $CopyInstall: conf/links.conf.example $(CONPATH) */
 
 #include "inspircd.h"
 #include <fstream>
@@ -65,37 +67,6 @@ void ServerConfig::ClearStack()
        include_stack.clear();
 }
 
-Module* ServerConfig::GetIOHook(BufferedSocket* is)
-{
-       std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
-       return (x != SocketIOHookModule.end() ? x->second : NULL);
-}
-
-bool ServerConfig::AddIOHook(Module* iomod, BufferedSocket* is)
-{
-       if (!GetIOHook(is))
-       {
-               SocketIOHookModule[is] = iomod;
-               is->IsIOHooked = true;
-               return true;
-       }
-       else
-       {
-               throw ModuleException("BufferedSocket derived class already hooked by another module");
-       }
-}
-
-bool ServerConfig::DelIOHook(BufferedSocket* is)
-{
-       std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
-       if (x != SocketIOHookModule.end())
-       {
-               SocketIOHookModule.erase(x);
-               return true;
-       }
-       return false;
-}
-
 void ServerConfig::Update005()
 {
        std::stringstream out(data005);
@@ -393,10 +364,10 @@ bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data)
        return true;
 }
 
-bool ValidateNotEmpty(ServerConfig*, const char* tag, const char*, ValueItem &data)
+bool ValidateNotEmpty(ServerConfig*, const char* tag, const char* val, ValueItem &data)
 {
        if (!*data.GetString())
-               throw CoreException(std::string("The value for ")+tag+" cannot be empty!");
+               throw CoreException(std::string("The value for <")+tag+":"+val+"> cannot be empty!");
        return true;
 }
 
@@ -732,7 +703,7 @@ bool DoneMaxBans(ServerConfig*, const char*)
        return true;
 }
 
-void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, User* user)
+void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, const std::string &useruid)
 {
        ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file: %s", errormessage.c_str());
        if (bail)
@@ -748,14 +719,18 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail,
                unsigned int prefixlen;
                start = 0;
                /* ":ServerInstance->Config->ServerName NOTICE user->nick :" */
-               if (user)
+               if (!useruid.empty())
                {
-                       prefixlen = strlen(this->ServerName) + user->nick.length() + 11;
-                       user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str());
-                       while (start < errors.length())
+                       User* user = ServerInstance->FindNick(useruid);
+                       if (user)
                        {
-                               user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str());
-                               start += 510 - prefixlen;
+                               prefixlen = strlen(this->ServerName) + user->nick.length() + 11;
+                               user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str());
+                               while (start < errors.length())
+                               {
+                                       user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str());
+                                       start += 510 - prefixlen;
+                               }
                        }
                }
                else
@@ -771,7 +746,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail,
        }
 }
 
-void ServerConfig::Read(bool bail, User* user)
+void ServerConfig::Read(bool bail, const std::string &useruid)
 {
        int rem = 0, add = 0;      /* Number of modules added, number of modules removed */
 
@@ -973,7 +948,7 @@ void ServerConfig::Read(bool bail, User* user)
 
        if (!this->DoInclude(newconfig, ServerInstance->ConfigFileName, errstr))
        {
-               ReportConfigError(errstr.str(), bail, user);
+               ReportConfigError(errstr.str(), bail, useruid);
                return;
        }
 
@@ -1205,7 +1180,7 @@ void ServerConfig::Read(bool bail, User* user)
 
        catch (CoreException &ce)
        {
-               ReportConfigError(ce.GetReason(), bail, user);
+               ReportConfigError(ce.GetReason(), bail, useruid);
                return;
        }
 
@@ -1232,8 +1207,12 @@ void ServerConfig::Read(bool bail, User* user)
                        }
                        if (!foundclass)
                        {
-                               if (user)
-                                       user->WriteServ("NOTICE %s :*** Warning: Oper type '%s' has a missing class named '%s', this does nothing!", user->nick.c_str(), item, classname.c_str());
+                               if (!useruid.empty())
+                               {
+                                       User* user = ServerInstance->FindNick(useruid);
+                                       if (user)
+                                               user->WriteServ("NOTICE %s :*** Warning: Oper type '%s' has a missing class named '%s', this does nothing!", user->nick.c_str(), item, classname.c_str());
+                               }
                                else
                                {
                                        if (bail)
@@ -1267,15 +1246,19 @@ void ServerConfig::Read(bool bail, User* user)
                FailedPortList pl;
                ServerInstance->BindPorts(false, found_ports, pl);
 
-               if (pl.size() && user)
+               if (pl.size() && !useruid.empty())
                {
                        ServerInstance->Threads->Lock();
-                       user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str());
-                       user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str());
-                       int j = 1;
-                       for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
+                       User* user = ServerInstance->FindNick(useruid);
+                       if (user)
                        {
-                               user->WriteServ("NOTICE %s :*** %d.   Address: %s        Reason: %s", user->nick.c_str(), j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
+                               user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str());
+                               user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str());
+                               int j = 1;
+                               for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
+                               {
+                                       user->WriteServ("NOTICE %s :*** %d.   Address: %s        Reason: %s", user->nick.c_str(), j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
+                               }
                        }
                        ServerInstance->Threads->Unlock();
                }
@@ -1289,15 +1272,27 @@ void ServerConfig::Read(bool bail, User* user)
                                {
                                        ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
 
-                                       if (user)
-                                               user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
+                                       if (!useruid.empty())
+                                       {
+                                               User* user = ServerInstance->FindNick(useruid);
+                                               if (user)
+                                                       user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
+                                       }
+                                       else
+                                               ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully unloaded.", removing->c_str());
 
                                        rem++;
                                }
                                else
                                {
-                                       if (user)
-                                               user->WriteNumeric(ERR_CANTUNLOADMODULE, "%s %s :Failed to unload module %s: %s",user->nick.c_str(), removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str());
+                                       if (!useruid.empty())
+                                       {
+                                               User* user = ServerInstance->FindNick(useruid);
+                                               if (user)
+                                                       user->WriteNumeric(ERR_CANTUNLOADMODULE, "%s %s :Failed to unload module %s: %s",user->nick.c_str(), removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str());
+                                       }
+                                       else
+                                                ServerInstance->SNO->WriteToSnoMask('A', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
                                }
                        }
                }
@@ -1309,16 +1304,27 @@ void ServerConfig::Read(bool bail, User* user)
                                if (ServerInstance->Modules->Load(adding->c_str()))
                                {
                                        ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH LOADED MODULE: %s",adding->c_str());
-
-                                       if (user)
-                                               user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
+                                       if (!useruid.empty())
+                                       {
+                                               User* user = ServerInstance->FindNick(useruid);
+                                               if (user)
+                                                       user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
+                                       }
+                                       else
+                                               ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully loaded.", adding->c_str());
 
                                        add++;
                                }
                                else
                                {
-                                       if (user)
-                                               user->WriteNumeric(ERR_CANTLOADMODULE, "%s %s :Failed to load module %s: %s",user->nick.c_str(), adding->c_str(), adding->c_str(), ServerInstance->Modules->LastError().c_str());
+                                       if (!useruid.empty())
+                                       {
+                                               User* user = ServerInstance->FindNick(useruid);
+                                               if (user)
+                                                       user->WriteNumeric(ERR_CANTLOADMODULE, "%s %s :Failed to load module %s: %s",user->nick.c_str(), adding->c_str(), adding->c_str(), ServerInstance->Modules->LastError().c_str());
+                                       }
+                                       else
+                                               ServerInstance->SNO->WriteToSnoMask('A', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
                                }
                        }
                }
@@ -1333,13 +1339,20 @@ void ServerConfig::Read(bool bail, User* user)
        {
                /** Note: This is safe, the method checks for user == NULL */
                ServerInstance->Threads->Lock();
+               User* user = NULL;
+               if (!useruid.empty())
+                       user = ServerInstance->FindNick(useruid);
                ServerInstance->Parser->SetupCommandTable(user);
                ServerInstance->Threads->Unlock();
        }
        else
        {
-               if (user)
-                       user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str());
+               if (!useruid.empty())
+               {
+                       User* user = ServerInstance->FindNick(useruid);
+                       if (user)
+                               user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str());
+               }
                else
                        ServerInstance->SNO->WriteToSnoMask('A', "*** Successfully rehashed server.");
        }
@@ -2361,8 +2374,7 @@ bool DoneELine(ServerConfig* conf, const char* tag)
 
 void ConfigReaderThread::Run()
 {
-       /* TODO: TheUser may be invalid by the time we get here! Check its validity, or pass a UID would be better */
-       ServerInstance->Config->Read(do_bail, TheUser);
+       ServerInstance->Config->Read(do_bail, TheUserUID);
        ServerInstance->Threads->Lock();
        this->SetExitFlag();
        ServerInstance->Threads->Unlock();