/** * Create a user record when the user has successfully connected * @param $arrUserData */ public static function createUser($arrUserData) { //If the user already exists just update the last connected time if (array_key_exists($arrUserData['id'], self::$arrUsers)) { System::debug("Additional Connection - user(" . $arrUserData['id'] . ")"); self::logUserConnection($arrUserData['id']); } else { System::debug("New Connection - user(" . $arrUserData['id'] . ")"); //Set the user to admin status if required (in the settings array) self::$arrUsers[$arrUserData['id']] = array('id' => $arrUserData['id'], 'name' => sprintf("%s %s", $arrUserData['firstname'], $arrUserData['surname']), 'email' => $arrUserData['email'], 'level' => $arrUserData['level'], 'time_connected' => time(), 'last_connected' => time(), 'global_settings' => array(), 'settings' => array('system_admin' => $arrUserData['level'] == self::$intAdminLevel)); } return $arrUserData['id']; }
/** * Get the headers passed by the current request, used during the handshake process * @param $strRequest * @return array */ protected function getHeaders($strRequest) { $strRequestURI = $strHost = $strOriginAddress = $strAcceptKey = $intProtocolVersion = $strProtocol = $strSecretKey1 = $strSecretKey2 = $strLast8Bytes = null; if (preg_match("/GET (.*) HTTP/", $strRequest, $arrMatch)) { $strRequestURI = $arrMatch[1]; } if (preg_match("/Host: (.*)\r\n/", $strRequest, $arrMatch)) { $strHost = $arrMatch[1]; } if (preg_match("/Origin: (.*)\r\n/", $strRequest, $arrMatch)) { $strOriginAddress = $arrMatch[1]; } if (preg_match("/Sec-WebSocket-Version: (.*)\r\n/", $strRequest, $arrMatch)) { $intProtocolVersion = $arrMatch[1]; } if (preg_match("/Sec-WebSocket-Protocol: (.*)\r\n/", $strRequest, $arrMatch)) { $strProtocol = $arrMatch[1]; } if (preg_match("/Sec-WebSocket-Key: (.*)\r\n/", $strRequest, $arrMatch)) { $strAcceptKey = $arrMatch[1]; } if (preg_match("/Sec-WebSocket-Key1: (.*)\r\n/", $strRequest, $arrMatch)) { System::debug("Sec Key1: " . ($strSecretKey1 = $arrMatch[1])); } if (preg_match("/Sec-WebSocket-Key2: (.*)\r\n/", $strRequest, $arrMatch)) { System::debug("Sec Key2: " . ($strSecretKey2 = $arrMatch[1])); } if ($arrMatch = substr($strRequest, -8)) { System::debug("Last 8 bytes: " . ($strLast8Bytes = $arrMatch)); } return array($strRequestURI, $strHost, $strOriginAddress, $strSecretKey1, $strSecretKey2, $strLast8Bytes, $strAcceptKey, $intProtocolVersion, $strProtocol); }