diff options
Diffstat (limited to 'OpenSim/Grid/MessagingServer.Modules/PresenceInformer.cs')
-rw-r--r-- | OpenSim/Grid/MessagingServer.Modules/PresenceInformer.cs | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/OpenSim/Grid/MessagingServer.Modules/PresenceInformer.cs b/OpenSim/Grid/MessagingServer.Modules/PresenceInformer.cs new file mode 100644 index 0000000..5d13c1b --- /dev/null +++ b/OpenSim/Grid/MessagingServer.Modules/PresenceInformer.cs | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections; | ||
29 | using System.Net; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using Nwc.XmlRpc; | ||
33 | using OpenSim.Data; | ||
34 | |||
35 | namespace OpenSim.Grid.MessagingServer.Modules | ||
36 | { | ||
37 | public delegate RegionProfileData GetRegionData(ulong region_handle); | ||
38 | public delegate void Done(PresenceInformer obj); | ||
39 | |||
40 | |||
41 | public class PresenceInformer | ||
42 | { | ||
43 | public event GetRegionData OnGetRegionData; | ||
44 | public event Done OnDone; | ||
45 | |||
46 | private GetRegionData handlerGetRegionData = null; | ||
47 | private Done handlerDone = null; | ||
48 | |||
49 | public UserPresenceData presence1 = null; | ||
50 | public UserPresenceData presence2 = null; | ||
51 | public string gridserverurl, gridserversendkey, gridserverrecvkey; | ||
52 | public bool lookupRegion = true; | ||
53 | //public methodGroup | ||
54 | |||
55 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | public PresenceInformer() | ||
58 | { | ||
59 | |||
60 | } | ||
61 | public void go(object o) | ||
62 | { | ||
63 | if (presence1 != null && presence2 != null) | ||
64 | { | ||
65 | SendRegionPresenceUpdate(presence1, presence2); | ||
66 | } | ||
67 | |||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Informs a region about an Agent | ||
72 | /// </summary> | ||
73 | /// <param name="TalkingAbout">User to talk about</param> | ||
74 | /// <param name="UserToUpdate">User we're sending this too (contains the region)</param> | ||
75 | public void SendRegionPresenceUpdate(UserPresenceData TalkingAbout, UserPresenceData UserToUpdate) | ||
76 | { | ||
77 | // TODO: Fill in pertenant Presence Data from 'TalkingAbout' | ||
78 | RegionProfileData whichRegion = new RegionProfileData(); | ||
79 | if (lookupRegion) | ||
80 | { | ||
81 | handlerGetRegionData = OnGetRegionData; | ||
82 | if (handlerGetRegionData != null) | ||
83 | { | ||
84 | whichRegion = handlerGetRegionData(UserToUpdate.regionData.regionHandle); | ||
85 | } | ||
86 | //RegionProfileData rp = RegionProfileData.RequestSimProfileData(UserToUpdate.regionData.regionHandle, gridserverurl, gridserversendkey, gridserverrecvkey); | ||
87 | |||
88 | //whichRegion = rp; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | whichRegion = UserToUpdate.regionData; | ||
93 | } | ||
94 | //whichRegion.httpServerURI | ||
95 | |||
96 | if (whichRegion != null) | ||
97 | { | ||
98 | Hashtable PresenceParams = new Hashtable(); | ||
99 | PresenceParams.Add("agent_id",TalkingAbout.agentData.AgentID.ToString()); | ||
100 | PresenceParams.Add("notify_id",UserToUpdate.agentData.AgentID.ToString()); | ||
101 | if (TalkingAbout.OnlineYN) | ||
102 | PresenceParams.Add("status","TRUE"); | ||
103 | else | ||
104 | PresenceParams.Add("status","FALSE"); | ||
105 | |||
106 | ArrayList SendParams = new ArrayList(); | ||
107 | SendParams.Add(PresenceParams); | ||
108 | |||
109 | m_log.InfoFormat("[PRESENCE]: Informing {0}@{1} at {2} about {3}", TalkingAbout.agentData.firstname + " " + TalkingAbout.agentData.lastname, whichRegion.regionName, whichRegion.httpServerURI, UserToUpdate.agentData.firstname + " " + UserToUpdate.agentData.lastname); | ||
110 | // Send | ||
111 | XmlRpcRequest RegionReq = new XmlRpcRequest("presence_update", SendParams); | ||
112 | try | ||
113 | { | ||
114 | // XmlRpcResponse RegionResp = RegionReq.Send(whichRegion.httpServerURI, 6000); | ||
115 | RegionReq.Send(whichRegion.httpServerURI, 6000); | ||
116 | } | ||
117 | catch (WebException) | ||
118 | { | ||
119 | m_log.WarnFormat("[INFORM]: failed notifying region {0} containing user {1} about {2}", whichRegion.regionName, UserToUpdate.agentData.firstname + " " + UserToUpdate.agentData.lastname, TalkingAbout.agentData.firstname + " " + TalkingAbout.agentData.lastname); | ||
120 | } | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | m_log.Info("[PRESENCEUPDATER]: Region data was null skipping"); | ||
125 | |||
126 | } | ||
127 | |||
128 | handlerDone = OnDone; | ||
129 | if (handlerDone != null) | ||
130 | { | ||
131 | handlerDone(this); | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | } | ||