Multiplayer client relay bridge and match lobby menu: WebSocket bridge, match lobby page, order relay, confirmed turns, checksums, chat, abort/resume

This commit is contained in:
Richard Zink committed 2026-11-04 12:47:34 +01:00
1 parent 848ab0f677
commit 583c3fcdaf
9 files changed
+1063 -6

No files matched your search

+62
View File
@@ -30,6 +30,11 @@ mod imp {
fn dc_http_poll(id: u32) -> i32;
fn dc_http_len(id: u32) -> u32;
fn dc_http_take(id: u32, dst: *mut u8);
fn dc_ws_connect(u: *const u8, ul: u32) -> i32;
fn dc_ws_state(id: i32) -> i32;
fn dc_ws_send(id: i32, p: *const u8, pl: u32) -> i32;
fn dc_ws_take(id: i32) -> i32;
fn dc_ws_close(id: i32);
}
// starts a request; poll the returned id with http_poll()
@@ -127,6 +132,45 @@ mod imp {
Some(buf)
}
}
pub fn ws_connect(url: &str) -> i32 {
unsafe { dc_ws_connect(url.as_ptr(), url.len() as u32) }
}
pub fn ws_state(id: i32) -> i32 {
if id <= 0 {
return 4;
}
unsafe { dc_ws_state(id) }
}
pub fn ws_send(id: i32, text: &str) -> bool {
if id <= 0 {
return false;
}
unsafe { dc_ws_send(id, text.as_ptr(), text.len() as u32) != 0 }
}
pub fn ws_recv(id: i32) -> Option<String> {
if id <= 0 {
return None;
}
unsafe {
let n = dc_ws_take(id);
if n <= 0 {
return None;
}
let mut buf = vec![0u8; n as usize];
dc_storage_take(buf.as_mut_ptr());
String::from_utf8(buf).ok()
}
}
pub fn ws_close(id: i32) {
if id > 0 {
unsafe { dc_ws_close(id) }
}
}
}
#[cfg(not(target_arch = "wasm32"))]
@@ -171,6 +215,24 @@ mod imp {
pub fn http_poll(_id: u32) -> Option<super::HttpResult> {
Some(super::HttpResult { status: 0, body: Vec::new() })
}
// no WebSocket in native builds: multi-user matches need the browser build
pub fn ws_connect(_url: &str) -> i32 {
0
}
pub fn ws_state(id: i32) -> i32 {
if id <= 0 {
0
} else {
4
}
}
pub fn ws_send(_id: i32, _text: &str) -> bool {
false
}
pub fn ws_recv(_id: i32) -> Option<String> {
None
}
pub fn ws_close(_id: i32) {}
}
pub use imp::*;