// GET
        public async Task <IActionResult> PlayersFromServers([FromQuery] int[] servers,
                                                             [FromQuery] string backgroundColorHex, [FromQuery] string fontColorHex)
        {
            var result = new List <PavlovServerPlayerListPublicViewModel>();

            foreach (var serverId in servers)
            {
                var server = await _pavlovServerService.FindOne(serverId);

                if (server == null)
                {
                    continue;
                }
                if (server.ServerServiceState != ServerServiceState.active &&
                    server.ServerType == ServerType.Community)
                {
                    continue;
                }
                if (server.ServerType == ServerType.Event)
                {
                    continue;
                }
                result.Add(await _publicViewListsService.GetPavlovServerPlayerListPublicViewModel(serverId, false));
            }

            ViewBag.background = backgroundColorHex;
            ViewBag.textColor  = fontColorHex;
            return(PartialView(result));
        }
Beispiel #2
0
        public async Task <IActionResult> StopAndTakeAway(string apiKey, int sshServerId, int pavlovServerId)
        {
            if (!HasAccess(apiKey))
            {
                return(BadRequest("No AuthKey set or wrong auth key!"));
            }
            var sshServer = await _sshServerSerivce.FindOne(sshServerId);

            var pavlovServer = await _pavlovServerService.FindOne(pavlovServerId);

            if (sshServer == null)
            {
                return(BadRequest("The ssh server does not exist!"));
            }
            if (!sshServer.IsForHosting)
            {
                return(BadRequest("The ssh server ist not for hosting!"));
            }
            await RconStatic.SystemDStop(pavlovServer, _pavlovServerService);

            pavlovServer.OldOwner = pavlovServer.Owner;
            pavlovServer.Owner    = null;
            await _pavlovServerService.Upsert(pavlovServer);

            return(Ok());
        }
        public async Task <bool> SaveServerSelectedMap(int serverId, string mapId, string gameMode, bool move = true, [CanBeNull] string oldMode = "")
        {
            if (!await RightsHandler.HasRightsToThisPavlovServer(HttpContext.User,
                                                                 await _userservice.getUserFromCp(HttpContext.User), serverId, _service, _pavlovServerService))
            {
                return(false);
            }
            var realMap = await _mapsService.FindOne(mapId);

            var pavlovServer = await _pavlovServerService.FindOne(serverId);

            var mapsSelected = await _serverSelectedMapService.FindAllFrom(pavlovServer);

            if (mapsSelected != null)
            {
                var toUpdate = mapsSelected.FirstOrDefault(x => x.Map?.Id == realMap.Id && x.GameMode == gameMode);
                if (toUpdate == null)
                {
                    var newMap = new ServerSelectedMap
                    {
                        Map          = realMap,
                        PavlovServer = pavlovServer,
                        GameMode     = gameMode
                    };
                    await _serverSelectedMapService.Insert(newMap);

                    if (!move) // means that it just changed GameMode
                    {
                        //i need to know to old Game Mode
                        var oldMap = mapsSelected.FirstOrDefault(x => x.Map?.Id == realMap.Id && x.GameMode == oldMode);
                        if (oldMap != null)
                        {
                            await _serverSelectedMapService.Delete(oldMap.Id);
                        }
                    }
                }
                else
                {
                    //Can never go here?
                    toUpdate.GameMode = gameMode;
                    await _serverSelectedMapService.Update(toUpdate);
                }
            }
            else
            {
                var newMap = new ServerSelectedMap
                {
                    GameMode     = gameMode,
                    Map          = realMap,
                    PavlovServer = pavlovServer
                };
                await _serverSelectedMapService.Insert(newMap);
            }

            return(true);
        }
        public void FindOne()
        {
            // arrange
            var sshServer     = SshServerServiceTests.SshServerInsert(_sshServerSerivce);
            var pavlovServers = PavlovServers(sshServer, _pavlovServerService);

            pavlovServers.Should().NotBeNullOrEmpty();
            // act
            var pavlovServer = _pavlovServerService.FindOne(pavlovServers.FirstOrDefault().Id).GetAwaiter().GetResult();

            // assert
            pavlovServer.Should().NotBe(null);
            pavlovServer.Name.Should().Be("test");
        }
        public async Task <IActionResult> EditServer(int serverId, int sshServerId, bool create = false,
                                                     bool remove = false)
        {
            if (!await RightsHandler.HasRightsToThisPavlovServer(HttpContext.User,
                                                                 await _userservice.getUserFromCp(HttpContext.User), serverId, _service, _pavlovServerService))
            {
                return(Forbid());
            }
            var server = new PavlovServer();

            if (serverId != 0)
            {
                server = await _pavlovServerService.FindOne(serverId);
            }

            if (server.SshServer == null)
            {
                server.SshServer = await _sshServerSerivce.FindOne(sshServerId);
            }

            var viewModel = new PavlovServerViewModel();

            viewModel = viewModel.fromPavlovServer(server, sshServerId);

            viewModel.LiteDbUsers = (await _userservice.FindAll()).ToList();

            viewModel.create = create;
            viewModel.remove = remove;
            return(View("Server", viewModel));
        }
