Beispiel #1
0
        public async Task <IActionResult> SearchPlayer([FromBody] SearchPlayer.Request req)
        {
            var res = new SearchPlayer.Response();

            res.items = new List <SearchPlayer.Response.Item>();

            var pbi = await Logic.SearchPlayer.ByPlayerName(req.searchKey, PDBSM, Common2DB);

            if (pbi == null)
            {
                pbi = await Logic.SearchPlayer.ByAccount(req.searchKey, PDBSM, Common1DB);

                if (pbi == null)
                {
                    return(Ok(res));
                }
            }

            res.player = new SearchPlayer.Response.Player()
            {
                playerId     = pbi.playerId,
                playerName   = pbi.playerName,
                initialLevel = pbi.initialLevel,
            };

            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                return(Ok(res));
            }

            var ownedRecords
                = await PDBSM.PersonalDBContext(pbi.playerId).ItemInventories.Where(r => r.playerId == pbi.playerId).ToListAsync();


            foreach (var itemId in masterData.AllItemIds)
            {
                var item = masterData.GetItemFromItemId(itemId);

                res.items.Add(new SearchPlayer.Response.Item()
                {
                    itemId      = item.itemId,
                    itemType    = item.itemType.ToString(),
                    displayName = item.displayName,
                    owned       = null != ownedRecords.Find(r => r.itemId == item.itemId) ||
                                  masterData.CheckDefaultOwnedItem(item.itemId),
                    isDefault = masterData.CheckDefaultOwnedItem(item.itemId),
                });
            }

            return(Ok(res));
        }
Beispiel #2
0
        public async Task <GetUnitResponse> GetUnit()
        {
            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                // todo: error message
                throw new Exception("master data not exist");
            }

            var mobileSuitIds = masterData.AllMobileSuitIds.OrderBy(x => x);
            var dictionary    = _translationService.GetMobileSuitDictionary();

            var temporarilyDisabledItems = await Common2DB.DisabledMobileSuits.ToListAsync();

            var response = new GetUnitResponse();

            response.units = new List <GetUnitResponse.Unit>();

            foreach (var mobileSuitId in mobileSuitIds)
            {
                var mobileSuit = masterData.GetMobileSuit(mobileSuitId);

                if (mobileSuit == null)
                {
                    continue;
                }

                TranslationItemCommon translationItem;
                dictionary.TryGetValue(mobileSuitId, out translationItem);

                var isEnabledInGmTool = !temporarilyDisabledItems.Any(x => x.itemId == mobileSuit.itemId);

                response.units.Add(new GetUnitResponse.Unit
                {
                    mobileSuitId          = mobileSuitId,
                    displayNameJapanese   = translationItem?.JpText ?? mobileSuitId,
                    displayNameEnglish    = translationItem?.EnText ?? mobileSuitId,
                    isEnabledOnMasterData = mobileSuit.availabled,
                    isEnabledOnGmTool     = isEnabledInGmTool,
                    isAvailable           = mobileSuit.availabled && isEnabledInGmTool,
                });
            }

            return(response);
        }
Beispiel #3
0
        public async Task <PutUnitTemporaryAvailabilityResponse> PutUnitTemporaryAvailability(string mobileSuitId, PutUnitTemporaryAvailabilityRequest request)
        {
            var response = new PutUnitTemporaryAvailabilityResponse();

            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                // todo: error message
                throw new Exception("master data not exist");
            }

            var mobileSuit = masterData.GetMobileSuit(mobileSuitId);

            if (mobileSuit == null)
            {
                // todo: error message
                throw new BadRequestException("unit not exist");
            }

            var temporarilyDisabledItem = await Common2DB.DisabledMobileSuits.Where(r => r.itemId == mobileSuit.itemId).FirstOrDefaultAsync();

            if (request.isEnabledOnGmTool)
            {
                if (temporarilyDisabledItem != null)
                {
                    Common2DB.DisabledMobileSuits.Remove(temporarilyDisabledItem);
                    await Common2DB.SaveChangesAsync();
                }
            }
            else
            {
                if (temporarilyDisabledItem == null)
                {
                    await Common2DB.DisabledMobileSuits.AddAsync(
                        new evolib.Databases.common2.DisabledMobileSuit
                    {
                        itemId = mobileSuit.itemId,
                    });

                    await Common2DB.SaveChangesAsync();
                }
            }

            return(response);
        }
