Esempio n. 1
0
    // This function handles input from client and server.

    // The client enters input via text field.

    // The server enters input via the ServerConsole

    // This function just parses the type of action and then invokes the command's action
    public void HandleInput()
    {
        string[] properties = input.Split(' ');



        for (int i = 0; i < commandList.Count; i++)
        {
            ConsoleCommandBase commandBase = commandList[i] as ConsoleCommandBase;

            if (input.Contains(commandBase.commandId))
            {
                if (commandList[i] as ConsoleCommand != null)
                {
                    (commandList[i] as ConsoleCommand).Invoke();
                }
                else if (commandList[i] as ConsoleCommand <ulong> != null)
                {
                    ulong x;
                    if (ulong.TryParse(properties[1], out x))
                    {
                        (commandList[i] as ConsoleCommand <ulong>).Invoke(x);
                    }
                }
                else if (commandList[i] as ConsoleCommand <int> != null)
                {
                    int x;
                    if (int.TryParse(properties[1], out x))
                    {
                        (commandList[i] as ConsoleCommand <int>).Invoke(x);
                    }
                }
                else if (commandList[i] as ConsoleCommand <float> != null)
                {
                    float x;
                    if (float.TryParse(properties[1], out x))
                    {
                        (commandList[i] as ConsoleCommand <float>).Invoke(x);
                    }
                }
                else if (commandList[i] as ConsoleCommand <List <string> > != null)
                {
                    List <string> propertiesAfterCommandId = new List <string>();

                    for (int j = 1; j < properties.Length; j++)
                    {
                        propertiesAfterCommandId.Add(properties[j]);
                    }


                    (commandList[i] as ConsoleCommand <List <string> >).Invoke(propertiesAfterCommandId);
                }

                else if (commandList[i] as ConsoleCommand <string> != null)
                {
                    (commandList[i] as ConsoleCommand <string>).Invoke(properties[1]);
                }
            }
        }
    }
Esempio n. 2
0
 internal static CCR ExecuteCommand(ConsoleCommandBase cmd, List <String> args)
 {
     using (PersonDb db = new PersonDb())
     {
         return(cmd.Execute(args, db));
     }
 }
Esempio n. 3
0
        public override void _Ready()
        {
            SetPauseMode(PauseModeEnum.Process);
            _sendCmd = (BaseButton) GetNode("./vbox/hbox/send");
            _entryField = (LineEdit) GetNode("./vbox/hbox/entry");
            _cmdHistoryList = (BoxContainer) GetNode("./vbox/scroll/vbox");

            ConsoleCommandBase cmdBase = (ConsoleCommandBase) GetNode("./commandBase");
            _console.Init(cmdBase);

            _sendCmd.Connect("pressed", this, "SendCmd");
        }
Esempio n. 4
0
    //****************************************************************
    #region コンソール入力関連

    /// <summary>
    /// デバッグコマンドを追加する
    /// </summary>
    private void AddDebugCommand(ConsoleCommandBase command)
    {
        // 既に同じコマンドが登録されていたらエラーを通知
        if (_debugCommands.ContainsKey(command.commandName) == true)
        {
            Debug.LogError(
                "既にこのコマンドは登録済みです。\n" +
                "commandName : " + command.commandName
                );
            return;
        }

        _debugCommands.Add(command.commandName, command);
    }
Esempio n. 5
0
    private int CommandHelpLog(string command_name)
    {
        if (DebugConsoleWindow.Instance.debugCommands.ContainsKey(command_name) == false)
        {
            Debug.LogError("指定したコマンド名は見つかりませんでした。");
            return(-10);
        }

        ConsoleCommandBase command = DebugConsoleWindow.Instance.debugCommands[command_name];

        // コマンドがあれば commandHelp の内容を表示
        DebugConsoleWindow.Instance.ConsoleLog(command.commandHelp);

        return(0);
    }
Esempio n. 6
0
    private void OnGUI()
    {
        if (!showConsole)
        {
            return;
        }

        float y = 0f;

        if (showHelp)
        {
            GUI.Box(new Rect(0, y, Screen.width, 100), "");

            Rect viewport = new Rect(0, 0, Screen.width - 30, 20 * commandList.Count);

            scroll = GUI.BeginScrollView(new Rect(0, y + 5f, Screen.width, 90), scroll, viewport);


            for (int i = 0; i < commandList.Count; i++)
            {
                ConsoleCommandBase command = commandList[i] as ConsoleCommandBase;


                string label = command.commandFormat + " - " + command.commandDescription;

                Rect labelRect = new Rect(5, 20 * i, viewport.width - 100, 20);

                GUI.Label(labelRect, label);
            }

            GUI.EndScrollView();


            y += 100;
        }

        GUI.Box(new Rect(0, y, Screen.width, 30), "");
        GUI.backgroundColor = new Color(0, 0, 0, 0);
        input = GUI.TextField(new Rect(10f, y + 5f, Screen.width - 20f, 20f), input);
    }
Esempio n. 7
0
 public void Init(ConsoleCommandBase cmdBase)
 {
     _parser.SetConsole(this);
     _parser.SetCommandBase(cmdBase);
 }
