server/team_commands.go (2070B)
1 package main 2 3 import "slices" 4 5 // The zone validates the live session and invitation. The team owner validates 6 // authority and applies the requested action to its current roster. 7 type teamCommand struct { 8 team, actor, action, member, lootOrder uint32 9 } 10 11 func (command teamCommand) prepare(current *playerTeam) *teamWrite { 12 if current == nil { 13 if command.team != 0 || command.action != 28 || command.actor == command.member { 14 return nil 15 } 16 return &teamWrite{updated: &playerTeam{leader: command.actor, members: []uint32{command.actor, command.member}}} 17 } 18 if !slices.Contains(current.members, command.actor) { 19 return nil 20 } 21 updated := *current 22 switch command.action { 23 case 28: 24 if current.leader != command.actor || len(current.members) == 6 || slices.Contains(current.members, command.member) { 25 return nil 26 } 27 updated.members = append(slices.Clone(current.members), command.member) 28 case 22, 24: 29 leaving := command.actor 30 if command.action == 22 { 31 if current.leader != command.actor || command.actor == command.member || !slices.Contains(current.members, command.member) { 32 return nil 33 } 34 leaving = command.member 35 } 36 if len(current.members) == 2 { 37 return &teamWrite{previous: current} 38 } 39 index := slices.Index(current.members, leaving) 40 updated.members = slices.Delete(slices.Clone(current.members), index, index+1) 41 if updated.leader == leaving { 42 updated.leader = updated.members[0] 43 } 44 case 25: 45 if current.leader != command.actor || command.actor == command.member || !slices.Contains(current.members, command.member) { 46 return nil 47 } 48 updated.leader = command.member 49 case 127: 50 if current.leader != command.actor || command.lootOrder > 2 { 51 return nil 52 } 53 if current.lootOrder == command.lootOrder { 54 // An unchanged policy needs an acknowledgement, not a database write. 55 return &teamWrite{previous: current, updated: current, revision: current.revision, applied: true} 56 } 57 updated.lootOrder = command.lootOrder 58 default: 59 return nil 60 } 61 return &teamWrite{previous: current, updated: &updated} 62 }