summaryrefslogtreecommitdiffstats
path: root/src/server/core.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-01 16:17:19 +0100
committersalmonik <salmonik@tuta.io>2026-11-01 16:17:19 +0100
commitf07221b4e1d8aa464a44fe566884ccc0565406e9 (patch)
tree48020a68cee1c95521d594dc6803c1f7ec01c801 /src/server/core.rs
parentadd nginx + php-fpm deployment example (diff)
downloadzagan-bet-f07221b4e1d8aa464a44fe566884ccc0565406e9.tar.gz
zagan-bet-f07221b4e1d8aa464a44fe566884ccc0565406e9.zip
v3.2.0: straight and split bets anywhere on the felt; add history command
Diffstat (limited to '')
-rw-r--r--src/server/core.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/server/core.rs b/src/server/core.rs
index 4b68ccb..89264f3 100644
--- a/src/server/core.rs
+++ b/src/server/core.rs
@@ -172,6 +172,21 @@ impl ServerCore {
172 self.handle_auth(state, parts[1], parts[2]) 172 self.handle_auth(state, parts[1], parts[2])
173 } 173 }
174 } 174 }
175 "HISTORY" => {
176 if parts.len() > 2 {
177 "ERROR Invalid HISTORY format. Usage: HISTORY [count]".to_string()
178 } else {
179 match parts.get(1) {
180 Some(raw) => match raw.parse::<u32>() {
181 Ok(count) if count > 0 => {
182 self.handle_history(state, count.min(crate::history::MAX_HISTORY))
183 }
184 _ => "ERROR Invalid HISTORY count".to_string(),
185 },
186 None => self.handle_history(state, crate::history::DEFAULT_HISTORY),
187 }
188 }
189 }
175 "PING" => "PONG".to_string(), 190 "PING" => "PONG".to_string(),
176 "INFO" => self.handle_info(state), 191 "INFO" => self.handle_info(state),
177 _ => msg.to_string(), 192 _ => msg.to_string(),
@@ -234,6 +249,25 @@ impl ServerCore {
234 } 249 }
235 } 250 }
236 251
252 fn handle_history(&mut self, state: &ConnectionState, limit: u32) -> String {
253 let Some(user) = state.user.as_deref() else {
254 return "ERROR Not logged in".to_string();
255 };
256 match database::recent_plays(&self.conn, user, limit) {
257 Ok(records) => match serde_json::to_string(&records) {
258 Ok(json) => format!("HISTORY {json}"),
259 Err(error) => {
260 eprintln!("History serialization failed for {user}: {error}");
261 "ERROR Could not read history".to_string()
262 }
263 },
264 Err(error) => {
265 eprintln!("History query failed for {user}: {error}");
266 "ERROR Could not read history".to_string()
267 }
268 }
269 }
270
237 fn handle_info(&self, state: &ConnectionState) -> String { 271 fn handle_info(&self, state: &ConnectionState) -> String {
238 let Some(user) = state.user.as_deref() else { 272 let Some(user) = state.user.as_deref() else {
239 return "ERROR Not logged in".to_string(); 273 return "ERROR Not logged in".to_string();