Guard the values used to set the cursor position in the real time console

0.6.3-post-fixes
Melanie Thielker 2009-02-13 20:49:23 +00:00
parent b71d68c9bc
commit a8f3d625cb
2 changed files with 54 additions and 16 deletions

View File

@ -554,13 +554,39 @@ namespace OpenSim.Framework.Console
WriteNewLine(DeriveColor(sender), sender, ConsoleColor.Gray, format, args);
}
private int SetCursorTop(int top)
{
if (top >= 0 && top < System.Console.BufferHeight)
{
System.Console.CursorTop = top;
return top;
}
else
{
return System.Console.CursorTop;
}
}
private int SetCursorLeft(int left)
{
if (left >= 0 && left < System.Console.BufferWidth)
{
System.Console.CursorLeft = left;
return left;
}
else
{
return System.Console.CursorLeft;
}
}
private void WriteNewLine(ConsoleColor senderColor, string sender, ConsoleColor color, string format, params object[] args)
{
lock (cmdline)
{
if (y != -1)
{
System.Console.CursorTop = y;
y=SetCursorTop(y);
System.Console.CursorLeft = 0;
int count = cmdline.Length;
@ -569,7 +595,7 @@ namespace OpenSim.Framework.Console
while (count-- > 0)
System.Console.Write(" ");
System.Console.CursorTop = y;
y=SetCursorTop(y);
System.Console.CursorLeft = 0;
}
WritePrefixLine(senderColor, sender);
@ -585,7 +611,7 @@ namespace OpenSim.Framework.Console
{
if (y != -1)
{
System.Console.CursorTop = y;
y=SetCursorTop(y);
System.Console.CursorLeft = 0;
int count = cmdline.Length;
@ -594,7 +620,7 @@ namespace OpenSim.Framework.Console
while (count-- > 0)
System.Console.Write(" ");
System.Console.CursorTop = y;
y=SetCursorTop(y);
System.Console.CursorLeft = 0;
}
WriteConsoleLine(color, format, args);
@ -695,7 +721,7 @@ namespace OpenSim.Framework.Console
System.Console.WriteLine(" ");
}
System.Console.CursorTop = y;
y=SetCursorTop(y);
System.Console.CursorLeft = 0;
if (echo)
@ -703,8 +729,8 @@ namespace OpenSim.Framework.Console
else
System.Console.Write("{0}", prompt);
System.Console.CursorLeft = new_x;
System.Console.CursorTop = new_y;
SetCursorLeft(new_x);
SetCursorTop(new_y);
}
}
@ -715,7 +741,7 @@ namespace OpenSim.Framework.Console
{
if (y != -1)
{
System.Console.CursorTop = y;
y = SetCursorTop(y);
System.Console.CursorLeft = 0;
int count = cmdline.Length + prompt.Length;
@ -723,7 +749,7 @@ namespace OpenSim.Framework.Console
while (count-- > 0)
System.Console.Write(" ");
System.Console.CursorTop = y;
y = SetCursorTop(y);
System.Console.CursorLeft = 0;
}
@ -754,7 +780,7 @@ namespace OpenSim.Framework.Console
return;
}
System.Console.CursorTop = y;
y = SetCursorTop(y);
System.Console.CursorLeft = 0;
int count = cmdline.Length + prompt.Length;
@ -762,7 +788,7 @@ namespace OpenSim.Framework.Console
while (count-- > 0)
System.Console.Write(" ");
System.Console.CursorTop = y;
y = SetCursorTop(y);
System.Console.CursorLeft = 0;
System.Console.WriteLine(text);
@ -915,7 +941,7 @@ namespace OpenSim.Framework.Console
cp--;
System.Console.CursorLeft = 0;
System.Console.CursorTop = y;
y = SetCursorTop(y);
System.Console.Write("{0}{1} ", prompt, cmdline);
@ -963,7 +989,7 @@ namespace OpenSim.Framework.Console
break;
case ConsoleKey.Enter:
System.Console.CursorLeft = 0;
System.Console.CursorTop = y;
y = SetCursorTop(y);
System.Console.WriteLine("{0}{1}", prompt, cmdline);

View File

@ -154,7 +154,9 @@ namespace OpenSim
protected override List<string> GetHelpTopics()
{
List<string> topics = base.GetHelpTopics();
topics.AddRange(SceneManager.CurrentOrFirstScene.GetCommanders().Keys);
Scene s = SceneManager.CurrentOrFirstScene;
if (s != null && s.GetCommanders() != null)
topics.AddRange(s.GetCommanders().Keys);
return topics;
}
@ -204,8 +206,15 @@ namespace OpenSim
"Execute subcommand for plugin '" + topic + "'",
null);
ICommander commander =
SceneManager.CurrentOrFirstScene.GetCommanders()[topic];
ICommander commander = null;
Scene s = SceneManager.CurrentOrFirstScene;
if (s != null && s.GetCommanders() != null)
{
if (s.GetCommanders().ContainsKey(topic))
commander = s.GetCommanders()[topic];
}
if (commander == null)
continue;
@ -227,6 +236,9 @@ namespace OpenSim
private void HandleCommanderHelp(string module, string[] cmd)
{
// Only safe for the interactive console, since it won't
// let us come here unless both scene and commander exist
//
ICommander moduleCommander = SceneManager.CurrentOrFirstScene.GetCommander(cmd[1]);
if (moduleCommander != null)
m_console.Notice(moduleCommander.Help);