diff --git a/back_end/src/json_handlers.rs b/back_end/src/json_handlers.rs index b3c20b6..acacafa 100644 --- a/back_end/src/json_handlers.rs +++ b/back_end/src/json_handlers.rs @@ -6,7 +6,10 @@ //This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // //You should have received a copy of the GNU General Public License along with this program. If not, see . -use crate::db_handler::{CheckPairingType, DBHandlerRequest, GetIDSenderType}; +use crate::{ + constants::BACKEND_PHRASE_MAX_LENGTH, + db_handler::{CheckPairingType, DBHandlerRequest, GetIDSenderType}, +}; use std::{ sync::mpsc::{sync_channel, SyncSender}, @@ -40,8 +43,19 @@ fn handle_pairing_request(root: Value, tx: SyncSender) -> Resu let (player_tx, player_rx) = sync_channel::(1); let mut phrase: Option = None; if let Some(phrase_text) = root.get("phrase") { - if let Some(phrase_str) = phrase_text.as_str() { + if let Some(mut phrase_str) = phrase_text.as_str() { if !phrase_str.is_empty() { + if phrase_str.len() > BACKEND_PHRASE_MAX_LENGTH { + let mut idx = BACKEND_PHRASE_MAX_LENGTH; + while idx > 0 && !phrase_str.is_char_boundary(idx) { + idx -= 1; + } + if idx == 0 { + phrase_str = ""; + } else { + phrase_str = phrase_str.split_at(idx).0; + } + } phrase = Some(phrase_str.to_owned()); } } diff --git a/front_end/src/constants.rs b/front_end/src/constants.rs index 1c082aa..6f59509 100644 --- a/front_end/src/constants.rs +++ b/front_end/src/constants.rs @@ -23,6 +23,8 @@ pub const PLAYER_CLEANUP_TIMEOUT: u64 = 300; pub const BACKEND_TICK_DURATION_MILLIS: i32 = 500; pub const BACKEND_CLEANUP_INTERVAL_SECONDS: u64 = 120; +pub const BACKEND_PHRASE_MAX_LENGTH: usize = 128; + // TODO: Change this to "https://asdm.seodisparate.com/api" when backend is installed #[cfg(debug_assertions)] pub const BACKEND_URL: &str = "http://testlocalhost/api";