replaced high_resolution_clock with system_time for timestamps

This commit is contained in:
kamilprzyb 2020-09-22 21:15:47 +02:00
parent 0931c88541
commit 7ba9b9a54f
4 changed files with 15 additions and 6 deletions

View File

@ -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)

View File

@ -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<Account>(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)

View File

@ -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) {

View File

@ -149,3 +149,11 @@ time_t getTime() {
return (time_t)value.count();
}
time_t getTimestamp() {
using namespace std::chrono;
milliseconds value = duration_cast<milliseconds>((time_point_cast<milliseconds>(system_clock::now())).time_since_epoch());
return (time_t)value.count();
}