lleventnotifier.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "lleventnotifier.h"
00035 
00036 #include "message.h"
00037 
00038 #include "llnotify.h"
00039 #include "lleventinfo.h"
00040 #include "llfloaterdirectory.h"
00041 #include "llfloaterworldmap.h"
00042 #include "llagent.h"
00043 
00044 LLEventNotifier gEventNotifier;
00045 
00046 LLEventNotifier::LLEventNotifier()
00047 {
00048 }
00049 
00050 
00051 LLEventNotifier::~LLEventNotifier()
00052 {
00053         en_map::iterator iter;
00054 
00055         for (iter = mEventNotifications.begin();
00056                  iter != mEventNotifications.end();
00057                  iter++)
00058         {
00059                 delete iter->second;
00060         }
00061 }
00062 
00063 
00064 void LLEventNotifier::update()
00065 {
00066         if (mNotificationTimer.getElapsedTimeF32() > 30.f)
00067         {
00068                 // Check our notifications again and send out updates
00069                 // if they happen.
00070 
00071                 U32 alert_time = time_corrected() + 5 * 60;
00072                 en_map::iterator iter;
00073                 for (iter = mEventNotifications.begin();
00074                          iter != mEventNotifications.end();)
00075                 {
00076                         LLEventNotification *np = iter->second;
00077 
00078                         if (np->getEventDate() < (alert_time))
00079                         {
00080                                 LLString::format_map_t args;
00081                                 args["[NAME]"] = np->getEventName();
00082                                 args["[DATE]"] = np->getEventDateStr();
00083                                 LLNotifyBox::showXml("EventNotification", args, 
00084                                                                          notifyCallback, np);
00085                                 mEventNotifications.erase(iter++);
00086                         }
00087                         else
00088                         {
00089                                 iter++;
00090                         }
00091                 }
00092                 mNotificationTimer.reset();
00093         }
00094 }
00095 
00096 void LLEventNotifier::load(const LLUserAuth::options_t& event_options)
00097 {
00098         LLUserAuth::options_t::const_iterator resp_it;
00099         for (resp_it = event_options.begin(); 
00100                  resp_it != event_options.end(); 
00101                  ++resp_it)
00102         {
00103                 const LLUserAuth::response_t& response = *resp_it;
00104 
00105                 LLEventNotification *new_enp = new LLEventNotification();
00106 
00107                 if (!new_enp->load(response))
00108                 {
00109                         delete new_enp;
00110                         continue;
00111                 }
00112                 
00113                 mEventNotifications[new_enp->getEventID()] = new_enp;
00114         }
00115 }
00116 
00117 
00118 BOOL LLEventNotifier::hasNotification(const U32 event_id)
00119 {
00120         if (mEventNotifications.find(event_id) != mEventNotifications.end())
00121         {
00122                 return TRUE;
00123         }
00124         return FALSE;
00125 }
00126 
00127 
00128 void LLEventNotifier::add(LLEventInfo &event_info)
00129 {
00130         // We need to tell the simulator that we want to pay attention to
00131         // this event, as well as add it to our list.
00132 
00133         if (mEventNotifications.find(event_info.mID) != mEventNotifications.end())
00134         {
00135                 // We already have a notification for this event, don't bother.
00136                 return;
00137         }
00138 
00139         // Push up a message to tell the server we have this notification.
00140         gMessageSystem->newMessage("EventNotificationAddRequest");
00141         gMessageSystem->nextBlockFast(_PREHASH_AgentData);
00142         gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
00143         gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00144         gMessageSystem->nextBlock("EventData");
00145         gMessageSystem->addU32("EventID", event_info.mID);
00146         gAgent.sendReliableMessage();
00147 
00148         LLEventNotification *enp = new LLEventNotification;
00149         enp->load(event_info);
00150         mEventNotifications[event_info.mID] = enp;
00151 }
00152 
00153 void LLEventNotifier::remove(const U32 event_id)
00154 {
00155         en_map::iterator iter;
00156         iter = mEventNotifications.find(event_id);
00157         if (iter == mEventNotifications.end())
00158         {
00159                 // We don't have a notification for this event, don't bother.
00160                 return;
00161         }
00162 
00163         // Push up a message to tell the server to remove this notification.
00164         gMessageSystem->newMessage("EventNotificationRemoveRequest");
00165         gMessageSystem->nextBlockFast(_PREHASH_AgentData);
00166         gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
00167         gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00168         gMessageSystem->nextBlock("EventData");
00169         gMessageSystem->addU32("EventID", event_id);
00170         gAgent.sendReliableMessage();
00171         
00172         delete iter->second;
00173         mEventNotifications.erase(iter);
00174 }
00175 
00176 //static
00177 void LLEventNotifier::notifyCallback(S32 option, void *user_data)
00178 {
00179         LLEventNotification *np = (LLEventNotification *)user_data;
00180         if (!np)
00181         {
00182                 llwarns << "Event notification callback without data!" << llendl;
00183                 return;
00184         }
00185         switch (option)
00186         {
00187         case 0:
00188                 gAgent.teleportViaLocation(np->getEventPosGlobal());
00189                 gFloaterWorldMap->trackLocation(np->getEventPosGlobal());
00190                 break;
00191         case 1:
00192                 gDisplayEventHack = TRUE;
00193                 LLFloaterDirectory::showEvents(np->getEventID());
00194                 break;
00195         case 2:
00196                 break;
00197         }
00198 
00199         // We could clean up the notification on the server now if we really wanted to.
00200 }
00201 
00202 
00203 
00204 LLEventNotification::LLEventNotification() :
00205         mEventID(0),
00206         mEventName("")
00207 {
00208 }
00209 
00210 
00211 LLEventNotification::~LLEventNotification()
00212 {
00213 }
00214 
00215 
00216 BOOL LLEventNotification::load(const LLUserAuth::response_t &response)
00217 {
00218 
00219         LLUserAuth::response_t::const_iterator option_it;
00220         BOOL event_ok = TRUE;
00221         option_it = response.find("event_id");
00222         if (option_it != response.end())
00223         {
00224                 mEventID = atoi(option_it->second.c_str());
00225         }
00226         else
00227         {
00228                 event_ok = FALSE;
00229         }
00230 
00231         option_it = response.find("event_name");
00232         if (option_it != response.end())
00233         {
00234                 llinfos << "Event: " << option_it->second << llendl;
00235                 mEventName = option_it->second;
00236         }
00237         else
00238         {
00239                 event_ok = FALSE;
00240         }
00241 
00242 
00243         option_it = response.find("event_date");
00244         if (option_it != response.end())
00245         {
00246                 llinfos << "EventDate: " << option_it->second << llendl;
00247                 mEventDateStr = option_it->second;
00248         }
00249         else
00250         {
00251                 event_ok = FALSE;
00252         }
00253 
00254         option_it = response.find("event_date_ut");
00255         if (option_it != response.end())
00256         {
00257                 llinfos << "EventDate: " << option_it->second << llendl;
00258                 mEventDate = strtoul(option_it->second.c_str(), NULL, 10);
00259         }
00260         else
00261         {
00262                 event_ok = FALSE;
00263         }
00264 
00265         S32 grid_x = 0;
00266         S32 grid_y = 0;
00267         S32 x_region = 0;
00268         S32 y_region = 0;
00269 
00270         option_it = response.find("grid_x");
00271         if (option_it != response.end())
00272         {
00273                 llinfos << "GridX: " << option_it->second << llendl;
00274                 grid_x= atoi(option_it->second.c_str());
00275         }
00276         else
00277         {
00278                 event_ok = FALSE;
00279         }
00280 
00281         option_it = response.find("grid_y");
00282         if (option_it != response.end())
00283         {
00284                 llinfos << "GridY: " << option_it->second << llendl;
00285                 grid_y = atoi(option_it->second.c_str());
00286         }
00287         else
00288         {
00289                 event_ok = FALSE;
00290         }
00291 
00292         option_it = response.find("x_region");
00293         if (option_it != response.end())
00294         {
00295                 llinfos << "RegionX: " << option_it->second << llendl;
00296                 x_region = atoi(option_it->second.c_str());
00297         }
00298         else
00299         {
00300                 event_ok = FALSE;
00301         }
00302 
00303         option_it = response.find("y_region");
00304         if (option_it != response.end())
00305         {
00306                 llinfos << "RegionY: " << option_it->second << llendl;
00307                 y_region = atoi(option_it->second.c_str());
00308         }
00309         else
00310         {
00311                 event_ok = FALSE;
00312         }
00313 
00314         mEventPosGlobal.mdV[VX] = grid_x * 256 + x_region;
00315         mEventPosGlobal.mdV[VY] = grid_y * 256 + y_region;
00316         mEventPosGlobal.mdV[VZ] = 0.f;
00317 
00318         return event_ok;
00319 }
00320 
00321 BOOL LLEventNotification::load(const LLEventInfo &event_info)
00322 {
00323 
00324         mEventID = event_info.mID;
00325         mEventName = event_info.mName;
00326         mEventDateStr = event_info.mTimeStr;
00327         mEventDate = event_info.mUnixTime;
00328         mEventPosGlobal = event_info.mPosGlobal;
00329         return TRUE;
00330 }
00331 

Generated on Thu Jul 1 06:08:29 2010 for Second Life Viewer by  doxygen 1.4.7