Пример #1
0
        public McpeBatch GetBatch()
        {
            if (_cache != null && _cachedBatch != null)
            {
                return(_cachedBatch);
            }

            McpeFullChunkData fullChunkData = McpeFullChunkData.CreateObject();

            fullChunkData.chunkX          = x;
            fullChunkData.chunkZ          = z;
            fullChunkData.chunkData       = GetBytes();
            fullChunkData.chunkDataLength = fullChunkData.chunkData.Length;
            byte[] bytes = fullChunkData.Encode();
            fullChunkData.PutPool();

            McpeBatch batch = McpeBatch.CreateObject();

            byte[] buffer = Player.CompressBytes(bytes, CompressionLevel.Optimal);
            batch.payloadSize = buffer.Length;
            batch.payload     = buffer;
            batch.Encode();
            batch.MarkPermanent();

            _cachedBatch = batch;

            return(batch);
        }
Пример #2
0
        public void SendLogin(string username)
        {
            Skin skin = new Skin {
                Slim = false, Texture = Encoding.Default.GetBytes(new string('Z', 8192))
            };

            skin.SkinType = "Standard_Custom";
            //Skin skin = new Skin { Slim = false, Texture = Encoding.Default.GetBytes(new string('Z', 16384)) };
            var packet = new McpeLogin()
            {
                username      = username,
                protocol      = 38,
                protocol2     = 38,
                clientId      = ClientId,
                clientUuid    = new UUID(Guid.NewGuid().ToByteArray()),
                serverAddress = _serverEndpoint.Address + ":" + _serverEndpoint.Port,
                clientSecret  = "iwmvi45hm85oncyo58",
                //clientSecret = Encoding.ASCII.GetString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes("" + ClientId + _serverEndpoint.Address + _serverEndpoint.Port))),
                skin = skin,
            };

            byte[] buffer = Player.CompressBytes(packet.Encode(), CompressionLevel.Fastest, true);

            McpeBatch batch = new McpeBatch();

            batch.payloadSize = buffer.Length;
            batch.payload     = buffer;
            batch.Encode();

            SendPackage(batch);
            LoginSent = true;
        }
Пример #3
0
        public McpeBatch GetBatch()
        {
            lock (_cacheSync)
            {
                if (_cache != null && _cachedBatch != null)
                {
                    return(_cachedBatch);
                }

                McpeFullChunkData fullChunkData = McpeFullChunkData.CreateObject();
                fullChunkData.chunkX          = x;
                fullChunkData.chunkZ          = z;
                fullChunkData.order           = 0;
                fullChunkData.chunkData       = GetBytes();
                fullChunkData.chunkDataLength = fullChunkData.chunkData.Length;
                byte[] bytes = fullChunkData.Encode();
                fullChunkData.PutPool();

                MemoryStream memStream = new MemoryStream();
                memStream.Write(BitConverter.GetBytes(Endian.SwapInt32(bytes.Length)), 0, 4);
                memStream.Write(bytes, 0, bytes.Length);

                McpeBatch batch  = McpeBatch.CreateObject();
                byte[]    buffer = Player.CompressBytes(memStream.ToArray(), CompressionLevel.Optimal);
                batch.payloadSize = buffer.Length;
                batch.payload     = buffer;
                batch.Encode();
                batch.MarkPermanent();

                _cachedBatch = batch;

                return(batch);
            }
        }
Пример #4
0
        internal static McpeBatch CreateMcpeBatch(byte[] bytes)
        {
            McpeBatch batch = BatchUtils.CreateBatchPacket(bytes, 0, (int)bytes.Length, CompressionLevel.Optimal, true);

            batch.MarkPermanent();
            batch.Encode();
            return(batch);
        }
Пример #5
0
        public object Clone()
        {
            ChunkColumn cc = (ChunkColumn)MemberwiseClone();

            //public int x;
            //public int z;
            //public bool isDirty;

            //public byte[] biomeId = ArrayOf<byte>.Create(256, 2);
            cc.biomeId = (byte[])biomeId.Clone();

            //public int[] biomeColor = ArrayOf<int>.Create(256, 1);
            cc.biomeColor = (int[])biomeColor.Clone();

            //public byte[] height = ArrayOf<byte>.Create(256, 0);
            cc.height = (byte[])height.Clone();

            //public byte[] blocks = new byte[16 * 16 * 128];
            cc.blocks = (byte[])blocks.Clone();

            //public NibbleArray metadata = new NibbleArray(16 * 16 * 128);
            cc.metadata = (NibbleArray)metadata.Clone();

            //public NibbleArray blocklight = new NibbleArray(16 * 16 * 128);
            cc.blocklight = (NibbleArray)blocklight.Clone();

            //public NibbleArray skylight = new NibbleArray(16 * 16 * 128);
            cc.skylight = (NibbleArray)skylight.Clone();

            //public IDictionary<BlockCoordinates, NbtCompound> BlockEntities = new Dictionary<BlockCoordinates, NbtCompound>();
            cc.BlockEntities = new Dictionary <BlockCoordinates, NbtCompound>();
            foreach (KeyValuePair <BlockCoordinates, NbtCompound> blockEntityPair in BlockEntities)
            {
                cc.BlockEntities.Add(blockEntityPair.Key, (NbtCompound)blockEntityPair.Value.Clone());
            }

            //private byte[] _cache;
            if (_cache != null)
            {
                cc._cache = (byte[])_cache.Clone();
            }

            //private McpeBatch _cachedBatch = null;
            McpeBatch batch = McpeBatch.CreateObject();

            batch.payloadSize = _cachedBatch.payloadSize;
            batch.payload     = _cachedBatch.payload;
            batch.Encode();
            batch.MarkPermanent();

            cc._cachedBatch = batch;

            //private object _cacheSync = new object();
            _cacheSync = new object();

            return(cc);
        }
