protected override void SharedApplyAbstractValueToConfig(IServerRatesConfig ratesConfig, ushort value) { ratesConfig.Set(this.Id, value, this.ValueDefault, this.Description); }
public void SharedApplyToConfig(IServerRatesConfig ratesConfig, object value) { if (typeof(TValue) == typeof(bool) && value is int x) { value = x == 1; } if (value is TValue convertedValue) { this.SharedApplyAbstractValueToConfig(ratesConfig, convertedValue); return; } try { convertedValue = (TValue)Convert.ChangeType(value, typeof(TValue)); this.SharedApplyAbstractValueToConfig(ratesConfig, convertedValue); return; } catch { // cannot convert } Api.Logger.Error("Incorrect value type " + value + " " + value?.GetType().FullName + " for " + this); }
private static bool HasChanges(IServerRatesConfig otherRatesConfig) { var currentRates = RatesManager.Rates.ToDictionary(r => r, r => r.SharedAbstractValue); var currentRatesConfig = Api.Client.Core.CreateNewServerRatesConfig(); foreach (var rate in currentRates) { rate.Key.SharedApplyToConfig(currentRatesConfig, rate.Value); } return(!currentRatesConfig.IsMatches(otherRatesConfig)); }
public static void ClientConfigureRatesOnServer(IServerRatesConfig ratesConfig) { if (Client.CurrentGame.ConnectionState != ConnectionState.Connected) { throw new Exception("Not connected"); } var address = Client.CurrentGame.ServerInfo.ServerAddress; var isLocalServer = address.IsLocalServer; if (!isLocalServer && !ServerOperatorSystem.SharedIsOperator(ClientCurrentCharacterHelper.Character)) { throw new Exception( "Cannot change rates for current server - the player must be a server operator or connect to a local server"); } instance.CallServer(_ => _.ServerRemote_SetRatesConfig(ratesConfig.ToDictionary())); }
protected abstract void SharedApplyAbstractValueToConfig(IServerRatesConfig ratesConfig, TValue value);