Skip to content

Commit

Permalink
feat(network): add WorldVisitQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyupe committed Jan 30, 2025
1 parent eee3cbb commit 904240a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Cafe.Matcha/Cafe.Matcha.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -109,22 +109,25 @@
<Compile Include="Constant\Secret.cs" />
<Compile Include="Constant\Secret.Local.cs" />
<Compile Include="Constant\TreasureShiftingWheelResultType.cs" />
<Compile Include="DTO\QueueDTO.cs" />
<Compile Include="DTO\FateWatchListChangedDTO.cs" />
<Compile Include="DTO\TreasureResultDTO.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Network\Handler\AbstractHandler.cs" />
<Compile Include="Network\Handler\QueueHandler.cs" />
<Compile Include="Network\Handler\MarketBoardHandler.cs" />
<Compile Include="Network\Packet.cs" />
<Compile Include="Network\Structures\WorldVisitQueue.cs" />
<Compile Include="Network\Structures\IMarketBoardCurrentOfferings.cs" />
<Compile Include="Network\Structures\IMarketBoardHistory.cs" />
<Compile Include="Network\Structures\IMarketBoardPurchase.cs" />
<Compile Include="Network\Structures\IMarketBoardPurchaseHandler.cs" />
<Compile Include="Network\Structures\IMarketTaxRates.cs" />
<Compile Include="Network\Structures\MarketBoardPurchase.cs" />
<Compile Include="Network\Structures\MarketBoardPurchaseHandler.cs" />
<Compile Include="Network\Structures\Examine.cs" />
<Compile Include="Network\Structures\Examine.cs" />
<Compile Include="Network\Structures\MarketTaxRates.cs" />
<Compile Include="Network\Structures\Materia.cs" />
<Compile Include="Network\Structures\Materia.cs" />
<Compile Include="Network\Universalis\Types\UniversalisItemListingDeleteRequest.cs" />
<Compile Include="Network\Universalis\Types\UniversalisItemUploadRequest.cs" />
<Compile Include="Network\Universalis\Types\UniversalisTaxData.cs" />
Expand Down
1 change: 1 addition & 0 deletions Cafe.Matcha/Constant/EventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public enum EventType

DynamicEvent,
FateWatchListChanged,
Queue,
}
}
31 changes: 31 additions & 0 deletions Cafe.Matcha/DTO/QueueDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) FFCafe. All rights reserved.
// Licensed under the AGPL-3.0 license. See LICENSE file in the project root for full license information.

namespace Cafe.Matcha.DTO
{
using Cafe.Matcha.Constant;
using Newtonsoft.Json;

internal class QueueDTO : BaseDTO
{
public override EventType EventType
{
get
{
return EventType.Queue;
}
}

[JsonProperty("type")]
public string Type;

[JsonProperty("stage")]
public string Stage;

[JsonProperty("order")]
public uint Order = 0;

[JsonProperty("time")]
public uint Time = 0;
}
}
36 changes: 36 additions & 0 deletions Cafe.Matcha/Network/Handler/QueueHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) FFCafe. All rights reserved.
// Licensed under the AGPL-3.0 license. See LICENSE file in the project root for full license information.

namespace Cafe.Matcha.Network.Handler
{
using System;
using Cafe.Matcha.Constant;
using Cafe.Matcha.DTO;
using Cafe.Matcha.Network.Structures;

internal class QueueHandler : AbstractHandler
{
public QueueHandler(Action<BaseDTO> fireEvent) : base(fireEvent)
{
}

public override bool Handle(Packet packet)
{
if (packet.MatchaOpcode == MatchaOpcode.WorldVisitQueue)
{
var data = WorldVisitQueue.Read(packet.GetRawData());
fireEvent(new QueueDTO()
{
Type = "world-visit",
Stage = data.Stage == 1 ? "waiting" : data.Stage == 2 ? "ready" : data.Stage == 3 ? "done" : "unknown",
Order = data.Order,
Time = data.Time,
});

return true;
}

return false;
}
}
}
1 change: 1 addition & 0 deletions Cafe.Matcha/Network/NetworkMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class NetworkMonitor : INetworkMonitor
public NetworkMonitor()
{
AddHandler<MarketBoardHandler>();
AddHandler<QueueHandler>();
}

public void HandleMessageReceived(string connection, long epoch, byte[] message)
Expand Down
34 changes: 34 additions & 0 deletions Cafe.Matcha/Network/Structures/WorldVisitQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) FFCafe. All rights reserved.
// Licensed under the AGPL-3.0 license. See LICENSE file in the project root for full license information.

namespace Cafe.Matcha.Network.Structures
{
using System.IO;

public class WorldVisitQueue
{
public uint Stage { get; internal set; }
public uint Order { get; internal set; }
public uint Time { get; internal set; }

/// <summary>
/// Read a <see cref="WorldVisitQueue"/> object from memory.
/// </summary>
/// <param name="data">Data to read.</param>
/// <returns>A new <see cref="WorldVisitQueue"/> object.</returns>
public static WorldVisitQueue Read(byte[] data)
{
using (var stream = new MemoryStream(data))
{
using (var reader = new BinaryReader(stream))
{
var output = new WorldVisitQueue();
output.Stage = reader.ReadUInt32();
output.Order = reader.ReadUInt32();
output.Time = reader.ReadUInt32();
return output;
}
}
}
}
}

0 comments on commit 904240a

Please sign in to comment.