use crate::errors::Result;
use tonic::transport::Channel;
mod api {
tonic::include_proto!("agones.dev.sdk.alpha");
}
use api::sdk_client::SdkClient;
#[derive(Clone)]
pub struct Alpha {
client: SdkClient<Channel>,
}
impl Alpha {
pub(crate) fn new(ch: Channel) -> Self {
Self {
client: SdkClient::new(ch),
}
}
#[inline]
pub async fn get_player_capacity(&mut self) -> Result<i64> {
Ok(self
.client
.get_player_capacity(api::Empty {})
.await
.map(|c| c.into_inner().count)?)
}
#[inline]
pub async fn set_player_capacity(&mut self, count: i64) -> Result<()> {
Ok(self
.client
.set_player_capacity(api::Count { count })
.await
.map(|_| ())?)
}
#[inline]
pub async fn player_connect(&mut self, id: impl Into<String>) -> Result<bool> {
Ok(self
.client
.player_connect(api::PlayerId {
player_id: id.into(),
})
.await
.map(|b| b.into_inner().bool)?)
}
#[inline]
pub async fn player_disconnect(&mut self, id: impl Into<String>) -> Result<bool> {
Ok(self
.client
.player_disconnect(api::PlayerId {
player_id: id.into(),
})
.await
.map(|b| b.into_inner().bool)?)
}
#[inline]
pub async fn get_player_count(&mut self) -> Result<i64> {
Ok(self
.client
.get_player_count(api::Empty {})
.await
.map(|c| c.into_inner().count)?)
}
#[inline]
pub async fn is_player_connected(&mut self, id: impl Into<String>) -> Result<bool> {
Ok(self
.client
.is_player_connected(api::PlayerId {
player_id: id.into(),
})
.await
.map(|b| b.into_inner().bool)?)
}
#[inline]
pub async fn get_connected_players(&mut self) -> Result<Vec<String>> {
Ok(self
.client
.get_connected_players(api::Empty {})
.await
.map(|pl| pl.into_inner().list)?)
}
}