fix: add plots
This commit is contained in:
parent
3e5b08e264
commit
544ef9a65b
|
@ -8,6 +8,7 @@ namespace OrangeGuidanceTomestone;
|
||||||
public class MessageRequest {
|
public class MessageRequest {
|
||||||
public uint Territory { get; set; }
|
public uint Territory { get; set; }
|
||||||
public uint? Ward { get; set; }
|
public uint? Ward { get; set; }
|
||||||
|
public uint? Plot { get; set; }
|
||||||
public float X { get; set; }
|
public float X { get; set; }
|
||||||
public float Y { get; set; }
|
public float Y { get; set; }
|
||||||
public float Z { get; set; }
|
public float Z { get; set; }
|
||||||
|
|
|
@ -153,7 +153,16 @@ internal class Messages : IDisposable {
|
||||||
return;
|
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)) {
|
if (this.Plugin.Config.DisableTrials && this.Trials.Contains(territory)) {
|
||||||
return;
|
return;
|
||||||
|
@ -175,17 +184,21 @@ internal class Messages : IDisposable {
|
||||||
|
|
||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
try {
|
try {
|
||||||
await this.DownloadMessages(territory, ward);
|
await this.DownloadMessages(territory, ward, plot);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
PluginLog.LogError(ex, $"Failed to get messages for territory {territory}");
|
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}";
|
var route = $"/messages/{territory}";
|
||||||
if (ward != null) {
|
if (ward != null) {
|
||||||
route += $"?ward={ward}";
|
route += $"?ward={ward}";
|
||||||
|
|
||||||
|
if (plot != null) {
|
||||||
|
route += $"&plot={plot}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp = await ServerHelper.SendRequest(
|
var resp = await ServerHelper.SendRequest(
|
||||||
|
|
|
@ -232,6 +232,7 @@ internal class Write : ITab {
|
||||||
var req = new MessageRequest {
|
var req = new MessageRequest {
|
||||||
Territory = this.Plugin.ClientState.TerritoryType,
|
Territory = this.Plugin.ClientState.TerritoryType,
|
||||||
Ward = this.Plugin.Common.Functions.Housing.Location?.Ward,
|
Ward = this.Plugin.Common.Functions.Housing.Location?.Ward,
|
||||||
|
Plot = this.Plugin.Common.Functions.Housing.Location?.Plot,
|
||||||
X = player.Position.X,
|
X = player.Position.X,
|
||||||
Y = player.Position.Y,
|
Y = player.Position.Y,
|
||||||
Z = player.Position.Z,
|
Z = player.Position.Z,
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
alter table messages
|
||||||
|
add column plot int;
|
||||||
|
create index messages_plot_idx on messages (plot);
|
|
@ -25,6 +25,8 @@ pub struct Message {
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub ward: Option<u16>,
|
pub ward: Option<u16>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub plot: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_default() -> i8 {
|
fn glyph_default() -> i8 {
|
||||||
|
@ -56,6 +58,7 @@ pub struct RetrievedMessageTerritory {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub territory: i64,
|
pub territory: i64,
|
||||||
pub ward: Option<i64>,
|
pub ward: Option<i64>,
|
||||||
|
pub plot: Option<i64>,
|
||||||
pub x: f64,
|
pub x: f64,
|
||||||
pub y: f64,
|
pub y: f64,
|
||||||
pub z: f64,
|
pub z: f64,
|
||||||
|
@ -74,6 +77,7 @@ pub struct OwnMessage {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub territory: i64,
|
pub territory: i64,
|
||||||
pub ward: Option<i64>,
|
pub ward: Option<i64>,
|
||||||
|
pub plot: Option<i64>,
|
||||||
pub x: f64,
|
pub x: f64,
|
||||||
pub y: f64,
|
pub y: f64,
|
||||||
pub z: f64,
|
pub z: f64,
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub enum WebError {
|
||||||
NoSuchMessage,
|
NoSuchMessage,
|
||||||
InvalidExtraCode,
|
InvalidExtraCode,
|
||||||
MissingWard,
|
MissingWard,
|
||||||
UnnecessaryWard,
|
UnnecessaryHousingInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reject for WebError {}
|
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::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::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::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() {
|
} else if err.is_not_found() {
|
||||||
(StatusCode::NOT_FOUND, "not_found", "route was unknown to the server".into())
|
(StatusCode::NOT_FOUND, "not_found", "route was unknown to the server".into())
|
||||||
|
|
|
@ -28,6 +28,8 @@ pub fn get_location(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
|
||||||
pub struct GetLocationQuery {
|
pub struct GetLocationQuery {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
ward: Option<u32>,
|
ward: Option<u32>,
|
||||||
|
#[serde(default)]
|
||||||
|
plot: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuery) -> Result<impl Reply, Rejection> {
|
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));
|
return Err(warp::reject::custom(WebError::MissingWard));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !housing && query.ward.is_some() {
|
if !housing && (query.ward.is_some() || query.plot.is_some()) {
|
||||||
return Err(warp::reject::custom(WebError::UnnecessaryWard));
|
return Err(warp::reject::custom(WebError::UnnecessaryHousingInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
let location = location as i64;
|
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 v on m.id = v.message
|
||||||
left join votes v2 on m.id = v2.message and v2.user = ?
|
left join votes v2 on m.id = v2.message and v2.user = ?
|
||||||
inner join users u on m.user = u.id
|
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"#,
|
group by m.id"#,
|
||||||
id,
|
id,
|
||||||
location,
|
location,
|
||||||
query.ward,
|
query.ward,
|
||||||
|
query.plot,
|
||||||
)
|
)
|
||||||
.fetch_all(&state.db)
|
.fetch_all(&state.db)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -28,6 +28,7 @@ async fn logic(state: Arc<State>, id: i64, message_id: Uuid) -> Result<impl Repl
|
||||||
select m.id,
|
select m.id,
|
||||||
m.territory,
|
m.territory,
|
||||||
m.ward,
|
m.ward,
|
||||||
|
m.plot,
|
||||||
m.x,
|
m.x,
|
||||||
m.y,
|
m.y,
|
||||||
m.z,
|
m.z,
|
||||||
|
|
|
@ -32,6 +32,7 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
|
||||||
select m.id,
|
select m.id,
|
||||||
m.territory,
|
m.territory,
|
||||||
m.ward,
|
m.ward,
|
||||||
|
m.plot,
|
||||||
m.x,
|
m.x,
|
||||||
m.y,
|
m.y,
|
||||||
m.z,
|
m.z,
|
||||||
|
|
|
@ -27,8 +27,8 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, message: Message) -> Resu
|
||||||
return Err(warp::reject::custom(WebError::MissingWard));
|
return Err(warp::reject::custom(WebError::MissingWard));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !housing && message.ward.is_some() {
|
if !housing && (message.ward.is_some() || message.plot.is_some()) {
|
||||||
return Err(warp::reject::custom(WebError::UnnecessaryWard));
|
return Err(warp::reject::custom(WebError::UnnecessaryHousingInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = {
|
let text = {
|
||||||
|
|
Loading…
Reference in New Issue