protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { tcp.Close(); tcp = null; if (isJoined) { // send despawn to nearbys Lib.sendToNearby(this.hero, PacketEncoder.despawnEntity(this.hero)); lock (Lib.entityListByMap) { Lib.entityListByMap.GetValueOrDefault(((IEntity)this.hero).map, null)?.Remove(this.hero); } lock (Lib.clientList) { Lib.clientList.Remove(this.hero.heroID); } } aes = null; if (listenerThread != null) { listenerThread = null; } } disposed = true; }