Esempio n. 1
0
        public virtual void SetupBuf(byte[] buf, int index)
        {
            _length = buf[index + GobalDef.BASE_MSG_LENGTH_INDEX];
            _pro    = buf[index + GobalDef.BASE_MSG_PROTYPE_INDEX];
            if (_xpp == null)
            {
                _xpp = new XorPacketParameter();
            }


            Utility.GetXorSec(buf, index + GobalDef.BASE_MSG_SEQ_INDEX, SecurityFactory.XorSec, _xpp);// buf[index + BASE_MSG_SEQ_INDEX];
            _seq = (short)(_xpp.Src_2 << 8 | _xpp.Src_1);
            Utility.GetXorSec(buf, index + GobalDef.BASE_MSG_FTTYPE_INDEX, SecurityFactory.XorSec, _xpp);
            _ftType    = _xpp.Src_1;
            _FromDevID = 0;
            for (int i = 0; i < 8; i = i + 2)
            {
                Lishate.Message.Utility.GetXorSec(buf, GobalDef.BASE_MSG_FROM_DEVID_INDEX + (i * 2) + index, SecurityFactory.XorSec, _xpp);
                _FromDevID = (ulong)(_FromDevID | ((ulong)(_xpp.Src_1)) << (i * 8));
                _FromDevID = (ulong)(_FromDevID | ((ulong)(_xpp.Src_2)) << ((i + 1) * 8));
            }
            _ToDevID = 0;
            for (int i = 0; i < 8; i = i + 2)
            {
                Lishate.Message.Utility.GetXorSec(buf, GobalDef.BASE_MSG_TO_DEVID_INDEX + (i * 2) + index, SecurityFactory.XorSec, _xpp);
                _ToDevID = (ulong)(_ToDevID | ((ulong)(_xpp.Src_1)) << (i * 8));
                _ToDevID = (ulong)(_ToDevID | ((ulong)(_xpp.Src_2)) << ((i + 1) * 8));
            }
            Lishate.Message.Utility.GetXorSec(buf, GobalDef.BASE_MSG_CMD_INDEX + index, SecurityFactory.XorSec, _xpp);
            _MType = _xpp.Src_1;
            _SType = _xpp.Src_2;
        }
Esempio n. 2
0
        private static BaseMessage GetPublicMsg(byte[] buf, int index, XorPacketParameter xpp)
        {
            BaseMessage bm  = null;
            int         cmd = xpp.Src_2;

            Utility.GetXorSec(buf, index + GobalDef.BASE_MSG_FTTYPE_INDEX, SecurityFactory.XorSec, xpp);
            int _ftType = xpp.Src_1;

            _ftType = _ftType & 0x3;
            switch (cmd)
            {
            case GobalDef.COMMAND_STYPE_PUBLIC_LOGIN:
                if (_ftType == GobalDef.BASE_MSG_FT_REQ)
                {
                    bm = new LoginReq();
                    bm.SetupBuf(buf, index);
                }
                else if (_ftType == GobalDef.BASE_MSG_FT_RCV)
                {
                    bm = new LoginRcv();
                    bm.SetupBuf(buf, index);
                }
                break;

            case GobalDef.COMMAND_STYPE_PUBLIC_CHECK_TIME:
                if (_ftType == GobalDef.BASE_MSG_FT_REQ)
                {
                    bm = new CheckTimeReq();
                    bm.SetupBuf(buf, index);
                }
                else if (_ftType == GobalDef.BASE_MSG_FT_RCV)
                {
                    bm = new CheckTimeRcv();
                    bm.SetupBuf(buf, index);
                }
                break;

            case GobalDef.COMMAND_STYPE_PUBLIC_GETSERVER:
                if (_ftType == GobalDef.BASE_MSG_FT_REQ)
                {
                    bm = new GetServerReq();
                    bm.SetupBuf(buf, index);
                }
                else if (_ftType == GobalDef.BASE_MSG_FT_RCV)
                {
                    bm = new GetServerRcv();
                    bm.SetupBuf(buf, index);
                }
                break;
            }
            return(bm);
        }
Esempio n. 3
0
        private void setip(byte[] content, int index, XorPacketParameter packetparmeter, IPEndPoint iep)
        {
            byte[] buf = new byte[6];
            for (int i = 0; i < 6; i = i + 2)
            {
                Utility.GetXorSec(content, index + (i * 2), Security.SecurityFactory.XorSec, packetparmeter);
                buf[i]     = packetparmeter.Src_1;
                buf[i + 1] = packetparmeter.Src_2;
            }
            String ipaddress = ((int)buf[0]).ToString() + "." + ((int)buf[1]).ToString() + "." + ((int)buf[2]).ToString() + "." + ((int)buf[3]).ToString();

            iep.Address = IPAddress.Parse(ipaddress);
            iep.Port    = buf[4] | (buf[5] << 8);
        }
Esempio n. 4
0
        private void packip(byte[] content, int index, XorPacketParameter packetparmeter, IPEndPoint iep)
        {
            String s = iep.Address.ToString();

            String[] ipbuf = s.Split(".".ToCharArray());
            packetparmeter.Src_1 = (byte)int.Parse(ipbuf[0]);
            packetparmeter.Src_2 = (byte)int.Parse(ipbuf[1]);
            Utility.SetXorSec(Content, index, Security.SecurityFactory.XorSec, packetparmeter);
            packetparmeter.Src_1 = (byte)int.Parse(ipbuf[2]);
            packetparmeter.Src_2 = (byte)int.Parse(ipbuf[3]);
            Utility.SetXorSec(Content, index + 4, Security.SecurityFactory.XorSec, packetparmeter);
            int temp = iep.Port;

            packetparmeter.Src_1 = (byte)(iep.Port & 0xFF);
            packetparmeter.Src_2 = (byte)((iep.Port >> 8) & 0xFF);
            Utility.SetXorSec(Content, index + 8, Security.SecurityFactory.XorSec, packetparmeter);
            //packetparmeter.Src_1 = (byte)((ipaddr >> (0 * 8)) & 0xFF);
            //packetparmeter.Src_2 = (byte)((ipaddr >> (1 * 8)) & 0xFF);
        }
Esempio n. 5
0
        public static BaseMessage GetMesssage(byte[] buf, int index)
        {
            BaseMessage bm = null;

            if (BaseMessage.CheckIsMessage(buf, index))
            {
                XorPacketParameter _xpp = new XorPacketParameter();
                Lishate.Message.Utility.GetXorSec(buf, GobalDef.BASE_MSG_CMD_INDEX + index, SecurityFactory.XorSec, _xpp);
                switch (_xpp.Src_1)
                {
                case GobalDef.COMMAND_MTYPE_PUBLIC:
                    bm = GetPublicMsg(buf, index, _xpp);
                    break;

                case GobalDef.COMMAND_MTYPE_SOCKET:
                    bm = GetSocketMsg(buf, index, _xpp);
                    break;
                }
            }
            return(bm);
        }
Esempio n. 6
0
        public virtual void PacketBuf()
        {
            //Log.Log.WriteDebugLog("BaseMessage PacketBuf\r\n");
            if (_content == null)
            {
                _content = new byte[Length];
            }
            _content[GobalDef.BASE_MSG_START_INDEX]   = GobalDef.BASE_MSG_START_VALUE;
            _content[GobalDef.BASE_MSG_LENGTH_INDEX]  = (byte)Length;
            _content[GobalDef.BASE_MSG_PROTYPE_INDEX] = GobalDef.BASE_MSG_PRO_11;
            if (_xpp == null)
            {
                _xpp = new XorPacketParameter();
            }
            _xpp.Src_1 = (byte)(_seq & 0xFF);
            _xpp.Src_2 = (byte)(_seq >> 8 & 0xFF);
            Lishate.Message.Utility.SetXorSec(_content, GobalDef.BASE_MSG_SEQ_INDEX, SecurityFactory.XorSec, _xpp);
            _xpp.Src_1 = _ftType;
            _xpp.Src_2 = (byte)Lishate.Security.Utility.GlobalRandon.Next(255);
            Lishate.Message.Utility.SetXorSec(_content, GobalDef.BASE_MSG_FTTYPE_INDEX, SecurityFactory.XorSec, _xpp);
            for (int i = 0; i < 8; i = i + 2)
            {
                _xpp.Src_1 = (byte)(_FromDevID >> (i * 8) & 0xFF);
                _xpp.Src_2 = (byte)(_FromDevID >> ((i + 1) * 8) & 0xFF);
                Lishate.Message.Utility.SetXorSec(_content, GobalDef.BASE_MSG_FROM_DEVID_INDEX + (i * 2), SecurityFactory.XorSec, _xpp);
            }
            for (int i = 0; i < 8; i = i + 2)
            {
                _xpp.Src_1 = (byte)(_ToDevID >> (i * 8) & 0xFF);
                _xpp.Src_2 = (byte)(_ToDevID >> ((i + 1) * 8) & 0xFF);
                Lishate.Message.Utility.SetXorSec(_content, GobalDef.BASE_MSG_TO_DEVID_INDEX + (i * 2), SecurityFactory.XorSec, _xpp);
            }
            _xpp.Src_1 = MCommand;
            _xpp.Src_2 = SCommand;
            Lishate.Message.Utility.SetXorSec(_content, GobalDef.BASE_MSG_CMD_INDEX, SecurityFactory.XorSec, _xpp);
            byte btemp = GetCheckSum(_content, 0);

            _content[_length - 2] = btemp;
            _content[_length - 1] = GobalDef.BASE_MSG_END_VALUE;
        }
Esempio n. 7
0
        private static BaseMessage GetSocketMsg(byte[] buf, int index, XorPacketParameter xpp)
        {
            BaseMessage bm  = null;
            int         cmd = xpp.Src_2;

            Utility.GetXorSec(buf, index + GobalDef.BASE_MSG_FTTYPE_INDEX, SecurityFactory.XorSec, xpp);
            int _ftType = xpp.Src_1;

            _ftType = _ftType & 0x3;
            switch (cmd)
            {
            case GobalDef.COMMAND_STYPE_SOCKET_GET_STATUE:
                if (_ftType == GobalDef.BASE_MSG_FT_REQ)
                {
                    bm = new SocketGetStatueReq();
                    bm.SetupBuf(buf, index);
                }
                else if (_ftType == GobalDef.BASE_MSG_FT_RCV)
                {
                    bm = new SocketGetStatueRcv();
                    bm.SetupBuf(buf, index);
                }
                break;

            case GobalDef.COMMAND_STYPE_SOCKET_OPEN:
                if (_ftType == GobalDef.BASE_MSG_FT_REQ)
                {
                    bm = new SocketOnReq();
                    bm.SetupBuf(buf, index);
                }
                else if (_ftType == GobalDef.BASE_MSG_FT_RCV)
                {
                    bm = new SocketOnRcv();
                    bm.SetupBuf(buf, index);
                }
                break;
            }
            return(bm);
        }
Esempio n. 8
0
 /*
  * public static void GetXorSec(byte[] src, int srcIndex, ref short value, XorSecurity xs)
  * {
  *  XorPacketParameter xpp = new XorPacketParameter();
  *  GetXorSec(src, srcIndex, ref value, xs, xpp);
  *
  * }
  */
 public static bool GetXorSec(RingBuffer buffer, int index, XorSecurity xs, XorPacketParameter xpp)
 {
     return(xs.Decode(xpp, buffer, index));
 }
Esempio n. 9
0
 public static void GetXorSec(byte[] src, int srcIndex, XorSecurity xs, XorPacketParameter xpp)
 {
     xs.Decode(xpp, src, srcIndex);
 }
