예제 #1
0
    public bool AddTable(string key, LoadComplateCB lcCB)
    {
        if (tableList_ == null)
        {
            try {
                hashWaiting_.Add(key, lcCB);
            } catch {
                MagiDebug.LogError(string.Format("Table key already {0}", key));
            }
            return(true);
        }
        else
        {
            string tableName;
            if (hashTableName_.TryGetValue(key, out tableName) == false)
            {
                if (key.Contains("weapontrail") || key.Contains("sound"))
                {
                    MagiDebug.Log(string.Format("{0} table not found.", key));
                    return(false);
                }

                MagiDebug.LogError(string.Format("{0} table not found.", key));
                return(false);
            }
            StartCoroutine(OpenTable(key, tableName, lcCB));
        }
        return(true);
    }
예제 #2
0
    /// <summary>
    /// <para>name : TcpReceiveCallBack</para>
    /// <para>parameter : System.IAsyncResult</para>
    /// <para>return : void</para>
    /// <para>describe : Receive message result callback.</para>
    /// </summary>
    private void TcpReceiveCallBack(System.IAsyncResult asynResult)
    {
        try {
            Socket socket   = asynResult.AsyncState as Socket;
            int    readSize = socket.EndReceive(asynResult);

            if (readSize > 0)
            {
                messageQueue.Enqueue(new UTF8Encoding().GetString(receiveBuffer, 0, MAXSIZE));

                receiveBuffer = new byte[MAXSIZE];
                Receive();
            }

            else
            {
                MagiDebug.Log(string.Format("Close Server Connect."));

                CloseSocket(SendMessageErrorType.RES_CONNECT_RETRY);
                InitSocket();
            }
        } catch (SocketException ex) {
            MagiDebug.Log(string.Format("Cannot Receive Chat Server > {0}", ex.Message));

            CloseSocket(SendMessageErrorType.RES_RECEIVE_RETRY);
            InitSocket();
        }
    }
예제 #3
0
    static void CleanCache()
    {
        Caching.CleanCache();

        string dbPath = Application.persistentDataPath + "/rustyhearts.db";

        MagiDebug.Log(dbPath);

        File.Delete(dbPath);
    }
예제 #4
0
    public static bool GetAssetBundleCheck(Object o, ref CAssetBundleCheck abc)
    {
        string collectDependenciesAssetPath = AssetDatabase.GetAssetPath(o).ToLower();

        Object[] dependencies;

        //        dependencies = new[] { o };
        if (o is GameObject)
        {
            dependencies = EditorUtility.CollectDependencies(new[] { o });
        }
        else if (o is TextAsset || o is Texture2D || o is AudioClip)
        {
            dependencies = new[] { o };
        }
        else
        {
            return(false);
        }

        foreach (var od in dependencies)
        {
            //if (od is TextAsset == false && od is GameObject == false && od is Texture2D == false && od is AudioClip == false)
            //{
            //    continue;
            //}

            string assetPath = AssetDatabase.GetAssetPath(od).ToLower();
            if (Path.GetExtension(assetPath) == ".cs")
            {
                MagiDebug.Log("GetAssetBundleCheck .cs - " + assetPath);
                continue;
            }

            var path = System.Environment.CurrentDirectory + "/" + assetPath;
            if (File.Exists(path) == false)
            {
                continue;
            }

            uint crc;
            if (MakeCRC.Make(path, out crc) == true)
            {
                abc.crc += crc;
            }
            FileInfo fi = new FileInfo(path);
            abc.size += (ulong)fi.Length;
            abc.count++;
        }
        dependencies = null;
        return(true);
    }
예제 #5
0
    public Table FindTable(string name)
    {
        string strlower = name.ToLower();

        Table table = new Table(strlower);

        if (hashTable_.TryGetValue(strlower, out table) == false)
        {
            MagiDebug.Log(string.Format("Invalid TableName {0}", name));
            return(null);
        }
        return(table);
    }
예제 #6
0
    public static bool Make(string fileName, out uint crc)
    {
        if (File.Exists(fileName) == false)
        {
            crc = 0;
            MagiDebug.Log(string.Format("File not found.{0}", fileName));
            return(false);
        }

        uint crc32 = 0xFFFFFFFF;

        byte[] buffer = File.ReadAllBytes(fileName);

        for (int i = 0; i < buffer.Length; ++i)
        {
            crc32 = (crc32 >> 8) ^ s_arrdwCrc32Table[(crc32 & 0xFF) ^ buffer[i]];
        }
        crc = crc32;

        buffer = null;
        return(true);
    }