Beispiel #4
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            {
                var map = new Dictionary <string, List <String> >();

                var kvsConnectionsSection = Configuration.GetSection("KvsConnections");
                foreach (var item in kvsConnectionsSection.GetChildren())
                {
                    map[item.Key] = item.Get <List <string> >();
                }

                Kvs.Initialize(map);
            }

            EvoApiJwt.issuer        = Configuration["Jwt:issuer"];
            EvoApiJwt.audience      = Configuration["Jwt:audience"];
            EvoApiJwt.expiryMinutes = int.Parse(Configuration["Jwt:expiryMinutes"]);

            MatchingServerInfo.Initialize(Configuration);
            SequencingServerInfo.Initialize(Configuration);
            AuthenticationServerInfo.Initialize(Configuration);

            DeliveryDataInfo.Initialize(Configuration);

            evolib.SystemInfo.Initialize(Configuration);

            evolib.VivoxInfo.Initialize(Configuration);

            Task.Run(async() =>
            {
                while (!await MatchingServerInfo.SetupMultiMatchingServersAsync())
                {
                    await Task.Delay(5000);
                }

                while (true)
                {
                    await MasterDataLoader.LoadAsync();
                    await Task.Delay(5000);
                }
            });

            evolib.Kvs.Models.Session.ExpiredSpan = TimeSpan.FromSeconds(
                ProtocolModels.HandShake.HandShake.NextResponseSeconds + 60);
        }
Beispiel #5
0
        public async Task <GetSeasonListResponse> GetSeasonList()
        {
            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                // todo: error message
                throw new Exception("master data not exist");
            }

            var dictionary = _translationService.GetSeasonDictionary();

            var seasons = masterData.AllSeasons.OrderBy(x => x.seasonNo);

            var response = new GetSeasonListResponse();

            response.seasons = new List <GetSeasonListResponse.Season>();

            foreach (var season in seasons)
            {
                if (season.seasonNo == 0)
                {
                    response.seasons.Add(new GetSeasonListResponse.Season
                    {
                        seasonNo            = season.seasonNo,
                        displayNameJapanese = "カジュアル",
                        displayNameEnglish  = "Casual",
                    });
                }
                else
                {
                    TranslationItemCommon translationItem;
                    dictionary.TryGetValue(season.seasonNo.ToString(), out translationItem);

                    response.seasons.Add(new GetSeasonListResponse.Season
                    {
                        seasonNo            = season.seasonNo,
                        displayNameJapanese = translationItem?.JpText ?? season.seasonNo.ToString(),
                        displayNameEnglish  = translationItem?.EnText ?? season.seasonNo.ToString(),
                    });
                }
            }

            return(response);
        }
Beispiel #6
0
        public async Task <IActionResult> AddAssets([FromBody] AddAssets.Request req)
        {
            var db  = PDBSM.PersonalDBContext(req.playerId.Value);
            var pbi = await db.PlayerBasicInformations.FindAsync(req.playerId);

            if (pbi == null)
            {
                return(BuildErrorResponse("BadParameter"));
            }

            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                return(BuildErrorResponse("Server Side Err."));
            }

            if (GiveAndTake.GiveResult.Ok != await GiveAndTake.GiveAsync(
                    masterData,
                    db,
                    "",
                    req.playerId.Value,
                    new GiveAndTake.GiveModel
            {
                model = new GiveAndTake.Model
                {
                    type = GiveAndTake.Type.Assets,
                    assetsId = req.assetsId,
                    amount = req.amount,
                },
                historyModel = new GiveAndTake.HistoryModel
                {
                    giveType = evolib.PresentBox.Type.Management,
                    text = "AddAssets",
                },
            }
                    ))
            {
                return(BuildErrorResponse("BadParameter"));
            }

            return(Ok());
        }
        public async Task <IActionResult> TakePresent([FromBody] TakePresent.Request req)
        {
            var res = new TakePresent.Response();

            var db  = PDBSM.PersonalDBContext(req.playerId.Value);
            var pbi = await db.PlayerBasicInformations.FindAsync(req.playerId);

            if (pbi == null)
            {
                return(BuildErrorResponse("BadParameter"));
            }

            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                return(BuildErrorResponse("Server Side Err."));
            }

            var setting = new evolib.PresentBox.Setting
            {
                beginDate = req.beginDate,
                endDate   = req.endDate,
                text      = req.text,
            };

            var model = new evolib.PresentBox.Model
            {
                type        = req.type,
                id          = req.id,
                amount      = req.amount,
                presentType = req.presentType,
                setting     = setting,
            };

            // プレゼントボックスに保存する
            var result = await evolib.PresentBox.TakeAsync(
                masterData, db,
                req.playerId.Value,
                model);

            return(Ok(res));
        }
