mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-13 09:12:15 +00:00
fix(multiplayer): reconcile authoritative initial connections
This commit is contained in:
@@ -30,21 +30,21 @@ func BuildCasualLineup(participants []ConnectParticipant) ([]CasualSlot, error)
|
||||
teamHuman := map[int]bool{}
|
||||
lineup := make([]CasualSlot, 6)
|
||||
usedSlots := make(map[int]bool)
|
||||
for i, participant := range participants {
|
||||
if participant.PlayerID == "" || participant.Team < 0 || participant.Team > 1 || seen[participant.PlayerID] || usedSlots[i] {
|
||||
for _, participant := range participants {
|
||||
if participant.PlayerID == "" || participant.Team < 0 || participant.Team > 1 || participant.Slot < 0 || participant.Slot > 5 || participant.Slot/3 != participant.Team || seen[participant.PlayerID] || usedSlots[participant.Slot] {
|
||||
return nil, fmt.Errorf("invalid casual participant")
|
||||
}
|
||||
seen[participant.PlayerID] = true
|
||||
usedSlots[i] = true
|
||||
usedSlots[participant.Slot] = true
|
||||
teamHuman[participant.Team] = true
|
||||
lineup[i] = CasualSlot{Slot: i, Team: participant.Team, PlayerID: participant.PlayerID}
|
||||
lineup[participant.Slot] = CasualSlot{Slot: participant.Slot, Team: participant.Team, PlayerID: participant.PlayerID}
|
||||
}
|
||||
if !teamHuman[0] || !teamHuman[1] {
|
||||
return nil, fmt.Errorf("casual lineup requires one human on each team")
|
||||
}
|
||||
for i := range lineup {
|
||||
if lineup[i].PlayerID == "" {
|
||||
lineup[i] = CasualSlot{Slot: i, Team: i % 2, PlayerID: fmt.Sprintf("bot-slot-%d", i), IsBot: true}
|
||||
lineup[i] = CasualSlot{Slot: i, Team: i / 3, PlayerID: fmt.Sprintf("bot-slot-%d", i), IsBot: true}
|
||||
}
|
||||
}
|
||||
return lineup, nil
|
||||
|
||||
Reference in New Issue
Block a user