Esempio n. 1
0
 /**
  * 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');
     }
 }
Esempio n. 2
0
 /**
  * Terminates bot 
  *
  * @param object $user   User Object
  * @param array  $msg    Message Array
  *
  * @return void
  */
 private function command_exit($user, $msg)
 {
     // check if user is owner
     if ($user['userId'] == $this->_userId) {
         // log output message
         $outputMsg = 'Bot has been terminated';
         // terminate message
         $this->internalSendMessage($outputMsg, true, $user);
         // logout
         $this->_eventEmitter->logout();
         // set exit indicator
         $this->_exitProgram = true;
         // log terminate request to console
         Logger::crit('[OWNER] Terminated Bot');
     }
 }
Esempio n. 3
0
 private function customQuery($stmt, $params, \Closure $callback = null)
 {
     try {
         // prepare query
         $stmtTest = $this->prepare($stmt);
         // bind params
         foreach ($params as $k => $v) {
             $stmtTest->bindValue($k, $v);
         }
         // execute query
         $stmtTest->execute();
         // if response is needed, give callback
         if ($callback != null) {
             $callback($stmtTest);
         }
         // close query
         $stmtTest->closeCursor();
     } catch (\PDOException $pdoException) {
         // output query error
         Logger::crit($pdoException->getMessage());
     }
 }
Esempio n. 4
0
 /**
  * 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');
     }
 }