Пример #1
0
        /// <summary>
        /// 端口独立线程,crtsnt数组序号
        /// </summary>
        void ClientThread(object clienttable)
        {
            var table = (ClientItem)clienttable;

            try
            {
                table.WorkEnable = true;
                table.Remote     = IPAddress.Parse(table.Client.Client.RemoteEndPoint.ToString().Split(':')[0]);
                OnAccept?.Invoke(table.Remote);
                using (var ns = table.Client.GetStream())
                {
                    var buffer = new byte[BufferSize];
                    var read   = 0;
                    while (table.WorkEnable && table.Client.Connected)
                    {
                        using (var ms = new MemoryStream())
                        {
                            while (ns.DataAvailable)//!sr.EndOfStream)
                            {
                                read = ns.Read(buffer, 0, BufferSize);
                                ms.Write(buffer, 0, read);
                            }
                            OnDataReceive?.Invoke(table.Remote, ms.ToArray());
                        }
                        Thread.Sleep(Interval);
                    }
                }
            }
            finally
            {
                table.Client.Close();
                ClientTable.Remove(table);
                OnDisConnect?.Invoke(table.Remote);
            }
        }
Пример #2
0
        protected virtual void OnAcceptConnection(Socket socket)
        {
            var xSocket = new XSocket(socket);

            _clientsConnected.Add(xSocket);
            OnAccept?.Invoke(this, new XSocketArgs(xSocket));
        }
        private IEnumerator HandleConversation(PlayerController interactor)
        {
            SpriteOutlineManager.AddOutlineToSprite(base.sprite, Color.black);
            base.spriteAnimator.PlayForDuration("talk_start", 1, "talk");
            interactor.SetInputOverride("npcConversation");
            Pixelator.Instance.LerpToLetterbox(0.35f, 0.25f);
            yield return(null);

            int conversationIndex = m_allowMeToIntroduceMyself ? 0 : conversation.Count - 1;

            while (conversationIndex < conversation.Count - 1)
            {
                Tools.Print($"Index: {conversationIndex}");
                TextBoxManager.ClearTextBox(this.talkPoint);
                TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, -1f, conversation[conversationIndex], interactor.characterAudioSpeechTag, instant: false, showContinueText: true);
                float timer = 0;
                while (!BraveInput.GetInstanceForPlayer(interactor.PlayerIDX).ActiveActions.GetActionFromType(GungeonActions.GungeonActionType.Interact).WasPressed || timer < 0.4f)
                {
                    timer += BraveTime.DeltaTime;
                    yield return(null);
                }
                conversationIndex++;
            }
            m_allowMeToIntroduceMyself = false;
            TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, -1f, conversation[conversation.Count - 1], interactor.characterAudioSpeechTag, instant: false, showContinueText: true);

            GameUIRoot.Instance.DisplayPlayerConversationOptions(interactor, null, acceptText, declineText);
            int selectedResponse = -1;

            while (!GameUIRoot.Instance.GetPlayerConversationResponse(out selectedResponse))
            {
                yield return(null);
            }

            if (selectedResponse == 0)
            {
                TextBoxManager.ClearTextBox(this.talkPoint);
                base.spriteAnimator.PlayForDuration("do_effect", -1, "talk");

                while (base.spriteAnimator.CurrentFrame < 20) //play do effect anim
                {
                    yield return(null);
                }
                OnAccept?.Invoke(interactor, this.gameObject);
                base.spriteAnimator.Play("talk");
                TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, 1f, "Bam!", interactor.characterAudioSpeechTag, instant: false);
                yield return(new WaitForSeconds(1f));
            }
            else
            {
                OnDecline?.Invoke(interactor, this.gameObject);
                TextBoxManager.ClearTextBox(this.talkPoint);
            }

            // Free player and run OnAccept/OnDecline actions
            interactor.ClearInputOverride("npcConversation");
            Pixelator.Instance.LerpToLetterbox(1, 0.25f);
            base.spriteAnimator.Play("idle");
        }
