示例#1
0
    public void Init()
    {
        //读取自带的版本号
        LoadInnerVersion();

        //读取SD卡的版本
        byte[] data = RuntimeInfo.GetLocalFile(RuntimeInfo.GetVersionFileName());
        if (data == null || data.Length != ResManager.RES_NUM * 4 + 4)
        {
            return;
        }
        uint crc = Crc.Crc32(data, 4, data.Length - 4);

        if (crc != System.BitConverter.ToUInt32(data, 0))
        {
            return;
        }

        for (int i = 0, idx = 4; i < ResManager.RES_NUM; ++i, idx += 4)
        {
            uint     resCrc = System.BitConverter.ToUInt32(data, idx);
            string   path   = RuntimeInfo.GetResPersistentPath((ResType)i);
            FileInfo fi     = new FileInfo(path);
            if (!fi.Exists)
            {
                continue;
            }
            m_ResVer[i].ResSize = (uint)fi.Length;
            m_ResVer[i].ResCrc  = resCrc;
        }
        m_bHasVerFile = true;
    }
示例#2
0
    public bool SaveVersion()
    {
        byte[]       data;
        MemoryStream ms = new MemoryStream(ResManager.RES_NUM * 4 + 4);

        for (int i = 0; i < ResManager.RES_NUM; ++i)
        {
            data = System.BitConverter.GetBytes(m_ResVer[i].ResCrc);
            ms.Write(data, 0, data.Length);
        }
        data = ms.ToArray();
        ms.Close();

        uint crc = Crc.Crc32(data, 0, data.Length);

        byte[]       crcValue = System.BitConverter.GetBytes(crc);
        MemoryStream ms2      = new MemoryStream(data.Length + crcValue.Length);

        ms2.Write(crcValue, 0, crcValue.Length);
        ms2.Write(data, 0, data.Length);
        bool bRet = RuntimeInfo.SaveLocalFile(RuntimeInfo.GetVersionFileName(), ms2.ToArray());

        ms2.Close();
        return(bRet);
    }
示例#3
0
    private bool IsCanShowExChangeUI()
    {
        //是否需要显示 兑换码的UI
        //1.获得玩家当前的兑换码的ID 进行测试
        string ChannelName = "";

        if (SDKMgr.Instance.LoginData != null && SDKMgr.Instance.LoginData.ChannelLabel != null)
        {
            ChannelName = SDKMgr.Instance.LoginData.ChannelLabel.ToLower().Trim();
        }
        UInt32 ChannelID = 0;

        if (ChannelName.Length != 0)
        {
            ChannelID = Crc.Crc32(Encoding.Default.GetBytes(ChannelName.ToCharArray()), 0, ChannelName.Length);
        }
        //获得了平台的ID我们进行处理  便利全部的兑换码类型
        //ID  TypeID  ChannelID  RewardID
        //ChannelID  0表示全部平台通用
        foreach (tagExChange var in FishConfig.Instance.m_ExChangeMap.m_ExChangeMap.Values)
        {
            if (var.ChannelID == 0 || var.ChannelID == ChannelID)
            {
                return(true);
            }
        }
        return(false);
    }
示例#4
0
        internal static byte[] Decode(byte[] arr, AesDecryptor aesDecryptor, ref int recvIdx)
        {
            byte flag  = arr[0];
            bool ziped = ((flag & 0x80) == 0x80);
            bool aesed = ((flag & 0x40) == 0x40);
            bool crced = ((flag & 0x20) == 0x20);
            int  idx   = flag & 0x1F;

            if (recvIdx == idx)
            {
                recvIdx++;
                if (recvIdx > 0x1F)
                {
                    recvIdx = 0;
                }
                Byte[] bcrc = new Byte[4];
                Buffer.BlockCopy(arr, 1, bcrc, 0, 4);
                int    crc32 = BitConverter.ToInt32(bcrc, 0);
                Byte[] data  = new Byte[arr.Length - 1 - 4];
                Buffer.BlockCopy(arr, 1 + 4, data, 0, data.Length);
                int ncrc32 = 0;
                if (crced)
                {
                    ncrc32 = Crc.Crc32(data);
                }
                if (ncrc32 == crc32)
                {
                    if (aesed)
                    {
                        data = aesDecryptor.Decrypt(data);
                    }
                    if (ziped)
                    {
                        data = ZLib.UnZip(data);
                    }
                    if (data != null)
                    {
                        return(data);
                    }
                    else
                    {
                        TcpLogger.LogError("Recv Decode data null");
                    }
                }
                else
                {
                    TcpLogger.LogError("Recv error crc32 " + crc32 + "   ncrc32" + ncrc32);
                }
            }
            else
            {
                TcpLogger.LogError("Recv error idx " + idx + "   lidx" + recvIdx);
            }
            return(null);
        }
