From: Akiko Date: Mon, 1 Jun 2015 09:17:12 +0000 (+0200) Subject: - started time handling function X-Git-Url: http://community.linux-addicted.net/gitweb/?a=commitdiff_plain;h=60126c9e73b96215f270da6346f03a70d721a639;p=tinns.git - started time handling function - started version functions replacements - fixed some const madness --- diff --git a/TinNS/Source/Common/CMakeLists.txt b/TinNS/Source/Common/CMakeLists.txt index b395c72..cd15a99 100644 --- a/TinNS/Source/Common/CMakeLists.txt +++ b/TinNS/Source/Common/CMakeLists.txt @@ -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) diff --git a/TinNS/Source/Common/Config.cxx b/TinNS/Source/Common/Config.cxx index 3803b1c..657e03a 100644 --- a/TinNS/Source/Common/Config.cxx +++ b/TinNS/Source/Common/Config.cxx @@ -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]; diff --git a/TinNS/Source/Common/Config.hxx b/TinNS/Source/Common/Config.hxx index 8f605dd..2a9f68e 100644 --- a/TinNS/Source/Common/Config.hxx +++ b/TinNS/Source/Common/Config.hxx @@ -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 index 0000000..1d160f0 --- /dev/null +++ b/TinNS/Source/Common/Defaults.hxx @@ -0,0 +1,7 @@ +#pragma once + +namespace DefMain +{ + static const char *const Name = "TinNS"; + static const char *const Version = "0.3 C++11 development"; +} diff --git a/TinNS/Source/Common/Includes.hxx b/TinNS/Source/Common/Includes.hxx index 0b2cc63..0e9aa9d 100644 --- a/TinNS/Source/Common/Includes.hxx +++ b/TinNS/Source/Common/Includes.hxx @@ -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 index a04c733..0000000 --- a/TinNS/Source/Common/SVNrevision.hxx +++ /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 index 0000000..a3fc0dc --- /dev/null +++ b/TinNS/Source/Common/Time.cxx @@ -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 index 0000000..5209098 --- /dev/null +++ b/TinNS/Source/Common/Time.hxx @@ -0,0 +1,18 @@ +#pragma once + +#include + +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 index 6048471..0000000 --- a/TinNS/Source/Common/Version.hxx +++ /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" diff --git a/TinNS/Source/GameServer/ConfigTemplate.hxx b/TinNS/Source/GameServer/ConfigTemplate.hxx index 99d327b..d7cd344 100644 --- a/TinNS/Source/GameServer/ConfigTemplate.hxx +++ b/TinNS/Source/GameServer/ConfigTemplate.hxx @@ -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"}, diff --git a/TinNS/Source/GameServer/GameCommands/Version.cxx b/TinNS/Source/GameServer/GameCommands/Version.cxx index 8b79309..279bfa1 100644 --- a/TinNS/Source/GameServer/GameCommands/Version.cxx +++ b/TinNS/Source/GameServer/GameCommands/Version.cxx @@ -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); diff --git a/TinNS/Source/GameServer/Includes.cxx b/TinNS/Source/GameServer/Includes.cxx index 801f2ac..9a494f7 100644 --- a/TinNS/Source/GameServer/Includes.cxx +++ b/TinNS/Source/GameServer/Includes.cxx @@ -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 |"); + 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 |"); @@ -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(); diff --git a/TinNS/Source/GameServer/Includes.hxx b/TinNS/Source/GameServer/Includes.hxx index d399724..18cc26d 100644 --- a/TinNS/Source/GameServer/Includes.hxx +++ b/TinNS/Source/GameServer/Includes.hxx @@ -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(); diff --git a/TinNS/Source/GameServer/Subway.hxx b/TinNS/Source/GameServer/Subway.hxx index 7f5a48c..472caf5 100644 --- a/TinNS/Source/GameServer/Subway.hxx +++ b/TinNS/Source/GameServer/Subway.hxx @@ -28,7 +28,7 @@ class PSubway { static const uint32_t mCabIntervalTime; static const uint32_t mOpenDoorOffset []; static const uint32_t mOpenDoorDuration []; - static const char* mSubwayStationName []; + static const char *mSubwayStationName []; static PCharCoordinates mCabExitPositions [2][mStationsNumber]; PSubwayInfo mSubways[mCabsNumber]; diff --git a/TinNS/Source/InfoServer/ConfigTemplate.hxx b/TinNS/Source/InfoServer/ConfigTemplate.hxx index 8e4ac9a..1578eb6 100644 --- a/TinNS/Source/InfoServer/ConfigTemplate.hxx +++ b/TinNS/Source/InfoServer/ConfigTemplate.hxx @@ -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 diff --git a/TinNS/Source/InfoServer/Includes.cxx b/TinNS/Source/InfoServer/Includes.cxx index d61e1a2..927e3db 100644 --- a/TinNS/Source/InfoServer/Includes.cxx +++ b/TinNS/Source/InfoServer/Includes.cxx @@ -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 |"); + Console->Print(WHITE, BLUE, "| Copyright (C) 2005 Linux Addicted Community |"); + 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 |"); @@ -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(); diff --git a/TinNS/Source/InfoServer/Includes.hxx b/TinNS/Source/InfoServer/Includes.hxx index 1253897..044dcc5 100644 --- a/TinNS/Source/InfoServer/Includes.hxx +++ b/TinNS/Source/InfoServer/Includes.hxx @@ -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(); diff --git a/TinNS/Source/PatchServer/ConfigTemplate.hxx b/TinNS/Source/PatchServer/ConfigTemplate.hxx index 080faef..5d5f713 100644 --- a/TinNS/Source/PatchServer/ConfigTemplate.hxx +++ b/TinNS/Source/PatchServer/ConfigTemplate.hxx @@ -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"}, diff --git a/TinNS/Source/PatchServer/Includes.cxx b/TinNS/Source/PatchServer/Includes.cxx index b691713..4eeedea 100644 --- a/TinNS/Source/PatchServer/Includes.cxx +++ b/TinNS/Source/PatchServer/Includes.cxx @@ -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 |"); + 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 |"); @@ -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(); diff --git a/TinNS/Source/PatchServer/Includes.hxx b/TinNS/Source/PatchServer/Includes.hxx index 16cf78d..cfb7958 100644 --- a/TinNS/Source/PatchServer/Includes.hxx +++ b/TinNS/Source/PatchServer/Includes.hxx @@ -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();