fix line ending mixing. Probably should put some

wiki descriptions up on line endings so we don't keep 
ending up in this place.
afrisby
Sean Dague 2007-10-21 14:59:18 +00:00
parent f6279beafb
commit 61397a3410
3 changed files with 348 additions and 348 deletions

View File

@ -1,223 +1,223 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.PolicyManager
{
#region ACL Core Class
/// <summary>
/// Access Control List Engine
/// </summary>
public class ACL
{
Dictionary<string, Role> Roles = new Dictionary<string, Role>();
Dictionary<string, Resource> Resources = new Dictionary<string, Resource>();
public ACL AddRole(Role role)
{
if (Roles.ContainsKey(role.Name))
throw new AlreadyContainsRoleException(role);
Roles.Add(role.Name, role);
return this;
}
public ACL AddResource(Resource resource)
{
Resources.Add(resource.Name, resource);
return this;
}
public Permission HasPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
return Roles[role].RequestPermission(resource);
}
public ACL GrantPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
Roles[role].GivePermission(resource, Permission.Allow);
return this;
}
public ACL DenyPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
Roles[role].GivePermission(resource, Permission.Deny);
return this;
}
public ACL ResetPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
Roles[role].GivePermission(resource, Permission.None);
return this;
}
}
#endregion
#region Exceptions
/// <summary>
/// Thrown when an ACL attempts to add a duplicate role.
/// </summary>
public class AlreadyContainsRoleException : Exception
{
protected Role m_role;
public Role ErrorRole
{
get { return m_role; }
}
public AlreadyContainsRoleException(Role role)
{
m_role = role;
}
public override string ToString()
{
return "This ACL already contains a role called '" + m_role.Name + "'.";
}
}
#endregion
#region Roles and Resources
/// <summary>
/// Does this Role have permission to access a specified Resource?
/// </summary>
public enum Permission { Deny, None, Allow };
/// <summary>
/// A role class, for use with Users or Groups
/// </summary>
public class Role
{
private string m_name;
private Role[] m_parents;
private Dictionary<string, Permission> m_resources = new Dictionary<string, Permission>();
public string Name
{
get { return m_name; }
}
public Permission RequestPermission(string resource)
{
return RequestPermission(resource, Permission.None);
}
public Permission RequestPermission(string resource, Permission current)
{
// Deny permissions always override any others
if (current == Permission.Deny)
return current;
Permission temp = Permission.None;
// Pickup non-None permissions
if (m_resources.ContainsKey(resource) && m_resources[resource] != Permission.None)
temp = m_resources[resource];
if (m_parents != null)
{
foreach (Role parent in m_parents)
{
temp = parent.RequestPermission(resource, temp);
}
}
return temp;
}
public void GivePermission(string resource, Permission perm)
{
m_resources[resource] = perm;
}
public Role(string name)
{
m_name = name;
m_parents = null;
}
public Role(string name, Role[] parents)
{
m_name = name;
m_parents = parents;
}
}
public class Resource
{
private string m_name;
public string Name
{
get { return m_name; }
}
public Resource(string name)
{
m_name = name;
}
}
#endregion
#region Tests
class ACLTester
{
public ACLTester()
{
ACL acl = new ACL();
Role Guests = new Role("Guests");
acl.AddRole(Guests);
Role[] parents = new Role[0];
parents[0] = Guests;
Role JoeGuest = new Role("JoeGuest", parents);
acl.AddRole(JoeGuest);
Resource CanBuild = new Resource("CanBuild");
acl.AddResource(CanBuild);
acl.GrantPermission("Guests", "CanBuild");
acl.HasPermission("JoeGuest", "CanBuild");
}
}
#endregion
}
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.PolicyManager
{
#region ACL Core Class
/// <summary>
/// Access Control List Engine
/// </summary>
public class ACL
{
Dictionary<string, Role> Roles = new Dictionary<string, Role>();
Dictionary<string, Resource> Resources = new Dictionary<string, Resource>();
public ACL AddRole(Role role)
{
if (Roles.ContainsKey(role.Name))
throw new AlreadyContainsRoleException(role);
Roles.Add(role.Name, role);
return this;
}
public ACL AddResource(Resource resource)
{
Resources.Add(resource.Name, resource);
return this;
}
public Permission HasPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
return Roles[role].RequestPermission(resource);
}
public ACL GrantPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
Roles[role].GivePermission(resource, Permission.Allow);
return this;
}
public ACL DenyPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
Roles[role].GivePermission(resource, Permission.Deny);
return this;
}
public ACL ResetPermission(string role, string resource)
{
if (!Roles.ContainsKey(role))
throw new KeyNotFoundException();
if (!Resources.ContainsKey(resource))
throw new KeyNotFoundException();
Roles[role].GivePermission(resource, Permission.None);
return this;
}
}
#endregion
#region Exceptions
/// <summary>
/// Thrown when an ACL attempts to add a duplicate role.
/// </summary>
public class AlreadyContainsRoleException : Exception
{
protected Role m_role;
public Role ErrorRole
{
get { return m_role; }
}
public AlreadyContainsRoleException(Role role)
{
m_role = role;
}
public override string ToString()
{
return "This ACL already contains a role called '" + m_role.Name + "'.";
}
}
#endregion
#region Roles and Resources
/// <summary>
/// Does this Role have permission to access a specified Resource?
/// </summary>
public enum Permission { Deny, None, Allow };
/// <summary>
/// A role class, for use with Users or Groups
/// </summary>
public class Role
{
private string m_name;
private Role[] m_parents;
private Dictionary<string, Permission> m_resources = new Dictionary<string, Permission>();
public string Name
{
get { return m_name; }
}
public Permission RequestPermission(string resource)
{
return RequestPermission(resource, Permission.None);
}
public Permission RequestPermission(string resource, Permission current)
{
// Deny permissions always override any others
if (current == Permission.Deny)
return current;
Permission temp = Permission.None;
// Pickup non-None permissions
if (m_resources.ContainsKey(resource) && m_resources[resource] != Permission.None)
temp = m_resources[resource];
if (m_parents != null)
{
foreach (Role parent in m_parents)
{
temp = parent.RequestPermission(resource, temp);
}
}
return temp;
}
public void GivePermission(string resource, Permission perm)
{
m_resources[resource] = perm;
}
public Role(string name)
{
m_name = name;
m_parents = null;
}
public Role(string name, Role[] parents)
{
m_name = name;
m_parents = parents;
}
}
public class Resource
{
private string m_name;
public string Name
{
get { return m_name; }
}
public Resource(string name)
{
m_name = name;
}
}
#endregion
#region Tests
class ACLTester
{
public ACLTester()
{
ACL acl = new ACL();
Role Guests = new Role("Guests");
acl.AddRole(Guests);
Role[] parents = new Role[0];
parents[0] = Guests;
Role JoeGuest = new Role("JoeGuest", parents);
acl.AddRole(JoeGuest);
Resource CanBuild = new Resource("CanBuild");
acl.AddResource(CanBuild);
acl.GrantPermission("Guests", "CanBuild");
acl.HasPermission("JoeGuest", "CanBuild");
}
}
#endregion
}

