aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-06 11:39:59 +0000
committerFuwn <[email protected]>2021-05-06 11:39:59 +0000
commit1643fb945fd5d7951578159124b15e072958adc2 (patch)
tree3e4f163c71d69ba007c32407419cff5adbbd4f10 /src
parentrefactor(server): clippy: module inception (diff)
downloadwhirl-1643fb945fd5d7951578159124b15e072958adc2.tar.xz
whirl-1643fb945fd5d7951578159124b15e072958adc2.zip
fix(docker): the dockering
Fix Docker functionalities.
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs6
-rw-r--r--src/config/mod.rs31
-rw-r--r--src/db/mod.rs2
-rw-r--r--src/prompt/mod.rs2
-rw-r--r--src/server/cmd/commands/property/create.rs6
-rw-r--r--src/server/cmd/commands/redirect_id.rs4
-rw-r--r--src/server/distributor.rs4
-rw-r--r--src/server/hub.rs4
-rw-r--r--src/subs.rs8
9 files changed, 46 insertions, 21 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 8fab8c2..ad067a3 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -21,7 +21,7 @@ impl Cli {
run().await;
} else if let Some(cmd) = matches.subcommand_matches("config") {
if cmd.is_present("show") {
- println!("{:#?}", Config::get().unwrap());
+ println!("{:#?}", Config::get());
}
} else if let Some(shell) = matches.subcommand_matches("completions") {
if shell.is_present("powershell") {
@@ -41,10 +41,10 @@ impl Cli {
fn calc_log_level(matches: &ArgMatches<'_>) {
let mut log_level = "whirl=error,whirl=warn,whirl=trace".to_string();
- if matches.is_present("debug") || Config::get().unwrap().whirlsplash.log_level >= 2 {
+ if matches.is_present("debug") || Config::get().whirlsplash.log_level >= 2 {
log_level += ",whirl=debug";
}
- if matches.is_present("trace") || Config::get().unwrap().whirlsplash.log_level >= 3 {
+ if matches.is_present("trace") || Config::get().whirlsplash.log_level >= 3 {
log_level += ",whirl=trace";
}
std::env::set_var("RUST_LOG", log_level);
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 3815b3d..66a9388 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -34,5 +34,34 @@ impl Config {
s.try_into()
}
- pub fn get() -> Result<Self, ConfigError> { Self::load() }
+ pub fn get() -> Config {
+ return if let Err(why) = Self::load() {
+ error!(
+ "unable to load configuration file, reverting to default: {}",
+ why
+ );
+ Self::default()
+ } else {
+ Self::load().unwrap()
+ };
+ }
+}
+impl Default for Config {
+ fn default() -> Self {
+ Config {
+ whirlsplash: WhirlsplashConfig {
+ worldsmaster_username: "WORLDSMASTER".to_string(),
+ log_level: 1,
+ ip: "0.0.0.0".to_string(),
+ prompt_ps1: "[WORLDSMASTER@Whirlsplash ~]$".to_string(),
+ },
+ distributor: DistributorConfig {
+ worldsmaster_greeting: "Welcome to Whirlsplash!".to_string(),
+ port: 6650,
+ },
+ hub: HubConfig {
+ port: 5673
+ },
+ }
+ }
}
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 496ec0a..b93390d 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -9,7 +9,7 @@ use diesel::prelude::*;
// use crate::db::models::*;
pub fn establish_connection() -> SqliteConnection {
- let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
+ let database_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "whirl.sqlite3".to_string());
SqliteConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("error connecting to {}", database_url))
}
diff --git a/src/prompt/mod.rs b/src/prompt/mod.rs
index 47a65e5..d1d08fa 100644
--- a/src/prompt/mod.rs
+++ b/src/prompt/mod.rs
@@ -33,7 +33,7 @@ impl Prompt {
}
fn write_prompt() {
- print!("{} ", Config::get().unwrap().whirlsplash.prompt_ps1);
+ print!("{} ", Config::get().whirlsplash.prompt_ps1);
io::stdout().flush().unwrap();
}
diff --git a/src/server/cmd/commands/property/create.rs b/src/server/cmd/commands/property/create.rs
index e4c4eb2..9908b27 100644
--- a/src/server/cmd/commands/property/create.rs
+++ b/src/server/cmd/commands/property/create.rs
@@ -59,7 +59,7 @@ pub fn create_property_update_as_distributor() -> Vec<u8> {
},
NetworkProperty {
prop_id: VAR_APPNAME,
- value: Config::get().unwrap().whirlsplash.worldsmaster_username,
+ value: Config::get().whirlsplash.worldsmaster_username,
},
],
)
@@ -100,7 +100,7 @@ pub fn create_property_update_as_hub() -> Vec<u8> {
},
NetworkProperty {
prop_id: VAR_APPNAME,
- value: Config::get().unwrap().whirlsplash.worldsmaster_username,
+ value: Config::get().whirlsplash.worldsmaster_username,
},
],
)
@@ -117,7 +117,7 @@ pub fn create_property_request_as_distributor() -> Vec<u8> {
},
NetworkProperty {
prop_id: VAR_APPNAME,
- value: Config::get().unwrap().whirlsplash.worldsmaster_username,
+ value: Config::get().whirlsplash.worldsmaster_username,
},
NetworkProperty {
prop_id: VAR_PROTOCOL,
diff --git a/src/server/cmd/commands/redirect_id.rs b/src/server/cmd/commands/redirect_id.rs
index fdcf859..e6d3ddd 100644
--- a/src/server/cmd/commands/redirect_id.rs
+++ b/src/server/cmd/commands/redirect_id.rs
@@ -29,10 +29,10 @@ impl Creatable for RedirectId {
command.put_u16(self.room_number as u16); // Room ID
// IP
- for byte in Config::get().unwrap().whirlsplash.ip.split('.') {
+ for byte in Config::get().whirlsplash.ip.split('.') {
command.put_u8(byte.parse::<u8>().unwrap());
}
- command.put_u16(Config::get().unwrap().hub.port as u16); // Port
+ command.put_u16(Config::get().hub.port as u16); // Port
// Length
let mut command_as_vec = command.to_vec();
diff --git a/src/server/distributor.rs b/src/server/distributor.rs
index e84afeb..26bc87f 100644
--- a/src/server/distributor.rs
+++ b/src/server/distributor.rs
@@ -89,8 +89,8 @@ impl Server for Distributor {
peer.bytes.get_mut()
.write_all(&Text {
- sender: Config::get()?.whirlsplash.worldsmaster_username,
- content: Config::get()?.distributor.worldsmaster_greeting,
+ sender: Config::get().whirlsplash.worldsmaster_username,
+ content: Config::get().distributor.worldsmaster_greeting,
}.create()).await?;
peer.bytes.get_mut()
.write_all(&create_action()).await?;
diff --git a/src/server/hub.rs b/src/server/hub.rs
index b2b176e..ef72877 100644
--- a/src/server/hub.rs
+++ b/src/server/hub.rs
@@ -88,8 +88,8 @@ impl Server for Hub {
peer.bytes.get_mut()
.write_all(&Text {
- sender: Config::get()?.whirlsplash.worldsmaster_username,
- content: Config::get()?.distributor.worldsmaster_greeting,
+ sender: Config::get().whirlsplash.worldsmaster_username,
+ content: Config::get().distributor.worldsmaster_greeting,
}.create()).await?;
peer.bytes.get_mut()
.write_all(&create_action()).await?;
diff --git a/src/subs.rs b/src/subs.rs
index 4bed5a1..bf979de 100644
--- a/src/subs.rs
+++ b/src/subs.rs
@@ -17,17 +17,13 @@ pub async fn run() -> ! {
let _threads = vec![
tokio::spawn(async move {
let _ = Distributor::listen(
- &*format!("0.0.0.0:{}", Config::get().unwrap().distributor.port),
+ &*format!("0.0.0.0:{}", Config::get().distributor.port),
AutoServer,
)
.await;
}),
tokio::spawn(async move {
- let _ = Hub::listen(
- &*format!("0.0.0.0:{}", Config::get().unwrap().hub.port),
- RoomServer,
- )
- .await;
+ let _ = Hub::listen(&*format!("0.0.0.0:{}", Config::get().hub.port), RoomServer).await;
}),
tokio::spawn(async move {
let _ = Api::listen();