aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/rlvhelper.h
diff options
context:
space:
mode:
authorMcCabe Maxsted2009-10-18 17:58:27 -0700
committerMcCabe Maxsted2009-10-18 17:58:27 -0700
commite4b0e7c82d670081c071d8a3da31b5ec407b8e07 (patch)
tree9410962bbb582eedbec448139e217f2714050777 /linden/indra/newview/rlvhelper.h
parentStarted 1.3.0 branch (diff)
parentUpdated and added some Linux libs. (diff)
downloadmeta-impy-e4b0e7c82d670081c071d8a3da31b5ec407b8e07.zip
meta-impy-e4b0e7c82d670081c071d8a3da31b5ec407b8e07.tar.gz
meta-impy-e4b0e7c82d670081c071d8a3da31b5ec407b8e07.tar.bz2
meta-impy-e4b0e7c82d670081c071d8a3da31b5ec407b8e07.tar.xz
Merged working branch of 1.2 into LL 1.23 merge
Diffstat (limited to 'linden/indra/newview/rlvhelper.h')
-rw-r--r--linden/indra/newview/rlvhelper.h416
1 files changed, 416 insertions, 0 deletions
diff --git a/linden/indra/newview/rlvhelper.h b/linden/indra/newview/rlvhelper.h
new file mode 100644
index 0000000..42d10b8
--- /dev/null
+++ b/linden/indra/newview/rlvhelper.h
@@ -0,0 +1,416 @@
1#ifndef RLV_HELPER_H
2#define RLV_HELPER_H
3
4#include "llboost.h"
5#include "llinventorymodel.h"
6#include "llselectmgr.h"
7#include "llviewercontrol.h"
8#include "llviewerobjectlist.h"
9#include "llwlparamset.h"
10#include "rlvdefines.h"
11
12#ifdef LL_WINDOWS
13 #pragma warning (push)
14 #pragma warning (disable : 4702) // warning C4702: unreachable code
15#endif
16#include <boost/variant.hpp>
17#ifdef LL_WINDOWS
18 #pragma warning (pop)
19#endif
20
21// ============================================================================
22// RlvCommand
23//
24
25class RlvCommand
26{
27public:
28 explicit RlvCommand(const std::string& strCommand);
29
30 /*
31 * Member functions
32 */
33public:
34 std::string asString() const;
35 const std::string& getBehaviour() const { return m_strBehaviour; }
36 ERlvBehaviour getBehaviourType() const { return m_eBehaviour; }
37 const std::string& getOption() const { return m_strOption; }
38 const std::string& getParam() const { return m_strParam; }
39 ERlvParamType getParamType() const { return m_eParamType; }
40 bool isStrict() const { return m_fStrict; }
41 bool isValid() const { return m_fValid; }
42
43 static ERlvBehaviour getBehaviourFromString(const std::string& strBhvr);
44 static const std::string& getStringFromBehaviour(ERlvBehaviour eBhvr);
45 static bool hasStrictVariant(ERlvBehaviour eBhvr);
46
47 static void initLookupTable();
48protected:
49 static bool parseCommand(const std::string& strCommand, std::string& strBehaviour, std::string& strOption, std::string& strParam);
50
51 /*
52 * Operators
53 */
54public:
55 bool operator ==(const RlvCommand&) const;
56
57 /*
58 * Member variables
59 */
60protected:
61 bool m_fValid;
62 std::string m_strBehaviour;
63 ERlvBehaviour m_eBehaviour;
64 bool m_fStrict;
65 std::string m_strOption;
66 std::string m_strParam;
67 ERlvParamType m_eParamType;
68
69 typedef std::map<std::string, ERlvBehaviour> RlvBhvrTable;
70 static RlvBhvrTable m_BhvrMap;
71
72 friend class RlvHandler;
73};
74typedef std::list<RlvCommand> rlv_command_list_t;
75
76// ============================================================================
77// RlvObject
78//
79
80class RlvObject
81{
82public:
83 RlvObject(const LLUUID& idObj);
84
85 /*
86 * Member functions
87 */
88public:
89 bool addCommand(const RlvCommand& rlvCmd);
90 bool removeCommand(const RlvCommand& rlvCmd);
91
92 std::string getStatusString(const std::string& strMatch) const;
93 bool hasBehaviour(ERlvBehaviour eBehaviour, bool fStrictOnly) const;
94 bool hasBehaviour(ERlvBehaviour eBehaviour, const std::string& strOption, bool fStrictOnly) const;
95
96 const rlv_command_list_t* getCommandList() const { return &m_Commands; }
97
98 /*
99 * Member variables
100 */
101protected:
102 LLUUID m_UUID; // The object's UUID
103 S32 m_idxAttachPt; // The object's attachment point (or 0 if it's not an attachment)
104 bool m_fLookup; // TRUE if the object existed in gObjectList at one point in time
105 S16 m_nLookupMisses; // Count of unsuccessful lookups in gObjectList by the GC
106 rlv_command_list_t m_Commands; // List of behaviours held by this object (in the order they were received)
107
108 friend class RlvHandler;
109};
110
111// ============================================================================
112// RlvCriteriaCategoryCollector - Criteria based folder matching filter used by @findfolder and @findfolders
113//
114
115class RlvCriteriaCategoryCollector : public LLInventoryCollectFunctor
116{
117public:
118 RlvCriteriaCategoryCollector(const std::string& strCriteria)
119 {
120 std::string::size_type idxIt, idxLast = 0;
121 while (idxLast < strCriteria.length())
122 {
123 idxIt = strCriteria.find("&&", idxLast);
124 if (std::string::npos == idxIt)
125 idxIt = strCriteria.length();
126 if (idxIt != idxLast)
127 m_Criteria.push_back(strCriteria.substr(idxLast, idxIt - idxLast));
128 idxLast = idxIt + 2;
129 }
130 }
131 virtual ~RlvCriteriaCategoryCollector() {}
132
133 virtual bool operator()(LLInventoryCategory* pFolder, LLInventoryItem* pItem)
134 {
135 if ( (!pFolder) || (m_Criteria.empty()) ) // We're only interested in matching folders, we don't care about items
136 return false; // (if there are no criteria then we don't want to return a match)
137
138 std::string strFolderName = pFolder->getName();
139 LLStringUtil::toLower(strFolderName);
140
141 if ( (strFolderName.empty()) || (RLV_FOLDER_PREFIX_HIDDEN == strFolderName[0]) )
142 return false;
143
144 for (std::list<std::string>::const_iterator itCrit = m_Criteria.begin(); itCrit != m_Criteria.end(); ++itCrit)
145 if (std::string::npos == strFolderName.find(*itCrit)) // Return false on the first mismatch
146 return false;
147 return true;
148 }
149
150protected:
151 std::list<std::string> m_Criteria;
152};
153
154// ============================================================================
155// RlvWearableItemCollector - Inventory item filter used by attach/detach/attachall/detachall/getinvworn
156//
157
158class RlvWearableItemCollector : public LLInventoryCollectFunctor
159{
160public:
161 RlvWearableItemCollector(const LLUUID& idFolder, bool fAttach, bool fMatchAll)
162 : m_idFolder(idFolder), m_fAttach(fAttach), m_fMatchAll(fMatchAll)
163 {
164 m_Wearable.push_back(idFolder);
165 }
166 virtual ~RlvWearableItemCollector() {}
167
168 virtual bool operator()(LLInventoryCategory* pFolder, LLInventoryItem* pItem);
169
170 const LLUUID& getFoldedParent(const LLUUID& idFolder) const;
171protected:
172 bool m_fAttach;
173 bool m_fMatchAll;
174 const LLUUID m_idFolder;
175
176 bool onCollectFolder(const LLInventoryCategory* pFolder);
177 bool onCollectItem(const LLInventoryItem* pItem);
178
179 std::list<LLUUID> m_Tentative;
180 std::list<LLUUID> m_Wearable;
181
182 std::map<LLUUID, LLUUID> m_Folding;
183};
184
185// ============================================================================
186// RlvRetainedCommand
187//
188
189struct RlvRetainedCommand
190{
191public:
192 std::string strObject;
193 LLUUID idObject;
194 std::string strCmd;
195
196 RlvRetainedCommand(const std::string obj, const LLUUID& uuid, const std::string& cmd) : strObject(obj), idObject(uuid), strCmd(cmd) {}
197private:
198 RlvRetainedCommand();
199};
200typedef std::list<RlvRetainedCommand> rlv_retained_list_t;
201
202// ============================================================================
203// RlvException
204//
205
206typedef boost::variant<std::string, LLUUID, S32, ERlvBehaviour> RlvExceptionOption;
207
208struct RlvException
209{
210public:
211 LLUUID idObject; // UUID of the object that added the exception
212 ERlvBehaviour eBehaviour; // Behaviour the exception applies to
213 RlvExceptionOption varOption; // Exception data (type is dependent on eBehaviour)
214
215 RlvException(const LLUUID& idObj, ERlvBehaviour eBhvr, const RlvExceptionOption& option) : idObject(idObj), eBehaviour(eBhvr), varOption(option) {}
216private:
217 RlvException();
218};
219
220// ============================================================================
221// RlvWLSnapshot
222//
223
224struct RlvWLSnapshot
225{
226public:
227 static void restoreSnapshot(const RlvWLSnapshot* pWLSnapshot);
228 static RlvWLSnapshot* takeSnapshot();
229private:
230 RlvWLSnapshot() {}
231
232 bool fIsRunning;
233 bool fUseLindenTime;
234 LLWLParamSet WLParams;
235};
236
237// ============================================================================
238// RlvSettings
239//
240
241inline BOOL rlvGetSettingBOOL(const std::string& strSetting, BOOL fDefault)
242{
243 return (gSavedSettings.controlExists(strSetting)) ? gSavedSettings.getBOOL(strSetting) : fDefault;
244}
245inline BOOL rlvGetPerUserSettingsBOOL(const std::string& strSetting, BOOL fDefault)
246{
247 return (gSavedPerAccountSettings.controlExists(strSetting)) ? gSavedPerAccountSettings.getBOOL(strSetting) : fDefault;
248}
249
250class RlvSettings
251{
252public:
253 static BOOL getDebug() { return rlvGetSettingBOOL(RLV_SETTING_DEBUG, FALSE); }
254 static BOOL getForbidGiveToRLV() { return rlvGetSettingBOOL(RLV_SETTING_FORBIDGIVETORLV, TRUE); }
255
256 static BOOL getEnableWear();
257 static BOOL getHideLockedLayers() { return rlvGetSettingBOOL(RLV_SETTING_HIDELOCKEDLAYER, FALSE); }
258 static BOOL getHideLockedAttach() { return rlvGetSettingBOOL(RLV_SETTING_HIDELOCKEDATTACH, FALSE); }
259 static BOOL getHideLockedInventory() { return rlvGetSettingBOOL(RLV_SETTING_HIDELOCKEDINVENTORY, FALSE); }
260 static BOOL getShowNameTags() { return fShowNameTags; }
261
262 #ifdef RLV_EXTENSION_STARTLOCATION
263 static BOOL getLoginLastLocation() { return rlvGetPerUserSettingsBOOL(RLV_SETTING_LOGINLASTLOCATION, TRUE); }
264 static void updateLoginLastLocation();
265 #endif // RLV_EXTENSION_STARTLOCATION
266
267 static BOOL fShowNameTags;
268};
269
270// ============================================================================
271// State keeping classes/structure
272//
273
274// ============================================================================
275// Various helper classes/timers/functors
276//
277
278class RlvGCTimer : public LLEventTimer
279{
280public:
281 RlvGCTimer() : LLEventTimer(30.0) {}
282 virtual BOOL tick();
283};
284
285class RlvCurrentlyWorn : public LLInventoryFetchObserver
286{
287public:
288 RlvCurrentlyWorn() {}
289 ~RlvCurrentlyWorn() {}
290 virtual void done() {}
291
292 static void fetchWorn();
293 void fetchItem(const LLUUID& idItem);
294};
295
296struct RlvSelectHasLockedAttach : public LLSelectedNodeFunctor
297{
298 virtual bool apply(LLSelectNode* pNode);
299};
300
301struct RlvSelectIsOwnedByOrGroupOwned : public LLSelectedNodeFunctor
302{
303 RlvSelectIsOwnedByOrGroupOwned(const LLUUID& uuid) : m_idAgent(uuid) {}
304 virtual bool apply(LLSelectNode* pNode);
305 LLUUID m_idAgent;
306};
307
308struct RlvSelectIsSittingOn : public LLSelectedNodeFunctor
309{
310 RlvSelectIsSittingOn(LLXform* pObject) : m_pObject(pObject) {}
311 virtual bool apply(LLSelectNode* pNode);
312 LLXform* m_pObject;
313};
314
315// ============================================================================
316// Various helper functions
317//
318
319BOOL rlvAttachToEnabler(void* pParam);
320bool rlvCanDeleteOrReturn();
321BOOL rlvEnableWearEnabler(void* pParam);
322S32 rlvGetDirectDescendentsCount(const LLInventoryCategory* pFolder, LLAssetType::EType type);
323bool rlvIsEmote(const std::string& strUTF8Text);
324bool rlvIsValidReplyChannel(S32 nChannel);
325bool rlvIsWearingItem(const LLInventoryItem* pItem);
326
327void rlvForceDetach(LLViewerJointAttachment* pAttachPt);
328void rlvSendBusyMessage(const LLUUID& idTo, const std::string& strMsg, const LLUUID& idSession = LLUUID::null);
329bool rlvSendChatReply(const std::string& strChannel, const std::string& strReply);
330bool rlvSendChatReply(S32 nChannel, const std::string& strReply);
331
332std::string rlvGetFirstParenthesisedText(const std::string& strText, std::string::size_type* pidxMatch = NULL);
333std::string rlvGetLastParenthesisedText(const std::string& strText, std::string::size_type* pidxStart = NULL);
334void rlvStringReplace(std::string& strText, std::string strFrom, const std::string& strTo);
335
336#ifdef RLV_ADVANCED_TOGGLE_RLVA
337 // "Advanced / RLVa / Enable RLV" menu option
338 void rlvToggleEnabled(void*);
339 BOOL rlvGetEnabled(void*);
340#endif // RLV_ADVANCED_TOGGLE_RLVA
341
342// ============================================================================
343// Debug helper functions
344//
345
346// ============================================================================
347// Inlined class member functions
348//
349
350// Checked: 2009-09-19 (RLVa-1.0.3d)
351inline std::string RlvCommand::asString() const
352{
353 // NOTE: @clear=<param> should be represented as clear:<param>
354 return (m_eParamType != RLV_TYPE_CLEAR)
355 ? (!m_strOption.empty()) ? (std::string(m_strBehaviour)).append(":").append(m_strOption) : (std::string(m_strBehaviour))
356 : (!m_strParam.empty()) ? (std::string(m_strBehaviour)).append(":").append(m_strParam) : (std::string(m_strBehaviour));
357}
358
359inline bool RlvCommand::operator ==(const RlvCommand& rhs) const
360{
361 // The specification notes that "@detach=n" is semantically identical to "@detach=add" (same for "y" and "rem"
362 return (m_strBehaviour == rhs.m_strBehaviour) && (m_strOption == rhs.m_strOption) &&
363 ( (RLV_TYPE_UNKNOWN != m_eParamType) ? (m_eParamType == rhs.m_eParamType) : (m_strParam == rhs.m_strParam) );
364}
365
366inline void RlvCurrentlyWorn::fetchItem(const LLUUID& idItem)
367{
368 if (idItem.notNull())
369 {
370 LLInventoryFetchObserver::item_ref_t idItems;
371 idItems.push_back(idItem);
372 fetchItems(idItems);
373 }
374}
375
376inline bool RlvCommand::hasStrictVariant(ERlvBehaviour eBhvr)
377{
378 switch (eBhvr)
379 {
380 case RLV_BHVR_RECVCHAT:
381 case RLV_BHVR_RECVEMOTE:
382 case RLV_BHVR_RECVIM:
383 case RLV_BHVR_SENDIM:
384 case RLV_BHVR_TPLURE:
385 case RLV_BHVR_SENDCHANNEL:
386 return true;
387 default:
388 return false;
389 }
390}
391
392// ============================================================================
393// Inlined helper functions
394//
395
396inline bool rlvIsEmote(const std::string& strUTF8Text)
397{
398 return (strUTF8Text.length() > 4) && ( (strUTF8Text.compare(0, 4, "/me ") == 0) || (strUTF8Text.compare(0, 4, "/me'") == 0) );
399}
400
401// Checked: 2009-09-05 (RLVa-1.0.2a) | Added: RLVa-1.0.2a
402inline bool rlvIsValidReplyChannel(S32 nChannel)
403{
404 return (nChannel > 0) && (CHAT_CHANNEL_DEBUG != nChannel);
405}
406
407// Checked: 2009-08-05 (RLVa-1.0.1e) | Added: RLVa-1.0.0e
408inline bool rlvSendChatReply(const std::string& strChannel, const std::string& strReply)
409{
410 S32 nChannel;
411 return (LLStringUtil::convertToS32(strChannel, nChannel)) ? rlvSendChatReply(nChannel, strReply) : false;
412}
413
414// ============================================================================
415
416#endif // RLV_HELPER_H