mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-12 21:34:35 +01:00
Fix some time related bugs when spoofing server time
This commit is contained in:
@@ -254,7 +254,14 @@ public class LunarCore {
|
||||
* Returns the current server's time in milliseconds to send to the client. Can be used to spoof server time.
|
||||
*/
|
||||
public static long currentServerTime() {
|
||||
return System.currentTimeMillis() + timeOffset;
|
||||
return convertToServerTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a timestamp (in milliseconds) to the server time
|
||||
*/
|
||||
public static long convertToServerTime(long time) {
|
||||
return time + timeOffset;
|
||||
}
|
||||
|
||||
private static void updateServerTimeOffset() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package emu.lunarcore.game.chat;
|
||||
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.proto.ChatOuterClass.Chat;
|
||||
import emu.lunarcore.proto.MsgTypeOuterClass.MsgType;
|
||||
import lombok.Getter;
|
||||
@@ -15,7 +16,7 @@ public class ChatMessage {
|
||||
public ChatMessage(int fromUid, int toUid) {
|
||||
this.fromUid = fromUid;
|
||||
this.toUid = toUid;
|
||||
this.time = System.currentTimeMillis() / 1000;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public ChatMessage(int fromUid, int toUid, String text) {
|
||||
@@ -35,7 +36,7 @@ public class ChatMessage {
|
||||
public Chat toProto() {
|
||||
var proto = Chat.newInstance()
|
||||
.setSenderUid(this.getFromUid())
|
||||
.setSentTime(this.getTime())
|
||||
.setSentTime(LunarCore.convertToServerTime(this.getTime()) / 1000)
|
||||
.setMsgType(this.getType())
|
||||
.setEmote(this.getEmote());
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package emu.lunarcore.game.scene;
|
||||
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.proto.BuffInfoOuterClass.BuffInfo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -52,7 +53,7 @@ public class SceneBuff {
|
||||
.setBuffId(this.getBuffId())
|
||||
.setLevel(this.getBuffLevel())
|
||||
.setBaseAvatarId(this.getCasterAvatarId())
|
||||
.setAddTimeMs(this.getCreateTime())
|
||||
.setAddTimeMs(LunarCore.convertToServerTime(this.getCreateTime()))
|
||||
.setLifeTime(this.getDuration())
|
||||
.setCount(this.getCount());
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package emu.lunarcore.game.scene.entity;
|
||||
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.data.excel.SummonUnitExcel;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
@@ -53,7 +54,7 @@ public class EntitySummonUnit implements GameEntity {
|
||||
public SceneEntityInfo toSceneEntityProto() {
|
||||
var summon = SceneSummonUnitInfo.newInstance()
|
||||
.setLifeTimeMs(this.getDuration())
|
||||
.setCreateTimeMs(this.getCreateTime())
|
||||
.setCreateTimeMs(LunarCore.convertToServerTime(this.getCreateTime()))
|
||||
.setCasterEntityId(this.getCaster().getEntityId())
|
||||
.setAttachEntityId(this.getAttachedEntityId())
|
||||
.setSummonUnitId(this.getExcel().getId());
|
||||
|
||||
Reference in New Issue
Block a user