* Handlerized ViewerEffect

* Now there-is-only-client-manager
* First step towards moving Logout and ConnectionClosed out of Client and into something else (which will let us get rid of ClientView reference to ClientManager
* General posititvity, peace, love and understanding
afrisby
lbsa71 2007-09-18 12:13:44 +00:00
parent a963b3057b
commit 0bac4b430c
10 changed files with 110 additions and 70 deletions

View File

@ -1,15 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using libsecondlife.Packets;
using OpenSim.Framework.Interfaces; using OpenSim.Framework.Interfaces;
namespace OpenSim.Framework namespace OpenSim.Framework
{ {
public delegate void ForEachClientDelegate( IClientAPI client ); public delegate void ForEachClientDelegate(IClientAPI client);
public class ClientManager public class ClientManager
{ {
private Dictionary<uint, IClientAPI> m_clients; private Dictionary<uint, IClientAPI> m_clients;
public void ForEachClient(ForEachClientDelegate whatToDo) public void ForEachClient(ForEachClientDelegate whatToDo)
{ {
foreach (IClientAPI client in m_clients.Values) foreach (IClientAPI client in m_clients.Values)
@ -17,20 +18,59 @@ namespace OpenSim.Framework
whatToDo(client); whatToDo(client);
} }
} }
public ClientManager() public ClientManager()
{ {
m_clients = new Dictionary<uint, IClientAPI>(); m_clients = new Dictionary<uint, IClientAPI>();
} }
public void Remove(uint id) public void Remove(uint id)
{
m_clients.Remove(id);
}
public void Add(uint id, IClientAPI client )
{ {
m_clients.Add( id, client ); m_clients.Remove(id);
}
public void Add(uint id, IClientAPI client)
{
m_clients.Add(id, client);
}
public void InPacket(uint circuitCode, libsecondlife.Packets.Packet packet)
{
IClientAPI client;
if (m_clients.TryGetValue(circuitCode, out client))
{
client.InPacket(packet);
}
}
public void ConnectionClosed(uint circuitCode)
{
IClientAPI client;
if (m_clients.TryGetValue(circuitCode, out client))
{
m_clients.Remove(circuitCode);
client.Close();
// TODO: Now remove all local childagents too
}
}
public void ViewerEffectHandler(IClientAPI sender, ViewerEffectPacket.EffectBlock[] effectBlock)
{
ViewerEffectPacket packet = new ViewerEffectPacket();
packet.Effect = effectBlock;
foreach (IClientAPI client in m_clients.Values)
{
if (client.AgentId != sender.AgentId)
{
packet.AgentData.AgentID = client.AgentId;
packet.AgentData.SessionID = client.SessionId;
client.OutPacket(packet);
}
}
} }
} }
} }

View File

@ -34,6 +34,7 @@ using OpenSim.Framework.Data;
namespace OpenSim.Framework.Interfaces namespace OpenSim.Framework.Interfaces
{ {
public delegate void ViewerEffectEventHandler(IClientAPI sender, ViewerEffectPacket.EffectBlock[] effectBlock);
public delegate void ChatFromViewer(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, LLUUID fromAgentID); public delegate void ChatFromViewer(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, LLUUID fromAgentID);
public delegate void ImprovedInstantMessage(LLUUID fromAgentID, LLUUID fromAgentSession, LLUUID toAgentID, LLUUID imSessionID, uint timestamp, string fromAgentName, string message, byte dialog); // Cut down from full list public delegate void ImprovedInstantMessage(LLUUID fromAgentID, LLUUID fromAgentSession, LLUUID toAgentID, LLUUID imSessionID, uint timestamp, string fromAgentName, string message, byte dialog); // Cut down from full list
public delegate void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos); public delegate void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos);
@ -242,6 +243,7 @@ namespace OpenSim.Framework.Interfaces
void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember, string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL, LLUUID partnerID); void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember, string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL, LLUUID partnerID);
void SetDebug(int newDebug); void SetDebug(int newDebug);
void InPacket(Packet NewPack); void InPacket(Packet NewPack);
void ConnectionClosed(); void Close();
event ViewerEffectEventHandler OnViewerEffect;
} }
} }

View File

@ -52,6 +52,7 @@ namespace OpenSim.Framework
public event StatusChange OnChildAgentStatus; public event StatusChange OnChildAgentStatus;
public event GenericCall2 OnStopMovement; public event GenericCall2 OnStopMovement;
public event GenericCall6 OnRemoveAvatar; public event GenericCall6 OnRemoveAvatar;
public event ViewerEffectEventHandler OnViewerEffect;
public event CreateNewInventoryItem OnCreateNewInventoryItem; public event CreateNewInventoryItem OnCreateNewInventoryItem;
public event CreateInventoryFolder OnCreateNewInventoryFolder; public event CreateInventoryFolder OnCreateNewInventoryFolder;
@ -172,9 +173,11 @@ namespace OpenSim.Framework
{ {
} }
public void ConnectionClosed() public void Close()
{ {
} }
} }
} }

