UserProfilesService.cs 9.4 KB

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