static void LoadConfig() { Logger.Instance.LogMessage("FTLAdmin.LoadConfig()"); try { var worldname = MyAPIGateway.Session.Name; worldname = Regex.Replace(worldname, "[<>:\"/\\|?*]", ""); // Remove invalid filename chars System.IO.TextReader reader = MyAPIGateway.Utilities.ReadFileInLocalStorage(string.Format(ConfigFileName, worldname), typeof(FTLAdmin)); var xmlData = reader.ReadToEnd(); Configuration = MyAPIGateway.Utilities.SerializeFromXML <FTLConfig>(xmlData); reader.Close(); Logger.Instance.Debug = Configuration.Debug; } catch (System.IO.FileNotFoundException) { // Config file doesn't exist, that's fine. Ignore the error. } catch (Exception ex) { Logger.Instance.LogMessage("FTLAdmin.LoadConfig() - Error"); Logger.Instance.LogMessage(ex.GetType().Name); Logger.Instance.LogException(ex); // Continue Processing } Globals.Reload(); FTLData.ReloadAll(); FTLInhibitor.ReloadAll(); }
public override void ProcessServer() { string message = string.Format("invalid {1} modifier: {0}", Type, ValueType.ToString().ToLowerInvariant()); List <MyTuple <ModifierType, float> > list = null; if (ValueType == ChangeType.Base) { list = FTLAdmin.Configuration.BaseValues; } else if (ValueType == ChangeType.Upgrade) { list = FTLAdmin.Configuration.Upgrades; } if (Reset) { MyTuple <ModifierType, float>?val = null; foreach (var entry in list) { if (entry.Item1 == Type) { val = entry; break; } } if (val == null) { message = string.Format("{1} modifier {0} already default", Type, ValueType.ToString().ToLowerInvariant()); } else { list.Remove(val.Value); message = string.Format("{1} modifier {0} reset to default", Type, ValueType.ToString().ToLowerInvariant()); } } else { bool found = false; for (int x = 0; x < list.Count; x++) { if (list[x].Item1 == Type) { var item = list[x]; item.Item2 = Modifier; list[x] = item; found = true; } } if (!found) { list.Add(new MyTuple <ModifierType, float>(Type, Modifier)); } message = string.Format("{2} modifier {0} set to {1}", Type, Modifier, ValueType.ToString().ToLowerInvariant()); } // Force reload all FTL data Globals.Reload(); FTLData.ReloadAll(); FTLInhibitor.ReloadAll(); MessageUtils.SendMessageToPlayer(SenderSteamId, new MessageChat() { Sender = Globals.ModName, MessageText = message }); }