public override void UserEventTriggered(IChannelHandlerContext context, object evt)
 {
     if (evt is IdleStateEvent)
     {
         IdleState state = ((IdleStateEvent)evt).State;
         if (state == IdleState.AllIdle)
         {
             IChannel channel     = context.Channel;
             string   channelInfo = channel.ToString();
             logger.Info($"exec idle event send active request", channelInfo);
             if (currentTime < TRY_TIMES)
             {
                 currentTime++;
                 SendActiveTest(context);
             }
             else
             {
                 logger.Info($"active idle close", channelInfo);
                 channel.CloseAsync();
             }
         }
     }
     else
     {
         base.UserEventTriggered(context, evt);
     }
 }
Exemple #2
0
        public void ForeverReConnect()
        {
            int connNum = Config.ConnNum - sessionMap.Count;

            var policy = Policy
                         .Handle <Exception>()
                         .WaitAndRetryForeverAsync((retryCount) => TimeSpan.FromSeconds(5), (e, rc, ts) =>
            {
                Config.ClientStatus = ClientStatus.CONNECT_FAIL;
                logger.Error($"open {Config.Ip}:{Config.Port} fali, retry {rc}", e);
            });

            for (int i = 0; i < connNum; i++)
            {
                Session session = new Session(loggerFactory);
                sessionMap.AddSession(session);
                policy.ExecuteAsync((token) =>
                {
                    return(bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Config.Ip), Config.Port)));
                }, session.reConnect.Token).ContinueWith(t =>
                {
                    IChannel channel = t.Result;
                    logger.Info($"open {Config.Ip}:{Config.Port} success", channel.ToString());
                    session.Channel = channel;
                });
            }
        }
        public override void ChannelActive(IChannelHandlerContext context)
        {
            logger.Info($"start login user:{config.UserName}, pwd:{config.Password}");
            this.context = context;
            SmsPacket connect = GetConnectRequestPacket(config.UserName, config.Password);

            CmppTools.SendAsync(context, connect);
            var delay = new TimeSpan(0, 0, disconnectSecond);

            timer.NewTimeout(this, delay);
            base.ChannelActive(context);
        }
Exemple #4
0
        public static string ConvertToResPath(string bundleName)
        {
            string text = bundleName.Replace('.', '/');

            ClientLogger.Info("==> ConvertToResPath : " + text);
            return(text);
        }
Exemple #5
0
        public static string ConvertToAssetBundleName(string ResName)
        {
            string text = ResName.Replace('/', '.');

            ClientLogger.Info("==> ConvertToAssetBundleName : " + text);
            return(text);
        }
Exemple #6
0
        public static string GetResourcePath()
        {
            string text = GlobalSetting.AssetSavePath;

            switch (Application.platform)
            {
            case RuntimePlatform.OSXPlayer:
                text += "Mac/";
                break;

            case RuntimePlatform.WindowsPlayer:
                text += "Windows/";
                break;

            case RuntimePlatform.OSXWebPlayer:
            case RuntimePlatform.WindowsWebPlayer:
                text += "WebPlayer/";
                break;

            case RuntimePlatform.IPhonePlayer:
                text += "IOS/";
                break;

            case RuntimePlatform.Android:
                text += "Android/";
                break;
            }
            ClientLogger.Info("==> GetResourcePath : " + text);
            return(text);
        }
        public bool dispatchEvent(CustomEvent evt)
        {
            string type = evt.type;

            if (!this.checkForEvent(type))
            {
                if (this.allowWarningOutputs)
                {
                    Debug.LogWarning("Event Manager: Event \"" + type + "\" triggered has no listeners!");
                }
                return(false);
            }
            ArrayList arrayList = this._listeners[type] as ArrayList;

            if (this.allowDebugOutputs)
            {
                ClientLogger.Info(string.Concat(new object[]
                {
                    "Event Manager: Event ",
                    type,
                    " dispatched to ",
                    arrayList.Count,
                    (arrayList.Count != 1) ? " listeners." : " listener."
                }));
            }
            foreach (EventListener eventListener in arrayList)
            {
                if (eventListener.listener && eventListener.listener.activeSelf)
                {
                    eventListener.listener.SendMessage(eventListener.function, evt, SendMessageOptions.DontRequireReceiver);
                }
            }
            return(false);
        }
        protected override void ChannelRead0(IChannelHandlerContext ctx, CmppMessageReceiveArgs <CmppHead, CmppActiveTest> msg)
        {
            logger.Info($"receive active request: {msg}", ctx.Channel.ToString());
            SmsPacket activeResp = GetActiveRespPacket(msg.Header);

            CmppTools.SendAsync(ctx, activeResp);
        }
 private void OnMsg_BattleShop_err(MobaMessage msg)
 {
     if (msg.Param != null)
     {
         string message = msg.Param as string;
         ClientLogger.Info(message);
         Singleton <TipView> .Instance.ShowViewSetText("操作失败", 1f);
     }
 }
 public override void Dump()
 {
     ClientLogger.Info(string.Format("=====>Stats: {0} {1}, {2}, release {3}", new object[]
     {
         this._name,
         this._popCount,
         this._newCount,
         this._releaseCount
     }));
 }
        public override void ChannelInactive(IChannelHandlerContext context)
        {
            logger.Info("channel inactive, channel clear own session", context.Channel.ToString());
            var session = sessionMap.GetSessionOrDefault(context);

            sessionMap.TryRemove(session);
            session.Send = false;
            connctCloseCallBack?.Invoke();
            base.ChannelInactive(context);
        }
Exemple #12
0
        protected override void Encode(IChannelHandlerContext context, SmsPacket message, List <object> output)
        {
            logger.Info($"send data packet:{message}", context.Channel.ToString());
            var         buffer      = message.Message.ToBytes();
            var         TotalLength = CmppConstants.HeaderSize + buffer.Length;
            IByteBuffer byteBuffer  = context.Allocator.Buffer(4)
                                      .WriteInt(TotalLength)
                                      .WriteInt((int)message.Message.GetCommandId())
                                      .WriteInt((int)((CmppHead)(message.Head)).SequenceId)
                                      .WriteBytes(buffer, 0, buffer.Length);

            output.Add(byteBuffer);
        }
Exemple #13
0
        public static string LoadConfigFile(string name)
        {
            string applicationDataPath = GlobalSetting.GetApplicationDataPath();
            string a      = FileUtils.LoadFileByLine(applicationDataPath, name);
            string result = null;

            if (a != "error")
            {
                ClientLogger.Info("LoadConfigFile : 读取配置文件错误!");
            }
            else
            {
                FileUtils.CreateFile(applicationDataPath, name, "192.168.200.252");
                result = FileUtils.LoadFileByLine(applicationDataPath, name);
            }
            return(result);
        }
 public static void CopyDirectory(string abssourcePath, string absdestinationPath, string filter = "")
 {
     if (abssourcePath.EndsWith("/*"))
     {
         abssourcePath = abssourcePath.Substring(0, abssourcePath.IndexOf("/*"));
         string[] directories = Directory.GetDirectories(abssourcePath);
         for (int i = 0; i < directories.Length; i++)
         {
             string        text                = directories[i];
             DirectoryInfo directoryInfo       = new DirectoryInfo(text);
             string        absdestinationPath2 = Path.Combine(absdestinationPath, directoryInfo.Name);
             FileUtils.CopyDirectory(text, absdestinationPath2, string.Empty);
         }
     }
     else
     {
         if (abssourcePath.EndsWith("/"))
         {
             abssourcePath = abssourcePath.Substring(0, abssourcePath.Length - 1);
         }
         ClientLogger.Info("==> CopyDirectory : sourcePath = " + abssourcePath + ",destinationPath = " + absdestinationPath);
         DirectoryInfo directoryInfo2 = new DirectoryInfo(abssourcePath);
         Directory.CreateDirectory(absdestinationPath);
         FileSystemInfo[] fileSystemInfos = directoryInfo2.GetFileSystemInfos();
         for (int j = 0; j < fileSystemInfos.Length; j++)
         {
             FileSystemInfo fileSystemInfo = fileSystemInfos[j];
             if (!fileSystemInfo.Name.Contains(".svn") && !fileSystemInfo.Name.Contains(".meta"))
             {
                 string text2 = Path.Combine(absdestinationPath, fileSystemInfo.Name);
                 if (fileSystemInfo is DirectoryInfo)
                 {
                     Directory.CreateDirectory(text2);
                     FileUtils.CopyDirectory(fileSystemInfo.FullName, text2, string.Empty);
                 }
                 else if (filter == string.Empty || fileSystemInfo.FullName.Contains(filter))
                 {
                     File.Copy(fileSystemInfo.FullName, text2, true);
                 }
             }
         }
     }
 }
    protected override void Update()
    {
        if (this.targets == null)
        {
            return;
        }
        Vector3?pos = this.pos;

        if (!pos.HasValue)
        {
            return;
        }
        if (this.trans == null)
        {
            return;
        }
        if (!this.inProcess)
        {
            this.startPos  = this.trans.position;
            this.dir       = (this.pos.Value + Vector3.up - this.trans.position).normalized;
            this.inProcess = true;
        }
        this.trans.position += this.dir * this.data.config.effect_speed * Time.deltaTime;
        this.distance        = Vector3.Distance(this.startPos, this.trans.position);
        if (this.distance >= 7.5f && this.isForward)
        {
            this.dir       = -this.dir;
            this.isForward = false;
        }
        ClientLogger.Info(this.distance);
        if (this.distance <= 0.3f && !this.isForward)
        {
            base.doDestroy();
        }
        if (this.CheackHit())
        {
            this.OnHit();
        }
    }