示例#5
0
    public void GlobalInit()
    {
        if (IS_DISABLED_SDK)
        {
            IS_SDK_CHANNEL = false;
            SDK_TYPE       = SdkType.SDK_SELF;
            PACKAGE_NAME   = "com.leduo.buyu.self";
            byte[] data2 = System.Text.Encoding.ASCII.GetBytes(PACKAGE_NAME);
            PACKAGE_NAME_CRC = Crc.Crc32(data2, 0, data2.Length);
            m_Interface      = null;
            m_Interface      = new SDKBaseNoSDK();
            return;
        }
        IS_SDK_CHANNEL = SDK_TYPE == SdkType.SDK_CHANNEL;
        if (IS_SDK_CHANNEL)
        {
#if DOME
            m_Interface  = new SDKChannelDome();
            CHANNEL_TYPE = ChannelType.Dome_ChannelType;
#elif TW
            m_Interface  = new SDKChannelTW();
            CHANNEL_TYPE = ChannelType.TW_ChannelType;
#else
            m_Interface = new SDKChannel();
#endif
            m_SceneCallbackObj      = new GameObject();
            m_SceneCallbackObj.name = "SDKCallbackObj";
            m_SceneCallback         = m_SceneCallbackObj.AddComponent <SDKSceneCallback>();
        }
        else
        {
            if (SDK_TYPE == SdkType.SDK_DERIVED)
            {
                m_Interface = new SDKDerived();
            }
            else
            {
                m_Interface = new SDKBase();
            }
        }
        PACKAGE_NAME = NativeInterface.GetPackageName();
        byte[] data = System.Text.Encoding.ASCII.GetBytes(PACKAGE_NAME);
        PACKAGE_NAME_CRC = Crc.Crc32(data, 0, data.Length);

        //SDK初始化
#if UNITY_IOS
        IS_APP_STORE_VER = NativeInterface.IsAppStoreVer();
#endif
        LogMgr.Log("包名:" + PACKAGE_NAME + "|类型:" + SDK_TYPE + "|官网:" + IsOfficialVersion);
        m_LoginData.Result = LoginState.LOGIN_NONE;
        m_Interface.GlobalInit();
    }
示例#6
0
        public static string GetMyUserID()
        {
            var nics = NetworkInterface.GetAllNetworkInterfaces().Where(x => !String.IsNullOrWhiteSpace(x.GetPhysicalAddress().ToString()) &&
                                                                        x.NetworkInterfaceType != NetworkInterfaceType.Loopback && x.NetworkInterfaceType != NetworkInterfaceType.Tunnel);

            var wantedNic = nics.FirstOrDefault();

            if (wantedNic != null)
            {
                return(Crc.Crc32(wantedNic.GetPhysicalAddress().GetAddressBytes()).ToString());
            }
            return("0");
        }
    public static bool ComputeCrc(string str, string pwd, out uint crc1, out uint crc2, out uint crc3)
    {
        //crc1 = 123;
        //crc2 = 123;
        //crc3 = 123;
        string pwd1 = (pwd + "OnePwd").ToLower().Trim();
        string pwd2 = (pwd + "SecodPwd").ToLower().Trim();
        string pwd3 = (pwd + "ThreePwd").ToLower().Trim();

        crc1 = Crc.Crc32(Encoding.Default.GetBytes(pwd1.ToCharArray()), 0, pwd1.Length);
        crc2 = Crc.Crc32(Encoding.Default.GetBytes(pwd2.ToCharArray()), 0, pwd2.Length);
        crc3 = Crc.Crc32(Encoding.Default.GetBytes(pwd3.ToCharArray()), 0, pwd3.Length);
        return(true);
    }
示例#8
0
 public static void TestCRC()
 {
     for (int i = 0; i < 8192; i++)
     {
         string mac   = GenerateMACAddress() + "lobby.springrts.com";
         byte[] mac2  = Encoding.ASCII.GetBytes(mac);
         uint   hash1 = Crc.Crc32(mac2);
         uint   hash2 = Crc.Crc32Old(mac2);
         if (hash1 != hash2)
         {
             Console.WriteLine("MISMATCH: {0} vs. {1} (MAC {2})", hash1, hash2, mac);
         }
     }
 }
示例#9
0
        internal static byte[] Encode(byte[] arr, AesEncryptor aesEncryptor, byte sendIdx)
        {
            bool ziped = false;

            if (arr.Length >= 1024)
            {
                arr   = ZLib.Zip(arr);
                ziped = true;
            }
            bool aesed = (new Random().Next() % 10) < 3;

            if (aesed)
            {
                arr = aesEncryptor.Encrypt(arr);
            }
            int  crc32 = 0;
            bool crced = (new Random().Next() % 10) < 3;

            if (crced)
            {
                crc32 = Crc.Crc32(arr);
            }

            int alllen = arr.Length + 1 + 4;

            byte[] balllen = BitConverter.GetBytes(alllen);
            byte   flag    = sendIdx;

            if (ziped)
            {
                flag |= 0x80;
            }
            if (aesed)
            {
                flag |= 0x40;
            }
            if (crced)
            {
                flag |= 0x20;
            }
            var m2 = BitConverter.GetBytes(crc32);
            var os = new MemoryStream();

            os.Write(balllen, 0, 4); //allLen
            os.WriteByte(flag);      //flag
            os.Write(m2, 0, 4);      //crc
            os.Write(arr, 0, arr.Length);
            return(os.ToArray());
        }
示例#10
0
    public string GetChannelString(string code)
    {
        byte[] ss  = System.Text.UnicodeEncoding.Default.GetBytes(code);
        uint   key = Crc.Crc32(ss, 0, ss.Length);
        string str;

        if (ChannelMapping.TryGetValue(key, out str))
        {
            return(str);
        }
        else
        {
            return("");
        }
    }
示例#11
0
        public static byte[] Encode(byte[] arr, AesEncryptor aesEncryptor, byte sendIdx)
        {
            byte flag  = sendIdx;
            int  crc32 = 0;

            if (Enabled_Compress && false)
            {
                if (arr.Length >= 1024)
                {
                    arr   = ZLib.Zip(arr);
                    flag |= CCC_Compress;
                }
            }
            if (Enabled_Crypto || true)
            {
                bool aesed = (new Random().Next() % 10) < 3;
                if (aesed || true)
                {
                    arr   = aesEncryptor.Encrypt(arr);
                    flag |= CCC_Crypto;
                }
            }
            if (Enabled_Crc)
            {
                bool crced = (new Random().Next() % 10) < 3;
                if (crced)
                {
                    crc32 = Crc.Crc32(arr);
                    flag |= CCC_Crc;
                }
            }

            int alllen = arr.Length;// + 1 + 4;

            byte[] balllen = BitConverter.GetBytes(alllen);
            CheckReverse(balllen);

            var m2 = BitConverter.GetBytes(crc32);

            CheckReverse(m2);
            var os = new MemoryStream();

            os.Write(balllen, 0, PackHeadSize); //allLen
            //os.WriteByte(flag);//flag
            //os.Write(m2, 0, 4);//crc
            os.Write(arr, 0, arr.Length);
            return(os.ToArray());
        }
示例#12
0
    bool SaveClient(MultiFileOK dd)
    {
        //验证crc
        DownResData drd = dd.Drd;

        if (drd.ResSize != dd.Data.Length)
        {
            LogMgr.Log("Client:" + drd.ResType + "大小不匹配,localSize:" + dd.Data.Length + ", serverSize:" + drd.ResSize);
            return(false);
        }
        uint crc = Crc.Crc32(dd.Data, 0, dd.Data.Length);

        if (crc != drd.ResCrc)
        {
            LogMgr.Log("Client:" + drd.ResType + "资源检验失败, size:" + dd.Data.Length + ", localCrc:" + crc + ", serverCrc:" + drd.ResCrc);
            return(false);
        }
        if (RuntimeInfo.GetPlatform() == GamePlatformType.Windows)
        {
            SaveWindowClientRes(dd.Data);
            return(true);
        }
        string path = GetClientPath();

        try
        {
            File.Delete(path);
        }
        catch
        {
        }
        FileStream fs = File.Create(path);

        if (fs == null)
        {
            LogMgr.Log("Client文件创建失败:" + drd.ResType);
            return(false);
        }
        fs.Write(dd.Data, 0, dd.Data.Length);
        fs.Flush();
        fs.Close();

        return(true);
    }
