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