aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/MessagingServer/MessageService.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-01-07 01:39:26 +0000
committerTeravus Ovares2008-01-07 01:39:26 +0000
commitf43e75762a4fe4458d8fd70e0e029ee4113c413f (patch)
tree940178f6b2c221b597869a1841f7c8789832af44 /OpenSim/Grid/MessagingServer/MessageService.cs
parentMore inventory work for CharlieO. Final patch to make it all work yet to come. (diff)
downloadopensim-SC_OLD-f43e75762a4fe4458d8fd70e0e029ee4113c413f.zip
opensim-SC_OLD-f43e75762a4fe4458d8fd70e0e029ee4113c413f.tar.gz
opensim-SC_OLD-f43e75762a4fe4458d8fd70e0e029ee4113c413f.tar.bz2
opensim-SC_OLD-f43e75762a4fe4458d8fd70e0e029ee4113c413f.tar.xz
* Adding More to the MessageServer classes.
* Don't forget to prebuild
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/MessagingServer/MessageService.cs224
1 files changed, 224 insertions, 0 deletions
diff --git a/OpenSim/Grid/MessagingServer/MessageService.cs b/OpenSim/Grid/MessagingServer/MessageService.cs
new file mode 100644
index 0000000..a4362c7
--- /dev/null
+++ b/OpenSim/Grid/MessagingServer/MessageService.cs
@@ -0,0 +1,224 @@
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*/
28using System;
29using System.Net;
30using System.Net.Sockets;
31using System.Collections;
32using System.Collections.Generic;
33using System.Xml;
34using libsecondlife;
35using Nwc.XmlRpc;
36using OpenSim.Framework;
37using OpenSim.Framework.Console;
38using OpenSim.Framework.Data;
39using OpenSim.Framework.Servers;
40
41namespace OpenSim.Grid.MessagingServer
42{
43 public class MessageService
44 {
45 private LogBase m_log;
46 private MessageServerConfig m_cfg;
47 private Hashtable m_presences = new Hashtable();
48 private Hashtable m_regionInfoCache = new Hashtable();
49
50 public MessageService(LogBase log, MessageServerConfig cfg)
51 {
52 m_log = log;
53 m_cfg = cfg;
54 }
55
56 public XmlRpcResponse UserLoggedOn(XmlRpcRequest request)
57 {
58
59 Hashtable requestData = (Hashtable)request.Params[0];
60 AgentCircuitData agentData = new AgentCircuitData();
61 agentData.SessionID = new LLUUID((string)requestData["session_id"]);
62 agentData.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
63 agentData.firstname = (string)requestData["firstname"];
64 agentData.lastname = (string)requestData["lastname"];
65 agentData.AgentID = new LLUUID((string)requestData["agent_id"]);
66 agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
67 agentData.CapsPath = (string)requestData["caps_path"];
68
69 if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
70 {
71 agentData.child = true;
72 }
73 else
74 {
75 agentData.startpos =
76 new LLVector3(Convert.ToUInt32(requestData["startpos_x"]),
77 Convert.ToUInt32(requestData["startpos_y"]),
78 Convert.ToUInt32(requestData["startpos_z"]));
79 agentData.child = false;
80 }
81
82 ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
83
84 m_presences.Add(regionHandle, agentData);
85
86
87 return new XmlRpcResponse();
88 }
89
90
91 #region FriendList Gathering
92
93 /// <summary>
94 /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner
95 /// </summary>
96 /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
97 public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
98 {
99 List<FriendListItem> buddylist = new List<FriendListItem>();
100
101 try
102 {
103 Hashtable param = new Hashtable();
104 param["ownerID"] = friendlistowner.UUID.ToString();
105
106 IList parameters = new ArrayList();
107 parameters.Add(param);
108 XmlRpcRequest req = new XmlRpcRequest("get_user_friend_list", parameters);
109 XmlRpcResponse resp = req.Send(m_cfg.UserServerURL, 3000);
110 Hashtable respData = (Hashtable)resp.Value;
111
112 if (respData.Contains("avcount"))
113 {
114 buddylist = ConvertXMLRPCDataToFriendListItemList(respData);
115 }
116
117 }
118 catch (WebException e)
119 {
120 MainLog.Instance.Warn("Error when trying to fetch Avatar's friends list: " +
121 e.Message);
122 // Return Empty list (no friends)
123 }
124 return buddylist;
125
126 }
127 public List<FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
128 {
129 List<FriendListItem> buddylist = new List<FriendListItem>();
130 int buddycount = Convert.ToInt32((string)data["avcount"]);
131
132
133 for (int i = 0; i < buddycount; i++)
134 {
135 FriendListItem buddylistitem = new FriendListItem();
136
137 buddylistitem.FriendListOwner = new LLUUID((string)data["ownerID" + i.ToString()]);
138 buddylistitem.Friend = new LLUUID((string)data["friendID" + i.ToString()]);
139 buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
140 buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);
141
142 buddylist.Add(buddylistitem);
143 }
144
145
146 return buddylist;
147 }
148 #endregion
149
150 #region regioninfo gathering
151
152 /// <summary>
153 /// Gets and caches a RegionInfo object from the gridserver based on regionhandle
154 /// if the regionhandle is already cached, use the cached values
155 /// </summary>
156 /// <param name="regionhandle">handle to the XY of the region we're looking for</param>
157 /// <returns>A RegionInfo object to stick in the presence info</returns>
158 public RegionInfo GetRegionInfo(ulong regionhandle)
159 {
160 RegionInfo regionInfo = null;
161 if (m_regionInfoCache.Contains(regionhandle))
162 {
163 regionInfo = (RegionInfo)m_regionInfoCache[regionhandle];
164 }
165 else
166 {
167 regionInfo = RequestRegionInfo(regionhandle);
168 }
169 return regionInfo;
170 }
171 public RegionInfo RequestRegionInfo(ulong regionHandle)
172 { RegionInfo regionInfo = null;
173 try
174 {
175
176 Hashtable requestData = new Hashtable();
177 requestData["region_handle"] = regionHandle.ToString();
178 requestData["authkey"] = m_cfg.GridSendKey;
179 ArrayList SendParams = new ArrayList();
180 SendParams.Add(requestData);
181 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
182 XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000);
183
184 Hashtable responseData = (Hashtable)GridResp.Value;
185
186 if (responseData.ContainsKey("error"))
187 {
188 m_log.Error("GRID","error received from grid server" + responseData["error"]);
189 return null;
190 }
191
192 uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
193 uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
194 string internalIpStr = (string)responseData["sim_ip"];
195 uint port = Convert.ToUInt32(responseData["sim_port"]);
196 string externalUri = (string)responseData["sim_uri"];
197
198 IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int)port);
199 string neighbourExternalUri = externalUri;
200 regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
201
202 regionInfo.RemotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
203 regionInfo.RemotingAddress = internalIpStr;
204
205 regionInfo.RegionID = new LLUUID((string)responseData["region_UUID"]);
206 regionInfo.RegionName = (string)responseData["region_name"];
207
208 m_regionInfoCache.Add(regionHandle, regionInfo);
209 }
210 catch (WebException)
211 {
212 MainLog.Instance.Error("GRID",
213 "Region lookup failed for: " + regionHandle.ToString() +
214 " - Is the GridServer down?");
215 return null;
216 }
217
218
219 return regionInfo;
220 }
221 #endregion
222 }
223
224}