fix: wsInterop (namespace + move interop code from index to controller

This commit is contained in:
SeekDaSky 2017-12-06 17:12:08 +01:00
parent 3ba539e9de
commit 27bb422aca
3 changed files with 40 additions and 38 deletions

View File

@ -1,6 +1,6 @@
<?php
namespace \kwebsocket\core;
namespace kwebsocket\core;
class wsinterop{

View File

@ -3,6 +3,8 @@
namespace router\controller;
use kwebsocket\core\wsinterop;
class page{
@ -24,6 +26,43 @@
*
*/
public function load(){
if( !isset($_SESSION['NAME']) || 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(['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(['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(['type' => 'guest', 'name' => null]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}
$wsi = null;
}
if( file_exists(__ROOT__."/view/home.php") )
include __ROOT__."/view/home.php";
else

View File

@ -5,46 +5,9 @@
use \api\core\Request;
use \api\core\AuthSystemDefault;
use \database\core\DatabaseDriver;
use \kwebsocket\core\wsinterop;
/* (1) Start session */
session_start();
if( !isset($_SESSION['NAME']) || 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(['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(['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(['type' => 'guest', 'name' => null]);
$check = $wsi->receive();
if( $check['error'] == false )
$_SESSION['NAME'] = $check['name'];
}
$wsi = null;
}
/* (2) Set default Driver for Repos */
Repo::setDriver(DatabaseDriver::get());