Compare commits

...

2 Commits

Author SHA1 Message Date
Anna 728c60b47b
fix: account for world 2023-02-19 23:52:04 -05:00
Anna 22bfa6c8f7
fix(server): account for world 2023-02-19 23:50:25 -05:00
10 changed files with 51 additions and 11 deletions

View File

@ -32,6 +32,7 @@ internal class MessageWithTerritory {
public uint Territory { get; init; }
public uint? Ward { get; init; }
public uint? Plot { get; init; }
public uint? World { get; init; }
public float X { get; init; }
public float Y { get; init; }
public float Z { get; init; }

View File

@ -181,6 +181,11 @@ internal class Messages : IDisposable {
return;
}
var world = this.Plugin.ClientState.LocalPlayer?.CurrentWorld.Id ?? 0;
if (world == 0) {
return;
}
var housing = this.Plugin.Common.Functions.Housing.Location;
var ward = housing?.Ward;
var plot = housing?.CombinedPlot();
@ -205,14 +210,14 @@ internal class Messages : IDisposable {
Task.Run(async () => {
try {
await this.DownloadMessages(territory, ward, plot);
await this.DownloadMessages(world, territory, ward, plot);
} catch (Exception ex) {
PluginLog.LogError(ex, $"Failed to get messages for territory {territory}");
}
});
}
private async Task DownloadMessages(ushort territory, ushort? ward, ushort? plot) {
private async Task DownloadMessages(uint world, ushort territory, ushort? ward, ushort? plot) {
var route = $"/messages/{territory}";
if (ward != null) {
route += $"?ward={ward}";
@ -220,6 +225,8 @@ internal class Messages : IDisposable {
if (plot != null) {
route += $"&plot={plot}";
}
route += $"&world={world}";
}
var resp = await ServerHelper.SendRequest(

View File

@ -76,7 +76,20 @@ internal class MessageList : ITab {
var loc = $"Location: {territoryName}";
if (message.Ward != null) {
loc += $" (Ward {message.Ward.Value}";
loc += " (";
if (message.World != null) {
var world = this.Plugin.DataManager.GetExcelSheet<World>()?.GetRow((ushort) message.World);
if (world != null) {
loc += world.Name.ToDalamudString().TextValue;
}
}
if (loc != " (") {
loc += ", ";
}
loc += $"Ward {message.Ward.Value}";
if (message.Plot != null) {
if (message.Plot.Value >= HousingLocationExt.Apt) {

View File

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

View File

@ -23,6 +23,8 @@ pub struct Message {
#[serde(default = "glyph_default")]
pub glyph: i8,
#[serde(default)]
pub world: Option<u32>,
#[serde(default)]
pub ward: Option<u16>,
#[serde(default)]
@ -57,6 +59,7 @@ pub struct RetrievedMessage {
pub struct RetrievedMessageTerritory {
pub id: String,
pub territory: i64,
pub world: Option<i64>,
pub ward: Option<i64>,
pub plot: Option<i64>,
pub x: f64,
@ -76,6 +79,7 @@ pub struct RetrievedMessageTerritory {
pub struct OwnMessage {
pub id: String,
pub territory: i64,
pub world: Option<i64>,
pub ward: Option<i64>,
pub plot: Option<i64>,
pub x: f64,

View File

@ -73,7 +73,7 @@ pub enum WebError {
TooManyMessages,
NoSuchMessage,
InvalidExtraCode,
MissingWard,
MissingHousingInfo,
UnnecessaryHousingInfo,
}
@ -94,7 +94,7 @@ async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> {
WebError::TooManyMessages => (StatusCode::BAD_REQUEST, "too_many_messages", "you have run out of messages - delete one and try again".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::MissingWard => (StatusCode::BAD_REQUEST, "missing_ward", "a ward was not provided - try updating the plugin".into()),
WebError::MissingHousingInfo => (StatusCode::BAD_REQUEST, "missing_housing_info", "housing info was not provided - 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() {

View File

@ -26,6 +26,8 @@ pub fn get_location(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
#[derive(Deserialize)]
pub struct GetLocationQuery {
#[serde(default)]
world: Option<u32>,
#[serde(default)]
ward: Option<u32>,
#[serde(default)]
@ -34,14 +36,20 @@ pub struct GetLocationQuery {
async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuery) -> Result<impl Reply, Rejection> {
let housing = HOUSING_ZONES.contains(&location);
if housing && query.ward.is_none() {
return Err(warp::reject::custom(WebError::MissingWard));
if housing && (query.world.is_none() || query.ward.is_none()) {
return Err(warp::reject::custom(WebError::MissingHousingInfo));
}
if !housing && (query.ward.is_some() || query.plot.is_some()) {
return Err(warp::reject::custom(WebError::UnnecessaryHousingInfo));
}
let world = if housing {
query.world
} else {
None
};
let location = location as i64;
let mut messages = sqlx::query_as!(
RetrievedMessage,
@ -64,10 +72,11 @@ 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 ? and m.plot is ?
where m.territory = ? and m.world is ? and m.ward is ? and m.plot is ?
group by m.id"#,
id,
location,
world,
query.ward,
query.plot,
)

View File

@ -27,6 +27,7 @@ async fn logic(state: Arc<State>, id: i64, message_id: Uuid) -> Result<impl Repl
r#"
select m.id,
m.territory,
m.world,
m.ward,
m.plot,
m.x,

View File

@ -31,6 +31,7 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
r#"
select m.id,
m.territory,
m.world,
m.ward,
m.plot,
m.x,

View File

@ -23,8 +23,8 @@ pub fn write(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
async fn logic(state: Arc<State>, id: i64, extra: i64, message: Message) -> Result<impl Reply, Rejection> {
let housing = HOUSING_ZONES.contains(&message.territory);
if housing && message.ward.is_none() {
return Err(warp::reject::custom(WebError::MissingWard));
if housing && (message.world.is_none() || message.ward.is_none()) {
return Err(warp::reject::custom(WebError::MissingHousingInfo));
}
if !housing && (message.ward.is_some() || message.plot.is_some()) {
@ -67,10 +67,11 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, message: Message) -> Resu
sqlx::query!(
// language=sqlite
"insert into messages (id, user, territory, ward, plot, x, y, z, yaw, message, glyph) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
"insert into messages (id, user, territory, world, ward, plot, x, y, z, yaw, message, glyph) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
message_id,
id,
territory,
message.world,
message.ward,
message.plot,
message.x,