- started time handling function
authorAkiko <akiko@linux-addicted.net>
Mon, 1 Jun 2015 09:17:12 +0000 (11:17 +0200)
committerAkiko <akiko@linux-addicted.net>
Mon, 1 Jun 2015 09:17:12 +0000 (11:17 +0200)
- started version functions replacements
- fixed some const madness

20 files changed:
TinNS/Source/Common/CMakeLists.txt
TinNS/Source/Common/Config.cxx
TinNS/Source/Common/Config.hxx
TinNS/Source/Common/Defaults.hxx [new file with mode: 0644]
TinNS/Source/Common/Includes.hxx
TinNS/Source/Common/SVNrevision.hxx [deleted file]
TinNS/Source/Common/Time.cxx [new file with mode: 0644]
TinNS/Source/Common/Time.hxx [new file with mode: 0644]
TinNS/Source/Common/Version.hxx [deleted file]
TinNS/Source/GameServer/ConfigTemplate.hxx
TinNS/Source/GameServer/GameCommands/Version.cxx
TinNS/Source/GameServer/Includes.cxx
TinNS/Source/GameServer/Includes.hxx
TinNS/Source/GameServer/Subway.hxx
TinNS/Source/InfoServer/ConfigTemplate.hxx
TinNS/Source/InfoServer/Includes.cxx
TinNS/Source/InfoServer/Includes.hxx
TinNS/Source/PatchServer/ConfigTemplate.hxx
TinNS/Source/PatchServer/Includes.cxx
TinNS/Source/PatchServer/Includes.hxx

index b395c72..cd15a99 100644 (file)
@@ -1 +1,2 @@
-ADD_LIBRARY             (Common Config.cxx Console.cxx FileSystem.cxx Message.cxx Misc.cxx Netcode.cxx RegEx.cxx)
+ADD_LIBRARY             (Common Config.cxx Console.cxx FileSystem.cxx Message.cxx Misc.cxx Netcode.cxx RegEx.cxx
+                                Time.cxx)
index 3803b1c..657e03a 100644 (file)
@@ -13,7 +13,7 @@ PConfig::~PConfig()
   delete mIncludeRegEx;
 }
 
