예제 #1
0
        private void EchoInput(RdlCommand cmd)
        {
            switch (cmd.TypeName)
            {
            case "SAY":
                if (!String.IsNullOrEmpty(cmd.Text))
                {
                    this.Write(MessageType.Say, String.Concat("You say: ", cmd.Text));
                }
                break;

            case "SHOUT":
                if (!String.IsNullOrEmpty(cmd.Text))
                {
                    this.Write(MessageType.Say, String.Concat("You shout: ", cmd.Text.ToUpper()));
                }
                break;

            case "TELL":
                string msg = cmd.GetArg <string>(1);
                if (!String.IsNullOrEmpty(msg))
                {
                    this.Write(MessageType.Tell, String.Format("You tell {0}: {1}", cmd.Args[0], msg));
                }
                break;

            case "EMOTE":
                // TODO: Echo Emotes...
                break;
            }
        }
예제 #2
0
        public override void Execute(RdlCommand command, Avatar caller, IMessageContext context)
        {
            // Args:
            // 0 = To
            // 1 = Message
            if (command.Args.Count >= 2)
            {
                string name    = command.GetArg <string>(0);
                string message = command.GetArg <string>(1);

                Avatar who = this.Server.World.FindAvatar(name);
                if (who != null)
                {
                    who.Context.Add(new Radiance.Markup.RdlTellMessage(name, String.Format(SR.MsgTellFormat, caller.Name, message)));
                }
                else
                {
                    context.Add(new Radiance.Markup.RdlErrorMessage(SR.MsgTellNotFound(name)));
                }
            }
            else
            {
                context.Add(new Radiance.Markup.RdlErrorMessage(SR.MsgTellNoAvatarDefined));
            }
        }
        private void ProcessCommand(Server server, RdlCommand command, IMessageContext context)
        {
            try
            {
                // Ensure the command exits for this virtual world.
                if (String.IsNullOrEmpty(command.TypeName) || !server.World.Commands.ContainsKey(command.TypeName))
                {
                    context.Add(RdlErrorMessage.InvalidCommand);
                    return;
                }

                // Validate that the user has permission to execute the command.
                if (!this.ValidateRole(server, this.Client.AuthKey.UserName, server.World.Commands[command.TypeName].RequiredRole))
                {
                    context.Add(new RdlErrorMessage(SR.AccessDenied(command.TypeName)));
                    return;
                }

                // Execute the command.
                CommandManager.ProcessCommand(server, command, this.Client);
            }
            catch (Exception ex)
            {
#if DEBUG
                Logger.LogInformation(ex.ToString());
                throw ex;
#else
                Logger.LogError(ex.ToString());
                context.Add(RdlErrorMessage.InternalError);
#endif
            }
        }
예제 #4
0
        private void btnSavePlace_Click(object sender, RoutedEventArgs e)
        {
            RdlPlace           place = new RdlPlace(_placeId, txtPlaceName.Text, _currentLocation.X, _currentLocation.Y, _currentLocation.Z);
            List <RdlProperty> props = new List <RdlProperty>();

            props.Add(new RdlProperty(place.ID, "Description", txtPlaceDesc.Text));
            props.Add(new RdlProperty(place.ID, "RuntimeType", ddlPlaceTypes.SelectedItem));
            props.Add(new RdlProperty(place.ID, "Terrain", ((Terrain)ddlTerrain.SelectedItem).ID));

            RdlTagCollection tags = new RdlTagCollection();

            tags.Add(place);
            tags.AddRange(props.ToArray());

            string cmdName = "ADMINCREATE";

            if (_placeId > 0)
            {
                cmdName = "ADMINSAVE";
            }

            RdlCommand cmd = new RdlCommand(cmdName);

            if (_placeId > 0)
            {
                cmd.Args.Add(_placeId);
            }
            else
            {
                cmd.Args.Add("place");
            }

            //ServerManager.Instance.SendCommand(Settings.UserAuthKey, "User", cmd, null, tags);
        }
예제 #5
0
 public string GetUserNameFromCommand(RdlCommand cmd)
 {
     if (cmd.Group != null)
     {
         AuthKey key = AuthKey.Get(cmd.Group.AuthKey);
         return(key.UserName);
     }
     return(String.Empty);
 }
