* Introduced ClientManager for great justice.

Sugilite
lbsa71 2007-07-09 21:03:36 +00:00
parent 4699efd6cb
commit 08a1fa3f96
7 changed files with 91 additions and 57 deletions

View File

@ -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<uint, IClientAPI> m_clientThreads;
public void ForEachClient(ForEachClientDelegate whatToDo)
{
foreach (IClientAPI client in m_clientThreads.Values)
{
whatToDo(client);
}
}
public ClientManager()
{
m_clientThreads = new Dictionary<uint, IClientAPI>();
}
public void Add(uint id, IClientAPI client )
{
m_clientThreads.Add( id, client );
}
}
}

View File

@ -41,7 +41,7 @@ namespace OpenSim.Region.ClientStack
private ClientStackNetworkHandler _networkHandler;
private IWorld _localWorld;
public Dictionary<uint, ClientView> ClientThreads = new Dictionary<uint, ClientView>();
public Dictionary<uint, IClientAPI> ClientAPIs = new Dictionary<uint, IClientAPI>();
public ClientManager ClientAPIs = new ClientManager();
public PacketServer(ClientStackNetworkHandler networkHandler)
{

View File

@ -43,7 +43,7 @@ namespace OpenSim.Region.Environment.Scenes
{
internal PrimData primData;
private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
// private Dictionary<uint, IClientAPI> m_clientThreads;
// private ClientManager m_clientThreads;
private ulong m_regionHandle;
private const uint FULL_MASK_PERMISSIONS = 2147483647;
private bool physicsEnabled = false;

View File

@ -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;
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);
}
case 0xff: // Broadcast
client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
break;
}
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;
}
});
}
/// <summary>

View File

@ -98,7 +98,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="clientThreads">Dictionary to contain client threads</param>
/// <param name="regionHandle">Region Handle for this region</param>
/// <param name="regionName">Region Name for this region</param>
public Scene(Dictionary<uint, IClientAPI> 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)

View File

@ -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<LLUUID, EntityBase> Entities;
protected Dictionary<uint, IClientAPI> m_clientThreads;
protected ClientManager m_clientThreads;
protected ulong m_regionHandle;
protected string m_regionName;
protected RegionInfo m_regInfo;

View File

@ -15,7 +15,7 @@ namespace SimpleApp
{
private List<ScenePresence> m_avatars;
public MyWorld(Dictionary<uint, IClientAPI> 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<Avatar>();