예제 #7
0
    /// <summary>
    /// <para>name : TcpSendCallBack</para>
    /// <para>parameter : System.IAsyncResult</para>
    /// <para>return : void</para>
    /// <para>describe : Send message result callback.</para>
    /// </summary>
    private void TcpSendCallBack(System.IAsyncResult asynResult)
    {
        try {
            string    sendMessage = (string)asynResult.AsyncState;
            Hashtable result      = sendMessage.hashtableFromJson();

            int pno = 0;
            if (result.ContainsKey("pno"))
            {
                int.TryParse(result["pno"].ToString(), out pno);
            }

            if (pno.Equals((int)SendMessageType.Type_Disconnect))
            {
                CloseSocket();
            }
        } catch (SocketException ex) {
            MagiDebug.Log(string.Format("Cannot Send Chat Server > {0}", ex.Message));

            CloseSocket(SendMessageErrorType.RES_RECEIVE_RETRY);
            InitSocket();
        }
    }
예제 #8
0
    /// <summary>
    /// <para>name : TcpConnectCallBack</para>
    /// <para>parameter : System.IAsyncResult</para>
    /// <para>return : void</para>
    /// <para>describe : Socket connect result callback.</para>
    /// </summary>
    private void TcpConnectCallBack(System.IAsyncResult asynResult)
    {
        try {
            Socket socket = asynResult.AsyncState as Socket;

            MagiDebug.Log(string.Format("Connect Chat Server > {0}", socket.RemoteEndPoint));

            socket.EndConnect(asynResult);

            callBackSocket = socket;
            callBackSocket.BeginReceive(receiveBuffer, 0, MAXSIZE, SocketFlags.None, new System.AsyncCallback(TcpReceiveCallBack), callBackSocket);

            if (isUserConnectComplete)
            {
                UserConnect();
            }
        } catch (SocketException ex) {
            MagiDebug.Log(string.Format("Cannot Connect Chat Server > {0}", ex.Message));

            CloseSocket(SendMessageErrorType.RES_CONNECT_RETRY);
            InitSocket(false);
        }
    }
예제 #9
0
    void Update()
    {
        if (PatchManager.Instance == null)
        {
            return;
        }
        if (PatchManager.Instance.IsLoadComplate == false)
        {
            return;
        }

        if (first_ == true)
        {
            AddTableList();
            first_ = false;
        }

        if (tableList_ != null)
        {
            if (hashTableName_.Count != 0)
            {
                foreach (var p in hashWaiting_)
                {
                    string tableName;
                    if (hashTableName_.TryGetValue(p.Key, out tableName) == false)
                    {
                        MagiDebug.Log(string.Format("table not found. {0}", p.Key));
                        continue;
                    }

                    StartCoroutine(OpenTable(p.Key, tableName, p.Value));
                }

                hashWaiting_.Clear();
            }
        }
    }
예제 #10
0
    static void GetPrefabsFolderFileNameList(out List <string> fileList)
    {
        fileList = new List <string>();

        int    currentDirectoryLength = System.Environment.CurrentDirectory.Length + 1;
        string prefabsPath            = System.Environment.CurrentDirectory + @"/Assets/Prefabs";

        MagiDebug.Log(prefabsPath);

        string[] files = Directory.GetFiles(prefabsPath, "*.*", SearchOption.AllDirectories);
        foreach (var file in files)
        {
            if (Path.GetExtension(file).ToLower() == ".meta")
            {
                continue;
            }
            if (Path.GetExtension(file).ToLower() == ".php")
            {
                continue;
            }
            if (Path.GetExtension(file).ToLower() == ".csv")
            {
                continue;
            }

            if (file.ToLower().Contains("nopatch") == true)
            {
                MagiDebug.Log(file);
                continue;
            }

            string temp = file.Remove(0, currentDirectoryLength);
            MagiDebug.Log(temp);
            fileList.Add(temp);
        }
    }
