mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-09-10 17:45:42 +00:00
b14a8cf162
Add a full automated build pipeline, interactive build scripts, documentation and development utilities. - Add GitHub Actions workflow (.github/workflows/build.yml) to build BetterDesk (hbbs/hbbr) for Linux x64, Linux ARM64 and Windows x64, upload artifacts, optionally create a release and update repository binaries. - Add interactive build scripts for Windows and Unix (build-betterdesk.ps1, build-betterdesk.sh) supporting download, patch application, cross-build and checksum generation. - Add build and status docs (docs/BUILD_GUIDE.md, docs/STATUS_TRACKING_v3.md) and update project README/instructions (.github/copilot-instructions.md) with new items and updated timestamp. - Add development utilities under dev_modules/ (multiple database/patch/test helpers) and move test_generator.py into dev_modules/test_generator.py. - Update .gitignore to exclude archive/ folder. - Modify hbbs-patch-v2 sources (database.rs, http_api.rs, main.rs, peer.rs and add rendezvous_server.rs) and remove legacy fixed files; update web UI backend and static files (web/app.py, web/static/*, web/templates/index.html). These changes set up CI/CD for multi-platform builds, provide local build tooling, expand docs for v3 status tracking and ID-change features, and add developer test/patch utilities.
76 lines
4.0 KiB
Python
76 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Patch rendezvous_server.rs to support ID change via old_id field in RegisterPk"""
|
|
|
|
with open("rendezvous_server.rs", "r") as f:
|
|
content = f.read()
|
|
|
|
# Find the RegisterPk handler and add old_id support
|
|
old_code = ''' Some(rendezvous_message::Union::RegisterPk(rk)) => {
|
|
if rk.uuid.is_empty() || rk.pk.is_empty() {
|
|
return Ok(());
|
|
}
|
|
let id = rk.id;'''
|
|
|
|
new_code = ''' Some(rendezvous_message::Union::RegisterPk(rk)) => {
|
|
if rk.uuid.is_empty() || rk.pk.is_empty() {
|
|
return Ok(());
|
|
}
|
|
|
|
// Handle ID change request (old_id is set)
|
|
if !rk.old_id.is_empty() {
|
|
log::info!("ID change request: {} -> {}", rk.old_id, rk.id);
|
|
|
|
// Validate new ID format
|
|
if rk.id.len() < 6 || rk.id.len() > 16 {
|
|
log::warn!("ID change rejected: invalid new ID length");
|
|
return send_rk_res(socket, addr, register_pk_response::Result::INVALID_ID_FORMAT).await;
|
|
}
|
|
|
|
// Check if new ID already exists
|
|
if self.pm.is_in_memory(&rk.id).await {
|
|
log::warn!("ID change rejected: new ID {} already exists", rk.id);
|
|
return send_rk_res(socket, addr, register_pk_response::Result::ID_EXISTS).await;
|
|
}
|
|
|
|
// Check if old ID exists and UUID matches
|
|
if let Some(old_peer) = self.pm.get_in_memory(&rk.old_id).await {
|
|
let old_uuid = old_peer.read().await.uuid.clone();
|
|
if old_uuid != rk.uuid {
|
|
log::warn!("ID change rejected: UUID mismatch for {}", rk.old_id);
|
|
return send_rk_res(socket, addr, UUID_MISMATCH).await;
|
|
}
|
|
|
|
// Perform ID change in database
|
|
match self.pm.db.change_id(&rk.old_id, &rk.id).await {
|
|
Ok(_) => {
|
|
log::info!("ID changed successfully: {} -> {}", rk.old_id, rk.id);
|
|
// Remove old peer from memory, it will re-register with new ID
|
|
self.pm.remove(&rk.old_id).await;
|
|
let mut msg_out = RendezvousMessage::new();
|
|
msg_out.set_register_pk_response(RegisterPkResponse {
|
|
result: register_pk_response::Result::OK.into(),
|
|
..Default::default()
|
|
});
|
|
return socket.send(&msg_out, addr).await;
|
|
}
|
|
Err(e) => {
|
|
log::error!("ID change failed: {}", e);
|
|
return send_rk_res(socket, addr, register_pk_response::Result::SERVER_ERROR).await;
|
|
}
|
|
}
|
|
} else {
|
|
log::warn!("ID change rejected: old ID {} not found", rk.old_id);
|
|
return send_rk_res(socket, addr, register_pk_response::Result::SERVER_ERROR).await;
|
|
}
|
|
}
|
|
|
|
let id = rk.id;'''
|
|
|
|
if old_code in content:
|
|
content = content.replace(old_code, new_code)
|
|
with open("rendezvous_server.rs", "w") as f:
|
|
f.write(content)
|
|
print("SUCCESS: Patched RegisterPk handler to support ID change")
|
|
else:
|
|
print("ERROR: Could not find target code block")
|