aboutsummaryrefslogtreecommitdiff
path: root/core/src/data/game/cli
diff options
context:
space:
mode:
author1992414357@qq.com <1992414357@qq.com>2025-06-11 19:14:04 +0800
committer1992414357@qq.com <1992414357@qq.com>2025-06-11 19:14:04 +0800
commit9e48af01ae56fe813869ada24de291ab98b361e2 (patch)
tree82b56adecbeb260ebbf2c512d78fe2d63805eb36 /core/src/data/game/cli
parentaa326e69b18a4390ffbc97268eaec4793761f083 (diff)
组合模块中 structs.rs 和 implements.rs 文件
Diffstat (limited to 'core/src/data/game/cli')
-rw-r--r--core/src/data/game/cli/cli_command.rs192
-rw-r--r--core/src/data/game/cli/mod.rs1
2 files changed, 0 insertions, 193 deletions
diff --git a/core/src/data/game/cli/cli_command.rs b/core/src/data/game/cli/cli_command.rs
deleted file mode 100644
index 5f296f8..0000000
--- a/core/src/data/game/cli/cli_command.rs
+++ /dev/null
@@ -1,192 +0,0 @@
-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::player::structs::Player;
-
-#[derive(Parser, Debug)]
-#[command(author, version, about, long_about = None)]
-pub struct GameCli {
- #[command(subcommand)]
- command: Commands,
-}
-
-#[derive(Subcommand, Debug)]
-enum Commands {
-
- #[command(about = "Clean the screen")]
- Clear,
-
- LockGame,
-
- UnlockGame,
-
- #[command(about = "Close the game")]
- Close,
-
- OnlineList,
-
- BannedList,
-
- Ban(PlayerIndex),
-
- Pardon(PlayerIndex),
-
- Kick(PlayerIndex),
-
- Event(SendEventArgs),
-
- Message(SendMessageArgs),
-
- Pop,
-
- PopAll,
-}
-
-#[derive(Args, Debug)]
-struct PlayerIndex {
- index: usize,
-}
-
-#[derive(Args, Debug)]
-struct SendEventArgs {
- index: usize,
- event: u8
-}
-
-#[derive(Args, Debug)]
-struct SendMessageArgs {
- index: usize,
- msg: String
-}
-
-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();
- });
- return false;
- }
-
- Commands::OnlineList => {
- entry_mutex!(runtime, |guard| {
- let mut i = 0;
- for account in guard.data.online_accounts() {
- info!("{}.{}", i, account.id);
- i += 1;
- }
- });
- }
-
- Commands::BannedList => {
- entry_mutex!(runtime, |guard| {
- let mut i = 0;
- for account in guard.data.banned_accounts() {
- info!("{}.{}", i, account.id);
- i += 1;
- }
- });
- }
-
- Commands::Ban(args) => {
- entry_mutex!(runtime, |guard| {
- if let Some(account) = guard.data.online_accounts().get(args.index) {
- if let Some(service_type) = guard.data.get_service_type(account) {
- guard.ban_player(&Player::from(account.clone()), service_type);
- info!("Account {} banned.", account.id);
- }
- } else {
- warn!("Account number {} not found", args.index);
- }
- });
- }
-
- Commands::Pardon(args) => {
- entry_mutex!(runtime, |guard| {
- if let Some(account) = guard.data.banned_accounts().get(args.index) {
- guard.pardon_player(&Player::from(account.clone()));
- info!("Account {} pardoned.", account.id);
- } else {
- warn!("Account number {} not found", args.index);
- }
- });
- }
-
- Commands::Kick(args) => {
- entry_mutex!(runtime, |guard| {
- if let Some(account) = guard.data.online_accounts().get(args.index) {
- if let Some(service_type) = guard.data.get_service_type(account) {
- guard.kick_player(&Player::from(account.clone()), service_type);
- info!("Account {} kicked.", account.id);
- }
- } else {
- warn!("Account number {} not found", args.index);
- }
- });
- }
-
- Commands::Event(args) => {
- entry_mutex!(runtime, |guard| {
- if let Some(account) = guard.data.online_accounts().get(args.index) {
- if let Some(service_type) = guard.data.get_service_type(account) {
- guard.send_event(account, args.event, service_type);
- info!("Sent event {} to {}.", args.event, account.id);
- }
- } else {
- warn!("Account number {} not found", args.index);
- }
- });
- }
-
- Commands::Message(args) => {
- entry_mutex!(runtime, |guard| {
- if let Some(account) = guard.data.online_accounts().get(args.index) {
- if let Some(service_type) = guard.data.get_service_type(account) {
- guard.send_message(account, args.msg.clone(), service_type);
- info!("Sent message \"{}\" to {}.", args.msg, account.id);
- }
- } else {
- warn!("Account number {} not found", args.index);
- }
- });
- }
-
- Commands::Pop => {
- entry_mutex!(runtime, |guard| {
- if let Some((account, message)) = guard.pop_event() {
- info!("{}: {:?}", account.id, message);
- } else {
- info!("None")
- }
- });
- }
-
- Commands::PopAll => {
- entry_mutex!(runtime, |guard| {
- while let Some((account, message)) = guard.pop_event() {
- info!("{}: {:?}", account.id, message);
- }
- });
- }
- }
- true
-} \ 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