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; package emu.lunarcore;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -22,6 +23,7 @@ public class Config {
public GameServerConfig gameServer = new GameServerConfig(23301); public GameServerConfig gameServer = new GameServerConfig(23301);
public ServerOptions serverOptions = new ServerOptions(); public ServerOptions serverOptions = new ServerOptions();
public ServerTime serverTime = new ServerTime();
public ServerRates serverRates = new ServerRates(); public ServerRates serverRates = new ServerRates();
public LogOptions logOptions = new LogOptions(); public LogOptions logOptions = new LogOptions();
public DownloadData downloadData = new DownloadData(); 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 @Getter
public static class ServerOptions { public static class ServerOptions {
public boolean autoCreateAccount = true; public boolean autoCreateAccount = true;

View File

@@ -44,6 +44,8 @@ public class LunarCore {
private static LineReaderImpl reader; private static LineReaderImpl reader;
@Getter private static boolean usingDumbTerminal; @Getter private static boolean usingDumbTerminal;
private static long timeOffset = 0;
static { static {
// Setup console reader // Setup console reader
try { try {
@@ -58,6 +60,7 @@ public class LunarCore {
// Load config // Load config
LunarCore.loadConfig(); LunarCore.loadConfig();
LunarCore.updateServerTimeOffset();
} }
public static void main(String[] args) { public static void main(String[] args) {
@@ -195,7 +198,12 @@ public class LunarCore {
public static void saveConfig() { public static void saveConfig() {
try (FileWriter file = new FileWriter(configFile)) { 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)); file.write(gson.toJson(config));
} catch (Exception e) { } catch (Exception e) {
getLogger().error("Config save error"); getLogger().error("Config save error");
@@ -242,6 +250,22 @@ 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;
}
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 // Server console
private static void startConsole() { private static void startConsole() {

View File

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

View File

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

View File

@@ -13,7 +13,7 @@ import com.google.gson.reflect.TypeToken;
import emu.lunarcore.LunarCore; import emu.lunarcore.LunarCore;
public class JsonUtils { 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(); private static final Gson gsonCompact = new GsonBuilder().create();
public static Gson getGsonFactory() { public static Gson getGsonFactory() {