Allow corp leaders to authorise corp v corp warfare.
This commit is contained in:
parent
7d1d6675b7
commit
1cf13413e8
@ -767,6 +767,21 @@ impl DBTrans {
|
||||
Some(row) => Ok(Some(serde_json::from_value(row.get(0))?))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn find_corp_consent_by_user_parties_type(&self, usr_consenting: &str, usr_consented: &str,
|
||||
consent_type: &ConsentType) -> DResult<Option<Consent>> {
|
||||
match self.pg_trans()?.query_opt(
|
||||
"SELECT cc.details FROM corp_consent cc \
|
||||
JOIN corp_membership cm_consenting ON cc.consenting_corp = cm_consenting.corp_id \
|
||||
JOIN corp_membership cm_consented ON cc.consented_corp = cm_consented.corp_id \
|
||||
WHERE cm_consenting.member_username = $1 AND \
|
||||
cm_consented.member_username = $2 AND cc.consent_type = $3",
|
||||
&[&usr_consenting, &usr_consented, &ConsentType::to_str(consent_type)]
|
||||
).await? {
|
||||
None => Ok(None),
|
||||
Some(row) => Ok(Some(serde_json::from_value(row.get(0))?))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn revoke_until_death_consent(&self, party: &str) -> DResult<()> {
|
||||
self.pg_trans()?.execute(
|
||||
|
@ -21,6 +21,7 @@ use crate::{
|
||||
static_content::room::room_map_by_code,
|
||||
};
|
||||
use ansi::ansi;
|
||||
use itertools::Itertools;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ConsentTarget<'t> {
|
||||
@ -693,6 +694,22 @@ async fn handle_corp_consent(ctx: &mut VerbContext<'_>, source_player: &Item,
|
||||
user_error("You don't have permission to declare war on behalf of that corp.".to_owned())?;
|
||||
}
|
||||
|
||||
if is_allow {
|
||||
let mut not_allowing_users = vec!();
|
||||
for (name, mem) in ctx.trans.list_corp_members(&from_corp_id).await? {
|
||||
if name != source_player.item_code && !mem.allow_combat {
|
||||
not_allowing_users.push(name);
|
||||
}
|
||||
}
|
||||
if !not_allowing_users.is_empty() {
|
||||
user_error(format!(ansi!("War can only be declared when all corp mates allow combat for that corp. Ask them to run <bold>corp allow combat from {}<reset>, or have them fired! <bold>corp config {} allow combat required<reset> will stop anyone joining without it / turning it off. Corp mates with it off: {}"),
|
||||
&from_corp.name,
|
||||
&from_corp.name,
|
||||
¬_allowing_users.iter().join(", ")
|
||||
))?;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.trans.delete_expired_corp_consent().await?;
|
||||
|
||||
let current_consent = ctx.trans.find_corp_consent_by_parties_type(
|
||||
@ -711,7 +728,7 @@ async fn handle_corp_consent(ctx: &mut VerbContext<'_>, source_player: &Item,
|
||||
};
|
||||
|
||||
let update = compute_new_consent_state(
|
||||
&to_corp.name,
|
||||
&from_corp.name,
|
||||
"their",
|
||||
&to_corp.name,
|
||||
"their",
|
||||
|
@ -67,6 +67,14 @@ pub async fn check_consent(trans: &DBTrans, action: &str,
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
|
||||
trans.delete_expired_corp_consent().await?;
|
||||
if let Some(consent) = trans.find_corp_consent_by_user_parties_type(
|
||||
&target.item_code, &by.item_code, consent_type).await? {
|
||||
if check_one_consent(&consent, action, &target) {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user