2023-10-31 22:40:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-09 14:32:53 +00:00
|
|
|
_ "embed"
|
2023-12-07 19:29:47 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-10-31 23:19:52 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2023-12-13 22:52:16 +00:00
|
|
|
"github.com/ectrc/snow/discord"
|
2023-11-21 23:42:39 +00:00
|
|
|
"github.com/ectrc/snow/fortnite"
|
2023-11-03 23:48:50 +00:00
|
|
|
"github.com/ectrc/snow/handlers"
|
2023-12-19 16:47:13 +00:00
|
|
|
"github.com/ectrc/snow/person"
|
2023-10-31 22:40:14 +00:00
|
|
|
"github.com/ectrc/snow/storage"
|
2023-11-03 23:48:50 +00:00
|
|
|
|
2023-12-09 15:35:33 +00:00
|
|
|
"github.com/goccy/go-json"
|
2024-01-20 01:58:57 +00:00
|
|
|
"github.com/gofiber/contrib/websocket"
|
2023-11-03 23:48:50 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2023-10-31 22:40:14 +00:00
|
|
|
)
|
2023-12-09 14:32:53 +00:00
|
|
|
|
|
|
|
//go:embed config.ini
|
|
|
|
var configFile []byte
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
func init() {
|
2023-12-09 14:32:53 +00:00
|
|
|
aid.LoadConfig(configFile)
|
2023-12-31 13:14:24 +00:00
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
var device storage.Storage
|
2023-11-01 21:51:14 +00:00
|
|
|
switch aid.Config.Database.Type {
|
2023-10-31 22:40:14 +00:00
|
|
|
case "postgres":
|
|
|
|
postgresStorage := storage.NewPostgresStorage()
|
2023-11-02 17:50:52 +00:00
|
|
|
if aid.Config.Database.DropAllTables {
|
2023-10-31 22:40:14 +00:00
|
|
|
postgresStorage.DropTables()
|
2024-01-03 19:56:23 +00:00
|
|
|
aid.Print("(snow) all tables dropped and reset")
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
2023-11-09 18:53:19 +00:00
|
|
|
postgresStorage.MigrateAll()
|
2023-10-31 22:40:14 +00:00
|
|
|
device = postgresStorage
|
2023-12-07 19:29:47 +00:00
|
|
|
default:
|
|
|
|
panic("Invalid database type: " + aid.Config.Database.Type)
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
2023-10-31 23:19:52 +00:00
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
storage.Repo = storage.NewStorage(device)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2023-12-13 22:52:16 +00:00
|
|
|
discord.IntialiseClient()
|
2023-11-26 22:39:05 +00:00
|
|
|
fortnite.PreloadCosmetics(aid.Config.Fortnite.Season)
|
2023-12-06 22:26:42 +00:00
|
|
|
fortnite.GenerateRandomStorefront()
|
2023-12-09 00:20:53 +00:00
|
|
|
fortnite.GeneratePlaylistImages()
|
2023-10-31 22:40:14 +00:00
|
|
|
|
2023-12-19 16:47:13 +00:00
|
|
|
if found := person.FindByDisplay("god"); found == nil {
|
2024-01-03 23:25:17 +00:00
|
|
|
god := fortnite.NewFortnitePerson("god", true)
|
|
|
|
god.AddPermission("all")
|
2023-12-19 16:47:13 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-31 22:40:14 +00:00
|
|
|
func main() {
|
2023-11-09 18:53:19 +00:00
|
|
|
r := fiber.New(fiber.Config{
|
|
|
|
DisableStartupMessage: true,
|
|
|
|
JSONEncoder: json.Marshal,
|
|
|
|
JSONDecoder: json.Unmarshal,
|
|
|
|
})
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
r.Use(aid.FiberLogger())
|
|
|
|
r.Use(aid.FiberLimiter())
|
|
|
|
r.Use(aid.FiberCors())
|
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
r.Get("/content/api/pages/fortnite-game", handlers.GetContentPages)
|
2023-11-20 21:20:26 +00:00
|
|
|
r.Get("/waitingroom/api/waitingroom", handlers.GetWaitingRoomStatus)
|
|
|
|
r.Get("/region", handlers.GetRegion)
|
2023-11-21 16:36:04 +00:00
|
|
|
r.Put("/profile/play_region", handlers.AnyNoContent)
|
2024-01-03 23:25:17 +00:00
|
|
|
r.Get("/api/v1/search/:accountId", handlers.GetPersonSearch)
|
2023-12-03 18:25:03 +00:00
|
|
|
r.Post("/api/v1/assets/Fortnite/:versionId/:assetName", handlers.PostAssets)
|
2024-01-20 01:58:57 +00:00
|
|
|
|
|
|
|
r.Get("//", func(c *fiber.Ctx) error { return c.Redirect("/socket") })
|
|
|
|
r.Get("/socket", handlers.MiddlewareWebsocket, websocket.New(handlers.WebsocketConnection))
|
2023-11-20 21:20:26 +00:00
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
account := r.Group("/account/api")
|
2023-11-09 18:42:28 +00:00
|
|
|
account.Get("/public/account", handlers.GetPublicAccounts)
|
2023-11-03 23:48:50 +00:00
|
|
|
account.Get("/public/account/:accountId", handlers.GetPublicAccount)
|
|
|
|
account.Get("/public/account/:accountId/externalAuths", handlers.GetPublicAccountExternalAuths)
|
2023-11-09 18:42:28 +00:00
|
|
|
account.Get("/public/account/displayName/:displayName", handlers.GetPublicAccountByDisplayName)
|
2023-12-26 03:39:12 +00:00
|
|
|
account.Get("/oauth/verify", handlers.GetTokenVerify)
|
2023-12-09 15:35:33 +00:00
|
|
|
account.Post("/oauth/token", handlers.PostFortniteToken)
|
2023-12-19 21:48:01 +00:00
|
|
|
account.Delete("/oauth/sessions/kill", handlers.DeleteToken)
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
fortnite := r.Group("/fortnite/api")
|
2023-11-05 22:08:53 +00:00
|
|
|
fortnite.Get("/receipts/v1/account/:accountId/receipts", handlers.GetFortniteReceipts)
|
2023-12-26 03:18:12 +00:00
|
|
|
fortnite.Get("/v2/versioncheck/:version", handlers.GetFortniteVersion)
|
2023-11-05 22:08:53 +00:00
|
|
|
fortnite.Get("/calendar/v1/timeline", handlers.GetFortniteTimeline)
|
|
|
|
|
|
|
|
storefront := fortnite.Group("/storefront/v2")
|
2023-12-19 21:48:01 +00:00
|
|
|
storefront.Use(handlers.MiddlewareFortnite)
|
2023-11-05 22:08:53 +00:00
|
|
|
storefront.Get("/catalog", handlers.GetStorefrontCatalog)
|
|
|
|
storefront.Get("/keychain", handlers.GetStorefrontKeychain)
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
matchmaking := fortnite.Group("/matchmaking")
|
2023-11-05 22:08:53 +00:00
|
|
|
matchmaking.Get("/session/findPlayer/:accountId", handlers.GetMatchmakingSession)
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
storage := fortnite.Group("/cloudstorage")
|
|
|
|
storage.Get("/system", handlers.GetCloudStorageFiles)
|
|
|
|
storage.Get("/system/config", handlers.GetCloudStorageConfig)
|
|
|
|
storage.Get("/system/:fileName", handlers.GetCloudStorageFile)
|
2023-11-09 18:42:28 +00:00
|
|
|
|
|
|
|
user := storage.Group("/user")
|
2023-12-19 21:48:01 +00:00
|
|
|
user.Use(handlers.MiddlewareFortnite)
|
2023-11-09 18:42:28 +00:00
|
|
|
user.Get("/:accountId", handlers.GetUserStorageFiles)
|
|
|
|
user.Get("/:accountId/:fileName", handlers.GetUserStorageFile)
|
|
|
|
user.Put("/:accountId/:fileName", handlers.PutUserStorageFile)
|
2023-12-31 13:14:24 +00:00
|
|
|
|
2024-01-03 23:25:17 +00:00
|
|
|
friends := r.Group("/friends/api")
|
|
|
|
friends.Use(handlers.MiddlewareFortnite)
|
|
|
|
friends.Get("/public/friends/:accountId", handlers.GetFriendList)
|
|
|
|
friends.Post("/public/friends/:accountId/:wanted", handlers.PostCreateFriend)
|
|
|
|
friends.Delete("/public/friends/:accountId/:wanted", handlers.DeleteFriend)
|
|
|
|
friends.Get("/:version/:accountId/summary", handlers.GetFriendListSummary)
|
|
|
|
friends.Get("/:version/:accountId/friends/:wanted", handlers.PostCreateFriend)
|
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
game := fortnite.Group("/game/v2")
|
2023-11-05 22:08:53 +00:00
|
|
|
game.Get("/enabled_features", handlers.GetGameEnabledFeatures)
|
|
|
|
game.Post("/tryPlayOnPlatform/account/:accountId", handlers.PostGamePlatform)
|
|
|
|
game.Post("/grant_access/:accountId", handlers.PostGameAccess)
|
2023-12-03 18:25:03 +00:00
|
|
|
game.Post("/creative/discovery/surface/:accountId", handlers.PostDiscovery)
|
2023-11-19 22:20:00 +00:00
|
|
|
game.Post("/profileToken/verify/:accountId", handlers.AnyNoContent)
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
profile := game.Group("/profile/:accountId")
|
2023-12-19 21:48:01 +00:00
|
|
|
profile.Use(handlers.MiddlewareFortnite)
|
2024-01-03 19:51:46 +00:00
|
|
|
profile.Post("/client/:action", handlers.PostClientProfileAction)
|
|
|
|
profile.Post("/dedicated_server/:action", handlers.PostServerProfileAction)
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
lightswitch := r.Group("/lightswitch/api")
|
2023-12-19 21:48:01 +00:00
|
|
|
lightswitch.Use(handlers.MiddlewareFortnite)
|
2023-11-03 23:48:50 +00:00
|
|
|
lightswitch.Get("/service/bulk/status", handlers.GetLightswitchBulkStatus)
|
2023-11-01 21:33:25 +00:00
|
|
|
|
2023-11-26 22:39:05 +00:00
|
|
|
snow := r.Group("/snow")
|
2023-12-07 23:25:17 +00:00
|
|
|
snow.Get("/cosmetics", handlers.GetPreloadedCosmetics)
|
|
|
|
snow.Get("/image/:playlist", handlers.GetPlaylistImage)
|
2023-11-26 22:39:05 +00:00
|
|
|
|
2023-12-09 15:35:33 +00:00
|
|
|
discord := snow.Group("/discord")
|
|
|
|
discord.Get("/", handlers.GetDiscordOAuthURL)
|
2023-12-31 13:14:24 +00:00
|
|
|
|
2023-12-09 15:35:33 +00:00
|
|
|
player := snow.Group("/player")
|
2023-12-19 21:48:01 +00:00
|
|
|
player.Use(handlers.MiddlewareWeb)
|
2023-12-16 22:08:37 +00:00
|
|
|
player.Get("/", handlers.GetPlayer)
|
2023-12-09 15:35:33 +00:00
|
|
|
player.Get("/locker", handlers.GetPlayerLocker)
|
|
|
|
|
2023-11-09 18:53:19 +00:00
|
|
|
r.Hooks().OnListen(func(ld fiber.ListenData) error {
|
2024-01-03 19:56:23 +00:00
|
|
|
aid.Print("(fiber) listening on " + aid.Config.API.Host + ":" + ld.Port)
|
2023-11-09 18:53:19 +00:00
|
|
|
return nil
|
|
|
|
})
|
2023-12-31 13:14:24 +00:00
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
r.All("*", func(c *fiber.Ctx) error { return c.Status(fiber.StatusNotFound).JSON(aid.ErrorNotFound) })
|
2023-12-31 13:14:24 +00:00
|
|
|
|
2023-12-09 15:35:33 +00:00
|
|
|
err := r.Listen("0.0.0.0" + aid.Config.API.Port)
|
2023-12-07 19:29:47 +00:00
|
|
|
if err != nil {
|
2024-01-03 23:51:42 +00:00
|
|
|
panic(fmt.Sprintf("(fiber) ailed to listen: %v", err))
|
2023-12-07 19:29:47 +00:00
|
|
|
}
|
2023-12-27 04:15:26 +00:00
|
|
|
}
|