public static bool Check(this PackedResult data) { return(data != null && data.Result != null && IsValidReportTime(data.ReportTime) && Enum.IsDefined(typeof(PackedResultType), data.Type) && CheckResult(data.Result, data.Type)); }
private static void Filter(int gameId, PackedResult data) { if (data.Type == PackedResultType.LobbyService && data.Result is LobbyServiceResult svc) { _service = svc; _serviceTime = Environment.TickCount; } if (data.Type == PackedResultType.LobbyCharacter && data.Result is LobbyCharacterResult chr) { _character = chr; _characterTime = Environment.TickCount; } }
public bool TryAdd(PackedResult pr) { switch (pr.Type) { // ignoring case PackedResultType.Chatlog: return(false); case PackedResultType.MarketRequest: return(false); // acknowledging case PackedResultType.CurrentWorld: if (!(pr.Result is CurrentWorldResult cwr)) { throw new InvalidCastException("Failed to convert type"); } Context.World = cwr.WorldId; return(true); // send on diff case PackedResultType.RetainerList: if (!(pr.Result is RetainerInfoResult rir)) { throw new InvalidCastException("Failed to convert type"); } if (_rirOriginal.RetainerInfo.Select(x => x.RetainerName) .SequenceEqual(rir.RetainerInfo.Select(x => x.RetainerName))) { return(true); } _rirOriginal = rir; break; // contexting case PackedResultType.LobbyService: if (!(pr.Result is LobbyServiceResult lsr)) { throw new InvalidCastException("Failed to convert type"); } Context.ServiceId = lsr.ServiceId; break; case PackedResultType.Status: if (!(pr.Result is StatusResult sr)) { throw new InvalidCastException("Failed to convert type"); } Context.World = sr.CharacterCurrentWorld; Context.CharacterId = sr.CharacterId; Context.ConnectionNumber = Environment.TickCount; break; // direct send case PackedResultType.Artisan: break; case PackedResultType.Inventory: break; case PackedResultType.InventoryNetwork: break; case PackedResultType.LobbyCharacter: break; case PackedResultType.MarketHistory: break; case PackedResultType.MarketListing: break; case PackedResultType.MarketOverview: break; case PackedResultType.RetainerHistory: break; case PackedResultType.RetainerUpdate: break; default: throw new ArgumentOutOfRangeException(); } //if (Context.CharacterId == 0 || Context.World == 0) return false; _dataQueue.Enqueue(new MilvanethProtocol { Context = Context.Copy(), Data = pr }); return(true); }
private void LocalHandler(int gameId, PackedResult result) { var worldId = pool.GetContext(gameId).World; if (result.Type == PackedResultType.MarketRequest) { var itemid = ((MarketRequestResult)result.Result).ItemId; Task.Run(() => { RETRY: int ret = 0; var listing = new List <ListingData>(); var history = new List <HistoryData>(); PackedResultBundle res = null; try { var local = new ExchangeProcedure(); try { ret = local.Step2(itemid, out res); } catch (HttpRequestException exception) { ret = 02_0000 + (int)exception.Data["StatusCode"]; } if (!CheckVendor.NotValidResponseCode(ret)) { listing.AddRange(res.Listings.Select(x => ListingData.FromResultItem(x.RawItem, x.ReportTime, 0, x.WorldId))); history.AddRange(res.Histories.Select(x => HistoryData.FromResultItem(x.RawItem, x.ReportTime, 0, x.WorldId))); } if (ret % 10000 == 0511 && ApiVendor.ValidateAndRenewToken()) { goto RETRY; } var lst = (List <ListingData>)DataHolder.GetCache(worldId, itemid, 0); var hst = (List <HistoryData>)DataHolder.GetCache(worldId, itemid, 1); if (lst != null) { listing.RemoveAll(x => x.World == worldId); br.OverlayListingData = listing.Concat(lst) .OrderBy(x => x.UnitPrice).ToList(); } else { lst = br.OverlayListingData.Where(x => x.World == worldId && x.ItemId == itemid).ToList(); if (lst.Any()) { listing.RemoveAll(x => x.World == worldId); br.OverlayListingData = listing.Concat(lst) .OrderBy(x => x.UnitPrice).ToList(); } br.OverlayListingData = listing.OrderBy(x => x.UnitPrice).ToList(); } if (hst != null) { history.RemoveAll(x => x.World == worldId); br.OverlayHistoryData = history.Concat(hst) .OrderByDescending(x => x.PurchaseTime).ToList(); } else { hst = br.OverlayHistoryData.Where(x => x.World == worldId && x.ItemId == itemid).ToList(); if (hst.Any()) { history.RemoveAll(x => x.World == worldId); br.OverlayHistoryData = history.Concat(hst) .OrderByDescending(x => x.PurchaseTime).ToList(); } br.OverlayHistoryData = history.OrderByDescending(x => x.PurchaseTime).ToList(); } } catch (HttpRequestException ex) { ret = 02_0000 + (int)(ex.Data["StatusCode"]); if (ret == 02_0511 && ApiVendor.ValidateAndRenewToken()) { goto RETRY; } } catch (Exception) { ret = 02_0000; } if (CheckVendor.NotValidResponseCode(ret)) { LoggingManagementService.WriteLine( $"Api Error: {MessageVendor.FormatError(ret)} on requesting {DictionaryManagementService.Item[itemid]}", "ApiSys"); } }); } if (result.Type == PackedResultType.MarketHistory) { var r = (MarketHistoryResult)result.Result; br.OverlayItemId = r.ItemId; var t = new List <HistoryData>(); foreach (var i in r.HistoryItems) { t.Add(new HistoryData { BuyerName = i.BuyerName, IsHq = i.IsHq == 1, ItemId = i.ItemId, OnMannequin = i.OnMannequin == 1, PurchaseTime = Helper.UnixTimeStampToDateTime(i.PurchaseTime), Quantity = i.Quantity, UnitPrice = i.UnitPrice, UpdateTime = DateTime.Now, World = worldId, Zone = 0 }); } DataHolder.AddCache(worldId, r.ItemId, 1, t, 120); } if (result.Type == PackedResultType.MarketListing) { var r = (MarketListingResult)result.Result; var t = new List <ListingData>(); foreach (var i in r.ListingItems) { t.Add(new ListingData { ItemId = i.ItemId, IsHq = i.IsHq == 1, Materia = new int[] { i.Materia1, i.Materia2, i.Materia3, i.Materia4, i.Materia5 }, UnitPrice = i.UnitPrice, Quantity = i.Quantity, Tax = i.TotalTax, Retainer = i.RetainerName, Artisan = i.ArtisanId.ToString("X"), OnMannequin = i.OnMannequin == 1, PlayerName = i.PlayerName, RetainerLocation = i.RetainerLocation, DyeId = i.DyeId, ListingTime = Helper.UnixTimeStampToDateTime(i.UpdateTime), UpdateTime = DateTime.Now, World = worldId, Zone = 0, }); } var sample = t.FirstOrDefault(); if (sample != null) { DataHolder.AddCache(worldId, sample.ItemId, 0, t, 120); } } LoggingManagementService.WriteLine($"Data Received: {result.Type.ToString()} @ {DictionaryManagementService.World[worldId]}", $"Game {gameId}"); }
public void SinkData(int identifier, PackedResult pr) { var container = _memTable.GetOrAdd(identifier, new DataContainer(_dataQueue)); container.TryAdd(pr); }