From 27bb422aca940cf9f108cdc8a9737d5d3cca6428 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Wed, 6 Dec 2017 17:12:08 +0100 Subject: [PATCH] fix: wsInterop (namespace + move interop code from index to controller --- build/kwebsocket/core/wsinterop.php | 2 +- build/router/controller/page.php | 39 +++++++++++++++++++++++++++++ public_html/index.php | 37 --------------------------- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/build/kwebsocket/core/wsinterop.php b/build/kwebsocket/core/wsinterop.php index 8867421..c3224ff 100644 --- a/build/kwebsocket/core/wsinterop.php +++ b/build/kwebsocket/core/wsinterop.php @@ -1,6 +1,6 @@ 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 diff --git a/public_html/index.php b/public_html/index.php index 12ea6cf..c57fb65 100755 --- a/public_html/index.php +++ b/public_html/index.php @@ -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());