-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimized structure and add terminal manager
- Loading branch information
Showing
14 changed files
with
146 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ target/ | |
_test/ | ||
.idea/ | ||
*.lock | ||
data/ |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::grouptypes::ProxySoftwareType; | ||
use super::grouptypes::ServerSoftwareType; | ||
use super::grouptypes::SupportedVersions; | ||
use super::grouptypes::StoreType; | ||
|
||
fn create_proxy_group(name: &str, proxy_software_type: ProxySoftwareType, | ||
min_memory: i64, max_memory: i64, max_players: i32, store_type: StoreType) { | ||
|
||
} | ||
|
||
fn create_lobby_group(name: &str, server_software_type: ServerSoftwareType, supported_versions: SupportedVersions, | ||
min_memory: i64, max_memory: i64, max_players: i32, store_type: StoreType) { | ||
|
||
} | ||
|
||
fn create_server_group(name: &str, server_software_type: ServerSoftwareType, supported_versions: SupportedVersions, | ||
min_memory: i64, max_memory: i64, max_players: i32, store_type: StoreType) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
enum ServiceType { | ||
pub(crate) enum ServiceType { | ||
PROXY, | ||
LOBBY, | ||
SERVER | ||
} | ||
|
||
enum ProxySoftwareType { | ||
pub(crate) enum ProxySoftwareType { | ||
BUNGEECORD, | ||
VELOCITY | ||
} | ||
|
||
enum ServerSoftwareType { | ||
pub(crate) enum ServerSoftwareType { | ||
SPIGOT, | ||
PAPER, | ||
PURPUR, | ||
FOLIA, | ||
MINESTOM | ||
} | ||
|
||
enum SupportedVersions { | ||
pub(crate) enum SupportedVersions { | ||
V1_19_4, | ||
V1_20_1, | ||
V1_20_4, | ||
V1_20_6, | ||
V1_21_1 | ||
} | ||
|
||
enum StoreType { | ||
pub(crate) enum StoreType { | ||
PERMANENTLY, | ||
TEMPORARY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,23 @@ | ||
mod cloud_terminal; | ||
mod terminal { | ||
pub(crate) mod cloud_terminal; | ||
pub(crate) mod terminal_manager; | ||
} | ||
mod database; | ||
mod json_config; | ||
|
||
use cloud_terminal::CloudTerminal; | ||
use json_config::JsonConfig; | ||
|
||
fn main() { | ||
let mut config = JsonConfig::new("data", "launch"); | ||
|
||
let main_terminal = CloudTerminal::new("main"); | ||
let setup_terminal = CloudTerminal::new("setup"); | ||
let group_setup_terminal = CloudTerminal::new("group-setup"); | ||
|
||
let mut current_terminal = main_terminal.get_current_terminal(); | ||
|
||
let need_setup = !config.get("Host").is_some(); | ||
let mut setup_step = 0; | ||
|
||
if need_setup { | ||
current_terminal = setup_terminal.get_current_terminal(); | ||
current_terminal.writeline("On which ip addresse should run the cloud?"); | ||
} | ||
mod config { | ||
pub(crate) mod json_config; | ||
} | ||
mod service; | ||
|
||
current_terminal.clear(); | ||
mod groups { | ||
mod group; | ||
mod grouptypes; | ||
} | ||
|
||
loop { | ||
let input = current_terminal.readline(); | ||
let current_terminal_name = current_terminal.name.as_str(); | ||
use terminal::terminal_manager::TerminalManager; | ||
use config::json_config::JsonConfig; | ||
|
||
match current_terminal_name { | ||
"main" => { | ||
if input == "clear" || input == "cls" { | ||
current_terminal.clear(); | ||
continue; | ||
} | ||
if input == "shutdown" { | ||
break; | ||
} | ||
} | ||
"setup" => { | ||
match setup_step { | ||
0 => { | ||
config.set("Host", input.clone()); | ||
current_terminal.writeline("On which port should run the cloud?"); | ||
setup_step += 1; | ||
continue; | ||
} | ||
1 => { | ||
config.set("Port", input.clone()); | ||
current_terminal.writeline("How many memory should use the cloud? (in GB)"); | ||
setup_step += 1; | ||
continue; | ||
} | ||
2 => { | ||
config.set("Memory", input.clone()); | ||
current_terminal.clear(); | ||
current_terminal = main_terminal.get_current_terminal(); | ||
setup_step += 1; | ||
continue; | ||
} | ||
_ => { | ||
current_terminal | ||
.writeline("Setup has been cancelled caused an unknown error."); | ||
break; | ||
} | ||
} | ||
} | ||
"group-setup" => {} | ||
_ => { | ||
if current_terminal_name.starts_with("service-") { | ||
if input == "leave" { | ||
current_terminal = main_terminal.get_current_terminal(); | ||
continue; | ||
} | ||
// TODO: Send Command into java application in terminal | ||
continue; | ||
} | ||
current_terminal.writeline("Unknown terminal."); | ||
} | ||
} | ||
current_terminal.writeline(&format!("Unknown command: {}", input)); | ||
} | ||
fn main() { | ||
let config: JsonConfig = JsonConfig::new("data", "launch"); | ||
let mut terminal_manager: TerminalManager = TerminalManager::new(config); | ||
terminal_manager.start_terminal(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
fn createPermanentlyService() { | ||
fn create_permanently_service() { | ||
|
||
} | ||
|
||
fn createTemporaryService() { | ||
fn create_temporary_service() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use super::cloud_terminal::CloudTerminal; | ||
use crate::config::json_config::JsonConfig; | ||
|
||
pub struct TerminalManager { | ||
pub(crate) launch_config: JsonConfig, | ||
pub(crate) main_terminal: CloudTerminal, | ||
pub(crate) setup_terminal: CloudTerminal, | ||
pub(crate) group_setup_terminal: CloudTerminal, | ||
} | ||
|
||
impl TerminalManager { | ||
|
||
pub fn new(launch_config: JsonConfig) -> Self { | ||
let launch_config = launch_config; | ||
Self { | ||
launch_config, | ||
main_terminal: CloudTerminal::new("main"), | ||
setup_terminal: CloudTerminal::new("setup"), | ||
group_setup_terminal: CloudTerminal::new("group-setup") | ||
} | ||
} | ||
|
||
pub fn start_terminal(&mut self) { | ||
let mut current_terminal = self.main_terminal.get_current_terminal(); | ||
|
||
let need_setup = !self.launch_config.get("Host").is_some(); | ||
let mut setup_step = 0; | ||
|
||
current_terminal.clear(); | ||
|
||
if need_setup { | ||
current_terminal = self.setup_terminal.get_current_terminal(); | ||
current_terminal.write_line("On which ip address should run the cloud?"); | ||
} | ||
|
||
loop { | ||
let input = current_terminal.readline(); | ||
let current_terminal_name = current_terminal.name.as_str(); | ||
|
||
match current_terminal_name { | ||
"main" => { | ||
if input == "clear" || input == "cls" { | ||
current_terminal.clear(); | ||
continue; | ||
} | ||
if input == "shutdown" || input == "exit" || input == "quit" || input == "stop" { | ||
break; | ||
} | ||
} | ||
"setup" => match setup_step { | ||
0 => { | ||
self.launch_config.set("Host", input.clone()); | ||
current_terminal.write_line("Which port should the cloud run on?"); | ||
setup_step += 1; | ||
continue; | ||
} | ||
1 => { | ||
self.launch_config.set("Port", input.clone()); | ||
current_terminal | ||
.write_line("How many memory should use the cloud? (in GB)"); | ||
setup_step += 1; | ||
continue; | ||
} | ||
2 => { | ||
self.launch_config.set("Memory", input.clone()); | ||
current_terminal.clear(); | ||
current_terminal = self.main_terminal.get_current_terminal(); | ||
setup_step += 1; | ||
continue; | ||
} | ||
_ => { | ||
current_terminal | ||
.write_line("Setup has been cancelled caused an unknown error."); | ||
break; | ||
} | ||
}, | ||
"group-setup" => {} | ||
_ => { | ||
if current_terminal_name.starts_with("service-") { | ||
if input == "leave" { | ||
current_terminal = self.main_terminal.get_current_terminal(); | ||
continue; | ||
} | ||
// TODO: Send Command into java application in terminal | ||
continue; | ||
} | ||
current_terminal.write_line("Unknown terminal."); | ||
} | ||
} | ||
current_terminal.write_line(&format!("Unknown command: {}", input)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters