当前位置: 首页>>代码示例>>C#>>正文


C# NetworkClient.SendHandshake方法代码示例

本文整理汇总了C#中Hypercube.Client.NetworkClient.SendHandshake方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkClient.SendHandshake方法的具体用法?C# NetworkClient.SendHandshake怎么用?C# NetworkClient.SendHandshake使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hypercube.Client.NetworkClient的用法示例。


在下文中一共展示了NetworkClient.SendHandshake方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Send

        //TODO: Create a cache system for map sending to cut down on cpu time.
        /// <summary>
        /// Prepares and sends the map to a client.
        /// </summary>
        /// <param name="client"></param>
        public void Send(NetworkClient client)
        {
            if (!Loaded)
                Load();

            if (HCSettings.Motd == null)
                client.SendHandshake();
            else
                client.SendHandshake(HCSettings.Motd);

            var temp = new byte[(CWMap.SizeX * CWMap.SizeY * CWMap.SizeZ) + 4]; // -- Map size, + 4 for the size int.
            var lenBytes = BitConverter.GetBytes(temp.Length - 4); // -- Gets the length (in bytes) of the map, as an int.
            var offset = 4;
            Array.Reverse(lenBytes); // -- Convert it to big-endian

            Buffer.BlockCopy(lenBytes, 0, temp, 0, 4); // -- Copy the length into the block array.

            for (var i = 0; i < CWMap.BlockData.Length - 1; i++) { // -- Get every block, check for CPE replacement, and add it to the array.
                var thisBlock = ServerCore.Blockholder.GetBlock(CWMap.BlockData[i]);

                if (thisBlock.CPELevel > client.CS.CustomBlocksLevel)
                    temp[offset] = (byte)thisBlock.CPEReplace;
                else
                    temp[offset] = thisBlock.OnClient;

                offset += 1;
            }

            temp = GZip.Compress(temp); // -- GZip the map

            var init = new LevelInit();
            client.SendQueue.Enqueue(init);

            offset = 0;

            while (offset != temp.Length) { // -- Write the map chunks
                if (temp.Length - offset > 1024) {
                    var send = new byte[1024];
                    Buffer.BlockCopy(temp, offset, send, 0, 1024);

                    var chunk = new LevelChunk
                    {
                        Length = 1024,
                        Data = send,
                        Percent = (byte) (((float) offset/temp.Length)*100)
                    };
                    client.SendQueue.Enqueue(chunk);

                    offset += 1024;
                } else { // -- Final Chunk, needs to be padded.
                    var send = new byte[1024];
                    Buffer.BlockCopy(temp, offset, send, 0, temp.Length - offset);

                    var chunk = new LevelChunk
                    {
                        Length = (short) ((temp.Length - offset)),
                        Data = send,
                        Percent = (byte) (((float) offset/temp.Length)*100)
                    };
                    client.SendQueue.Enqueue(chunk);

                    offset += chunk.Length;
                }
            }

            var final = new LevelFinalize {SizeX = CWMap.SizeX, SizeY = CWMap.SizeZ, SizeZ = CWMap.SizeY};
            client.SendQueue.Enqueue(final);

            CPE.PostMapActions(client);
            GC.Collect();
        }
开发者ID:umby24,项目名称:Hypercube,代码行数:76,代码来源:HypercubeMap.cs


注:本文中的Hypercube.Client.NetworkClient.SendHandshake方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。