aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Profiles
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Profiles')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Profiles/AvatarProfilesModule.cs145
1 files changed, 145 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Profiles/AvatarProfilesModule.cs b/OpenSim/Region/CoreModules/Avatar/Profiles/AvatarProfilesModule.cs
new file mode 100644
index 0000000..6ea5b56
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Profiles/AvatarProfilesModule.cs
@@ -0,0 +1,145 @@
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 OpenSim 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
28using System;
29using System.Globalization;
30using System.Reflection;
31using OpenMetaverse;
32using log4net;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37
38namespace OpenSim.Region.CoreModules.Avatar.Profiles
39{
40 public class AvatarProfilesModule : IRegionModule
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 private Scene m_scene;
44
45 public AvatarProfilesModule()
46 {
47 }
48
49 #region IRegionModule Members
50
51 public void Initialise(Scene scene, IConfigSource config)
52 {
53 m_scene = scene;
54 m_scene.EventManager.OnNewClient += NewClient;
55 }
56
57 public void PostInitialise()
58 {
59 }
60
61 public void Close()
62 {
63 }
64
65 public string Name
66 {
67 get { return "AvatarProfilesModule"; }
68 }
69
70 public bool IsSharedModule
71 {
72 get { return false; }
73 }
74
75 #endregion
76
77 public void NewClient(IClientAPI client)
78 {
79 client.OnRequestAvatarProperties += RequestAvatarProperty;
80 client.OnUpdateAvatarProperties += UpdateAvatarProperties;
81 }
82
83 public void RemoveClient(IClientAPI client)
84 {
85 client.OnRequestAvatarProperties -= RequestAvatarProperty;
86 client.OnUpdateAvatarProperties -= UpdateAvatarProperties;
87 }
88
89 /// <summary>
90 ///
91 /// </summary>
92 /// <param name="remoteClient"></param>
93 /// <param name="avatarID"></param>
94 public void RequestAvatarProperty(IClientAPI remoteClient, UUID avatarID)
95 {
96 // FIXME: finish adding fields such as url, masking, etc.
97 UserProfileData profile = m_scene.CommsManager.UserService.GetUserProfile(avatarID);
98 if (null != profile)
99 {
100 Byte[] charterMember;
101 if (profile.CustomType == "")
102 {
103 charterMember = new Byte[1];
104 charterMember[0] = (Byte)((profile.UserFlags & 0xf00) >> 8);
105 }
106 else
107 {
108 charterMember = Utils.StringToBytes(profile.CustomType);
109 }
110
111 remoteClient.SendAvatarProperties(profile.ID, profile.AboutText,
112 Util.ToDateTime(profile.Created).ToString("M/d/yyyy", CultureInfo.InvariantCulture),
113 charterMember, profile.FirstLifeAboutText, (uint)(profile.UserFlags & 0xff),
114 profile.FirstLifeImage, profile.Image, String.Empty, profile.Partner);
115 }
116 else
117 {
118 m_log.Debug("[AvatarProfilesModule]: Got null for profile for " + avatarID.ToString());
119 }
120 }
121
122 public void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData newProfile)
123 {
124 UserProfileData Profile = m_scene.CommsManager.UserService.GetUserProfile(newProfile.ID);
125
126 // if it's the profile of the user requesting the update, then we change only a few things.
127 if (remoteClient.AgentId.CompareTo(Profile.ID) == 0)
128 {
129 Profile.Image = newProfile.Image;
130 Profile.FirstLifeImage = newProfile.FirstLifeImage;
131 Profile.AboutText = newProfile.AboutText;
132 Profile.FirstLifeAboutText = newProfile.FirstLifeAboutText;
133 }
134 else
135 {
136 return;
137 }
138
139 if (m_scene.CommsManager.UserService.UpdateUserProfile(Profile))
140 {
141 RequestAvatarProperty(remoteClient, newProfile.ID);
142 }
143 }
144 }
145}