using System; using System.Collections.Generic; using Network; using UnityEngine; using Newtonsoft.Json; namespace Oxide.Plugins { [Info("BackToTheCarpet", "MikeHawke", "1.0.0")] [Description("Send Custom Message if protocol is mis-matched")] class BackToTheCarpet : RustPlugin { private int ServerProt; void Unload() { } void Init() { ServerProt = Rust.Protocol.network; } void OnServerInitialized() { LoadConfigVariables(); SaveConfig(configData); } #region ConfigVar private ConfigData configData; class ConfigData { public Server ServerUpdateRequired = new Server(); public Client ClientUpdateRequired = new Client(); } class Server { [JsonProperty(PropertyName = "Server Update Required Message")] public string ServerMsg = "The Server Need Updating, Please Try Again Later"; } class Client { [JsonProperty(PropertyName = "Client Update Required Message")] public string ClientMsg = "Your Client Needs Updating, Close Client And Reload"; } #endregion private bool LoadConfigVariables() { try {configData = Config.ReadObject();} catch {return false;} SaveConfig(configData); return true; } protected override void LoadDefaultConfig() { Puts("Creating new config file."); var config = new ConfigData(); SaveConfig(config); } void SaveConfig(ConfigData config) { Config.WriteObject(config, true); } void OnClientAuth(Connection connection) { if (connection.protocol > ServerProt) { Network.Net.sv.Kick(connection, configData.ServerUpdateRequired.ServerMsg); NextTick(() => ServerMgr.Instance.connectionQueue.RemoveConnection(connection)); } if (connection.protocol < ServerProt) { Network.Net.sv.Kick(connection, configData.ClientUpdateRequired.ClientMsg); NextTick(() => ServerMgr.Instance.connectionQueue.RemoveConnection(connection)); } } } }