/** * Extends socketPrepare() - this method requests the websocket server using * polling parameters as default, and handles incrementation on t parameter * * @param string $cookie Cookie to send * @param string $config Optional - Options to add to standard polling config * @param integer $request 1 - POST or 0 - GET * @param mixed $payload Post fields to send with request, if POST * * @return string Socket response */ public function socketRequest($cookie, $config = false, $request = 0, $payload = false) { // config $params = 'EIO=3&transport=polling&t=' . TimeSpan::microstamp() . '-' . $this->_sockTick; // extending config if (is_string($config)) { $params .= '&' . $config; } // get main host $host = str_replace('ws.', '', parse_url($this->_sockLink)['host']); // wss request $wssResponse = Fetch::getPage($this->_sockLink . '?' . $params, $cookie, $host, $request, $payload); // increment ticker $this->_sockTick++; // return response return $wssResponse; }
/** * Displays when given username was last seen in chatroom * * @param object $user User Object * @param array $msg Message Array * * @return void */ private function command_seen($user, $msg) { // log output message $outputMsg = null; // // if username has been entered if (isset($msg[1]) && isset(trim($msg[1])[0])) { // if username is too long if (mb_strlen($msg[1], 'utf8') >= 50) { // blacklist user for spam $this->_blacklist[] = $user["user"]; } else { if (strtolower($msg[1]) == $this->_botName) { // output silly message $outputMsg = 'Nobody knows I am always watching :('; } else { if (strtolower($user['user']) == strtolower($msg[1])) { // output humor message $outputMsg = 'You are a bit blind, arent you ' . $user['user'] . '? ;)'; } else { if ($timestamp = $this->_userTable->getTimestamp($msg[1])) { // time calculation $timeDiff = TimeSpan::calcDiff(time(), $timestamp, 5); // if seen later than 5 mins if ($timeDiff != 'now') { // show time span $outputMsg = $msg[1] . ' was last seen ' . $timeDiff . ' ago'; } else { // show as present $outputMsg = $msg[1] . ' seems to be here now'; } // if user has not been seen } else { if (strlen($msg[1]) > 0) { // username not seen $outputMsg = $msg[1] . ' has not been seen'; } } } } } // output log/message $this->internalSendMessage($outputMsg); } else { // store message $outputMsg = 'Seen example: (!seen Stars) will return how long ago Stars was seen in chat :)'; // output log / message $this->internalSendMessage($outputMsg, true, $user); } }