コード例 #1
0
        public async Task <IActionResult> SendCommand(int server, string command)
        {
            if (!await CheckRights())
            {
                return(new UnauthorizedResult());
            }
            var response   = "";
            var rconServer = new RconServer();

            try
            {
                rconServer = _serverService.FindOne(server);
                response   = await _service.SendCommand(rconServer, command);
            }
            catch (CommandException e)
            {
                return(BadRequest(e.Message));
            }

            if (String.IsNullOrEmpty(response))
            {
                return(BadRequest("The response was empty!"));
            }
            return(new ObjectResult(response));
        }
コード例 #2
0
        public async Task <IActionResult> SendCommand(int[] servers, string command)
        {
            var results = new List <string>();

            if (!await CheckRights())
            {
                return(Unauthorized());
            }
            foreach (var server in servers)
            {
                var response   = "";
                var rconServer = new RconServer();
                try
                {
                    rconServer = _serverService.FindOne(server);
                    response   = await _service.SendCommand(rconServer, command);
                }
                catch (CommandException e)
                {
                    results.Add(e.Message);
                    continue;
                }

                if (String.IsNullOrEmpty(response))
                {
                    results.Add("The response from " + rconServer.Adress + " was empty!");
                    continue;
                }

                if (command != "ServerInfo")
                {
                    response = "\"" + rconServer.Name + "\": " + response;
                }
                results.Add(response);
            }
            ;
            if (command != "ServerInfo")
            {
                return(new ObjectResult("{" + String.Join(",", results) + "}"));
            }
            else
            {
                return(new ObjectResult(results));
            }
        }