Skip to main content

nil_ffi/
lib.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4#![feature(nonpoison_mutex, sync_nonpoison)]
5#![expect(clippy::missing_safety_doc)]
6
7mod client;
8mod json;
9mod macros;
10mod queue;
11mod request;
12mod response;
13mod runtime;
14mod server;
15mod status;
16
17use crate::runtime::RUNTIME;
18use crate::server::SERVER;
19use client::CLIENT;
20use futures::future::BoxFuture;
21use json::serialize;
22use nil_core::event::Event;
23use std::ffi::{CString, c_char};
24use std::ptr;
25use tap::TryConv;
26
27pub use request::RequestId;
28pub use response::{Response, Result};
29pub use status::Status;
30
31///////////////////////////////
32//////////// FFI //////////////
33///////////////////////////////
34
35#[unsafe(no_mangle)]
36pub unsafe extern "C" fn nil_ffi_free_str(ptr: *mut c_char) {
37  if !ptr.is_null() {
38    drop(unsafe { CString::from_raw(ptr) });
39  }
40}
41
42#[unsafe(no_mangle)]
43pub unsafe extern "C" fn nil_ffi_poll(json_out: *mut *mut c_char) -> Status {
44  if json_out.is_null() {
45    return Status::ERR_NULL_POINTER;
46  }
47
48  unsafe { *json_out = ptr::null_mut() };
49
50  match queue::poll() {
51    Some(entry) => {
52      match serialize(&entry) {
53        Ok(json) => {
54          let json = CString::new(json).unwrap();
55          unsafe { *json_out = json.into_raw() };
56          Status::OK
57        }
58        Err(_) => Status::ERR_SERIALIZATION,
59      }
60    }
61    None => Status::ERR_NOTHING_TO_POLL,
62  }
63}
64
65#[unsafe(no_mangle)]
66pub unsafe extern "C" fn nil_ffi_shutdown() {
67  queue::clear();
68}
69
70#[unsafe(no_mangle)]
71pub unsafe extern "C" fn nil_ffi_version(request_id: RequestId) {
72  push_ok!(request_id, env!("CARGO_PKG_VERSION"));
73}
74
75///////////////////////////////
76//////////// SERVER ///////////
77///////////////////////////////
78
79#[unsafe(no_mangle)]
80pub unsafe extern "C" fn nil_is_host(request_id: RequestId) {
81  async_push_ok!(request_id, SERVER.read().await.is_some());
82}
83
84/// [`nil_server::local::start`]
85#[unsafe(no_mangle)]
86pub unsafe extern "C" fn nil_start_server(request_id: RequestId, json_options: *const c_char) {
87  let f = |options| {
88    RUNTIME.spawn(async move {
89      let result = server::start_with_options(options).await;
90      queue::push_result(request_id, Result::from(result));
91    });
92  };
93
94  unsafe { json::with_ptr(request_id, json_options, f) };
95}
96
97/// [`nil_server::local::load`]
98#[unsafe(no_mangle)]
99pub unsafe extern "C" fn nil_start_server_with_savedata(
100  request_id: RequestId,
101  json_path: *const c_char,
102) {
103  let f = |path| {
104    RUNTIME.spawn(async move {
105      let result = server::start_with_savedata(path).await;
106      queue::push_result(request_id, Result::from(result));
107    });
108  };
109
110  unsafe { json::with_ptr(request_id, json_path, f) };
111}
112
113/// [`LocalServer::stop`](nil_server::local::LocalServer::stop)
114#[unsafe(no_mangle)]
115pub unsafe extern "C" fn nil_stop_server(request_id: RequestId) {
116  RUNTIME.spawn(async move {
117    server::stop().await;
118    queue::push_ok(request_id, ());
119  });
120}
121
122///////////////////////////////
123//////////// CLIENT ///////////
124///////////////////////////////
125
126#[unsafe(no_mangle)]
127pub unsafe extern "C" fn nil_client_version(request_id: RequestId) {
128  push_ok!(request_id, nil_client::VERSION);
129}
130
131/// [`Client::is_local`](nil_client::Client::is_local)
132#[unsafe(no_mangle)]
133pub unsafe extern "C" fn nil_is_local(request_id: RequestId) {
134  async_push_ok!(request_id, CLIENT.read().await.is_local());
135}
136
137/// [`Client::is_ready`](nil_client::Client::is_ready)
138#[unsafe(no_mangle)]
139pub unsafe extern "C" fn nil_is_ready(request_id: RequestId) {
140  async_push_ok!(request_id, CLIENT.read().await.is_ready().await);
141}
142
143/// [`Client::is_remote`](nil_client::Client::is_remote)
144#[unsafe(no_mangle)]
145pub unsafe extern "C" fn nil_is_remote(request_id: RequestId) {
146  async_push_ok!(request_id, CLIENT.read().await.is_remote());
147}
148
149/// [`Client::server_addr`](nil_client::Client::server_addr)
150#[unsafe(no_mangle)]
151pub unsafe extern "C" fn nil_server_addr(request_id: RequestId) {
152  async_push_ok!(request_id, CLIENT.read().await.server_addr());
153}
154
155/// [`Client::set_user_agent`](nil_client::Client::set_user_agent)
156#[unsafe(no_mangle)]
157pub unsafe extern "C" fn nil_set_user_agent(request_id: RequestId, json_user_agent: *const c_char) {
158  let f = |user_agent: String| {
159    RUNTIME.spawn(async move {
160      CLIENT
161        .write()
162        .await
163        .set_user_agent(&user_agent);
164
165      queue::push_ok(request_id, ());
166    });
167  };
168
169  unsafe { json::with_ptr(request_id, json_user_agent, f) };
170}
171
172/// [`Client::stop`](nil_client::Client::stop)
173#[unsafe(no_mangle)]
174pub unsafe extern "C" fn nil_stop_client(request_id: RequestId) {
175  RUNTIME.spawn(async move {
176    CLIENT.write().await.stop().await;
177    queue::push_ok(request_id, ());
178  });
179}
180
181/// [`Client::update`](nil_client::Client::update)
182#[unsafe(no_mangle)]
183pub unsafe extern "C" fn nil_update_client(request_id: RequestId, json_options: *const c_char) {
184  let f = |options| {
185    type OnEvent = fn(Event) -> BoxFuture<'static, ()>;
186    RUNTIME.spawn(async move {
187      let result = CLIENT
188        .write()
189        .await
190        .update(options, None::<OnEvent>)
191        .await;
192
193      queue::push_result(request_id, Result::from(result));
194    });
195  };
196
197  unsafe { json::with_ptr(request_id, json_options, f) };
198}
199
200/// [`Client::user_agent`](nil_client::Client::user_agent)
201#[unsafe(no_mangle)]
202pub unsafe extern "C" fn nil_user_agent(request_id: RequestId) {
203  async_push_ok!(request_id, CLIENT.read().await.user_agent().to_owned());
204}
205
206/// [`Client::world`](nil_client::Client::world)
207#[unsafe(no_mangle)]
208pub unsafe extern "C" fn nil_world(request_id: RequestId) {
209  RUNTIME.spawn(async move {
210    match CLIENT.read().await.world() {
211      Some(world) => queue::push_ok(request_id, world),
212      None => queue::push_ok(request_id, None::<&str>),
213    }
214  });
215}
216
217///////////////////////////////
218/////////// RUNTIME ///////////
219///////////////////////////////
220
221/// [`RuntimeMetrics::global_queue_depth`](tokio::runtime::RuntimeMetrics::global_queue_depth)
222#[unsafe(no_mangle)]
223pub unsafe extern "C" fn nil_runtime_global_queue_depth(request_id: RequestId) {
224  push_result!(
225    request_id,
226    RUNTIME
227      .metrics()
228      .global_queue_depth()
229      .try_conv::<u32>()
230  );
231}
232
233/// [`RuntimeMetrics::num_alive_tasks`](tokio::runtime::RuntimeMetrics::num_alive_tasks)
234#[unsafe(no_mangle)]
235pub unsafe extern "C" fn nil_runtime_num_alive_tasks(request_id: RequestId) {
236  push_result!(
237    request_id,
238    RUNTIME
239      .metrics()
240      .num_alive_tasks()
241      .try_conv::<u32>()
242  );
243}
244
245/// [`RuntimeMetrics::num_workers`](tokio::runtime::RuntimeMetrics::num_workers)
246#[unsafe(no_mangle)]
247pub unsafe extern "C" fn nil_runtime_num_workers(request_id: RequestId) {
248  push_result!(
249    request_id,
250    RUNTIME
251      .metrics()
252      .num_workers()
253      .try_conv::<u32>()
254  );
255}
256
257///////////////////////////////
258////////// ENDPOINTS //////////
259///////////////////////////////
260
261/// [`Client::add_academy_recruit_order`](nil_client::Client::add_academy_recruit_order)
262#[unsafe(no_mangle)]
263pub unsafe extern "C" fn nil_add_academy_recruit_order(
264  request_id: RequestId,
265  json_req: *const c_char,
266) {
267  send!(request_id, add_academy_recruit_order, json_req);
268}
269
270/// [`Client::add_prefecture_build_order`](nil_client::Client::add_prefecture_build_order)
271#[unsafe(no_mangle)]
272pub unsafe extern "C" fn nil_add_prefecture_build_order(
273  request_id: RequestId,
274  json_req: *const c_char,
275) {
276  send!(request_id, add_prefecture_build_order, json_req);
277}
278
279/// [`Client::add_stable_recruit_order`](nil_client::Client::add_stable_recruit_order)
280#[unsafe(no_mangle)]
281pub unsafe extern "C" fn nil_add_stable_recruit_order(
282  request_id: RequestId,
283  json_req: *const c_char,
284) {
285  send!(request_id, add_stable_recruit_order, json_req);
286}
287
288/// [`Client::add_workshop_recruit_order`](nil_client::Client::add_workshop_recruit_order)
289#[unsafe(no_mangle)]
290pub unsafe extern "C" fn nil_add_workshop_recruit_order(
291  request_id: RequestId,
292  json_req: *const c_char,
293) {
294  send!(request_id, add_workshop_recruit_order, json_req);
295}
296
297/// [`Client::authorize`](nil_client::Client::authorize)
298#[unsafe(no_mangle)]
299pub unsafe extern "C" fn nil_authorize(request_id: RequestId, json_req: *const c_char) {
300  send!(request_id, authorize, json_req);
301}
302
303/// [`Client::cancel_academy_recruit_order`](nil_client::Client::cancel_academy_recruit_order)
304#[unsafe(no_mangle)]
305pub unsafe extern "C" fn nil_cancel_academy_recruit_order(
306  request_id: RequestId,
307  json_req: *const c_char,
308) {
309  send!(request_id, cancel_academy_recruit_order, json_req);
310}
311
312/// [`Client::cancel_maneuver`](nil_client::Client::cancel_maneuver)
313#[unsafe(no_mangle)]
314pub unsafe extern "C" fn nil_cancel_maneuver(request_id: RequestId, json_req: *const c_char) {
315  send!(request_id, cancel_maneuver, json_req);
316}
317
318/// [`Client::cancel_prefecture_build_order`](nil_client::Client::cancel_prefecture_build_order)
319#[unsafe(no_mangle)]
320pub unsafe extern "C" fn nil_cancel_prefecture_build_order(
321  request_id: RequestId,
322  json_req: *const c_char,
323) {
324  send!(request_id, cancel_prefecture_build_order, json_req);
325}
326
327/// [`Client::cancel_stable_recruit_order`](nil_client::Client::cancel_stable_recruit_order)
328#[unsafe(no_mangle)]
329pub unsafe extern "C" fn nil_cancel_stable_recruit_order(
330  request_id: RequestId,
331  json_req: *const c_char,
332) {
333  send!(request_id, cancel_stable_recruit_order, json_req);
334}
335
336/// [`Client::cancel_workshop_recruit_order`](nil_client::Client::cancel_workshop_recruit_order)
337#[unsafe(no_mangle)]
338pub unsafe extern "C" fn nil_cancel_workshop_recruit_order(
339  request_id: RequestId,
340  json_req: *const c_char,
341) {
342  send!(request_id, cancel_workshop_recruit_order, json_req);
343}
344
345/// [`Client::cheat_fill_world`](nil_client::Client::cheat_fill_world)
346#[unsafe(no_mangle)]
347pub unsafe extern "C" fn nil_cheat_fill_world(request_id: RequestId, json_req: *const c_char) {
348  send!(request_id, cheat_fill_world, json_req);
349}
350
351/// [`Client::cheat_get_academy_recruit_queue`](nil_client::Client::cheat_get_academy_recruit_queue)
352#[unsafe(no_mangle)]
353pub unsafe extern "C" fn nil_cheat_get_academy_recruit_queue(
354  request_id: RequestId,
355  json_req: *const c_char,
356) {
357  send!(request_id, cheat_get_academy_recruit_queue, json_req);
358}
359
360/// [`Client::cheat_get_academy_recruit_queues`](nil_client::Client::cheat_get_academy_recruit_queues)
361#[unsafe(no_mangle)]
362pub unsafe extern "C" fn nil_cheat_get_academy_recruit_queues(
363  request_id: RequestId,
364  json_req: *const c_char,
365) {
366  send!(request_id, cheat_get_academy_recruit_queues, json_req);
367}
368
369/// [`Client::cheat_get_all_academy_recruit_queues`](nil_client::Client::cheat_get_all_academy_recruit_queues)
370#[unsafe(no_mangle)]
371pub unsafe extern "C" fn nil_cheat_get_all_academy_recruit_queues(
372  request_id: RequestId,
373  json_req: *const c_char,
374) {
375  send!(request_id, cheat_get_all_academy_recruit_queues, json_req);
376}
377
378/// [`Client::cheat_get_all_prefecture_build_queues`](nil_client::Client::cheat_get_all_prefecture_build_queues)
379#[unsafe(no_mangle)]
380pub unsafe extern "C" fn nil_cheat_get_all_prefecture_build_queues(
381  request_id: RequestId,
382  json_req: *const c_char,
383) {
384  send!(request_id, cheat_get_all_prefecture_build_queues, json_req);
385}
386
387/// [`Client::cheat_get_all_stable_recruit_queues`](nil_client::Client::cheat_get_all_stable_recruit_queues)
388#[unsafe(no_mangle)]
389pub unsafe extern "C" fn nil_cheat_get_all_stable_recruit_queues(
390  request_id: RequestId,
391  json_req: *const c_char,
392) {
393  send!(request_id, cheat_get_all_stable_recruit_queues, json_req);
394}
395
396/// [`Client::cheat_get_build_steps`](nil_client::Client::cheat_get_build_steps)
397#[unsafe(no_mangle)]
398pub unsafe extern "C" fn nil_cheat_get_build_steps(request_id: RequestId, json_req: *const c_char) {
399  send!(request_id, cheat_get_build_steps, json_req);
400}
401
402/// [`Client::cheat_get_cities`](nil_client::Client::cheat_get_cities)
403#[unsafe(no_mangle)]
404pub unsafe extern "C" fn nil_cheat_get_cities(request_id: RequestId, json_req: *const c_char) {
405  send!(request_id, cheat_get_cities, json_req);
406}
407
408/// [`Client::cheat_get_city`](nil_client::Client::cheat_get_city)
409#[unsafe(no_mangle)]
410pub unsafe extern "C" fn nil_cheat_get_city(request_id: RequestId, json_req: *const c_char) {
411  send!(request_id, cheat_get_city, json_req);
412}
413
414/// [`Client::cheat_get_ethics`](nil_client::Client::cheat_get_ethics)
415#[unsafe(no_mangle)]
416pub unsafe extern "C" fn nil_cheat_get_ethics(request_id: RequestId, json_req: *const c_char) {
417  send!(request_id, cheat_get_ethics, json_req);
418}
419
420/// [`Client::cheat_get_idle_armies_at`](nil_client::Client::cheat_get_idle_armies_at)
421#[unsafe(no_mangle)]
422pub unsafe extern "C" fn nil_cheat_get_idle_armies_at(
423  request_id: RequestId,
424  json_req: *const c_char,
425) {
426  send!(request_id, cheat_get_idle_armies_at, json_req);
427}
428
429/// [`Client::cheat_get_idle_personnel_at`](nil_client::Client::cheat_get_idle_personnel_at)
430#[unsafe(no_mangle)]
431pub unsafe extern "C" fn nil_cheat_get_idle_personnel_at(
432  request_id: RequestId,
433  json_req: *const c_char,
434) {
435  send!(request_id, cheat_get_idle_personnel_at, json_req);
436}
437
438/// [`Client::cheat_get_infrastructure`](nil_client::Client::cheat_get_infrastructure)
439#[unsafe(no_mangle)]
440pub unsafe extern "C" fn nil_cheat_get_infrastructure(
441  request_id: RequestId,
442  json_req: *const c_char,
443) {
444  send!(request_id, cheat_get_infrastructure, json_req);
445}
446
447/// [`Client::cheat_get_maneuvers`](nil_client::Client::cheat_get_maneuvers)
448#[unsafe(no_mangle)]
449pub unsafe extern "C" fn nil_cheat_get_maneuvers(request_id: RequestId, json_req: *const c_char) {
450  send!(request_id, cheat_get_maneuvers, json_req);
451}
452
453/// [`Client::cheat_get_maneuvers_of`](nil_client::Client::cheat_get_maneuvers_of)
454#[unsafe(no_mangle)]
455pub unsafe extern "C" fn nil_cheat_get_maneuvers_of(
456  request_id: RequestId,
457  json_req: *const c_char,
458) {
459  send!(request_id, cheat_get_maneuvers_of, json_req);
460}
461
462/// [`Client::cheat_get_player`](nil_client::Client::cheat_get_player)
463#[unsafe(no_mangle)]
464pub unsafe extern "C" fn nil_cheat_get_player(request_id: RequestId, json_req: *const c_char) {
465  send!(request_id, cheat_get_player, json_req);
466}
467
468/// [`Client::cheat_get_players`](nil_client::Client::cheat_get_players)
469#[unsafe(no_mangle)]
470pub unsafe extern "C" fn nil_cheat_get_players(request_id: RequestId, json_req: *const c_char) {
471  send!(request_id, cheat_get_players, json_req);
472}
473
474/// [`Client::cheat_get_prefecture_build_queue`](nil_client::Client::cheat_get_prefecture_build_queue)
475#[unsafe(no_mangle)]
476pub unsafe extern "C" fn nil_cheat_get_prefecture_build_queue(
477  request_id: RequestId,
478  json_req: *const c_char,
479) {
480  send!(request_id, cheat_get_prefecture_build_queue, json_req);
481}
482
483/// [`Client::cheat_get_prefecture_build_queues`](nil_client::Client::cheat_get_prefecture_build_queues)
484#[unsafe(no_mangle)]
485pub unsafe extern "C" fn nil_cheat_get_prefecture_build_queues(
486  request_id: RequestId,
487  json_req: *const c_char,
488) {
489  send!(request_id, cheat_get_prefecture_build_queues, json_req);
490}
491
492/// [`Client::cheat_get_resources`](nil_client::Client::cheat_get_resources)
493#[unsafe(no_mangle)]
494pub unsafe extern "C" fn nil_cheat_get_resources(request_id: RequestId, json_req: *const c_char) {
495  send!(request_id, cheat_get_resources, json_req);
496}
497
498/// [`Client::cheat_get_stable_recruit_queue`](nil_client::Client::cheat_get_stable_recruit_queue)
499#[unsafe(no_mangle)]
500pub unsafe extern "C" fn nil_cheat_get_stable_recruit_queue(
501  request_id: RequestId,
502  json_req: *const c_char,
503) {
504  send!(request_id, cheat_get_stable_recruit_queue, json_req);
505}
506
507/// [`Client::cheat_get_stable_recruit_queues`](nil_client::Client::cheat_get_stable_recruit_queues)
508#[unsafe(no_mangle)]
509pub unsafe extern "C" fn nil_cheat_get_stable_recruit_queues(
510  request_id: RequestId,
511  json_req: *const c_char,
512) {
513  send!(request_id, cheat_get_stable_recruit_queues, json_req);
514}
515
516/// [`Client::cheat_get_storage_capacity`](nil_client::Client::cheat_get_storage_capacity)
517#[unsafe(no_mangle)]
518pub unsafe extern "C" fn nil_cheat_get_storage_capacity(
519  request_id: RequestId,
520  json_req: *const c_char,
521) {
522  send!(request_id, cheat_get_storage_capacity, json_req);
523}
524
525/// [`Client::cheat_set_bot_ethics`](nil_client::Client::cheat_set_bot_ethics)
526#[unsafe(no_mangle)]
527pub unsafe extern "C" fn nil_cheat_set_bot_ethics(request_id: RequestId, json_req: *const c_char) {
528  send!(request_id, cheat_set_bot_ethics, json_req);
529}
530
531/// [`Client::cheat_set_building_level`](nil_client::Client::cheat_set_building_level)
532#[unsafe(no_mangle)]
533pub unsafe extern "C" fn nil_cheat_set_building_level(
534  request_id: RequestId,
535  json_req: *const c_char,
536) {
537  send!(request_id, cheat_set_building_level, json_req);
538}
539
540/// [`Client::cheat_set_food`](nil_client::Client::cheat_set_food)
541#[unsafe(no_mangle)]
542pub unsafe extern "C" fn nil_cheat_set_food(request_id: RequestId, json_req: *const c_char) {
543  send!(request_id, cheat_set_food, json_req);
544}
545
546/// [`Client::cheat_set_iron`](nil_client::Client::cheat_set_iron)
547#[unsafe(no_mangle)]
548pub unsafe extern "C" fn nil_cheat_set_iron(request_id: RequestId, json_req: *const c_char) {
549  send!(request_id, cheat_set_iron, json_req);
550}
551
552/// [`Client::cheat_set_max_food`](nil_client::Client::cheat_set_max_food)
553#[unsafe(no_mangle)]
554pub unsafe extern "C" fn nil_cheat_set_max_food(request_id: RequestId, json_req: *const c_char) {
555  send!(request_id, cheat_set_max_food, json_req);
556}
557
558/// [`Client::cheat_set_max_infrastructure`](nil_client::Client::cheat_set_max_infrastructure)
559#[unsafe(no_mangle)]
560pub unsafe extern "C" fn nil_cheat_set_max_infrastructure(
561  request_id: RequestId,
562  json_req: *const c_char,
563) {
564  send!(request_id, cheat_set_max_infrastructure, json_req);
565}
566
567/// [`Client::cheat_set_max_iron`](nil_client::Client::cheat_set_max_iron)
568#[unsafe(no_mangle)]
569pub unsafe extern "C" fn nil_cheat_set_max_iron(request_id: RequestId, json_req: *const c_char) {
570  send!(request_id, cheat_set_max_iron, json_req);
571}
572
573/// [`Client::cheat_set_max_resources`](nil_client::Client::cheat_set_max_resources)
574#[unsafe(no_mangle)]
575pub unsafe extern "C" fn nil_cheat_set_max_resources(
576  request_id: RequestId,
577  json_req: *const c_char,
578) {
579  send!(request_id, cheat_set_max_resources, json_req);
580}
581
582/// [`Client::cheat_set_max_silo_resources`](nil_client::Client::cheat_set_max_silo_resources)
583#[unsafe(no_mangle)]
584pub unsafe extern "C" fn nil_cheat_set_max_silo_resources(
585  request_id: RequestId,
586  json_req: *const c_char,
587) {
588  send!(request_id, cheat_set_max_silo_resources, json_req);
589}
590
591/// [`Client::cheat_set_max_stone`](nil_client::Client::cheat_set_max_stone)
592#[unsafe(no_mangle)]
593pub unsafe extern "C" fn nil_cheat_set_max_stone(request_id: RequestId, json_req: *const c_char) {
594  send!(request_id, cheat_set_max_stone, json_req);
595}
596
597/// [`Client::cheat_set_max_warehouse_resources`](nil_client::Client::cheat_set_max_warehouse_resources)
598#[unsafe(no_mangle)]
599pub unsafe extern "C" fn nil_cheat_set_max_warehouse_resources(
600  request_id: RequestId,
601  json_req: *const c_char,
602) {
603  send!(request_id, cheat_set_max_warehouse_resources, json_req);
604}
605
606/// [`Client::cheat_set_max_wood`](nil_client::Client::cheat_set_max_wood)
607#[unsafe(no_mangle)]
608pub unsafe extern "C" fn nil_cheat_set_max_wood(request_id: RequestId, json_req: *const c_char) {
609  send!(request_id, cheat_set_max_wood, json_req);
610}
611
612/// [`Client::cheat_set_resources`](nil_client::Client::cheat_set_resources)
613#[unsafe(no_mangle)]
614pub unsafe extern "C" fn nil_cheat_set_resources(request_id: RequestId, json_req: *const c_char) {
615  send!(request_id, cheat_set_resources, json_req);
616}
617
618/// [`Client::cheat_set_stability`](nil_client::Client::cheat_set_stability)
619#[unsafe(no_mangle)]
620pub unsafe extern "C" fn nil_cheat_set_stability(request_id: RequestId, json_req: *const c_char) {
621  send!(request_id, cheat_set_stability, json_req);
622}
623
624/// [`Client::cheat_set_stone`](nil_client::Client::cheat_set_stone)
625#[unsafe(no_mangle)]
626pub unsafe extern "C" fn nil_cheat_set_stone(request_id: RequestId, json_req: *const c_char) {
627  send!(request_id, cheat_set_stone, json_req);
628}
629
630/// [`Client::cheat_set_wood`](nil_client::Client::cheat_set_wood)
631#[unsafe(no_mangle)]
632pub unsafe extern "C" fn nil_cheat_set_wood(request_id: RequestId, json_req: *const c_char) {
633  send!(request_id, cheat_set_wood, json_req);
634}
635
636/// [`Client::cheat_skip_round`](nil_client::Client::cheat_skip_round)
637#[unsafe(no_mangle)]
638pub unsafe extern "C" fn nil_cheat_skip_round(request_id: RequestId, json_req: *const c_char) {
639  send!(request_id, cheat_skip_round, json_req);
640}
641
642/// [`Client::cheat_spawn_bot`](nil_client::Client::cheat_spawn_bot)
643#[unsafe(no_mangle)]
644pub unsafe extern "C" fn nil_cheat_spawn_bot(request_id: RequestId, json_req: *const c_char) {
645  send!(request_id, cheat_spawn_bot, json_req);
646}
647
648/// [`Client::cheat_spawn_city`](nil_client::Client::cheat_spawn_city)
649#[unsafe(no_mangle)]
650pub unsafe extern "C" fn nil_cheat_spawn_city(request_id: RequestId, json_req: *const c_char) {
651  send!(request_id, cheat_spawn_city, json_req);
652}
653
654/// [`Client::cheat_spawn_personnel`](nil_client::Client::cheat_spawn_personnel)
655#[unsafe(no_mangle)]
656pub unsafe extern "C" fn nil_cheat_spawn_personnel(request_id: RequestId, json_req: *const c_char) {
657  send!(request_id, cheat_spawn_personnel, json_req);
658}
659
660/// [`Client::create_remote_world`](nil_client::Client::create_remote_world)
661#[unsafe(no_mangle)]
662pub unsafe extern "C" fn nil_create_remote_world(request_id: RequestId, json_req: *const c_char) {
663  send!(request_id, create_remote_world, json_req);
664}
665
666/// [`Client::create_user`](nil_client::Client::create_user)
667#[unsafe(no_mangle)]
668pub unsafe extern "C" fn nil_create_user(request_id: RequestId, json_req: *const c_char) {
669  send!(request_id, create_user, json_req);
670}
671
672/// [`Client::delete_remote_world`](nil_client::Client::delete_remote_world)
673#[unsafe(no_mangle)]
674pub unsafe extern "C" fn nil_delete_remote_world(request_id: RequestId, json_req: *const c_char) {
675  send!(request_id, delete_remote_world, json_req);
676}
677
678/// [`Client::forward_report`](nil_client::Client::forward_report)
679#[unsafe(no_mangle)]
680pub unsafe extern "C" fn nil_forward_report(request_id: RequestId, json_req: *const c_char) {
681  send!(request_id, forward_report, json_req);
682}
683
684/// [`Client::get_academy_recruit_catalog`](nil_client::Client::get_academy_recruit_catalog)
685#[unsafe(no_mangle)]
686pub unsafe extern "C" fn nil_get_academy_recruit_catalog(
687  request_id: RequestId,
688  json_req: *const c_char,
689) {
690  send!(request_id, get_academy_recruit_catalog, json_req);
691}
692
693/// [`Client::get_armies`](nil_client::Client::get_armies)
694#[unsafe(no_mangle)]
695pub unsafe extern "C" fn nil_get_armies(request_id: RequestId, json_req: *const c_char) {
696  send!(request_id, get_armies, json_req);
697}
698
699/// [`Client::get_army`](nil_client::Client::get_army)
700#[unsafe(no_mangle)]
701pub unsafe extern "C" fn nil_get_army(request_id: RequestId, json_req: *const c_char) {
702  send!(request_id, get_army, json_req);
703}
704
705/// [`Client::get_army_owner`](nil_client::Client::get_army_owner)
706#[unsafe(no_mangle)]
707pub unsafe extern "C" fn nil_get_army_owner(request_id: RequestId, json_req: *const c_char) {
708  send!(request_id, get_army_owner, json_req);
709}
710
711/// [`Client::get_bot_coords`](nil_client::Client::get_bot_coords)
712#[unsafe(no_mangle)]
713pub unsafe extern "C" fn nil_get_bot_coords(request_id: RequestId, json_req: *const c_char) {
714  send!(request_id, get_bot_coords, json_req);
715}
716
717/// [`Client::get_chat_history`](nil_client::Client::get_chat_history)
718#[unsafe(no_mangle)]
719pub unsafe extern "C" fn nil_get_chat_history(request_id: RequestId, json_req: *const c_char) {
720  send!(request_id, get_chat_history, json_req);
721}
722
723/// [`Client::get_cities`](nil_client::Client::get_cities)
724#[unsafe(no_mangle)]
725pub unsafe extern "C" fn nil_get_cities(request_id: RequestId, json_req: *const c_char) {
726  send!(request_id, get_cities, json_req);
727}
728
729/// [`Client::get_city`](nil_client::Client::get_city)
730#[unsafe(no_mangle)]
731pub unsafe extern "C" fn nil_get_city(request_id: RequestId, json_req: *const c_char) {
732  send!(request_id, get_city, json_req);
733}
734
735/// [`Client::get_city_score`](nil_client::Client::get_city_score)
736#[unsafe(no_mangle)]
737pub unsafe extern "C" fn nil_get_city_score(request_id: RequestId, json_req: *const c_char) {
738  send!(request_id, get_city_score, json_req);
739}
740
741/// [`Client::get_continent_size`](nil_client::Client::get_continent_size)
742#[unsafe(no_mangle)]
743pub unsafe extern "C" fn nil_get_continent_size(request_id: RequestId, json_req: *const c_char) {
744  send!(request_id, get_continent_size, json_req);
745}
746
747/// [`Client::get_idle_armies_at`](nil_client::Client::get_idle_armies_at)
748#[unsafe(no_mangle)]
749pub unsafe extern "C" fn nil_get_idle_armies_at(request_id: RequestId, json_req: *const c_char) {
750  send!(request_id, get_idle_armies_at, json_req);
751}
752
753/// [`Client::get_idle_armies_coords`](nil_client::Client::get_idle_armies_coords)
754#[unsafe(no_mangle)]
755pub unsafe extern "C" fn nil_get_idle_armies_coords(
756  request_id: RequestId,
757  json_req: *const c_char,
758) {
759  send!(request_id, get_idle_armies_coords, json_req);
760}
761
762/// [`Client::get_maneuver`](nil_client::Client::get_maneuver)
763#[unsafe(no_mangle)]
764pub unsafe extern "C" fn nil_get_maneuver(request_id: RequestId, json_req: *const c_char) {
765  send!(request_id, get_maneuver, json_req);
766}
767
768/// [`Client::get_player`](nil_client::Client::get_player)
769#[unsafe(no_mangle)]
770pub unsafe extern "C" fn nil_get_player(request_id: RequestId, json_req: *const c_char) {
771  send!(request_id, get_player, json_req);
772}
773
774/// [`Client::get_player_coords`](nil_client::Client::get_player_coords)
775#[unsafe(no_mangle)]
776pub unsafe extern "C" fn nil_get_player_coords(request_id: RequestId, json_req: *const c_char) {
777  send!(request_id, get_player_coords, json_req);
778}
779
780/// [`Client::get_player_ids`](nil_client::Client::get_player_ids)
781#[unsafe(no_mangle)]
782pub unsafe extern "C" fn nil_get_player_ids(request_id: RequestId, json_req: *const c_char) {
783  send!(request_id, get_player_ids, json_req);
784}
785
786/// [`Client::get_player_maintenance`](nil_client::Client::get_player_maintenance)
787#[unsafe(no_mangle)]
788pub unsafe extern "C" fn nil_get_player_maintenance(
789  request_id: RequestId,
790  json_req: *const c_char,
791) {
792  send!(request_id, get_player_maintenance, json_req);
793}
794
795/// [`Client::get_player_military`](nil_client::Client::get_player_military)
796#[unsafe(no_mangle)]
797pub unsafe extern "C" fn nil_get_player_military(request_id: RequestId, json_req: *const c_char) {
798  send!(request_id, get_player_military, json_req);
799}
800
801/// [`Client::get_player_status`](nil_client::Client::get_player_status)
802#[unsafe(no_mangle)]
803pub unsafe extern "C" fn nil_get_player_status(request_id: RequestId, json_req: *const c_char) {
804  send!(request_id, get_player_status, json_req);
805}
806
807/// [`Client::get_player_storage_capacity`](nil_client::Client::get_player_storage_capacity)
808#[unsafe(no_mangle)]
809pub unsafe extern "C" fn nil_get_player_storage_capacity(
810  request_id: RequestId,
811  json_req: *const c_char,
812) {
813  send!(request_id, get_player_storage_capacity, json_req);
814}
815
816/// [`Client::get_player_worlds`](nil_client::Client::get_player_worlds)
817#[unsafe(no_mangle)]
818pub unsafe extern "C" fn nil_get_player_worlds(request_id: RequestId, json_req: *const c_char) {
819  send!(request_id, get_player_worlds, json_req);
820}
821
822/// [`Client::get_precursor_coords`](nil_client::Client::get_precursor_coords)
823#[unsafe(no_mangle)]
824pub unsafe extern "C" fn nil_get_precursor_coords(request_id: RequestId, json_req: *const c_char) {
825  send!(request_id, get_precursor_coords, json_req);
826}
827
828/// [`Client::get_prefecture_build_catalog`](nil_client::Client::get_prefecture_build_catalog)
829#[unsafe(no_mangle)]
830pub unsafe extern "C" fn nil_get_prefecture_build_catalog(
831  request_id: RequestId,
832  json_req: *const c_char,
833) {
834  send!(request_id, get_prefecture_build_catalog, json_req);
835}
836
837/// [`Client::get_public_bot`](nil_client::Client::get_public_bot)
838#[unsafe(no_mangle)]
839pub unsafe extern "C" fn nil_get_public_bot(request_id: RequestId, json_req: *const c_char) {
840  send!(request_id, get_public_bot, json_req);
841}
842
843/// [`Client::get_public_bots`](nil_client::Client::get_public_bots)
844#[unsafe(no_mangle)]
845pub unsafe extern "C" fn nil_get_public_bots(request_id: RequestId, json_req: *const c_char) {
846  send!(request_id, get_public_bots, json_req);
847}
848
849/// [`Client::get_public_cities`](nil_client::Client::get_public_cities)
850#[unsafe(no_mangle)]
851pub unsafe extern "C" fn nil_get_public_cities(request_id: RequestId, json_req: *const c_char) {
852  send!(request_id, get_public_cities, json_req);
853}
854
855/// [`Client::get_public_city`](nil_client::Client::get_public_city)
856#[unsafe(no_mangle)]
857pub unsafe extern "C" fn nil_get_public_city(request_id: RequestId, json_req: *const c_char) {
858  send!(request_id, get_public_city, json_req);
859}
860
861/// [`Client::get_public_field`](nil_client::Client::get_public_field)
862#[unsafe(no_mangle)]
863pub unsafe extern "C" fn nil_get_public_field(request_id: RequestId, json_req: *const c_char) {
864  send!(request_id, get_public_field, json_req);
865}
866
867/// [`Client::get_public_fields`](nil_client::Client::get_public_fields)
868#[unsafe(no_mangle)]
869pub unsafe extern "C" fn nil_get_public_fields(request_id: RequestId, json_req: *const c_char) {
870  send!(request_id, get_public_fields, json_req);
871}
872
873/// [`Client::get_public_player`](nil_client::Client::get_public_player)
874#[unsafe(no_mangle)]
875pub unsafe extern "C" fn nil_get_public_player(request_id: RequestId, json_req: *const c_char) {
876  send!(request_id, get_public_player, json_req);
877}
878
879/// [`Client::get_public_players`](nil_client::Client::get_public_players)
880#[unsafe(no_mangle)]
881pub unsafe extern "C" fn nil_get_public_players(request_id: RequestId, json_req: *const c_char) {
882  send!(request_id, get_public_players, json_req);
883}
884
885/// [`Client::get_public_precursor`](nil_client::Client::get_public_precursor)
886#[unsafe(no_mangle)]
887pub unsafe extern "C" fn nil_get_public_precursor(request_id: RequestId, json_req: *const c_char) {
888  send!(request_id, get_public_precursor, json_req);
889}
890
891/// [`Client::get_public_precursors`](nil_client::Client::get_public_precursors)
892#[unsafe(no_mangle)]
893pub unsafe extern "C" fn nil_get_public_precursors(request_id: RequestId, json_req: *const c_char) {
894  send!(request_id, get_public_precursors, json_req);
895}
896
897/// [`Client::get_rank`](nil_client::Client::get_rank)
898#[unsafe(no_mangle)]
899pub unsafe extern "C" fn nil_get_rank(request_id: RequestId, json_req: *const c_char) {
900  send!(request_id, get_rank, json_req);
901}
902
903/// [`Client::get_ranking`](nil_client::Client::get_ranking)
904#[unsafe(no_mangle)]
905pub unsafe extern "C" fn nil_get_ranking(request_id: RequestId, json_req: *const c_char) {
906  send!(request_id, get_ranking, json_req);
907}
908
909/// [`Client::get_remote_world`](nil_client::Client::get_remote_world)
910#[unsafe(no_mangle)]
911pub unsafe extern "C" fn nil_get_remote_world(request_id: RequestId, json_req: *const c_char) {
912  send!(request_id, get_remote_world, json_req);
913}
914
915/// [`Client::get_remote_world_limit`](nil_client::Client::get_remote_world_limit)
916#[unsafe(no_mangle)]
917pub unsafe extern "C" fn nil_get_remote_world_limit(request_id: RequestId) {
918  send!(request_id, get_remote_world_limit);
919}
920
921/// [`Client::get_remote_world_limit_per_user`](nil_client::Client::get_remote_world_limit_per_user)
922#[unsafe(no_mangle)]
923pub unsafe extern "C" fn nil_get_remote_world_limit_per_user(request_id: RequestId) {
924  send!(request_id, get_remote_world_limit_per_user);
925}
926
927/// [`Client::get_remote_worlds`](nil_client::Client::get_remote_worlds)
928#[unsafe(no_mangle)]
929pub unsafe extern "C" fn nil_get_remote_worlds(request_id: RequestId) {
930  send!(request_id, get_remote_worlds);
931}
932
933/// [`Client::get_round`](nil_client::Client::get_round)
934#[unsafe(no_mangle)]
935pub unsafe extern "C" fn nil_get_round(request_id: RequestId, json_req: *const c_char) {
936  send!(request_id, get_round, json_req);
937}
938
939/// [`Client::get_server_kind`](nil_client::Client::get_server_kind)
940#[unsafe(no_mangle)]
941pub unsafe extern "C" fn nil_get_server_kind(request_id: RequestId) {
942  send!(request_id, get_server_kind);
943}
944
945/// [`Client::get_stable_recruit_catalog`](nil_client::Client::get_stable_recruit_catalog)
946#[unsafe(no_mangle)]
947pub unsafe extern "C" fn nil_get_stable_recruit_catalog(
948  request_id: RequestId,
949  json_req: *const c_char,
950) {
951  send!(request_id, get_stable_recruit_catalog, json_req);
952}
953
954/// [`Client::get_workshop_recruit_catalog`](nil_client::Client::get_workshop_recruit_catalog)
955#[unsafe(no_mangle)]
956pub unsafe extern "C" fn nil_get_workshop_recruit_catalog(
957  request_id: RequestId,
958  json_req: *const c_char,
959) {
960  send!(request_id, get_workshop_recruit_catalog, json_req);
961}
962
963/// [`Client::get_world_bots`](nil_client::Client::get_world_bots)
964#[unsafe(no_mangle)]
965pub unsafe extern "C" fn nil_get_world_bots(request_id: RequestId, json_req: *const c_char) {
966  send!(request_id, get_world_bots, json_req);
967}
968
969/// [`Client::get_world_config`](nil_client::Client::get_world_config)
970#[unsafe(no_mangle)]
971pub unsafe extern "C" fn nil_get_world_config(request_id: RequestId, json_req: *const c_char) {
972  send!(request_id, get_world_config, json_req);
973}
974
975/// [`Client::get_world_personnel`](nil_client::Client::get_world_personnel)
976#[unsafe(no_mangle)]
977pub unsafe extern "C" fn nil_get_world_personnel(request_id: RequestId, json_req: *const c_char) {
978  send!(request_id, get_world_personnel, json_req);
979}
980
981/// [`Client::get_world_players`](nil_client::Client::get_world_players)
982#[unsafe(no_mangle)]
983pub unsafe extern "C" fn nil_get_world_players(request_id: RequestId, json_req: *const c_char) {
984  send!(request_id, get_world_players, json_req);
985}
986
987/// [`Client::get_world_precursors`](nil_client::Client::get_world_precursors)
988#[unsafe(no_mangle)]
989pub unsafe extern "C" fn nil_get_world_precursors(request_id: RequestId, json_req: *const c_char) {
990  send!(request_id, get_world_precursors, json_req);
991}
992
993/// [`Client::get_world_stats`](nil_client::Client::get_world_stats)
994#[unsafe(no_mangle)]
995pub unsafe extern "C" fn nil_get_world_stats(request_id: RequestId, json_req: *const c_char) {
996  send!(request_id, get_world_stats, json_req);
997}
998
999/// [`Client::player_exists`](nil_client::Client::player_exists)
1000#[unsafe(no_mangle)]
1001pub unsafe extern "C" fn nil_player_exists(request_id: RequestId, json_req: *const c_char) {
1002  send!(request_id, player_exists, json_req);
1003}
1004
1005/// [`Client::push_chat_message`](nil_client::Client::push_chat_message)
1006#[unsafe(no_mangle)]
1007pub unsafe extern "C" fn nil_push_chat_message(request_id: RequestId, json_req: *const c_char) {
1008  send!(request_id, push_chat_message, json_req);
1009}
1010
1011/// [`Client::rename_city`](nil_client::Client::rename_city)
1012#[unsafe(no_mangle)]
1013pub unsafe extern "C" fn nil_rename_city(request_id: RequestId, json_req: *const c_char) {
1014  send!(request_id, rename_city, json_req);
1015}
1016
1017/// [`Client::request_maneuver`](nil_client::Client::request_maneuver)
1018#[unsafe(no_mangle)]
1019pub unsafe extern "C" fn nil_request_maneuver(request_id: RequestId, json_req: *const c_char) {
1020  send!(request_id, request_maneuver, json_req);
1021}
1022
1023/// [`Client::save_local_world`](nil_client::Client::save_local_world)
1024#[unsafe(no_mangle)]
1025pub unsafe extern "C" fn nil_save_local_world(request_id: RequestId, json_req: *const c_char) {
1026  send!(request_id, save_local_world, json_req);
1027}
1028
1029/// [`Client::search_city`](nil_client::Client::search_city)
1030#[unsafe(no_mangle)]
1031pub unsafe extern "C" fn nil_search_city(request_id: RequestId, json_req: *const c_char) {
1032  send!(request_id, search_city, json_req);
1033}
1034
1035/// [`Client::search_public_city`](nil_client::Client::search_public_city)
1036#[unsafe(no_mangle)]
1037pub unsafe extern "C" fn nil_search_public_city(request_id: RequestId, json_req: *const c_char) {
1038  send!(request_id, search_public_city, json_req);
1039}
1040
1041/// [`Client::version`](nil_client::Client::version)
1042#[unsafe(no_mangle)]
1043pub unsafe extern "C" fn nil_server_version(request_id: RequestId) {
1044  send!(request_id, version);
1045}
1046
1047/// [`Client::set_player_ready`](nil_client::Client::set_player_ready)
1048#[unsafe(no_mangle)]
1049pub unsafe extern "C" fn nil_set_player_ready(request_id: RequestId, json_req: *const c_char) {
1050  send!(request_id, set_player_ready, json_req);
1051}
1052
1053/// [`Client::set_player_status`](nil_client::Client::set_player_status)
1054#[unsafe(no_mangle)]
1055pub unsafe extern "C" fn nil_set_player_status(request_id: RequestId, json_req: *const c_char) {
1056  send!(request_id, set_player_status, json_req);
1057}
1058
1059/// [`Client::simulate_battle`](nil_client::Client::simulate_battle)
1060#[unsafe(no_mangle)]
1061pub unsafe extern "C" fn nil_simulate_battle(request_id: RequestId, json_req: *const c_char) {
1062  send!(request_id, simulate_battle, json_req);
1063}
1064
1065/// [`Client::spawn_player`](nil_client::Client::spawn_player)
1066#[unsafe(no_mangle)]
1067pub unsafe extern "C" fn nil_spawn_player(request_id: RequestId, json_req: *const c_char) {
1068  send!(request_id, spawn_player, json_req);
1069}
1070
1071/// [`Client::start_round`](nil_client::Client::start_round)
1072#[unsafe(no_mangle)]
1073pub unsafe extern "C" fn nil_start_round(request_id: RequestId, json_req: *const c_char) {
1074  send!(request_id, start_round, json_req);
1075}
1076
1077/// [`Client::toggle_building`](nil_client::Client::toggle_building)
1078#[unsafe(no_mangle)]
1079pub unsafe extern "C" fn nil_toggle_building(request_id: RequestId, json_req: *const c_char) {
1080  send!(request_id, toggle_building, json_req);
1081}
1082
1083/// [`Client::user_exists`](nil_client::Client::user_exists)
1084#[unsafe(no_mangle)]
1085pub unsafe extern "C" fn nil_user_exists(request_id: RequestId, json_req: *const c_char) {
1086  send!(request_id, user_exists, json_req);
1087}
1088
1089/// [`Client::validate_token`](nil_client::Client::validate_token)
1090#[unsafe(no_mangle)]
1091pub unsafe extern "C" fn nil_validate_token(request_id: RequestId, json_req: *const c_char) {
1092  send!(request_id, validate_token, json_req);
1093}