Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SKPG-Tech committed Aug 16, 2024
1 parent 7beab19 commit 58d7eaf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Jean-François Geyelin
Copyright (c) 2024 PewPew Live

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 9 additions & 5 deletions level_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -39,7 +38,12 @@ type LevelManifest struct {

// GetDir returns the path to the content directory.
func GetDir() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
cwd, err := os.Getwd()
if err != nil {
panic(err)
}

dir, err := filepath.Abs(cwd)
if err != nil {
panic(err)
}
Expand All @@ -65,7 +69,7 @@ func ListLevels(dir string) []LevelJSON {
return stat_err
}

log.Print("path: " + path + ", file_info.Mode():" + string(file_info.Mode()))
log.Print("path: " + path + ", file_info.Mode():" + file_info.Mode().String())

fileIsASymLink := file_info.Mode()&os.ModeSymlink != 0
// If the file is a symlink, recursively walk it.
Expand All @@ -88,7 +92,7 @@ func ListLevels(dir string) []LevelJSON {
return nil
}

jsonContent, err := ioutil.ReadFile(path)
jsonContent, err := os.ReadFile(path)
if err != nil {
log.Print("Failed to read file at path " + path)
return nil
Expand Down Expand Up @@ -187,5 +191,5 @@ func GetLevelData(levelID string, disableFilter bool) (bytes.Buffer, error) {

// GetLevelManifest returns the manifest of the level.
func GetLevelManifest(levelID string) ([]byte, error) {
return ioutil.ReadFile(levelID + "manifest.json")
return os.ReadFile(levelID + "manifest.json")
}
8 changes: 3 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
)

func setHeaders(w http.ResponseWriter, r *http.Request) {
func setHeaders(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Cache-Control", "no-store")
Expand All @@ -30,13 +30,13 @@ func list(w http.ResponseWriter, r *http.Request) {
http.Error(w, marshalingError.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, string(jsonStr))
fmt.Fprint(w, string(jsonStr))
}

func getStrippedLevelID(r *http.Request) (string, error) {
levelID := r.FormValue("level_uuid")
if levelID == "" {
return "", errors.New("Missing level_id paramenter in request")
return "", errors.New("missing level_id paramenter in request")
}
return levelID, nil
}
Expand Down Expand Up @@ -81,8 +81,6 @@ func main() {
http.Handle("/", fs)

http.HandleFunc("/custom_levels/get_public_levels", list)
// Deprecated. Remove once Era2 has been released for a while.
http.HandleFunc("/custom_levels/list2", list)
http.HandleFunc("/custom_levels/get_level", getLevel)
http.HandleFunc("/custom_levels/get_level_manifest", getLevelManifest)

Expand Down

0 comments on commit 58d7eaf

Please sign in to comment.