aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-07-25 22:16:50 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-07-25 22:16:50 +0200
commit67276bd0bbac15fe087edafd59d164c686509b35 (patch)
treeb844126c3d0987c4beb12cb60a968a9f53fc6ce9 /planetwars-server/src
parent93c4306b1015594bb6d7e08d03138c12229ac598 (diff)
downloadplanetwars.dev-67276bd0bbac15fe087edafd59d164c686509b35.tar.xz
planetwars.dev-67276bd0bbac15fe087edafd59d164c686509b35.zip
rename bot_api to client_api
Diffstat (limited to 'planetwars-server/src')
-rw-r--r--planetwars-server/src/lib.rs4
-rw-r--r--planetwars-server/src/modules/client_api.rs (renamed from planetwars-server/src/modules/bot_api.rs)47
-rw-r--r--planetwars-server/src/modules/mod.rs2
3 files changed, 29 insertions, 24 deletions
diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs
index 3ad0c88..e16b232 100644
--- a/planetwars-server/src/lib.rs
+++ b/planetwars-server/src/lib.rs
@@ -17,7 +17,7 @@ use bb8::{Pool, PooledConnection};
use bb8_diesel::{self, DieselConnectionManager};
use config::ConfigError;
use diesel::{Connection, PgConnection};
-use modules::bot_api::run_bot_api;
+use modules::client_api::run_client_api;
use modules::ranking::run_ranker;
use modules::registry::registry_service;
use serde::{Deserialize, Serialize};
@@ -172,7 +172,7 @@ pub async fn run_app() {
tokio::spawn(run_ranker(global_config.clone(), db_pool.clone()));
}
tokio::spawn(run_registry(global_config.clone(), db_pool.clone()));
- tokio::spawn(run_bot_api(global_config.clone(), db_pool.clone()));
+ tokio::spawn(run_client_api(global_config.clone(), db_pool.clone()));
let api_service = Router::new()
.nest("/api", api())
diff --git a/planetwars-server/src/modules/bot_api.rs b/planetwars-server/src/modules/client_api.rs
index 3efb1c2..7026671 100644
--- a/planetwars-server/src/modules/bot_api.rs
+++ b/planetwars-server/src/modules/client_api.rs
@@ -1,5 +1,8 @@
pub mod pb {
- tonic::include_proto!("grpc.planetwars.bot_api");
+ tonic::include_proto!("grpc.planetwars.client_api");
+
+ pub use player_api_client_message::ClientMessage as PlayerApiClientMessageType;
+ pub use player_api_server_message::ServerMessage as PlayerApiServerMessageType;
}
use std::collections::HashMap;
@@ -24,7 +27,7 @@ use crate::GlobalConfig;
use super::matches::{MatchPlayer, RunMatch};
-pub struct BotApiServer {
+pub struct ClientApiServer {
conn_pool: ConnectionPool,
runner_config: Arc<GlobalConfig>,
router: PlayerRouter,
@@ -65,12 +68,12 @@ impl PlayerRouter {
}
#[tonic::async_trait]
-impl pb::bot_api_service_server::BotApiService for BotApiServer {
- type ConnectPlayerStream = UnboundedReceiverStream<Result<pb::ServerMessage, Status>>;
+impl pb::client_api_service_server::ClientApiService for ClientApiServer {
+ type ConnectPlayerStream = UnboundedReceiverStream<Result<pb::PlayerApiServerMessage, Status>>;
async fn connect_player(
&self,
- req: Request<Streaming<pb::ClientMessage>>,
+ req: Request<Streaming<pb::PlayerApiClientMessage>>,
) -> Result<Response<Self::ConnectPlayerStream>, Status> {
// TODO: clean up errors
let player_key = req
@@ -97,8 +100,8 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer {
async fn create_match(
&self,
- req: Request<pb::MatchRequest>,
- ) -> Result<Response<pb::CreatedMatch>, Status> {
+ req: Request<pb::CreateMatchRequest>,
+ ) -> Result<Response<pb::CreateMatchResponse>, Status> {
// TODO: unify with matchrunner module
let conn = self.conn_pool.get().await.unwrap();
@@ -131,7 +134,7 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer {
.await
.expect("failed to create match");
- Ok(Response::new(pb::CreatedMatch {
+ Ok(Response::new(pb::CreateMatchResponse {
match_id: created_match.base.id,
player_key,
// TODO: can we avoid hardcoding this?
@@ -145,8 +148,8 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer {
// TODO: please rename me
struct SyncThingData {
- tx: oneshot::Sender<Streaming<pb::ClientMessage>>,
- server_messages: mpsc::UnboundedReceiver<Result<pb::ServerMessage, Status>>,
+ tx: oneshot::Sender<Streaming<pb::PlayerApiClientMessage>>,
+ server_messages: mpsc::UnboundedReceiver<Result<pb::PlayerApiServerMessage, Status>>,
}
struct RemoteBotSpec {
@@ -203,13 +206,13 @@ impl runner::BotSpec for RemoteBotSpec {
async fn handle_bot_messages(
player_id: u32,
event_bus: Arc<Mutex<EventBus>>,
- mut messages: Streaming<pb::ClientMessage>,
+ mut messages: Streaming<pb::PlayerApiClientMessage>,
) {
// TODO: can this be writte nmore nicely?
while let Some(message) = messages.message().await.unwrap() {
match message.client_message {
- Some(pb::client_message::ClientMessage::RequestResponse(resp)) => {
- let request_id = (player_id, resp.request_id as u32);
+ Some(pb::PlayerApiClientMessageType::Action(resp)) => {
+ let request_id = (player_id, resp.action_request_id as u32);
event_bus
.lock()
.unwrap()
@@ -221,20 +224,20 @@ async fn handle_bot_messages(
}
struct RemoteBotHandle {
- sender: mpsc::UnboundedSender<Result<pb::ServerMessage, Status>>,
+ sender: mpsc::UnboundedSender<Result<pb::PlayerApiServerMessage, Status>>,
player_id: u32,
event_bus: Arc<Mutex<EventBus>>,
}
impl PlayerHandle for RemoteBotHandle {
fn send_request(&mut self, r: RequestMessage) {
- let req = pb::PlayerRequest {
- request_id: r.request_id as i32,
+ let req = pb::PlayerActionRequest {
+ action_request_id: r.request_id as i32,
content: r.content,
};
- let server_message = pb::ServerMessage {
- server_message: Some(pb::server_message::ServerMessage::PlayerRequest(req)),
+ let server_message = pb::PlayerApiServerMessage {
+ server_message: Some(pb::PlayerApiServerMessageType::ActionRequest(req)),
};
let res = self.sender.send(Ok(server_message));
@@ -282,9 +285,9 @@ async fn schedule_timeout(
.resolve_request(request_id, Err(RequestError::Timeout));
}
-pub async fn run_bot_api(runner_config: Arc<GlobalConfig>, pool: ConnectionPool) {
+pub async fn run_client_api(runner_config: Arc<GlobalConfig>, pool: ConnectionPool) {
let router = PlayerRouter::new();
- let server = BotApiServer {
+ let server = ClientApiServer {
router,
conn_pool: pool,
runner_config,
@@ -292,7 +295,9 @@ pub async fn run_bot_api(runner_config: Arc<GlobalConfig>, pool: ConnectionPool)
let addr = SocketAddr::from(([127, 0, 0, 1], 50051));
Server::builder()
- .add_service(pb::bot_api_service_server::BotApiServiceServer::new(server))
+ .add_service(pb::client_api_service_server::ClientApiServiceServer::new(
+ server,
+ ))
.serve(addr)
.await
.unwrap()
diff --git a/planetwars-server/src/modules/mod.rs b/planetwars-server/src/modules/mod.rs
index 1200f9d..1d3ddbf 100644
--- a/planetwars-server/src/modules/mod.rs
+++ b/planetwars-server/src/modules/mod.rs
@@ -1,7 +1,7 @@
// This module implements general domain logic, not directly
// tied to the database or API layers.
-pub mod bot_api;
pub mod bots;
+pub mod client_api;
pub mod matches;
pub mod ranking;
pub mod registry;