Beispiel #1
0
        /// <summary>
        /// Handles a new prompt for this user.
        /// </summary>
        /// <param name="newPrompt"></param>
        public void Prompt(HeldPrompt newPrompt)
        {
            if (this.clearingPrompts)
            {
                return;
            }
            int foundPrompt = -1;

            lock (this.prompts)
            {
                for (int i = 0; i < prompts.Length; i++)
                {
                    if (this.prompts[i] == null)
                    {
                        foundPrompt     = i;
                        this.prompts[i] = newPrompt;
                        break;
                    }
                }
            }
            if (foundPrompt != -1)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("New Prompt ").Append(foundPrompt + 1).Append(endOfLine);
                newPrompt.OnTransition();
                this.sendMessage(builder.ToString());
            }
            else
            {
                //this.sendMessage("You were too busy to " + TODO ?);
                newPrompt.Respond(null);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Forces this connection to log out of the current account and basically reset.
 /// </summary>
 public void LogOut()
 {
     lock (this.prompts)
     {
         ClearPrompts();
         mainPrompt = new LoginPrompt(this);
     }
     //No need for account.LogOut(), but if there was it would maybe go here.
     this.LoggedInAccount = null;
     mainPrompt.OnTransition();
 }
Beispiel #3
0
 public void Prompt(HeldPrompt prompt)
 {
     if (Client != null)
     {
         Client.Prompt(prompt);
     }
     else
     {
         prompt.Respond(null); //Use default from prompt.
         //TODO / NOTE: Caller should do everything it's supposed to do before calling Prompt.
     }
 }
Beispiel #4
0
 public Client(Socket s, int packetSize)
 {
     this.socket       = s;
     this.buffer       = new byte[packetSize];
     this.LastReceived = DateTime.UtcNow;
     this.inputHandlerTypes.Add(IACHandlerType.Instance);
     this.TransitionToInputHandler(new DefaultInputHandler());
     this.socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, receiveData, null);
     negotiateTelnetMode(TelnetCode.TERMTYPE);
     this.mainPrompt = new LoginPrompt(this);
     //TODO: Server intro goes here
     this.sendMessage("Unnamed EspressoMUD Server"); //TODO: Move to external resource file.
     mainPrompt.OnTransition();
 }
Beispiel #5
0
 /// <summary>
 /// Removes the HeldPrompt specified from this User's response options. Caller is responsible for cleaning up game state
 /// and other things associated with the prompt; prompt is not told to clean itself up.
 /// </summary>
 /// <param name="prompt"></param>
 public void RemovePrompt(HeldPrompt prompt)
 {
     lock (this.prompts)
     {
         for (int i = 0; i < prompts.Length; i++)
         {
             if (prompts[i] == prompt)
             {
                 prompts[i] = null;
                 return;
             }
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// Responds to a prompt and handles the prompt's return value. Non-null responses should usually call this instead of calling Respond manually.
        /// </summary>
        /// <param name="input">User's response to the prompt.</param>
        /// <param name="prompt">Prompt being responded to.</param>
        /// <param name="toPrompt">Internal 'position' of the prompt being responded to in this.prompts</param>
        private void RespondToPrompt(string input, HeldPrompt prompt, int toPrompt = -1)
        {
            HeldPrompt next;

            try
            {
                next = prompt.Respond(input); //Skip prompt number + space
            }
            catch (Exception e)
            {
                //TODO: Error logging
                sendMessage("An error has occurred while processing your input: ^n" + e.ToString());
                if (!prompt.IsStillValid())
                {
                    if (this.mainPrompt == prompt)
                    {
                        sendMessage("Logging out to get back to a working state.");
                        LogOut();
                    }
                    else
                    {
                        sendMessage("Aborting broken prompt " + toPrompt);
                        this.RemovePrompt(prompt);
                    }
                }
                return;
            }
            if (next != null && !this.clearingPrompts)
            {
                lock (this.prompts)
                {
                    if (toPrompt != -1 && this.prompts[toPrompt] == prompt)
                    {
                        this.prompts[toPrompt] = next;
                        next.OnTransition();
                    }
                    else if (toPrompt == -1 && this.mainPrompt == prompt)
                    {
                        this.mainPrompt = next;
                        next.OnTransition();
                    }
                    else
                    {
                        this.Prompt(next);
                    }
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Forces this connection to log out of the current MOB, but stay in the account.
 /// </summary>
 public void ReturnToLoggedInPrompt()
 {
     lock (this.prompts)
     {
         if (this.LoggedInAccount == null)
         {
             LogOut();
         }
         else
         {
             ClearPrompts();
             mainPrompt = LoginPrompt.GetLoggedInPrompt(this);
             mainPrompt.OnTransition();
         }
     }
 }
Beispiel #8
0
        private bool trySpecificPrompt(string input)
        {
            string[] words       = input.Split(' ');
            int      promptIndex = words[0].IndexOf('.');

            if (promptIndex == -1)
            {
                return(false);
            }
            int toPrompt;

            if (!Int32.TryParse(words[0].Substring(0, promptIndex), out toPrompt))
            {
                return(false);
            }
            //words[0] = words[0].Substring(promptIndex + 1);
            HeldPrompt prompt = this.GetPrompt(toPrompt);

            if (prompt == null)
            {
                this.sendMessage(toPrompt.ToString() + " is not a valid prompt index. Do not start a message with something like \"1.\" without an associated prompt.");
            }
            else if (!prompt.IsStillValid())
            {
                this.sendMessage("That prompt has recently expired.");
                this.RemovePrompt(toPrompt);
            }
            else if (words.Length == 1)
            {
                this.sendMessage(prompt.PromptMessage);
            }
            else
            {
                RespondToPrompt(input.Substring(promptIndex + 1), prompt, toPrompt);
            }
            return(true);
        }