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>, Box<Error>>
pub fn login_with_credentials( &mut self, username: &str, password: &str, ) -> Result<Vec<String>, Box<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?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Write RC File
22 webtile
23 .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1")
24 .expect("Failed to set RC file.");
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Read RC File
30 let rc_file = webtile
31 .get_rc_file("dcss-0.32")
32 .expect("Failed to get RC file.");
33
34 print!("RC FILE: \n\n {}\n\n", rc_file);
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
More examples
8fn main() {
9 // Connect to DCSS Webtile
10 let mut webtile =
11 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
22 webtile
23 .start_game_seeded(&gameid[0], "1", false, "b", "f", "b")
24 .expect("Failed to start game");
25
26 // Process the messages
27 while let Some(message) = webtile.get_message() {
28 processor(&message);
29 }
30
31 // Depending on what is found in the "map" data, a move up may make sense (up to the
32 // bot to decide this) -- note this may if a north wall exists (no bot intelligence here).
33 write_key_bot(&mut webtile, "key_dir_n", "player").expect("Failed");
34 write_key_bot(&mut webtile, "key_dir_s", "player").expect("Failed");
35
36 // Quit game (same as dying)
37 webtile.quit_game().expect("Failed to quit");
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Get cookie from the game
22 let cookie = webtile.request_cookie().unwrap();
23
24 println!("{}", cookie);
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Disconnect from DCSS Webtile
30 webtile.disconnect().expect("Failed to disconnect.");
31
32 // Connect (again) to DCSS Webtile
33 let mut webtile =
34 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Login with cookie
40 let _gameid = webtile
41 .login_with_cookie(cookie.as_str())
42 .expect("Failed to login");
43
44 // Empty message queue;
45 while webtile.get_message().is_some() {}
46
47 // Disconnect from DCSS Webtile
48 webtile.disconnect().expect("Failed to disconnect.");
49}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Print the game id's that can be started
19 println!("{:?}", gameid);
20
21 // Empty message queue;
22 while webtile.get_message().is_some() {}
23
24 // Start a random game (seed `0`) on 'dcss-0.32', for Minotaur berserker with a mace.
25 webtile
26 .start_game_seeded(&gameid[0], "0", false, "b", "f", "b")
27 .expect("Failed to start game");
28
29 // Print the messages you get upon starting the game (should be processed)
30 while let Some(message) = webtile.get_message() {
31 println!("{:?}", message)
32 }
33
34 // Move up and back
35 webtile.write_key("key_dir_n").expect("Failed to write key");
36 webtile.write_key("key_dir_s").expect("Failed to write key");
37
38 // Print the messages you while moving (should be processed)
39 while let Some(message) = webtile.get_message() {
40 println!("{:?}", message)
41 }
42
43 // Quit game (same as dying)
44 webtile.quit_game().expect("Failed to quit");
45
46 // Print the messages after you quit game
47 while let Some(message) = webtile.get_message() {
48 println!("{:?}", message)
49 }
50
51 // Disconnect from webtile
52 webtile.disconnect().expect("Failed to disconnect");
53}
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}
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?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Get cookie from the game
22 let cookie = webtile.request_cookie().unwrap();
23
24 println!("{}", cookie);
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Disconnect from DCSS Webtile
30 webtile.disconnect().expect("Failed to disconnect.");
31
32 // Connect (again) to DCSS Webtile
33 let mut webtile =
34 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Login with cookie
40 let _gameid = webtile
41 .login_with_cookie(cookie.as_str())
42 .expect("Failed to login");
43
44 // Empty message queue;
45 while webtile.get_message().is_some() {}
46
47 // Disconnect from DCSS Webtile
48 webtile.disconnect().expect("Failed to disconnect.");
49}
Sourcepub fn register_account(
&mut self,
username: &str,
password: &str,
email: Option<&str>,
) -> Result<Vec<String>, Box<Error>>
pub fn register_account( &mut self, username: &str, password: &str, email: Option<&str>, ) -> Result<Vec<String>, Box<Error>>
Create an account and login to the game, using a username and password. It returns a vector of all playable game IDs. If the account exists, it will simply login using the provided password.
§Arguments
username
- A string slice of the user’s username.password
- A string slice of the user’s password.email
- A optional string slice of the user’s email.
§Example
// Register and login under the user "Username", with a password of "Password"
webtile.register_account("Username", "Password", None)?;
Examples found in repository?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Register usernames for tests
14 webtile
15 .register_account("Username", "Password", None)
16 .expect("Failed to register");
17
18 // For "log in" test
19 for i in 1..4 {
20 webtile
21 .register_account(format!("Username{i}").as_str(), "Password", None)
22 .expect("Failed to register");
23 }
24
25 // For "tiles" test
26 for i in 1..4 {
27 webtile
28 .register_account(format!("Tiles{i}").as_str(), "Password", None)
29 .expect("Failed to register");
30 }
31
32 // For "monsters" test
33 for i in 1..10 {
34 webtile
35 .register_account(format!("Monsters{i}").as_str(), "Password", None)
36 .expect("Failed to register");
37 }
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
Examples found in repository?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Get cookie from the game
22 let cookie = webtile.request_cookie().unwrap();
23
24 println!("{}", cookie);
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Disconnect from DCSS Webtile
30 webtile.disconnect().expect("Failed to disconnect.");
31
32 // Connect (again) to DCSS Webtile
33 let mut webtile =
34 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Login with cookie
40 let _gameid = webtile
41 .login_with_cookie(cookie.as_str())
42 .expect("Failed to login");
43
44 // Empty message queue;
45 while webtile.get_message().is_some() {}
46
47 // Disconnect from DCSS Webtile
48 webtile.disconnect().expect("Failed to disconnect.");
49}
Sourcepub fn get_rc_file(&mut self, game_id: &str) -> Result<String, Box<Error>>
pub fn get_rc_file(&mut self, game_id: &str) -> Result<String, Box<Error>>
Get the RC file content for 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?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Write RC File
22 webtile
23 .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1")
24 .expect("Failed to set RC file.");
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Read RC File
30 let rc_file = webtile
31 .get_rc_file("dcss-0.32")
32 .expect("Failed to get RC file.");
33
34 print!("RC FILE: \n\n {}\n\n", rc_file);
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
Sourcepub fn set_rc_file(
&mut self,
game_id: &str,
content: &str,
) -> Result<(), Box<Error>>
pub fn set_rc_file( &mut self, game_id: &str, content: &str, ) -> Result<(), Box<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?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Write RC File
22 webtile
23 .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1")
24 .expect("Failed to set RC file.");
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Read RC File
30 let rc_file = webtile
31 .get_rc_file("dcss-0.32")
32 .expect("Failed to get RC file.");
33
34 print!("RC FILE: \n\n {}\n\n", rc_file);
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
Source§impl Webtile
impl Webtile
Sourcepub fn start_game(
&mut self,
game_id: &str,
species: &str,
background: &str,
weapon: &str,
) -> Result<(), Box<Error>>
pub fn start_game( &mut self, game_id: &str, species: &str, background: &str, weapon: &str, ) -> Result<(), Box<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 (f), with a mace (b)
webtile.start_game("dcss-web-trunk", "b", "f", "b")?;
Examples found in repository?
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}
Sourcepub fn start_game_seeded(
&mut self,
game_id: &str,
seed: &str,
pregenerate: bool,
species: &str,
background: &str,
weapon: &str,
) -> Result<(), Box<Error>>
pub fn start_game_seeded( &mut self, game_id: &str, seed: &str, pregenerate: bool, species: &str, background: &str, weapon: &str, ) -> Result<(), Box<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", "f", "b")?;
Examples found in repository?
8fn main() {
9 // Connect to DCSS Webtile
10 let mut webtile =
11 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
22 webtile
23 .start_game_seeded(&gameid[0], "1", false, "b", "f", "b")
24 .expect("Failed to start game");
25
26 // Process the messages
27 while let Some(message) = webtile.get_message() {
28 processor(&message);
29 }
30
31 // Depending on what is found in the "map" data, a move up may make sense (up to the
32 // bot to decide this) -- note this may if a north wall exists (no bot intelligence here).
33 write_key_bot(&mut webtile, "key_dir_n", "player").expect("Failed");
34 write_key_bot(&mut webtile, "key_dir_s", "player").expect("Failed");
35
36 // Quit game (same as dying)
37 webtile.quit_game().expect("Failed to quit");
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
More examples
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Print the game id's that can be started
19 println!("{:?}", gameid);
20
21 // Empty message queue;
22 while webtile.get_message().is_some() {}
23
24 // Start a random game (seed `0`) on 'dcss-0.32', for Minotaur berserker with a mace.
25 webtile
26 .start_game_seeded(&gameid[0], "0", false, "b", "f", "b")
27 .expect("Failed to start game");
28
29 // Print the messages you get upon starting the game (should be processed)
30 while let Some(message) = webtile.get_message() {
31 println!("{:?}", message)
32 }
33
34 // Move up and back
35 webtile.write_key("key_dir_n").expect("Failed to write key");
36 webtile.write_key("key_dir_s").expect("Failed to write key");
37
38 // Print the messages you while moving (should be processed)
39 while let Some(message) = webtile.get_message() {
40 println!("{:?}", message)
41 }
42
43 // Quit game (same as dying)
44 webtile.quit_game().expect("Failed to quit");
45
46 // Print the messages after you quit game
47 while let Some(message) = webtile.get_message() {
48 println!("{:?}", message)
49 }
50
51 // Disconnect from webtile
52 webtile.disconnect().expect("Failed to disconnect");
53}
Sourcepub fn quit_game(&mut self) -> Result<(), Box<Error>>
pub fn quit_game(&mut self) -> Result<(), Box<Error>>
Quit the game (same result as dying), by sending a CTRL + Q
and
answering yes
.
§Example
webtile.quit_game()?;
Examples found in repository?
8fn main() {
9 // Connect to DCSS Webtile
10 let mut webtile =
11 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
22 webtile
23 .start_game_seeded(&gameid[0], "1", false, "b", "f", "b")
24 .expect("Failed to start game");
25
26 // Process the messages
27 while let Some(message) = webtile.get_message() {
28 processor(&message);
29 }
30
31 // Depending on what is found in the "map" data, a move up may make sense (up to the
32 // bot to decide this) -- note this may if a north wall exists (no bot intelligence here).
33 write_key_bot(&mut webtile, "key_dir_n", "player").expect("Failed");
34 write_key_bot(&mut webtile, "key_dir_s", "player").expect("Failed");
35
36 // Quit game (same as dying)
37 webtile.quit_game().expect("Failed to quit");
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
More examples
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Print the game id's that can be started
19 println!("{:?}", gameid);
20
21 // Empty message queue;
22 while webtile.get_message().is_some() {}
23
24 // Start a random game (seed `0`) on 'dcss-0.32', for Minotaur berserker with a mace.
25 webtile
26 .start_game_seeded(&gameid[0], "0", false, "b", "f", "b")
27 .expect("Failed to start game");
28
29 // Print the messages you get upon starting the game (should be processed)
30 while let Some(message) = webtile.get_message() {
31 println!("{:?}", message)
32 }
33
34 // Move up and back
35 webtile.write_key("key_dir_n").expect("Failed to write key");
36 webtile.write_key("key_dir_s").expect("Failed to write key");
37
38 // Print the messages you while moving (should be processed)
39 while let Some(message) = webtile.get_message() {
40 println!("{:?}", message)
41 }
42
43 // Quit game (same as dying)
44 webtile.quit_game().expect("Failed to quit");
45
46 // Print the messages after you quit game
47 while let Some(message) = webtile.get_message() {
48 println!("{:?}", message)
49 }
50
51 // Disconnect from webtile
52 webtile.disconnect().expect("Failed to disconnect");
53}
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}
Source§impl Webtile
impl Webtile
Sourcepub fn connect(
url: &str,
speed_ms: u32,
_version: &str,
) -> Result<Self, Box<Error>>
pub fn connect( url: &str, speed_ms: u32, _version: &str, ) -> Result<Self, Box<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 u32 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?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Register usernames for tests
14 webtile
15 .register_account("Username", "Password", None)
16 .expect("Failed to register");
17
18 // For "log in" test
19 for i in 1..4 {
20 webtile
21 .register_account(format!("Username{i}").as_str(), "Password", None)
22 .expect("Failed to register");
23 }
24
25 // For "tiles" test
26 for i in 1..4 {
27 webtile
28 .register_account(format!("Tiles{i}").as_str(), "Password", None)
29 .expect("Failed to register");
30 }
31
32 // For "monsters" test
33 for i in 1..10 {
34 webtile
35 .register_account(format!("Monsters{i}").as_str(), "Password", None)
36 .expect("Failed to register");
37 }
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
More examples
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Write RC File
22 webtile
23 .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1")
24 .expect("Failed to set RC file.");
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Read RC File
30 let rc_file = webtile
31 .get_rc_file("dcss-0.32")
32 .expect("Failed to get RC file.");
33
34 print!("RC FILE: \n\n {}\n\n", rc_file);
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
8fn main() {
9 // Connect to DCSS Webtile
10 let mut webtile =
11 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
22 webtile
23 .start_game_seeded(&gameid[0], "1", false, "b", "f", "b")
24 .expect("Failed to start game");
25
26 // Process the messages
27 while let Some(message) = webtile.get_message() {
28 processor(&message);
29 }
30
31 // Depending on what is found in the "map" data, a move up may make sense (up to the
32 // bot to decide this) -- note this may if a north wall exists (no bot intelligence here).
33 write_key_bot(&mut webtile, "key_dir_n", "player").expect("Failed");
34 write_key_bot(&mut webtile, "key_dir_s", "player").expect("Failed");
35
36 // Quit game (same as dying)
37 webtile.quit_game().expect("Failed to quit");
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Get cookie from the game
22 let cookie = webtile.request_cookie().unwrap();
23
24 println!("{}", cookie);
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Disconnect from DCSS Webtile
30 webtile.disconnect().expect("Failed to disconnect.");
31
32 // Connect (again) to DCSS Webtile
33 let mut webtile =
34 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Login with cookie
40 let _gameid = webtile
41 .login_with_cookie(cookie.as_str())
42 .expect("Failed to login");
43
44 // Empty message queue;
45 while webtile.get_message().is_some() {}
46
47 // Disconnect from DCSS Webtile
48 webtile.disconnect().expect("Failed to disconnect.");
49}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Print the game id's that can be started
19 println!("{:?}", gameid);
20
21 // Empty message queue;
22 while webtile.get_message().is_some() {}
23
24 // Start a random game (seed `0`) on 'dcss-0.32', for Minotaur berserker with a mace.
25 webtile
26 .start_game_seeded(&gameid[0], "0", false, "b", "f", "b")
27 .expect("Failed to start game");
28
29 // Print the messages you get upon starting the game (should be processed)
30 while let Some(message) = webtile.get_message() {
31 println!("{:?}", message)
32 }
33
34 // Move up and back
35 webtile.write_key("key_dir_n").expect("Failed to write key");
36 webtile.write_key("key_dir_s").expect("Failed to write key");
37
38 // Print the messages you while moving (should be processed)
39 while let Some(message) = webtile.get_message() {
40 println!("{:?}", message)
41 }
42
43 // Quit game (same as dying)
44 webtile.quit_game().expect("Failed to quit");
45
46 // Print the messages after you quit game
47 while let Some(message) = webtile.get_message() {
48 println!("{:?}", message)
49 }
50
51 // Disconnect from webtile
52 webtile.disconnect().expect("Failed to disconnect");
53}
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}
Sourcepub fn disconnect(&mut self) -> Result<(), Box<Error>>
pub fn disconnect(&mut self) -> Result<(), Box<Error>>
Examples found in repository?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Register usernames for tests
14 webtile
15 .register_account("Username", "Password", None)
16 .expect("Failed to register");
17
18 // For "log in" test
19 for i in 1..4 {
20 webtile
21 .register_account(format!("Username{i}").as_str(), "Password", None)
22 .expect("Failed to register");
23 }
24
25 // For "tiles" test
26 for i in 1..4 {
27 webtile
28 .register_account(format!("Tiles{i}").as_str(), "Password", None)
29 .expect("Failed to register");
30 }
31
32 // For "monsters" test
33 for i in 1..10 {
34 webtile
35 .register_account(format!("Monsters{i}").as_str(), "Password", None)
36 .expect("Failed to register");
37 }
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
More examples
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Write RC File
22 webtile
23 .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1")
24 .expect("Failed to set RC file.");
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Read RC File
30 let rc_file = webtile
31 .get_rc_file("dcss-0.32")
32 .expect("Failed to get RC file.");
33
34 print!("RC FILE: \n\n {}\n\n", rc_file);
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
8fn main() {
9 // Connect to DCSS Webtile
10 let mut webtile =
11 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
22 webtile
23 .start_game_seeded(&gameid[0], "1", false, "b", "f", "b")
24 .expect("Failed to start game");
25
26 // Process the messages
27 while let Some(message) = webtile.get_message() {
28 processor(&message);
29 }
30
31 // Depending on what is found in the "map" data, a move up may make sense (up to the
32 // bot to decide this) -- note this may if a north wall exists (no bot intelligence here).
33 write_key_bot(&mut webtile, "key_dir_n", "player").expect("Failed");
34 write_key_bot(&mut webtile, "key_dir_s", "player").expect("Failed");
35
36 // Quit game (same as dying)
37 webtile.quit_game().expect("Failed to quit");
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Get cookie from the game
22 let cookie = webtile.request_cookie().unwrap();
23
24 println!("{}", cookie);
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Disconnect from DCSS Webtile
30 webtile.disconnect().expect("Failed to disconnect.");
31
32 // Connect (again) to DCSS Webtile
33 let mut webtile =
34 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Login with cookie
40 let _gameid = webtile
41 .login_with_cookie(cookie.as_str())
42 .expect("Failed to login");
43
44 // Empty message queue;
45 while webtile.get_message().is_some() {}
46
47 // Disconnect from DCSS Webtile
48 webtile.disconnect().expect("Failed to disconnect.");
49}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Print the game id's that can be started
19 println!("{:?}", gameid);
20
21 // Empty message queue;
22 while webtile.get_message().is_some() {}
23
24 // Start a random game (seed `0`) on 'dcss-0.32', for Minotaur berserker with a mace.
25 webtile
26 .start_game_seeded(&gameid[0], "0", false, "b", "f", "b")
27 .expect("Failed to start game");
28
29 // Print the messages you get upon starting the game (should be processed)
30 while let Some(message) = webtile.get_message() {
31 println!("{:?}", message)
32 }
33
34 // Move up and back
35 webtile.write_key("key_dir_n").expect("Failed to write key");
36 webtile.write_key("key_dir_s").expect("Failed to write key");
37
38 // Print the messages you while moving (should be processed)
39 while let Some(message) = webtile.get_message() {
40 println!("{:?}", message)
41 }
42
43 // Quit game (same as dying)
44 webtile.quit_game().expect("Failed to quit");
45
46 // Print the messages after you quit game
47 while let Some(message) = webtile.get_message() {
48 println!("{:?}", message)
49 }
50
51 // Disconnect from webtile
52 webtile.disconnect().expect("Failed to disconnect");
53}
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}
Sourcepub fn read_until(
&mut self,
msg: &str,
key: Option<&str>,
value: Option<u64>,
) -> Result<(), Box<Error>>
pub fn read_until( &mut self, msg: &str, key: Option<&str>, value: Option<u64>, ) -> Result<(), Box<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?
43fn write_key_bot(
44 webtile: &mut Webtile,
45 to_send: &str,
46 to_receive: &str,
47) -> Result<(), Box<APIError>> {
48 println!("SEND: {}", to_send);
49
50 webtile.write_key(to_send)?;
51
52 // Make sure you verify for blocking errors;
53 if let Err(e) = webtile.read_until(to_receive, None, None) {
54 match *e {
55 APIError::Blocking(BlockingError::More) => webtile.write_key(" ")?,
56 APIError::Blocking(BlockingError::TextInput) => {
57 println!("ERROR: Likely level up choice");
58 }
59 APIError::Blocking(BlockingError::Pickup) => println!("ERROR: Pickup"),
60 APIError::Blocking(BlockingError::Acquirement(_)) => println!("ERROR: Acquirement"),
61 APIError::Blocking(BlockingError::Identify(_)) => println!("ERROR: Identify"),
62 APIError::Blocking(BlockingError::EnchantWeapon(_)) => println!("ERROR: EnchantWeapon"),
63 APIError::Blocking(BlockingError::EnchantItem(_)) => println!("ERROR: EnchantItem"),
64 APIError::Blocking(BlockingError::BrandWeapon(_)) => println!("ERROR: BrandWeapon"),
65 APIError::Blocking(BlockingError::Skill) => println!("ERROR: Skill"),
66 APIError::Blocking(BlockingError::Died) => {
67 println!("ERROR: Died");
68 process::exit(0);
69 }
70 _ => Err(e)?,
71 }
72 }
73
74 // Process the data based on what was done (e.g. new map revealed, health of player...)
75 while let Some(message) = webtile.get_message() {
76 processor(&message);
77 }
78
79 Ok(())
80}
More examples
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}
Sourcepub fn write_json(&mut self, json_val: Value) -> Result<(), Box<Error>>
pub fn write_json(&mut self, json_val: Value) -> Result<(), Box<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",
}))?;
Sourcepub fn write_key(&mut self, key: &str) -> Result<(), Box<Error>>
pub fn write_key(&mut self, key: &str) -> Result<(), Box<Error>>
Write a string slice (processed by the crate) 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_a
tokey_ctrl_z
- Special chars =
key_tab
,key_esc
andkey_enter
- Cardinal directions:
key_dir_n
,key_dir_ne
,key_dir_e
,key_dir_se
,key_dir_s
,key_dir_sw
,key_dir_w
andkey_dir_nw
- Stairs:
key_stair_down
andkey_stair_up
§Arguments
key
- A string slice to be sent to DCSS (after processing).
§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?
43fn write_key_bot(
44 webtile: &mut Webtile,
45 to_send: &str,
46 to_receive: &str,
47) -> Result<(), Box<APIError>> {
48 println!("SEND: {}", to_send);
49
50 webtile.write_key(to_send)?;
51
52 // Make sure you verify for blocking errors;
53 if let Err(e) = webtile.read_until(to_receive, None, None) {
54 match *e {
55 APIError::Blocking(BlockingError::More) => webtile.write_key(" ")?,
56 APIError::Blocking(BlockingError::TextInput) => {
57 println!("ERROR: Likely level up choice");
58 }
59 APIError::Blocking(BlockingError::Pickup) => println!("ERROR: Pickup"),
60 APIError::Blocking(BlockingError::Acquirement(_)) => println!("ERROR: Acquirement"),
61 APIError::Blocking(BlockingError::Identify(_)) => println!("ERROR: Identify"),
62 APIError::Blocking(BlockingError::EnchantWeapon(_)) => println!("ERROR: EnchantWeapon"),
63 APIError::Blocking(BlockingError::EnchantItem(_)) => println!("ERROR: EnchantItem"),
64 APIError::Blocking(BlockingError::BrandWeapon(_)) => println!("ERROR: BrandWeapon"),
65 APIError::Blocking(BlockingError::Skill) => println!("ERROR: Skill"),
66 APIError::Blocking(BlockingError::Died) => {
67 println!("ERROR: Died");
68 process::exit(0);
69 }
70 _ => Err(e)?,
71 }
72 }
73
74 // Process the data based on what was done (e.g. new map revealed, health of player...)
75 while let Some(message) = webtile.get_message() {
76 processor(&message);
77 }
78
79 Ok(())
80}
More examples
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Print the game id's that can be started
19 println!("{:?}", gameid);
20
21 // Empty message queue;
22 while webtile.get_message().is_some() {}
23
24 // Start a random game (seed `0`) on 'dcss-0.32', for Minotaur berserker with a mace.
25 webtile
26 .start_game_seeded(&gameid[0], "0", false, "b", "f", "b")
27 .expect("Failed to start game");
28
29 // Print the messages you get upon starting the game (should be processed)
30 while let Some(message) = webtile.get_message() {
31 println!("{:?}", message)
32 }
33
34 // Move up and back
35 webtile.write_key("key_dir_n").expect("Failed to write key");
36 webtile.write_key("key_dir_s").expect("Failed to write key");
37
38 // Print the messages you while moving (should be processed)
39 while let Some(message) = webtile.get_message() {
40 println!("{:?}", message)
41 }
42
43 // Quit game (same as dying)
44 webtile.quit_game().expect("Failed to quit");
45
46 // Print the messages after you quit game
47 while let Some(message) = webtile.get_message() {
48 println!("{:?}", message)
49 }
50
51 // Disconnect from webtile
52 webtile.disconnect().expect("Failed to disconnect");
53}
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}
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?
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Register usernames for tests
14 webtile
15 .register_account("Username", "Password", None)
16 .expect("Failed to register");
17
18 // For "log in" test
19 for i in 1..4 {
20 webtile
21 .register_account(format!("Username{i}").as_str(), "Password", None)
22 .expect("Failed to register");
23 }
24
25 // For "tiles" test
26 for i in 1..4 {
27 webtile
28 .register_account(format!("Tiles{i}").as_str(), "Password", None)
29 .expect("Failed to register");
30 }
31
32 // For "monsters" test
33 for i in 1..10 {
34 webtile
35 .register_account(format!("Monsters{i}").as_str(), "Password", None)
36 .expect("Failed to register");
37 }
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
More examples
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Write RC File
22 webtile
23 .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1")
24 .expect("Failed to set RC file.");
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Read RC File
30 let rc_file = webtile
31 .get_rc_file("dcss-0.32")
32 .expect("Failed to get RC file.");
33
34 print!("RC FILE: \n\n {}\n\n", rc_file);
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
8fn main() {
9 // Connect to DCSS Webtile
10 let mut webtile =
11 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
22 webtile
23 .start_game_seeded(&gameid[0], "1", false, "b", "f", "b")
24 .expect("Failed to start game");
25
26 // Process the messages
27 while let Some(message) = webtile.get_message() {
28 processor(&message);
29 }
30
31 // Depending on what is found in the "map" data, a move up may make sense (up to the
32 // bot to decide this) -- note this may if a north wall exists (no bot intelligence here).
33 write_key_bot(&mut webtile, "key_dir_n", "player").expect("Failed");
34 write_key_bot(&mut webtile, "key_dir_s", "player").expect("Failed");
35
36 // Quit game (same as dying)
37 webtile.quit_game().expect("Failed to quit");
38
39 // Disconnect from webtile
40 webtile.disconnect().expect("Failed to disconnect");
41}
42
43fn write_key_bot(
44 webtile: &mut Webtile,
45 to_send: &str,
46 to_receive: &str,
47) -> Result<(), Box<APIError>> {
48 println!("SEND: {}", to_send);
49
50 webtile.write_key(to_send)?;
51
52 // Make sure you verify for blocking errors;
53 if let Err(e) = webtile.read_until(to_receive, None, None) {
54 match *e {
55 APIError::Blocking(BlockingError::More) => webtile.write_key(" ")?,
56 APIError::Blocking(BlockingError::TextInput) => {
57 println!("ERROR: Likely level up choice");
58 }
59 APIError::Blocking(BlockingError::Pickup) => println!("ERROR: Pickup"),
60 APIError::Blocking(BlockingError::Acquirement(_)) => println!("ERROR: Acquirement"),
61 APIError::Blocking(BlockingError::Identify(_)) => println!("ERROR: Identify"),
62 APIError::Blocking(BlockingError::EnchantWeapon(_)) => println!("ERROR: EnchantWeapon"),
63 APIError::Blocking(BlockingError::EnchantItem(_)) => println!("ERROR: EnchantItem"),
64 APIError::Blocking(BlockingError::BrandWeapon(_)) => println!("ERROR: BrandWeapon"),
65 APIError::Blocking(BlockingError::Skill) => println!("ERROR: Skill"),
66 APIError::Blocking(BlockingError::Died) => {
67 println!("ERROR: Died");
68 process::exit(0);
69 }
70 _ => Err(e)?,
71 }
72 }
73
74 // Process the data based on what was done (e.g. new map revealed, health of player...)
75 while let Some(message) = webtile.get_message() {
76 processor(&message);
77 }
78
79 Ok(())
80}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let _gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Empty message queue;
19 while webtile.get_message().is_some() {}
20
21 // Get cookie from the game
22 let cookie = webtile.request_cookie().unwrap();
23
24 println!("{}", cookie);
25
26 // Empty message queue;
27 while webtile.get_message().is_some() {}
28
29 // Disconnect from DCSS Webtile
30 webtile.disconnect().expect("Failed to disconnect.");
31
32 // Connect (again) to DCSS Webtile
33 let mut webtile =
34 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
35
36 // Empty message queue;
37 while webtile.get_message().is_some() {}
38
39 // Login with cookie
40 let _gameid = webtile
41 .login_with_cookie(cookie.as_str())
42 .expect("Failed to login");
43
44 // Empty message queue;
45 while webtile.get_message().is_some() {}
46
47 // Disconnect from DCSS Webtile
48 webtile.disconnect().expect("Failed to disconnect.");
49}
5fn main() {
6 // Connect to DCSS Webtile
7 let mut webtile =
8 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
9
10 // Empty message queue;
11 while webtile.get_message().is_some() {}
12
13 // Log in (to a user called "Username", with a password "Password")
14 let gameid = webtile
15 .login_with_credentials("Username", "Password")
16 .expect("Failed to login");
17
18 // Print the game id's that can be started
19 println!("{:?}", gameid);
20
21 // Empty message queue;
22 while webtile.get_message().is_some() {}
23
24 // Start a random game (seed `0`) on 'dcss-0.32', for Minotaur berserker with a mace.
25 webtile
26 .start_game_seeded(&gameid[0], "0", false, "b", "f", "b")
27 .expect("Failed to start game");
28
29 // Print the messages you get upon starting the game (should be processed)
30 while let Some(message) = webtile.get_message() {
31 println!("{:?}", message)
32 }
33
34 // Move up and back
35 webtile.write_key("key_dir_n").expect("Failed to write key");
36 webtile.write_key("key_dir_s").expect("Failed to write key");
37
38 // Print the messages you while moving (should be processed)
39 while let Some(message) = webtile.get_message() {
40 println!("{:?}", message)
41 }
42
43 // Quit game (same as dying)
44 webtile.quit_game().expect("Failed to quit");
45
46 // Print the messages after you quit game
47 while let Some(message) = webtile.get_message() {
48 println!("{:?}", message)
49 }
50
51 // Disconnect from webtile
52 webtile.disconnect().expect("Failed to disconnect");
53}
6fn main() {
7 // Connect to DCSS Webtile
8 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 // Empty message queue;
12 while webtile.get_message().is_some() {}
13
14 // Log in (to a user called "Username", with a password "Password")
15 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 // Empty message queue;
20 while webtile.get_message().is_some() {}
21
22 // Start a random game on 'dcss-web-trunk', for Minotaur berserker with a mace.
23 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 // Print the messages you get upon starting the game (should be processed)
28 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 // Open inventory, drop everything
33 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 // Print the messages you get upon doing these actions (should be processed)
59 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 // Try to pick up what was dropped.
64 webtile.write_key(",").expect("");
65
66 // Normally when picking up ONE item on the ground, you would read until
67 // DCSS Webtiles returns a "input_mode" of mode = 1 (ready for input),
68 // but since there are two items on the ground, a menu will pop up so you can
69 // select the item to pick up(can't be easily anticipated, so dealt with using
70 // a BlockingError).
71 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); // Esc to ignore it
77 webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 // Print the messages you get upon picking up an item (should be processed)
86 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 // Quit game (same as dying)
91 webtile.quit_game().expect("Failed to quit");
92
93 // Print the messages after you quit game
94 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 // Disconnect from webtile
99 webtile.disconnect().expect("Failed to disconnect");
100}