前端获取服务器时间
parent
64b0a75b7e
commit
c9ead9d4d3
|
@ -28,6 +28,7 @@ public class CBean2Proto {
|
|||
.setCurMapId((maxMapId == 0 && mapId == 0) ? 100 : mapId)
|
||||
.setEnergy(playerManager.getEnergy())
|
||||
.setLastUpdateEnergyTime(playerManager.getLastUpdateEnergyTime())
|
||||
.setServerTime((int)(System.currentTimeMillis()/1000))
|
||||
.build();
|
||||
return player;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import com.ljsd.jieling.protocols.MessageTypeProto;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class MessageUtil {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MessageUtil.class);
|
||||
|
@ -21,6 +23,7 @@ public class MessageUtil {
|
|||
} else {
|
||||
backMessage = generatedMessage.toByteArray();
|
||||
}
|
||||
|
||||
int length = PackageConstant.UID_FIELD_LEN + PackageConstant.TOKEN_LEN
|
||||
+ PackageConstant.MSG_ID_FIELD_LEN + PackageConstant.INDEX_FIELD_LEN
|
||||
+ PackageConstant.RESULT_LEN + backMessage.length;
|
||||
|
@ -61,8 +64,9 @@ public class MessageUtil {
|
|||
}
|
||||
|
||||
public static void sendHeartBeat(ISession session) {
|
||||
int now = (int)(System.currentTimeMillis()/1000);
|
||||
int length = PackageConstant.UID_FIELD_LEN + PackageConstant.TOKEN_LEN
|
||||
+ PackageConstant.MSG_ID_FIELD_LEN ;
|
||||
+ PackageConstant.MSG_ID_FIELD_LEN + 4 ;
|
||||
byte[] bytes = new byte[length];
|
||||
int pos = 0;
|
||||
Tea.intToByte(bytes, pos, session.getUid());
|
||||
|
@ -70,6 +74,8 @@ public class MessageUtil {
|
|||
Tea.intToByte(bytes, pos, session.getToken());
|
||||
pos += PackageConstant.TOKEN_LEN;
|
||||
Tea.intToByte(bytes, pos, MessageTypeProto.MessageType.HEART_BEAT_RESPONSE_VALUE);
|
||||
pos +=4;
|
||||
Tea.intToByte(bytes, pos, now);
|
||||
byte[] byteBuf = Tea.encrypt2(bytes, Tea.KEY);
|
||||
session.writeAndFlush(byteBuf);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue