Fix some time related bugs when spoofing server time

This commit is contained in:
Melledy
2024-01-01 16:56:16 -08:00
parent 9170768d6f
commit 5c935fba76
4 changed files with 15 additions and 5 deletions

View File

@@ -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() {

View File

@@ -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());

View File

@@ -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());

View File

@@ -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());