From 5ed3817c8685ac156bac46e57ee66aaae56c261d Mon Sep 17 00:00:00 2001 From: eccentric Date: Thu, 9 Nov 2023 19:35:39 +0000 Subject: [PATCH] Add Banner Equiping --- handlers/auth.go | 3 --- handlers/profile.go | 61 +++++++++++++++++++++++++++++++++++++++------ person/fortnite.go | 58 +++++++++++++++++++++++++++++++++++------- 3 files changed, 103 insertions(+), 19 deletions(-) diff --git a/handlers/auth.go b/handlers/auth.go index 78a07d7..9f964ef 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -215,9 +215,6 @@ func GetPublicAccounts(c *fiber.Ctx) error { }) } - aid.PrintJSON(accountIds) - aid.PrintJSON(response) - return c.Status(fiber.StatusOK).JSON(response) } diff --git a/handlers/profile.go b/handlers/profile.go index 0d2dc5d..f5250e3 100644 --- a/handlers/profile.go +++ b/handlers/profile.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "strconv" "strings" "time" @@ -17,6 +18,7 @@ var ( "ClientQuestLogin": PostQueryProfileAction, "MarkItemSeen": PostMarkItemSeenAction, "EquipBattleRoyaleCustomization": PostEquipBattleRoyaleCustomizationAction, + "SetBattleRoyaleBanner": PostSetBattleRoyaleBannerAction, } ) @@ -68,7 +70,7 @@ func PostMarkItemSeenAction(c *fiber.Ctx, person *p.Person, profile *p.Profile) err := c.BodyParser(&body) if err != nil { - return c.Status(400).JSON(aid.ErrorBadRequest("Invalid Body")) + return fmt.Errorf("invalid Body") } for _, itemId := range body.ItemIds { @@ -93,21 +95,24 @@ func PostEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, pr err := c.BodyParser(&body) if err != nil { - return c.Status(400).JSON(aid.ErrorBadRequest("Invalid Body")) + return fmt.Errorf("invalid Body") } item := profile.Items.GetItem(body.ItemToSlot) if item == nil { - return c.Status(400).JSON(aid.ErrorBadRequest("Item not found")) + if body.ItemToSlot != "" && !strings.Contains(strings.ToLower(body.ItemToSlot), "random") { + return fmt.Errorf("item not found") + } + + item = &p.Item{ + ID: body.ItemToSlot, + } } attr := profile.Attributes.GetAttributeByKey("favorite_" + strings.ToLower(body.SlotName)) if attr == nil { - return c.Status(400).JSON(aid.ErrorBadRequest("Attribute not found")) + return fmt.Errorf("attribute not found") } - defer func() { - go attr.Save() - }() switch body.SlotName { case "Dance": @@ -122,5 +127,47 @@ func PostEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, pr attr.ValueJSON = aid.JSONStringify(item.ID) } + go attr.Save() + return nil +} + +func PostSetBattleRoyaleBannerAction(c *fiber.Ctx, person *p.Person, profile *p.Profile) error { + var body struct { + HomebaseBannerColorID string `json:"homebaseBannerColorId" binding:"required"` + HomebaseBannerIconID string `json:"homebaseBannerIconId" binding:"required"` + } + + err := c.BodyParser(&body) + if err != nil { + return fmt.Errorf("invalid Body") + } + + colorItem := person.CommonCoreProfile.Items.GetItemByTemplateID("HomebaseBannerColor:"+body.HomebaseBannerColorID) + if colorItem == nil { + return fmt.Errorf("color item not found") + } + + iconItem := person.CommonCoreProfile.Items.GetItemByTemplateID("HomebaseBannerIcon:"+body.HomebaseBannerIconID) + if iconItem == nil { + return fmt.Errorf("icon item not found") + } + + iconAttr := profile.Attributes.GetAttributeByKey("banner_icon") + if iconAttr == nil { + return fmt.Errorf("icon attribute not found") + } + + colorAttr := profile.Attributes.GetAttributeByKey("banner_color") + if colorAttr == nil { + return fmt.Errorf("color attribute not found") + } + + iconAttr.ValueJSON = aid.JSONStringify(strings.Split(iconItem.TemplateID, ":")[1]) + colorAttr.ValueJSON = aid.JSONStringify(strings.Split(colorItem.TemplateID, ":")[1]) + + go func() { + iconAttr.Save() + colorAttr.Save() + }() return nil } \ No newline at end of file diff --git a/person/fortnite.go b/person/fortnite.go index 4e7a3e9..7df75da 100644 --- a/person/fortnite.go +++ b/person/fortnite.go @@ -1,21 +1,59 @@ package person -import "github.com/ectrc/snow/aid" +import ( + "strconv" -func NewFortnitePerson(displayName string, key string) { + "github.com/ectrc/snow/aid" +) + +var ( + defaultAthenaItems = []string{ + "AthenaCharacter:CID_001_Athena_Commando_F_Default", + "AthenaPickaxe:DefaultPickaxe", + "AthenaGlider:DefaultGlider", + "AthenaDance:EID_DanceMoves", + } + defaultCommonCoreItems = []string{ + "Currency:MtxPurchased", + "HomebaseBannerIcon:StandardBanner", + "HomebaseBannerColor:DefaultColor", + } +) + +func NewFortnitePerson(displayName string, key string) *Person { person := NewPerson() person.DisplayName = displayName person.AccessKey = key - person.AthenaProfile.Items.AddItem(NewItem("AthenaCharacter:CID_001_Athena_Commando_F_Default", 1)) - person.AthenaProfile.Items.AddItem(NewItem("AthenaCharacter:CID_032_Athena_Commando_M_Medieval", 1)) - person.AthenaProfile.Items.AddItem(NewItem("AthenaCharacter:CID_033_Athena_Commando_F_Medieval", 1)) - person.AthenaProfile.Items.AddItem(NewItem("AthenaPickaxe:DefaultPickaxe", 1)) - person.AthenaProfile.Items.AddItem(NewItem("AthenaGlider:DefaultGlider", 1)) - person.AthenaProfile.Items.AddItem(NewItem("AthenaDance:EID_DanceMoves", 1)) - person.CommonCoreProfile.Items.AddItem(NewItem("Currency:MtxPurchased", 0)) person.Profile0Profile.Items.AddItem(NewItem("Currency:MtxPurchased", 0)) // for season 2 and bellow + for _, item := range defaultAthenaItems { + person.AthenaProfile.Items.AddItem(NewItem(item, 1)) + } + + for _, item := range defaultCommonCoreItems { + if item == "HomebaseBannerIcon:StandardBanner" { + for i := 1; i < 32; i++ { + person.CommonCoreProfile.Items.AddItem(NewItem(item+strconv.Itoa(i), 1)) + } + continue + } + + if item == "HomebaseBannerColor:DefaultColor" { + for i := 1; i < 22; i++ { + person.CommonCoreProfile.Items.AddItem(NewItem(item+strconv.Itoa(i), 1)) + } + continue + } + + if item == "Currency:MtxPurchased" { + person.CommonCoreProfile.Items.AddItem(NewItem(item, 0)) + continue + } + + person.CommonCoreProfile.Items.AddItem(NewItem(item, 1)) + } + person.AthenaProfile.Attributes.AddAttribute(NewAttribute("mfa_reward_claimed", true)) person.AthenaProfile.Attributes.AddAttribute(NewAttribute("rested_xp_overflow", 0)) person.AthenaProfile.Attributes.AddAttribute(NewAttribute("lifetime_wins", 0)) @@ -69,4 +107,6 @@ func NewFortnitePerson(displayName string, key string) { person.CommonCoreProfile.Attributes.AddAttribute(NewAttribute("gift_history", aid.JSON{})) person.Save() + + return person } \ No newline at end of file