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

Document more random things, move session_id from PacketState to LobbyConnection

This commit is contained in:
Joshua Goins 2025-03-17 16:58:48 -04:00
parent 9009ae527c
commit c510d955bd
7 changed files with 42 additions and 7 deletions

View file

@ -1,5 +1,6 @@
[package]
name = "kawari"
description = "A server replacement for a certain MMO."
version = "0.1.0"
edition = "2024"

View file

@ -23,12 +23,15 @@ async fn main() {
let state = PacketState {
client_key: None,
session_id: None,
clientbound_oodle: FFXIVOodle::new(),
serverbound_oodle: FFXIVOodle::new(),
};
let mut connection = LobbyConnection { socket, state };
let mut connection = LobbyConnection {
socket,
state,
session_id: None,
};
tokio::spawn(async move {
let mut buf = [0; 2056];
@ -58,7 +61,7 @@ async fn main() {
"Client {session_id} ({version_info}) logging in!"
);
connection.state.session_id = Some(session_id.clone());
connection.session_id = Some(session_id.clone());
connection.send_account_list().await;

View file

@ -33,7 +33,6 @@ async fn main() {
let state = PacketState {
client_key: None,
session_id: None,
clientbound_oodle: FFXIVOodle::new(),
serverbound_oodle: FFXIVOodle::new(),
};

View file

@ -1,3 +1,5 @@
//! A server replacement for a certain MMO.
use common::CustomizeData;
use minijinja::Environment;
use rand::Rng;
@ -29,7 +31,7 @@ pub mod packet;
// TODO: make this configurable
/// The world ID and name for the lobby.
/// See https://ffxiv.consolegameswiki.com/wiki/Servers for a list of possible IDs.
/// See <https://ffxiv.consolegameswiki.com/wiki/Servers> for a list of possible IDs.
pub const WORLD_ID: u16 = 63;
pub const WORLD_NAME: &str = "KAWARI";

View file

@ -25,6 +25,8 @@ use crate::lobby::ipc::ClientLobbyIpcSegment;
pub struct LobbyConnection {
pub socket: TcpStream,
pub session_id: Option<String>,
pub state: PacketState,
}
@ -287,7 +289,7 @@ impl LobbyConnection {
}
pub async fn send_enter_world(&mut self, sequence: u64, lookup_id: u64) {
let Some(session_id) = &self.state.session_id else {
let Some(session_id) = &self.session_id else {
panic!("Missing session id!");
};

View file

@ -8,6 +8,28 @@ pub trait IpcSegmentTrait:
fn calc_size(&self) -> u32;
}
/// An IPC packet segment.
/// When implementing a new connection type, `OpCode` and `Data` can be used to specialize this type:
/// ```
/// # use binrw::binrw;
/// # use kawari::packet::IpcSegment;
/// #
/// # #[binrw]
/// # #[brw(repr = u16)]
/// # #[derive(Clone, PartialEq, Debug)]
/// # pub enum ClientLobbyIpcType {
/// # Dummy = 0x1,
/// # }
/// #
/// # #[binrw]
/// # #[br(import(magic: &ClientLobbyIpcType))]
/// # #[derive(Debug, Clone)]
/// # pub enum ClientLobbyIpcData {
/// # Dummy()
/// # }
/// #
/// pub type ClientLobbyIpcSegment = IpcSegment<ClientLobbyIpcType, ClientLobbyIpcData>;
/// ```
#[binrw]
#[derive(Debug, Clone)]
pub struct IpcSegment<OpCode, Data>
@ -17,12 +39,18 @@ where
for<'a> Data: BinRead<Args<'a> = (&'a OpCode,)> + 'a + std::fmt::Debug,
for<'a> Data: BinWrite<Args<'a> = ()> + 'a + std::fmt::Debug,
{
/// Unknown purpose, but usually 20.
pub unk1: u8,
/// Unknown purpose, but usually 0.
pub unk2: u8,
/// The opcode for this segment.
pub op_code: OpCode,
#[brw(pad_before = 2)] // empty
/// Unknown purpose, but safe to keep 0.
pub server_id: u16,
/// The timestamp of this packet in seconds since UNIX epoch.
pub timestamp: u32,
/// The data associated with the opcode.
#[brw(pad_before = 4)]
#[br(args(&op_code))]
pub data: Data,

View file

@ -194,9 +194,9 @@ pub async fn send_packet<T: IpcSegmentTrait>(
}
// temporary
/// State needed for each connection between the client & server, containing various things like the compressor and encryption keys.
pub struct PacketState {
pub client_key: Option<[u8; 16]>,
pub session_id: Option<String>,
pub serverbound_oodle: FFXIVOodle,
pub clientbound_oodle: FFXIVOodle,
}