This commit is contained in:
Anna 2022-09-03 09:55:36 -04:00
parent cef98173e3
commit be92a100b6
7 changed files with 95 additions and 15 deletions

10
client/Configuration.cs Normal file
View File

@ -0,0 +1,10 @@
using Dalamud.Configuration;
namespace OrangeGuidanceTomestone;
[Serializable]
public class Configuration : IPluginConfiguration {
public int Version { get; set; } = 1;
public string ApiKey { get; set; } = string.Empty;
}

21
client/MessageRequest.cs Normal file
View File

@ -0,0 +1,21 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace OrangeGuidanceTomestone;
[Serializable]
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class MessageRequest {
public uint Territory { get; set; }
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public Guid PackId { get; set; }
public int Template1 { get; set; }
public int? Word1List { get; set; }
public int? Word1Word { get; set; }
public int? Conjunction { get; set; }
public int? Template2 { get; set; }
public int? Word2List { get; set; }
public int? Word2Word { get; set; }
}

View File

@ -51,20 +51,21 @@
<HintPath>$(Dalamud)\Lumina.Excel.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(Dalamud)\Newtonsoft.Json.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.8"/>
<PackageReference Include="Fody" Version="6.6.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Resourcer.Fody" Version="1.8.0"/>
<PackageReference Include="YamlDotNet" Version="12.0.0"/>
<PackageReference Include="DalamudPackager" Version="2.1.8" />
<PackageReference Include="Fody" Version="6.6.3" PrivateAssets="all" />
<PackageReference Include="Resourcer.Fody" Version="1.8.0" />
<PackageReference Include="YamlDotNet" Version="12.0.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="../server/packs/*.yaml" LinkBase="packs"/>
<EmbeddedResource Include="../server/packs/*.yaml" LinkBase="packs" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,5 @@
using Dalamud.IoC;
using Dalamud.Game.ClientState;
using Dalamud.IoC;
using Dalamud.Plugin;
namespace OrangeGuidanceTomestone;
@ -8,15 +9,32 @@ public class Plugin : IDalamudPlugin {
[PluginService]
internal DalamudPluginInterface Interface { get; init; }
[PluginService]
internal ClientState ClientState { get; init; }
internal Configuration Config { get; }
internal PluginUi Ui { get; }
public Plugin() {
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
if (this.Config.ApiKey == string.Empty) {
Task.Run(async () => {
var resp = await new HttpClient().PostAsync("https://tryfingerbuthole.anna.lgbt/account", null);
var key = await resp.Content.ReadAsStringAsync();
this.Config.ApiKey = key;
this.SaveConfig();
});
}
this.Ui = new PluginUi(this);
}
public void Dispose() {
this.Ui.Dispose();
}
internal void SaveConfig() {
this.Interface.SavePluginConfig(this.Config);
}
}

View File

@ -1,5 +1,7 @@
using System.Net.Http.Headers;
using System.Text;
using ImGuiNET;
using Newtonsoft.Json;
namespace OrangeGuidanceTomestone;
@ -151,7 +153,34 @@ public class PluginUi : IDisposable {
ImGui.BeginDisabled();
}
if (ImGui.Button("Write") && valid) {
if (ImGui.Button("Write") && valid && this.Plugin.ClientState.LocalPlayer is { } player) {
var req = new MessageRequest {
Territory = this.Plugin.ClientState.TerritoryType,
X = player.Position.X,
Y = player.Position.Y,
Z = player.Position.Z,
PackId = pack.Id,
Template1 = this._part1,
Word1List = this._word1.Item1 == -1 ? null : this._word1.Item1,
Word1Word = this._word1.Item2 == -1 ? null : this._word1.Item2,
Conjunction = this._conj == -1 ? null : this._conj,
Template2 = this._part2,
Word2List = this._word2.Item1 == -1 ? null : this._word2.Item1,
Word2Word = this._word2.Item2 == -1 ? null : this._word2.Item2,
};
var json = JsonConvert.SerializeObject(req);
Task.Run(async () => {
var content = new StringContent(json) {
Headers = {
ContentType = new MediaTypeHeaderValue("application/json"),
},
};
content.Headers.Add("X-Api-Key", this.Plugin.Config.ApiKey);
await new HttpClient().PostAsync("https://tryfingerbuthole.anna.lgbt/messages", content);
});
}
if (valid) {

View File

@ -89,7 +89,6 @@ async fn main() -> Result<()> {
).await?;
Ok(())
}))
// .connect_with(options.filename(&config.database.path))
.connect_with(options.filename(&config.database))
.await
.context("could not connect to database")?;
@ -103,9 +102,11 @@ async fn main() -> Result<()> {
packs: Default::default(),
});
println!("adding packs");
state.update_packs().await?;
let address = state.config.address.clone();
println!("listening at {}", address);
warp::serve(web::routes(state)).run(address).await;
Ok(())
}

View File

@ -12,7 +12,7 @@ pub struct Message {
pub template_1: usize,
pub word_1_list: Option<usize>,
pub word_1_word: Option<usize>,
pub conjugation: Option<usize>,
pub conjunction: Option<usize>,
pub template_2: Option<usize>,
pub word_2_list: Option<usize>,
pub word_2_word: Option<usize>,