From 561b87b303e8e141ef516b8725ebd3c0be8b1122 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Wed, 11 Jul 2007 02:51:51 +0000 Subject: * Applying dalien's patches from bug#177 and #179 --- OpenSim/Region/ClientStack/ClientView.API.cs | 17 +++++++++ .../ClientStack/ClientView.PacketHandlers.cs | 25 ++------------ .../ClientStack/ClientView.ProcessPackets.cs | 2 +- OpenSim/Region/ClientStack/ClientView.cs | 40 +++++++++++++++++----- OpenSim/Region/ClientStack/ClientViewBase.cs | 3 +- OpenSim/Region/ClientStack/PacketServer.cs | 1 + OpenSim/Region/Environment/Scenes/Scene.cs | 22 ++++++++++++ OpenSim/Region/Environment/Scenes/ScenePresence.cs | 31 +++++++++++++---- 8 files changed, 99 insertions(+), 42 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs index 48d5b9d..225e906 100644 --- a/OpenSim/Region/ClientStack/ClientView.API.cs +++ b/OpenSim/Region/ClientStack/ClientView.API.cs @@ -476,6 +476,23 @@ namespace OpenSim.Region.ClientStack OutPacket(money); } + public void SendStartPingCheck(byte seq) + { + StartPingCheckPacket pc = new StartPingCheckPacket(); + pc.PingID.PingID = seq; + OutPacket(pc); + } + + public void SendKillObject(ulong regionHandle, uint avatarLocalID) + { + KillObjectPacket kill = new KillObjectPacket(); + kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; + kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); + kill.ObjectData[0].ID = avatarLocalID; + OutPacket(kill); + } + + #region Appearance/ Wearables Methods /// diff --git a/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs b/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs index 31ea3eb..e67807e 100644 --- a/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs +++ b/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs @@ -51,29 +51,8 @@ namespace OpenSim.Region.ClientStack logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock(); logReply.InventoryData[0].ItemID = LLUUID.Zero; OutPacket(logReply); - //tell all clients to kill our object - KillObjectPacket kill = new KillObjectPacket(); - kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; - kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); - // kill.ObjectData[0].ID = this.ClientAvatar.localid; - foreach (ClientView client in m_clientThreads.Values) - { - client.OutPacket(kill); - } - - this.m_inventoryCache.ClientLeaving(this.AgentID, null); - - - // m_gridServer.LogoutSession(this.SessionID, this.AgentID, this.CircuitCode); - /*lock (m_world.Entities) - { - m_world.Entities.Remove(this.AgentID); - }*/ - // m_world.RemoveViewerAgent(this); - //need to do other cleaning up here too - m_clientThreads.Remove(this.CircuitCode); - m_networkServer.RemoveClientCircuit(this.CircuitCode); - this.ClientThread.Abort(); + // + this.KillClient(); return true; } diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index 7d924d0..3265898 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs @@ -45,7 +45,7 @@ namespace OpenSim.Region.ClientStack { if (Pack.Type != PacketType.AgentUpdate) { - Console.WriteLine("IN: " + Pack.Type.ToString()); + Console.WriteLine(CircuitCode + ":IN: " + Pack.Type.ToString()); } } diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 52749a1..0fe3884 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ +using System; using System.Collections.Generic; using System.Net; using System.Text; @@ -77,6 +78,11 @@ namespace OpenSim.Region.ClientStack private int cachedtextureserial = 0; protected AuthenticateSessionsBase m_authenticateSessionsHandler; private Encoding enc = Encoding.ASCII; + // Dead client detection vars + private Timer clientPingTimer; + private int packetsReceived = 0; + private int probesWithNoIngressPackets = 0; + private int lastPacketsReceived = 0; public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, Dictionary clientThreads, IWorld world, AssetCache assetCache, PacketServer packServer, InventoryCache inventoryCache, AuthenticateSessionsBase authenSessions ) { @@ -112,15 +118,7 @@ namespace OpenSim.Region.ClientStack public void KillClient() { - KillObjectPacket kill = new KillObjectPacket(); - kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; - kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); - //kill.ObjectData[0].ID = this.ClientAvatar.localid; - foreach (ClientView client in m_clientThreads.Values) - { - client.OutPacket(kill); - } - + clientPingTimer.Stop(); this.m_inventoryCache.ClientLeaving(this.AgentID, null); m_world.RemoveClient(this.AgentId); @@ -193,6 +191,9 @@ namespace OpenSim.Region.ClientStack if (nextPacket.Incoming) { //is a incoming packet + if (nextPacket.Packet.Type != PacketType.AgentUpdate) { + packetsReceived++; + } ProcessInPacket(nextPacket.Packet); } else @@ -204,10 +205,31 @@ namespace OpenSim.Region.ClientStack } # endregion + protected void CheckClientConnectivity(object sender, ElapsedEventArgs e) + { + if (packetsReceived == lastPacketsReceived) { + probesWithNoIngressPackets++; + if (probesWithNoIngressPackets > 30) { + this.KillClient(); + } else { + // this will normally trigger at least one packet (ping response) + SendStartPingCheck(0); + } + } else { + // Something received in the meantime - we can reset the counters + probesWithNoIngressPackets = 0; + lastPacketsReceived = packetsReceived; + } + } + # region Setup protected virtual void InitNewClient() { + clientPingTimer = new Timer(1000); + clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity); + clientPingTimer.Enabled = true; + MainLog.Instance.Verbose( "OpenSimClient.cs:InitNewClient() - Adding viewer agent to world"); this.m_world.AddNewClient(this, false); } diff --git a/OpenSim/Region/ClientStack/ClientViewBase.cs b/OpenSim/Region/ClientStack/ClientViewBase.cs index ec7b039..048f4df 100644 --- a/OpenSim/Region/ClientStack/ClientViewBase.cs +++ b/OpenSim/Region/ClientStack/ClientViewBase.cs @@ -71,8 +71,7 @@ namespace OpenSim.Region.ClientStack // Keep track of when this packet was sent out Pack.TickCount = Environment.TickCount; - - // Console.WriteLine("OUT: " + Pack.Type.ToString()); + Console.WriteLine(CircuitCode + ":OUT: " + Pack.Type.ToString()); if (!Pack.Header.Resent) { diff --git a/OpenSim/Region/ClientStack/PacketServer.cs b/OpenSim/Region/ClientStack/PacketServer.cs index c7ca315..a88c682 100644 --- a/OpenSim/Region/ClientStack/PacketServer.cs +++ b/OpenSim/Region/ClientStack/PacketServer.cs @@ -178,6 +178,7 @@ namespace OpenSim.Region.ClientStack public virtual void RemoveClientCircuit(uint circuitcode) { this._networkHandler.RemoveClientCircuit(circuitcode); + this.m_clientManager.Remove(circuitcode); } } } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index cd81384..d1f6038 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -546,6 +546,28 @@ namespace OpenSim.Region.Environment.Scenes { eventManager.TriggerOnRemovePresence(agentID); + ScenePresence avatar = this.RequestAvatar(agentID); + + m_clientManager.ForEachClient( + delegate(IClientAPI client) + { + client.SendKillObject(avatar.RegionHandle, avatar.LocalId); + }); + + lock (Avatars) { + if (Avatars.ContainsKey(agentID)) { + Avatars.Remove(agentID); + } + } + lock (Entities) { + if (Entities.ContainsKey(agentID)) { + Entities.Remove(agentID); + } + } + // TODO: Add the removal from physics ? + + + return; } #endregion diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 7330bc5..e65ab7c 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -91,6 +91,12 @@ namespace OpenSim.Region.Environment.Scenes return _physActor; } } + + public ulong RegionHandle + { + get { return m_regionHandle; } + } + #endregion #region Constructor(s) @@ -390,6 +396,16 @@ namespace OpenSim.Region.Environment.Scenes remoteAvatar.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture); } + public void SendFullUpdateToALLClients() + { + List avatars = this.m_world.RequestAvatarList(); + foreach (ScenePresence avatar in this.m_world.RequestAvatarList()) + { + this.SendFullUpdateToOtherClient(avatar); + avatar.SendFullUpdateToOtherClient(this); + } + } + /// /// /// @@ -410,6 +426,7 @@ namespace OpenSim.Region.Environment.Scenes public void SendOurAppearance(IClientAPI OurClient) { this.ControllingClient.SendWearables(this.Wearables); + this.SendFullUpdateToALLClients(); this.m_world.SendAllSceneObjectsToClient(this.ControllingClient); } @@ -429,13 +446,13 @@ namespace OpenSim.Region.Environment.Scenes /// public void SendAnimPack(LLUUID animID, int seq) { - this.current_anim = animID; - this.anim_seq = anim_seq; - List avatars = this.m_world.RequestAvatarList(); - for (int i = 0; i < avatars.Count; i++) - { - avatars[i].ControllingClient.SendAnimation(animID, seq, this.ControllingClient.AgentId); - } + this.current_anim = animID; + this.anim_seq = seq; + List avatars = this.m_world.RequestAvatarList(); + for (int i = 0; i < avatars.Count; i++) + { + avatars[i].ControllingClient.SendAnimation(animID, seq, this.ControllingClient.AgentId); + } } /// -- cgit v1.1