/// <summary> /// Tries to parse given line as a server command. /// </summary> /// <param name="line">The line to be parsed.</param> /// <param name="invokerClient">The invoker client if any.</param> /// <param name="respondOver">The response medium to command</param> /// <returns><see cref="bool"/></returns> public static bool TryParse(string line, MooNetClient invokerClient, RespondOver respondOver) { string output = string.Empty; string command; string parameters; var found = false; if (!ExtractCommandAndParameters(line, out command, out parameters)) return false; foreach(var pair in CommandGroups) { if (pair.Key.Name != command) continue; output = pair.Value.Handle(parameters, invokerClient); found = true; break; } if (found == false) output = string.Format("Unknown command: {0} {1}", command, parameters); if (output == string.Empty) return true; switch (respondOver) { case RespondOver.Channel: // if invoked from client within a channel if (invokerClient != null) invokerClient.SendServerMessage(output); break; case RespondOver.Whisper: // if invoked from client with a whisper if (invokerClient != null) invokerClient.SendServerWhisper(output); break; } return true; }