Server now sends time to clients periodically

This commit is contained in:
Light2
2013-07-08 13:39:26 +02:00
parent 9e8eea30a1
commit 323ce803eb
3 changed files with 57 additions and 4 deletions
+2 -2
View File
@@ -39,12 +39,12 @@ public class ServerTimeMessage extends SWGMessage {
}
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);;
IoBuffer result = IoBuffer.allocate(14).order(ByteOrder.LITTLE_ENDIAN);;
result.putShort((short)2);
result.putInt(0x2EBC3BD9);
result.putLong(time); //time in milliseconds
return result;
return result.flip();
}
}
+1 -1
View File
@@ -135,7 +135,7 @@ public class LoginService implements INetworkDispatch{
LoginClientToken clientToken = new LoginClientToken(client.getSessionKey(), id, user);
CharacterCreationDisabled charCreationDisabled = new CharacterCreationDisabled(0);
StationIdHasJediSlot jediSlot = new StationIdHasJediSlot(false);
ServerNowEpochTime time = new ServerNowEpochTime(0);
ServerNowEpochTime time = new ServerNowEpochTime((int) (System.currentTimeMillis() / 1000));
session.write(time.serialize());
session.write(clientToken.serialize());
+54 -1
View File
@@ -21,6 +21,59 @@
******************************************************************************/
package services;
public class PlayerService {
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.ServerTimeMessage;
import main.NGECore;
import engine.clients.Client;
import engine.resources.service.INetworkDispatch;
import engine.resources.service.INetworkRemoteEvent;
public class PlayerService implements INetworkDispatch {
private NGECore core;
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
public PlayerService(final NGECore core) {
this.core = core;
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
ServerTimeMessage time = new ServerTimeMessage(System.currentTimeMillis() / 1000);
IoBuffer packet = time.serialize();
synchronized(core.getActiveConnectionsMap()) {
for(Client c : core.getActiveConnectionsMap().values()) {
if(c.getParent() != null) {
c.getSession().write(packet);
}
}
}
}
}, 1, 1, TimeUnit.MINUTES);
}
@Override
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> arg0,
Map<Integer, INetworkRemoteEvent> arg1) {
// TODO Auto-generated method stub
}
@Override
public void shutdown() {
// TODO Auto-generated method stub
}
}