mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-26 05:50:14 +00:00
wip more lua stuff (events + cleanup/util)
This commit is contained in:
1 parent
56cd0eca11
commit
6a1baa249a
3 files changed
+30
-11
No files matched your search
+6
-4
@@ -399,10 +399,6 @@ impl Server {
|
|||||||
ip: String::from("not yet implemented"),
|
ip: String::from("not yet implemented"),
|
||||||
beammp_id: beammp_id.clone(),
|
beammp_id: beammp_id.clone(),
|
||||||
} }, Some(tx)))).await;
|
} }, 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);
|
vrx.push(rx);
|
||||||
}
|
}
|
||||||
self.clients_queue.push((client, vrx, Vec::new()));
|
self.clients_queue.push((client, vrx, Vec::new()));
|
||||||
@@ -437,7 +433,13 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if allowed {
|
if allowed {
|
||||||
|
let pid = client.id;
|
||||||
self.clients.push(client);
|
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 {
|
} else {
|
||||||
// TODO: Custom kick message defined from within lua somehow?
|
// TODO: Custom kick message defined from within lua somehow?
|
||||||
// TODO: Kicking the client and then immediately dropping them results in the
|
// 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 {
|
let (event_name, args) = match event {
|
||||||
ScriptEvent::OnPluginLoaded => ("onInit", vec![]),
|
ScriptEvent::OnPluginLoaded => ("onInit", vec![]),
|
||||||
ScriptEvent::OnShutdown => ("onShutdown", 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::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::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)]),
|
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...");
|
debug!("sending result...");
|
||||||
if let Some(resp) = resp {
|
if let Some(resp) = resp {
|
||||||
let arg = match ret {
|
let arg = value_to_arg(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),
|
|
||||||
};
|
|
||||||
resp.send(arg).expect("Failed to send!");
|
resp.send(arg).expect("Failed to send!");
|
||||||
}
|
}
|
||||||
debug!("call_event_handler done");
|
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> {
|
fn arg_to_value(lua: &Lua, arg: Argument) -> Option<Value> {
|
||||||
match arg {
|
match arg {
|
||||||
Argument::String(s) => if let Ok(lua_str) = lua.create_string(&s) { Some(Value::String(lua_str)) } else { None },
|
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,
|
OnPluginLoaded,
|
||||||
OnShutdown,
|
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 },
|
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 },
|
OnPlayerDisconnect { pid: u8, name: String },
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user