From 7ba9b9a54f1733a34d281b115aed06115c304607 Mon Sep 17 00:00:00 2001 From: kamilprzyb Date: Tue, 22 Sep 2020 21:15:47 +0200 Subject: [PATCH] replaced high_resolution_clock with system_time for timestamps --- src/CNStructs.hpp | 1 + src/Database.cpp | 10 +++++----- src/NPCManager.cpp | 2 +- src/main.cpp | 8 ++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 3fa635b..9f87bb6 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -33,6 +33,7 @@ std::string U16toU8(char16_t* src); size_t U8toU16(std::string src, char16_t* des); // returns number of char16_t that was written at des time_t getTime(); +time_t getTimestamp(); // The PROTOCOL_VERSION definition is defined by the build system. #if !defined(PROTOCOL_VERSION) diff --git a/src/Database.cpp b/src/Database.cpp index a2527be..99bff3b 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -128,7 +128,7 @@ int Database::addAccount(std::string login, std::string password) account.Login = login; account.Password = password; account.Selected = 1; - account.Created = getTime(); + account.Created = getTimestamp(); return db.insert(account); } @@ -137,7 +137,7 @@ void Database::updateSelected(int accountId, int slot) Account acc = db.get(accountId); acc.Selected = slot; //timestamp - acc.LastLogin = getTime(); + acc.LastLogin = getTimestamp(); db.update(acc); } @@ -172,7 +172,7 @@ int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID) DbPlayer create = {}; //set timestamp - create.Created = getTime(); + create.Created = getTimestamp(); // save packet data create.FirstName = U16toU8(save->szFirstName); create.LastName = U16toU8(save->szLastName); @@ -380,7 +380,7 @@ Database::DbPlayer Database::playerToDb(Player *player) appendBlob(&result.QuestFlag, flag); } //timestamp - result.LastLogin = getTime(); + result.LastLogin = getTimestamp(); result.Created = getDbPlayerById(player->iID).Created; return result; @@ -611,7 +611,7 @@ void Database::getInventory(Player* player) { } void Database::removeExpiredVehicles(Player* player) { - uint64_t currentTime = getTime(); + uint64_t currentTime = getTimestamp(); //remove from bank immediately for (int i = 0; i < ABANK_COUNT; i++) { if (player->Bank[i].iType == 10 && player->Bank[i].iTimeLimit < currentTime) diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index bccb906..c054dff 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -118,7 +118,7 @@ void NPCManager::npcVendorBuy(CNSocket* sock, CNPacketData* data) { // if vehicle if (req->Item.iType == 10) // set time limit: current time + 7days - req->Item.iTimeLimit = getTime() + 604800; + req->Item.iTimeLimit = getTimestamp() + 604800; if (slot != req->iInvenSlotNum) { diff --git a/src/main.cpp b/src/main.cpp index de22839..1dd3520 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,3 +149,11 @@ time_t getTime() { return (time_t)value.count(); } + +time_t getTimestamp() { + using namespace std::chrono; + + milliseconds value = duration_cast((time_point_cast(system_clock::now())).time_since_epoch()); + + return (time_t)value.count(); +}