2023-11-26 22:39:05 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2024-03-10 18:16:42 +00:00
|
|
|
"time"
|
|
|
|
|
2023-12-10 01:55:11 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2023-11-26 22:39:05 +00:00
|
|
|
"github.com/ectrc/snow/fortnite"
|
2023-12-10 01:55:11 +00:00
|
|
|
p "github.com/ectrc/snow/person"
|
2024-03-10 18:16:42 +00:00
|
|
|
"github.com/ectrc/snow/shop"
|
|
|
|
"github.com/ectrc/snow/socket"
|
2023-11-26 22:39:05 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
2024-02-11 18:33:57 +00:00
|
|
|
func MiddlewareOnlyDebug(c *fiber.Ctx) error {
|
|
|
|
if aid.Config.API.Debug {
|
|
|
|
return c.Next()
|
2023-12-07 23:25:17 +00:00
|
|
|
}
|
|
|
|
|
2024-02-11 18:33:57 +00:00
|
|
|
return c.SendStatus(403)
|
|
|
|
}
|
|
|
|
|
2024-02-12 20:29:02 +00:00
|
|
|
func GetSnowPreloadedCosmetics(c *fiber.Ctx) error {
|
2024-02-19 04:07:40 +00:00
|
|
|
return c.JSON(fortnite.DataClient)
|
2023-12-07 23:25:17 +00:00
|
|
|
}
|
2023-12-09 15:35:33 +00:00
|
|
|
|
2024-02-12 20:29:02 +00:00
|
|
|
func GetSnowCachedPlayers(c *fiber.Ctx) error {
|
2024-02-03 15:08:16 +00:00
|
|
|
persons := p.AllFromCache()
|
|
|
|
players := make([]p.PersonSnapshot, len(persons))
|
|
|
|
|
|
|
|
for i, person := range persons {
|
|
|
|
players[i] = *person.Snapshot()
|
|
|
|
}
|
|
|
|
|
2024-02-19 01:49:14 +00:00
|
|
|
return c.Status(200).JSON(players)
|
2024-02-11 18:33:57 +00:00
|
|
|
}
|
2024-02-12 20:29:02 +00:00
|
|
|
|
|
|
|
func GetSnowParties(c *fiber.Ctx) error {
|
|
|
|
parties := []aid.JSON{}
|
|
|
|
|
|
|
|
p.Parties.Range(func(key string, value *p.Party) bool {
|
|
|
|
parties = append(parties, value.GenerateFortniteParty())
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
return c.JSON(parties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetSnowShop(c *fiber.Ctx) error {
|
2024-03-10 18:16:42 +00:00
|
|
|
shop := shop.GetShop()
|
2024-02-19 04:07:40 +00:00
|
|
|
return c.JSON(shop.GenerateFortniteCatalogResponse())
|
2024-02-19 01:49:14 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func PostSnowLog(c *fiber.Ctx) error {
|
|
|
|
var body struct {
|
|
|
|
JSON aid.JSON `json:"json"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.BodyParser(&body); err != nil {
|
|
|
|
return c.Status(400).JSON(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
aid.PrintJSON(body.JSON)
|
|
|
|
return c.JSON(body)
|
|
|
|
}
|
2024-02-19 01:49:14 +00:00
|
|
|
|
|
|
|
func GetPlayer(c *fiber.Ctx) error {
|
|
|
|
person := c.Locals("person").(*p.Person)
|
2024-03-10 18:16:42 +00:00
|
|
|
return c.Status(200).JSON(aid.JSON{
|
|
|
|
"snapshot": person.Snapshot(),
|
|
|
|
"season": aid.JSON{
|
|
|
|
"level": fortnite.DataClient.SnowSeason.GetSeasonLevel(person.CurrentSeasonStats),
|
|
|
|
"xp": fortnite.DataClient.SnowSeason.GetRelativeSeasonXP(person.CurrentSeasonStats),
|
|
|
|
"bookLevel": fortnite.DataClient.SnowSeason.GetBookLevel(person.CurrentSeasonStats),
|
|
|
|
"bookXp": fortnite.DataClient.SnowSeason.GetRelativeBookXP(person.CurrentSeasonStats),
|
|
|
|
},
|
|
|
|
})
|
2024-02-19 01:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetPlayerOkay(c *fiber.Ctx) error {
|
|
|
|
return c.Status(200).SendString("okay")
|
2024-03-10 18:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func PostPlayerCreateCode(c *fiber.Ctx) error {
|
|
|
|
person := c.Locals("person").(*p.Person)
|
|
|
|
code := person.ID + "=" + time.Now().Format("2006-01-02T15:04:05.999Z")
|
|
|
|
encrypted, sig := aid.KeyPair.EncryptAndSignB64([]byte(code))
|
|
|
|
return c.Status(200).SendString(encrypted + "." + sig)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetLauncherStatus(c *fiber.Ctx) error {
|
|
|
|
return c.Status(200).JSON(aid.JSON{
|
|
|
|
"CurrentSeason": aid.Config.Fortnite.Season,
|
|
|
|
"CurrentBuild": aid.Config.Fortnite.Build,
|
|
|
|
"PlayersOnline": aid.FormatNumber(socket.JabberSockets.Len()),
|
|
|
|
})
|
2024-02-12 20:29:02 +00:00
|
|
|
}
|