From 0bac4b430c264741b7f9e63b5d8fb781ba306c68 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 18 Sep 2007 12:13:44 +0000 Subject: * 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 --- OpenSim/Framework/General/ClientManager.cs | 56 ++++++++++++++++++---- OpenSim/Framework/General/Interfaces/IClientAPI.cs | 4 +- OpenSim/Framework/General/NullClientAPI.cs | 5 +- OpenSim/Region/ClientStack/ClientView.API.cs | 1 + .../ClientStack/ClientView.PacketHandlers.cs | 44 +++++++++++------ .../ClientStack/ClientView.ProcessPackets.cs | 13 ----- OpenSim/Region/ClientStack/ClientView.cs | 20 +++----- OpenSim/Region/ClientStack/PacketServer.cs | 28 +++++------ OpenSim/Region/ClientStack/UDPServer.cs | 2 +- .../Region/Examples/SimpleApp/MyNpcCharacter.cs | 3 +- 10 files changed, 108 insertions(+), 68 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/General/ClientManager.cs b/OpenSim/Framework/General/ClientManager.cs index 0e45d03..274a2d3 100644 --- a/OpenSim/Framework/General/ClientManager.cs +++ b/OpenSim/Framework/General/ClientManager.cs @@ -1,15 +1,16 @@ using System; using System.Collections.Generic; using System.Text; +using libsecondlife.Packets; using OpenSim.Framework.Interfaces; namespace OpenSim.Framework { - public delegate void ForEachClientDelegate( IClientAPI client ); + public delegate void ForEachClientDelegate(IClientAPI client); public class ClientManager { private Dictionary m_clients; - + public void ForEachClient(ForEachClientDelegate whatToDo) { foreach (IClientAPI client in m_clients.Values) @@ -17,20 +18,59 @@ namespace OpenSim.Framework whatToDo(client); } } - + public ClientManager() { m_clients = new Dictionary(); } - 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); + } + + 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 Add(uint id, IClientAPI client ) + public void ViewerEffectHandler(IClientAPI sender, ViewerEffectPacket.EffectBlock[] effectBlock) { - m_clients.Add( id, client ); + 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); + } + } } } } diff --git a/OpenSim/Framework/General/Interfaces/IClientAPI.cs b/OpenSim/Framework/General/Interfaces/IClientAPI.cs index 580a263..9c0771f 100644 --- a/OpenSim/Framework/General/Interfaces/IClientAPI.cs +++ b/OpenSim/Framework/General/Interfaces/IClientAPI.cs @@ -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; } } diff --git a/OpenSim/Framework/General/NullClientAPI.cs b/OpenSim/Framework/General/NullClientAPI.cs index 2b6de9e..2fe46d6 100644 --- a/OpenSim/Framework/General/NullClientAPI.cs +++ b/OpenSim/Framework/General/NullClientAPI.cs @@ -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() { } + + } } diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs index 9d5a9e8..a15a964 100644 --- a/OpenSim/Region/ClientStack/ClientView.API.cs +++ b/OpenSim/Region/ClientStack/ClientView.API.cs @@ -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; diff --git a/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs b/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs index 71fea0d..65ad431 100644 --- a/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs +++ b/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs @@ -37,13 +37,28 @@ 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) { - 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 LogoutReplyPacket logReply = new LogoutReplyPacket(); logReply.AgentData.AgentID = this.AgentId; @@ -52,8 +67,9 @@ namespace OpenSim.Region.ClientStack logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock(); logReply.InventoryData[0].ItemID = LLUUID.Zero; OutPacket(logReply); - // - this.KillClient(); + // + this.Close(); + return true; } @@ -81,7 +97,7 @@ namespace OpenSim.Region.ClientStack protected bool MultipleObjUpdate(IClientAPI simClient, Packet 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++) { #region position @@ -99,7 +115,7 @@ namespace OpenSim.Region.ClientStack if (OnUpdatePrimSinglePosition != null) { 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); } } @@ -128,7 +144,7 @@ namespace OpenSim.Region.ClientStack if (OnUpdatePrimGroupRotation != null) { 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); } } @@ -139,7 +155,7 @@ namespace OpenSim.Region.ClientStack libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); 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 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); } } @@ -164,10 +180,10 @@ namespace OpenSim.Region.ClientStack if (OnUpdatePrimScale != null) { libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12); - // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z ); - OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this); - libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); - OnUpdatePrimSinglePosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this); + // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z ); + OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this); + libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); + OnUpdatePrimSinglePosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this); } } else if (multipleupdate.ObjectData[i].Type == 5)//single prim scale from object tab @@ -175,7 +191,7 @@ namespace OpenSim.Region.ClientStack if (OnUpdatePrimScale != null) { 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); } } @@ -184,7 +200,7 @@ namespace OpenSim.Region.ClientStack if (OnUpdatePrimScale != null) { 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); } } diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index 95ce3c5..009ddac 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs @@ -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; diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 2bff88a..f8ac1d8 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -71,7 +71,7 @@ namespace OpenSim.Region.ClientStack private LLUUID newAssetFolder = LLUUID.Zero; private int debug = 0; protected IScene m_scene; - private Dictionary 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 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 { diff --git a/OpenSim/Region/ClientStack/PacketServer.cs b/OpenSim/Region/ClientStack/PacketServer.cs index 481e445..bceeeb3 100644 --- a/OpenSim/Region/ClientStack/PacketServer.cs +++ b/OpenSim/Region/ClientStack/PacketServer.cs @@ -40,7 +40,6 @@ namespace OpenSim.Region.ClientStack { private ClientStackNetworkHandler _networkHandler; private IScene _localScene; - public Dictionary ClientThreads = new Dictionary(); private ClientManager m_clientManager = new ClientManager(); public ClientManager ClientManager { @@ -66,20 +65,14 @@ namespace OpenSim.Region.ClientStack /// /// /// - 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); } /// @@ -129,9 +122,9 @@ namespace OpenSim.Region.ClientStack } - protected virtual IClientAPI CreateNewClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, Dictionary 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 ); } /// @@ -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; } + + /// /// /// diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index 10ae6ee..efc9c87 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -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) { diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 72a1e19..a055339 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -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() { } } -- cgit v1.1