Add parametized auth and game servers
This commit is contained in:
parent
67e72dcf20
commit
6bfce870af
@ -94,7 +94,7 @@ orientation = 0
|
|||||||
|
|
||||||
# Optional. Announcements are sent every 45 minutes. Use {location} to insert the bot's current
|
# 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
|
# 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}."
|
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
|
# The buy_prices and sell_prices tables are required. The keys are item definition IDs and the
|
||||||
|
15
src/bot.rs
15
src/bot.rs
@ -72,6 +72,8 @@ impl Bot {
|
|||||||
/// and return a Bot instance ready to run.
|
/// and return a Bot instance ready to run.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
game_server: String,
|
||||||
|
auth_server: &str,
|
||||||
username: String,
|
username: String,
|
||||||
password: &str,
|
password: &str,
|
||||||
character: &str,
|
character: &str,
|
||||||
@ -84,7 +86,7 @@ impl Bot {
|
|||||||
) -> Result<Self, String> {
|
) -> Result<Self, String> {
|
||||||
log::info!("Connecting to veloren");
|
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));
|
let mut clock = Clock::new(Duration::from_secs_f64(1.0 / 30.0));
|
||||||
|
|
||||||
client.load_character_list();
|
client.load_character_list();
|
||||||
@ -917,14 +919,19 @@ enum TradeMode {
|
|||||||
Trade,
|
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 runtime = Arc::new(Runtime::new().unwrap());
|
||||||
let runtime2 = Arc::clone(&runtime);
|
let runtime2 = Arc::clone(&runtime);
|
||||||
|
|
||||||
runtime
|
runtime
|
||||||
.block_on(Client::new(
|
.block_on(Client::new(
|
||||||
ConnectionArgs::Tcp {
|
ConnectionArgs::Tcp {
|
||||||
hostname: "server.veloren.net".to_string(),
|
hostname: game_server,
|
||||||
prefer_ipv6: false,
|
prefer_ipv6: false,
|
||||||
},
|
},
|
||||||
runtime2,
|
runtime2,
|
||||||
@ -932,7 +939,7 @@ fn connect_to_veloren(username: &str, password: &str) -> Result<Client, String>
|
|||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
None,
|
None,
|
||||||
|provider| provider == "https://auth.veloren.net",
|
|provider| provider == auth_server,
|
||||||
&|_| {},
|
&|_| {},
|
||||||
|_| {},
|
|_| {},
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -44,6 +44,12 @@ fn main() {
|
|||||||
|
|
||||||
toml::from_str::<Config>(&file_content).expect("Failed to parse config")
|
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
|
let buy_prices_with_full_id = config
|
||||||
.buy_prices
|
.buy_prices
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -63,6 +69,8 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let mut bot = Bot::new(
|
let mut bot = Bot::new(
|
||||||
|
game_server,
|
||||||
|
&auth_server,
|
||||||
secrets.username,
|
secrets.username,
|
||||||
&secrets.password,
|
&secrets.password,
|
||||||
&secrets.character,
|
&secrets.character,
|
||||||
|
Loading…
Reference in New Issue
Block a user