View File

@ -42,6 +42,7 @@ namespace OpenSim.Region.ClientStack
{ {
partial class ClientView partial class ClientView
{ {
public event ViewerEffectEventHandler OnViewerEffect;
public event ImprovedInstantMessage OnInstantMessage; public event ImprovedInstantMessage OnInstantMessage;
public event ChatFromViewer OnChatFromViewer; public event ChatFromViewer OnChatFromViewer;
public event RezObject OnRezObject; public event RezObject OnRezObject;

View File

@ -37,13 +37,28 @@ namespace OpenSim.Region.ClientStack
protected virtual void RegisterLocalPacketHandlers() protected virtual void RegisterLocalPacketHandlers()
{ {
this.AddLocalPacketHandler(PacketType.LogoutRequest, this.Logout); this.AddLocalPacketHandler(PacketType.LogoutRequest, this.Logout);
this.AddLocalPacketHandler(PacketType.ViewerEffect, this.HandleViewerEffect);
this.AddLocalPacketHandler(PacketType.AgentCachedTexture, this.AgentTextureCached); this.AddLocalPacketHandler(PacketType.AgentCachedTexture, this.AgentTextureCached);
this.AddLocalPacketHandler(PacketType.MultipleObjectUpdate, this.MultipleObjUpdate); this.AddLocalPacketHandler(PacketType.MultipleObjectUpdate, this.MultipleObjUpdate);
} }
protected virtual bool Logout(IClientAPI simClient, Packet packet) private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
{ {
MainLog.Instance.Verbose( "OpenSimClient.cs:ProcessInPacket() - Got a logout request"); ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
if( OnViewerEffect != null )
{
OnViewerEffect(sender, viewer.Effect);
}
return true;
}
protected virtual bool Logout(IClientAPI client, Packet packet)
{
// TODO: Refactor out this into an OnLogout so the ClientManager can close all clients.
MainLog.Instance.Verbose("OpenSimClient.cs:ProcessInPacket() - Got a logout request");
//send reply to let the client logout //send reply to let the client logout
LogoutReplyPacket logReply = new LogoutReplyPacket(); LogoutReplyPacket logReply = new LogoutReplyPacket();
logReply.AgentData.AgentID = this.AgentId; logReply.AgentData.AgentID = this.AgentId;
@ -52,8 +67,9 @@ namespace OpenSim.Region.ClientStack
logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock(); logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
logReply.InventoryData[0].ItemID = LLUUID.Zero; logReply.InventoryData[0].ItemID = LLUUID.Zero;
OutPacket(logReply); OutPacket(logReply);
// //
this.KillClient(); this.Close();
return true; return true;
} }
@ -81,7 +97,7 @@ namespace OpenSim.Region.ClientStack
protected bool MultipleObjUpdate(IClientAPI simClient, Packet packet) protected bool MultipleObjUpdate(IClientAPI simClient, Packet packet)
{ {
MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet; MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
// System.Console.WriteLine("new multi update packet " + multipleupdate.ToString()); // System.Console.WriteLine("new multi update packet " + multipleupdate.ToString());
for (int i = 0; i < multipleupdate.ObjectData.Length; i++) for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
{ {
#region position #region position
@ -99,7 +115,7 @@ namespace OpenSim.Region.ClientStack
if (OnUpdatePrimSinglePosition != null) if (OnUpdatePrimSinglePosition != null)
{ {
libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
// System.Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z); // System.Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
OnUpdatePrimSinglePosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this); OnUpdatePrimSinglePosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this);
} }
} }
@ -128,7 +144,7 @@ namespace OpenSim.Region.ClientStack
if (OnUpdatePrimGroupRotation != null) if (OnUpdatePrimGroupRotation != null)
{ {
libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true); libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true);
// Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W); // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
OnUpdatePrimGroupRotation(multipleupdate.ObjectData[i].ObjectLocalID, rot, this); OnUpdatePrimGroupRotation(multipleupdate.ObjectData[i].ObjectLocalID, rot, this);
} }
} }
@ -139,7 +155,7 @@ namespace OpenSim.Region.ClientStack
libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 12, true); libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 12, true);
//Console.WriteLine("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z); //Console.WriteLine("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
// Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W); // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
OnUpdatePrimGroupMouseRotation(multipleupdate.ObjectData[i].ObjectLocalID, pos, rot, this); OnUpdatePrimGroupMouseRotation(multipleupdate.ObjectData[i].ObjectLocalID, pos, rot, this);
} }
} }
@ -164,10 +180,10 @@ namespace OpenSim.Region.ClientStack
if (OnUpdatePrimScale != null) if (OnUpdatePrimScale != null)
{ {
libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12); libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
// Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z ); // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z );
OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this); OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
OnUpdatePrimSinglePosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this); OnUpdatePrimSinglePosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this);
} }
} }
else if (multipleupdate.ObjectData[i].Type == 5)//single prim scale from object tab else if (multipleupdate.ObjectData[i].Type == 5)//single prim scale from object tab
@ -175,7 +191,7 @@ namespace OpenSim.Region.ClientStack
if (OnUpdatePrimScale != null) if (OnUpdatePrimScale != null)
{ {
libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12); libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
// Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this); OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
} }
} }
@ -184,7 +200,7 @@ namespace OpenSim.Region.ClientStack
if (OnUpdatePrimScale != null) if (OnUpdatePrimScale != null)
{ {
libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12); libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
// Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this); OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
} }
} }

