UserProfilesService.cs 9.5 KB

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