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

Last change on this file since 129 was 128, checked in by alloc, 10 years ago

Fixes

File size: 2.2 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 if (tmpInfo.SteamID == null || tmpInfo.SteamID.Length == 0)
13 {
14 tmpInfo.PermissionLevel = 1000;
15 }
16
17 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions;
18 ConsoleSdtd console = CommonMappingFunctions.GetGameManager ().m_GUIConsole;
19
20 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);
28 }
29 }
30 }
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);
45 }
46
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) {
56 foreach (string ccName in getAlternativeNames(cmd)) {
57 if (atcp.Command.ToLower ().Equals (ccName)) {
58 return true;
59 }
60 }
61 }
62 return false;
63 }
64
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);
70 }
71 }
72 }
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}
84
Note: See TracBrowser for help on using the repository browser.