45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package common
|
|
|
|
import "fmt"
|
|
|
|
// Missing avatars must not become a successful empty roster: scene actors and
|
|
// the Client's lineup member array would then disagree during login.
|
|
func ValidateAvatarRoster(avatars map[uint32]*AvatarJson) error {
|
|
if len(avatars) == 0 {
|
|
return fmt.Errorf("player data is missing a non-empty avatars object")
|
|
}
|
|
for id, avatar := range avatars {
|
|
if id == 0 || avatar == nil || avatar.AvatarID != id {
|
|
return fmt.Errorf("invalid avatar record for key %d", id)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ValidateAdventureLineup(avatars map[uint32]*AvatarJson, lineup map[uint32]uint32) error {
|
|
if err := ValidateAvatarRoster(avatars); err != nil {
|
|
return err
|
|
}
|
|
rules, err := LoadTeamPresetRules()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
members := 0
|
|
for slot, id := range lineup {
|
|
if id == 0 {
|
|
continue
|
|
}
|
|
if slot >= rules.MaxMembers {
|
|
return fmt.Errorf("lineup slot %d exceeds captured member limit", slot)
|
|
}
|
|
if avatars[id] == nil {
|
|
return fmt.Errorf("lineup slot %d references missing avatar %d", slot, id)
|
|
}
|
|
members++
|
|
}
|
|
if members == 0 {
|
|
return fmt.Errorf("active adventure lineup has no valid members")
|
|
}
|
|
return nil
|
|
}
|