mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-02-22 08:31:30 +08:00
Various cleanup
This commit is contained in:
parent
4cc2d3431c
commit
15a32c0e23
@ -21,11 +21,12 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/pagefaultgames/rogueserver/api/account"
|
||||
"github.com/pagefaultgames/rogueserver/api/daily"
|
||||
"github.com/pagefaultgames/rogueserver/db"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Init(mux *http.ServeMux) error {
|
||||
@ -86,7 +87,11 @@ func tokenFromRequest(r *http.Request) ([]byte, error) {
|
||||
|
||||
func uuidFromRequest(r *http.Request) ([]byte, error) {
|
||||
_, uuid, err := tokenAndUuidFromRequest(r)
|
||||
return uuid, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return uuid, nil
|
||||
}
|
||||
|
||||
func tokenAndUuidFromRequest(r *http.Request) ([]byte, []byte, error) {
|
||||
@ -108,7 +113,7 @@ func httpError(w http.ResponseWriter, r *http.Request, err error, code int) {
|
||||
http.Error(w, err.Error(), code)
|
||||
}
|
||||
|
||||
func jsonResponse(w http.ResponseWriter, r *http.Request, data any) {
|
||||
func writeJSON(w http.ResponseWriter, r *http.Request, data any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err := json.NewEncoder(w).Encode(data)
|
||||
if err != nil {
|
||||
|
@ -59,7 +59,7 @@ func handleAccountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, response)
|
||||
writeJSON(w, r, response)
|
||||
}
|
||||
|
||||
func handleAccountRegister(w http.ResponseWriter, r *http.Request) {
|
||||
@ -91,7 +91,7 @@ func handleAccountLogin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, response)
|
||||
writeJSON(w, r, response)
|
||||
}
|
||||
|
||||
func handleAccountChangePW(w http.ResponseWriter, r *http.Request) {
|
||||
@ -139,7 +139,7 @@ func handleGameTitleStats(w http.ResponseWriter, r *http.Request) {
|
||||
BattleCount: battleCount,
|
||||
}
|
||||
|
||||
jsonResponse(w, r, stats)
|
||||
writeJSON(w, r, stats)
|
||||
}
|
||||
|
||||
func handleGameClassicSessionCount(w http.ResponseWriter, r *http.Request) {
|
||||
@ -187,7 +187,7 @@ func handleGetSessionData(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, save)
|
||||
writeJSON(w, r, save)
|
||||
}
|
||||
|
||||
const legacyClientSessionId = "LEGACY_CLIENT"
|
||||
@ -237,11 +237,11 @@ func legacyHandleGetSaveData(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, save)
|
||||
writeJSON(w, r, save)
|
||||
}
|
||||
|
||||
// FIXME UNFINISHED!!!
|
||||
func clearSessionData(w http.ResponseWriter, r *http.Request) {
|
||||
/*func clearSessionData(w http.ResponseWriter, r *http.Request) {
|
||||
uuid, err := uuidFromRequest(r)
|
||||
if err != nil {
|
||||
httpError(w, r, err, http.StatusBadRequest)
|
||||
@ -407,7 +407,7 @@ func deleteSystemSave(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
}*/
|
||||
|
||||
func legacyHandleSaveData(w http.ResponseWriter, r *http.Request) {
|
||||
uuid, err := uuidFromRequest(r)
|
||||
@ -567,7 +567,7 @@ func legacyHandleSaveData(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, save)
|
||||
writeJSON(w, r, save)
|
||||
}
|
||||
|
||||
type CombinedSaveData struct {
|
||||
@ -699,7 +699,7 @@ func handleSystemVerify(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, response)
|
||||
writeJSON(w, r, response)
|
||||
}
|
||||
|
||||
func handleGetSystemData(w http.ResponseWriter, r *http.Request) {
|
||||
@ -735,7 +735,7 @@ func handleGetSystemData(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
//TODO apply vouchers
|
||||
|
||||
jsonResponse(w, r, save)
|
||||
writeJSON(w, r, save)
|
||||
}
|
||||
|
||||
func legacyHandleNewClear(w http.ResponseWriter, r *http.Request) {
|
||||
@ -760,7 +760,7 @@ func legacyHandleNewClear(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, newClear)
|
||||
writeJSON(w, r, newClear)
|
||||
}
|
||||
|
||||
// daily
|
||||
@ -804,7 +804,7 @@ func handleDailyRankings(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, r, rankings)
|
||||
writeJSON(w, r, rankings)
|
||||
}
|
||||
|
||||
func handleDailyRankingPageCount(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -19,9 +19,10 @@ package savedata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/pagefaultgames/rogueserver/db"
|
||||
"github.com/pagefaultgames/rogueserver/defs"
|
||||
"log"
|
||||
)
|
||||
|
||||
// /savedata/delete - delete save data
|
||||
@ -33,14 +34,20 @@ func Delete(uuid []byte, datatype, slot int) error {
|
||||
|
||||
switch datatype {
|
||||
case 0: // System
|
||||
return db.DeleteSystemSaveData(uuid)
|
||||
err = db.DeleteSystemSaveData(uuid)
|
||||
case 1: // Session
|
||||
if slot < 0 || slot >= defs.SessionSlotCount {
|
||||
return fmt.Errorf("slot id %d out of range", slot)
|
||||
err = fmt.Errorf("slot id %d out of range", slot)
|
||||
break
|
||||
}
|
||||
|
||||
return db.DeleteSessionSaveData(uuid, slot)
|
||||
err = db.DeleteSessionSaveData(uuid, slot)
|
||||
default:
|
||||
return fmt.Errorf("invalid data type")
|
||||
err = fmt.Errorf("invalid data type")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ func GetDailyRunSeed() (string, error) {
|
||||
}
|
||||
|
||||
return seed, nil
|
||||
|
||||
}
|
||||
|
||||
func AddOrUpdateAccountDailyRun(uuid []byte, score int, wave int) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user