Exemple #16
0
        public static string GetRuntimeStreamingAssetsPath()
        {
            string text;

            if (Application.platform == RuntimePlatform.Android)
            {
                text = "jar:file://" + Application.persistentDataPath + "!/assets/";
            }
            else if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                text = Application.persistentDataPath + "/Raw/";
            }
            else if (Application.platform == RuntimePlatform.WindowsPlayer)
            {
                text = "file://" + Application.dataPath + "/StreamingAssets/";
            }
            else
            {
                text = "file://" + Application.dataPath + "/StreamingAssets/";
            }
            ClientLogger.Info("==> StreamingAssetsPath : " + text);
            return(text);
        }
Exemple #17
0
        protected override object Decode(IChannelHandlerContext context, IByteBuffer input)
        {
            var channelInfo = context.Channel.ToString();
            var obj         = base.Decode(context, input);

            if (AcceptInboundMessage(obj))
            {
                IByteBuffer msg   = (IByteBuffer)obj;
                byte[]      array = new byte[msg.ReadableBytes];
                msg.GetBytes(0, array);
                var cmppHeader = new CmppHead().FromBytes0(array);

                if (cmppHeader.TotalLength == array.Length)
                {
                    object args = null;
                    switch (cmppHeader.CommandId)
                    {
                    case CmppConstants.CommandCode.Connect:

                        break;

                    case CmppConstants.CommandCode.ConnectResp:
                        var ConnectResp = new CmppConnectResp().FromBytes0(array);
                        args = new CmppMessageReceiveArgs <CmppHead, CmppConnectResp>(cmppHeader, ConnectResp);
                        break;

                    case CmppConstants.CommandCode.Terminate:
                        //var Terminate = new CmppTerminate();
                        //Terminate.FromBytes(packet);
                        break;

                    case CmppConstants.CommandCode.TerminateResp:
                        //var TerminateResp = new CmppTerminateResp();
                        //TerminateResp.FromBytes(packet);
                        break;

                    case CmppConstants.CommandCode.Submit:
                        //var Submit = new Cmpp2.CmppSubmit();
                        //Submit.FromBytes(packet);
                        break;

                    case CmppConstants.CommandCode.SubmitResp:
                        var SubmitResp = new CmppSubmitResp().FromBytes0(array);
                        args = new CmppMessageReceiveArgs <CmppHead, CmppSubmitResp>(cmppHeader, SubmitResp);
                        break;

                    case CmppConstants.CommandCode.Deliver:
                        var Deliver = new CmppDeliver().FromBytes0(array);
                        args = new CmppMessageReceiveArgs <CmppHead, CmppDeliver>(cmppHeader, Deliver);
                        break;

                    case CmppConstants.CommandCode.DeliverResp:
                        //var DeliverResp = new Cmpp2.CmppDeliverResp();
                        //DeliverResp.FromBytes(packet);
                        break;

                    case CmppConstants.CommandCode.ActiveTest:
                        var ActiveTest = new CmppActiveTest().FromBytes0(array);
                        args = new CmppMessageReceiveArgs <CmppHead, CmppActiveTest>(cmppHeader, ActiveTest);
                        break;

                    case CmppConstants.CommandCode.ActiveTestResp:
                        //var ActiveTestResp = new CmppActiveTestResp().FromBytes0(array);
                        //args = new CmppMessageReceiveArgs<CmppHead, CmppActiveTestResp>(cmppHeader, ActiveTestResp);
                        break;

                    default:
                        throw new NotSupportedException(cmppHeader.CommandId.ToString());
                    }
                    logger.Info($"receive cmpp data:{args?.ToString()} cmd:{cmppHeader.CommandId}", channelInfo);
                    return(args);
                }
                else
                {
                    throw new InvalidDataException("The received cmpp package is invalid");
                }
            }

            logger.Info($"receive unknown data:{obj?.ToString()}", channelInfo);
            return(obj);
        }
 public override void ChannelActive(IChannelHandlerContext ctx)
 {
     logger.Info($"channel active", ctx.Channel.ToString());
     ctx.FireChannelActive();
 }
Exemple #19
0
 protected override void Cmpp2SubmitResp(List <CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > > msgs)
 {
     logger.Info("Cmpp2SubmitResp receive: " + string.Join(",", msgs));
 }