fix: add plots

This commit is contained in:
Anna 2023-02-19 21:55:17 -05:00
parent 3e5b08e264
commit 544ef9a65b
10 changed files with 37 additions and 10 deletions

View File

@ -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; }

View File

@ -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(

View File

@ -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,

View File

@ -0,0 +1,3 @@
alter table messages
add column plot int;
create index messages_plot_idx on messages (plot);

View File

@ -25,6 +25,8 @@ pub struct Message {
#[serde(default)]
pub ward: Option<u16>,
#[serde(default)]
pub plot: Option<u16>,
}
fn glyph_default() -> i8 {
@ -56,6 +58,7 @@ pub struct RetrievedMessageTerritory {
pub id: String,
pub territory: i64,
pub ward: Option<i64>,
pub plot: Option<i64>,
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<i64>,
pub plot: Option<i64>,
pub x: f64,
pub y: f64,
pub z: f64,

View File

@ -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<impl Reply, Infallible> {
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())

View File

@ -28,6 +28,8 @@ pub fn get_location(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
pub struct GetLocationQuery {
#[serde(default)]
ward: Option<u32>,
#[serde(default)]
plot: Option<u32>,
}
async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuery) -> Result<impl Reply, Rejection> {
@ -36,8 +38,8 @@ async fn logic(state: Arc<State>, 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<State>, 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

View File

@ -28,6 +28,7 @@ async fn logic(state: Arc<State>, id: i64, message_id: Uuid) -> Result<impl Repl
select m.id,
m.territory,
m.ward,
m.plot,
m.x,
m.y,
m.z,

View File

@ -32,6 +32,7 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
select m.id,
m.territory,
m.ward,
m.plot,
m.x,
m.y,
m.z,

View File

@ -27,8 +27,8 @@ async fn logic(state: Arc<State>, 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 = {