Party 2 now has basic functionality
This commit is contained in:
parent
0781a3c83e
commit
0b9da07d2e
|
@ -89,7 +89,6 @@ func (c *ExternalDataClient) LoadExternalData() {
|
||||||
for _, setValue := range addNumericStylesToSets {
|
for _, setValue := range addNumericStylesToSets {
|
||||||
set, found := c.FortniteSets[setValue]
|
set, found := c.FortniteSets[setValue]
|
||||||
if !found {
|
if !found {
|
||||||
aid.Print("set not found: " + setValue)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,10 @@ func NewFortnitePersonWithId(id string, displayName string, everything bool) *p.
|
||||||
person.CommonCoreProfile.Attributes.AddAttribute(p.NewAttribute("allowed_to_send_gifts", true)).Save()
|
person.CommonCoreProfile.Attributes.AddAttribute(p.NewAttribute("allowed_to_send_gifts", true)).Save()
|
||||||
person.CommonCoreProfile.Attributes.AddAttribute(p.NewAttribute("gift_history", aid.JSON{})).Save()
|
person.CommonCoreProfile.Attributes.AddAttribute(p.NewAttribute("gift_history", aid.JSON{})).Save()
|
||||||
|
|
||||||
|
person.CommonCoreProfile.Attributes.AddAttribute(p.NewAttribute("party.recieveIntents", "ALL")).Save()
|
||||||
|
person.CommonCoreProfile.Attributes.AddAttribute(p.NewAttribute("party.recieveInvites", "ALL")).Save()
|
||||||
|
|
||||||
|
|
||||||
loadout := p.NewLoadout("PRESET 1", person.AthenaProfile)
|
loadout := p.NewLoadout("PRESET 1", person.AthenaProfile)
|
||||||
person.AthenaProfile.Loadouts.AddLoadout(loadout).Save()
|
person.AthenaProfile.Loadouts.AddLoadout(loadout).Save()
|
||||||
person.AthenaProfile.Attributes.AddAttribute(p.NewAttribute("loadouts", []string{loadout.ID})).Save()
|
person.AthenaProfile.Attributes.AddAttribute(p.NewAttribute("loadouts", []string{loadout.ID})).Save()
|
||||||
|
|
|
@ -415,7 +415,7 @@ func GenerateRandomStorefront() {
|
||||||
}
|
}
|
||||||
|
|
||||||
minimumSets := 4
|
minimumSets := 4
|
||||||
if aid.Config.Fortnite.Season < 11 {
|
if aid.Config.Fortnite.Season <+ 12 {
|
||||||
minimumSets = 3
|
minimumSets = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,31 @@ func PostTokenClientCredentials(c *fiber.Ctx, body *FortniteTokenBody) error {
|
||||||
return c.Status(400).JSON(aid.ErrorBadRequest("Client Credentials is disabled."))
|
return c.Status(400).JSON(aid.ErrorBadRequest("Client Credentials is disabled."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientCredentials, err := aid.JWTSign(aid.JSON{
|
||||||
|
"creation_date": time.Now().Format("2006-01-02T15:04:05.999Z"),
|
||||||
|
"clsvc": "prod-fn",
|
||||||
|
"t": "s",
|
||||||
|
"mver": false,
|
||||||
|
"clid": aid.Hash([]byte(c.IP())),
|
||||||
|
"ic": true,
|
||||||
|
"exp": 1707772234,
|
||||||
|
"iat": 1707757834,
|
||||||
|
"jti": "snow-revoke",
|
||||||
|
"pfpid": "prod-fn",
|
||||||
|
"am": "client_credentials",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer)
|
||||||
|
}
|
||||||
|
|
||||||
return c.Status(200).JSON(aid.JSON{
|
return c.Status(200).JSON(aid.JSON{
|
||||||
"access_token": "snow",
|
"access_token": clientCredentials,
|
||||||
|
"application_id": "fghi4567FNFBKFz3E4TROb0bmPS8h1GW",
|
||||||
"token_type": "bearer",
|
"token_type": "bearer",
|
||||||
"client_id": aid.Hash([]byte(c.IP())),
|
"client_id": aid.Hash([]byte(c.IP())),
|
||||||
"client_service": "fortnite",
|
"client_service": "prod-fn",
|
||||||
"internal_client": true,
|
"internal_client": true,
|
||||||
|
"product_id": "prod-fn",
|
||||||
"expires_in": 3600,
|
"expires_in": 3600,
|
||||||
"expires_at": time.Now().Add(time.Hour).Format("2006-01-02T15:04:05.999Z"),
|
"expires_at": time.Now().Add(time.Hour).Format("2006-01-02T15:04:05.999Z"),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ectrc/snow/aid"
|
"github.com/ectrc/snow/aid"
|
||||||
p "github.com/ectrc/snow/person"
|
p "github.com/ectrc/snow/person"
|
||||||
|
"github.com/ectrc/snow/socket"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,3 +26,167 @@ func GetUserParties(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return c.Status(200).JSON(response)
|
return c.Status(200).JSON(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserPartyPrivacy(c *fiber.Ctx) error {
|
||||||
|
person := c.Locals("person").(*p.Person)
|
||||||
|
|
||||||
|
recieveIntents := person.CommonCoreProfile.Attributes.GetAttributeByKey("party.recieveIntents")
|
||||||
|
if recieveIntents == nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("No Privacy Found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
recieveInvites := person.CommonCoreProfile.Attributes.GetAttributeByKey("party.recieveInvites")
|
||||||
|
if recieveIntents == nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("No Privacy Found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status(200).JSON(aid.JSON{
|
||||||
|
"recieveIntents": aid.JSONParse(recieveIntents.ValueJSON),
|
||||||
|
"recieveInvites": aid.JSONParse(recieveInvites.ValueJSON),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetUserPartyNotifications(c *fiber.Ctx) error {
|
||||||
|
return c.Status(200).JSON(aid.JSON{
|
||||||
|
"pings": 0,
|
||||||
|
"invites": 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPartyForMember(c *fiber.Ctx) error {
|
||||||
|
person := c.Locals("person").(*p.Person)
|
||||||
|
|
||||||
|
party, ok := person.Parties.Get(c.Params("partyId"))
|
||||||
|
if !ok {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Party Not Found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status(200).JSON(party.GenerateFortniteParty())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PostCreateParty(c *fiber.Ctx) error {
|
||||||
|
person := c.Locals("person").(*p.Person)
|
||||||
|
|
||||||
|
person.Parties.Range(func(key string, party *p.Party) bool {
|
||||||
|
party.RemoveMember(person)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
var body struct {
|
||||||
|
Config map[string]interface{} `json:"config"`
|
||||||
|
Meta map[string]interface{} `json:"meta"`
|
||||||
|
JoinInformation struct {
|
||||||
|
Meta map[string]interface{} `json:"meta"`
|
||||||
|
Connection aid.JSON `json:"connection"`
|
||||||
|
} `json:"join_info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.BodyParser(&body); err != nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Invalid Request"))
|
||||||
|
}
|
||||||
|
|
||||||
|
party := p.NewParty()
|
||||||
|
party.UpdateMeta(body.Meta)
|
||||||
|
party.UpdateConfig(body.Config)
|
||||||
|
|
||||||
|
party.AddMember(person, "CAPTAIN")
|
||||||
|
party.UpdateMemberMeta(person, body.JoinInformation.Meta)
|
||||||
|
|
||||||
|
body.JoinInformation.Connection["connected_at"] = time.Now().Format(time.RFC3339)
|
||||||
|
body.JoinInformation.Connection["updated_at"] = time.Now().Format(time.RFC3339)
|
||||||
|
party.UpdateMemberConnections(person, body.JoinInformation.Connection)
|
||||||
|
|
||||||
|
member := party.GetMember(person)
|
||||||
|
if member == nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Failed to create party"))
|
||||||
|
}
|
||||||
|
|
||||||
|
s, ok := socket.JabberSockets.Get(person.ID)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("No socket connection found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
s.JabberSendMessageToPerson(aid.JSON{
|
||||||
|
"ns": "Fortnite",
|
||||||
|
"party_id": party.ID,
|
||||||
|
"account_id": person.ID,
|
||||||
|
"account_dn": person.DisplayName,
|
||||||
|
"connection": body.JoinInformation.Connection,
|
||||||
|
"member_state_updated": member.Meta,
|
||||||
|
"updated_at": member.UpdatedAt.Format(time.RFC3339),
|
||||||
|
"joined_at": member.JoinedAt.Format(time.RFC3339),
|
||||||
|
"sent": time.Now().Format(time.RFC3339),
|
||||||
|
"revision": 0,
|
||||||
|
"type": "com.epicgames.social.party.notification.v0.MEMBER_JOINED",
|
||||||
|
})
|
||||||
|
|
||||||
|
return c.Status(200).JSON(party.GenerateFortniteParty())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PatchUpdateParty(c *fiber.Ctx) error {
|
||||||
|
person := c.Locals("person").(*p.Person)
|
||||||
|
|
||||||
|
var body struct {
|
||||||
|
Config map[string]interface{} `json:"config"`
|
||||||
|
Meta struct {
|
||||||
|
Update map[string]interface{} `json:"update"`
|
||||||
|
Delete []string `json:"delete"`
|
||||||
|
} `json:"meta"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.BodyParser(&body); err != nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Invalid Request"))
|
||||||
|
}
|
||||||
|
|
||||||
|
party, ok := person.Parties.Get(c.Params("partyId"))
|
||||||
|
if !ok {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Party Not Found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
member := party.GetMember(person)
|
||||||
|
if member == nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Not in Party"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if member.Role != "CAPTAIN" {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Not Captain"))
|
||||||
|
}
|
||||||
|
|
||||||
|
party.UpdateConfig(body.Config)
|
||||||
|
party.UpdateMeta(body.Meta.Update)
|
||||||
|
party.DeleteMeta(body.Meta.Delete)
|
||||||
|
|
||||||
|
return c.Status(200).JSON(party.GenerateFortniteParty())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PatchUpdatePartyMemberMeta(c *fiber.Ctx) error {
|
||||||
|
person := c.Locals("person").(*p.Person)
|
||||||
|
|
||||||
|
var body struct {
|
||||||
|
Update map[string]interface{} `json:"update"`
|
||||||
|
Delete []string `json:"delete"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.BodyParser(&body); err != nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Invalid Request"))
|
||||||
|
}
|
||||||
|
|
||||||
|
party, ok := person.Parties.Get(c.Params("partyId"))
|
||||||
|
if !ok {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Party Not Found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
member := party.GetMember(person)
|
||||||
|
if member == nil {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Not in Party"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Params("accountId") != person.ID {
|
||||||
|
return c.Status(400).JSON(aid.ErrorBadRequest("Not owner of person"))
|
||||||
|
}
|
||||||
|
|
||||||
|
party.UpdateMemberMeta(person, body.Update)
|
||||||
|
party.DeleteMemberMeta(person, body.Delete)
|
||||||
|
|
||||||
|
return c.Status(200).JSON(party.GenerateFortniteParty())
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ func MiddlewareOnlyDebug(c *fiber.Ctx) error {
|
||||||
return c.SendStatus(403)
|
return c.SendStatus(403)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPreloadedCosmetics(c *fiber.Ctx) error {
|
func GetSnowPreloadedCosmetics(c *fiber.Ctx) error {
|
||||||
return c.JSON(fortnite.External)
|
return c.JSON(fortnite.External)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func GetPlayer(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCachedPlayers(c *fiber.Ctx) error {
|
func GetSnowCachedPlayers(c *fiber.Ctx) error {
|
||||||
persons := p.AllFromCache()
|
persons := p.AllFromCache()
|
||||||
players := make([]p.PersonSnapshot, len(persons))
|
players := make([]p.PersonSnapshot, len(persons))
|
||||||
|
|
||||||
|
@ -59,3 +59,18 @@ func GetSnowConfig(c *fiber.Ctx) error {
|
||||||
"amazon": storage.Repo.Amazon,
|
"amazon": storage.Repo.Amazon,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSnowParties(c *fiber.Ctx) error {
|
||||||
|
parties := []aid.JSON{}
|
||||||
|
|
||||||
|
p.Parties.Range(func(key string, value *p.Party) bool {
|
||||||
|
parties = append(parties, value.GenerateFortniteParty())
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
return c.JSON(parties)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSnowShop(c *fiber.Ctx) error {
|
||||||
|
return c.JSON(fortnite.StaticCatalog)
|
||||||
|
}
|
|
@ -43,7 +43,7 @@ func WebsocketConnection(c *websocket.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConnectedSockets(c *fiber.Ctx) error {
|
func GetSnowConnectedSockets(c *fiber.Ctx) error {
|
||||||
jabber := aid.JSON{}
|
jabber := aid.JSON{}
|
||||||
socket.JabberSockets.Range(func(key string, value *socket.Socket[socket.JabberData]) bool {
|
socket.JabberSockets.Range(func(key string, value *socket.Socket[socket.JabberData]) bool {
|
||||||
jabber[key] = value
|
jabber[key] = value
|
||||||
|
|
30
main.go
30
main.go
|
@ -120,12 +120,9 @@ func main() {
|
||||||
storage.Get("/system", handlers.GetCloudStorageFiles)
|
storage.Get("/system", handlers.GetCloudStorageFiles)
|
||||||
storage.Get("/system/config", handlers.GetCloudStorageConfig)
|
storage.Get("/system/config", handlers.GetCloudStorageConfig)
|
||||||
storage.Get("/system/:fileName", handlers.GetCloudStorageFile)
|
storage.Get("/system/:fileName", handlers.GetCloudStorageFile)
|
||||||
|
storage.Get("/user/:accountId", handlers.MiddlewareFortnite, handlers.GetUserStorageFiles)
|
||||||
user := storage.Group("/user")
|
storage.Get("/user/:accountId/:fileName", handlers.MiddlewareFortnite, handlers.GetUserStorageFile)
|
||||||
user.Use(handlers.MiddlewareFortnite)
|
storage.Put("/user/:accountId/:fileName", handlers.MiddlewareFortnite, handlers.PutUserStorageFile)
|
||||||
user.Get("/:accountId", handlers.GetUserStorageFiles)
|
|
||||||
user.Get("/:accountId/:fileName", handlers.GetUserStorageFile)
|
|
||||||
user.Put("/:accountId/:fileName", handlers.PutUserStorageFile)
|
|
||||||
|
|
||||||
friends := r.Group("/friends/api")
|
friends := r.Group("/friends/api")
|
||||||
friends.Use(handlers.MiddlewareFortnite)
|
friends.Use(handlers.MiddlewareFortnite)
|
||||||
|
@ -155,13 +152,28 @@ func main() {
|
||||||
party := r.Group("/party/api/v1/Fortnite")
|
party := r.Group("/party/api/v1/Fortnite")
|
||||||
party.Use(handlers.MiddlewareFortnite)
|
party.Use(handlers.MiddlewareFortnite)
|
||||||
party.Get("/user/:accountId", handlers.GetUserParties)
|
party.Get("/user/:accountId", handlers.GetUserParties)
|
||||||
|
party.Get("/user/:accountId/settings/privacy", handlers.GetUserPartyPrivacy)
|
||||||
|
party.Get("/user/:accountId/notifications/undelivered/count", handlers.GetUserPartyNotifications)
|
||||||
|
party.Post("/parties", handlers.PostCreateParty)
|
||||||
|
party.Get("/parties/:partyId", handlers.GetPartyForMember)
|
||||||
|
party.Patch("/parties/:partyId", handlers.PatchUpdateParty)
|
||||||
|
party.Patch("/parties/:partyId/members/:accountId/meta", handlers.PatchUpdatePartyMemberMeta)
|
||||||
|
// post /parties/:partyId/members/:accountId/conferences/connection (join a voip channel)
|
||||||
|
// delete /parties/:partyId/members/:accountid (remove a person from a party)
|
||||||
|
// 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)
|
||||||
|
// delete /user/:accountId/pings/:pinger/friendId (delete pings)
|
||||||
|
// post /members/:friendId/intentions/:accountId (send an invite and add invite to party)
|
||||||
|
|
||||||
snow := r.Group("/snow")
|
snow := r.Group("/snow")
|
||||||
snow.Use(handlers.MiddlewareOnlyDebug)
|
snow.Use(handlers.MiddlewareOnlyDebug)
|
||||||
snow.Get("/cache", handlers.GetCachedPlayers)
|
snow.Get("/cache", handlers.GetSnowCachedPlayers)
|
||||||
snow.Get("/config", handlers.GetSnowConfig)
|
snow.Get("/config", handlers.GetSnowConfig)
|
||||||
snow.Get("/sockets", handlers.GetConnectedSockets)
|
snow.Get("/sockets", handlers.GetSnowConnectedSockets)
|
||||||
snow.Get("/cosmetics", handlers.GetPreloadedCosmetics)
|
snow.Get("/cosmetics", handlers.GetSnowPreloadedCosmetics)
|
||||||
|
snow.Get("/parties", handlers.GetSnowParties)
|
||||||
|
snow.Get("/shop", handlers.GetSnowShop)
|
||||||
|
|
||||||
discord := snow.Group("/discord")
|
discord := snow.Group("/discord")
|
||||||
discord.Get("/", handlers.GetDiscordOAuthURL)
|
discord.Get("/", handlers.GetDiscordOAuthURL)
|
||||||
|
|
|
@ -8,20 +8,44 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PartyPing struct{
|
||||||
|
Person *Person
|
||||||
|
Party *Party
|
||||||
|
}
|
||||||
|
|
||||||
type PartyMember struct{
|
type PartyMember struct{
|
||||||
Person *Person
|
Person *Person
|
||||||
ConnectionID string
|
ConnectionID string
|
||||||
Meta map[string]interface{}
|
Meta map[string]interface{}
|
||||||
Connections map[string]aid.JSON
|
Connections map[string]aid.JSON
|
||||||
Role string
|
Role string
|
||||||
|
JoinedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pm *PartyMember) GenerateFortnitePartyMember() aid.JSON {
|
||||||
|
connections := []aid.JSON{}
|
||||||
|
for _, connection := range pm.Connections {
|
||||||
|
connections = append(connections, connection)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aid.JSON{
|
||||||
|
"account_id": pm.Person.ID,
|
||||||
|
"role": pm.Role,
|
||||||
|
"meta": pm.Meta,
|
||||||
|
"joined_at": pm.JoinedAt.Format(time.RFC3339),
|
||||||
|
"connections": connections,
|
||||||
|
"revision": 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Party struct{
|
type Party struct{
|
||||||
ID string
|
ID string
|
||||||
Members []*PartyMember
|
Members map[string]*PartyMember
|
||||||
Config map[string]interface{}
|
Config map[string]interface{}
|
||||||
Meta map[string]interface{}
|
Meta map[string]interface{}
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -31,16 +55,29 @@ var (
|
||||||
func NewParty() *Party {
|
func NewParty() *Party {
|
||||||
party := &Party{
|
party := &Party{
|
||||||
ID: uuid.New().String(),
|
ID: uuid.New().String(),
|
||||||
Members: []*PartyMember{},
|
Members: make(map[string]*PartyMember),
|
||||||
Config: make(map[string]interface{}),
|
Config: map[string]interface{}{
|
||||||
|
"type": "DEFAULT",
|
||||||
|
"sub_type": "default",
|
||||||
|
"intention_ttl:": 60,
|
||||||
|
"invite_ttl:": 60,
|
||||||
|
},
|
||||||
Meta: make(map[string]interface{}),
|
Meta: make(map[string]interface{}),
|
||||||
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
Parties.Set(party.ID, party)
|
Parties.Set(party.ID, party)
|
||||||
return party
|
return party
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Party) AddMember(person *Person) {
|
func (p *Party) GetMember(person *Person) *PartyMember {
|
||||||
|
p.m.Lock()
|
||||||
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
return p.Members[person.ID]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Party) AddMember(person *Person, role string) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
@ -48,10 +85,11 @@ func (p *Party) AddMember(person *Person) {
|
||||||
Person: person,
|
Person: person,
|
||||||
Meta: make(map[string]interface{}),
|
Meta: make(map[string]interface{}),
|
||||||
Connections: make(map[string]aid.JSON),
|
Connections: make(map[string]aid.JSON),
|
||||||
Role: "MEMBER",
|
Role: role,
|
||||||
|
JoinedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Members = append(p.Members, partyMember)
|
p.Members[person.ID] = partyMember
|
||||||
person.Parties.Set(p.ID, p)
|
person.Parties.Set(p.ID, p)
|
||||||
// xmpp to person and rest of party to say new member!
|
// xmpp to person and rest of party to say new member!
|
||||||
}
|
}
|
||||||
|
@ -60,77 +98,91 @@ func (p *Party) RemoveMember(person *Person) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
for i, member := range p.Members {
|
delete(p.Members, person.ID)
|
||||||
if member.Person == person {
|
|
||||||
p.Members = append(p.Members[:i], p.Members[i+1:]...)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(p.Members) == 0 {
|
if len(p.Members) == 0 {
|
||||||
Parties.Delete(p.ID)
|
Parties.Delete(p.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
person.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{}) {
|
func (p *Party) UpdateMeta(m map[string]interface{}) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
for key, value := range m {
|
||||||
p.Meta[key] = value
|
p.Meta[key] = value
|
||||||
// xmpp to rest of party to say meta updated!
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Party) DeleteMeta(key string) {
|
func (p *Party) DeleteMeta(keys []string) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
delete(p.Meta, key)
|
delete(p.Meta, key)
|
||||||
// xmpp to rest of party to say meta deleted!
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Party) UpdateMemberMeta(person *Person, key string, value interface{}) {
|
func (p *Party) UpdateMemberMeta(person *Person, m map[string]interface{}) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
for _, member := range p.Members {
|
member, ok := p.Members[person.ID]
|
||||||
if member.Person == person {
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range m {
|
||||||
member.Meta[key] = value
|
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) {
|
func (p *Party) UpdateMemberRevision(person *Person, revision int) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
for _, member := range p.Members {
|
member, ok := p.Members[person.ID]
|
||||||
if member.Person == person {
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
member.Meta["revision"] = revision
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Party) DeleteMemberMeta(person *Person, keys []string) {
|
||||||
|
p.m.Lock()
|
||||||
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
member, ok := p.Members[person.ID]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
delete(member.Meta, key)
|
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{}) {
|
func (p *Party) UpdateMemberConnections(person *Person, m aid.JSON) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
member, ok := p.Members[person.ID]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
member.Connections[m["id"].(string)] = m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Party) UpdateConfig(m map[string]interface{}) {
|
||||||
|
p.m.Lock()
|
||||||
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
for key, value := range m {
|
||||||
p.Config[key] = value
|
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 {
|
func (p *Party) GenerateFortniteParty() aid.JSON {
|
||||||
|
@ -139,21 +191,19 @@ func (p *Party) GenerateFortniteParty() aid.JSON {
|
||||||
|
|
||||||
party := aid.JSON{
|
party := aid.JSON{
|
||||||
"id": p.ID,
|
"id": p.ID,
|
||||||
"members": aid.JSON{},
|
|
||||||
"config": p.Config,
|
"config": p.Config,
|
||||||
"meta": p.Meta,
|
"meta": p.Meta,
|
||||||
"created_at": "0000-00-00T00:00:00Z",
|
"applicants": []aid.JSON{},
|
||||||
|
"members": []aid.JSON{},
|
||||||
|
"invites": []aid.JSON{},
|
||||||
|
"intentions": []aid.JSON{},
|
||||||
|
"created_at": p.CreatedAt.Format(time.RFC3339),
|
||||||
"updated_at": time.Now().Format(time.RFC3339),
|
"updated_at": time.Now().Format(time.RFC3339),
|
||||||
"revision": 0,
|
"revision": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range p.Members {
|
for _, member := range p.Members {
|
||||||
party["members"].(aid.JSON)[member.Person.ID] = aid.JSON{
|
party["members"] = append(party["members"].([]aid.JSON), member.GenerateFortnitePartyMember())
|
||||||
"account_id": member.Person.ID,
|
|
||||||
"role": member.Role,
|
|
||||||
"meta": member.Meta,
|
|
||||||
"connections": member.Connections,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return party
|
return party
|
||||||
|
|
|
@ -23,6 +23,7 @@ type Person struct {
|
||||||
BanHistory aid.GenericSyncMap[storage.DB_BanStatus]
|
BanHistory aid.GenericSyncMap[storage.DB_BanStatus]
|
||||||
Relationships aid.GenericSyncMap[Relationship]
|
Relationships aid.GenericSyncMap[Relationship]
|
||||||
Parties aid.GenericSyncMap[Party]
|
Parties aid.GenericSyncMap[Party]
|
||||||
|
Pings aid.GenericSyncMap[PartyPing]
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPerson() *Person {
|
func NewPerson() *Person {
|
||||||
|
@ -37,6 +38,10 @@ func NewPerson() *Person {
|
||||||
Profile0Profile: NewProfile("profile0"),
|
Profile0Profile: NewProfile("profile0"),
|
||||||
CollectionsProfile: NewProfile("collections"),
|
CollectionsProfile: NewProfile("collections"),
|
||||||
CreativeProfile: NewProfile("creative"),
|
CreativeProfile: NewProfile("creative"),
|
||||||
|
BanHistory: aid.GenericSyncMap[storage.DB_BanStatus]{},
|
||||||
|
Relationships: aid.GenericSyncMap[Relationship]{},
|
||||||
|
Parties: aid.GenericSyncMap[Party]{},
|
||||||
|
Pings: aid.GenericSyncMap[PartyPing]{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +57,10 @@ func NewPersonWithCustomID(id string) *Person {
|
||||||
Profile0Profile: NewProfile("profile0"),
|
Profile0Profile: NewProfile("profile0"),
|
||||||
CollectionsProfile: NewProfile("collections"),
|
CollectionsProfile: NewProfile("collections"),
|
||||||
CreativeProfile: NewProfile("creative"),
|
CreativeProfile: NewProfile("creative"),
|
||||||
|
BanHistory: aid.GenericSyncMap[storage.DB_BanStatus]{},
|
||||||
|
Relationships: aid.GenericSyncMap[Relationship]{},
|
||||||
|
Parties: aid.GenericSyncMap[Party]{},
|
||||||
|
Pings: aid.GenericSyncMap[PartyPing]{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +208,7 @@ func findHelper(databasePerson *storage.DB_Person, shallow bool, save bool) *Per
|
||||||
Discord: &databasePerson.Discord,
|
Discord: &databasePerson.Discord,
|
||||||
RefundTickets: databasePerson.RefundTickets,
|
RefundTickets: databasePerson.RefundTickets,
|
||||||
Relationships: aid.GenericSyncMap[Relationship]{},
|
Relationships: aid.GenericSyncMap[Relationship]{},
|
||||||
|
Parties: aid.GenericSyncMap[Party]{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ban := range databasePerson.BanHistory {
|
for _, ban := range databasePerson.BanHistory {
|
||||||
|
|
|
@ -5,6 +5,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDefaultEngine() []byte {
|
func GetDefaultEngine() []byte {
|
||||||
|
/*[OnlineSubsystemMcp]
|
||||||
|
bUsePartySystemV2=true
|
||||||
|
|
||||||
|
[OnlineSubsystemMcp.OnlinePartySystemMcpAdapter]
|
||||||
|
bUsePartySystemV2=true*/
|
||||||
return []byte(`
|
return []byte(`
|
||||||
[OnlineSubsystemMcp.Xmpp]
|
[OnlineSubsystemMcp.Xmpp]
|
||||||
bUseSSL=false
|
bUseSSL=false
|
||||||
|
@ -16,12 +21,6 @@ bUseSSL=false
|
||||||
Protocol=ws
|
Protocol=ws
|
||||||
ServerAddr="ws://`+ aid.Config.API.Host + aid.Config.API.Port +`/?"
|
ServerAddr="ws://`+ aid.Config.API.Host + aid.Config.API.Port +`/?"
|
||||||
|
|
||||||
[OnlineSubsystemMcp]
|
|
||||||
bUsePartySystemV2=true
|
|
||||||
|
|
||||||
[OnlineSubsystemMcp.OnlinePartySystemMcpAdapter]
|
|
||||||
bUsePartySystemV2=true
|
|
||||||
|
|
||||||
[XMPP]
|
[XMPP]
|
||||||
bEnableWebsockets=true
|
bEnableWebsockets=true
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user