diff --git a/handlers/parties.go b/handlers/parties.go new file mode 100644 index 0000000..2fce347 --- /dev/null +++ b/handlers/parties.go @@ -0,0 +1,25 @@ +package handlers + +import ( + "github.com/ectrc/snow/aid" + p "github.com/ectrc/snow/person" + "github.com/gofiber/fiber/v2" +) + +func GetUserParties(c *fiber.Ctx) error { + person := c.Locals("person").(*p.Person) + + response := aid.JSON{ + "current": []aid.JSON{}, + "invites": []aid.JSON{}, + "pending": []aid.JSON{}, + "pings": []aid.JSON{}, + } + + person.Parties.Range(func(key string, party *p.Party) bool { + response["current"] = append(response["current"].([]aid.JSON), party.GenerateFortniteParty()) + return true + }) + + return c.Status(200).JSON(response) +} \ No newline at end of file diff --git a/main.go b/main.go index c47c638..b738d89 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,6 @@ func init() { discord.IntialiseClient() fortnite.PreloadCosmetics() fortnite.GenerateRandomStorefront() - fortnite.GeneratePlaylistImages() for _, username := range aid.Config.Accounts.Gods { found := person.FindByDisplay(username) @@ -153,14 +152,16 @@ func main() { lightswitch.Use(handlers.MiddlewareFortnite) lightswitch.Get("/service/bulk/status", handlers.GetLightswitchBulkStatus) + party := r.Group("/party/api/v1/Fortnite") + party.Use(handlers.MiddlewareFortnite) + party.Get("/user/:accountId", handlers.GetUserParties) + snow := r.Group("/snow") - snow.Get("/image/:playlist", handlers.GetPlaylistImage) - if aid.Config.API.Debug { - snow.Get("/cache", handlers.GetCachedPlayers) - snow.Get("/config", handlers.GetSnowConfig) - snow.Get("/sockets", handlers.GetConnectedSockets) - snow.Get("/cosmetics", handlers.GetPreloadedCosmetics) - } + snow.Use(handlers.MiddlewareOnlyDebug) + snow.Get("/cache", handlers.GetCachedPlayers) + snow.Get("/config", handlers.GetSnowConfig) + snow.Get("/sockets", handlers.GetConnectedSockets) + snow.Get("/cosmetics", handlers.GetPreloadedCosmetics) discord := snow.Group("/discord") discord.Get("/", handlers.GetDiscordOAuthURL) diff --git a/person/parties.go b/person/parties.go index 5fbd78d..b36ca4f 100644 --- a/person/parties.go +++ b/person/parties.go @@ -1,13 +1,27 @@ package person import ( + "sync" + "time" + "github.com/ectrc/snow/aid" "github.com/google/uuid" ) +type PartyMember struct{ + Person *Person + ConnectionID string + Meta map[string]interface{} + Connections map[string]aid.JSON + Role string +} + type Party struct{ ID string - Members []*Person + Members []*PartyMember + Config map[string]interface{} + Meta map[string]interface{} + m sync.Mutex } var ( @@ -17,8 +31,130 @@ var ( func NewParty() *Party { party := &Party{ ID: uuid.New().String(), + Members: []*PartyMember{}, + Config: make(map[string]interface{}), + Meta: make(map[string]interface{}), } + Parties.Set(party.ID, party) - + return party +} + +func (p *Party) AddMember(person *Person) { + p.m.Lock() + defer p.m.Unlock() + + partyMember := &PartyMember{ + Person: person, + Meta: make(map[string]interface{}), + Connections: make(map[string]aid.JSON), + Role: "MEMBER", + } + + p.Members = append(p.Members, partyMember) + person.Parties.Set(p.ID, p) + // xmpp to person and rest of party to say new member! +} + +func (p *Party) RemoveMember(person *Person) { + p.m.Lock() + defer p.m.Unlock() + + for i, member := range p.Members { + if member.Person == person { + p.Members = append(p.Members[:i], p.Members[i+1:]...) + break + } + } + + if len(p.Members) == 0 { + Parties.Delete(p.ID) + } + + person.Parties.Delete(p.ID) + // xmpp to person and rest of party to say member left! +} + +func (p *Party) UpdateMeta(key string, value interface{}) { + p.m.Lock() + defer p.m.Unlock() + + p.Meta[key] = value + // xmpp to rest of party to say meta updated! +} + +func (p *Party) DeleteMeta(key string) { + p.m.Lock() + defer p.m.Unlock() + + delete(p.Meta, key) + // xmpp to rest of party to say meta deleted! +} + +func (p *Party) UpdateMemberMeta(person *Person, key string, value interface{}) { + p.m.Lock() + defer p.m.Unlock() + + for _, member := range p.Members { + if member.Person == person { + member.Meta[key] = value + // xmpp to person and rest of party to say member meta updated! + break + } + } +} + +func (p *Party) DeleteMemberMeta(person *Person, key string) { + p.m.Lock() + defer p.m.Unlock() + + for _, member := range p.Members { + if member.Person == person { + delete(member.Meta, key) + // xmpp to person and rest of party to say member meta deleted! + break + } + } +} + +func (p *Party) UpdateConfig(key string, value interface{}) { + p.m.Lock() + defer p.m.Unlock() + + p.Config[key] = value + // xmpp to rest of party to say config updated! +} + +func (p *Party) DeleteConfig(key string) { + p.m.Lock() + defer p.m.Unlock() + + delete(p.Config, key) + // xmpp to rest of party to say config deleted! +} + +func (p *Party) GenerateFortniteParty() aid.JSON { + p.m.Lock() + defer p.m.Unlock() + + party := aid.JSON{ + "id": p.ID, + "members": aid.JSON{}, + "config": p.Config, + "meta": p.Meta, + "created_at": "0000-00-00T00:00:00Z", + "updated_at": time.Now().Format(time.RFC3339), + "revision": 0, + } + + for _, member := range p.Members { + party["members"].(aid.JSON)[member.Person.ID] = aid.JSON{ + "account_id": member.Person.ID, + "role": member.Role, + "meta": member.Meta, + "connections": member.Connections, + } + } + return party } \ No newline at end of file diff --git a/person/person.go b/person/person.go index 88c67eb..09571ea 100644 --- a/person/person.go +++ b/person/person.go @@ -22,6 +22,7 @@ type Person struct { Discord *storage.DB_DiscordPerson BanHistory aid.GenericSyncMap[storage.DB_BanStatus] Relationships aid.GenericSyncMap[Relationship] + Parties aid.GenericSyncMap[Party] } func NewPerson() *Person { diff --git a/storage/hotfix.go b/storage/hotfix.go index 295d972..8609824 100644 --- a/storage/hotfix.go +++ b/storage/hotfix.go @@ -17,10 +17,10 @@ Protocol=ws ServerAddr="ws://`+ aid.Config.API.Host + aid.Config.API.Port +`/?" [OnlineSubsystemMcp] -bUsePartySystemV2=false +bUsePartySystemV2=true [OnlineSubsystemMcp.OnlinePartySystemMcpAdapter] -bUsePartySystemV2=false +bUsePartySystemV2=true [XMPP] bEnableWebsockets=true diff --git a/storage/mem/background.png b/storage/mem/background.png deleted file mode 100644 index b873be8..0000000 Binary files a/storage/mem/background.png and /dev/null differ diff --git a/storage/mem/glow.png b/storage/mem/glow.png deleted file mode 100644 index 21a82b2..0000000 Binary files a/storage/mem/glow.png and /dev/null differ