Implement server time spoofer

This commit is contained in:
Melledy
2024-01-01 04:56:59 -08:00
parent 5b1218d09d
commit 6da87a4a1f
5 changed files with 38 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
package emu.lunarcore;
import java.util.Date;
import java.util.List;
import java.util.Set;
@@ -22,6 +23,7 @@ public class Config {
public GameServerConfig gameServer = new GameServerConfig(23301);
public ServerOptions serverOptions = new ServerOptions();
public ServerTime serverTime = new ServerTime();
public ServerRates serverRates = new ServerRates();
public LogOptions logOptions = new LogOptions();
public DownloadData downloadData = new DownloadData();
@@ -107,6 +109,12 @@ public class Config {
}
}
@Getter
public static class ServerTime {
public boolean spoofTime = false;
public Date spoofDate = new Date(1705276800000L); // January 15, 2024 12:00:00 AM (GMT)
}
@Getter
public static class ServerOptions {
public boolean autoCreateAccount = true;

View File

@@ -43,6 +43,8 @@ public class LunarCore {
private static LineReaderImpl reader;
@Getter private static boolean usingDumbTerminal;
private static long timeOffset = 0;
static {
// Setup console reader
@@ -58,6 +60,7 @@ public class LunarCore {
// Load config
LunarCore.loadConfig();
LunarCore.updateServerTimeOffset();
}
public static void main(String[] args) {
@@ -195,7 +198,12 @@ public class LunarCore {
public static void saveConfig() {
try (FileWriter file = new FileWriter(configFile)) {
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
Gson gson = new GsonBuilder()
.setDateFormat("dd-MM-yyyy hh:mm:ss")
.setPrettyPrinting()
.serializeNulls()
.create();
file.write(gson.toJson(config));
} catch (Exception e) {
getLogger().error("Config save error");
@@ -241,6 +249,22 @@ public class LunarCore {
return builder.toString();
}
}
/**
* 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;
}
private static void updateServerTimeOffset() {
var timeOptions = LunarCore.getConfig().getServerTime();
if (timeOptions.isSpoofTime() && timeOptions.getSpoofDate() != null) {
timeOffset = timeOptions.getSpoofDate().getTime() - System.currentTimeMillis();
} else {
timeOffset = 0;
}
}
// Server console

View File

@@ -1,5 +1,6 @@
package emu.lunarcore.server.packet.send;
import emu.lunarcore.LunarCore;
import emu.lunarcore.proto.PlayerHeartbeatScRspOuterClass.PlayerHeartbeatScRsp;
import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId;
@@ -11,7 +12,7 @@ public class PacketPlayerHeartBeatScRsp extends BasePacket {
var data = PlayerHeartbeatScRsp.newInstance()
.setClientTimeMs(clientTime)
.setServerTimeMs(System.currentTimeMillis());
.setServerTimeMs(LunarCore.currentServerTime());
this.setData(data);
}

View File

@@ -1,6 +1,7 @@
package emu.lunarcore.server.packet.send;
import emu.lunarcore.GameConstants;
import emu.lunarcore.LunarCore;
import emu.lunarcore.proto.PlayerLoginScRspOuterClass.PlayerLoginScRsp;
import emu.lunarcore.server.game.GameSession;
import emu.lunarcore.server.packet.BasePacket;
@@ -14,7 +15,7 @@ public class PacketPlayerLoginScRsp extends BasePacket {
var data = PlayerLoginScRsp.newInstance()
.setBasicInfo(session.getPlayer().toProto())
.setCurTimezone(GameConstants.CURRENT_TIMEZONE)
.setServerTimestampMs(System.currentTimeMillis())
.setServerTimestampMs(LunarCore.currentServerTime())
.setStamina(session.getPlayer().getStamina());
this.setData(data);

View File

@@ -13,7 +13,7 @@ import com.google.gson.reflect.TypeToken;
import emu.lunarcore.LunarCore;
public class JsonUtils {
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final Gson gson = new GsonBuilder().setDateFormat("dd-MM-yyyy hh:mm:ss").setPrettyPrinting().create();
private static final Gson gsonCompact = new GsonBuilder().create();
public static Gson getGsonFactory() {