/** * Prepares connection with web socket server * * @return void */ public function socketPrepare() { // log start Logger::notice('[SOCKET] Preparing connection...'); /* 1ST REQUEST : COOKIES */ $wssJson = $this->socketRequest($this->_cookie); // removing null chars $wssJson = urldecode(str_replace('%00%09%07%FF0', '', urlencode($wssJson))); // check if valid json object if (Fetch::isPageJson($wssJson)) { // storing sid $socketId = json_decode($wssJson)->sid; $sockConf = 'sid=' . $socketId; // appending io token to cookie $ioCookie = Fetch::removePageCookie($this->_cookie, 'PHPSESSID') . 'io=' . $socketId . ';'; /* 2ND REQUEST : TEST */ // if response returns data if (isset($this->socketRequest($ioCookie, $sockConf)[0])) { // generate payload $key = '["auth","' . $this->getAuthKey() . '"]'; /* 3RD REQUEST : HANDSHAKE */ // if handshake is ok if ($this->socketRequest($ioCookie, $sockConf, true, '45:' . (strlen($key) - 1) . $key) == 'ok') { /* 4TH REQUEST: AUTH SUCCESS TEST */ // if response returns data if (isset($this->socketRequest($ioCookie, $sockConf)[0])) { // reset socket tick $this->_sockTick = 0; // log endn Logger::notice('[SOCKET] Connection prepared'); // return sid return array($ioCookie, $socketId); } else { Logger::crit('[SOCKET] 4: Auth success failed'); } } else { Logger::crit('[SOCKET] 3: Handshake failed'); } } else { Logger::crit('[SOCKET] 2: Test request failed'); } } else { Logger::crit('[SOCKET] 1: SID fetch failed'); } }
/** * Prepares connection with web socket server * * @return void */ public function socketPrepare() { // log start Logger::notice('[SOCKET] Preparing connection...'); /* 1ST REQUEST : COOKIES */ $wssJson = $this->socketRequest(false); // removing null chars $wssJson = urldecode(str_replace('%00%09%07%FF0', '', urlencode($wssJson))); // check if valid json object if (Fetch::isPageJson($wssJson)) { // storing sid $socketId = json_decode($wssJson)->sid; $sockConf = 'sid=' . $socketId; // appending io token to cookie $ioCookie = 'io=' . $socketId . ';'; /* 2ND REQUEST : TEST */ // if response returns data if (isset($this->socketRequest($ioCookie, $sockConf)[0])) { // generate payload $stats = '42["stats"]'; /* 3RD REQUEST : HANDSHAKE */ // if handshake is ok if ($this->socketRequest($ioCookie, $sockConf, true, mb_strlen($stats, 'utf8') . ':' . $stats) == 'ok') { /* 4TH REQUEST: TEST */ // if response returns data if (isset($this->socketRequest($ioCookie, $sockConf)[0])) { /* 5TH Auth TEST */ // generate payload $partOne = '42["chat"]'; $partTwo = '42["user","' . $this->_accessToken . '"]'; // if connected if ($this->socketRequest($ioCookie, $sockConf, true, mb_strlen($partOne, 'utf8') . ':' . $partOne . mb_strlen($partTwo, 'utf8') . ':' . $partTwo) == 'ok') { // log end Logger::notice('[SOCKET] Connection prepared'); // return sid return array($ioCookie, $socketId); } else { Logger::crit('[SOCKET] 5: Chat Success failed'); } } else { Logger::crit('[SOCKET] 4: Stats request failed'); } } else { Logger::crit('[SOCKET] 3: Handshake failed'); } } else { Logger::crit('[SOCKET] 2: Test request failed'); } } else { Logger::crit('[SOCKET] 1: SID fetch failed'); } }