mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-19 22:36:49 +00:00
Pass PlayerData to onBeginLogin function
This commit is contained in:
parent
4d88f78184
commit
a99b0e7c17
3 changed files with 22 additions and 9 deletions
|
@ -1,3 +1,3 @@
|
|||
function onBeginLogin()
|
||||
print("Hello, world!")
|
||||
function onBeginLogin(player)
|
||||
print("Player " .. player.content_id .. " is connecting!")
|
||||
end
|
||||
|
|
|
@ -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 { .. } => {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue