Пример #1
0
            public void Execute(CharacterData ch, string[] args)
            {
                // For now, get a ClientConnection since I haven't reworked everything to just use the ID yet
                Network.ClientConnection state = ch.Descriptor;

                // Header
                string result = "ACTIVE CONNECTIONS\n\rID     Remote IP         Player       Duration   Tx/Rx\n\r";

                //2345	  123.123.123.132   00:00:00   Seath        1024.1MB/1024.1MB

                // Data
                foreach (Network.ClientConnection conn in Network.ClientConnections)
                {
                    result += String.Format("{0,-7}{1,-18}{2,-13}{3,-11}{4}/{5}\n\r",
                                            conn.ID.ToString(),
                                            conn.RemoteIP.ToString(),
                                            ch.Name,
                                            conn.ConnectionDuration.ToString(@"hh\:mm\:ss"),
                                            conn.bytesSent,
                                            conn.bytesReceived);
                }

                // Send the result
                Network.Send(result, state);
            }
Пример #2
0
        /// <summary>
        /// Forces the point pulse outside of its regular schedule. Invoking this does not reset the point pulse schedule, the next automated pulse will happen as scheduled.
        /// </summary>
        /// <param name="connID">Connection ID of the user requesting the point pulse</param>
        public static void ForcePointPulse(int connID)
        {
            Network.ClientConnection state = Network.ClientConnections.Single(c => c.ID == connID);

            Program.PointTimerCallback(state);
            Network.Send("Point tick forced.\n\r", state);
        }
Пример #3
0
        public static void SingleUser(int connID)
        {
            // For now, get a ClientConnection since I haven't reworked everything to just use the ID yet
            Network.ClientConnection state = Network.ClientConnections.Single(c => c.ID == connID);

            // Send the single user login text
            Network.Send("Connected to server running in single-user mode.\n\r", state);
        }
Пример #4
0
            public void Execute(CharacterData ch, string[] args)
            {
                Network.ClientConnection state = ch.Descriptor;

                // Send statistics
                Network.Send(String.Format("SERVER STATISTICS\n\r=================\n\r{0} rooms loaded\n\r{1} mobiles loaded\n\r{2} object prototypes loaded\n\r{3} connections currently open\n\rServer uptime is {4}\n\r",
                                           Program.World.Rooms.Count,
                                           Program.World.Mobs.Count,
                                           Program.World.Objects.Count,
                                           Network.ClientConnections.Count,
                                           (DateTime.Now - Program.World.StartupTime).ToString()), state);
            }
Пример #5
0
            public void Execute(CharacterData ch, string[] args)
            {
                string arg1, arg2;

                // Recombine args
                List <string> argList = args.ToList();
                string        command = args.First();

                argList.RemoveAt(0);
                string arguments = String.Join(" ", argList);

                // Pull arguments
                arguments = GetOneArgument(arguments, out arg1);
                arguments = GetOneArgument(arguments, out arg2);

                Network.ClientConnection state = ch.Descriptor;
                CharacterData            victim;
                RoomIndexData            room;

                // Get the character's current room
                room = ch.InRoom;

                // Attempt to pull a character from the first argument
                victim = room.Characters.SingleOrDefault(c => c.Name.ToLower().Equals(arg1));

                if (victim != null)
                {
                    string output = ShowCharToChar(ch, victim);
                    Network.Send(output + "\n\r", state);
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(String.Format("{0}\n\r\n\r{1}\n\r\n\r", room.Name, room.Description));

                    foreach (CharacterData person in room.Characters)
                    {
                        sb.Append(person.LongDescription + "\n\r");
                    }

                    Network.Send(sb.ToString() + "\n\r", state);
                }
            }
Пример #6
0
        public static void DoGreeting(int connID)
        {
            // For now, get a ClientConnection since I haven't reworked everything to just use the ID yet
            Network.ClientConnection state = Network.ClientConnections.Single(c => c.ID == connID);

            // Update the client's state
            state.State = ROMSharp.Enums.ClientState.Login_WaitingForCharacterName;

            // Send the greeting text
            Network.Send(Consts.Strings.Greeting, state);
            //
            //				// Ensure we don't call BeginReceive() multiple times
            //				if (!state.IsWaitingForData) {
            //					// Flag that we're waiting for data
            //					state.IsWaitingForData = true;
            //
            //					// Wait for data
            //					handler.BeginReceive (state.buffer, 0, ClientConnection.BufferSize, 0, new AsyncCallback (ReadCallback), state);
            //				}
        }
