Ejemplo n.º 1
0
        public string Read_str()
        {
            ushort len = Read_ushort();

            byte[] bytes = Read_bytes(len);
            return(ByteAr_b.b2str(bytes));;
        }
Ejemplo n.º 2
0
        private void ReceiveBodyCallback(IAsyncResult ar)
        {
            try
            {
                OnInfo("--------------------start ReceiveBodyCallback");

                if (!this.socket.Connected)
                {
                    return;
                }

                int count = this.socket.EndReceive(ar);


                if (count == 0)
                {
                    OnError("ReceiveBodyCallback:socket receive 0");
                    return;
                }

                this.readBytes += count;
                if (this.readBytes < this.bodyBuf.Length)
                {
                    this.BeginReceiveBody(this.readBytes);
                    return;
                }

                byte[] bytes_cmdid = new byte[2];
                byte[] bytes_seq   = new byte[4];
                byte[] bytes_body  = new byte[bodyBuf.Length - 6];
                ByteAr_b.PickBytes(this.bodyBuf, bytes_cmdid.Length, bytes_cmdid, 0);
                ByteAr_b.PickBytes(this.bodyBuf, bytes_seq.Length, bytes_seq, 2);
                ByteAr_b.PickBytes(this.bodyBuf, bytes_body.Length, bytes_body, bytes_cmdid.Length + bytes_seq.Length);

                if (ByteAr_b.b2us(bytes_cmdid) == 0xa10b)
                {
                    PswCode = ByteAr_b.b2i(bytes_body);
                }
                else
                {
                    this.OnReceived(this.bodyBuf);

/*					Pt pt = ptMng.GetInstance().MakePt(ByteAr_b.b2us(bytes_cmdid),ByteAr_b.b2ui(bytes_seq), bytes_body);
 *
 *                      if (pt == null)
 *                          OnError("Receive unknow pt pt_id = " + ByteAr_b.b2us(bytes_cmdid));
 *                      else
 *                      {
 *                          pt.seq = ByteAr_b.b2ui(bytes_seq);
 *                      this.OnReceived(pt);
 *                      }*/
                }

                this.BeginReceiveHeader(0);
            }
            catch (Exception e)
            {
                OnError("ReceiveBodyCallback:socket catch" + e.Message);
            }
        }
Ejemplo n.º 3
0
        public byte[] Read_bytes(int len)
        {
            if (this.data.Length < read_indx + len)
            {
                return(null);
            }

            byte[] getbytes = new byte[len];
            ByteAr_b.PickBytes(this.data, len, getbytes, read_indx);
            read_indx += len;
            return(getbytes);
        }
Ejemplo n.º 4
0
        public void Send(Pt pt)
        {
            if (pt == null)
            {
                OnInfo("--------------------error pt");
                return;
            }

            byte[] data = pt.toBinary();
            OnInfo("--------------------start send:" + (data.Length + 10));

            if ((this.socket == null) || (!this.socket.Connected))
            {
                OnInfo("--------------------send,no net");
                return;
            }

            int allLen = data.Length + 10;

            allLen = allLen ^ PswCode;
            byte[] bytesLen = ByteAr_b.i2b(allLen);
            byte[] bytesPt  = ByteAr_b.s2b(pt.GetID());
            byte[] bytesSeq = ByteAr_b.i2b(pt.seq);


            byte[] allData = new byte[data.Length + 10];
            Array.Copy(bytesLen, 0, allData, 0, bytesLen.Length);
            Array.Copy(bytesPt, 0, allData, bytesLen.Length, bytesPt.Length);
            Array.Copy(bytesSeq, 0, allData, bytesLen.Length + bytesPt.Length, bytesSeq.Length);
            Array.Copy(data, 0, allData, bytesLen.Length + bytesPt.Length + bytesSeq.Length, data.Length);

            lock (send_buf)
            {
                if (send_len == 0)
                {
                    allData.CopyTo(send_buf, send_len);
                    send_len = send_len + allData.Length;
                    BeginSend();
                }
                else
                {
                    allData.CopyTo(send_buf, send_len);
                    send_len = send_len + allData.Length;
                }
            }
        }
Ejemplo n.º 5
0
    public static void Update()
    {
        if (unHandMsgList != null)
        {
            while (unHandMsgList.Count > 0)
            {
                Pt pt = null;
                if (unHandMsgList.Count > 0)
                {
                    lock (unHandMsgList)
                    {
                        byte[] bts         = unHandMsgList.Dequeue();
                        byte[] bytes_cmdid = new byte[2];
                        byte[] bytes_seq   = new byte[4];
                        byte[] bytes_body  = new byte[bts.Length - 6];
                        ByteAr_b.PickBytes(bts, bytes_cmdid.Length, bytes_cmdid, 0);
                        ByteAr_b.PickBytes(bts, bytes_seq.Length, bytes_seq, 2);
                        ByteAr_b.PickBytes(bts, bytes_body.Length, bytes_body, bytes_cmdid.Length + bytes_seq.Length);

                        ushort head = ByteAr_b.b2us(bytes_cmdid);
                        if (msgStructDic.ContainsKey(head))
                        {
                            pt     = msgStructDic[head].createNew();
                            pt.seq = ByteAr_b.b2ui(bytes_seq);
                            pt.fromBinary(bytes_body);
                        }
                    }
                }

                if (pt != null)
                {
                    if (screen_Debug_Log_S2C)
                    {
                        GameSys.LogInternal("[S] to [C] :" + Convert.ToString(pt.GetID(), 16), false);
                    }
                    if (editor_Debug_Log_S2C)
                    {
                        Debug.Log("[S] to [C] :" + Convert.ToString(pt.GetID(), 16));
                    }
                    MsgHander.ProcComand(pt);
                }
            }
        }
    }
Ejemplo n.º 6
0
        private void ReceiveHeaderCallback(IAsyncResult ar)
        {
            try
            {
                OnInfo("--------------------start ReceiveHeaderCallback");

                if (!this.socket.Connected)
                {
                    OnError("ReceiveHeaderCallback socket not connected");
                    return;
                }

                int count = this.socket.EndReceive(ar);
                if (count == 0)
                {
                    OnError("ReceiveHeaderCallback:socket receive 0");
                    return;
                }

                this.readBytes += count;
                if (this.readBytes < this.headerBuf.Length)
                {
                    this.BeginReceiveHeader(this.readBytes);
                    return;
                }

                int dataSize = ByteAr_b.b2i(headerBuf);
                dataSize = dataSize ^ PswCode;
                int bodySize = dataSize - this.headerBuf.Length;
                this.bodyBuf = new byte[bodySize];
                this.BeginReceiveBody(0);
            }
            catch (Exception e)
            {
                OnError("ReceiveHeaderCallback:socket catch" + e.Message);
            }
        }
Ejemplo n.º 7
0
 public int Read_int()
 {
     byte[] bytes = Read_bytes(4);
     return(ByteAr_b.b2i(bytes));
 }
Ejemplo n.º 8
0
 public bool write_long(ulong data)
 {
     return(write_bytes(ByteAr_b.l2b(data)));
 }
Ejemplo n.º 9
0
 public bool write_byte(byte data)
 {
     return(write_bytes(ByteAr_b.b2b(data)));
 }
Ejemplo n.º 10
0
 public bool write_short(short data)
 {
     return(write_bytes(ByteAr_b.s2b(data)));
 }
Ejemplo n.º 11
0
 public byte Read_byte()
 {
     byte[] bytes = Read_bytes(1);
     return(ByteAr_b.b2b(bytes));
 }
Ejemplo n.º 12
0
 public bool write_float(float data)
 {
     return(write_bytes(ByteAr_b.f2b(data)));
 }
Ejemplo n.º 13
0
 public uint Read_uint()
 {
     byte[] bytes = Read_bytes(4);
     return(ByteAr_b.b2ui(bytes));
 }
Ejemplo n.º 14
0
 public ushort Read_ushort()
 {
     byte[] bytes = Read_bytes(2);
     return(ByteAr_b.b2us(bytes));
 }
Ejemplo n.º 15
0
 public bool write_int(uint data)
 {
     return(write_bytes(ByteAr_b.i2b(data)));
 }
Ejemplo n.º 16
0
 public ulong Read_ulong()
 {
     byte[] bytes = Read_bytes(8);
     return(ByteAr_b.b2ul(bytes));
 }
Ejemplo n.º 17
0
 public long Read_long()
 {
     byte[] bytes = Read_bytes(8);
     return(ByteAr_b.b2l(bytes));
 }
Ejemplo n.º 18
0
 public float Read_float()
 {
     byte[] bytes = Read_bytes(4);
     return(ByteAr_b.b2f(bytes));
 }
Ejemplo n.º 19
0
 public bool write_str(string str)
 {
     return(write_bytes(ByteAr_b.str2b(str)));
 }