1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-20 06:37:45 +00:00

Pass PlayerData to onBeginLogin function

This commit is contained in:
Joshua Goins 2025-03-27 19:24:36 -04:00
parent 4d88f78184
commit a99b0e7c17
3 changed files with 22 additions and 9 deletions

View file

@ -1,3 +1,3 @@
function onBeginLogin()
print("Hello, world!")
function onBeginLogin(player)
print("Player " .. player.content_id .. " is connecting!")
end

View file

@ -24,7 +24,7 @@ use kawari::world::{
},
};
use kawari::world::{PlayerData, WorldDatabase};
use mlua::Lua;
use mlua::{Function, Lua};
use physis::common::{Language, Platform};
use physis::gamedata::GameData;
use tokio::io::AsyncReadExt;
@ -331,12 +331,18 @@ async fn main() {
}
let lua = lua.lock().unwrap();
lua.load(
r#"
onBeginLogin()
"#,
)
.exec()
lua.scope(|scope| {
let player_data = scope
.create_userdata_ref(&connection.player_data)
.unwrap();
let func: Function =
lua.globals().get("onBeginLogin").unwrap();
func.call::<()>(player_data).unwrap();
Ok(())
})
.unwrap();
}
ClientZoneIpcData::FinishLoading { .. } => {

View file

@ -1,3 +1,4 @@
use mlua::{UserData, UserDataFields};
use tokio::net::TcpStream;
use crate::{
@ -24,6 +25,12 @@ pub struct PlayerData {
pub account_id: u32,
}
impl UserData for PlayerData {
fn add_fields<F: UserDataFields<Self>>(fields: &mut F) {
fields.add_field_method_get("content_id", |_, this| Ok(this.content_id));
}
}
/// Represents a single connection between an instance of the client and the world server
pub struct ZoneConnection {
pub socket: TcpStream,