OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AccessModule.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.Collections.Generic;
30 using System.Reflection;
31 using log4net;
32 using Mono.Addins;
33 using Nini.Config;
34 using OpenMetaverse;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Console;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
40 
41 namespace OpenSim.Region.CoreModules.World
42 {
43  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AccessModule")]
45  {
46 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 
48  private List<Scene> m_SceneList = new List<Scene>();
49 
50  public void Initialise(IConfigSource config)
51  {
52  MainConsole.Instance.Commands.AddCommand("Users", true,
53  "login enable",
54  "login enable",
55  "Enable simulator logins",
56  String.Empty,
57  HandleLoginCommand);
58 
59  MainConsole.Instance.Commands.AddCommand("Users", true,
60  "login disable",
61  "login disable",
62  "Disable simulator logins",
63  String.Empty,
64  HandleLoginCommand);
65 
66  MainConsole.Instance.Commands.AddCommand("Users", true,
67  "login status",
68  "login status",
69  "Show login status",
70  String.Empty,
71  HandleLoginCommand);
72  }
73 
74  public void PostInitialise()
75  {
76  }
77 
78  public void Close()
79  {
80  }
81 
82  public string Name
83  {
84  get { return "AccessModule"; }
85  }
86 
87  public Type ReplaceableInterface
88  {
89  get { return null; }
90  }
91 
92  public void AddRegion(Scene scene)
93  {
94  lock (m_SceneList)
95  {
96  if (!m_SceneList.Contains(scene))
97  m_SceneList.Add(scene);
98  }
99  }
100 
101  public void RemoveRegion(Scene scene)
102  {
103  lock (m_SceneList)
104  m_SceneList.Remove(scene);
105  }
106 
107  public void RegionLoaded(Scene scene)
108  {
109  }
110 
111  public void HandleLoginCommand(string module, string[] cmd)
112  {
113  if ((Scene)MainConsole.Instance.ConsoleScene == null)
114  {
115  foreach (Scene s in m_SceneList)
116  {
117  if (!ProcessCommand(s, cmd))
118  break;
119  }
120  }
121  else
122  {
123  ProcessCommand((Scene)MainConsole.Instance.ConsoleScene, cmd);
124  }
125  }
126 
127  bool ProcessCommand(Scene scene, string[] cmd)
128  {
129  if (cmd.Length < 2)
130  {
131  MainConsole.Instance.Output("Syntax: login enable|disable|status");
132  return false;
133  }
134 
135  switch (cmd[1])
136  {
137  case "enable":
138  scene.LoginsEnabled = true;
139  MainConsole.Instance.Output(String.Format("Logins are enabled for region {0}", scene.RegionInfo.RegionName));
140  break;
141  case "disable":
142  scene.LoginsEnabled = false;
143  MainConsole.Instance.Output(String.Format("Logins are disabled for region {0}", scene.RegionInfo.RegionName));
144  break;
145  case "status":
146  if (scene.LoginsEnabled)
147  MainConsole.Instance.Output(String.Format("Login in {0} are enabled", scene.RegionInfo.RegionName));
148  else
149  MainConsole.Instance.Output(String.Format("Login in {0} are disabled", scene.RegionInfo.RegionName));
150  break;
151  default:
152  MainConsole.Instance.Output("Syntax: login enable|disable|status");
153  return false;
154  }
155 
156  return true;
157  }
158  }
159 }
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
Definition: AccessModule.cs:78
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Definition: AccessModule.cs:92
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 Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
Definition: AccessModule.cs:50
static ICommandConsole Instance
Definition: MainConsole.cs:35
void HandleLoginCommand(string module, string[] cmd)
Interactive OpenSim region server
Definition: OpenSim.cs:55
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...
Definition: AccessModule.cs:74