summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/account-server/main-account.cpp15
-rw-r--r--src/utils/logger.cpp57
-rw-r--r--src/utils/time.h86
4 files changed, 101 insertions, 58 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cf04d397..0633ffda 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -183,6 +183,7 @@ SET(SRCS_MANASERVACCOUNT
utils/sha256.h
utils/sha256.cpp
utils/throwerror.h
+ utils/time.h
)
SET(SRCS_MANASERVGAME
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index ae24ee6d..25e96232 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -38,6 +38,7 @@
#include "utils/logger.h"
#include "utils/processorutils.h"
#include "utils/stringfilter.h"
+#include "utils/time.h"
#include "utils/timer.h"
#include "defines.h"
#include "manaserv_protocol.h"
@@ -245,10 +246,19 @@ static void deinitializeServer()
/**
* Dumps statistics.
*/
-static void dumpStatistics()
+static void dumpStatistics(std::string accountAddress, int accountClientPort,
+ int accountGamePort, int chatClientPort)
{
std::ofstream os(statisticsFile.c_str());
os << "<statistics>\n";
+ // Print last heartbeat
+ os << "<heartbeat=\"" << utils::getCurrentDate() << "_"
+ << utils::getCurrentTime() << "\" />\n";
+ // Add account server information
+ os << "<accountserver address=\"" << accountAddress << "\" clientport=\""
+ << accountClientPort << "\" gameport=\"" << accountGamePort
+ << "\" chatclientport=\"" << chatClientPort << "\" />\n";
+ // Add game servers information
GameServerHandler::dumpStatistics(os);
os << "</statistics>\n";
}
@@ -425,7 +435,8 @@ int main(int argc, char *argv[])
chatHandler->process(50);
if (statTimer.poll())
- dumpStatistics();
+ dumpStatistics(accountHost, options.port, accountGamePort,
+ chatClientPort);
if (banTimer.poll())
storage->checkBannedAccounts();
diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp
index 05041956..d3f82418 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 00000000..e22e52e8
--- /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