4 files added
3 files modified
294 ■■■■ changed files
EOG/Models/Stripe.php 51 ●●●●● patch | view | raw | blame | history
templates/admin/modules/overlay.twig 42 ●●●● patch | view | raw | blame | history
templates/overlays/stripe.twig 42 ●●●● patch | view | raw | blame | history
ws-com/composer.json 29 ●●●●● patch | view | raw | blame | history
ws-com/src/Chat.php 48 ●●●●● patch | view | raw | blame | history
ws-com/src/Pusher.php 53 ●●●●● patch | view | raw | blame | history
ws-com/websocket.php 29 ●●●●● patch | view | raw | blame | history
EOG/Models/Stripe.php
@@ -23,28 +23,31 @@
        'cup'    => [
            'number' => '#76',
            'name'   => '5on5 Open Cup',
            'bestof'   => '5',
        ],
        'team'   => [
            'orange' =>
                [
                    'name' => 'Narancs Csapat',
                    'ban'  => [
                    'name'  => 'Narancs Csapat',
                    'ban'   => [
                        'mira',
                        'jackal'
                    ],
                    'score' => [
                        true,
                        true,
                        true
                    ]
                ],
            'blue'   => [
                'name' => 'Kék csapat',
                'ban'  => [
                'name'  => 'Kék csapat',
                'ban'   => [
                    'rook',
                    'blitz'
                ],
                'score' => [
                    true,
                    true,
                    true
                ]
@@ -74,10 +77,11 @@
        $this->state['team'][$team]['score'][$number] = $score;
    }
    public function setCup(string $number, string $name)
    public function setCup(string $number, string $name, int $bestOf = 1)
    {
        $this->state['cup']['number'] = $number;
        $this->state['cup']['name'] = $name;
        $this->state['cup']['bestof'] = $bestOf;
    }
    /**
@@ -93,7 +97,7 @@
        }
    }
    public function setTeamName(string $team_color = self::TEAM_BLUE, $name= '')
    public function setTeamName(string $team_color = self::TEAM_BLUE, $name = '')
    {
        $this->testColor($team_color);
        $this->state['team'][$team_color]['name'] = $name;
@@ -142,20 +146,34 @@
        unset($this->state);
        $this->state = [];
        if (!empty($state['team']['orange']['score'][0])) {
            $this->setScore('orange',0,true);
        if (!empty($state['team']['orange']['score'][0]))
        {
            $this->setScore('orange', 0, true);
        }
        if (!empty($state['team']['orange']['score'][1])) {
            $this->setScore('orange',1,true);
        if (!empty($state['team']['orange']['score'][1]))
        {
            $this->setScore('orange', 1, true);
        }
        if (!empty($state['team']['blue']['score'][0])) {
            $this->setScore('blue',0,true);
        if (!empty($state['team']['orange']['score'][2]))
        {
            $this->setScore('orange', 2, true);
        }
        if (!empty($state['team']['blue']['score'][1])) {
            $this->setScore('blue',1,true);
        if (!empty($state['team']['blue']['score'][0]))
        {
            $this->setScore('blue', 0, true);
        }
        if (!empty($state['team']['blue']['score'][1]))
        {
            $this->setScore('blue', 1, true);
        }
        if (!empty($state['team']['blue']['score'][2]))
        {
            $this->setScore('blue', 2, true);
        }
        if (!empty($state['stripe']["class"]))
@@ -163,11 +181,12 @@
            $this->setClass($state['stripe']["class"]);
        }
        if (!empty($state['cup']['name']) || !empty($state['cup']['number']))
        if (!empty($state['cup']['name']) || !empty($state['cup']['number']) || !empty($state['cup']['bestof']))
        {
            $cupNum = $state['cup']['number'] ?? '';
            $cupName = $state['cup']['name'] ?? '';
            $this->setCup($cupNum, $cupName);
            $bestOf = (int) $state['cup']['bestof'] ?? 1;
            $this->setCup($cupNum, $cupName, $bestOf);
        }
        if (!empty($state['team']))
templates/admin/modules/overlay.twig
@@ -17,7 +17,16 @@
                    <input type="text" name="stripe[cup][name]" class="form-control" id="validationServer01"
                           placeholder="Pld.: 5on5 Bomb Cup" value="{{ stripe.cup.name }}">
                </div>
                <div class="col-md-8 mb-3">
                    <label for="bestof">Win condition</label>
                    <select name="stripe[cup][bestof]" class="form-control" id="bestof">
                        <option value="1" {{ stripe.cup.bestof == 1 ? "selected='selected'" }}>Best Of 1</option>
                        <option value="3" {{ stripe.cup.bestof == 3 ? "selected='selected'" }}>Best Of 3</option>
                        <option value="5" {{ stripe.cup.bestof == 5 ? "selected='selected'" }}>Best Of 5</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-row">
            <div class="form-group bg-primary">
@@ -35,10 +44,16 @@
                    <div class="form-group">
                        <label>
                            <input type="checkbox" id="checkbox_p_b1" name="stripe[team][blue][score][0]"
                                   value="true" {{ stripe.team.blue.score[0] ? "checked" }}>Map 1</label>
                                   value="true" {{ stripe.team.blue.score[0] ? "checked" }}>Map 1
                        </label>
                        <label>
                            <input type="checkbox" id="checkbox_p_b2" name="stripe[team][blue][score][1]"
                                   value="true" {{ stripe.team.blue.score[1] ? "checked" }}>Map 2</label>
                                   value="true" {{ stripe.team.blue.score[1] ? "checked" }}>Map 2
                        </label>
                        <label>
                            <input type="checkbox" id="checkbox_p_b3" name="stripe[team][blue][score][2]"
                                   value="true" {{ stripe.team.blue.score[2] ? "checked" }}>Map 3
                        </label>
                    </div>
                </div>
                <div class="col-md-12 mb-4">
@@ -56,9 +71,9 @@
                </button>
            </div>
            <div class="form-group bg-warning">
                <div class="col-md-12 mb-4">
                <div class="col-md-12 mb-4">
                    {% include 'admin/modules/team-list-select.twig'  with {'target': 'team_orange_name'} %}
                </div>
                </div>
                <div class="col-md-12 mb-4">
                    <div class="form-group">
                        <label>Narancs csapat neve
@@ -71,13 +86,18 @@
                        <label>
                            <input type="checkbox" id="checkbox_po_1" name="stripe[team][orange][score][0]"
                                   value="true" {{ stripe.team.orange.score[0] ? "checked" }}>
                            Map 1
                            Map 1
                        </label>
                        <label>
                            <input type="checkbox" id="checkbox_po_2" name="stripe[team][orange][score][1]"
                                   value="true" {{ stripe.team.orange.score[1] ? "checked" }}>
                            Map 2
                            Map 2
                        </label>
                        <label>
                            <input type="checkbox" id="checkbox_po_3" name="stripe[team][orange][score][2]"
                                   value="true" {{ stripe.team.orange.score[2] ? "checked" }}>
                            Map 3
                        </label>
                    </div>
                </div>
@@ -118,6 +138,10 @@
            var blue = document.getElementById('team_blue_name');
            var orange = document.getElementById('team_orange_name');
            swapCheckboxValues(document.getElementById('checkbox_p_b1'), document.getElementById('checkbox_po_1'));
            swapCheckboxValues(document.getElementById('checkbox_p_b2'), document.getElementById('checkbox_po_2'));
            swapCheckboxValues(document.getElementById('checkbox_p_b3'), document.getElementById('checkbox_po_3'));
            var blue_name = blue.value;
            blue.value = orange.value;
            orange.value = blue_name;
@@ -125,5 +149,11 @@
            return false;
        }
        function swapCheckboxValues(objectOne, objectTwo) {
            var tempValue = $(objectOne).prop("checked");
            $(objectOne).prop("checked", $(objectTwo).prop("checked"));
            $(objectTwo).prop("checked", tempValue);
        }
    </script>
{% endblock %}
templates/overlays/stripe.twig
@@ -39,18 +39,19 @@
                {% endif %}
            {% endblock %}
            {% block logo %}
                {% if stripe.team.blue.score[0] == true %}
                    <div class="mapwin left one"></div>
                    <div class="mapwin left one {{ stripe.team.blue.score[0] ? "checked" }}"></div>
                    <div class="mapwin right one {{ stripe.team.orange.score[0] ? "checked" }}"></div>
                {% if stripe.cup.bestof > 1 %}
                    <div class="mapwin left two {{ stripe.team.blue.score[1] ? "checked" }}"></div>
                    <div class="mapwin right two {{ stripe.team.orange.score[1] ? "checked" }}"></div>
                {% endif %}
                {% if stripe.team.blue.score[1] == true %}
                    <div class="mapwin left two"></div>
                {% if stripe.cup.bestof > 3 %}
                    <div class="mapwin left three {{ stripe.team.blue.score[2] ? "checked" }}"></div>
                    <div class="mapwin right three {{ stripe.team.orange.score[2] ? "checked" }}"></div>
                {% endif %}
                {% if stripe.team.orange.score[0] == true %}
                    <div class="mapwin right one"></div>
                {% endif %}
                {% if stripe.team.orange.score[1] == true %}
                    <div class="mapwin right two"></div>
                {% endif %}
            {% endblock %}
            {% block team_orange %}
                {% if stripe.team.orange and stripe.stripe.class in ['team-ban', 'team'] %}
@@ -71,12 +72,29 @@
            {% endblock %}
            {% block info_right %}
            <span class="info right">
                {% if stripe.cup.number%}
                <span class="info right">
                {% if stripe.cup.number %}
                    <img class="wargasz-logo" src="/assets/WARGASZ_color.png"/>
                {% endif %}
            </span>
            {% endblock %}
        </div>
    {% endblock %}
    <script type="text/javascript">
        // Create WebSocket connection.
        const socket = new WebSocket('ws://esl.unr.hu/generator/ws-com/');
        // Connection opened
        socket.addEventListener('open', function (event) {
            console.log("Sending server: " + "Hello Bitch!");
            socket.send('Hello Bitch!');
        });
        // Listen for messages
        socket.addEventListener('message', function (event) {
            console.log('Message from server ', event.data);
            if (event.data === "update") {
                location.reload();
            }
        });
    </script>
{% endblock %}
ws-com/composer.json
New file
@@ -0,0 +1,29 @@
{
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "laravie/predis-async",
        "version": "1",
        "type": "library",
        "source": {
          "url": "https://github.com/laravie/predis-async",
          "type": "git",
          "reference": "master"
        }
      }
    }
  ],
  "autoload": {
    "psr-4": {
      "WS\\": "src",
      "Predis\\Async\\": "vendor/laravie/predis-async/src/"
    }
  },
  "require": {
    "cboden/ratchet": "*",
    "laravie/predis-async": "*",
    "predis/predis": "*",
    "clue/redis-protocol": "^0.3.1"
  }
}
ws-com/src/Chat.php
New file
@@ -0,0 +1,48 @@
<?php
namespace WS;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface
{
    protected $clients;
    public function __construct()
    {
        $this->clients = new \SplObjectStorage;
    }
    public function onOpen(ConnectionInterface $conn)
    {
        $this->clients->attach($conn);
        $conn->send("Hello overlay client!");
    }
    public function onMessage(ConnectionInterface $conn, $msg)
    {
        $conn->send("Never talk to me like that again!");
    }
    public function onClose(ConnectionInterface $conn)
    {
        $this->clients->detach($conn);
        echo "Connection {$conn->resourceId} has disconnected\n";
    }
    public function onError(ConnectionInterface $conn, \Exception $e)
    {
        echo "An error has occurred: {$e->getMessage()}\n";
        $conn->close();
    }
    public function sendToClients($message)
    {
        foreach ($this->clients as $client)
        {
            $client->send($message);
        }
    }
}
ws-com/src/Pusher.php
New file
@@ -0,0 +1,53 @@
<?php
namespace WS;
use Ratchet\ConnectionInterface;
use Ratchet\MessageComponentInterface;
class Pusher implements MessageComponentInterface
{
    protected $clients;
    public function __construct()
    {
        $this->clients = new \SplObjectStorage;
    }
    public function broadcast($msg)
    {
        foreach ($this->clients as $client)
        {
            // The sender is not the receiver, send to each client connected
            $client->send($msg);
        }
    }
    public function onOpen(ConnectionInterface $conn)
    {
        echo __METHOD__ . "\n";
        // Store the new connection to send messages to later
        $this->clients->attach($conn);
        echo "New connection! ({$conn->resourceId})\n";
    }
    public function onClose(ConnectionInterface $conn)
    {
        echo __METHOD__ . "\n";
        $this->clients->detach($conn);
        echo "Connection {$conn->resourceId} has disconnected\n";
    }
    function onMessage(ConnectionInterface $conn, $msg)
    {
        echo __METHOD__ . "\n";
        echo $msg . PHP_EOL;
        $conn->send("https://www.youtube.com/watch?v=TR3Vdo5etCQ");
    }
    public function onError(ConnectionInterface $conn, \Exception $e)
    {
        echo __METHOD__ . "\n";
    }
}
ws-com/websocket.php
New file
@@ -0,0 +1,29 @@
<?php
require './vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new WS\Pusher;
$client = new Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
$client->connect(function ($client) use ($pusher) {
    /** @var Predis\Async\Client $client */
    $client->pubSubLoop('overlay', function ($event, $pubsub) use ($pusher) {
        $pusher->broadcast($event->payload);
        var_dump($event->payload);
    });
});
if (!$client->isConnected())
{
    die("Fatal error: TCP connection to redis-server is closed\n");
}
$webSock = new React\Socket\Server('127.0.0.1:8000', $loop);
$webServer = new Ratchet\Server\IoServer(
    new \Ratchet\Http\HttpServer(
        new \Ratchet\WebSocket\WsServer(
            $pusher
        )
    ), $webSock);
$loop->run();