Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix universalis query not working in non-inject mode and misc fix #24

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 7 additions & 33 deletions Cafe.Matcha/Network/NetworkMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ internal interface INetworkMonitor

internal class NetworkMonitor : INetworkMonitor
{
private uint marketQueryItemId = 0;

public void HandleMessageReceived(string connection, long epoch, byte[] message)
{
Expand Down Expand Up @@ -524,42 +523,10 @@ private bool HandleMessageByOpcode(Packet packet)
}
else if (opcode == MatchaOpcode.MarketBoardItemListingCount)
{
if (packet.DataLength != 8)
{
return false;
}

var status = BitConverter.ToUInt32(data, 0);
var count = BitConverter.ToUInt32(data, 4);
var itemId = marketQueryItemId;

if (status == 0 && itemId != 0) // OK
{
ThreadPool.QueueUserWorkItem(o => Universalis.Client.QueryItem(State.Instance.WorldId, itemId, FireEvent));
FireEvent(new MarketBoardItemListingCountDTO()
{
Item = (int)itemId,
Count = (int)count,
World = State.Instance.WorldId
});
}

marketQueryItemId = 0;
return true;
}
else if (opcode == MatchaOpcode.MarketBoardRequestItemListingInfo)
{
if (packet.DataLength != 8)
{
return false;
}

var itemId = BitConverter.ToUInt32(data, 0);
if (itemId != 0)
{
marketQueryItemId = itemId;
}

return true;
}
else if (opcode == MatchaOpcode.MarketBoardItemListing)
Expand Down Expand Up @@ -587,6 +554,13 @@ private bool HandleMessageByOpcode(Packet packet)

if (itemId != 0)
{
ThreadPool.QueueUserWorkItem(o => Universalis.Client.QueryItem(State.Instance.WorldId, itemId, FireEvent));
FireEvent(new MarketBoardItemListingCountDTO
{
Item = (int)itemId,
Count = items.Count,
World = State.Instance.WorldId
});
FireEvent(new MarketBoardItemListingDTO()
{
Item = (int)itemId,
Expand Down
8 changes: 7 additions & 1 deletion Cafe.Matcha/Network/Universalis/PacketProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void LogStartObserved(MarketBoardItemRequest request)
.And(OnMarketBoardSalesBatch(startObservable))
.And(OnMarketBoardListingsBatch(startObservable))
.Then((request, sales, listings) => (request, sales, listings)))
.Where(ShouldUpload)
.Where(ShouldUpload)
.SubscribeOn(ThreadPoolScheduler.Instance)
.Subscribe(
data =>
Expand All @@ -225,6 +225,12 @@ private void UploadMarketBoardData(
ICollection<MarketBoardCurrentOfferings.MarketBoardItemListing> listings)
{
var catalogId = listings.FirstOrDefault()?.CatalogId ?? 0;
if (catalogId == 0)
{
Log?.Invoke(this, $"Wrong catalogId of Market Board listings received for request: item#{catalogId}");
return;
}

if (listings.Count != request.AmountToArrive)
{
Log?.Invoke(this, $"Wrong number of Market Board listings received for request: {listings.Count} != {request.AmountToArrive} item#{catalogId}");
Expand Down