From 08a1fa3f96eee5e067475da453a3770ff15780f9 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Mon, 9 Jul 2007 21:03:36 +0000 Subject: * Introduced ClientManager for great justice. --- OpenSim/Framework/General/ClientManager.cs | 31 ++++++++ OpenSim/Region/ClientStack/PacketServer.cs | 2 +- OpenSim/Region/Environment/Scenes/PrimitiveOld.cs | 2 +- .../Environment/Scenes/Scene.PacketHandlers.cs | 84 +++++++++++----------- OpenSim/Region/Environment/Scenes/Scene.cs | 28 ++++---- OpenSim/Region/Environment/Scenes/SceneBase.cs | 3 +- OpenSim/Region/Examples/SimpleApp/MyWorld.cs | 2 +- 7 files changed, 93 insertions(+), 59 deletions(-) create mode 100644 OpenSim/Framework/General/ClientManager.cs (limited to 'OpenSim') diff --git a/OpenSim/Framework/General/ClientManager.cs b/OpenSim/Framework/General/ClientManager.cs new file mode 100644 index 0000000..5b6e7b3 --- /dev/null +++ b/OpenSim/Framework/General/ClientManager.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Framework.Interfaces; + +namespace OpenSim.Framework +{ + public delegate void ForEachClientDelegate( IClientAPI client ); + public class ClientManager + { + private Dictionary m_clientThreads; + + public void ForEachClient(ForEachClientDelegate whatToDo) + { + foreach (IClientAPI client in m_clientThreads.Values) + { + whatToDo(client); + } + } + + public ClientManager() + { + m_clientThreads = new Dictionary(); + } + + public void Add(uint id, IClientAPI client ) + { + m_clientThreads.Add( id, client ); + } + } +} diff --git a/OpenSim/Region/ClientStack/PacketServer.cs b/OpenSim/Region/ClientStack/PacketServer.cs index b5f0a02..5e62450 100644 --- a/OpenSim/Region/ClientStack/PacketServer.cs +++ b/OpenSim/Region/ClientStack/PacketServer.cs @@ -41,7 +41,7 @@ namespace OpenSim.Region.ClientStack private ClientStackNetworkHandler _networkHandler; private IWorld _localWorld; public Dictionary ClientThreads = new Dictionary(); - public Dictionary ClientAPIs = new Dictionary(); + public ClientManager ClientAPIs = new ClientManager(); public PacketServer(ClientStackNetworkHandler networkHandler) { diff --git a/OpenSim/Region/Environment/Scenes/PrimitiveOld.cs b/OpenSim/Region/Environment/Scenes/PrimitiveOld.cs index 247ff87..4933b01 100644 --- a/OpenSim/Region/Environment/Scenes/PrimitiveOld.cs +++ b/OpenSim/Region/Environment/Scenes/PrimitiveOld.cs @@ -43,7 +43,7 @@ namespace OpenSim.Region.Environment.Scenes { internal PrimData primData; private LLVector3 positionLastFrame = new LLVector3(0, 0, 0); - // private Dictionary m_clientThreads; + // private ClientManager m_clientThreads; private ulong m_regionHandle; private const uint FULL_MASK_PERMISSIONS = 2147483647; private bool physicsEnabled = false; diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index 6dc9968..bb19996 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -139,48 +139,50 @@ namespace OpenSim.Region.Environment.Scenes { // Console.WriteLine("Chat message"); ScenePresence avatar = null; - foreach (IClientAPI client in m_clientThreads.Values) - { - int dis = -1000; - if (this.Avatars.ContainsKey(client.AgentId)) - { - - avatar = this.Avatars[client.AgentId]; - // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); - dis= (int)avatar.Pos.GetDistanceTo(fromPos); - //Console.WriteLine("found avatar at " +dis); - - } - - switch (type) - { - case 0: // Whisper - if ((dis < 10) && (dis > -10)) - { - //should change so the message is sent through the avatar rather than direct to the ClientView - client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); - } - break; - case 1: // Say - if ((dis < 30) && (dis > -30)) - { - Console.WriteLine("sending chat"); - client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); - } - break; - case 2: // Shout - if ((dis < 100) && (dis > -100)) - { - client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); - } - break; - case 0xff: // Broadcast - client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); - break; - } - - } + m_clientThreads.ForEachClient(delegate(IClientAPI client) + { + int dis = -1000; + if (this.Avatars.ContainsKey(client.AgentId)) + { + avatar = this.Avatars[client.AgentId]; + // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); + dis = (int) avatar.Pos.GetDistanceTo(fromPos); + //Console.WriteLine("found avatar at " +dis); + } + + switch (type) + { + case 0: // Whisper + if ((dis < 10) && (dis > -10)) + { + //should change so the message is sent through the avatar rather than direct to the ClientView + client.SendChatMessage(message, type, fromPos, fromName, + fromAgentID); + } + break; + case 1: // Say + if ((dis < 30) && (dis > -30)) + { + Console.WriteLine("sending chat"); + client.SendChatMessage(message, type, fromPos, fromName, + fromAgentID); + } + break; + case 2: // Shout + if ((dis < 100) && (dis > -100)) + { + client.SendChatMessage(message, type, fromPos, fromName, + fromAgentID); + } + break; + + case 0xff: // Broadcast + client.SendChatMessage(message, type, fromPos, fromName, + fromAgentID); + break; + } + }); } /// diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 5e08d53..043dcd7 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -98,7 +98,7 @@ namespace OpenSim.Region.Environment.Scenes /// Dictionary to contain client threads /// Region Handle for this region /// Region Name for this region - public Scene(Dictionary clientThreads, RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, BaseHttpServer httpServer) + public Scene(ClientManager clientThreads, RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, BaseHttpServer httpServer) { updateLock = new Mutex(false); this.authenticateHandler = authen; @@ -229,11 +229,11 @@ namespace OpenSim.Region.Environment.Scenes } this.localStorage.SaveMap(this.Terrain.getHeights1D()); - foreach (IClientAPI client in m_clientThreads.Values) - { - this.SendLayerData(client); - } - + m_clientThreads.ForEachClient(delegate(IClientAPI client) + { + this.SendLayerData(client); + }); + foreach (LLUUID UUID in Entities.Keys) { Entities[UUID].LandRenegerated(); @@ -260,10 +260,10 @@ namespace OpenSim.Region.Environment.Scenes } this.localStorage.SaveMap(this.Terrain.getHeights1D()); - foreach (IClientAPI client in m_clientThreads.Values) - { - this.SendLayerData(client); - } + m_clientThreads.ForEachClient(delegate(IClientAPI client) + { + this.SendLayerData(client); + }); foreach (LLUUID UUID in Entities.Keys) { @@ -290,10 +290,10 @@ namespace OpenSim.Region.Environment.Scenes { /* Dont save here, rely on tainting system instead */ - foreach (IClientAPI client in m_clientThreads.Values) - { - this.SendLayerData(pointx, pointy, client); - } + m_clientThreads.ForEachClient(delegate(IClientAPI client) + { + this.SendLayerData(pointx, pointy, client); + }); } } catch (Exception e) diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs index 4036743..44121b4 100644 --- a/OpenSim/Region/Environment/Scenes/SceneBase.cs +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs @@ -34,13 +34,14 @@ using OpenSim.Framework.Interfaces; using OpenSim.Framework.Types; using OpenSim.Region.Caches; using OpenSim.Region.Terrain; +using OpenSim.Framework; namespace OpenSim.Region.Environment.Scenes { public abstract class SceneBase : IWorld { public Dictionary Entities; - protected Dictionary m_clientThreads; + protected ClientManager m_clientThreads; protected ulong m_regionHandle; protected string m_regionName; protected RegionInfo m_regInfo; diff --git a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs index da1b43d..b82529a 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs @@ -15,7 +15,7 @@ namespace SimpleApp { private List m_avatars; - public MyWorld(Dictionary clientThreads, RegionInfo regionInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, BaseHttpServer httpServer) + public MyWorld(ClientManager clientThreads, RegionInfo regionInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, BaseHttpServer httpServer) : base(clientThreads, regionInfo, authen, commsMan, assetCach, httpServer) { m_avatars = new List(); -- cgit v1.1