예제 #6
0
        /// <summary>
        /// Sends the specified command to the server using the current CommunicationProtocol and provides an
        /// alternate handler for the server response.
        /// </summary>
        /// <param name="command">The CommandTag to send to the server.</param>
        /// <param name="serverResponseCallback">The CommunicatorResponseEventHandler that will handle the
        /// response from this command.</param>
        public void SendCommand(RdlCommand command, CommunicatorResponseEventHandler serverResponseCallback)
        {
            RdlCommandGroup group = new RdlCommandGroup(new RdlCommand[] { command });

            group.AuthKey     = this.AuthKey;
            group.AuthKeyType = this.AuthKeyType;

            this.Init();
            _communicator.Execute(group, serverResponseCallback);
        }
예제 #7
0
        private void ExecuteAction(ActionEventArgs e)
        {
            // Execute the action.
            RdlCommand cmd = new RdlCommand(e.ActionName);

            cmd.Args.Add(e.ActorAlias);
            cmd.Args.AddRange(e.Args.ToArray());

            ServerManager.Instance.SendCommand(cmd);
        }
예제 #8
0
        private void SendCommand(string authKey, string authKeyType, string commandName, ServerResponseEventHandler callback, params object[] args)
        {
            RdlCommand cmd = new RdlCommand(commandName.ToUpper());

            if (args != null && args.Length > 0)
            {
                cmd.Args.AddRange(args);
            }
            this.SendCommand(authKey, authKeyType, cmd, callback, null);
        }
예제 #9
0
        /// <summary>
        /// Processes the specified command, providing results to the IMessageContext of the specified IClient instance.
        /// </summary>
        /// <param name="server">The current Radiance.Server instance this command is to be executed in.</param>
        /// <param name="cmd">The RdlCommand to execute.</param>
        /// <param name="client">The IClient instance executing the specified command.</param>
        public static void ProcessCommand(Server server, RdlCommand cmd, IClient client)
        {
            // Check to see if a handler exists for the current command, if not use the old provider.
            List <ICommandHandler> handlers;

            if (_handlers.TryGetValue(cmd.TypeName, out handlers))
            {
                for (int i = 0; i < handlers.Count; i++)
                {
                    handlers[i].HandleCommand(server, cmd, client);
                }
            }
            else
            {
                _provider.ProcessCommand(server, cmd, client);
            }
        }
예제 #10
0
        /// <summary>
        /// Validates that the specified command can be executed by this handler.
        /// </summary>
        /// <param name="server">The current server instance.</param>
        /// <param name="commands">The commands being executed.</param>
        /// <returns>True if the commands can be executed by the current handler; otherwise false.</returns>
        protected override bool ValidateCommands(Server server, RdlCommandGroup commands)
        {
            if (this.Client.AuthKey.ID > 0)
            {
                this.Client.Handler = new PlayerCommandHandler(this.Client);
                this.Client.Handler.ProcessCommands(server, commands);
                return(false);
            }

            RdlCommand cmd = commands.Where(c => c.TypeName == "ADMINBUILD").FirstOrDefault();

            if (cmd != null)
            {
                this.Client.Handler = new AdminCommandHandler(this.Client);
                this.Client.Handler.ProcessCommands(server, commands);
                return(false);
            }

            return(true);
        }
예제 #11
0
        public void SendCommand(string authKey, string authKeyType, RdlCommand cmd, ServerResponseEventHandler callback, RdlTagCollection tags)
        {
            //RdlCommandGroup group = new RdlCommandGroup(new RdlCommand[] { cmd });
            //group.AuthKey = authKey;
            //group.AuthKeyType = authKeyType;
            //if (tags != null)
            //{
            //    group.Tags.AddRange(tags);
            //}

//#if DEBUG
            //            Logger.LogDebug(String.Concat("CLIENT CMD = ", group.ToString()));
//#endif
            //var commands = new RdlCommandGroup(new RdlCommand[] { cmd });
            //commands.AuthKey = authKey;
            //commands.AuthKeyType = authKeyType;

            Logger.LogDebug(String.Format("Sending Command: {0}", cmd));

            _altResponse = callback;
            //_client.ProcessAsync(commands.ToBytes());

            _manager.AuthKey     = authKey;
            _manager.AuthKeyType = authKeyType;
            _manager.SendCommand(cmd, (e) =>
            {
                if (e.Tags.Count > 0)
                {
                    if (_altResponse != null)
                    {
                        _altResponse(new ServerResponseEventArgs(e.Tags));
                        _altResponse = null;
                    }
                    else
                    {
                        this.Response(new ServerResponseEventArgs(e.Tags));
                    }
                }
            });
        }
