continue-puzzle-progress #6
@@ -118,7 +118,9 @@ class GameResponseService
|
||||
case 'ls':
|
||||
if(!in_array('ls', $rechten))
|
||||
return ['result' => ['Unknown command']];
|
||||
break;
|
||||
|
||||
$files = $this->getAllCurrentFilesInDirectory($player);
|
||||
return ['result' => $files];
|
||||
case 'cd':
|
||||
if(!in_array('cd', $rechten))
|
||||
return ['result' => ['Unknown command']];
|
||||
@@ -170,7 +172,6 @@ class GameResponseService
|
||||
default:
|
||||
return ['result' => ['Unknown command']];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getHelpCommand(mixed $rechten) : array
|
||||
@@ -473,4 +474,48 @@ class GameResponseService
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
private function getAllCurrentFilesInDirectory(Player $player) : array
|
||||
{
|
||||
$pwd = $this->playerService->getCurrentPwdOfPlayer($player);
|
||||
if (!$pwd) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$allPaths = $this->getAllPossiblePaths($player);
|
||||
$allFiles = $this->getAllPossibleFiles();
|
||||
$deletedFiles = $this->playerService->getDeletedFilesOfSession($player);
|
||||
|
||||
$entries = [];
|
||||
|
||||
// Find directories in current pwd
|
||||
foreach ($allPaths as $path) {
|
||||
if ($path === $pwd) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if $path is a direct child of $pwd
|
||||
$parent = $this->getPrevPath($path);
|
||||
if ($parent === $pwd) {
|
||||
$parts = explode('/', $path);
|
||||
$entries[] = [end($parts) . '/', 'dir'];
|
||||
}
|
||||
}
|
||||
|
||||
// Find files in current pwd
|
||||
foreach ($allFiles as $file) {
|
||||
if (in_array($file, $deletedFiles)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$parent = $this->getPrevPath($file);
|
||||
if ($parent === $pwd) {
|
||||
$parts = explode('/', $file);
|
||||
$entries[] = [end($parts), 'file'];
|
||||
}
|
||||
}
|
||||
|
||||
sort($entries);
|
||||
return $entries;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user