add boardgamers server api
This commit is contained in:
parent
09d572ccc3
commit
14b4b645f9
3 changed files with 118 additions and 9 deletions
84
server/Cargo.lock
generated
84
server/Cargo.lock
generated
|
|
@ -3,5 +3,87 @@
|
|||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "game"
|
||||
name = "itoa"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
||||
|
|
|
|||
|
|
@ -6,3 +6,5 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
serde_json = "1.0.91"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GameData;
|
||||
|
||||
pub type GameJson = String;
|
||||
|
||||
pub struct Move;
|
||||
|
||||
pub struct GameOptions;
|
||||
|
|
@ -21,41 +26,61 @@ pub async extern "C" fn init(
|
|||
options: GameOptions,
|
||||
seed: String,
|
||||
creator: Option<usize>,
|
||||
) -> GameData {
|
||||
) -> GameJson {
|
||||
toJson(GameData {});
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[export_name = "move"]
|
||||
pub extern "C" fn execute_move(game: GameData, move_data: Move, player: usize) -> GameData {
|
||||
pub extern "C" fn execute_move(json: GameJson, move_data: Move, player: usize) -> GameJson {
|
||||
let data = fromJson(json);
|
||||
toJson(data);
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[export_name = "ended"]
|
||||
pub extern "C" fn ended(game: GameData) -> bool {
|
||||
pub extern "C" fn ended(json: GameJson) -> bool {
|
||||
let data = fromJson(json);
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[export_name = "scores"]
|
||||
pub extern "C" fn scores(game: GameData) -> Vec<u32> {
|
||||
pub extern "C" fn scores(json: GameJson) -> Vec<u32> {
|
||||
let data = fromJson(json);
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[export_name = "dropPlayer"]
|
||||
pub async extern "C" fn drop_player(game: GameData, player: usize) -> GameData {
|
||||
pub async extern "C" fn drop_player(json: GameJson, player: usize) -> GameJson {
|
||||
let data = fromJson(json);
|
||||
toJson(data);
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[export_name = "currentPlayer"]
|
||||
pub async extern "C" fn current_player(game: GameData) -> Option<usize> {
|
||||
pub async extern "C" fn current_player(json: GameJson) -> Option<usize> {
|
||||
let data = fromJson(json);
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[export_name = "logLength"]
|
||||
pub async extern "C" fn log_length(game: GameData) -> u32 {
|
||||
pub async extern "C" fn log_length(json: GameJson) -> u32 {
|
||||
let data = fromJson(json);
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[export_name = "logSlice"]
|
||||
pub async extern "C" fn log_slice(game: GameData, options: LogSliceOptions) -> LogData {
|
||||
pub async extern "C" fn log_slice(json: GameJson, options: LogSliceOptions) -> LogData {
|
||||
let data = fromJson(json);
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
||||
fn fromJson(data: GameJson) -> GameData {
|
||||
let game: GameData = serde_json::from_str(&data).unwrap();
|
||||
return game;
|
||||
}
|
||||
|
||||
fn toJson(game: GameData) -> GameJson {
|
||||
return serde_json::to_string(&game).unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue