Struct dcss_api::Webtile

source ·
pub struct Webtile { /* private fields */ }
Expand description

Webtile connection, using websocket (tungstenite) and a Deflate decoder (flate2).

Implementations§

source§

impl Webtile

source

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?
examples/get_playable_games.rs (line 15)
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
Hide additional examples
examples/basic.rs (line 17)
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)
    }
}
examples/start_game.rs (line 12)
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() {}
}
examples/cookie.rs (line 17)
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/rc_file.rs (line 17)
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)
    }
}
examples/blocking_error.rs (line 19)
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?
examples/cookie.rs (line 32)
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");
}

Request a cookie from the DCSS Webtile.

Example
webtile.request_cookie()?;
Examples found in repository?
examples/cookie.rs (line 21)
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");
}
source

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?
examples/rc_file.rs (line 32)
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

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?
examples/rc_file.rs (line 22)
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

source

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")?;
source

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?
examples/start_game.rs (line 22)
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

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?
examples/start_game.rs (line 16)
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

pub fn save_game(&mut self) -> Result<(), Error>

Save a game by sending the “CTRL + S” command.

Example
webtile.save_game()?;
Examples found in repository?
examples/start_game.rs (line 19)
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

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?
examples/start_game.rs (line 25)
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

source

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 the ws:// or wss:// URL
  • speed_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?
examples/get_playable_games.rs (line 8)
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
Hide additional examples
examples/basic.rs (line 8)
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)
    }
}
examples/start_game.rs (line 8)
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() {}
}
examples/cookie.rs (line 8)
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/rc_file.rs (line 8)
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)
    }
}
examples/blocking_error.rs (line 10)
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"),
        },
    };
}
source

pub fn disconnect(&mut self) -> Result<(), Error>

Close the websocket connection.

Example
webtile.disconnect()?;
Examples found in repository?
examples/cookie.rs (line 24)
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");
}
source

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 the key, 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?
examples/blocking_error.rs (line 31)
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"),
        },
    };
}
source

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
Example
// Send the login command
webtile.write_json(json!({
    "msg": "login",
    "username": "Username",
    "password": "Password",
}))?;
Examples found in repository?
examples/blocking_error.rs (line 29)
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"),
        },
    };
}
source

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_a to key_ctrl_z
  • Special chars = key_tab, key_esc and key_enter
  • Cardinal directions: key_dir_n, key_dir_ne, key_dir_e, key_dir_se, key_dir_s, key_dir_sw, key_dir_w and key_dir_nw
  • Stairs: key_stair_down and key_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?
examples/blocking_error.rs (line 32)
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"),
        },
    };
}
source

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?
examples/get_playable_games.rs (line 11)
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
Hide additional examples
examples/basic.rs (line 11)
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)
    }
}
examples/start_game.rs (line 28)
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() {}
}
examples/cookie.rs (line 11)
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/rc_file.rs (line 11)
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)
    }
}
examples/blocking_error.rs (line 13)
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"),
        },
    };
}

Trait Implementations§

source§

impl Debug for Webtile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Ungil for Twhere T: Send,