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

Last change on this file since 119 was 107, checked in by alloc, 10 years ago

fixes

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