Exemplo n.º 1
0
        public HttpResponseMessage UpdatePlayerData(PlayerDataSql playerData)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(null);
            }

            string userName = User.Identity.Name;

            playerData.SteamId = userName;

            HttpResponseMessage response;

            try
            {
                playerData.SaveBaseData();
            }
            catch (Exception ex)
            {
                response = new HttpResponseMessage();
                response.ReasonPhrase = $"Error processing request: {ex.Message}";
                response.StatusCode   = System.Net.HttpStatusCode.BadRequest;
                return(response);
            }

            response            = new HttpResponseMessage();
            response.StatusCode = System.Net.HttpStatusCode.OK;
            return(response);
        }
Exemplo n.º 2
0
        public HttpResponseMessage StartBattleWithRigInDb(int battleSceneId)
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            SpaceshipRig rig = SpaceshipRig.RigForBattle(playerId, battleSceneId);

            Battle battle = null;

            if (rig != null)
            {
                if (rig.Id == 0)
                {
                    rig.SaveData(playerId, "");
                }
            }
            else
            {
                rig = SpaceshipRig.RigForBattle(playerId, battleSceneId);
            }

            battle     = Battle.CreateBattle(playerId, battleSceneId, rig.Id, true);
            battle.Rig = rig;


            string serializedElement = JsonConvert.SerializeObject(battle);

            serializedElement = CommonFunctions.Compress(serializedElement);
            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 3
0
        public HttpResponseMessage GetPlayerData()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(null);
            }

            string     userName   = User.Identity.Name;
            PlayerData playerData = PlayerDataSql.GetPlayerData(userName);


            HttpResponseMessage response;

            if (playerData == null)
            {
                response = new HttpResponseMessage();
                response.ReasonPhrase = $"Error processing request: user not found";
                response.StatusCode   = System.Net.HttpStatusCode.BadRequest;
                return(response);
            }

            string json = JsonConvert.SerializeObject(playerData);

            response            = new HttpResponseMessage();
            response.StatusCode = System.Net.HttpStatusCode.OK;
            response.Content    = new StringContent(json);
            return(response);
        }
Exemplo n.º 4
0
        public HttpResponseMessage RegisterBattleProgress(BattleProgressRegistration progress)
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            return(SaveBattleProgress(progress, playerId));
        }
