Esempio n. 1
0
        /// <summary>
        /// Handle Message From Client when associated terminal is in guest status
        /// </summary>
        /// <param name="telnetClient">Telnet client</param>
        /// <param name="message">message from client</param>
        private void MFCTerminalGuest(TelnetClient telnetClient, string message)
        {
            if (telnetClient.GetTerminal().GetDataBag()["step"] == "connected")
            {
                switch (message.ToLower())
                {
                case "?":
                case "help":
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n\r\n"
                                                     + "  new    - Create a new account\r\n"
                                                     + "  login  - Login to an existing account\r\n"
                                                     + "  bye    - Disconnect\r\n\r\n"
                                                     + "Welcome> ");
                    break;

                case "q":
                case "bye":
                    TelnetServer.SendMessageToClient(telnetClient, "\r\nCya...\r\n\r\n");
                    TelnetServer.KickClient(telnetClient);
                    break;

                case "new":
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Name: ");
                    telnetClient.GetTerminal().GetDataBag()["step"] = "create_name";
                    break;

                case "login":
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Email: ");
                    telnetClient.GetTerminal().GetDataBag()["step"] = "login_name";
                    break;

                default:
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Unknown welcome command \"" + message + "\". Try \"help\".\r\n\r\n"
                                                     + "Welcome> ");
                    break;
                }
            }
            else if (telnetClient.GetTerminal().GetDataBag()["step"] == "login_name")
            {
                telnetClient.GetTerminal().GetDataBag()["login_name"] = message;
                telnetClient.GetTerminal().GetDataBag()["step"]       = "login_password";
                TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                 + "Password: "******"step"] == "login_password")
            {
                var loginRequest = new AccountLoginAccountRequest()
                {
                    Email    = telnetClient.GetTerminal().GetDataBag()["login_name"],
                    Password = message
                };
                AccountLoginAccountResponse loginResponse = (AccountLoginAccountResponse)telnetClient.GetTerminal().SendToApi(loginRequest);
                if (loginResponse.IsSuccess())
                {
                    telnetClient.GetTerminal().Authenticate(loginResponse.Account.Id);
                    telnetClient.GetTerminal().SubscribeMessageToTerminal(MessageFromTerminal);
                    Clients[telnetClient.GetTerminal().GetId()]     = telnetClient;
                    telnetClient.GetTerminal().GetDataBag()["step"] = "authenticated";
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Hello " + telnetClient.GetTerminal().GetDataBag()["login_name"] + "\r\n\r\n"
                                                     + "Account> ");
                }
                else
                {
                    telnetClient.GetTerminal().GetDataBag()["step"] = "connected";
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Bad username or password.\r\n\r\n"
                                                     + "Welcome> ");
                }
            }
            else if (telnetClient.GetTerminal().GetDataBag()["step"] == "create_name")
            {
                telnetClient.GetTerminal().GetDataBag()["create_name"] = message;
                telnetClient.GetTerminal().GetDataBag()["step"]        = "create_email";
                TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                 + "Email: ");
            }
            else if (telnetClient.GetTerminal().GetDataBag()["step"] == "create_email")
            {
                telnetClient.GetTerminal().GetDataBag()["create_email"] = message;
                telnetClient.GetTerminal().GetDataBag()["step"]         = "create_password";
                TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                 + "Password: "******"step"] == "create_password")
            {
                var createAccountResponse = telnetClient.GetTerminal().SendToApi(new AccountCreateAccountRequest()
                {
                    Email    = telnetClient.GetTerminal().GetDataBag()["create_email"],
                    Password = message
                });
                if (createAccountResponse.IsSuccess())
                {
                    telnetClient.GetTerminal().SubscribeMessageToTerminal(MessageFromTerminal);
                    Clients[telnetClient.GetTerminal().GetId()]     = telnetClient;
                    telnetClient.GetTerminal().GetDataBag()["step"] = "authenticated";
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Hello " + telnetClient.GetTerminal().GetDataBag()["create_name"] + "\r\n\r\n"
                                                     + "Account> ");
                }
                else
                {
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Unable to create account (but I still like you).\r\n\r\n"
                                                     + "Welcome> ");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handle Message From Client when associated terminal is in authenticated status
        /// </summary>
        /// <param name="telnetClient">Telnet client</param>
        /// <param name="message">message from client</param>
        private void MFCTerminalAuthenticated(TelnetClient telnetClient, string message)
        {
            if (telnetClient.GetTerminal().GetDataBag()["step"] == "create_character")
            {
                MFCTerminalAuthenticatedCreatePlayer(telnetClient, message);
            }
            else if (telnetClient.GetTerminal().GetDataBag()["step"] == "authenticated")
            {
                switch (message.Split(' ').First().ToLower())
                {
                case "?":
                case "help":
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n\r\n"
                                                     + "  new         - Create a new character\r\n"
                                                     + "  list        - List existing characters\r\n"
                                                     + "  play {name} - Play an existing character\r\n"
                                                     + "  back        - Return to previous screen\r\n"
                                                     + "  bye         - Disconnect\r\n\r\n"
                                                     + "Account> ");
                    break;

                case "back":
                    telnetClient.GetTerminal().SetStatus(TerminalStatus.Guest);
                    telnetClient.GetTerminal().GetDataBag()["step"] = "connected";
                    TelnetServer.SendMessageToClient(telnetClient, "\r\nWelcome> ");
                    break;

                case "new":
                    telnetClient.GetTerminal().GetDataBag()["step"] = "create_character";
                    MFCTerminalAuthenticatedCreatePlayer(telnetClient, message);
                    break;

                case "list":
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n\r\n");
                    var characters = telnetClient.GetTerminal().GetAttachable();
                    characters.ForEach(delegate(Item player)
                    {
                        TelnetServer.SendMessageToClient(telnetClient, "  " +
                                                         player.GetProperty <VisibleItemProperty>().Name +
                                                         " (" + player.Id + ")\r\n");
                    });
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n");
                    TelnetServer.SendMessageToClient(telnetClient, "Account> ");
                    break;

                case "q":
                case "bye":
                    TelnetServer.SendMessageToClient(telnetClient, "Cya...\r\n");
                    TelnetServer.KickClient(telnetClient);
                    break;

                case "play":
                    var name = message.Split(' ').Last().ToLower();
                    telnetClient.GetTerminal().GetAttachable().ForEach(delegate(Item player)
                    {
                        if (player.GetProperty <VisibleItemProperty>().Name.ToLower() == name)
                        {
                            telnetClient.GetTerminal().Attach(player.Id);
                            telnetClient.GetTerminal().GetDataBag()["step"] = "attached";
                            TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                             + "Terminal attached to avatar. Play!\r\n\r\n"
                                                             + "> ");
                        }
                    });
                    if (telnetClient.GetTerminal().GetStatus() != TerminalStatus.Attached)
                    {
                        TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                         + "Unknown character \"" + name + "\"\r\n"
                                                         + "Account> ");
                    }
                    break;

                default:
                    TelnetServer.SendMessageToClient(telnetClient, "\r\n"
                                                     + "Unknown account command \"" + message + "\". Try \"help\".\r\n\r\n"
                                                     + "Account> ");
                    break;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handle Message From client when associated terminal is in attached status (playing!)
        /// </summary>
        /// <param name="telnetClient"></param>
        /// <param name="message"></param>
        private void MFCTerminalAttached(TelnetClient telnetClient, string message)
        {
            string firstWord = message.Split(' ').First();

            switch (firstWord)
            {
            case "admin":
                var words = message.Split(' ');
                if (message == "admin item graph")
                {
                    MFCAdminItemTree(telnetClient, message);
                }
                if (words[1] == "item" && words[2] == "json" && words[3] == "update")
                {
                    var json = message.Remove(0, message.IndexOf('{'));
                    MFCAdminItemJsonUpdate(telnetClient, words[4], json);
                }
                if (words[1] == "item" && words[2] == "json" && words[3] == "read")
                {
                    MFCAdminItemJsonRead(telnetClient, words[4]);
                }
                break;

            case "bye":
            case "q":
            case "exit":
                TelnetServer.SendMessageToClient(telnetClient, "\r\n\r\nCya...\r\n");
                TelnetServer.KickClient(telnetClient);
                break;

            case "look":
                var response = telnetClient.GetTerminal().SendToApi(new WorldReadLocationSummaryRequest()
                {
                });
                telnetClient.GetTerminal().SendToClientAsync(response);
                break;

            case "go":
                MFCGo(telnetClient, message);
                break;

            case "smile":
            case "frown":
                MFCEmote(telnetClient, message);
                break;

            case "help":
                TelnetServer.SendMessageToClient(telnetClient, "\r\n\r\n" +
                                                 " - Admin item graph\r\n" +
                                                 " - Admin item json update {guid} {json}\r\n" +
                                                 " - Admin item json read {guid}\r\n" +
                                                 " - Look\r\n" +
                                                 " - Bye\r\n" +
                                                 " - Go {exit name, or partial exit name}\r\n" +
                                                 " - Smile\r\n" +
                                                 " - Frown\r\n\r\n> ");
                break;

            default:
                TelnetServer.SendMessageToClient(telnetClient, "\r\nBad command. Try \"help\"\r\n> ");
                break;
            }
        }