/// <summary> /// On RPC_PeerInfo on client, also ask server for admin status. /// </summary> /// <param name="orig"></param> /// <param name="self"></param> /// <param name="rpc"></param> /// <param name="pkg"></param> private void ZNet_RPC_PeerInfo(On.ZNet.orig_RPC_PeerInfo orig, ZNet self, ZRpc rpc, ZPackage pkg) { orig(self, rpc, pkg); if (ZNet.instance.IsClientInstance()) { ZRoutedRpc.instance.InvokeRoutedRPC(ZNet.instance.GetServerPeer().m_uid, nameof(RPC_Jotunn_IsAdmin), false); } }
// 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); }