diff --git a/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs b/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs index 272dac8..9e5f9ac 100644 --- a/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs +++ b/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs @@ -1,7 +1,6 @@ using DLatchPoke.Client.Keybindings; -using DLatchPoke.Client.Network; using DLatchPoke.Shared.Packets.C2S; -using EccsLogicWorldAPI.Client.Injectors; +using EccsLogicWorldAPI.Client.PacketIndexOrdering; using FancyInput; using LogicAPI.Client; using LogicAPI.Data; @@ -14,7 +13,6 @@ using LogicWorld.Players; namespace DLatchPoke.Client { public class DLatchPokeClient : ClientMod { public new static ILogicLogger Logger; - public static bool ServerSupportsMod = false; protected override void Initialize() { Logger = base.Logger; @@ -25,7 +23,7 @@ namespace DLatchPoke.Client { // Register the keybinding to enter the path analyzer game state FirstPersonInteraction.RegisterBuildingKeybinding(DLatchPokeTrigger.Poke, () => { - if (!ServerSupportsMod) { + if (!PacketIndexOrdering.doesServerSupportPacket(typeof(DLatchPokeRequest))) { Logger.Error("Server does not support this mod"); return false; } @@ -33,9 +31,9 @@ namespace DLatchPoke.Client { return PokeDLatch(); } ); - - // Inject packet handlers - RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version)); + + // Mark it as optional so that the game works even if the mod is not present on one end + PacketIndexOrdering.markModAsOptional(GetType().Assembly); Logger.Info("DLatchPoke mod loaded"); } diff --git a/DLatchPoke/DLatchPoke/src/client/network/AnnounceModPacketHandler.cs b/DLatchPoke/DLatchPoke/src/client/network/AnnounceModPacketHandler.cs deleted file mode 100644 index f822208..0000000 --- a/DLatchPoke/DLatchPoke/src/client/network/AnnounceModPacketHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using DLatchPoke.Shared.Packets.S2C; -using LogicWorld.SharedCode.Networking; - -namespace DLatchPoke.Client.Network { - public class AnnounceModPacketHandler : PacketHandler { - private readonly Version _version; - - public AnnounceModPacketHandler(Version version) { - _version = version; - } - - public override void Handle(AnnounceModPresence packet, HandlerContext context) { - if (packet.Version == _version) { - DLatchPokeClient.Logger.Info($"Mod is supported on the server: version={packet.Version}"); - DLatchPokeClient.ServerSupportsMod = true; - } else { - DLatchPokeClient.Logger.Error($"Mod version mismatch: client={_version}, server={packet.Version}"); - } - } - } -} \ No newline at end of file diff --git a/DLatchPoke/DLatchPoke/src/server/DLatchPokeServer.cs b/DLatchPoke/DLatchPoke/src/server/DLatchPokeServer.cs index 2ba9a32..cfaee01 100644 --- a/DLatchPoke/DLatchPoke/src/server/DLatchPokeServer.cs +++ b/DLatchPoke/DLatchPoke/src/server/DLatchPokeServer.cs @@ -1,68 +1,34 @@ -using System.Collections.Generic; -using System.Linq; using DLatchPoke.Server.Network; -using DLatchPoke.Shared.Packets.S2C; using EccsLogicWorldAPI.Server; using EccsLogicWorldAPI.Server.Injectors; -using EccsLogicWorldAPI.Shared.PacketWrapper; +using EccsLogicWorldAPI.Server.PacketIndexOrdering; using LogicAPI.Data; -using LogicAPI.Networking.Packets.Initialization; using LogicAPI.Server; using LogicAPI.Server.Components; -using LogicAPI.Server.Networking; -using LogicAPI.Server.Networking.ClientVerification; using LogicLog; using LogicWorld.LogicCode; using LogicWorld.Server.Circuitry; -using LogicWorld.SharedCode.Networking; namespace DLatchPoke.Server { // ReSharper disable once ClassNeverInstantiated.Global - public class DLatchPokeServer : ServerMod, IClientVerifier { + public class DLatchPokeServer : ServerMod { public new static ILogicLogger Logger; - private NetworkServer _networkServer; - private readonly Dictionary _playerHasMod = new Dictionary(); private static ICircuitryManager _circuits; protected override void Initialize() { Logger = base.Logger; Logger.Info("DLatchPoke server mod loading"); - _networkServer = ServiceGetter.getService(); - - // Inject client verifier: - RawJoinVerifierInjector.addVerifier(this); - PacketHandlerManager.getCustomPacketHandler() - .addHandlerToEnd(new ClientJoinedPacketHandler(this)); + // Register handler for client request packet RawPacketHandlerInjector.addPacketHandler(new DLatchPokeRequestHandler(this)); + + // Mark it as optional so that the game works even if the mod is not present on one end + PacketIndexOrdering.markModAsOptional(GetType().Assembly); _circuits = ServiceGetter.getService(); Logger.Info("DLatchPoke server mod loaded"); } - /// - /// Gets called before a player (client) joins the server. - /// Used to check if the player has this mod installed - /// - public void Verify(VerificationContext ctx) { - bool hasMod = ctx.ApprovalPacket.ClientMods.Contains((Manifest.ID, Manifest.Version)); - string playerName = ctx.PlayerID.Name; - _playerHasMod[playerName] = hasMod; - } - - /// - /// Gets called after verifying a connecting player. - /// If the player has this mod installed, send a packet informing about the mod's presence on the server. - /// - public void PlayerJoined(PlayerData playerData, HandlerContext context) { - _playerHasMod.TryGetValue(playerData.Name, out bool hasWireTracer); - if (hasWireTracer) { - _networkServer.Send(context.Sender, new AnnounceModPresence() { - Version = Manifest.Version - }); - } - } - /// /// Gets called from the DLatchPokeRequestHandler. /// Toggle the internal state of the DLatch diff --git a/DLatchPoke/DLatchPoke/src/server/network/ClientJoinedPacketHandler.cs b/DLatchPoke/DLatchPoke/src/server/network/ClientJoinedPacketHandler.cs deleted file mode 100644 index 500d584..0000000 --- a/DLatchPoke/DLatchPoke/src/server/network/ClientJoinedPacketHandler.cs +++ /dev/null @@ -1,16 +0,0 @@ -using EccsLogicWorldAPI.Shared.PacketWrapper; -using LogicAPI.Networking.Packets.Initialization; -using LogicWorld.SharedCode.Networking; - -namespace DLatchPoke.Server.Network { - public class ClientJoinedPacketHandler : CustomPacketHandler { - private readonly DLatchPokeServer _dLatchPokeServer; - public ClientJoinedPacketHandler(DLatchPokeServer dLatchPokeServer) { - _dLatchPokeServer = dLatchPokeServer; - } - - public override void handle(ref bool isCancelled, ref ClientLoadedWorldPacket packet, HandlerContext context) { - _dLatchPokeServer.PlayerJoined(packet.PlayerData, context); - } - } -} \ No newline at end of file diff --git a/DLatchPoke/DLatchPoke/src/shared/packets/s2c/AnnounceModPresence.cs b/DLatchPoke/DLatchPoke/src/shared/packets/s2c/AnnounceModPresence.cs deleted file mode 100644 index d0b7fbb..0000000 --- a/DLatchPoke/DLatchPoke/src/shared/packets/s2c/AnnounceModPresence.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using LogicAPI.Networking.Packets; -using MessagePack; - -namespace DLatchPoke.Shared.Packets.S2C { - [MessagePackObject] - public class AnnounceModPresence : Packet { - [Key(0)] public Version Version; - } -} \ No newline at end of file