1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Fix battle chats

This commit is contained in:
NG (Graham)
2025-08-13 23:36:34 -04:00
parent 624fee6d72
commit d38d4d4fdb
8 changed files with 257 additions and 78 deletions

View File

@@ -555,6 +555,54 @@ impl UserData {
}
Ok(players)
}
async fn get_players_in_current_game(&self) -> Result<Vec<(oj_rc_database::schema::multiplayer_game_player::Model, oj_rc_database::schema::user::Model)>, polariton_server::operations::SimpleOpError> {
let current_game = self.db.game_by_user_id_and_completion(self.account.id, false).await
.map_err(|e| {
log::error!("Failed to retrieve ongoing game for user {}: {}", self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16,
format!("Failed to retrieve ongoing game for user {}", self.account.id),
)
})?;
if let Some(current_game) = current_game {
let guid = current_game.guid;
self.db.players_by_game_guid_and_completion_heavy(current_game.guid, false).await
.map_err(|e| {
log::error!("Failed to retrieve players for game {} for user {}: {}", guid, self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16,
format!("Failed to retrieve ongoing game {} for user {}", guid, self.account.id),
)
})
} else {
Ok(Vec::default())
}
}
async fn get_teammates_in_current_game(&self) -> Result<Vec<(oj_rc_database::schema::multiplayer_game_player::Model, oj_rc_database::schema::user::Model)>, polariton_server::operations::SimpleOpError> {
let current_game_info = self.db.game_and_player_by_user_id_and_completion(self.account.id, false).await
.map_err(|e| {
log::error!("Failed to retrieve ongoing game for user {}: {}", self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16,
format!("Failed to retrieve ongoing game for user {}", self.account.id),
)
})?;
if let Some((current_game, current_player)) = current_game_info {
let guid = current_game.guid;
self.db.players_by_game_guid_and_completion_and_team_heavy(current_game.guid, current_player.team, false).await
.map_err(|e| {
log::error!("Failed to retrieve players for game {} for user {}: {}", guid, self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16,
format!("Failed to retrieve ongoing game {} for user {}", guid, self.account.id),
)
})
} else {
Ok(Vec::default())
}
}
}
const INVALID_ROBOT_ERR: i16 = crate::data::error_codes::WebServicesError::InvalidRobot as i16; // 140
@@ -1299,6 +1347,24 @@ impl super::ChatUser for UserData {
Err(crate::data::error_codes::ChatErrorCodes::DoesNotExist as i16)
}
}
async fn get_teammates(&self) -> Result<Vec<String>, polariton_server::operations::SimpleOpError> {
Ok(
self.get_teammates_in_current_game().await?
.into_iter()
.map(|player| player.1.public_id)
.collect()
)
}
async fn get_gamemates(&self) -> Result<Vec<String>, polariton_server::operations::SimpleOpError> {
Ok(
self.get_players_in_current_game().await?
.into_iter()
.map(|player| player.1.public_id)
.collect()
)
}
}
#[async_trait::async_trait]

View File

@@ -211,6 +211,9 @@ pub trait ChatUser {
//async fn has_pending_sanctions(&self) -> Result<bool, i16>;
async fn get_sanctions(&self, username: String) -> Result<polariton::operation::Typed<()>, i16>;
async fn set_sanction(&self, sanction: SetSanction) -> Result<(), i16>;
// multiplayer-related
async fn get_teammates(&self) -> Result<Vec<String>, polariton_server::operations::SimpleOpError>;
async fn get_gamemates(&self) -> Result<Vec<String>, polariton_server::operations::SimpleOpError>;
}
pub struct SetSanction {