- new time functions are done
authorAkiko <akiko@linux-addicted.net>
Mon, 1 Jun 2015 10:12:06 +0000 (12:12 +0200)
committerAkiko <akiko@linux-addicted.net>
Mon, 1 Jun 2015 10:12:06 +0000 (12:12 +0200)
- replaced more of the version/revision system

TinNS/Source/Common/Defaults.hxx
TinNS/Source/Common/Time.cxx
TinNS/Source/Common/Time.hxx
TinNS/Source/DevelopmentTools/CMakeLists.txt
TinNS/Source/DevelopmentTools/getsvnrev.cxx [deleted file]
TinNS/Source/GameServer/GameCommands/Version.cxx
TinNS/Source/GameServer/Includes.cxx
TinNS/Source/InfoServer/Includes.cxx
TinNS/Source/PatchServer/Includes.cxx

index 1d160f0..833ef16 100644 (file)
@@ -1,7 +1,11 @@
 #pragma once
 
+#include <string>
+#include "Common/Time.hxx"
+
 namespace DefMain
 {
-    static const char *const Name = "TinNS";
-    static const char *const Version = "0.3 C++11 development";
+    static const std::string Name = "TinNS";
+    static const std::string Version = "0.3 C++11 development";
+    static const std::string Revision = Time::toDateString(Time::now()).c_str();
 }
index a3fc0dc..8c81a9d 100644 (file)
@@ -1,3 +1,5 @@
+#include <iomanip>
+#include <sstream>
 #include "Common/Time.hxx"
 
 namespace Time
@@ -18,4 +20,19 @@ namespace Time
     {
         return Clock::from_time_t(timet);
     }
+
+    std::string toDateString(const time_t timet, const std::string &format)
+    {
+        const struct std::tm temp = *std::localtime(&timet);
+        std::stringstream result;
+
+        result << std::put_time(&temp, format.c_str());
+
+        return result.str();
+    }
+
+    std::string toDateString(const Timepoint &timepoint, const std::string &format)
+    {
+        return toDateString(toTimeT(timepoint), format);
+    }
 }
index 5209098..63b14cd 100644 (file)
@@ -1,18 +1,27 @@
 #pragma once
 
 #include <chrono>
+#include <string>
 
 namespace Time
 {
-    //--- types ---
+    //--- types and constants ---
     using Clock = std::chrono::system_clock;
     using Rep = Clock::rep;
     using Period = Clock::period;
     using Duration = Clock::duration;
     using Timepoint = Clock::time_point;
 
+    // fromat: YYYYMMDD.hhmmss - 24h
+    static const std::string DefCompactDateTime = "%Y%m%j.%H%M%S";
+    static const std::string DefDateTime = "%Y/%m/%j %H:%M:%S";
+
     //--- functions ---
     Timepoint now();
+
     time_t toTimeT(const Timepoint &timepoint);
     Timepoint toTimepoint(const time_t timet);
+
+    std::string toDateString(const time_t timet, const std::string &format = DefCompactDateTime);
+    std::string toDateString(const Timepoint &timepoint, const std::string &format = DefCompactDateTime);
 }
index 50b0b11..ff3ac3d 100644 (file)
@@ -1,2 +1 @@
-ADD_EXECUTABLE          (getsvnrev getsvnrev.cxx)
 ADD_EXECUTABLE          (cleandepfile cleandepfile.c)
