Ejemplo n.º 1
0
        static bool ChangeType(Type t, FastQueue <string> paramQueue, out object result)
        {
            if (paramQueue.Count == 0)
            {
                RuntimeConsole.LogResultError("Not enough parameters");
                result = null;
                return(false);
            }

            string value = paramQueue.Dequeue();

            return(ChangeType(t, value, out result));
        }
Ejemplo n.º 2
0
        public static void ExecuteCommand(string command)
        {
            command = command.Replace(',', ' ');
            command = command.Trim(' ');

            if (command == string.Empty)
            {
                return;
            }
            if (command == instance.adminModeConsoleCommand && (instance.adminModeInBuild == AccessMode.EnabledOnConsoleCommand || instance.testOnlyFreeConsoleCommands))
            {
                accessLevel = AccessLevel.Admin;
                LogResult("AccessLevel = Admin");
                return;
            }
            if (command == instance.specialModeConsoleCommand && (instance.specialModeInBuild == AccessMode.EnabledOnConsoleCommand || instance.testOnlyFreeConsoleCommands))
            {
                accessLevel = AccessLevel.Special;
                LogResult("AccessLevel = Special");
                return;
            }

            if (command[0] == instance.searchCommandPrefix)
            {
                return;
            }

            int isRemoteCommand = IsRemoteCommand(ref command);

            string argumentString;

            int spaceIndex = command.IndexOf(" ");

            if (spaceIndex != -1)
            {
                argumentString = command.Substring(spaceIndex + 1);
            }
            else
            {
                argumentString = string.Empty;
            }

            GetArguments(command, inputCommands);

            // inputCommands.EnqueueRange(command.Split(' '));

            string firstCommand = inputCommands.Dequeue();

            CommandData commandData;

            if (!commandsTable.lookup.TryGetValue(firstCommand, out commandData) || commandData.obj == null)
            {
                CannotFindCommand(command, firstCommand);
                return;
            }

            if (commandData.consoleCommand != null && !commandData.consoleCommand.HasAccess(accessLevel))
            {
                CannotFindCommand(command, firstCommand);
                return;
            }

            if (!commandData.IsRegistered())
            {
                LogResultError("There is no registered instance for command '" + firstCommand + "'");
                return;
            }

            if (isRemoteCommand > 0)
            {
                if (onRemoteCommand != null)
                {
                    onRemoteCommand.Invoke(command);
                }
                if (isRemoteCommand == 2)
                {
                    command = "Execute only on remote '" + command + "'";
                }
                else
                {
                    command = "Execute on all '" + command + "'";
                }
            }

            Log(new LogEntry(command, null, LogType.Log, EntryType.Command, Color.green, instance.logFontSize, FontStyle.Bold));
            if (HtmlDebug.instance)
            {
                HtmlDebug.instance.UnityDebugLog(command, null, LogType.Log, true, -1, null, EntryType2.Command, false);
            }

            if (isRemoteCommand != 2)
            {
                commandData.Execute(inputCommands, argumentString);
            }
        }
Ejemplo n.º 3
0
        static object ChangeType(Type t, FastQueue <string> paramQueue, ref bool valid)
        {
            if (paramQueue.Count == 0)
            {
                LogResultError("Not enough parameters");
                valid = false;
                return(null);
            }

            string value = paramQueue.Dequeue();

            value = value.Trim();

            // Debug.Log("TryParse: " + value);

            if (t == typeof(string))
            {
                return(value);
            }
            else if (t == typeof(bool))
            {
                bool result; bool.TryParse(value, out result); return(result);
            }
            else if (t == typeof(byte))
            {
                byte result; byte.TryParse(value, out result); return(result);
            }
            else if (t == typeof(sbyte))
            {
                sbyte result; sbyte.TryParse(value, out result); return(result);
            }
            else if (t == typeof(char))
            {
                char result; char.TryParse(value, out result); return(result);
            }
            else if (t == typeof(decimal))
            {
                decimal result; decimal.TryParse(value, out result); return(result);
            }
            else if (t == typeof(double))
            {
                double result; double.TryParse(value, out result); return(result);
            }
            else if (t == typeof(float))
            {
                float result; float.TryParse(value, out result); return(result);
            }
            else if (t == typeof(int))
            {
                int result; int.TryParse(value, out result); return(result);
            }
            else if (t == typeof(uint))
            {
                uint result; uint.TryParse(value, out result); return(result);
            }
            else if (t == typeof(long))
            {
                long result; long.TryParse(value, out result); return(result);
            }
            else if (t == typeof(ulong))
            {
                ulong result; ulong.TryParse(value, out result); return(result);
            }
            else if (t == typeof(short))
            {
                short result; short.TryParse(value, out result); return(result);
            }
            else if (t == typeof(ushort))
            {
                ushort result; ushort.TryParse(value, out result); return(result);
            }
            else if (t.IsEnum)
            {
                try
                {
                    return(Enum.Parse(t, value, true));
                }
                catch (Exception)
                {
                    LogResultError("Cannot find '" + value + "'");
                }
            }

            valid = false;
            return(null);
        }