Пример #1
0
 void CheckVersion(string version)
 {
     if (string.IsNullOrEmpty(version))
     {
         version = GameManager.localVersion.ToString();
     }
     else
     {
         GameVersion remoteVersion = GameVersion.CreateVersion(version);
         if (GameManager.localVersion < GameManager.packVersion)
         {
             if (remoteVersion < GameManager.packVersion)
             {
                 version = GameManager.packVersion.ToString();
             }
         }
         else
         {
             if (remoteVersion < GameManager.localVersion)
             {
                 version = GameManager.localVersion.ToString();
             }
         }
     }
     User_Config.SetWebServerUrl(Path.Combine(User_Config.resource_server, version));
     Debug.Log(string.Format("Set web url: {0}", User_Config.web_url));
     if (onGetServerInfo != null)
     {
         onGetServerInfo();
     }
 }
    private static int Save(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 0);
            User_Config.Save();
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int LoadConfig(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            string configContent = ToLua.CheckString(L, 1);
            User_Config.LoadConfig(configContent);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int SetLastServerList(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            ArrayList lastServerList = (ArrayList)ToLua.CheckObject(L, 1, typeof(ArrayList));
            User_Config.SetLastServerList(lastServerList);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int SetDefaultServer(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            int defaultServer = (int)LuaDLL.luaL_checknumber(L, 1);
            User_Config.SetDefaultServer(defaultServer);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int SetLoginServerInfo(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            ServerInfo loginServerInfo = (ServerInfo)ToLua.CheckObject(L, 1, typeof(ServerInfo));
            User_Config.SetLoginServerInfo(loginServerInfo);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int SetWebServerUrl(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            string webServerUrl = ToLua.CheckString(L, 1);
            User_Config.SetWebServerUrl(webServerUrl);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int SetString(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 2);
            string key   = ToLua.CheckString(L, 1);
            string value = ToLua.CheckString(L, 2);
            User_Config.SetString(key, value);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int GetFloat(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            string key    = ToLua.CheckString(L, 1);
            float  @float = User_Config.GetFloat(key);
            LuaDLL.lua_pushnumber(L, (double)@float);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int GetString(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            string key     = ToLua.CheckString(L, 1);
            string @string = User_Config.GetString(key);
            LuaDLL.lua_pushstring(L, @string);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
    private static int SetUserInfo(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 2);
            string name     = ToLua.CheckString(L, 1);
            string password = ToLua.CheckString(L, 2);
            User_Config.SetUserInfo(name, password);
            result = 0;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Пример #12
0
    void LoadConfig()
    {
        // first check local config exists or not
        string content = string.Empty;

        if (!AppConst.DebugMode && !Directory.Exists(Util.DataPath))
        {
            Directory.CreateDirectory(Util.DataPath);
        }

        string config_path = Util.DataPath + "/config.txt";

        if (FileManager.FileExist(config_path))
        {
            content = FileManager.ReadFileString(config_path);
        }
        else
        {
            TextAsset obj = Resources.Load <TextAsset>("config");
#if UNITY_EDITOR
            if (obj == null)
            {
                File.Copy("Assets/config.txt.example", "Assets/Resources/config.txt", true);
                UnityEditor.AssetDatabase.Refresh();
                obj = Resources.Load <TextAsset>("config");
            }
#else
            if (obj == null)
            {
                MessageBox.Show(UpdateTips.NO_CONFIG_VIA_MOBLIEPLATFORM, (int)MessageBox.Style.OkOnly, (go) =>
                {
                    Application.Quit();
                });
            }
#endif
            content = obj.text;
#if !UNITY_EDITOR
            FileManager.WriteFile(config_path, content);
#endif
        }
        // load config
        User_Config.LoadConfig(content);
        User_Config.LoadGlobalSetting();
#if UNITY_IOS && !UNITY_EDITOR
        // iphone 6及以下强行设置为流畅 否则可能出现内存问题闪退
        try
        {
            string deviceVersion = SystemInfo.deviceModel;
            Debug.Log(deviceVersion);
            if (!string.IsNullOrEmpty(deviceVersion))
            {
                string[] tmps = deviceVersion.Split(',');
                Debug.Assert(tmps.Length == 2);
                int iVer = Convert.ToInt32(tmps[0].Substring(tmps[0].Length - 1, 1));
                if (iVer < 7 || (iVer == 7 && tmps[1].Equals("iPhone7,2")))
                {
                    Debug.Log("iphone version < iphone6, set quality to 0");
                    User_Config.quality = 0;
                }
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
#endif
    }
Пример #13
0
    /// <summary>
    /// 释放本地的整包资源
    /// </summary>
    /// <returns></returns>
    public IEnumerator OnExtractResources()
    {
        ThreadManager threadMgr = AppFacade.Instance.GetManager <ThreadManager>();

        if (extractStartTime == 0)
        {
            extractStartTime = Time.realtimeSinceStartup;
        }
        if (extractErrorCount >= 3)
        {
            MessageBox.Show(LanguageTips.READ_FILES_ERROR_QUIT, (result) =>
            {
                Application.Quit();
            });
            yield break;
        }
        extractFiles.Clear();

#if UNITY_EDITOR
        PlayerPrefs.DeleteAll();
#else
        if (Application.platform == RuntimePlatform.WindowsPlayer)
        {
            PlayerPrefs.DeleteAll();
        }
#endif

        string dataPath = Util.DataPath;                                            //数据目录
        string resPath  = Path.Combine(Util.StreamingAssetsPath(), LuaConst.osDir); //游戏包资源目录

        if (Application.platform != RuntimePlatform.WindowsPlayer)
        {
            if (Directory.Exists(dataPath))
            {
                Directory.Delete(dataPath, true);
            }
            Directory.CreateDirectory(dataPath);
        }

        // 解压前先重新加载一次config,防止覆盖安装config文件不能更改的问题
        TextAsset obj = Resources.Load <TextAsset>("config");
        if (obj == null)
        {
            MessageBox.Show(LanguageTips.NO_CONFIG_VIA_MOBLIEPLATFORM, (result) =>
            {
                Application.Quit();
            });
        }
        string config_path = Util.DataPath + "/config.txt";
        if (File.Exists(config_path))
        {
            File.Delete(config_path);
        }
        FileManager.WriteFile(config_path, obj.text);
        User_Config.ResetConfig(obj.text);
        User_Config.LoadGlobalSetting();

        string splitFile = Path.Combine(resPath, "split.txt");
        WWW    www       = new WWW(splitFile);
        yield return(www);

        if (www.isDone && www.text == "1")
        {
            LuaHelper.GetGameManager().downloadAll = true;
        }
        if (www != null)
        {
            www.Dispose();
        }

        if (LuaHelper.GetGameManager().downloadAll)
        {
            onExtractComplete(null);
            yield break;
        }

        yield return(Yielders.EndOfFrame);

        string infile  = Path.Combine(resPath, "packlist.txt");
        string content = string.Empty;
//        Debug.Log(infile);
        www = new WWW(infile);
        yield return(www);

        if (www.isDone)
        {
            content = www.text;
        }
        www.Dispose();

        yield return(Yielders.EndOfFrame);

        //释放所有文件到数据目录

        string[] files = content.Split('\n');
#if UNITY_IOS
        extractLeftFiles.AddRange(files);
        curSingleStreamingIndex   = 0;
        totalSingleStreamingCount = files.Length;
        bar.UpdateProgress(0);
        if (extractLeftFiles.Count > 0)
        {
            bar.SetMessage(LanguageTips.READ_FILES);
        }
        LuaHelper.GetGameManager().StartCoroutine(ExtractOneByOne());
#else
        int    curStreamingIndex        = 0;
        int    totalStreamingCount      = files.Length;
        string outfile                  = string.Empty;
        List <LocalExtractExecutor> les = new List <LocalExtractExecutor>();
        bar.SetMessage(LanguageTips.READ_FILES);
        for (int i = 0; i < files.Length; ++i)
        {
            var file = files[i].Trim();
            curStreamingIndex++;

            var percent1 = (float)curStreamingIndex / (float)totalStreamingCount;
            bar.SetMessage(string.Format("{0}: {1}%", LanguageTips.READ_FILES, (percent1 * 100).ToString("f0")));
            bar.UpdateProgress(percent1);

            if (string.IsNullOrEmpty(file))
            {
                continue;
            }

            string[] fs = file.Split('|');
            infile = Path.Combine(resPath, fs[0]);   //

            outfile = dataPath + fs[0];
            string srcMd5 = fs[1].Trim();
            Debug.Assert(fs.Length == 2, "read packlist.txt error:" + file);

            bool isBinFile = outfile.CustomEndsWith(".bin");
            //文件被非法删除,Bin文件无法确认存在,只能直接再释放一次
            var tempMd5 = string.Format("{0}_md5", fs[0]);
            if (isBinFile || !File.Exists(outfile))
            {
                PlayerPrefs.DeleteKey(fs[0]);
                PlayerPrefs.DeleteKey(tempMd5);
            }

            if (srcMd5 == PlayerPrefs.GetString(tempMd5))
            {
                if (isBinFile)
                {
                    totalExtractCount++;
                }
                continue;
            }

            WWW streamingWWW = new WWW(infile);
            yield return(streamingWWW);

            if (streamingWWW.error != null)
            {
                Debug.LogError(infile);
                continue;
            }
            if (streamingWWW.isDone)
            {
                string dir = Path.GetDirectoryName(outfile);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                if (isBinFile)
                {
                    LocalExtractExecutor lee = new LocalExtractExecutor();
                    lee.LocalPath  = dataPath;
                    lee.FileName   = fs[0];
                    lee.SrcMD5     = srcMd5;
                    lee.FileBytes  = streamingWWW.bytes;
                    lee.OnComplete = OnUpdateChangeStatus;

                    totalExtractCount++;
                    les.Add(lee);
                    extractFiles.Add(fs[0]);
                }
                else
                {
                    File.WriteAllBytes(outfile, streamingWWW.bytes);
                    PlayerPrefs.SetInt(fs[0], 1);
                    PlayerPrefs.SetString(tempMd5, srcMd5);
                    if (curStreamingIndex % 3 == 0)  //每写入3个文件后保存记录,减少IO
                    {
                        PlayerPrefs.Save();
                    }
//                    Debugger.Log("正在解包文件:>" + infile) ;
                }
            }
            streamingWWW.Dispose();
        }

        yield return(Yielders.EndOfFrame);

        //启动多线程解压
        //		Debugger.Log("MaxThreadCount:" + maxThreadCount);
        bar.UpdateProgress(0);
        if (les.Count > 0)
        {
            bar.SetMessage(LanguageTips.EXTRACT_PACKAGE);
            threadMgr.PoolScheduler.StartASyncThreads(les.ToArray(), onExtractComplete, onExtractDone, maxThreadCount);
        }
        else
        {
            onExtractComplete(null);
        }
#endif
    }
Пример #14
0
    bool SetServerInfo()
    {
        Hashtable tbl = MiniJSON.Json.Deserialize(_serverInfo) as Hashtable;

        if (tbl == null)
        {
            Debug.LogError(string.Format("Get server list error: {0}", _serverInfo));

#if UNITY_EDITOR
            print("------------------------------------------------------------------");
            _serverInfo = "{\"update_url\":\"http://192.168.0.243/rsync/TestServer/Resources/\",\"corp\":\"1\",\"version\":\"1.0.0\",\"recommend_no\":\"2\",\"serverlist\":[{\"server_no\":\"1\",\"server_name\":\"彭老师联调\",\"ip\":\"192.168.0.94\",\"port\":\"1221\",\"is_open\":\"1\",\"other\":\"\"},{\"server_no\":\"2\",\"server_name\":\"高士哥\",\"ip\":\"192.168.0.80\",\"port\":\"8999\",\"is_open\":\"1\",\"other\":\"\"},{\"server_no\":\"3\",\"server_name\":\"243内部\",\"ip\":\"192.168.0.243\",\"port\":\"2001\",\"is_open\":\"1\",\"other\":\"\"},{\"server_no\":\"5\",\"server_name\":\"海明\",\"ip\":\"192.168.0.185\",\"port\":\"1221\",\"is_open\":\"1\",\"other\":\"\"},{\"server_no\":\"4\",\"server_name\":\"243内部(稳)\",\"ip\":\"192.168.0.243\",\"port\":\"2002\",\"is_open\":\"1\",\"other\":\"\"}]}";
            tbl         = MiniJSON.Json.Deserialize(_serverInfo) as Hashtable;
            if (tbl == null)
            {
                return(false);
            }
#else
            return(false);
#endif
        }

        var           temp_url   = tbl["update_url"].ToString().TrimEnd('/');
        var           temps      = temp_url.Split('/');
        StringBuilder update_url = new StringBuilder();
        for (int i = 0; i < temps.Length; ++i)
        {
            if (i < temps.Length - 1)
            {
                update_url.Append(temps[i]);
                update_url.Append("/");
            }
            else
            {
                if (temps[i].Split('.').Length >= 3)
                {
                    var remoteVersion = GameVersion.CreateVersion(temps[i]);
                    if (GameManager.localVersion < GameManager.packVersion)
                    {
                        if (remoteVersion < GameManager.packVersion)
                        {
                            update_url.Append(GameManager.packVersion.ToString());
                        }
                        else
                        {
                            update_url.Append(remoteVersion.ToString());
                        }
                    }
                    else
                    {
                        if (remoteVersion < GameManager.localVersion)
                        {
                            update_url.Append(GameManager.localVersion.ToString());
                        }
                        else
                        {
                            update_url.Append(remoteVersion.ToString());
                        }
                    }
                }
                else
                {
                    update_url.Append(temps[i]);
                }
                update_url.Append("/");
            }
        }

        User_Config.SetWebServerUrl(update_url.ToString());
        User_Config.SetDefaultServer(Convert.ToInt32(tbl["recommend_no"]));

        ServerInfo info;
        if (User_Config.serverList == null)
        {
            User_Config.serverList = new System.Collections.Generic.List <ServerInfo>();
        }

        ArrayList list = tbl["serverlist"] as ArrayList;
        Hashtable serverTbl;
        int       len = list.Count;
        for (int i = 0; i < len; i++)
        {
            serverTbl = list[i] as Hashtable;

            info            = new ServerInfo();
            info.openTime   = i;
            info.serverNo   = Convert.ToInt32(serverTbl["server_no"].ToString());
            info.serverName = serverTbl["server_name"].ToString();
            info.serverIp   = serverTbl["ip"].ToString();
            info.serverPort = serverTbl["port"].ToString();
            info.isOpen     = Convert.ToInt32(serverTbl["is_open"].ToString());
            info.other      = serverTbl["other"].ToString();
            info.hostId     = serverTbl["host_id"].ToString();
            if (serverTbl.ContainsKey("corp_id"))
            {
                info.corpId = serverTbl["corp_id"].ToString();
            }
            else
            {
                info.corpId = "1000";
            }

            User_Config.serverList.Add(info);
        }

        User_Config.serverList.Sort((x, y) => x.openTime.CompareTo(y.openTime) * -1);
        return(true);
    }
Пример #15
0
    /// <summary>
    /// 用户登录接口回调
    /// </summary>
    /// <param name="result"></param>
    private void LoginCallback(string result)
    {
        if (result == "TIMEOUT" || result == "ERROR")
        {
            MessageBox.Show("访问网络超时或出错");
            return;
        }
        object jsonParsed = MiniJSON.Json.Deserialize(result);

        if (jsonParsed != null)
        {
            Hashtable jsonMap = jsonParsed as Hashtable;
            if (jsonMap.ContainsKey("errorCode"))
            {
                int errorCode = Int32.Parse(jsonMap["errorCode"].ToString());
                if (errorCode != 0)
                {
                    Debugger.LogError("errorCode: {0}", errorCode);
                    MessageBox.Show(ErrorCodeText(errorCode));
                    return;
                }
            }
            if (jsonMap.ContainsKey("data"))
            {
                Hashtable dataDict = jsonMap["data"] as Hashtable;
                if (dataDict.ContainsKey("time"))
                {
                    time = dataDict["time"].ToString();
                }
                if (dataDict.ContainsKey("token"))
                {
                    token = dataDict["token"].ToString();
                }
                if (dataDict.ContainsKey("accountName"))
                {
                    accountName = dataDict["accountName"].ToString();
                }
                if (dataDict.ContainsKey("roleInfoList"))
                {
                    if (User_Config.roleInfoList != null)
                    {
                        User_Config.roleInfoList.Clear();
                    }
                    roleInfoList = dataDict["roleInfoList"] as ArrayList;
                    User_Config.SetRoleInfoList(roleInfoList);
                }
                if (dataDict.ContainsKey("lastServer"))
                {
                    if (User_Config.lastServerList != null)
                    {
                        User_Config.lastServerList.Clear();
                    }
                    lastServer = dataDict["lastServer"] as ArrayList;
                    User_Config.SetLastServerList(lastServer);
                    User_Config.SetServerListLevel(User_Config.lastServerList);
                }
                if (dataDict.ContainsKey("serverList"))
                {
                    if (User_Config.serverList != null)
                    {
                        User_Config.serverList.Clear();
                    }
                    serverList = dataDict["serverList"] as ArrayList;
                    User_Config.SetServerList(serverList);
                    User_Config.SetServerListLevel(User_Config.serverList);
                }
                if (dataDict.ContainsKey("showAccount"))
                {
                    showAccount = bool.Parse(dataDict["showAccount"].ToString());
                }
                if (dataDict.ContainsKey("versionView"))
                {
                    versionView = bool.Parse(dataDict["versionView"].ToString());
                }
                if (dataDict.ContainsKey("access_token"))
                {
                    access_token = dataDict["access_token"].ToString();
                }
                if (dataDict.ContainsKey("isWhite"))
                {
                    IsWhite = bool.Parse(dataDict["isWhite"].ToString());
                }
            }
            Debugger.Log("用户登录接口回调: {0}", result);
        }
        else
        {
            Debugger.LogError("Login callback json parse error!");
        }
    }