Get() public méthode

Gets the argument at the specified index.
public Get ( int idx ) : string
idx int
Résultat string
Exemple #1
0
        private void ListByFlags(idCmdArgs args, CommandFlags flags)
        {
            string match = string.Empty;
            List <CommandDefinition> cmdList = new List <CommandDefinition>();

            if (args.Length > 1)
            {
                match = args.Get(1, -1).Replace(" ", "");
            }

            foreach (KeyValuePair <string, CommandDefinition> kvp in _commands)
            {
                if ((kvp.Value.Flags & flags) == 0)
                {
                    continue;
                }

                if ((match.Length > 0) && (kvp.Value.Name.StartsWith(match) == false))
                {
                    continue;
                }

                cmdList.Add(kvp.Value);
            }

            cmdList.Sort((a, b) => a.Description.CompareTo(b.Description));

            foreach (CommandDefinition cmd in cmdList)
            {
                idConsole.WriteLine(" {0} {1}", cmd.Name.PadRight(21, ' '), cmd.Description);
            }

            idConsole.WriteLine("{0} commands", cmdList.Count);
        }
Exemple #2
0
        /// <summary>
        /// Called by the command system when a command is unrecognized.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool Command(idCmdArgs args)
        {
            idInternalCvar intern = FindInternal(args.Get(0));

            if (intern == null)
            {
                return(false);
            }

            if (args.Length == 1)
            {
                // print the variable
                idConsole.WriteLine("\"{0}\" is: \"{1}\" {2} default: \"{3}\"", intern.Name, intern.ToString(), idColorString.White, intern.ResetString);

                if (intern.Description.Length > 0)
                {
                    idConsole.WriteLine("{0}{1}", idColorString.White, intern.Description);
                }
            }
            else
            {
                // set the value
                intern.Set(args.ToString(), false, false);
            }

            return(true);
        }
Exemple #3
0
        private void ExecuteTokenizedString(idCmdArgs args)
        {
            // execute the command line.
            if (args.Length == 0)
            {
                return;                 // no tokens.
            }

            CommandDefinition cmd;

            // check registered command functions.
            if (_commands.TryGetValue(args.Get(0), out cmd) == true)
            {
                if (((cmd.Flags & (CommandFlags.Cheat | CommandFlags.Tool)) != 0) &&
                    (idE.Session.IsMultiplayer == true) && (idE.CvarSystem.GetBool("net_allowCheats") == false))
                {
                    idConsole.WriteLine("Command '{0}' not valid in multiplayer mode.", cmd.Name);
                    return;
                }

                // perform the action.
                if (cmd.Handler != null)
                {
                    cmd.Handler(this, new CommandEventArgs(args));
                }

                return;
            }

            // check cvars.
            if (idE.CvarSystem.Command(args) == true)
            {
                return;
            }

            idConsole.WriteLine("Unknown command '{0}'", args.Get(0));
        }
Exemple #4
0
        private void ListByFlags(idCmdArgs args, CvarFlags flags)
        {
            int           argNum = 1;
            string        match;
            ShowMode      show = ShowMode.Value;
            List <idCvar> list = new List <idCvar>();

            if ((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum), "-") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum), "/") == 0))
            {
                if ((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "help") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "?") == 0))
                {
                    argNum = 3;
                    show   = ShowMode.Description;
                }
                else if ((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "type") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "range") == 0))
                {
                    argNum = 3;
                    show   = ShowMode.Type;
                }
                else if (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "flags") == 0)
                {
                    argNum = 3;
                    show   = ShowMode.Flags;
                }
            }

            if (args.Length > argNum)
            {
                match = args.Get(argNum, -1);
                match = match.Replace(" ", "");
            }
            else
            {
                match = "";
            }

            foreach (KeyValuePair <string, idInternalCvar> kvp in _cvarList)
            {
                idInternalCvar cvar = kvp.Value;

                if ((cvar.Flags & flags) == 0)
                {
                    continue;
                }

                if ((match.Length > 0) && (cvar.Name.ToLower().Contains(match.ToLower()) == false))
                {
                    continue;
                }

                list.Add(cvar);
            }

            list.OrderBy(a => a.Name);

            switch (show)
            {
            case ShowMode.Value:
                foreach (idCvar cvar in list)
                {
                    idConsole.WriteLine("{0}{1}\"{2}\"", cvar.Name.PadRight(32), idColorString.White, cvar.ToString());
                }
                break;

            case ShowMode.Description:
                foreach (idCvar cvar in list)
                {
                    idConsole.WriteLine("{0}{1}{2}", cvar.Name.PadRight(32), idColorString.White, idHelper.WrapText(cvar.Description, 77 - 33, 33));
                }
                break;

            case ShowMode.Type:
                foreach (idCvar cvar in list)
                {
                    if ((cvar.Flags & CvarFlags.Bool) == CvarFlags.Bool)
                    {
                        idConsole.WriteLine("{0}{1}bool", cvar.Name.PadRight(32), idColorString.Cyan);
                    }
                    else if ((cvar.Flags & CvarFlags.Integer) == CvarFlags.Integer)
                    {
                        if (cvar.MinValue < cvar.MaxValue)
                        {
                            idConsole.WriteLine("{0}{1}int {2}[{3}, {4}]", cvar.Name.PadRight(32), idColorString.Green, idColorString.White, cvar.MinValue, cvar.MaxValue);
                        }
                        else
                        {
                            idConsole.WriteLine("{0}{1}int", cvar.Name.PadRight(32), idColorString.Green);
                        }
                    }
                    else if ((cvar.Flags & CvarFlags.Float) == CvarFlags.Float)
                    {
                        if (cvar.MinValue < cvar.MaxValue)
                        {
                            idConsole.WriteLine("{0}{1}float {2}[{3}, {4}]", cvar.Name.PadRight(32), idColorString.Red, idColorString.White, cvar.MinValue, cvar.MaxValue);
                        }
                        else
                        {
                            idConsole.WriteLine("{0}{1}float", cvar.Name.PadRight(32), idColorString.Red);
                        }
                    }
                    else if (cvar.ValueStrings != null)
                    {
                        idConsole.Write("{0}{1}string {2}[", cvar.Name.PadRight(32), idColorString.White, idColorString.White);

                        int count = cvar.ValueStrings.Length;

                        for (int j = 0; j < count; j++)
                        {
                            if (j > 0)
                            {
                                idConsole.Write("{0}, {1}", idColorString.White, cvar.ValueStrings[j]);
                            }
                            else
                            {
                                idConsole.Write("{0}{1}", idColorString.White, cvar.ValueStrings[j]);
                            }
                        }

                        idConsole.WriteLine("{0}]", idColorString.White);
                    }
                    else
                    {
                        idConsole.WriteLine("{0}{1}string", cvar.Name.PadRight(32), idColorString.White);
                    }
                }
                break;

            case ShowMode.Flags:
                foreach (idCvar cvar in list)
                {
                    idConsole.Write(cvar.Name.PadRight(32));

                    string str = string.Empty;

                    if ((cvar.Flags & CvarFlags.Bool) == CvarFlags.Bool)
                    {
                        str += string.Format("{0}B ", idColorString.Cyan);
                    }
                    else if ((cvar.Flags & CvarFlags.Integer) == CvarFlags.Integer)
                    {
                        str += string.Format("{0}U ", idColorString.Green);
                    }
                    else if ((cvar.Flags & CvarFlags.Float) == CvarFlags.Float)
                    {
                        str += string.Format("{0}F ", idColorString.Red);
                    }
                    else
                    {
                        str += string.Format("{0}S ", idColorString.White);
                    }

                    if ((cvar.Flags & CvarFlags.System) == CvarFlags.System)
                    {
                        str += string.Format("{0}SYS  ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Renderer) == CvarFlags.Renderer)
                    {
                        str += string.Format("{0}RNDR ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Sound) == CvarFlags.Sound)
                    {
                        str += string.Format("{0}SND  ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Gui) == CvarFlags.Gui)
                    {
                        str += string.Format("{0}GUI  ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Game) == CvarFlags.Game)
                    {
                        str += string.Format("{0}GAME ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Tool) == CvarFlags.Tool)
                    {
                        str += string.Format("{0}TOOL ", idColorString.White);
                    }
                    else
                    {
                        str += string.Format("{0}     ", idColorString.White);
                    }

                    str += ((cvar.Flags & CvarFlags.UserInfo) == CvarFlags.UserInfo) ? "UI " : "   ";
                    str += ((cvar.Flags & CvarFlags.ServerInfo) == CvarFlags.ServerInfo) ? "SI " : "   ";
                    str += ((cvar.Flags & CvarFlags.Static) == CvarFlags.Static) ? "ST " : "   ";
                    str += ((cvar.Flags & CvarFlags.Cheat) == CvarFlags.Cheat) ? "CH " : "   ";
                    str += ((cvar.Flags & CvarFlags.Init) == CvarFlags.Init) ? "IN " : "   ";
                    str += ((cvar.Flags & CvarFlags.ReadOnly) == CvarFlags.ReadOnly) ? "RO " : "   ";
                    str += ((cvar.Flags & CvarFlags.Archive) == CvarFlags.Archive) ? "AR " : "   ";
                    str += ((cvar.Flags & CvarFlags.Modified) == CvarFlags.Modified) ? "MO " : "   ";

                    idConsole.WriteLine(str);
                }
                break;
            }

            idConsole.WriteLine("\n{0} cvars listed\n", list.Count);
            idConsole.WriteLine("listCvar [search string]          = list cvar values");
            idConsole.WriteLine("listCvar -help [search string]    = list cvar descriptions");
            idConsole.WriteLine("listCvar -type [search string]    = list cvar types");
            idConsole.WriteLine("listCvar -flags [search string]   = list cvar flags");
        }
Exemple #5
0
		private void ListByFlags(idCmdArgs args, CommandFlags flags)
		{
			string match = string.Empty;
			List<CommandDefinition> cmdList = new List<CommandDefinition>();

			if(args.Length > 1)
			{
				match = args.Get(1, -1).Replace(" ", "");
			}

			foreach(KeyValuePair<string, CommandDefinition> kvp in _commands)
			{
				if((kvp.Value.Flags & flags) == 0)
				{
					continue;
				}

				if((match.Length > 0) && (kvp.Value.Name.StartsWith(match) == false))
				{
					continue;
				}

				cmdList.Add(kvp.Value);
			}

			cmdList.Sort((a, b) => a.Description.CompareTo(b.Description));

			foreach(CommandDefinition cmd in cmdList)
			{
				idConsole.WriteLine(" {0} {1}", cmd.Name.PadRight(21, ' '), cmd.Description);
			}

			idConsole.WriteLine("{0} commands", cmdList.Count);
		}
Exemple #6
0
		private void ExecuteTokenizedString(idCmdArgs args)
		{
			// execute the command line.
			if(args.Length == 0)
			{
				return; // no tokens.
			}

			CommandDefinition cmd;

			// check registered command functions.
			if(_commands.TryGetValue(args.Get(0), out cmd) == true)
			{
				if(((cmd.Flags & (CommandFlags.Cheat | CommandFlags.Tool)) != 0) 
					&& (idE.Session.IsMultiplayer == true) && (idE.CvarSystem.GetBool("net_allowCheats") == false))
				{
					idConsole.WriteLine("Command '{0}' not valid in multiplayer mode.", cmd.Name);
					return;
				}

				// perform the action.
				if(cmd.Handler != null)
				{
					cmd.Handler(this, new CommandEventArgs(args));
				}

				return;
			}

			// check cvars.
			if(idE.CvarSystem.Command(args) == true)
			{
				return;
			}

			idConsole.WriteLine("Unknown command '{0}'", args.Get(0));
		}
		private void ListByFlags(idCmdArgs args, CvarFlags flags)
		{
			int argNum = 1;
			string match;
			ShowMode show = ShowMode.Value;
			List<idCvar> list = new List<idCvar>();

			if((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum), "-") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum), "/") == 0))
			{
				if((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "help") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "?") == 0))
				{
					argNum = 3;
					show = ShowMode.Description;
				}
				else if((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "type") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "range") == 0))
				{
					argNum = 3;
					show = ShowMode.Type;
				}
				else if(StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "flags") == 0)
				{
					argNum = 3;
					show = ShowMode.Flags;
				}
			}

			if(args.Length > argNum)
			{
				match = args.Get(argNum, -1);
				match = match.Replace(" ", "");
			}
			else
			{
				match = "";
			}

			foreach(KeyValuePair<string, idInternalCvar> kvp in _cvarList)
			{
				idInternalCvar cvar = kvp.Value;

				if((cvar.Flags & flags) == 0)
				{
					continue;
				}

				if((match.Length > 0) && (cvar.Name.ToLower().Contains(match.ToLower()) == false))
				{
					continue;
				}

				list.Add(cvar);
			}

			list.OrderBy(a => a.Name);

			switch(show)
			{
				case ShowMode.Value:
					foreach(idCvar cvar in list)
					{
						idConsole.WriteLine("{0}{1}\"{2}\"", cvar.Name.PadRight(32), idColorString.White, cvar.ToString());
					}
					break;

				case ShowMode.Description:
					foreach(idCvar cvar in list)
					{
						idConsole.WriteLine("{0}{1}{2}", cvar.Name.PadRight(32), idColorString.White, idHelper.WrapText(cvar.Description, 77 - 33, 33));
					}
					break;

				case ShowMode.Type:
					foreach(idCvar cvar in list)
					{
						if((cvar.Flags & CvarFlags.Bool) == CvarFlags.Bool)
						{
							idConsole.WriteLine("{0}{1}bool", cvar.Name.PadRight(32), idColorString.Cyan);
						}
						else if((cvar.Flags & CvarFlags.Integer) == CvarFlags.Integer)
						{
							if(cvar.MinValue < cvar.MaxValue)
							{
								idConsole.WriteLine("{0}{1}int {2}[{3}, {4}]", cvar.Name.PadRight(32), idColorString.Green, idColorString.White, cvar.MinValue, cvar.MaxValue);
							}
							else
							{
								idConsole.WriteLine("{0}{1}int", cvar.Name.PadRight(32), idColorString.Green);
							}
						}
						else if((cvar.Flags & CvarFlags.Float) == CvarFlags.Float)
						{
							if(cvar.MinValue < cvar.MaxValue)
							{
								idConsole.WriteLine("{0}{1}float {2}[{3}, {4}]", cvar.Name.PadRight(32), idColorString.Red, idColorString.White, cvar.MinValue, cvar.MaxValue);
							}
							else
							{
								idConsole.WriteLine("{0}{1}float", cvar.Name.PadRight(32), idColorString.Red);
							}
						}
						else if(cvar.ValueStrings != null)
						{
							idConsole.Write("{0}{1}string {2}[", cvar.Name.PadRight(32), idColorString.White, idColorString.White);

							int count = cvar.ValueStrings.Length;

							for(int j = 0; j < count; j++)
							{
								if(j > 0)
								{
									idConsole.Write("{0}, {1}", idColorString.White, cvar.ValueStrings[j]);
								}
								else
								{
									idConsole.Write("{0}{1}", idColorString.White, cvar.ValueStrings[j]);
								}
							}

							idConsole.WriteLine("{0}]", idColorString.White);
						}
						else
						{
							idConsole.WriteLine("{0}{1}string", cvar.Name.PadRight(32), idColorString.White);
						}
					}
					break;

				case ShowMode.Flags:
					foreach(idCvar cvar in list)
					{
						idConsole.Write(cvar.Name.PadRight(32));

						string str = string.Empty;

						if((cvar.Flags & CvarFlags.Bool) == CvarFlags.Bool)
						{
							str += string.Format("{0}B ", idColorString.Cyan);
						}
						else if((cvar.Flags & CvarFlags.Integer) == CvarFlags.Integer)
						{
							str += string.Format("{0}U ", idColorString.Green);
						}
						else if((cvar.Flags & CvarFlags.Float) == CvarFlags.Float)
						{
							str += string.Format("{0}F ", idColorString.Red);
						}
						else
						{
							str += string.Format("{0}S ", idColorString.White);
						}

						if((cvar.Flags & CvarFlags.System) == CvarFlags.System)
						{
							str += string.Format("{0}SYS  ", idColorString.White);
						}
						else if((cvar.Flags & CvarFlags.Renderer) == CvarFlags.Renderer)
						{
							str += string.Format("{0}RNDR ", idColorString.White);
						}
						else if((cvar.Flags & CvarFlags.Sound) == CvarFlags.Sound)
						{
							str += string.Format("{0}SND  ", idColorString.White);
						}
						else if((cvar.Flags & CvarFlags.Gui) == CvarFlags.Gui)
						{
							str += string.Format("{0}GUI  ", idColorString.White);
						}
						else if((cvar.Flags & CvarFlags.Game) == CvarFlags.Game)
						{
							str += string.Format("{0}GAME ", idColorString.White);
						}
						else if((cvar.Flags & CvarFlags.Tool) == CvarFlags.Tool)
						{
							str += string.Format("{0}TOOL ", idColorString.White);
						}
						else
						{
							str += string.Format("{0}     ", idColorString.White);
						}

						str += ((cvar.Flags & CvarFlags.UserInfo) == CvarFlags.UserInfo) ? "UI " : "   ";
						str += ((cvar.Flags & CvarFlags.ServerInfo) == CvarFlags.ServerInfo) ? "SI " : "   ";
						str += ((cvar.Flags & CvarFlags.Static) == CvarFlags.Static) ? "ST " : "   ";
						str += ((cvar.Flags & CvarFlags.Cheat) == CvarFlags.Cheat) ? "CH " : "   ";
						str += ((cvar.Flags & CvarFlags.Init) == CvarFlags.Init) ? "IN " : "   ";
						str += ((cvar.Flags & CvarFlags.ReadOnly) == CvarFlags.ReadOnly) ? "RO " : "   ";
						str += ((cvar.Flags & CvarFlags.Archive) == CvarFlags.Archive) ? "AR " : "   ";
						str += ((cvar.Flags & CvarFlags.Modified) == CvarFlags.Modified) ? "MO " : "   ";

						idConsole.WriteLine(str);						
					}
					break;
			}

			idConsole.WriteLine("\n{0} cvars listed\n", list.Count);
			idConsole.WriteLine("listCvar [search string]          = list cvar values");
			idConsole.WriteLine("listCvar -help [search string]    = list cvar descriptions");
			idConsole.WriteLine("listCvar -type [search string]    = list cvar types");
			idConsole.WriteLine("listCvar -flags [search string]   = list cvar flags");
		}
		/// <summary>
		/// Called by the command system when a command is unrecognized.
		/// </summary>
		/// <param name="args"></param>
		/// <returns></returns>
		public bool Command(idCmdArgs args)
		{
			idInternalCvar intern = FindInternal(args.Get(0));

			if(intern == null)
			{
				return false;
			}

			if(args.Length == 1)
			{
				// print the variable
				idConsole.WriteLine("\"{0}\" is: \"{1}\" {2} default: \"{3}\"", intern.Name, intern.ToString(), idColorString.White, intern.ResetString);

				if(intern.Description.Length > 0)
				{
					idConsole.WriteLine("{0}{1}", idColorString.White, intern.Description);
				}
			}
			else
			{
				// set the value
				intern.Set(args.ToString(), false, false);
			}

			return true;
		}