|
|
|
@ -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<string, bool> _playerHasMod = new Dictionary<string, bool>();
|
|
|
|
|
private static ICircuitryManager _circuits;
|
|
|
|
|
|
|
|
|
|
protected override void Initialize() {
|
|
|
|
|
Logger = base.Logger;
|
|
|
|
|
Logger.Info("DLatchPoke server mod loading");
|
|
|
|
|
|
|
|
|
|
_networkServer = ServiceGetter.getService<NetworkServer>();
|
|
|
|
|
|
|
|
|
|
// Inject client verifier:
|
|
|
|
|
RawJoinVerifierInjector.addVerifier(this);
|
|
|
|
|
PacketHandlerManager.getCustomPacketHandler<ClientLoadedWorldPacket>()
|
|
|
|
|
.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<ICircuitryManager>();
|
|
|
|
|
Logger.Info("DLatchPoke server mod loaded");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets called before a player (client) joins the server.
|
|
|
|
|
/// Used to check if the player has this mod installed
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Verify(VerificationContext ctx) {
|
|
|
|
|
bool hasMod = ctx.ApprovalPacket.ClientMods.Contains(Manifest.ID);
|
|
|
|
|
string playerName = ctx.PlayerID.Name;
|
|
|
|
|
_playerHasMod[playerName] = hasMod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
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
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets called from the DLatchPokeRequestHandler.
|
|
|
|
|
/// Toggle the internal state of the DLatch
|
|
|
|
|