mirror of
https://github.com/lcdr/lu_packets.git
synced 2026-05-02 16:09:24 -05:00
Add documentation for a few packets
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
//! Auth messages.
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
//! Chat messages.
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Shared types.
|
||||
mod str;
|
||||
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
@@ -9,6 +10,11 @@ use endio::{Deserialize, LE, LERead, LEWrite, Serialize};
|
||||
|
||||
pub use self::str::*;
|
||||
|
||||
/**
|
||||
Wraps a `Vec` with a length type so the vector can be (de-)serialized.
|
||||
|
||||
Note: the length type is not checked and the `Vec` still uses `usize` internally. Handle with care.
|
||||
*/
|
||||
#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct LVec<T, L>(Vec<T>, PhantomData<L>);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Client-received general messages.
|
||||
use endio::{Deserialize, Serialize};
|
||||
use lu_packets_derive::VariantTests;
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
//! General messages.
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Server-received general messages.
|
||||
use endio::{Deserialize, Serialize};
|
||||
use lu_packets_derive::VariantTests;
|
||||
|
||||
@@ -10,13 +11,35 @@ pub enum GeneralMessage {
|
||||
Handshake(Handshake)
|
||||
}
|
||||
|
||||
/**
|
||||
Client network version info.
|
||||
|
||||
### Purpose
|
||||
Providing the client's network version to identify outdated clients and disconnect them early.
|
||||
|
||||
### Trigger
|
||||
Establishment of raknet connection (receipt of [`ConnectionRequestAccepted`](crate::raknet::client::ConnectionRequestAccepted)).
|
||||
|
||||
### Handling
|
||||
Check if [`network_version`](Handshake::network_version) matches the version you expect. Otherwise, disconnect the client, ideally with a [`DisconnectNotify::InvalidGameVersion`](super::client::DisconnectNotify::WrongGameVersion) specifying the expected version.
|
||||
|
||||
### Response
|
||||
Respond with a server-sent [`Handshake`](super::client::Handshake) providing the server's network version and service ID.
|
||||
|
||||
### Notes
|
||||
This packet should not be seen as proof that the client's network version is actually what they report it to be. The client can provide any value, and malicious clients can deviate from the protocol in any way they like. Therefore, proper length and value checking is still required for packet parsing, and care should be taken that your server does not crash on invalid input. If you're using the parsing functionality of this library, this will be taken care of for you.
|
||||
*/
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[trailing_padding=33]
|
||||
pub struct Handshake {
|
||||
/// The network protocol version of the client. For unmodified live clients, this is `171022`. This was relevant mainly back when LU was actively updated. If you intend to make modifications to the protocol for your server project, you should change this to a different value.
|
||||
pub network_version: u32,
|
||||
#[padding=4]
|
||||
/// Service ID of the client, always [`ServiceId::Client`]. LU used this packet for all service communications, including server-to-server, which is the reason it's necessary to specify this.
|
||||
pub service_id: ServiceId,
|
||||
#[padding=2]
|
||||
/// Process ID of the client.
|
||||
pub process_id: u32,
|
||||
/// Local port of the client, not necessarily the same as the one the connection is from in case of NAT.
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
+39
-2
@@ -1,17 +1,54 @@
|
||||
/*!
|
||||
Documentation and (de-)serialization support for LU's network protocol.
|
||||
*/
|
||||
#![feature(arbitrary_enum_discriminant)]
|
||||
|
||||
/**
|
||||
Creates a [`LuNameValue`] containing the arguments.
|
||||
|
||||
The syntax is `name: value`, where `name` is a string literal that will be converted to a [`LuVarWString<u32>`], and `value` is an expression that will be converted to an [`LnvValue`].
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
lnv! {
|
||||
"wstring": "string expression",
|
||||
"i32": 42i32,
|
||||
"f32": 3.14f32,
|
||||
"f64": 3.14f64,
|
||||
"u32": 42u32,
|
||||
"bool": true,
|
||||
"i64": i64::MAX,
|
||||
"u64": u64::MAX,
|
||||
"string": b"byte slice"[..],
|
||||
}
|
||||
```
|
||||
|
||||
Care should be taken with integer and float literals to suffix them with the correct type, as seen above. Rust assumes `i32` for integer and `f64` for float literals by default, which may not be what you want, and can lead to incorrect serialization.
|
||||
|
||||
[`LuNameValue`]: crate::world::lnv::LuNameValue
|
||||
[`LuVarWString<u32>`]: crate::common::str::variable::LuVarWString
|
||||
[`LnvValue`]: crate::world::lnv::LnvValue
|
||||
*/
|
||||
#[macro_export]
|
||||
macro_rules! lnv {
|
||||
{} => { crate::world::lnv::LuNameValue::new() };
|
||||
{$($name:literal:$val:expr,)*} => {
|
||||
{$($name:literal:$value:expr,)*} => {
|
||||
{
|
||||
let mut lnv = crate::world::lnv::LuNameValue::new();
|
||||
$(lnv.insert(::std::convert::TryInto::try_into($name).unwrap(), $val.into());)*
|
||||
$(lnv.insert(::std::convert::TryInto::try_into($name).unwrap(), $value.into());)*
|
||||
lnv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Converts the argument to a LU string.
|
||||
|
||||
This forwards to the [`TryInto`] implementation on the argument, which means the macro is flexible and works with both string and wstring types, and both fixed and variable types, depending on context. Generally, to convert to a string type, pass a byte slice, and for a wstring type, pass a `&str` or `String`.
|
||||
|
||||
[`TryInto`]: std::convert::TryInto
|
||||
*/
|
||||
#[macro_export]
|
||||
macro_rules! lu {
|
||||
($str_lit:expr) => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Raknet messages.
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ pub(super) trait GmParam: Sized {
|
||||
fn serialize<W: Write>(&self, writer: &mut W) -> Res<()>;
|
||||
}
|
||||
|
||||
/// Implements `GmParam` by forwarding to `Deserialize` and `Serialize`.
|
||||
#[macro_export]
|
||||
macro_rules! gm_param {
|
||||
($typ:ty) => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! World messages.
|
||||
pub mod client;
|
||||
pub mod gm;
|
||||
pub mod lnv;
|
||||
|
||||
@@ -40,10 +40,35 @@ pub enum WorldMessage {
|
||||
UgcDownloadFailed(UgcDownloadFailed) = 120,
|
||||
}
|
||||
|
||||
/**
|
||||
Client session info.
|
||||
|
||||
### Purpose
|
||||
Providing session info for authentication.
|
||||
|
||||
### Trigger
|
||||
[Server handshake](crate::general::client::Handshake).
|
||||
|
||||
### Handling
|
||||
Verify with your auth server that the `(username, session_key)` combination is valid. If not, immediately disconnect the client, ideally with a [`DisconnectNotify::InvalidSessionKey`](crate::general::client::DisconnectNotify::InvalidSessionKey).
|
||||
|
||||
If you are concerned about players modding their client DB, also check the `fdb_checksum`. Note that players can still change their client to send a fake checksum, but this requires exe modding, which most players are presumably not familiar with.
|
||||
|
||||
If all validation checks pass, store the connection -> username association, as this is the only packet that references the username.
|
||||
|
||||
### Response
|
||||
The client does not require a fixed response to this packet. However, world servers (with the exception of a dedicated char server) will usually want to respond to this with [`LoadStaticZone`](super::client::LoadStaticZone).
|
||||
|
||||
### Notes
|
||||
**Important**: Do **not** handle any other packets from clients that have not yet been validated. Handling other packets before validation can lead to errors because the connection has not yet been associated with a username, and can lead to security vulnerabilities if session keys are not validated properly.
|
||||
*/
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ClientValidation {
|
||||
/// Account username.
|
||||
pub username: LuWString33,
|
||||
/// [Session key from auth's login response](crate::auth::client::LoginResponse::Ok::session_key).
|
||||
pub session_key: LuWString33,
|
||||
/// MD5 hash of null-terminated cdclient.fdb file contents.
|
||||
pub fdb_checksum: [u8; 32],
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user