示例#13
0
    public static bool Init()
    {
        Object obj = ResManager.Instance.LoadObject("channel_setting", "GlobalRes/LocalSetting/", ResType.GlobalRes, typeof(TextAsset));

        if (obj == null)
        {
            InitLogic.SetInitFailed();
            return(false);
        }
        TextAsset   ta  = obj as TextAsset;
        XmlDocument doc = new XmlDocument();

        doc.LoadXml(ta.text);

        //比赛的标题
        //====================================
        XmlNode node = doc.DocumentElement.SelectSingleNode("match_title");

        byte[] data   = System.Text.Encoding.ASCII.GetBytes("com.leduo.buyu");
        uint   defCrc = Crc.Crc32(data, 0, data.Length);

        foreach (XmlNode n in node.ChildNodes)
        {
            string str  = n.Attributes["title"].Value;
            string str2 = n.Attributes["package"].Value;

            data = System.Text.Encoding.ASCII.GetBytes(str2);
            uint crc = Crc.Crc32(data, 0, data.Length);
            if (crc == defCrc)
            {
                m_DefaultTitle = str;
            }
            m_MatchTitle.Add(crc, str);
        }
        //====================================
        ResManager.Instance.UnloadObject(obj);
        return(true);
    }
示例#14
0
        public static long GetMyUserID()
        {
            try
            {
                var nics =
                    NetworkInterface.GetAllNetworkInterfaces()
                    .Where(
                        x =>
                        !String.IsNullOrWhiteSpace(x.GetPhysicalAddress().ToString()) &&
                        (x.NetworkInterfaceType != NetworkInterfaceType.Loopback) && (x.NetworkInterfaceType != NetworkInterfaceType.Tunnel));

                var wantedNic = nics.FirstOrDefault();

                if (wantedNic != null)
                {
                    return(Crc.Crc32(wantedNic.GetPhysicalAddress().GetAddressBytes()));
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Failed to get the userID: {0}", ex);
            }
            return(0);
        }
示例#15
0
    bool SaveRes(MultiFileOK dd)
    {
        //验证crc
        DownResData drd = dd.Drd;

        if (drd.ResSize != dd.Data.Length)
        {
            LogMgr.Log("Res:" + drd.ResType + " 大小不匹配,localSize:" + dd.Data.Length + ", serverSize:" + drd.ResSize);
            return(false);
        }
        uint crc = Crc.Crc32(dd.Data, 0, dd.Data.Length);

        if (crc != drd.ResCrc)
        {
            LogMgr.Log("Res:" + drd.ResType + "资源检验失败, size:" + dd.Data.Length + ", localCrc:" + crc + ", serverCrc:" + drd.ResCrc);
            return(false);
        }

        System.Random rr       = new System.Random();
        int           name     = rr.Next(100, 10000);
        string        tempFile = RuntimeInfo.GetLocalPath(drd.ResType + name.ToString() + "_temp.dat");
        string        path     = RuntimeInfo.GetResPersistentPath(drd.ResType);

        try
        {
            File.Delete(tempFile);
        }
        catch
        {
        }
        try
        {
            File.Delete(path);
        }
        catch
        {
        }
        try
        {
            FileStream fsTemp = File.Create(tempFile);
            if (fsTemp == null)
            {
                LogMgr.Log("RES文件创建失败:" + drd.ResType);
                return(false);
            }
            //解压
            fsTemp.Write(dd.Data, 0, dd.Data.Length);
            fsTemp.Flush();
            fsTemp.Close();
            fsTemp = null;
            LZMA.DecompressFile(tempFile, path);
        }
        catch (System.Exception e)
        {
            ReportException.Instance.AddException("文件解压失败:" + e.ToString());
        }
        try
        {
            File.Delete(tempFile);
        }
        catch
        {
        }
        if (File.Exists(path) == false)
        {
            LogMgr.Log("RES文件解压失败:" + drd.ResType);
            return(false);
        }
        ResManager.Instance.VersionMgr.SetResVersion(drd.ResType, drd.ResCrc, drd.ResUnzipSize);
        return(ResManager.Instance.VersionMgr.SaveVersion());
    }