OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
RemoteUserAccountServiceConnector.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 Nini.Config;
30 using log4net;
31 using Mono.Addins;
32 using System.Reflection;
33 using OpenSim.Region.Framework.Interfaces;
34 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Services.Interfaces;
36 using OpenSim.Services.Connectors;
37 using OpenSim.Framework;
38 
39 using OpenMetaverse;
40 
41 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
42 {
43  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteUserAccountServicesConnector")]
46  {
47  private static readonly ILog m_log =
48  LogManager.GetLogger(
49  MethodBase.GetCurrentMethod().DeclaringType);
50 
51  private bool m_Enabled = false;
52  private UserAccountCache m_Cache;
53 
54  public Type ReplaceableInterface
55  {
56  get { return null; }
57  }
58 
59  public string Name
60  {
61  get { return "RemoteUserAccountServicesConnector"; }
62  }
63 
64  public override void Initialise(IConfigSource source)
65  {
66  IConfig moduleConfig = source.Configs["Modules"];
67  if (moduleConfig != null)
68  {
69  string name = moduleConfig.GetString("UserAccountServices", "");
70  if (name == Name)
71  {
72  IConfig userConfig = source.Configs["UserAccountService"];
73  if (userConfig == null)
74  {
75  m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpenSim.ini");
76  return;
77  }
78 
79  m_Enabled = true;
80 
81  base.Initialise(source);
82  m_Cache = new UserAccountCache();
83 
84  m_log.Info("[USER CONNECTOR]: Remote users enabled");
85  }
86  }
87  }
88 
89  public void PostInitialise()
90  {
91  if (!m_Enabled)
92  return;
93  }
94 
95  public void Close()
96  {
97  if (!m_Enabled)
98  return;
99  }
100 
101  public void AddRegion(Scene scene)
102  {
103  if (!m_Enabled)
104  return;
105 
106  scene.RegisterModuleInterface<IUserAccountService>(this);
107  scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
108 
109  scene.EventManager.OnNewClient += OnNewClient;
110  }
111 
112  public void RemoveRegion(Scene scene)
113  {
114  if (!m_Enabled)
115  return;
116  }
117 
118  public void RegionLoaded(Scene scene)
119  {
120  if (!m_Enabled)
121  return;
122  }
123 
124  // When a user actually enters the sim, clear them from
125  // cache so the sim will have the current values for
126  // flags, title, etc. And country, don't forget country!
127  private void OnNewClient(IClientAPI client)
128  {
129  m_Cache.Remove(client.Name);
130  }
131 
132  #region Overwritten methods from IUserAccountService
133 
134  public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
135  {
136  bool inCache = false;
137  UserAccount account = m_Cache.Get(userID, out inCache);
138  if (inCache)
139  return account;
140 
141  account = base.GetUserAccount(scopeID, userID);
142  m_Cache.Cache(userID, account);
143 
144  return account;
145  }
146 
147  public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
148  {
149  bool inCache = false;
150  UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache);
151  if (inCache)
152  return account;
153 
154  account = base.GetUserAccount(scopeID, firstName, lastName);
155  if (account != null)
156  m_Cache.Cache(account.PrincipalID, account);
157 
158  return account;
159  }
160 
161  public override bool StoreUserAccount(UserAccount data)
162  {
163  // This remote connector refuses to serve this method
164  return false;
165  }
166 
167  #endregion
168  }
169 }
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
override bool StoreUserAccount(UserAccount data)
Store the data given, wich replaces the stored data, therefore must be complete.