public static void SaveService(CoreServiceInfo csi) { if (csi == null) { return; } csi.ToConsole("Saving..."); TryCatch(csi.SaveOptions, csi.ToConsole); if (csi.SaveSupported) { TryCatch(csi.GetSaveHandler(), csi.ToConsole); } TryCatch(csi.OnSaved, csi.ToConsole); if (OnServiceSaved != null) { TryCatch(() => OnServiceSaved(csi), csi.ToConsole); } csi.ToConsole("Done."); }
private static void OnCoreCommand(CommandEventArgs e) { if (e == null || e.Mobile == null || e.Mobile.Deleted) { return; } if (e.Arguments == null || e.Arguments.Length == 0) { new MenuGump( e.Mobile as PlayerMobile, null, new MenuGumpOptions( new[] { new ListGumpEntry("Help", () => OnCoreCommand(new CommandEventArgs(e.Mobile, e.Command, "?", new[] { "?" }))), new ListGumpEntry("Services", () => new CoreServiceListGump(e.Mobile as PlayerMobile).Send()), new ListGumpEntry("Modules", () => new CoreModuleListGump(e.Mobile as PlayerMobile).Send()) })).Send(); return; } switch (e.Arguments[0].ToLower()) { case "?": case "help": { e.Mobile.SendMessage(0x55, "Usage: {0}{1} <srv | mod | ? | help>", CommandSystem.Prefix, e.Command); e.Mobile.SendMessage(0x55, "Usage: srv <name> <ver | save>"); e.Mobile.SendMessage(0x55, "Usage: mod <name> <ver | save | enable | disable>"); } break; case "srv": { if (e.Arguments.Length < 2) { new CoreServiceListGump(e.Mobile as PlayerMobile).Send(); return; } string search = e.Arguments[1]; CoreServiceInfo info = _CoreServices.FirstOrDefault(csi => Insensitive.Contains(csi.Name, search)); if (info == null) { new CoreServiceListGump(e.Mobile as PlayerMobile).Send(); return; } if (e.Arguments.Length < 3) { e.Mobile.SendGump(new PropertiesGump(e.Mobile, info)); return; } switch (e.Arguments[2].ToLower()) { case "ver": case "version": e.Mobile.SendMessage(0x55, "{0} version: {1}", info.Name, info.Version); break; case "save": { Action sh = info.GetSaveHandler(); if (sh == null) { e.Mobile.SendMessage(0x22, "{0} does not implement the CSSave feature.", info.Name); return; } TryCatch(sh, ex => e.Mobile.SendMessage(0x22, "An error occured, check the logs for more information.")); } break; } } break; case "mod": { if (e.Arguments.Length < 2) { new CoreModuleListGump(e.Mobile as PlayerMobile).Send(); return; } string search = e.Arguments[1]; CoreModuleInfo info = _CoreModules.FirstOrDefault(cmi => Insensitive.Contains(cmi.Name, search)); if (info == null) { new CoreModuleListGump(e.Mobile as PlayerMobile).Send(); return; } if (e.Arguments.Length < 3) { e.Mobile.SendGump(new PropertiesGump(e.Mobile, info)); return; } switch (e.Arguments[2].ToLower()) { case "ver": case "version": e.Mobile.SendMessage(0x55, "{0} version: {1}", info.Name, info.Version); break; case "enable": { if (info.Enabled) { e.Mobile.SendMessage(0x22, "{0} is already enabled.", info.Name); } else { info.Enabled = true; e.Mobile.SendMessage(0x55, "{0} has been enabled.", info.Name); } } break; case "disable": { if (!info.Enabled) { e.Mobile.SendMessage(0x22, "{0} is already disabled.", info.Name); } else { info.Enabled = false; e.Mobile.SendMessage(0x55, "{0} has been disabled.", info.Name); } } break; case "save": { Action sh = info.GetSaveHandler(); if (sh == null) { e.Mobile.SendMessage(0x22, "{0} does not implement the CMSave feature.", info.Name); } else { TryCatch( sh, ex => { e.Mobile.SendMessage(0x22, "An error occured, check the logs for more information."); ToConsole(ex); }); } } break; } } break; } }