Skip to main content

nil_client/
request.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use crate::client::Client;
5use crate::error::Result;
6use nil_payload::request::prelude::*;
7use nil_payload::response::prelude::*;
8
9pub trait Request {
10  type Response;
11
12  async fn send(self, client: &Client) -> Result<Self::Response>;
13}
14
15macro_rules! impl_request {
16  (function = $fun:ident, request = $req:ty, response = $res:ty) => {
17    impl Request for $req {
18      type Response = $res;
19
20      async fn send(self, client: &Client) -> Result<Self::Response> {
21        client.$fun(self).await
22      }
23    }
24  };
25}
26
27macro_rules! dispatch {
28  ($($name:ident),+) => {
29    paste::paste! {
30      $(
31        impl_request!(
32          function = $name,
33          request = [<$name:camel Request>],
34          response = [<$name:camel Response>]
35        );
36      )+
37    }
38  };
39}
40
41macro_rules! dispatch_unit {
42  ($($name:ident),+) => {
43    paste::paste! {
44      $(
45        impl_request!(
46          function = $name,
47          request = [<$name:camel Request>],
48          response = ()
49        );
50      )+
51    }
52  };
53}
54
55dispatch!(
56  authorize,
57  cheat_get_academy_recruit_queue,
58  cheat_get_academy_recruit_queues,
59  cheat_get_all_academy_recruit_queues,
60  cheat_get_all_prefecture_build_queues,
61  cheat_get_all_stable_recruit_queues,
62  cheat_get_build_steps,
63  cheat_get_cities,
64  cheat_get_city,
65  cheat_get_ethics,
66  cheat_get_idle_armies_at,
67  cheat_get_idle_personnel_at,
68  cheat_get_infrastructure,
69  cheat_get_maneuvers,
70  cheat_get_maneuvers_of,
71  cheat_get_player,
72  cheat_get_players,
73  cheat_get_prefecture_build_queue,
74  cheat_get_prefecture_build_queues,
75  cheat_get_resources,
76  cheat_get_stable_recruit_queue,
77  cheat_get_stable_recruit_queues,
78  cheat_get_storage_capacity,
79  cheat_spawn_bot,
80  create_remote_world,
81  get_academy_recruit_catalog,
82  get_armies,
83  get_army,
84  get_army_owner,
85  get_bot_coords,
86  get_chat_history,
87  get_cities,
88  get_city,
89  get_city_score,
90  get_continent_size,
91  get_idle_armies_at,
92  get_idle_armies_coords,
93  get_maneuver,
94  get_market,
95  get_market_fee,
96  get_player,
97  get_player_coords,
98  get_player_ids,
99  get_player_maintenance,
100  get_player_military,
101  get_player_status,
102  get_player_storage_capacity,
103  get_player_worlds,
104  get_precursor_coords,
105  get_prefecture_build_catalog,
106  get_public_bot,
107  get_public_bots,
108  get_public_cities,
109  get_public_city,
110  get_public_field,
111  get_public_fields,
112  get_public_player,
113  get_public_players,
114  get_public_precursor,
115  get_public_precursors,
116  get_rank,
117  get_ranking,
118  get_remote_world,
119  get_round,
120  get_stable_recruit_catalog,
121  get_workshop_recruit_catalog,
122  get_world_bots,
123  get_world_config,
124  get_world_personnel,
125  get_world_players,
126  get_world_precursors,
127  get_world_rulers,
128  get_world_stats,
129  player_exists,
130  push_chat_message,
131  request_maneuver,
132  search_city,
133  search_public_city,
134  set_player_ready,
135  simulate_battle,
136  start_round,
137  user_exists,
138  validate_token
139);
140
141dispatch_unit!(
142  add_academy_recruit_order,
143  add_prefecture_build_order,
144  add_stable_recruit_order,
145  add_workshop_recruit_order,
146  cancel_academy_recruit_order,
147  cancel_maneuver,
148  cancel_prefecture_build_order,
149  cancel_stable_recruit_order,
150  cancel_workshop_recruit_order,
151  cheat_fill_world,
152  cheat_skip_round,
153  cheat_set_bot_ethics,
154  cheat_set_building_level,
155  cheat_set_food,
156  cheat_set_iron,
157  cheat_set_market_fee,
158  cheat_set_max_food,
159  cheat_set_max_infrastructure,
160  cheat_set_max_iron,
161  cheat_set_max_resources,
162  cheat_set_max_silo_resources,
163  cheat_set_max_stone,
164  cheat_set_max_warehouse_resources,
165  cheat_set_max_wood,
166  cheat_set_resources,
167  cheat_set_stability,
168  cheat_set_stone,
169  cheat_set_wood,
170  cheat_spawn_city,
171  cheat_spawn_personnel,
172  delete_remote_world,
173  create_user,
174  forward_report,
175  rename_city,
176  save_local_world,
177  send_resources,
178  set_player_status,
179  spawn_player,
180  toggle_building
181);