Gameserver: lineup configuration with .env
This commit is contained in:
parent
c132f0d2ee
commit
daf4507b34
7 changed files with 52 additions and 7 deletions
1
gameserver/.env
Normal file
1
gameserver/.env
Normal file
|
@ -0,0 +1 @@
|
||||||
|
LINEUP=1309,1308,1307,1315
|
|
@ -7,6 +7,8 @@ version.workspace = true
|
||||||
ansi_term.workspace = true
|
ansi_term.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
atomic_refcell.workspace = true
|
atomic_refcell.workspace = true
|
||||||
|
dirs.workspace = true
|
||||||
|
dotenv.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
hex.workspace = true
|
hex.workspace = true
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
|
|
16
gameserver/src/game/globals.rs
Normal file
16
gameserver/src/game/globals.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref LINEUP: Vec<u32> = {
|
||||||
|
let lineup_str = env::var("LINEUP").expect("Missing .env parameter: LINEUP");
|
||||||
|
let mut lineup = Vec::new();
|
||||||
|
|
||||||
|
for s in lineup_str.trim().replace(" ", "").split(",") {
|
||||||
|
lineup.push(s.parse().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
lineup
|
||||||
|
};
|
||||||
|
}
|
1
gameserver/src/game/mod.rs
Normal file
1
gameserver/src/game/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod globals;
|
|
@ -1,15 +1,42 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
|
mod game;
|
||||||
mod logging;
|
mod logging;
|
||||||
mod net;
|
mod net;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use logging::init_tracing;
|
use logging::init_tracing;
|
||||||
|
|
||||||
|
const DEFAULT_DOTENV: &str = include_str!("../.env");
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
init_tracing();
|
init_tracing();
|
||||||
|
init_config()?;
|
||||||
|
|
||||||
net::gateway::listen("0.0.0.0", 23301).await?;
|
net::gateway::listen("0.0.0.0", 23301).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_config() -> Result<()> {
|
||||||
|
let local_dotenv = std::path::Path::new(".env");
|
||||||
|
if local_dotenv.exists() {
|
||||||
|
dotenv::dotenv()?;
|
||||||
|
} else {
|
||||||
|
let config = dirs::config_dir()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("No config directory found"))?
|
||||||
|
.join("hkrpg-gameserver");
|
||||||
|
|
||||||
|
std::fs::create_dir_all(&config)?;
|
||||||
|
|
||||||
|
let env = config.join(".env");
|
||||||
|
|
||||||
|
if !env.exists() {
|
||||||
|
std::fs::write(&env, DEFAULT_DOTENV)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
dotenv::from_path(&env)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::game::globals;
|
||||||
static BATTLE_LINEUP: [u32; 4] = [1309, 1308, 1307, 1315];
|
|
||||||
|
|
||||||
pub async fn on_start_cocoon_stage_cs_req(
|
pub async fn on_start_cocoon_stage_cs_req(
|
||||||
session: &mut PlayerSession,
|
session: &mut PlayerSession,
|
||||||
|
@ -15,7 +14,7 @@ pub async fn on_start_cocoon_stage_cs_req(
|
||||||
stage_id: 201012311,
|
stage_id: 201012311,
|
||||||
logic_random_seed: 4444,
|
logic_random_seed: 4444,
|
||||||
battle_id: 1,
|
battle_id: 1,
|
||||||
battle_avatar_list: BATTLE_LINEUP
|
battle_avatar_list: globals::LINEUP
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, id)| BattleAvatar {
|
.map(|(idx, id)| BattleAvatar {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::game::globals;
|
||||||
static STARTING_LINEUP: [u32; 4] = [1309, 1308, 1307, 1315];
|
|
||||||
|
|
||||||
pub async fn on_get_all_lineup_data_cs_req(
|
pub async fn on_get_all_lineup_data_cs_req(
|
||||||
session: &mut PlayerSession,
|
session: &mut PlayerSession,
|
||||||
|
@ -16,7 +15,7 @@ pub async fn on_get_all_lineup_data_cs_req(
|
||||||
plane_id: 10001,
|
plane_id: 10001,
|
||||||
name: String::from("Lineup 1"),
|
name: String::from("Lineup 1"),
|
||||||
index: 0,
|
index: 0,
|
||||||
avatar_list: STARTING_LINEUP
|
avatar_list: globals::LINEUP
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, id)| LineupAvatar {
|
.map(|(idx, id)| LineupAvatar {
|
||||||
|
@ -51,7 +50,7 @@ pub async fn on_get_cur_lineup_data_cs_req(
|
||||||
plane_id: 10001,
|
plane_id: 10001,
|
||||||
name: String::from("Lineup 1"),
|
name: String::from("Lineup 1"),
|
||||||
index: 0,
|
index: 0,
|
||||||
avatar_list: STARTING_LINEUP
|
avatar_list: globals::LINEUP
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, id)| LineupAvatar {
|
.map(|(idx, id)| LineupAvatar {
|
||||||
|
|
Loading…
Reference in a new issue