Пример #1
0
 public virtual void Stop(bool forceStop = false)
 {
     IsPlaying = false;
     BaseFallingPhysics unused = null;
     World.PhysicsBlocks.TryRemove(EntityId, out unused);
     DestroyEntityPacket entity = new DestroyEntityPacket { EntitiesCount = 1, EntitiesId = new []{EntityId}};
     World.Server.SendPacketToNearbyPlayers(World,
                                            UniversalCoords.FromAbsWorld(Position),
                                            entity);
     if (!forceStop)
         OnStop();
 }
Пример #2
0
 private void OnDestroyEntity(DestroyEntityPacket p)
 {
     if (DestroyEntity != null) DestroyEntity.Invoke(this, new PacketEventArgs<DestroyEntityPacket>(p));
 }
Пример #3
0
 public static void ReadDestroyEntity(TestClient client, PacketReader reader)
 {
     DestroyEntityPacket de = new DestroyEntityPacket();
     de.Read(reader);
 }
Пример #4
0
 public virtual void Stop()
 {
     IsPlaying = false;
     BlockBasePhysics unused = null;
     World.PhysicsBlocks.TryRemove(EntityId, out unused);
     DestroyEntityPacket entity = new DestroyEntityPacket { EntityId = EntityId };
     foreach (var nearbyPlayer in World.Server.GetNearbyPlayers(World, new AbsWorldCoords(Position.X, Position.Y, Position.Z)))
     {
         nearbyPlayer.SendPacket(entity);
     }
     OnStop();
 }
Пример #5
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();
        }