From 587e4e8279beeb956a3ddbe071189b70b58f21de Mon Sep 17 00:00:00 2001 From: Akiko Date: Mon, 1 Jun 2015 12:12:06 +0200 Subject: [PATCH] - new time functions are done - replaced more of the version/revision system --- TinNS/Source/Common/Defaults.hxx | 8 +- TinNS/Source/Common/Time.cxx | 17 ++++ TinNS/Source/Common/Time.hxx | 11 ++- TinNS/Source/DevelopmentTools/CMakeLists.txt | 1 - TinNS/Source/DevelopmentTools/getsvnrev.cxx | 104 ----------------------- TinNS/Source/GameServer/GameCommands/Version.cxx | 2 +- TinNS/Source/GameServer/Includes.cxx | 6 +- TinNS/Source/InfoServer/Includes.cxx | 4 +- TinNS/Source/PatchServer/Includes.cxx | 4 +- 9 files changed, 41 insertions(+), 116 deletions(-) delete mode 100644 TinNS/Source/DevelopmentTools/getsvnrev.cxx diff --git a/TinNS/Source/Common/Defaults.hxx b/TinNS/Source/Common/Defaults.hxx index 1d160f0..833ef16 100644 --- a/TinNS/Source/Common/Defaults.hxx +++ b/TinNS/Source/Common/Defaults.hxx @@ -1,7 +1,11 @@ #pragma once +#include +#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(); } diff --git a/TinNS/Source/Common/Time.cxx b/TinNS/Source/Common/Time.cxx index a3fc0dc..8c81a9d 100644 --- a/TinNS/Source/Common/Time.cxx +++ b/TinNS/Source/Common/Time.cxx @@ -1,3 +1,5 @@ +#include +#include #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); + } } diff --git a/TinNS/Source/Common/Time.hxx b/TinNS/Source/Common/Time.hxx index 5209098..63b14cd 100644 --- a/TinNS/Source/Common/Time.hxx +++ b/TinNS/Source/Common/Time.hxx @@ -1,18 +1,27 @@ #pragma once #include +#include 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); } diff --git a/TinNS/Source/DevelopmentTools/CMakeLists.txt b/TinNS/Source/DevelopmentTools/CMakeLists.txt index 50b0b11..ff3ac3d 100644 --- a/TinNS/Source/DevelopmentTools/CMakeLists.txt +++ b/TinNS/Source/DevelopmentTools/CMakeLists.txt @@ -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 index 501129d..0000000 --- a/TinNS/Source/DevelopmentTools/getsvnrev.cxx +++ /dev/null @@ -1,104 +0,0 @@ -/* - TinNS (TinNS is not a Neocron Server) - Copyright (C) 2005 Linux Addicted Community - maintainer Akiko - - 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 -#include -#include -#include - -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); -} diff --git a/TinNS/Source/GameServer/GameCommands/Version.cxx b/TinNS/Source/GameServer/GameCommands/Version.cxx index 279bfa1..e08accf 100644 --- a/TinNS/Source/GameServer/GameCommands/Version.cxx +++ b/TinNS/Source/GameServer/GameCommands/Version.cxx @@ -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); diff --git a/TinNS/Source/GameServer/Includes.cxx b/TinNS/Source/GameServer/Includes.cxx index 9a494f7..70385d2 100644 --- a/TinNS/Source/GameServer/Includes.cxx +++ b/TinNS/Source/GameServer/Includes.cxx @@ -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 |"); + Console->Print(WHITE, BLUE, "| maintainer Akiko |"); 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(); diff --git a/TinNS/Source/InfoServer/Includes.cxx b/TinNS/Source/InfoServer/Includes.cxx index 927e3db..e0b8e41 100644 --- a/TinNS/Source/InfoServer/Includes.cxx +++ b/TinNS/Source/InfoServer/Includes.cxx @@ -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(); diff --git a/TinNS/Source/PatchServer/Includes.cxx b/TinNS/Source/PatchServer/Includes.cxx index 4eeedea..7852718 100644 --- a/TinNS/Source/PatchServer/Includes.cxx +++ b/TinNS/Source/PatchServer/Includes.cxx @@ -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(); -- 2.15.1