summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-26 22:59:03 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-26 22:59:03 +0100
commitb92c3f2e1c6a4d6ed87ed596f97d268fc4c53785 (patch)
tree32079432854736c6cd4c2285b8774ff4703dc83e /src/utils
parentfeb848940855a8001a65252ee727887be8e2cf35 (diff)
downloadmanaserv-b92c3f2e1c6a4d6ed87ed596f97d268fc4c53785.tar.gz
manaserv-b92c3f2e1c6a4d6ed87ed596f97d268fc4c53785.tar.xz
manaserv-b92c3f2e1c6a4d6ed87ed596f97d268fc4c53785.zip
Add an heartbeat time flag in the statistics file.
This way, any kind of external service can know about the running state of each servers, even if only the account server is updating the statistics because: 1. When the account server is running, each <gameserver> tag is a running game server. Otherwise, it's not listed. 2. Whenever the account server stops running, the stat file isn't updated anymore and so the <heartbeat> tag isn't. 3. Game servers without any contact with an account server will try to reconnect to the account server and kick out every players so they aren't considered as running in that case. Reviewed-by: Crush. Resolves: Mana-mantis #270.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/logger.cpp57
-rw-r--r--src/utils/time.h86
2 files changed, 87 insertions, 56 deletions
diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp
index 0504195..d3f8241 100644
--- a/src/utils/logger.cpp
+++ b/src/utils/logger.cpp
@@ -22,10 +22,9 @@
#include "logger.h"
#include "common/resourcemanager.h"
#include "utils/string.h"
+#include "utils/time.h"
-#include <ctime>
#include <fstream>
-#include <iomanip>
#include <iostream>
#ifdef WIN32
@@ -60,60 +59,6 @@ static std::string mLastCallDate = "";
static std::string mOldDate = "";
/**
- * Gets the current time.
- *
- * @return the current time as string.
- */
-static std::string getCurrentTime()
-{
- time_t now;
- tm local;
-
- // Get current time_t value
- time(&now);
-
- // Convert time_t to tm struct to break the time into individual
- // constituents.
- local = *(localtime(&now));
-
- // Stringify the time, the format is: hh:mm:ss
- using namespace std;
- ostringstream os;
- os << setw(2) << setfill('0') << local.tm_hour
- << ":" << setw(2) << setfill('0') << local.tm_min
- << ":" << setw(2) << setfill('0') << local.tm_sec;
-
- return os.str();
-}
-
-/**
- * Gets the current date.
- *
- * @return the current date as string.
- */
-static std::string getCurrentDate()
-{
- time_t now;
- tm local;
-
- // Get current time_t value
- time(&now);
-
- // Convert time_t to tm struct to break the time into individual
- // constituents.
- local = *(localtime(&now));
-
- // Stringify the time, the format is: yyyy-mm-dd
- using namespace std;
- ostringstream os;
- os << setw(4) << setfill('0') << (local.tm_year + 1900)
- << "-" << setw(2) << setfill('0') << local.tm_mon
- << "-" << setw(2) << setfill('0') << local.tm_mday;
-
- return os.str();
-}
-
-/**
* Check whether the day has changed since the last call.
*
* @return whether the day has changed.
diff --git a/src/utils/time.h b/src/utils/time.h
new file mode 100644
index 0000000..e22e52e
--- /dev/null
+++ b/src/utils/time.h
@@ -0,0 +1,86 @@
+/*
+ * The Mana Server
+ * Copyright (C) 2011 The Mana Development Team
+ *
+ * This file is part of The Mana Server.
+ *
+ * The Mana Server 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; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana Server 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 The Mana Server. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TIME_H
+#define TIME_H
+
+#include <ctime>
+#include <iomanip>
+#include <string>
+
+namespace utils {
+
+/**
+ * Gets the current time.
+ *
+ * @return the current time as string.
+ */
+static std::string getCurrentTime()
+{
+ time_t now;
+ tm local;
+
+ // Get current time_t value
+ time(&now);
+
+ // Convert time_t to tm struct to break the time into individual
+ // constituents.
+ local = *(localtime(&now));
+
+ // Stringify the time, the format is: hh:mm:ss
+ using namespace std;
+ ostringstream os;
+ os << setw(2) << setfill('0') << local.tm_hour
+ << ":" << setw(2) << setfill('0') << local.tm_min
+ << ":" << setw(2) << setfill('0') << local.tm_sec;
+
+ return os.str();
+}
+
+/**
+ * Gets the current date.
+ *
+ * @return the current date as string.
+ */
+static std::string getCurrentDate()
+{
+ time_t now;
+ tm local;
+
+ // Get current time_t value
+ time(&now);
+
+ // Convert time_t to tm struct to break the time into individual
+ // constituents.
+ local = *(localtime(&now));
+
+ // Stringify the time, the format is: yyyy-mm-dd
+ using namespace std;
+ ostringstream os;
+ os << setw(4) << setfill('0') << (local.tm_year + 1900)
+ << "-" << setw(2) << setfill('0') << local.tm_mon + 1
+ << "-" << setw(2) << setfill('0') << local.tm_mday;
+
+ return os.str();
+}
+
+};
+
+#endif // TIME_H