/** * The bot has been tickled by someone. * * @param \Mars\Network\Server $server The server instance. * @param array $data The data received from the socket. * * @return bool */ public function onZ(Server $server, $data) { if (isset($data['z']['u']) && !empty($data['z']['u'])) { $id = User::parseId($data['z']['u']); $server->ModuleManager->answerTickle((int) $id); return true; } return false; }
/** * A message has been send in the room. * * @param \Mars\Network\Server $server The server instance. * @param array $response The data received from the socket. * * @return void|bool */ public function onM(Server $server, $response) { //A message has been posted in main chat. $data['message'] = $response['m']['t']; //Ignore all commands message starting with / (Like deleting a message, Typing etc). if (!isset($data['message']) || substr($data['message'], 0, 1) == '/') { return; } $data['old'] = isset($response['m']['s']) ? true : false; //Xat send sometimes the old messages, we ignore it so. if ($data['old']) { return; } //Get the Id of the user who has sent the message. $data['userId'] = isset($response['m']['u']) ? $response['m']['u'] : false; if ($data['userId']) { $data['userId'] = User::parseId($response['m']['u']); } $message = new Message($data); $server->ModuleManager->onChannelMessage($message); return true; }
/** * Create the new user with his information. * * @param array $user The user to create. * * @return array The user created. */ protected function _createUser(array $user = []) { $user['u']['u'] = User::parseId($user['u']['u']); $status = strstr($user['u']['n'], '##'); if ($status != false) { $status = substr($status, 2); } $newUser = ['id' => $user['u']['u'], 'name' => $user['u']['n'], 'registeredName' => isset($user['u']['N']) ? $user['u']['N'] : '', 'avatar' => $user['u']['a'], 'homepage' => $user['u']['h'], 'status' => $status != false ? $status : false, 'rank' => isset($user['u']['f']) ? User::fToRank($user['u']['f']) : 'guest', 'loaded' => time(), 'modified' => false]; return $newUser; }