feat(server): only show players and parties when supposed to
This commit is contained in:
parent
8eca9edae6
commit
c39cf3779f
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
||||||
|
pub mod game_info;
|
|
@ -30,8 +30,10 @@ use tower_http::cors::CorsLayer;
|
||||||
use tower_http::decompression::RequestDecompressionLayer;
|
use tower_http::decompression::RequestDecompressionLayer;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
use crate::generated::game_info::{TERRITORY_INFO, TerritoryInfo};
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod generated;
|
||||||
|
|
||||||
static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!();
|
static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!();
|
||||||
|
|
||||||
|
@ -191,6 +193,25 @@ async fn territory(
|
||||||
Query(query): Query<TerritoryQuery>,
|
Query(query): Query<TerritoryQuery>,
|
||||||
) -> Result<MsgPack<QueryResponse<Vec<AnonymousPlayerInfo>>>, AppError>
|
) -> Result<MsgPack<QueryResponse<Vec<AnonymousPlayerInfo>>>, AppError>
|
||||||
{
|
{
|
||||||
|
let territory_info = match TERRITORY_INFO.get(territory as usize) {
|
||||||
|
Some(info) => *info,
|
||||||
|
None => {
|
||||||
|
eprintln!("warn: missing territory info for territory {territory}");
|
||||||
|
TerritoryInfo {
|
||||||
|
parties_visible: false,
|
||||||
|
map_visible: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if !territory_info.map_visible {
|
||||||
|
return Ok(MsgPack(QueryResponse {
|
||||||
|
populations: state.populations.read().await.clone(),
|
||||||
|
parties: Default::default(),
|
||||||
|
data: Default::default(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
let info = sqlx::query_as!(
|
let info = sqlx::query_as!(
|
||||||
AnonymousPlayerInfoInternal,
|
AnonymousPlayerInfoInternal,
|
||||||
// language=postgresql
|
// language=postgresql
|
||||||
|
@ -220,10 +241,17 @@ async fn territory(
|
||||||
.fetch_all(&*state.pool)
|
.fetch_all(&*state.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let parties = get_parties(&state, territory, &info);
|
let parties = if territory_info.parties_visible {
|
||||||
|
get_parties(&state, territory, &info)
|
||||||
|
} else {
|
||||||
|
Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
let mut info: Vec<_> = info.into_iter()
|
let mut info: Vec<_> = info.into_iter()
|
||||||
.filter(|player| match query.party {
|
.filter(|player| match query.party {
|
||||||
None => true,
|
None => true,
|
||||||
|
// don't allow filtering on party-hidden maps
|
||||||
|
_ if !territory_info.parties_visible => true,
|
||||||
x => player.party_hash(&state.hasher, &state.salt, territory) == x,
|
x => player.party_hash(&state.hasher, &state.salt, territory) == x,
|
||||||
})
|
})
|
||||||
.map(|player| AnonymousPlayerInfo::new_from(player, &state.hasher, &state.salt, territory))
|
.map(|player| AnonymousPlayerInfo::new_from(player, &state.hasher, &state.salt, territory))
|
||||||
|
|
Loading…
Reference in New Issue