OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
HGUserManagementModule.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 using System;
28 using System.Collections.Generic;
29 using System.IO;
30 using System.Reflection;
31 
32 using OpenSim.Framework;
33 using OpenSim.Framework.Console;
34 using OpenSim.Region.Framework;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Services.Connectors.Hypergrid;
39 
40 using OpenMetaverse;
41 using OpenMetaverse.Packets;
42 using log4net;
43 using Nini.Config;
44 using Mono.Addins;
45 
46 namespace OpenSim.Region.CoreModules.Framework.UserManagement
47 {
48  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGUserManagementModule")]
50  {
51  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 
53  #region ISharedRegionModule
54 
55  public new void Initialise(IConfigSource config)
56  {
57  string umanmod = config.Configs["Modules"].GetString("UserManagementModule", null);
58  if (umanmod == Name)
59  {
60  m_Enabled = true;
61  Init();
62  m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name);
63  }
64  }
65 
66  public override string Name
67  {
68  get { return "HGUserManagementModule"; }
69  }
70 
71  #endregion ISharedRegionModule
72 
73  protected override void AddAdditionalUsers(string query, List<UserData> users)
74  {
75  if (query.Contains("@")) // First.Last@foo.com, maybe?
76  {
77  string[] words = query.Split(new char[] { '@' });
78  if (words.Length != 2)
79  {
80  m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", query);
81  return;
82  }
83 
84  words[0] = words[0].Trim(); // it has at least 1
85  words[1] = words[1].Trim();
86 
87  if (words[0] == String.Empty) // query was @foo.com?
88  {
89  foreach (UserData d in m_UserCache.Values)
90  {
91  if (d.LastName.ToLower().StartsWith("@" + words[1].ToLower()))
92  users.Add(d);
93  }
94 
95  // We're done
96  return;
97  }
98 
99  // words.Length == 2 and words[0] != string.empty
100  // first.last@foo.com ?
101  foreach (UserData d in m_UserCache.Values)
102  {
103  if (d.LastName.StartsWith("@") &&
104  d.FirstName.ToLower().Equals(words[0].ToLower()) &&
105  d.LastName.ToLower().Equals("@" + words[1].ToLower()))
106  {
107  users.Add(d);
108  // It's cached. We're done
109  return;
110  }
111  }
112 
113  // This is it! Let's ask the other world
114  if (words[0].Contains("."))
115  {
116  string[] names = words[0].Split(new char[] { '.' });
117  if (names.Length >= 2)
118  {
119 
120  string uriStr = "http://" + words[1];
121  // Let's check that the last name is a valid address
122  try
123  {
124  new Uri(uriStr);
125  }
126  catch (UriFormatException)
127  {
128  m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", uriStr);
129  return;
130  }
131 
133 
134  UUID userID = UUID.Zero;
135  try
136  {
137  userID = uasConn.GetUUID(names[0], names[1]);
138  }
139  catch (Exception e)
140  {
141  m_log.Debug("[USER MANAGEMENT MODULE]: GetUUID call failed ", e);
142  }
143 
144  if (!userID.Equals(UUID.Zero))
145  {
146  UserData ud = new UserData();
147  ud.Id = userID;
148  ud.FirstName = words[0];
149  ud.LastName = "@" + words[1];
150  users.Add(ud);
151  // WARNING! that uriStr is not quite right... it may be missing the / at the end,
152  // which will cause trouble (duplicate entries on some tables). We should
153  // get the UUI instead from the UAS. TO BE FIXED.
154  AddUser(userID, names[0], names[1], uriStr);
155  m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} found", words[0], words[1]);
156  }
157  else
158  m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} not found", words[0], words[1]);
159  }
160  }
161  }
162  //else
163  //{
164  // foreach (UserData d in m_UserCache.Values)
165  // {
166  // if (d.LastName.StartsWith("@") &&
167  // (d.FirstName.ToLower().StartsWith(query.ToLower()) ||
168  // d.LastName.ToLower().StartsWith(query.ToLower())))
169  // users.Add(d);
170  // }
171  //}
172  }
173 
174  }
175 }
new void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
override void AddAdditionalUsers(string query, List< UserData > users)
Interactive OpenSim region server
Definition: OpenSim.cs:55
This maintains the relationship between a UUID and a user name.