aboutsummaryrefslogtreecommitdiff
path: root/server/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs37
1 files changed, 31 insertions, 6 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 7c072319..db667779 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -15,10 +15,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use anyhow::Result;
+use anyhow::{anyhow, Result};
use futures_util::{SinkExt, StreamExt};
-use log::{debug, info, warn};
-use std::{env::args, process::exit, sync::Arc, time::Duration};
+use log::{debug, info, warn, LevelFilter};
+use std::{env::args, path::PathBuf, process::exit, str::FromStr, sync::Arc, time::Duration};
use tokio::{
net::TcpListener,
spawn,
@@ -27,13 +27,16 @@ use tokio::{
};
use tokio_tungstenite::tungstenite::Message;
use undercooked::{
+ data::DATA_DIR,
protocol::{PacketC, PacketS, PlayerID},
state::State,
};
-#[tokio::main]
-async fn main() -> Result<()> {
- env_logger::init_from_env("LOG");
+fn main() -> Result<()> {
+ env_logger::builder()
+ .filter_level(LevelFilter::Info)
+ .parse_env("LOG")
+ .init();
if let Some(arg) = args().nth(1) {
match arg.as_str() {
@@ -43,6 +46,28 @@ async fn main() -> Result<()> {
exit(0);
}
+ let data_dir = PathBuf::from_str(
+ [
+ "/usr/local/share/undercooked/data",
+ "/usr/share/undercooked/data",
+ "./data",
+ ]
+ .into_iter()
+ .find(|p| PathBuf::from_str(p).unwrap().join("index.yaml").exists())
+ .ok_or(anyhow!("no data dir detected"))?,
+ )
+ .unwrap();
+ info!("Detected data dir to be {data_dir:?}");
+ *DATA_DIR.lock().unwrap() = Some(data_dir);
+
+ tokio::runtime::Builder::new_multi_thread()
+ .enable_all()
+ .build()?
+ .block_on(run())?;
+ Ok(())
+}
+
+async fn run() -> anyhow::Result<()> {
let ws_listener = TcpListener::bind("0.0.0.0:27032").await?;
info!("listening for websockets on {}", ws_listener.local_addr()?);