- Timestamp:
- Aug 26, 2014, 4:41:47 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src/CustomCommands
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/CustomCommands/GetGamePrefs.cs
r107 r130 2 2 using System.Collections.Generic; 3 3 4 public class GetGamePrefs : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 private string[] forbiddenPrefs = new string[] { 6 public class GetGamePrefs : ConsoleCommand 7 { 8 private string[] forbiddenPrefs = new string[] { 7 9 "telnet", 8 10 "adminfilename", … … 14 16 }; 15 17 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; 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 } 22 25 } 26 return true; 23 27 } 24 return true;25 }26 28 27 public GetGamePrefs (ConsoleSdtd cons) : base(cons)28 {29 }29 public GetGamePrefs (ConsoleSdtd cons) : base(cons) 30 { 31 } 30 32 31 public override string Description ()32 {33 return "gets a game pref";34 }33 public override string Description () 34 { 35 return "gets a game pref"; 36 } 35 37 36 public override string[] Names ()37 {38 return new string[]38 public override string[] Names () 39 { 40 return new string[] 39 41 { 40 42 "getgamepref", 41 43 "gg" 42 44 }; 43 }45 } 44 46 45 public override void Run (string[] _params)46 {47 try {48 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last;47 public override void Run (string[] _params) 48 { 49 try { 50 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last; 49 51 50 if (_params.Length > 0) { 51 try { 52 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0])); 53 } catch (Exception) { 52 if (_params.Length > 0) { 53 try { 54 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0])); 55 } catch (Exception) { 56 } 54 57 } 55 }56 58 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))); 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 } 63 66 } 64 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"); 65 76 } 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"); 77 } catch (Exception e) { 78 Log.Out ("Error in GetGamePrefs.Run: " + e); 74 79 } 75 } catch (Exception e) {76 Log.Out ("Error in GetGamePrefs.Run: " + e);77 80 } 78 81 } 79 82 } 80
Note:
See TracChangeset
for help on using the changeset viewer.