* 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,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife.Packets;
using OpenSim.Framework.Interfaces;
namespace OpenSim.Framework
@ -32,5 +33,44 @@ namespace OpenSim.Framework
{
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
{
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 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);
@ -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 SetDebug(int newDebug);
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 GenericCall2 OnStopMovement;
public event GenericCall6 OnRemoveAvatar;
public event ViewerEffectEventHandler OnViewerEffect;
public event CreateNewInventoryItem OnCreateNewInventoryItem;
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
{
public event ViewerEffectEventHandler OnViewerEffect;
public event ImprovedInstantMessage OnInstantMessage;
public event ChatFromViewer OnChatFromViewer;
public event RezObject OnRezObject;

View File

@ -37,12 +37,27 @@ namespace OpenSim.Region.ClientStack
protected virtual void RegisterLocalPacketHandlers()
{
this.AddLocalPacketHandler(PacketType.LogoutRequest, this.Logout);
this.AddLocalPacketHandler(PacketType.ViewerEffect, this.HandleViewerEffect);
this.AddLocalPacketHandler(PacketType.AgentCachedTexture, this.AgentTextureCached);
this.AddLocalPacketHandler(PacketType.MultipleObjectUpdate, this.MultipleObjUpdate);
}
protected virtual bool Logout(IClientAPI simClient, Packet packet)
private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
{
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
LogoutReplyPacket logReply = new LogoutReplyPacket();
@ -53,7 +68,8 @@ namespace OpenSim.Region.ClientStack
logReply.InventoryData[0].ItemID = LLUUID.Zero;
OutPacket(logReply);
//
this.KillClient();
this.Close();
return true;
}

View File

@ -75,19 +75,6 @@ namespace OpenSim.Region.ClientStack
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
case PacketType.AvatarPropertiesRequest:
AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;

View File

@ -71,7 +71,7 @@ namespace OpenSim.Region.ClientStack
private LLUUID newAssetFolder = LLUUID.Zero;
private int debug = 0;
protected IScene m_scene;
private Dictionary<uint, IClientAPI> m_clientThreads;
private ClientManager m_clientManager;
private AssetCache m_assetCache;
// private InventoryCache m_inventoryCache;
private int cachedtextureserial = 0;
@ -83,12 +83,12 @@ namespace OpenSim.Region.ClientStack
private int probesWithNoIngressPackets = 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_scene = scene;
m_clientThreads = clientThreads;
m_clientManager = clientManager;
m_assetCache = assetCache;
m_networkServer = packServer;
@ -127,24 +127,17 @@ namespace OpenSim.Region.ClientStack
# region Client Methods
public void KillClient()
public void Close()
{
clientPingTimer.Stop();
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);
this.ClientThread.Abort();
}
public void ConnectionClosed()
{
clientPingTimer.Stop();
m_clientThreads.Remove(this.CircuitCode);
m_networkServer.RemoveClientCircuit(this.CircuitCode);
this.ClientThread.Abort();
}
#endregion
# region Packet Handling
@ -259,7 +252,8 @@ namespace OpenSim.Region.ClientStack
probesWithNoIngressPackets++;
if (probesWithNoIngressPackets > 30)
{
this.KillClient();
// Refactor out this into an OnConnectionClosed so the ClientManager can clean up
this.Close();
}
else
{

View File

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

View File

@ -126,7 +126,7 @@ namespace OpenSim.Region.ClientStack
if (this.clientCircuits.ContainsKey(epSender))
{
//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)
{

View File

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