/** * Loops over the players and sorts them into teams * * @return $this */ public function teams() { $players = $this->client->tabulate($this->client->adminGetPlayerlist())['players']; $temp = []; $lockedSquads = [0 => [], 1 => [], 2 => [], 3 => [], 4 => []]; foreach ($players as $player) { $teamID = $player['teamId']; $squadID = $player['squadId']; $squadName = BattlefieldHelper::squad($squadID); if (array_key_exists($squadName, $lockedSquads[$teamID]) !== true) { $lockedSquads[$teamID][$squadName] = $this->client->adminGetSquadPrivate($teamID, $squadID); } $additional = ['isSquadLocked' => array_key_exists($squadName, $lockedSquads[$teamID]) !== false ? $lockedSquads[$teamID][$squadName] : null, 'squadName' => $squadName]; switch ($teamID) { case 0: $score = null; break; case 1: $score = (int) $this->serverinfo[9]; break; case 2: $score = (int) $this->serverinfo[10]; break; case 3: $score = (int) $this->serverinfo[11]; break; case 4: $score = (int) $this->serverinfo[12]; break; } $teamName = $this->getTeamName($teamID); $temp[$teamID]['team'] = $teamName; $serverInfoLength = count($this->serverinfo); if ($serverInfoLength >= 26 && $serverInfoLength <= 28 && in_array($this->gameName, ['BF4', 'BFHL']) || $serverInfoLength == 25 && $this->gameName == 'BF3') { $temp[$teamID]['score'] = $score; } else { $temp[$teamID]['score'] = 0; } if (array_key_exists('ping', $player) && $player['ping'] == 65535) { $player['ping'] = null; } switch (array_key_exists('type', $player) ? $player['type'] : 0) { case 1: $temp[$teamID]['spectators'][] = $player; $this->data['server']['players']['spectators']++; break; case 2: case 3: $temp[$teamID]['commander'] = $player; $this->data['server']['players']['commanders']++; break; default: $temp[$teamID]['players'][] = array_merge($player, $additional); } } $this->data['lockedSquads'] = $lockedSquads; $this->data['teams'] = $temp; $this->getPlayerDBData(); return $this; }
public function getSquadAttribute() { return BattlefieldHelper::squad($this->SquadID); }