Jump to content

Workaround for Time Sync Issue


jahangir13

Recommended Posts

Hi,

 

I've found a workaround for my server to get the time snyched better between players.

E.g. I had the issue (I guess others too) that if the server starts at 8 and 12 and a player logs in within this time the player always got the time the server restarted. So some players could have night where others already got day again.

 

1.)

In dayz_server.pbo I've created a folder 'custom' and in 'custom' a file 'settime.sqf'. The content of the file:

     // Time sync
     _DateStamp=Date;
     setDate _DateStamp;
     PVDZE_plr_SetDate = _DateStamp;
     publicVariable "PVDZE_plr_SetDate";
     diag_log ("JAHANHIVE: Local Time set to " + str(_DateStamp));

 

This is called in the file 'compile/server_playerLogin.sqf' in the dayz_server.pbo.

In this file search for...

     while {_doLoop < 5} do {
    _key = format["CHILD:101:%1:%2:%3:",_playerID,dayZ_instance,_playerName];
    diag_log (_key);
        _key = format["\cache\players\%1\%2.sqf", MyPlayerCounter, _playerID];
        diag_log ("LOAD PLAYER: "+_key);
        _res = preprocessFile _key;
        diag_log ("PLAYER CACHE: "+_res);

 

...and add this after the lines above:

         ////////// settime for players
        onPlayerConnected "[_id, _name] execVM ""\z\addons\dayz_server\custom\settime.sqf""";

 

Repack the dayz_server.pbo, upload it to the server.

 

2.)

Create a file changetime.pl (e.g. in your server dir) with the following content (taken from DEVDs restarter.pl):

#!/usr/bin/perl
use warnings;
use strict;
use constant PATH      => '/home/dayzepoch/server1042/';

set_time  ();

sub set_time {
    print STDERR "Changing time in cache file.\n";
    my ($s, $m, $h, $day, $mon, $y) = localtime(time() - 5*3600);
    $y += 1900;
    $mon++;

    $m = ($m + 1); # if it's too unaccurate, you can +/- a minute or two
    my $file2 = PATH."cache/set_time.sqf";
    open  (IN, ">$file2") or die "Can't find $file2";
    # ["PASS", [year, month, day, hour, minute]]
    print IN '["PASS",[2013,8,3,'.$h.','.$m.']]'; # with full moon
    close (IN);
    print STDERR "Changed time in cache file.\n";
}

 

(Change PATH and the -5 in 'localtime(time() - 5*3600);' to your values.)

 

Create a crontab entry to execute that script every minute.

E.g.:

*/1 * * * * /home/dayz/server1042/changetime.pl >> /home/dayz/server1042/changetime.log 2>&1

(Change the paths for your settings.)

 

This will update cache/set_time.sqf every minute.

server_monitor.sqf in dayz_server.pbo/system is called with init.sqf from the mission pbo each time a player connects and in the default DEVD version cache/set_time.sqf is only updated once per server restart (I guess).

 

Restart the server now.

Wait a few minutes, connect to the server and the time on a watch ingame should be the expected (e.g. your localtime -5 hours or something).

 

Regards,

jahan.

Link to comment
Share on other sites

Very intresting. I had players report this aswell. I thought it was a trouble with my restart function and the server not loading the timezones properly. But since it's incidental and doesnt effect everyone you might be on to something.

Link to comment
Share on other sites

Hm, for me it happened all the time. When server restarted at 8:00 and I logged in at 9:00, I got 8:00 on my watch ingame...when I logged in at 10:00 I got 8:00 too. It seemed that the time for newly connecting players was fixed until the next restart. You don't recognize this too much if you login directly after the restart and stay in the game ,) You should see it if you take a look at a watch ingame, logout for 10 minutes. Relog and have a new look at the watch.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...