Exemple #1
0
        void onBEMessageReceivedEvent(Message message)
        {
            if (State == WebSocketState.Closed || State == WebSocketState.Closing)
            {
                CloseConnection();
                return;
            }

            var res = new WSBEMessage(message);
            Send(res.ToString());
        }
Exemple #2
0
        private void RunCommand(string cmd)
        {
            AppConsole.Log(String.Format("New Command From WebRCON: {0}", cmd), ConsoleColor.Blue);
            var res = new WSBEMessage()
            {
                msgtype = "Log",
                received = DateTime.Now,
                message = "",
                type = 2
            };
            Command command;
            try
            {
                command = new Command(cmd);
            }
            catch (Exception ex)
            {
                AppConsole.Log(String.Format("Error parsing BECommand string: {0} - {1}", cmd, ex.Message), ConsoleColor.Red);
                res.message = "Error parsing command";
                Send(res.ToString());
                return;
            }
            _api.SendCommand(command);

            switch (command.Type)
            {
                case Command.CmdType.Lock:
                    res.message = "Server Locked";
                    break;
                case Command.CmdType.Unlock:
                    res.message = "Server Unlocked";
                    break;
                case Command.CmdType.MaxPing:
                    res.message = String.Format("Max Ping Set To {0}", command.Parameters);
                    break;
                case Command.CmdType.loadEvents:
                    res.message = "Reloading Events";
                    break;
                case Command.CmdType.LoadScripts:
                    res.message = "Reloading Scripts";
                    break;
                case Command.CmdType.LoadBans:
                    res.message = "Reloading Bans";
                    break;
                case Command.CmdType.RemoveBan:
                    res.message = "Removed ban";
                    break;
                case Command.CmdType.AddBan:
                    res.message = String.Format("Added Ban: {0}", command.Parameters);
                    break;
            }

            if (res.message != "")
            {
                Send(res.ToString());
            }
        }