Hint for first part
This commit is contained in:
@@ -8,6 +8,8 @@ use App\Game\Entity\Player;
|
||||
use App\Game\Repository\SessionSettingRepository;
|
||||
use App\Tech\Entity\User;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Mercure\HubInterface;
|
||||
use Symfony\Component\Mercure\Update;
|
||||
|
||||
class GameResponseService
|
||||
{
|
||||
@@ -15,10 +17,11 @@ class GameResponseService
|
||||
private Security $security,
|
||||
private PlayerService $playerService,
|
||||
private SessionSettingRepository $sessionSettingRepository,
|
||||
private HubInterface $hub,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getGameResponse(string $raw)
|
||||
public function getGameResponse(string $raw) : array
|
||||
{
|
||||
$info = json_decode($raw, true);
|
||||
|
||||
@@ -83,8 +86,10 @@ class GameResponseService
|
||||
if(!in_array('chat', $rechten))
|
||||
return ['result' => ['Unknown command']];
|
||||
|
||||
$this->handleChatMessage($message);
|
||||
break;
|
||||
if($this->handleChatMessage($message, $player))
|
||||
return ['result' => ['succesfully send']];
|
||||
else
|
||||
return ['result' => ['Error sending']];
|
||||
case '/help':
|
||||
return ['result' => $this->getHelpCommand($rechten)];
|
||||
case '/decode':
|
||||
@@ -101,7 +106,6 @@ class GameResponseService
|
||||
default:
|
||||
return ['result' => ['Unknown command']];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private function checkConsoleCommando(string $message, Player $player, bool $sudo = false) : array
|
||||
@@ -124,6 +128,9 @@ class GameResponseService
|
||||
|
||||
$this->playerService->saveCurrentPwdOfPlayer($player, $newLocation);
|
||||
return ['result' => ['Path: ' . $newLocation]];
|
||||
case 'pwd':
|
||||
$pwd = $this->playerService->getCurrentPwdOfPlayer($player);
|
||||
return ['result' => ['Path: ' . $pwd]];
|
||||
case 'rm':
|
||||
break;
|
||||
case 'sudo':
|
||||
@@ -161,6 +168,13 @@ class GameResponseService
|
||||
$messages[] = ' USAGE: /decode {message}';
|
||||
$messages[] = '';
|
||||
break;
|
||||
case 'pwd':
|
||||
$messages[] = 'pwd';
|
||||
$messages[] = ' This message will let you know what your current location is.';
|
||||
$messages[] = ' It will show you the folder you are in so you can continue navigating the server.';
|
||||
$messages[] = ' USAGE: pwd';
|
||||
$messages[] = '';
|
||||
break;
|
||||
case 'cat':
|
||||
$messages[] = 'cat';
|
||||
$messages[] = ' To read a file, use cat {filename}.';
|
||||
@@ -210,9 +224,42 @@ class GameResponseService
|
||||
return $messages;
|
||||
}
|
||||
|
||||
private function handleChatMessage(string $message)
|
||||
private function handleChatMessage(string $message, Player $player) : bool
|
||||
{
|
||||
$messageParts = explode(' ', $message);
|
||||
$toSingle = false;
|
||||
|
||||
if (isset($messageParts[1]) &&
|
||||
is_numeric($messageParts[1]) &&
|
||||
$messageParts[1] >= 1 &&
|
||||
$messageParts[1] <= 3) {
|
||||
|
||||
$toSingle = true;
|
||||
}
|
||||
|
||||
$chatMessage = array_shift($messageParts);
|
||||
$sendTo = 0;
|
||||
|
||||
if ($toSingle) {
|
||||
$sendTo = array_shift($messageParts);
|
||||
}
|
||||
|
||||
$message = $player->getUser()->getUsername() . ': ' . $chatMessage;
|
||||
foreach($messageParts as $messagePart) {
|
||||
$message .= $messagePart . ' ';
|
||||
}
|
||||
|
||||
$message = trim($message);
|
||||
|
||||
$activeGame = $player->getSession()?->getId();
|
||||
|
||||
if(is_null($activeGame))
|
||||
return false;
|
||||
|
||||
$topic = $_ENV['MERCURE_TOPIC_BASE'] . '/game/hub-' . $activeGame;
|
||||
$this->hub->publish(new Update($topic, json_encode([$sendTo, $message])));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function handleDecodeMessage(string $message, Player $player)
|
||||
|
||||
Reference in New Issue
Block a user