diff --git a/client/MessageRequest.cs b/client/MessageRequest.cs index 089e00f..c524490 100644 --- a/client/MessageRequest.cs +++ b/client/MessageRequest.cs @@ -8,6 +8,7 @@ namespace OrangeGuidanceTomestone; public class MessageRequest { public uint Territory { get; set; } public uint? Ward { get; set; } + public uint? Plot { get; set; } public float X { get; set; } public float Y { get; set; } public float Z { get; set; } diff --git a/client/Messages.cs b/client/Messages.cs index a0aa248..b5cdab0 100644 --- a/client/Messages.cs +++ b/client/Messages.cs @@ -153,7 +153,16 @@ internal class Messages : IDisposable { return; } - var ward = this.Plugin.Common.Functions.Housing.Location?.Ward; + var housing = this.Plugin.Common.Functions.Housing.Location; + var ward = housing?.Ward; + ushort? plot = null; + if (housing is { Apartment: { } apt, ApartmentWing: { } wing }) { + plot = (ushort) (10_000 + + (wing - 1) * 5_000 + + apt); + } else if (housing?.Plot is { } plotNum) { + plot = plotNum; + } if (this.Plugin.Config.DisableTrials && this.Trials.Contains(territory)) { return; @@ -175,17 +184,21 @@ internal class Messages : IDisposable { Task.Run(async () => { try { - await this.DownloadMessages(territory, ward); + await this.DownloadMessages(territory, ward, plot); } catch (Exception ex) { PluginLog.LogError(ex, $"Failed to get messages for territory {territory}"); } }); } - private async Task DownloadMessages(ushort territory, ushort? ward) { + private async Task DownloadMessages(ushort territory, ushort? ward, ushort? plot) { var route = $"/messages/{territory}"; if (ward != null) { route += $"?ward={ward}"; + + if (plot != null) { + route += $"&plot={plot}"; + } } var resp = await ServerHelper.SendRequest( diff --git a/client/Ui/MainWindowTabs/Write.cs b/client/Ui/MainWindowTabs/Write.cs index ed3a1c4..0bab9e9 100644 --- a/client/Ui/MainWindowTabs/Write.cs +++ b/client/Ui/MainWindowTabs/Write.cs @@ -232,6 +232,7 @@ internal class Write : ITab { var req = new MessageRequest { Territory = this.Plugin.ClientState.TerritoryType, Ward = this.Plugin.Common.Functions.Housing.Location?.Ward, + Plot = this.Plugin.Common.Functions.Housing.Location?.Plot, X = player.Position.X, Y = player.Position.Y, Z = player.Position.Z, diff --git a/server/migrations/11_more_housing_changes.sql b/server/migrations/11_more_housing_changes.sql new file mode 100644 index 0000000..37e9517 --- /dev/null +++ b/server/migrations/11_more_housing_changes.sql @@ -0,0 +1,3 @@ +alter table messages + add column plot int; +create index messages_plot_idx on messages (plot); diff --git a/server/src/message.rs b/server/src/message.rs index 2f49bad..d73e9a0 100644 --- a/server/src/message.rs +++ b/server/src/message.rs @@ -25,6 +25,8 @@ pub struct Message { #[serde(default)] pub ward: Option, + #[serde(default)] + pub plot: Option, } fn glyph_default() -> i8 { @@ -56,6 +58,7 @@ pub struct RetrievedMessageTerritory { pub id: String, pub territory: i64, pub ward: Option, + pub plot: Option, pub x: f64, pub y: f64, pub z: f64, @@ -74,6 +77,7 @@ pub struct OwnMessage { pub id: String, pub territory: i64, pub ward: Option, + pub plot: Option, pub x: f64, pub y: f64, pub z: f64, diff --git a/server/src/web.rs b/server/src/web.rs index 9e23e4c..c300ea8 100644 --- a/server/src/web.rs +++ b/server/src/web.rs @@ -74,7 +74,7 @@ pub enum WebError { NoSuchMessage, InvalidExtraCode, MissingWard, - UnnecessaryWard, + UnnecessaryHousingInfo, } impl Reject for WebError {} @@ -95,7 +95,7 @@ async fn handle_rejection(err: Rejection) -> Result { WebError::NoSuchMessage => (StatusCode::NOT_FOUND, "no_such_message", "no message with that id was found".into()), WebError::InvalidExtraCode => (StatusCode::BAD_REQUEST, "invalid_extra_code", "that extra code was not found".into()), WebError::MissingWard => (StatusCode::BAD_REQUEST, "missing_ward", "a ward was not provided - try updating the plugin".into()), - WebError::UnnecessaryWard => (StatusCode::BAD_REQUEST, "unnecessary_ward", "a ward was provided but not necessary - try updating the plugin".into()), + WebError::UnnecessaryHousingInfo => (StatusCode::BAD_REQUEST, "unnecessary_housing_info", "a ward/plot was provided but not necessary - try updating the plugin".into()), } } else if err.is_not_found() { (StatusCode::NOT_FOUND, "not_found", "route was unknown to the server".into()) diff --git a/server/src/web/get_location.rs b/server/src/web/get_location.rs index 6528b64..b0611db 100644 --- a/server/src/web/get_location.rs +++ b/server/src/web/get_location.rs @@ -28,6 +28,8 @@ pub fn get_location(state: Arc) -> BoxedFilter<(impl Reply, )> { pub struct GetLocationQuery { #[serde(default)] ward: Option, + #[serde(default)] + plot: Option, } async fn logic(state: Arc, id: i64, location: u32, query: GetLocationQuery) -> Result { @@ -36,8 +38,8 @@ async fn logic(state: Arc, id: i64, location: u32, query: GetLocationQuer return Err(warp::reject::custom(WebError::MissingWard)); } - if !housing && query.ward.is_some() { - return Err(warp::reject::custom(WebError::UnnecessaryWard)); + if !housing && (query.ward.is_some() || query.plot.is_some()) { + return Err(warp::reject::custom(WebError::UnnecessaryHousingInfo)); } let location = location as i64; @@ -62,11 +64,12 @@ async fn logic(state: Arc, id: i64, location: u32, query: GetLocationQuer left join votes v on m.id = v.message left join votes v2 on m.id = v2.message and v2.user = ? inner join users u on m.user = u.id - where m.territory = ? and m.ward is ? + where m.territory = ? and m.ward is ? and m.plot is ? group by m.id"#, id, location, query.ward, + query.plot, ) .fetch_all(&state.db) .await diff --git a/server/src/web/get_message.rs b/server/src/web/get_message.rs index 877e0da..b934a64 100644 --- a/server/src/web/get_message.rs +++ b/server/src/web/get_message.rs @@ -28,6 +28,7 @@ async fn logic(state: Arc, id: i64, message_id: Uuid) -> Result, id: i64, extra: i64, mut query: HashMap, id: i64, extra: i64, message: Message) -> Resu return Err(warp::reject::custom(WebError::MissingWard)); } - if !housing && message.ward.is_some() { - return Err(warp::reject::custom(WebError::UnnecessaryWard)); + if !housing && (message.ward.is_some() || message.plot.is_some()) { + return Err(warp::reject::custom(WebError::UnnecessaryHousingInfo)); } let text = {