public async Task <ICollection <AccountsSearchResponseItem>?> FindAccounts( string accountNick, RealmType realmType, RequestLanguage language) { var searchResponse = await _wargamingApiClient.FindAccounts(accountNick, realmType, language); if (searchResponse == null) { return(null); } var accounts = _mapper.Map <List <WotAccountListResponse>, List <AccountsSearchResponseItem> >(searchResponse); if (searchResponse.Count > 100) { return(accounts); } var accountIds = accounts.Select(a => a.AccountId).ToArray(); var shortAccountInfos = await _wargamingApiClient.GetShortPlayerAccountsInfo(accountIds, realmType, language); var accountClans = await _wargamingApiClient.GetBulkPlayerClans(accountIds, realmType, language); List <ClanInfo>?clans = null; if (accountClans != null) { clans = await _wargamingApiClient.GetShortClansInfo(accountClans.Where(c => c.ClanId.HasValue).Select(c => c.ClanId !.Value).ToArray(), realmType, language); } for (int i = 0; i < accounts.Count; i++) { var accountResponse = accounts.ToArray()[i]; var shortAccountInfo = shortAccountInfos?.FirstOrDefault(a => a.AccountId == accountResponse.AccountId); if (shortAccountInfo != null) { _mapper.Map(shortAccountInfo, accountResponse); } // Clan if (accountClans != null && clans != null) { var aClan = accountClans.FirstOrDefault(c => c.AccountId == accountResponse.AccountId); var clan = clans.FirstOrDefault(c => c.ClanId == aClan?.ClanId); if (clan != null) { accountResponse.ClanTag = clan.Tag; } } } // Filter WOT Blitz accounts accounts = accounts.Where(a => a.BattlesCount > 0).ToList(); return(accounts); }
public AccountRequest(long accountId, RealmType realmType, RequestLanguage requestLanguage, string?authenticationToken = null) { AccountId = accountId; RealmType = realmType; RequestLanguage = requestLanguage; AuthenticationToken = authenticationToken; }
protected async Task <T?> GetFromBlitzApi <T>( RealmType realmType, RequestLanguage language, string method, params string[] queryParameters) where T : class { string uri = GetUri(realmType, language, method, queryParameters); _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await _httpClient.GetAsync(uri); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var responseBody = JsonConvert.DeserializeObject <ResponseBody <T> >(responseString); switch (responseBody.Status) { case "ok": return(responseBody.Data); case "error": { var error = responseBody.Error; var message = $"Field:{(error?.Field ?? "undefined")} Message:{(error?.Message ?? "undefined")} Value:{(error?.Value ?? "undefined")} Code:{(error?.Code ?? "undefined")}"; throw new ArgumentException(message); } default: throw new ArgumentException($"Unexpected response body status '{responseBody.Status}'"); } }
public async Task <AccountInfoHistoryResponse> GetAccountInfoHistory(RealmType realm, long accountId, DateTime startDate, RequestLanguage requestLanguage) { var contextData = new AccountHistoryInformationPipelineContextData(startDate); try { var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage)); context.AddOrReplace(contextData); var pipeline = new Pipeline <IOperationContext>(_operationFactory); pipeline.AddOperation <ReadAccountInfoFromDbOperation>() .AddOperation <ReadAccountInfoHistoryFromDbOperation>() .AddOperation <CheckIfHistoryIsEmptyOperation>() .AddOperation <FillOverallStatisticsOperation>() .AddOperation <FillPeriodStatisticsOperation>() .AddOperation <FillPeriodDifferenceOperation>() .AddOperation <FillStatisticsDifferenceOperation>() .AddOperation <FillAccountInfoHistoryResponse>() ; var firstOperation = pipeline.Build(); if (firstOperation != null) { await firstOperation .Invoke(context, null) .ConfigureAwait(false); } } catch (Exception e) { _logger.LogError(e, "GetAccountInfoHistory error"); throw; } return(contextData?.Response ?? new AccountInfoHistoryResponse()); }
public WorldContext GetWorldContext(RealmType type) { WorldContext context; switch (type) { case RealmType.TitansLeague: { context = _serviceProvider.GetService <TitansLeagueWorldContext>(); break; } case RealmType.TwinkNation: { context = _serviceProvider.GetService <TwinkNationWorldContext>(); break; } case RealmType.MountOlympus: { context = _serviceProvider.GetService <MountOlympusWorldContext>(); break; } //case RealmType.Helios: //{ // context = _serviceProvider.GetService<HeliosWorldContext>(); // break; //} default: throw new ArgumentOutOfRangeException(nameof(type), type, $"RealmType {type} is not supported"); } return(context); }
public void UpdateWorldServer(string name, Uri location, RealmFlags flags, RealmCategory category, RealmType type, RealmStatus status, int characterCount, int characterCapacity, Version clientVersion) { var id = OperationContext.Current.SessionId; Contract.Assume(!string.IsNullOrEmpty(id)); Realm realm = null; RealmManager.Instance.PostWait(mgr => realm = mgr.GetRealm(id)).Wait(); if (realm == null) throw new InvalidOperationException("A realm has not registered before updating itself."); RealmManager.Instance.PostAsync(() => { realm.Name = name; realm.Location = location; realm.Flags = flags; realm.Category = category; realm.Type = type; realm.Status = status; realm.Population = characterCount; realm.Capacity = characterCapacity; realm.ClientVersion = clientVersion; }); }
/// <summary> /// Gathers all account information /// </summary> /// <param name="realmType">Account region</param> /// <param name="accountId">AccountId</param> /// <param name="requestLanguage">Request language</param> /// <param name="wgToken">Wargaming authentication token</param> /// <returns></returns> public Task <AccountInfoResponse> GatherAccountInformation( RealmType realmType, long accountId, RequestLanguage requestLanguage, [GlobalState("WgToken")] string wgToken) { return(_wargamingAccounts.GatherAndSaveAccountInformation(realmType, accountId, requestLanguage, wgToken)); }
public async Task <List <WotEncyclopediaVehiclesResponse>?> GetVehicles(RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { var response = await GetFromBlitzApi <Dictionary <string, WotEncyclopediaVehiclesResponse> >( realmType, language, "encyclopedia/vehicles/").ConfigureAwait(false); return(response?.Values.ToList()); }
public void UpdateWorldServer(string name, Uri location, RealmFlags flags, RealmCategory category, RealmType type, RealmStatus status, int characterCount, int characterCapacity, Version clientVersion) { Contract.Requires(!string.IsNullOrEmpty(name)); Contract.Requires(location != null); Contract.Requires(characterCount >= 0); Contract.Requires(characterCapacity >= 0); Contract.Requires(clientVersion != null); }
public async Task <List <WotAccountListResponse>?> FindAccounts(string nickName, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { return(await GetFromBlitzApi <List <WotAccountListResponse> >( realmType, language, "account/list/", $"search={nickName}").ConfigureAwait(false)); }
public async Task <List <WotClanListResponse>?> FindClans(string searchString, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { return(await GetFromBlitzApi <List <WotClanListResponse> >( realmType, language, "clans/list/", $"search={searchString}").ConfigureAwait(false)); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public Realm(string realmName, RealmType serverType, RealmStatus serverStatus, RealmTimeZone timeZone, RealmColor color, int maxPlayers) { RealmName = realmName; ServerType = serverType; ServerStatus = serverStatus; TimeZone = timeZone; Color = color; MaxPlayers = maxPlayers; }
public async Task <List <WotAccountTanksStatistics>?> GetPlayerAccountTanksInfo( long accountId, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { var tanks = await GetFromBlitzApi <Dictionary <string, List <WotAccountTanksStatistics> > >( realmType, language, "tanks/stats/", $"account_id={accountId}").ConfigureAwait(false); return(tanks?[accountId.ToString()] ?? new List <WotAccountTanksStatistics>()); }
public async Task <ICollection <ClanSearchResponseItem>?> FindClans( string searchString, RealmType realmType, RequestLanguage language) { var response = await _wargamingApiClient.FindClans(searchString, realmType, language); if (response == null) { return(null); } return(_mapper.Map <List <WotClanListResponse>, List <ClanSearchResponseItem> >(response)); }
public async Task <List <InventoryModel> > MapInventory(RealmType realmType, List <InventoryModel> inventoryModels) { var worldContext = _contextService.GetWorldContext(realmType); var itemEntries = inventoryModels.Select(x => x.ItemEntry).ToList(); var items = await worldContext.ItemTemplate.Where(x => itemEntries.Contains(x.Entry)).ToListAsync(); foreach (var inventoryModel in inventoryModels) { inventoryModel.Item = items.FirstOrDefault(x => x.Entry == inventoryModel.ItemEntry); } return(inventoryModels); }
public async Task <List <ClanInfo>?> GetShortClansInfo(long[] clanIds, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { if (clanIds.Length == 0) { return(null); } var clanInfo = await GetFromBlitzApi <Dictionary <string, ClanInfo> >( realmType, language, "clans/info/", $"clan_id={string.Join(',', clanIds)}&fields=clan_id,tag").ConfigureAwait(false); return(clanInfo?.Values.ToList()); }
public void RegisterWorldServer(string name, Uri location, RealmFlags flags, RealmCategory category, RealmType type, RealmStatus status, int characterCount, int characterCapacity, Version clientVersion) { var id = OperationContext.Current.SessionId; Contract.Assume(!string.IsNullOrEmpty(id)); RealmManager.Instance.PostAsync(mgr => mgr.AddRealm(new Realm(id, name, location, clientVersion) { Flags = flags, Category = category, Type = type, Status = status, Population = characterCount, Capacity = characterCapacity, })); }
public async Task <ClanAccountInfo?> GetPlayerClanInfo(long accountId, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { var clanInfo = await GetFromBlitzApi <Dictionary <string, ClanAccountInfo> >( realmType, language, "clans/accountinfo/", $"account_id={accountId}").ConfigureAwait(false); if (clanInfo != null && clanInfo.ContainsKey(accountId.ToString())) { return(clanInfo[accountId.ToString()]); } return(null); }
public async Task <AccountAchievementsResponse> GetTankAchievements(RealmType realm, long accountId, long tankId, RequestLanguage requestLanguage) { try { // Get account achievements from WG API var wgAchievements = await _wargamingAchievementsService.GetTankAchievements(accountId, tankId, realm, requestLanguage); return(await FillAchievements(accountId, wgAchievements, requestLanguage)); } catch (Exception e) { _logger.LogError(e, "GetTankAchievements error"); throw; } }
private string GetUri(RealmType realmType, RequestLanguage language, string method, string[] queryParameters) { var uri = new StringBuilder($"{_blitzApiUrls[realmType]}{method}"); uri.Append("?application_id=") .Append(_wargamingApiSettings.ApplicationId) .Append("&language=") .Append(language.ToString().ToLower()); if (queryParameters != null) { foreach (var param in queryParameters) { uri.Append("&") .Append(param); } } return(uri.ToString()); }
WotClanMembersDictionaryResponse?)> GetStaticDictionariesAsync( RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { var encyclopedia = await GetFromBlitzApi <WotEncyclopediaInfoResponse>( realmType, language, "encyclopedia/info/" ).ConfigureAwait(false); var clanGlossaryResponse = await GetFromBlitzApi <WotClanMembersDictionaryResponse>( realmType, language, "clans/glossary/"); return(encyclopedia, clanGlossaryResponse); }
/// <inheritdoc /> public RealmInfo(RealmType realmType, bool isLocked, DefaultRealmInformation defaultInformation, [CanBeNull] RealmBuildInformation buildInfo) { if (!Enum.IsDefined(typeof(RealmType), realmType)) { throw new ArgumentOutOfRangeException(nameof(realmType), "Value should be defined in the RealmType enum."); } //Don't check build info. It can be null. Only if the specify build was not included RealmType = realmType; this.isLocked = isLocked; DefaultInformation = defaultInformation; BuildInfo = buildInfo; //Check after initialization if we have everything needed if (HasBuildInformation && BuildInfo == null) { throw new ArgumentNullException(nameof(buildInfo), $"{defaultInformation} has the {RealmFlags.SpecifyBuild} flags but no build information is provided."); } }
public async Task <WotAccountInfo?> GetPlayerAccountInfo( long accountId, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En, string?authenticationToken = null) { var account = authenticationToken == null ? await GetFromBlitzApi <Dictionary <string, WotAccountInfo> >( realmType, language, "account/info/", $"account_id={accountId}").ConfigureAwait(false) : await GetFromBlitzApi <Dictionary <string, WotAccountInfo> >( realmType, language, "account/info/", $"account_id={accountId}", $"access_token={authenticationToken}").ConfigureAwait(false); return(account?[accountId.ToString()]); }
public async Task <AccountInfoResponse> GatherAndSaveAccountInformation( RealmType realm, long accountId, RequestLanguage requestLanguage, string wargamingToken) { var contextData = new AccountInformationPipelineContextData(); try { var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage, wargamingToken)); context.AddOrReplace(contextData); var pipeline = new Pipeline <IOperationContext>(_operationFactory); pipeline.AddOperation <GetAccountInfoOperation>() .AddOperation <ReadAccountInfoFromDbOperation>() .AddOperation <CheckLastBattleDateOperation>() .AddOperation <GetTanksInfoOperation>() .AddOperation <CalculateStatisticsOperation>() .AddOperation <SaveAccountAndTanksOperation>() .AddOperation <BuildAccountInfoResponseOperation>() ; var firstOperation = pipeline.Build(); if (firstOperation != null) { await firstOperation .Invoke(context, null) .ConfigureAwait(false); } } catch (Exception e) { _logger.LogError(e, "GatherAndSaveAccountInformation error"); throw; } return(contextData?.Response ?? new AccountInfoResponse()); }
public override byte[] OnRecv(byte[] section, int length) { int t; byte[] data; for (int i = 0; i < length; i++) { input.Add(section[i]); } RealmType code = (RealmType)input[0]; switch (code) { case RealmType.LOGON_CHALLENGE: // Logon challenge case RealmType.RECONNECT_CHALLENGE: { if (input.Length < 34 || input.Length < 34 + input[33]) { return(null); } int clientVersion = input.Seek(11).GetWord(); //byte[] blu = input.GetArray(5, input[33]); //Console.WriteLine("DEBUG:" + clientVersion); userName = input.GetArray(34, input[33]); data = input; input.Length = 0; sUserName = System.Text.Encoding.ASCII.GetString(userName); //string ble = System.Text.Encoding.ASCII.GetString(blu); byte [] hash = rl.GetUserPasswordHash(sUserName); //Console.WriteLine("DEBUG - ble:" + ble + "user: "******" code: " + code); } ByteArrayBuilder p = new ByteArrayBuilder(); p.Add((byte)1, 3); p.Add(new byte[116]); return(p); } if (LogMessageEvent != null) { LogMessageEvent(sUserName + " code: " + code); } byte [] res = new Byte[hash.Length + salt.Length]; Const.rand.NextBytes(salt); #if CHECK salt = new byte[] { 0x33, 0xf1, 0x40, 0xd4, 0x6c, 0xb6, 0x6e, 0x63, 0x1f, 0xdb, 0xbb, 0xc9, 0xf0, 0x29, 0xad, 0x88, 0x98, 0xe0, 0x5e, 0xe5, 0x33, 0x87, 0x61, 0x18, 0x18, 0x5e, 0x56, 0xdd, 0xe8, 0x43, 0x67, 0x4f }; #endif t = 0; foreach (byte s in salt) { res[t++] = s; } foreach (byte s in hash) { res[t++] = s; } SHA1 sha = new SHA1CryptoServiceProvider(); byte [] hash2 = sha.ComputeHash(res, 0, res.Length); byte [] x = Reverse(hash2); rN = Reverse(N); Const.rand.NextBytes(b); #if CHECK b = new byte[] { 0x86, 0x92, 0xE3, 0xA6, 0xBA, 0x48, 0xB5, 0xB1, 0x00, 0x4C, 0xEF, 0x76, 0x82, 0x51, 0x27, 0xB7, 0xEB, 0x7D, 0x1A, 0xEF }; #endif rb = Reverse(b); BigInteger bi = new BigInteger(x); BigInteger bi2 = new BigInteger(rN); G = new BigInteger(new byte[] { 7 }); v = G.modPow(bi, bi2); K = new BigInteger(new Byte[] { 3 }); BigInteger temp1 = K * v; BigInteger temp2 = G.modPow(new BigInteger(rb), new BigInteger(rN)); BigInteger temp3 = temp1 + temp2; B = temp3 % new BigInteger(rN); ByteArrayBuilder pack = new ByteArrayBuilder(); pack.Add((byte)0, 0, 0); pack.Add(Reverse(B.getBytes(32))); pack.Add((byte)1, 7, 32); pack.Add(N); pack.Add(salt); pack.Add(new byte[16]); return(pack); } case RealmType.LOGON_PROOF: // Logon proof case RealmType.RECONNECT_PROOF: { if (input.Length < 53) { return(null); } byte[] A = input.GetArray(1, 32); byte[] kM1 = input.GetArray(33, 20); data = input; input.Length = 0; #if CHECK A = new byte[] { 0x23, 0x2f, 0xb1, 0xb8, 0x85, 0x29, 0x64, 0x3d, 0x95, 0xb8, 0xdc, 0xe7, 0x8f, 0x27, 0x50, 0xc7, 0x5b, 0x2d, 0xf3, 0x7a, 0xcb, 0xa8, 0x73, 0xeb, 0x31, 0x07, 0x38, 0x39, 0xed, 0xa0, 0x73, 0x8d }; #endif byte [] rA = Reverse(A); byte [] AB = Concat(A, Reverse(B.getBytes(32))); SHA1 shaM1 = new SHA1CryptoServiceProvider(); byte [] U = shaM1.ComputeHash(AB); byte [] rU = Reverse(U); // SS_Hash BigInteger temp1 = v.modPow(new BigInteger(rU), new BigInteger(rN)); BigInteger temp2 = temp1 * new BigInteger(rA); BigInteger temp3 = temp2.modPow(new BigInteger(rb), new BigInteger(rN)); byte [] S1 = new byte[16]; byte [] S2 = new byte[16]; byte [] S = temp3.getBytes(32); byte [] rS = Reverse(S); for (t = 0; t < 16; t++) { S1[t] = rS[t * 2]; S2[t] = rS[(t * 2) + 1]; } byte [] hashS1 = shaM1.ComputeHash(S1); byte [] hashS2 = shaM1.ComputeHash(S2); byte [] SS_Hash = new byte[hashS1.Length + hashS2.Length]; for (t = 0; t < hashS1.Length; t++) { SS_Hash[t * 2] = hashS1[t]; SS_Hash[(t * 2) + 1] = hashS2[t]; } // cal M1 byte [] NHash = shaM1.ComputeHash(N); byte [] GHash = shaM1.ComputeHash(G.getBytes()); byte [] userHash = shaM1.ComputeHash(userName); byte [] NG_Hash = new byte[20]; for (t = 0; t < 20; t++) { NG_Hash[t] = (byte)(NHash[t] ^ GHash[t]); } byte [] Temp = Concat(NG_Hash, userHash); Temp = Concat(Temp, salt); Temp = Concat(Temp, A); Temp = Concat(Temp, Reverse(B.getBytes(32))); Temp = Concat(Temp, SS_Hash); byte [] M1 = shaM1.ComputeHash(Temp); ByteArrayBuilder pack; if (!ByteArray.Same(M1, kM1)) { if (LogMessageEvent != null) { LogMessageEvent(sUserName + " code: " + code); } pack = new ByteArrayBuilder(); pack.Add((byte)1, 3); pack.Add(new byte[24]); return(pack); } if (LogMessageEvent != null) { LogMessageEvent(sUserName + " code: " + code); } rl.SetUserSessionKey(sUserName, SS_Hash); // cal M2 Temp = Concat(A, M1); Temp = Concat(Temp, SS_Hash); byte [] M2 = shaM1.ComputeHash(Temp); pack = new ByteArrayBuilder(); pack.Add((byte)1, 0); pack.Add(M2); pack.Add(new byte[4]); return(pack); } case RealmType.UPDATESRV: // Update server if (input.Length < 1) { return(null); } data = input; input.Length = 0; if (LogMessageEvent != null) { LogMessageEvent("UPDATESRV"); } break; case RealmType.REALMLIST: // Realm List { if (input.Length < 1) { return(null); } byte[] request = input.GetArray(1, 4); input.Length = 0; if (LogMessageEvent != null) { LogMessageEvent("REALMLIST"); } ByteArrayBuilder pack = new ByteArrayBuilder(false); pack.Add((byte)RealmType.REALMLIST, 0, 0); pack.Add(request); rl.GetRealmList(sUserName, pack); pack.Add((byte)0, (byte)0); pack.Set(1, (ushort)(pack.Length - 3)); return(pack); } default: data = input; input.Length = 0; if (LogMessageEvent != null) { LogMessageEvent("Receive unknown command {0}" + data[0]); } break; } byte [] ret = { 0, 0 }; return(ret); }
void UpdateRealms(object source, ElapsedEventArgs e) { PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_REALMLIST); SQLResult result = DB.Login.Query(stmt); Dictionary <RealmHandle, string> existingRealms = new Dictionary <RealmHandle, string>(); foreach (var p in _realms) { existingRealms[p.Key] = p.Value.Name; } _realms.Clear(); // Circle through results and add them to the realm map if (!result.IsEmpty()) { do { var realm = new Realm(); uint realmId = result.Read <uint>(0); realm.Name = result.Read <string>(1); realm.ExternalAddress = IPAddress.Parse(result.Read <string>(2)); realm.LocalAddress = IPAddress.Parse(result.Read <string>(3)); realm.LocalSubnetMask = IPAddress.Parse(result.Read <string>(4)); realm.Port = result.Read <ushort>(5); RealmType realmType = (RealmType)result.Read <byte>(6); if (realmType == RealmType.FFAPVP) { realmType = RealmType.PVP; } if (realmType >= RealmType.MaxType) { realmType = RealmType.Normal; } realm.Type = (byte)realmType; realm.Flags = (RealmFlags)result.Read <byte>(7); realm.Timezone = result.Read <byte>(8); AccountTypes allowedSecurityLevel = (AccountTypes)result.Read <byte>(9); realm.AllowedSecurityLevel = (allowedSecurityLevel <= AccountTypes.Administrator ? allowedSecurityLevel : AccountTypes.Administrator); realm.PopulationLevel = result.Read <float>(10); realm.Build = result.Read <uint>(11); byte region = result.Read <byte>(12); byte battlegroup = result.Read <byte>(13); realm.Id = new RealmHandle(region, battlegroup, realmId); UpdateRealm(realm); var subRegion = new RealmHandle(region, battlegroup, 0).GetAddressString(); if (!_subRegions.Contains(subRegion)) { _subRegions.Add(subRegion); } if (!existingRealms.ContainsKey(realm.Id)) { Log.outInfo(LogFilter.Realmlist, "Added realm \"{0}\" at {1}:{2}", realm.Name, realm.ExternalAddress.ToString(), realm.Port); } else { Log.outDebug(LogFilter.Realmlist, "Updating realm \"{0}\" at {1}:{2}", realm.Name, realm.ExternalAddress.ToString(), realm.Port); } existingRealms.Remove(realm.Id); }while (result.NextRow()); } foreach (var pair in existingRealms) { Log.outInfo(LogFilter.Realmlist, "Removed realm \"{0}\".", pair.Value); } }
public async Task <IReadOnlyList <IFindClans_Clans>?> FindClans(string clanNameOrTag, RealmType realmType) { var result = new List <IFindClans_Clans>(); var faker = new Faker(FakerLanguage(GetLanguage())); var random = faker.Random.Number(10, 80); for (int i = 0; i < random; i++) { result.Add(new FindClans_Clans_ClanSearchResponseItem( faker.Random.Long(100000, 999999), Convert.ToInt32((faker.Date.Past() - new DateTime(1970, 1, 1)).TotalSeconds), faker.Random.Number(1, 50), faker.Lorem.Word(), faker.Lorem.Letter())); } await Task.Delay(1000); return(result); }
public async Task <IReadOnlyList <IFindPlayers_Players>?> FindPlayers(string accountNick, RealmType realmType) { var result = new List <IFindPlayers_Players>(); var faker = new Faker(FakerLanguage(GetLanguage())); var random = faker.Random.Number(10, 80); for (int i = 0; i < random; i++) { result.Add(new FindPlayers_Players_AccountsSearchResponseItem( faker.Random.Long(100000, 999999), faker.Internet.UserName(), faker.Hacker.Abbreviation().OrNull(faker, 0.6f), faker.Date.Past(), faker.Random.Number(10, 20000), faker.Random.Number(30, 90))); } await Task.Delay(1000); return(result); }
public void Update(Realm srcRealm) { Name = srcRealm.Name; Slug = srcRealm.Slug; Queue = srcRealm.Queue; Status = srcRealm.Status; Population = srcRealm.Population; Type = srcRealm.Type; }
public async Task <List <InventoryModel> > MapCustomInventory(RealmType realmType, List <InventoryModel> inventoryModels, int owner = 0) { var worldContext = _contextService.GetWorldContext(realmType); var characterContext = _contextService.GetCharacterContext(realmType); var itemEntries = inventoryModels.Select(x => x.ItemEntry).ToList(); var itemGuids = inventoryModels.Select(x => x.ItemGuid).ToList(); var upgrades = await characterContext.CustomItemUpgrades.Where(x => itemGuids.Contains(x.ItemGuid) && x.IsActive()).ToListAsync(); var upgradesInfo = await worldContext.CustomItemUpgrades.ToListAsync(); var items = await worldContext.ItemTemplate.Where(x => itemEntries.Contains(x.Entry)).ToListAsync(); var sets = await characterContext.CustomItemUpgradeSets.Where(x => x.Owner == owner).ToListAsync(); if (!sets.Any()) { sets.Add(new CustomItemUpgradeSets(owner, 0, "Main Set")); } var character = await characterContext.Characters.Where(x => x.Id == owner).Select(x => new { Name = x.Name, Class = x.Class }).FirstOrDefaultAsync(); var classColor = Utilities.GetClassColor(character.Class); foreach (var item in items) { var inventoryItem = inventoryModels.FirstOrDefault(x => x.ItemEntry == item.Entry); if (inventoryItem == null) { continue; } var upgrade = upgrades.FirstOrDefault(x => x.ItemGuid == inventoryItem.ItemGuid); if (upgrade == null) { continue; } var activeSet = sets.Find(x => x.SetId == upgrade.SetId); if (activeSet == null) { continue; } CustomItemUpgrades upgradeStatType; if (upgrade.StatId1 > 0) { upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId1); item.StatType1 = upgradeStatType?.StatType ?? 0; item.StatValue1 = upgradeStatType?.StatValue ?? 0; } if (upgrade.StatId2 > 0) { upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId2); item.StatType2 = upgradeStatType?.StatType ?? 0; item.StatValue2 = upgradeStatType?.StatValue ?? 0; } if (upgrade.StatId3 > 0) { upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId3); item.StatType3 = upgradeStatType?.StatType ?? 0; item.StatValue3 = upgradeStatType?.StatValue ?? 0; } if (upgrade.StatId4 > 0) { upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId4); item.StatType4 = upgradeStatType?.StatType ?? 0; item.StatValue4 = upgradeStatType?.StatValue ?? 0; } if (upgrade.StatId5 > 0) { upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId5); item.StatType5 = upgradeStatType?.StatType ?? 0; item.StatValue5 = upgradeStatType?.StatValue ?? 0; } if (upgrade.ArmorId > 0) { upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.ArmorId); item.Armor = upgradeStatType?.StatValue ?? 0; } if (upgrade.DmgId1 > 0 || upgrade.DmgId2 > 0) { if (item.Class == (int)ItemClass.ITEM_CLASS_WEAPON) { var twoHandBonus = item.InventoryType == (int)InventoryType.INVTYPE_TWOHANDWEAPON ? TwoHandBonus : 1.0f; upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.DmgId1); item.DmgMin1 = (float)((upgradeStatType?.StatValue ?? 0) * twoHandBonus); item.DmgMax1 = (float)((upgradeStatType?.StatValue ?? 0) * MaxWeaponDamageBonus * twoHandBonus); upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.DmgId2); item.DmgMin2 = (float)((upgradeStatType?.StatValue ?? 0) * twoHandBonus); item.DmgMax2 = (float)((upgradeStatType?.StatValue ?? 0) * MaxWeaponDamageBonus * twoHandBonus); } } if (!upgrade.Name.IsNullOrEmpty()) { item.Name = upgrade.Name; } if (upgrade.Quality >= 0) { item.Quality = (byte)upgrade.Quality; } if (upgrade.UpgradeLevel > 0) { item.ItemLevel = (short)upgrade.UpgradeLevel; } // Not in use yet //upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId6); //item.StatType6 = upgradeStatType?.StatType ?? 0; //item.StatValue6 = upgradeStatType?.StatValue ?? 0; //upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId7); //item.StatType7 = upgradeStatType?.StatType ?? 0; //item.StatValue7 = upgradeStatType?.StatValue ?? 0; //upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId8); //item.StatType8 = upgradeStatType?.StatType ?? 0; //item.StatValue8 = upgradeStatType?.StatValue ?? 0; //upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId9); //item.StatType9 = upgradeStatType?.StatType ?? 0; //item.StatValue9 = upgradeStatType?.StatValue ?? 0; //upgradeStatType = upgradesInfo.FirstOrDefault(x => x.Id == upgrade.StatId10); //item.StatType10 = upgradeStatType?.StatType ?? 0; //item.StatValue10 = upgradeStatType?.StatValue ?? 0; item.Description = "--- Upgrade Information ---" + $"<br />Owner: <font color='#{classColor}'>{character.Name}</font>." + $"<br />Upgrade Level: <font color='red'>{upgrade.UpgradeLevel}</font>." + $"<br />Set: <font color='red'>{activeSet.SetName}</font>."; } foreach (var inventoryModel in inventoryModels) { inventoryModel.Item = items.FirstOrDefault(x => x.Entry == inventoryModel.ItemEntry); } return(inventoryModels); }
public void UpdateWorldServer(string name, Uri location, RealmFlags flags, RealmCategory category, RealmType type, RealmStatus status, int characterCount, int characterCapacity, Version clientVersion) { Contract.Requires(!string.IsNullOrEmpty(name)); Contract.Requires(location != null); Contract.Requires(characterCount >= 0); Contract.Requires(characterCapacity >= 0); Contract.Requires(clientVersion != null); }
public async Task <List <WotAccountInfo>?> GetShortPlayerAccountsInfo(long[] accountIds, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En, string?authenticationToken = null) { var accounts = await GetFromBlitzApi <Dictionary <string, WotAccountInfo> >( realmType, language, "account/info/", $"account_id={string.Join(',', accountIds)}&fields=account_id,nickname,last_battle_time,statistics.all.battles,statistics.all.wins").ConfigureAwait(false); return(accounts?.Values.ToList()); }
/// <inheritdoc /> public RealmInfo(RealmType realmType, bool isLocked, [NotNull] DefaultRealmInformation information) : this(realmType, isLocked, information, null) { }
public static IEnumerable<Realm> WithType(this IEnumerable<Realm> realms, RealmType realmType) { return realms.Where(r => r.Type == realmType); }
public async Task <List <ClanAccountInfo>?> GetBulkPlayerClans(long[] accountIds, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { if (accountIds.Length == 0) { return(null); } var clanInfo = await GetFromBlitzApi <Dictionary <string, ClanAccountInfo> >( realmType, language, "clans/accountinfo/", $"account_id={string.Join(',', accountIds)}&fields=account_id,clan_id,account_name").ConfigureAwait(false); return(clanInfo?.Values.Where(c => c != null).ToList()); }