예제 #11
0
    IEnumerator OpenTable(string key, string tableName, LoadComplateCB lcCB)
    {
        string url = "";

        MemoryStream stream = null;

        switch (OptionManager.Instance.pathType)
        {
        case OptionManager.EPathType.Develop: {
            url = OptionManager.ROOT_PATH + "/" + tableUrl_ + "/bytes/" + tableName + ".bytes";

            TextAsset bytes = Resources.LoadAssetAtPath(url, typeof(TextAsset)) as TextAsset;
            if (bytes == null)
            {
                MagiDebug.Log(string.Format("{0}, bytes==null", url));
                break;
            }
            stream = new MemoryStream(bytes.bytes);
        }
        break;

        case OptionManager.EPathType.Live: {
            AssetBundle assetBundle;
            if (PatchManager.Instance.FindAssetBundle("table", out assetBundle))
            {
                TextAsset bytes = assetBundle.Load(key, typeof(TextAsset)) as TextAsset;
                if (bytes == null)
                {
                    MagiDebug.LogError(key + " table not found.");
                    yield break;
                }

                stream = new MemoryStream(bytes.bytes);
            }
        }
        break;
        }

        if (stream == null)
        {
            MagiDebug.Log(stream + "," + key + "," + tableName);
            yield break;
        }

        BinaryReader binReader = new BinaryReader(stream);
        Table        table     = new Table(key);

        int lineNum   = binReader.ReadInt32();
        int columnNum = binReader.ReadInt32();

        if (ReadColumnName(columnNum, ref table, binReader) == false)
        {
            yield break;
        }
        if (ReadColumnType(columnNum, ref table, binReader) == false)
        {
            yield break;
        }

        for (int i = 0; i < lineNum; i++)
        {
            if (ReadData(columnNum, ref table, binReader) == false)
            {
                yield break;
            }
        }

        try {
            hashTable_.Add(key, table);
        } catch {
            MagiDebug.LogError(string.Format("Table key already {0}, {1}", key, tableName));
        }
        if (lcCB != null)
        {
            lcCB(table);
        }
    }
