feat(plugin): use messagepack
This commit is contained in:
parent
71ecba455f
commit
75a4ec5ca8
|
@ -55,6 +55,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
|
||||
<PackageReference Include="MessagePack" Version="2.5.129" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Dalamud.Game.ClientState.Objects.Enums;
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using MessagePack;
|
||||
|
||||
namespace PlayerMap;
|
||||
|
||||
|
@ -78,22 +76,18 @@ public class Plugin : IDalamudPlugin {
|
|||
players.Shuffle();
|
||||
|
||||
var update = new Update(territory, player.CurrentWorld.Id, players);
|
||||
var json = JsonConvert.SerializeObject(update, new JsonSerializerSettings {
|
||||
ContractResolver = new DefaultContractResolver {
|
||||
NamingStrategy = new SnakeCaseNamingStrategy(),
|
||||
},
|
||||
});
|
||||
var msgpack = MessagePackSerializer.Serialize(update, MessagePackSerializerOptions.Standard);
|
||||
|
||||
using var mem = new MemoryStream();
|
||||
await using (var gz = new GZipStream(mem, CompressionLevel.Optimal)) {
|
||||
await gz.WriteAsync(Encoding.UTF8.GetBytes(json));
|
||||
await gz.WriteAsync(msgpack);
|
||||
await gz.FlushAsync();
|
||||
}
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Post, "https://map.anna.lgbt/api/upload") {
|
||||
Content = new ByteArrayContent(mem.ToArray()) {
|
||||
Headers = {
|
||||
ContentType = new MediaTypeHeaderValue("application/json"),
|
||||
ContentType = new MediaTypeHeaderValue("application/msgpack"),
|
||||
ContentEncoding = { "gzip" },
|
||||
},
|
||||
},
|
||||
|
@ -115,13 +109,20 @@ public class Plugin : IDalamudPlugin {
|
|||
}
|
||||
|
||||
[Serializable]
|
||||
[MessagePackObject]
|
||||
internal struct Update(uint territory, uint world, List<PlayerInfo> players) {
|
||||
[Key(0)]
|
||||
public readonly uint Territory = territory;
|
||||
|
||||
[Key(1)]
|
||||
public readonly uint World = world;
|
||||
|
||||
[Key(2)]
|
||||
public readonly List<PlayerInfo> Players = players;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[MessagePackObject]
|
||||
internal struct PlayerInfo(
|
||||
string name,
|
||||
uint world,
|
||||
|
@ -136,16 +137,39 @@ internal struct PlayerInfo(
|
|||
uint currentHp,
|
||||
uint maxHp
|
||||
) {
|
||||
[Key(0)]
|
||||
public readonly string Name = name;
|
||||
|
||||
[Key(1)]
|
||||
public readonly uint World = world;
|
||||
|
||||
[Key(2)]
|
||||
public readonly float X = x;
|
||||
|
||||
[Key(3)]
|
||||
public readonly float Y = y;
|
||||
|
||||
[Key(4)]
|
||||
public readonly float Z = z;
|
||||
|
||||
[Key(5)]
|
||||
public readonly float W = w;
|
||||
|
||||
[Key(6)]
|
||||
public readonly List<byte> Customize = customize;
|
||||
|
||||
[Key(7)]
|
||||
public readonly byte Level = level;
|
||||
|
||||
[Key(8)]
|
||||
public readonly uint Job = job;
|
||||
|
||||
[Key(9)]
|
||||
public readonly string FreeCompany = freeCompany;
|
||||
|
||||
[Key(10)]
|
||||
public readonly uint CurrentHp = currentHp;
|
||||
|
||||
[Key(11)]
|
||||
public readonly uint MaxHp = maxHp;
|
||||
};
|
||||
|
|
|
@ -7,6 +7,32 @@
|
|||
"requested": "[2.1.12, )",
|
||||
"resolved": "2.1.12",
|
||||
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
|
||||
},
|
||||
"MessagePack": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.5.129, )",
|
||||
"resolved": "2.5.129",
|
||||
"contentHash": "1jBW0Q3qvv+PJBwer8lQ2l26/fKptJIqFgVdyKfn4zW+LSYE8xEcvd4svfh0erI5f4d+rQRIAN229I2ARI/A5w==",
|
||||
"dependencies": {
|
||||
"MessagePack.Annotations": "2.5.129",
|
||||
"Microsoft.NET.StringTools": "17.6.3",
|
||||
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
|
||||
}
|
||||
},
|
||||
"MessagePack.Annotations": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.5.129",
|
||||
"contentHash": "wNJB3EaJKjq+5pti+0T8b444fEb2PRw3hFefp9+of/BvDdTWO0iIUWfYNZbKx5aAIrpFzhLEfMAEJnGWWq3OFQ=="
|
||||
},
|
||||
"Microsoft.NET.StringTools": {
|
||||
"type": "Transitive",
|
||||
"resolved": "17.6.3",
|
||||
"contentHash": "N0ZIanl1QCgvUumEL1laasU0a7sOE5ZwLZVTn0pAePnfhq8P7SvTjF8Axq+CnavuQkmdQpGNXQ1efZtu5kDFbA=="
|
||||
},
|
||||
"System.Runtime.CompilerServices.Unsafe": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.0.0",
|
||||
"contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue