From 0222b4fbccd27c1c06385a75eab6f71b24218273 Mon Sep 17 00:00:00 2001 From: 2vb <2vb@protonmail.com> Date: Tue, 26 Dec 2023 20:15:26 -0800 Subject: [PATCH 1/5] Skins in game + Save user settings to local file --- .gitignore | 3 +- handlers/storage.go | 71 +++++++++++++++++++++++++++++++++++++++++++-- main.go | 3 +- 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 82b125c..92a0214 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ tmp config.ini -hide_* \ No newline at end of file +hide_* +UserStorage \ No newline at end of file diff --git a/handlers/storage.go b/handlers/storage.go index d519888..cf3adb9 100644 --- a/handlers/storage.go +++ b/handlers/storage.go @@ -144,13 +144,78 @@ func GetCloudStorageFile(c *fiber.Ctx) error { } func GetUserStorageFiles(c *fiber.Ctx) error { - return c.Status(fiber.StatusOK).JSON([]aid.JSON{}) + basePath := "UserStorage/" + c.Params("accountId") + "/" + if _, err := os.Stat(basePath); os.IsNotExist(err) { + if err := os.MkdirAll(basePath, 0755); err != nil { + return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) + } + } else { + filePath := basePath + fileContent, err := os.ReadFile(filePath + "ClientSettings.Sav") + if err != nil { + return c.Status(fiber.StatusOK).JSON(aid.JSON{}) + } + settingsHash := sha1.Sum(fileContent) + settingsHash256 := sha1.Sum(fileContent) + return c.Status(fiber.StatusOK).JSON(aid.JSON{ + "uniqueFilename": "ClientSettings.Sav", + "filename": "ClientSettings.Sav", + "hash": hex.EncodeToString(settingsHash[:]), + "hash256": hex.EncodeToString(settingsHash256[:]), + "length": len(fileContent), + "contentType": "application/octet-stream", + "uploaded": "2021-01-01T00:00:00.000Z", + "storageType": "S3", + "doNotCache": false, + "storageIds": []string{"primary"}, + }) + } + return c.Status(fiber.StatusOK).JSON(aid.JSON{}) } func GetUserStorageFile(c *fiber.Ctx) error { - return c.Status(fiber.StatusOK).JSON(aid.JSON{}) + basePath := "UserStorage/" + c.Params("accountId") + "/" + if _, err := os.Stat(basePath); os.IsNotExist(err) { + if err := os.MkdirAll(basePath, 0755); err != nil { + return c.Status(fiber.StatusOK).JSON(aid.JSON{}) + } + } else { + filePath := basePath + c.Params("fileName") + _, err := os.Stat(filePath) + if err != nil { + return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorNotFound) + } else { + return c.Status(fiber.StatusOK).SendFile(filePath) + } + + } + return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) } func PutUserStorageFile(c *fiber.Ctx) error { + bytes := string(c.BodyRaw()) + + if c.Request().Header.ContentLength() > 400000 || strings.ToLower(c.Params("fileName")) != "clientsettings.sav" { + return c.Status(fiber.StatusBadRequest).JSON(aid.ErrorBadRequest("Invalid File")) + } + + filePath := "UserStorage/" + c.Params("accountId") + "/" + if _, err := os.Stat(filePath); os.IsNotExist(err) { + if err := os.MkdirAll(filePath, 0755); err != nil { + return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) + } + } + + file, err := os.Create(filePath + c.Params("fileName")) + if err != nil { + return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) + } + defer file.Close() + + _, err = io.Copy(file, strings.NewReader(bytes)) + if err != nil { + return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) + } + return c.Status(fiber.StatusOK).JSON(aid.JSON{}) -} \ No newline at end of file +} diff --git a/main.go b/main.go index 117aca1..8532896 100644 --- a/main.go +++ b/main.go @@ -108,6 +108,7 @@ func main() { profile := game.Group("/profile/:accountId") profile.Use(handlers.MiddlewareFortnite) profile.Post("/client/:action", handlers.PostProfileAction) + profile.Post("/dedicated_server/:action", handlers.PostProfileAction) lightswitch := r.Group("/lightswitch/api") lightswitch.Use(handlers.MiddlewareFortnite) @@ -136,4 +137,4 @@ func main() { if err != nil { panic(fmt.Sprintf("Failed to listen: %v", err)) } -} \ No newline at end of file +} From 04f2aab84f6cd4e6c44e34b672f47afa73f9570e Mon Sep 17 00:00:00 2001 From: 2vb <2vb@protonmail.com> Date: Tue, 26 Dec 2023 20:19:56 -0800 Subject: [PATCH 2/5] Add imports that I forgot to --- handlers/storage.go | 71 +++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/handlers/storage.go b/handlers/storage.go index cf3adb9..cea1c45 100644 --- a/handlers/storage.go +++ b/handlers/storage.go @@ -3,6 +3,9 @@ package handlers import ( "crypto/sha1" "encoding/hex" + "io" + "os" + "strings" "github.com/ectrc/snow/aid" "github.com/gofiber/fiber/v2" @@ -79,39 +82,39 @@ func GetCloudStorageFiles(c *fiber.Ctx) error { return c.Status(fiber.StatusOK).JSON([]aid.JSON{ { "uniqueFilename": "DefaultEngine.ini", - "filename": "DefaultEngine.ini", - "hash": hex.EncodeToString(engineHash[:]), - "hash256": hex.EncodeToString(engineHash256[:]), - "length": len(TEMP_STORAGE["DefaultEngine.ini"]), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, + "filename": "DefaultEngine.ini", + "hash": hex.EncodeToString(engineHash[:]), + "hash256": hex.EncodeToString(engineHash256[:]), + "length": len(TEMP_STORAGE["DefaultEngine.ini"]), + "contentType": "application/octet-stream", + "uploaded": "2021-01-01T00:00:00.000Z", + "storageType": "S3", + "doNotCache": false, + "storageIds": []string{"primary"}, }, { "uniqueFilename": "DefaultGame.ini", - "filename": "DefaultGame.ini", - "hash": hex.EncodeToString(gameHash[:]), - "hash256": hex.EncodeToString(gameHash256[:]), - "length": len(TEMP_STORAGE["DefaultGame.ini"]), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, + "filename": "DefaultGame.ini", + "hash": hex.EncodeToString(gameHash[:]), + "hash256": hex.EncodeToString(gameHash256[:]), + "length": len(TEMP_STORAGE["DefaultGame.ini"]), + "contentType": "application/octet-stream", + "uploaded": "2021-01-01T00:00:00.000Z", + "storageType": "S3", + "doNotCache": false, + "storageIds": []string{"primary"}, }, { "uniqueFilename": "DefaultRuntimeOptions.ini", - "filename": "DefaultRuntimeOptions.ini", - "hash": hex.EncodeToString(runtimeHash[:]), - "hash256": hex.EncodeToString(runtimeHash256[:]), - "length": len(TEMP_STORAGE["DefaultRuntimeOptions.ini"]), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, + "filename": "DefaultRuntimeOptions.ini", + "hash": hex.EncodeToString(runtimeHash[:]), + "hash256": hex.EncodeToString(runtimeHash256[:]), + "length": len(TEMP_STORAGE["DefaultRuntimeOptions.ini"]), + "contentType": "application/octet-stream", + "uploaded": "2021-01-01T00:00:00.000Z", + "storageType": "S3", + "doNotCache": false, + "storageIds": []string{"primary"}, }, }) } @@ -119,13 +122,13 @@ func GetCloudStorageFiles(c *fiber.Ctx) error { func GetCloudStorageConfig(c *fiber.Ctx) error { return c.Status(fiber.StatusOK).JSON(aid.JSON{ "enumerateFilesPath": "/api/cloudstorage/system", - "enableMigration": true, - "enableWrites": true, - "epicAppName": "Live", - "isAuthenticated": true, - "disableV2": true, - "lastUpdated": "0000-00-00T00:00:00.000Z", - "transports": []string{}, + "enableMigration": true, + "enableWrites": true, + "epicAppName": "Live", + "isAuthenticated": true, + "disableV2": true, + "lastUpdated": "0000-00-00T00:00:00.000Z", + "transports": []string{}, }) } From 1d1e81d8a6c69290a8db36db1b5dadfcab3adcfb Mon Sep 17 00:00:00 2001 From: 2vb <2vb@protonmail.com> Date: Tue, 26 Dec 2023 20:35:12 -0800 Subject: [PATCH 3/5] Full locker discord command --- discord/admin.go | 28 +++++++++++++++++++ discord/handlers.go | 23 +++++++++++++++ handlers/storage.go | 68 ++++++++++++++++++++++----------------------- 3 files changed, 85 insertions(+), 34 deletions(-) diff --git a/discord/admin.go b/discord/admin.go index 2c512fd..00085f2 100644 --- a/discord/admin.go +++ b/discord/admin.go @@ -5,6 +5,7 @@ import ( "github.com/bwmarrin/discordgo" "github.com/ectrc/snow/aid" + "github.com/ectrc/snow/fortnite" "github.com/ectrc/snow/person" "github.com/ectrc/snow/storage" ) @@ -133,6 +134,33 @@ func banHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { }) } +func GiveFLHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { + looker := person.FindByDiscord(i.Member.User.ID) + if looker == nil { + s.InteractionRespond(i.Interaction, &ErrorNoPermission) + return + } + + if !looker.HasPermission(person.PermissionBan) { + s.InteractionRespond(i.Interaction, &ErrorNoPermission) + return + } + + player := getPersonFromOptions(i.ApplicationCommandData(), s) + if player == nil { + s.InteractionRespond(i.Interaction, &ErrorInvalidDisplayOrDiscord) + return + } + + fortnite.GiveEverything(player) + s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: player.DisplayName + " has been granted everything.", + }, + }) +} + func unbanHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { looker := person.FindByDiscord(i.Member.User.ID) if looker == nil { diff --git a/discord/handlers.go b/discord/handlers.go index 15a6c9c..5c94749 100644 --- a/discord/handlers.go +++ b/discord/handlers.go @@ -109,6 +109,29 @@ func addCommands() { Handler: banHandler, AdminOnly: true, }) + + addCommand(&DiscordCommand{ + Command: &discordgo.ApplicationCommand{ + Name: "give-everything", + Description: "Give a player full locker", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionUser, + Name: "discord", + Description: "The discord account of the player.", + Required: false, + }, + { + Type: discordgo.ApplicationCommandOptionString, + Name: "display", + Description: "The display name of the player.", + Required: false, + }, + }, + }, + Handler: GiveFLHandler, + AdminOnly: true, + }) addCommand(&DiscordCommand{ Command: &discordgo.ApplicationCommand{ diff --git a/handlers/storage.go b/handlers/storage.go index cea1c45..b1c6dbc 100644 --- a/handlers/storage.go +++ b/handlers/storage.go @@ -82,39 +82,39 @@ func GetCloudStorageFiles(c *fiber.Ctx) error { return c.Status(fiber.StatusOK).JSON([]aid.JSON{ { "uniqueFilename": "DefaultEngine.ini", - "filename": "DefaultEngine.ini", - "hash": hex.EncodeToString(engineHash[:]), - "hash256": hex.EncodeToString(engineHash256[:]), - "length": len(TEMP_STORAGE["DefaultEngine.ini"]), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, + "filename": "DefaultEngine.ini", + "hash": hex.EncodeToString(engineHash[:]), + "hash256": hex.EncodeToString(engineHash256[:]), + "length": len(TEMP_STORAGE["DefaultEngine.ini"]), + "contentType": "application/octet-stream", + "uploaded": "2021-01-01T00:00:00.000Z", + "storageType": "S3", + "doNotCache": false, + "storageIds": []string{"primary"}, }, { "uniqueFilename": "DefaultGame.ini", - "filename": "DefaultGame.ini", - "hash": hex.EncodeToString(gameHash[:]), - "hash256": hex.EncodeToString(gameHash256[:]), - "length": len(TEMP_STORAGE["DefaultGame.ini"]), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, + "filename": "DefaultGame.ini", + "hash": hex.EncodeToString(gameHash[:]), + "hash256": hex.EncodeToString(gameHash256[:]), + "length": len(TEMP_STORAGE["DefaultGame.ini"]), + "contentType": "application/octet-stream", + "uploaded": "2021-01-01T00:00:00.000Z", + "storageType": "S3", + "doNotCache": false, + "storageIds": []string{"primary"}, }, { "uniqueFilename": "DefaultRuntimeOptions.ini", - "filename": "DefaultRuntimeOptions.ini", - "hash": hex.EncodeToString(runtimeHash[:]), - "hash256": hex.EncodeToString(runtimeHash256[:]), - "length": len(TEMP_STORAGE["DefaultRuntimeOptions.ini"]), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, + "filename": "DefaultRuntimeOptions.ini", + "hash": hex.EncodeToString(runtimeHash[:]), + "hash256": hex.EncodeToString(runtimeHash256[:]), + "length": len(TEMP_STORAGE["DefaultRuntimeOptions.ini"]), + "contentType": "application/octet-stream", + "uploaded": "2021-01-01T00:00:00.000Z", + "storageType": "S3", + "doNotCache": false, + "storageIds": []string{"primary"}, }, }) } @@ -122,13 +122,13 @@ func GetCloudStorageFiles(c *fiber.Ctx) error { func GetCloudStorageConfig(c *fiber.Ctx) error { return c.Status(fiber.StatusOK).JSON(aid.JSON{ "enumerateFilesPath": "/api/cloudstorage/system", - "enableMigration": true, - "enableWrites": true, - "epicAppName": "Live", - "isAuthenticated": true, - "disableV2": true, - "lastUpdated": "0000-00-00T00:00:00.000Z", - "transports": []string{}, + "enableMigration": true, + "enableWrites": true, + "epicAppName": "Live", + "isAuthenticated": true, + "disableV2": true, + "lastUpdated": "0000-00-00T00:00:00.000Z", + "transports": []string{}, }) } From b02c2829c7fbefff522e75c456abf8209f32acc7 Mon Sep 17 00:00:00 2001 From: 2vb <2vb@protonmail.com> Date: Tue, 26 Dec 2023 20:41:58 -0800 Subject: [PATCH 4/5] Move SQL function to after discord response --- discord/admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/admin.go b/discord/admin.go index 00085f2..ea29203 100644 --- a/discord/admin.go +++ b/discord/admin.go @@ -152,13 +152,13 @@ func GiveFLHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { return } - fortnite.GiveEverything(player) s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: player.DisplayName + " has been granted everything.", }, }) + fortnite.GiveEverything(player) } func unbanHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { From 54e72c315103a6e7cb05ddcf02e35f7daaabba51 Mon Sep 17 00:00:00 2001 From: 2vb <2vb@protonmail.com> Date: Sun, 31 Dec 2023 05:14:24 -0800 Subject: [PATCH 5/5] Removal of saving user settings as a local file --- .gitignore | 3 +- handlers/storage.go | 70 +-------------------------------------------- main.go | 10 +++---- 3 files changed, 7 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index 92a0214..82b125c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,4 @@ tmp config.ini -hide_* -UserStorage \ No newline at end of file +hide_* \ No newline at end of file diff --git a/handlers/storage.go b/handlers/storage.go index b1c6dbc..b631fed 100644 --- a/handlers/storage.go +++ b/handlers/storage.go @@ -3,9 +3,6 @@ package handlers import ( "crypto/sha1" "encoding/hex" - "io" - "os" - "strings" "github.com/ectrc/snow/aid" "github.com/gofiber/fiber/v2" @@ -147,78 +144,13 @@ func GetCloudStorageFile(c *fiber.Ctx) error { } func GetUserStorageFiles(c *fiber.Ctx) error { - basePath := "UserStorage/" + c.Params("accountId") + "/" - if _, err := os.Stat(basePath); os.IsNotExist(err) { - if err := os.MkdirAll(basePath, 0755); err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - } else { - filePath := basePath - fileContent, err := os.ReadFile(filePath + "ClientSettings.Sav") - if err != nil { - return c.Status(fiber.StatusOK).JSON(aid.JSON{}) - } - settingsHash := sha1.Sum(fileContent) - settingsHash256 := sha1.Sum(fileContent) - return c.Status(fiber.StatusOK).JSON(aid.JSON{ - "uniqueFilename": "ClientSettings.Sav", - "filename": "ClientSettings.Sav", - "hash": hex.EncodeToString(settingsHash[:]), - "hash256": hex.EncodeToString(settingsHash256[:]), - "length": len(fileContent), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, - }) - } - return c.Status(fiber.StatusOK).JSON(aid.JSON{}) + return c.Status(fiber.StatusOK).JSON([]aid.JSON{}) } func GetUserStorageFile(c *fiber.Ctx) error { - basePath := "UserStorage/" + c.Params("accountId") + "/" - if _, err := os.Stat(basePath); os.IsNotExist(err) { - if err := os.MkdirAll(basePath, 0755); err != nil { return c.Status(fiber.StatusOK).JSON(aid.JSON{}) - } - } else { - filePath := basePath + c.Params("fileName") - _, err := os.Stat(filePath) - if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorNotFound) - } else { - return c.Status(fiber.StatusOK).SendFile(filePath) - } - - } - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) } func PutUserStorageFile(c *fiber.Ctx) error { - bytes := string(c.BodyRaw()) - - if c.Request().Header.ContentLength() > 400000 || strings.ToLower(c.Params("fileName")) != "clientsettings.sav" { - return c.Status(fiber.StatusBadRequest).JSON(aid.ErrorBadRequest("Invalid File")) - } - - filePath := "UserStorage/" + c.Params("accountId") + "/" - if _, err := os.Stat(filePath); os.IsNotExist(err) { - if err := os.MkdirAll(filePath, 0755); err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - } - - file, err := os.Create(filePath + c.Params("fileName")) - if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - defer file.Close() - - _, err = io.Copy(file, strings.NewReader(bytes)) - if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - return c.Status(fiber.StatusOK).JSON(aid.JSON{}) } diff --git a/main.go b/main.go index 8532896..a51a3dc 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ var configFile []byte func init() { aid.LoadConfig(configFile) - + var device storage.Storage switch aid.Config.Database.Type { case "postgres": @@ -97,7 +97,7 @@ func main() { user.Get("/:accountId", handlers.GetUserStorageFiles) user.Get("/:accountId/:fileName", handlers.GetUserStorageFile) user.Put("/:accountId/:fileName", handlers.PutUserStorageFile) - + game := fortnite.Group("/game/v2") game.Get("/enabled_features", handlers.GetGameEnabledFeatures) game.Post("/tryPlayOnPlatform/account/:accountId", handlers.PostGamePlatform) @@ -120,7 +120,7 @@ func main() { discord := snow.Group("/discord") discord.Get("/", handlers.GetDiscordOAuthURL) - + player := snow.Group("/player") player.Use(handlers.MiddlewareWeb) player.Get("/", handlers.GetPlayer) @@ -130,9 +130,9 @@ func main() { aid.Print("Listening on " + aid.Config.API.Host + ":" + ld.Port) return nil }) - + r.All("*", func(c *fiber.Ctx) error { return c.Status(fiber.StatusNotFound).JSON(aid.ErrorNotFound) }) - + err := r.Listen("0.0.0.0" + aid.Config.API.Port) if err != nil { panic(fmt.Sprintf("Failed to listen: %v", err))