少年修仙传客户端代码仓库
client_Wu Xijin
2018-10-23 930ba67b9f3e4b099f20574319b5d04c2e429552
3335 更新lua库
3个文件已修改
90 ■■■■ 已修改文件
Core/NetworkPackage/GameNetPackBasic.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/Socket/ClientSocketController.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Lua/LuaGameNetSystem.cs 84 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/GameNetPackBasic.cs
@@ -85,7 +85,10 @@
        try
        {
            if (_writedBytes == null)
            {
                _writedBytes = new byte[0];
            }
            byte[] vCmdAndSubCmd = new byte[2];
            vCmdAndSubCmd[0] = (byte)((_cmd & 0xFF00) >> 8);
            vCmdAndSubCmd[1] = (byte)(_cmd & 0xFF);
@@ -104,6 +107,7 @@
                var _lengthBytes = BitConverter.GetBytes((ushort)vCmdAndBody.Length);
                vExCmdAndBody[2] = _lengthBytes[0];
                vExCmdAndBody[3] = _lengthBytes[1];
                Array.Copy(vCmdAndBody, 0, vExCmdAndBody, 4, vCmdAndBody.Length);
                vCmdAndBody = vExCmdAndBody;
            }
Core/NetworkPackage/Socket/ClientSocketController.cs
@@ -329,7 +329,7 @@
        Array.Copy(vMsgBodyLength, 0, vTotal, 2, vMsgBodyLength.Length);
        Array.Copy(vBytes, 0, vTotal, 6, vBytes.Length);
        SendBytes(vBytes);
        SendBytes(vTotal);
    }
    /// <summary>
Lua/LuaGameNetSystem.cs
@@ -8,6 +8,7 @@
public class LuaGameNetPackBase
{
    public ushort cmd = 0;
    public ushort combineCmd = 0;
    List<byte> sendBytes = new List<byte>();
    Action writeBytesAction;
@@ -19,52 +20,113 @@
    public void WriteShortBytes(ushort value, LuaGameNetSystem.NetDataType type)
    {
        sendBytes.AddRange(BitConverter.GetBytes(value));
        byte[] bytes;
        switch (type)
        {
            case LuaGameNetSystem.NetDataType.BYTE:
                bytes = new byte[1];
                bytes[0] = (byte)(value & 0xFF);
                break;
            case LuaGameNetSystem.NetDataType.WORD:
                bytes = BitConverter.GetBytes((short)value);
                break;
            default:
                bytes = BitConverter.GetBytes((int)value);
                break;
        }
        sendBytes.AddRange(bytes);
    }
    public void WriteUintsBytes(uint value, LuaGameNetSystem.NetDataType type)
    {
        sendBytes.AddRange(BitConverter.GetBytes(value));
        byte[] bytes;
        switch (type)
        {
            case LuaGameNetSystem.NetDataType.BYTE:
                bytes = new byte[1];
                bytes[0] = (byte)(value & 0xFF);
                break;
            case LuaGameNetSystem.NetDataType.WORD:
                bytes = BitConverter.GetBytes((short)value);
                break;
            default:
                bytes = BitConverter.GetBytes((int)value);
                break;
        }
        sendBytes.AddRange(bytes);
    }
    public void WriteIntsBytes(int value, LuaGameNetSystem.NetDataType type)
    {
        sendBytes.AddRange(BitConverter.GetBytes(value));
        byte[] bytes;
        switch (type)
        {
            case LuaGameNetSystem.NetDataType.BYTE:
                bytes = new byte[1];
                bytes[0] = (byte)(value & 0xFF);
                break;
            case LuaGameNetSystem.NetDataType.WORD:
                bytes = BitConverter.GetBytes((short)value);
                break;
            default:
                bytes = BitConverter.GetBytes((int)value);
                break;
        }
        sendBytes.AddRange(bytes);
    }
    public void WriteStringBytes(string value, LuaGameNetSystem.NetDataType type)
    public void WriteStringBytes(string value, LuaGameNetSystem.NetDataType type, int length)
    {
        sendBytes.AddRange(stringEncoding.GetBytes(value));
        var bytes = stringEncoding.GetBytes(value);
        if (bytes.Length != length)
        {
            Array.Resize(ref bytes, length);
        }
        sendBytes.AddRange(bytes);
    }
    public void WriteShortsWriteLenBytes(ushort[] values, LuaGameNetSystem.NetDataType type)
    {
        for (var i = 0; i < values.Length; i++)
        {
            sendBytes.AddRange(BitConverter.GetBytes(values[i]));
            WriteShortBytes(values[i], type);
        }
    }
    public void WriteIntsWriteLenBytes(uint[] values, LuaGameNetSystem.NetDataType type)
    public void WriteIntsWriteLenBytes(int[] values, LuaGameNetSystem.NetDataType type)
    {
        for (var i = 0; i < values.Length; i++)
        {
            sendBytes.AddRange(BitConverter.GetBytes(values[i]));
            WriteIntsBytes(values[i], type);
        }
    }
    public void WriteUintsWriteLenBytes(uint[] values, LuaGameNetSystem.NetDataType type)
    {
        for (var i = 0; i < values.Length; i++)
        {
            WriteUintsBytes(values[i], type);
        }
    }
    public void Send()
    {
        sendBytes.AddRange(BitConverter.GetBytes(cmd));
        sendBytes.Add((byte)((cmd & 0xFF00) >> 8));
        sendBytes.Add((byte)(cmd & 0xFF));
        if (writeBytesAction != null)
        {
            writeBytesAction();
        }
        foreach (var item in sendBytes)
        if (combineCmd != 0)
        {
            Debug.Log(item);
            var lengthBytes = BitConverter.GetBytes((ushort)sendBytes.Count);
            sendBytes.Insert(0, lengthBytes[1]);
            sendBytes.Insert(0, lengthBytes[0]);
            sendBytes.Insert(0, (byte)(combineCmd & 0xFF));
            sendBytes.Insert(0, (byte)((combineCmd & 0xFF00) >> 8));
        }
        GameNetSystem.Instance.SendInfo(sendBytes.ToArray());