Skip to content

Commit

Permalink
Restructured the ChessServer\Socket\WebSocket namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 29, 2024
1 parent 3ef4e84 commit 8b333ad
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ RUN pecl install msgpack \
RUN curl --silent --show-error https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer

CMD ["php", "cli/dev.php"]
CMD ["php", "cli/ratchet/dev.php"]
2 changes: 1 addition & 1 deletion Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ RUN pecl install msgpack \
RUN curl --silent --show-error https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer

CMD ["php", "cli/prod.php"]
CMD ["php", "cli/ratchet/prod.php"]
2 changes: 1 addition & 1 deletion Dockerfile.staging
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ RUN pecl install msgpack \
RUN curl --silent --show-error https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer

CMD ["php", "cli/staging.php"]
CMD ["php", "cli/ratchet/staging.php"]
2 changes: 1 addition & 1 deletion Dockerfile.testing
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ RUN pecl install msgpack \
RUN curl --silent --show-error https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer

CMD ["php", "cli/testing.php"]
CMD ["php", "cli/ratchet/testing.php"]
10 changes: 5 additions & 5 deletions cli/dev.php → cli/ratchet/dev.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

namespace ChessServer\Cli;
namespace ChessServer\Cli\Ratchet;

use ChessServer\Socket\WebSocket;
use ChessServer\Socket\WebSocket\RatchetWebSocket;
use Dotenv\Dotenv;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$dotenv = Dotenv::createImmutable(__DIR__.'/../');
$dotenv = Dotenv::createImmutable(__DIR__.'/../../');
$dotenv->load();

