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

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

server fixes

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