Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: server save countdown #40

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
'achievements_base' => 300000,

'server_save' => '05:00:00',
'timezone_set' => 'America/Sao_Paulo',

'signature_enabled' => false,
'signature_type' => 'tibian', // signature engine to use: tibian, mango, gesior
Expand Down
45 changes: 32 additions & 13 deletions templates/tibiacom/boxes/serversave.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,42 @@
$hours_ServerSave = $explodeServerSave[0];
$minutes_ServerSave = $explodeServerSave[1];
$seconds_ServerSave = $explodeServerSave[2];
$timezone_set = $config['timezone_set'];
date_default_timezone_set($timezone_set);

$now = new DateTime();
$serverSaveTime = new DateTime();
$serverSaveTime->setTime($hours_ServerSave, $minutes_ServerSave, $seconds_ServerSave);

if ($now > $serverSaveTime) {
$serverSaveTime->modify('+1 day');
}

$interval = $now->diff($serverSaveTime);
?>
<script>
var countDownDate = new Date("Jan 01, 2023 <?php echo $hours_ServerSave ?>:<?php echo $minutes_ServerSave ?>:<?php echo $seconds_ServerSave ?>").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
var serverSaveTime = new Date(<?php echo $serverSaveTime->format('Y, n-1, j, G, i, s') ?>);

var x = setInterval(function() {
var now = new Date().getTime();
var distance = serverSaveTime - now;

var hours = Math.floor(distance / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Adiciona zeros à esquerda, se necessário
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

document.getElementById("timerServerSave").innerHTML = "" + hours + ":" + minutes + ":" + seconds + "";
document.getElementById("timerServerSave").innerHTML = hours + ":" + minutes + ":" + seconds;

if (distance < 0) {
clearInterval(x);
document.getElementById("timerServerSave").innerHTML = "Server save now!";
}
}, 1000);
if (distance < 0) {
clearInterval(x);
document.getElementById("timerServerSave").innerHTML = "Server save now!";
}
}, 1000);
</script>
<div class="serversave">
<div class="serversave_header">Server Save</div>
Expand Down