UserProfilesService.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.Reflection;
  29. using System.Text;
  30. using Nini.Config;
  31. using log4net;
  32. using OpenSim.Server.Base;
  33. using OpenSim.Services.Interfaces;
  34. using OpenSim.Services.UserAccountService;
  35. using OpenSim.Data;
  36. using OpenMetaverse;
  37. using OpenMetaverse.StructuredData;
  38. using OpenSim.Framework;
  39. namespace OpenSim.Services.ProfilesService
  40. {
  41. public class UserProfilesService: UserProfilesServiceBase, IUserProfilesService
  42. {
  43. static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. IUserAccountService userAccounts;
  45. public UserProfilesService(IConfigSource config, string configName):
  46. base(config, configName)
  47. {
  48. IConfig Config = config.Configs[configName];
  49. if (Config == null)
  50. {
  51. m_log.Warn("[PROFILES SERVICE]: No configuration found!");
  52. return;
  53. }
  54. Object[] args = null;
  55. args = new Object[] { config };
  56. string accountService = Config.GetString("UserAccountService", String.Empty);
  57. if (accountService != string.Empty)
  58. userAccounts = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
  59. args = new Object[] { config };
  60. }
  61. #region Classifieds
  62. public OSD AvatarClassifiedsRequest(UUID creatorId)
  63. {
  64. OSDArray records = ProfilesData.GetClassifiedRecords(creatorId);
  65. return records;
  66. }
  67. public bool ClassifiedUpdate(UserClassifiedAdd ad, ref string result)
  68. {
  69. if(!ProfilesData.UpdateClassifiedRecord(ad, ref result))
  70. {
  71. return false;
  72. }
  73. result = "success";
  74. return true;
  75. }
  76. public bool ClassifiedDelete(UUID recordId)
  77. {
  78. if(ProfilesData.DeleteClassifiedRecord(recordId))
  79. return true;
  80. return false;
  81. }
  82. public bool ClassifiedInfoRequest(ref UserClassifiedAdd ad, ref string result)
  83. {
  84. if(ProfilesData.GetClassifiedInfo(ref ad, ref result))
  85. return true;
  86. return false;
  87. }
  88. #endregion Classifieds
  89. #region Picks
  90. public OSD AvatarPicksRequest(UUID creatorId)
  91. {
  92. OSDArray records = ProfilesData.GetAvatarPicks(creatorId);
  93. return records;
  94. }
  95. public bool PickInfoRequest(ref UserProfilePick pick, ref string result)
  96. {
  97. pick = ProfilesData.GetPickInfo(pick.CreatorId, pick.PickId);
  98. result = "OK";
  99. return true;
  100. }
  101. public bool PicksUpdate(ref UserProfilePick pick, ref string result)
  102. {
  103. return ProfilesData.UpdatePicksRecord(pick);
  104. }
  105. public bool PicksDelete(UUID pickId)
  106. {
  107. return ProfilesData.DeletePicksRecord(pickId);
  108. }
  109. #endregion Picks
  110. #region Notes
  111. public bool AvatarNotesRequest(ref UserProfileNotes note)
  112. {
  113. return ProfilesData.GetAvatarNotes(ref note);
  114. }
  115. public bool NotesUpdate(ref UserProfileNotes note, ref string result)
  116. {
  117. return ProfilesData.UpdateAvatarNotes(ref note, ref result);
  118. }
  119. #endregion Notes
  120. #region Profile Properties
  121. public bool AvatarPropertiesRequest(ref UserProfileProperties prop, ref string result)
  122. {
  123. return ProfilesData.GetAvatarProperties(ref prop, ref result);
  124. }
  125. public bool AvatarPropertiesUpdate(ref UserProfileProperties prop, ref string result)
  126. {
  127. return ProfilesData.UpdateAvatarProperties(ref prop, ref result);
  128. }
  129. #endregion Profile Properties
  130. #region Interests
  131. public bool AvatarInterestsUpdate(UserProfileProperties prop, ref string result)
  132. {
  133. return ProfilesData.UpdateAvatarInterests(prop, ref result);
  134. }
  135. #endregion Interests
  136. #region User Preferences
  137. public bool UserPreferencesUpdate(ref UserPreferences pref, ref string result)
  138. {
  139. if(string.IsNullOrEmpty(pref.EMail))
  140. {
  141. UserAccount account = new UserAccount();
  142. if(userAccounts is UserAccountService.UserAccountService)
  143. {
  144. try
  145. {
  146. account = userAccounts.GetUserAccount(UUID.Zero, pref.UserId);
  147. if(string.IsNullOrEmpty(account.Email))
  148. {
  149. pref.EMail = string.Empty;
  150. }
  151. else
  152. pref.EMail = account.Email;
  153. }
  154. catch
  155. {
  156. m_log.Error ("[PROFILES SERVICE]: UserAccountService Exception: Could not get user account");
  157. result = "UserAccountService settings error in UserProfileService!";
  158. return false;
  159. }
  160. }
  161. else
  162. {
  163. m_log.Error ("[PROFILES SERVICE]: UserAccountService: Could not get user account");
  164. result = "UserAccountService settings error in UserProfileService!";
  165. return false;
  166. }
  167. }
  168. return ProfilesData.UpdateUserPreferences(ref pref, ref result);
  169. }
  170. public bool UserPreferencesRequest(ref UserPreferences pref, ref string result)
  171. {
  172. if (!ProfilesData.GetUserPreferences(ref pref, ref result))
  173. return false;
  174. if(string.IsNullOrEmpty(pref.EMail))
  175. {
  176. UserAccount account = new UserAccount();
  177. if(userAccounts is UserAccountService.UserAccountService)
  178. {
  179. try
  180. {
  181. account = userAccounts.GetUserAccount(UUID.Zero, pref.UserId);
  182. if(string.IsNullOrEmpty(account.Email))
  183. {
  184. pref.EMail = string.Empty;
  185. }
  186. else
  187. {
  188. pref.EMail = account.Email;
  189. UserPreferencesUpdate(ref pref, ref result);
  190. }
  191. }
  192. catch
  193. {
  194. m_log.Error ("[PROFILES SERVICE]: UserAccountService Exception: Could not get user account");
  195. result = "UserAccountService settings error in UserProfileService!";
  196. return false;
  197. }
  198. }
  199. else
  200. {
  201. m_log.Error ("[PROFILES SERVICE]: UserAccountService: Could not get user account");
  202. result = "UserAccountService settings error in UserProfileService!";
  203. return false;
  204. }
  205. }
  206. if(string.IsNullOrEmpty(pref.EMail))
  207. pref.EMail = "No Email Address On Record";
  208. return true;
  209. }
  210. #endregion User Preferences
  211. #region Utility
  212. public OSD AvatarImageAssetsRequest(UUID avatarId)
  213. {
  214. OSDArray records = ProfilesData.GetUserImageAssets(avatarId);
  215. return records;
  216. }
  217. #endregion Utility
  218. #region UserData
  219. public bool RequestUserAppData(ref UserAppData prop, ref string result)
  220. {
  221. return ProfilesData.GetUserAppData(ref prop, ref result);
  222. }
  223. public bool SetUserAppData(UserAppData prop, ref string result)
  224. {
  225. return true;
  226. }
  227. #endregion UserData
  228. }
  229. }