Page 1 of 1

How to change server time?

Posted: Fri Nov 08, 2013 8:50 am
by Amida
If you want to receive support we need this info to help you properly.
» Find Revision
L2J Revision Number:
L2JDP Revision Number:

Hi, I have the private server run in CentOS server, my server time is correct (GMT +7) but game time not correct. Please guide me how to fix it?

Re: How to change server time?

Posted: Fri Nov 08, 2013 11:48 pm
by Hyrelius
Hi there,

as far as I am aware, you currently cannot change gametime (ingame game time, which displays on the map of each player). I have written such a method myself, but it still isn't perfect. It lets me adjust the time though.

The class you should have a look at, is "GameTimeController". I simply added a setter method for the time. It seems to adjust the time (along with sending the proper packet to all available players), but the conversion from server time to ingame-time is a bit difficult.

Added setGameTime in GameTimeController.java:

Code: Select all

     public final void setGameTime(int hour, int minute, int second)    {        final Calendar c = Calendar.getInstance();        c.set(Calendar.HOUR_OF_DAY, hour);        c.set(Calendar.MINUTE, minute);        c.set(Calendar.SECOND, second);        c.set(Calendar.MILLISECOND, 0);        _referenceTime = c.getTimeInMillis();    } 
Created "GameTime"-L2Script, which adds the admin commands "settime" (admin_settime) and "srt" (admin_srt).
The code still contains errors, but you get the idea. I didn't have time to fix them yet.

