From 6fc1694930215ec2d9dca1e98901c071ce56c594 Mon Sep 17 00:00:00 2001 From: Eccentric Date: Sat, 10 Feb 2024 02:27:42 +0000 Subject: [PATCH] Add deleting friends --- handlers/friends.go | 30 ++++++++++++++++++++++++++++++ main.go | 1 + person/relationships.go | 16 ++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/handlers/friends.go b/handlers/friends.go index a421e9a..b5458f1 100644 --- a/handlers/friends.go +++ b/handlers/friends.go @@ -56,6 +56,36 @@ func PostCreateFriend(c *fiber.Ctx) error { } func DeleteFriend(c *fiber.Ctx) error { + person := c.Locals("person").(*p.Person) + + relationship, found := person.Relationships.Get(c.Params("wanted")) + if !found { + return c.Status(404).JSON(aid.ErrorNotFound) + } + + from, found := socket.JabberSockets.Get(relationship.From.ID) + if found { + from.JabberSendMessageToPerson(aid.JSON{ + "type": "com.epicgames.friends.core.apiobjects.FriendRemoval", + "timestamp": time.Now().Format(time.RFC3339), + "payload": relationship.GenerateFortniteFriendRemovalEntry(p.GenerateTypeFromPerson), + }) + from.JabberNotifyFriends() + } + + towards, found := socket.JabberSockets.Get(relationship.Towards.ID) + if found { + towards.JabberSendMessageToPerson(aid.JSON{ + "type": "com.epicgames.friends.core.apiobjects.FriendRemoval", + "timestamp": time.Now().Format(time.RFC3339), + "payload": relationship.GenerateFortniteFriendRemovalEntry(p.GenerateTypeTowardsPerson), + }) + towards.JabberNotifyFriends() + } + + relationship.Delete() + person.Relationships.Delete(c.Params("friend")) + return c.SendStatus(204) } diff --git a/main.go b/main.go index 964cb74..541436e 100644 --- a/main.go +++ b/main.go @@ -135,6 +135,7 @@ func main() { friends.Delete("/public/friends/:accountId/:wanted", handlers.DeleteFriend) friends.Get("/:version/:accountId/summary", handlers.GetFriendListSummary) friends.Post("/:version/:accountId/friends/:wanted", handlers.PostCreateFriend) + friends.Delete("/:version/:accountId/friends/:wanted", handlers.DeleteFriend) game := fortnite.Group("/game/v2") game.Get("/enabled_features", handlers.GetGameEnabledFeatures) diff --git a/person/relationships.go b/person/relationships.go index 6920006..74d41b3 100644 --- a/person/relationships.go +++ b/person/relationships.go @@ -50,6 +50,22 @@ func (r *Relationship) GenerateFortniteFriendEntry(t RelationshipGenerateType) a return result } +func (r *Relationship) GenerateFortniteFriendRemovalEntry(t RelationshipGenerateType) aid.JSON { + result := aid.JSON{ + "reason": "DELETED", + } + + switch t { + case GenerateTypeFromPerson: + result["accountId"] = r.Towards.ID + case GenerateTypeTowardsPerson: + result["accountId"] = r.From.ID + } + + return result +} + + func (r *Relationship) GenerateFortniteSummaryEntry(t RelationshipGenerateType) aid.JSON { result := aid.JSON{ "created": time.Now().Add(-time.Hour * 24 * 3).Format(time.RFC3339),