aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorSean Dague2007-10-21 14:59:18 +0000
committerSean Dague2007-10-21 14:59:18 +0000
commit61397a34105e7aa8353fc661a497fc3d714b582f (patch)
treeeec79315ee4a229c52adb055543277716c3144c7 /OpenSim
parentFixed a situation where a reference to OpenSim.Region.ScriptEngine.DotNetEngi... (diff)
downloadopensim-SC-61397a34105e7aa8353fc661a497fc3d714b582f.zip
opensim-SC-61397a34105e7aa8353fc661a497fc3d714b582f.tar.gz
opensim-SC-61397a34105e7aa8353fc661a497fc3d714b582f.tar.bz2
opensim-SC-61397a34105e7aa8353fc661a497fc3d714b582f.tar.xz
fix line ending mixing. Probably should put some
wiki descriptions up on line endings so we don't keep ending up in this place.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/General/PolicyManager/ACL.cs446
-rw-r--r--OpenSim/Region/Environment/Modules/ChatModule.cs248
-rw-r--r--OpenSim/Region/Environment/PermissionManager.cs2
3 files changed, 348 insertions, 348 deletions
diff --git a/OpenSim/Framework/General/PolicyManager/ACL.cs b/OpenSim/Framework/General/PolicyManager/ACL.cs
index 4f357c4..53c1b2d 100644
--- a/OpenSim/Framework/General/PolicyManager/ACL.cs
+++ b/OpenSim/Framework/General/PolicyManager/ACL.cs
@@ -1,223 +1,223 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4 4
5namespace OpenSim.Framework.PolicyManager 5namespace OpenSim.Framework.PolicyManager
6{ 6{
7 #region ACL Core Class 7 #region ACL Core Class
8 /// <summary> 8 /// <summary>
9 /// Access Control List Engine 9 /// Access Control List Engine
10 /// </summary> 10 /// </summary>
11 public class ACL 11 public class ACL
12 { 12 {
13 Dictionary<string, Role> Roles = new Dictionary<string, Role>(); 13 Dictionary<string, Role> Roles = new Dictionary<string, Role>();
14 Dictionary<string, Resource> Resources = new Dictionary<string, Resource>(); 14 Dictionary<string, Resource> Resources = new Dictionary<string, Resource>();
15 15
16 public ACL AddRole(Role role) 16 public ACL AddRole(Role role)
17 { 17 {
18 if (Roles.ContainsKey(role.Name)) 18 if (Roles.ContainsKey(role.Name))
19 throw new AlreadyContainsRoleException(role); 19 throw new AlreadyContainsRoleException(role);
20 20
21 Roles.Add(role.Name, role); 21 Roles.Add(role.Name, role);
22 22
23 return this; 23 return this;
24 } 24 }
25 25
26 public ACL AddResource(Resource resource) 26 public ACL AddResource(Resource resource)
27 { 27 {
28 Resources.Add(resource.Name, resource); 28 Resources.Add(resource.Name, resource);
29 29
30 return this; 30 return this;
31 } 31 }
32 32
33 public Permission HasPermission(string role, string resource) 33 public Permission HasPermission(string role, string resource)
34 { 34 {
35 if (!Roles.ContainsKey(role)) 35 if (!Roles.ContainsKey(role))
36 throw new KeyNotFoundException(); 36 throw new KeyNotFoundException();
37 37
38 if (!Resources.ContainsKey(resource)) 38 if (!Resources.ContainsKey(resource))
39 throw new KeyNotFoundException(); 39 throw new KeyNotFoundException();
40 40
41 return Roles[role].RequestPermission(resource); 41 return Roles[role].RequestPermission(resource);
42 } 42 }
43 43
44 public ACL GrantPermission(string role, string resource) 44 public ACL GrantPermission(string role, string resource)
45 { 45 {
46 if (!Roles.ContainsKey(role)) 46 if (!Roles.ContainsKey(role))
47 throw new KeyNotFoundException(); 47 throw new KeyNotFoundException();
48 48
49 if (!Resources.ContainsKey(resource)) 49 if (!Resources.ContainsKey(resource))
50 throw new KeyNotFoundException(); 50 throw new KeyNotFoundException();
51 51
52 Roles[role].GivePermission(resource, Permission.Allow); 52 Roles[role].GivePermission(resource, Permission.Allow);
53 53
54 return this; 54 return this;
55 } 55 }
56 56
57 public ACL DenyPermission(string role, string resource) 57 public ACL DenyPermission(string role, string resource)
58 { 58 {
59 if (!Roles.ContainsKey(role)) 59 if (!Roles.ContainsKey(role))
60 throw new KeyNotFoundException(); 60 throw new KeyNotFoundException();
61 61
62 if (!Resources.ContainsKey(resource)) 62 if (!Resources.ContainsKey(resource))
63 throw new KeyNotFoundException(); 63 throw new KeyNotFoundException();
64 64
65 Roles[role].GivePermission(resource, Permission.Deny); 65 Roles[role].GivePermission(resource, Permission.Deny);
66 66
67 return this; 67 return this;
68 } 68 }
69 69
70 public ACL ResetPermission(string role, string resource) 70 public ACL ResetPermission(string role, string resource)
71 { 71 {
72 if (!Roles.ContainsKey(role)) 72 if (!Roles.ContainsKey(role))
73 throw new KeyNotFoundException(); 73 throw new KeyNotFoundException();
74 74
75 if (!Resources.ContainsKey(resource)) 75 if (!Resources.ContainsKey(resource))
76 throw new KeyNotFoundException(); 76 throw new KeyNotFoundException();
77 77
78 Roles[role].GivePermission(resource, Permission.None); 78 Roles[role].GivePermission(resource, Permission.None);
79 79
80 return this; 80 return this;
81 } 81 }
82 } 82 }
83 #endregion 83 #endregion
84 84
85 #region Exceptions 85 #region Exceptions
86 /// <summary> 86 /// <summary>
87 /// Thrown when an ACL attempts to add a duplicate role. 87 /// Thrown when an ACL attempts to add a duplicate role.
88 /// </summary> 88 /// </summary>
89 public class AlreadyContainsRoleException : Exception 89 public class AlreadyContainsRoleException : Exception
90 { 90 {
91 protected Role m_role; 91 protected Role m_role;
92 92
93 public Role ErrorRole 93 public Role ErrorRole
94 { 94 {
95 get { return m_role; } 95 get { return m_role; }
96 } 96 }
97 97
98 public AlreadyContainsRoleException(Role role) 98 public AlreadyContainsRoleException(Role role)
99 { 99 {
100 m_role = role; 100 m_role = role;
101 } 101 }
102 102
103 public override string ToString() 103 public override string ToString()
104 { 104 {
105 return "This ACL already contains a role called '" + m_role.Name + "'."; 105 return "This ACL already contains a role called '" + m_role.Name + "'.";
106 } 106 }
107 } 107 }
108 #endregion 108 #endregion
109 109
110 #region Roles and Resources 110 #region Roles and Resources
111 111
112 /// <summary> 112 /// <summary>
113 /// Does this Role have permission to access a specified Resource? 113 /// Does this Role have permission to access a specified Resource?
114 /// </summary> 114 /// </summary>
115 public enum Permission { Deny, None, Allow }; 115 public enum Permission { Deny, None, Allow };
116 116
117 /// <summary> 117 /// <summary>
118 /// A role class, for use with Users or Groups 118 /// A role class, for use with Users or Groups
119 /// </summary> 119 /// </summary>
120 public class Role 120 public class Role
121 { 121 {
122 private string m_name; 122 private string m_name;
123 private Role[] m_parents; 123 private Role[] m_parents;
124 private Dictionary<string, Permission> m_resources = new Dictionary<string, Permission>(); 124 private Dictionary<string, Permission> m_resources = new Dictionary<string, Permission>();
125 125
126 public string Name 126 public string Name
127 { 127 {
128 get { return m_name; } 128 get { return m_name; }
129 } 129 }
130 130
131 public Permission RequestPermission(string resource) 131 public Permission RequestPermission(string resource)
132 { 132 {
133 return RequestPermission(resource, Permission.None); 133 return RequestPermission(resource, Permission.None);
134 } 134 }
135 135
136 public Permission RequestPermission(string resource, Permission current) 136 public Permission RequestPermission(string resource, Permission current)
137 { 137 {
138 // Deny permissions always override any others 138 // Deny permissions always override any others
139 if (current == Permission.Deny) 139 if (current == Permission.Deny)
140 return current; 140 return current;
141 141
142 Permission temp = Permission.None; 142 Permission temp = Permission.None;
143 143
144 // Pickup non-None permissions 144 // Pickup non-None permissions
145 if (m_resources.ContainsKey(resource) && m_resources[resource] != Permission.None) 145 if (m_resources.ContainsKey(resource) && m_resources[resource] != Permission.None)
146 temp = m_resources[resource]; 146 temp = m_resources[resource];
147 147
148 if (m_parents != null) 148 if (m_parents != null)
149 { 149 {
150 foreach (Role parent in m_parents) 150 foreach (Role parent in m_parents)
151 { 151 {
152 temp = parent.RequestPermission(resource, temp); 152 temp = parent.RequestPermission(resource, temp);
153 } 153 }
154 } 154 }
155 155
156 return temp; 156 return temp;
157 } 157 }
158 158
159 public void GivePermission(string resource, Permission perm) 159 public void GivePermission(string resource, Permission perm)
160 { 160 {
161 m_resources[resource] = perm; 161 m_resources[resource] = perm;
162 } 162 }
163 163
164 public Role(string name) 164 public Role(string name)
165 { 165 {
166 m_name = name; 166 m_name = name;
167 m_parents = null; 167 m_parents = null;
168 } 168 }
169 169
170 public Role(string name, Role[] parents) 170 public Role(string name, Role[] parents)
171 { 171 {
172 m_name = name; 172 m_name = name;
173 m_parents = parents; 173 m_parents = parents;
174 } 174 }
175 } 175 }
176 176
177 public class Resource 177 public class Resource
178 { 178 {
179 private string m_name; 179 private string m_name;
180 180
181 public string Name 181 public string Name
182 { 182 {
183 get { return m_name; } 183 get { return m_name; }
184 } 184 }
185 185
186 public Resource(string name) 186 public Resource(string name)
187 { 187 {
188 m_name = name; 188 m_name = name;
189 } 189 }
190 } 190 }
191 191
192 #endregion 192 #endregion
193 193
194 #region Tests 194 #region Tests
195 195
196 class ACLTester 196 class ACLTester
197 { 197 {
198 public ACLTester() 198 public ACLTester()
199 { 199 {
200 ACL acl = new ACL(); 200 ACL acl = new ACL();
201 201
202 Role Guests = new Role("Guests"); 202 Role Guests = new Role("Guests");
203 acl.AddRole(Guests); 203 acl.AddRole(Guests);
204 204
205 Role[] parents = new Role[0]; 205 Role[] parents = new Role[0];
206 parents[0] = Guests; 206 parents[0] = Guests;
207 207
208 Role JoeGuest = new Role("JoeGuest", parents); 208 Role JoeGuest = new Role("JoeGuest", parents);
209 acl.AddRole(JoeGuest); 209 acl.AddRole(JoeGuest);
210 210
211 Resource CanBuild = new Resource("CanBuild"); 211 Resource CanBuild = new Resource("CanBuild");
212 acl.AddResource(CanBuild); 212 acl.AddResource(CanBuild);
213 213
214 214
215 acl.GrantPermission("Guests", "CanBuild"); 215 acl.GrantPermission("Guests", "CanBuild");
216 216
217 acl.HasPermission("JoeGuest", "CanBuild"); 217 acl.HasPermission("JoeGuest", "CanBuild");
218 218
219 } 219 }
220 } 220 }
221 221
222 #endregion 222 #endregion
223} 223}
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs
index e1a591b..77e038f 100644
--- a/OpenSim/Region/Environment/Modules/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/ChatModule.cs
@@ -41,18 +41,18 @@ using OpenSim.Region.Environment.Scenes;
41namespace OpenSim.Region.Environment.Modules 41namespace OpenSim.Region.Environment.Modules
42{ 42{
43 public class ChatModule : IRegionModule, ISimChat 43 public class ChatModule : IRegionModule, ISimChat
44 { 44 {
45 private List<Scene> m_scenes = new List<Scene>(); 45 private List<Scene> m_scenes = new List<Scene>();
46 private LogBase m_log; 46 private LogBase m_log;
47 47
48 private string m_server = null; 48 private string m_server = null;
49 private int m_port = 6668; 49 private int m_port = 6668;
50 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot"; 50 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
51 private string m_nick = null; 51 private string m_nick = null;
52 private string m_channel = null; 52 private string m_channel = null;
53 53
54 private int m_whisperdistance = 10; 54 private int m_whisperdistance = 10;
55 private int m_saydistance = 30; 55 private int m_saydistance = 30;
56 private int m_shoutdistance = 100; 56 private int m_shoutdistance = 100;
57 57
58 private NetworkStream m_stream; 58 private NetworkStream m_stream;
@@ -71,8 +71,8 @@ namespace OpenSim.Region.Environment.Modules
71 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); 71 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99);
72 m_irc = null; 72 m_irc = null;
73 m_ircWriter = null; 73 m_ircWriter = null;
74 m_ircReader = null; 74 m_ircReader = null;
75 75
76 m_log = OpenSim.Framework.Console.MainLog.Instance; 76 m_log = OpenSim.Framework.Console.MainLog.Instance;
77 } 77 }
78 78
@@ -89,17 +89,17 @@ namespace OpenSim.Region.Environment.Modules
89 } 89 }
90 } catch (Exception e) { 90 } catch (Exception e) {
91 Console.WriteLine("No IRC config information, skipping IRC bridge configuration"); 91 Console.WriteLine("No IRC config information, skipping IRC bridge configuration");
92 } 92 }
93 93
94 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance"); 94 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance");
95 m_saydistance = config.Configs["Chat"].GetInt("say_distance"); 95 m_saydistance = config.Configs["Chat"].GetInt("say_distance");
96 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance"); 96 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance");
97 97
98 if (!m_scenes.Contains(scene)) 98 if (!m_scenes.Contains(scene))
99 { 99 {
100 m_scenes.Add(scene); 100 m_scenes.Add(scene);
101 scene.EventManager.OnNewClient += NewClient; 101 scene.EventManager.OnNewClient += NewClient;
102 scene.RegisterModuleInterface<ISimChat>(this); 102 scene.RegisterModuleInterface<ISimChat>(this);
103 } 103 }
104 } 104 }
105 105
@@ -177,18 +177,18 @@ namespace OpenSim.Region.Environment.Modules
177 Console.WriteLine(inputLine); 177 Console.WriteLine(inputLine);
178 if (inputLine.Contains(m_channel)) 178 if (inputLine.Contains(m_channel))
179 { 179 {
180 string mess = inputLine.Substring(inputLine.IndexOf(m_channel)); 180 string mess = inputLine.Substring(inputLine.IndexOf(m_channel));
181 foreach (Scene m_scene in m_scenes) 181 foreach (Scene m_scene in m_scenes)
182 { 182 {
183 m_scene.Broadcast(delegate(IClientAPI client) 183 m_scene.Broadcast(delegate(IClientAPI client)
184 { 184 {
185 client.SendChatMessage( 185 client.SendChatMessage(
186 Helpers.StringToField(mess), 255, pos, "IRC:", 186 Helpers.StringToField(mess), 255, pos, "IRC:",
187 LLUUID.Zero); 187 LLUUID.Zero);
188 }); 188 });
189 } 189 }
190 } 190 }
191 } 191 }
192 Thread.Sleep(50); 192 Thread.Sleep(50);
193 } 193 }
194 } 194 }
@@ -205,7 +205,7 @@ namespace OpenSim.Region.Environment.Modules
205 scene = m_scenes[0]; 205 scene = m_scenes[0];
206 206
207 // Filled in since it's easier than rewriting right now. 207 // Filled in since it's easier than rewriting right now.
208 LLVector3 fromPos = e.Position; 208 LLVector3 fromPos = e.Position;
209 LLVector3 fromRegionPos = e.Position + new LLVector3(e.Scene.RegionInfo.RegionLocX * 256, e.Scene.RegionInfo.RegionLocY * 256, 0); 209 LLVector3 fromRegionPos = e.Position + new LLVector3(e.Scene.RegionInfo.RegionLocX * 256, e.Scene.RegionInfo.RegionLocY * 256, 0);
210 string fromName = e.From; 210 string fromName = e.From;
211 string message = e.Message; 211 string message = e.Message;
@@ -217,108 +217,108 @@ namespace OpenSim.Region.Environment.Modules
217 217
218 if (avatar != null) 218 if (avatar != null)
219 { 219 {
220 fromPos = avatar.AbsolutePosition; 220 fromPos = avatar.AbsolutePosition;
221 fromRegionPos = fromPos + new LLVector3(e.Scene.RegionInfo.RegionLocX * 256, e.Scene.RegionInfo.RegionLocY * 256, 0); 221 fromRegionPos = fromPos + new LLVector3(e.Scene.RegionInfo.RegionLocX * 256, e.Scene.RegionInfo.RegionLocY * 256, 0);
222 fromName = avatar.Firstname + " " + avatar.Lastname; 222 fromName = avatar.Firstname + " " + avatar.Lastname;
223 fromAgentID = e.Sender.AgentId; 223 fromAgentID = e.Sender.AgentId;
224 avatar = null; 224 avatar = null;
225 } 225 }
226 226
227 string typeName; 227 string typeName;
228 switch (e.Type) 228 switch (e.Type)
229 { 229 {
230 case ChatTypeEnum.Broadcast: 230 case ChatTypeEnum.Broadcast:
231 typeName = "broadcasts"; 231 typeName = "broadcasts";
232 break; 232 break;
233 case ChatTypeEnum.Say: 233 case ChatTypeEnum.Say:
234 typeName = "says"; 234 typeName = "says";
235 break; 235 break;
236 case ChatTypeEnum.Shout: 236 case ChatTypeEnum.Shout:
237 typeName = "shouts"; 237 typeName = "shouts";
238 break; 238 break;
239 case ChatTypeEnum.Whisper: 239 case ChatTypeEnum.Whisper:
240 typeName = "whispers"; 240 typeName = "whispers";
241 break; 241 break;
242 default: 242 default:
243 typeName = "unknown"; 243 typeName = "unknown";
244 break; 244 break;
245 } 245 }
246 246
247 m_log.Verbose("CHAT", fromName + " (" + e.Channel + " @ " + scene.RegionInfo.RegionName + ") " + typeName + ": " + e.Message); 247 m_log.Verbose("CHAT", fromName + " (" + e.Channel + " @ " + scene.RegionInfo.RegionName + ") " + typeName + ": " + e.Message);
248 248
249 if (connected) 249 if (connected)
250 { 250 {
251 try 251 try
252 { 252 {
253 m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + " in " + scene.RegionInfo.RegionName + ">: " + 253 m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + " in " + scene.RegionInfo.RegionName + ">: " +
254 e.Message); 254 e.Message);
255 m_ircWriter.Flush(); 255 m_ircWriter.Flush();
256 } 256 }
257 catch (IOException) 257 catch (IOException)
258 { 258 {
259 m_log.Error("IRC","Disconnected from IRC server."); 259 m_log.Error("IRC","Disconnected from IRC server.");
260 listener.Abort(); 260 listener.Abort();
261 pingSender.Abort(); 261 pingSender.Abort();
262 connected = false; 262 connected = false;
263 }
264 }
265
266 if (e.Channel == 0)
267 {
268 foreach (Scene m_scene in m_scenes)
269 {
270 m_scene.ForEachScenePresence(delegate(ScenePresence presence)
271 {
272 int dis = -100000;
273
274 LLVector3 avatarRegionPos = presence.AbsolutePosition + new LLVector3(scene.RegionInfo.RegionLocX * 256, scene.RegionInfo.RegionLocY * 256, 0);
275 dis = Math.Abs((int)avatarRegionPos.GetDistanceTo(fromRegionPos));
276
277 switch (e.Type)
278 {
279 case ChatTypeEnum.Whisper:
280 if (dis < m_whisperdistance)
281 {
282 //should change so the message is sent through the avatar rather than direct to the ClientView
283 presence.ControllingClient.SendChatMessage(message,
284 type,
285 fromPos,
286 fromName,
287 fromAgentID);
288 }
289 break;
290 default:
291 case ChatTypeEnum.Say:
292 if (dis < m_saydistance)
293 {
294 //Console.WriteLine("sending chat");
295 presence.ControllingClient.SendChatMessage(message,
296 type,
297 fromPos,
298 fromName,
299 fromAgentID);
300 }
301 break;
302 case ChatTypeEnum.Shout:
303 if (dis < m_shoutdistance)
304 {
305 presence.ControllingClient.SendChatMessage(message,
306 type,
307 fromPos,
308 fromName,
309 fromAgentID);
310 }
311 break;
312
313 case ChatTypeEnum.Broadcast:
314 presence.ControllingClient.SendChatMessage(message, type,
315 fromPos,
316 fromName,
317 fromAgentID);
318 break;
319 }
320 });
263 } 321 }
264 }
265
266 if (e.Channel == 0)
267 {
268 foreach (Scene m_scene in m_scenes)
269 {
270 m_scene.ForEachScenePresence(delegate(ScenePresence presence)
271 {
272 int dis = -100000;
273
274 LLVector3 avatarRegionPos = presence.AbsolutePosition + new LLVector3(scene.RegionInfo.RegionLocX * 256, scene.RegionInfo.RegionLocY * 256, 0);
275 dis = Math.Abs((int)avatarRegionPos.GetDistanceTo(fromRegionPos));
276
277 switch (e.Type)
278 {
279 case ChatTypeEnum.Whisper:
280 if (dis < m_whisperdistance)
281 {
282 //should change so the message is sent through the avatar rather than direct to the ClientView
283 presence.ControllingClient.SendChatMessage(message,
284 type,
285 fromPos,
286 fromName,
287 fromAgentID);
288 }
289 break;
290 default:
291 case ChatTypeEnum.Say:
292 if (dis < m_saydistance)
293 {
294 //Console.WriteLine("sending chat");
295 presence.ControllingClient.SendChatMessage(message,
296 type,
297 fromPos,
298 fromName,
299 fromAgentID);
300 }
301 break;
302 case ChatTypeEnum.Shout:
303 if (dis < m_shoutdistance)
304 {
305 presence.ControllingClient.SendChatMessage(message,
306 type,
307 fromPos,
308 fromName,
309 fromAgentID);
310 }
311 break;
312
313 case ChatTypeEnum.Broadcast:
314 presence.ControllingClient.SendChatMessage(message, type,
315 fromPos,
316 fromName,
317 fromAgentID);
318 break;
319 }
320 });
321 }
322 } 322 }
323 } 323 }
324 } 324 }
diff --git a/OpenSim/Region/Environment/PermissionManager.cs b/OpenSim/Region/Environment/PermissionManager.cs
index c856d57..d32ac0b 100644
--- a/OpenSim/Region/Environment/PermissionManager.cs
+++ b/OpenSim/Region/Environment/PermissionManager.cs
@@ -28,7 +28,7 @@
28 28
29using libsecondlife; 29using libsecondlife;
30using OpenSim.Region.Environment.LandManagement; 30using OpenSim.Region.Environment.LandManagement;
31using OpenSim.Region.Environment.Scenes; 31using OpenSim.Region.Environment.Scenes;
32 32
33namespace OpenSim.Region.Environment 33namespace OpenSim.Region.Environment
34{ 34{