diff --git a/TinNS/Source/DevelopmentTools/getsvnrev.cxx b/TinNS/Source/DevelopmentTools/getsvnrev.cxx
deleted file mode 100644 (file)
index 501129d..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
-       TinNS (TinNS is not a Neocron Server)
-       Copyright (C) 2005 Linux Addicted Community
-       maintainer Akiko <akiko@gmx.org>
-
-       This program 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 (at your option) any later version.
-
-       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, write to the Free Software
-       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-       02110-1301, USA.
-*/
-
-
-
-/*
-       getsvnrev - a simple tool to read out actual SVN revision-number
-
-       Why?
-               Well for example my server doesnt have any SVN libs installed. Therefore,
-               the getsvnrev script fails. I need this little tool, and maybe someone else too ^^
-
-       Usage: 
-               call getsvnrev either without parameters or with the directory you
-               want to know the SVN revision.
-       
-       Console output:
-               If no .svn directory is found, the tool returns 0.
-               Otherwise it will return the SVN revision of the target dir
-
-       MODIFIED: 22 Dec 2006 Namikon
-       REASON: - started this tool
-       MODIFIED: 09 Jun 2009 Akiko
-       REASON: - more C++ stylish
-               - missing libs (cstring, cstdlib)
-
-       TODO:
-               - Better way to get SVN rev than this (2nd number in file)
-*/
-
-
-#include <cstdio>
-#include <cstring>
-#include <cstdlib>
-#include <iostream>
-
-int main(int argc, char **argv)
-{
-       std::string targetdir;
-       FILE *f;
-
-        if(argc == 2)
-       {
-               int i = 0;
-               while(argv[1][i] != '\0') { i++; };
-               if(argv[1][i-1] == '/')
-               {
-                       targetdir = strcat(argv[1], ".svn/entries");
-               }
-               else
-               {
-                       targetdir = strcat(argv[1], "/.svn/entries");
-               }
-        }
-       else
-       {
-               targetdir = ".svn/entries";
-       }
-
-
-        if ((f = fopen(targetdir.c_str(), "r")) != NULL) {
-                char line[255];
-                int rev;
-               bool firstnrfound = false;
-               
-               do
-               {
-                  fgets (line, 255, f);
-                  rev = atoi(line);
-                  if(rev > 0 && firstnrfound == false)
-                  {
-                       firstnrfound = true;
-                       rev = 0;
-                   }
-               } while (rev == 0);
-               
-                fclose(f);
-
-                std::cout << rev << std::endl;
-        }
-       else
-       {
-               std::cout << "0" << std::endl;
-       }
-       return(0);
-}
index 279bfa1..e08accf 100644 (file)
@@ -5,7 +5,7 @@ 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(), DefMain::Version, DefMain::Version);
+             Config->GetOption("server_name").c_str(), DefMain::Version.c_str(), DefMain::Version.c_str());
     tmpChatMsg[299] = '\0';
 
     Chat->send(source, CHAT_DIRECT, "System", tmpChatMsg);
index 9a494f7..70385d2 100644 (file)
@@ -46,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@linux-addicte.net>            |");
+    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                    |");
@@ -64,8 +64,8 @@ bool InitTinNS()
     //GetSVNRev(svnrev);
     Console->LPrint("You are running TinNS Gameserver version");
     Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
-    Console->LPrint(WHITE, BLACK, " - SVN Rev");
-    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
+    Console->LPrint(WHITE, BLACK, " - Revision");
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Revision);
     Console->LClose();
 
     Config = new PConfig();
index 927e3db..e0b8e41 100644 (file)
@@ -35,8 +35,8 @@ bool Init()
     //GetSVNRev(svnrev);
     Console->LPrint("You are running TinNS Infoserver version");
     Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
-    Console->LPrint(WHITE, BLACK, " - SVN Rev");
-    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
+    Console->LPrint(WHITE, BLACK, " - Revision");
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Revision);
     Console->LClose();
 
     Config = new PConfig();
index 4eeedea..7852718 100644 (file)
@@ -33,8 +33,8 @@ bool InitTinNS()
     //GetSVNRev(svnrev);
     Console->LPrint("You are running TinNS Patchserver version");
     Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
-    Console->LPrint(WHITE, BLACK, " - SVN Rev");
-    Console->LPrint(GREEN, BLACK, " %s", DefMain::Version);
+    Console->LPrint(WHITE, BLACK, " - Revision");
+    Console->LPrint(GREEN, BLACK, " %s", DefMain::Revision);
     Console->LClose();
 
     Config = new PConfig();