mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-24 08:07:45 +00:00
Move some more connection tasks into ZoneConnection
Notably part of the initialization and actor control self calls.
This commit is contained in:
parent
37c19ee1b8
commit
fe318cbc65
2 changed files with 111 additions and 165 deletions
|
@ -135,94 +135,14 @@ async fn main() {
|
||||||
for segment in &segments {
|
for segment in &segments {
|
||||||
match &segment.segment_type {
|
match &segment.segment_type {
|
||||||
SegmentType::InitializeSession { actor_id } => {
|
SegmentType::InitializeSession { actor_id } => {
|
||||||
tracing::info!("actor id to parse: {actor_id}");
|
// for some reason they send a string representation
|
||||||
|
let actor_id = actor_id.parse::<u32>().unwrap();
|
||||||
|
|
||||||
// collect actor data
|
// collect actor data
|
||||||
connection.player_data =
|
connection.player_data = database.find_player_data(actor_id);
|
||||||
database.find_player_data(actor_id.parse::<u32>().unwrap());
|
connection.initialize(&connection_type, actor_id).await;
|
||||||
// some still hardcoded values
|
|
||||||
connection.player_data.classjob_id = 1;
|
|
||||||
connection.player_data.level = 5;
|
|
||||||
connection.player_data.curr_hp = 100;
|
|
||||||
connection.player_data.max_hp = 100;
|
|
||||||
connection.player_data.curr_mp = 10000;
|
|
||||||
connection.player_data.max_mp = 10000;
|
|
||||||
|
|
||||||
exit_position = Some(connection.player_data.position);
|
exit_position = Some(connection.player_data.position);
|
||||||
exit_rotation = Some(connection.player_data.rotation);
|
exit_rotation = Some(connection.player_data.rotation);
|
||||||
|
|
||||||
// We have send THEM a keep alive
|
|
||||||
{
|
|
||||||
connection
|
|
||||||
.send_segment(PacketSegment {
|
|
||||||
source_actor: 0,
|
|
||||||
target_actor: 0,
|
|
||||||
segment_type: SegmentType::KeepAlive {
|
|
||||||
id: 0xE0037603u32,
|
|
||||||
timestamp: timestamp_secs(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
match connection_type {
|
|
||||||
kawari::packet::ConnectionType::Zone => {
|
|
||||||
tracing::info!(
|
|
||||||
"Client {actor_id} is initializing zone session..."
|
|
||||||
);
|
|
||||||
|
|
||||||
connection
|
|
||||||
.send_segment(PacketSegment {
|
|
||||||
source_actor: 0,
|
|
||||||
target_actor: 0,
|
|
||||||
segment_type: SegmentType::ZoneInitialize {
|
|
||||||
player_id: connection.player_data.actor_id,
|
|
||||||
timestamp: timestamp_secs(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
kawari::packet::ConnectionType::Chat => {
|
|
||||||
tracing::info!(
|
|
||||||
"Client {actor_id} is initializing chat session..."
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
|
||||||
connection
|
|
||||||
.send_segment(PacketSegment {
|
|
||||||
source_actor: 0,
|
|
||||||
target_actor: 0,
|
|
||||||
segment_type: SegmentType::ZoneInitialize {
|
|
||||||
player_id: connection.player_data.actor_id,
|
|
||||||
timestamp: timestamp_secs(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let ipc = ServerZoneIpcSegment {
|
|
||||||
op_code: ServerZoneIpcType::InitializeChat,
|
|
||||||
timestamp: timestamp_secs(),
|
|
||||||
data: ServerZoneIpcData::InitializeChat {
|
|
||||||
unk: [0; 8],
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
connection
|
|
||||||
.send_segment(PacketSegment {
|
|
||||||
source_actor: connection.player_data.actor_id,
|
|
||||||
target_actor: connection.player_data.actor_id,
|
|
||||||
segment_type: SegmentType::Ipc { data: ipc },
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => panic!(
|
|
||||||
"The client is trying to initialize the wrong connection?!"
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SegmentType::Ipc { data } => {
|
SegmentType::Ipc { data } => {
|
||||||
match &data.data {
|
match &data.data {
|
||||||
|
@ -265,31 +185,16 @@ async fn main() {
|
||||||
// Send inventory
|
// Send inventory
|
||||||
connection.send_inventory().await;
|
connection.send_inventory().await;
|
||||||
|
|
||||||
// Control Data
|
// set chara gear param
|
||||||
{
|
connection
|
||||||
let ipc = ServerZoneIpcSegment {
|
.actor_control_self(ActorControlSelf {
|
||||||
op_code: ServerZoneIpcType::ActorControlSelf,
|
category:
|
||||||
timestamp: timestamp_secs(),
|
ActorControlCategory::SetCharaGearParamUI {
|
||||||
data: ServerZoneIpcData::ActorControlSelf(
|
|
||||||
ActorControlSelf {
|
|
||||||
category:
|
|
||||||
ActorControlCategory::SetCharaGearParamUI {
|
|
||||||
unk1: 1,
|
unk1: 1,
|
||||||
unk2: 1,
|
unk2: 1,
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
})
|
||||||
..Default::default()
|
.await;
|
||||||
};
|
|
||||||
|
|
||||||
connection
|
|
||||||
.send_segment(PacketSegment {
|
|
||||||
source_actor: connection.player_data.actor_id,
|
|
||||||
target_actor: connection.player_data.actor_id,
|
|
||||||
segment_type: SegmentType::Ipc { data: ipc },
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stats
|
// Stats
|
||||||
{
|
{
|
||||||
|
@ -727,62 +632,16 @@ async fn main() {
|
||||||
GameMasterCommandType::ChangeTerritory => {
|
GameMasterCommandType::ChangeTerritory => {
|
||||||
connection.change_zone(*arg as u16).await
|
connection.change_zone(*arg as u16).await
|
||||||
}
|
}
|
||||||
GameMasterCommandType::ToggleInvisibility => {
|
GameMasterCommandType::ToggleInvisibility => connection.actor_control_self(ActorControlSelf {
|
||||||
let ipc = ServerZoneIpcSegment {
|
category:
|
||||||
op_code: ServerZoneIpcType::ActorControlSelf,
|
ActorControlCategory::ToggleInvisibility {
|
||||||
timestamp: timestamp_secs(),
|
invisible: 1
|
||||||
data: ServerZoneIpcData::ActorControlSelf(
|
},
|
||||||
ActorControlSelf {
|
}).await,
|
||||||
category:
|
GameMasterCommandType::ToggleWireframe => connection.actor_control_self(ActorControlSelf {
|
||||||
ActorControlCategory::ToggleInvisibility {
|
category:
|
||||||
invisible: 1
|
ActorControlCategory::ToggleWireframeRendering() ,
|
||||||
},
|
}).await
|
||||||
},
|
|
||||||
),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
connection
|
|
||||||
.send_segment(PacketSegment {
|
|
||||||
source_actor: connection
|
|
||||||
.player_data
|
|
||||||
.actor_id,
|
|
||||||
target_actor: connection
|
|
||||||
.player_data
|
|
||||||
.actor_id,
|
|
||||||
segment_type: SegmentType::Ipc {
|
|
||||||
data: ipc,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
GameMasterCommandType::ToggleWireframe => {
|
|
||||||
let ipc = ServerZoneIpcSegment {
|
|
||||||
op_code: ServerZoneIpcType::ActorControlSelf,
|
|
||||||
timestamp: timestamp_secs(),
|
|
||||||
data: ServerZoneIpcData::ActorControlSelf(
|
|
||||||
ActorControlSelf {
|
|
||||||
category:
|
|
||||||
ActorControlCategory::ToggleWireframeRendering(),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
connection
|
|
||||||
.send_segment(PacketSegment {
|
|
||||||
source_actor: connection
|
|
||||||
.player_data
|
|
||||||
.actor_id,
|
|
||||||
target_actor: connection
|
|
||||||
.player_data
|
|
||||||
.actor_id,
|
|
||||||
segment_type: SegmentType::Ipc {
|
|
||||||
data: ipc,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClientZoneIpcData::EnterZoneLine {
|
ClientZoneIpcData::EnterZoneLine {
|
||||||
|
|
|
@ -12,9 +12,9 @@ use crate::{
|
||||||
use super::{
|
use super::{
|
||||||
Actor, Event, Inventory, Item, LuaPlayer, Zone,
|
Actor, Event, Inventory, Item, LuaPlayer, Zone,
|
||||||
ipc::{
|
ipc::{
|
||||||
ActorSetPos, ClientZoneIpcSegment, ContainerInfo, ContainerType, InitZone, ItemInfo,
|
ActorControl, ActorControlSelf, ActorSetPos, ClientZoneIpcSegment, ContainerInfo,
|
||||||
ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect, StatusEffectList, UpdateClassInfo,
|
ContainerType, InitZone, ItemInfo, ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect,
|
||||||
WeatherChange,
|
StatusEffectList, UpdateClassInfo, WeatherChange,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,6 +106,77 @@ impl ZoneConnection {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn initialize(&mut self, connection_type: &ConnectionType, actor_id: u32) {
|
||||||
|
// some still hardcoded values
|
||||||
|
self.player_data.classjob_id = 1;
|
||||||
|
self.player_data.level = 5;
|
||||||
|
self.player_data.curr_hp = 100;
|
||||||
|
self.player_data.max_hp = 100;
|
||||||
|
self.player_data.curr_mp = 10000;
|
||||||
|
self.player_data.max_mp = 10000;
|
||||||
|
|
||||||
|
// We have send THEM a keep alive
|
||||||
|
{
|
||||||
|
self.send_segment(PacketSegment {
|
||||||
|
source_actor: 0,
|
||||||
|
target_actor: 0,
|
||||||
|
segment_type: SegmentType::KeepAlive {
|
||||||
|
id: 0xE0037603u32,
|
||||||
|
timestamp: timestamp_secs(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
match connection_type {
|
||||||
|
ConnectionType::Zone => {
|
||||||
|
tracing::info!("Client {actor_id} is initializing zone session...");
|
||||||
|
|
||||||
|
self.send_segment(PacketSegment {
|
||||||
|
source_actor: 0,
|
||||||
|
target_actor: 0,
|
||||||
|
segment_type: SegmentType::ZoneInitialize {
|
||||||
|
player_id: self.player_data.actor_id,
|
||||||
|
timestamp: timestamp_secs(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
ConnectionType::Chat => {
|
||||||
|
tracing::info!("Client {actor_id} is initializing chat session...");
|
||||||
|
|
||||||
|
{
|
||||||
|
self.send_segment(PacketSegment {
|
||||||
|
source_actor: 0,
|
||||||
|
target_actor: 0,
|
||||||
|
segment_type: SegmentType::ZoneInitialize {
|
||||||
|
player_id: self.player_data.actor_id,
|
||||||
|
timestamp: timestamp_secs(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let ipc = ServerZoneIpcSegment {
|
||||||
|
op_code: ServerZoneIpcType::InitializeChat,
|
||||||
|
timestamp: timestamp_secs(),
|
||||||
|
data: ServerZoneIpcData::InitializeChat { unk: [0; 8] },
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
self.send_segment(PacketSegment {
|
||||||
|
source_actor: self.player_data.actor_id,
|
||||||
|
target_actor: self.player_data.actor_id,
|
||||||
|
segment_type: SegmentType::Ipc { data: ipc },
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => panic!("The client is trying to initialize the wrong connection?!"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn set_player_position(&mut self, position: Position) {
|
pub async fn set_player_position(&mut self, position: Position) {
|
||||||
// set pos
|
// set pos
|
||||||
{
|
{
|
||||||
|
@ -381,4 +452,20 @@ impl ZoneConnection {
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn actor_control_self(&mut self, actor_control: ActorControlSelf) {
|
||||||
|
let ipc = ServerZoneIpcSegment {
|
||||||
|
op_code: ServerZoneIpcType::ActorControlSelf,
|
||||||
|
timestamp: timestamp_secs(),
|
||||||
|
data: ServerZoneIpcData::ActorControlSelf(actor_control),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
self.send_segment(PacketSegment {
|
||||||
|
source_actor: self.player_data.actor_id,
|
||||||
|
target_actor: self.player_data.actor_id,
|
||||||
|
segment_type: SegmentType::Ipc { data: ipc },
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue