Dispose() public method

public Dispose ( ) : void
return void
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 8
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());
        }
    }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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);
        }
    }