Update SyncbackRequest structure and API protocol validation

- Changed the `protocol_version` and `place_id` fields in the `SyncbackRequest` struct from `u64` to `f64` to accommodate Luau's numeric representation.
- Updated the API's protocol version validation to compare the `syncback_request.protocol_version` as a `u64`, ensuring compatibility with the expected protocol version.
- Enhanced type handling for `place_id` to maintain consistency in the syncback process.

These changes improve the handling of numeric fields in syncback requests, aligning with the requirements of the Luau environment.
This commit is contained in:
Joe 2026-02-18 05:32:46 -06:00
parent fa2b86c3d9
commit 372a422b3d
2 changed files with 10 additions and 5 deletions

View file

@ -194,11 +194,12 @@ async fn handle_api_syncback(
} }
}; };
if syncback_request.protocol_version != PROTOCOL_VERSION { let client_protocol = syncback_request.protocol_version as u64;
if client_protocol != PROTOCOL_VERSION {
return msgpack( return msgpack(
ErrorResponse::bad_request(format!( ErrorResponse::bad_request(format!(
"Protocol version mismatch: expected {}, got {}", "Protocol version mismatch: expected {}, got {}",
PROTOCOL_VERSION, syncback_request.protocol_version PROTOCOL_VERSION, client_protocol
)), )),
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
); );
@ -219,7 +220,8 @@ async fn handle_api_syncback(
); );
} }
if let Some(place_id) = syncback_request.place_id { if let Some(place_id_f64) = syncback_request.place_id {
let place_id = place_id_f64 as u64;
if let Some(expected) = service.serve_session.serve_place_ids() { if let Some(expected) = service.serve_session.serve_place_ids() {
if !expected.contains(&place_id) { if !expected.contains(&place_id) {
return msgpack( return msgpack(

View file

@ -37,12 +37,15 @@ pub struct ServiceChunk {
} }
/// Incoming request from the plugin for live syncback. /// Incoming request from the plugin for live syncback.
/// Numeric fields use `f64` because Luau has no integer type -- all numbers
/// are IEEE 754 doubles, and large values (like place IDs) get encoded as
/// msgpack float64 which rmp_serde cannot coerce into u64.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SyncbackRequest { pub struct SyncbackRequest {
pub protocol_version: u64, pub protocol_version: f64,
pub server_version: String, pub server_version: String,
pub place_id: Option<u64>, pub place_id: Option<f64>,
pub services: Vec<ServiceChunk>, pub services: Vec<ServiceChunk>,
} }