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