aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/Application/OpenSim.cs94
1 files changed, 93 insertions, 1 deletions
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index b020a6c..3c37e90 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -177,7 +177,7 @@ namespace OpenSim
177 public override void RunCmd(string command, string[] cmdparams) 177 public override void RunCmd(string command, string[] cmdparams)
178 { 178 {
179 base.RunCmd(command, cmdparams); 179 base.RunCmd(command, cmdparams);
180 180 RunPluginCommands(command + " " + CombineParams(cmdparams, 0));
181 switch (command) 181 switch (command)
182 { 182 {
183 case "clear-assets": 183 case "clear-assets":
@@ -226,6 +226,7 @@ namespace OpenSim
226 break; 226 break;
227 227
228 case "help": 228 case "help":
229 RunPluginCommandHelp(CombineParams(cmdparams, 0),m_console);
229 m_console.Notice("alert - send alert to a designated user or all users."); 230 m_console.Notice("alert - send alert to a designated user or all users.");
230 m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive."); 231 m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
231 m_console.Notice(" alert general [Message] - send an alert to all users."); 232 m_console.Notice(" alert general [Message] - send an alert to all users.");
@@ -673,5 +674,96 @@ namespace OpenSim
673 } 674 }
674 675
675 #endregion 676 #endregion
677
678 static private List<ConsolePluginCommand> m_PluginCommandInfos = new List<ConsolePluginCommand>();
679
680 public bool RunPluginCommands(string cmd)
681 {
682 ConsolePluginCommand bestMatch = null;
683 int bestLength = 0;
684 foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
685 {
686 int matchLen = cmdinfo.matchLength(cmd);
687 if (matchLen > bestLength)
688 {
689 bestMatch = cmdinfo;
690 bestLength = matchLen;
691 }
692 }
693 if (bestMatch == null)
694 {
695 return false;
696 }
697 bestMatch.Run(cmd);
698 return true;
699 }
700 public bool RunPluginCommandHelp(string cmd, ConsoleBase console)
701 {
702 ConsolePluginCommand bestMatch = null;
703 int bestLength = 0;
704 foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
705 {
706 int matchLen = cmdinfo.matchLength(cmd);
707 if (matchLen > bestLength)
708 {
709 bestMatch = cmdinfo;
710 bestLength = matchLen;
711 }
712 }
713 if (bestMatch == null)
714 {
715 return false;
716 }
717 bestMatch.ShowHelp(console);
718 return true;
719 }
720 public static void RegisterCmd(string cmd, ConsoleCommand deligate, string hlp)
721 {
722 m_PluginCommandInfos.Add(new ConsolePluginCommand(cmd, deligate, hlp));
723 }
724
725 public class ConsolePluginCommand
726 {
727 private ConsoleCommand m_commandDelegate;
728 private string m_helpText;
729 private string m_cmdText;
730
731 public int matchLength(string targetText)
732 {
733 // QUESTION: have a case insensitive flag?
734 targetText = targetText.ToLower();
735 string matchText = m_cmdText.ToLower();
736 if (targetText.StartsWith(matchText))
737 {
738 // TODO return cmdText.Length; ?
739 return matchText.Length;
740 }
741 return 0;
742 }
743 public ConsolePluginCommand(string cmd, ConsoleCommand del, string help)
744 {
745 m_cmdText = cmd;
746 m_commandDelegate = del;
747 m_helpText = help;
748 }
749
750 public void Run(string incomming)
751 {
752 string targetText = m_cmdText.ToLower();
753 string matchText = incomming.ToLower();
754
755 if (targetText.StartsWith(matchText))
756 {
757 incomming = incomming.Substring(matchText.Length);
758 }
759 m_commandDelegate(incomming.Split(new char[] {' '}));
760 }
761
762 public void ShowHelp(ConsoleBase console)
763 {
764 console.Notice(m_cmdText + ": " + m_helpText);
765 // throw new Exception("The method or operation is not implemented.");
766 }
767 }
676 } 768 }
677} 769}