$server = IoServer::factory(
new HttpServer(
new WsServer(
new WebSocket()
new RatchetWebSocket()
)
),
$_ENV['WS_PORT'],
Expand Down
10 changes: 5 additions & 5 deletions cli/prod.php → cli/ratchet/prod.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ChessServer\Cli;
namespace ChessServer\Cli\Ratchet;

use ChessServer\Socket\WebSocket;
use ChessServer\Socket\WebSocket\RatchetWebSocket;
use Dotenv\Dotenv;
use Ratchet\Http\HttpServer;
use Ratchet\Http\OriginCheck;
Expand All @@ -13,9 +13,9 @@
use React\Socket\Server;
use React\Socket\SecureServer;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$dotenv = Dotenv::createImmutable(__DIR__.'/../');
$dotenv = Dotenv::createImmutable(__DIR__.'/../../');
$dotenv->load();

$allowed = [
Expand All @@ -37,7 +37,7 @@
$httpServer = new HttpServer(
new OriginCheck(
new WsServer(
new WebSocket()
new RatchetWebSocket()
),
$allowed,
)
Expand Down
10 changes: 5 additions & 5 deletions cli/staging.php → cli/ratchet/staging.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ChessServer\Cli;
namespace ChessServer\Cli\Ratchet;

use ChessServer\Socket\WebSocket;
use ChessServer\Socket\WebSocket\RatchetWebSocket;
use Dotenv\Dotenv;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
Expand All @@ -12,9 +12,9 @@
use React\Socket\Server;
use React\Socket\SecureServer;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$dotenv = Dotenv::createImmutable(__DIR__.'/../');
$dotenv = Dotenv::createImmutable(__DIR__.'/../../');
$dotenv->load();

$loop = Factory::create();
Expand All @@ -31,7 +31,7 @@

$httpServer = new HttpServer(
new WsServer(
new WebSocket()
new RatchetWebSocket()
)
);

Expand Down
13 changes: 13 additions & 0 deletions cli/ratchet/testing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace ChessServer\Cli\Ratchet;

use ChessServer\Socket\TcpSocket\RatchetTcpSocket;
use Dotenv\Dotenv;

require __DIR__ . '/../../vendor/autoload.php';

$dotenv = Dotenv::createImmutable(__DIR__.'/../../');
$dotenv->load();

$server = new RatchetTcpSocket($_ENV['TCP_PORT']);
13 changes: 0 additions & 13 deletions cli/testing.php

This file was deleted.

18 changes: 9 additions & 9 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ Finally, you may want to add the following entry to your `/etc/hosts` file if ru

## Run the Chess Server

The chess server comes in four different flavors and can be run using a PHP script.
The chess server runs by default using Ratchet-PHP WebSockets and comes in four different flavors.

| Script | Description | Use |
| ------ | ----------- | --- |
| [cli/testing.php](https://github.com/chesslablab/chess-server/blob/master/cli/testing.php) | TCP socket. | Functional testing. |
| [cli/dev.php](https://github.com/chesslablab/chess-server/blob/master/cli/dev.php) | Simple WebSocket server. | Development. |
| [cli/staging.php](https://github.com/chesslablab/chess-server/blob/master/cli/staging.php) | Secure WebSocket server. | Staging. |
| [cli/prod.php](https://github.com/chesslablab/chess-server/blob/master/cli/prod.php) | Secure WebSocket server. | Production. |
| [cli/ratchet/testing.php](https://github.com/chesslablab/chess-server/blob/master/cli/ratchet/testing.php) | TCP socket. | Functional testing. |
| [cli/ratchet/dev.php](https://github.com/chesslablab/chess-server/blob/master/cli/ratchet/dev.php) | Simple WebSocket server. | Development. |
| [cli/ratchet/staging.php](https://github.com/chesslablab/chess-server/blob/master/cli/ratchet/staging.php) | Secure WebSocket server. | Staging. |
| [cli/ratchet/prod.php](https://github.com/chesslablab/chess-server/blob/master/cli/ratchet/prod.php) | Secure WebSocket server. | Production. |


### Functional Testing

Run the TCP socket server.

```
php cli/testing.php
php cli/ratchet/testing.php
```

### Simple WebSocket Server

Run the simple WebSocket server if you are not using an SSL/TLS certificate.

```txt
php cli/dev.php
php cli/ratchet/dev.php
```

### Staging
Expand All @@ -67,7 +67,7 @@ Before starting the secure WebSocket server for the first time, make sure to hav
Run the staging secure WebSocket server if you don't want to check the website's origin.

```txt
php cli/staging.php
php cli/ratchet/staging.php
```

This will allow any origin to send a request to it.
Expand All @@ -79,7 +79,7 @@ Before starting the secure WebSocket server for the first time, make sure to hav
Run the secure WebSocket server to check the website's origin as defined in the `WSS_ALLOWED` variable in the `.env.example` file.

```txt
php cli/prod.php
php cli/ratchet/prod.php
```

This will allow the `WSS_ALLOWED` website to send a request to it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

namespace ChessServer\Socket;
namespace ChessServer\Socket\TcpSocket;

use ChessServer\Command\LeaveCommand;
use ChessServer\Game\PlayMode;
use ChessServer\Exception\InternalErrorException;
use ChessServer\Exception\ParserException;
use ChessServer\Socket\ChesslaBlab;
use ChessServer\Socket\SendInterface;
use React\Socket\ConnectionInterface;
use React\Socket\TcpServer;

class TcpSocket extends ChesslaBlab implements SendInterface
class RatchetTcpSocket extends ChesslaBlab implements SendInterface
{
private TcpServer $server;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

namespace ChessServer\Socket;
namespace ChessServer\Socket\WebSocket;

use ChessServer\Command\LeaveCommand;
use ChessServer\Game\PlayMode;
use ChessServer\Exception\InternalErrorException;
use ChessServer\Exception\ParserException;
use ChessServer\Socket\ChesslaBlab;
use ChessServer\Socket\SendInterface;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class WebSocket extends ChesslaBlab implements MessageComponentInterface, SendInterface
class RatchetWebSocket extends ChesslaBlab implements MessageComponentInterface, SendInterface
{
public function onOpen(ConnectionInterface $conn)
{
Expand Down

0 comments on commit 8b333ad

Please sign in to comment.