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:
parent
4d88f78184
commit
a99b0e7c17
3 changed files with 22 additions and 9 deletions
|
@ -1,3 +1,3 @@
|
||||||
function onBeginLogin()
|
function onBeginLogin(player)
|
||||||
print("Hello, world!")
|
print("Player " .. player.content_id .. " is connecting!")
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ use kawari::world::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use kawari::world::{PlayerData, WorldDatabase};
|
use kawari::world::{PlayerData, WorldDatabase};
|
||||||
use mlua::Lua;
|
use mlua::{Function, Lua};
|
||||||
use physis::common::{Language, Platform};
|
use physis::common::{Language, Platform};
|
||||||
use physis::gamedata::GameData;
|
use physis::gamedata::GameData;
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
|
@ -331,12 +331,18 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let lua = lua.lock().unwrap();
|
let lua = lua.lock().unwrap();
|
||||||
lua.load(
|
lua.scope(|scope| {
|
||||||
r#"
|
let player_data = scope
|
||||||
onBeginLogin()
|
.create_userdata_ref(&connection.player_data)
|
||||||
"#,
|
.unwrap();
|
||||||
)
|
|
||||||
.exec()
|
let func: Function =
|
||||||
|
lua.globals().get("onBeginLogin").unwrap();
|
||||||
|
|
||||||
|
func.call::<()>(player_data).unwrap();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
ClientZoneIpcData::FinishLoading { .. } => {
|
ClientZoneIpcData::FinishLoading { .. } => {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use mlua::{UserData, UserDataFields};
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -24,6 +25,12 @@ pub struct PlayerData {
|
||||||
pub account_id: u32,
|
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
|
/// Represents a single connection between an instance of the client and the world server
|
||||||
pub struct ZoneConnection {
|
pub struct ZoneConnection {
|
||||||
pub socket: TcpStream,
|
pub socket: TcpStream,
|
||||||
|
|
Loading…
Add table
Reference in a new issue