예제 #12
0
        private void ctlChat_InputReceived(object sender, Lionsguard.InputReceivedEventArgs e)
        {
            RdlCommandParserErrorType errType = RdlCommandParserErrorType.None;
            RdlCommand cmd;

            if (RdlCommand.TryParse(e.Input, out cmd, out errType))
            {
                // Only echo say, shout, tell and emotes.
                this.EchoInput(cmd);

                if (this.ServerCommandType == CommandType.Player)
                {
                    ServerManager.Instance.SendCommand(cmd);
                }
                else
                {
                    ServerManager.Instance.SendUserCommand(cmd);
                }
            }
            else
            {
                switch (errType)
                {
                case RdlCommandParserErrorType.NoTargetForTell:
                    this.Write(MessageType.Error, "TELL requires the name of the person you wish to send a message.");
                    break;

                case RdlCommandParserErrorType.NoArgumentsSpecified:
                    this.Write(MessageType.Error, String.Format("No arguments were specified for the {0} command.", cmd.TypeName));
                    break;

                case RdlCommandParserErrorType.InvalidNumberOfArguments:
                    this.Write(MessageType.Error, String.Format("An invalid number of arguments were specified for the {0} command.", cmd.TypeName));
                    break;
                }
            }
        }
예제 #13
0
 /// <summary>
 /// Executes the current command using the specified args and outputing the results to the specified context.
 /// </summary>
 /// <param name="command">The RdlCommand to execute.</param>
 /// <param name="caller">The Avatar executing the command.</param>
 /// <param name="context">The IMessageContext for handling command output responses.</param>
 public abstract void Execute(RdlCommand command, Avatar caller, IMessageContext context);
예제 #14
0
 public override void Execute(RdlCommand command, Avatar caller, IMessageContext context)
 {
 }
예제 #15
0
 public override void Execute(RdlCommand command, Avatar caller, IMessageContext context)
 {
     context.Add(new Radiance.Markup.RdlSystemMessage(0, caller.Place.ToString()));
 }
예제 #16
0
 public override void Execute(RdlCommand command, Avatar caller, IMessageContext context)
 {
     this.Server.SendAll(new RdlChatMessage(caller.Name, String.Format(SR.MsgShoutFormat, caller.Name, command.GetArg <string>(0).ToUpper())), caller);
 }
예제 #17
0
 public override void Execute(RdlCommand command, Avatar caller, IMessageContext context)
 {
     caller.Place.SendAll(new RdlChatMessage(caller.Name, String.Format(SR.MsgSayFormat, caller.Name, command.GetArg <string>(0))), caller);
 }
예제 #18
0
 public void SendUserCommand(RdlCommand cmd)
 {
     this.SendCommand(Settings.UserAuthKey, "User", cmd, null, null);
 }
예제 #19
0
 /// <summary>
 /// Processes the specified command, providing results to the IMessageContext of the specified IClient instance.
 /// </summary>
 /// <param name="server">The current Radiance.Server instance this command is to be executed in.</param>
 /// <param name="cmd">The RdlCommand to execute.</param>
 /// <param name="client">The IClient instance executing the specified command.</param>
 public abstract void ProcessCommand(Server server, RdlCommand cmd, IClient client);
예제 #20
0
 public void SendCommand(RdlCommand cmd)
 {
     this.SendCommand(cmd, null);
 }
예제 #21
0
 public void SendCommand(string authKey, string authKeyType, RdlCommand cmd, ServerResponseEventHandler callback)
 {
     this.SendCommand(authKey, authKeyType, cmd, callback, null);
 }
예제 #22
0
 public void SendCommand(RdlCommand cmd, ServerResponseEventHandler callback)
 {
     this.SendCommand(Settings.PlayerAuthKey, "Player", cmd, callback, null);
 }
예제 #23
0
 public void HandleCommand(Server server, RdlCommand cmd, IClient client)
 {
 }
