pub struct ApiClient {
pub session_id: Option<String>,
pub matchmaker_token: Option<String>,
/* private fields */
}Expand description
Statefull, non-blocking nakama client. Works as a state machine - all calls are non-blocking, but may modify some internal ApiClient state and therefore results of other calls in the future.
Fields§
§session_id: Option<String>§matchmaker_token: Option<String>Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn new(key: &str, server: &str, port: u32, protocol: &str) -> ApiClient
pub fn new(key: &str, server: &str, port: u32, protocol: &str) -> ApiClient
Examples found in repository?
More examples
examples/leaderboard.rs (line 7)
6fn main() {
7 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
8
9 client.register("email@provider.com", "password", "Leader");
10
11 while client.in_progress() {
12 client.tick()
13 }
14
15 client.write_leaderboard_record("wins", 1);
16
17 while client.in_progress() {
18 client.tick()
19 }
20
21 client.list_leaderboard_records("wins");
22
23 while client.in_progress() {
24 client.tick()
25 }
26
27 if let Some(leaderboard) = client.leaderboard_records("wins") {
28 for record in &leaderboard.records {
29 println!("{:?}", record);
30 }
31 }
32}examples/matchmaker.rs (line 22)
20fn match_rank_range() {
21 let mut clients: Vec<ApiClient> = (1..5).map(|_| {
22 ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http")
23 }).collect();
24
25 clients.iter_mut().enumerate().for_each(|(i, client)| {
26 client.register(&format!("email{}@provider.com", i), "password", &format!("Player{}", i));
27 });
28
29 tick_clients(&mut clients);
30
31 println!("Client 1 with rank 5 searching for a match with rank between 3 and 7");
32 let mut matchmaker = Matchmaker::new();
33 matchmaker
34 .add_numeric_property("rank", 5.0)
35 .add_query_item(&QueryItemBuilder::new("rank").geq(3).required().build())
36 .add_query_item(&QueryItemBuilder::new("rank").leq(7).required().build());
37
38 println!("Client 2 with rank 4 searching for a match with rank between 2 and 6");
39 let mut matchmaker2 = Matchmaker::new();
40 matchmaker2
41 .add_numeric_property("rank", 4.0)
42 .add_query_item(&QueryItemBuilder::new("rank").geq(2).required().build())
43 .add_query_item(&QueryItemBuilder::new("rank").leq(6).required().build());
44
45 println!("Client 3 with rank 10 searching for a match with rank between 8 and 12");
46 let mut matchmaker3 = Matchmaker::new();
47 matchmaker3
48 .add_numeric_property("rank", 10.0)
49 .add_query_item(&QueryItemBuilder::new("rank").geq(8).required().build())
50 .add_query_item(&QueryItemBuilder::new("rank").leq(12).required().build());
51
52 println!("Client 4 with rank 9 searching for a match with rank between 7 and 11");
53 let mut matchmaker4 = Matchmaker::new();
54 matchmaker4
55 .add_numeric_property("rank", 9.0)
56 .add_query_item(&QueryItemBuilder::new("rank").geq(7).required().build())
57 .add_query_item(&QueryItemBuilder::new("rank").leq(11).required().build());
58
59 clients[0].socket_add_matchmaker(&matchmaker);
60 clients[1].socket_add_matchmaker(&matchmaker2);
61 clients[2].socket_add_matchmaker(&matchmaker3);
62 clients[3].socket_add_matchmaker(&matchmaker4);
63
64 wait_tokens(&mut clients) ;
65
66 assert_eq!(clients[0].matchmaker_token, clients[1].matchmaker_token);
67 println!("Successfully ranked the clients with rank 4 and 5");
68 assert_eq!(clients[2].matchmaker_token, clients[3].matchmaker_token);
69 println!("Successfully ranked the clients with rank 9 and 10");
70}
71
72fn match_region() {
73 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
74 let mut client2 = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
75
76 client.register("email1@provider.com", "password", "Player1");
77 client2.register("email2@provider.com", "password", "Player2");
78
79 while client.in_progress() {
80 client.tick()
81 }
82
83 while client2.in_progress() {
84 client2.tick()
85 }
86
87 println!("Both clients Searching for a match in Europe");
88 let mut matchmaker = Matchmaker::new();
89 matchmaker
90 .add_string_property("region", "Europe")
91 .add_query_item(&QueryItemBuilder::new("region").term("Europe").required().build());
92
93 client.socket_add_matchmaker(&matchmaker);
94 client2.socket_add_matchmaker(&matchmaker);
95
96 while client.matchmaker_token.is_none() || client2.matchmaker_token.is_none() {
97 client.tick();
98 client2.tick();
99 }
100
101 assert_eq!(client.matchmaker_token, client2.matchmaker_token);
102 println!("Both clients found a match in Europe");
103}Sourcepub fn in_progress(&self) -> bool
pub fn in_progress(&self) -> bool
Examples found in repository?
examples/matchmaker.rs (line 5)
4fn tick_clients(clients: &mut Vec<ApiClient>) {
5 while clients.iter().any(|client| client.in_progress()) {
6 clients.iter_mut().for_each(|client| {
7 client.tick();
8 })
9 }
10}
11
12fn wait_tokens(clients: &mut Vec<ApiClient>) {
13 while clients.iter().any(|client| client.matchmaker_token.is_none()) {
14 clients.iter_mut().for_each(|client| {
15 client.tick();
16 })
17 }
18}
19
20fn match_rank_range() {
21 let mut clients: Vec<ApiClient> = (1..5).map(|_| {
22 ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http")
23 }).collect();
24
25 clients.iter_mut().enumerate().for_each(|(i, client)| {
26 client.register(&format!("email{}@provider.com", i), "password", &format!("Player{}", i));
27 });
28
29 tick_clients(&mut clients);
30
31 println!("Client 1 with rank 5 searching for a match with rank between 3 and 7");
32 let mut matchmaker = Matchmaker::new();
33 matchmaker
34 .add_numeric_property("rank", 5.0)
35 .add_query_item(&QueryItemBuilder::new("rank").geq(3).required().build())
36 .add_query_item(&QueryItemBuilder::new("rank").leq(7).required().build());
37
38 println!("Client 2 with rank 4 searching for a match with rank between 2 and 6");
39 let mut matchmaker2 = Matchmaker::new();
40 matchmaker2
41 .add_numeric_property("rank", 4.0)
42 .add_query_item(&QueryItemBuilder::new("rank").geq(2).required().build())
43 .add_query_item(&QueryItemBuilder::new("rank").leq(6).required().build());
44
45 println!("Client 3 with rank 10 searching for a match with rank between 8 and 12");
46 let mut matchmaker3 = Matchmaker::new();
47 matchmaker3
48 .add_numeric_property("rank", 10.0)
49 .add_query_item(&QueryItemBuilder::new("rank").geq(8).required().build())
50 .add_query_item(&QueryItemBuilder::new("rank").leq(12).required().build());
51
52 println!("Client 4 with rank 9 searching for a match with rank between 7 and 11");
53 let mut matchmaker4 = Matchmaker::new();
54 matchmaker4
55 .add_numeric_property("rank", 9.0)
56 .add_query_item(&QueryItemBuilder::new("rank").geq(7).required().build())
57 .add_query_item(&QueryItemBuilder::new("rank").leq(11).required().build());
58
59 clients[0].socket_add_matchmaker(&matchmaker);
60 clients[1].socket_add_matchmaker(&matchmaker2);
61 clients[2].socket_add_matchmaker(&matchmaker3);
62 clients[3].socket_add_matchmaker(&matchmaker4);
63
64 wait_tokens(&mut clients) ;
65
66 assert_eq!(clients[0].matchmaker_token, clients[1].matchmaker_token);
67 println!("Successfully ranked the clients with rank 4 and 5");
68 assert_eq!(clients[2].matchmaker_token, clients[3].matchmaker_token);
69 println!("Successfully ranked the clients with rank 9 and 10");
70}
71
72fn match_region() {
73 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
74 let mut client2 = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
75
76 client.register("email1@provider.com", "password", "Player1");
77 client2.register("email2@provider.com", "password", "Player2");
78
79 while client.in_progress() {
80 client.tick()
81 }
82
83 while client2.in_progress() {
84 client2.tick()
85 }
86
87 println!("Both clients Searching for a match in Europe");
88 let mut matchmaker = Matchmaker::new();
89 matchmaker
90 .add_string_property("region", "Europe")
91 .add_query_item(&QueryItemBuilder::new("region").term("Europe").required().build());
92
93 client.socket_add_matchmaker(&matchmaker);
94 client2.socket_add_matchmaker(&matchmaker);
95
96 while client.matchmaker_token.is_none() || client2.matchmaker_token.is_none() {
97 client.tick();
98 client2.tick();
99 }
100
101 assert_eq!(client.matchmaker_token, client2.matchmaker_token);
102 println!("Both clients found a match in Europe");
103}More examples
examples/leaderboard.rs (line 11)
6fn main() {
7 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
8
9 client.register("email@provider.com", "password", "Leader");
10
11 while client.in_progress() {
12 client.tick()
13 }
14
15 client.write_leaderboard_record("wins", 1);
16
17 while client.in_progress() {
18 client.tick()
19 }
20
21 client.list_leaderboard_records("wins");
22
23 while client.in_progress() {
24 client.tick()
25 }
26
27 if let Some(leaderboard) = client.leaderboard_records("wins") {
28 for record in &leaderboard.records {
29 println!("{:?}", record);
30 }
31 }
32}pub fn authenticate(&mut self, email: &str, password: &str)
Sourcepub fn register(&mut self, email: &str, password: &str, username: &str)
pub fn register(&mut self, email: &str, password: &str, username: &str)
Examples found in repository?
More examples
examples/leaderboard.rs (line 9)
6fn main() {
7 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
8
9 client.register("email@provider.com", "password", "Leader");
10
11 while client.in_progress() {
12 client.tick()
13 }
14
15 client.write_leaderboard_record("wins", 1);
16
17 while client.in_progress() {
18 client.tick()
19 }
20
21 client.list_leaderboard_records("wins");
22
23 while client.in_progress() {
24 client.tick()
25 }
26
27 if let Some(leaderboard) = client.leaderboard_records("wins") {
28 for record in &leaderboard.records {
29 println!("{:?}", record);
30 }
31 }
32}examples/matchmaker.rs (line 26)
20fn match_rank_range() {
21 let mut clients: Vec<ApiClient> = (1..5).map(|_| {
22 ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http")
23 }).collect();
24
25 clients.iter_mut().enumerate().for_each(|(i, client)| {
26 client.register(&format!("email{}@provider.com", i), "password", &format!("Player{}", i));
27 });
28
29 tick_clients(&mut clients);
30
31 println!("Client 1 with rank 5 searching for a match with rank between 3 and 7");
32 let mut matchmaker = Matchmaker::new();
33 matchmaker
34 .add_numeric_property("rank", 5.0)
35 .add_query_item(&QueryItemBuilder::new("rank").geq(3).required().build())
36 .add_query_item(&QueryItemBuilder::new("rank").leq(7).required().build());
37
38 println!("Client 2 with rank 4 searching for a match with rank between 2 and 6");
39 let mut matchmaker2 = Matchmaker::new();
40 matchmaker2
41 .add_numeric_property("rank", 4.0)
42 .add_query_item(&QueryItemBuilder::new("rank").geq(2).required().build())
43 .add_query_item(&QueryItemBuilder::new("rank").leq(6).required().build());
44
45 println!("Client 3 with rank 10 searching for a match with rank between 8 and 12");
46 let mut matchmaker3 = Matchmaker::new();
47 matchmaker3
48 .add_numeric_property("rank", 10.0)
49 .add_query_item(&QueryItemBuilder::new("rank").geq(8).required().build())
50 .add_query_item(&QueryItemBuilder::new("rank").leq(12).required().build());
51
52 println!("Client 4 with rank 9 searching for a match with rank between 7 and 11");
53 let mut matchmaker4 = Matchmaker::new();
54 matchmaker4
55 .add_numeric_property("rank", 9.0)
56 .add_query_item(&QueryItemBuilder::new("rank").geq(7).required().build())
57 .add_query_item(&QueryItemBuilder::new("rank").leq(11).required().build());
58
59 clients[0].socket_add_matchmaker(&matchmaker);
60 clients[1].socket_add_matchmaker(&matchmaker2);
61 clients[2].socket_add_matchmaker(&matchmaker3);
62 clients[3].socket_add_matchmaker(&matchmaker4);
63
64 wait_tokens(&mut clients) ;
65
66 assert_eq!(clients[0].matchmaker_token, clients[1].matchmaker_token);
67 println!("Successfully ranked the clients with rank 4 and 5");
68 assert_eq!(clients[2].matchmaker_token, clients[3].matchmaker_token);
69 println!("Successfully ranked the clients with rank 9 and 10");
70}
71
72fn match_region() {
73 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
74 let mut client2 = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
75
76 client.register("email1@provider.com", "password", "Player1");
77 client2.register("email2@provider.com", "password", "Player2");
78
79 while client.in_progress() {
80 client.tick()
81 }
82
83 while client2.in_progress() {
84 client2.tick()
85 }
86
87 println!("Both clients Searching for a match in Europe");
88 let mut matchmaker = Matchmaker::new();
89 matchmaker
90 .add_string_property("region", "Europe")
91 .add_query_item(&QueryItemBuilder::new("region").term("Europe").required().build());
92
93 client.socket_add_matchmaker(&matchmaker);
94 client2.socket_add_matchmaker(&matchmaker);
95
96 while client.matchmaker_token.is_none() || client2.matchmaker_token.is_none() {
97 client.tick();
98 client2.tick();
99 }
100
101 assert_eq!(client.matchmaker_token, client2.matchmaker_token);
102 println!("Both clients found a match in Europe");
103}pub fn rpc(&mut self, name: &str, body: &str)
pub fn logout(&mut self)
pub fn authenticated(&self) -> bool
Sourcepub fn write_leaderboard_record(&mut self, leaderboard_id: &str, score: i32)
pub fn write_leaderboard_record(&mut self, leaderboard_id: &str, score: i32)
Examples found in repository?
examples/leaderboard.rs (line 15)
6fn main() {
7 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
8
9 client.register("email@provider.com", "password", "Leader");
10
11 while client.in_progress() {
12 client.tick()
13 }
14
15 client.write_leaderboard_record("wins", 1);
16
17 while client.in_progress() {
18 client.tick()
19 }
20
21 client.list_leaderboard_records("wins");
22
23 while client.in_progress() {
24 client.tick()
25 }
26
27 if let Some(leaderboard) = client.leaderboard_records("wins") {
28 for record in &leaderboard.records {
29 println!("{:?}", record);
30 }
31 }
32}Sourcepub fn list_leaderboard_records(&mut self, leaderboard_id: &str)
pub fn list_leaderboard_records(&mut self, leaderboard_id: &str)
Examples found in repository?
examples/leaderboard.rs (line 21)
6fn main() {
7 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
8
9 client.register("email@provider.com", "password", "Leader");
10
11 while client.in_progress() {
12 client.tick()
13 }
14
15 client.write_leaderboard_record("wins", 1);
16
17 while client.in_progress() {
18 client.tick()
19 }
20
21 client.list_leaderboard_records("wins");
22
23 while client.in_progress() {
24 client.tick()
25 }
26
27 if let Some(leaderboard) = client.leaderboard_records("wins") {
28 for record in &leaderboard.records {
29 println!("{:?}", record);
30 }
31 }
32}Sourcepub fn leaderboard_records(
&self,
leaderboard_id: &str,
) -> Option<Rc<ApiLeaderboardRecordList>>
pub fn leaderboard_records( &self, leaderboard_id: &str, ) -> Option<Rc<ApiLeaderboardRecordList>>
Examples found in repository?
examples/leaderboard.rs (line 27)
6fn main() {
7 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
8
9 client.register("email@provider.com", "password", "Leader");
10
11 while client.in_progress() {
12 client.tick()
13 }
14
15 client.write_leaderboard_record("wins", 1);
16
17 while client.in_progress() {
18 client.tick()
19 }
20
21 client.list_leaderboard_records("wins");
22
23 while client.in_progress() {
24 client.tick()
25 }
26
27 if let Some(leaderboard) = client.leaderboard_records("wins") {
28 for record in &leaderboard.records {
29 println!("{:?}", record);
30 }
31 }
32}pub fn try_recv(&mut self) -> Option<Event>
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Examples found in repository?
examples/matchmaker.rs (line 7)
4fn tick_clients(clients: &mut Vec<ApiClient>) {
5 while clients.iter().any(|client| client.in_progress()) {
6 clients.iter_mut().for_each(|client| {
7 client.tick();
8 })
9 }
10}
11
12fn wait_tokens(clients: &mut Vec<ApiClient>) {
13 while clients.iter().any(|client| client.matchmaker_token.is_none()) {
14 clients.iter_mut().for_each(|client| {
15 client.tick();
16 })
17 }
18}
19
20fn match_rank_range() {
21 let mut clients: Vec<ApiClient> = (1..5).map(|_| {
22 ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http")
23 }).collect();
24
25 clients.iter_mut().enumerate().for_each(|(i, client)| {
26 client.register(&format!("email{}@provider.com", i), "password", &format!("Player{}", i));
27 });
28
29 tick_clients(&mut clients);
30
31 println!("Client 1 with rank 5 searching for a match with rank between 3 and 7");
32 let mut matchmaker = Matchmaker::new();
33 matchmaker
34 .add_numeric_property("rank", 5.0)
35 .add_query_item(&QueryItemBuilder::new("rank").geq(3).required().build())
36 .add_query_item(&QueryItemBuilder::new("rank").leq(7).required().build());
37
38 println!("Client 2 with rank 4 searching for a match with rank between 2 and 6");
39 let mut matchmaker2 = Matchmaker::new();
40 matchmaker2
41 .add_numeric_property("rank", 4.0)
42 .add_query_item(&QueryItemBuilder::new("rank").geq(2).required().build())
43 .add_query_item(&QueryItemBuilder::new("rank").leq(6).required().build());
44
45 println!("Client 3 with rank 10 searching for a match with rank between 8 and 12");
46 let mut matchmaker3 = Matchmaker::new();
47 matchmaker3
48 .add_numeric_property("rank", 10.0)
49 .add_query_item(&QueryItemBuilder::new("rank").geq(8).required().build())
50 .add_query_item(&QueryItemBuilder::new("rank").leq(12).required().build());
51
52 println!("Client 4 with rank 9 searching for a match with rank between 7 and 11");
53 let mut matchmaker4 = Matchmaker::new();
54 matchmaker4
55 .add_numeric_property("rank", 9.0)
56 .add_query_item(&QueryItemBuilder::new("rank").geq(7).required().build())
57 .add_query_item(&QueryItemBuilder::new("rank").leq(11).required().build());
58
59 clients[0].socket_add_matchmaker(&matchmaker);
60 clients[1].socket_add_matchmaker(&matchmaker2);
61 clients[2].socket_add_matchmaker(&matchmaker3);
62 clients[3].socket_add_matchmaker(&matchmaker4);
63
64 wait_tokens(&mut clients) ;
65
66 assert_eq!(clients[0].matchmaker_token, clients[1].matchmaker_token);
67 println!("Successfully ranked the clients with rank 4 and 5");
68 assert_eq!(clients[2].matchmaker_token, clients[3].matchmaker_token);
69 println!("Successfully ranked the clients with rank 9 and 10");
70}
71
72fn match_region() {
73 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
74 let mut client2 = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
75
76 client.register("email1@provider.com", "password", "Player1");
77 client2.register("email2@provider.com", "password", "Player2");
78
79 while client.in_progress() {
80 client.tick()
81 }
82
83 while client2.in_progress() {
84 client2.tick()
85 }
86
87 println!("Both clients Searching for a match in Europe");
88 let mut matchmaker = Matchmaker::new();
89 matchmaker
90 .add_string_property("region", "Europe")
91 .add_query_item(&QueryItemBuilder::new("region").term("Europe").required().build());
92
93 client.socket_add_matchmaker(&matchmaker);
94 client2.socket_add_matchmaker(&matchmaker);
95
96 while client.matchmaker_token.is_none() || client2.matchmaker_token.is_none() {
97 client.tick();
98 client2.tick();
99 }
100
101 assert_eq!(client.matchmaker_token, client2.matchmaker_token);
102 println!("Both clients found a match in Europe");
103}More examples
examples/leaderboard.rs (line 12)
6fn main() {
7 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
8
9 client.register("email@provider.com", "password", "Leader");
10
11 while client.in_progress() {
12 client.tick()
13 }
14
15 client.write_leaderboard_record("wins", 1);
16
17 while client.in_progress() {
18 client.tick()
19 }
20
21 client.list_leaderboard_records("wins");
22
23 while client.in_progress() {
24 client.tick()
25 }
26
27 if let Some(leaderboard) = client.leaderboard_records("wins") {
28 for record in &leaderboard.records {
29 println!("{:?}", record);
30 }
31 }
32}pub fn match_id(&self) -> Option<String>
pub fn rpc_response(&self) -> Option<String>
Sourcepub fn socket_add_matchmaker(&mut self, matchmaker: &Matchmaker)
pub fn socket_add_matchmaker(&mut self, matchmaker: &Matchmaker)
Examples found in repository?
examples/matchmaker.rs (line 59)
20fn match_rank_range() {
21 let mut clients: Vec<ApiClient> = (1..5).map(|_| {
22 ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http")
23 }).collect();
24
25 clients.iter_mut().enumerate().for_each(|(i, client)| {
26 client.register(&format!("email{}@provider.com", i), "password", &format!("Player{}", i));
27 });
28
29 tick_clients(&mut clients);
30
31 println!("Client 1 with rank 5 searching for a match with rank between 3 and 7");
32 let mut matchmaker = Matchmaker::new();
33 matchmaker
34 .add_numeric_property("rank", 5.0)
35 .add_query_item(&QueryItemBuilder::new("rank").geq(3).required().build())
36 .add_query_item(&QueryItemBuilder::new("rank").leq(7).required().build());
37
38 println!("Client 2 with rank 4 searching for a match with rank between 2 and 6");
39 let mut matchmaker2 = Matchmaker::new();
40 matchmaker2
41 .add_numeric_property("rank", 4.0)
42 .add_query_item(&QueryItemBuilder::new("rank").geq(2).required().build())
43 .add_query_item(&QueryItemBuilder::new("rank").leq(6).required().build());
44
45 println!("Client 3 with rank 10 searching for a match with rank between 8 and 12");
46 let mut matchmaker3 = Matchmaker::new();
47 matchmaker3
48 .add_numeric_property("rank", 10.0)
49 .add_query_item(&QueryItemBuilder::new("rank").geq(8).required().build())
50 .add_query_item(&QueryItemBuilder::new("rank").leq(12).required().build());
51
52 println!("Client 4 with rank 9 searching for a match with rank between 7 and 11");
53 let mut matchmaker4 = Matchmaker::new();
54 matchmaker4
55 .add_numeric_property("rank", 9.0)
56 .add_query_item(&QueryItemBuilder::new("rank").geq(7).required().build())
57 .add_query_item(&QueryItemBuilder::new("rank").leq(11).required().build());
58
59 clients[0].socket_add_matchmaker(&matchmaker);
60 clients[1].socket_add_matchmaker(&matchmaker2);
61 clients[2].socket_add_matchmaker(&matchmaker3);
62 clients[3].socket_add_matchmaker(&matchmaker4);
63
64 wait_tokens(&mut clients) ;
65
66 assert_eq!(clients[0].matchmaker_token, clients[1].matchmaker_token);
67 println!("Successfully ranked the clients with rank 4 and 5");
68 assert_eq!(clients[2].matchmaker_token, clients[3].matchmaker_token);
69 println!("Successfully ranked the clients with rank 9 and 10");
70}
71
72fn match_region() {
73 let mut client = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
74 let mut client2 = ApiClient::new("defaultkey", "127.0.0.1", config::DEFAULT_PORT, "http");
75
76 client.register("email1@provider.com", "password", "Player1");
77 client2.register("email2@provider.com", "password", "Player2");
78
79 while client.in_progress() {
80 client.tick()
81 }
82
83 while client2.in_progress() {
84 client2.tick()
85 }
86
87 println!("Both clients Searching for a match in Europe");
88 let mut matchmaker = Matchmaker::new();
89 matchmaker
90 .add_string_property("region", "Europe")
91 .add_query_item(&QueryItemBuilder::new("region").term("Europe").required().build());
92
93 client.socket_add_matchmaker(&matchmaker);
94 client2.socket_add_matchmaker(&matchmaker);
95
96 while client.matchmaker_token.is_none() || client2.matchmaker_token.is_none() {
97 client.tick();
98 client2.tick();
99 }
100
101 assert_eq!(client.matchmaker_token, client2.matchmaker_token);
102 println!("Both clients found a match in Europe");
103}pub fn socket_create_match(&mut self) -> u32
pub fn socket_join_match_by_id(&mut self, match_id: &str) -> u32
pub fn socket_join_match_by_token(&mut self, token_id: &str) -> u32
pub fn socket_leave_match(&mut self) -> u32
pub fn socket_send<T: SerBin>(&mut self, opcode: i32, data: &T)
pub fn socket_response(&self, cid: u32) -> Option<SocketEvent>
pub fn error(&self) -> Option<String>
Auto Trait Implementations§
impl Freeze for ApiClient
impl !RefUnwindSafe for ApiClient
impl !Send for ApiClient
impl !Sync for ApiClient
impl Unpin for ApiClient
impl !UnwindSafe for ApiClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more