// Hook RPC_PeerInfo to check in front of the original method private static void ZNet_RPC_PeerInfo(On.ZNet.orig_RPC_PeerInfo orig, ZNet self, ZRpc rpc, ZPackage pkg) { if (ZNet.instance.IsServerInstance() || ZNet.instance.IsLocalInstance()) { try { var clientVersion = new ModuleVersionData(clientVersions[rpc.GetSocket().GetEndPointString()]); var serverVersion = new ModuleVersionData(GetEnforcableMods().ToList()); // Remove from list clientVersions.Remove(rpc.GetSocket().GetEndPointString()); // Compare and disconnect when not equal if (!clientVersion.Equals(serverVersion)) { rpc.Invoke("Error", 3); return; } } catch (EndOfStreamException) { Logger.LogError("Reading beyond end of stream. Probably client without Jotunn tried to connect."); // Client did not send appended package, just disconnect with the incompatible version error rpc.Invoke("Error", 3); return; } catch (KeyNotFoundException ex) { // Vanilla client trying to connect? // Check mods, if there are some installed on the server which need also to be on the client if (GetEnforcableMods().Any(x => x.Item3 == CompatibilityLevel.EveryoneMustHaveMod)) { // There is a mod, which needs to be client side too // Lets disconnect the vanilla client with Incompatible Version message rpc.Invoke("Error", 3); return; } } } else { // If we got this far on client side, clear lastServerVersion again lastServerVersion = null; } // call original method orig(self, rpc, pkg); }
/// <summary> /// Store server's message. /// </summary> /// <param name="sender"></param> /// <param name="data"></param> private static void RPC_Jotunn_ReceiveVersionData(ZRpc sender, ZPackage data) { Logger.LogDebug($"Received Version package from {sender.m_socket.GetEndPointString()}"); if (!ZNet.instance.IsClientInstance()) { clientVersions[sender.m_socket.GetEndPointString()] = data; var clientVersion = new ModuleVersionData(clientVersions[sender.GetSocket().GetEndPointString()]); var serverVersion = new ModuleVersionData(GetEnforcableMods().ToList()); if (!clientVersion.Equals(serverVersion)) { // Disconnect if mods are not network compatible sender.Invoke("Error", 3); } } else { lastServerVersion = data; } }