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

Last change on this file since 122 was 120, checked in by alloc, 10 years ago

Fixes: Permission fix

File size: 2.2 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);
[120]12 if (tmpInfo.SteamID == null || tmpInfo.SteamID.Length == 0)
13 {
14 tmpInfo.PermissionLevel = 1000;
15 }
[86]16
[103]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 }
[84]29 }
30 }
[107]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 }
[120]42
[103]43 } catch (Exception e) {
44 Log.Out ("Error in GetAllowedCommandsList: " + e);
[84]45 }
46
[103]47
[84]48 return allowed.ToArray ();
49 }
[86]50
[107]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
[86]65 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd)
66 {
[107]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);
[86]77 if (cc != null) {
[107]78 return cc.Names ();
[86]79 } else {
[107]80 return new string[0];
[86]81 }
82 }
[84]83}
84
Note: See TracBrowser for help on using the repository browser.