本文整理汇总了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();
}