More party groundwork
This commit is contained in:
parent
3cea75e5a0
commit
0781a3c83e
25
handlers/parties.go
Normal file
25
handlers/parties.go
Normal file
|
@ -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)
|
||||||
|
}
|
9
main.go
9
main.go
|
@ -47,7 +47,6 @@ func init() {
|
||||||
discord.IntialiseClient()
|
discord.IntialiseClient()
|
||||||
fortnite.PreloadCosmetics()
|
fortnite.PreloadCosmetics()
|
||||||
fortnite.GenerateRandomStorefront()
|
fortnite.GenerateRandomStorefront()
|
||||||
fortnite.GeneratePlaylistImages()
|
|
||||||
|
|
||||||
for _, username := range aid.Config.Accounts.Gods {
|
for _, username := range aid.Config.Accounts.Gods {
|
||||||
found := person.FindByDisplay(username)
|
found := person.FindByDisplay(username)
|
||||||
|
@ -153,14 +152,16 @@ func main() {
|
||||||
lightswitch.Use(handlers.MiddlewareFortnite)
|
lightswitch.Use(handlers.MiddlewareFortnite)
|
||||||
lightswitch.Get("/service/bulk/status", handlers.GetLightswitchBulkStatus)
|
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 := r.Group("/snow")
|
||||||
snow.Get("/image/:playlist", handlers.GetPlaylistImage)
|
snow.Use(handlers.MiddlewareOnlyDebug)
|
||||||
if aid.Config.API.Debug {
|
|
||||||
snow.Get("/cache", handlers.GetCachedPlayers)
|
snow.Get("/cache", handlers.GetCachedPlayers)
|
||||||
snow.Get("/config", handlers.GetSnowConfig)
|
snow.Get("/config", handlers.GetSnowConfig)
|
||||||
snow.Get("/sockets", handlers.GetConnectedSockets)
|
snow.Get("/sockets", handlers.GetConnectedSockets)
|
||||||
snow.Get("/cosmetics", handlers.GetPreloadedCosmetics)
|
snow.Get("/cosmetics", handlers.GetPreloadedCosmetics)
|
||||||
}
|
|
||||||
|
|
||||||
discord := snow.Group("/discord")
|
discord := snow.Group("/discord")
|
||||||
discord.Get("/", handlers.GetDiscordOAuthURL)
|
discord.Get("/", handlers.GetDiscordOAuthURL)
|
||||||
|
|
|
@ -1,13 +1,27 @@
|
||||||
package person
|
package person
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ectrc/snow/aid"
|
"github.com/ectrc/snow/aid"
|
||||||
"github.com/google/uuid"
|
"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{
|
type Party struct{
|
||||||
ID string
|
ID string
|
||||||
Members []*Person
|
Members []*PartyMember
|
||||||
|
Config map[string]interface{}
|
||||||
|
Meta map[string]interface{}
|
||||||
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -17,8 +31,130 @@ var (
|
||||||
func NewParty() *Party {
|
func NewParty() *Party {
|
||||||
party := &Party{
|
party := &Party{
|
||||||
ID: uuid.New().String(),
|
ID: uuid.New().String(),
|
||||||
|
Members: []*PartyMember{},
|
||||||
|
Config: make(map[string]interface{}),
|
||||||
|
Meta: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
Parties.Set(party.ID, party)
|
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
|
return party
|
||||||
}
|
}
|
|
@ -22,6 +22,7 @@ type Person struct {
|
||||||
Discord *storage.DB_DiscordPerson
|
Discord *storage.DB_DiscordPerson
|
||||||
BanHistory aid.GenericSyncMap[storage.DB_BanStatus]
|
BanHistory aid.GenericSyncMap[storage.DB_BanStatus]
|
||||||
Relationships aid.GenericSyncMap[Relationship]
|
Relationships aid.GenericSyncMap[Relationship]
|
||||||
|
Parties aid.GenericSyncMap[Party]
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPerson() *Person {
|
func NewPerson() *Person {
|
||||||
|
|
|
@ -17,10 +17,10 @@ Protocol=ws
|
||||||
ServerAddr="ws://`+ aid.Config.API.Host + aid.Config.API.Port +`/?"
|
ServerAddr="ws://`+ aid.Config.API.Host + aid.Config.API.Port +`/?"
|
||||||
|
|
||||||
[OnlineSubsystemMcp]
|
[OnlineSubsystemMcp]
|
||||||
bUsePartySystemV2=false
|
bUsePartySystemV2=true
|
||||||
|
|
||||||
[OnlineSubsystemMcp.OnlinePartySystemMcpAdapter]
|
[OnlineSubsystemMcp.OnlinePartySystemMcpAdapter]
|
||||||
bUsePartySystemV2=false
|
bUsePartySystemV2=true
|
||||||
|
|
||||||
[XMPP]
|
[XMPP]
|
||||||
bEnableWebsockets=true
|
bEnableWebsockets=true
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 134 KiB |
Binary file not shown.
Before Width: | Height: | Size: 67 KiB |
Loading…
Reference in New Issue
Block a user