Пример #6
0
        public void SendMoveList(List <McpeMovePlayer> movePlayerPackages)
        {
            if (!IsConnected)
            {
                return;
            }

            //if (Level.TickTime%4 != 0) return;

            int messageCount = 0;

            MemoryStream stream = new MemoryStream();

            foreach (var movePlayer in movePlayerPackages)
            {
                if (movePlayer.entityId != EntityId)
                {
                    messageCount++;
                    byte[] bytes = movePlayer.Encode();
                    stream.Write(bytes, 0, bytes.Length);
                }

                movePlayer.PutPool();
            }

            if (messageCount > 0)
            {
                McpeBatch batch  = McpeBatch.CreateObject();
                byte[]    buffer = CompressBytes(stream.ToArray());
                batch.payloadSize = buffer.Length;
                batch.payload     = buffer;
                batch.Encode();

                Server.SendPackage(this, new List <Package> {
                    batch
                }, _mtuSize, ref _reliableMessageNumber);
                //Server.SendPackage(EndPoint, messages, _mtuSize, ref _reliableMessageNumber);
            }
        }
Пример #7
0
        public object Clone()
        {
            ChunkColumn cc = (ChunkColumn)MemberwiseClone();

            cc.chunks = new Chunk[16];
            for (int i = 0; i < chunks.Length; i++)
            {
                cc.chunks[i] = (Chunk)chunks[i].Clone();
            }

            cc.biomeId    = (byte[])biomeId.Clone();
            cc.biomeColor = (int[])biomeColor.Clone();
            cc.height     = (byte[])height.Clone();

            cc.BlockEntities = new Dictionary <BlockCoordinates, NbtCompound>();
            foreach (KeyValuePair <BlockCoordinates, NbtCompound> blockEntityPair in BlockEntities)
            {
                cc.BlockEntities.Add(blockEntityPair.Key, (NbtCompound)blockEntityPair.Value.Clone());
            }

            if (_cache != null)
            {
                cc._cache = (byte[])_cache.Clone();
            }

            McpeBatch batch = McpeBatch.CreateObject();

            batch.payload = _cachedBatch.payload;
            batch.Encode();
            batch.MarkPermanent();

            cc._cachedBatch = batch;

            _cacheSync = new object();

            return(cc);
        }
Пример #8
0
        public void SendLogin(string username)
        {
            Skin skin = new Skin {Slim = false, Texture = Encoding.Default.GetBytes(new string('Z', 8192))};
            skin.SkinType = "Standard_Custom";
            //Skin skin = new Skin { Slim = false, Texture = Encoding.Default.GetBytes(new string('Z', 16384)) };
            var packet = new McpeLogin()
            {
                username = username,
                protocol = 39,
                protocol2 = 39,
                clientId = ClientId,
                clientUuid = new UUID(Guid.NewGuid().ToByteArray()),
                serverAddress = _serverEndpoint.Address + ":" + _serverEndpoint.Port,
                clientSecret = "iwmvi45hm85oncyo58",
                //clientSecret = Encoding.ASCII.GetString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes("" + ClientId + _serverEndpoint.Address + _serverEndpoint.Port))),
                skin = skin,
            };

            byte[] buffer = Player.CompressBytes(packet.Encode(), CompressionLevel.Fastest, true);

            McpeBatch batch = new McpeBatch();
            batch.payloadSize = buffer.Length;
            batch.payload = buffer;
            batch.Encode();

            SendPackage(batch);
            LoginSent = true;
        }
Пример #9
0
        private void SendQueue(object sender)
        {
            if (!IsConnected)
            {
                return;
            }

            Queue <Package> queue = _sendQueueNotConcurrent;

            int messageCount = 0;

            int          lenght = queue.Count;
            MemoryStream stream = new MemoryStream();

            for (int i = 0; i < lenght; i++)
            {
                Package package = null;
                lock (_queueSync)
                {
                    if (queue.Count == 0)
                    {
                        break;
                    }
                    try
                    {
                        package = queue.Dequeue();
                    }
                    catch (Exception e)
                    {
                    }
                }

                if (package == null)
                {
                    continue;
                }

                byte[] bytes = package.Encode();
                if (bytes != null)
                {
                    messageCount++;
                    stream.Write(bytes, 0, bytes.Length);
                    package.PutPool();
                }
            }

            if (messageCount == 0)
            {
                return;
            }

            McpeBatch batch = McpeBatch.CreateObject();

            byte[] buffer = CompressBytes(stream.ToArray());
            batch.payloadSize = buffer.Length;
            batch.payload     = buffer;
            batch.Encode();

            Server.SendPackage(this, new List <Package> {
                batch
            }, _mtuSize, ref _reliableMessageNumber);
            //Server.SendPackage(EndPoint, messages, _mtuSize, ref _reliableMessageNumber);
        }