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

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

fixes

File size: 2.1 KB
RevLine 
[84]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
[103]10 try {
11 AdminToolsClientInfo tmpInfo = admTools.GetClientCommandInfo (_steamID);
[86]12
[103]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 }
[84]25 }
26 }
[107]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 }
[103]38 } catch (Exception e) {
39 Log.Out ("Error in GetAllowedCommandsList: " + e);
[84]40 }
41
[103]42
[84]43 return allowed.ToArray ();
44 }
[86]45
[107]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
[86]60 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd)
61 {
[107]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);
[86]72 if (cc != null) {
[107]73 return cc.Names ();
[86]74 } else {
[107]75 return new string[0];
[86]76 }
77 }
[84]78}
79
Note: See TracBrowser for help on using the repository browser.