source: binary-improvements/7dtd-server-fixes/src/TelnetCommands/GetGamePrefs.cs@ 91

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

fixes

File size: 1.7 KB
RevLine 
[83]1using System;
2using System.Collections.Generic;
3
4public 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 {
[91]47 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last;
48
49 if (_params.Length > 0) {
50 try {
51 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0]));
52 } catch (Exception) {
53 }
54 }
55
56 if (enumGamePrefs == EnumGamePrefs.Last) {
[83]57 SortedList<string, string> sortedList = new SortedList<string, string> ();
58 foreach (EnumGamePrefs gp in Enum.GetValues(typeof(EnumGamePrefs))) {
[91]59 if ((_params.Length == 0) || (gp.ToString ().ToLower ().Contains (_params [0].ToLower ()))) {
60 if (prefAccessAllowed (gp)) {
61 sortedList.Add (gp.ToString (), string.Format ("{0} = {1}", gp.ToString (), GamePrefs.GetObject (gp)));
62 }
63 }
[83]64 }
65 foreach (string s in sortedList.Keys) {
66 m_Console.md000a (sortedList [s]);
67 }
[91]68 } else {
69 if (prefAccessAllowed (enumGamePrefs))
70 m_Console.md000a (string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs)));
71 else
72 m_Console.md000a ("Access to requested preference is forbidden");
[83]73 }
74 }
75}
76
Note: See TracBrowser for help on using the repository browser.