pub struct Webtile { /* private fields */ }Expand description
Webtile connection, using websocket (tungstenite) and a Deflate decoder (flate2).
Implementations§
source§impl Webtile
impl Webtile
sourcepub fn login_with_credentials(
&mut self,
username: &str,
password: &str
) -> Result<Vec<String>, Error>
pub fn login_with_credentials( &mut self, username: &str, password: &str ) -> Result<Vec<String>, Error>
Login to the game, using a username and password. It returns a vector of all playable game IDs.
Arguments
username- A string slice of the user’s username.password- A string slice of the user’s password.
Example
// Login under the user "Username", with a password of "Password"
webtile.login_with_credentials("Username", "Password")?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 50, "0.29").expect("Failed to connect");
// Empty message queue;
while webtile.get_message().is_some() {}
// Log in (to a user called "Username", with a password "Password")
let game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
println!("{:?}", game_ids);
// Empty message queue;
while webtile.get_message().is_some() {}
}More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect");
// Log in (to a user called "Username", with a password "Password")
let _game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
webtile
.start_game_seeded("seeded-web-trunk", "1", true, "b", "i", "b")
.expect("Failed to start game");
webtile.save_game().expect("Failed to save the game.");
webtile
.continue_game("dcss-web-trunk")
.expect("Failed to continue game");
webtile.quit_game().expect("Failed to quit the game.");
// Empty message queue (would be used to process the info);
while webtile.get_message().is_some() {}
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Get cookie from the game
let cookie = webtile.request_cookie().unwrap();
// Disconnect from DCSS Webtile
webtile.disconnect().expect("Failed to disconnect.");
// Connect (again) to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Login with cookie
let _gameid = webtile
.login_with_cookie(cookie.as_str())
.expect("Failed to login");
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Write RC File
webtile
.set_rc_file("seeded-web-trunk", "show_more = false\nrest_delay = -1")
.expect("Failed to set RC file.");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Read RC File
let rc_file = webtile
.get_rc_file("seeded-web-trunk")
.expect("Failed to get RC file.");
print!("RC FILE: \n\n {}", rc_file);
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Start game
webtile
.write_json(json!({"msg": "play", "game_id": "seeded-web-trunk"}))
.expect("");
webtile.read_until("player", None, None).expect("");
webtile.write_key("-").expect("");
webtile.read_until("ui-state-sync", None, None).expect("");
webtile.write_key("1").expect("");
webtile.write_key("\t\t\t \r").expect("");
webtile.read_until("ui-push", None, None).expect("");
webtile.write_key("b").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile
.read_until("input_mode", Some("mode"), Some(1))
.expect("");
webtile.write_key("6").expect("");
webtile.write_key("i").expect("");
webtile.write_key("a").expect("");
webtile.write_key("d").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile.write_key("d").expect("");
webtile.write_key(",").expect("");
match webtile.read_until("ignore", None, None) {
Ok(_) => (),
Err(e) => match e {
Error::Blocking(BlockingError::Pickup) => print!("PICKUP"),
Error::Blocking(BlockingError::Died) => print!("PICKUP"),
_ => panic!("Unexpected Error"),
},
};
}Login to the game, using a cookie. It returns a vector of all playable game IDs.
Arguments
cookie- A string slice of the user’s cookie (received previously).
Example
// Login under the user "Username", with a cookie
webtile.login_with_cookie("Username%123456789123456789123456789")?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Get cookie from the game
let cookie = webtile.request_cookie().unwrap();
// Disconnect from DCSS Webtile
webtile.disconnect().expect("Failed to disconnect.");
// Connect (again) to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Login with cookie
let _gameid = webtile
.login_with_cookie(cookie.as_str())
.expect("Failed to login");
}Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Get cookie from the game
let cookie = webtile.request_cookie().unwrap();
// Disconnect from DCSS Webtile
webtile.disconnect().expect("Failed to disconnect.");
// Connect (again) to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Login with cookie
let _gameid = webtile
.login_with_cookie(cookie.as_str())
.expect("Failed to login");
}sourcepub fn get_rc_file(&mut self, game_id: &str) -> Result<String, Error>
pub fn get_rc_file(&mut self, game_id: &str) -> Result<String, Error>
Get the RC file content of a specific game ID.
Arguments
game_id- A string slice of the game’s ID.
Example
webtile.get_rc_file("dcss-web-trunk")?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Write RC File
webtile
.set_rc_file("seeded-web-trunk", "show_more = false\nrest_delay = -1")
.expect("Failed to set RC file.");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Read RC File
let rc_file = webtile
.get_rc_file("seeded-web-trunk")
.expect("Failed to get RC file.");
print!("RC FILE: \n\n {}", rc_file);
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}sourcepub fn set_rc_file(&mut self, game_id: &str, content: &str) -> Result<(), Error>
pub fn set_rc_file(&mut self, game_id: &str, content: &str) -> Result<(), Error>
Set the RC file content of a specific game ID.
Arguments
game_id- A string slice of the game’s ID.content- A string slice of the content to write to the RC file.
Example
webtile..set_rc_file("dcss-web-trunk", "show_more = false\nrest_delay = -1")?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Write RC File
webtile
.set_rc_file("seeded-web-trunk", "show_more = false\nrest_delay = -1")
.expect("Failed to set RC file.");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Read RC File
let rc_file = webtile
.get_rc_file("seeded-web-trunk")
.expect("Failed to get RC file.");
print!("RC FILE: \n\n {}", rc_file);
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}source§impl Webtile
impl Webtile
sourcepub fn start_game(
&mut self,
game_id: &str,
species: &str,
background: &str,
weapon: &str
) -> Result<(), Error>
pub fn start_game( &mut self, game_id: &str, species: &str, background: &str, weapon: &str ) -> Result<(), Error>
Start an unseeded game by selecting the game_id and the character’s specifications.
Arguments
game_id- A string slice of the game’s ID.species- A string slice for the character’s species.background- A string slice for the character’s background.weapon- A string slice for the character’s weapon.
Example
// Start a game on "dcss-web-trunk", for a Minotaur (b), Berserker (i), with a mace (b)
webtile.start_game("dcss-web-trunk", "b", "i", "b")?;sourcepub fn continue_game(&mut self, game_id: &str) -> Result<(), Error>
pub fn continue_game(&mut self, game_id: &str) -> Result<(), Error>
Continue a saved game by selecting it’s game ID.
Arguments
game_id- A string slice of the game’s ID.
Example
// Start a game on "dcss-web-trunk", for a Minotaur (b), Berserker (i), with a mace (b)
webtile.continue_game("dcss-web-trunk")?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect");
// Log in (to a user called "Username", with a password "Password")
let _game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
webtile
.start_game_seeded("seeded-web-trunk", "1", true, "b", "i", "b")
.expect("Failed to start game");
webtile.save_game().expect("Failed to save the game.");
webtile
.continue_game("dcss-web-trunk")
.expect("Failed to continue game");
webtile.quit_game().expect("Failed to quit the game.");
// Empty message queue (would be used to process the info);
while webtile.get_message().is_some() {}
}sourcepub fn start_game_seeded(
&mut self,
game_id: &str,
seed: &str,
pregenerate: bool,
species: &str,
background: &str,
weapon: &str
) -> Result<(), Error>
pub fn start_game_seeded( &mut self, game_id: &str, seed: &str, pregenerate: bool, species: &str, background: &str, weapon: &str ) -> Result<(), Error>
Start an seeded game by selecting the game_id, the seed and the character’s specifications.
Arguments
game_id- A string slice of the game’s ID.seed- A string slice of the game’s seed.pregenerate- A bool on if the pregeneration option should be selected.species- A string slice for the character’s species.background- A string slice for the character’s background.weapon- A string slice for the character’s weapon.
Example
// Start a game on "dcss-web-trunk", for the "123" seed (pregenerated) for a
// Minotaur (b), Berserker (i), with a mace (b)
webtile.start_game_seeded("dcss-web-trunk", "123", true, "b", "i", "b")?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect");
// Log in (to a user called "Username", with a password "Password")
let _game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
webtile
.start_game_seeded("seeded-web-trunk", "1", true, "b", "i", "b")
.expect("Failed to start game");
webtile.save_game().expect("Failed to save the game.");
webtile
.continue_game("dcss-web-trunk")
.expect("Failed to continue game");
webtile.quit_game().expect("Failed to quit the game.");
// Empty message queue (would be used to process the info);
while webtile.get_message().is_some() {}
}sourcepub fn save_game(&mut self) -> Result<(), Error>
pub fn save_game(&mut self) -> Result<(), Error>
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect");
// Log in (to a user called "Username", with a password "Password")
let _game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
webtile
.start_game_seeded("seeded-web-trunk", "1", true, "b", "i", "b")
.expect("Failed to start game");
webtile.save_game().expect("Failed to save the game.");
webtile
.continue_game("dcss-web-trunk")
.expect("Failed to continue game");
webtile.quit_game().expect("Failed to quit the game.");
// Empty message queue (would be used to process the info);
while webtile.get_message().is_some() {}
}sourcepub fn quit_game(&mut self) -> Result<(), Error>
pub fn quit_game(&mut self) -> Result<(), Error>
Quit the game (same result as dying), by sending a “CTRL + Q” and answering yes.
Example
webtile.quit_game()?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect");
// Log in (to a user called "Username", with a password "Password")
let _game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
webtile
.start_game_seeded("seeded-web-trunk", "1", true, "b", "i", "b")
.expect("Failed to start game");
webtile.save_game().expect("Failed to save the game.");
webtile
.continue_game("dcss-web-trunk")
.expect("Failed to continue game");
webtile.quit_game().expect("Failed to quit the game.");
// Empty message queue (would be used to process the info);
while webtile.get_message().is_some() {}
}source§impl Webtile
impl Webtile
sourcepub fn connect(
url: &str,
speed_ms: usize,
_version: &str
) -> Result<Self, Error>
pub fn connect( url: &str, speed_ms: usize, _version: &str ) -> Result<Self, Error>
Connects to a websocket URL, prepares the decompressor (using flate2::Decompress) and returns a Webtile connection object.
Arguments
url- A &str that holds thews://orwss://URLspeed_ms- A usize that depicts the speed limit in milliseconds between each command sent to DCSS Webtiles._version- Currently a placeholder for the version number of DCSS, in case the API changes in the future.
Example
let mut webtile = Webtile::connect("ws://localhost:8080/socket", 100, "0.29")?;Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 50, "0.29").expect("Failed to connect");
// Empty message queue;
while webtile.get_message().is_some() {}
// Log in (to a user called "Username", with a password "Password")
let game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
println!("{:?}", game_ids);
// Empty message queue;
while webtile.get_message().is_some() {}
}More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect");
// Log in (to a user called "Username", with a password "Password")
let _game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
webtile
.start_game_seeded("seeded-web-trunk", "1", true, "b", "i", "b")
.expect("Failed to start game");
webtile.save_game().expect("Failed to save the game.");
webtile
.continue_game("dcss-web-trunk")
.expect("Failed to continue game");
webtile.quit_game().expect("Failed to quit the game.");
// Empty message queue (would be used to process the info);
while webtile.get_message().is_some() {}
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Get cookie from the game
let cookie = webtile.request_cookie().unwrap();
// Disconnect from DCSS Webtile
webtile.disconnect().expect("Failed to disconnect.");
// Connect (again) to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Login with cookie
let _gameid = webtile
.login_with_cookie(cookie.as_str())
.expect("Failed to login");
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Write RC File
webtile
.set_rc_file("seeded-web-trunk", "show_more = false\nrest_delay = -1")
.expect("Failed to set RC file.");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Read RC File
let rc_file = webtile
.get_rc_file("seeded-web-trunk")
.expect("Failed to get RC file.");
print!("RC FILE: \n\n {}", rc_file);
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Start game
webtile
.write_json(json!({"msg": "play", "game_id": "seeded-web-trunk"}))
.expect("");
webtile.read_until("player", None, None).expect("");
webtile.write_key("-").expect("");
webtile.read_until("ui-state-sync", None, None).expect("");
webtile.write_key("1").expect("");
webtile.write_key("\t\t\t \r").expect("");
webtile.read_until("ui-push", None, None).expect("");
webtile.write_key("b").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile
.read_until("input_mode", Some("mode"), Some(1))
.expect("");
webtile.write_key("6").expect("");
webtile.write_key("i").expect("");
webtile.write_key("a").expect("");
webtile.write_key("d").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile.write_key("d").expect("");
webtile.write_key(",").expect("");
match webtile.read_until("ignore", None, None) {
Ok(_) => (),
Err(e) => match e {
Error::Blocking(BlockingError::Pickup) => print!("PICKUP"),
Error::Blocking(BlockingError::Died) => print!("PICKUP"),
_ => panic!("Unexpected Error"),
},
};
}sourcepub fn disconnect(&mut self) -> Result<(), Error>
pub fn disconnect(&mut self) -> Result<(), Error>
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Get cookie from the game
let cookie = webtile.request_cookie().unwrap();
// Disconnect from DCSS Webtile
webtile.disconnect().expect("Failed to disconnect.");
// Connect (again) to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Login with cookie
let _gameid = webtile
.login_with_cookie(cookie.as_str())
.expect("Failed to login");
}sourcepub fn read_until(
&mut self,
msg: &str,
key: Option<&str>,
value: Option<u64>
) -> Result<(), Error>
pub fn read_until( &mut self, msg: &str, key: Option<&str>, value: Option<u64> ) -> Result<(), Error>
Read the websocket messages until a specified message is found. Stores the
messages in a VecDeque that can be accessed by the user through the
Webtile::get_message() function. Any known blocking message (e.g.
a ‘more’ log statement) will return a api_errors::BlockingError.
Will block forever if the expected message never comes.
Arguments
msg- A &str that holds the value expected in the “msg” field of any returned message.key- A optional &str with the name of the specific key in the json data to search for.value- A optional u64 with the value of thekey, only if u64. Specifically meant to distinguish between types of “modes” for the input_mode.
Example
// Read until the "close_all_menu" message is received
webtile.read_until("close_all_menus", None, None)
// Read until the "input_mode" message is received, with mode == 1
webtile.read_until("input_mode", Some("mode"), Some(1))Examples found in repository?
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Start game
webtile
.write_json(json!({"msg": "play", "game_id": "seeded-web-trunk"}))
.expect("");
webtile.read_until("player", None, None).expect("");
webtile.write_key("-").expect("");
webtile.read_until("ui-state-sync", None, None).expect("");
webtile.write_key("1").expect("");
webtile.write_key("\t\t\t \r").expect("");
webtile.read_until("ui-push", None, None).expect("");
webtile.write_key("b").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile
.read_until("input_mode", Some("mode"), Some(1))
.expect("");
webtile.write_key("6").expect("");
webtile.write_key("i").expect("");
webtile.write_key("a").expect("");
webtile.write_key("d").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile.write_key("d").expect("");
webtile.write_key(",").expect("");
match webtile.read_until("ignore", None, None) {
Ok(_) => (),
Err(e) => match e {
Error::Blocking(BlockingError::Pickup) => print!("PICKUP"),
Error::Blocking(BlockingError::Died) => print!("PICKUP"),
_ => panic!("Unexpected Error"),
},
};
}sourcepub fn write_json(&mut self, json_val: Value) -> Result<(), Error>
pub fn write_json(&mut self, json_val: Value) -> Result<(), Error>
Write a serde_json::Value to the websocket. Will only send if sufficient time has
elapsed since the last sent data, according to the Webtile::connect speed_ms option.
Arguments
json_val- A serde_json::Value to send to DCSS Webtiles.
Example
// Send the login command
webtile.write_json(json!({
"msg": "login",
"username": "Username",
"password": "Password",
}))?;Examples found in repository?
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Start game
webtile
.write_json(json!({"msg": "play", "game_id": "seeded-web-trunk"}))
.expect("");
webtile.read_until("player", None, None).expect("");
webtile.write_key("-").expect("");
webtile.read_until("ui-state-sync", None, None).expect("");
webtile.write_key("1").expect("");
webtile.write_key("\t\t\t \r").expect("");
webtile.read_until("ui-push", None, None).expect("");
webtile.write_key("b").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile
.read_until("input_mode", Some("mode"), Some(1))
.expect("");
webtile.write_key("6").expect("");
webtile.write_key("i").expect("");
webtile.write_key("a").expect("");
webtile.write_key("d").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile.write_key("d").expect("");
webtile.write_key(",").expect("");
match webtile.read_until("ignore", None, None) {
Ok(_) => (),
Err(e) => match e {
Error::Blocking(BlockingError::Pickup) => print!("PICKUP"),
Error::Blocking(BlockingError::Died) => print!("PICKUP"),
_ => panic!("Unexpected Error"),
},
};
}sourcepub fn write_key(&mut self, key: &str) -> Result<(), Error>
pub fn write_key(&mut self, key: &str) -> Result<(), Error>
Write a string slice (passed through [common::keys]) to the websocket. Special
characters starting with key_ will be sent as a keycode (e.g. key_esc will
send the esc character). Will only send if sufficient time has elapsed since
the last sent data, according to the Webtile::connect speed_ms option.
Special keys:
- CTRL+char =
key_ctrl_atokey_ctrl_z - Special chars =
key_tab,key_escandkey_enter - Cardinal directions:
key_dir_n,key_dir_ne,key_dir_e,key_dir_se,key_dir_s,key_dir_sw,key_dir_wandkey_dir_nw - Stairs:
key_stair_downandkey_stair_up
Arguments
key- A string slice to be sent to DCSS (passed through [common::keys]).
Example
// Send the `esc` key
webtile.write_key("key_esc")
// Send the 'a' key
webtile.write_key("a")
// Send a string of keys that will move left, open a menu and drop an item (slot a)
webtile.write_key("6iad")Examples found in repository?
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Start game
webtile
.write_json(json!({"msg": "play", "game_id": "seeded-web-trunk"}))
.expect("");
webtile.read_until("player", None, None).expect("");
webtile.write_key("-").expect("");
webtile.read_until("ui-state-sync", None, None).expect("");
webtile.write_key("1").expect("");
webtile.write_key("\t\t\t \r").expect("");
webtile.read_until("ui-push", None, None).expect("");
webtile.write_key("b").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile
.read_until("input_mode", Some("mode"), Some(1))
.expect("");
webtile.write_key("6").expect("");
webtile.write_key("i").expect("");
webtile.write_key("a").expect("");
webtile.write_key("d").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile.write_key("d").expect("");
webtile.write_key(",").expect("");
match webtile.read_until("ignore", None, None) {
Ok(_) => (),
Err(e) => match e {
Error::Blocking(BlockingError::Pickup) => print!("PICKUP"),
Error::Blocking(BlockingError::Died) => print!("PICKUP"),
_ => panic!("Unexpected Error"),
},
};
}sourcepub fn get_message(&mut self) -> Option<Value>
pub fn get_message(&mut self) -> Option<Value>
Get the messages received by the DCSS Webtile (as serde_json::Value), in order of reception. Will return None if the queue is empty.
Example
// Print the messages received, until the queue is empty
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 50, "0.29").expect("Failed to connect");
// Empty message queue;
while webtile.get_message().is_some() {}
// Log in (to a user called "Username", with a password "Password")
let game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
println!("{:?}", game_ids);
// Empty message queue;
while webtile.get_message().is_some() {}
}More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect");
// Log in (to a user called "Username", with a password "Password")
let _game_ids = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
webtile
.start_game_seeded("seeded-web-trunk", "1", true, "b", "i", "b")
.expect("Failed to start game");
webtile.save_game().expect("Failed to save the game.");
webtile
.continue_game("dcss-web-trunk")
.expect("Failed to continue game");
webtile.quit_game().expect("Failed to quit the game.");
// Empty message queue (would be used to process the info);
while webtile.get_message().is_some() {}
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Get cookie from the game
let cookie = webtile.request_cookie().unwrap();
// Disconnect from DCSS Webtile
webtile.disconnect().expect("Failed to disconnect.");
// Connect (again) to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Login with cookie
let _gameid = webtile
.login_with_cookie(cookie.as_str())
.expect("Failed to login");
}5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Write RC File
webtile
.set_rc_file("seeded-web-trunk", "show_more = false\nrest_delay = -1")
.expect("Failed to set RC file.");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Read RC File
let rc_file = webtile
.get_rc_file("seeded-web-trunk")
.expect("Failed to get RC file.");
print!("RC FILE: \n\n {}", rc_file);
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
}7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
// Connect to DCSS Webtile
let mut webtile =
Webtile::connect("ws://localhost:8080/socket", 100, "0.29").expect("Failed to connect");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Log in (to a user called "Username", with a password "Password")
let _gameid = webtile
.login_with_credentials("Username", "Password")
.expect("Failed to login");
// Print the messages you get upon connecting
while let Some(message) = webtile.get_message() {
println!("{:?}", message)
}
// Start game
webtile
.write_json(json!({"msg": "play", "game_id": "seeded-web-trunk"}))
.expect("");
webtile.read_until("player", None, None).expect("");
webtile.write_key("-").expect("");
webtile.read_until("ui-state-sync", None, None).expect("");
webtile.write_key("1").expect("");
webtile.write_key("\t\t\t \r").expect("");
webtile.read_until("ui-push", None, None).expect("");
webtile.write_key("b").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile
.read_until("input_mode", Some("mode"), Some(1))
.expect("");
webtile.write_key("6").expect("");
webtile.write_key("i").expect("");
webtile.write_key("a").expect("");
webtile.write_key("d").expect("");
webtile.write_key("i").expect("");
webtile.write_key("b").expect("");
webtile.write_key("d").expect("");
webtile.write_key(",").expect("");
match webtile.read_until("ignore", None, None) {
Ok(_) => (),
Err(e) => match e {
Error::Blocking(BlockingError::Pickup) => print!("PICKUP"),
Error::Blocking(BlockingError::Died) => print!("PICKUP"),
_ => panic!("Unexpected Error"),
},
};
}