aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Framework.Console
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.Framework.Console')
-rw-r--r--OpenSim.Framework.Console/ConsoleBase.cs144
-rw-r--r--OpenSim.Framework.Console/ConsoleCallbacksBase.cs12
-rw-r--r--OpenSim.Framework.Console/OpenSim.Framework.Console.csproj5
-rw-r--r--OpenSim.Framework.Console/OpenSim.Framework.Console.dll.build83
4 files changed, 183 insertions, 61 deletions
diff --git a/OpenSim.Framework.Console/ConsoleBase.cs b/OpenSim.Framework.Console/ConsoleBase.cs
index 5343e71..e2e4457 100644
--- a/OpenSim.Framework.Console/ConsoleBase.cs
+++ b/OpenSim.Framework.Console/ConsoleBase.cs
@@ -1,45 +1,151 @@
1using System; 1using System;
2using System.IO;
2 3
3namespace OpenSim.Framework.Console 4namespace OpenSim.Framework.Console
4{ 5{
5 public abstract class ConsoleBase 6 public class ConsoleBase
6 { 7 {
8 StreamWriter Log;
9 public conscmd_callback cmdparser;
10 public string componentname;
7 11
8 public enum ConsoleType 12 // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!!
13 // constype - the type of console to use (see enum ConsoleType)
14 // sparam - depending on the console type:
15 // TCP - the IP to bind to (127.0.0.1 if blank)
16 // Local - param ignored
17 // and for the iparam:
18 // TCP - the port to bind to
19 // Local - param ignored
20 // LogFile - duh
21 // componentname - which component of the OGS system? (user, asset etc)
22 // cmdparser - a reference to a conscmd_callback object
23
24 public ConsoleBase(string LogFile, string componentname, conscmd_callback cmdparser)
9 { 25 {
10 Local, // Use stdio 26 this.componentname = componentname;
11 TCP, // Use TCP/telnet 27 this.cmdparser = cmdparser;
12 SimChat // Use in-world chat (for gods) 28
29 System.Console.WriteLine("ServerConsole.cs - creating new local console");
30 System.Console.WriteLine("Logs will be saved to current directory in " + LogFile);
31 Log = File.AppendText(LogFile);
32 Log.WriteLine("========================================================================");
33 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString());
13 } 34 }
14 35
15 public abstract void Close(); 36 public void Close()
37 {
38 Log.WriteLine("Shutdown at " + DateTime.Now.ToString());
39 Log.Close();
40 }
41
42 public void Write(string format, params object[] args)
43 {
44 Log.Write(format, args);
45 System.Console.Write(format, args);
46 return;
47 }
16 48
17 public abstract void Write(string format, params object[] args); 49 public void WriteLine(string format, params object[] args)
50 {
51 Log.WriteLine(format, args);
52 System.Console.WriteLine(format, args);
53 return;
54 }
18 55
19 public abstract void WriteLine(string format, params object[] args); 56 public string ReadLine()
57 {
58 string TempStr = System.Console.ReadLine();
59 Log.WriteLine(TempStr);
60 return TempStr;
61 }
20 62
21 public abstract string ReadLine(); 63 public int Read()
64 {
65 int TempInt = System.Console.Read();
66 Log.Write((char)TempInt);
67 return TempInt;
68 }
22 69
23 public abstract int Read(); 70 // Displays a prompt and waits for the user to enter a string, then returns that string
71 // Done with no echo and suitable for passwords
72 public string PasswdPrompt(string prompt)
73 {
74 // FIXME: Needs to be better abstracted
75 Log.WriteLine(prompt);
76 this.Write(prompt);
77 ConsoleColor oldfg = System.Console.ForegroundColor;
78 System.Console.ForegroundColor = System.Console.BackgroundColor;
79 string temp = System.Console.ReadLine();
80 System.Console.ForegroundColor = oldfg;
81 return temp;
82 }
24 83
25 // Displays a command prompt and waits for the user to enter a string, then returns that string 84 // Displays a command prompt and waits for the user to enter a string, then returns that string
26 public abstract string CmdPrompt(string prompt); 85 public string CmdPrompt(string prompt)
86 {
87 this.Write(prompt);
88 return this.ReadLine();
89 }
27 90
28 // Displays a command prompt and returns a default value if the user simply presses enter 91 // Displays a command prompt and returns a default value if the user simply presses enter
29 public abstract string CmdPrompt(string prompt, string defaultresponse); 92 public string CmdPrompt(string prompt, string defaultresponse)
93 {
94 string temp = CmdPrompt(prompt);
95 if (temp == "")
96 {
97 return defaultresponse;
98 }
99 else
100 {
101 return temp;
102 }
103 }
30 104
31 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options 105 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
32 public abstract string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB); 106 public string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB)
107 {
108 bool itisdone = false;
109 string temp = CmdPrompt(prompt, defaultresponse);
110 while (itisdone == false)
111 {
112 if ((temp == OptionA) || (temp == OptionB))
113 {
114 itisdone = true;
115 }
116 else
117 {
118 this.WriteLine("Valid options are " + OptionA + " or " + OptionB);
119 temp = CmdPrompt(prompt, defaultresponse);
120 }
121 }
122 return temp;
123 }
33 124
34 // Runs a command with a number of parameters 125 // Runs a command with a number of parameters
35 public abstract Object RunCmd(string Cmd, string[] cmdparams); 126 public Object RunCmd(string Cmd, string[] cmdparams)
127 {
128 cmdparser.RunCmd(Cmd, cmdparams);
129 return null;
130 }
36 131
37 // Shows data about something 132 // Shows data about something
38 public abstract void ShowCommands(string ShowWhat); 133 public void ShowCommands(string ShowWhat)
39 134 {
40 // Displays a prompt to the user and then runs the command they entered 135 cmdparser.Show(ShowWhat);
41 public abstract void MainConsolePrompt(); 136 }
42 137
43 public abstract void SetStatus(string status); 138 public void MainConsolePrompt()
139 {
140 string[] tempstrarray;
141 string tempstr = this.CmdPrompt(this.componentname + "# ");
142 tempstrarray = tempstr.Split(' ');
143 string cmd = tempstrarray[0];
144 Array.Reverse(tempstrarray);
145 Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1);
146 Array.Reverse(tempstrarray);
147 string[] cmdparams = (string[])tempstrarray;
148 RunCmd(cmd, cmdparams);
149 }
44 } 150 }
45} 151}
diff --git a/OpenSim.Framework.Console/ConsoleCallbacksBase.cs b/OpenSim.Framework.Console/ConsoleCallbacksBase.cs
new file mode 100644
index 0000000..bb589d2
--- /dev/null
+++ b/OpenSim.Framework.Console/ConsoleCallbacksBase.cs
@@ -0,0 +1,12 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.Console
6{
7 public interface conscmd_callback
8 {
9 void RunCmd(string cmd, string[] cmdparams);
10 void Show(string ShowWhat);
11 }
12}
diff --git a/OpenSim.Framework.Console/OpenSim.Framework.Console.csproj b/OpenSim.Framework.Console/OpenSim.Framework.Console.csproj
index a2718a5..bd10ce2 100644
--- a/OpenSim.Framework.Console/OpenSim.Framework.Console.csproj
+++ b/OpenSim.Framework.Console/OpenSim.Framework.Console.csproj
@@ -3,7 +3,7 @@
3 <ProjectType>Local</ProjectType> 3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion> 4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion> 5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{F5AD51E9-CF59-4C70-A586-CBD161EBB85F}</ProjectGuid> 6 <ProjectGuid>{7AED7536-7D6B-4E28-8016-B5A554C663B4}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon> 9 <ApplicationIcon></ApplicationIcon>
@@ -72,6 +72,9 @@
72 <Compile Include="ConsoleBase.cs"> 72 <Compile Include="ConsoleBase.cs">
73 <SubType>Code</SubType> 73 <SubType>Code</SubType>
74 </Compile> 74 </Compile>
75 <Compile Include="ConsoleCallbacksBase.cs">
76 <SubType>Code</SubType>
77 </Compile>
75 <Compile Include="MainConsole.cs"> 78 <Compile Include="MainConsole.cs">
76 <SubType>Code</SubType> 79 <SubType>Code</SubType>
77 </Compile> 80 </Compile>
diff --git a/OpenSim.Framework.Console/OpenSim.Framework.Console.dll.build b/OpenSim.Framework.Console/OpenSim.Framework.Console.dll.build
index 2dfc9b0..fa90bb6 100644
--- a/OpenSim.Framework.Console/OpenSim.Framework.Console.dll.build
+++ b/OpenSim.Framework.Console/OpenSim.Framework.Console.dll.build
@@ -1,41 +1,42 @@
1<?xml version="1.0" ?> 1<?xml version="1.0" ?>
2<project name="OpenSim.Framework.Console" default="build"> 2<project name="OpenSim.Framework.Console" default="build">
3 <target name="build"> 3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" /> 4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" /> 5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}"> 6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}"> 7 <fileset basedir="${project::get-base-directory()}">
8 </fileset> 8 </fileset>
9 </copy> 9 </copy>
10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll"> 10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
11 <resources prefix="OpenSim.Framework.Console" dynamicprefix="true" > 11 <resources prefix="OpenSim.Framework.Console" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="AssemblyInfo.cs" /> 14 <include name="AssemblyInfo.cs" />
15 <include name="ConsoleBase.cs" /> 15 <include name="ConsoleBase.cs" />
16 <include name="MainConsole.cs" /> 16 <include name="ConsoleCallbacksBase.cs" />
17 </sources> 17 <include name="MainConsole.cs" />
18 <references basedir="${project::get-base-directory()}"> 18 </sources>
19 <lib> 19 <references basedir="${project::get-base-directory()}">
20 <include name="${project::get-base-directory()}" /> 20 <lib>
21 <include name="${project::get-base-directory()}/${build.dir}" /> 21 <include name="${project::get-base-directory()}" />
22 </lib> 22 <include name="${project::get-base-directory()}/${build.dir}" />
23 <include name="System.dll" /> 23 </lib>
24 </references> 24 <include name="System.dll" />
25 </csc> 25 </references>
26 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../bin/" /> 26 </csc>
27 <mkdir dir="${project::get-base-directory()}/../bin/"/> 27 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../bin/" />
28 <copy todir="${project::get-base-directory()}/../bin/"> 28 <mkdir dir="${project::get-base-directory()}/../bin/"/>
29 <fileset basedir="${project::get-base-directory()}/${build.dir}/" > 29 <copy todir="${project::get-base-directory()}/../bin/">
30 <include name="*.dll"/> 30 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
31 <include name="*.exe"/> 31 <include name="*.dll"/>
32 </fileset> 32 <include name="*.exe"/>
33 </copy> 33 </fileset>
34 </target> 34 </copy>
35 <target name="clean"> 35 </target>
36 <delete dir="${bin.dir}" failonerror="false" /> 36 <target name="clean">
37 <delete dir="${obj.dir}" failonerror="false" /> 37 <delete dir="${bin.dir}" failonerror="false" />
38 </target> 38 <delete dir="${obj.dir}" failonerror="false" />
39 <target name="doc" description="Creates documentation."> 39 </target>
40 </target> 40 <target name="doc" description="Creates documentation.">
41</project> 41 </target>
42</project>