mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-07 00:06:22 +00:00
closing tui no longer crashes + onShutdown event
This commit is contained in:
@@ -137,6 +137,7 @@ impl Backend for BackendLua {
|
||||
fn call_event_handler(&mut self, event: ScriptEvent, resp: Option<oneshot::Sender<Argument>>) {
|
||||
let (event_name, args) = match event {
|
||||
ScriptEvent::OnPluginLoaded => ("onInit", vec![]),
|
||||
ScriptEvent::OnShutdown => ("onShutdown", vec![]),
|
||||
ScriptEvent::OnPlayerAuthenticated { name, role, is_guest, identifiers } => ("onPlayerAuth", vec![Argument::String(name), Argument::String(role), Argument::Boolean(is_guest), Argument::Table(identifiers.to_map())]),
|
||||
ScriptEvent::OnPlayerDisconnect { pid, name } => ("onPlayerDisconnect", vec![Argument::Number(pid as f32), Argument::String(name)]),
|
||||
};
|
||||
|
||||
@@ -45,6 +45,7 @@ impl PlayerIdentifiers {
|
||||
#[derive(Debug)]
|
||||
pub enum ScriptEvent {
|
||||
OnPluginLoaded,
|
||||
OnShutdown,
|
||||
|
||||
OnPlayerAuthenticated { name: String, role: String, is_guest: bool, identifiers: PlayerIdentifiers },
|
||||
|
||||
@@ -114,6 +115,13 @@ impl Plugin {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn close(mut self) {
|
||||
let (tx, mut rx) = oneshot::channel();
|
||||
self.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnShutdown, Some(tx)))).await;
|
||||
let _ = rx.await; // We just wait for it to finish shutting down
|
||||
self.runtime.shutdown_background();
|
||||
}
|
||||
|
||||
// TODO: For performance I think we can turn this into an iterator instead of first allocating
|
||||
// a full vector?
|
||||
pub fn get_events(&mut self) -> Vec<ServerBoundPluginEvent> {
|
||||
|
||||
Reference in New Issue
Block a user