mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-08-28 19:44:25 -05:00
DLS1: Implement the 'count' action
This commit is contained in:
@@ -34,3 +34,22 @@ func GetString(buf []byte) string {
|
||||
nullTerminator := bytes.IndexByte(buf, 0)
|
||||
return string(buf[:nullTerminator])
|
||||
}
|
||||
|
||||
// Checks if the given string is composed exclusively of uppercase alphanumeric characters.
|
||||
func IsUppercaseAlphanumeric(str string) bool {
|
||||
strLength := len(str)
|
||||
|
||||
if strLength == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < strLength; i++ {
|
||||
c := str[i]
|
||||
|
||||
if (c < '0' || c > '9') && (c < 'A' || c > 'Z') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
3
dlc/README.md
Normal file
3
dlc/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Downloadable Content
|
||||
|
||||
Create a folder in this directory using the game's game code as the folder name. Afterwards, place downloadable content into the aforementioned folder.
|
||||
30
nas/auth.go
30
nas/auth.go
@@ -5,6 +5,8 @@ import (
|
||||
"github.com/logrusorgru/aurora/v3"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -13,6 +15,10 @@ import (
|
||||
"wwfc/logging"
|
||||
)
|
||||
|
||||
var (
|
||||
dlcDir = "./dlc"
|
||||
)
|
||||
|
||||
func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
@@ -87,6 +93,13 @@ func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
rhgamecd, ok := fields["rhgamecd"]
|
||||
if !ok || !isValidRhgamecd(rhgamecd) {
|
||||
logging.Error(moduleName, "Missing or invalid rhgamecd")
|
||||
replyHTTPError(w, 400, "400 Bad Request")
|
||||
return
|
||||
}
|
||||
|
||||
switch action {
|
||||
case "count":
|
||||
response = []byte(dlsCount(moduleName, fields))
|
||||
@@ -210,7 +223,22 @@ func handleProfanity(moduleName string, fields map[string]string) map[string]str
|
||||
}
|
||||
|
||||
func dlsCount(moduleName string, fields map[string]string) string {
|
||||
return "0"
|
||||
dlcFolder := filepath.Join(dlcDir, fields["rhgamecd"])
|
||||
|
||||
dir, ok := os.ReadDir(dlcFolder)
|
||||
if ok != nil {
|
||||
return "0"
|
||||
}
|
||||
|
||||
return strconv.Itoa(len(dir))
|
||||
}
|
||||
|
||||
func isValidRhgamecd(rhgamecd string) bool {
|
||||
if len(rhgamecd) != 4 {
|
||||
return false
|
||||
}
|
||||
|
||||
return common.IsUppercaseAlphanumeric(rhgamecd)
|
||||
}
|
||||
|
||||
func getDateTime() string {
|
||||
|
||||
Reference in New Issue
Block a user