3 files modified
4 files added
| | |
| | | '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 |
| | | ] |
| | |
| | | $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; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | 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; |
| | |
| | | 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"])) |
| | |
| | | $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'])) |
| | |
| | | <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"> |
| | |
| | | <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"> |
| | |
| | | </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 |
| | |
| | | <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> |
| | |
| | | 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; |
| | |
| | | return false; |
| | | } |
| | | |
| | | function swapCheckboxValues(objectOne, objectTwo) { |
| | | var tempValue = $(objectOne).prop("checked"); |
| | | $(objectOne).prop("checked", $(objectTwo).prop("checked")); |
| | | $(objectTwo).prop("checked", tempValue); |
| | | } |
| | | |
| | | </script> |
| | | {% endblock %} |
| | |
| | | {% 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'] %} |
| | |
| | | {% 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 %} |
New file |
| | |
| | | { |
| | | "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" |
| | | } |
| | | } |
New file |
| | |
| | | <?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); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | <?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"; |
| | | } |
| | | } |
New file |
| | |
| | | <?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(); |