rogueserver/api/generic.go

72 lines
1.4 KiB
Go
Raw Normal View History

2023-12-05 10:28:08 -08:00
package api
import (
2024-04-06 14:43:11 -07:00
"encoding/gob"
"net/http"
)
2023-12-29 11:30:47 -08:00
type Server struct {
Debug bool
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2024-04-06 14:43:11 -07:00
gob.Register([]interface{}{})
gob.Register(map[string]interface{}{})
2023-12-29 11:30:47 -08:00
if s.Debug {
2023-12-29 11:34:58 -08:00
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
2023-12-29 11:33:11 -08:00
w.Header().Set("Access-Control-Allow-Origin", "*")
2023-12-29 11:30:47 -08:00
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
}
switch r.URL.Path {
case "/account/info":
2024-04-01 19:54:55 -07:00
s.handleAccountInfo(w, r)
2023-12-29 11:30:47 -08:00
case "/account/register":
2024-04-01 19:54:55 -07:00
s.handleAccountRegister(w, r)
2023-12-29 11:30:47 -08:00
case "/account/login":
2024-04-01 19:54:55 -07:00
s.handleAccountLogin(w, r)
2023-12-29 11:30:47 -08:00
case "/account/logout":
2024-04-01 19:54:55 -07:00
s.handleAccountLogout(w, r)
2023-12-29 11:30:47 -08:00
2024-03-23 18:34:18 -07:00
case "/game/playercount":
2024-04-07 14:22:34 -07:00
s.handlePlayerCountGet(w, r)
2024-04-06 15:15:47 -07:00
case "/game/titlestats":
2024-04-07 14:22:34 -07:00
s.handleTitleStatsGet(w, r)
2024-04-06 15:15:47 -07:00
case "/game/classicsessioncount":
2024-04-07 14:22:34 -07:00
s.handleClassicSessionCountGet(w, r)
2024-03-23 18:34:18 -07:00
2023-12-29 11:30:47 -08:00
case "/savedata/get":
2024-04-01 19:54:55 -07:00
s.handleSavedataGet(w, r)
2023-12-29 11:30:47 -08:00
case "/savedata/update":
2024-04-01 19:54:55 -07:00
s.handleSavedataUpdate(w, r)
2023-12-29 11:30:47 -08:00
case "/savedata/delete":
2024-04-01 19:54:55 -07:00
s.handleSavedataDelete(w, r)
2024-03-16 18:51:13 -07:00
case "/savedata/clear":
2024-04-01 19:54:55 -07:00
s.handleSavedataClear(w, r)
2024-03-16 18:51:13 -07:00
case "/daily/seed":
2024-04-01 19:54:55 -07:00
s.handleSeed(w)
2024-03-17 10:18:51 -07:00
case "/daily/rankings":
2024-04-01 19:54:55 -07:00
s.handleRankings(w, r)
case "/daily/rankingpagecount":
2024-04-01 19:54:55 -07:00
s.handleRankingPageCount(w, r)
2023-12-29 11:30:47 -08:00
}
}
2023-12-05 10:28:08 -08:00
// auth
type GenericAuthRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
type GenericAuthResponse struct {
Token string `json:"token"`
}