Пример #4
0
        private void CheckAuthorization()
        {
            var userHash = UserHash.FromUserData(Login);

            if (Authorization.CheckAuthorization(userHash))
            {
                OnAccept?.Invoke();
            }
        }
Пример #5
0
        // private readonly Action<TcpConnection> initialize;

        /// <summary>
        /// <see cref="TcpClient"/> adapter.
        /// </summary>
        /// <param name="client">The specified client.</param>
        /// <param name="action">client action.</param>
        public TcpConnection(TcpClient client, Action <TcpConnection> action)
        {
            tcpClient = client;
            //initialize = action;
            networkStream  = tcpClient.GetStream();
            RemoteEndPoint = CopyEndPoint(tcpClient.Client.RemoteEndPoint);
            action?.Invoke(this);
            OnAccept?.Invoke(this);
            receiveBuffer = new byte[tcpClient.ReceiveBufferSize];
            StartReceive();
        }
Пример #6
0
        private void ProcessAccept(SocketAsyncEventArgs e)
        {
            Socket socket = null;

            if (e.SocketError != SocketError.Success)
            {
                OnError?.Invoke(this.Socket, new SocketException((int)e.SocketError));
                //var errorCode = (int)e.SocketError;

                //The listen socket was closed
                //if (errorCode == 995 || errorCode == 10004 || errorCode == 10038)
                //{
                //    Error(new SocketException(errorCode), "接受客户连接时异常");
                //    return;
                //}
                //this.SerConfig.Error(new SocketException(errorCode));
            }
            else
            {
                socket = e.AcceptSocket;
            }
            e.AcceptSocket = null;//下一次开始接受需要设置null;
            bool canContinue;

            try
            {
                canContinue = Socket.AcceptAsync(e);
            }
            catch (ObjectDisposedException)
            {
                canContinue = true;
            }
            catch (NullReferenceException)
            {
                canContinue = true;
            }
            catch (Exception exc)
            {
                OnError?.Invoke(this.Socket, exc);
                //this.SerConfig.Error(exc);
                canContinue = true;
            }
            if (socket != null)
            {
                OnAccept?.Invoke(socket);
                //CreateConSession(socket);
            }
            if (!canContinue)
            {
                ProcessAccept(e);
            }
        }
Пример #7
0
        public virtual bool NewInput(MyConsoleKeyInfo KeyInfo)
        {
            switch (KeyInfo.KeyChar)
            {
            case (char)SpecialAsciiKeys.Tab:
                OnTab?.Invoke(this, DateTime.Now);
                return(true);

            case '\n':
                OnAccept?.Invoke(this, DateTime.Now);
                return(true);
            }
            return(false);
        }
Пример #8
0
        async void OnAcceptChallenge()
        {
            bool success;

            using (new HUD("Accepting challenge..."))
            {
                success = await ViewModel.AcceptChallenge();
            }

            if (success)
            {
                "Challenge accepted".ToToast(ToastNotificationType.Success);
            }

            OnAccept?.Invoke();
        }
Пример #9
0
        protected State ProcessInputChar(char nextChar)
        {
            if (nextChar == '\n')
            {
                _lineCounter++;
                _charCounter = 0;
            }
            else if (nextChar != '\r')
            {
                _charCounter++;
            }

            if (IsSkip(nextChar))
            {
                return(State.Ignore);
            }

            State result = _parser.AddSymbol(nextChar);

            switch (result)
            {
            case State.Ignore:
                OnIgnore?.Invoke(this, _charCounter, nextChar);
                break;

            case State.Accept:
                OnAccept?.Invoke(this, _charCounter, nextChar);
                break;

            case State.Incorrect:
                OnIncorrect?.Invoke(this, _lineCounter, _charCounter, nextChar);
                break;

            case State.VeryBigDigit:
                OnVeryBigDigit?.Invoke(this, _lineCounter);
                break;

            case State.PairDone:
                OnNewPair?.Invoke(this, _parser.ReceivedCoordinates.Last());
                break;

            default:
                break;
            }

            return(result);
        }
Пример #10
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public ConfirmDialogBoxViewModel()
        {
            AcceptCommand = new RelayParamCommand((param) =>
            {
                // Set the response
                Response = true;

                // Call dialog close command
                if (param is ICommand command && command.CanExecute(null))
                {
                    command.Execute(null);
                }

                // Invoke accept callback
                OnAccept?.Invoke();
            });
        }
Пример #11
0
        /// <summary>
        /// 当异步连接完成时调用此方法
        /// </summary>
        /// <param name="e">操作对象</param>
        private void ProcessAccept(SocketAsyncEventArgs e)
        {
            connectId++;
            //把连接到的客户端信息添加到集合中
            ConnectClient connecttoken = new ConnectClient();

            connecttoken.socket = e.AcceptSocket;
            //从接受端重用池获取一个新的SocketAsyncEventArgs对象
            connecttoken.saea_receive              = m_receivePool.Pop();
            connecttoken.saea_receive.UserToken    = connectId;
            connecttoken.saea_receive.AcceptSocket = e.AcceptSocket;
            connectClient.TryAdd(connectId, connecttoken);
            //一旦客户机连接,就准备接收。
            if (!e.AcceptSocket.ReceiveAsync(connecttoken.saea_receive))
            {
                ProcessReceive(connecttoken.saea_receive);
            }
            //事件回调
            OnAccept?.Invoke(connectId);
            //接受第二连接的请求
            StartAccept(e);
        }
Пример #12
0
 private void HandleIncomingConnection()
 {
     while (IsStarted)
     {
         if (server.Pending())
         {
             var id     = Guid.NewGuid().ToString();
             var client = server.AcceptSocket();
             if (clients.TryAdd(id, client))
             {
                 new Thread(() => HandleReceiveData(id)).Start();
                 OnAccept?.Invoke(this, id);
                 Send(id, Encoding.UTF8.GetBytes("Hello, i'm server!"));
             }
             else
             {
                 client.Shutdown(SocketShutdown.Both);
                 client.Close();
             }
         }
         Thread.Sleep(50);
     }
 }
Пример #13
0
 void HandleAccept()
 {
     OnAccept?.Invoke();
 }
Пример #14
0
 public void Accept()
 {
     OnAccept?.Invoke();
     Close();
 }
Пример #15
0
 private void MessageServer_OnAccept(int connectID)
 {
     OnAccept?.Invoke(GetClientIpById(connectID), GetClientPortIpById(connectID), connectID);
 }