Beispiel #8
0
        public async Task <IActionResult> DisabledMobileSuit(string itemId, bool disabled)
        {
            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            var item = masterData.GetItemFromItemId(itemId);

            if (item == null ||
                item.itemType != evolib.Item.Type.MobileSuit)
            {
                return(BadRequest());
            }

            var record = await Common2DB.DisabledMobileSuits
                         .Where(r => r.itemId == itemId)
                         .FirstOrDefaultAsync();

            if (disabled)
            {
                if (record == null)
                {
                    await Common2DB.DisabledMobileSuits.AddAsync(
                        new evolib.Databases.common2.DisabledMobileSuit
                    {
                        itemId = itemId,
                    }
                        );

                    await Common2DB.SaveChangesAsync();
                }
            }
            else
            {
                if (record != null)
                {
                    Common2DB.DisabledMobileSuits.Remove(record);
                    await Common2DB.SaveChangesAsync();
                }
            }

            return(Ok(new { itemId, disabled }));
        }
Beispiel #9
0
        public async Task <GetMobileSuitListResponse> GetMobileSuitList()
        {
            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                // todo: error message
                throw new Exception("master data not exist");
            }

            var mobileSuitIds = masterData.AllMobileSuitIds.OrderBy(x => x);

            var dictionary = _translationService.GetMobileSuitDictionary();

            var response = new GetMobileSuitListResponse();

            response.mobileSuits = new List <GetMobileSuitListResponse.MobileSuit>();

            foreach (var mobileSuitId in mobileSuitIds)
            {
                var mobileSuit = masterData.GetMobileSuit(mobileSuitId);

                if (mobileSuit == null)
                {
                    continue;
                }

                TranslationItemCommon translationItem;
                dictionary.TryGetValue(mobileSuitId, out translationItem);

                response.mobileSuits.Add(new GetMobileSuitListResponse.MobileSuit
                {
                    mobileSuitId        = mobileSuitId,
                    displayNameJapanese = translationItem?.JpText ?? mobileSuitId,
                    displayNameEnglish  = translationItem?.EnText ?? mobileSuitId,
                });
            }

            return(response);
        }
Beispiel #10
0
        public async Task <IActionResult> GetDisabledMobileSuitsList()
        {
            var res = "itemId(availabled): disabled\n";

            res += "--------\n";


            var records = await Common2DB.DisabledMobileSuits.ToListAsync();

            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            foreach (var msId in masterData.AllMobileSuitIds)
            {
                var ms = masterData.GetMobileSuit(msId);

                res += $"{ms.itemId}({ms.availabled}): {records.Find(r => r.itemId == ms.itemId) != null}\n";
            }

            return(Ok(res));
        }
Beispiel #11
0
        public async Task <IActionResult> GetAllItems([FromBody] GetAllItems.Request req)
        {
            var res = new GetAllItems.Response
            {
                playerId = req.playerId.Value,
                itemIds  = new List <string>(),
            };


            var db = PDBSM.PersonalDBContext(req.playerId.Value);

            var playerBasicInfo = await db.PlayerBasicInformations.FindAsync(req.playerId);

            if (playerBasicInfo == null)
            {
                return(BuildErrorResponse("BadParameter"));
            }

            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                return(BuildErrorResponse("Server Side Err."));
            }

            var ownedRecords
                = await db.ItemInventories.Where(r => r.playerId == req.playerId).ToListAsync();

            var openItems = new List <evolib.Kvs.Models.ConnectionQueueData.OpenItems.Item>();

            foreach (var itemId in masterData.AllItemIds)
            {
                if (masterData.CheckDefaultOwnedItem(itemId))
                {
                    continue;
                }

                if (null != ownedRecords.Find(r => r.itemId == itemId))
                {
                    continue;
                }

                var item = masterData.GetItemFromItemId(itemId);

                await db.ItemInventories.AddAsync(new ItemInventory()
                {
                    playerId     = req.playerId.Value,
                    itemId       = item.itemId,
                    itemType     = item.itemType,
                    obtainedDate = DateTime.UtcNow,
                    obtainedWay  = evolib.Item.ObtainedWay.Tool,
                    isNew        = true,
                });

                res.itemIds.Add(itemId);

                openItems.Add(new evolib.Kvs.Models.ConnectionQueueData.OpenItems.Item
                {
                    itemId = itemId,
                    close  = false,
                });
            }

            await db.SaveChangesAsync();

            var player = new Player(req.playerId.Value);

            if (await player.FetchAsync() && !string.IsNullOrEmpty(player.Model.sessionId))
            {
                await new ConnectionQueue(player.Model.sessionId).EnqueueAsync(
                    new evolib.Kvs.Models.ConnectionQueueData.OpenItems()
                {
                    items = openItems,
                }
                    );
            }

            return(Ok(res));
        }
