diff options
45 files changed, 214 insertions, 496 deletions
@@ -2,5 +2,4 @@ /export/dev/ /documents/cargo_doc/ -/.cargo/scripts/nogamepads-console/Microsoft.DesktopAppInstaller.msixbundle /nogamepads.yaml diff --git a/.idea/runConfigurations/Generate_Documents.xml b/.idea/runConfigurations/Generate_Documents.xml index 6e70949..3d70073 100644 --- a/.idea/runConfigurations/Generate_Documents.xml +++ b/.idea/runConfigurations/Generate_Documents.xml @@ -1,6 +1,6 @@ <component name="ProjectRunConfigurationManager"> <configuration default="false" name="Generate Documents" type="CargoCommandRunConfiguration" factoryName="Cargo Command" folderName="Document"> - <option name="command" value="doc --workspace" /> + <option name="command" value="doc --workspace --no-deps" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" /> <envs /> <option name="emulateTerminal" value="true" /> diff --git a/.obsidian/app.json b/.obsidian/app.json deleted file mode 100644 index 9e26dfe..0000000 --- a/.obsidian/app.json +++ /dev/null @@ -1 +0,0 @@ -{}
\ No newline at end of file diff --git a/.obsidian/appearance.json b/.obsidian/appearance.json deleted file mode 100644 index 9e26dfe..0000000 --- a/.obsidian/appearance.json +++ /dev/null @@ -1 +0,0 @@ -{}
\ No newline at end of file diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json deleted file mode 100644 index b977c25..0000000 --- a/.obsidian/core-plugins.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "file-explorer": true, - "global-search": true, - "switcher": true, - "graph": true, - "backlink": true, - "canvas": true, - "outgoing-link": true, - "tag-pane": true, - "properties": false, - "page-preview": true, - "daily-notes": true, - "templates": true, - "note-composer": true, - "command-palette": true, - "slash-command": false, - "editor-status": true, - "bookmarks": true, - "markdown-importer": false, - "zk-prefixer": false, - "random-note": false, - "outline": true, - "word-count": true, - "slides": false, - "audio-recorder": false, - "workspaces": false, - "file-recovery": true, - "publish": false, - "sync": true, - "webviewer": false -}
\ No newline at end of file diff --git a/.obsidian/graph.json b/.obsidian/graph.json deleted file mode 100644 index 42a46ec..0000000 --- a/.obsidian/graph.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "collapse-filter": true, - "search": "", - "showTags": false, - "showAttachments": false, - "hideUnresolved": false, - "showOrphans": true, - "collapse-color-groups": true, - "colorGroups": [], - "collapse-display": true, - "showArrow": false, - "textFadeMultiplier": 0, - "nodeSizeMultiplier": 1, - "lineSizeMultiplier": 1, - "collapse-forces": true, - "centerStrength": 0.518713248970312, - "repelStrength": 10, - "linkStrength": 1, - "linkDistance": 250, - "scale": 1, - "close": true -}
\ No newline at end of file diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json deleted file mode 100644 index 0016205..0000000 --- a/.obsidian/workspace.json +++ /dev/null @@ -1,191 +0,0 @@ -{ - "main": { - "id": "a0056f92bdc64f6d", - "type": "split", - "children": [ - { - "id": "fc3609b0f0318eda", - "type": "tabs", - "children": [ - { - "id": "1e9c5e9fbcfb0e16", - "type": "leaf", - "state": { - "type": "markdown", - "state": { - "file": "README.md", - "mode": "source", - "source": false - }, - "icon": "lucide-file", - "title": "README" - } - } - ] - } - ], - "direction": "vertical" - }, - "left": { - "id": "6cde324fca0fc667", - "type": "split", - "children": [ - { - "id": "64265198a9ce5aac", - "type": "tabs", - "children": [ - { - "id": "70c5b38cff9cdddc", - "type": "leaf", - "state": { - "type": "file-explorer", - "state": { - "sortOrder": "alphabetical", - "autoReveal": false - }, - "icon": "lucide-folder-closed", - "title": "文件列表" - } - }, - { - "id": "04a128176f90e83a", - "type": "leaf", - "state": { - "type": "search", - "state": { - "query": "", - "matchingCase": false, - "explainSearch": false, - "collapseAll": false, - "extraContext": false, - "sortOrder": "alphabetical" - }, - "icon": "lucide-search", - "title": "搜索" - } - }, - { - "id": "44e2df1962ca7851", - "type": "leaf", - "state": { - "type": "bookmarks", - "state": {}, - "icon": "lucide-bookmark", - "title": "书签" - } - } - ] - } - ], - "direction": "horizontal", - "width": 300 - }, - "right": { - "id": "3824e4164ed4d9df", - "type": "split", - "children": [ - { - "id": "8a18ce67d19fb459", - "type": "tabs", - "children": [ - { - "id": "0c0d507eb8ea7b53", - "type": "leaf", - "state": { - "type": "backlink", - "state": { - "file": "未命名.md", - "collapseAll": false, - "extraContext": false, - "sortOrder": "alphabetical", - "showSearch": false, - "searchQuery": "", - "backlinkCollapsed": false, - "unlinkedCollapsed": true - }, - "icon": "links-coming-in", - "title": "未命名 的反向链接列表" - } - }, - { - "id": "f9bf37aeee2cb12b", - "type": "leaf", - "state": { - "type": "outgoing-link", - "state": { - "file": "未命名.md", - "linksCollapsed": false, - "unlinkedCollapsed": true - }, - "icon": "links-going-out", - "title": "未命名 的出链列表" - } - }, - { - "id": "5bed5e8aaf8b9996", - "type": "leaf", - "state": { - "type": "tag", - "state": { - "sortOrder": "frequency", - "useHierarchy": true, - "showSearch": false, - "searchQuery": "" - }, - "icon": "lucide-tags", - "title": "标签" - } - }, - { - "id": "9ccacef0149d1612", - "type": "leaf", - "state": { - "type": "outline", - "state": { - "file": "未命名.md", - "followCursor": false, - "showSearch": false, - "searchQuery": "" - }, - "icon": "lucide-list", - "title": "未命名 的大纲" - } - } - ] - } - ], - "direction": "horizontal", - "width": 300, - "collapsed": true - }, - "left-ribbon": { - "hiddenItems": { - "switcher:打开快速切换": false, - "graph:查看关系图谱": false, - "canvas:新建白板": false, - "daily-notes:打开/创建今天的日记": false, - "templates:插入模板": false, - "command-palette:打开命令面板": false - } - }, - "active": "1e9c5e9fbcfb0e16", - "lastOpenFiles": [ - "core/src/service/tcp_network/duplex.rs~", - "core/src/service/tcp_network/server.rs~", - "core/src/service/tcp_network/mod.rs~", - "core/src/service/tcp_network/duplex.rs", - "core/src/service/tcp_network/long_connection.rs", - "core/src/data/player/structs.rs~", - "core/src/service/tcp_network/client.rs~", - "src/macros.rs~", - "core/src/data/game/runtime/implements.rs~", - "core/src/data/player/implements.rs~", - "core/src/data/message/enums.rs~", - "core/core.canvas", - "README.md", - "documents/临时/About Toolchain - 关于 Rust 工具链.md", - "documents/临时/路线.md", - "未命名.md", - "欢迎.md" - ] -}
\ No newline at end of file diff --git a/client/src/plugin_client.rs b/client/src/plugin_client.rs index 481f52a..d998f75 100644 --- a/client/src/plugin_client.rs +++ b/client/src/plugin_client.rs @@ -4,10 +4,10 @@ use bevy::log::info; use bevy::prelude::{App, Commands, Component, IntoScheduleConfigs, KeyCode, Plugin, PreStartup, Query, ResMut, Startup, Update}; use bevy_tokio_tasks::TokioTasksRuntime; use nogamepads::entry_mutex; -use nogamepads_core::data::controller::runtime::structs::ControllerRuntime; -use nogamepads_core::data::controller::structs::ControllerData; -use nogamepads_core::data::player::structs::Player; -use nogamepads_core::service::tcp_network::pad_client::structs::PadClientNetwork; +use nogamepads_core::data::controller::controller_data::ControllerData; +use nogamepads_core::data::controller::controller_runtime::ControllerRuntime; +use nogamepads_core::data::player::player_data::Player; +use nogamepads_core::service::tcp_network::pad_client::pad_client_service::PadClientNetwork; #[derive(Component)] struct ClientComponent { diff --git a/console/src/bin/padc.rs b/console/src/bin/padc.rs index a60559f..e6bab4d 100644 --- a/console/src/bin/padc.rs +++ b/console/src/bin/padc.rs @@ -1,8 +1,6 @@ use clap::{Args, ColorChoice, CommandFactory, Parser, Subcommand}; use nogamepads::string_utils::process_id_text; use nogamepads_console::utils::{confirm, read_password, read_password_and_confirm}; -use nogamepads_core::data::game::structs::{GameData, GameRuntimeDataArchive}; -use nogamepads_core::data::player::structs::Player; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::env::current_dir; @@ -23,14 +21,16 @@ use tokio::signal::ctrl_c; use tokio::time::sleep; use nogamepads::entry_mutex; use nogamepads::logger_utils::logger_build; -use nogamepads_core::data::controller::cli::cli_command::{process_controller_cli, ControllerCli}; -use nogamepads_core::data::controller::structs::ControllerData; -use nogamepads_core::data::game::cli::cli_command::{process_game_cli, GameCli}; +use nogamepads_core::data::controller::controller_cli::{process_controller_cli, ControllerCli}; +use nogamepads_core::data::controller::controller_data::ControllerData; +use nogamepads_core::data::game::game_cli::{process_game_cli, GameCli}; +use nogamepads_core::data::game::game_data::{GameData, GameRuntimeDataArchive}; +use nogamepads_core::data::player::player_data::Player; use nogamepads_core::service::cli_addition::runtime_consoles::RuntimeConsole; use nogamepads_core::service::service_runner::{NoGamepadsService, ServiceRunner}; use nogamepads_core::service::tcp_network::DEFAULT_PORT; -use nogamepads_core::service::tcp_network::pad_client::structs::PadClientNetwork; -use nogamepads_core::service::tcp_network::pad_server::structs::PadServerNetwork; +use nogamepads_core::service::tcp_network::pad_client::pad_client_service::PadClientNetwork; +use nogamepads_core::service::tcp_network::pad_server::pad_server_service::PadServerNetwork; use nogamepads_core::service::tcp_network::utils::tokio_utils::build_tokio_runtime; #[derive(Parser, Debug)] diff --git a/core/Cargo.toml b/core/Cargo.toml index 6758217..9b9d42c 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -13,8 +13,4 @@ serde = { version = "1.0.219", features = ["derive"] } clap = { version = "4.5.38", features = ["derive"] } sha1 = "0.10.6" log = "0.4.27" -shell-words = "1.1.0" - -[lib] -name = "nogamepads_core" -crate-type = [ "rlib"]
\ No newline at end of file +shell-words = "1.1.0"
\ No newline at end of file diff --git a/core/examples/connect.rs b/core/examples/connect.rs index 1fd9bca..e6f70c4 100644 --- a/core/examples/connect.rs +++ b/core/examples/connect.rs @@ -22,7 +22,6 @@ fn main () { let runtime = controller.runtime(); let client = PadClientNetwork::build(Arc::clone(&runtime)); - // client.connect(); - // or + build_tokio_runtime("Tokio Runtime".to_string()).block_on(client.build_entry()) }
\ No newline at end of file diff --git a/core/examples/tcp_server.rs b/core/examples/tcp_server.rs index 9dce538..87e63c8 100644 --- a/core/examples/tcp_server.rs +++ b/core/examples/tcp_server.rs @@ -1,6 +1,6 @@ use clap::CommandFactory; use nogamepads::logger_utils::logger_build; -use nogamepads_core::data::game::cli::cli_command::{process_game_cli, GameCli}; +use nogamepads_core::data::game::game_cli::{process_game_cli, GameCli}; use nogamepads_core::data::game::structs::{GameData, GameRuntimeDataArchive}; use nogamepads_core::run_services; use nogamepads_core::service::cli_addition::runtime_consoles::RuntimeConsole; diff --git a/core/src/data/controller/cli/mod.rs b/core/src/data/controller/cli/mod.rs deleted file mode 100644 index 043f7b8..0000000 --- a/core/src/data/controller/cli/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod cli_command;
\ No newline at end of file diff --git a/core/src/data/controller/cli/cli_command.rs b/core/src/data/controller/controller_cli.rs index 9fee0b0..9ab49d6 100644 --- a/core/src/data/controller/cli/cli_command.rs +++ b/core/src/data/controller/controller_cli.rs @@ -3,7 +3,7 @@ use clap::{Args, Parser, Subcommand}; use clearscreen::clear; use log::info; use nogamepads::entry_mutex; -use crate::data::controller::runtime::structs::ControllerRuntime; +use crate::data::controller::controller_runtime::ControllerRuntime; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] diff --git a/core/src/data/controller/implements.rs b/core/src/data/controller/controller_data.rs index 86a19de..a3f1c02 100644 --- a/core/src/data/controller/implements.rs +++ b/core/src/data/controller/controller_data.rs @@ -1,7 +1,15 @@ use std::sync::{Arc, Mutex}; -use crate::data::controller::runtime::structs::ControllerRuntime; -use crate::data::controller::structs::ControllerData; -use crate::data::player::structs::Player; +use crate::data::controller::controller_runtime::ControllerRuntime; +use crate::data::player::player_data::Player; + +/// Controller-side Data +/// Describes the basic information of the controller side +#[derive(Default)] +pub struct ControllerData { + + /// Player bound to the controller side + pub(crate) player: Player +} impl ControllerData { diff --git a/core/src/data/controller/runtime/implements.rs b/core/src/data/controller/controller_runtime.rs index 1f2734a..5e7bb6d 100644 --- a/core/src/data/controller/runtime/implements.rs +++ b/core/src/data/controller/controller_runtime.rs @@ -1,11 +1,28 @@ use std::collections::{HashMap, VecDeque}; +use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::SeqCst; use log::trace; -use crate::data::controller::runtime::structs::ControllerRuntime; -use crate::data::message::enums::{ControlMessage, GameMessage}; +use crate::data::game::types::GameInfo; +use crate::data::message::message_enums::{ControlMessage, GameMessage}; use crate::data::message::traits::MessageManager; +use crate::data::player::player_data::Player; use crate::service::service_types::ServiceType; +/// Controller-side runtime +/// Stores all data involved in game pad_client interactions during runtime +#[derive(Default)] +pub struct ControllerRuntime { + + pub(crate) service_type: ServiceType, + pub(crate) received: HashMap<(ServiceType, u8), VecDeque<GameMessage>>, + pub(crate) send: HashMap<(ServiceType, u8), VecDeque<ControlMessage>>, + + pub(crate) player: Player, + + pub game_info: GameInfo, + pub close: AtomicBool, +} + /// Message manager for controller-side runtime /// After the service starts, it can be accessed or relevant messages can be stored. impl MessageManager<GameMessage, ControlMessage, u8> for ControllerRuntime { diff --git a/core/src/data/controller/mod.rs b/core/src/data/controller/mod.rs index 019ebcf..ce9d9c3 100644 --- a/core/src/data/controller/mod.rs +++ b/core/src/data/controller/mod.rs @@ -1,4 +1,3 @@ -pub mod cli; -pub mod runtime; -pub mod implements; -pub mod structs;
\ No newline at end of file +pub mod controller_cli; +pub mod controller_runtime; +pub mod controller_data;
\ No newline at end of file diff --git a/core/src/data/controller/runtime/mod.rs b/core/src/data/controller/runtime/mod.rs deleted file mode 100644 index 0ff870f..0000000 --- a/core/src/data/controller/runtime/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod implements; -pub mod structs;
\ No newline at end of file diff --git a/core/src/data/controller/runtime/structs.rs b/core/src/data/controller/runtime/structs.rs deleted file mode 100644 index bfd39c5..0000000 --- a/core/src/data/controller/runtime/structs.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::collections::{HashMap, VecDeque}; -use std::sync::atomic::AtomicBool; -use crate::data::game::types::GameInfo; -use crate::data::message::enums::{ControlMessage, GameMessage}; -use crate::data::player::structs::Player; -use crate::service::service_types::ServiceType; - -/// Controller-side runtime -/// Stores all data involved in game pad_client interactions during runtime -#[derive(Default)] -pub struct ControllerRuntime { - - pub(crate) service_type: ServiceType, - pub(crate) received: HashMap<(ServiceType, u8), VecDeque<GameMessage>>, - pub(crate) send: HashMap<(ServiceType, u8), VecDeque<ControlMessage>>, - - pub(crate) player: Player, - - pub game_info: GameInfo, - pub close: AtomicBool, -}
\ No newline at end of file diff --git a/core/src/data/controller/structs.rs b/core/src/data/controller/structs.rs deleted file mode 100644 index c6fdd31..0000000 --- a/core/src/data/controller/structs.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::data::player::structs::Player; - -/// Controller-side Data -/// Describes the basic information of the controller side -#[derive(Default)] -pub struct ControllerData { - - /// Player bound to the controller side - pub(crate) player: Player -}
\ No newline at end of file diff --git a/core/src/data/game/cli/mod.rs b/core/src/data/game/cli/mod.rs deleted file mode 100644 index 043f7b8..0000000 --- a/core/src/data/game/cli/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod cli_command;
\ No newline at end of file diff --git a/core/src/data/game/cli/cli_command.rs b/core/src/data/game/game_cli.rs index 5f296f8..521de3f 100644 --- a/core/src/data/game/cli/cli_command.rs +++ b/core/src/data/game/game_cli.rs @@ -3,8 +3,8 @@ use clap::{Args, Parser, Subcommand}; use clearscreen::clear; use log::{info, warn}; use nogamepads::entry_mutex; -use crate::data::game::runtime::structs::GameRuntime; -use crate::data::player::structs::Player; +use crate::data::game::game_runtime::GameRuntime; +use crate::data::player::player_data::Player; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] diff --git a/core/src/data/game/implements.rs b/core/src/data/game/game_data.rs index ad86572..3bdf28b 100644 --- a/core/src/data/game/implements.rs +++ b/core/src/data/game/game_data.rs @@ -1,9 +1,35 @@ +use std::collections::HashMap; use std::sync::{Arc, Mutex}; +use serde::{Deserialize, Serialize}; use nogamepads::entry_mutex; -use crate::data::game::runtime::structs::{GameControlRuntime, GameRuntime, GameRuntimeData}; -use crate::data::game::structs::{GameControlData, GameData, GameRuntimeDataArchive}; +use crate::data::game::game_runtime::{GameControlRuntime, GameRuntime, GameRuntimeData}; use crate::data::game::types::{GameInfo, Players}; -use crate::data::player::structs::Player; +use crate::data::player::player_data::{Account, Player}; + +/// Game pad_client data +/// Describes the basic information of the game pad_client +#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)] +pub struct GameData { + pub info: GameInfo, + pub control: GameControlData, + pub archive: GameRuntimeDataArchive +} + +/// Game control information +/// Describes the buttons, axes, and directions that can be controlled. +#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)] +pub struct GameControlData { + pub direction_keys : HashMap<u8, String>, + pub axis_keys : HashMap<u8, String>, + pub button_keys : HashMap<u8, String>, +} + +/// Archive of game runtime data +/// The game pad_client can convert data into this structure for persistence. +#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)] +pub struct GameRuntimeDataArchive { + pub banned: Vec<Account> +} impl Default for GameData { fn default() -> Self { diff --git a/core/src/data/game/runtime/implements.rs b/core/src/data/game/game_runtime.rs index 22b6a5d..1c5a548 100644 --- a/core/src/data/game/runtime/implements.rs +++ b/core/src/data/game/game_runtime.rs @@ -1,20 +1,55 @@ use std::collections::{HashMap, VecDeque}; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::SeqCst; +use std::sync::Mutex; use log::{info, trace, warn}; use nogamepads::entry_mutex; -use crate::data::game::runtime::structs::{GameControlRuntime, GameRuntime, GameRuntimeData}; -use crate::data::game::types::Players; -use crate::data::message::enums::{JoinFailedMessage, ControlMessage, ExitReason, GameMessage}; -use crate::data::message::enums::JoinFailedMessage::{ContainIdenticalPlayer, GameLocked, PlayerBanned}; -use crate::data::message::enums::ControlMessage::{Axis, Dir, Msg, Pressed, Released}; -use crate::data::message::enums::ExitReason::{YouAreBanned, YouAreKicked}; -use crate::data::message::enums::GameMessage::{EventTrigger, LetExit}; +use crate::data::game::game_data::GameControlData; +use crate::data::game::types::{GameInfo, Players}; +use crate::data::message::message_enums::{JoinFailedMessage, ControlMessage, ExitReason, GameMessage}; +use crate::data::message::message_enums::JoinFailedMessage::{ContainIdenticalPlayer, GameLocked, PlayerBanned}; +use crate::data::message::message_enums::ControlMessage::{Axis, Dir, Msg, Pressed, Released}; +use crate::data::message::message_enums::ExitReason::{YouAreBanned, YouAreKicked}; +use crate::data::message::message_enums::GameMessage::{EventTrigger, LetExit}; use crate::data::message::traits::MessageManager; -use crate::data::player::structs::{Account, Player}; +use crate::data::player::player_data::{Account, Player}; use crate::service::service_types::ServiceType; use crate::service::service_types::ServiceType::TCPConnection; +/// Game pad_client runtime +/// Stores the game state, player information, and all data involved in controller-side interactions during runtime +pub struct GameRuntime { + + pub info: GameInfo, + pub data: GameRuntimeData, + pub control: GameControlRuntime, + + pub writer_count: i32, + pub reader_count: i32, +} + +pub struct GameRuntimeData { + + pub(crate) received: HashMap<(ServiceType, Account), VecDeque<(Account, ControlMessage)>>, + pub(crate) send: HashMap<(ServiceType, Account), VecDeque<(Account, GameMessage)>>, + + pub(crate) players_online: Players, + pub(crate) players_banned: Players, + pub(crate) account_service_type: Mutex<HashMap<Account, ServiceType>>, + + pub locked: AtomicBool, + pub close: AtomicBool, +} + +#[derive(Default)] +pub struct GameControlRuntime { + pub(crate) keys: GameControlData, + pub(crate) directions : HashMap<u8, HashMap<Account, (f64, f64)>>, + pub(crate) axes : HashMap<u8, HashMap<Account, f64>>, + pub(crate) button : HashMap<u8, HashMap<Account, bool>>, + pub(crate) events : VecDeque<(Account, ControlMessage)> +} + impl GameRuntime { /// Attempt to have the specified player join the game diff --git a/core/src/data/game/mod.rs b/core/src/data/game/mod.rs index 4a0a3d4..1a31cf1 100644 --- a/core/src/data/game/mod.rs +++ b/core/src/data/game/mod.rs @@ -1,6 +1,5 @@ -pub mod cli; -pub mod runtime; +pub mod game_cli; -pub mod implements; -pub mod structs; +pub mod game_data; +pub mod game_runtime; pub mod types;
\ No newline at end of file diff --git a/core/src/data/game/runtime/mod.rs b/core/src/data/game/runtime/mod.rs deleted file mode 100644 index 0ff870f..0000000 --- a/core/src/data/game/runtime/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod implements; -pub mod structs;
\ No newline at end of file diff --git a/core/src/data/game/runtime/structs.rs b/core/src/data/game/runtime/structs.rs deleted file mode 100644 index c6e005f..0000000 --- a/core/src/data/game/runtime/structs.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::collections::{HashMap, VecDeque}; -use std::sync::atomic::AtomicBool; -use std::sync::Mutex; -use crate::data::game::structs::GameControlData; -use crate::data::game::types::{GameInfo, Players}; -use crate::data::message::enums::{ControlMessage, GameMessage}; -use crate::data::player::structs::Account; -use crate::service::service_types::ServiceType; - -/// Game pad_client runtime -/// Stores the game state, player information, and all data involved in controller-side interactions during runtime -pub struct GameRuntime { - - pub info: GameInfo, - pub data: GameRuntimeData, - pub control: GameControlRuntime, - - pub writer_count: i32, - pub reader_count: i32, -} - -pub struct GameRuntimeData { - - pub(crate) received: HashMap<(ServiceType, Account), VecDeque<(Account, ControlMessage)>>, - pub(crate) send: HashMap<(ServiceType, Account), VecDeque<(Account, GameMessage)>>, - - pub(crate) players_online: Players, - pub(crate) players_banned: Players, - pub(crate) account_service_type: Mutex<HashMap<Account, ServiceType>>, - - pub locked: AtomicBool, - pub close: AtomicBool, -} - -#[derive(Default)] -pub struct GameControlRuntime { - pub(crate) keys: GameControlData, - pub(crate) directions : HashMap<u8, HashMap<Account, (f64, f64)>>, - pub(crate) axes : HashMap<u8, HashMap<Account, f64>>, - pub(crate) button : HashMap<u8, HashMap<Account, bool>>, - pub(crate) events : VecDeque<(Account, ControlMessage)> -}
\ No newline at end of file diff --git a/core/src/data/game/structs.rs b/core/src/data/game/structs.rs deleted file mode 100644 index 52fc0f1..0000000 --- a/core/src/data/game/structs.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::collections::HashMap; -use serde::{Deserialize, Serialize}; -use crate::data::game::types::GameInfo; -use crate::data::player::structs::Account; - -/// Game pad_client data -/// Describes the basic information of the game pad_client -#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)] -pub struct GameData { - pub info: GameInfo, - pub control: GameControlData, - pub archive: GameRuntimeDataArchive -} - -/// Game control information -/// Describes the buttons, axes, and directions that can be controlled. -#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)] -pub struct GameControlData { - pub direction_keys : HashMap<u8, String>, - pub axis_keys : HashMap<u8, String>, - pub button_keys : HashMap<u8, String>, -} - -/// Archive of game runtime data -/// The game pad_client can convert data into this structure for persistence. -#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)] -pub struct GameRuntimeDataArchive { - pub banned: Vec<Account> -}
\ No newline at end of file diff --git a/core/src/data/game/types.rs b/core/src/data/game/types.rs index 8af17d3..778201f 100644 --- a/core/src/data/game/types.rs +++ b/core/src/data/game/types.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use std::sync::Mutex; -use crate::data::player::structs::{Account, Player}; +use crate::data::player::player_data::{Account, Player}; pub(crate) type GameInfo = HashMap<String, String>; diff --git a/core/src/data/message/implements.rs b/core/src/data/message/message_encoders.rs index 2d5bae8..d20e74a 100644 --- a/core/src/data/message/implements.rs +++ b/core/src/data/message/message_encoders.rs @@ -1,4 +1,4 @@ -use crate::data::message::enums::{ConnectionResponseMessage, JoinFailedMessage, ConnectionMessage, ControlMessage, ExitReason, GameMessage}; +use crate::data::message::message_enums::{ConnectionResponseMessage, JoinFailedMessage, ConnectionMessage, ControlMessage, ExitReason, GameMessage}; use crate::data::message::traits::MessageEncoder; #[macro_export] diff --git a/core/src/data/message/enums.rs b/core/src/data/message/message_enums.rs index 4150b63..fd369a9 100644 --- a/core/src/data/message/enums.rs +++ b/core/src/data/message/message_enums.rs @@ -1,6 +1,6 @@ -use crate::data::player::structs::Player; use bincode::{Decode, Encode}; use crate::data::game::types::GameInfo; +use crate::data::player::player_data::Player; /// Control messages. /// Messages sent from controller to game pad_client after establishing persistent connection diff --git a/core/src/data/message/mod.rs b/core/src/data/message/mod.rs index 96fdd73..1b9d2fd 100644 --- a/core/src/data/message/mod.rs +++ b/core/src/data/message/mod.rs @@ -1,3 +1,3 @@ -pub mod enums; -pub mod implements; +pub mod message_encoders; +pub mod message_enums; pub mod traits;
\ No newline at end of file diff --git a/core/src/data/player/mod.rs b/core/src/data/player/mod.rs index 7e8fe28..ff6ae85 100644 --- a/core/src/data/player/mod.rs +++ b/core/src/data/player/mod.rs @@ -1,4 +1,3 @@ -pub mod implements; -pub mod structs; +pub mod player_data; pub const ACCOUNT_HASH_SALT : &str = env!("TEST_PLAYER_ACCOUNT");
\ No newline at end of file diff --git a/core/src/data/player/implements.rs b/core/src/data/player/player_data.rs index bbaefc4..1fe5ff0 100644 --- a/core/src/data/player/implements.rs +++ b/core/src/data/player/player_data.rs @@ -1,11 +1,54 @@ -use crate::data::player::structs::{Account, Customize, Player}; use crate::data::player::ACCOUNT_HASH_SALT; use hex::encode; use sha1::{Digest, Sha1}; use std::fmt::{Display, Formatter}; use std::hash::{Hash, Hasher}; +use bincode::{Decode, Encode}; +use serde::{Deserialize, Serialize}; use nogamepads::string_utils::process_id_text; +/// Player information +/// Describes a player's specific details, which are frequently exchanged between the controller and game pad_client. +#[derive(Default, Clone, Encode, Decode, Serialize, Deserialize, Debug)] +pub struct Player { + + /// Account information + pub account: Account, + + /// Custom information (Optional) + pub customize: Option<Customize> +} + +/// Account information +/// Essential data for verifying player uniqueness, including the player's hash value and account ID. +#[derive(Default, Clone, Encode, Decode, Serialize, Deserialize, Eq, Hash, PartialEq, Debug)] +pub struct Account { + + /// Player name stored in data, allowing only lowercase letters and underscores + pub id: String, + + /// Player hash value proving player uniqueness + pub player_hash: String +} + +/// Custom information +/// Describes personalized player details displayed in-game, such as name, color, or other customizations. +#[derive(Default, Clone, Encode, Decode, Serialize, Deserialize, PartialEq, Debug)] +pub struct Customize { + + /// Player name displayed in the game + pub nickname: String, + + /// HSV Color - Hue (Range: 0 - 360) + pub color_hue: i32, + + /// HSV Color - Saturation (Range: 0 - 1) + pub color_saturation: f64, + + /// HSV Color - Value (Range: 0 - 1) + pub color_value: f64 +} + impl Player { /// Create new player information using a username and password diff --git a/core/src/data/player/structs.rs b/core/src/data/player/structs.rs deleted file mode 100644 index cc3d7c9..0000000 --- a/core/src/data/player/structs.rs +++ /dev/null @@ -1,45 +0,0 @@ -use bincode::{Decode, Encode}; -use serde::{Deserialize, Serialize}; -use std::hash::{Hash}; - -/// Player information -/// Describes a player's specific details, which are frequently exchanged between the controller and game pad_client. -#[derive(Default, Clone, Encode, Decode, Serialize, Deserialize, Debug)] -pub struct Player { - - /// Account information - pub account: Account, - - /// Custom information (Optional) - pub customize: Option<Customize> -} - -/// Account information -/// Essential data for verifying player uniqueness, including the player's hash value and account ID. -#[derive(Default, Clone, Encode, Decode, Serialize, Deserialize, Eq, Hash, PartialEq, Debug)] -pub struct Account { - - /// Player name stored in data, allowing only lowercase letters and underscores - pub id: String, - - /// Player hash value proving player uniqueness - pub player_hash: String -} - -/// Custom information -/// Describes personalized player details displayed in-game, such as name, color, or other customizations. -#[derive(Default, Clone, Encode, Decode, Serialize, Deserialize, PartialEq, Debug)] -pub struct Customize { - - /// Player name displayed in the game - pub nickname: String, - - /// HSV Color - Hue (Range: 0 - 360) - pub color_hue: i32, - - /// HSV Color - Saturation (Range: 0 - 1) - pub color_saturation: f64, - - /// HSV Color - Value (Range: 0 - 1) - pub color_value: f64 -}
\ No newline at end of file diff --git a/core/src/lib.rs b/core/src/lib.rs index 49db429..81d1155 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -5,4 +5,4 @@ pub mod data; pub mod service; pub const BINCODE_CONVERT_FAILED : Vec<u8> = Vec::new(); -pub const BINCODE_CONFIG : Configuration = config::standard(); +pub const BINCODE_CONFIG : Configuration = config::standard();
\ No newline at end of file diff --git a/core/src/message_encoders.rs b/core/src/message_encoders.rs new file mode 100644 index 0000000..49db429 --- /dev/null +++ b/core/src/message_encoders.rs @@ -0,0 +1,8 @@ +use bincode::config; +use bincode::config::Configuration; + +pub mod data; +pub mod service; + +pub const BINCODE_CONVERT_FAILED : Vec<u8> = Vec::new(); +pub const BINCODE_CONFIG : Configuration = config::standard(); diff --git a/core/src/service/tcp_network/long_connection.rs b/core/src/service/tcp_network/long_connection.rs index 200cf61..c8916fa 100644 --- a/core/src/service/tcp_network/long_connection.rs +++ b/core/src/service/tcp_network/long_connection.rs @@ -1,6 +1,3 @@ -use crate::data::player::structs::Player; -use crate::service::tcp_network::pad_client::structs::PadClientNetwork; -use crate::service::tcp_network::pad_server::structs::PadServerNetwork; use std::sync::Arc; use std::sync::atomic::Ordering::SeqCst; use log::{error, info, trace, warn}; @@ -9,12 +6,15 @@ use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf}; use tokio::net::TcpStream; use tokio::spawn; use nogamepads::entry_mutex; -use crate::data::message::enums::{ControlMessage, GameMessage}; -use crate::data::message::enums::ExitReason::GameOver; -use crate::data::message::enums::GameMessage::{End, LetExit}; +use crate::data::message::message_enums::{ControlMessage, GameMessage}; +use crate::data::message::message_enums::ExitReason::GameOver; +use crate::data::message::message_enums::GameMessage::{End, LetExit}; use crate::data::message::traits::{MessageEncoder, MessageManager}; +use crate::data::player::player_data::Player; use crate::service::service_types::ServiceType; use crate::service::service_types::ServiceType::TCPConnection; +use crate::service::tcp_network::pad_client::pad_client_service::PadClientNetwork; +use crate::service::tcp_network::pad_server::pad_server_service::PadServerNetwork; impl PadServerNetwork { diff --git a/core/src/service/tcp_network/pad_client/mod.rs b/core/src/service/tcp_network/pad_client/mod.rs index 0ff870f..4e9794d 100644 --- a/core/src/service/tcp_network/pad_client/mod.rs +++ b/core/src/service/tcp_network/pad_client/mod.rs @@ -1,2 +1 @@ -pub mod implements; -pub mod structs;
\ No newline at end of file +pub mod pad_client_service;
\ No newline at end of file diff --git a/core/src/service/tcp_network/pad_client/implements.rs b/core/src/service/tcp_network/pad_client/pad_client_service.rs index 021b325..9b1826b 100644 --- a/core/src/service/tcp_network/pad_client/implements.rs +++ b/core/src/service/tcp_network/pad_client/pad_client_service.rs @@ -6,16 +6,20 @@ use log::{error, info, warn}; use tokio::{join, spawn}; use tokio::time::sleep; use nogamepads::entry_mutex; -use crate::data::controller::runtime::structs::ControllerRuntime; -use crate::data::message::enums::ConnectionMessage::{Join, RequestGameInfos}; -use crate::data::message::enums::ConnectionResponseMessage; +use crate::data::controller::controller_runtime::ControllerRuntime; +use crate::data::message::message_enums::ConnectionMessage::{Join, RequestGameInfos}; +use crate::data::message::message_enums::ConnectionResponseMessage; use crate::service::service_runner::NoGamepadsService; use crate::service::service_types::ServiceType; -use crate::service::tcp_network::pad_client::structs::PadClientNetwork; use crate::service::tcp_network::DEFAULT_PORT; use crate::service::tcp_network::utils::stream_utils::{read_msg, send_msg}; use crate::service::tcp_network::utils::tokio_utils::build_tokio_runtime; +pub struct PadClientNetwork { + pub(crate) addr: SocketAddr, + pub(crate) runtime: Arc<Mutex<ControllerRuntime>> +} + macro_rules! connect_once { ($addr:expr, |$conn:ident| $code:block) => {{ use tokio::net::TcpStream; diff --git a/core/src/service/tcp_network/pad_client/structs.rs b/core/src/service/tcp_network/pad_client/structs.rs deleted file mode 100644 index 10c93c4..0000000 --- a/core/src/service/tcp_network/pad_client/structs.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::net::SocketAddr; -use std::sync::{Arc, Mutex}; -use crate::data::controller::runtime::structs::ControllerRuntime; - -pub struct PadClientNetwork { - pub(crate) addr: SocketAddr, - pub(crate) runtime: Arc<Mutex<ControllerRuntime>> -}
\ No newline at end of file diff --git a/core/src/service/tcp_network/pad_server/mod.rs b/core/src/service/tcp_network/pad_server/mod.rs index b37b320..43d81a9 100644 --- a/core/src/service/tcp_network/pad_server/mod.rs +++ b/core/src/service/tcp_network/pad_server/mod.rs @@ -1,2 +1 @@ -pub mod implements; -pub mod structs; +pub mod pad_server_service;
\ No newline at end of file diff --git a/core/src/service/tcp_network/pad_server/implements.rs b/core/src/service/tcp_network/pad_server/pad_server_service.rs index d4288bf..1b665a0 100644 --- a/core/src/service/tcp_network/pad_server/implements.rs +++ b/core/src/service/tcp_network/pad_server/pad_server_service.rs @@ -5,19 +5,26 @@ use std::time::Duration; use log::{error, info, trace, warn}; use tokio::{join, select, spawn}; use tokio::net::{TcpListener, TcpStream}; -use tokio::sync::watch::{channel}; +use tokio::sync::watch::{channel, Receiver, Sender}; use tokio::time::sleep; use nogamepads::entry_mutex; -use crate::data::game::runtime::structs::GameRuntime; -use crate::data::message::enums::ConnectionMessage; -use crate::data::message::enums::ConnectionMessage::{Join, RequestGameInfos, RequestLayoutConfigure, RequestSkinPackage, Ready}; -use crate::data::message::enums::ConnectionResponseMessage::{Deny, GameInfos, Welcome}; +use crate::data::game::game_runtime::GameRuntime; +use crate::data::message::message_enums::ConnectionMessage; +use crate::data::message::message_enums::ConnectionMessage::{Join, RequestGameInfos, RequestLayoutConfigure, RequestSkinPackage, Ready}; +use crate::data::message::message_enums::ConnectionResponseMessage::{Deny, GameInfos, Welcome}; use crate::service::service_runner::NoGamepadsService; use crate::service::tcp_network::DEFAULT_PORT; -use crate::service::tcp_network::pad_server::structs::PadServerNetwork; use crate::service::tcp_network::utils::stream_utils::{get_target_address, read_msg, send_msg}; use crate::service::tcp_network::utils::tokio_utils::build_tokio_runtime; +pub struct PadServerNetwork { + pub(crate) addr: SocketAddr, + pub(crate) runtime: Arc<Mutex<GameRuntime>>, + + pub(crate) close_tx: Sender<bool>, + pub(crate) close_rx: Receiver<bool>, +} + impl PadServerNetwork { pub fn build(runtime: Arc<Mutex<GameRuntime>>) -> PadServerNetwork { diff --git a/core/src/service/tcp_network/pad_server/structs.rs b/core/src/service/tcp_network/pad_server/structs.rs deleted file mode 100644 index f46608a..0000000 --- a/core/src/service/tcp_network/pad_server/structs.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::data::game::runtime::structs::GameRuntime; -use std::net::SocketAddr; -use std::sync::{Arc, Mutex}; -use tokio::sync::watch::{Receiver, Sender}; - -pub struct PadServerNetwork { - pub(crate) addr: SocketAddr, - pub(crate) runtime: Arc<Mutex<GameRuntime>>, - - pub(crate) close_tx: Sender<bool>, - pub(crate) close_rx: Receiver<bool>, -}
\ No newline at end of file diff --git a/export/dev/bin/padc.exe b/export/dev/bin/padc.exe Binary files differindex 95b2043..5c6b7a0 100644 --- a/export/dev/bin/padc.exe +++ b/export/dev/bin/padc.exe |
