Add player count handler

This commit is contained in:
Flashfyre committed 2024-03-23 21:34:18 -04:00
1 parent 2495c1ee9a
commit 7d23859dea
3 files changed
+42

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
package api
import (
"encoding/json"
"fmt"
"net/http"
"github.com/Flashfyre/pokerogue-server/db"
)
// /game/playercount - get player count
func (s *Server) HandlePlayerCountGet(w http.ResponseWriter, r *http.Request) {
playerCount, err := db.FetchPlayerCount()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
response, err := json.Marshal(playerCount)
if err != nil {
http.Error(w, fmt.Sprintf("failed to marshal response json: %s", err), http.StatusInternalServerError)
return
}
w.Write(response)
}
+3
View File
@@ -34,6 +34,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case "/account/logout":
s.HandleAccountLogout(w, r)
case "/game/playercount":
s.HandlePlayerCountGet(w, r)
case "/savedata/get":
s.HandleSavedataGet(w, r)
case "/savedata/update":