Пример #16
0
        private IEnumerator HandleConversation(PlayerController interactor)
        {
            SpriteOutlineManager.AddOutlineToSprite(base.sprite, Color.black);
            base.spriteAnimator.PlayForDuration("talk_start", 1, "talk");
            interactor.SetInputOverride("npcConversation");
            Pixelator.Instance.LerpToLetterbox(0.35f, 0.25f);
            yield return(null);

            //Determine Dialogue
            var conversationToUse = new List <string>()
            {
                "Null"
            };

            //Price Mult
            GameLevelDefinition lastLoadedLevelDefinition = GameManager.Instance.GetLastLoadedLevelDefinition();
            float PriceMult = (lastLoadedLevelDefinition == null) ? 1f : lastLoadedLevelDefinition.priceMultiplier;

            //Check for if ever met before and then else
            if (hasDeclinedAlreadyThisRun)
            {
                conversationToUse = new List <string>()
                {
                    "You're back? Did you change your mind?",
                    "Did you get hopelessly lost?",
                    "Please tell me you got hopelessly lost!",
                };
            }
            else
            {
                conversationToUse = new List <string>()
                {
                    "Well hello again, young adventurer!",
                    "You look lost... mayhaps you are in need of a finely crafted... map?",
                    "Only " + (20 * PriceMult) + " of those little janglies, you know the deal."
                };
            }


            int conversationIndex = 0;

            while (conversationIndex < conversationToUse.Count - 1)
            {
                TextBoxManager.ClearTextBox(this.talkPoint);
                TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, -1f, conversationToUse[conversationIndex], interactor.characterAudioSpeechTag, instant: false, showContinueText: true);
                float timer = 0;
                while (!BraveInput.GetInstanceForPlayer(interactor.PlayerIDX).ActiveActions.GetActionFromType(GungeonActions.GungeonActionType.Interact).WasPressed || timer < 0.4f)
                {
                    timer += BraveTime.DeltaTime;
                    yield return(null);
                }
                conversationIndex++;
            }
            TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, -1f, conversationToUse[conversationToUse.Count - 1], interactor.characterAudioSpeechTag, instant: false, showContinueText: true);


            var acceptanceTextToUse = "Null";
            var declineTextToUse    = "Null";

            if (hasDeclinedAlreadyThisRun)
            {
                acceptanceTextToUse = "...Just give me the map. <Lose " + (20 * PriceMult) + " Money>";
                declineTextToUse    = "Not lost, I know EXACTLY where I am!";
            }
            else
            {
                acceptanceTextToUse = "Yeah, a map would be nice <Lose " + (20 * PriceMult) + " Money>";
                declineTextToUse    = "No thanks, I can find my way around juuust fine.";
            }

            GameUIRoot.Instance.DisplayPlayerConversationOptions(interactor, null, acceptanceTextToUse, declineTextToUse);
            int selectedResponse = -1;

            while (!GameUIRoot.Instance.GetPlayerConversationResponse(out selectedResponse))
            {
                yield return(null);
            }

            if (selectedResponse == 0)
            {
                TextBoxManager.ClearTextBox(this.talkPoint);
                base.spriteAnimator.PlayForDuration("do_effect", -1, "talk");
                base.spriteAnimator.Play("talk");
                if (interactor.carriedConsumables.Currency >= (20 * PriceMult))
                {
                    TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, 1f, "Enjoy the fruits of my knowledge!", interactor.characterAudioSpeechTag, instant: false);
                    OnAccept?.Invoke(interactor, this.gameObject);
                    hasBeenUsedThisRun = true;
                }
                else
                {
                    TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, 1f, "Oh... looks like you don't have the cash. Welp, research ain't free.", interactor.characterAudioSpeechTag, instant: false);
                }
                yield return(new WaitForSeconds(1f));
            }
            else
            {
                OnDecline?.Invoke(interactor, this.gameObject);
                TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, 1f, "Harumph, enjoy being lost...", interactor.characterAudioSpeechTag, instant: false);
                hasDeclinedAlreadyThisRun = true;
                TextBoxManager.ClearTextBox(this.talkPoint);
            }

            interactor.ClearInputOverride("npcConversation");
            Pixelator.Instance.LerpToLetterbox(1, 0.25f);
            base.spriteAnimator.Play("idle");
        }
Пример #17
0
        private IEnumerator HandleConversation(PlayerController interactor)
        {
            // Show text and lock player in place
            TextBoxManager.ShowStoneTablet(this.talkPoint.position, this.talkPoint, -1f, text, true, false);
            int selectedResponse = -1;

            interactor.SetInputOverride("shrineConversation");
            yield return(null);

            // Wait for player response
            if (!m_canUse)
            {
                GameUIRoot.Instance.DisplayPlayerConversationOptions(interactor, null, declineText, string.Empty);
            }
            else if (isToggle)
            {
                if (m_isToggled)
                {
                    GameUIRoot.Instance.DisplayPlayerConversationOptions(interactor, null, declineText, string.Empty);
                }
                else
                {
                    GameUIRoot.Instance.DisplayPlayerConversationOptions(interactor, null, acceptText, string.Empty);
                }
            }
            else
            {
                GameUIRoot.Instance.DisplayPlayerConversationOptions(interactor, null, acceptText, declineText);
            }


            while (!GameUIRoot.Instance.GetPlayerConversationResponse(out selectedResponse))
            {
                yield return(null);
            }

            // Free player and run OnAccept/OnDecline actions
            interactor.ClearInputOverride("shrineConversation");
            TextBoxManager.ClearTextBox(this.talkPoint);
            if (!m_canUse)
            {
                yield break;
            }

            if (selectedResponse == 0 && isToggle)
            {
                (m_isToggled ? OnDecline : OnAccept)?.Invoke(interactor, this.gameObject);
                m_isToggled = !m_isToggled;
                yield break;
            }

            if (selectedResponse == 0)
            {
                OnAccept?.Invoke(interactor, this.gameObject);
            }
            else
            {
                OnDecline?.Invoke(interactor, this.gameObject);
            }
            yield break;
        }
