1
0

UserProfilesService.cs 9.3 KB

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