snow/main.go

224 lines
8.7 KiB
Go
Raw Normal View History

2023-10-31 22:40:14 +00:00
package main
import (
_ "embed"
2023-12-07 19:29:47 +00:00
"fmt"
"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"
"github.com/ectrc/snow/handlers"
"github.com/ectrc/snow/person"
"github.com/ectrc/snow/shop"
2023-10-31 22:40:14 +00:00
"github.com/ectrc/snow/storage"
2023-12-09 15:35:33 +00:00
"github.com/goccy/go-json"
2024-01-28 22:04:40 +00:00
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
2023-10-31 22:40:14 +00:00
)
//go:embed config.ini
var configFile []byte
2023-10-31 22:40:14 +00:00
func init() {
aid.LoadConfig(configFile)
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
}
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 22:40:14 +00:00
storage.Repo = storage.NewStorage(device)
2024-02-04 19:49:31 +00:00
if aid.Config.Amazon.Enabled {
storage.Repo.Amazon = storage.NewAmazonClient(aid.Config.Amazon.BucketURI, aid.Config.Amazon.AccessKeyID, aid.Config.Amazon.SecretAccessKey, aid.Config.Amazon.ClientSettingsBucket)
}
2023-10-31 22:40:14 +00:00
}
func init() {
2023-12-13 22:52:16 +00:00
discord.IntialiseClient()
fortnite.PreloadCosmetics()
fortnite.PreloadEvents()
shop.GetShop()
2023-10-31 22:40:14 +00:00
2024-02-03 02:33:54 +00:00
for _, username := range aid.Config.Accounts.Gods {
found := person.FindByDisplay(username)
if found == nil {
2024-02-19 01:49:14 +00:00
found = fortnite.NewFortnitePersonWithId(username, username, aid.Config.Fortnite.Everything)
2024-02-03 02:33:54 +00:00
}
found.Discord = &storage.DB_DiscordPerson{
ID: found.ID,
PersonID: found.ID,
Username: username,
}
found.Save()
2024-02-10 00:34:12 +00:00
found.AddPermission(person.PermissionAllWithRoles)
aid.Print("(snow) max account " + username + " loaded")
}
for _, username := range aid.Config.Accounts.Owners {
found := person.FindByDisplay(username)
if found == nil {
continue
2024-02-03 02:33:54 +00:00
}
2024-02-19 01:49:14 +00:00
found.AddPermission(person.PermissionAllWithRoles)
2024-02-10 00:34:12 +00:00
aid.Print("(snow) owner account " + username + " loaded")
2024-02-03 02:33:54 +00:00
}
}
2024-02-10 00:34:12 +00:00
2023-10-31 22:40:14 +00:00
func main() {
r := fiber.New(fiber.Config{
DisableStartupMessage: true,
JSONEncoder: json.Marshal,
JSONDecoder: json.Unmarshal,
})
r.Use(aid.FiberLogger())
r.Use(aid.FiberLimiter(1000))
r.Use(aid.FiberCors())
r.Get("/region", handlers.GetRegion)
2024-01-20 23:08:29 +00:00
r.Get("/content/api/pages/fortnite-game", handlers.GetContentPages)
r.Get("/waitingroom/api/waitingroom", handlers.GetWaitingRoomStatus)
2024-02-10 00:34:12 +00:00
r.Get("/affiliate/api/public/affiliates/slug/:slug", handlers.GetAffiliate)
r.Get("/profile/privacy_settings", handlers.MiddlewareFortnite, handlers.GetPrivacySettings)
2024-02-04 20:03:53 +00:00
r.Put("/profile/play_region", handlers.AnyNoContent)
r.Get("/api/v1/search/:accountId", handlers.GetPersonSearch)
2024-01-28 22:04:40 +00:00
r.Get("/", handlers.RedirectSocket)
r.Get("/socket", handlers.MiddlewareWebsocket, websocket.New(handlers.WebsocketConnection))
account := r.Group("/account/api")
2023-11-09 18:42:28 +00:00
account.Get("/public/account", handlers.GetPublicAccounts)
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)
fortnite := r.Group("/fortnite/api")
fortnite.Get("/receipts/v1/account/:accountId/receipts", handlers.MiddlewareFortnite, handlers.GetFortniteReceipts)
2023-12-26 03:18:12 +00:00
fortnite.Get("/v2/versioncheck/:version", handlers.GetFortniteVersion)
fortnite.Get("/calendar/v1/timeline", handlers.GetFortniteTimeline)
storefront := fortnite.Group("/storefront/v2")
2023-12-19 21:48:01 +00:00
storefront.Use(handlers.MiddlewareFortnite)
2024-02-14 20:30:55 +00:00
storefront.Use(aid.FiberLimiter(4))
storefront.Get("/catalog", handlers.GetStorefrontCatalog)
storefront.Get("/keychain", handlers.GetStorefrontKeychain)
2024-02-19 04:07:40 +00:00
r.Get("/catalog/api/shared/bulk/offers", handlers.GetStorefrontCatalogBulkOffers)
matchmaking := fortnite.Group("/matchmaking")
matchmaking.Get("/session/findPlayer/:accountId", handlers.GetMatchmakingSession)
storage := fortnite.Group("/cloudstorage")
storage.Get("/system", handlers.GetCloudStorageFiles)
storage.Get("/system/config", handlers.GetCloudStorageConfig)
storage.Get("/system/:fileName", handlers.GetCloudStorageFile)
2024-02-12 20:29:02 +00:00
storage.Get("/user/:accountId", handlers.MiddlewareFortnite, handlers.GetUserStorageFiles)
storage.Get("/user/:accountId/:fileName", handlers.MiddlewareFortnite, handlers.GetUserStorageFile)
storage.Put("/user/:accountId/:fileName", handlers.MiddlewareFortnite, handlers.PutUserStorageFile)
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)
2024-02-04 16:01:24 +00:00
friends.Post("/:version/:accountId/friends/:wanted", handlers.PostCreateFriend)
2024-02-10 02:27:42 +00:00
friends.Delete("/:version/:accountId/friends/:wanted", handlers.DeleteFriend)
2024-01-03 23:25:17 +00:00
events := r.Group("/api/v1/events/Fortnite")
events.Use(handlers.MiddlewareFortnite)
events.Get("/download/:accountId", handlers.GetEvents)
events.Get("/:eventId/history/:accountId", handlers.GetEventsBulkHistory)
game := fortnite.Group("/game/v2")
game.Get("/enabled_features", handlers.GetGameEnabledFeatures)
game.Post("/tryPlayOnPlatform/account/:accountId", handlers.PostGamePlatform)
game.Post("/grant_access/:accountId", handlers.PostGameAccess)
2023-11-19 22:20:00 +00:00
game.Post("/profileToken/verify/:accountId", handlers.AnyNoContent)
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)
lightswitch := r.Group("/lightswitch/api")
2023-12-19 21:48:01 +00:00
lightswitch.Use(handlers.MiddlewareFortnite)
lightswitch.Get("/service/bulk/status", handlers.GetLightswitchBulkStatus)
purchasing := r.Group("/purchase")
purchasing.Get("/", handlers.GetHtmlPurchasePage)
purchasing.Get("/offer", handlers.MiddlewareFortnite, handlers.GetPurchaseOffer)
purchasing.Post("/offer", handlers.MiddlewareFortnite, handlers.PostPurchaseOffer)
purchasing.Get("/assets", handlers.GetPurchaseAsset)
2024-02-11 19:09:23 +00:00
party := r.Group("/party/api/v1/Fortnite")
party.Use(handlers.MiddlewareFortnite)
2024-02-14 20:30:55 +00:00
party.Get("/user/:accountId", handlers.GetPartiesForUser)
party.Get("/user/:accountId/settings/privacy", handlers.GetPartyUserPrivacy)
party.Get("/user/:accountId/notifications/undelivered/count", handlers.GetPartyNotifications)
party.Get("/user/:accountId/pings/:friendId/parties", handlers.GetPartyPingsFromFriend)
2024-02-17 14:40:17 +00:00
party.Post("/user/:accountId/pings/:friendId/join", handlers.PostPartyJoinFromPing)
party.Delete("/user/:accountId/pings/:friendId", handlers.PostPartyDeletePings)
2024-02-12 20:29:02 +00:00
party.Get("/parties/:partyId", handlers.GetPartyForMember)
2024-02-14 20:30:55 +00:00
party.Post("/parties", handlers.PostPartyCreate)
party.Post("/parties/:partyId/invites/:accountId", handlers.PostPartyInvite)
party.Post("/parties/:partyId/members/:accountId/join", handlers.PostPartyJoin)
2024-02-14 22:20:17 +00:00
party.Post("/parties/:partyId/members/:accountId/promote", handlers.PostPartyPromoteMember)
2024-02-14 20:30:55 +00:00
party.Patch("/parties/:partyId", handlers.PatchPartyUpdateState)
party.Patch("/parties/:partyId/members/:accountId/meta", handlers.PatchPartyUpdateMemberState)
party.Delete("/parties/:partyId/members/:accountId", handlers.DeletePartyMember)
2024-02-17 14:40:17 +00:00
party.Post("/members/:friendId/intentions/:accountId", handlers.PostPartyCreateIntention)
2024-02-11 19:09:23 +00:00
snow := r.Group("/snow")
snow.Post("/log", handlers.PostSnowLog)
2023-12-09 15:35:33 +00:00
discord := snow.Group("/discord")
discord.Get("/", handlers.GetDiscordOAuthURL)
launcher := snow.Group("/launcher")
launcher.Get("/", handlers.GetLauncherStatus)
2023-12-09 15:35:33 +00:00
player := snow.Group("/player")
2023-12-19 21:48:01 +00:00
player.Use(handlers.MiddlewareWeb)
player.Get("/", handlers.GetPlayer)
2024-02-19 01:49:14 +00:00
player.Get("/okay", handlers.GetPlayerOkay)
player.Post("/code", handlers.PostPlayerCreateCode)
2024-02-19 01:49:14 +00:00
debug := snow.Group("/")
debug.Use(handlers.MiddlewareOnlyDebug)
debug.Get("/cache", handlers.GetSnowCachedPlayers)
debug.Get("/sockets", handlers.GetSnowConnectedSockets)
debug.Get("/cosmetics", handlers.GetSnowPreloadedCosmetics)
debug.Get("/parties", handlers.GetSnowParties)
debug.Get("/shop", handlers.GetSnowShop)
2023-12-09 15:35:33 +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)
return nil
})
r.All("*", func(c *fiber.Ctx) error { return c.Status(fiber.StatusNotFound).JSON(aid.ErrorNotFound) })
// if aid.Config.Fortnite.Season <= 2 {
// t := handlers.NewServer()
// go t.Listen()
// }
2024-02-16 01:14:14 +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-02-16 01:14:14 +00:00
panic(fmt.Sprintf("(fiber) failed to listen: %v", err))
2023-12-07 19:29:47 +00:00
}
}