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