Esempio n. 1
0
		public static void SetProp(object propHolder, MemberInfo prop, CmdTrigger<RealmServerCmdArgs> trigger)
		{
			if (prop != null && ReflectUtil.Instance.CanWrite(prop, trigger.Args.Role))
			{
				var expr = trigger.Text.Remainder.Trim();
				if (expr.Length == 0)
				{
					trigger.Reply("No expression given");
				}
				else
				{
					var exprType = prop.GetVariableType();
					object actualValue = null;

					if (exprType.IsInteger())
					{
						object error = null;
						long value = 0;
						if (!Utility.Eval(exprType, ref value, expr, ref error, false))
						{
							trigger.Reply("Invalid expression: " + error);
							return;
						}
						actualValue = ConvertActualType(value, exprType);
					}
					else
					{
						if (!Utility.Parse(expr, exprType, ref actualValue))
						{
							trigger.Reply("Could not change value \"{0}\" to Type: {1}", expr, exprType);
							return;
						}
					}

					prop.SetUnindexedValue(propHolder, actualValue);
					string strValue;
					if (exprType.IsEnum)
					{
						strValue = Enum.Format(exprType, actualValue, "g");
					}
					else
					{
						strValue = actualValue.ToString();
					}
					trigger.Reply("{0} is now {1}.", prop.Name, strValue);
				}
			}
			else
			{
				trigger.Reply("Invalid field.");
			}
		}
Esempio n. 2
0
		public static void ModProp(object propHolder, MemberInfo prop, CmdTrigger<RealmServerCmdArgs> trigger)
		{
			if (prop != null && ReflectUtil.Instance.CanWrite(prop, trigger.Args.Role))
			{
				var exprType = prop.GetVariableType();
				if (!exprType.IsInteger())
				{
					trigger.Reply("Can only modify Integer-values.");
				}
				else
				{
					var expr = trigger.Text.Remainder.Trim();
					if (expr.Length == 0)
					{
						trigger.Reply("No expression given");
					}
					else
					{
						object error = null;
						var value = Convert.ToInt64(prop.GetUnindexedValue(propHolder));

						if (!Utility.Eval(exprType, ref value, expr, ref error, true))
						{
							trigger.Reply("Invalid expression: " + error);
						}
						else
						{
							var actualValue = TryParseEnum(value, exprType);
							prop.SetUnindexedValue(propHolder, actualValue);
							string strValue;
							if (exprType.IsEnum)
							{
								strValue = Enum.Format(exprType, actualValue, "g");
							}
							else
							{
								strValue = value.ToString();
							}
							trigger.Reply("Success: {0} is now {1}.", prop.Name, strValue);
						}
					}
				}
			}
			else
			{
				trigger.Reply("Invalid field.");
			}
		}