Пример #1
0
 private void OnPlayerLeft(ClientLeftEventArgs e)
 {
     foreach (EventListener bl in Plugins)
     {
         IPlayerListener pl = (IPlayerListener)bl.Listener;
         if (bl.Event == Event.PlayerLeft)
             pl.OnPlayerLeft(e);
     }
 }
        public void OnPlayerLeft(ClientLeftEventArgs e)
        {
            if (e.EventCanceled || string.IsNullOrEmpty(e.Client.Username))
                return;

            SchematicAction unused;
            if (_plugin.Actions.ContainsKey(e.Client.Username))
                _plugin.Actions.TryRemove(e.Client.Username, out unused);
        }
Пример #3
0
 public void OnPlayerLeft(ClientLeftEventArgs e)
 {
 }
Пример #4
0
        /// <summary>
        /// Disposes associated resources and stops the client.  Also removes the client from the server's client/entity lists.
        /// </summary>
        public void Dispose()
        {
            if (_player != null)
            {
                Server.Logger.Log(LogLevel.Info, "Disposing {0}", _player.DisplayName);
                string disconnectMsg = ChatColor.Yellow + _player.DisplayName + " has left the game.";
                //Event
                ClientLeftEventArgs e = new ClientLeftEventArgs(this);
                Server.PluginManager.CallEvent(Event.PlayerLeft, e);
                //You cant stop the player from leaving so dont try.
                disconnectMsg = e.BrodcastMessage;
                //End Event

                if (_player.LoggedIn)
                {
                    _player.Server.BroadcastSync(disconnectMsg, this);
                    Save();
                }

                Task.Factory.StartNew(() =>
                {
                    foreach (Chunk chunk in _player.LoadedChunks.Values)
                    {
                        if (chunk != null)
                            chunk.RemoveClient(this);
                    }
                });

                Server.RemoveAuthenticatedClient(this);

                Server.Logger.Log(LogLevel.Info, "Clients online: {0}", Server.Clients.Count);
                Server.RemoveEntity(_player, false);

                Client[] nearbyClients = Server.GetNearbyPlayersInternal(_player.World, UniversalCoords.FromAbsWorld(_player.Position)).ToArray();

                foreach (var client in nearbyClients)
                {
                    if (client != this)
                    {
                        DestroyEntityPacket de = new DestroyEntityPacket { EntitiesId = new [] { _player.EntityId } };
                        de.Write();
                        byte[] data = de.GetBuffer();
                        client.Send_Sync(data);
                    }
                }

                _player.LoggedIn = false;
                _player.Ready = false;
                Running = false;

                if (_keepAliveTimer != null)
                {
                    _keepAliveTimer.Dispose();
                    _keepAliveTimer = null;
                }
            }
            else
            {
                Server.Logger.Log(LogLevel.Info, "Disposing {0}", Username);
                Running = false;
                Server.RemoveClient(this);
                Server.Logger.Log(LogLevel.Info, "Clients online: {0}", Server.Clients.Count);
                Server.FreeConnectionSlot();
            }

            _chunkSendTimer.Dispose();
            _chunkSendTimer = null;

            RecvBufferPool.ReleaseBuffer(_recvBuffer);
            SendSocketEventPool.Push(_sendSocketEvent);
            RecvSocketEventPool.Push(_recvSocketEvent);

            if (_socket.Connected)
            {
                try
                {
                    _socket.Shutdown(SocketShutdown.Both);
                }
                catch(SocketException)
                {
                    // Ignore errors in socket shutdown (e.g. if client crashes there is a no connection error when trying to shutdown)
                }
            }
            _socket.Close();

            //GC.Collect();
        }