Exemple #1
0
        /// <summary>
        /// Creates a new instance from the specified link string.
        /// </summary>
        /// <param name="cryLink">A CryLink string.</param>
        public CryLink(String cryLink) : base(cryLink)
        {
            if (!ExtractConsoleCommands())
            {
                ConsoleCommands = new CryConsoleCommand[0];
            }

            ServiceName = base.Authority.ToLower();
        }
        /// <summary>
        /// Executes a console command.
        /// </summary>
        /// <param name="command">Console command to send</param>
        /// <returns>Command return value as string.</returns>
        public String ExecuteCommand(CryConsoleCommand command)
        {
            try
            {
                XmlRPCMethod method = new XmlRPCMethod(Connection, command.Name);
                method.KeepAlive = true;

                return(method.Call <String>(new ArrayList(command.Params)));
            }
            catch (Exception)
            {
                return("");
            }
        }
Exemple #3
0
        /// <summary>
        /// Extracts the console commands that are specified in the link.
        /// </summary>
        /// <returns>True if one or more commands were found.</returns>
        private bool ExtractConsoleCommands()
        {
            if (base.Segments[base.Segments.Length - 1] == "exec" && base.Query[0] == '?')
            {
                String[] queryParams = base.Query.Substring(1, base.Query.Length - 1).Split('&');
                ConsoleCommands = new CryConsoleCommand[queryParams.Length];

                foreach (String param in queryParams)
                {
                    const Int32 key   = 0;
                    const Int32 value = 1;

                    String[] query = param.Split('=');

                    if (query[key].StartsWith("cmd"))
                    {
                        Int32 idx;
                        if (Int32.TryParse(query[key].Substring(3), out idx))
                        {
                            CryConsoleCommand command = new CryConsoleCommand();

                            String[] commandArgs = query[value].Split('+');
                            for (Int32 i = 1; i < commandArgs.Length; ++i)
                            {
                                command.Params.Add(commandArgs[i]);
                            }

                            command.Name             = commandArgs[0];
                            ConsoleCommands[idx - 1] = command;
                        }
                    }
                }

                return(ConsoleCommands.Length > 0);
            }

            return(false);
        }