/** * Handles commands. * * @param \Mars\Network\Server $server The server instance. * @param \Mars\Message\Message $message The message instance. * * @return bool|void */ protected function _handleQuery(Server $server, $message) { //Verify all required information. if (!User::hasPermission($message->userId, $this->_botAdmins)) { $server->ModuleManager->message('You are not administrator of the bot.'); return false; } elseif (count($message->arguments) < $this->_commands[$message->command]['params']) { //Check if the user has given enough parameters. $server->ModuleManager->message('Not enough parameters given. Syntax: ' . $this->_commands[$message->command]['syntax']); return false; } //Handle the command. switch ($message->command) { case 'aistart': if ($this->_aiStarted === false) { $this->_aiStarted = true; } $server->ModuleManager->message('Artificial Intelligence started !'); break; case 'aistop': if ($this->_aiStarted === true) { $this->_aiStarted = false; } $server->ModuleManager->message('Artificial Intelligence has been stoped !'); break; case 'module': $this->_handleModule($server, $message); break; } }
/** * 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; }
/** * Handles commands. * * @param \Mars\Network\Server $server The server instance. * @param \Mars\Message\Message $message The message instance. * * @return bool|void */ protected function _handleQuery(Server $server, $message) { //Verify all required information. if (!User::hasPermission($message->userId, $this->_botAdmins)) { $server->ModuleManager->message('You are not administrator of the bot.'); return false; } elseif (count($message->arguments) < $this->_commands[$message->command]['params']) { //Check if the user has given enough parameters. $server->ModuleManager->message('Not enough parameters given. Syntax: ' . $this->_commands[$message->command]['syntax']); return false; } //Handle the command. switch ($message->command) { case 'packet': $this->_handlePacket($server, $message); break; } }
/** * 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; }