diff --git a/cncnet-api/app/Commands/Matchup/ClanMatchupHandler.php b/cncnet-api/app/Commands/Matchup/ClanMatchupHandler.php index 663a0e41..55e089d9 100644 --- a/cncnet-api/app/Commands/Matchup/ClanMatchupHandler.php +++ b/cncnet-api/app/Commands/Matchup/ClanMatchupHandler.php @@ -71,7 +71,7 @@ public function matchup() else { $playerNames = implode(",", $this->getPlayerNamesInQueue($readyQMQueueEntries)); - Log::info("Launching clan match with players $playerNames"); + Log::info("Launching clan match with players $playerNames, " . $currentPlayer->username); return $this->createMatch( $commonQmMaps, $readyQMQueueEntries @@ -80,7 +80,7 @@ public function matchup() } } - private function getPlayerNamesInQueue($readyQMQueueEntries) + public static function getPlayerNamesInQueue($readyQMQueueEntries) { $playerNames = []; diff --git a/cncnet-api/app/Commands/Matchup/PlayerMatchupHandler.php b/cncnet-api/app/Commands/Matchup/PlayerMatchupHandler.php index 4c3955ad..80d50a46 100644 --- a/cncnet-api/app/Commands/Matchup/PlayerMatchupHandler.php +++ b/cncnet-api/app/Commands/Matchup/PlayerMatchupHandler.php @@ -206,7 +206,7 @@ public function matchup() return !is_null($value); }); - Log::info("FindOpponent ** Recent played maps from player1 ($currentPlayer->username): $recentMaps"); + // Log::info("FindOpponent ** Recent played maps from player1 ($currentPlayer->username): $recentMaps"); foreach ($recentMaps as $recentMap) { @@ -235,7 +235,7 @@ public function matchup() return !is_null($value); }); - Log::info("FindOpponent ** Recent played maps from player2 ($oppPlayer->username): $recentMaps"); + // Log::info("FindOpponent ** Recent played maps from player2 ($oppPlayer->username): $recentMaps"); foreach ($recentMaps as $recentMap) //remove the opponent's recent maps from common_qm_maps { diff --git a/cncnet-api/app/Http/Controllers/ClanController.php b/cncnet-api/app/Http/Controllers/ClanController.php index 42c1996b..d2deda3a 100644 --- a/cncnet-api/app/Http/Controllers/ClanController.php +++ b/cncnet-api/app/Http/Controllers/ClanController.php @@ -94,10 +94,14 @@ public function editLadderClan(Request $request, $ladderAbbrev, $clanId) return $p->clanPlayer !== null && $p->clanPlayer->clan_id == $clan->id; })->first(); - if ($player === null) + if ($player === null && !$user->isGod()) { return response('Not Authorized', 403); } + else if ($player === null && $user->isGod()) + { + $player = $clan->clanPlayers[0]->player; + } $invitations = $clan->invitations; @@ -484,16 +488,15 @@ public function saveMembers(Request $request, $ladderAbbrev, $clanId) } $player = \App\Player::find($request->player_id); + $user = $request->user(); - if ($player === null || !$player->clanPlayer->isOwner()) + if (($player === null || !$player->clanPlayer->isOwner()) && !$user->isGod()) { $request->session()->flash('error', "You don't have permission to do that."); return redirect()->back(); } - $user = $request->user(); - - if ($player->user_id != $user->id) + if ($player->user_id != $user->id && !$user->isGod()) { $request->session()->flash('error', "You don't have permission to do that."); return redirect()->back(); diff --git a/cncnet-api/app/Http/Services/QuickMatchService.php b/cncnet-api/app/Http/Services/QuickMatchService.php index eccbd15e..e800cfff 100644 --- a/cncnet-api/app/Http/Services/QuickMatchService.php +++ b/cncnet-api/app/Http/Services/QuickMatchService.php @@ -7,6 +7,7 @@ use App\QmMatchPlayer; use App\QmQueueEntry; use Illuminate\Support\Facades\Log; +use App\Commands\Matchup\ClanMatchupHandler; class QuickMatchService { @@ -268,6 +269,15 @@ public function createQmMatch( $ladder = \App\Ladder::where('id', $qmPlayer->ladder_id)->first(); + $actualPlayerCount = count($otherQMQueueEntries) + 1; //total player counts equals myself plus other players to be matched + $expectedPlayerCount = $ladder->qmLadderRules->player_count; + if ($actualPlayerCount != $expectedPlayerCount) + { + Log::error("Only found $actualPlayerCount players, expected $expectedPlayerCount."); + Log::error(implode(",", $actualPlayerCount) . ", " . $qmPlayer->player->username); + // return null + } + # Create the Game $game = Game::genQmEntry($qmMatch, $gameType); $qmMatch->game_id = $game->id; @@ -279,7 +289,7 @@ public function createQmMatch( $qmMap = $qmMatch->map; $spawnOrder = explode(',', $qmMap->spawn_order); - if ($qmMap->random_spawns && $qmMap->map->spawn_count > 2) //this map uses random spawns + if ($qmMap->random_spawns && $qmMap->map->spawn_count > 2 && $expectedPlayerCount == 2) //this map uses 1v1 random spawns { $spawnOrder = []; $numSpawns = $qmMap->map->spawn_count; @@ -361,10 +371,14 @@ public function createQmMatch( # Set up player specific information # Color will be used for spawn location $qmPlayer = \App\QmMatchPlayer::where('id', $qmPlayer->id)->first(); - if (!$teamSpotsAssigned) //spots were team assigned + $colorsArr = getColorsArr($actualPlayerCount, $ladder->clans_allowed && !$teamSpotsAssigned); + Log::info("Color values created: " . implode(",", $colorsArr)); + $i = 0; + if (!$teamSpotsAssigned) //spots were not team assigned { - $qmPlayer->color = 0; - $qmPlayer->location = $spawnOrder[$qmPlayer->color] - 1; + $qmPlayer->color = $colorsArr[$i]; + $qmPlayer->location = $spawnOrder[$i] - 1; + $i++; } $qmPlayer->qm_match_id = $qmMatch->id; $qmPlayer->tunnel_id = $qmMatch->seed + $qmPlayer->color; @@ -388,7 +402,6 @@ public function createQmMatch( return $s >= 0; })); - $color = 1; foreach ($otherQMQueueEntries as $qOpn) { $opn = $qOpn->qmPlayer; @@ -416,10 +429,11 @@ public function createQmMatch( $opn->actual_side = $perMS[mt_rand(0, count($perMS) - 1)]; } - if (!$teamSpotsAssigned) //spots were team assigned + if (!$teamSpotsAssigned) //spots were not team assigned { - $opn->color = $color++; - $opn->location = $spawnOrder[$opn->color] - 1; + $opn->color = $colorsArr[$i]; + $opn->location = $spawnOrder[$i] - 1; + $i++; } $opn->qm_match_id = $qmMatch->id; @@ -433,6 +447,24 @@ public function createQmMatch( } $qmPlayer->save(); + $playerNames = implode(",", ClanMatchupHandler::getPlayerNamesInQueue($otherQMQueueEntries)); + Log::info("Launching match with players $playerNames, " . $qmPlayer->player->username . " on map: " . $qmMatch->map->name); + return $qmMatch; } } + +/** + * Given $numPlayers, return an array of numbers, length of array = $numPlayers. + * + * Clan ladder matches should randomize the colors. 1v1 should use red vs yellow. + */ +function getColorsArr($numPlayers, $randomize) +{ + $possibleColors = [0, 1, 2, 3, 4, 5, 6, 7]; + + if ($randomize) + shuffle($possibleColors); + + return array_slice($possibleColors, 0, $numPlayers); +} diff --git a/cncnet-api/app/Http/Services/QuickMatchSpawnService.php b/cncnet-api/app/Http/Services/QuickMatchSpawnService.php index 90eea447..8b5fc504 100644 --- a/cncnet-api/app/Http/Services/QuickMatchSpawnService.php +++ b/cncnet-api/app/Http/Services/QuickMatchSpawnService.php @@ -110,9 +110,8 @@ function ($var) */ public static function appendOthersAndTeamAlliancesToSpawnIni($spawnStruct, $qmPlayer, $otherQmPlayers) { - $otherIdx = 1; - $multiIdx = $qmPlayer->color + 1; - $myIndex = $multiIdx; + $otherIdx = 1; //create the [Other] objects, starting from 1 [Other1] + $myIndex = $qmPlayer->color + 1; $observerIndex = -1; # Checks if player is observer @@ -126,7 +125,7 @@ public static function appendOthersAndTeamAlliancesToSpawnIni($spawnStruct, $qmP Log::info("Setting $myPlayerUsername getting set as spectator"); } - $spawnStruct["spawn"]["SpawnLocations"]["Multi{$multiIdx}"] = $qmPlayer->location; + $spawnStruct["spawn"]["SpawnLocations"]["Multi{$myIndex}"] = $qmPlayer->location; if ($qmPlayer->player->user->userSettings->skip_score_screen) { @@ -158,8 +157,8 @@ public static function appendOthersAndTeamAlliancesToSpawnIni($spawnStruct, $qmP $observerIndex = $otherIdx; } - $multiIdx = $opn->color + 1; - $spawnStruct["spawn"]["SpawnLocations"]["Multi{$multiIdx}"] = $opn->location; + $opponentIndex = $opn->color + 1; + $spawnStruct["spawn"]["SpawnLocations"]["Multi{$otherIdx}"] = $opn->location; # Check if other player is in my clan, if so add alliance if ($qmPlayer->clan_id && $qmPlayer->clan_id == $opn->clan_id) @@ -168,9 +167,9 @@ public static function appendOthersAndTeamAlliancesToSpawnIni($spawnStruct, $qmP $p2Name = $opn->player->username; Log::info("PlayerIndex ** assigning $p1Name with $p2Name"); - $spawnStruct["spawn"]["Multi{$myIndex}_Alliances"]["HouseAllyOne"] = $multiIdx - 1; - $spawnStruct["spawn"]["Multi{$multiIdx}_Alliances"]["HouseAllyOne"] = $myIndex - 1; - $myTeamIndices[] = $multiIdx; + $spawnStruct["spawn"]["Multi{$myIndex}_Alliances"]["HouseAllyOne"] = $opponentIndex - 1; + $spawnStruct["spawn"]["Multi{$opponentIndex}_Alliances"]["HouseAllyOne"] = $myIndex - 1; + $myTeamIndices[] = $opponentIndex; } $otherIdx++; @@ -189,25 +188,25 @@ public static function appendOthersAndTeamAlliancesToSpawnIni($spawnStruct, $qmP $completed = false; foreach ($otherQmPlayers as $opn) { - $multiIdx = $opn->color + 1; + $opponent1Index = $opn->color + 1; - if (!in_array($multiIdx, $myTeamIndices)) //this index is opponent's team + if (!in_array($opponent1Index, $myTeamIndices)) //this index is opponent's team { foreach ($otherQmPlayers as $opn2) //find teammate(s) { - $otherIdx = $opn2->color + 1; + $opponent2Index = $opn2->color + 1; - if ($otherIdx == $multiIdx) //self + if ($otherIdx == $opponent1Index) //self continue; - if (!in_array($otherIdx, $myTeamIndices)) //this index is opponent's teammate + if (!in_array($opponent2Index, $myTeamIndices)) //this index is opponent's teammate { $p1Name = $opn->player->username; $p2Name = $opn2->player->username; Log::info("PlayerIndex ** assigning opponents $p1Name with $p2Name"); - $spawnStruct["spawn"]["Multi{$otherIdx}_Alliances"]["HouseAllyOne"] = $multiIdx - 1; - $spawnStruct["spawn"]["Multi{$multiIdx}_Alliances"]["HouseAllyOne"] = $otherIdx - 1; + $spawnStruct["spawn"]["Multi{$opponent2Index}_Alliances"]["HouseAllyOne"] = $opponent1Index - 1; + $spawnStruct["spawn"]["Multi{$opponent1Index}_Alliances"]["HouseAllyOne"] = $opponent2Index - 1; $completed = true; } }