xash3d-master/protocol/src/lib.rs

63 lines
1.6 KiB
Rust
Raw Normal View History

// SPDX-License-Identifier: LGPL-3.0-only
2023-10-17 07:21:52 +00:00
// SPDX-FileCopyrightText: 2023 Denis Drakhnia <numas13@gmail.com>
2024-01-28 11:01:43 +00:00
#![deny(unsafe_code)]
#![deny(missing_docs)]
//! Xash3D protocol between clients, servers and masters.
#[macro_use]
extern crate log;
2023-10-17 07:21:52 +00:00
mod cursor;
mod server_info;
pub mod admin;
2023-10-19 14:38:39 +00:00
pub mod color;
2023-10-17 07:21:52 +00:00
pub mod filter;
pub mod game;
pub mod master;
pub mod server;
pub mod wrappers;
2023-10-17 07:21:52 +00:00
pub use cursor::Error as CursorError;
2023-10-17 07:21:52 +00:00
pub use server_info::ServerInfo;
use thiserror::Error;
2023-10-19 14:38:39 +00:00
use crate::filter::Version;
/// Current protocol version.
2023-10-19 14:38:39 +00:00
pub const PROTOCOL_VERSION: u8 = 49;
/// Current client version.
2023-10-19 14:38:39 +00:00
pub const CLIENT_VERSION: Version = Version::new(0, 20);
2023-10-17 07:21:52 +00:00
/// The error type for decoding and encoding packets.
2023-10-17 07:21:52 +00:00
#[derive(Error, Debug, PartialEq, Eq)]
pub enum Error {
/// Failed to decode a packet.
2023-10-17 07:21:52 +00:00
#[error("Invalid packet")]
InvalidPacket,
/// Invalid region.
#[error("Invalid region")]
InvalidRegion,
/// Invalid client announce IP.
#[error("Invalid client announce IP")]
InvalidClientAnnounceIp,
/// Invalid last IP.
#[error("Invalid last server IP")]
InvalidQueryServersLast,
/// Server protocol version is not supported.
2023-10-19 07:54:06 +00:00
#[error("Invalid protocol version")]
InvalidProtocolVersion,
/// Cursor error.
#[error("{0}")]
CursorError(#[from] CursorError),
/// Invalid value for server add packet.
#[error("Invalid value for server add key `{0}`: {1}")]
InvalidServerValue(&'static str, #[source] CursorError),
/// Invalid value for query servers packet.
#[error("Invalid value for filter key `{0}`: {1}")]
InvalidFilterValue(&'static str, #[source] CursorError),
2023-10-17 07:21:52 +00:00
}