Add parametized auth and game servers

This commit is contained in:
Jeff 2024-07-16 10:18:26 -04:00
parent 67e72dcf20
commit 6bfce870af
3 changed files with 20 additions and 5 deletions

View File

@ -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

View File

@ -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<Self, String> {
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<Client, String> {
fn connect_to_veloren(
game_server: String,
auth_server: &str,
username: &str,
password: &str,
) -> Result<Client, String> {
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<Client, String>
username,
password,
None,
|provider| provider == "https://auth.veloren.net",
|provider| provider == auth_server,
&|_| {},
|_| {},
Default::default(),

View File

@ -44,6 +44,12 @@ fn main() {
toml::from_str::<Config>(&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,