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

Move chat connection initialization out of WorldConnection

I think this just causes more confusion, it's not really it's job to do
this.
This commit is contained in:
Joshua Goins 2025-05-02 00:11:37 -04:00
parent f3f25eb219
commit 54fd1b90b1
2 changed files with 80 additions and 89 deletions

View file

@ -9,11 +9,12 @@ use kawari::common::{GameData, ObjectId, timestamp_secs};
use kawari::common::{Position, determine_initial_starting_zone}; use kawari::common::{Position, determine_initial_starting_zone};
use kawari::config::get_config; use kawari::config::get_config;
use kawari::oodle::OodleNetwork; use kawari::oodle::OodleNetwork;
use kawari::opcodes::ServerZoneIpcType; use kawari::opcodes::{ServerChatIpcType, ServerZoneIpcType};
use kawari::packet::{ use kawari::packet::{
CompressionType, ConnectionType, PacketSegment, PacketState, SegmentData, SegmentType, CompressionType, ConnectionType, PacketSegment, PacketState, SegmentData, SegmentType,
send_keep_alive, send_packet, send_keep_alive, send_packet,
}; };
use kawari::world::chat::{ServerChatIpcData, ServerChatIpcSegment};
use kawari::world::ipc::{ use kawari::world::ipc::{
ActionEffect, ActionResult, ClientZoneIpcData, EffectKind, GameMasterCommandType, ActionEffect, ActionResult, ClientZoneIpcData, EffectKind, GameMasterCommandType,
GameMasterRank, OnlineStatus, ServerZoneIpcData, ServerZoneIpcSegment, SocialListRequestType, GameMasterRank, OnlineStatus, ServerZoneIpcData, ServerZoneIpcSegment, SocialListRequestType,
@ -282,15 +283,63 @@ async fn client_loop(
connection.player_data = database.find_player_data(actor_id); connection.player_data = database.find_player_data(actor_id);
} }
// collect actor data
connection.initialize(&connection_type, actor_id).await;
if connection_type == ConnectionType::Zone { if connection_type == ConnectionType::Zone {
// collect actor data
connection.initialize(actor_id).await;
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);
// tell the server we exist, now that we confirmed we are a legitimate connection // tell the server we exist, now that we confirmed we are a legitimate connection
connection.handle.send(ToServer::NewClient(client_handle.clone())).await; connection.handle.send(ToServer::NewClient(client_handle.clone())).await;
} else if connection_type == ConnectionType::Chat {
// We have send THEM a keep alive
connection.send_chat_segment(PacketSegment {
source_actor: 0,
target_actor: 0,
segment_type: SegmentType::KeepAliveRequest,
data: SegmentData::KeepAliveRequest {
id: 0xE0037603u32,
timestamp: timestamp_secs(),
},
})
.await;
// initialize connection
connection.send_chat_segment(PacketSegment {
source_actor: 0,
target_actor: 0,
segment_type: SegmentType::Initialize,
data: SegmentData::Initialize {
player_id: connection.player_data.actor_id,
timestamp: timestamp_secs(),
},
})
.await;
// we need the actor id at this point!
assert!(connection.player_data.actor_id != 0);
// send login reply
{
let ipc = ServerChatIpcSegment {
op_code: ServerChatIpcType::LoginReply,
timestamp: timestamp_secs(),
data: ServerChatIpcData::LoginReply {
timestamp: 0,
sid: 0,
},
..Default::default()
};
connection.send_chat_segment(PacketSegment {
source_actor: connection.player_data.actor_id,
target_actor: connection.player_data.actor_id,
segment_type: SegmentType::Ipc,
data: SegmentData::Ipc { data: ipc },
})
.await;
}
} }
} }
SegmentData::Ipc { data } => { SegmentData::Ipc { data } => {

View file

@ -12,16 +12,16 @@ use crate::{
OBFUSCATION_ENABLED_MODE, OBFUSCATION_ENABLED_MODE,
common::{GameData, ObjectId, Position, timestamp_secs}, common::{GameData, ObjectId, Position, timestamp_secs},
config::get_config, config::get_config,
opcodes::{ServerChatIpcType, ServerZoneIpcType}, opcodes::ServerZoneIpcType,
packet::{ packet::{
CompressionType, ConnectionType, PacketSegment, PacketState, SegmentData, SegmentType, CompressionType, ConnectionType, PacketSegment, PacketState, SegmentData, SegmentType,
parse_packet, send_packet, parse_packet, send_packet,
}, },
world::chat::{ServerChatIpcData, ServerChatIpcSegment},
}; };
use super::{ use super::{
Actor, CharacterData, Event, Inventory, Item, LuaPlayer, StatusEffects, WorldDatabase, Zone, Actor, CharacterData, Event, Inventory, Item, LuaPlayer, StatusEffects, WorldDatabase, Zone,
chat::ServerChatIpcSegment,
inventory::Container, inventory::Container,
ipc::{ ipc::{
ActorControlSelf, ActorMove, ActorSetPos, ClientZoneIpcSegment, CommonSpawn, ContainerInfo, ActorControlSelf, ActorMove, ActorSetPos, ClientZoneIpcSegment, CommonSpawn, ContainerInfo,
@ -181,7 +181,7 @@ impl ZoneConnection {
.await; .await;
} }
pub async fn initialize(&mut self, connection_type: &ConnectionType, actor_id: u32) { pub async fn initialize(&mut self, actor_id: u32) {
// some still hardcoded values // some still hardcoded values
self.player_data.classjob_id = 1; self.player_data.classjob_id = 1;
self.player_data.level = 5; self.player_data.level = 5;
@ -190,8 +190,6 @@ impl ZoneConnection {
self.player_data.curr_mp = 10000; self.player_data.curr_mp = 10000;
self.player_data.max_mp = 10000; self.player_data.max_mp = 10000;
match connection_type {
ConnectionType::Zone => {
tracing::info!("Client {actor_id} is initializing zone session..."); tracing::info!("Client {actor_id} is initializing zone session...");
// We have send THEM a keep alive // We have send THEM a keep alive
@ -219,62 +217,6 @@ impl ZoneConnection {
}) })
.await; .await;
} }
ConnectionType::Chat => {
tracing::info!("Client {actor_id} is initializing chat session...");
// We have send THEM a keep alive
{
self.send_chat_segment(PacketSegment {
source_actor: 0,
target_actor: 0,
segment_type: SegmentType::KeepAliveRequest,
data: SegmentData::KeepAliveRequest {
id: 0xE0037603u32,
timestamp: timestamp_secs(),
},
})
.await;
}
{
self.send_chat_segment(PacketSegment {
source_actor: 0,
target_actor: 0,
segment_type: SegmentType::Initialize,
data: SegmentData::Initialize {
player_id: self.player_data.actor_id,
timestamp: timestamp_secs(),
},
})
.await;
}
// we need the actor id at this point!
assert!(self.player_data.actor_id != 0);
{
let ipc = ServerChatIpcSegment {
op_code: ServerChatIpcType::LoginReply,
timestamp: timestamp_secs(),
data: ServerChatIpcData::LoginReply {
timestamp: 0,
sid: 0,
},
..Default::default()
};
self.send_chat_segment(PacketSegment {
source_actor: self.player_data.actor_id,
target_actor: self.player_data.actor_id,
segment_type: SegmentType::Ipc,
data: SegmentData::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