View File

@ -41,18 +41,18 @@ using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Region.Environment.Modules
{
public class ChatModule : IRegionModule, ISimChat
{
private List<Scene> m_scenes = new List<Scene>();
{
private List<Scene> m_scenes = new List<Scene>();
private LogBase m_log;
private string m_server = null;
private int m_port = 6668;
private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
private string m_nick = null;
private string m_channel = null;
private int m_whisperdistance = 10;
private int m_saydistance = 30;
private string m_channel = null;
private int m_whisperdistance = 10;
private int m_saydistance = 30;
private int m_shoutdistance = 100;
private NetworkStream m_stream;
@ -71,8 +71,8 @@ namespace OpenSim.Region.Environment.Modules
m_nick = "OSimBot" + Util.RandomClass.Next(1, 99);
m_irc = null;
m_ircWriter = null;
m_ircReader = null;
m_ircReader = null;
m_log = OpenSim.Framework.Console.MainLog.Instance;
}
@ -89,17 +89,17 @@ namespace OpenSim.Region.Environment.Modules
}
} catch (Exception e) {
Console.WriteLine("No IRC config information, skipping IRC bridge configuration");
}
m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance");
m_saydistance = config.Configs["Chat"].GetInt("say_distance");
m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance");
if (!m_scenes.Contains(scene))
{
m_scenes.Add(scene);
scene.EventManager.OnNewClient += NewClient;
scene.RegisterModuleInterface<ISimChat>(this);
}
m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance");
m_saydistance = config.Configs["Chat"].GetInt("say_distance");
m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance");
if (!m_scenes.Contains(scene))
{
m_scenes.Add(scene);
scene.EventManager.OnNewClient += NewClient;
scene.RegisterModuleInterface<ISimChat>(this);
}
}
@ -177,18 +177,18 @@ namespace OpenSim.Region.Environment.Modules
Console.WriteLine(inputLine);
if (inputLine.Contains(m_channel))
{
string mess = inputLine.Substring(inputLine.IndexOf(m_channel));
foreach (Scene m_scene in m_scenes)
{
m_scene.Broadcast(delegate(IClientAPI client)
{
client.SendChatMessage(
Helpers.StringToField(mess), 255, pos, "IRC:",
LLUUID.Zero);
});
string mess = inputLine.Substring(inputLine.IndexOf(m_channel));
foreach (Scene m_scene in m_scenes)
{
m_scene.Broadcast(delegate(IClientAPI client)
{
client.SendChatMessage(
Helpers.StringToField(mess), 255, pos, "IRC:",
LLUUID.Zero);
});
}
}
}
}
Thread.Sleep(50);
}
}
@ -205,7 +205,7 @@ namespace OpenSim.Region.Environment.Modules
scene = m_scenes[0];
// Filled in since it's easier than rewriting right now.
LLVector3 fromPos = e.Position;
LLVector3 fromPos = e.Position;
LLVector3 fromRegionPos = e.Position + new LLVector3(e.Scene.RegionInfo.RegionLocX * 256, e.Scene.RegionInfo.RegionLocY * 256, 0);
string fromName = e.From;
string message = e.Message;
@ -217,108 +217,108 @@ namespace OpenSim.Region.Environment.Modules
if (avatar != null)
{
fromPos = avatar.AbsolutePosition;
fromPos = avatar.AbsolutePosition;
fromRegionPos = fromPos + new LLVector3(e.Scene.RegionInfo.RegionLocX * 256, e.Scene.RegionInfo.RegionLocY * 256, 0);
fromName = avatar.Firstname + " " + avatar.Lastname;
fromAgentID = e.Sender.AgentId;
avatar = null;
}
string typeName;
switch (e.Type)
{
case ChatTypeEnum.Broadcast:
typeName = "broadcasts";
break;
case ChatTypeEnum.Say:
typeName = "says";
break;
case ChatTypeEnum.Shout:
typeName = "shouts";
break;
case ChatTypeEnum.Whisper:
typeName = "whispers";
break;
default:
typeName = "unknown";
break;
}
}
string typeName;
switch (e.Type)
{
case ChatTypeEnum.Broadcast:
typeName = "broadcasts";
break;
case ChatTypeEnum.Say:
typeName = "says";
break;
case ChatTypeEnum.Shout:
typeName = "shouts";
break;
case ChatTypeEnum.Whisper:
typeName = "whispers";
break;
default:
typeName = "unknown";
break;
}
m_log.Verbose("CHAT", fromName + " (" + e.Channel + " @ " + scene.RegionInfo.RegionName + ") " + typeName + ": " + e.Message);
if (connected)
{
try
{
m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + " in " + scene.RegionInfo.RegionName + ">: " +
e.Message);
m_ircWriter.Flush();
}
catch (IOException)
{
m_log.Error("IRC","Disconnected from IRC server.");
listener.Abort();
pingSender.Abort();
connected = false;
{
try
{
m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + " in " + scene.RegionInfo.RegionName + ">: " +
e.Message);
m_ircWriter.Flush();
}
catch (IOException)
{
m_log.Error("IRC","Disconnected from IRC server.");
listener.Abort();
pingSender.Abort();
connected = false;
}
}
if (e.Channel == 0)
{
foreach (Scene m_scene in m_scenes)
{
m_scene.ForEachScenePresence(delegate(ScenePresence presence)
{
int dis = -100000;
LLVector3 avatarRegionPos = presence.AbsolutePosition + new LLVector3(scene.RegionInfo.RegionLocX * 256, scene.RegionInfo.RegionLocY * 256, 0);
dis = Math.Abs((int)avatarRegionPos.GetDistanceTo(fromRegionPos));
switch (e.Type)
{
case ChatTypeEnum.Whisper:
if (dis < m_whisperdistance)
{
//should change so the message is sent through the avatar rather than direct to the ClientView
presence.ControllingClient.SendChatMessage(message,
type,
fromPos,
fromName,
fromAgentID);
}
break;
default:
case ChatTypeEnum.Say:
if (dis < m_saydistance)
{
//Console.WriteLine("sending chat");
presence.ControllingClient.SendChatMessage(message,
type,
fromPos,
fromName,
fromAgentID);
}
break;
case ChatTypeEnum.Shout:
if (dis < m_shoutdistance)
{
presence.ControllingClient.SendChatMessage(message,
type,
fromPos,
fromName,
fromAgentID);
}
break;
case ChatTypeEnum.Broadcast:
presence.ControllingClient.SendChatMessage(message, type,
fromPos,
fromName,
fromAgentID);
break;
}
});
}
}
if (e.Channel == 0)
{
foreach (Scene m_scene in m_scenes)
{
m_scene.ForEachScenePresence(delegate(ScenePresence presence)
{
int dis = -100000;
LLVector3 avatarRegionPos = presence.AbsolutePosition + new LLVector3(scene.RegionInfo.RegionLocX * 256, scene.RegionInfo.RegionLocY * 256, 0);
dis = Math.Abs((int)avatarRegionPos.GetDistanceTo(fromRegionPos));
switch (e.Type)
{
case ChatTypeEnum.Whisper:
if (dis < m_whisperdistance)
{
//should change so the message is sent through the avatar rather than direct to the ClientView
presence.ControllingClient.SendChatMessage(message,
type,
fromPos,
fromName,
fromAgentID);
}
break;
default:
case ChatTypeEnum.Say:
if (dis < m_saydistance)
{
//Console.WriteLine("sending chat");
presence.ControllingClient.SendChatMessage(message,
type,
fromPos,
fromName,
fromAgentID);
}
break;
case ChatTypeEnum.Shout:
if (dis < m_shoutdistance)
{
presence.ControllingClient.SendChatMessage(message,
type,
fromPos,
fromName,
fromAgentID);
}
break;
case ChatTypeEnum.Broadcast:
presence.ControllingClient.SendChatMessage(message, type,
fromPos,
fromName,
fromAgentID);
break;
}
});
}
}
}
}

View File

@ -28,7 +28,7 @@
using libsecondlife;
using OpenSim.Region.Environment.LandManagement;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Region.Environment
{