add server actions

This commit is contained in:
Eccentric 2024-01-03 19:51:46 +00:00
parent 850a59f1f6
commit f6056108a2
4 changed files with 88 additions and 29 deletions

View File

@ -317,13 +317,14 @@ func giveEverythingHandler(s *discordgo.Session, i *discordgo.InteractionCreate)
return
}
s.InteractionResponseEdit(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDefferedChannelMessageWithSource,
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
})
fortnite.GiveEverything(player)
str := player.DisplayName + "has been granted everything."
s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: player.DisplayName + " has been granted everything.",
Content: &str,
})
}

View File

@ -14,21 +14,21 @@ import (
)
var (
profileActions = map[string]func(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
"QueryProfile": PostQueryProfileAction,
"ClientQuestLogin": PostQueryProfileAction,
"MarkItemSeen": PostMarkItemSeenAction,
"SetItemFavoriteStatusBatch": PostSetItemFavoriteStatusBatchAction,
"EquipBattleRoyaleCustomization": PostEquipBattleRoyaleCustomizationAction,
"SetBattleRoyaleBanner": PostSetBattleRoyaleBannerAction,
"SetCosmeticLockerSlot": PostSetCosmeticLockerSlotAction,
"SetCosmeticLockerBanner": PostSetCosmeticLockerBannerAction,
"PurchaseCatalogEntry": PostPurchaseCatalogEntryAction,
clientActions = map[string]func(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
"QueryProfile": clientQueryProfileAction,
"ClientQuestLogin": clientQueryProfileAction,
"MarkItemSeen": clientMarkItemSeenAction,
"SetItemFavoriteStatusBatch": clientSetItemFavoriteStatusBatchAction,
"EquipBattleRoyaleCustomization": clientEquipBattleRoyaleCustomizationAction,
"SetBattleRoyaleBanner": clientSetBattleRoyaleBannerAction,
"SetCosmeticLockerSlot": clientSetCosmeticLockerSlotAction,
"SetCosmeticLockerBanner": clientSetCosmeticLockerBannerAction,
"PurchaseCatalogEntry": clientPurchaseCatalogEntryAction,
}
)
func PostProfileAction(c *fiber.Ctx) error {
person := p.Find(c.Params("accountId"))
func PostClientProfileAction(c *fiber.Ctx) error {
person := c.Locals("person").(*p.Person)
if person == nil {
return c.Status(404).JSON(aid.ErrorBadRequest("No Account Found"))
}
@ -52,7 +52,7 @@ func PostProfileAction(c *fiber.Ctx) error {
notifications := []aid.JSON{}
action, ok := profileActions[c.Params("action")];
action, ok := clientActions[c.Params("action")];
if ok && profile != nil {
if err := action(c, person, profile, &notifications); err != nil {
return c.Status(400).JSON(aid.ErrorBadRequest(err.Error()))
@ -107,9 +107,9 @@ func PostProfileAction(c *fiber.Ctx) error {
return c.Status(200).JSON(aid.JSON{
"profileId": c.Query("profileId"),
"profileRevision": revision,
"profileCommandRevision": revision,
"profileChangesBaseRevision": revision - 1,
"profileRevision": profile.Revision,
"profileCommandRevision": profile.Revision,
"profileChangesBaseRevision": profile.Revision - 1,
"profileChanges": profile.Changes,
"multiUpdate": multiUpdate,
"notifications": notifications,
@ -118,12 +118,12 @@ func PostProfileAction(c *fiber.Ctx) error {
})
}
func PostQueryProfileAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientQueryProfileAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
profile.CreateFullProfileUpdateChange()
return nil
}
func PostMarkItemSeenAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientMarkItemSeenAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
var body struct {
ItemIds []string `json:"itemIds"`
}
@ -146,7 +146,7 @@ func PostMarkItemSeenAction(c *fiber.Ctx, person *p.Person, profile *p.Profile,
return nil
}
func PostEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
var body struct {
SlotName string `json:"slotName" binding:"required"`
ItemToSlot string `json:"itemToSlot"`
@ -191,7 +191,7 @@ func PostEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, pr
return nil
}
func PostSetBattleRoyaleBannerAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientSetBattleRoyaleBannerAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
var body struct {
HomebaseBannerColorID string `json:"homebaseBannerColorId" binding:"required"`
HomebaseBannerIconID string `json:"homebaseBannerIconId" binding:"required"`
@ -232,7 +232,7 @@ func PostSetBattleRoyaleBannerAction(c *fiber.Ctx, person *p.Person, profile *p.
return nil
}
func PostSetItemFavoriteStatusBatchAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientSetItemFavoriteStatusBatchAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
var body struct {
ItemIds []string `json:"itemIds" binding:"required"`
Favorite []bool `json:"itemFavStatus" binding:"required"`
@ -256,7 +256,7 @@ func PostSetItemFavoriteStatusBatchAction(c *fiber.Ctx, person *p.Person, profil
return nil
}
func PostSetCosmeticLockerSlotAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientSetCosmeticLockerSlotAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
var body struct {
Category string `json:"category" binding:"required"` // item type e.g. Character
ItemToSlot string `json:"itemToSlot" binding:"required"` // template id
@ -325,7 +325,7 @@ func PostSetCosmeticLockerSlotAction(c *fiber.Ctx, person *p.Person, profile *p.
return nil
}
func PostSetCosmeticLockerBannerAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientSetCosmeticLockerBannerAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
var body struct {
LockerItem string `json:"lockerItem" binding:"required"` // locker id
BannerColorTemplateName string `json:"bannerColorTemplateName" binding:"required"` // template id
@ -361,7 +361,7 @@ func PostSetCosmeticLockerBannerAction(c *fiber.Ctx, person *p.Person, profile *
return nil
}
func PostPurchaseCatalogEntryAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
func clientPurchaseCatalogEntryAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
var body struct{
OfferID string `json:"offerId" binding:"required"`
PurchaseQuantity int `json:"purchaseQuantity" binding:"required"`

58
handlers/server.go Normal file
View File

@ -0,0 +1,58 @@
package handlers
import (
"time"
"github.com/ectrc/snow/aid"
p "github.com/ectrc/snow/person"
"github.com/gofiber/fiber/v2"
)
var (
serverActions = map[string]func(c *fiber.Ctx, person *p.Person, profile *p.Profile, profileChanges, multiUpdate, notifications *[]aid.JSON) error{
"QueryProfile": serverQueryProfileAction,
}
)
func PostServerProfileAction(c *fiber.Ctx) error {
person := p.Find(c.Params("accountId"))
if person == nil {
return c.Status(404).JSON(aid.ErrorBadRequest("No Account Found"))
}
profile := person.GetProfileFromType(c.Query("profileId"))
if profile == nil {
return c.Status(404).JSON(aid.ErrorBadRequest("No Profile Found"))
}
profileChanges := []aid.JSON{}
multiUpdate := []aid.JSON{}
notifications := []aid.JSON{}
if action, ok := serverActions[c.Query("action")]; ok {
if err := action(c, person, profile, &profileChanges, &multiUpdate, &notifications); err != nil {
return c.Status(500).JSON(aid.ErrorBadRequest(err.Error()))
}
}
return c.Status(200).JSON(aid.JSON{
"profileId": c.Query("profileId"),
"profileRevision": profile.Revision,
"profileCommandRevision": profile.Revision,
"profileChangesBaseRevision": profile.Revision - 1,
"profileChanges": []aid.JSON{},
"multiUpdate": []aid.JSON{},
"notifications": []aid.JSON{},
"responseVersion": 1,
"serverTime": time.Now().Format("2006-01-02T15:04:05.999Z"),
})
}
func serverQueryProfileAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, profileChanges, multiUpdate, notifications *[]aid.JSON) error {
*profileChanges = append(*profileChanges, aid.JSON{
"changeType": "fullProfileUpdate",
"profile": profile.GenerateFortniteProfileEntry(),
})
return nil
}

View File

@ -107,8 +107,8 @@ func main() {
profile := game.Group("/profile/:accountId")
profile.Use(handlers.MiddlewareFortnite)
profile.Post("/client/:action", handlers.PostProfileAction)
profile.Post("/dedicated_server/:action", handlers.PostProfileAction)
profile.Post("/client/:action", handlers.PostClientProfileAction)
profile.Post("/dedicated_server/:action", handlers.PostServerProfileAction)
lightswitch := r.Group("/lightswitch/api")
lightswitch.Use(handlers.MiddlewareFortnite)