diff options
Diffstat (limited to 'linden/indra/newview/llviewermessage.cpp')
-rw-r--r-- | linden/indra/newview/llviewermessage.cpp | 199 |
1 files changed, 178 insertions, 21 deletions
diff --git a/linden/indra/newview/llviewermessage.cpp b/linden/indra/newview/llviewermessage.cpp index 87ff5aa..8f2fc1a 100644 --- a/linden/indra/newview/llviewermessage.cpp +++ b/linden/indra/newview/llviewermessage.cpp | |||
@@ -154,6 +154,22 @@ LLFrameTimer gThrottleTimer; | |||
154 | const U32 OFFER_THROTTLE_MAX_COUNT=5; //number of items per time period | 154 | const U32 OFFER_THROTTLE_MAX_COUNT=5; //number of items per time period |
155 | const F32 OFFER_THROTTLE_TIME=10.f; //time period in seconds | 155 | const F32 OFFER_THROTTLE_TIME=10.f; //time period in seconds |
156 | 156 | ||
157 | //script permissions | ||
158 | const LLString SCRIPT_QUESTIONS[SCRIPT_PERMISSION_EOF] = | ||
159 | { | ||
160 | "ScriptTakeMoney", | ||
161 | "ActOnControlInputs", | ||
162 | "RemapControlInputs", | ||
163 | "AnimateYourAvatar", | ||
164 | "AttachToYourAvatar", | ||
165 | "ReleaseOwnership", | ||
166 | "LinkAndDelink", | ||
167 | "AddAndRemoveJoints", | ||
168 | "ChangePermissions", | ||
169 | "TrackYourCamera", | ||
170 | "ControlYourCamera" | ||
171 | }; | ||
172 | |||
157 | struct LLFriendshipOffer | 173 | struct LLFriendshipOffer |
158 | { | 174 | { |
159 | LLUUID mFromID; | 175 | LLUUID mFromID; |
@@ -4243,8 +4259,8 @@ void process_economy_data(LLMessageSystem *msg, void** /*user_data*/) | |||
4243 | class LLScriptQuestionCBData | 4259 | class LLScriptQuestionCBData |
4244 | { | 4260 | { |
4245 | public: | 4261 | public: |
4246 | LLScriptQuestionCBData(const LLUUID &taskid, const LLUUID &itemid, const LLHost &sender, S32 questions) | 4262 | LLScriptQuestionCBData(const LLUUID &taskid, const LLUUID &itemid, const LLHost &sender, S32 questions, const char *object_name, const char *owner_name) |
4247 | : mTaskID(taskid), mItemID(itemid), mSender(sender), mQuestions(questions) | 4263 | : mTaskID(taskid), mItemID(itemid), mSender(sender), mQuestions(questions), mObjectName(object_name), mOwnerName(owner_name) |
4248 | { | 4264 | { |
4249 | } | 4265 | } |
4250 | 4266 | ||
@@ -4252,17 +4268,138 @@ public: | |||
4252 | LLUUID mItemID; | 4268 | LLUUID mItemID; |
4253 | LLHost mSender; | 4269 | LLHost mSender; |
4254 | S32 mQuestions; | 4270 | S32 mQuestions; |
4271 | LLString mObjectName; | ||
4272 | LLString mOwnerName; | ||
4255 | }; | 4273 | }; |
4256 | 4274 | ||
4275 | void notify_cautioned_script_question(LLScriptQuestionCBData* cbdata, S32 orig_questions, BOOL granted) | ||
4276 | { | ||
4277 | // only continue if at least some permissions were requested | ||
4278 | if (orig_questions) | ||
4279 | { | ||
4280 | // "'[OBJECTNAME]', an object owned by '[OWNERNAME]', | ||
4281 | // located in [REGIONNAME] at [REGIONPOS], | ||
4282 | // has been <granted|denied> permission to: [PERMISSIONS]." | ||
4283 | |||
4284 | LLUIString notice(LLNotifyBox::getTemplateMessage(granted ? "ScriptQuestionCautionChatGranted" : "ScriptQuestionCautionChatDenied")); | ||
4285 | |||
4286 | // always include the object name and owner name | ||
4287 | notice.setArg("[OBJECTNAME]", cbdata->mObjectName); | ||
4288 | notice.setArg("[OWNERNAME]", cbdata->mOwnerName); | ||
4289 | |||
4290 | // try to lookup viewerobject that corresponds to the object that | ||
4291 | // requested permissions (here, taskid->requesting object id) | ||
4292 | BOOL foundpos = FALSE; | ||
4293 | LLViewerObject* viewobj = gObjectList.findObject(cbdata->mTaskID); | ||
4294 | if (viewobj) | ||
4295 | { | ||
4296 | // found the viewerobject, get it's position in its region | ||
4297 | LLVector3 objpos(viewobj->getPosition()); | ||
4298 | |||
4299 | // try to lookup the name of the region the object is in | ||
4300 | LLViewerRegion* viewregion = viewobj->getRegion(); | ||
4301 | if (viewregion) | ||
4302 | { | ||
4303 | // got the region, so include the region and 3d coordinates of the object | ||
4304 | notice.setArg("[REGIONNAME]", viewregion->getName()); | ||
4305 | LLString formatpos = llformat("%.1f, %.1f,%.1f", objpos[VX], objpos[VY], objpos[VZ]); | ||
4306 | notice.setArg("[REGIONPOS]", formatpos); | ||
4307 | |||
4308 | foundpos = TRUE; | ||
4309 | } | ||
4310 | } | ||
4311 | |||
4312 | if (!foundpos) | ||
4313 | { | ||
4314 | // unable to determine location of the object | ||
4315 | notice.setArg("[REGIONNAME]", "(unknown region)"); | ||
4316 | notice.setArg("[REGIONPOS]", "(unknown position)"); | ||
4317 | } | ||
4318 | |||
4319 | // check each permission that was requested, and list each | ||
4320 | // permission that has been flagged as a caution permission | ||
4321 | BOOL caution = FALSE; | ||
4322 | S32 count = 0; | ||
4323 | LLString perms; | ||
4324 | for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; i++) | ||
4325 | { | ||
4326 | if ((orig_questions & LSCRIPTRunTimePermissionBits[i]) && LLNotifyBox::getTemplateIsCaution(SCRIPT_QUESTIONS[i])) | ||
4327 | { | ||
4328 | count++; | ||
4329 | caution = TRUE; | ||
4330 | |||
4331 | // add a comma before the permission description if it is not the first permission | ||
4332 | // added to the list or the last permission to check | ||
4333 | if ((count > 1) && (i < SCRIPT_PERMISSION_EOF)) | ||
4334 | { | ||
4335 | perms.append(", "); | ||
4336 | } | ||
4337 | |||
4338 | perms.append(LLNotifyBox::getTemplateMessage(SCRIPT_QUESTIONS[i])); | ||
4339 | } | ||
4340 | } | ||
4341 | |||
4342 | notice.setArg("[PERMISSIONS]", perms); | ||
4343 | |||
4344 | // log a chat message as long as at least one requested permission | ||
4345 | // is a caution permission | ||
4346 | if (caution) | ||
4347 | { | ||
4348 | LLChat chat(notice.getString()); | ||
4349 | LLFloaterChat::addChat(chat, FALSE, FALSE); | ||
4350 | } | ||
4351 | } | ||
4352 | } | ||
4353 | |||
4354 | void script_question_decline_cb(S32 option, void* user_data) | ||
4355 | { | ||
4356 | LLMessageSystem *msg = gMessageSystem; | ||
4357 | LLScriptQuestionCBData *cbdata = (LLScriptQuestionCBData *)user_data; | ||
4358 | |||
4359 | // remember the permissions requested so they can be checked | ||
4360 | // when it comes time to log a chat message | ||
4361 | S32 orig = cbdata->mQuestions; | ||
4362 | |||
4363 | // this callback will always decline all permissions requested | ||
4364 | // (any question flags set in the ScriptAnswerYes message | ||
4365 | // will be interpreted as having been granted, so clearing all | ||
4366 | // the bits will deny every permission) | ||
4367 | cbdata->mQuestions = 0; | ||
4368 | |||
4369 | // respond with the permissions denial | ||
4370 | msg->newMessageFast(_PREHASH_ScriptAnswerYes); | ||
4371 | msg->nextBlockFast(_PREHASH_AgentData); | ||
4372 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
4373 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); | ||
4374 | msg->nextBlockFast(_PREHASH_Data); | ||
4375 | msg->addUUIDFast(_PREHASH_TaskID, cbdata->mTaskID); | ||
4376 | msg->addUUIDFast(_PREHASH_ItemID, cbdata->mItemID); | ||
4377 | msg->addS32Fast(_PREHASH_Questions, cbdata->mQuestions); | ||
4378 | msg->sendReliable(cbdata->mSender); | ||
4379 | |||
4380 | // log a chat message, if appropriate | ||
4381 | notify_cautioned_script_question(cbdata, orig, FALSE); | ||
4382 | |||
4383 | delete cbdata; | ||
4384 | } | ||
4257 | 4385 | ||
4258 | void script_question_cb(S32 option, void* user_data) | 4386 | void script_question_cb(S32 option, void* user_data) |
4259 | { | 4387 | { |
4260 | LLMessageSystem *msg = gMessageSystem; | 4388 | LLMessageSystem *msg = gMessageSystem; |
4261 | LLScriptQuestionCBData *cbdata = (LLScriptQuestionCBData *)user_data; | 4389 | LLScriptQuestionCBData *cbdata = (LLScriptQuestionCBData *)user_data; |
4390 | S32 orig = cbdata->mQuestions; | ||
4391 | |||
4392 | // check whether permissions were granted or denied | ||
4393 | BOOL allowed = TRUE; | ||
4394 | // the "yes/accept" button is the first button in the template, making it button 0 | ||
4395 | // if any other button was clicked, the permissions were denied | ||
4262 | if (option != 0) | 4396 | if (option != 0) |
4263 | { | 4397 | { |
4264 | cbdata->mQuestions = 0; | 4398 | cbdata->mQuestions = 0; |
4265 | } | 4399 | allowed = FALSE; |
4400 | } | ||
4401 | |||
4402 | // reply with the permissions granted or denied | ||
4266 | msg->newMessageFast(_PREHASH_ScriptAnswerYes); | 4403 | msg->newMessageFast(_PREHASH_ScriptAnswerYes); |
4267 | msg->nextBlockFast(_PREHASH_AgentData); | 4404 | msg->nextBlockFast(_PREHASH_AgentData); |
4268 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | 4405 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); |
@@ -4272,27 +4409,20 @@ void script_question_cb(S32 option, void* user_data) | |||
4272 | msg->addUUIDFast(_PREHASH_ItemID, cbdata->mItemID); | 4409 | msg->addUUIDFast(_PREHASH_ItemID, cbdata->mItemID); |
4273 | msg->addS32Fast(_PREHASH_Questions, cbdata->mQuestions); | 4410 | msg->addS32Fast(_PREHASH_Questions, cbdata->mQuestions); |
4274 | msg->sendReliable(cbdata->mSender); | 4411 | msg->sendReliable(cbdata->mSender); |
4412 | |||
4413 | // only log a chat message if caution prompts are enabled | ||
4414 | if (gSavedSettings.getBOOL("PermissionsCautionEnabled")) | ||
4415 | { | ||
4416 | // log a chat message, if appropriate | ||
4417 | notify_cautioned_script_question(cbdata, orig, allowed); | ||
4418 | } | ||
4419 | |||
4275 | delete cbdata; | 4420 | delete cbdata; |
4276 | } | 4421 | } |
4277 | 4422 | ||
4278 | |||
4279 | void process_script_question(LLMessageSystem *msg, void **user_data) | 4423 | void process_script_question(LLMessageSystem *msg, void **user_data) |
4280 | { | 4424 | { |
4281 | // XUI:translate owner name -> [FIRST] [LAST] | 4425 | // XUI:translate owner name -> [FIRST] [LAST] |
4282 | const LLString script_questions[SCRIPT_PERMISSION_EOF] = | ||
4283 | { | ||
4284 | "ScriptTakeMoney", | ||
4285 | "ActOnControlInputs", | ||
4286 | "RemapControlInputs", | ||
4287 | "AnimateYourAvatar", | ||
4288 | "AttachToYourAvatar", | ||
4289 | "ReleaseOwnership", | ||
4290 | "LinkAndDelink", | ||
4291 | "AddAndRemoveJoints", | ||
4292 | "ChangePermissions", | ||
4293 | "TrackYourCamera", | ||
4294 | "ControlYourCamera" | ||
4295 | }; | ||
4296 | 4426 | ||
4297 | LLHost sender = msg->getSender(); | 4427 | LLHost sender = msg->getSender(); |
4298 | 4428 | ||
@@ -4302,7 +4432,9 @@ void process_script_question(LLMessageSystem *msg, void **user_data) | |||
4302 | char object_name[255]; /* Flawfinder: ignore */ | 4432 | char object_name[255]; /* Flawfinder: ignore */ |
4303 | char owner_name[DB_FULL_NAME_BUF_SIZE]; /* Flawfinder: ignore */ | 4433 | char owner_name[DB_FULL_NAME_BUF_SIZE]; /* Flawfinder: ignore */ |
4304 | 4434 | ||
4435 | // taskid -> object key of object requesting permissions | ||
4305 | msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid ); | 4436 | msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid ); |
4437 | // itemid -> script asset key of script requesting permissions | ||
4306 | msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid ); | 4438 | msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid ); |
4307 | msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, 255, object_name); | 4439 | msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, 255, object_name); |
4308 | msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, DB_FULL_NAME_BUF_SIZE, owner_name); | 4440 | msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, DB_FULL_NAME_BUF_SIZE, owner_name); |
@@ -4311,23 +4443,48 @@ void process_script_question(LLMessageSystem *msg, void **user_data) | |||
4311 | LLString script_question; | 4443 | LLString script_question; |
4312 | if (questions) | 4444 | if (questions) |
4313 | { | 4445 | { |
4446 | BOOL caution = FALSE; | ||
4314 | S32 count = 0; | 4447 | S32 count = 0; |
4315 | LLString::format_map_t args; | 4448 | LLString::format_map_t args; |
4316 | args["[OBJECTNAME]"] = object_name; | 4449 | args["[OBJECTNAME]"] = object_name; |
4317 | args["[NAME]"] = owner_name; | 4450 | args["[NAME]"] = owner_name; |
4451 | |||
4452 | // check the received permission flags against each permission | ||
4318 | for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; i++) | 4453 | for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; i++) |
4319 | { | 4454 | { |
4320 | if (questions & LSCRIPTRunTimePermissionBits[i]) | 4455 | if (questions & LSCRIPTRunTimePermissionBits[i]) |
4321 | { | 4456 | { |
4322 | count++; | 4457 | count++; |
4323 | script_question += " " + LLNotifyBox::getTemplateMessage(script_questions[i]) + "\n"; | 4458 | script_question += " " + LLNotifyBox::getTemplateMessage(SCRIPT_QUESTIONS[i]) + "\n"; |
4459 | |||
4460 | // check whether permission question should cause special caution dialog | ||
4461 | caution |= LLNotifyBox::getTemplateIsCaution(SCRIPT_QUESTIONS[i]); | ||
4324 | } | 4462 | } |
4325 | } | 4463 | } |
4326 | args["[QUESTIONS]"] = script_question; | 4464 | args["[QUESTIONS]"] = script_question; |
4327 | 4465 | ||
4328 | LLScriptQuestionCBData *cbdata = new LLScriptQuestionCBData(taskid, itemid, sender, questions); | 4466 | LLScriptQuestionCBData *cbdata = new LLScriptQuestionCBData(taskid, itemid, sender, questions, object_name, owner_name); |
4467 | |||
4468 | // check whether cautions are even enabled or not | ||
4469 | if (gSavedSettings.getBOOL("PermissionsCautionEnabled")) | ||
4470 | { | ||
4471 | if (caution) | ||
4472 | { | ||
4473 | // display the caution permissions prompt | ||
4474 | LLNotifyBox::showXml("ScriptQuestionCaution", args, TRUE, script_question_cb, cbdata); | ||
4475 | } | ||
4476 | else | ||
4477 | { | ||
4478 | // display the permissions request normally | ||
4479 | LLNotifyBox::showXml("ScriptQuestion", args, FALSE, script_question_cb, cbdata); | ||
4480 | } | ||
4481 | } | ||
4482 | else | ||
4483 | { | ||
4484 | // fall back to default behavior if cautions are entirely disabled | ||
4485 | LLNotifyBox::showXml("ScriptQuestion", args, FALSE, script_question_cb, cbdata); | ||
4486 | } | ||
4329 | 4487 | ||
4330 | LLNotifyBox::showXml("ScriptQuestion", args, script_question_cb, cbdata); | ||
4331 | } | 4488 | } |
4332 | } | 4489 | } |
4333 | 4490 | ||