Skip to content

Commit

Permalink
Merge pull request #18 from ZOTTCE/net-rework
Browse files Browse the repository at this point in the history
net rework
  • Loading branch information
Pycckue-Bnepeg authored Sep 21, 2021
2 parents bfb6bf3 + 57e6f02 commit 9952bda
Show file tree
Hide file tree
Showing 25 changed files with 716 additions and 177 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"server",
"cef-api",
"cef-interface",
"network",
]

[profile.release]
Expand Down
9 changes: 9 additions & 0 deletions cef/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ impl Frame {
V8Context::from_raw(ctx)
}

pub fn load_url(&self, url: &str) {
let url = CefString::new(url);
let load = self.inner.load_url.unwrap();

unsafe {
load(self.inner.get_mut(), url.as_cef_string());
}
}

pub fn send_process_message(&self, target_process: ProcessId, message: ProcessMessage) {
let send = self
.inner
Expand Down
12 changes: 6 additions & 6 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ encoding_rs = "0.8.20"
client-api = { git = "https://github.com/zottce/samp-client-api.git", branch = "destroy" }
cef = { path = "../cef" }
cef-sys = { path = "../cef-sys" }
crossbeam-channel = "0.3.9"
crossbeam-channel = "0.5.1"
d3dx9 = { path = "../d3dx9" }
winapi = { version = "0.3.8", features = ["d3d9", "winuser", "libloaderapi", "winver", "consoleapi", "memoryapi", "shlobj"] }
laminar = { git = "https://github.com/zottce/laminar.git" }
messages = { path = "../messages" }
quick-protobuf = "0.7.0"
quick-protobuf = "0.8.0"
detour = { git = "https://github.com/darfink/detour-rs", rev = "3b6f17a" }
libloading = "0.5.2"
libloading = "0.7.0"
alto = "3.0.4"
log = "0.4.14"
simplelog = "0.9.0"
simplelog = "0.10.0"
ambisonic = "0.4.1"
nalgebra = "0.24.1"
nalgebra = "0.29.0"
parking_lot = "0.11.1"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
net = { path = "../network", package = "network" }
6 changes: 6 additions & 0 deletions client/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub enum Event {
RemoveFromObject(u32, i32),
ToggleDevTools(u32, bool),
SetAudioSettings(u32, crate::audio::BrowserAudioSettings),
LoadUrl(u32, String),

CefInitialize,

Expand Down Expand Up @@ -456,6 +457,11 @@ pub fn mainloop() {
manager.set_audio_settings(browser, audio_settings);
}

Event::LoadUrl(browser, url) => {
let mut manager = app.manager.lock();
manager.load_url(browser, &url);
}

_ => (),
}
}
Expand Down
6 changes: 6 additions & 0 deletions client/src/browser/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ impl WebClient {
});
}

pub fn load_url(&self, url: &str) {
if let Some(browser) = self.browser() {
browser.main_frame().load_url(url);
}
}

pub fn id(&self) -> u32 {
self.id
}
Expand Down
6 changes: 6 additions & 0 deletions client/src/browser/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ impl Manager {
});
}

pub fn load_url(&self, browser_id: u32, url: &str) {
self.clients
.get(&browser_id)
.map(|client| client.load_url(url));
}

pub fn call_browser_ready(&self, browser_id: u32) {
self.ready_callbacks
.get(&browser_id)
Expand Down
76 changes: 40 additions & 36 deletions client/src/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,42 +113,46 @@ pub fn initialize(event_tx: Sender<Event>, manager: Arc<Mutex<Manager>>) -> Call
for dir in rd.filter_map(|dir| dir.ok()) {
if let Some(ext) = dir.path().extension() {
if ext.to_string_lossy() == "dll" {
match Library::new(dir.path().as_os_str()) {
Ok(mut lib) => unsafe {
let library: &'static mut Library = &mut *(&mut lib as *mut Library);

let mainloop =
library.get::<extern "C" fn()>(b"cef_samp_mainloop").ok();

let dxreset = library.get::<extern "C" fn()>(b"cef_dxreset").ok();
let initialize = library
.get::<extern "C" fn(*mut InternalApi)>(b"cef_initialize")
.ok();

let connect = library.get::<extern "C" fn()>(b"cef_connect").ok();
let disconnect = library.get::<extern "C" fn()>(b"cef_disconnect").ok();
let quit = library.get::<extern "C" fn()>(b"cef_quit").ok();
let browser_created = library
.get::<extern "C" fn(u32, i32)>(b"cef_browser_created")
.ok();

let plugin = ExtPlugin {
library: lib,
initialize,
mainloop,
dxreset,
connect,
disconnect,
quit,
browser_created,
};

external.plugins.push(plugin);

log::trace!("loaded plugin: {:?}", dir.path());
},

Err(e) => log::trace!("error loading library {:?}", e),
unsafe {
match Library::new(dir.path().as_os_str()) {
Ok(mut lib) => {
let library: &'static mut Library =
&mut *(&mut lib as *mut Library);

let mainloop =
library.get::<extern "C" fn()>(b"cef_samp_mainloop").ok();

let dxreset = library.get::<extern "C" fn()>(b"cef_dxreset").ok();
let initialize = library
.get::<extern "C" fn(*mut InternalApi)>(b"cef_initialize")
.ok();

let connect = library.get::<extern "C" fn()>(b"cef_connect").ok();
let disconnect =
library.get::<extern "C" fn()>(b"cef_disconnect").ok();
let quit = library.get::<extern "C" fn()>(b"cef_quit").ok();
let browser_created = library
.get::<extern "C" fn(u32, i32)>(b"cef_browser_created")
.ok();

let plugin = ExtPlugin {
library: lib,
initialize,
mainloop,
dxreset,
connect,
disconnect,
quit,
browser_created,
};

external.plugins.push(plugin);

log::trace!("loaded plugin: {:?}", dir.path());
}

Err(e) => log::trace!("error loading library {:?}", e),
}
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ pub extern "stdcall" fn DllMain(instance: HMODULE, reason: u32, _reserved: u32)
DisableThreadLibraryCalls(instance);
}

let mut config = simplelog::ConfigBuilder::new();

let config = config
.add_filter_allow_str("client")
.add_filter_allow_str("client_api")
.set_max_level(LevelFilter::Trace)
.build();

CombinedLogger::init(vec![WriteLogger::new(
LevelFilter::Trace,
Config::default(),
config,
File::create("cef_client.log").unwrap(),
)])
.unwrap();
Expand Down
Loading

0 comments on commit 9952bda

Please sign in to comment.