Esempio n. 1
0
        public async Task <IActionResult> AddViewNum([FromBody] AddViewNum.Request req)
        {
            var record = await Common3DB.ReplayViewNum.FindAsync(req.matchId);

            if (record == null)
            {
                var temp = new ReplayViewNum();
                temp.matchId = req.matchId;
                temp.ViewNum = 1;
                await Common3DB.ReplayViewNum.AddAsync(temp);
            }
            else
            {
                record.ViewNum++;
            }

            await Common3DB.SaveChangesAsync();

            var res = new AddViewNum.Response();

            return(Ok(res));
        }
Esempio n. 2
0
        public async Task <IActionResult> ReplayInfoSave([FromBody] ReplayInfoSave.Request req)
        {
            // parse BattleServer-Package-version
            int[] pver = req.packageVersion.Split('.').Select(a => int.Parse(a)).ToArray();
            if (pver.Length < 4)
            {
                return(BuildErrorResponse(Error.LowCode.BadParameter));
            }
            UInt64 packageVersion = VersionChecker.Valued(VersionChecker.ReferenceSrc.PackageVersion, pver);

            //Console.WriteLine("ReplayInfoSave:packageVersion={0}", packageVersion);

            // parse BattleServer-MasterData-version
            int[] mver = req.masterDataVersion.Split('-').Select(a => int.Parse(a)).ToArray();
            if (mver.Length < 3)
            {
                return(BuildErrorResponse(Error.LowCode.BadParameter));
            }
            UInt64 masterDataVersion = VersionChecker.Valued(VersionChecker.ReferenceSrc.MasterDataVersion, mver);
            //Console.WriteLine("ReplayInfoSave:masterDataVersion={0}", masterDataVersion);

            var info = new ReplayInfoAllMatch();

            info.packageVersion    = packageVersion;
            info.masterDataVersion = masterDataVersion;
            info.date        = req.baseInfo.date;
            info.matchId     = req.baseInfo.matchId;
            info.matchType   = req.baseInfo.matchType;
            info.mapId       = req.baseInfo.mapId;
            info.gameMode    = req.baseInfo.gameMode;
            info.totalTime   = req.baseInfo.totalTime;
            info.result      = req.baseInfo.result;
            info.mvpUserName = req.baseInfo.mvpPlayer;
            info.mvpUnitId   = req.baseInfo.mvpUnit;

            await Common3DB.ReplayInfoAllMatch.AddAsync(info);

            // ランクマッチテーブル登録
            if (req.saveRank)
            {
                var rank = new ReplayInfoRankMatch();
                rank.packageVersion    = packageVersion;
                rank.masterDataVersion = masterDataVersion;
                rank.date          = req.baseInfo.date;
                rank.matchId       = req.baseInfo.matchId;
                rank.mapId         = req.baseInfo.mapId;
                rank.gameMode      = req.baseInfo.gameMode;
                rank.mvpUnitId     = req.baseInfo.mvpUnit;
                rank.ratingAverage = req.rateAverage;

                rank.isFeatured = req.isFeatured;

                // 使われた機体をbitで管理
                UInt64 spawn = 0;
                foreach (int bit_idx in req.spawnUnits)
                {
                    UInt64 mask = (UInt64)(1 << bit_idx);
                    spawn |= mask;
                }
                // 表彰機体をbitで管理
                UInt64 award = 0;
                foreach (int bit_idx in req.awardUnits)
                {
                    UInt64 mask = (UInt64)(1 << bit_idx);
                    award |= mask;
                }
                //Console.WriteLine("spawn = {0}", spawn);
                //Console.WriteLine("award = {0}", award);

                rank.spawnUnits = spawn;
                rank.awardUnits = award;

                await Common3DB.ReplayInfoRankMatch.AddAsync(rank);
            }

            // フィーチャードマッチ用データ登録
            if (req.isFeatured)
            {
                var member = new MatchMember();
                member.matchId     = req.baseInfo.matchId;
                member.playersInfo = req.members;

                await Common3DB.MatchMember.AddAsync(member);
            }

            // 更新適用
            await Common3DB.SaveChangesAsync();


            // ユーザ毎の保存
            foreach (var userresult in req.playerResult)
            {
                var personalDb = PDBSM.PersonalDBContext(userresult.playerId);

                var userdata = new ReplayUserHistory();
                userdata.playerId   = userresult.playerId;
                userdata.resultType = userresult.result;

                userdata.packageVersion    = packageVersion;
                userdata.masterDataVersion = masterDataVersion;
                userdata.date      = req.baseInfo.date;
                userdata.matchId   = req.baseInfo.matchId;
                userdata.matchType = req.baseInfo.matchType;

                await personalDb.ReplayUserHistory.AddAsync(userdata);

                await personalDb.SaveChangesAsync();
            }

            var res = new ReplayInfoSave.Response();

            return(Ok(res));
        }