summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp65
1 files changed, 26 insertions, 39 deletions
diff --git a/src/main.cpp b/src/main.cpp
index bbcccee27..b171c9794 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,12 +1,20 @@
-/* Services -- main source file.
+/*
+ * 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"
@@ -15,6 +23,8 @@
#include "bots.h"
#include "socketengine.h"
#include "uplink.h"
+#include "event.h"
+#include "modules.h"
#ifndef _WIN32
#include <limits.h>
@@ -33,6 +43,7 @@ sig_atomic_t Anope::Signal = 0;
bool Anope::Quitting = false;
bool Anope::Restarting = false;
Anope::string Anope::QuitReason;
+Logger Anope::Logger;
static Anope::string BinaryDir; /* Full path to services bin directory */
@@ -41,37 +52,17 @@ time_t Anope::CurTime = time(NULL);
int Anope::CurrentUplink = -1;
-class UpdateTimer : public Timer
-{
- public:
- UpdateTimer(time_t timeout) : Timer(timeout, Anope::CurTime, true) { }
-
- void Tick(time_t) anope_override
- {
- Anope::SaveDatabases();
- }
-};
-
class ExpireTimer : public Timer
{
public:
ExpireTimer(time_t timeout) : Timer(timeout, Anope::CurTime, true) { }
- void Tick(time_t) anope_override
+ void Tick(time_t) override
{
- FOREACH_MOD(OnExpireTick, ());
+ EventManager::Get()->Dispatch(&Event::ExpireTick::OnExpireTick);
}
};
-void Anope::SaveDatabases()
-{
- if (Anope::ReadOnly)
- return;
-
- Log(LOG_DEBUG) << "Saving databases";
- FOREACH_MOD(OnSaveDatabase, ());
-}
-
/** The following comes from InspIRCd to get the full path of the Anope executable
*/
static Anope::string GetFullProgDir(const Anope::string &argv0)
@@ -113,9 +104,6 @@ static Anope::string GetFullProgDir(const Anope::string &argv0)
int main(int ac, char **av, char **envp)
{
- /* String comparisons won't work until we build the case map cache, so do it first */
- Anope::CaseMapRebuild();
-
BinaryDir = GetFullProgDir(av[0]);
if (BinaryDir[BinaryDir.length() - 1] == '.')
BinaryDir = BinaryDir.substr(0, BinaryDir.length() - 2);
@@ -141,7 +129,7 @@ int main(int ac, char **av, char **envp)
}
catch (const CoreException &ex)
{
- Log() << ex.GetReason();
+ Anope::Logger.Log(ex.GetReason());
return -1;
}
@@ -151,18 +139,17 @@ int main(int ac, char **av, char **envp)
}
catch (const SocketException &ex)
{
- Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port << "): " << ex.GetReason();
+ Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, ex.GetReason());
}
/* Set up timers */
time_t last_check = Anope::CurTime;
- UpdateTimer updateTimer(Config->GetBlock("options")->Get<time_t>("updatetimeout", "5m"));
ExpireTimer expireTimer(Config->GetBlock("options")->Get<time_t>("expiretimeout", "30m"));
/*** Main loop. ***/
while (!Anope::Quitting)
{
- Log(LOG_DEBUG_2) << "Top of main loop";
+ Anope::Logger.Debug2("Top of main loop");
/* Process timers */
if (Anope::CurTime - last_check >= Config->TimeoutCheck)
@@ -180,16 +167,16 @@ int main(int ac, char **av, char **envp)
if (Anope::Restarting)
{
- FOREACH_MOD(OnRestart, ());
+ EventManager::Get()->Dispatch(&Event::Restart::OnRestart);
}
else
{
- FOREACH_MOD(OnShutdown, ());
+ EventManager::Get()->Dispatch(&Event::Shutdown::OnShutdown);
}
if (Anope::QuitReason.empty())
Anope::QuitReason = "Terminating, reason unknown";
- Log() << Anope::QuitReason;
+ Anope::Logger.Log(Anope::QuitReason);
delete UplinkSock;
@@ -210,7 +197,7 @@ int main(int ac, char **av, char **envp)
Anope::string sbin = "./" + Anope::ServicesBin;
av[0] = const_cast<char *>(sbin.c_str());
execve(Anope::ServicesBin.c_str(), av, envp);
- Log() << "Restart failed";
+ Anope::Logger.Log("Restart failed");
Anope::ReturnValue = -1;
}