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)); }
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); }
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); }
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); }
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); }
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)); }
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 })); }
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); }
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)); }
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)); }
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, })); }