corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) 2006-2014, openmetaverse.org
3 * All rights reserved.
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 *
8 * - Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * - Neither the name of the openmetaverse.org nor the names
11 * of its contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26  
27 using System;
28 using System.Collections.Generic;
29 using System.Net;
30 using System.Text;
31 using System.Threading;
32 using OpenMetaverse.Packets;
33 using OpenMetaverse.StructuredData;
34 using OpenMetaverse.Interfaces;
35 using OpenMetaverse.Http;
36  
37 namespace OpenMetaverse
38 {
39 /// <summary>
40 /// Capabilities is the name of the bi-directional HTTP REST protocol
41 /// used to communicate non real-time transactions such as teleporting or
42 /// group messaging
43 /// </summary>
44 public partial class Caps
45 {
46 /// <summary>
47 /// Triggered when an event is received via the EventQueueGet
48 /// capability
49 /// </summary>
50 /// <param name="capsKey">Event name</param>
51 /// <param name="message">Decoded event data</param>
52 /// <param name="simulator">The simulator that generated the event</param>
53 //public delegate void EventQueueCallback(string message, StructuredData.OSD body, Simulator simulator);
54  
55 public delegate void EventQueueCallback(string capsKey, IMessage message, Simulator simulator);
56  
57 /// <summary>Reference to the simulator this system is connected to</summary>
58 public Simulator Simulator;
59  
60 internal string _SeedCapsURI;
61 internal Dictionary<string, Uri> _Caps = new Dictionary<string, Uri>();
62  
63 private CapsClient _SeedRequest;
64 private EventQueueClient _EventQueueCap = null;
65  
66 /// <summary>Capabilities URI this system was initialized with</summary>
67 public string SeedCapsURI { get { return _SeedCapsURI; } }
68  
69 /// <summary>Whether the capabilities event queue is connected and
70 /// listening for incoming events</summary>
71 public bool IsEventQueueRunning
72 {
73 get
74 {
75 if (_EventQueueCap != null)
76 return _EventQueueCap.Running;
77 else
78 return false;
79 }
80 }
81  
82 /// <summary>
83 /// Default constructor
84 /// </summary>
85 /// <param name="simulator"></param>
86 /// <param name="seedcaps"></param>
87 internal Caps(Simulator simulator, string seedcaps)
88 {
89 Simulator = simulator;
90 _SeedCapsURI = seedcaps;
91  
92 MakeSeedRequest();
93 }
94  
95 public void Disconnect(bool immediate)
96 {
97 Logger.Log(String.Format("Caps system for {0} is {1}", Simulator,
98 (immediate ? "aborting" : "disconnecting")), Helpers.LogLevel.Info, Simulator.Client);
99  
100 if (_SeedRequest != null)
101 _SeedRequest.Cancel();
102  
103 if (_EventQueueCap != null)
104 _EventQueueCap.Stop(immediate);
105 }
106  
107 /// <summary>
108 /// Request the URI of a named capability
109 /// </summary>
110 /// <param name="capability">Name of the capability to request</param>
111 /// <returns>The URI of the requested capability, or String.Empty if
112 /// the capability does not exist</returns>
113 public Uri CapabilityURI(string capability)
114 {
115 Uri cap;
116  
117 if (_Caps.TryGetValue(capability, out cap))
118 return cap;
119 else
120 return null;
121 }
122  
123 private void MakeSeedRequest()
124 {
125 if (Simulator == null || !Simulator.Client.Network.Connected)
126 return;
127  
128 // Create a request list
129 OSDArray req = new OSDArray();
130 // This list can be updated by using the following command to obtain a current list of capabilities the official linden viewer supports:
131 // wget -q -O - https://bitbucket.org/lindenlab/viewer-release/raw/default/indra/newview/llviewerregion.cpp | grep 'capabilityNames.append' | sed 's/^[ \t]*//;s/capabilityNames.append("/req.Add("/'
132 req.Add("AgentPreferences");
133 req.Add("AgentState");
134 req.Add("AttachmentResources");
135 req.Add("AvatarPickerSearch");
136 req.Add("AvatarRenderInfo");
137 req.Add("CharacterProperties");
138 req.Add("ChatSessionRequest");
139 req.Add("CopyInventoryFromNotecard");
140 req.Add("CreateInventoryCategory");
141 req.Add("DispatchRegionInfo");
142 req.Add("EnvironmentSettings");
143 req.Add("EstateChangeInfo");
144 req.Add("EventQueueGet");
145 req.Add("FacebookConnect");
146 req.Add("FlickrConnect");
147 req.Add("TwitterConnect");
148 req.Add("FetchLib2");
149 req.Add("FetchLibDescendents2");
150 req.Add("FetchInventory2");
151 req.Add("FetchInventoryDescendents2");
152 req.Add("IncrementCOFVersion");
153 req.Add("GetDisplayNames");
154 req.Add("GetMesh");
155 req.Add("GetMesh2");
156 req.Add("GetObjectCost");
157 req.Add("GetObjectPhysicsData");
158 req.Add("GetTexture");
159 req.Add("GroupAPIv1");
160 req.Add("GroupMemberData");
161 req.Add("GroupProposalBallot");
162 req.Add("HomeLocation");
163 req.Add("LandResources");
164 req.Add("LSLSyntax");
165 req.Add("MapLayer");
166 req.Add("MapLayerGod");
167 req.Add("MeshUploadFlag");
168 req.Add("NavMeshGenerationStatus");
169 req.Add("NewFileAgentInventory");
170 req.Add("ObjectMedia");
171 req.Add("ObjectMediaNavigate");
172 req.Add("ObjectNavMeshProperties");
173 req.Add("ParcelPropertiesUpdate");
174 req.Add("ParcelVoiceInfoRequest");
175 req.Add("ProductInfoRequest");
176 req.Add("ProvisionVoiceAccountRequest");
177 req.Add("RemoteParcelRequest");
178 req.Add("RenderMaterials");
179 req.Add("RequestTextureDownload");
180 req.Add("ResourceCostSelected");
181 req.Add("RetrieveNavMeshSrc");
182 req.Add("SearchStatRequest");
183 req.Add("SearchStatTracking");
184 req.Add("SendPostcard");
185 req.Add("SendUserReport");
186 req.Add("SendUserReportWithScreenshot");
187 req.Add("ServerReleaseNotes");
188 req.Add("SetDisplayName");
189 req.Add("SimConsoleAsync");
190 req.Add("SimulatorFeatures");
191 req.Add("StartGroupProposal");
192 req.Add("TerrainNavMeshProperties");
193 req.Add("TextureStats");
194 req.Add("UntrustedSimulatorMessage");
195 req.Add("UpdateAgentInformation");
196 req.Add("UpdateAgentLanguage");
197 req.Add("UpdateAvatarAppearance");
198 req.Add("UpdateGestureAgentInventory");
199 req.Add("UpdateGestureTaskInventory");
200 req.Add("UpdateNotecardAgentInventory");
201 req.Add("UpdateNotecardTaskInventory");
202 req.Add("UpdateScriptAgent");
203 req.Add("UpdateScriptTask");
204 req.Add("UploadBakedTexture");
205 req.Add("ViewerMetrics");
206 req.Add("ViewerStartAuction");
207 req.Add("ViewerStats");
208  
209 _SeedRequest = new CapsClient(new Uri(_SeedCapsURI));
210 _SeedRequest.OnComplete += new CapsClient.CompleteCallback(SeedRequestCompleteHandler);
211 _SeedRequest.BeginGetResponse(req, OSDFormat.Xml, Simulator.Client.Settings.CAPS_TIMEOUT);
212 }
213  
214 private void SeedRequestCompleteHandler(CapsClient client, OSD result, Exception error)
215 {
216 if (result != null && result.Type == OSDType.Map)
217 {
218 OSDMap respTable = (OSDMap)result;
219  
220 foreach (string cap in respTable.Keys)
221 {
222 _Caps[cap] = respTable[cap].AsUri();
223 }
224  
225 if (_Caps.ContainsKey("EventQueueGet"))
226 {
227 Logger.DebugLog("Starting event queue for " + Simulator.ToString(), Simulator.Client);
228  
229 _EventQueueCap = new EventQueueClient(_Caps["EventQueueGet"]);
230 _EventQueueCap.OnConnected += EventQueueConnectedHandler;
231 _EventQueueCap.OnEvent += EventQueueEventHandler;
232 _EventQueueCap.Start();
233 }
234 }
235 else if (
236 error != null &&
237 error is WebException &&
238 ((WebException)error).Response != null &&
239 ((HttpWebResponse)((WebException)error).Response).StatusCode == HttpStatusCode.NotFound)
240 {
241 // 404 error
242 Logger.Log("Seed capability returned a 404, capability system is aborting", Helpers.LogLevel.Error);
243 }
244 else
245 {
246 // The initial CAPS connection failed, try again
247 MakeSeedRequest();
248 }
249 }
250  
251 private void EventQueueConnectedHandler()
252 {
253 Simulator.Client.Network.RaiseConnectedEvent(Simulator);
254 }
255  
256 /// <summary>
257 /// Process any incoming events, check to see if we have a message created for the event,
258 /// </summary>
259 /// <param name="eventName"></param>
260 /// <param name="body"></param>
261 private void EventQueueEventHandler(string eventName, OSDMap body)
262 {
263 IMessage message = Messages.MessageUtils.DecodeEvent(eventName, body);
264 if (message != null)
265 {
266 Simulator.Client.Network.CapsEvents.BeginRaiseEvent(eventName, message, Simulator);
267  
268 #region Stats Tracking
269 if (Simulator.Client.Settings.TRACK_UTILIZATION)
270 {
271 Simulator.Client.Stats.Update(eventName, OpenMetaverse.Stats.Type.Message, 0, body.ToString().Length);
272 }
273 #endregion
274 }
275 else
276 {
277 Logger.Log("No Message handler exists for event " + eventName + ". Unable to decode. Will try Generic Handler next", Helpers.LogLevel.Warning);
278 Logger.Log("Please report this information to http://jira.openmetaverse.org/: \n" + body, Helpers.LogLevel.Debug);
279  
280 // try generic decoder next which takes a caps event and tries to match it to an existing packet
281 if (body.Type == OSDType.Map)
282 {
283 OSDMap map = (OSDMap)body;
284 Packet packet = Packet.BuildPacket(eventName, map);
285 if (packet != null)
286 {
287 NetworkManager.IncomingPacket incomingPacket;
288 incomingPacket.Simulator = Simulator;
289 incomingPacket.Packet = packet;
290  
291 Logger.DebugLog("Serializing " + packet.Type.ToString() + " capability with generic handler", Simulator.Client);
292  
293 Simulator.Client.Network.PacketInbox.Enqueue(incomingPacket);
294 }
295 else
296 {
297 Logger.Log("No Packet or Message handler exists for " + eventName, Helpers.LogLevel.Warning);
298 }
299 }
300 }
301 }
302 }
303 }