[84] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
[130] | 4 | namespace AllocsFixes
|
---|
[84] | 5 | {
|
---|
[130] | 6 | public class AdminToolsStuff
|
---|
[84] | 7 | {
|
---|
[130] | 8 | public static string[] GetAllowedCommandsList (AdminTools admTools, string _steamID)
|
---|
| 9 | {
|
---|
| 10 | List<string> allowed = new List<string> ();
|
---|
[84] | 11 |
|
---|
[130] | 12 | try {
|
---|
| 13 | AdminToolsClientInfo tmpInfo = admTools.GetClientCommandInfo (_steamID);
|
---|
| 14 | if (tmpInfo.SteamID == null || tmpInfo.SteamID.Length == 0) {
|
---|
| 15 | tmpInfo.PermissionLevel = 1000;
|
---|
| 16 | }
|
---|
[86] | 17 |
|
---|
[130] | 18 | List<AdminToolsCommandPermissions> perms = admTools.commandPermissions;
|
---|
| 19 | ConsoleSdtd console = CommonMappingFunctions.GetGameManager ().m_GUIConsole;
|
---|
[103] | 20 |
|
---|
[130] | 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 | }
|
---|
[103] | 30 | }
|
---|
[84] | 31 | }
|
---|
[107] | 32 |
|
---|
[130] | 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 | }
|
---|
[107] | 40 | }
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
[130] | 43 |
|
---|
| 44 | } catch (Exception e) {
|
---|
| 45 | Log.Out ("Error in GetAllowedCommandsList: " + e);
|
---|
[107] | 46 | }
|
---|
[120] | 47 |
|
---|
[130] | 48 |
|
---|
| 49 | return allowed.ToArray ();
|
---|
[84] | 50 | }
|
---|
| 51 |
|
---|
[130] | 52 | private static bool hasPermissionLevel (AdminTools admTools, string cmd)
|
---|
| 53 | {
|
---|
| 54 | List<AdminToolsCommandPermissions> perms = admTools.commandPermissions;
|
---|
[103] | 55 |
|
---|
[130] | 56 | foreach (AdminToolsCommandPermissions atcp in perms) {
|
---|
| 57 | foreach (string ccName in getAlternativeNames(cmd)) {
|
---|
| 58 | if (atcp.Command.ToLower ().Equals (ccName)) {
|
---|
| 59 | return true;
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | return false;
|
---|
| 64 | }
|
---|
[86] | 65 |
|
---|
[130] | 66 | private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd)
|
---|
| 67 | {
|
---|
[107] | 68 | foreach (string ccName in getAlternativeNames(cmd)) {
|
---|
[130] | 69 | if (!list.Contains (ccName)) {
|
---|
| 70 | list.Add (ccName);
|
---|
[107] | 71 | }
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[130] | 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};
|
---|
[107] | 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
[84] | 85 | }
|
---|