aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/SceneManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneManager.cs210
1 files changed, 210 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneManager.cs b/OpenSim/Region/Environment/Scenes/SceneManager.cs
new file mode 100644
index 0000000..9773407
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/SceneManager.cs
@@ -0,0 +1,210 @@
1using System.Collections.Generic;
2using System;
3using OpenSim.Framework.Console;
4using OpenSim.Framework.Types;
5
6namespace OpenSim.Region.Environment.Scenes
7{
8 public class SceneManager
9 {
10 private readonly List<Scene> m_localScenes;
11 private Scene m_currentScene = null;
12 public Scene CurrentScene
13 {
14 get
15 {
16 return m_currentScene;
17 }
18 }
19
20 private Scene CurrentOrFirstScene
21 {
22 get
23 {
24 if (m_currentScene == null)
25 {
26 return m_localScenes[0];
27 }
28 else
29 {
30 return m_currentScene;
31 }
32 }
33 }
34
35 public SceneManager()
36 {
37 m_localScenes = new List<Scene>();
38 }
39
40 public void Close()
41 {
42 for (int i = 0; i < m_localScenes.Count; i++)
43 {
44 m_localScenes[i].Close();
45 }
46 }
47
48 public void Add(Scene scene)
49 {
50 m_localScenes.Add(scene);
51 }
52
53 public void SavePrimsToXml(string filename)
54 {
55 CurrentOrFirstScene.SavePrimsToXml(filename);
56 }
57
58 public void LoadPrimsFromXml(string filename)
59 {
60 CurrentOrFirstScene.LoadPrimsFromXml(filename);
61 }
62
63 public bool RunTerrainCmd(string[] cmdparams, ref string result)
64 {
65 if (m_currentScene == null)
66 {
67 bool success = true;
68 foreach (Scene scene in m_localScenes)
69 {
70 if (!scene.Terrain.RunTerrainCmd(cmdparams, ref result, scene.RegionInfo.RegionName))
71 {
72 success = false;
73 }
74 }
75
76 return success;
77 }
78 else
79 {
80 return m_currentScene.Terrain.RunTerrainCmd(cmdparams, ref result, m_currentScene.RegionInfo.RegionName);
81 }
82 }
83
84 public void SendCommandToScripts(string[] cmdparams)
85 {
86 ForEach(delegate(Scene scene)
87 {
88 scene.SendCommandToScripts(cmdparams);
89 });
90 }
91
92 public void BypassPermissions(bool bypassPermissions)
93 {
94 ForEach(delegate(Scene scene)
95 {
96 scene.PermissionsMngr.BypassPermissions = bypassPermissions;
97 });
98 }
99
100 private void ForEach(Action<Scene> func)
101 {
102 if (m_currentScene == null)
103 {
104 m_localScenes.ForEach(func);
105 }
106 else
107 {
108 func(m_currentScene);
109 }
110 }
111
112 public void Backup()
113 {
114 ForEach(delegate(Scene scene)
115 {
116 scene.Backup();
117 });
118 }
119
120 public void HandleAlertCommand(string[] cmdparams)
121 {
122 ForEach(delegate(Scene scene)
123 {
124 scene.HandleAlertCommand(cmdparams);
125 });
126 }
127
128 public bool TrySetCurrentRegion(string regionName)
129 {
130 if ((String.Compare(regionName, "root") == 0) || (String.Compare(regionName, "..") == 0))
131 {
132 m_currentScene = null;
133 return true;
134 }
135 else
136 {
137 Console.WriteLine("Searching for Region: '" + regionName + "'");
138 Scene foundScene = null;
139
140 foreach (Scene scene in m_localScenes)
141 {
142 if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0)
143 {
144 m_currentScene = scene;
145 return true;
146 }
147 }
148
149 return false;
150 }
151 }
152
153 public void DebugPacket(LogBase log, int newDebug)
154 {
155 ForEach(delegate(Scene scene)
156 {
157 foreach (EntityBase entity in scene.Entities.Values)
158 {
159 if (entity is ScenePresence)
160 {
161 ScenePresence scenePrescence = entity as ScenePresence;
162 if (!scenePrescence.childAgent)
163 {
164 log.Error(String.Format("Packet debug for {0} {1} set to {2}",
165 scenePrescence.Firstname, scenePrescence.Lastname,
166 newDebug));
167
168 scenePrescence.ControllingClient.SetDebug(newDebug);
169 }
170 }
171 }
172 });
173 }
174
175 public List<ScenePresence> GetAvatars()
176 {
177 List<ScenePresence> avatars = new List<ScenePresence>();
178
179 ForEach(delegate(Scene scene)
180 {
181 foreach (EntityBase entity in scene.Entities.Values)
182 {
183 if (entity is ScenePresence)
184 {
185 ScenePresence scenePrescence = entity as ScenePresence;
186 if (!scenePrescence.childAgent)
187 {
188 avatars.Add(scenePrescence);
189 }
190 }
191 }
192 });
193
194 return avatars;
195 }
196
197 public RegionInfo GetRegionInfo(ulong regionHandle)
198 {
199 foreach (Scene scene in m_localScenes)
200 {
201 if( scene.RegionInfo.RegionHandle == regionHandle )
202 {
203 return scene.RegionInfo;
204 }
205 }
206
207 return null;
208 }
209 }
210}