Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Release]Server Time PHP

Joined
Aug 16, 2006
Messages
1,251
Reaction score
199
Tired of this error?
Code:
ERROR: Cannot reach time server, reverting to local time

Here is a simple fix.

Following my Guide to Compiling

Open the server source. Navigate to org.pokenet.server.feature > TimeService.java

Find the comment in the source:
Code:
/*
			 * Parses time from a common server.
			 * The webpage should just have text (no html tags) in the form:
			 * DAY HOUR MINUTES
			 * where day is a number from 0 - 6
			 */

Below that will be a code, something like
Code:
URL url = new URL("http://pokedev.org/time.php");

Simply take the php code below, put it into your web server and put the url of the php into the code above.

Ex.
Code:
URL url = new URL("http://127.0.0.1/time.php");

Since its on your server, your the only one actually connecting to it when you start your server, so local host will suffice.

Simply save TimeService.java and compile the server.

Gl :D

TimeService PHP
PHP:
<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('America/Los_Angeles');

// Format for PokeNet 
// DAY HOUR MINUTES
// where day is a number from 0 - 6

// Prints something like: 2 5 30
echo date('w h i');

// Coded by -DefaulT for PokeNet servers
?>

Of course change the America/Los_Angeles to your time zone;



Ex:
-DefaulT - [Release]Server Time PHP - RaGEZONE Forums
 
Last edited:
Newbie Spellweaver
Joined
Apr 19, 2011
Messages
36
Reaction score
0
Tested and works, server wise only sadly. The server now doesn't debug the TimeService error message already, but on the client the time isn't correct, still. Fix?
 
Joined
Aug 16, 2006
Messages
1,251
Reaction score
199
Ill look into it, maybe there is something i need to do on the client as well.


I dont know why, but the clients time is setup differently.

Code:
package org.pokenet.client.backend.time;

import mdes.slick.sui.Label;

import org.newdawn.slick.Color;
import org.pokenet.client.GameClient;

/**
 * Handles time and rendering of night. Also acts as a label for usage in GUI
 * @author shadowkanji
 *
 */
public class TimeService extends Label implements Runnable {
	private int m_hour, m_minutes, m_daylight, m_targetDaylight;
	private Thread m_thread;
	
	/**
	 * Default constructor
	 */
	public TimeService() {
		super("00:00");
		this.pack();
		this.setLocation(4, 4);
		this.setVisible(true);
		this.setFont(GameClient.getFontLarge());
		this.setForeground(new Color(255, 255, 255));
		m_thread = new Thread(this);
	}
	
	/**
	 * Called by thread.start()
	 */
	public void run() {
		String min;
		String hour;
		while(true) {
			m_minutes = m_minutes == 59 ? 0 : m_minutes + 1;
			if(m_minutes == 0) {
				m_hour = m_hour == 23 ? 0 : m_hour + 1;
				switch(m_hour) {
				case 3:
					m_targetDaylight = 150;
					break;
				case 4:
					m_targetDaylight = 125;
					break;
				case 5:
					m_targetDaylight = 100;
					break;
				case 6:
					m_targetDaylight = 75;
					break;
				case 7:
					m_targetDaylight = 0;
					break;
				case 17:
					m_targetDaylight = 75;
					break;
				case 18:
					m_targetDaylight = 100;
					break;
				case 19:
					m_targetDaylight = 125;
					break;
				case 20:
					m_targetDaylight = 150;
					break;
				case 21:
					m_targetDaylight = 175;
					break;
				default:
					break;
				}
			}
			hour = m_hour < 10 ? "0" + String.valueOf(m_hour) : String.valueOf(m_hour);
			min = m_minutes < 10 ? "0" + String.valueOf(m_minutes) : String.valueOf(m_minutes);
			this.setText(hour + ":" + min);
			this.pack();
			try {
				Thread.sleep(60000);
			} catch (Exception e) {}
		}
	}
	
	/**
	 * Updates daylight
	 */
	public void updateDaylight() {
		if(m_daylight < m_targetDaylight)
			m_daylight++;
		else if(m_daylight > m_targetDaylight)
			m_daylight--;
	}

	/**
	 * Sets the current time and starts the time service
	 * @param hours
	 * @param minutes
	 */
	public void setTime(int hour, int minutes) {
		m_hour = hour;
		m_minutes = minutes;
		
		if(hour == 17) {
			m_daylight = 75;
			m_targetDaylight = 75;
		} else if(hour == 18) {
			m_daylight = 100;
			m_targetDaylight = 100;
		} else if(hour == 19) {
			m_daylight = 125;
			m_targetDaylight = 125;
		} else if(hour == 20) {
			m_daylight = 150;
			m_targetDaylight = 150;
		} else if(hour == 3) {
			m_daylight = 150;
			m_targetDaylight = 150;
		} else if(hour == 4) {
			m_daylight = 125;
			m_targetDaylight = 125;
		} else if(hour == 5) {
			m_daylight = 100;
			m_targetDaylight = 100;
		} else if(hour == 6) {
			m_daylight = 75;
			m_targetDaylight = 75;
		} else if(hour >= 8 && hour <= 17) {
			m_daylight = 0;
			m_targetDaylight = 0;
		} else {
			m_daylight = 175;
			m_targetDaylight = 175;
		}
		this.setText(hour + ":" + minutes);
		
		// Stop was causing this next part not to work for some reason...
		// hopefully this doesn't cause any problems if setTime gets called
		// in the future
		m_thread.start();
	}
	
