- Timestamp:
- Aug 26, 2014, 4:41:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/AdminToolsStuff.cs
r128 r130 2 2 using System.Collections.Generic; 3 3 4 public class AdminToolsStuff 4 namespace AllocsFixes 5 5 { 6 public static string[] GetAllowedCommandsList (AdminTools admTools, string _steamID)6 public class AdminToolsStuff 7 7 { 8 List<string> allowed = new List<string> (); 8 public static string[] GetAllowedCommandsList (AdminTools admTools, string _steamID) 9 { 10 List<string> allowed = new List<string> (); 9 11 10 try { 11 AdminToolsClientInfo tmpInfo = admTools.GetClientCommandInfo (_steamID); 12 if (tmpInfo.SteamID == null || tmpInfo.SteamID.Length == 0) 13 { 14 tmpInfo.PermissionLevel = 1000; 12 try { 13 AdminToolsClientInfo tmpInfo = admTools.GetClientCommandInfo (_steamID); 14 if (tmpInfo.SteamID == null || tmpInfo.SteamID.Length == 0) { 15 tmpInfo.PermissionLevel = 1000; 16 } 17 18 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions; 19 ConsoleSdtd console = CommonMappingFunctions.GetGameManager ().m_GUIConsole; 20 21 foreach (AdminToolsCommandPermissions atcp in perms) { 22 if (tmpInfo.SteamID != null && tmpInfo.SteamID.Length > 0) { 23 if ((atcp.PermissionLevel >= tmpInfo.PermissionLevel) || (atcp.PermissionLevel >= 1000)) { 24 addAllowed (console, allowed, atcp.Command); 25 } 26 } else { 27 if (atcp.PermissionLevel >= 1000) { 28 addAllowed (console, allowed, atcp.Command); 29 } 30 } 31 } 32 33 if (tmpInfo.PermissionLevel <= 0) { 34 List<ConsoleCommand> commands = console.commands; 35 foreach (ConsoleCommand c in commands) { 36 if (!allowed.Contains (c.Names () [0])) { 37 if (!hasPermissionLevel (admTools, c.Names () [0])) { 38 addAllowed (console, allowed, c.Names () [0]); 39 } 40 } 41 } 42 } 43 44 } catch (Exception e) { 45 Log.Out ("Error in GetAllowedCommandsList: " + e); 15 46 } 16 47 48 49 return allowed.ToArray (); 50 } 51 52 private static bool hasPermissionLevel (AdminTools admTools, string cmd) 53 { 17 54 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions; 18 ConsoleSdtd console = CommonMappingFunctions.GetGameManager ().m_GUIConsole;19 55 20 56 foreach (AdminToolsCommandPermissions atcp in perms) { 21 if (tmpInfo.SteamID != null && tmpInfo.SteamID.Length > 0) { 22 if ((atcp.PermissionLevel >= tmpInfo.PermissionLevel) || (atcp.PermissionLevel >= 1000)) { 23 addAllowed (console, allowed, atcp.Command); 24 } 25 } else { 26 if (atcp.PermissionLevel >= 1000) { 27 addAllowed (console, allowed, atcp.Command); 57 foreach (string ccName in getAlternativeNames(cmd)) { 58 if (atcp.Command.ToLower ().Equals (ccName)) { 59 return true; 28 60 } 29 61 } 30 62 } 31 32 if (tmpInfo.PermissionLevel <= 0) { 33 List<ConsoleCommand> commands = console.commands; 34 foreach (ConsoleCommand c in commands) { 35 if (!allowed.Contains (c.Names () [0])) { 36 if (!hasPermissionLevel (admTools, c.Names () [0])) { 37 addAllowed (console, allowed, c.Names () [0]); 38 } 39 } 40 } 41 } 42 43 } catch (Exception e) { 44 Log.Out ("Error in GetAllowedCommandsList: " + e); 63 return false; 45 64 } 46 65 47 48 return allowed.ToArray (); 49 } 50 51 private static bool hasPermissionLevel (AdminTools admTools, string cmd) 52 { 53 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions; 54 55 foreach (AdminToolsCommandPermissions atcp in perms) { 66 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd) 67 { 56 68 foreach (string ccName in getAlternativeNames(cmd)) { 57 if ( atcp.Command.ToLower ().Equals (ccName)) {58 return true;69 if (!list.Contains (ccName)) { 70 list.Add (ccName); 59 71 } 60 72 } 61 73 } 62 return false;63 }64 74 65 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd) 66 { 67 foreach (string ccName in getAlternativeNames(cmd)) { 68 if (!list.Contains (ccName)) { 69 list.Add (ccName); 75 private static string[] getAlternativeNames (string cmd) 76 { 77 ConsoleCommand cc = CommonMappingFunctions.GetGameManager ().m_GUIConsole.getCommand (cmd); 78 if (cc != null) { 79 return cc.Names (); 80 } else { 81 return new string[]{cmd}; 70 82 } 71 83 } 72 84 } 73 74 private static string[] getAlternativeNames (string cmd)75 {76 ConsoleCommand cc = CommonMappingFunctions.GetGameManager ().m_GUIConsole.getCommand (cmd);77 if (cc != null) {78 return cc.Names ();79 } else {80 return new string[]{cmd};81 }82 }83 85 } 84
Note:
See TracChangeset
for help on using the changeset viewer.