source: binary-improvements/7dtd-server-fixes/src/AdminToolsStuff.cs@ 194

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

Fixes

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes
5{
6 public class AdminToolsStuff
7 {
8 public static string[] GetAllowedCommandsList (AdminTools admTools, string _steamID)
9 {
10 List<string> allowed = new List<string> ();
11
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);
46 }
47
48
49 return allowed.ToArray ();
50 }
51
52 private static bool hasPermissionLevel (AdminTools admTools, string cmd)
53 {
54 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions;
55
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 }
65
66 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd)
67 {
68 foreach (string ccName in getAlternativeNames(cmd)) {
69 if (!list.Contains (ccName)) {
70 list.Add (ccName);
71 }
72 }
73 }
74
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};
82 }
83 }
84 }
85}
Note: See TracBrowser for help on using the repository browser.