예제 #12
0
    static void ExecutePatch(string local, string target)
    {
        //        System.DateTime nowDateTime = System.DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss");
        System.DateTime nowDateTime = System.DateTime.Now;

        BuildTarget buildTarget;
        string      targetPath = "";

        switch (target)
        {
        case "Android": {
            targetPath  = "android/";
            buildTarget = BuildTarget.Android;
        }
        break;

        case "iPhone": {
            targetPath  = "iphone/";
            buildTarget = BuildTarget.iPhone;
        }
        break;

        default:
            return;
        }

        string localPath = local.ToLower() + "/";

        //patch revision info 로딩.
        int    lastRevision          = 0;
        string version               = "";
        string infoPatchRevisionInfo = GetAssetbundlePath(buildTarget) + localPath + targetPath + @"patchRevisionInfo.txt";

        if (File.Exists(infoPatchRevisionInfo) == true)
        {
            string[] infoPatchRevision = File.ReadAllLines(infoPatchRevisionInfo);
            if (infoPatchRevision.Length <= 2)
            {
                MagiDebug.LogError(string.Format("{0} file error", infoPatchRevisionInfo));
                return;
            }

            lastRevision = System.Int32.Parse(infoPatchRevision[0]);
            version      = infoPatchRevision[1];
        }

        else
        {
            version = nowDateTime.ToString("yyyy-MM-dd_HH:mm:ss");
        }

        lastRevision++;

        EditorUtility.UnloadUnusedAssets();

        string lastAssetBundleCheckInfoFileName = "AssetBundleCheckInfo3_" + target + ".txt";
        //        Object[] listObject = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

        List <string> fileList;

        GetPrefabsFolderFileNameList(out fileList);

        //pathlist 작업.
        string newAssetbundlePath = GetAssetbundlePath(buildTarget) + localPath + targetPath + lastRevision.ToString() + "/";
        string lastAssetBundleCheckInfoPathName = System.Environment.CurrentDirectory + @"/Assets/Prefabs/" + lastAssetBundleCheckInfoFileName;
        string errorListPath = System.Environment.CurrentDirectory + @"/Assets/Prefabs/" + "AssetBundleError.txt";

        Dictionary <string, CAssetBundleCheck> lastAssetBundleCheckInfo = new Dictionary <string, CAssetBundleCheck>();

        ReadAssetBundleCheckInfo(out lastAssetBundleCheckInfo, lastAssetBundleCheckInfoPathName);
        Dictionary <string, CAssetBundleCheck> assetBundleCheckInfo = new Dictionary <string, CAssetBundleCheck>();

        Dictionary <string, List <Object> > hashAssetBundle = new Dictionary <string, List <Object> >();
        //        for (int i = 0; i < listObject.Length; ++i)
        //        {
        //            Object o = listObject[i];

        List <ePatchInfo> newPathInfoAssetBundle = new List <ePatchInfo>();
        ePatchInfo        currentPatchInfo       = new ePatchInfo();

        for (int i = 0; i < fileList.Count; ++i)
        {
            Object o = null;
            try {
                o = AssetDatabase.LoadMainAssetAtPath(fileList[i]);
            } catch {
                MagiDebug.LogError(string.Format("AssetDatabase.LoadMainAssetAtPath error, {0}", fileList[i]));
                continue;
            }

            if (o == null)
            {
                MagiDebug.LogError("AssetDatabase.LoadMainAssetAtPath == false, " + fileList[i]);
                continue;
            }
            //Object o = fileList[i];

            //            MagiDebug.Log(o);

            string assetPath = AssetDatabase.GetAssetPath(o).ToLower();
            if (assetPath.Contains("assets/prefabs/") == false)
            {
                continue;
            }
            if (assetPath.Contains("assets/prefabs/pathinfo") == true)
            {
                continue;
            }
            if (assetPath.Contains("assets/prefabs/patchrevisioninfo.txt") == true)
            {
                continue;
            }

            float s = (float)i / fileList.Count;
            EditorUtility.DisplayProgressBar("Make AssetBundleCheckInfo", assetPath, s);

            string assetBundleName = GetAssetBundleName(assetPath);
            if (assetBundleName == "")
            {
                continue;
            }

            if (assetBundleCheckInfo.ContainsKey(assetBundleName) == true)
            {
                CAssetBundleCheck temp = assetBundleCheckInfo[assetBundleName];
                GetAssetBundleCheck(o, ref temp);
            }
            else
            {
                CAssetBundleCheck temp = new CAssetBundleCheck();
                GetAssetBundleCheck(o, ref temp);
                assetBundleCheckInfo.Add(assetBundleName, temp);
            }

            if (hashAssetBundle.ContainsKey(assetBundleName) == true)
            {
                hashAssetBundle[assetBundleName].Add(o);
            }
            else
            {
                var listO = new List <Object>();
                listO.Add(o);
                hashAssetBundle.Add(assetBundleName, listO);
            }

            System.GC.Collect();
            for (int n = 0; n < System.GC.MaxGeneration; ++n)
            {
                System.GC.Collect(n, System.GCCollectionMode.Forced);
            }
            System.GC.WaitForPendingFinalizers();
            EditorUtility.UnloadUnusedAssets();
        }
        EditorUtility.ClearProgressBar();

        if (assetBundleCheckInfo.Count == 0)
        {
            return;
        }

        string buildAssetBundle = System.Environment.CurrentDirectory + @"/Assets/Prefabs/" + "BuildAssetBundle.txt";

        int  c   = 0;
        uint crc = 0;

        foreach (var p in hashAssetBundle)
        {
            c++;
            float s = (float)c / hashAssetBundle.Count;
            EditorUtility.DisplayProgressBar("BuildAssetBundle", p.Key, s);

            CAssetBundleCheck abc;
            if (assetBundleCheckInfo.TryGetValue(p.Key, out abc) == false)
            {
                continue;
            }

            if (lastAssetBundleCheckInfo.ContainsKey(p.Key) == true)
            {
                CAssetBundleCheck lastAbc;
                lastAssetBundleCheckInfo.TryGetValue(p.Key, out lastAbc);
                if (abc.count == lastAbc.count && abc.crc == lastAbc.crc && abc.size == lastAbc.size)
                {
                    continue;
                }
            }

            string path = newAssetbundlePath + p.Key + ".assetbundle";
            MagiDebug.Log(path);

            if (!Directory.Exists(newAssetbundlePath))
            {
                Directory.CreateDirectory(newAssetbundlePath);
            }

            File.WriteAllText(buildAssetBundle, path);

            BuildPipeline.PushAssetDependencies();

            if (BuildPipeline.BuildAssetBundle(p.Value[0], p.Value.ToArray(), path, out crc, BuildAssetBundleOptions.CollectDependencies, buildTarget) == false)
            {
                MagiDebug.LogError("BuildPipeline.BuildAssetBundle == false, " + path);
            }

            BuildPipeline.PopAssetDependencies();

            currentPatchInfo         = new ePatchInfo();
            currentPatchInfo.key     = p.Key;
            currentPatchInfo.version = lastRevision;
            currentPatchInfo.crc     = crc;

            newPathInfoAssetBundle.Add(currentPatchInfo);
        }

        EditorUtility.ClearProgressBar();

        // 패치할 파일이 없으면 pass
        if (newPathInfoAssetBundle.Count == 0)
        {
            return;
        }

        //revision 버젼 저장.
        List <ePatchInfo> finalPatchInfo = new List <ePatchInfo>();

        if (File.Exists(infoPatchRevisionInfo) == true)
        {
            string[] infoPatchRevision = File.ReadAllLines(infoPatchRevisionInfo);
            if (infoPatchRevision.Length <= 2)
            {
                MagiDebug.LogError(string.Format("{0} file error", infoPatchRevisionInfo));
                return;
            }

            ePatchInfo newPatchInfo;
            ePatchInfo patchInfo;
            string[]   szAssetBundleInfo;
            for (int i = 2; i < infoPatchRevision.Length; i++)
            {
                szAssetBundleInfo = infoPatchRevision[i].Split(',');

                if (szAssetBundleInfo.Length < 3)
                {
                    continue;
                }

                patchInfo         = new ePatchInfo();
                patchInfo.key     = szAssetBundleInfo[0];
                patchInfo.version = System.Int32.Parse(szAssetBundleInfo[1]);
                patchInfo.crc     = System.UInt32.Parse(szAssetBundleInfo[2]);

                newPatchInfo = newPathInfoAssetBundle.Find(delegate(ePatchInfo a) {
                    return(a.key.Equals(patchInfo.key));
                });

                if (newPatchInfo != null)
                {
                    finalPatchInfo.Add(newPatchInfo);
                }
                else
                {
                    finalPatchInfo.Add(patchInfo);
                }
            }
        }

        else
        {
            finalPatchInfo.AddRange(newPathInfoAssetBundle);
        }

        finalPatchInfo.Sort(delegate(ePatchInfo a, ePatchInfo b) {
            return(a.key.CompareTo(b.key));
        });

        List <string> szFinalPatchInfo = new List <string>();

        for (int i = 0; i < finalPatchInfo.Count; i++)
        {
            szFinalPatchInfo.Add(string.Format("{0},{1},{2}", finalPatchInfo[i].key, finalPatchInfo[i].version.ToString(), finalPatchInfo[i].crc.ToString()));
        }

        List <string> revisionInfo = new List <string>();

        revisionInfo.Add(lastRevision.ToString());
        revisionInfo.Add(version.ToString());

        revisionInfo.AddRange(szFinalPatchInfo);

        if (File.Exists(infoPatchRevisionInfo) == true)
        {
            File.Delete(infoPatchRevisionInfo);
        }

        File.WriteAllLines(infoPatchRevisionInfo, revisionInfo.ToArray());

        WriteAssetBundleCheckInfo(assetBundleCheckInfo, lastAssetBundleCheckInfoPathName);

        MagiDebug.Log(System.DateTime.Now - nowDateTime);

        #region FTP unload작업.
        //{
        //    //            string ftpRoot = "app/rustyhearts/" + targetPath + lastRevision.ToString() + "/";
        //    string ftpRoot = localPath + targetPath + lastRevision.ToString() + "/";
        //    MagiFtp magiFtp = new MagiFtp("1.214.41.130", "rh_rpg", "z00games?!ftp");

        //    string ftpRoot2 = localPath + targetPath + lastRevision.ToString();
        //    magiFtp.MakeDirectory(ftpRoot2);

        //    for (int i = 0; i < pathInfoAssetBundle.Count; )
        //    {
        //        string ftpFile = ftpRoot + pathInfoAssetBundle[i] + ".assetbundle";
        //        string clientPath = newAssetbundlePath + pathInfoAssetBundle[i] + ".assetbundle";

        //        //                FtpDelete(magiFtp, ftpFile);
        //        CreateNewAssetbundles.FtpUpload(magiFtp, ftpFile, clientPath);

        //        float s = (float)i / pathInfoAssetBundle.Count;
        //        EditorUtility.DisplayProgressBar("Upload", clientPath, s);
        //        ++i;
        //    }
        //    EditorUtility.ClearProgressBar();

        //    // fileinfo.txt upload
        //    {
        //        string ftpDir = ftpRoot + Path.GetFileName(newFileInfoPathName);
        //        string clientPath = newFileInfoPathName;
        //        CreateNewAssetbundles.FtpUpload(magiFtp, ftpDir, clientPath);
        //    }

        //    // patchRevisionInfo.txt upload
        //    {
        //        string ftpDir = localPath + targetPath + "patchRevisionInfo.txt";
        //        string clientPath = infoPatchRevisionInfo;
        //        CreateNewAssetbundles.FtpUpload(magiFtp, ftpDir, clientPath);
        //    }
        //}
        #endregion
    }