Code: Select all

 package custom.nocturne.handler.voice.gametime; import java.util.Calendar;import java.util.logging.Level; import com.l2jserver.gameserver.GameTimeController;import com.l2jserver.gameserver.handler.AdminCommandHandler;import com.l2jserver.gameserver.handler.IAdminCommandHandler;import com.l2jserver.gameserver.model.L2World;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;import com.l2jserver.gameserver.model.interfaces.IL2Procedure;import com.l2jserver.gameserver.model.quest.Quest;import com.l2jserver.gameserver.network.serverpackets.ClientSetTime;import com.l2jserver.gameserver.scripting.scriptengine.impl.L2Script; import custom.nocturne.locale.Locale; public class GameTime extends L2Script implements IAdminCommandHandler {     // Attributes    private static final String[] GAMETIME_COMMANDS = { "admin_settime", "admin_srt" };    private static final int INITIAL_HOUR = 12;     public static void main(final String[] args) {        AdminCommandHandler.getInstance().registerHandler(new GameTime());    }     public GameTime() {        super(0, GameTime.class.getName(), GameTime.class.getName());        Quest._log.log(                Level.INFO,                "GameTime"                        + Locale.getInstance()                                .getLocalizedValue("has_been_loaded_successfully", Locale.getInstance().getLanguages().get(0)));    }     private void setGameTime(final int ingameHour, final int ingameMinute) {        // 9:27 ; 0:00 ; 7:25        final int ingameMinutes = ingameHour * 60 + ingameMinute; // 567 ; 0 ; 444        System.out.println("ingameMinutes: " + ingameMinutes);        final int ingameCurrentMinutes = Calendar.getInstance().get(Calendar.MINUTE) * 6; // 36 * 6 = 216 ; 216 ; 24        System.out.println("ingameCurrentMinutes: " + ingameCurrentMinutes);        final int totalIngameMinutes = 720 - (ingameMinutes + ingameCurrentMinutes); // 783 ; 216 ; 468        System.out.println("totalIngameMinutes: " + totalIngameMinutes);        final double totalReallifeMinutes = (double) totalIngameMinutes / (double) 6; // 130,5 ; 36 ; 78        System.out.println("totalReallifeMinutes: " + totalReallifeMinutes);         final double totalReallifeSetHour = Math.floor(totalReallifeMinutes / 60); // 2 ; 0 ; 1        System.out.println("totalReallifeSetHour: " + totalReallifeSetHour);        final double totalReallifeSetMinutes = Math.floor(totalReallifeMinutes % 60); // 10 ; 0 ; 18        System.out.println("totalReallifeSetMinutes: " + totalReallifeSetMinutes);        final double totalReallifeSetSeconds = Math.floor(((totalReallifeMinutes % 60) - totalReallifeSetMinutes) * 60); // 0,5 ; 0 ; 0        System.out.println("totalReallifeSetSeconds: " + totalReallifeSetSeconds);         // 2 hours, 10 minutes, 30 seconds, 36 minutes current time        // 12:00 - 12:00 - 01:00 - 00:03 + 03:36 =        // 22:57 + 03:36 =        // 2:33         // 0 hours, 36 minutes, 0 seconds, 36 minutes current time        // 12:00 - 0 - 3:36 - 0 + 3:36 =        // 12:00 - 0 =        // 12:00         // 1 hours, 18 minutes, 0 seconds, 4 minutes current time        // 12:00 - 6:00 - 1:48 - 0 + 0:24 =        // 06:00 - 1:48 + 0:24 =        // 06:00 - 1:24 =        // 04:36        // 12:00 - 04:36 = 7:24         GameTimeController.getInstance().setGameTime((int) totalReallifeSetHour, (int) totalReallifeSetMinutes,                (int) totalReallifeSetSeconds);         L2World.getInstance().forEachPlayer(new ForEachPlayerSetClientTime());    }     @Override    public boolean useAdminCommand(final String command, final L2PcInstance character) {        boolean executeCommand = false;        System.out.println("COMMAND: " + command);        if (command.contains(GameTime.GAMETIME_COMMANDS[0]) && character.isGM()) {            final int commandLength = command.trim().split(" ").length;            String time = "";            if (commandLength < 1 || commandLength > 2) {                character.sendMessage("Sets the ingame time; use 24h notation\nUsage: //setingametime HH:mm");            } else if (commandLength == 2) {                time = command.split(" ")[1].trim();                if (time.split(":").length != 2) {                    character.sendMessage("Sets the ingame time; use 24h notation\nUsage: //setingametime HH:mm");                } else {                    executeCommand = true;                }            }             if (executeCommand) {                final int hours = Integer.parseInt(time.split(":")[0]);                final int minutes = Integer.parseInt(time.split(":")[1]);                character.sendMessage("Setting ingame time to " + hours + ":" + minutes + "...");                setGameTime(hours, minutes);            }        } else if (command.contains("srt") && character.isGM()) {            System.out.println("setting raw time");            final int commandLength = command.trim().split(" ").length;            String time = "";            if (commandLength < 1 || commandLength > 2) {                character.sendMessage("Sets the ingame time; use 24h notation\nUsage: //setingametime HH:mm");            } else if (commandLength == 2) {                time = command.split(" ")[1].trim();                if (time.split(":").length != 3) {                    character.sendMessage("Sets the ingame time; use 24h notation\nUsage: //setingametime HH:mm");                } else {                    executeCommand = true;                }            }             if (executeCommand) {                final int hours = Integer.parseInt(time.split(":")[0]);                final int minutes = Integer.parseInt(time.split(":")[1]);                final int seconds = Integer.parseInt(time.split(":")[2]);                character.sendMessage("Setting ingame time to " + hours + ":" + minutes + ":" + seconds + "...");                GameTimeController.getInstance().setGameTime(hours, minutes, seconds);            }        }        return executeCommand;    }     @Override    public String[] getAdminCommandList() {        return GameTime.GAMETIME_COMMANDS;    }     /**     * This internal IL2Procedure enables us to swiftly iterate over all online players and output the corresponding message in the language     * chosen by each player.     *      * @author divStarHQ     *      */    private static final class ForEachPlayerSetClientTime implements IL2Procedure<L2PcInstance> {         @Override        public final boolean execute(final L2PcInstance player) {            if ((player != null) && player.isOnline()) {                player.sendPacket(ClientSetTime.STATIC_PACKET);            }            return true;        }    }} 
I hope I understood your question. If not - please do ignore my post.