Esempio n. 8
0
    private void Awake()
    {
        if (singleton == null)
        {
            singleton = this;
        }
        else
        {
            Destroy(this.gameObject);
        }


        Utilities.DontDestroyOnLoad(this.gameObject);



        // ADD MORE COMMANDS HERE

        HELP = new ConsoleCommand("help", "Shows list of console commands", "help", () =>
        {
#if UNITY_SERVER
            Debug.Log("Below is a list of commands you can use. Note some of them are just for clients and they won't do anything.");

            for (int i = 0; i < commandList.Count; i++)
            {
                ConsoleCommandBase command = commandList[i] as ConsoleCommandBase;

                Debug.Log(command.commandId + " - " + command.commandDescription + " - " + command.commandFormat);
            }
#else
            showHelp = !showHelp;
#endif
        });

        SET_FOV = new ConsoleCommand <float>("set_fov", "Sets the fov of Camera.main. use set_fov <any positive number>", "set_fov <float>", (x) =>
        {
            Camera.main.fieldOfView = x;
        });


        BAN_BY_ID = new ConsoleCommand <ulong>("ban_id", "Bans the user with the given steam id", "ban_id <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Ban(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.ban, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to ban player with id: " + x);
#endif
        });

        BAN_BY_NAME = new ConsoleCommand <List <string> >("ban_name", "Bans the first found user with this steam name, be careful using this.", "ban_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Ban(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.ban, name = JoinWithSpaces(x), id = 0
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to ban player with name: " + JoinWithSpaces(x));
#endif
        });


        MOD_BY_ID = new ConsoleCommand <ulong>("mod_id", "Adds a server moderator by steamid.", "mod_id <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Mod(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.mod, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to mod player with id: " + x);
#endif
        });

        MOD_BY_NAME = new ConsoleCommand <List <string> >("mod_name", "Adds a server moderator using the first found user with this steam name, be careful using this.", "mod_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Mod(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.mod, name = JoinWithSpaces(x), id = 0
            }, 0);

            // Ask server to mod this player
            Debug.Log("Asking server to mod player with name: " + JoinWithSpaces(x));
#endif
        });


        UNBAN_BY_ID = new ConsoleCommand <ulong>("unban_id", "UnBans the user with the given steam id", "unban_id <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.UnBan(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unban, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to unban player with id: " + x);
#endif
        });

        UNBAN_BY_NAME = new ConsoleCommand <List <string> >("unban_name", "UnBans the first found user with this steam name, be careful using this.", "unban_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.UnBan(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unban, name = name, id = 0
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to unban player with name: " + x);
#endif
        });


        UNMOD_BY_ID = new ConsoleCommand <ulong>("unmod_id", "Removes a server moderator by steamid.", "unmod_id <int>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.UnBan(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unmod, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to unmod player with id: " + x);
#endif
        });

        UNMOD_BY_NAME = new ConsoleCommand <List <string> >("unmod_name", "Removes a server moderator using the first found user with this steam name, be careful using this.", "unmod_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Unmod(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unmod, name = JoinWithSpaces(x), id = 0
            }, 0);

            // Ask server to mod this player
            Debug.Log("Asking server to unmod player with name: " + JoinWithSpaces(x));
#endif
        });


        KICK_BY_ID = new ConsoleCommand <ulong>("kick_id", "Kicks the player from the session", "kick <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Kick(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.kick, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to kick player with id: " + x);
#endif
        });


        KICK_BY_NAME = new ConsoleCommand <List <string> >("kick_name", "Kicks the player from the session", "kick <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Kick(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.kick, name = JoinWithSpaces(x), id = 0
            }, 0);

            Debug.Log("Asking server to kick player with name: " + JoinWithSpaces(x));
#endif
        });


        SET_FOV = new ConsoleCommand <float>("set_fov", "Sets the fov of Camera.main. use set_fov <any positive number>", "set_fov <float>", (x) =>
        {
            Camera.main.fieldOfView = x;
        });



        // Takes a list of strings and concatinates them into one string connected with spaces
        string JoinWithSpaces(List <string> x)
        {
            string name = "";

            for (int i = 0; i < x.Count; i++)
            {
                name += x[i];

                if (i < x.Count - 1)
                {
                    name += " ";
                }
            }

            Debug.Log("JoinWithSpaces() returned: " + name);

            return(name);
        }

        // Prepend server only commands with #if UNITY_SERVER so that they don't get put into client builds at all
#if UNITY_SERVER
        SERVER_DEBUG_MESSAGE = new ConsoleCommand <string>("debug", "Debug.logs a message on the server's client only", "debug <string>", (x) =>
        {
            Debug.Log(x);
        });
#endif

        // ADD MORE COMMANDS HERE



        commandList = new List <object>
        {
            SET_FOV,
            HELP,
            BAN_BY_NAME,
            BAN_BY_ID,
            MOD_BY_ID,
            MOD_BY_NAME,
            KICK_BY_ID,
            KICK_BY_NAME,
            UNBAN_BY_ID,
            UNMOD_BY_ID,
            UNBAN_BY_NAME,
            UNMOD_BY_NAME,



#if UNITY_SERVER
            SERVER_DEBUG_MESSAGE,
#endif
        };
    }
Esempio n. 9
0
 private static void RegisterCommand(ConsoleCommandBase command)
 {
     Commands.Add(command.Label.ToLower(), command);
 }
Esempio n. 10
0
 public void SetCommandBase(ConsoleCommandBase cmdBase)
 {
     _cmdBase = cmdBase;
 }