summaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp94
1 files changed, 60 insertions, 34 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 7e5722603..ec23a7b4b 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1,12 +1,20 @@
-/* Initialization and related routines.
+/*
+ * Anope IRC Services
*
- * (C) 2003-2016 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2003-2016 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
#include "services.h"
@@ -18,6 +26,8 @@
#include "socketengine.h"
#include "servers.h"
#include "language.h"
+#include "event.h"
+#include "modules.h"
#ifndef _WIN32
#include <sys/wait.h>
@@ -105,7 +115,7 @@ void Anope::Fork()
{
#ifndef _WIN32
kill(getppid(), SIGUSR2);
-
+
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
@@ -207,14 +217,14 @@ static void InitSignals()
static void remove_pidfile()
{
- remove(Config->GetBlock("serverinfo")->Get<const Anope::string>("pid").c_str());
+ remove(Config->GetBlock("serverinfo")->Get<Anope::string>("pid").c_str());
}
/* Create our PID file and write the PID to it. */
static void write_pidfile()
{
- FILE *pidfile = fopen(Config->GetBlock("serverinfo")->Get<const Anope::string>("pid").c_str(), "w");
+ FILE *pidfile = fopen(Config->GetBlock("serverinfo")->Get<Anope::string>("pid").c_str(), "w");
if (pidfile)
{
#ifdef _WIN32
@@ -226,7 +236,7 @@ static void write_pidfile()
atexit(remove_pidfile);
}
else
- throw CoreException("Can not write to PID file " + Config->GetBlock("serverinfo")->Get<const Anope::string>("pid"));
+ throw CoreException("Can not write to PID file " + Config->GetBlock("serverinfo")->Get<Anope::string>("pid"));
}
static void setuidgid()
@@ -236,21 +246,21 @@ static void setuidgid()
uid_t uid = -1;
gid_t gid = -1;
- if (!options->Get<const Anope::string>("user").empty())
+ if (!options->Get<Anope::string>("user").empty())
{
errno = 0;
- struct passwd *u = getpwnam(options->Get<const Anope::string>("user").c_str());
+ struct passwd *u = getpwnam(options->Get<Anope::string>("user").c_str());
if (u == NULL)
- Log() << "Unable to setuid to " << options->Get<const Anope::string>("user") << ": " << Anope::LastError();
+ Log() << "Unable to setuid to " << options->Get<Anope::string>("user") << ": " << Anope::LastError();
else
uid = u->pw_uid;
}
- if (!options->Get<const Anope::string>("group").empty())
+ if (!options->Get<Anope::string>("group").empty())
{
errno = 0;
- struct group *g = getgrnam(options->Get<const Anope::string>("group").c_str());
+ struct group *g = getgrnam(options->Get<Anope::string>("group").c_str());
if (g == NULL)
- Log() << "Unable to setgid to " << options->Get<const Anope::string>("group") << ": " << Anope::LastError();
+ Log() << "Unable to setgid to " << options->Get<Anope::string>("group") << ": " << Anope::LastError();
else
gid = g->gr_gid;
}
@@ -270,16 +280,16 @@ static void setuidgid()
if (static_cast<int>(gid) != -1)
{
if (setgid(gid) == -1)
- Log() << "Unable to setgid to " << options->Get<const Anope::string>("group") << ": " << Anope::LastError();
+ Log() << "Unable to setgid to " << options->Get<Anope::string>("group") << ": " << Anope::LastError();
else
- Log() << "Successfully set group to " << options->Get<const Anope::string>("group");
+ Log() << "Successfully set group to " << options->Get<Anope::string>("group");
}
if (static_cast<int>(uid) != -1)
{
if (setuid(uid) == -1)
- Log() << "Unable to setuid to " << options->Get<const Anope::string>("user") << ": " << Anope::LastError();
+ Log() << "Unable to setuid to " << options->Get<Anope::string>("user") << ": " << Anope::LastError();
else
- Log() << "Successfully set user to " << options->Get<const Anope::string>("user");
+ Log() << "Successfully set user to " << options->Get<Anope::string>("user");
}
#endif
}
@@ -291,8 +301,6 @@ void Anope::Init(int ac, char **av)
umask(DEFUMASK);
#endif
- Serialize::RegisterTypes();
-
/* Parse command line arguments */
ParseCommandLineArguments(ac, av);
@@ -423,7 +431,7 @@ void Anope::Init(int ac, char **av)
{
/* If we are configured to setuid later, don't issue a warning */
Configuration::Block *options = Config->GetBlock("options");
- if (options->Get<const Anope::string>("user").empty())
+ if (options->Get<Anope::string>("user").empty())
{
std::cerr << "WARNING: You are currently running Anope as the root superuser. Anope does not" << std::endl;
std::cerr << " require root privileges to run, and it is discouraged that you run Anope" << std::endl;
@@ -480,6 +488,13 @@ void Anope::Init(int ac, char **av)
/* Initialize the socket engine. Note that some engines can not survive a fork(), so this must be here. */
SocketEngine::Init();
+ ServiceManager::Init();
+ EventManager::Init();
+
+ new BotInfoType();
+ new XLineType(nullptr);
+ new OperBlockType();
+
/* Read configuration file; exit if there are problems. */
try
{
@@ -488,7 +503,7 @@ void Anope::Init(int ac, char **av)
catch (const ConfigException &ex)
{
Log(LOG_TERMINAL) << ex.GetReason();
- Log(LOG_TERMINAL) << "*** Support resources: Read through the services.conf self-contained";
+ Log(LOG_TERMINAL) << "*** Support resources: Read through the anope.conf self-contained";
Log(LOG_TERMINAL) << "*** documentation. Read the documentation files found in the 'docs'";
Log(LOG_TERMINAL) << "*** folder. Visit our portal located at http://www.anope.org/. Join";
Log(LOG_TERMINAL) << "*** our support channel on /server irc.anope.org channel #anope.";
@@ -497,10 +512,15 @@ void Anope::Init(int ac, char **av)
/* Create me */
Configuration::Block *block = Config->GetBlock("serverinfo");
- Me = new Server(NULL, block->Get<const Anope::string>("name"), 0, block->Get<const Anope::string>("description"), block->Get<const Anope::string>("id"));
- for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
+ Me = new Server(NULL, block->Get<Anope::string>("name"), 0, block->Get<Anope::string>("description"), block->Get<Anope::string>("id"));
+ for (std::pair<Anope::string, User *> p : UserListByNick)
{
- it->second->server = Me;
+ User *u = p.second;
+ if (u->type != UserType::BOT)
+ continue;
+
+ ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u);
+ bi->server = Me;
++Me->users;
}
@@ -516,10 +536,12 @@ void Anope::Init(int ac, char **av)
block = Config->GetBlock("options");
srand(block->Get<unsigned>("seed") ^ time(NULL));
+ ModeManager::Apply(nullptr);
+
/* load modules */
Log() << "Loading modules...";
for (int i = 0; i < Config->CountBlock("module"); ++i)
- ModuleManager::LoadModule(Config->GetBlock("module", i)->Get<const Anope::string>("name"), NULL);
+ ModuleManager::LoadModule(Config->GetBlock("module", i)->Get<Anope::string>("name"), NULL);
#ifndef _WIN32
/* We won't background later, so we should setuid now */
@@ -542,20 +564,24 @@ void Anope::Init(int ac, char **av)
Anope::string sid = IRCD->SID_Retrieve();
if (Me->GetSID() == Me->GetName())
Me->SetSID(sid);
- for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
- it->second->GenerateUID();
+ for (std::pair<Anope::string, User *> p : UserListByNick)
+ {
+ User *u = p.second;
+ if (u->type != UserType::BOT)
+ continue;
+
+ ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u);
+ bi->GenerateUID();
+ }
}
/* Load up databases */
Log() << "Loading databases...";
- EventReturn MOD_RESULT;
- FOREACH_RESULT(OnLoadDatabase, MOD_RESULT, ());
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::LoadDatabase::OnLoadDatabase);;
static_cast<void>(MOD_RESULT);
Log() << "Databases loaded";
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
it->second->Sync();
-
- Serialize::CheckTypes();
}