/// <summary> /// Removes the next char if it's a Command Prefix, and /// sets dbl = true, if it is double. /// </summary> public static bool ConsumeCommandPrefix(StringStream str, out bool dbl) { char c = str.PeekChar(); if (RealmCommandHandler.IsCommandPrefix(c)) { ++str.Position; dbl = str.ConsumeNext(c); return(true); } dbl = false; return(false); }
/// <summary>Default Command-Handling method</summary> /// <returns>Whether the given msg triggered a command</returns> public static bool HandleCommand(IUser user, string msg, IGenericChatTarget target) { if (msg.Length > 0 && user.Role.Commands.Count > 0) { char ch1; bool isCall; if (!(isCall = !RealmCommandHandler.IsCommandPrefix(ch1 = msg[0])) || (int)ch1 == (int)RealmCommandHandler.ExecCommandPrefix) { if (msg.Length != 2 || msg[1] != '?') { bool flag = false; foreach (char ch2 in msg) { if (ch2 >= 'A') { flag = true; break; } } if (!flag) { return(false); } } bool dbl = false; int startIndex = 1; if ((int)msg[1] == (int)ch1) { if (!user.Role.CanUseCommandsOnOthers) { user.SendMessage("You are not allowed to use Commands on others."); return(true); } if (user.Target == null) { user.SendMessage("Invalid target."); return(true); } dbl = true; ++startIndex; } IngameCmdTrigger trigger = new IngameCmdTrigger(new StringStream(msg.Substring(startIndex)), user, target, dbl); if (trigger.InitTrigger()) { if (trigger.Args.Context != null) { trigger.Args.Context.ExecuteInContext((Action)(() => { if (!isCall) { RealmCommandHandler.Instance.Execute((CmdTrigger <RealmServerCmdArgs>)trigger, false); } else { RealmCommandHandler.Call((CmdTrigger <RealmServerCmdArgs>)trigger); } })); } else if (!isCall) { RealmCommandHandler.Instance.Execute((CmdTrigger <RealmServerCmdArgs>)trigger, false); } else { RealmCommandHandler.Call((CmdTrigger <RealmServerCmdArgs>)trigger); } } return(true); } if ((int)ch1 == (int)RealmCommandHandler.SelectCommandPrefix && user.Role.IsStaff) { return(RealmCommandHandler.SelectCommand(user, msg.Substring(1))); } } return(false); }