source: binary-improvements/7dtd-server-fixes/src/CustomCommands/GetGamePrefs.cs@ 177

Last change on this file since 177 was 130, checked in by alloc, 10 years ago

Fixes

File size: 1.9 KB
RevLine 
[83]1using System;
2using System.Collections.Generic;
3
[130]4namespace AllocsFixes.CustomCommands
[83]5{
[130]6 public class GetGamePrefs : ConsoleCommand
7 {
8 private string[] forbiddenPrefs = new string[] {
[83]9 "telnet",
10 "adminfilename",
11 "controlpanel",
12 "password",
13 "savegamefolder",
14 "options",
15 "last"
16 };
17
[130]18 private bool prefAccessAllowed (EnumGamePrefs gp)
19 {
20 string gpName = gp.ToString ().ToLower ();
21 foreach (string s in forbiddenPrefs) {
22 if (gpName.Contains (s)) {
23 return false;
24 }
[83]25 }
[130]26 return true;
[83]27 }
28
[130]29 public GetGamePrefs (ConsoleSdtd cons) : base(cons)
30 {
31 }
[83]32
[130]33 public override string Description ()
34 {
35 return "gets a game pref";
36 }
[83]37
[130]38 public override string[] Names ()
[83]39 {
[130]40 return new string[]
41 {
[83]42 "getgamepref",
43 "gg"
44 };
[130]45 }
[83]46
[130]47 public override void Run (string[] _params)
48 {
49 try {
50 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last;
[91]51
[130]52 if (_params.Length > 0) {
53 try {
54 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0]));
55 } catch (Exception) {
56 }
[103]57 }
[91]58
[130]59 if (enumGamePrefs == EnumGamePrefs.Last) {
60 SortedList<string, string> sortedList = new SortedList<string, string> ();
61 foreach (EnumGamePrefs gp in Enum.GetValues(typeof(EnumGamePrefs))) {
62 if ((_params.Length == 0) || (gp.ToString ().ToLower ().Contains (_params [0].ToLower ()))) {
63 if (prefAccessAllowed (gp)) {
64 sortedList.Add (gp.ToString (), string.Format ("{0} = {1}", gp.ToString (), GamePrefs.GetObject (gp)));
65 }
[103]66 }
[91]67 }
[130]68 foreach (string s in sortedList.Keys) {
69 m_Console.SendResult (sortedList [s]);
70 }
71 } else {
72 if (prefAccessAllowed (enumGamePrefs))
73 m_Console.SendResult (string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs)));
74 else
75 m_Console.SendResult ("Access to requested preference is forbidden");
[91]76 }
[130]77 } catch (Exception e) {
78 Log.Out ("Error in GetGamePrefs.Run: " + e);
[83]79 }
80 }
81 }
82}
Note: See TracBrowser for help on using the repository browser.