1#[macro_use]
2extern crate serde_derive;
3
4pub const OP_TAKE_TURN: &str = "wdTakeTurn";
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7pub struct MechInfo {
8 pub name: String,
9 pub avatar: String,
10 pub team: String,
11 pub id: String,
12}
13
14pub mod events {
15 use chrono::prelude::*;
16 use domain::events::EndCause;
17 use wasmdome_domain as domain;
18
19 pub fn events_subject(match_id: Option<&str>) -> String {
20 if let Some(match_id) = match_id {
21 format!("wasmdome.match.{}.events", match_id)
22 } else {
23 "wasmdome.public.arena.events".to_string()
24 }
25 }
26
27 #[derive(Clone, Debug, Serialize, Deserialize)]
28 pub enum ArenaEvent {
29 MechConnected {
30 actor: String,
31 name: String,
32 avatar: String,
33 team: String,
34 time: DateTime<Utc>,
35 },
36 MechDisconnected {
37 actor: String,
38 time: DateTime<Utc>,
39 },
40 MatchStarted {
41 match_id: String,
42 actors: Vec<String>,
43 board_height: u32,
44 board_width: u32,
45 start_time: DateTime<Utc>,
46 },
47 MatchCompleted {
48 match_id: String,
49 cause: EndCause,
50 time: DateTime<Utc>,
51 },
52 }
53
54 #[derive(Clone, Debug, Serialize, Deserialize)]
55 pub enum MatchEvent {
56 TurnEvent {
58 actor: String,
59 match_id: String,
60 turn: u32,
61 turn_event: domain::events::GameEvent,
62 },
63 }
64}
65
66pub mod commands {
67 use crate::MechInfo;
68 use wasmdome_domain as domain;
69
70 pub fn arena_control_subject() -> String {
71 "wasmdome.internal.arena.control".to_string()
72 }
73
74 #[derive(Debug, Clone, Serialize, Deserialize)]
75 pub enum ArenaControlCommand {
76 StartMatch(CreateMatch),
77 QueryMechs,
78 }
79
80 #[derive(Debug, Clone, Serialize, Deserialize)]
84 pub struct TakeTurn {
85 pub actor: String,
86 pub match_id: String,
87 pub turn: u32,
88 pub state: domain::state::MatchState,
89 }
90
91 #[derive(Debug, Clone, Serialize, Deserialize)]
92 pub struct TakeTurnResponse {
93 pub commands: Vec<domain::commands::MechCommand>,
94 }
95
96 #[derive(Debug, Clone, Serialize, Deserialize)]
98 pub struct CreateMatch {
99 pub match_id: String,
100 pub actors: Vec<String>,
101 pub board_height: u32,
102 pub board_width: u32,
103 pub max_turns: u32,
104 pub aps_per_turn: u32,
105 }
106
107 #[derive(Debug, Clone, Serialize, Deserialize)]
108 pub struct MechQueryResponse {
109 pub mechs: Vec<MechInfo>,
110 }
111}
112
113pub mod tools {
114 #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
115 pub struct TokenRequest {
116 pub account_key: String,
117 }
118
119 #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
120 pub struct CredentialsRequest {
121 pub account_key: String,
122 pub token: String,
123 }
124
125 #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
126 pub enum CredentialsResponse {
127 Valid {
128 user_jwt: String,
129 user_secret: String,
130 },
131 Error(String),
132 }
133}
134
135pub mod scheduler {
136 use chrono::DateTime;
137 use chrono::Utc;
138
139 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
140 pub struct MatchScheduleEntry {
141 pub max_actors: u32,
142 pub board_height: u32,
143 pub board_width: u32,
144 pub max_turns: u32,
145 pub match_start: DateTime<Utc>,
146 }
147
148 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
149 pub struct MatchIdentifier {
150 pub match_id: String,
151 }
152
153 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
154 pub struct StoredMatch {
155 pub match_id: String,
156 pub entry: MatchScheduleEntry,
157 pub aps_per_turn: u32,
158 }
159}