mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-07 08:16:24 +00:00
wip more lua stuff (events + cleanup/util)
This commit is contained in:
@@ -399,10 +399,6 @@ impl Server {
|
||||
ip: String::from("not yet implemented"),
|
||||
beammp_id: beammp_id.clone(),
|
||||
} }, Some(tx)))).await;
|
||||
// TODO: This never returns, because it blocks the entire process function
|
||||
// from running, so it never manages to run the function correctly.
|
||||
// let res = rx.await.unwrap_or(Argument::Number(-1f32));
|
||||
// debug!("res: {:?}", res);
|
||||
vrx.push(rx);
|
||||
}
|
||||
self.clients_queue.push((client, vrx, Vec::new()));
|
||||
@@ -437,7 +433,13 @@ impl Server {
|
||||
}
|
||||
}
|
||||
if allowed {
|
||||
let pid = client.id;
|
||||
self.clients.push(client);
|
||||
|
||||
for plugin in &mut self.plugins {
|
||||
plugin.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnPlayerConnecting { pid }, None))).await;
|
||||
plugin.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnPlayerJoining { pid }, None))).await;
|
||||
}
|
||||
} else {
|
||||
// TODO: Custom kick message defined from within lua somehow?
|
||||
// TODO: Kicking the client and then immediately dropping them results in the
|
||||
|
||||
@@ -167,8 +167,13 @@ impl Backend for BackendLua {
|
||||
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::OnPlayerConnecting { pid } => ("onPlayerConnecting", vec![Argument::Integer(pid as i64)]),
|
||||
ScriptEvent::OnPlayerJoining { pid } => ("onPlayerJoining", vec![Argument::Integer(pid as i64)]),
|
||||
|
||||
ScriptEvent::OnPlayerDisconnect { pid, name } => ("onPlayerDisconnect", vec![Argument::Integer(pid as i64), Argument::String(name)]),
|
||||
|
||||
ScriptEvent::OnChatMessage { pid, name, message } => ("onChatMessage", vec![Argument::Integer(pid as i64), Argument::String(name), Argument::String(message)]),
|
||||
};
|
||||
|
||||
@@ -196,19 +201,23 @@ impl Backend for BackendLua {
|
||||
|
||||
debug!("sending result...");
|
||||
if let Some(resp) = resp {
|
||||
let arg = match ret {
|
||||
Value::Boolean(b) => Argument::Boolean(b),
|
||||
Value::Integer(i) => Argument::Integer(i),
|
||||
Value::Number(f) => Argument::Number(f as f32),
|
||||
Value::String(s) => Argument::String(s.to_string_lossy().to_string()),
|
||||
_ => Argument::Number(-1f32),
|
||||
};
|
||||
let arg = value_to_arg(ret);
|
||||
resp.send(arg).expect("Failed to send!");
|
||||
}
|
||||
debug!("call_event_handler done");
|
||||
}
|
||||
}
|
||||
|
||||
fn value_to_arg(value: Value) -> Argument {
|
||||
match value {
|
||||
Value::Boolean(b) => Argument::Boolean(b),
|
||||
Value::Integer(i) => Argument::Integer(i),
|
||||
Value::Number(f) => Argument::Number(f as f32),
|
||||
Value::String(s) => Argument::String(s.to_string_lossy().to_string()),
|
||||
_ => Argument::Number(-1f32),
|
||||
}
|
||||
}
|
||||
|
||||
fn arg_to_value(lua: &Lua, arg: Argument) -> Option<Value> {
|
||||
match arg {
|
||||
Argument::String(s) => if let Ok(lua_str) = lua.create_string(&s) { Some(Value::String(lua_str)) } else { None },
|
||||
|
||||
@@ -47,7 +47,15 @@ pub enum ScriptEvent {
|
||||
OnPluginLoaded,
|
||||
OnShutdown,
|
||||
|
||||
// TODO: Because of limitations in how we accept clients, onPlayerAuth runs after mod downloading and syncing
|
||||
// has already happened. With some reworking, this can be avoided, but it's not easy.
|
||||
// This is quite important however, because otherwise mod downloads will get triggered
|
||||
// constantly even when someone isn't allowed to join!
|
||||
OnPlayerAuthenticated { name: String, role: String, is_guest: bool, identifiers: PlayerIdentifiers },
|
||||
// TODO: See the comment above, this results in these 2 events being useless for now.
|
||||
// I've simply left them in for backwards compatibility for now!
|
||||
OnPlayerConnecting { pid: u8 },
|
||||
OnPlayerJoining { pid: u8 },
|
||||
|
||||
OnPlayerDisconnect { pid: u8, name: String },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user