diff --git a/client/Configuration.cs b/client/Configuration.cs new file mode 100644 index 0000000..eead563 --- /dev/null +++ b/client/Configuration.cs @@ -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; +} diff --git a/client/MessageRequest.cs b/client/MessageRequest.cs new file mode 100644 index 0000000..07d39ae --- /dev/null +++ b/client/MessageRequest.cs @@ -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; } +} diff --git a/client/OrangeGuidanceTomestone.csproj b/client/OrangeGuidanceTomestone.csproj index b345367..e87b58f 100755 --- a/client/OrangeGuidanceTomestone.csproj +++ b/client/OrangeGuidanceTomestone.csproj @@ -51,20 +51,21 @@ $(Dalamud)\Lumina.Excel.dll false + + $(Dalamud)\Newtonsoft.Json.dll + false + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + - + diff --git a/client/Plugin.cs b/client/Plugin.cs index 8d02ff9..7c55577 100644 --- a/client/Plugin.cs +++ b/client/Plugin.cs @@ -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); + } } diff --git a/client/PluginUi.cs b/client/PluginUi.cs index 7899aea..afc5bb5 100644 --- a/client/PluginUi.cs +++ b/client/PluginUi.cs @@ -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) { diff --git a/server/src/main.rs b/server/src/main.rs index cff3af1..22ce152 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -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(()) } diff --git a/server/src/message.rs b/server/src/message.rs index dff2c3f..15f5ac1 100644 --- a/server/src/message.rs +++ b/server/src/message.rs @@ -12,7 +12,7 @@ pub struct Message { pub template_1: usize, pub word_1_list: Option, pub word_1_word: Option, - pub conjugation: Option, + pub conjunction: Option, pub template_2: Option, pub word_2_list: Option, pub word_2_word: Option,