Private
Public Access
1
0
Files
MineSeeker/src/Rpc/MineseekerRpc.php

77 lines
1.9 KiB
PHP

<?php
/**
* This file is part of the SplendidBear Websites' projects.
*
* Copyright (c) 2019 @ www.splendidbear.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Rpc;
use App\Util\RpcManager;
use Ratchet\ConnectionInterface;
use Gos\Bundle\WebSocketBundle\RPC\RpcInterface;
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
/**
* Class MineseekerRpc
*
* @package App\Rpc
* @author system7 <https://www.splendidbear.org>
*/
class MineseekerRpc implements RpcInterface
{
/** @var RpcManager $manager */
private $manager;
/**
* MineseekerRpc constructor.
*
* @param RpcManager $manager
*/
public function __construct(RpcManager $manager)
{
$this->manager = $manager;
}
/**
* Name of RPC, use for pubsub router (see step3)
*
* @return string
*/
public function getName(): string
{
return 'mineseeker.rpc';
}
/**
* It handles the game starting processes
*
* @param ConnectionInterface $connection
* @param WampRequest $request
* @param array $params
*
* @return boolean
*/
public function startGame(ConnectionInterface $connection, WampRequest $request, array $params): bool
{
return $this->manager->saveGrid($params);
}
/**
* It handles when somebody trying to connect to the party
*
* @param ConnectionInterface $connection
* @param WampRequest $request
* @param array $params
*
* @return string Json string for frontend w/ numbering consideration. (=> a number is not string)
*/
public function connectGame(ConnectionInterface $connection, WampRequest $request, array $params): string
{
return $this->manager->getConnectInformation($params);
}
}