예제 #1
0
 /**
  * The main and only function needed to be called to initialise the socket server
  * @param null $strHostAddress
  * @param null $intPort
  */
 public function server($strHostAddress = null, $intPort = null)
 {
     \Twist::Session()->start();
     \Twist::framework()->register()->cancelHandler('error');
     \Twist::framework()->register()->cancelHandler('fatal');
     \Twist::framework()->register()->cancelHandler('exception');
     if (is_null($strHostAddress)) {
         $strHostAddress = \Twist::framework()->setting('WS_SERVER_HOST');
     }
     if (is_null($intPort)) {
         $intPort = \Twist::framework()->setting('WS_SERVER_PORT');
     }
     CronLock::$strLockLocation = __DIR__ . '/../lock/';
     //Remove the lock on complete failure, fatal error and exception
     \Twist::framework()->register()->shutdownEvent('CronLock', '\\Packages\\WebSockets\\Models\\CronLock', "destroy");
     //Only start if their is no lock file present
     if (!CronLock::active()) {
         //Create a lock file so that the server will function
         CronLock::create();
         $this->listen($strHostAddress, $intPort);
         //Remove the lock on safe shutdown of the server
         CronLock::destroy();
     }
 }
예제 #2
0
<?php

Twist::framework()->package()->uninstall();
//Optional Line: Add this line if you are uninstalling database tables
Twist::framework()->package()->importSQL(sprintf('%s/Install/uninstall-websockets.sql', dirname(__FILE__)));
//Optional Line: Add this line if you are removing all package settings
Twist::framework()->package()->removeSettings();
/**
 * Remove all Lavish Shopping Hooks for the system
 */
\Twist::framework()->hooks()->cancel('TWIST_MANAGER_ROUTE', 'websockets-manager', true);
예제 #3
0
 /**
  * Get the users data by email and password of Guest Details
  * @param $strUID
  * @param null $strPassword
  * @return array
  */
 protected static function requestUserData($strUID, $strPassword = null)
 {
     $arrOut = array('status' => false, 'message' => 'Login method not allowed', 'data' => array());
     //Get the user data if valid credentials
     if ($strUID != 'guest' && !strstr($strUID, '@')) {
         //If the UID dosnt contain an @ symbol treat it as a session Key of a logged in user
         $intUserID = Auth::SessionHandler()->validateCode($strUID, false);
         if (!is_null($intUserID) && $intUserID > 0) {
             $arrOut['data'] = \Twist::User()->getData($intUserID);
             $arrOut['status'] = true;
             $arrOut['message'] = sprintf('Connected to Twist WebSocket Server as %s %s', $arrOut['data']['firstname'], $arrOut['data']['surname']);
         }
     } elseif (\Twist::framework()->setting('WS_ALLOW_GUEST_LOGIN') && $strUID == 'guest' && is_null($strPassword)) {
         self::$intGuestCount++;
         //If Guest Users are allowed then set a special guest ID prefixed with a 'g'
         $arrOut['status'] = true;
         $arrOut['message'] = 'Connected to Twist WebSocket Server as Guest';
         $arrOut['data'] = array('id' => 'g' . self::$intGuestCount, 'firstname' => 'Guest', 'surname' => 'User', 'level' => 1, 'email' => sprintf('guest@%s', \Twist::framework()->setting('HTTP_HOST')), 'session_key' => '');
     } elseif (\Twist::framework()->setting('WS_ALLOW_REMOTE_LOGIN')) {
         //Authenticate the user, grab the user data and then logout (remove session data)
         Auth::validate($strUID, $strPassword);
         $arrSession = Auth::current();
         Auth::logout();
         $arrOut['status'] = $arrSession['status'];
         $arrOut['message'] = $arrSession['status'] ? sprintf('Connected to Twist WebSocket Server as %s %s', $arrSession['user_data']['firstname'], $arrSession['user_data']['surname']) : $arrSession['message'];
         $arrOut['data'] = array_key_exists('user_data', $arrSession) ? $arrSession['user_data'] : array();
     }
     return $arrOut;
 }
예제 #4
0
<?php

Twist::framework()->package()->install();
//Optional Line: Add this line if you are adding database tables
Twist::framework()->package()->importSQL(sprintf('%s/Install/websockets.sql', dirname(__FILE__)));
//Optional Line: Add this line if you are adding framework settings
Twist::framework()->package()->importSettings(sprintf('%s/Install/settings.json', dirname(__FILE__)));
/**
 * Install all Lavish Shopping Hooks for the system
 */
\Twist::framework()->hooks()->register('TWIST_MANAGER_ROUTE', 'websockets-manager', dirname(__FILE__) . '/Hooks/manager.php', true);
예제 #5
0
 public function _index()
 {
     $arrConnectionData = array('ws_host' => array_key_exists('ws_host', $_GET) ? $_GET['ws_host'] : \Twist::framework()->setting('WS_SERVER_HOST'), 'ws_port' => array_key_exists('ws_port', $_GET) ? $_GET['ws_port'] : \Twist::framework()->setting('WS_SERVER_PORT'), 'session_key' => \Twist::Session()->data('user-session_key'));
     return $this->_view('manager/overview.tpl', $arrConnectionData);
 }
예제 #6
0
 public static function load()
 {
     //Load in all the Twist Hooks and register them ready for use in the system
     self::$arrApps = \Twist::framework()->hooks()->getAll('WEB_SOCKET_APPS');
 }