add server actions
This commit is contained in:
parent
850a59f1f6
commit
f6056108a2
|
@ -317,13 +317,14 @@ func giveEverythingHandler(s *discordgo.Session, i *discordgo.InteractionCreate)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.InteractionResponseEdit(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseDefferedChannelMessageWithSource,
|
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
||||||
})
|
})
|
||||||
|
|
||||||
fortnite.GiveEverything(player)
|
fortnite.GiveEverything(player)
|
||||||
|
|
||||||
|
str := player.DisplayName + "has been granted everything."
|
||||||
s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
Content: player.DisplayName + " has been granted everything.",
|
Content: &str,
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -14,21 +14,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
profileActions = map[string]func(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
|
clientActions = map[string]func(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error {
|
||||||
"QueryProfile": PostQueryProfileAction,
|
"QueryProfile": clientQueryProfileAction,
|
||||||
"ClientQuestLogin": PostQueryProfileAction,
|
"ClientQuestLogin": clientQueryProfileAction,
|
||||||
"MarkItemSeen": PostMarkItemSeenAction,
|
"MarkItemSeen": clientMarkItemSeenAction,
|
||||||
"SetItemFavoriteStatusBatch": PostSetItemFavoriteStatusBatchAction,
|
"SetItemFavoriteStatusBatch": clientSetItemFavoriteStatusBatchAction,
|
||||||
"EquipBattleRoyaleCustomization": PostEquipBattleRoyaleCustomizationAction,
|
"EquipBattleRoyaleCustomization": clientEquipBattleRoyaleCustomizationAction,
|
||||||
"SetBattleRoyaleBanner": PostSetBattleRoyaleBannerAction,
|
"SetBattleRoyaleBanner": clientSetBattleRoyaleBannerAction,
|
||||||
"SetCosmeticLockerSlot": PostSetCosmeticLockerSlotAction,
|
"SetCosmeticLockerSlot": clientSetCosmeticLockerSlotAction,
|
||||||
"SetCosmeticLockerBanner": PostSetCosmeticLockerBannerAction,
|
"SetCosmeticLockerBanner": clientSetCosmeticLockerBannerAction,
|
||||||
"PurchaseCatalogEntry": PostPurchaseCatalogEntryAction,
|
"PurchaseCatalogEntry": clientPurchaseCatalogEntryAction,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func PostProfileAction(c *fiber.Ctx) error {
|
func PostClientProfileAction(c *fiber.Ctx) error {
|
||||||
person := p.Find(c.Params("accountId"))
|
person := c.Locals("person").(*p.Person)
|
||||||
if person == nil {
|
if person == nil {
|
||||||
return c.Status(404).JSON(aid.ErrorBadRequest("No Account Found"))
|
return c.Status(404).JSON(aid.ErrorBadRequest("No Account Found"))
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func PostProfileAction(c *fiber.Ctx) error {
|
||||||
|
|
||||||
notifications := []aid.JSON{}
|
notifications := []aid.JSON{}
|
||||||
|
|
||||||
action, ok := profileActions[c.Params("action")];
|
action, ok := clientActions[c.Params("action")];
|
||||||
if ok && profile != nil {
|
if ok && profile != nil {
|
||||||
if err := action(c, person, profile, ¬ifications); err != nil {
|
if err := action(c, person, profile, ¬ifications); err != nil {
|
||||||
return c.Status(400).JSON(aid.ErrorBadRequest(err.Error()))
|
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{
|
return c.Status(200).JSON(aid.JSON{
|
||||||
"profileId": c.Query("profileId"),
|
"profileId": c.Query("profileId"),
|
||||||
"profileRevision": revision,
|
"profileRevision": profile.Revision,
|
||||||
"profileCommandRevision": revision,
|
"profileCommandRevision": profile.Revision,
|
||||||
"profileChangesBaseRevision": revision - 1,
|
"profileChangesBaseRevision": profile.Revision - 1,
|
||||||
"profileChanges": profile.Changes,
|
"profileChanges": profile.Changes,
|
||||||
"multiUpdate": multiUpdate,
|
"multiUpdate": multiUpdate,
|
||||||
"notifications": notifications,
|
"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()
|
profile.CreateFullProfileUpdateChange()
|
||||||
return nil
|
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 {
|
var body struct {
|
||||||
ItemIds []string `json:"itemIds"`
|
ItemIds []string `json:"itemIds"`
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func PostMarkItemSeenAction(c *fiber.Ctx, person *p.Person, profile *p.Profile,
|
||||||
return nil
|
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 {
|
var body struct {
|
||||||
SlotName string `json:"slotName" binding:"required"`
|
SlotName string `json:"slotName" binding:"required"`
|
||||||
ItemToSlot string `json:"itemToSlot"`
|
ItemToSlot string `json:"itemToSlot"`
|
||||||
|
@ -191,7 +191,7 @@ func PostEquipBattleRoyaleCustomizationAction(c *fiber.Ctx, person *p.Person, pr
|
||||||
return nil
|
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 {
|
var body struct {
|
||||||
HomebaseBannerColorID string `json:"homebaseBannerColorId" binding:"required"`
|
HomebaseBannerColorID string `json:"homebaseBannerColorId" binding:"required"`
|
||||||
HomebaseBannerIconID string `json:"homebaseBannerIconId" binding:"required"`
|
HomebaseBannerIconID string `json:"homebaseBannerIconId" binding:"required"`
|
||||||
|
@ -232,7 +232,7 @@ func PostSetBattleRoyaleBannerAction(c *fiber.Ctx, person *p.Person, profile *p.
|
||||||
return nil
|
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 {
|
var body struct {
|
||||||
ItemIds []string `json:"itemIds" binding:"required"`
|
ItemIds []string `json:"itemIds" binding:"required"`
|
||||||
Favorite []bool `json:"itemFavStatus" binding:"required"`
|
Favorite []bool `json:"itemFavStatus" binding:"required"`
|
||||||
|
@ -256,7 +256,7 @@ func PostSetItemFavoriteStatusBatchAction(c *fiber.Ctx, person *p.Person, profil
|
||||||
return nil
|
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 {
|
var body struct {
|
||||||
Category string `json:"category" binding:"required"` // item type e.g. Character
|
Category string `json:"category" binding:"required"` // item type e.g. Character
|
||||||
ItemToSlot string `json:"itemToSlot" binding:"required"` // template id
|
ItemToSlot string `json:"itemToSlot" binding:"required"` // template id
|
||||||
|
@ -325,7 +325,7 @@ func PostSetCosmeticLockerSlotAction(c *fiber.Ctx, person *p.Person, profile *p.
|
||||||
return nil
|
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 {
|
var body struct {
|
||||||
LockerItem string `json:"lockerItem" binding:"required"` // locker id
|
LockerItem string `json:"lockerItem" binding:"required"` // locker id
|
||||||
BannerColorTemplateName string `json:"bannerColorTemplateName" binding:"required"` // template id
|
BannerColorTemplateName string `json:"bannerColorTemplateName" binding:"required"` // template id
|
||||||
|
@ -361,7 +361,7 @@ func PostSetCosmeticLockerBannerAction(c *fiber.Ctx, person *p.Person, profile *
|
||||||
return nil
|
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{
|
var body struct{
|
||||||
OfferID string `json:"offerId" binding:"required"`
|
OfferID string `json:"offerId" binding:"required"`
|
||||||
PurchaseQuantity int `json:"purchaseQuantity" binding:"required"`
|
PurchaseQuantity int `json:"purchaseQuantity" binding:"required"`
|
58
handlers/server.go
Normal file
58
handlers/server.go
Normal 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, ¬ifications); 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
|
||||||
|
}
|
4
main.go
4
main.go
|
@ -107,8 +107,8 @@ func main() {
|
||||||
|
|
||||||
profile := game.Group("/profile/:accountId")
|
profile := game.Group("/profile/:accountId")
|
||||||
profile.Use(handlers.MiddlewareFortnite)
|
profile.Use(handlers.MiddlewareFortnite)
|
||||||
profile.Post("/client/:action", handlers.PostProfileAction)
|
profile.Post("/client/:action", handlers.PostClientProfileAction)
|
||||||
profile.Post("/dedicated_server/:action", handlers.PostProfileAction)
|
profile.Post("/dedicated_server/:action", handlers.PostServerProfileAction)
|
||||||
|
|
||||||
lightswitch := r.Group("/lightswitch/api")
|
lightswitch := r.Group("/lightswitch/api")
|
||||||
lightswitch.Use(handlers.MiddlewareFortnite)
|
lightswitch.Use(handlers.MiddlewareFortnite)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user