Beispiel #1
0
        private void AcceptCallback(IAsyncResult ar)
        {
            try
            {
                allDone.Set();

                Socket listener = (Socket)ar.AsyncState;
                Socket handler  = listener.EndAccept(ar);   //DMO Client

                Console.WriteLine("Accepting a client: {0}", handler.RemoteEndPoint);

                Client state = new Client();
                state.m_socket = handler;

                if (OnAccept != null)
                {
                    OnAccept.BeginInvoke(state, new AsyncCallback(ProcessedAccept), state);
                }
                else
                {
                    handler.BeginReceive(state.buffer, 0, Client.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
                }
            }
            catch (ObjectDisposedException) { }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: AcceptCallback\n{0}", e);
            }
        }
Beispiel #2
0
        private void ProcessedAccept(IAsyncResult ar)
        {
            OnAccept.EndInvoke(ar);

            Client state   = (Client)ar.AsyncState;
            Socket handler = state.m_socket;

            try
            {
                handler.BeginReceive(state.buffer, 0, Client.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), state);
            }
            catch (Exception e)
            {
                if (e is ObjectDisposedException || (e is SocketException))
                {
                    if (OnClose != null)
                    {
                        OnClose.BeginInvoke(state, new AsyncCallback(EndClose), state);
                    }
                }
                else
                {
                    throw;
                }
            }
        }
        /// <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);
            }
        }
Beispiel #4
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");
        }
Beispiel #6
0
        private void CheckAuthorization()
        {
            var userHash = UserHash.FromUserData(Login);

            if (Authorization.CheckAuthorization(userHash))
            {
                OnAccept?.Invoke();
            }
        }
Beispiel #7
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();
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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);
        }
Beispiel #10
0
 public TextDialog(OnAccept callback, string description, Predicate<string> predicate, string startingValue)
 {
     //save the predicate that is used to determine whether the result is acceptable
     _valueAcceptancePredicate = predicate;
     //init the description
     _descriptionText = new Text(description, 32) {Color = Color.Black};
     //register callback for after having been added to a scene
     OnAdded += OnAdd;
     //save callback
     _callback = callback;
     //set group to avoid pausing this
     Group = (int) PauseGroups.Menu;
     //reset input
     _startingInputValue = startingValue;
 }
Beispiel #11
0
        async void OnAcceptChallenge()
        {
            bool success;

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

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

            OnAccept?.Invoke();
        }
Beispiel #12
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);
        }
Beispiel #13
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();
            });
        }
Beispiel #14
0
 public TextDialog(OnAccept callback, string description, Predicate <string> predicate, string startingValue)
 {
     //save the predicate that is used to determine whether the result is acceptable
     _valueAcceptancePredicate = predicate;
     //init the description
     _descriptionText = new Text(description, 32)
     {
         Color = Color.Black
     };
     //register callback for after having been added to a scene
     OnAdded += OnAdd;
     //save callback
     _callback = callback;
     //set group to avoid pausing this
     Group = (int)PauseGroups.Menu;
     //reset input
     _startingInputValue = startingValue;
 }
Beispiel #15
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);
        }
Beispiel #16
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);
     }
 }
Beispiel #17
0
 public static extern void HP_Set_FN_Server_OnAccept(IntPtr pListener, OnAccept fn);
Beispiel #18
0
 private void MessageServer_OnAccept(int connectID)
 {
     OnAccept?.Invoke(GetClientIpById(connectID), GetClientPortIpById(connectID), connectID);
 }
        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");
        }
Beispiel #20
0
 private void ServerSokcet_OnAccepted(object obj)
 {
     OnAccept?.Invoke(this, ((IUserToken)obj).ID);
 }
Beispiel #21
0
 void Accept() => OnAccept?.Invoke();
Beispiel #22
0
 public void InvokeAccept(BaseCommand BaseCommand)
 {
     OnAccept?.Invoke(this, DateTime.Now);
 }
Beispiel #23
0
 public static extern void HP_Set_FN_HttpServer_OnAccept(IntPtr pListener, OnAccept fn);
Beispiel #24
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;
        }
 public MessageBoxGamePadController(OnAccept acceptDelegate_, OnCancel cancelDelegate_)
 {
     AcceptCallBack = acceptDelegate_;
     CancelCallBack = cancelDelegate_;
 }
Beispiel #26
0
 public void Accept()
 {
     OnAccept?.Invoke();
     Close();
 }
Beispiel #27
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");
        }
Beispiel #28
0
 private void ButtonAccept_OnClick(object sender, EventArgs e)
 {
     OnAccept?.Invoke(data, null);
 }
Beispiel #29
0
 void HandleAccept()
 {
     OnAccept?.Invoke();
 }