-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathllimprocessing.cpp
More file actions
2015 lines (1810 loc) · 77.7 KB
/
Copy pathllimprocessing.cpp
File metadata and controls
2015 lines (1810 loc) · 77.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file LLIMProcessing.cpp
* @brief Container for Instant Messaging
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2018, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llimprocessing.h"
#include "llagent.h"
#include "llagentui.h"
#include "llappviewer.h"
#include "llavatarnamecache.h"
#include "llfirstuse.h"
#include "llfloaterreg.h"
#include "llfloaterimnearbychat.h"
#include "llimview.h"
#include "llinventoryobserver.h"
#include "llinventorymodel.h"
#include "llmutelist.h"
#include "llnotifications.h"
#include "llnotificationsutil.h"
#include "llnotificationmanager.h"
#include "llpanelgroup.h"
#include "llregex.h"
#include "llregionhandle.h"
#include "llsdserialize.h"
#include "llslurl.h"
#include "llstring.h"
#include "lltoastnotifypanel.h"
#include "lltrans.h"
#include "llviewergenericmessage.h"
#include "llviewerobjectlist.h"
#include "llviewermessage.h"
#include "llviewerwindow.h"
#include "llviewerregion.h"
#include "llvoavatarself.h"
#include "llworld.h"
// [RLVa:KB] - Checked: 2010-03-09 (RLVa-1.2.0a)
#include "rlvactions.h"
#include "rlvhelper.h"
#include "rlvhandler.h"
#include "rlvinventory.h"
#include "rlvui.h"
// [/RLVa:KB]
#include <boost/algorithm/string/predicate.hpp> // <alchemy/>
#include <boost/algorithm/string/replace.hpp>
#include "boost/lexical_cast.hpp"
// Resurrect the Autorespond from the archive
// -- Fallen
std::string replace_wildcards(std::string input, const LLUUID& id, const std::string& name)
{
boost::algorithm::replace_all(input, "#n", name);
// disable boost::lexical_cast warning
LLSLURL slurl;
LLAgentUI::buildSLURL(slurl);
boost::algorithm::replace_all(input, "#r", slurl.getSLURLString());
LLAvatarName av_name;
boost::algorithm::replace_all(input, "#d", LLAvatarNameCache::get(id, &av_name) ? av_name.getDisplayName() : name);
return input;
}
extern void on_new_message(const LLSD& msg);
// Strip out "Resident" for display, but only if the message came from a user
// (rather than a script)
static std::string clean_name_from_im(const std::string& name, EInstantMessage type)
{
switch (type)
{
case IM_NOTHING_SPECIAL:
case IM_MESSAGEBOX:
case IM_GROUP_INVITATION:
case IM_INVENTORY_OFFERED:
case IM_INVENTORY_ACCEPTED:
case IM_INVENTORY_DECLINED:
case IM_GROUP_VOTE:
case IM_GROUP_MESSAGE_DEPRECATED:
//IM_TASK_INVENTORY_OFFERED
//IM_TASK_INVENTORY_ACCEPTED
//IM_TASK_INVENTORY_DECLINED
case IM_NEW_USER_DEFAULT:
case IM_SESSION_INVITE:
case IM_SESSION_P2P_INVITE:
case IM_SESSION_GROUP_START:
case IM_SESSION_CONFERENCE_START:
case IM_SESSION_SEND:
case IM_SESSION_LEAVE:
//IM_FROM_TASK
case IM_DO_NOT_DISTURB_AUTO_RESPONSE:
case IM_CONSOLE_AND_CHAT_HISTORY:
case IM_LURE_USER:
case IM_LURE_ACCEPTED:
case IM_LURE_DECLINED:
case IM_GODLIKE_LURE_USER:
case IM_TELEPORT_REQUEST:
case IM_GROUP_ELECTION_DEPRECATED:
//IM_GOTO_URL
//IM_FROM_TASK_AS_ALERT
case IM_GROUP_NOTICE:
case IM_GROUP_NOTICE_INVENTORY_ACCEPTED:
case IM_GROUP_NOTICE_INVENTORY_DECLINED:
case IM_GROUP_INVITATION_ACCEPT:
case IM_GROUP_INVITATION_DECLINE:
case IM_GROUP_NOTICE_REQUESTED:
case IM_FRIENDSHIP_OFFERED:
case IM_FRIENDSHIP_ACCEPTED:
case IM_FRIENDSHIP_DECLINED_DEPRECATED:
//IM_TYPING_START
//IM_TYPING_STOP
return LLCacheName::cleanFullName(name);
default:
return name;
}
}
static std::string clean_name_from_task_im(const std::string& msg,
bool from_group)
{
boost::smatch match;
static const boost::regex returned_exp(
"(.*been returned to your inventory lost and found folder by )(.+)( (from|near).*)");
if (ll_regex_match(msg, match, returned_exp))
{
// match objects are 1-based for groups
std::string final = match[1].str();
std::string name = match[2].str();
// Don't try to clean up group names
if (!from_group)
{
final += LLCacheName::buildUsername(name);
}
final += match[3].str();
return final;
}
return msg;
}
const std::string NOT_ONLINE_MSG("User not online - message will be stored and delivered later.");
const std::string NOT_ONLINE_INVENTORY("User not online - inventory has been saved.");
void translate_if_needed(std::string& message)
{
if (message == NOT_ONLINE_MSG)
{
message = LLTrans::getString("not_online_msg");
}
else if (message == NOT_ONLINE_INVENTORY)
{
message = LLTrans::getString("not_online_inventory");
}
}
class LLPostponedIMSystemTipNotification : public LLPostponedNotification
{
protected:
/* virtual */
void modifyNotificationParams()
{
LLSD payload = mParams.payload;
payload["SESSION_NAME"] = mName;
mParams.payload = payload;
}
};
class LLPostponedOfferNotification : public LLPostponedNotification
{
protected:
/* virtual */
void modifyNotificationParams()
{
LLSD substitutions = mParams.substitutions;
substitutions["NAME"] = mName;
mParams.substitutions = substitutions;
}
};
void inventory_offer_handler(LLOfferInfo* info)
{
// If muted, don't even go through the messaging stuff. Just curtail the offer here.
// Passing in a null UUID handles the case of where you have muted one of your own objects by_name.
// The solution for STORM-1297 seems to handle the cases where the object is owned by someone else.
if (LLMuteList::getInstance()->isMuted(info->mFromID, info->mFromName) ||
LLMuteList::getInstance()->isMuted(LLUUID::null, info->mFromName))
{
info->forceResponse(IOR_MUTE);
return;
}
bool bAutoAccept(false);
// Strip any SLURL from the message display. (DEV-2754)
std::string msg = info->mDesc;
auto indx = msg.find(" ( http://slurl.com/secondlife/");
if (indx == std::string::npos)
{
// https
indx = msg.find(" ( https://slurl.com/secondlife/");
}
if (indx == std::string::npos)
{
// try to find new slurl http host
indx = msg.find(" ( http://maps.secondlife.com/secondlife/");
}
if (indx == std::string::npos)
{
// try to find new slurl https host
indx = msg.find(" ( https://maps.secondlife.com/secondlife/");
}
if (indx >= 0)
{
LLStringUtil::truncate(msg, indx);
}
// Avoid the Accept/Discard dialog if the user so desires.
if (gSavedSettings.getBOOL("AutoAcceptNewInventory")
&& ((!rlv_handler_t::isEnabled()) || (!RlvInventory::instance().isGiveToRLVOffer(*info))))
{
bAutoAccept = true;
// Archive parity: announce auto-accepted inventory in a toast.
if (info->mType != LLAssetType::AT_NOTECARD
&& info->mType != LLAssetType::AT_LANDMARK
&& info->mType != LLAssetType::AT_TEXTURE)
{
LLSD auto_accept_args;
auto_accept_args["NAME"] = LLSLURL(info->mFromGroup ? "group" : "agent", info->mFromID, "about").getSLURLString();
if (info->mFromObject)
{
auto_accept_args["ITEM"] = msg;
}
else
{
const std::string& verb = "select?name=" + LLURI::escape(msg);
auto_accept_args["ITEM"] = LLSLURL("inventory", info->mObjectID, verb.c_str()).getSLURLString();
}
LLNotificationsUtil::add("AutoAcceptedInventory", auto_accept_args);
}
}
LLSD args;
args["[OBJECTNAME]"] = msg;
LLSD payload;
// must protect against a NULL return from lookupHumanReadable()
std::string typestr = ll_safe_string(LLAssetType::lookupHumanReadable(info->mType));
if (!typestr.empty())
{
// human readable matches string name from strings.xml
// lets get asset type localized name
args["OBJECTTYPE"] = LLTrans::getString(typestr);
}
else
{
LL_WARNS("Messaging") << "LLAssetType::lookupHumanReadable() returned NULL - probably bad asset type: " << info->mType << LL_ENDL;
args["OBJECTTYPE"] = "";
// This seems safest, rather than propagating bogosity
LL_WARNS("Messaging") << "Forcing an inventory-decline for probably-bad asset type." << LL_ENDL;
info->forceResponse(IOR_DECLINE);
return;
}
// If mObjectID is null then generate the object_id based on msg to prevent
// multiple creation of chiclets for same object.
LLUUID object_id = info->mObjectID;
if (object_id.isNull())
object_id.generate(msg);
payload["from_id"] = info->mFromID;
// Needed by LLScriptFloaterManager to bind original notification with
// faked for toast one.
payload["object_id"] = object_id;
// Flag indicating that this notification is faked for toast.
payload["give_inventory_notification"] = false;
args["OBJECTFROMNAME"] = info->mFromName;
args["NAME"] = info->mFromName;
if (info->mFromGroup)
{
args["NAME_SLURL"] = LLSLURL("group", info->mFromID, "about").getSLURLString();
}
else
{
// [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
args["NAME_LABEL"] = LLSLURL("agent", info->mFromID, "completename").getSLURLString();
// [/SL:KB]
args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "about").getSLURLString();
}
std::string verb = "select?name=" + LLURI::escape(msg);
args["ITEM_SLURL"] = LLSLURL("inventory", info->mObjectID, verb.c_str()).getSLURLString();
LLNotification::Params p;
// Object -> Agent Inventory Offer
if (info->mFromObject && !bAutoAccept)
{
// [RLVa:KB] - Checked: RLVa-1.2.2
// Only filter if the object owner is a nearby agent
if ( (RlvActions::isRlvEnabled()) && (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, info->mFromID)) && (RlvUtil::isNearbyAgent(info->mFromID)) )
{
payload["rlv_shownames"] = true;
args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "rlvanonym").getSLURLString();
}
// [/RLVa:KB]
// Inventory Slurls don't currently work for non agent transfers, so only display the object name.
args["ITEM_SLURL"] = msg;
// Note: sets inventory_task_offer_callback as the callback
p.substitutions(args).payload(payload).functor.responder(LLNotificationResponderPtr(info));
info->mPersist = true;
// Offers from your own objects need a special notification template.
p.name = info->mFromID == gAgentID ? "OwnObjectGiveItem" : "ObjectGiveItem";
// Pop up inv offer chiclet and let the user accept (keep), or reject (and silently delete) the inventory.
LLPostponedNotification::add<LLPostponedOfferNotification>(p, info->mFromID, info->mFromGroup);
}
else // Agent -> Agent Inventory Offer
{
// [RLVa:KB] - Checked: RLVa-2.0.1
// Only filter if the offer is from a nearby agent and if there's no open IM session (doesn't necessarily have to be focused)
bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
(RlvActions::canShowName(RlvActions::SNC_DEFAULT, info->mFromID)) || (!RlvUtil::isNearbyAgent(info->mFromID)) || (RlvUIEnabler::hasOpenIM(info->mFromID)) || (RlvUIEnabler::hasOpenProfile(info->mFromID));
if (!fRlvCanShowName)
{
payload["rlv_shownames"] = true;
args["NAME"] = RlvStrings::getAnonym(info->mFromName);
args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "rlvanonym").getSLURLString();
}
// [/RLVa:KB]
p.responder = info;
// Note: sets inventory_offer_callback as the callback
// *TODO fix memory leak
// inventory_offer_callback() is not invoked if user received notification and
// closes viewer(without responding the notification)
p.substitutions(args).payload(payload).functor.responder(LLNotificationResponderPtr(info));
info->mPersist = true;
p.name = "UserGiveItem";
p.offer_from_agent = true;
// Prefetch the item into your local inventory.
LLInventoryFetchItemsObserver* fetch_item = new LLInventoryFetchItemsObserver(info->mObjectID);
fetch_item->startFetch();
if (fetch_item->isFinished())
{
fetch_item->done();
}
else
{
gInventory.addObserver(fetch_item);
}
// In viewer 2 we're now auto receiving inventory offers and messaging as such (not sending reject messages).
info->send_auto_receive_response();
if (gAgent.isDoNotDisturb())
{
send_do_not_disturb_message(gMessageSystem, info->mFromID);
}
if (!bAutoAccept) // if we auto accept, do not pester the user
{
// Inform user that there is a script floater via toast system
payload["give_inventory_notification"] = true;
p.payload = payload;
LLPostponedNotification::add<LLPostponedOfferNotification>(p, info->mFromID, false);
}
if (bAutoAccept && gSavedSettings.getBOOL("ShowNewInventory"))
{
LLViewerInventoryCategory* catp = nullptr;
catp = (LLViewerInventoryCategory*)gInventory.getCategory(info->mObjectID);
LLViewerInventoryItem* itemp = nullptr;
if (!catp)
{
itemp = (LLViewerInventoryItem*)gInventory.getItem(info->mObjectID);
}
LLOpenAgentOffer* open_agent_offer = new LLOpenAgentOffer(info->mObjectID, info->mFromName, false);
open_agent_offer->startFetch();
if (catp || (itemp && itemp->isFinished()))
{
open_agent_offer->done();
}
else
{
gInventory.addObserver(open_agent_offer);
}
}
}
LLFirstUse::newInventory();
}
// Callback for name resolution of a god/estate message
static void god_message_name_cb(const LLAvatarName& av_name, LLChat chat, std::string message)
{
LLSD args;
args["NAME"] = av_name.getCompleteName();
args["MESSAGE"] = message;
LLNotificationsUtil::add("GodMessage", args);
// Treat like a system message and put in chat history.
chat.mSourceType = CHAT_SOURCE_SYSTEM;
chat.mText = message;
LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
if (nearby_chat)
{
nearby_chat->addMessage(chat);
}
}
static bool parse_lure_bucket(const std::string& bucket,
U64& region_handle,
LLVector3& pos,
LLVector3& look_at,
U8& region_access)
{
// tokenize the bucket
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
tokenizer tokens(bucket, sep);
tokenizer::iterator iter = tokens.begin();
S32 gx, gy, rx, ry, rz, lx, ly, lz;
try
{
gx = boost::lexical_cast<S32>((*(iter)).c_str());
gy = boost::lexical_cast<S32>((*(++iter)).c_str());
rx = boost::lexical_cast<S32>((*(++iter)).c_str());
ry = boost::lexical_cast<S32>((*(++iter)).c_str());
rz = boost::lexical_cast<S32>((*(++iter)).c_str());
lx = boost::lexical_cast<S32>((*(++iter)).c_str());
ly = boost::lexical_cast<S32>((*(++iter)).c_str());
lz = boost::lexical_cast<S32>((*(++iter)).c_str());
}
catch (boost::bad_lexical_cast&)
{
LL_WARNS("parse_lure_bucket")
<< "Couldn't parse lure bucket."
<< LL_ENDL;
return false;
}
// Grab region access
region_access = SIM_ACCESS_MIN;
if (++iter != tokens.end())
{
std::string access_str((*iter).c_str());
LLStringUtil::trim(access_str);
if (access_str == "A")
{
region_access = SIM_ACCESS_ADULT;
}
else if (access_str == "M")
{
region_access = SIM_ACCESS_MATURE;
}
else if (access_str == "PG")
{
region_access = SIM_ACCESS_PG;
}
}
pos.setVec((F32)rx, (F32)ry, (F32)rz);
look_at.setVec((F32)lx, (F32)ly, (F32)lz);
region_handle = to_region_handle(gx, gy);
return true;
}
static void notification_display_name_callback(const LLUUID& id,
const LLAvatarName& av_name,
const std::string& name,
LLSD& substitutions,
const LLSD& payload)
{
substitutions["NAME"] = av_name.getDisplayName();
LLNotificationsUtil::add(name, substitutions, payload);
}
void LLIMProcessing::processNewMessage(LLUUID from_id,
bool from_group,
LLUUID to_id,
U8 offline,
EInstantMessage dialog, // U8
LLUUID session_id,
U32 timestamp,
std::string agentName,
std::string message,
U32 parent_estate_id,
LLUUID region_id,
LLVector3 position,
U8 *binary_bucket,
S32 binary_bucket_size,
LLHost &sender,
LLSD metadata,
LLUUID aux_id)
{
LLChat chat;
std::string buffer;
std::string name = agentName;
// make sure that we don't have an empty or all-whitespace name
LLStringUtil::trim(name);
static const LLCachedControl<bool> sMarkUnnamedObjects(gSavedSettings, "AlchemyChatMarkUnnamedObjects", true);
if (sMarkUnnamedObjects && name.empty())
{
name = LLTrans::getString("Unnamed");
}
// Preserve the unaltered name for use in group notice mute checking.
std::string original_name = name;
// IDEVO convert new-style "Resident" names for display
name = clean_name_from_im(name, dialog);
bool is_do_not_disturb = gAgent.isDoNotDisturb();
// NOTE: Not set on this
// *TODO*: Revisit this
// -- Fallen
static LLCachedControl<bool> AlchemyRejectTeleportOffers(gSavedPerAccountSettings, "ALRejectTeleportOffersMode");
static LLCachedControl<bool> AlchemyDontRejectTeleportOffersFromFriends(gSavedPerAccountSettings, "ALDontRejectTeleportOffersFromFriends");
static LLCachedControl<bool> AlchemyRejectFriendshipRequests(gSavedPerAccountSettings, "ALRejectFriendshipRequestsMode");
// Resurrect AutoResponse from Alchemy Archive (Thanks Cinders!)
// -- Fallen
static LLCachedControl<bool> sAutorespond(gSavedPerAccountSettings, "AlchemyAutoresponseEnable");
static LLCachedControl<bool> sAutorespondNonFriend(gSavedPerAccountSettings, "AlchemyAutoresponseNotFriendEnable");
bool is_muted = LLMuteList::getInstance()->isMuted(from_id, name, LLMute::flagTextChat)
// object IMs contain sender object id in session_id (STORM-1209)
|| (dialog == IM_FROM_TASK && LLMuteList::getInstance()->isMuted(session_id));
bool is_owned_by_me = false;
bool is_friend = LLAvatarTracker::instance().getBuddyInfo(from_id) != NULL;
bool accept_im_from_only_friend = gSavedPerAccountSettings.getBOOL("VoiceCallsFriendsOnly");
bool is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
LLMuteList::isLinden(name);
/***
* The simulator may have flagged this sender as a bot, if the viewer would like to display
* the chat text in a different color or font, the below code is how the viewer can
* tell if the sender is a bot.
*-----------------------------------------------------
bool is_bot = false;
if (metadata.has("sender"))
{ // The server has identified this sender as a bot.
is_bot = metadata["sender"]["bot"].asBoolean();
}
*-----------------------------------------------------
*/
std::string notice_name;
LLSD notice_args;
if (metadata.has("notice"))
{ // The server has injected a notice into the IM conversation.
// These will be things like bot notifications, etc.
notice_name = metadata["notice"]["id"].asString();
notice_args = metadata["notice"]["data"];
}
chat.mMuted = is_muted;
chat.mFromID = from_id;
chat.mFromName = name;
chat.mSourceType = (from_id.isNull() || (name == std::string(SYSTEM_FROM))) ? CHAT_SOURCE_SYSTEM : CHAT_SOURCE_AGENT;
if (chat.mSourceType == CHAT_SOURCE_SYSTEM)
{ // Translate server message if required (MAINT-6109)
translate_if_needed(message);
}
LLViewerObject *source = gObjectList.findObject(session_id); //Session ID is probably the wrong thing.
if (source)
{
is_owned_by_me = source->permYouOwner();
}
std::string separator_string(": ");
LLSD args;
LLSD payload;
LLNotification::Params params;
switch (dialog)
{
case IM_CONSOLE_AND_CHAT_HISTORY:
args["MESSAGE"] = message;
payload["from_id"] = from_id;
params.name = "IMSystemMessageTip";
params.substitutions = args;
params.payload = payload;
LLPostponedNotification::add<LLPostponedIMSystemTipNotification>(params, from_id, false);
break;
case IM_NOTHING_SPECIAL: // p2p IM
// Don't show dialog, just do IM
if (!gAgent.isGodlike()
&& gAgent.inPrelude()
&& to_id.isNull())
{
// do nothing -- don't distract newbies in
// Prelude with global IMs
}
// [RLVa:KB] - Checked: RLVa-2.1.0
else if ( (RlvActions::isRlvEnabled()) && (offline == IM_ONLINE) && (!is_muted) && ((!accept_im_from_only_friend) || (is_friend)) &&
(message.length() > 3) && (RLV_CMD_PREFIX == message[0]) && (RlvHandler::instance().processIMQuery(from_id, message)) )
{
// Eat the message and do nothing
}
// [/RLVa:KB]
// else if (offline == IM_ONLINE
// && is_do_not_disturb
// && from_id.notNull() //not a system message
// && to_id.notNull()) //not global message
// [RLVa:KB] - Checked: 2010-11-30 (RLVa-1.3.0)
else if (offline == IM_ONLINE
&& is_do_not_disturb
&& from_id.notNull() //not a system message
&& to_id.notNull() //not global message
&& RlvActions::canReceiveIM(from_id))
// [/RLVa:KB]
{
// now store incoming IM in chat history
buffer = message;
LL_DEBUGS("Messaging") << "session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
// add to IM panel, but do not bother the user
gIMMgr->addMessage(
session_id,
from_id,
name,
buffer,
IM_OFFLINE == offline,
LLStringUtil::null,
dialog,
parent_estate_id,
region_id,
position,
false, // is_region_msg
timestamp);
if (!gIMMgr->isDNDMessageSend(session_id))
{
// return a standard "do not disturb" message, but only do it to online IM
// (i.e. not other auto responses and not store-and-forward IM)
send_do_not_disturb_message(gMessageSystem, from_id, session_id);
gIMMgr->setDNDMessageSent(session_id, true);
}
}
else if (offline == IM_ONLINE
&& (sAutorespond || (sAutorespondNonFriend && !is_friend))
&& from_id.notNull() //not a system message
&& to_id.notNull()) //not global message
{
buffer = message;
LL_DEBUGS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
bool send_response = !gIMMgr->hasSession(session_id);
gIMMgr->addMessage(session_id,
from_id,
name,
buffer,
IM_OFFLINE == offline,
LLStringUtil::null,
dialog,
parent_estate_id,
region_id,
position,
true);
if (send_response)
{
std::string my_name;
LLAgentUI::buildFullname(my_name);
std::string response = gSavedPerAccountSettings.getString(sAutorespondNonFriend && !is_friend
? "AlchemyAutoresponseNotFriend"
: "AlchemyAutoresponse");
response = replace_wildcards(response, from_id, name);
pack_instant_message(
gMessageSystem,
gAgent.getID(),
false,
gAgent.getSessionID(),
from_id,
my_name,
response,
IM_ONLINE,
IM_DO_NOT_DISTURB_AUTO_RESPONSE,
session_id);
gAgent.sendReliableMessage();
gIMMgr->addMessage(session_id, gAgent.getID(), my_name, LLTrans::getString("AutoresponsePrefix").append(response));
}
}
else if (from_id.isNull())
{
LLSD args;
args["MESSAGE"] = message;
LLNotificationsUtil::add("SystemMessage", args);
}
else if (to_id.isNull())
{
// Message to everyone from GOD, look up the fullname since
// server always slams name to legacy names
LLAvatarNameCache::get(from_id, boost::bind(god_message_name_cb, _2, chat, message));
}
else
{
// standard message, server may have injected a notice into the conversation.
std::string saved;
if (offline == IM_OFFLINE)
{
LLStringUtil::format_map_t args;
args["[LONG_TIMESTAMP]"] = formatted_time(timestamp);
saved = LLTrans::getString("Saved_message", args);
}
buffer = saved + message;
LL_DEBUGS("Messaging") << "session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
bool mute_im = is_muted;
if (accept_im_from_only_friend && !is_friend && !is_linden)
{
if (!gIMMgr->isNonFriendSessionNotified(session_id))
{
std::string message = LLTrans::getString("IM_unblock_only_groups_friends");
gIMMgr->addMessage(session_id, from_id, name, message, IM_OFFLINE == offline);
gIMMgr->addNotifiedNonFriendSessionID(session_id);
}
mute_im = true;
}
// [RLVa:KB] - Checked: 2010-11-30 (RLVa-1.3.0)
// Don't block offline IMs, or IMs from Lindens
if ( (rlv_handler_t::isEnabled()) && (offline != IM_OFFLINE) && (!RlvActions::canReceiveIM(from_id)) && (!LLMuteList::getInstance()->isLinden(original_name) ))
{
if (!mute_im)
RlvUtil::sendBusyMessage(from_id, RlvStrings::getString(RlvStringKeys::Blocked::RecvImRemote), session_id);
buffer = RlvStrings::getString(RlvStringKeys::Blocked::RecvIm);
}
// [/RLVa:KB]
if (!mute_im)
{
bool region_message = false;
if (region_id.isNull())
{
LLViewerRegion* regionp = LLWorld::instance().getRegionFromID(from_id);
if (regionp)
{
region_message = true;
}
}
std::string real_name;
if (!notice_name.empty())
{ // The simulator has injected some sort of notice into the conversation.
// findString will only replace the contents of buffer if the notice_id is found.
LLTrans::findString(buffer, notice_name, notice_args);
real_name = SYSTEM_FROM;
}
gIMMgr->addMessage(session_id,
from_id,
name,
buffer,
IM_OFFLINE == offline,
LLStringUtil::null,
dialog,
parent_estate_id,
region_id,
position,
region_message,
timestamp,
LLUUID::null,
real_name);
}
else
{
/*
EXT-5099
*/
}
}
break;
case IM_TYPING_START:
{
static LLCachedControl<bool> sNotifyIncomingMessage(gSavedSettings, "AlchemyNotifyIncomingMessage");
if (sNotifyIncomingMessage &&
!gIMMgr->hasSession(session_id) &&
((accept_im_from_only_friend && (is_friend || is_linden)) ||
(!(is_muted || is_do_not_disturb)))
)
{
LLStringUtil::format_map_t args;
args["[NAME]"] = name;
const std::string notify_str = LLTrans::getString("NotifyIncomingMessage", args);
gIMMgr->addMessage(session_id,
from_id,
LLStringUtil::null,
notify_str,
IM_ONLINE,
LLStringUtil::null,
IM_NOTHING_SPECIAL,
parent_estate_id,
region_id,
position,
false,
0
);
}
gIMMgr->processIMTypingStart(from_id, dialog);
}
break;
case IM_TYPING_STOP:
{
gIMMgr->processIMTypingStop(from_id, dialog);
}
break;
case IM_MESSAGEBOX:
{
// This is a block, modeless dialog.
args["MESSAGE"] = message;
LLNotificationsUtil::add("SystemMessageTip", args);
}
break;
case IM_GROUP_NOTICE:
case IM_GROUP_NOTICE_REQUESTED:
{
LL_INFOS("Messaging") << "Received IM_GROUP_NOTICE message." << LL_ENDL;
LLUUID agent_id;
U8 has_inventory;
U8 asset_type = 0;
LLUUID group_id;
std::string item_name;
if (aux_id.notNull())
{
// aux_id contains group id, binary bucket contains name and asset type
group_id = aux_id;
has_inventory = binary_bucket_size > 1;
from_group = true; // inaccurate value correction
if (has_inventory)
{
std::string str_bucket = ll_safe_string((char*)binary_bucket, binary_bucket_size);
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
tokenizer tokens(str_bucket, sep);
tokenizer::iterator iter = tokens.begin();
asset_type = (LLAssetType::EType)(atoi((*(iter++)).c_str()));
iter++; // wearable type if applicable, otherwise asset type
item_name = std::string((*(iter++)).c_str());
}
}
else
{
// All info is in binary bucket, read it for more information.
struct notice_bucket_header_t
{
U8 has_inventory;
U8 asset_type;
LLUUID group_id;
};
struct notice_bucket_full_t
{
struct notice_bucket_header_t header;
U8 item_name[DB_INV_ITEM_NAME_BUF_SIZE];
}*notice_bin_bucket;
// Make sure the binary bucket is big enough to hold the header
// and a null terminated item name.
if ((binary_bucket_size < (S32)((sizeof(notice_bucket_header_t) + sizeof(U8))))
|| (binary_bucket[binary_bucket_size - 1] != '\0'))
{
LL_WARNS("Messaging") << "Malformed group notice binary bucket" << LL_ENDL;
break;
}
notice_bin_bucket = (struct notice_bucket_full_t*) &binary_bucket[0];
has_inventory = notice_bin_bucket->header.has_inventory;
asset_type = notice_bin_bucket->header.asset_type;
group_id = notice_bin_bucket->header.group_id;
item_name = ll_safe_string((const char*)notice_bin_bucket->item_name);
}
if (group_id != from_id)
{
agent_id = from_id;
}
else
{
auto index = original_name.find(" Resident");
if (index != std::string::npos)
{
original_name = original_name.substr(0, index);
}
// The group notice packet does not have an AgentID. Obtain one from the name cache.
// If last name is "Resident" strip it out so the cache name lookup works.
std::string legacy_name = gCacheName->buildLegacyName(original_name);
agent_id = LLAvatarNameCache::getInstance()->findIdByName(legacy_name);
if (agent_id.isNull())
{
LL_WARNS("Messaging") << "buildLegacyName returned null while processing " << original_name << LL_ENDL;
}
}
if (agent_id.notNull() && LLMuteList::getInstance()->isMuted(agent_id))
{
break;
}
// If there is inventory, give the user the inventory offer.
LLOfferInfo* info = NULL;
if (has_inventory)
{
info = new LLOfferInfo();
info->mIM = dialog;
info->mFromID = from_id;
info->mFromGroup = from_group;
info->mTransactionID = session_id;
info->mType = (LLAssetType::EType) asset_type;
info->mFolderID = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(info->mType));
std::string from_name;
from_name += "A group member named ";
from_name += name;
info->mFromName = from_name;
info->mDesc = item_name;
info->mHost = sender;
}
std::string str(message);
// Tokenize the string.
// TODO: Support escaped tokens ("||" -> "|")
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
tokenizer tokens(str, sep);
tokenizer::iterator iter = tokens.begin();
std::string subj(*iter++);
std::string mes(*iter++);
// Send the notification down the new path.
// For requested notices, we don't want to send the popups.
if (dialog != IM_GROUP_NOTICE_REQUESTED)
{
payload["subject"] = subj;
payload["message"] = mes;
payload["sender_name"] = name;
payload["sender_id"] = agent_id;
payload["group_id"] = group_id;
payload["inventory_name"] = item_name;
payload["received_time"] = LLDate::now();
if (info && info->asLLSD())
{
payload["inventory_offer"] = info->asLLSD();
}