	/**
	 * Returns true if it is night
	 * @return
	 */
	public boolean isNight() {
		return m_hour >= 18 && m_hour <= 7;
	}
	
	/**
	 * Returns the current daylight
	 * @return
	 */
	public int getDaylight() {
		return m_daylight;
	}
	
	/**
	 * Returns the target daylight
	 * @return
	 */
	public int getTargetDaylight() {
		return m_targetDaylight;
	}
}

As you can see, it starts out on 00:00, then it just +'s accordingly, then it continues on to change the daylight to the time. I believe this is because the Pokemon world time goes by faster?
 
Last edited:
凸(ಠ益ಠ)凸
Loyal Member
Joined
Jun 16, 2008
Messages
1,665
Reaction score
227
Ill look into it, maybe there is something i need to do on the client as well.


I dont know why, but the clients time is setup differently.

Code:
package org.pokenet.client.backend.time;

import mdes.slick.sui.Label;

import org.newdawn.slick.Color;
import org.pokenet.client.GameClient;

/**
 * Handles time and rendering of night. Also acts as a label for usage in GUI
 * @author shadowkanji
 *
 */
public class TimeService extends Label implements Runnable {
	private int m_hour, m_minutes, m_daylight, m_targetDaylight;
	private Thread m_thread;
	
	/**
	 * Default constructor
	 */
	public TimeService() {
		super("00:00");
		this.pack();
		this.setLocation(4, 4);
		this.setVisible(true);
		this.setFont(GameClient.getFontLarge());
		this.setForeground(new Color(255, 255, 255));
		m_thread = new Thread(this);
	}
	
	/**
	 * Called by thread.start()
	 */
	public void run() {
		String min;
		String hour;
		while(true) {
			m_minutes = m_minutes == 59 ? 0 : m_minutes + 1;
			if(m_minutes == 0) {
				m_hour = m_hour == 23 ? 0 : m_hour + 1;
				switch(m_hour) {
				case 3:
					m_targetDaylight = 150;
					break;
				case 4:
					m_targetDaylight = 125;
					break;
				case 5:
					m_targetDaylight = 100;
					break;
				case 6:
					m_targetDaylight = 75;
					break;
				case 7:
					m_targetDaylight = 0;
					break;
				case 17:
					m_targetDaylight = 75;
					break;
				case 18:
					m_targetDaylight = 100;
					break;
				case 19:
					m_targetDaylight = 125;
					break;
				case 20:
					m_targetDaylight = 150;
					break;
				case 21:
					m_targetDaylight = 175;
					break;
				default:
					break;
				}
			}
			hour = m_hour < 10 ? "0" + String.valueOf(m_hour) : String.valueOf(m_hour);
			min = m_minutes < 10 ? "0" + String.valueOf(m_minutes) : String.valueOf(m_minutes);
			this.setText(hour + ":" + min);
			this.pack();
			try {
				Thread.sleep(60000);
			} catch (Exception e) {}
		}
	}
	
	/**
	 * Updates daylight
	 */
	public void updateDaylight() {
		if(m_daylight < m_targetDaylight)
			m_daylight++;
		else if(m_daylight > m_targetDaylight)
			m_daylight--;
	}

	/**
	 * Sets the current time and starts the time service
	 * @param hours
	 * @param minutes
	 */
	public void setTime(int hour, int minutes) {
		m_hour = hour;
		m_minutes = minutes;
		
		if(hour == 17) {
			m_daylight = 75;
			m_targetDaylight = 75;
		} else if(hour == 18) {
			m_daylight = 100;
			m_targetDaylight = 100;
		} else if(hour == 19) {
			m_daylight = 125;
			m_targetDaylight = 125;
		} else if(hour == 20) {
			m_daylight = 150;
			m_targetDaylight = 150;
		} else if(hour == 3) {
			m_daylight = 150;
			m_targetDaylight = 150;
		} else if(hour == 4) {
			m_daylight = 125;
			m_targetDaylight = 125;
		} else if(hour == 5) {
			m_daylight = 100;
			m_targetDaylight = 100;
		} else if(hour == 6) {
			m_daylight = 75;
			m_targetDaylight = 75;
		} else if(hour >= 8 && hour <= 17) {
			m_daylight = 0;
			m_targetDaylight = 0;
		} else {
			m_daylight = 175;
			m_targetDaylight = 175;
		}
		this.setText(hour + ":" + minutes);
		
		// Stop was causing this next part not to work for some reason...
		// hopefully this doesn't cause any problems if setTime gets called
		// in the future
		m_thread.start();
	}
	
	/**
	 * Returns true if it is night
	 * @return
	 */
	public boolean isNight() {
		return m_hour >= 18 && m_hour <= 7;
	}
	
	/**
	 * Returns the current daylight
	 * @return
	 */
	public int getDaylight() {
		return m_daylight;
	}
	
	/**
	 * Returns the target daylight
	 * @return
	 */
	public int getTargetDaylight() {
		return m_targetDaylight;
	}
}

As you can see, it starts out on 00:00, then it just +'s accordingly, then it continues on to change the daylight to the time. I believe this is because the Pokemon world time goes by faster?

welcome considering it is a game, the time would go faster... it would be nice to have real time day and night.
 
Junior Spellweaver
Joined
Dec 21, 2009
Messages
188
Reaction score
40
Thanks but my client weirdly fixed the error itself.
 
Newbie Spellweaver
Joined
Oct 21, 2011
Messages
12
Reaction score
0
mrs: pleace, I want to ask you post or write all the home servers or profesional servers you have of Pokenet that exist in this moment online for play best reggards.
 
Back
Top