Beispiel #12
0
        public async Task <IActionResult> SwitchOwnedItem([FromBody] SwitchOwnedItem.Request req)
        {
            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                return(BuildErrorResponse("Server Side Err."));
            }

            if (masterData.CheckDefaultOwnedItem(req.itemId))
            {
                return(Ok(new SwitchOwnedItem.Response()
                {
                    playerId = req.playerId.Value,
                    itemId = req.itemId,
                    owned = true,
                }));
            }

            var item = masterData.GetItemFromItemId(req.itemId);

            if (item == null)
            {
                return(BuildErrorResponse("BadParameter"));
            }

            var db = PDBSM.PersonalDBContext(req.playerId.Value);

            var playerBasicInfo = await db.PlayerBasicInformations.FindAsync(req.playerId);

            if (playerBasicInfo == null)
            {
                return(BuildErrorResponse("BadParameter"));
            }

            var inventory = await db.ItemInventories.SingleOrDefaultAsync(i => i.playerId == req.playerId && i.itemId == req.itemId);

            var owned = false;

            if (inventory == null)
            {
                await db.ItemInventories.AddAsync(new ItemInventory()
                {
                    playerId     = req.playerId.Value,
                    itemId       = item.itemId,
                    itemType     = item.itemType,
                    obtainedDate = DateTime.UtcNow,
                    obtainedWay  = evolib.Item.ObtainedWay.Tool,
                    isNew        = true,
                });

                owned = true;
            }
            else
            {
                db.ItemInventories.Remove(inventory);
                owned = false;
            }

            await db.SaveChangesAsync();


            var player = new Player(playerBasicInfo.playerId);
            await player.FetchAsync();

            if (!string.IsNullOrEmpty(player.Model.sessionId))
            {
                await new ConnectionQueue(player.Model.sessionId).EnqueueAsync(
                    new evolib.Kvs.Models.ConnectionQueueData.OpenItems()
                {
                    items = new List <evolib.Kvs.Models.ConnectionQueueData.OpenItems.Item>()
                    {
                        new evolib.Kvs.Models.ConnectionQueueData.OpenItems.Item
                        {
                            itemId = item.itemId,
                            close  = !owned,
                        }
                    }
                }
                    );
            }

            return(Ok(new SwitchOwnedItem.Response()
            {
                playerId = req.playerId.Value,
                itemId = req.itemId,
                owned = owned,
            }));
        }
    public void DownloadData()
    {
        MasterDataLoader dataLoader = new MasterDataLoader();

        dataLoader.DownloadData();
    }
    public void UpdateData()
    {
        MasterDataLoader dataLoader = new MasterDataLoader();

        MasterDataSet = dataLoader.ReadData();
    }