View File

@ -75,19 +75,6 @@ namespace OpenSim.Region.ClientStack
switch (Pack.Type) switch (Pack.Type)
{ {
case PacketType.ViewerEffect:
ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
foreach (IClientAPI client in m_clientThreads.Values)
{
if (client.AgentId != this.AgentId)
{
viewer.AgentData.AgentID = client.AgentId;
viewer.AgentData.SessionID = client.SessionId;
client.OutPacket(viewer);
}
}
break;
#region Scene/Avatar #region Scene/Avatar
case PacketType.AvatarPropertiesRequest: case PacketType.AvatarPropertiesRequest:
AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;

View File

@ -71,7 +71,7 @@ namespace OpenSim.Region.ClientStack
private LLUUID newAssetFolder = LLUUID.Zero; private LLUUID newAssetFolder = LLUUID.Zero;
private int debug = 0; private int debug = 0;
protected IScene m_scene; protected IScene m_scene;
private Dictionary<uint, IClientAPI> m_clientThreads; private ClientManager m_clientManager;
private AssetCache m_assetCache; private AssetCache m_assetCache;
// private InventoryCache m_inventoryCache; // private InventoryCache m_inventoryCache;
private int cachedtextureserial = 0; private int cachedtextureserial = 0;
@ -83,12 +83,12 @@ namespace OpenSim.Region.ClientStack
private int probesWithNoIngressPackets = 0; private int probesWithNoIngressPackets = 0;
private int lastPacketsReceived = 0; private int lastPacketsReceived = 0;
public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, Dictionary<uint, IClientAPI> clientThreads, IScene scene, AssetCache assetCache, PacketServer packServer, AgentCircuitManager authenSessions) public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, ClientManager clientManager, IScene scene, AssetCache assetCache, PacketServer packServer, AgentCircuitManager authenSessions)
{ {
m_moneyBalance = 1000; m_moneyBalance = 1000;
m_scene = scene; m_scene = scene;
m_clientThreads = clientThreads; m_clientManager = clientManager;
m_assetCache = assetCache; m_assetCache = assetCache;
m_networkServer = packServer; m_networkServer = packServer;
@ -127,24 +127,17 @@ namespace OpenSim.Region.ClientStack
# region Client Methods # region Client Methods
public void KillClient() public void Close()
{ {
clientPingTimer.Stop(); clientPingTimer.Stop();
m_scene.RemoveClient(this.AgentId); m_scene.RemoveClient(this.AgentId);
m_clientThreads.Remove(this.CircuitCode); m_clientManager.Remove(this.CircuitCode); // TODO: Move out and delete ref to clientmanager.
m_networkServer.RemoveClientCircuit(this.CircuitCode); m_networkServer.RemoveClientCircuit(this.CircuitCode);
this.ClientThread.Abort(); this.ClientThread.Abort();
} }
public void ConnectionClosed()
{
clientPingTimer.Stop();
m_clientThreads.Remove(this.CircuitCode);
m_networkServer.RemoveClientCircuit(this.CircuitCode);
this.ClientThread.Abort();
}
#endregion #endregion
# region Packet Handling # region Packet Handling
@ -259,7 +252,8 @@ namespace OpenSim.Region.ClientStack
probesWithNoIngressPackets++; probesWithNoIngressPackets++;
if (probesWithNoIngressPackets > 30) if (probesWithNoIngressPackets > 30)
{ {
this.KillClient(); // Refactor out this into an OnConnectionClosed so the ClientManager can clean up
this.Close();
} }
else else
{ {

View File

@ -40,7 +40,6 @@ namespace OpenSim.Region.ClientStack
{ {
private ClientStackNetworkHandler _networkHandler; private ClientStackNetworkHandler _networkHandler;
private IScene _localScene; private IScene _localScene;
public Dictionary<uint, IClientAPI> ClientThreads = new Dictionary<uint, IClientAPI>();
private ClientManager m_clientManager = new ClientManager(); private ClientManager m_clientManager = new ClientManager();
public ClientManager ClientManager public ClientManager ClientManager
{ {
@ -66,20 +65,14 @@ namespace OpenSim.Region.ClientStack
/// </summary> /// </summary>
/// <param name="circuitCode"></param> /// <param name="circuitCode"></param>
/// <param name="packet"></param> /// <param name="packet"></param>
public virtual void ClientInPacket(uint circuitCode, Packet packet) public virtual void InPacket(uint circuitCode, Packet packet)
{ {
if (this.ClientThreads.ContainsKey(circuitCode)) m_clientManager.InPacket(circuitCode, packet);
{
ClientThreads[circuitCode].InPacket(packet);
}
} }
public virtual void ConnectionClosed(uint circuitCode) public virtual void ConnectionClosed(uint circuitCode)
{ {
if (this.ClientThreads.ContainsKey(circuitCode)) m_clientManager.ConnectionClosed(circuitCode);
{
ClientThreads[circuitCode].ConnectionClosed();
}
} }
/// <summary> /// <summary>
@ -129,9 +122,9 @@ namespace OpenSim.Region.ClientStack
} }
protected virtual IClientAPI CreateNewClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, Dictionary<uint, IClientAPI> clientThreads, IScene scene, AssetCache assetCache, PacketServer packServer, AgentCircuitManager authenSessions) protected virtual IClientAPI CreateNewClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, ClientManager clientManager, IScene scene, AssetCache assetCache, PacketServer packServer, AgentCircuitManager authenSessions)
{ {
return new ClientView(remoteEP, initialcirpack, clientThreads, scene, assetCache, packServer, authenSessions ); return new ClientView(remoteEP, initialcirpack, clientManager, scene, assetCache, packServer, authenSessions );
} }
/// <summary> /// <summary>
@ -146,15 +139,18 @@ namespace OpenSim.Region.ClientStack
public virtual bool AddNewClient(EndPoint epSender, UseCircuitCodePacket useCircuit, AssetCache assetCache, AgentCircuitManager authenticateSessionsClass) public virtual bool AddNewClient(EndPoint epSender, UseCircuitCodePacket useCircuit, AssetCache assetCache, AgentCircuitManager authenticateSessionsClass)
{ {
IClientAPI newuser = IClientAPI newuser =
CreateNewClient(epSender, useCircuit, ClientThreads, _localScene, assetCache, this, CreateNewClient(epSender, useCircuit, m_clientManager, _localScene, assetCache, this,
authenticateSessionsClass); authenticateSessionsClass);
this.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser); this.m_clientManager.Add(useCircuit.CircuitCode.Code, newuser);
this.m_clientManager.Add(useCircuit.CircuitCode.Code, (IClientAPI)newuser);
newuser.OnViewerEffect += m_clientManager.ViewerEffectHandler;
return true; return true;
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@ -126,7 +126,7 @@ namespace OpenSim.Region.ClientStack
if (this.clientCircuits.ContainsKey(epSender)) if (this.clientCircuits.ContainsKey(epSender))
{ {
//if so then send packet to the packetserver //if so then send packet to the packetserver
this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet); this._packetServer.InPacket(this.clientCircuits[epSender], packet);
} }
else if (packet.Type == PacketType.UseCircuitCode) else if (packet.Type == PacketType.UseCircuitCode)
{ {

View File

@ -43,6 +43,7 @@ namespace SimpleApp
public event UpdateVector OnGrabObject; public event UpdateVector OnGrabObject;
public event ObjectSelect OnDeGrabObject; public event ObjectSelect OnDeGrabObject;
public event MoveObject OnGrabUpdate; public event MoveObject OnGrabUpdate;
public event ViewerEffectEventHandler OnViewerEffect;
public event UpdateShape OnUpdatePrimShape; public event UpdateShape OnUpdatePrimShape;
@ -228,7 +229,7 @@ namespace SimpleApp
{ {
} }
public void ConnectionClosed() public void Close()
{ {
} }
} }