123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680 |
- /**
- * @file llavataractions.cpp
- * @brief avatar-related actions (IM, teleporting, etc)
- *
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "llviewerprecompiledheaders.h"
- #include "llavataractions.h"
- #include "llcachename.h"
- #include "llnotifications.h"
- #include "lltrans.h"
- #include "roles_constants.h" // For GP_LAND_ADMIN
- #include "llagent.h"
- #include "llcommandhandler.h"
- #include "llfloateravatarinfo.h"
- #include "llfloaterfriends.h"
- #include "llfloaterinspect.h"
- #include "llfloatermute.h"
- #include "llfloaterpay.h"
- #include "llinventorymodel.h"
- #include "llimmgr.h"
- //MK
- #include "mkrlinterface.h"
- //mk
- #include "llviewermessage.h" // send_improved_im() handle_lure() give_money()
- #include "llviewerobjectlist.h"
- #include "llviewerparcelmgr.h"
- #include "llviewerregion.h"
- #include "llvoavatar.h"
- //-----------------------------------------------------------------------------
- // Command handler
- //-----------------------------------------------------------------------------
- static void on_name_cache_mute(const LLUUID& agent_id, const std::string& name,
- bool is_group, bool mute_it)
- {
- LLMute mute(agent_id, name, LLMute::AGENT);
- if (LLMuteList::isMuted(agent_id, name))
- {
- if (!mute_it)
- {
- LLMuteList::remove(mute);
- }
- }
- else
- {
- if (mute_it)
- {
- LLMuteList::add(mute);
- }
- LLFloaterMute::selectMute(agent_id);
- }
- }
- class LLAgentHandler final : public LLCommandHandler
- {
- public:
- LLAgentHandler()
- : LLCommandHandler("agent", UNTRUSTED_THROTTLE)
- {
- }
- bool canHandleUntrusted(const LLSD& params, const LLSD&,
- LLMediaCtrl*, const std::string& nav_type) override
- {
- if (params.size() < 2)
- {
- return true; // Do not block; it will fail later in handle()
- }
- if (nav_type == "clicked" || nav_type == "external")
- {
- return true;
- }
- std::string verb = params[1].asString();
- return verb == "about" || verb == "inspect" || verb == "username" ||
- verb == "displayname" || verb == "completename";
- }
- bool handle(const LLSD& params, const LLSD&, LLMediaCtrl*) override
- {
- if (params.size() < 2) return false;
- LLUUID agent_id;
- if (!agent_id.set(params[0], false))
- {
- return false;
- }
- const std::string verb = params[1].asString();
- if (verb == "about" || verb == "username" || verb == "displayname" ||
- verb == "completename")
- {
- LLFloaterAvatarInfo::show(agent_id);
- }
- else if (verb == "inspect")
- {
- HBFloaterInspectAvatar::show(agent_id);
- }
- else if (verb == "pay")
- {
- LLAvatarActions::pay(agent_id);
- }
- else if (verb == "offerteleport")
- {
- LLAvatarActions::offerTeleport(agent_id);
- }
- else if (verb == "im")
- {
- LLAvatarActions::startIM(agent_id);
- }
- else if (verb == "requestfriend")
- {
- LLAvatarActions::requestFriendshipDialog(agent_id);
- }
- else if (verb == "mute" || verb == "unmute" ||
- verb == "block" || verb == "unblock")
- {
- if (!gCacheNamep) return false; // Paranoia
- gCacheNamep->get(agent_id, false,
- boost::bind(&on_name_cache_mute,
- _1, _2, _3,
- verb == "mute" || verb == "block"));
- }
- else
- {
- return false;
- }
- return true;
- }
- };
- LLAgentHandler gAgentHandler;
- ///////////////////////////////////////////////////////////////////////////////
- // LLAvatarActions class
- ///////////////////////////////////////////////////////////////////////////////
- static void on_avatar_name_friendship(const LLUUID& id,
- const LLAvatarName& av_name)
- {
- std::string fullname;
- if (!LLAvatarName::sLegacyNamesForFriends &&
- LLAvatarNameCache::useDisplayNames())
- {
- if (LLAvatarNameCache::useDisplayNames() == 2)
- {
- fullname = av_name.mDisplayName;
- }
- else
- {
- fullname = av_name.getNames();
- }
- }
- else
- {
- fullname = av_name.getLegacyName();
- }
- LLAvatarActions::requestFriendshipDialog(id, fullname);
- }
- //static
- void LLAvatarActions::requestFriendshipDialog(const LLUUID& id)
- {
- if (id.isNull() || !gCacheNamep)
- {
- return;
- }
- std::string fullname;
- if (gCacheNamep->getFullName(id, fullname) &&
- (LLAvatarName::sLegacyNamesForFriends ||
- !LLAvatarNameCache::useDisplayNames()))
- {
- requestFriendshipDialog(id, fullname);
- return;
- }
- LLAvatarNameCache::get(id,
- boost::bind(&on_avatar_name_friendship, _1, _2));
- }
- static bool callback_add_friend(const LLSD& notification,
- const LLSD& response)
- {
- if (LLNotification::getSelectedOption(notification, response) == 0)
- {
- LLUUID id = notification["payload"]["id"].asUUID();
- std::string message = response["message"].asString();
- //MK
- if (gRLenabled && !gRLInterface.canSendIM(id))
- {
- message = "(Hidden)";
- }
- //mk
- std::string name = notification["payload"]["name"].asString();
- LLAvatarActions::requestFriendship(id, name, message);
- }
- return false;
- }
- //static
- void LLAvatarActions::requestFriendshipDialog(const LLUUID& id,
- const std::string& name)
- {
- if (id == gAgentID)
- {
- gNotifications.add("AddSelfFriend");
- return;
- }
- LLSD args;
- args["NAME"] = name;
- LLSD payload;
- payload["id"] = id;
- payload["name"] = name;
- gNotifications.add("AddFriendWithMessage", args, payload,
- callback_add_friend);
- }
- //static
- void LLAvatarActions::requestFriendship(const LLUUID& id,
- const std::string& name,
- const std::string& message)
- {
- const LLUUID& folder_id =
- gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
- send_improved_im(id, name, message, IM_ONLINE, IM_FRIENDSHIP_OFFERED,
- folder_id);
- }
- //static
- void LLAvatarActions::offerTeleport(const LLUUID& id)
- {
- if (id.isNull())
- {
- llwarns << "Null avatar UUID, aborted." << llendl;
- }
- else if (id == gAgentID)
- {
- llwarns << "Cannot teleport self !" << llendl;
- }
- else
- {
- uuid_vec_t ids;
- ids.push_back(id);
- handle_lure(ids);
- }
- }
- //static
- void LLAvatarActions::offerTeleport(const uuid_vec_t& ids)
- {
- if (ids.size() > 0)
- {
- handle_lure(ids);
- }
- else
- {
- llwarns << "Tried to offer teleport to an empty list of avatars"
- << llendl;
- }
- }
- static void teleport_request_callback(const LLSD& notification,
- const LLSD& response)
- {
- S32 option = 0;
- if (response.isInteger())
- {
- option = response.asInteger();
- }
- else
- {
- option = LLNotification::getSelectedOption(notification, response);
- }
- if (option == 0)
- {
- LLMessageSystem* msg = gMessageSystemp;
- msg->newMessageFast(_PREHASH_ImprovedInstantMessage);
- msg->nextBlockFast(_PREHASH_AgentData);
- msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
- msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
- msg->nextBlockFast(_PREHASH_MessageBlock);
- msg->addBoolFast(_PREHASH_FromGroup, false);
- LLUUID target_id = notification["substitutions"]["uuid"].asUUID();
- msg->addUUIDFast(_PREHASH_ToAgentID, target_id);
- msg->addU8Fast(_PREHASH_Offline, IM_ONLINE);
- msg->addU8Fast(_PREHASH_Dialog, IM_TELEPORT_REQUEST);
- msg->addUUIDFast(_PREHASH_ID, LLUUID::null);
- // no timestamp necessary
- msg->addU32Fast(_PREHASH_Timestamp, NO_TIMESTAMP);
- std::string name;
- gAgent.buildFullname(name);
- msg->addStringFast(_PREHASH_FromAgentName, name);
- //MK
- if (gRLenabled && !gRLInterface.canSendIM(target_id))
- {
- msg->addStringFast(_PREHASH_Message, "(Hidden)");
- }
- else
- //mk
- {
- msg->addStringFast(_PREHASH_Message, response["message"]);
- }
- msg->addU32Fast(_PREHASH_ParentEstateID, 0);
- msg->addUUIDFast(_PREHASH_RegionID, LLUUID::null);
- msg->addVector3Fast(_PREHASH_Position, gAgent.getPositionAgent());
- msg->addBinaryDataFast(_PREHASH_BinaryBucket, EMPTY_BINARY_BUCKET,
- EMPTY_BINARY_BUCKET_SIZE);
- gAgent.sendReliableMessage();
- }
- }
- //static
- void LLAvatarActions::teleportRequest(const LLUUID& id)
- {
- if (id.isNull())
- {
- llwarns << "Null avatar UUID, aborted." << llendl;
- }
- else if (id == gAgentID)
- {
- llwarns << "Cannot request a teleport to self !" << llendl;
- }
- else
- {
- LLAvatarName av_name;
- if (LLAvatarNameCache::get(id, &av_name))
- {
- LLSD notification;
- notification["uuid"] = id;
- notification["NAME"] = av_name.getNames();
- LLSD payload;
- gNotifications.add("TeleportRequestPrompt", notification, payload,
- teleport_request_callback);
- }
- else // Unlikely ... they just picked this name from somewhere...
- {
- // Re-invoke this very method after the name resolves
- LLAvatarNameCache::get(id, boost::bind(&teleportRequest, id));
- }
- }
- }
- static void on_avatar_name_cache_start_im(const LLUUID& agent_id,
- const LLAvatarName& av_name)
- {
- if (gIMMgrp)
- {
- gIMMgrp->setFloaterOpen(true);
- gIMMgrp->addSession(av_name.getLegacyName(), IM_NOTHING_SPECIAL,
- agent_id);
- make_ui_sound("UISndStartIM");
- }
- }
- //static
- void LLAvatarActions::startIM(const LLUUID& id)
- {
- if (id.isNull())
- {
- llwarns << "Null avatar UUID, aborted." << llendl;
- }
- else if (id == gAgentID)
- {
- llwarns << "Cannot IM to self !" << llendl;
- }
- else
- {
- LLAvatarNameCache::get(id, boost::bind(&on_avatar_name_cache_start_im,
- _1, _2));
- }
- }
- //static
- void LLAvatarActions::startIM(const uuid_vec_t& ids, bool friends)
- {
- if (!gIMMgrp) return;
- S32 count = ids.size();
- if (count > 1)
- {
- // Group IM
- LLUUID session_id;
- session_id.generate();
- gIMMgrp->setFloaterOpen(true);
- // *TODO: translate
- gIMMgrp->addSession(friends ? "Friends Conference"
- : "Avatars Conference",
- IM_SESSION_CONFERENCE_START, ids[0], ids);
- make_ui_sound("UISndStartIM");
- }
- else if (count == 1)
- {
- // Single avatar
- LLUUID agent_id = ids[0];
- startIM(agent_id);
- }
- else
- {
- llwarns << "Tried to initiate an IM conference with an empty list of participants"
- << llendl;
- }
- }
- //static
- void LLAvatarActions::pay(const LLUUID& id)
- {
- if (id.isNull())
- {
- llwarns << "Null avatar UUID, aborted." << llendl;
- }
- else
- {
- LLFloaterPay::payDirectly(&give_money, id, false);
- }
- }
- //static
- void LLAvatarActions::buildAvatarsList(std::vector<LLAvatarName> avatar_names,
- std::string& avatars, bool force_legacy,
- const std::string& separator)
- {
- U32 name_usage = force_legacy ? 0 : LLAvatarNameCache::useDisplayNames();
- std::sort(avatar_names.begin(), avatar_names.end());
- for (std::vector<LLAvatarName>::const_iterator it = avatar_names.begin(),
- end = avatar_names.end();
- it != end; ++it)
- {
- if (!avatars.empty())
- {
- avatars.append(separator);
- }
- switch (name_usage)
- {
- case 2:
- avatars.append(it->mDisplayName);
- break;
- case 1:
- avatars.append(it->getNames());
- break;
- default:
- avatars.append(it->getLegacyName());
- }
- }
- }
- //static
- LLViewerRegion* LLAvatarActions::canEjectOrFreeze(const LLUUID& avatar_id)
- {
- LLVOAvatar* avatarp = gObjectList.findAvatar(avatar_id);
- if (!avatarp)
- {
- return NULL;
- }
- LLViewerRegion* regionp = avatarp->getRegion();
- if (!regionp)
- {
- return NULL;
- }
- const LLVector3& pos = avatarp->getPositionRegion();
- bool can_do = regionp->isOwnedSelf(pos);
- const LLVector3d& pos_global = avatarp->getPositionGlobal();
- LLParcel* parcelp =
- gViewerParcelMgr.selectParcelAt(pos_global)->getParcel();
- if (parcelp && (!can_do || regionp->isOwnedGroup(pos)))
- {
- can_do = gViewerParcelMgr.isParcelOwnedByAgent(parcelp, GP_LAND_ADMIN);
- }
- return regionp;
- }
- //static
- bool LLAvatarActions::sendEject(const LLUUID& avatar_id, bool ban)
- {
- LLViewerRegion* regionp = canEjectOrFreeze(avatar_id);
- if (!regionp)
- {
- return false;
- }
- LLMessageSystem* msg = gMessageSystemp;
- if (!msg) return false; // Paranoia
- msg->newMessage(_PREHASH_EjectUser);
- msg->nextBlock(_PREHASH_AgentData);
- msg->addUUID(_PREHASH_AgentID, gAgentID);
- msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
- msg->nextBlock(_PREHASH_Data);
- msg->addUUID(_PREHASH_TargetID, avatar_id);
- msg->addU32(_PREHASH_Flags, ban ? 0x1 : 0x0);
- msg->sendReliable(regionp->getHost());
- return true;
- }
- //static
- bool LLAvatarActions::sendFreeze(const LLUUID& avatar_id, bool freeze)
- {
- LLViewerRegion* regionp = canEjectOrFreeze(avatar_id);
- if (!regionp)
- {
- return false;
- }
- LLMessageSystem* msg = gMessageSystemp;
- if (!msg) return false; // Paranoia
- msg->newMessage(_PREHASH_FreezeUser);
- msg->nextBlock(_PREHASH_AgentData);
- msg->addUUID(_PREHASH_AgentID, gAgentID);
- msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
- msg->nextBlock(_PREHASH_Data);
- msg->addUUID(_PREHASH_TargetID, avatar_id);
- msg->addU32(_PREHASH_Flags, freeze ? 0x0 : 0x1);
- msg->sendReliable(regionp->getHost());
- return true;
- }
- static bool god_finish_kick(const LLSD& notification, const LLSD& response)
- {
- if (LLNotification::getSelectedOption(notification, response) == 0)
- {
- LLMessageSystem* msg = gMessageSystemp;
- if (!msg) return false; // Paranoia
- LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
- U32 flags = notification["payload"]["flags"].asInteger();
- msg->newMessageFast(_PREHASH_GodKickUser);
- msg->nextBlockFast(_PREHASH_UserInfo);
- msg->addUUIDFast(_PREHASH_GodID, gAgentID);
- msg->addUUIDFast(_PREHASH_GodSessionID, gAgentSessionID);
- msg->addUUIDFast(_PREHASH_AgentID, avatar_id);
- msg->addU32(_PREHASH_KickFlags, flags);
- msg->addStringFast(_PREHASH_Reason, response["message"].asString());
- gAgent.sendReliableMessage();
- }
- return false;
- }
- static bool user_finish_eject(const LLSD& notification, const LLSD& response)
- {
- if (LLNotification::getSelectedOption(notification, response) == 0)
- {
- LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
- LLAvatarActions::sendEject(avatar_id, false);
- }
- return false;
- }
- static bool user_finish_freeze(const LLSD& notification, const LLSD& response)
- {
- if (LLNotification::getSelectedOption(notification, response) == 0)
- {
- LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
- bool freeze = notification["payload"]["freeze"].asBoolean();
- LLAvatarActions::sendFreeze(avatar_id, freeze);
- }
- return false;
- }
- //static
- void LLAvatarActions::kick(const LLUUID& avatar_id)
- {
- LLSD payload;
- payload["avatar_id"] = avatar_id;
- LLSD args;
- std::string fullname;
- if (gCacheNamep && gCacheNamep->getFullName(avatar_id, fullname))
- {
- //MK
- if (gRLenabled &&
- (gRLInterface.mContainsShownames ||
- gRLInterface.mContainsShownametags))
- {
- fullname = gRLInterface.getDummyName(fullname);
- }
- //mk
- args["AVATAR_NAME"] = fullname;
- }
- else
- {
- args["AVATAR_NAME"] = LLTrans::getString("this_resident");
- }
- if (gAgent.isGodlikeWithoutAdminMenuFakery())
- {
- payload["flags"] = S32(KICK_FLAGS_DEFAULT);
- gNotifications.add("KickUser", args, payload, god_finish_kick);
- }
- else if (canEjectOrFreeze(avatar_id))
- {
- gNotifications.add("EjectUserNoMessage", args, payload,
- user_finish_eject);
- }
- }
- //static
- void LLAvatarActions::freeze(const LLUUID& avatar_id, bool freeze)
- {
- LLSD payload;
- payload["avatar_id"] = avatar_id;
- LLSD args;
- std::string fullname;
- if (gCacheNamep && gCacheNamep->getFullName(avatar_id, fullname))
- {
- //MK
- if (gRLenabled &&
- (gRLInterface.mContainsShownames ||
- gRLInterface.mContainsShownametags))
- {
- fullname = gRLInterface.getDummyName(fullname);
- }
- //mk
- args["AVATAR_NAME"] = fullname;
- }
- else
- {
- args["AVATAR_NAME"] = LLTrans::getString("this_resident");
- }
- if (gAgent.isGodlikeWithoutAdminMenuFakery())
- {
- payload["flags"] = S32(freeze ? KICK_FLAGS_FREEZE
- : KICK_FLAGS_UNFREEZE);
- gNotifications.add("FreezeUser", args, payload, god_finish_kick);
- }
- else if (canEjectOrFreeze(avatar_id))
- {
- payload["freeze"] = freeze;
- gNotifications.add("FreezeUserNoMessage", args, payload,
- user_finish_freeze);
- }
- }
|