Use unix timestamp util
This commit is contained in:
@@ -191,7 +191,7 @@ function showCharacterSelectToClient(client) {
|
|||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
|
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
|
||||||
let tempSubAccount = getPlayerData(client).subAccounts[0];
|
let tempSubAccount = getPlayerData(client).subAccounts[0];
|
||||||
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
||||||
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${getTimeDifferenceDisplay(tempSubAccount.lastLogin, new Date().getTime())} ago` : "Never";
|
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${getTimeDifferenceDisplay(tempSubAccount.lastLogin, getCurrentUnixTimestamp())} ago` : "Never";
|
||||||
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, tempSubAccount.skin);
|
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, tempSubAccount.skin);
|
||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select GUI`);
|
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select GUI`);
|
||||||
} else {
|
} else {
|
||||||
@@ -201,7 +201,7 @@ function showCharacterSelectToClient(client) {
|
|||||||
messagePlayerNormal(client, `You have the following characters. Use /usechar <id> to select one:`, getColourByName("teal"));
|
messagePlayerNormal(client, `You have the following characters. Use /usechar <id> to select one:`, getColourByName("teal"));
|
||||||
getPlayerData(client).subAccounts.forEach(function(subAccount, index) {
|
getPlayerData(client).subAccounts.forEach(function(subAccount, index) {
|
||||||
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
||||||
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `Last played ${getTimeDifferenceDisplay(tempSubAccount.lastLogin, new Date().getTime())} ago` : "Never played";
|
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `Last played ${getTimeDifferenceDisplay(tempSubAccount.lastLogin, getCurrentUnixTimestamp())} ago` : "Never played";
|
||||||
messagePlayerNormal(client, `${index+1} • [#BBBBBB]${subAccount.firstName} ${subAccount.lastName} ($${tempSubAccount.cash}, ${lastPlayedText})`);
|
messagePlayerNormal(client, `${index+1} • [#BBBBBB]${subAccount.firstName} ${subAccount.lastName} ($${tempSubAccount.cash}, ${lastPlayedText})`);
|
||||||
});
|
});
|
||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select/list message (GUI disabled)`);
|
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select/list message (GUI disabled)`);
|
||||||
@@ -258,7 +258,7 @@ function checkPreviousCharacter(client) {
|
|||||||
let tempSubAccount = getPlayerData(client).subAccounts[subAccountId];
|
let tempSubAccount = getPlayerData(client).subAccounts[subAccountId];
|
||||||
|
|
||||||
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
||||||
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${getTimeDifferenceDisplay(tempSubAccount.lastLogin, new Date().getTime())} ago` : "Never";
|
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${getTimeDifferenceDisplay(tempSubAccount.lastLogin, getCurrentUnixTimestamp())} ago` : "Never";
|
||||||
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, tempSubAccount.skin);
|
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, tempSubAccount.skin);
|
||||||
|
|
||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
|
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
|
||||||
@@ -279,7 +279,7 @@ function checkNextCharacter(client) {
|
|||||||
let tempSubAccount = getPlayerData(client).subAccounts[subAccountId];
|
let tempSubAccount = getPlayerData(client).subAccounts[subAccountId];
|
||||||
|
|
||||||
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
let clanName = (tempSubAccount.clan != 0) ? getClanData(tempSubAccount.clan).name : "None";
|
||||||
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${getTimeDifferenceDisplay(tempSubAccount.lastLogin, new Date().getTime())} ago` : "Never";
|
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${getTimeDifferenceDisplay(tempSubAccount.lastLogin, getCurrentUnixTimestamp())} ago` : "Never";
|
||||||
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, tempSubAccount.skin);
|
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, tempSubAccount.skin);
|
||||||
|
|
||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
|
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
|
||||||
@@ -317,7 +317,7 @@ function selectCharacter(client, characterId = -1) {
|
|||||||
onPlayerSpawn(client);
|
onPlayerSpawn(client);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
getPlayerCurrentSubAccount(client).lastLogin = new Date().getTime();
|
getPlayerCurrentSubAccount(client).lastLogin = getCurrentUnixTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
@@ -325,12 +325,12 @@ function selectCharacter(client, characterId = -1) {
|
|||||||
function switchCharacterCommand(command, params, client) {
|
function switchCharacterCommand(command, params, client) {
|
||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is requesting to switch characters (current character: ${getCharacterFullName(client)} [${getPlayerData(client).currentSubAccount}/${getPlayerCurrentSubAccount(client).databaseId}])`);
|
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is requesting to switch characters (current character: ${getCharacterFullName(client)} [${getPlayerData(client).currentSubAccount}/${getPlayerCurrentSubAccount(client).databaseId}])`);
|
||||||
if(!isPlayerSpawned(client)) {
|
if(!isPlayerSpawned(client)) {
|
||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is allowed to switch characters (not spawned)`);
|
logToConsole(LOG_WARN, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is not allowed to switch characters (not spawned)`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isPlayerSwitchingCharacter(client)) {
|
if(isPlayerSwitchingCharacter(client)) {
|
||||||
logToConsole(LOG_DEBUG, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is not allowed to switch characters (already in switch char mode)`);
|
logToConsole(LOG_WARN, `[Asshat.SubAccount] ${getPlayerDisplayForConsole(client)} is not allowed to switch characters (already in switch char mode)`);
|
||||||
messagePlayerError(client, "You are already selecting/switching characters!");
|
messagePlayerError(client, "You are already selecting/switching characters!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,15 +362,12 @@ function getCardinalDirection(pos1, pos2) {
|
|||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
function getTimeDifferenceDisplay(timeStamp1, timeStamp2) {
|
function getTimeDifferenceDisplay(timeStamp2, timeStamp1) {
|
||||||
let dateTime1 = new Date(timeStamp1).getTime();
|
if(isNaN(timeStamp1) || isNaN(timeStamp2)) {
|
||||||
let dateTime2 = new Date(timeStamp2).getTime();
|
|
||||||
|
|
||||||
if(isNaN(dateTime1) || isNaN(dateTime2)) {
|
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
let millisecondDiff = dateTime2 - dateTime1;
|
let millisecondDiff = timeStamp2 - timeStamp1;
|
||||||
|
|
||||||
let days = Math.floor(millisecondDiff / 1000 / 60 / (60 * 24));
|
let days = Math.floor(millisecondDiff / 1000 / 60 / (60 * 24));
|
||||||
let diffDate = new Date(millisecondDiff);
|
let diffDate = new Date(millisecondDiff);
|
||||||
@@ -1289,3 +1286,9 @@ function isPlayerMuted(client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
|
function getCurrentUnixTimestamp() {
|
||||||
|
return new Date().getTime()/1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
@@ -442,7 +442,7 @@ function rentVehicleCommand(command, params, client) {
|
|||||||
|
|
||||||
getVehicleData(vehicle).rentedBy = client;
|
getVehicleData(vehicle).rentedBy = client;
|
||||||
getPlayerCurrentSubAccount(client).rentingVehicle = vehicle;
|
getPlayerCurrentSubAccount(client).rentingVehicle = vehicle;
|
||||||
getVehicleData(vehicle).rentStart = new Date().getTime();
|
getVehicleData(vehicle).rentStart = getCurrentUnixTimestamp();
|
||||||
|
|
||||||
meActionToNearbyPlayers(client, `rents the ${getVehicleName(vehicle)} and receives a set of vehicle keys!`);
|
meActionToNearbyPlayers(client, `rents the ${getVehicleName(vehicle)} and receives a set of vehicle keys!`);
|
||||||
messagePlayerAlert(client, `You will be charged ${getVehicleData(vehicle).rentPrice} per minute to use this vehicle. To stop renting this vehicle, use /vehrent again.`);
|
messagePlayerAlert(client, `You will be charged ${getVehicleData(vehicle).rentPrice} per minute to use this vehicle. To stop renting this vehicle, use /vehrent again.`);
|
||||||
|
|||||||
Reference in New Issue
Block a user