add new method for litelib to check if server is online
This commit is contained in:
@@ -14,6 +14,7 @@ extern char * litelib_initialize_existing (bool dangerous,const char* server);
|
||||
extern char * litelib_execute (const char* s, const char* args);
|
||||
extern void litelib_rust_free_string (char* s);
|
||||
extern char * blake3_PW (char* pw);
|
||||
extern bool litelib_check_server_online (const char* server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -245,6 +245,24 @@ pub extern fn litelib_execute(cmd: *const c_char, args: *const c_char) -> *mut c
|
||||
return c_str.into_raw();
|
||||
}
|
||||
|
||||
// Check is Server Connection is fine
|
||||
#[no_mangle]
|
||||
pub extern "C" fn litelib_check_server_online(server: *const c_char) -> bool {
|
||||
let server_str = unsafe {
|
||||
assert!(!server.is_null());
|
||||
|
||||
CStr::from_ptr(server).to_string_lossy().into_owned()
|
||||
};
|
||||
|
||||
let server = LightClientConfig::get_server_or_default(Some(server_str));
|
||||
let result = LightClientConfig::create(server, false);
|
||||
|
||||
match result {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callers that receive string return values from other functions should call this to return the string
|
||||
* back to rust, so it can be freed. Failure to call this function will result in a memory leak
|
||||
|
||||
Reference in New Issue
Block a user