48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package sdkserver
|
|
|
|
import (
|
|
"encoding/json"
|
|
"gac-hkrpg-go/internal/common"
|
|
"net/http"
|
|
)
|
|
|
|
func apiAhaHelp(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet && r.Method != http.MethodPost {
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
if r.Method == http.MethodPost {
|
|
var body map[string]json.RawMessage
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
http.Error(w, "invalid JSON", http.StatusBadRequest)
|
|
return
|
|
}
|
|
raw, ok := body["level"]
|
|
var level *uint32
|
|
if !ok || json.Unmarshal(raw, &level) != nil {
|
|
http.Error(w, "level must be null or an unsigned integer", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if err := common.SaveAhaHelpLevel(level); err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
}
|
|
levels, err := common.LoadAhaHelpLevels()
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
selected, err := common.ReadAhaHelpLevel()
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
data, err := common.LoadFreesrData()
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
writeJSON(w, map[string]any{"status": 200, "level": selected, "levels": levels, "legacy_enabled": data.BattleConfig.EnableInvasionSupport})
|
|
}
|