Пример #18
0
 void Accept() => OnAccept?.Invoke();
Пример #19
0
 public void InvokeAccept(BaseCommand BaseCommand)
 {
     OnAccept?.Invoke(this, DateTime.Now);
 }
Пример #20
0
 private void ServerSokcet_OnAccepted(object obj)
 {
     OnAccept?.Invoke(this, ((IUserToken)obj).ID);
 }
Пример #21
0
 private void ButtonAccept_OnClick(object sender, EventArgs e)
 {
     OnAccept?.Invoke(data, null);
 }
Пример #22
0
        private IEnumerator HandleConversation(PlayerController interactor)
        {
            //ETGModConsole.Log("HandleConversation Started");
            SpriteOutlineManager.AddOutlineToSprite(base.sprite, Color.black);
            base.spriteAnimator.PlayForDuration("talk_start", 1, "talk");
            interactor.SetInputOverride("npcConversation");
            Pixelator.Instance.LerpToLetterbox(0.35f, 0.25f);
            yield return(null);

            var conversationToUse = AllJammedState.AllJammedActive ? conversation2 : conversation;
            int conversationIndex = 0;

            //ETGModConsole.Log("We made it to the while loop");
            while (conversationIndex < conversationToUse.Count - 1)
            {
                Tools.Print($"Index: {conversationIndex}");
                TextBoxManager.ClearTextBox(this.talkPoint);
                TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, -1f, conversationToUse[conversationIndex], interactor.characterAudioSpeechTag, instant: false, showContinueText: true);
                float timer = 0;
                while (!BraveInput.GetInstanceForPlayer(interactor.PlayerIDX).ActiveActions.GetActionFromType(GungeonActions.GungeonActionType.Interact).WasPressed || timer < 0.4f)
                {
                    timer += BraveTime.DeltaTime;
                    yield return(null);
                }
                conversationIndex++;
            }
            //ETGModConsole.Log("We made it through the while loop");
            m_allowMeToIntroduceMyself = false;
            TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, -1f, conversationToUse[conversationToUse.Count - 1], interactor.characterAudioSpeechTag, instant: false, showContinueText: true);

            var acceptanceTextToUse = AllJammedState.AllJammedActive ? acceptText2 : acceptText;
            var declineTextToUse    = AllJammedState.AllJammedActive ? declineText2 : declineText;

            GameUIRoot.Instance.DisplayPlayerConversationOptions(interactor, null, acceptanceTextToUse, declineTextToUse);
            int selectedResponse = -1;

            while (!GameUIRoot.Instance.GetPlayerConversationResponse(out selectedResponse))
            {
                yield return(null);
            }
            //ETGModConsole.Log("We made it to the if statement");
            if (selectedResponse == 0)
            {
                TextBoxManager.ClearTextBox(this.talkPoint);
                base.spriteAnimator.PlayForDuration("do_effect", -1, "talk");
                OnAccept?.Invoke(interactor, this.gameObject);
                base.spriteAnimator.Play("talk");
                TextBoxManager.ShowTextBox(this.talkPoint.position, this.talkPoint, 1f, "It is done...", interactor.characterAudioSpeechTag, instant: false);
                yield return(new WaitForSeconds(1f));
            }
            else
            {
                OnDecline?.Invoke(interactor, this.gameObject);
                TextBoxManager.ClearTextBox(this.talkPoint);
            }
            //ETGModConsole.Log("We made it through the if statement");

            // Free player and run OnAccept/OnDecline actions
            interactor.ClearInputOverride("npcConversation");
            Pixelator.Instance.LerpToLetterbox(1, 0.25f);
            base.spriteAnimator.Play("idle");
            //ETGModConsole.Log("We made it");
        }