aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lleventnotifier.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lleventnotifier.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/lleventnotifier.cpp327
1 files changed, 327 insertions, 0 deletions
diff --git a/linden/indra/newview/lleventnotifier.cpp b/linden/indra/newview/lleventnotifier.cpp
new file mode 100644
index 0000000..0487223
--- /dev/null
+++ b/linden/indra/newview/lleventnotifier.cpp
@@ -0,0 +1,327 @@
1/**
2 * @file lleventnotifier.cpp
3 * @brief Viewer code for managing event notifications
4 *
5 * Copyright (c) 2004-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "lleventnotifier.h"
31
32#include "message.h"
33
34#include "llnotify.h"
35#include "lleventinfo.h"
36#include "llfloaterdirectory.h"
37#include "llfloaterworldmap.h"
38#include "llagent.h"
39
40LLEventNotifier gEventNotifier;
41
42LLEventNotifier::LLEventNotifier()
43{
44}
45
46
47LLEventNotifier::~LLEventNotifier()
48{
49 en_map::iterator iter;
50
51 for (iter = mEventNotifications.begin();
52 iter != mEventNotifications.end();
53 iter++)
54 {
55 delete iter->second;
56 }
57}
58
59
60void LLEventNotifier::update()
61{
62 if (mNotificationTimer.getElapsedTimeF32() > 30.f)
63 {
64 // Check our notifications again and send out updates
65 // if they happen.
66
67 U32 alert_time = time_corrected() + 5 * 60;
68 en_map::iterator iter;
69 for (iter = mEventNotifications.begin();
70 iter != mEventNotifications.end();)
71 {
72 LLEventNotification *np = iter->second;
73
74 if (np->getEventDate() < (alert_time))
75 {
76 LLString::format_map_t args;
77 args["[NAME]"] = np->getEventName();
78 args["[DATE]"] = np->getEventDateStr();
79 LLNotifyBox::showXml("EventNotification", args,
80 notifyCallback, np);
81 mEventNotifications.erase(iter++);
82 }
83 else
84 {
85 iter++;
86 }
87 }
88 mNotificationTimer.reset();
89 }
90}
91
92void LLEventNotifier::load(const LLUserAuth::options_t& event_options)
93{
94 LLUserAuth::options_t::const_iterator resp_it;
95 for (resp_it = event_options.begin();
96 resp_it != event_options.end();
97 ++resp_it)
98 {
99 const LLUserAuth::response_t& response = *resp_it;
100
101 LLEventNotification *new_enp = new LLEventNotification();
102
103 if (!new_enp->load(response))
104 {
105 delete new_enp;
106 continue;
107 }
108
109 mEventNotifications[new_enp->getEventID()] = new_enp;
110 }
111}
112
113
114BOOL LLEventNotifier::hasNotification(const U32 event_id)
115{
116 if (mEventNotifications.find(event_id) != mEventNotifications.end())
117 {
118 return TRUE;
119 }
120 return FALSE;
121}
122
123
124void LLEventNotifier::add(LLEventInfo &event_info)
125{
126 // We need to tell the simulator that we want to pay attention to
127 // this event, as well as add it to our list.
128
129 if (mEventNotifications.find(event_info.mID) != mEventNotifications.end())
130 {
131 // We already have a notification for this event, don't bother.
132 return;
133 }
134
135 // Push up a message to tell the server we have this notification.
136 gMessageSystem->newMessage("EventNotificationAddRequest");
137 gMessageSystem->nextBlockFast(_PREHASH_AgentData);
138 gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
139 gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
140 gMessageSystem->nextBlock("EventData");
141 gMessageSystem->addU32("EventID", event_info.mID);
142 gAgent.sendReliableMessage();
143
144 LLEventNotification *enp = new LLEventNotification;
145 enp->load(event_info);
146 mEventNotifications[event_info.mID] = enp;
147}
148
149void LLEventNotifier::remove(const U32 event_id)
150{
151 en_map::iterator iter;
152 iter = mEventNotifications.find(event_id);
153 if (iter == mEventNotifications.end())
154 {
155 // We don't have a notification for this event, don't bother.
156 return;
157 }
158
159 // Push up a message to tell the server to remove this notification.
160 gMessageSystem->newMessage("EventNotificationRemoveRequest");
161 gMessageSystem->nextBlockFast(_PREHASH_AgentData);
162 gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
163 gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
164 gMessageSystem->nextBlock("EventData");
165 gMessageSystem->addU32("EventID", event_id);
166 gAgent.sendReliableMessage();
167
168 delete iter->second;
169 mEventNotifications.erase(iter);
170}
171
172//static
173void LLEventNotifier::notifyCallback(S32 option, void *user_data)
174{
175 LLEventNotification *np = (LLEventNotification *)user_data;
176 if (!np)
177 {
178 llwarns << "Event notification callback without data!" << llendl;
179 return;
180 }
181 switch (option)
182 {
183 case 0:
184 gAgent.teleportViaLocation(np->getEventPosGlobal());
185 gFloaterWorldMap->trackLocation(np->getEventPosGlobal());
186 break;
187 case 1:
188 gDisplayEventHack = TRUE;
189 LLFloaterDirectory::showEvents(np->getEventID());
190 break;
191 case 2:
192 break;
193 }
194
195 // We could clean up the notification on the server now if we really wanted to.
196}
197
198
199
200LLEventNotification::LLEventNotification() :
201 mEventID(0),
202 mEventName("")
203{
204}
205
206
207LLEventNotification::~LLEventNotification()
208{
209}
210
211
212BOOL LLEventNotification::load(const LLUserAuth::response_t &response)
213{
214
215 LLUserAuth::response_t::const_iterator option_it;
216 BOOL event_ok = TRUE;
217 option_it = response.find("event_id");
218 if (option_it != response.end())
219 {
220 mEventID = atoi(option_it->second.c_str());
221 }
222 else
223 {
224 event_ok = FALSE;
225 }
226
227 option_it = response.find("event_name");
228 if (option_it != response.end())
229 {
230 llinfos << "Event: " << option_it->second << llendl;
231 mEventName = option_it->second;
232 }
233 else
234 {
235 event_ok = FALSE;
236 }
237
238
239 option_it = response.find("event_date");
240 if (option_it != response.end())
241 {
242 llinfos << "EventDate: " << option_it->second << llendl;
243 mEventDateStr = option_it->second;
244 }
245 else
246 {
247 event_ok = FALSE;
248 }
249
250 option_it = response.find("event_date_ut");
251 if (option_it != response.end())
252 {
253 llinfos << "EventDate: " << option_it->second << llendl;
254 mEventDate = strtoul(option_it->second.c_str(), NULL, 10);
255 }
256 else
257 {
258 event_ok = FALSE;
259 }
260
261 S32 grid_x = 0;
262 S32 grid_y = 0;
263 S32 x_region = 0;
264 S32 y_region = 0;
265
266 option_it = response.find("grid_x");
267 if (option_it != response.end())
268 {
269 llinfos << "GridX: " << option_it->second << llendl;
270 grid_x= atoi(option_it->second.c_str());
271 }
272 else
273 {
274 event_ok = FALSE;
275 }
276
277 option_it = response.find("grid_y");
278 if (option_it != response.end())
279 {
280 llinfos << "GridY: " << option_it->second << llendl;
281 grid_y = atoi(option_it->second.c_str());
282 }
283 else
284 {
285 event_ok = FALSE;
286 }
287
288 option_it = response.find("x_region");
289 if (option_it != response.end())
290 {
291 llinfos << "RegionX: " << option_it->second << llendl;
292 x_region = atoi(option_it->second.c_str());
293 }
294 else
295 {
296 event_ok = FALSE;
297 }
298
299 option_it = response.find("y_region");
300 if (option_it != response.end())
301 {
302 llinfos << "RegionY: " << option_it->second << llendl;
303 y_region = atoi(option_it->second.c_str());
304 }
305 else
306 {
307 event_ok = FALSE;
308 }
309
310 mEventPosGlobal.mdV[VX] = grid_x * 256 + x_region;
311 mEventPosGlobal.mdV[VY] = grid_y * 256 + y_region;
312 mEventPosGlobal.mdV[VZ] = 0.f;
313
314 return event_ok;
315}
316
317BOOL LLEventNotification::load(const LLEventInfo &event_info)
318{
319
320 mEventID = event_info.mID;
321 mEventName = event_info.mName;
322 mEventDateStr = event_info.mTimeStr;
323 mEventDate = event_info.mUnixTime;
324 mEventPosGlobal = event_info.mPosGlobal;
325 return TRUE;
326}
327