diff --git a/server-cli/src/cli.rs b/server-cli/src/cli.rs
index 32d98cfeb6..652d9b9c6e 100644
--- a/server-cli/src/cli.rs
+++ b/server-cli/src/cli.rs
@@ -74,6 +74,9 @@ pub enum Message {
/// returns active player names
ListPlayers,
ListLogs,
+ SendWorldMsg {
+ msg: String,
+ },
}
#[derive(Debug, Clone)]
diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs
index 31f82c5af5..3549c7bdd2 100644
--- a/server-cli/src/main.rs
+++ b/server-cli/src/main.rs
@@ -26,7 +26,11 @@ use crate::{
tui_runner::Tui,
tuilog::TuiLog,
};
-use common::{clock::Clock, comp::Player, consts::MIN_RECOMMENDED_TOKIO_THREADS};
+use common::{
+ clock::Clock,
+ comp::{ChatType, Player},
+ consts::MIN_RECOMMENDED_TOKIO_THREADS,
+};
use common_base::span;
use core::sync::atomic::{AtomicUsize, Ordering};
use server::{persistence::DatabaseSettings, settings::Protocol, Event, Input, Server};
@@ -394,6 +398,11 @@ fn server_loop(
.collect();
let _ = response.send(MessageReturn::Logs(lines));
},
+ Message::SendWorldMsg { msg } => {
+ use server::state_ext::StateExt;
+ let msg = ChatType::Meta.into_plain_msg(msg);
+ server.state().send_chat(msg);
+ },
}
false
};
diff --git a/server-cli/src/web/ui.rs b/server-cli/src/web/ui.rs
index 4e26772762..fb5206dfa7 100644
--- a/server-cli/src/web/ui.rs
+++ b/server-cli/src/web/ui.rs
@@ -150,6 +150,9 @@ fn inner() -> &'static str {
+
+
+
Players
@@ -192,6 +195,25 @@ function changeSlider(evt, sliderId, showId) {
sliderNo.innerHTML = slider.value;
}
+async function sendGlobalMsg() {
+ var world_msg = document.getElementById("world_msg");
+ const msg_text = world_msg.value;
+
+ const msg_response = await fetch("/ui_api/v1/send_world_msg", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ msg: msg_text
+ })
+ });
+
+ if (msg_response.status == 200) {
+ world_msg.value = '';
+ }
+}
+
async function update_players() {
const players_response = await fetch("/ui_api/v1/players");
const players = await players_response.json();
diff --git a/server-cli/src/web/ui_api.rs b/server-cli/src/web/ui_api.rs
index f47fc0c4f5..28baeb5f6d 100644
--- a/server-cli/src/web/ui_api.rs
+++ b/server-cli/src/web/ui_api.rs
@@ -4,10 +4,11 @@ use axum::{
http::header::COOKIE,
middleware::Next,
response::{IntoResponse, Response},
- routing::get,
+ routing::{get, post},
Json, Router,
};
use hyper::{Request, StatusCode};
+use serde::Deserialize;
use std::{
collections::HashSet,
net::{IpAddr, SocketAddr},
@@ -69,6 +70,7 @@ pub fn router(web_ui_request_s: UiRequestSender, secret_token: String) -> Router
Router::new()
.route("/players", get(players))
.route("/logs", get(logs))
+ .route("/send_world_msg", post(send_world_msg))
.layer(axum::middleware::from_fn_with_state(ip_addrs, log_users))
.layer(axum::middleware::from_fn_with_state(token, validate_secret))
.with_state(web_ui_request_s)
@@ -101,3 +103,19 @@ async fn logs(
_ => Err(StatusCode::INTERNAL_SERVER_ERROR),
}
}
+
+#[derive(Deserialize)]
+struct SendWorldMsgBody {
+ msg: String,
+}
+
+async fn send_world_msg(
+ State(web_ui_request_s): State
,
+ Json(payload): Json,
+) -> Result {
+ let (dummy_s, _) = tokio::sync::oneshot::channel();
+ let _ = web_ui_request_s
+ .send((Message::SendWorldMsg { msg: payload.msg }, dummy_s))
+ .await;
+ Ok(())
+}