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

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

Fixes

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands
5{
6 public class GetGamePrefs : ConsoleCommand
7 {
8 private string[] forbiddenPrefs = new string[] {
9 "telnet",
10 "adminfilename",
11 "controlpanel",
12 "password",
13 "savegamefolder",
14 "options",
15 "last"
16 };
17
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 }
25 }
26 return true;
27 }
28
29 public GetGamePrefs (ConsoleSdtd cons) : base(cons)
30 {
31 }
32
33 public override string Description ()
34 {
35 return "gets a game pref";
36 }
37
38 public override string[] Names ()
39 {
40 return new string[]
41 {
42 "getgamepref",
43 "gg"
44 };
45 }
46
47 public override void Run (string[] _params)
48 {
49 try {
50 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last;
51
52 if (_params.Length > 0) {
53 try {
54 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0]));
55 } catch (Exception) {
56 }
57 }
58
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 }
66 }
67 }
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");
76 }
77 } catch (Exception e) {
78 Log.Out ("Error in GetGamePrefs.Run: " + e);
79 }
80 }
81 }
82}
Note: See TracBrowser for help on using the repository browser.