From c6b1eadcd03fe1a6e91507d2bb4674c7b29e7f20 Mon Sep 17 00:00:00 2001 From: yHSJ Date: Tue, 26 Nov 2024 13:26:20 -0800 Subject: [PATCH] chore: replace websocket protocol with http protocol --- crates/rpc/src/routes/add_player.rs | 7 +++++- crates/rpc/src/routes/cleanup.rs | 28 ---------------------- crates/rpc/src/routes/end_game.rs | 29 ---------------------- crates/rpc/src/routes/new_game.rs | 7 +++++- crates/rpc/src/routes/start_game.rs | 37 ----------------------------- 5 files changed, 12 insertions(+), 96 deletions(-) delete mode 100644 crates/rpc/src/routes/cleanup.rs delete mode 100644 crates/rpc/src/routes/end_game.rs delete mode 100644 crates/rpc/src/routes/start_game.rs diff --git a/crates/rpc/src/routes/add_player.rs b/crates/rpc/src/routes/add_player.rs index bd0851b..7cf20fa 100644 --- a/crates/rpc/src/routes/add_player.rs +++ b/crates/rpc/src/routes/add_player.rs @@ -23,7 +23,12 @@ pub async fn add_player( let (external_url, local_url): (String, String) = node .status .as_ref() - .map(|status| (status.external_url.clone(), status.local_url.clone())) + .map(|status| { + ( + status.external_url.clone().replace("ws://", "https://"), + status.local_url.clone().replace("ws://", "https://"), + ) + }) .unwrap_or_default(); let url = local_url + "/game/add_player?address=" + address; diff --git a/crates/rpc/src/routes/cleanup.rs b/crates/rpc/src/routes/cleanup.rs deleted file mode 100644 index ff82b7b..0000000 --- a/crates/rpc/src/routes/cleanup.rs +++ /dev/null @@ -1,28 +0,0 @@ -use rocket::{http::Status, post, State}; -use tracing::error; - -use crate::{ - guards::api_key::ApiKey, - model::cluster::{ClusterState, NodeClient}, -}; - -#[post("/cleanup?")] -pub async fn cleanup( - id: &str, - _api_key: ApiKey, - state: &State, -) -> Result<(), Status> { - let node = state.get_node_by_id(id).ok_or(Status::NotFound)?; - - let client = NodeClient::new(node, state.admin_sk.clone(), state.remote, state.network) - .inspect_err(|err| error!("error connecting to node: {}", err)) - .map_err(|_| Status::InternalServerError)?; - - client - .cleanup_game() - .await - .inspect_err(|err| error!("failed to cleanup game: {}", err)) - .map_err(|_| Status::InternalServerError)?; - - Ok(()) -} diff --git a/crates/rpc/src/routes/end_game.rs b/crates/rpc/src/routes/end_game.rs deleted file mode 100644 index 1f57d97..0000000 --- a/crates/rpc/src/routes/end_game.rs +++ /dev/null @@ -1,29 +0,0 @@ -use rocket::{http::Status, post, State}; -use tracing::error; - -use crate::{ - guards::api_key::ApiKey, - model::cluster::{ClusterState, NodeClient}, -}; - -#[post("/end_game?")] -pub async fn end_game( - id: &str, - _api_key: ApiKey, - state: &State, -) -> Result<(), Status> { - let node = state.get_node_by_id(id).ok_or(Status::NotFound)?; - - let client = NodeClient::new(node, state.admin_sk.clone(), state.remote, state.network) - .inspect_err(|err| error!("error connecting to node: {}", err)) - .map_err(|_| Status::InternalServerError)?; - - // TODO: we need to take in the "end state" of the game. Currently, we are always aborting - client - .end_game() - .await - .inspect_err(|err| error!("failed to end game: {}", err)) - .map_err(|_| Status::InternalServerError)?; - - Ok(()) -} diff --git a/crates/rpc/src/routes/new_game.rs b/crates/rpc/src/routes/new_game.rs index fd7a2a1..72c052f 100644 --- a/crates/rpc/src/routes/new_game.rs +++ b/crates/rpc/src/routes/new_game.rs @@ -29,7 +29,12 @@ pub async fn new_game(address: &str, state: &State) -> Result")] -pub async fn start_game( - id: &str, - _api_key: ApiKey, - state: &State, -) -> Result<(), Status> { - let node = state - .get_node_by_id(id) - .ok_or(Status::BadRequest) - .inspect_err(|_| error!("failed to fetch node with id: {}", id))?; - - let node_id = node.metadata.name.clone().expect("node without a name"); - info!(id = node_id, "start game for node"); - - let client = NodeClient::new(node, state.admin_sk.clone(), state.remote, state.network) - .inspect_err(|err| error!("failed to connect to node: {}", err)) - .map_err(|_| Status::ServiceUnavailable)?; - - info!(id = node_id, "connected to node"); - - client - .start_game() - .await - .inspect_err(|err| error!("failed to submit start game tx: {}", err)) - .map_err(|_| Status::InternalServerError)?; - - Ok(()) -}