Beispiel #1
0
        /// <summary>
        /// 处理网络操作线程
        /// </summary>
        private void WebThreadHandle()
        {
            while (m_threadRunFlag)
            {
                if (!m_netRunFlag)
                {
                    continue;
                }

                HttpPacket sendPacket = null;
                lock (m_sendQueue)
                {
                    if (m_sendQueue.Count > 0)
                    {
                        sendPacket = m_sendQueue.Dequeue();
                    }
                }

                if (null == sendPacket)
                {
                    Thread.Sleep(c_ThreadSleepTime);
                    continue;
                }

                try
                {
                    byte[] bytes   = NetEnCoder.Encode(sendPacket);
                    byte[] byteRes = m_webClient.UploadData(NetHttpManager.Instance.GetUrl(), c_httpMethod, bytes);

                    if (null != byteRes)
                    {
                        //解析http返回包
                        //目前解析 太浪费内存、使用缓冲区
                        int resLength = byteRes.Length;
                        int offset    = 0;
                        int nLength   = NetEnCoder.DecodeInt(byteRes, ref offset);
                        resLength -= offset;

                        if (resLength >= nLength)
                        {
                            uint uCode = NetEnCoder.DecodeUInt(byteRes, ref offset);

                            int        nCount     = nLength - NetEnCoder.GetIntLength();
                            object     msg        = PBEnCoder.Decode(uCode, byteRes, offset, nCount);
                            HttpPacket recvPacket = new HttpPacket(uCode, nCount);
                            recvPacket.handler = sendPacket.handler;

                            lock (m_recvQueueLocker)
                            {
                                m_recvQueue.Enqueue(recvPacket);
                            }
                        }
                    }
                }
                catch (WebException e)
                {
                    LoggerHelper.Except(e);
                }
            }
        }
Beispiel #2
0
    public bool ReadMd5FromXML(string packageMD5Content, ref Dictionary <string, string> packageMD5Dic, ref List <PackageInfo> packageInfoList)
    {
        SecurityElement element = XMLParser.LoadXML(packageMD5Content);

        if (element == null)
        {
            return(false);
        }
        packageInfoList.Clear();
        packageMD5Dic.Clear();
        foreach (SecurityElement element2 in element.Children)
        {
            try
            {
                PackageInfo item = new PackageInfo();
                string      str  = element2.Attribute("n");
                item.Name = str;
                string str2    = str.Substring(7, str.Length - 11);
                string version = str2.Substring(0, str2.IndexOf('-'));
                item.LowVersion = new VersionCodeInfo(version);
                string str4 = str2.Substring(str2.IndexOf('-') + 1);
                item.HighVersion = new VersionCodeInfo(str4);
                item.Md5         = element2.Text;
                packageInfoList.Add(item);
                packageMD5Dic[item.Name] = item.Md5;
            }
            catch (Exception exception)
            {
                LoggerHelper.Except(exception, null);
            }
        }
        return(true);
    }
        public override void OnDeath(int actionID)
        {
            if (IsGolem)
            {
                if (golem != null)
                {
                    golem.Dying();
                }
                if (golemFx != null)
                {
                    golemFx.Dying();
                }
            }
            else
            {
                base.OnDeath(actionID);
            }
            try
            {
                if (sfxHandler)
                {
                    sfxHandler.RemoveAllFX();
                    if (m_monsterData != null && m_monsterData.dieFx != null)
                    {
                        foreach (var item in m_monsterData.dieFx)
                        {
                            sfxHandler.HandleFx(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Except(ex);
            }
            if (motor)
            {
                motor.gravity = 0;
            }
            if (Actor)
            {
                var cc = Actor.collider as CharacterController;
                if (cc)
                {
                    cc.radius = 0;
                }
            }
            #region Shader

            if (m_monsterData != null && ShaderData.dataMap.ContainsKey(m_monsterData.shader) &&
                GameObject && GameObject.GetComponentsInChildren <SkinnedMeshRenderer>(true) != null)
            {
                fadeTimer = TimerHeap.AddTimer((uint)(m_monsterData.deadTime - 500), 0, () =>
                {
                    MogoFXManager.Instance.AlphaFadeOut(GameObject, 0.3f);
                });
            }

            #endregion
        }
    public void ShowNotice()
    {
        if (String.IsNullOrEmpty(noticeXml))
        {
            LoggerHelper.Info("Empty Notice.");
            return;
        }
        try
        {
            var xml = XMLParser.LoadXML(noticeXml);
            var map = XMLParser.LoadIntMap(xml, SystemConfig.NOTICE_CONTENT_KEY);

            List <MogoNotice2.Notice> list = new List <MogoNotice2.Notice>();
            foreach (Dictionary <string, string> dic in map.Values)
            {
                MogoNotice2.Notice notice = new MogoNotice2.Notice();
                notice.text  = dic["text"];
                notice.title = dic["title"];
                notice.date  = dic["date"];
                notice.isNew = (dic["isnew"] == "1" ? true : false);
                list.Add(notice);

                //LoggerHelper.Debug("date:" + notice.date + ",title:" + notice.title + ",text:" + notice.text + ",isnew:" + notice.isNew);
            }
            list.Reverse();

            MogoNotice2.Instance.ShowNotice(list);
        }
        catch (Exception ex)
        {
            LoggerHelper.Except(ex);
        }
    }
Beispiel #5
0
        public Dictionary <int, T> FormatXMLDataTem <T>(string fileName) where T : GameData, new()
        {
            var result = new Dictionary <int, T>();

            try
            {
                Dictionary <Int32, Dictionary <String, String> > map; //int32 为 id, string 为 属性名, string 为 属性值
                if (XMLParser.LoadIntMap(fileName, m_isUseOutterConfig, out map))
                {
                    //result = dicType.GetConstructor(Type.EmptyTypes).Invoke(null);
                    var props = typeof(T).GetProperties();  //获取实体属性
                    foreach (var item in map)
                    {
                        var t = new T(); //构造实体实例
                        t.SetData(props, item);
                        //  var v1 = Utils.GetValue((string)item.Key, typeof(Int32));
                        result.Add(item.Key, t);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Except(ex, "FormatData Error: " + fileName);
            }

            return(result);
        }
Beispiel #6
0
    public void Unfocus()
    {
        try
        {
            if (gameObject == null)
            {
                return;
            }

            if (smr == null)
            {
                smr = gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(true)[0];
            }
            if (PlayerShader == null)
            {
                return;
            }

            if (smr.sharedMaterial == null)
            {
                return;
            }
            smr.sharedMaterial.shader = PlayerShader;
        }
        catch (Exception ex)
        {
            LoggerHelper.Except(ex);
        }
        //if (sfxHandler)
        //    sfxHandler.RemoveFXs(51001);
    }
    public System.Collections.IEnumerator GetGameObject(Action <Object> action)
    {
        while (true)
        {
            if (!m_gameObject)
            {
                yield return(null);

                try
                {
                    m_gameObject = Resources.Load(Path);
                    if (m_gameObject == null)
                    {
                        LoggerHelper.Warning("null gameobject: " + Path);
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Except(ex, Path);
                }
                yield return(null);
            }

            if (action != null)
            {
                action(m_gameObject);
            }
            yield break;
        }
    }
 protected virtual void SetNextMove()
 {
     try
     {
         if (motor)
         {
             if (transform.parent != null)
             {
                 motor.MoveTo(pathPoints[currentPointIndex] + transform.parent.position);
             }
             else
             {
                 motor.MoveTo(pathPoints[currentPointIndex] + transform.position);
             }
         }
         else
         {
             Debug.LogError("null motor");
         }
     }
     catch (System.Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
Beispiel #9
0
    /// <summary>
    /// 调用加载资源等待完成。
    /// </summary>
    /// <param name="resource"></param>
    /// <param name="loaded"></param>
    /// <returns></returns>
    private void WaitAndDo(Resource resource, Queue <Action> q, Action <Resource, MonoBehaviour, Action> loadResource, Action <Object> loaded, Action <Resource> progress = null)
    {
        var sw = new System.Diagnostics.Stopwatch();

        sw.Start();
        Action act = () =>
        {
            resource.IsLoading = false;
            sw.Stop();
            //Mogo.Util.LoggerHelper.Debug("LoadResource: " + sw.ElapsedMilliseconds);
            try
            {
                if (loaded != null)
                {
                    if (resource.Object == null)
                    {
                        if (!resource.RelativePath.EndsWith(".unity"))
                        {
                            LoggerHelper.Error(string.Concat("Can not load: ", resource.RelativePath));
                        }
                        loaded(null);
                    }
                    else
                    {
                        loaded(resource.Object);
                        //foreach (var item in ResourceManager.GetResourcesInfo(resource))
                        //{
                        //    item.Release(false);
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Except(ex);
            }

            if (q.Count != 0)
            {
                var action = q.Dequeue();
                action();
            }
            else
            {
                m_isLoading[q] = false;
                //Mogo.Util.LoggerHelper.Debug("isLoading false");
            }
        };

        resource.IsLoading = true;
        loadResource(resource, this, act);
        if (progress != null)
        {
            progress(resource);
        }
        //StartCoroutine(ResourceManager.LoadResource(resource, act));
        //yield return StartCoroutine(res.Wait());
        //act();
    }
Beispiel #10
0
    //添加一个网络异常处理的功能,mycontinue跳过当前这个下载下一个
    static void HandleNetworkError(Exception e, Action mycontinue, Action again, Action finished = null)
    {
        LoggerHelper.Except(e);
        Action action = () =>
        {
            //LoggerHelper.Debug("webclient error:" + e.Message);
            if (e.Message.Contains("ConnectFailure") || //连接失败
                e.Message.Contains("NameResolutionFailure") || //域名解析失败
                e.Message.Contains("No route to host"))    //找不到主机
            {
                LoggerHelper.Error("-----------------Webclient ConnectFailure-------------");
                //异常时弹出网络设置对话框
                ShowMsgBoxForNetworkDisconnect(again, _showMsg ? ":" + e.Message : "");
            }
            else
            //(404) Not Found
            if (e.Message.Contains("(404) Not Found") || e.Message.Contains("403"))
            {
                LoggerHelper.Error("-----------------WebClient NotFount-------------");
                //抛出一个error,并且继续下载下一个
                //mycontinue();
                //服务器维护中,请稍后再试
                ShowMsgForServerMaintenance(again, _showMsg ? ":" + e.Message : "");
            }
            else
            //Disk full
            if (e.Message.Contains("Disk full"))
            {
                LoggerHelper.Error("-----------------WebClient Disk full-------------");
                ShowMsgBoxForDiskFull(again, _showMsg ? ":" + e.Message : "");
            }
            else
            //timed out
            if (e.Message.Contains("timed out") || e.Message.Contains("Error getting response stream"))
            {
                LoggerHelper.Error("-----------------WebClient timed out-------------");
                //again();
                ShowMsgForTimeout(again, _showMsg ? ":" + e.Message : "");
            }
            else
            //Sharing violation on path
            if (e.Message.Contains("Sharing violation on path"))
            {
                LoggerHelper.Error("-----------------WebClient Sharing violation on path-------------");
                again();
            }
            else
            {
                //LoggerHelper.Debug("-----------------WebClient myfinished-------------");
                //if (finished != null) finished();
                //again();
                ShowMsgForUnknown(again, _showMsg ? ":" + e.Message : "");
            }
        };

        DriverLib.Invoke(action);
    }
Beispiel #11
0
        /// <summary>
        /// 切包
        /// </summary>
        private void SplitPackets()
        {
            try
            {
                int offset = 0; //recvBuffer的整体读取游标
                while (m_recvUnreadBytes > NetEnCoder.GetIntLength())
                {
                    try
                    {
                        //备注:消息协议=长度(nCode和body所占字节长度) + sessionId +  nCode + body
                        int nLength = NetEnCoder.DecodeInt(m_recvBuffer, ref offset);//nocde + body 所占字节数
                        m_recvUnreadBytes -= offset;

                        if (m_recvUnreadBytes >= nLength)
                        {
                            uint uSession = NetEnCoder.DecodeUInt(m_recvBuffer, ref offset);

                            uint uCode = NetEnCoder.DecodeUInt(m_recvBuffer, ref offset);

                            int    nCount = nLength - 2 * NetEnCoder.GetIntLength();
                            object msg    = PBEnCoder.Decode(uCode, m_recvBuffer, offset, nCount);

                            TcpPacket packet = new TcpPacket(uSession, uCode, msg);
                            lock (m_recvQueueLocker)
                            {
                                LoggerHelper.Log(packet.ToString());
                                m_recvQueue.Enqueue(packet);
                            }

                            offset            += nCount;
                            m_recvUnreadBytes -= nLength;
                        }
                        else
                        {
                            m_recvUnreadBytes += offset;
                            offset            -= NetEnCoder.GetIntLength();
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        LoggerHelper.Except(e);
                        break;
                    }
                }

                // 整理 RecvBuffer, 将buffer 内容前移
                Buffer.BlockCopy(m_recvBuffer, offset, m_recvBuffer, 0, m_recvUnreadBytes);
            }
            catch (Exception e)
            {
                LoggerHelper.Except(e);
                LoggerHelper.Critical("SplitPackets error.");
                Close();
            }
        }
Beispiel #12
0
        /// <summary>
        /// 释放场景资源。
        /// </summary>
        public void UnloadScene(Action callBack)
        {
            if (m_currentMap != null)
            {
                try
                {
                    BillboardViewManager.Instance.Clear();
                    MogoFXManager.Instance.RemoveAllShadow();
                }
                catch (Exception ex)
                {
                    LoggerHelper.Except(ex);
                }
                foreach (var item in m_sceneObjects)
                {
                    //AssetCacheMgr.UnloadAsset(item);
                    AssetCacheMgr.ReleaseInstance(item);
                }
                m_sceneObjects.Clear();
                AssetCacheMgr.ReleaseResource(m_lightmap);
                m_lightmap = null;
                AssetCacheMgr.ReleaseResource(m_lightProbes);
                m_lightProbes = null;
                StoryManager.Instance.ClearPreload();
                SubAssetCacheMgr.ReleaseCharacterResources();
                SubAssetCacheMgr.ReleaseGearResources();
                SfxHandler.UnloadAllFXs();
                if (!String.IsNullOrEmpty(m_lastSceneResourceName))
                {
                    AssetCacheMgr.ReleaseResource(m_lastSceneResourceName);
                }
                //ResourceManager.UnloadUnusedAssets();
                //GC.Collect();
                if (callBack != null)
                {
                    callBack();
                }

                //LoggerHelper.Error("StartCoroutine UnloadUnusedAssets");
                //Driver.Instance.StartCoroutine(UnloadUnusedAssets(() =>
                //{
                //    //LoggerHelper.Error("UnloadUnusedAssets finish");
                //    GC.Collect();
                //    if (callBack != null)
                //        callBack();
                //}));
            }
            else
            {
                if (callBack != null)
                {
                    callBack();
                }
            }
        }
Beispiel #13
0
 private void OnFriendListResp(LuaTable luatable, UInt32 errorid)
 {
     try
     {
         friendManager.FriendListResp(luatable, (int)errorid);
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
Beispiel #14
0
 public string DownLoadText(string url)
 {
     try
     {
         return(this._webClient.DownloadString(url));
     }
     catch (Exception exception)
     {
         LoggerHelper.Except(exception, null);
         return(string.Empty);
     }
 }
Beispiel #15
0
 public string DownLoadText(String url)
 {
     try
     {
         return(_webClient.DownloadString(url));
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
         return(String.Empty);
     }
 }
Beispiel #16
0
 public string DownLoadText(String url)
 {
     //LoggerHelper.Debug ("DownloadMgr.DownLoadText() url="+url);
     try
     {
         return(_webClient.DownloadString(url));
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
         return(String.Empty);
     }
 }
Beispiel #17
0
 public override void SendReConnectKey(string key)
 {
     try
     {
         var u      = new ReConnectPluto();
         var result = u.Encode(key);
         m_tcpWorker.Send(result);
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
Beispiel #18
0
 public override void CheckDefMD5(Byte[] bytes)
 {
     try
     {
         var u      = new CheckDefMD5Pluto();
         var result = u.Encode(bytes);
         m_tcpWorker.Send(result);
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
Beispiel #19
0
 public override void Move(byte face, ushort x, ushort y)
 {
     try
     {
         var u      = new MovePluto();
         var result = u.Encode(face, x, y);
         m_tcpWorker.Send(result);
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
 public PlayerSkillManager(EntityParent owner)
     : base(owner)
 {
     theOwner = owner;
     AddListeners();
     try
     {
         InitData();
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
Beispiel #21
0
    public bool DownloadFile(String url, String localPath, String bakPath)
    {
        if (File.Exists(bakPath))
        {
            File.Delete(bakPath);
        }
        if (File.Exists(localPath))
        {
            File.Move(localPath, bakPath);
        }
        var path = Utils.GetDirectoryName(localPath);

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        try
        {
            if (IsEditor)
            {
                // 使用DownloadGzipString这个函数无法调试,所以Editor使用这个
                _webClient.DownloadFile(GetRandomParasUrl(url), localPath);
                return(true);
            }
            else
            {
                return(DownloadGzipFile(GetRandomParasUrl(url), localPath));
            }
        }
        catch (Exception ex)
        {
            LoggerHelper.Except(ex);
            if (File.Exists(bakPath))
            {
                if (File.Exists(localPath))
                {
                    File.Delete(localPath);
                }
                File.Move(bakPath, localPath);
            }
            return(false);
        }
        finally
        {
            if (File.Exists(bakPath))
            {
                File.Delete(bakPath);
            }
        }
    }
Beispiel #22
0
 public void InitEquip()
 {
     try
     {
         if (actorParent)
         {
             actorParent.InitNakedEquid();
         }
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
 public static void HideLoading()
 {
     try
     {
         if (MogoGlobleUIManager.Instance)
         {
             MogoGlobleUIManager.Instance.ShowGlobleLoadingUI(false);
         }
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
 public static void Loading(int progress)
 {
     try
     {
         if (MogoGlobleUIManager.Instance)
         {
             MogoGlobleUIManager.Instance.SetLoadingStatus(progress);
         }
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
 public static void ShowLoading(int tipId = 0, int textureId = 0)
 {
     try
     {
         if (MogoGlobleUIManager.Instance)
         {
             MogoGlobleUIManager.Instance.ShowGlobleLoadingUI(true, tipId, textureId);
         }
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
Beispiel #26
0
 public void Equip(List <int> equips, Action onDone = null)
 {
     try
     {
         if (actorParent)
         {
             actorParent.Equip(equips, onDone);
         }
     }
     catch (Exception ex)
     {
         LoggerHelper.Except(ex);
     }
 }
Beispiel #27
0
    public static List <T> LoadXMLText <T>(string text)
    {
        List <T> list = new List <T>();

        try
        {
            if (String.IsNullOrEmpty(text))
            {
                return(list);
            }
            Type type = typeof(T);
            var  xml  = XMLParser.LoadXML(text);
            Dictionary <Int32, Dictionary <String, String> > map = XMLParser.LoadIntMap(xml, text);
            var props = type.GetProperties(~System.Reflection.BindingFlags.Static);
            foreach (var item in map)
            {
                var obj = type.GetConstructor(Type.EmptyTypes).Invoke(null);
                foreach (var prop in props)
                {
                    if (prop.Name == "id")
                    {
                        prop.SetValue(obj, item.Key, null);
                    }
                    else
                    {
                        try
                        {
                            if (item.Value.ContainsKey(prop.Name))
                            {
                                var value = Utils.GetValue(item.Value[prop.Name], prop.PropertyType);
                                prop.SetValue(obj, value, null);
                            }
                        }
                        catch (Exception ex)
                        {
                            LoggerHelper.Except(ex);
                        }
                    }
                }
                list.Add((T)obj);
            }
        }
        catch (Exception ex)
        {
            LoggerHelper.Except(ex);
            LoggerHelper.Error("error text: \n" + text);
        }
        return(list);
    }
Beispiel #28
0
    public bool DownloadFile(string url, string localPath, string bakPath)
    {
        bool flag;

        if (System.IO.File.Exists(bakPath))
        {
            System.IO.File.Delete(bakPath);
        }
        if (System.IO.File.Exists(localPath))
        {
            System.IO.File.Move(localPath, bakPath);
        }
        string directoryName = Utils.GetDirectoryName(localPath);

        if (!Directory.Exists(directoryName))
        {
            Directory.CreateDirectory(directoryName);
        }
        try
        {
            if (this.IsEditor)
            {
                this._webClient.DownloadFile(this.GetRandomParasUrl(url), localPath);
                return(true);
            }
            flag = DownloadGzipFile(this.GetRandomParasUrl(url), localPath);
        }
        catch (Exception exception)
        {
            LoggerHelper.Except(exception, null);
            if (System.IO.File.Exists(bakPath))
            {
                if (System.IO.File.Exists(localPath))
                {
                    System.IO.File.Delete(localPath);
                }
                System.IO.File.Move(bakPath, localPath);
            }
            flag = false;
        }
        finally
        {
            if (System.IO.File.Exists(bakPath))
            {
                System.IO.File.Delete(bakPath);
            }
        }
        return(flag);
    }
        public override void HandleData()
        {
            string ip    = Arguments[0] as String;
            int    port  = (Int32)(UInt16)Arguments[1];
            string token = Arguments[2] as String;

            try
            {
                EventDispatcher.TriggerEvent <string, int, string>(Events.FrameWorkEvent.BaseLogin, ip, port, token);
            }
            catch (Exception ex)
            {
                LoggerHelper.Except(ex);
            }
        }
Beispiel #30
0
    public string GetText(string moduleName, string keyName)
    {
        string str = string.Empty;

        try
        {
            str = m_jsonData[moduleName][keyName].ToString();
        }
        catch (System.Exception ex)
        {
            LoggerHelper.Except(ex);
        }

        return(string.Empty);
    }