UserServerAvatarAppearanceModule.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using log4net;
  33. using Nwc.XmlRpc;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Communications;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Grid.Framework;
  40. namespace OpenSim.Grid.UserServer.Modules
  41. {
  42. public class UserServerAvatarAppearanceModule
  43. {
  44. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private UserDataBaseService m_userDataBaseService;
  46. private BaseHttpServer m_httpServer;
  47. public UserServerAvatarAppearanceModule(UserDataBaseService userDataBaseService)
  48. {
  49. m_userDataBaseService = userDataBaseService;
  50. }
  51. public void Initialise(IGridServiceCore core)
  52. {
  53. }
  54. public void PostInitialise()
  55. {
  56. }
  57. public void RegisterHandlers(BaseHttpServer httpServer)
  58. {
  59. m_httpServer = httpServer;
  60. m_httpServer.AddXmlRPCHandler("get_avatar_appearance", XmlRPCGetAvatarAppearance);
  61. m_httpServer.AddXmlRPCHandler("update_avatar_appearance", XmlRPCUpdateAvatarAppearance);
  62. }
  63. public XmlRpcResponse XmlRPCGetAvatarAppearance(XmlRpcRequest request, IPEndPoint remoteClient)
  64. {
  65. XmlRpcResponse response = new XmlRpcResponse();
  66. Hashtable requestData = (Hashtable)request.Params[0];
  67. AvatarAppearance appearance;
  68. Hashtable responseData;
  69. if (requestData.Contains("owner"))
  70. {
  71. appearance = m_userDataBaseService.GetUserAppearance(new UUID((string)requestData["owner"]));
  72. if (appearance == null)
  73. {
  74. responseData = new Hashtable();
  75. responseData["error_type"] = "no appearance";
  76. responseData["error_desc"] = "There was no appearance found for this avatar";
  77. }
  78. else
  79. {
  80. responseData = appearance.ToHashTable();
  81. }
  82. }
  83. else
  84. {
  85. responseData = new Hashtable();
  86. responseData["error_type"] = "unknown_avatar";
  87. responseData["error_desc"] = "The avatar appearance requested is not in the database";
  88. }
  89. response.Value = responseData;
  90. return response;
  91. }
  92. public XmlRpcResponse XmlRPCUpdateAvatarAppearance(XmlRpcRequest request, IPEndPoint remoteClient)
  93. {
  94. XmlRpcResponse response = new XmlRpcResponse();
  95. Hashtable requestData = (Hashtable)request.Params[0];
  96. Hashtable responseData;
  97. if (requestData.Contains("owner"))
  98. {
  99. AvatarAppearance appearance = new AvatarAppearance(requestData);
  100. // TODO: Sometime in the future we may have a database layer that is capable of updating appearance when
  101. // the TextureEntry is null. When that happens, this check can be removed
  102. if (appearance.Texture != null)
  103. m_userDataBaseService.UpdateUserAppearance(new UUID((string)requestData["owner"]), appearance);
  104. responseData = new Hashtable();
  105. responseData["returnString"] = "TRUE";
  106. }
  107. else
  108. {
  109. responseData = new Hashtable();
  110. responseData["error_type"] = "unknown_avatar";
  111. responseData["error_desc"] = "The avatar appearance requested is not in the database";
  112. }
  113. response.Value = responseData;
  114. return response;
  115. }
  116. }
  117. }