Ejemplo n.º 1
0
        public static byte[] c2sSyn()
        {
            byte[] nByte = StructConverter.Pack(0);

            int len = HELLO_STR.Length + nByte.Length;

            byte[] bytes = new byte[len];

            int offset = 0;
            Buffer.BlockCopy(nByte, 0, bytes, 0, nByte.Length);
            offset = offset + nByte.Length;

            byte[] cBytes = System.Text.Encoding.ASCII.GetBytes(HELLO_STR);
            Buffer.BlockCopy(cBytes, 0, bytes, offset, cBytes.Length);

            return bytes;
        }
Ejemplo n.º 2
0
        /*
        public static byte[] c2sReset(int fd, int token)
        {
            return StructConverter.Pack(fd, C2S_RESET, token);
        }

        public static byte[] c2sPing(int fd, int token)
        {
            return StructConverter.Pack(fd, C2S_PING, token);
        }

        public static byte[] s2cSyn(int fd, int token)
        {
            return StructConverter.Pack(S2C_SYN, fd, token);
        }

        public static byte[] s2cAck(int fd, int token)
        {
            return StructConverter.Pack(S2C_ACK, fd, token);
        }

        public static byte[] s2cPingAck()
        {
            return StructConverter.Pack(S2C_PING_ACK);
        }

        public static byte[] s2cRst()
        {
            return StructConverter.Pack(S2C_RST);
        }
        
        public static object[] serverUnpack(byte[] vBytes)
        {
            object[] list = null;
            if (vBytes.Length == 12)
            {
                list = StructConverter.Unpack("<iii", vBytes);
            }
            else if (vBytes.Length == 16)
            {
                list = StructConverter.Unpack("<iiii", vBytes);
            }
            else if (vBytes.Length == 20)
            {
                list = StructConverter.Unpack("<iiiii", vBytes);
            }
            return list;
        }*/
        
        public static KcpStruct clientUnpack(byte[] vBytes)
        {
            int oper = 0;
            StructConverter.Unpack(vBytes, out oper);
            KcpStruct kcp = new KcpStruct(oper);
            switch(oper)
            {
                case S2C_ACK:
                case S2C_RST:
                    break;
                case S2C_SYN:
                    StructConverter.Unpack(vBytes, out kcp.oper, out kcp.fd, out kcp.token);
                    break;
                default:
                    Debug.LogErrorFormat("[UdpMessage] oper {0}", oper);
                    break;
            }
            return kcp;
        }
Ejemplo n.º 3
0
 public static byte[] c2sAck(int fd, int token)
 {
     return StructConverter.Pack(fd, C2S_ACK, token);
 }