Beispiel #6
0
        public async Task <IActionResult> SendCommandMulti(int server, string command, string[] players, string value = "")
        {
            var singleServer = await _pavlovServerService.FindOne(server);

            var servers = await GiveServerWhichTheUserHasRightsTo();

            LiteDbUser user;

            user = await _userservice.getUserFromCp(HttpContext.User);

            if (!servers.Select(x => x.Id).Contains(singleServer.Id))
            {
                return(Forbid());
            }
            var isMod = await RightsHandler.IsModOnTheServer(_serverSelectedModsService, singleServer, user.Id);

            var commands = await RightsHandler.GetAllowCommands(new RconViewModel(), HttpContext.User, _userservice, isMod, singleServer, user);



            var contains = false;

            foreach (var singleCommand in commands)
            {
                if (command.Contains(singleCommand))
                {
                    contains = true;
                }
            }
            if (contains != true)
            {
                return(Forbid());
            }

            if (command.StartsWith("GodMode"))
            {
                command = "Slap";
                value   = "-2147000000";
            }
            if (command.StartsWith("CustomPlayer") || command.StartsWith("Custom"))
            {
                if (command.StartsWith("CustomPlayer"))
                {
                    var count = value.Count(x => x == ' ');
                    if (count == 1)
                    {
                        var pieces = value.Split(new[] { ' ' }, 2);
                        command = pieces[0];
                        value   = pieces[1];
                    }
                }
                else
                {
                    command = command.Substring(7);
                }
            }


            var responses = Array.Empty <string>();

            try
            {
                var commandsList = new List <string>();
                foreach (var player in players)
                {
                    if (value == null)
                    {
                        commandsList.Add(command + " " + player);
                    }
                    else
                    {
                        commandsList.Add(command + " " + player + " " + value);
                    }
                }
                responses = await RconStatic.SShTunnelMultipleCommands(singleServer, commandsList.ToArray(), _toastifyService);
            }
            catch (CommandException e)
            {
                return(BadRequest(e.Message));
            }
            if (string.IsNullOrEmpty(string.Join(";", responses)))
            {
                return(BadRequest("The response was empty!"));
            }

            var commandsResulsts = new List <string>();

            try
            {
                foreach (var response in responses)
                {
                    var tmp = JsonConvert.DeserializeObject <MinimumRconResultObject>(response, new JsonSerializerSettings {
                        CheckAdditionalContent = false
                    });
                    var o      = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(response);
                    var value3 = o.Property("")?.Value;
                    var value2 = o.Property(tmp.Command)?.Value;
                    if (tmp != null && (value3 is { HasValues: false } || value2 is { HasValues: false }))