From a179961138509048608c1b6a6587b45b0e9d3864 Mon Sep 17 00:00:00 2001 From: Eccentric Date: Wed, 14 Feb 2024 23:07:05 +0000 Subject: [PATCH] Proper affiliate rewards --- handlers/client.go | 59 +++++++++++++++++++++++++++++----------------- main.go | 4 ---- person/changes.go | 2 +- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/handlers/client.go b/handlers/client.go index 2b1c180..e892dfa 100644 --- a/handlers/client.go +++ b/handlers/client.go @@ -17,7 +17,7 @@ import ( var ( clientActions = map[string]func(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error { "QueryProfile": clientQueryProfileAction, - "ClientQuestLogin": clientQueryProfileAction, + "ClientQuestLogin": clientClientQuestLoginAction, "MarkItemSeen": clientMarkItemSeenAction, "SetItemFavoriteStatusBatch": clientSetItemFavoriteStatusBatchAction, "EquipBattleRoyaleCustomization": clientEquipBattleRoyaleCustomizationAction, @@ -89,28 +89,28 @@ func PostClientProfileAction(c *fiber.Ctx) error { delete(profileSnapshots, profile.Type) multiUpdate := []aid.JSON{} - for key := range profileSnapshots { - profile := person.GetProfileFromType(key) - if profile == nil { - continue - } - profile.Revision++ - - if len(profile.Changes) == 0 { - continue - } - - multiUpdate = append(multiUpdate, aid.JSON{ - "profileId": profile.Type, - "profileRevision": profile.Revision, - "profileCommandRevision": profile.Revision, - "profileChangesBaseRevision": profile.Revision - 1, - "profileChanges": profile.Changes, - }) - - profile.ClearProfileChanges() - go profile.Save() + for key := range profileSnapshots { + profile := person.GetProfileFromType(key) + if profile == nil { + continue } + profile.Revision++ + + if len(profile.Changes) == 0 { + continue + } + + multiUpdate = append(multiUpdate, aid.JSON{ + "profileId": profile.Type, + "profileRevision": profile.Revision, + "profileCommandRevision": profile.Revision, + "profileChangesBaseRevision": profile.Revision - 1, + "profileChanges": profile.Changes, + }) + + profile.ClearProfileChanges() + go profile.Save() + } return c.Status(200).JSON(aid.JSON{ "profileId": c.Query("profileId"), @@ -130,6 +130,10 @@ func clientQueryProfileAction(c *fiber.Ctx, person *p.Person, profile *p.Profile return nil } +func clientClientQuestLoginAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error { + return nil +} + func clientMarkItemSeenAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error { var body struct { ItemIds []string `json:"itemIds"` @@ -664,6 +668,17 @@ func clientPurchaseCatalogEntryAction(c *fiber.Ctx, person *p.Person, profile *p "primary": true, }) + affiliate := person.CommonCoreProfile.Attributes.GetAttributeByKey("mtx_affiliate") + if affiliate == nil { + return c.Status(400).JSON(aid.ErrorBadRequest("Invalid affiliate attribute")) + } + + creator := p.Find(p.AttributeConvert[string](affiliate)) + if creator != nil { + creator.CommonCoreProfile.Items.GetItemByTemplateID("Currency:MtxPurchased").Quantity += body.ExpectedTotalPrice + creator.Profile0Profile.Items.GetItemByTemplateID("Currency:MtxPurchased").Quantity += body.ExpectedTotalPrice + } + return nil } diff --git a/main.go b/main.go index ed1fc94..ae5919b 100644 --- a/main.go +++ b/main.go @@ -152,12 +152,10 @@ func main() { party := r.Group("/party/api/v1/Fortnite") party.Use(handlers.MiddlewareFortnite) - 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) - party.Get("/parties/:partyId", handlers.GetPartyForMember) party.Post("/parties", handlers.PostPartyCreate) party.Post("/parties/:partyId/invites/:accountId", handlers.PostPartyInvite) @@ -166,9 +164,7 @@ func main() { party.Patch("/parties/:partyId", handlers.PatchPartyUpdateState) party.Patch("/parties/:partyId/members/:accountId/meta", handlers.PatchPartyUpdateMemberState) party.Delete("/parties/:partyId/members/:accountId", handlers.DeletePartyMember) - // post /parties/:partyId/members/:accountId/conferences/connection (join a voip channel) - // get /user/:accountId/pings/:pinger/friendId/parties (get pings from a friend) // post /user/:accountId/pings/:pinger/join (join a party from a ping) // post /user/:friendId/pings/:accountId (send a ping) diff --git a/person/changes.go b/person/changes.go index bd9ae76..227e546 100644 --- a/person/changes.go +++ b/person/changes.go @@ -4,7 +4,7 @@ import "github.com/ectrc/snow/aid" type FullProfileUpdate struct { ChangeType string `json:"changeType"` - Profile aid.JSON `json:"profile"` + Profile interface{} `json:"profile"` } type StatModified struct {