|
|
@ -4,10 +4,8 @@ import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
|
|
|
"encoding/gob"
|
|
|
|
"encoding/hex"
|
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
|
@ -19,228 +17,146 @@ import (
|
|
|
|
const sessionSlotCount = 3
|
|
|
|
const sessionSlotCount = 3
|
|
|
|
|
|
|
|
|
|
|
|
// /savedata/get - get save data
|
|
|
|
// /savedata/get - get save data
|
|
|
|
func (s *Server) handleSavedataGet(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func handleSavedataGet(uuid []byte, datatype, slot int) (any, error) {
|
|
|
|
uuid, err := getUUIDFromRequest(r)
|
|
|
|
switch datatype {
|
|
|
|
if err != nil {
|
|
|
|
case 0: // System
|
|
|
|
httpError(w, r, err.Error(), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch r.URL.Query().Get("datatype") {
|
|
|
|
|
|
|
|
case "0": // System
|
|
|
|
|
|
|
|
system, err := readSystemSaveData(uuid)
|
|
|
|
system, err := readSystemSaveData(uuid)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, err.Error(), http.StatusInternalServerError)
|
|
|
|
return nil, err
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
saveJson, err := json.Marshal(system)
|
|
|
|
return system, nil
|
|
|
|
if err != nil {
|
|
|
|
case 1: // Session
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to marshal save to json: %s", err), http.StatusInternalServerError)
|
|
|
|
if slot < 0 || slot >= sessionSlotCount {
|
|
|
|
return
|
|
|
|
return nil, fmt.Errorf("slot id %d out of range", slot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
w.Write(saveJson)
|
|
|
|
session, err := readSessionSaveData(uuid, slot)
|
|
|
|
case "1": // Session
|
|
|
|
|
|
|
|
slotID, err := strconv.Atoi(r.URL.Query().Get("slot"))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to convert slot id: %s", err), http.StatusBadRequest)
|
|
|
|
return nil, err
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if slotID < 0 || slotID >= sessionSlotCount {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("slot id %d out of range", slotID), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
session, err := readSessionSaveData(uuid, slotID)
|
|
|
|
return session, nil
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveJson, err := json.Marshal(session)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to marshal save to json: %s", err), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w.Write(saveJson)
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
httpError(w, r, "invalid data type", http.StatusBadRequest)
|
|
|
|
return nil, fmt.Errorf("invalid data type")
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// /savedata/update - update save data
|
|
|
|
// /savedata/update - update save data
|
|
|
|
func (s *Server) handleSavedataUpdate(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func handleSavedataUpdate(uuid []byte, slot int, save any) error {
|
|
|
|
uuid, err := getUUIDFromRequest(r)
|
|
|
|
err := db.UpdateAccountLastActivity(uuid)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, err.Error(), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = db.UpdateAccountLastActivity(uuid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Print("failed to update account last activity")
|
|
|
|
log.Print("failed to update account last activity")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hexUUID := hex.EncodeToString(uuid)
|
|
|
|
hexUUID := hex.EncodeToString(uuid)
|
|
|
|
|
|
|
|
|
|
|
|
switch r.URL.Query().Get("datatype") {
|
|
|
|
switch save := save.(type) {
|
|
|
|
case "0": // System
|
|
|
|
case defs.SystemSaveData: // System
|
|
|
|
var system defs.SystemSaveData
|
|
|
|
if save.TrainerID == 0 && save.SecretID == 0 {
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&system)
|
|
|
|
return fmt.Errorf("invalid system data")
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to decode request body: %s", err), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if system.TrainerID == 0 && system.SecretID == 0 {
|
|
|
|
|
|
|
|
httpError(w, r, "invalid system data", http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = db.UpdateAccountStats(uuid, system.GameStats)
|
|
|
|
err = db.UpdateAccountStats(uuid, save.GameStats)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to update account stats: %s", err), http.StatusBadRequest)
|
|
|
|
return fmt.Errorf("failed to update account stats: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var gobBuffer bytes.Buffer
|
|
|
|
var gobBuffer bytes.Buffer
|
|
|
|
err = gob.NewEncoder(&gobBuffer).Encode(system)
|
|
|
|
err = gob.NewEncoder(&gobBuffer).Encode(save)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to serialize save: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to serialize save: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
zstdWriter, err := zstd.NewWriter(nil)
|
|
|
|
zstdWriter, err := zstd.NewWriter(nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to create zstd writer, %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to create zstd writer, %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
compressed := zstdWriter.EncodeAll(gobBuffer.Bytes(), nil)
|
|
|
|
compressed := zstdWriter.EncodeAll(gobBuffer.Bytes(), nil)
|
|
|
|
|
|
|
|
|
|
|
|
err = os.MkdirAll("userdata/"+hexUUID, 0755)
|
|
|
|
err = os.MkdirAll("userdata/"+hexUUID, 0755)
|
|
|
|
if err != nil && !os.IsExist(err) {
|
|
|
|
if err != nil && !os.IsExist(err) {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to create userdata folder: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to create userdata folder: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = os.WriteFile("userdata/"+hexUUID+"/system.pzs", compressed, 0644)
|
|
|
|
err = os.WriteFile("userdata/"+hexUUID+"/system.pzs", compressed, 0644)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to write save file: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to write save file: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "1": // Session
|
|
|
|
case defs.SessionSaveData: // Session
|
|
|
|
slotID, err := strconv.Atoi(r.URL.Query().Get("slot"))
|
|
|
|
if slot < 0 || slot >= sessionSlotCount {
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("slot id %d out of range", slot)
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to convert slot id: %s", err), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if slotID < 0 || slotID >= sessionSlotCount {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("slot id %d out of range", slotID), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileName := "session"
|
|
|
|
fileName := "session"
|
|
|
|
if slotID != 0 {
|
|
|
|
if slot != 0 {
|
|
|
|
fileName += strconv.Itoa(slotID)
|
|
|
|
fileName += strconv.Itoa(slot)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var session defs.SessionSaveData
|
|
|
|
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&session)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to decode request body: %s", err), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var gobBuffer bytes.Buffer
|
|
|
|
var gobBuffer bytes.Buffer
|
|
|
|
err = gob.NewEncoder(&gobBuffer).Encode(session)
|
|
|
|
err = gob.NewEncoder(&gobBuffer).Encode(save)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to serialize save: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to serialize save: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
zstdWriter, err := zstd.NewWriter(nil)
|
|
|
|
zstdWriter, err := zstd.NewWriter(nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to create zstd writer, %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to create zstd writer, %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
compressed := zstdWriter.EncodeAll(gobBuffer.Bytes(), nil)
|
|
|
|
compressed := zstdWriter.EncodeAll(gobBuffer.Bytes(), nil)
|
|
|
|
|
|
|
|
|
|
|
|
err = os.MkdirAll("userdata/"+hexUUID, 0755)
|
|
|
|
err = os.MkdirAll("userdata/"+hexUUID, 0755)
|
|
|
|
if err != nil && !os.IsExist(err) {
|
|
|
|
if err != nil && !os.IsExist(err) {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to create userdata folder: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf(fmt.Sprintf("failed to create userdata folder: %s", err))
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = os.WriteFile(fmt.Sprintf("userdata/%s/%s.pzs", hexUUID, fileName), compressed, 0644)
|
|
|
|
err = os.WriteFile(fmt.Sprintf("userdata/%s/%s.pzs", hexUUID, fileName), compressed, 0644)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to write save file: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to write save file: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
httpError(w, r, "invalid data type", http.StatusBadRequest)
|
|
|
|
return fmt.Errorf("invalid data type")
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// /savedata/delete - delete save data
|
|
|
|
// /savedata/delete - delete save data
|
|
|
|
func (s *Server) handleSavedataDelete(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func handleSavedataDelete(uuid []byte, datatype, slot int) error {
|
|
|
|
uuid, err := getUUIDFromRequest(r)
|
|
|
|
err := db.UpdateAccountLastActivity(uuid)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, err.Error(), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = db.UpdateAccountLastActivity(uuid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Print("failed to update account last activity")
|
|
|
|
log.Print("failed to update account last activity")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hexUUID := hex.EncodeToString(uuid)
|
|
|
|
hexUUID := hex.EncodeToString(uuid)
|
|
|
|
|
|
|
|
|
|
|
|
switch r.URL.Query().Get("datatype") {
|
|
|
|
switch datatype {
|
|
|
|
case "0": // System
|
|
|
|
case 0: // System
|
|
|
|
err := os.Remove("userdata/" + hexUUID + "/system.pzs")
|
|
|
|
err := os.Remove("userdata/" + hexUUID + "/system.pzs")
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to delete save file: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to delete save file: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "1": // Session
|
|
|
|
case 1: // Session
|
|
|
|
slotID, err := strconv.Atoi(r.URL.Query().Get("slot"))
|
|
|
|
if slot < 0 || slot >= sessionSlotCount {
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("slot id %d out of range", slot)
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to convert slot id: %s", err), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if slotID < 0 || slotID >= sessionSlotCount {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("slot id %d out of range", slotID), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileName := "session"
|
|
|
|
fileName := "session"
|
|
|
|
if slotID != 0 {
|
|
|
|
if slot != 0 {
|
|
|
|
fileName += strconv.Itoa(slotID)
|
|
|
|
fileName += strconv.Itoa(slot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = os.Remove(fmt.Sprintf("userdata/%s/%s.pzs", hexUUID, fileName))
|
|
|
|
err = os.Remove(fmt.Sprintf("userdata/%s/%s.pzs", hexUUID, fileName))
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to delete save file: %s", err), http.StatusInternalServerError)
|
|
|
|
return fmt.Errorf("failed to delete save file: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
httpError(w, r, "invalid data type", http.StatusBadRequest)
|
|
|
|
return fmt.Errorf("invalid data type")
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SavedataClearResponse struct {
|
|
|
|
type SavedataClearResponse struct {
|
|
|
@ -248,73 +164,46 @@ type SavedataClearResponse struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// /savedata/clear - mark session save data as cleared and delete
|
|
|
|
// /savedata/clear - mark session save data as cleared and delete
|
|
|
|
func (s *Server) handleSavedataClear(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func handleSavedataClear(uuid []byte, slot int, save defs.SessionSaveData) (SavedataClearResponse, error) {
|
|
|
|
uuid, err := getUUIDFromRequest(r)
|
|
|
|
err := db.UpdateAccountLastActivity(uuid)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, err.Error(), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = db.UpdateAccountLastActivity(uuid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Print("failed to update account last activity")
|
|
|
|
log.Print("failed to update account last activity")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
slotID, err := strconv.Atoi(r.URL.Query().Get("slot"))
|
|
|
|
if slot < 0 || slot >= sessionSlotCount {
|
|
|
|
if err != nil {
|
|
|
|
return SavedataClearResponse{}, fmt.Errorf("slot id %d out of range", slot)
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to convert slot id: %s", err), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if slotID < 0 || slotID >= sessionSlotCount {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("slot id %d out of range", slotID), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var session defs.SessionSaveData
|
|
|
|
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&session)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to decode request body: %s", err), http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sessionCompleted := validateSessionCompleted(session)
|
|
|
|
sessionCompleted := validateSessionCompleted(save)
|
|
|
|
newCompletion := false
|
|
|
|
newCompletion := false
|
|
|
|
|
|
|
|
|
|
|
|
if session.GameMode == 3 && session.Seed == dailyRunSeed {
|
|
|
|
if save.GameMode == 3 && save.Seed == dailyRunSeed {
|
|
|
|
waveCompleted := session.WaveIndex
|
|
|
|
waveCompleted := save.WaveIndex
|
|
|
|
if !sessionCompleted {
|
|
|
|
if !sessionCompleted {
|
|
|
|
waveCompleted--
|
|
|
|
waveCompleted--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = db.AddOrUpdateAccountDailyRun(uuid, session.Score, waveCompleted)
|
|
|
|
err = db.AddOrUpdateAccountDailyRun(uuid, save.Score, waveCompleted)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("failed to add or update daily run record: %s", err)
|
|
|
|
log.Printf("failed to add or update daily run record: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if sessionCompleted {
|
|
|
|
if sessionCompleted {
|
|
|
|
newCompletion, err = db.TryAddSeedCompletion(uuid, session.Seed, int(session.GameMode))
|
|
|
|
newCompletion, err = db.TryAddSeedCompletion(uuid, save.Seed, int(save.GameMode))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("failed to mark seed as completed: %s", err)
|
|
|
|
log.Printf("failed to mark seed as completed: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
response, err := json.Marshal(SavedataClearResponse{Success: newCompletion})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to marshal response json: %s", err), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileName := "session"
|
|
|
|
fileName := "session"
|
|
|
|
if slotID != 0 {
|
|
|
|
if slot != 0 {
|
|
|
|
fileName += strconv.Itoa(slotID)
|
|
|
|
fileName += strconv.Itoa(slot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = os.Remove(fmt.Sprintf("userdata/%s/%s.pzs", hex.EncodeToString(uuid), fileName))
|
|
|
|
err = os.Remove(fmt.Sprintf("userdata/%s/%s.pzs", hex.EncodeToString(uuid), fileName))
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
httpError(w, r, fmt.Sprintf("failed to delete save file: %s", err), http.StatusInternalServerError)
|
|
|
|
return SavedataClearResponse{}, fmt.Errorf("failed to delete save file: %s", err)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
w.Write(response)
|
|
|
|
return SavedataClearResponse{Success: newCompletion}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|