57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: jean-kevin
|
|
* Date: 08/12/17
|
|
* Time: 02:07
|
|
*/
|
|
|
|
namespace router\controller;
|
|
|
|
|
|
use kwebsocket\core\wsinterop;
|
|
|
|
abstract class loader {
|
|
|
|
public static function start() {
|
|
if( $_SESSION['WS'] || strlen($_SESSION['NAME']) == 0 ){
|
|
|
|
// ask with websocketInterop
|
|
$wsi = new wsinterop('localhost', 9998);
|
|
|
|
if( count($_SESSION['USER']) > 0 ){
|
|
|
|
// get/send name to web socket
|
|
$wsi->send(['operation' => "Connect",'type' => 'user', 'name' => $_SESSION['USER']['username']]);
|
|
$check = $wsi->receive();
|
|
|
|
if( $check['error'] == false )
|
|
$_SESSION['NAME'] = $check['name'];
|
|
|
|
}elseif( count($_SESSION['ADMIN']) > 0 ){
|
|
|
|
// get/send name to web socket
|
|
$wsi->send(['operation' => "Connect",'type' => 'admin', 'name' => $_SESSION['ADMIN']['username']]);
|
|
$check = $wsi->receive();
|
|
|
|
if( $check['error'] == false )
|
|
$_SESSION['NAME'] = $check['name'];
|
|
|
|
}else{
|
|
|
|
// get/send name to web socket
|
|
$wsi->send(['operation' => "Connect",'type' => 'guest', 'name' => null]);
|
|
$check = $wsi->receive();
|
|
|
|
if( $check['error'] == false )
|
|
$_SESSION['NAME'] = $check['name'];
|
|
}
|
|
|
|
$wsi->close();
|
|
$wsi = null;
|
|
|
|
$_SESSION['WS'] = false;
|
|
}
|
|
}
|
|
|
|
} |