Exemplo n.º 5
0
        public HttpResponseMessage GetImage(int ImageId)
        {
            HttpResponseMessage response;

            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            if (playerId == 0)
            {
                response = new HttpResponseMessage(HttpStatusCode.Forbidden);
                return(response);
            }

            Story.RebelImageToTransfer curImage = Story.RebelImageToTransfer.ImageToTransferById(ImageId);
            if (curImage == null)
            {
                response = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(response);
            }

            string serializedElement = JsonConvert.SerializeObject(curImage);

            response         = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 6
0
        public HttpResponseMessage RegisterStoryElementCompleted()
        {
            string       steamId           = User.Identity.Name;
            StringAndInt currentElement    = PlayerDataSql.RegisterStoryElementCompleted(steamId);
            string       serializedElement = JsonConvert.SerializeObject(currentElement);
            var          response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 7
0
        public HttpResponseMessage GetOfficerList()
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);
            List <Crew.CrewOfficer> officers = Crew.CrewOfficer.OfficersForPlayer(playerId);
            string serializedElement         = JsonConvert.SerializeObject(officers);
            var    response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 8
0
        public HttpResponseMessage GetPlayerAsset()
        {
            string      steamId           = User.Identity.Name;
            int         playerId          = PlayerDataSql.PlayerId(steamId);
            PlayerAsset playerAsset       = PlayerDataSql.GetPlayerAsset(playerId);
            string      serializedElement = JsonConvert.SerializeObject(playerAsset);
            var         response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 9
0
        public HttpResponseMessage GetPlayerModules()
        {
            string            steamId           = User.Identity.Name;
            int               playerId          = PlayerDataSql.PlayerId(steamId);
            List <ShipModule> modules           = ShipModule.PlayerModules(playerId);
            string            serializedElement = JsonConvert.SerializeObject(modules);
            var               response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 10
0
        public HttpResponseMessage BattleSceneList()
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            List <Battle> playerBattles     = Battle.BattlesForPlayer(playerId, true);
            string        serializedElement = JsonConvert.SerializeObject(playerBattles);
            var           response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 11
0
        public HttpResponseMessage UpdateOfficerSkillsets(Crew.OfficerExperience officerExperience)
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            //Внимание! Данные залетают в базу без какой-либо проверки.
            officerExperience.SaveData();

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            return(response);
        }
Exemplo n.º 12
0
        public HttpResponseMessage RigForBattle(int BattleSceneId)
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            var rig = SpaceshipRig.RigForBattle(playerId, BattleSceneId);

            string serializedElement = JsonConvert.SerializeObject(rig);
            var    response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 13
0
        public HttpResponseMessage GetPlayerResources()
        {
            string          steamId         = User.Identity.Name;
            int             playerId        = PlayerDataSql.PlayerId(steamId);
            PlayerResources playerResources = new PlayerResources();

            playerResources.LoadData(PlayerResources.StorageType.MainWarehouse, 0, playerId);
            string serializedElement = JsonConvert.SerializeObject(playerResources);
            var    response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 14
0
        private void buttonSaCreateOfficer_Click(object sender, EventArgs e)
        {
            if (comboSaOfficers.SelectedItem == null)
            {
                return;
            }
            CrewOfficerType ofType = (CrewOfficerType)comboSaOfficers.SelectedItem;
            //int playerId = DataConnection.GetResultInt("SELECT MAX(id) AS Result FROM [admirals]");
            int         playerId   = PlayerDataSql.GetTestPlayerData().Id;
            CrewOfficer newOfficer = new CrewOfficer(ofType, playerId);

            listSaOfficers.Items.Add(newOfficer);
        }
Exemplo n.º 15
0
        public HttpResponseMessage RegisterRigCompleted(SpaceshipRig rig)
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            if (rig != null)
            {
                rig.SaveData(playerId, "");
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            return(response);
        }
Exemplo n.º 16
0
        private void FillPlayersOfficers()
        {
            PlayerData pData = PlayerDataSql.GetTestPlayerData();

            listSaOfficers.Items.Clear();
            List <CrewOfficer> officers = CrewOfficer.OfficersForPlayer(pData.Id);

            if (officers.Count > 0)
            {
                foreach (CrewOfficer off in officers)
                {
                    listSaOfficers.Items.Add(off);
                }
            }
        }
Exemplo n.º 17
0
        public HttpResponseMessage RegisterOfficerChanges(Crew.CrewOfficer officer)
        {
            string steamId            = User.Identity.Name;
            int    playerId           = PlayerDataSql.PlayerId(steamId);
            string statsEditingResult = Crew.CrewOfficer.RegisterOfficerStatsChanged(playerId, officer);

            if (string.IsNullOrEmpty(statsEditingResult))
            {
                var response = new HttpResponseMessage(HttpStatusCode.OK);
                return(response);
            }
            else
            {
                var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
                response.ReasonPhrase = statsEditingResult;
                return(response);
            }
        }
Exemplo n.º 18
0
        public HttpResponseMessage RegisterBattleCompleted(BattleProgressRegistration progress)
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            var response = SaveBattleProgress(progress, playerId);

            if (!response.IsSuccessStatusCode)
            {
                return(response);
            }

            Battle currentBattle = Battle.BattleByCode(progress.BattleCode);

            currentBattle.RegisterBattleCompleted(progress);

            return(response);
        }
Exemplo n.º 19
0
        public HttpResponseMessage GetStationInfo()
        {
            string     steamId    = User.Identity.Name;
            PlayerData playerData = PlayerDataSql.GetPlayerData(steamId);

            if (playerData.StationOpened == 0)
            {
                var negativeResponse = new HttpResponseMessage(HttpStatusCode.BadRequest);
                negativeResponse.ReasonPhrase = "Station is not opened yet";
                return(negativeResponse);
            }
            int     playerId          = playerData.Id;
            Station station           = new Station(playerId);
            string  serializedElement = JsonConvert.SerializeObject(station);
            var     response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 20
0
        public HttpResponseMessage ContinueBattle(int battleSceneId)
        {
            string steamId  = User.Identity.Name;
            int    playerId = PlayerDataSql.PlayerId(steamId);

            Battle      battle  = Battle.BattleByTypeId(playerId, battleSceneId);
            BattleScene tBattle = new BattleScene(BattleSceneType.SceneById(battleSceneId));

            battle.battleScene = new UnityBattleScene(tBattle);
            battle.Rig         = SpaceshipRig.RigById(battle.RigId);

            string serializedElement = JsonConvert.SerializeObject(battle);

            serializedElement = CommonFunctions.Compress(serializedElement);
            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }
Exemplo n.º 21
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            model.Password        = CodeBits.PasswordGenerator.Generate(14, CodeBits.PasswordCharacters.All) + "!";
            model.ConfirmPassword = model.Password;
            model.Email           = model.Email + "@admiraldomain";

            /*if (!ModelState.IsValid)
             * {
             *  Exception ex = new Exception($"checking model state failed: {ModelState}");
             *  return new System.Web.Http.Results.ExceptionResult(ex, this);
             * }*/

            var user = new ApplicationUser()
            {
                UserName = model.SteamId, Email = model.Email
            };

            IdentityResult result;

            try
            {
                result = await UserManager.CreateAsync(user, model.Password);
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception($"error registering ASP.NET user: {ex.Message}");
                return(new System.Web.Http.Results.ExceptionResult(ex2, this));
            }


            if (!result.Succeeded)
            {
                //return GetErrorResult(result);
                string err = "";
                foreach (var error in result.Errors)
                {
                    err += error + ", ";
                }
                Exception ex = new Exception($"UserManager.CreateAsync failed: {err}");
                return(new System.Web.Http.Results.ExceptionResult(ex, this));
            }

            string serializedBindingModel = JsonConvert.SerializeObject(model);
            string registerResult         = PlayerDataSql.RegisterAccount(serializedBindingModel);

            if (!String.IsNullOrEmpty(registerResult))
            {
                Exception ex = new Exception($"procedure PlayerData.RegisterAccount fails: {registerResult}");
                return(new System.Web.Http.Results.ExceptionResult(ex, this));
            }

            //return Ok();
            string json = JsonConvert.SerializeObject(model);
            HttpResponseMessage responseMessage = new HttpResponseMessage();

            responseMessage.StatusCode = System.Net.HttpStatusCode.OK;
            responseMessage.Content    = new StringContent(json);
            IHttpActionResult response = ResponseMessage(responseMessage);

            return(response);
        }
Exemplo n.º 22
0
    public static bool BattleCanBeStarted(string steamId, int battleSceneId)
    {
        StringAndInt nextObject = PlayerDataSql.NextStoryObject(steamId);

        return(nextObject.StrValue == "battle" && nextObject.IntValue == battleSceneId);
    }