WorldViewRequestHandler.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 OpenSimulator 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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Xml;
  32. using OpenSim.Framework;
  33. using OpenSim.Server.Base;
  34. using OpenSim.Framework.Servers.HttpServer;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenMetaverse;
  38. using log4net;
  39. namespace OpenSim.Region.OptionalModules.World.WorldView
  40. {
  41. public class WorldViewRequestHandler : BaseStreamHandler
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. protected WorldViewModule m_WorldViewModule;
  45. protected Object m_RequestLock = new Object();
  46. public WorldViewRequestHandler(WorldViewModule fmodule, string rid)
  47. : base("GET", "/worldview/" + rid)
  48. {
  49. m_WorldViewModule = fmodule;
  50. }
  51. public override byte[] Handle(string path, Stream requestData,
  52. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  53. {
  54. httpResponse.ContentType = "image/jpeg";
  55. // StreamReader sr = new StreamReader(requestData);
  56. // string body = sr.ReadToEnd();
  57. // sr.Close();
  58. // body = body.Trim();
  59. try
  60. {
  61. lock (m_RequestLock)
  62. {
  63. Dictionary<string, object> request =
  64. new Dictionary<string, object>();
  65. foreach (string name in httpRequest.QueryString)
  66. request[name] = httpRequest.QueryString[name];
  67. return SendWorldView(request);
  68. }
  69. }
  70. catch (Exception e)
  71. {
  72. m_log.Debug("[WORLDVIEW]: Exception: " + e.ToString());
  73. }
  74. return new Byte[0];
  75. }
  76. public Byte[] SendWorldView(Dictionary<string, object> request)
  77. {
  78. float posX;
  79. float posY;
  80. float posZ;
  81. float rotX;
  82. float rotY;
  83. float rotZ;
  84. float fov;
  85. int width;
  86. int height;
  87. bool usetex;
  88. if (!request.ContainsKey("posX"))
  89. return new Byte[0];
  90. if (!request.ContainsKey("posY"))
  91. return new Byte[0];
  92. if (!request.ContainsKey("posZ"))
  93. return new Byte[0];
  94. if (!request.ContainsKey("rotX"))
  95. return new Byte[0];
  96. if (!request.ContainsKey("rotY"))
  97. return new Byte[0];
  98. if (!request.ContainsKey("rotZ"))
  99. return new Byte[0];
  100. if (!request.ContainsKey("fov"))
  101. return new Byte[0];
  102. if (!request.ContainsKey("width"))
  103. return new Byte[0];
  104. if (!request.ContainsKey("height"))
  105. return new Byte[0];
  106. if (!request.ContainsKey("usetex"))
  107. return new Byte[0];
  108. try
  109. {
  110. posX = Convert.ToSingle(request["posX"]);
  111. posY = Convert.ToSingle(request["posY"]);
  112. posZ = Convert.ToSingle(request["posZ"]);
  113. rotX = Convert.ToSingle(request["rotX"]);
  114. rotY = Convert.ToSingle(request["rotY"]);
  115. rotZ = Convert.ToSingle(request["rotZ"]);
  116. fov = Convert.ToSingle(request["fov"]);
  117. width = Convert.ToInt32(request["width"]);
  118. height = Convert.ToInt32(request["height"]);
  119. usetex = Convert.ToBoolean(request["usetex"]);
  120. }
  121. catch
  122. {
  123. return new Byte[0];
  124. }
  125. Vector3 pos = new Vector3(posX, posY, posZ);
  126. Vector3 rot = new Vector3(rotX, rotY, rotZ);
  127. return m_WorldViewModule.GenerateWorldView(pos, rot, fov, width,
  128. height, usetex);
  129. }
  130. }
  131. }