Esempio n. 10
0
 /*
  * public static void SetXorSec(short value, byte[] buf, int index, XorSecurity xs)
  * {
  *
  *  XorPacketParameter xpp = new XorPacketParameter();
  *  SetXorSec(value, buf, index, xs, xpp);
  * }
  *
  *
  * public static void SetXorSec(short value, byte[] buf, int index, XorSecurity xs, XorPacketParameter xpp)
  * {
  *  xpp.Src_1 = (byte)((value >> 8) & 0xFF);
  *  xpp.Src_2 = (byte)(value & 0xFF);
  *  xs.Encode(xpp, buf, index);
  * }
  *
  * public static void GetXorSec(byte[] src, int srcIndex, ref short value, XorSecurity xs, XorPacketParameter xpp)
  * {
  *
  *  xs.Decode(xpp, src, srcIndex);
  *  value = (short)(xpp.Src_1 << 8);
  *  value = (short)(value + xpp.Src_2);
  * }
  */
 public static void SetXorSec(byte[] buf, int index, XorSecurity xs, XorPacketParameter xpp)
 {
     xs.Encode(xpp, buf, index);
 }
Esempio n. 11
0
        public virtual bool SetupBuf(RingBuffer buffer)
        {
            byte temp = 0;

            if (buffer.GetIndexByte((int)GobalDef.BASE_MSG_LENGTH_INDEX, ref temp))
            {
                _length = temp;
            }
            else
            {
                return(false);
            }
            if (buffer.GetIndexByte((int)GobalDef.BASE_MSG_PROTYPE_INDEX, ref temp))
            {
                _pro = temp;
            }
            else
            {
                return(false);
            }
            if (_xpp == null)
            {
                _xpp = new XorPacketParameter();
            }
            if (Utility.GetXorSec(buffer, GobalDef.BASE_MSG_SEQ_INDEX, Security.SecurityFactory.XorSec, _xpp))
            {
                _seq = (short)(_xpp.Src_2 << 8 | _xpp.Src_1);
            }
            else
            {
                return(false);
            }
            if (Utility.GetXorSec(buffer, GobalDef.BASE_MSG_FTTYPE_INDEX, SecurityFactory.XorSec, _xpp) == true)
            {
                _ftType = _xpp.Src_1;
            }
            else
            {
                return(false);
            }
            _FromDevID = 0;
            for (int i = 0; i < 8; i = i + 2)
            {
                if (Lishate.Message.Utility.GetXorSec(buffer, GobalDef.BASE_MSG_FROM_DEVID_INDEX + (i * 2), SecurityFactory.XorSec, _xpp))
                {
                    _FromDevID = (ulong)(_FromDevID | ((ulong)(_xpp.Src_1)) << (i * 8));
                    _FromDevID = (ulong)(_FromDevID | ((ulong)(_xpp.Src_2)) << ((i + 1) * 8));
                }
                else
                {
                    return(false);
                }
            }
            _ToDevID = 0;
            for (int i = 0; i < 8; i = i + 2)
            {
                if (Lishate.Message.Utility.GetXorSec(buffer, GobalDef.BASE_MSG_TO_DEVID_INDEX + (i * 2), SecurityFactory.XorSec, _xpp))
                {
                    _ToDevID = (ulong)(_ToDevID | ((ulong)(_xpp.Src_1)) << (i * 8));
                    _ToDevID = (ulong)(_ToDevID | ((ulong)(_xpp.Src_2)) << ((i + 1) * 8));
                }
                else
                {
                    return(false);
                }
            }
            if (Lishate.Message.Utility.GetXorSec(buffer, GobalDef.BASE_MSG_CMD_INDEX, SecurityFactory.XorSec, _xpp))
            {
                _MType = _xpp.Src_1;
                _SType = _xpp.Src_2;
            }
            else
            {
                return(false);
            }
            return(true);
        }