diff options
author | gareth | 2007-03-25 01:40:26 +0000 |
---|---|---|
committer | gareth | 2007-03-25 01:40:26 +0000 |
commit | 2fc543e0ab7b721fab9a575584ee01187a372a74 (patch) | |
tree | cf2ceeb3932a7a14566a859cdca3a08cb620a516 /OGS | |
parent | Added skeleton ODE plugin (diff) | |
download | opensim-SC-2fc543e0ab7b721fab9a575584ee01187a372a74.zip opensim-SC-2fc543e0ab7b721fab9a575584ee01187a372a74.tar.gz opensim-SC-2fc543e0ab7b721fab9a575584ee01187a372a74.tar.bz2 opensim-SC-2fc543e0ab7b721fab9a575584ee01187a372a74.tar.xz |
Adding the only stuff that makes sense
Diffstat (limited to '')
-rw-r--r-- | OGS/common/OGS-Console.cs | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/OGS/common/OGS-Console.cs b/OGS/common/OGS-Console.cs new file mode 100644 index 0000000..c35c75c --- /dev/null +++ b/OGS/common/OGS-Console.cs | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * Copyright (c) OpenSim project, http://sim.opensecondlife.org/ | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * * Redistributions of source code must retain the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer. | ||
8 | * * Redistributions in binary form must reproduce the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer in the | ||
10 | * documentation and/or other materials provided with the distribution. | ||
11 | * * Neither the name of the <organization> nor the | ||
12 | * names of its contributors may be used to endorse or promote products | ||
13 | * derived from this software without specific prior written permission. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
18 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
25 | * | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Threading; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using ServerConsole; | ||
35 | |||
36 | namespace OpenGridServices | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Description of ServerConsole. | ||
40 | /// </summary> | ||
41 | public class MServerConsole : ConsoleBase | ||
42 | { | ||
43 | |||
44 | private ConsoleType ConsType; | ||
45 | StreamWriter Log; | ||
46 | public conscmd_callback cmdparser; | ||
47 | public string componentname; | ||
48 | |||
49 | // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!! | ||
50 | // constype - the type of console to use (see enum ConsoleType) | ||
51 | // sparam - depending on the console type: | ||
52 | // TCP - the IP to bind to (127.0.0.1 if blank) | ||
53 | // Local - param ignored | ||
54 | // and for the iparam: | ||
55 | // TCP - the port to bind to | ||
56 | // Local - param ignored | ||
57 | // LogFile - duh | ||
58 | // componentname - which component of the OGS system? (user, asset etc) | ||
59 | // cmdparser - a reference to a conscmd_callback object | ||
60 | |||
61 | public MServerConsole(ConsoleType constype, string sparam, int iparam, string LogFile, string componentname, conscmd_callback cmdparser) { | ||
62 | ConsType = constype; | ||
63 | this.componentname = componentname; | ||
64 | this.cmdparser = cmdparser; | ||
65 | switch(constype) { | ||
66 | case ConsoleType.Local: | ||
67 | Console.WriteLine("ServerConsole.cs - creating new local console"); | ||
68 | Console.WriteLine("Logs will be saved to current directory in " + LogFile); | ||
69 | Log=File.AppendText(LogFile); | ||
70 | Log.WriteLine("========================================================================"); | ||
71 | Log.WriteLine(componentname + " " + VersionInfo.Version + " Started at " + DateTime.Now.ToString()); | ||
72 | break; | ||
73 | |||
74 | case ConsoleType.TCP: | ||
75 | break; | ||
76 | |||
77 | default: | ||
78 | Console.WriteLine("ServerConsole.cs - what are you smoking? that isn't a valid console type!"); | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public override void Close() { | ||
84 | Log.WriteLine("Shutdown at " + DateTime.Now.ToString()); | ||
85 | Log.Close(); | ||
86 | } | ||
87 | |||
88 | // You know what ReadLine() and WriteLine() do, right? And Read() and Write()? Right, you do actually know C#, right? Are you actually a programmer? Do you know english? Do you find my sense of humour in comments irritating? Good, glad you're still here | ||
89 | public override void WriteLine(string Line) { | ||
90 | Log.WriteLine(Line); | ||
91 | Console.WriteLine(Line); | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | public override string ReadLine() { | ||
96 | string TempStr=Console.ReadLine(); | ||
97 | Log.WriteLine(TempStr); | ||
98 | return TempStr; | ||
99 | } | ||
100 | |||
101 | public override int Read() { | ||
102 | int TempInt= Console.Read(); | ||
103 | Log.Write((char)TempInt); | ||
104 | return TempInt; | ||
105 | } | ||
106 | |||
107 | public override void Write(string Line) { | ||
108 | Console.Write(Line); | ||
109 | Log.Write(Line); | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | |||
114 | // Displays a prompt and waits for the user to enter a string, then returns that string | ||
115 | // Done with no echo and suitable for passwords | ||
116 | public override string PasswdPrompt(string prompt) { | ||
117 | // FIXME: Needs to be better abstracted | ||
118 | Log.WriteLine(prompt); | ||
119 | this.Write(prompt); | ||
120 | ConsoleColor oldfg=Console.ForegroundColor; | ||
121 | Console.ForegroundColor=Console.BackgroundColor; | ||
122 | string temp=Console.ReadLine(); | ||
123 | Console.ForegroundColor=oldfg; | ||
124 | return temp; | ||
125 | } | ||
126 | |||
127 | // Displays a command prompt and waits for the user to enter a string, then returns that string | ||
128 | public override string CmdPrompt(string prompt) { | ||
129 | this.Write(prompt); | ||
130 | return this.ReadLine(); | ||
131 | } | ||
132 | |||
133 | // Displays a command prompt and returns a default value if the user simply presses enter | ||
134 | public override string CmdPrompt(string prompt, string defaultresponse) { | ||
135 | string temp=CmdPrompt(prompt); | ||
136 | if(temp=="") { | ||
137 | return defaultresponse; | ||
138 | } else { | ||
139 | return temp; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | // Displays a command prompt and returns a default value, user may only enter 1 of 2 options | ||
144 | public override string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) { | ||
145 | bool itisdone=false; | ||
146 | string temp=CmdPrompt(prompt,defaultresponse); | ||
147 | while(itisdone==false) { | ||
148 | if((temp==OptionA) || (temp==OptionB)) { | ||
149 | itisdone=true; | ||
150 | } else { | ||
151 | this.WriteLine("Valid options are " + OptionA + " or " + OptionB); | ||
152 | temp=CmdPrompt(prompt,defaultresponse); | ||
153 | } | ||
154 | } | ||
155 | return temp; | ||
156 | } | ||
157 | |||
158 | // Runs a command with a number of parameters | ||
159 | public override Object RunCmd(string Cmd, string[] cmdparams) { | ||
160 | cmdparser.RunCmd(Cmd, cmdparams); | ||
161 | return null; | ||
162 | } | ||
163 | |||
164 | // Shows data about something | ||
165 | public override void ShowCommands(string ShowWhat) { | ||
166 | cmdparser.Show(ShowWhat); | ||
167 | } | ||
168 | |||
169 | public override void MainConsolePrompt() { | ||
170 | string[] tempstrarray; | ||
171 | string tempstr = this.CmdPrompt(this.componentname + "# "); | ||
172 | tempstrarray = tempstr.Split(' '); | ||
173 | string cmd=tempstrarray[0]; | ||
174 | Array.Reverse(tempstrarray); | ||
175 | Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1); | ||
176 | Array.Reverse(tempstrarray); | ||
177 | string[] cmdparams=(string[])tempstrarray; | ||
178 | RunCmd(cmd,cmdparams); | ||
179 | } | ||
180 | } | ||
181 | } | ||