Beispiel #15
0
        public async Task <IActionResult> SetPath([FromBody] SetPath.Request req)
        {
            try
            {
                var requester = new DummyRequester();

                var plainPath = req.path;
                var resPlain  = await requester.GetAsync(plainPath);

                if (resPlain.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(BadRequest("Not Found: plain masterdata."));
                }

                var encryptPath = req.path.Substring(0, req.path.Length - Path.GetExtension(req.path).Length);
                var resEncrypt  = await requester.GetBinaryAsync(encryptPath);

                if (resEncrypt.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(BadRequest("Not Found: encryption masterdata."));
                }

                var s3PutClient = new AmazonS3Client(
                    Amazon.RegionEndpoint.GetBySystemName(DeliveryDataInfo.S3BucketRegion)
                    );

                var plainKey = evolib.Util.KeyGen.GetUrlSafe(64);
                {
                    var putReq = new PutObjectRequest()
                    {
                        BucketName = DeliveryDataInfo.S3BucketName,

                        Key = plainKey,

                        InputStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(resPlain.Payload)),
                    };
                    var putRes = await s3PutClient.PutObjectAsync(putReq);
                }

                var encryptkey = evolib.Util.KeyGen.GetUrlSafe(32);
                {
                    var putReq = new PutObjectRequest()
                    {
                        BucketName = DeliveryDataInfo.S3BucketName,

                        Key = encryptkey,

                        InputStream = new MemoryStream(resEncrypt.Payload),
                    };
                    var putRes = await s3PutClient.PutObjectAsync(putReq);
                }


                var masterData = await MasterDataLoader.ParseAsync(resPlain.Payload, "", "");

                var masterDataPath = new MasterDataPath();
                masterDataPath.Model.pathSrc     = req.path;
                masterDataPath.Model.s3KeyPlain  = plainKey;
                masterDataPath.Model.pathPlain   = $"https://{DeliveryDataInfo.CfDomainName }/{plainKey}";
                masterDataPath.Model.pathEncrypt = $"https://{DeliveryDataInfo.CfDomainName }/{encryptkey}";
                masterDataPath.Model.updateDate  = System.DateTime.UtcNow;
                masterDataPath.Model.version     = masterData.VersionStr;
                await masterDataPath.SaveAsync();


                System.Action <GenericData> pushRecord = (record) =>
                {
                    record.MasterDataPathRecord(
                        req.path,
                        plainKey,
                        $"https://{DeliveryDataInfo.CfDomainName }/{plainKey}",
                        $"https://{DeliveryDataInfo.CfDomainName }/{encryptkey}",
                        masterData.VersionStr
                        );
                };
                var rec = await Common2DB.GenericDatas.FindAsync(GenericData.Type.MasterDataPath);

                if (rec == null)
                {
                    rec = new GenericData();
                    pushRecord(rec);
                    await Common2DB.GenericDatas.AddAsync(rec);
                }
                else
                {
                    pushRecord(rec);
                }
                await Common2DB.SaveChangesAsync();


                var res = new SetPath.Response();
                return(Ok(res));
            }
            catch (System.Exception e)
            {
                return(BadRequest("Failed to update."));
            }
        }
Beispiel #16
0
        public async Task <IActionResult> SetPath(string path, string pathEncrypt)
        {
            try
            {
                if (string.IsNullOrEmpty(pathEncrypt))
                {
                    pathEncrypt = path.Substring(0, path.Length - Path.GetExtension(path).Length);
                }

                var requester = new DummyRequester();
                var response  = await requester.GetAsync(pathEncrypt);

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(BadRequest("param: pathEncrypt is invalid."));
                }
                response = await requester.GetAsync(path);

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(BadRequest("param: path is invalid."));
                }

                var masterData = await MasterDataLoader.ParseAsync(response.Payload, "", "");

                var masterDataPath = new MasterDataPath();
                masterDataPath.Model.pathSrc     = path;
                masterDataPath.Model.s3KeyPlain  = "";
                masterDataPath.Model.pathPlain   = path;
                masterDataPath.Model.pathEncrypt = pathEncrypt;
                masterDataPath.Model.updateDate  = System.DateTime.UtcNow;
                masterDataPath.Model.version     = masterData.VersionStr;
                await masterDataPath.SaveAsync();


                System.Action <GenericData> pushRecord = (record) =>
                {
                    record.MasterDataPathRecord(
                        path,
                        "",
                        path,
                        pathEncrypt,
                        masterData.VersionStr
                        );
                };
                var rec = await Common2DB.GenericDatas.FindAsync(GenericData.Type.MasterDataPath);

                if (rec == null)
                {
                    rec = new GenericData();
                    pushRecord(rec);
                    await Common2DB.GenericDatas.AddAsync(rec);
                }
                else
                {
                    pushRecord(rec);
                }
                await Common2DB.SaveChangesAsync();
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            var res = new SetPath.Response();

            return(Ok(res));
        }