Skip to content

Commit e71b09c

Browse files
authored
Merge pull request #445 from CnCNet/develop
Merge develop into main
2 parents 6e96cf3 + 39a25e2 commit e71b09c

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

cncnet-api/app/Http/Services/QuickMatchSpawnService.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,28 +420,35 @@ public static function appendRA1AlliancesToSpawnIni($spawnStruct, QmMatchPlayer
420420
*/
421421
public static function appendObservers($spawnStruct, $qmPlayer, $otherQmMatchPlayers)
422422
{
423-
# Checks if current player is observer
423+
// Sort players by color
424+
$allPlayers = $otherQmMatchPlayers->concat([$qmPlayer])->sortBy('color')->values();
425+
426+
$rankByPlayerId = array();
427+
$index = 0;
428+
foreach ($allPlayers as $player)
429+
{
430+
$rankByPlayerId[$player->id] = $index + 1;
431+
$index = $index + 1;
432+
}
433+
424434
if ($qmPlayer->isObserver())
425435
{
426-
$playerIndex = 1;
427436
$spawnStruct["spawn"]["Settings"]["IsSpectator"] = "True";
428-
$spawnStruct["isspectator"]["Multi$playerIndex"] = "True";
429437
}
430438

431-
# Make sure we mark other players too
432-
foreach ($otherQmMatchPlayers as $playerIndex => $opn)
439+
// Multi<Rank> = True for every observer
440+
foreach ($allPlayers as $player)
433441
{
434-
if ($opn->isObserver())
442+
if ($player->isObserver())
435443
{
436-
# Because it references "Other", which is 1-8
437-
$playerIndex = $playerIndex + 1;
438-
$spawnStruct["isspectator"]["Multi$playerIndex"] = "True";
444+
$rank = $rankByPlayerId[$player->id];
445+
$spawnStruct["isspectator"]["Multi" . $rank] = "True";
439446
}
440447
}
448+
441449
return $spawnStruct;
442450
}
443451

444-
445452
/**
446453
* Prepend quick-coop ini file to allow 2 real players vs 2 ai
447454
* @param mixed $spawnStruct

0 commit comments

Comments
 (0)