aboutsummaryrefslogtreecommitdiff
path: root/core/src/data
diff options
context:
space:
mode:
author1992414357@qq.com <1992414357@qq.com>2025-06-09 10:28:16 +0800
committer1992414357@qq.com <1992414357@qq.com>2025-06-09 10:28:16 +0800
commit7093b08b8efd6e35a434b2923c40b763b51e675b (patch)
treefe46f65e50effe5a89055febd9af4c8d456241e1 /core/src/data
parenta75ee4f12e78b880f6d008a5e72d70b0c7f997b4 (diff)
将控制台的关闭改为了自动
Diffstat (limited to 'core/src/data')
-rw-r--r--core/src/data/controller/cli/cli_command.rs29
-rw-r--r--core/src/data/game/cli/cli_command.rs38
2 files changed, 25 insertions, 42 deletions
diff --git a/core/src/data/controller/cli/cli_command.rs b/core/src/data/controller/cli/cli_command.rs
index d5cda07..b918d47 100644
--- a/core/src/data/controller/cli/cli_command.rs
+++ b/core/src/data/controller/cli/cli_command.rs
@@ -1,13 +1,9 @@
-use std::process::exit;
use std::sync::{Arc, Mutex};
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::message::enums::ControlMessage;
-use crate::data::message::traits::MessageManager;
-use crate::service::service_types::ServiceType::TCPConnection;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
@@ -25,9 +21,6 @@ enum Commands {
#[command(about = "Close the controller")]
Close,
- #[command(about = "Exit the console")]
- Exit,
-
#[command(about = "Send a message")]
Message(MessageArgs),
@@ -71,7 +64,7 @@ struct DirectionArgs {
y: f64
}
-pub fn process_controller_cli(runtime: Arc<Mutex<ControllerRuntime>>, cmd: ControllerCli) {
+pub fn process_controller_cli(runtime: Arc<Mutex<ControllerRuntime>>, cmd: ControllerCli) -> bool {
match cmd.command {
Commands::Clear => {
@@ -82,40 +75,37 @@ pub fn process_controller_cli(runtime: Arc<Mutex<ControllerRuntime>>, cmd: Contr
entry_mutex!(runtime, |guard| {
guard.close();
});
- }
-
- Commands::Exit => {
- exit(1);
+ return false;
}
Commands::Message(args) => {
entry_mutex!(runtime, |guard| {
guard.message(args.message);
- })
+ });
}
Commands::Press(args) => {
entry_mutex!(runtime, |guard| {
guard.press_button(args.button_key);
- })
+ });
}
Commands::Release(args) => {
entry_mutex!(runtime, |guard| {
guard.release_button(args.button_key);
- })
+ });
}
Commands::Axis(args) => {
entry_mutex!(runtime, |guard| {
guard.change_axis(args.axis_key, args.axis_value);
- })
+ });
}
Commands::Direction(args) => {
entry_mutex!(runtime, |guard| {
guard.change_direction(args.dir_key, args.x, args.y);
- })
+ });
}
Commands::Pop => {
@@ -125,7 +115,7 @@ pub fn process_controller_cli(runtime: Arc<Mutex<ControllerRuntime>>, cmd: Contr
} else {
info!("None!");
}
- })
+ });
}
Commands::PopAll => {
@@ -133,7 +123,8 @@ pub fn process_controller_cli(runtime: Arc<Mutex<ControllerRuntime>>, cmd: Contr
while let Some(msg) = guard.pop() {
info!("Pop: {:?}", msg);
}
- })
+ });
}
}
+ true
} \ No newline at end of file
diff --git a/core/src/data/game/cli/cli_command.rs b/core/src/data/game/cli/cli_command.rs
index 9b74831..5f296f8 100644
--- a/core/src/data/game/cli/cli_command.rs
+++ b/core/src/data/game/cli/cli_command.rs
@@ -1,11 +1,9 @@
-use std::process::exit;
use std::sync::{Arc, Mutex};
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::message::traits::MessageManager;
use crate::data::player::structs::Player;
#[derive(Parser, Debug)]
@@ -28,9 +26,6 @@ enum Commands {
#[command(about = "Close the game")]
Close,
- #[command(about = "Exit the console")]
- Exit,
-
OnlineList,
BannedList,
@@ -67,33 +62,29 @@ struct SendMessageArgs {
msg: String
}
-pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
+pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) -> bool {
match cmd.command {
Commands::Clear => {
clear().expect("Failed to clear screen");
-
}
Commands::LockGame => {
entry_mutex!(runtime, |guard| {
guard.lock_game();
- })
+ });
}
Commands::UnlockGame => {
entry_mutex!(runtime, |guard| {
guard.unlock_game();
- })
+ });
}
Commands::Close => {
entry_mutex!(runtime, |guard| {
guard.close_game();
- })
- }
-
- Commands::Exit => {
- exit(1);
+ });
+ return false;
}
Commands::OnlineList => {
@@ -103,7 +94,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
info!("{}.{}", i, account.id);
i += 1;
}
- })
+ });
}
Commands::BannedList => {
@@ -113,7 +104,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
info!("{}.{}", i, account.id);
i += 1;
}
- })
+ });
}
Commands::Ban(args) => {
@@ -126,7 +117,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
} else {
warn!("Account number {} not found", args.index);
}
- })
+ });
}
Commands::Pardon(args) => {
@@ -137,7 +128,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
} else {
warn!("Account number {} not found", args.index);
}
- })
+ });
}
Commands::Kick(args) => {
@@ -150,7 +141,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
} else {
warn!("Account number {} not found", args.index);
}
- })
+ });
}
Commands::Event(args) => {
@@ -163,7 +154,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
} else {
warn!("Account number {} not found", args.index);
}
- })
+ });
}
Commands::Message(args) => {
@@ -176,7 +167,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
} else {
warn!("Account number {} not found", args.index);
}
- })
+ });
}
Commands::Pop => {
@@ -186,7 +177,7 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
} else {
info!("None")
}
- })
+ });
}
Commands::PopAll => {
@@ -194,7 +185,8 @@ pub fn process_game_cli(runtime: Arc<Mutex<GameRuntime>>, cmd: GameCli) {
while let Some((account, message)) = guard.pop_event() {
info!("{}: {:?}", account.id, message);
}
- })
+ });
}
}
+ true
} \ No newline at end of file