예제 #24
0
        /// <summary>
        /// Creates a player instance in the virtual world.
        /// </summary>
        /// <param name="context">The current IMessageContext of the requestor.</param>
        /// <param name="cmd">The RdlCommand containing the player parameters.</param>
        /// <param name="player">The player instance to create.</param>
        public bool CreatePlayer(IMessageContext context, RdlCommand cmd, IPlayer player)
        {
            // Command arguments are grouped into key:value pairs, each argument is a key:value pair.

            // Find the user from rdlcommandgroup associated with this command.
            bool   success = false;
            string message = SR.CreateCharacterInvalidUser;

            if (cmd.Group != null)
            {
                AuthKey key = AuthKey.Get(cmd.Group.AuthKey);

                //=================================================================================
                // Ensure the user can create additional character.
                //=================================================================================
                UserDetail user = this.Provider.GetUserDetail(key.UserName);
                if (user == null)
                {
                    // Use the default error message.
                    goto finished;
                }
                int playerCount = this.Provider.GetPlayers(user.UserName).Count;
                if (user.MaxCharacters == 0)
                {
                    // Preset the max characters to the world default.
                    user.MaxCharacters = this.DefaultMaxCharacters;
                    this.Provider.SaveUserDetail(user);
                }
                if (playerCount >= user.MaxCharacters)
                {
                    message = SR.CreateCharacterMaxExceeded(this.DefaultMaxCharacters);
                    goto finished;
                }
                player.Properties.SetValue("UserName", user.UserName);

                //=================================================================================
                // Parse the key:value pairs.
                //=================================================================================
                foreach (var item in cmd.Args)
                {
                    if (item != null)
                    {
                        string[] pairs = item.ToString().Split(':');
                        if (pairs != null && pairs.Length == 2)
                        {
                            if (pairs[0].ToLower().Equals("name"))
                            {
                                player.Name = pairs[1];
                            }
                            else
                            {
                                player.Properties.SetValue(pairs[0], pairs[1]);
                            }
                        }
                    }
                }

                //=================================================================================
                // Validate player name.
                //=================================================================================
                if (!this.IsValidName(player.Name, out message))
                {
                    goto finished;
                }

                //=================================================================================
                // Ensure a gender is specified.
                //=================================================================================
                if (player.Gender == Gender.None)
                {
                    message = SR.CreateCharacterInvalidGender;
                    goto finished;
                }

                //=================================================================================
                // Ensure a race is specified.
                //=================================================================================
                if (String.IsNullOrEmpty(player.Race) || !this.Races.ContainsKey(player.Race))
                {
                    message = SR.CreateCharacterInvalidRace;
                    goto finished;
                }
                // Set the player's location from the race instance.
                player.Location = this.Races[player.Race].StartingLocation;

                //=================================================================================
                // Ensure that attributes are within acceptable range.
                //=================================================================================
                int attrTotal = 0;
                foreach (var item in player.Attributes)
                {
                    if (item.Value < -1 || item.Value > 8)
                    {
                        message = SR.CreateCharacterAttributeOutOfRange(item.Key);
                        goto finished;
                    }
                    else
                    {
                        attrTotal += item.Value;
                    }
                }
                int raceDefaultAttrTotal = 0;
                foreach (var item in this.Races[player.Race].Attributes)
                {
                    if (item.Value > 0)
                    {
                        raceDefaultAttrTotal += item.Value;
                    }
                }
                // The max number of attribute points depends largely on the value of the attributes selected.
                if (attrTotal > (AttributeList.MaxAttributePoints + raceDefaultAttrTotal))                 // plus race bonus defaults
                {
                    message = SR.CreateCharacterAttributePointsOverLimit;
                    goto finished;
                }

                //=================================================================================
                // Set Body and Mind values.
                //=================================================================================
                int body = player.Attributes.Stamina * this.RealismMultiplier;
                int mind = player.Attributes.Endurance * this.PowerMultiplier;
                if (body == 0)
                {
                    body = 4;
                }
                player.SetBody(body, body);
                player.SetMind(mind, mind);


                //=================================================================================
                // Ensure that skills contain acceptable values and that they do not exceed 32 in value.
                //=================================================================================
                double skillTotal = 0;
                foreach (var item in player.Skills)
                {
                    if (item.Value < 0 || item.Value > SkillManager.MaxSkillPointsInCharacterCreation)
                    {
                        message = SR.CreateCharacterSkillOutOfRange(item.Key);
                        goto finished;
                    }
                    else
                    {
                        skillTotal += item.Value;
                    }
                }
                if ((int)skillTotal > SkillManager.MaxSkillPointsInCharacterCreation)
                {
                    message = SR.CreateCharacterSkillPointsOverLimit;
                    goto finished;
                }

                //=================================================================================
                // Add any missing skills to the players list of skills.
                //=================================================================================
                foreach (var skill in this.Skills)
                {
                    if (!player.Skills.ContainsKey(skill.Key))
                    {
                        player.Skills.Add(skill.Key, 0);
                    }
                }

                //=================================================================================
                // Check to ensure the name has not been taken and it passes the word filter.
                //=================================================================================
                if (!this.IsValidName(player.Name, out message))
                {
                    goto finished;
                }

                //=================================================================================
                // Save the player instance and send back a success message.
                //=================================================================================
                this.Provider.SavePlayer <IPlayer>(player);
                if (player.ID > 0)
                {
                    success = true;
                    message = SR.CreateCharacterSuccess;
                }
            }

finished:
            context.Add(new RdlCommandResponse(cmd.TypeName, success, message));

            return(success);
        }