Annotation of /trunk/OpenSimProfile/Modules/ProfileModule/OpenProfile.cs
Parent Directory
|
Revision Log
Revision 17 - (view) (download)
| 1 : | fly-man- | 2 | using System; |
| 2 : | using System.Collections; | ||
| 3 : | using System.Collections.Generic; | ||
| 4 : | using System.Globalization; | ||
| 5 : | using System.Net; | ||
| 6 : | using System.Net.Sockets; | ||
| 7 : | using System.Reflection; | ||
| 8 : | using System.Xml; | ||
| 9 : | using OpenMetaverse; | ||
| 10 : | using log4net; | ||
| 11 : | using Nini.Config; | ||
| 12 : | using Nwc.XmlRpc; | ||
| 13 : | using OpenSim.Framework; | ||
| 14 : | using OpenSim.Region.Interfaces; | ||
| 15 : | using OpenSim.Region.Environment.Interfaces; | ||
| 16 : | using OpenSim.Region.Environment.Scenes; | ||
| 17 : | using OpenSim.Framework.Communications.Cache; | ||
| 18 : | |||
| 19 : | namespace OpenSimProfile.Modules.OpenProfile | ||
| 20 : | { | ||
| 21 : | public class OpenProfileModule : IRegionModule | ||
| 22 : | { | ||
| 23 : | // | ||
| 24 : | // Log module | ||
| 25 : | // | ||
| 26 : | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
| 27 : | |||
| 28 : | // | ||
| 29 : | // Module vars | ||
| 30 : | // | ||
| 31 : | private IConfigSource m_gConfig; | ||
| 32 : | private List<Scene> m_Scenes = new List<Scene>(); | ||
| 33 : | private string m_ProfileServer = ""; | ||
| 34 : | private bool m_Enabled = true; | ||
| 35 : | |||
| 36 : | public void Initialise(Scene scene, IConfigSource config) | ||
| 37 : | { | ||
| 38 : | if (!m_Enabled) | ||
| 39 : | return; | ||
| 40 : | |||
| 41 : | IConfig profileConfig = config.Configs["Profile"]; | ||
| 42 : | |||
| 43 : | if (m_Scenes.Count == 0) // First time | ||
| 44 : | { | ||
| 45 : | if (profileConfig == null) | ||
| 46 : | { | ||
| 47 : | m_log.Info("[PROFILE] Not configured, disabling"); | ||
| 48 : | m_Enabled = false; | ||
| 49 : | return; | ||
| 50 : | } | ||
| 51 : | m_ProfileServer = profileConfig.GetString("ProfileURL", ""); | ||
| 52 : | if (m_ProfileServer == "") | ||
| 53 : | { | ||
| 54 : | m_log.Error("[PROFILE] No profile server, disabling profiles"); | ||
| 55 : | m_Enabled = false; | ||
| 56 : | return; | ||
| 57 : | } | ||
| 58 : | else | ||
| 59 : | { | ||
| 60 : | m_log.Info("[PROFILE] Profile module is activated"); | ||
| 61 : | m_Enabled = true; | ||
| 62 : | } | ||
| 63 : | } | ||
| 64 : | |||
| 65 : | if (!m_Scenes.Contains(scene)) | ||
| 66 : | m_Scenes.Add(scene); | ||
| 67 : | |||
| 68 : | m_gConfig = config; | ||
| 69 : | |||
| 70 : | // Hook up events | ||
| 71 : | scene.EventManager.OnNewClient += OnNewClient; | ||
| 72 : | } | ||
| 73 : | |||
| 74 : | public void PostInitialise() | ||
| 75 : | { | ||
| 76 : | if (!m_Enabled) | ||
| 77 : | return; | ||
| 78 : | } | ||
| 79 : | |||
| 80 : | public void Close() | ||
| 81 : | { | ||
| 82 : | } | ||
| 83 : | |||
| 84 : | public string Name | ||
| 85 : | { | ||
| 86 : | get { return "ProfileModule"; } | ||
| 87 : | } | ||
| 88 : | |||
| 89 : | public bool IsSharedModule | ||
| 90 : | { | ||
| 91 : | get { return true; } | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | /// New Client Event Handler | ||
| 95 : | private void OnNewClient(IClientAPI client) | ||
| 96 : | { | ||
| 97 : | // Subscribe to messages | ||
| 98 : | melanie | 4 | client.AddGenericPacketHandler("avatarclassifiedsrequest", HandleAvatarClassifiedsRequest); |
| 99 : | client.AddGenericPacketHandler("avatarpicksrequest", HandleAvatarPicksRequest); | ||
| 100 : | client.AddGenericPacketHandler("avatarnotesrequest", HandleAvatarNotesRequest); | ||
| 101 : | fly-man- | 10 | // Handle the Classifieds / Picks reading part |
| 102 : | client.AddGenericPacketHandler("pickinforequest", HandlePickInfoRequest); | ||
| 103 : | fly-man- | 2 | } |
| 104 : | |||
| 105 : | // | ||
| 106 : | // Make external XMLRPC request | ||
| 107 : | // | ||
| 108 : | private Hashtable GenericXMLRPCRequest(Hashtable ReqParams, string method) | ||
| 109 : | { | ||
| 110 : | ArrayList SendParams = new ArrayList(); | ||
| 111 : | SendParams.Add(ReqParams); | ||
| 112 : | |||
| 113 : | // Send Request | ||
| 114 : | XmlRpcResponse Resp; | ||
| 115 : | try | ||
| 116 : | { | ||
| 117 : | XmlRpcRequest Req = new XmlRpcRequest(method, SendParams); | ||
| 118 : | Resp = Req.Send(m_ProfileServer, 30000); | ||
| 119 : | } | ||
| 120 : | catch (WebException ex) | ||
| 121 : | { | ||
| 122 : | m_log.ErrorFormat("[PROFILE]: Unable to connect to Profile " + | ||
| 123 : | melanie | 4 | "Server {0}. Exception {1}", m_ProfileServer, ex); |
| 124 : | fly-man- | 2 | |
| 125 : | Hashtable ErrorHash = new Hashtable(); | ||
| 126 : | ErrorHash["success"] = false; | ||
| 127 : | ErrorHash["errorMessage"] = "Unable to search at this time. "; | ||
| 128 : | ErrorHash["errorURI"] = ""; | ||
| 129 : | |||
| 130 : | return ErrorHash; | ||
| 131 : | } | ||
| 132 : | catch (SocketException ex) | ||
| 133 : | { | ||
| 134 : | m_log.ErrorFormat( | ||
| 135 : | fly-man- | 6 | "[PROFILE]: Unable to connect to Profile Server {0}. " + |
| 136 : | melanie | 4 | "Exception {1}", m_ProfileServer, ex); |
| 137 : | fly-man- | 2 | |
| 138 : | Hashtable ErrorHash = new Hashtable(); | ||
| 139 : | ErrorHash["success"] = false; | ||
| 140 : | ErrorHash["errorMessage"] = "Unable to search at this time. "; | ||
| 141 : | ErrorHash["errorURI"] = ""; | ||
| 142 : | |||
| 143 : | return ErrorHash; | ||
| 144 : | } | ||
| 145 : | catch (XmlException ex) | ||
| 146 : | { | ||
| 147 : | m_log.ErrorFormat( | ||
| 148 : | fly-man- | 6 | "[PROFILE]: Unable to connect to Profile Server {0}. " + |
| 149 : | melanie | 4 | "Exception {1}", m_ProfileServer, ex); |
| 150 : | fly-man- | 2 | |
| 151 : | Hashtable ErrorHash = new Hashtable(); | ||
| 152 : | ErrorHash["success"] = false; | ||
| 153 : | ErrorHash["errorMessage"] = "Unable to search at this time. "; | ||
| 154 : | ErrorHash["errorURI"] = ""; | ||
| 155 : | |||
| 156 : | return ErrorHash; | ||
| 157 : | } | ||
| 158 : | if (Resp.IsFault) | ||
| 159 : | { | ||
| 160 : | Hashtable ErrorHash = new Hashtable(); | ||
| 161 : | ErrorHash["success"] = false; | ||
| 162 : | ErrorHash["errorMessage"] = "Unable to search at this time. "; | ||
| 163 : | ErrorHash["errorURI"] = ""; | ||
| 164 : | return ErrorHash; | ||
| 165 : | } | ||
| 166 : | Hashtable RespData = (Hashtable)Resp.Value; | ||
| 167 : | |||
| 168 : | return RespData; | ||
| 169 : | } | ||
| 170 : | |||
| 171 : | melanie | 4 | public void HandleAvatarClassifiedsRequest(Object sender, string method, List<String> args) |
| 172 : | fly-man- | 2 | { |
| 173 : | melanie | 4 | if (!(sender is IClientAPI)) |
| 174 : | return; | ||
| 175 : | |||
| 176 : | IClientAPI remoteClient = (IClientAPI)sender; | ||
| 177 : | |||
| 178 : | fly-man- | 2 | Hashtable ReqHash = new Hashtable(); |
| 179 : | melanie | 4 | ReqHash["uuid"] = args[0]; |
| 180 : | fly-man- | 2 | |
| 181 : | Hashtable result = GenericXMLRPCRequest(ReqHash, | ||
| 182 : | melanie | 4 | method); |
| 183 : | fly-man- | 2 | |
| 184 : | if (!Convert.ToBoolean(result["success"])) | ||
| 185 : | { | ||
| 186 : | remoteClient.SendAgentAlertMessage( | ||
| 187 : | result["errorMessage"].ToString(), false); | ||
| 188 : | return; | ||
| 189 : | } | ||
| 190 : | fly-man- | 8 | |
| 191 : | ArrayList dataArray = (ArrayList)result["data"]; | ||
| 192 : | |||
| 193 : | melanie | 14 | Dictionary<UUID, string> classifieds = new Dictionary<UUID, string>(); |
| 194 : | |||
| 195 : | melanie | 13 | foreach (Object o in dataArray) |
| 196 : | { | ||
| 197 : | Hashtable d = (Hashtable)o; | ||
| 198 : | |||
| 199 : | melanie | 14 | classifieds[new UUID(d["classifiedid"].ToString())] = d["name"].ToString(); |
| 200 : | melanie | 13 | } |
| 201 : | |||
| 202 : | melanie | 14 | remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, |
| 203 : | melanie | 13 | classifieds); |
| 204 : | melanie | 4 | } |
| 205 : | fly-man- | 2 | |
| 206 : | melanie | 4 | public void HandleAvatarPicksRequest(Object sender, string method, List<String> args) |
| 207 : | { | ||
| 208 : | if (!(sender is IClientAPI)) | ||
| 209 : | return; | ||
| 210 : | fly-man- | 2 | |
| 211 : | melanie | 4 | IClientAPI remoteClient = (IClientAPI)sender; |
| 212 : | fly-man- | 2 | |
| 213 : | melanie | 4 | Hashtable ReqHash = new Hashtable(); |
| 214 : | ReqHash["uuid"] = args[0]; | ||
| 215 : | |||
| 216 : | Hashtable result = GenericXMLRPCRequest(ReqHash, | ||
| 217 : | method); | ||
| 218 : | fly-man- | 2 | |
| 219 : | melanie | 4 | if (!Convert.ToBoolean(result["success"])) |
| 220 : | { | ||
| 221 : | remoteClient.SendAgentAlertMessage( | ||
| 222 : | result["errorMessage"].ToString(), false); | ||
| 223 : | return; | ||
| 224 : | } | ||
| 225 : | fly-man- | 8 | |
| 226 : | ArrayList dataArray = (ArrayList)result["data"]; | ||
| 227 : | |||
| 228 : | fly-man- | 15 | Dictionary<UUID, string> picks = new Dictionary<UUID, string>(); |
| 229 : | |||
| 230 : | foreach (Object o in dataArray) | ||
| 231 : | { | ||
| 232 : | Hashtable d = (Hashtable)o; | ||
| 233 : | |||
| 234 : | picks[new UUID(d["pickid"].ToString())] = d["name"].ToString(); | ||
| 235 : | } | ||
| 236 : | |||
| 237 : | remoteClient.SendAvatarPicksReply(remoteClient.AgentId, | ||
| 238 : | picks); | ||
| 239 : | fly-man- | 10 | } |
| 240 : | fly-man- | 8 | |
| 241 : | fly-man- | 10 | public void HandleAvatarNotesRequest(Object sender, string method, List<String> args) |
| 242 : | { | ||
| 243 : | if (!(sender is IClientAPI)) | ||
| 244 : | return; | ||
| 245 : | fly-man- | 8 | |
| 246 : | fly-man- | 10 | IClientAPI remoteClient = (IClientAPI)sender; |
| 247 : | |||
| 248 : | Hashtable ReqHash = new Hashtable(); | ||
| 249 : | |||
| 250 : | ReqHash["avatar_id"] = remoteClient.AgentId.ToString(); | ||
| 251 : | ReqHash["uuid"] = args[0]; | ||
| 252 : | |||
| 253 : | Hashtable result = GenericXMLRPCRequest(ReqHash, | ||
| 254 : | method); | ||
| 255 : | |||
| 256 : | if (!Convert.ToBoolean(result["success"])) | ||
| 257 : | fly-man- | 8 | { |
| 258 : | fly-man- | 10 | remoteClient.SendAgentAlertMessage( |
| 259 : | result["errorMessage"].ToString(), false); | ||
| 260 : | return; | ||
| 261 : | fly-man- | 8 | } |
| 262 : | |||
| 263 : | fly-man- | 10 | ArrayList dataArray = (ArrayList)result["data"]; |
| 264 : | |||
| 265 : | fly-man- | 16 | Hashtable d = (Hashtable)dataArray[0]; |
| 266 : | fly-man- | 2 | |
| 267 : | fly-man- | 16 | remoteClient.SendAvatarNotesReply( |
| 268 : | new UUID(d["targetid"].ToString()), | ||
| 269 : | d["notes"].ToString()); | ||
| 270 : | fly-man- | 10 | } |
| 271 : | fly-man- | 8 | |
| 272 : | fly-man- | 10 | public void HandlePickInfoRequest(Object sender, string method, List<String> args) |
| 273 : | { | ||
| 274 : | if (!(sender is IClientAPI)) | ||
| 275 : | return; | ||
| 276 : | fly-man- | 8 | |
| 277 : | fly-man- | 10 | IClientAPI remoteClient = (IClientAPI)sender; |
| 278 : | fly-man- | 8 | |
| 279 : | fly-man- | 10 | Hashtable ReqHash = new Hashtable(); |
| 280 : | fly-man- | 8 | |
| 281 : | fly-man- | 10 | ReqHash["avatar_id"] = args[0]; |
| 282 : | ReqHash["pick_id"] = args[1]; | ||
| 283 : | |||
| 284 : | Hashtable result = GenericXMLRPCRequest(ReqHash, | ||
| 285 : | method); | ||
| 286 : | |||
| 287 : | if (!Convert.ToBoolean(result["success"])) | ||
| 288 : | fly-man- | 8 | { |
| 289 : | fly-man- | 10 | remoteClient.SendAgentAlertMessage( |
| 290 : | result["errorMessage"].ToString(), false); | ||
| 291 : | return; | ||
| 292 : | fly-man- | 8 | } |
| 293 : | melanie | 13 | |
| 294 : | melanie | 14 | ArrayList dataArray = (ArrayList)result["data"]; |
| 295 : | |||
| 296 : | melanie | 13 | Hashtable d = (Hashtable)dataArray[0]; |
| 297 : | |||
| 298 : | Vector3 globalPos = new Vector3(); | ||
| 299 : | Vector3.TryParse(d["posglobal"].ToString(), out globalPos); | ||
| 300 : | |||
| 301 : | melanie | 14 | // remoteClient.SendPickInfoReply( |
| 302 : | // new UUID(d["pickuuid"].ToString()), | ||
| 303 : | // new UUID(d["creatoruuid"].ToString()), | ||
| 304 : | // d["toppick"].ToString(), | ||
| 305 : | // new UUID(d["parceluuid"].ToString()), | ||
| 306 : | // d["name"].ToString(), | ||
| 307 : | // d["description"].ToString(), | ||
| 308 : | // new UUID(d["snapshotuuid"].ToString()), | ||
| 309 : | // d["user"].ToString(), | ||
| 310 : | // d["originalname"].ToString(), | ||
| 311 : | // globalPos, | ||
| 312 : | // d["sortorder"].ToString(), | ||
| 313 : | // d["enabled"].ToString()); | ||
| 314 : | fly-man- | 2 | } |
| 315 : | } | ||
| 316 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

