MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / run_server

Function run_server

mserver/MasterService/src/main.rs:115–164  ·  view source on GitHub ↗
(args: ServerArgs)

Source from the content-addressed store, hash-verified

113}
114
115async fn run_server(args: ServerArgs) -> Result<()> {
116 info!("Starting PAPA BEAR");
117
118 // `--db` accepts either a sqlx URL (postgres://… or sqlite://…) or a bare file path,
119 // which is treated as a local SQLite database (created if missing).
120 let (db_url, db_path) = resolve_db_url(&args.db)?;
121 if let Some(db_path) = &db_path {
122 if let Some(parent) = ensure_parent_directory(db_path)? {
123 info!("Database directory ready at {}", parent.display());
124 }
125 }
126
127 let directory = Arc::new(SqliteServerDirectory::open(&db_url).await?);
128 info!("Using database {}", redact_db_url(&db_url));
129
130 let mods_path_hint = db_path.clone().unwrap_or_else(|| PathBuf::from("."));
131 let mods_dir = resolve_mods_path(args.mods_dir.as_deref(), &mods_path_hint, args.dev)?;
132 let mod_store = build_mod_store(mods_dir.as_deref())?;
133 info!(
134 "Mod store: {}",
135 if mod_store.is_some() {
136 "enabled"
137 } else {
138 "disabled"
139 }
140 );
141
142 if args.dev {
143 let seeded_servers = seed_dev_data(&directory, current_time_millis()?).await?;
144 let seeded_mods = if let Some(store) = &mod_store {
145 seed_dev_mods(store).await?
146 } else {
147 0
148 };
149 info!("Loaded dev seed ({seeded_servers} servers, {seeded_mods} mods)");
150 }
151
152 let app = build_router_with_store(
153 directory,
154 args.admin_api_key,
155 mod_store,
156 args.client_ip_header,
157 args.require_server_token,
158 );
159 let listener = tokio::net::TcpListener::bind(&args.listen).await?;
160 let local_addr = listener.local_addr()?;
161 log_listen_urls(local_addr);
162 axum::serve(
163 listener,
164 app.into_make_service_with_connect_info::<SocketAddr>(),
165 )
166 .await?;
167 Ok(())

Callers 1

mainFunction · 0.70

Calls 10

resolve_db_urlFunction · 0.85
ensure_parent_directoryFunction · 0.85
resolve_mods_pathFunction · 0.85
build_mod_storeFunction · 0.85
seed_dev_dataFunction · 0.85
seed_dev_modsFunction · 0.85
build_router_with_storeFunction · 0.85
log_listen_urlsFunction · 0.85
cloneMethod · 0.80
current_time_millisFunction · 0.70

Tested by

no test coverage detected