Esempio n. 1
0
        /// <summary>
        /// If our connection doesn't have a Player yet, everything is sent here to handle 
        /// login and Player creation.
        /// </summary>
        /// <param name="conn">The TelnetConnection the input is coming from</param>
        /// <param name="line">The input string</param>
        public static void LoginInterpret(TelnetConnection conn, string line)
        {
            Player player = new Player();
            player.MaxHealth = 200;
            player.Health = 200;
            player.PhysicalPower = 10;
            player.MagicPower = 10;
            player.Name = line;
            player.HandlingName = line;
            player.Connection = conn;

            foreach (Skill skill in Global.SkillTable.Values)
            {
                if (skill.Name == "Autoattack")
                    continue;
                player.Skills.Add(skill.Name, new SkillInstance(skill));
            }

            player.SkillSlots.Insert(0, player.Skills["Backstab"]);
            player.SkillSlots.Insert(1, player.Skills["Flurry"]);
            player.SkillSlots.Insert(2, player.Skills["Savage Strike"]);
            conn.SetPlayer(player);

            InputStringMenu strMenu = new InputStringMenu(player, "HandlePasswordInput");
            player.Menu = strMenu;
            player.SendMessage("Password: ");
        }
Esempio n. 2
0
        /// <summary>
        /// Thread-safe callback from each TelnetConnection, parsing input. 
        /// This function is timed internally by PulseTimer().
        /// </summary>
        /// <param name="conn">The TelnetConnection the input is coming from</param>
        /// <param name="line">The input string</param>
        public static void Interpret(TelnetConnection conn, string line)
        {
            // If the connection doesn't have a Player yet, it must be a new connection.
            // Forward it to LoginInterpret().
            if (conn.GetPlayer() == null)
            {
                LoginInterpret(conn, line);
            }
            else
            {
                Player player = conn.GetPlayer();
                string commandText = GetArgument(line, 1).Text;

                if (commandText == "" || line == "")
                    return;

                if (player.Menu == null)
                {
                    // Mosey through all the commands
                    foreach (KeyValuePair<string, Command> pair in Global.Commands.List)
                    {
                        // Match the command, allowing shorthand abbreviation (e.g. south = so = s)
                        // Note: Commands are parsed in the order they are added to the list in
                        //   Commands.cs, to give commands priority, add them to the top of the
                        //   list. (e.g. s will always match south, because it always comes before
                        //   score)
                        if (pair.Key.StartsWith(commandText.ToLower()))
                        {
                            Command command = pair.Value;

                            player.SendMessage("Command debug: " + GetArgument(line, 1).Text + "|" + GetArgument(line, 2).Text + "|" + GetArgument(line, 3).Text + "|" + GetArgument(line, 4).Text + "\n\r");
                            if (command != null)
                            {
                                // Voodoo reflection magic to execute the method that the command
                                //   wants to execute. Passes the Player itself, as well as the
                                //   input string to that method.
                                // TODO: This could be improved for effeciency by retrieving the
                                //   method once on load and storing it as a reference - possibly
                                //   a delegate? I'm not too sure. -DWE 2009/08/04
                                MethodInfo method = typeof(Commands).GetMethod(command.Method);
                                method.Invoke(Global.Commands, new object[] { player, pair.Value, line });
                                return;
                            }
                        }
                    }
                }
                else
                {
                    if (player.Menu is DynamicMenu)
                    {
                        // Mosey through all the commands
                        DynamicMenu menu = (DynamicMenu)player.Menu;
                        foreach (KeyValuePair<string, Command> pair in menu.List)
                        {
                            // Match the command, allowing shorthand abbreviation (e.g. south = so = s)
                            // Note: Commands are parsed in the order they are added to the list in
                            //   Commands.cs, to give commands priority, add them to the top of the
                            //   list. (e.g. s will always match south, because it always comes before
                            //   score)
                            if (pair.Key.StartsWith(commandText.ToLower()))
                            {
                                Command command = pair.Value;
                                if (command != null)
                                {
                                    // Voodoo reflection magic to execute the method that the command
                                    //   wants to execute. Passes the Player itself, as well as the
                                    //   input string to that method.
                                    // TODO: This could be improved for effeciency by retrieving the
                                    //   method once on load and storing it as a reference - possibly
                                    //   a delegate? I'm not too sure. -DWE 2009/08/04
                                    Type type = player.Menu.Caller.GetType();
                                    MethodInfo method = type.GetMethod(player.Menu.CallbackMethod);
                                    method.Invoke(player.Menu.Caller, new object[] { line });
                                    return;
                                }
                            }
                        }
                    }
                    else if (player.Menu is InputNumberMenu)
                    {
                        double number;
                        bool valid = double.TryParse(commandText, out number);
                        if (valid)
                        {
                            Type type = player.Menu.Caller.GetType();
                            MethodInfo method = type.GetMethod(player.Menu.CallbackMethod);
                            method.Invoke(player.Menu.Caller, new object[] { line });
                            return;
                        }
                        else
                        {
                            conn.GetPlayer().SendMessage("That is not a valid number.\n\r");
                            return;
                        }

                    }
                    else if (player.Menu is InputStringMenu)
                    {
                        Type type = player.Menu.Caller.GetType();
                        MethodInfo method = type.GetMethod(player.Menu.CallbackMethod);
                        method.Invoke(player.Menu.Caller, new object[] { line });
                        return;
                    }

                    if (player.Menu.DisplayMessage != "" && player.Menu.Caller is Player)
                    {
                        ((Player)player.Menu.Caller).SendMessage(player.Menu.DisplayMessage);
                    }
                    return;
                }

                conn.GetPlayer().SendMessage("Huh? \"" + commandText + "\" isn't a command!\n\r");

                // Nifty argument debugger, uncomment to see arguments as they are being parsed
                //  - SUPER spammy, sends globally for all input
                /*
                for (int x = 1; x <= 10; x++)
                {
                    Argument arg = GetArgument(line, x);

                    if(arg != null)
                        Global.Server.SendToAll(arg.Index + ".  " + arg.Count + "*  " + arg.Text);
                    else
                        Global.Server.SendToAll("Huh?");
                }
                */
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Thread-safe callback from each TelnetConnection, parsing input.
        /// This function is timed internally by PulseTimer().
        /// </summary>
        /// <param name="conn">The TelnetConnection the input is coming from</param>
        /// <param name="line">The input string</param>
        static public void Interpret(TelnetConnection conn, string line)
        {
            // If the connection doesn't have a Player yet, it must be a new connection.
            // Forward it to LoginInterpret().
            if (conn.GetPlayer() == null)
            {
                LoginInterpret(conn, line);
            }
            else
            {
                Player player      = conn.GetPlayer();
                string commandText = GetArgument(line, 1).Text;

                if (commandText == "" || line == "")
                {
                    return;
                }

                if (player.Menu == null)
                {
                    // Mosey through all the commands
                    foreach (KeyValuePair <string, Command> pair in Global.Commands.List)
                    {
                        // Match the command, allowing shorthand abbreviation (e.g. south = so = s)
                        // Note: Commands are parsed in the order they are added to the list in
                        //   Commands.cs, to give commands priority, add them to the top of the
                        //   list. (e.g. s will always match south, because it always comes before
                        //   score)
                        if (pair.Key.StartsWith(commandText.ToLower()))
                        {
                            Command command = pair.Value;

                            player.SendMessage("Command debug: " + GetArgument(line, 1).Text + "|" + GetArgument(line, 2).Text + "|" + GetArgument(line, 3).Text + "|" + GetArgument(line, 4).Text + "\n\r");
                            if (command != null)
                            {
                                // Voodoo reflection magic to execute the method that the command
                                //   wants to execute. Passes the Player itself, as well as the
                                //   input string to that method.
                                // TODO: This could be improved for effeciency by retrieving the
                                //   method once on load and storing it as a reference - possibly
                                //   a delegate? I'm not too sure. -DWE 2009/08/04
                                MethodInfo method = typeof(Commands).GetMethod(command.Method);
                                method.Invoke(Global.Commands, new object[] { player, pair.Value, line });
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // Mosey through all the commands
                    foreach (KeyValuePair <string, Command> pair in player.Menu.List)
                    {
                        // Match the command, allowing shorthand abbreviation (e.g. south = so = s)
                        // Note: Commands are parsed in the order they are added to the list in
                        //   Commands.cs, to give commands priority, add them to the top of the
                        //   list. (e.g. s will always match south, because it always comes before
                        //   score)
                        if (pair.Key.StartsWith(commandText.ToLower()))
                        {
                            Command command = pair.Value;
                            if (command != null)
                            {
                                // Voodoo reflection magic to execute the method that the command
                                //   wants to execute. Passes the Player itself, as well as the
                                //   input string to that method.
                                // TODO: This could be improved for effeciency by retrieving the
                                //   method once on load and storing it as a reference - possibly
                                //   a delegate? I'm not too sure. -DWE 2009/08/04
                                Type       type   = player.Menu.Caller.GetType();
                                MethodInfo method = type.GetMethod(player.Menu.CallbackMethod);
                                method.Invoke(player.Menu.Caller, new object[] { line });
                                return;
                            }
                        }
                    }
                }

                conn.GetPlayer().SendMessage("Huh? \"" + commandText + "\" isn't a command!\n\r");

                // Nifty argument debugger, uncomment to see arguments as they are being parsed
                //  - SUPER spammy, sends globally for all input

                /*
                 * for (int x = 1; x <= 10; x++)
                 * {
                 *      Argument arg = GetArgument(line, x);
                 *
                 *      if(arg != null)
                 *              Global.Server.SendToAll(arg.Index + ".  " + arg.Count + "*  " + arg.Text);
                 *      else
                 *              Global.Server.SendToAll("Huh?");
                 * }
                 */
            }
        }
Esempio n. 4
0
        /// <summary>
        /// If our connection doesn't have a Player yet, everything is sent here to handle 
        /// login and Player creation.
        /// </summary>
        /// <param name="conn">The TelnetConnection the input is coming from</param>
        /// <param name="line">The input string</param>
        public static void LoginInterpret(TelnetConnection conn, string line)
        {
            Player player = new Player();
            player.MaxHealth = 200;
            player.Health = 200;
            player.PhysicalPower = 10;
            player.MagicPower = 10;
            player.Name = line;
            player.HandlingName = line;
            player.Connection = conn;

            foreach (Skill skill in Global.SkillTable.Values)
            {
                if (skill.Name == "Autoattack")
                    continue;
                player.Skills.Add(skill.Name, new SkillInstance(skill));
            }

            player.SkillSlots.Insert(0, player.Skills["Backstab"]);
            player.SkillSlots.Insert(1, player.Skills["Flurry"]);
            player.SkillSlots.Insert(2, player.Skills["Savage Strike"]);
            conn.SetPlayer(player);

            DynamicMenu menu = new DynamicMenu(player, "HandleClientMenu");
            menu.List.Add("telnet", new Command("telnet", "", false, "Sets your client type as a telnet connection (telnet, terminal, MUD client)"));
            menu.List.Add("full", new Command("full", "", false, "Sets your client type as the official rich client"));
            menu.List.Add("android", new Command("android", "", false, "Sets your client type as an Android phone"));
            player.Menu = menu;
            player.SendMessage("Please select your client type:\n\r- telnet\n\r- full\n\r- android\n\r");
        }