Example #1
0
        public object UserLoginSucceedAck(byte[] data)
        {
            Proto.ByteArray     ba       = new Proto.ByteArray(data);
            Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba);
            ba.Dispose();

            return(snapshot.uid);
        }
Example #2
0
        // 游客信息
        public object UserLoginSucceedAck(byte[] data)
        {
            Proto.ByteArray     ba       = new Proto.ByteArray(data);
            Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba);
            ba.Dispose();
            Debug.Log("Welcome userid: " + snapshot.uid);

            return(null);
        }
Example #3
0
        // 游客信息
        public object UserLoginSucceedAck(byte[] data)
        {
            Proto.ByteArray ba = new Proto.ByteArray(data);
            Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba);
            ba.Dispose();
            Debug.Log("Welcome userid: " + snapshot.uid);

            return null;
        }
Example #4
0
        // 服务器返回密钥并加密连接
        public object GetSeedAck(byte[] data)
        {
            Proto.ByteArray ba = new Proto.ByteArray(data);
            Proto.seed_info si = Proto.seed_info.UnPack(ba);
            ba.Dispose();

            // 启用加密通讯
            NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed);

            return(null);
        }
Example #5
0
        // 服务器返回密钥并加密连接
        public object GetSeedAck(byte[] data)
        {
            Proto.ByteArray ba = new Proto.ByteArray(data);
            Proto.seed_info si = Proto.seed_info.UnPack(ba);
            ba.Dispose();

            // 启用加密通讯
            NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed);

            return null;
        }
Example #6
0
        // 服务器返回公钥
        public object KeyExchangeAck(byte[] data)
        {
            Proto.ByteArray ba = new Proto.ByteArray(data);
            Proto.seed_info si = Proto.seed_info.UnPack(ba);
            ba.Dispose();

            // 启用加密通讯
            NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed);

            // for testing action input
            return(si);
        }
Example #7
0
        // 服务器返回公钥
        public object KeyExchangeAck(byte[] data)
        {
            Proto.ByteArray ba = new Proto.ByteArray(data);
            Proto.seed_info si = Proto.seed_info.UnPack(ba);
            ba.Dispose();

            // 启用加密通讯
            NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed);

            // for testing action input
            return si;
        }
Example #8
0
        public object UserLoginSucceedAck(byte[] data)
        {
            Proto.ByteArray ba = new Proto.ByteArray(data);
            Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba);
            ba.Dispose();

            return snapshot.uid;
        }
Example #9
0
    // 发送数据包
    public void Send(NetProto.Proto.NetBase packet)
    {
        NetProto.Proto.ByteArray ba = new NetProto.Proto.ByteArray();
        packet.Pack(ba);
        byte[] data = ba.Data();
        ba.Dispose();
        Int16 id = packet.NetMsgId;

        seqid++;
        UInt16 payloadSize = 6; // sizeof(seqid) + sizeof(opcode)

        if (data != null)
        {
            if (data.Length > UInt16.MaxValue - 6)
            {
                Debug.LogError(data.Length + " > UInt16.MaxValue-6");
                return;
            }
            payloadSize += (UInt16)data.Length;
        }

        // payload
        byte[] payload = new byte[payloadSize];

        // seqid
        Byte[] _seqid = BitConverter.GetBytes(seqid);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(_seqid);
        }
        _seqid.CopyTo(payload, 0);

        // opcode
        Byte[] _opcode = BitConverter.GetBytes(id);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(_opcode);
        }
        _opcode.CopyTo(payload, 4);

        // data
        if (data != null)
        {
            data.CopyTo(payload, 6);
        }

        // try encrypt
        byte[] encrypted = EncryptStream(payload);

        // =>pack
        byte[] buffer = new byte[2 + payloadSize]; // sizeof(header) + payloadSize

        // =>header
        Byte[] _header = BitConverter.GetBytes(payloadSize);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(_header);
        }
        _header.CopyTo(buffer, 0);

        // =>payload
        encrypted.CopyTo(buffer, 2);

        if (socket.Connected)
        {
            socket.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(SendCallback), socket);
        }
    }
Example #10
0
 public override void Pack(ByteArray w)
 {
 }
Example #11
0
 public override void Pack(ByteArray w)
 {
     w.WriteUnsignedInt(this.id);
 }
Example #12
0
 public override void Pack(ByteArray w)
 {
     w.WriteUTF(this.id);
 }
Example #13
0
 public override void Pack(ByteArray w)
 {
     w.WriteUTF(this.name);
     w.WriteUTF(this.timeStr);
     w.WriteUTF(this.msg);
 }
Example #14
0
 public override void Pack(ByteArray w)
 {
     w.WriteUTF(this.account);
     w.WriteUTF(this.password);
 }
Example #15
0
        public static null_struct UnPack(ByteArray reader)
        {
            null_struct tbl = new null_struct();

            return(tbl);
        }
Example #16
0
    // 发送数据包
    public void Send(NetProto.Api.ENetMsgId msgId, NetProto.Proto.NetBase packet)
    {
        Int16 id = (Int16)msgId;

        seqId++;
        UInt16 payloadSize = 6; // sizeof(seqid) + sizeof(msgid)

        byte[] data = null;

        if (packet != null)
        {
            NetProto.Proto.ByteArray ba = new NetProto.Proto.ByteArray();
            packet.Pack(ba);
            data = ba.Data();
            ba.Dispose();
            if (data.Length > UInt16.MaxValue - 6)
            {
                Debug.LogError(data.Length + " > UInt16.MaxValue-6");
                return;
            }
            payloadSize += (UInt16)data.Length;
        }

        if (_beforeSendHook != null)
        {
            _beforeSendHook(msgId, data);
        }

        // payload
        byte[] payload = new byte[payloadSize];

        // seqid
        Byte[] _seqid = BitConverter.GetBytes(seqId);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(_seqid);
        }
        _seqid.CopyTo(payload, 0);

        // opcode
        Byte[] _opcode = BitConverter.GetBytes(id);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(_opcode);
        }
        _opcode.CopyTo(payload, 4);

        // data
        if (data != null)
        {
            data.CopyTo(payload, 6);
        }

        // try encrypt
        byte[] encrypted = EncryptStream(payload);

        // =>pack
        byte[] buffer = new byte[2 + payloadSize]; // sizeof(header) + payloadSize

        // =>header
        Byte[] _header = BitConverter.GetBytes(payloadSize);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(_header);
        }
        _header.CopyTo(buffer, 0);

        // =>payload
        encrypted.CopyTo(buffer, 2);

        sendDone.Reset();
        try
        {
            socket.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(SendCallback), socket);
        }
        catch (Exception e)
        {
            // 如果socket已经断了,报这个异常
            // System.Net.Sockets.SocketException: The socket is not connected
            Debug.Log(e.ToString());
        }
    }
Example #17
0
 public abstract void Pack(ByteArray w);