Пример #7
0
            public void Execute(CharacterData ch, string[] args)
            {
                Network.ClientConnection state = ch.Descriptor;

                StringBuilder sb = new StringBuilder();

                sb.Append("You are carrying:\n\r");

                if (state.PlayerCharacter.Inventory.Count == 0)
                {
                    sb.Append("Nothing.\n\r");
                }
                else
                {
                    foreach (ObjectData obj in state.PlayerCharacter.Inventory)
                    {
                        sb.Append(obj.ShortDescription + "\n\r");
                    }
                }

                // Send output
                Network.Send(sb.ToString() + "\n\r", state);
            }
Пример #8
0
            public void Execute(CharacterData ch, string[] args)
            {
                Network.ClientConnection state = ch.Descriptor;

                // Check the first argument for a type
                string firstArg = args[1];

                switch (firstArg.ToLower())
                {
                case "room":
                    string secondArg = args[2];

                    if (!Int32.TryParse(secondArg, out int vnum))
                    {
                        Network.Send(@"Syntax:\n\r
        stat <name>\n\r
        stat obj <name>\n\r
        stat mob <name>\n\r
        stat room <number>\n\r", state);
                        return;
                    }
                    else
                    {
                        StatRoom(ch, vnum);
                    }

                    return;

                case "obj":
                    Network.Send("\"stat obj\" not implemented yet", state);
                    return;

                case "mob":
                    Network.Send("\"stat mob\" not implemented yet", state);
                    return;
                }
            }
Пример #9
0
            public void Execute(CharacterData ch, string[] args)
            {
                Network.ClientConnection state = ch.Descriptor;

                if (args.Length < 3)
                {
                    // Invalid, we need at least 3 arguments
                    Network.Send("Syntax:\n\r  load mob <vnum>\n\r  load obj <vnum> <level>\n\r", state);
                    return;
                }
                else
                {
                    switch (args[1].ToLower().Trim())
                    {
                    case "obj":
                        int objVNUM, objLevel;

                        // Need 4 args for this
                        if (args.Length != 4)
                        {
                            Network.Send("Syntax:\n\r  load mob <vnum>\n\r  load obj <vnum> <level>\n\r", state);
                            return;
                        }

                        // VNUM must be numeric
                        if (!Int32.TryParse(args[2], out objVNUM))
                        {
                            Network.Send("Syntax: load obj <vnum:int> <level:int>\n\r", state);
                            return;
                        }

                        // Level must be numeric and between 0 and the player's level
                        if (!Int32.TryParse(args[3], out objLevel))
                        {
                            Network.Send("Syntax: load obj <vnum:int> <level:int>\n\r", state);
                            return;
                        }
                        else
                        {
                            // Level needs to be between 0 and the player's trust level 9using player level for now)
                            // TODO: Switch to using trust level
                            if (objLevel < 0 || objLevel > state.PlayerCharacter.Level)
                            {
                                Network.Send("Level must be between 0 and your level.\n\r", state);
                                return;
                            }
                        }

                        // Object VNUM must exist
                        if (Program.World.Objects[objVNUM] == null)
                        {
                            Network.Send("No object has that VNUM.\n\r", state);
                            return;
                        }

                        // Go ahead and instantiate the object
                        Models.ObjectData newObj = new Models.ObjectData(Program.World.Objects[objVNUM]);

                        // Give it to the character
                        state.PlayerCharacter.Inventory.Add(newObj);

                        // Send feedback
                        Network.Send("Ok.\n\r\n\r", state);

                        break;

                    default:
                        Network.Send("Syntax:\n\r  load mob <vnum>\n\r  load obj <vnum> <level>\n\r", state);
                        break;
                    }
                }
            }
Пример #10
0
        public static void ParseCommand(string input, int connID)
        {
            Network.ClientConnection state = Network.ClientConnections.Single(c => c.ID == connID);
            ICommand matchedCommand;

            // Split commandString for easier handling
            string[] commandArr = input.Split(' ');

            // The first word of a user input is the command - isolate it
            string command = commandArr[0].ToLower().Trim();

            // If the command is "!", re-execute the player's last command
            if (command.Equals("!") && state.LastCommand != null)
            {
                matchedCommand = state.LastCommand;
            }
            else
            {
                // Try to find a matching command
                IEnumerable <ICommand> matchedCommands = Program.commandTable.Where(cmd => cmd.MinimumLevel <= state.PlayerCharacter.Trust && cmd.Name.ToLower().Equals(command.Trim().ToLower()) || cmd.Aliases.Contains(command.Trim().ToLower()));

                // If we got one or more commands, execute the first match
                if (matchedCommands.Count() > 0)
                {
                    // Grab the matched command
                    matchedCommand = matchedCommands.First();

                    // Store this as the player's last command executed
                    state.LastCommand = matchedCommand;
                }
                else
                {
                    // Not sure what they're looking for
                    Network.Send("Huh?\n\r", state);
                    return;
                }
            }

            // Check the character's position vs. the command's minimum
            if ((int)state.PlayerCharacter.Position.PositionCode < (int)matchedCommand.MinimumPosition)
            {
                switch (state.PlayerCharacter.Position.PositionCode)
                {
                case Position.Dead:
                    Network.Send("Lie still; you are DEAD.\n\r", state);
                    break;

                case Position.MortallyWounded:
                case Position.Incapacitated:
                    Network.Send("You are hurt far too badly for that.\n\r", state);
                    break;

                case Position.Stunned:
                    Network.Send("You are too stunned to do that.\n\r", state);
                    break;

                case Position.Sleeping:
                    Network.Send("In your dreams, or what?\n\r", state);
                    break;

                case Position.Resting:
                    Network.Send("Nah... You feel too relaxed...\n\r", state);
                    break;

                case Position.Sitting:
                    Network.Send("Better stand up first.\n\r", state);
                    break;

                case Position.Fighting:
                    Network.Send("No way! You are still fighting!\n\r", state);
                    break;
                }

                return;
            }

            // Execute the command
            matchedCommand.Execute(state.PlayerCharacter, commandArr);
        }
Пример #11
0
        public static void InterpretInput(string input, int connID)
        {
            Network.ClientConnection state = Network.ClientConnections.Single(c => c.ID == connID);

            // If we have no data, there's nothing to do
            if (String.IsNullOrWhiteSpace(input))
            {
                Network.Send("", state);
                return;
            }

            // Check what the client's state is to determine how to proceed
            switch (state.State)
            {
            // At idle, treat the input as a command with arguments
            case Enums.ClientState.Idle:
                ParseCommand(input, connID);
                break;

            // Waiting for the character name (logging in)
            case ClientState.Login_WaitingForCharacterName:
                // Is the name legal?
                if (Character.IsLegalName(input.Trim()))
                {
                    // Instantiate a new Character in the user's state and set the name
                    state.PlayerCharacter = new Models.PlayerCharacterData();

                    // Do we recognize this username?
                    if (Character.Exists(input))
                    {
                        // It's a known character, start the login process - update the user state.
                        state.State = ClientState.Login_WaitingForPassword;

                        // Send the Password: prompt
                        Network.Send(Consts.Strings.LoginPasswordPrompt, state);
                    }
                    else
                    {
                        // It's an unknown character, start the creation process - update the user state.
                        state.State = ClientState.Creation_WaitingForPassword;

                        // Send the password prompt
                        Network.Send(state.workSocket, String.Format("{0} {1}: ", Consts.Strings.CreationPasswordPrompt, input), state, false);

                        // Send the local echo off command
                        Network.SendCommand(state.workSocket, Consts.Misc.TelnetCommands.LocalEchoOff, state);
                    }
                }
                else
                {
                    // Illegal name - leave the state as is, tell the user to try again
                    Network.Send(Consts.Strings.LoginCharacterNameIllegal, state);
                }
                break;

            case ClientState.Creation_WaitingForPassword:
                // Ensure the password meets requirements
                if (Password.MeetsComplexityRequirements(input))
                {
                    // Password is good - update the user state then prompt for the user to repeat the password
                    state.State = ClientState.Creation_WaitingForPasswordConfirm;

                    // Store the password temporarily
                    state.TempPass = input;

                    // Prompt for confirmation
                    Network.Send("\n\r" + Consts.Strings.CreationPasswordConfirmPrompt, state);
                }
                else
                {
                    // Password isn't good - roll the user state back then re-prompt for a password
                    state.State = ClientState.Creation_WaitingForPassword;

                    Network.Send("\n\r" + Consts.Strings.CreationInvalidPassword + "\n\r" + Consts.Strings.CreationPasswordPrompt, state);
                }
                break;
            }
        }