From 6bfce870af6732cb77f851af3360e7f6c1db27db Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 16 Jul 2024 10:18:26 -0400 Subject: [PATCH] Add parametized auth and game servers --- README.md | 2 +- src/bot.rs | 15 +++++++++++---- src/main.rs | 8 ++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7225d86..da552e8 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ orientation = 0 # Optional. Announcements are sent every 45 minutes. Use {location} to insert the bot's current # location. If not set, the bot will not send /world announcements but will still send /region -# announcement with usage instructions. +# announcements with usage instructions. announcement = "I love cheese! I am at {location}." # The buy_prices and sell_prices tables are required. The keys are item definition IDs and the diff --git a/src/bot.rs b/src/bot.rs index 3a6819f..9ad47cc 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -72,6 +72,8 @@ impl Bot { /// and return a Bot instance ready to run. #[allow(clippy::too_many_arguments)] pub fn new( + game_server: String, + auth_server: &str, username: String, password: &str, character: &str, @@ -84,7 +86,7 @@ impl Bot { ) -> Result { log::info!("Connecting to veloren"); - let mut client = connect_to_veloren(&username, password)?; + let mut client = connect_to_veloren(game_server, auth_server, &username, password)?; let mut clock = Clock::new(Duration::from_secs_f64(1.0 / 30.0)); client.load_character_list(); @@ -917,14 +919,19 @@ enum TradeMode { Trade, } -fn connect_to_veloren(username: &str, password: &str) -> Result { +fn connect_to_veloren( + game_server: String, + auth_server: &str, + username: &str, + password: &str, +) -> Result { let runtime = Arc::new(Runtime::new().unwrap()); let runtime2 = Arc::clone(&runtime); runtime .block_on(Client::new( ConnectionArgs::Tcp { - hostname: "server.veloren.net".to_string(), + hostname: game_server, prefer_ipv6: false, }, runtime2, @@ -932,7 +939,7 @@ fn connect_to_veloren(username: &str, password: &str) -> Result username, password, None, - |provider| provider == "https://auth.veloren.net", + |provider| provider == auth_server, &|_| {}, |_| {}, Default::default(), diff --git a/src/main.rs b/src/main.rs index b7508f6..c691c12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,6 +44,12 @@ fn main() { toml::from_str::(&file_content).expect("Failed to parse config") }; + let game_server = config + .game_server + .unwrap_or("server.veloren.net".to_string()); + let auth_server = config + .auth_server + .unwrap_or("https://auth.veloren.net".to_string()); let buy_prices_with_full_id = config .buy_prices .into_iter() @@ -63,6 +69,8 @@ fn main() { }) .collect(); let mut bot = Bot::new( + game_server, + &auth_server, secrets.username, &secrets.password, &secrets.character,