-bool PConfig::LoadOptions(const char* nConfigTemplate[][2], const char* nConfigFile, int nDepth)
+bool PConfig::LoadOptions(const char *const nConfigTemplate[][2], const char *nConfigFile, int nDepth)
 {
     FILE *ConfigFile;
     char line[255];
index 8f605dd..2a9f68e 100644 (file)
@@ -14,13 +14,13 @@ private:
     RegEx *mOptValRegEx;
     RegEx *mIncludeRegEx;
 
-    bool LoadOptions(const char *nConfigTemplate[][2], const char *nConfigFile, int32_t nDepth);
+    bool LoadOptions(const char *const nConfigTemplate[][2], const char *nConfigFile, int32_t nDepth);
 
 public:
     PConfig();
     ~PConfig();
 
-    inline bool LoadOptions(const char *nConfigTemplate[][2], const char *nConfigFile)
+    inline bool LoadOptions(const char *const nConfigTemplate[][2], const char *nConfigFile)
       { return LoadOptions(nConfigTemplate, nConfigFile, 0); }
     inline const std::string &GetOption(const char *Name) const { return GetOption((std::string) Name); }
     const std::string &GetOption(const std::string Name) const;
diff --git a/TinNS/Source/Common/Defaults.hxx b/TinNS/Source/Common/Defaults.hxx
new file mode 100644 (file)
index 0000000..1d160f0
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma once
+
+namespace DefMain
+{
+    static const char *const Name = "TinNS";
+    static const char *const Version = "0.3 C++11 development";
+}
index 0b2cc63..0e9aa9d 100644 (file)
@@ -2,10 +2,10 @@
 
 #include "Common/Config.hxx"
 #include "Common/Console.hxx"
+#include "Common/Defaults.hxx"
 #include "Common/FileSystem.hxx"
 #include "Common/Message.hxx"
 #include "Common/Misc.hxx"
 #include "Common/Netcode.hxx"
 #include "Common/RegEx.hxx"
-#include "Common/SVNrevision.hxx"
-#include "Common/Version.hxx"
+#include "Common/Time.hxx"
diff --git a/TinNS/Source/Common/SVNrevision.hxx b/TinNS/Source/Common/SVNrevision.hxx
deleted file mode 100644 (file)
index a04c733..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma once
-
-#define TINNS_SVN_REVISION "AKIKO_CMAKE_R3"
-
diff --git a/TinNS/Source/Common/Time.cxx b/TinNS/Source/Common/Time.cxx
new file mode 100644 (file)
index 0000000..a3fc0dc
--- /dev/null
@@ -0,0 +1,21 @@
+#include "Common/Time.hxx"
+
+namespace Time
+{
+    //--- functions ---
+
+    Timepoint now()
+    {
+        return Clock::now();
+    }
+
+    time_t toTimeT(const Timepoint &timepoint)
+    {
+        return Clock::to_time_t(timepoint);
+    }
+
+    Timepoint toTimepoint(const time_t timet)
+    {
+        return Clock::from_time_t(timet);
+    }
+}
diff --git a/TinNS/Source/Common/Time.hxx b/TinNS/Source/Common/Time.hxx
new file mode 100644 (file)
index 0000000..5209098
--- /dev/null
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <chrono>
+
+namespace Time
+{
+    //--- types ---
+    using Clock = std::chrono::system_clock;
+    using Rep = Clock::rep;
+    using Period = Clock::period;
+    using Duration = Clock::duration;
+    using Timepoint = Clock::time_point;
+
+    //--- functions ---
+    Timepoint now();
+    time_t toTimeT(const Timepoint &timepoint);
+    Timepoint toTimepoint(const time_t timet);
+}
diff --git a/TinNS/Source/Common/Version.hxx b/TinNS/Source/Common/Version.hxx
deleted file mode 100644 (file)
index 6048471..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-
-#include "Common/SVNrevision.hxx"
-
-#define TINNS_PATCH_VERSION "0.0.2 Dev"
-#define TINNS_INFO_VERSION "0.0.2 Dev"
-#define TINNS_GAME_VERSION "0.1.38 Dev"
index 99d327b..d7cd344 100644 (file)
@@ -4,7 +4,7 @@
   TODO: put a single data_directory entry as the root directory for all NC data
 */
 
-static const char *GameConfigTemplate[][2] = {
+static const char *const GameConfigTemplate[][2] = {
   // {option_name, default_value} if default_value is empty string, it means option is mandatory
   // List ends with empty string for option_name
   {"info_sql_host", "127.0.0.1"},
@@ -62,7 +62,7 @@ static const char *GameConfigTemplate[][2] = {
   {"", ""} // do not change this line (end mark)
 };
 
-static const char *CommandsTemplate[][2] = {
+static const char *const CommandsTemplate[][2] = {
     {"debug", "100"},
     {"settime", "100"},
     {"warp", "0"},
index 8b79309..279bfa1 100644 (file)
@@ -4,7 +4,8 @@
 void PCommands::doCmdversion()
 {
     char tmpChatMsg[300];
-    snprintf(tmpChatMsg, 299, "You are on TinNS server %s runnig version %s - SVN Rev. %s", Config->GetOption("server_name").c_str(), ServerVersion, SVNRevision);
+    snprintf(tmpChatMsg, 299, "You are on TinNS server %s runnig version %s - SVN Rev. %s",
+             Config->GetOption("server_name").c_str(), DefMain::Version, DefMain::Version);
     tmpChatMsg[299] = '\0';
 
     Chat->send(source, CHAT_DIRECT, "System", tmpChatMsg);
index 801f2ac..9a494f7 100644 (file)
@@ -5,9 +5,6 @@
 
 // TODO:   - Get logfile name from config file
 
-const char ServerVersion[] = TINNS_GAME_VERSION;
-const char SVNRevision[] = TINNS_SVN_REVISION;
-
 PVehicles *Vehicles = 0;
 PMySQL *MySQL = 0;
 PConsole *Console = 0;
@@ -49,7 +46,7 @@ bool InitTinNS()
     Console->Print(WHITE, BLUE, "/-------------------------------------------------------------------\\");
     Console->Print(WHITE, BLUE, "|               TinNS (TinNS is not a Neocron Server)               |");
     Console->Print(WHITE, BLUE, "|            Copyright (C) 2005 Linux Addicted Community            |");
-    Console->Print(WHITE, BLUE, "|                  maintainer Akiko <akiko@gmx.org>                 |");
+    Console->Print(WHITE, BLUE, "|             maintainer Akiko <akiko@linux-addicte.net>            |");
     Console->Print(WHITE, BLUE, "|             ==========================================            |");
     Console->Print(WHITE, BLUE, "|      Head coders:                   The packet analyzing team:    |");
     Console->Print(WHITE, BLUE, "|      - Akiko                         - MaxxJag                    |");
@@ -66,9 +63,9 @@ bool InitTinNS()
     //char svnrev[10];
     //GetSVNRev(svnrev);
     Console->LPrint("You are running TinNS Gameserver version");
-    Console->LPrint(GREEN, BLACK, " %s", ServerVersion);
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
     Console->LPrint(WHITE, BLACK, " - SVN Rev");
-    Console->LPrint(GREEN, BLACK, " %s", SVNRevision);
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
     Console->LClose();
 
     Config = new PConfig();
index d399724..18cc26d 100644 (file)
@@ -82,8 +82,5 @@ extern class PSubway* Subway;
 //Infoserver update
 extern class PISC *ISC;
 
-extern const char ServerVersion[];
-extern const char SVNRevision[];
-
 bool InitTinNS();
 void Shutdown();
index 7f5a48c..472caf5 100644 (file)
@@ -28,7 +28,7 @@ class PSubway {
     static const uint32_t mCabIntervalTime;
     static const uint32_t mOpenDoorOffset [];
     static const uint32_t mOpenDoorDuration [];
-    static const charmSubwayStationName [];
+    static const char *mSubwayStationName [];
     static PCharCoordinates mCabExitPositions [2][mStationsNumber];
 
     PSubwayInfo mSubways[mCabsNumber];
index 8e4ac9a..1578eb6 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
-static const char *InfoConfigTemplate[][2] = {
+static const char *const InfoConfigTemplate[][2] = {
   // {option_name, default_value} if default_value is empty string, it means option is mandatory
   // List ends with empty string for option_name
   {"sql_host", "127.0.0.1"}, // should be renanmed to info_sql_host
index d61e1a2..927e3db 100644 (file)
@@ -2,9 +2,6 @@
 #include "InfoServer/Includes.hxx"
 #include "Common/Includes.hxx"
 
-const char ServerVersion[] = TINNS_INFO_VERSION;
-const char SVNRevision[] = TINNS_SVN_REVISION;
-
 ServerSocket* ServerSock = 0;
 PMySQL *MySQL = 0;
 PConsole *Console = 0;
@@ -19,8 +16,8 @@ bool Init()
     Console->Print("Starting TinNS Infoserver");
     Console->Print(WHITE, BLUE, "/-------------------------------------------------------------------\\");
     Console->Print(WHITE, BLUE, "|               TinNS (TinNS is not a Neocron Server)               |");
-  Console->Print(WHITE, BLUE, "|            Copyright (C) 2005 Linux Addicted Community            |");
-    Console->Print(WHITE, BLUE, "|                  maintainer Akiko <akiko@gmx.org>                 |");
+    Console->Print(WHITE, BLUE, "|            Copyright (C) 2005 Linux Addicted Community            |");
+    Console->Print(WHITE, BLUE, "|             maintainer Akiko <akiko@linux-addicted.net>           |");
     Console->Print(WHITE, BLUE, "|             ==========================================            |");
     Console->Print(WHITE, BLUE, "|      Head coders:                   The packet analyzing team:    |");
     Console->Print(WHITE, BLUE, "|      - Akiko                         - MaxxJag                    |");
@@ -29,7 +26,7 @@ bool Init()
     Console->Print(WHITE, BLUE, "|      - Hammag                                                     |");
     Console->Print(WHITE, BLUE, "|-------------------------------------------------------------------|");
     Console->Print(WHITE, BLUE, "|  This project would'nt be at its current stage without the help   |");
-  Console->Print(WHITE, BLUE, "|        from the NeoPolis team, special thanks to you guys!        |");
+    Console->Print(WHITE, BLUE, "|        from the NeoPolis team, special thanks to you guys!        |");
     Console->Print(WHITE, BLUE, "|-------------------------------------------------------------------|");
     Console->Print(WHITE, BLUE, "|  This project is under GPL, see any source file for more details  |");
     Console->Print(WHITE, BLUE, "\\-------------------------------------------------------------------/");
@@ -37,9 +34,9 @@ bool Init()
     //char svnrev[10];
     //GetSVNRev(svnrev);
     Console->LPrint("You are running TinNS Infoserver version");
-    Console->LPrint(GREEN, BLACK, " %s", ServerVersion);
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
     Console->LPrint(WHITE, BLACK, " - SVN Rev");
-    Console->LPrint(GREEN, BLACK, " %s", SVNRevision);
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
     Console->LClose();
 
     Config = new PConfig();
index 1253897..044dcc5 100644 (file)
@@ -16,9 +16,6 @@ extern class PInfoServer *InfoServer;
 extern class PMySQL* MySQL;
 //extern class PAccounts* Accounts;  // To be removed
 
-extern const char ServerVersion[];
-extern const char SVNRevision[];
-
 bool Init();
 void Shutdown();
 bool AdditionnalConfigChecks();
index 080faef..5d5f713 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
-static const char *PatchConfigTemplate[][2] = {
+static const char *const PatchConfigTemplate[][2] = {
   // {option_name, default_value} if default_value is empty string, it means option is mandatory
   // List ends with empty string for option_name
   {"server_version", "200"},
index b691713..4eeedea 100644 (file)
@@ -1,9 +1,6 @@
 #include "PatchServer/Includes.hxx"
 #include "Common/Includes.hxx"
 
-const char ServerVersion[] = TINNS_PATCH_VERSION;
-const char SVNRevision[] = TINNS_SVN_REVISION;
-
 ServerSocket* ServerSock = 0;
 PConsole *Console = 0;
 PServer *Server = 0;
@@ -18,7 +15,7 @@ bool InitTinNS()
     Console->Print(WHITE, BLUE, "/-------------------------------------------------------------------\\");
     Console->Print(WHITE, BLUE, "|               TinNS (TinNS is not a Neocron Server)               |");
     Console->Print(WHITE, BLUE, "|            Copyright (C) 2005 Linux Addicted Community            |");
-    Console->Print(WHITE, BLUE, "|                  maintainer Akiko <akiko@gmx.org>                 |");
+    Console->Print(WHITE, BLUE, "|             maintainer Akiko <akiko@linux-addicted.net>           |");
     Console->Print(WHITE, BLUE, "|             ==========================================            |");
     Console->Print(WHITE, BLUE, "|      Head coders:                   The packet analyzing team:    |");
     Console->Print(WHITE, BLUE, "|      - Akiko                         - MaxxJag                    |");
@@ -35,9 +32,9 @@ bool InitTinNS()
     //char svnrev[10];
     //GetSVNRev(svnrev);
     Console->LPrint("You are running TinNS Patchserver version");
-    Console->LPrint(GREEN, BLACK, " %s", ServerVersion);
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
     Console->LPrint(WHITE, BLACK, " - SVN Rev");
-    Console->LPrint(GREEN, BLACK, " %s", SVNRevision);
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
     Console->LClose();
 
     Config = new PConfig();
index 16cf78d..cfb7958 100644 (file)
@@ -12,8 +12,5 @@ extern class PFileSystem *Filesystem;
 extern class PServer *Server;
 extern class PPatchServer *PatchServer;
 
-extern const char ServerVersion[];
-extern const char SVNRevision[];
-
 bool InitTinNS();
 void Shutdown();