void ShowCommandPermissionLevel(string command)
        {
            CFuncMethod cfuncMethod = null;

            if (!string.IsNullOrEmpty(command))
            {
                cfuncMethod = GameManager.instance.FindConsoleCommand(command);
            }

            if (cfuncMethod != null)
            {
                if (cfuncMethod.cfunc.isServer)
                {
                    ConsolePrint(LogType.Warning, command + " requires permission level " + cfuncMethod.cfunc.permissionLevel + ".");
                }
                else
                {
                    ConsolePrint(LogType.Warning, command + " is not subject to any permission level restrictions.");
                }
            }
            else
            {
                ConsolePrint(LogType.Error, "There is no command named " + command + ".");
            }
        }
        void SetCommandPermissionLevel(string command, int level)
        {
            CFuncMethod cfuncMethod = null;

            if (!string.IsNullOrEmpty(command))
            {
                cfuncMethod = GameManager.instance.FindConsoleCommand(command);
            }

            if (cfuncMethod != null)
            {
                if (cfuncMethod.cfunc.permissionLevel == level)
                {
                    ConsolePrint(LogType.Error, command + " is already set to permission level " + level + ".");
                }
                else if (level < 0)
                {
                    ConsolePrint(LogType.Error, "Permission levels must be >= 0.");
                }
                else
                {
                    cfuncMethod.cfunc = new CFunc(cfuncMethod.cfunc);
                    cfuncMethod.cfunc.permissionLevel = level;
                    ConsolePrint(LogType.Warning, command + " permission level is now " + level + ".");
                    BroadcastConsolePrint(LogType.Warning, playerState.playerName + " changed " + command + " command permission level to " + level + ".", playerState);
                }
            }
            else
            {
                ConsolePrint(LogType.Error, "There is no command named " + command + ".");
            }
        }
 public void ExecuteServerCFunc(CFuncMethod cfuncMethod, string command)
 {
     if (cfuncMethod.cfunc.isServer)
     {
         rpc_Server_ExecuteCFunc.Invoke(command);
     }
 }
示例#4
0
    public static string GetFuncPrototype(CFuncMethod cfuncMethod)
    {
        var prototype = GetTypeName(cfuncMethod.method.ReturnType) + " ";

        if ((cfuncMethod.cfunc.shortcuts != null) && (cfuncMethod.cfunc.shortcuts.Length > 0))
        {
            prototype += "[" + cfuncMethod.method.Name.ToLower();

            foreach (var name in cfuncMethod.cfunc.shortcuts)
            {
                prototype += ", " + name;
            }

            prototype += "]";
        }
        else
        {
            prototype += cfuncMethod.method.Name.ToLower();
        }

        prototype += "(";

        bool firstParam = true;

        foreach (var p in cfuncMethod.method.GetParameters())
        {
            if (!firstParam)
            {
                prototype += ", ";
            }
            firstParam = false;

            if (p.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
            {
                prototype += "params string[] " + p.Name;
            }
            else
            {
                prototype += GetTypeName(p.ParameterType) + " " + p.Name;
            }
        }

        prototype += ")";
        return(prototype);
    }
示例#5
0
    public static Dictionary <string, CFuncMethod> GetCFuncs(Assembly[] assemblies)
    {
        Dictionary <string, CFuncMethod> cvarMethods = new Dictionary <string, CFuncMethod>();

        using (var stopWatch = StopWatchPool.New()) {
            stopWatch.stopWatch.Start();

            foreach (var a in assemblies)
            {
                foreach (var t in a.GetTypes())
                {
                    if (!t.IsClass)
                    {
                        continue;
                    }
                    foreach (var m in t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static))
                    {
                        if (!m.IsConstructor && (m.DeclaringType == t))
                        {
                            var cvarAttrs = m.GetCustomAttributes(typeof(CFunc), false);
                            if (cvarAttrs.Length > 0)
                            {
                                var cfuncMethod = new CFuncMethod();
                                cfuncMethod.cfunc  = (CFunc)cvarAttrs[0];
                                cfuncMethod.method = m;

                                var nameList = cfuncMethod.cfunc.shortcuts;
                                if ((nameList != null) && (nameList.Length > 0))
                                {
                                    foreach (var cvarName in nameList)
                                    {
                                        var         name = cvarName.ToLower();
                                        CFuncMethod collision;
                                        if (cvarMethods.TryGetValue(name, out collision))
                                        {
                                            throw new System.Exception("CFunc defined multiple times, first at: " + collision.method.DeclaringType.FullName + "." + collision.method.Name + ", and then at: " + cfuncMethod.method.DeclaringType.FullName + "." + cfuncMethod.method.Name);
                                        }
                                        else
                                        {
                                            cvarMethods.Add(name, cfuncMethod);
                                        }
                                    }
                                }

                                {
                                    var         cvarName = m.Name.ToLower();
                                    CFuncMethod collision;
                                    if (cvarMethods.TryGetValue(cvarName, out collision))
                                    {
                                        throw new System.Exception("CFunc defined multiple times, first at: " + collision.method.DeclaringType.FullName + "." + collision.method.Name + ", and then at: " + cfuncMethod.method.DeclaringType.FullName + "." + cfuncMethod.method.Name);
                                    }
                                    else
                                    {
                                        cvarMethods.Add(cvarName, cfuncMethod);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Debug.Log("Loaded CFuncs in " + stopWatch.stopWatch.Elapsed);
        }

        return(cvarMethods);
    }