diff options
author | gareth | 2007-03-06 15:57:36 +0000 |
---|---|---|
committer | gareth | 2007-03-06 15:57:36 +0000 |
commit | d828af7036fd11a4a1f678b2b7e51bdb6380087a (patch) | |
tree | 99544eb8c363afeccd0da17ba67970b8cc505d14 /src/ServerConsole.cs | |
parent | Added sandbox mode and setup facility (diff) | |
download | opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.zip opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.gz opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.bz2 opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.xz |
Implemented local console and VERY rough skeleton for TCP/Worldchat console
Implemented seperate logging (but no packetlog or chat yet)
Diffstat (limited to 'src/ServerConsole.cs')
-rw-r--r-- | src/ServerConsole.cs | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/src/ServerConsole.cs b/src/ServerConsole.cs new file mode 100644 index 0000000..690e8ee --- /dev/null +++ b/src/ServerConsole.cs | |||
@@ -0,0 +1,190 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenSim project, http://osgrid.org/ | ||
3 | |||
4 | * Copyright (c) <year>, <copyright holder> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Threading; | ||
34 | using System.IO; | ||
35 | using System.Net; | ||
36 | using libsecondlife; | ||
37 | using libsecondlife.Packets; | ||
38 | |||
39 | namespace OpenSim | ||
40 | { | ||
41 | public class ServerConsole { | ||
42 | private ConsoleType ConsType; | ||
43 | StreamWriter Log; | ||
44 | |||
45 | public enum ConsoleType { | ||
46 | Local, // Use stdio | ||
47 | TCP, // Use TCP/telnet | ||
48 | SimChat // Use in-world chat (for gods) | ||
49 | } | ||
50 | |||
51 | |||
52 | // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!! | ||
53 | // constype - the type of console to use (see enum ConsoleType) | ||
54 | // sparam - depending on the console type: | ||
55 | // TCP - the IP to bind to (127.0.0.1 if blank) | ||
56 | // Local - param ignored | ||
57 | // SimChat - the AgentID of this sim's admin | ||
58 | // and for the iparam: | ||
59 | // TCP - the port to bind to | ||
60 | // Local - param ignored | ||
61 | // SimChat - the chat channel to accept commands from | ||
62 | public ServerConsole(ConsoleType constype, string sparam, int iparam) { | ||
63 | ConsType = constype; | ||
64 | switch(constype) { | ||
65 | case ConsoleType.Local: | ||
66 | Console.WriteLine("ServerConsole.cs - creating new local console"); | ||
67 | Console.WriteLine("Logs will be saved to current directory in opensim-console.log"); | ||
68 | Log=File.AppendText("opensim-console.log"); | ||
69 | Log.WriteLine("========================================================================"); | ||
70 | Log.WriteLine("OpenSim " + VersionInfo.Version + " Started at " + DateTime.Now.ToString()); | ||
71 | break; | ||
72 | case ConsoleType.TCP: | ||
73 | break; | ||
74 | case ConsoleType.SimChat: | ||
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 void Close() { | ||
84 | Log.WriteLine("OpenSim 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 void WriteLine(string Line) { | ||
90 | Log.WriteLine(Line); | ||
91 | Console.WriteLine(Line); | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | public string ReadLine() { | ||
96 | string TempStr=Console.ReadLine(); | ||
97 | Log.WriteLine(TempStr); | ||
98 | return TempStr; | ||
99 | } | ||
100 | |||
101 | public int Read() { | ||
102 | int TempInt= Console.Read(); | ||
103 | Log.Write((char)TempInt); | ||
104 | return TempInt; | ||
105 | } | ||
106 | |||
107 | public void Write(string Line) { | ||
108 | Console.Write(Line); | ||
109 | Log.Write(Line); | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | // Displays a command prompt and waits for the user to enter a string, then returns that string | ||
114 | public string CmdPrompt(string prompt) { | ||
115 | this.Write(prompt); | ||
116 | return this.ReadLine(); | ||
117 | } | ||
118 | |||
119 | // Displays a command prompt and returns a default value if the user simply presses enter | ||
120 | public string CmdPrompt(string prompt, string defaultresponse) { | ||
121 | string temp=CmdPrompt(prompt); | ||
122 | if(temp=="") { | ||
123 | return defaultresponse; | ||
124 | } else { | ||
125 | return temp; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | // Displays a command prompt and returns a default value, user may only enter 1 of 2 options | ||
130 | public string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) { | ||
131 | bool itisdone=false; | ||
132 | string temp=CmdPrompt(prompt,defaultresponse); | ||
133 | while(itisdone==false) { | ||
134 | if((temp==OptionA) || (temp==OptionB)) { | ||
135 | itisdone=true; | ||
136 | } else { | ||
137 | this.WriteLine("Valid options are " + OptionA + " or " + OptionB); | ||
138 | temp=CmdPrompt(prompt,defaultresponse); | ||
139 | } | ||
140 | } | ||
141 | return temp; | ||
142 | } | ||
143 | |||
144 | // Runs a command with a number of parameters | ||
145 | public Object RunCmd(string Cmd, string[] cmdparams) { | ||
146 | switch(Cmd) { | ||
147 | case "show": | ||
148 | ShowCommands(cmdparams[0]); | ||
149 | break; | ||
150 | |||
151 | case "shutdown": | ||
152 | OpenSim_Main.Shutdown(); | ||
153 | break; | ||
154 | } | ||
155 | return null; | ||
156 | } | ||
157 | |||
158 | // Shows data about something | ||
159 | public void ShowCommands(string ShowWhat) { | ||
160 | switch(ShowWhat) { | ||
161 | case "uptime": | ||
162 | this.WriteLine("OpenSim has been running since " + OpenSim_Main.startuptime.ToString()); | ||
163 | this.WriteLine("That is " + (DateTime.Now-OpenSim_Main.startuptime).ToString()); | ||
164 | break; | ||
165 | case "users": | ||
166 | OpenSim.world.Avatar TempAv; | ||
167 | this.WriteLine(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}","Firstname", "Lastname","Agent ID", "Session ID", "Circuit", "IP")); | ||
168 | foreach (libsecondlife.LLUUID UUID in OpenSim_Main.local_world.Entities.Keys) { | ||
169 | TempAv=(OpenSim.world.Avatar)OpenSim_Main.local_world.Entities[UUID]; | ||
170 | this.WriteLine(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}",TempAv.firstname, TempAv.lastname,UUID, TempAv.ControllingClient.SessionID, TempAv.ControllingClient.CircuitCode, TempAv.ControllingClient.userEP.ToString())); | ||
171 | } | ||
172 | break; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | // Displays a prompt to the user and then runs the command they entered | ||
177 | public void MainConsolePrompt() { | ||
178 | string[] tempstrarray; | ||
179 | string tempstr = this.CmdPrompt("OpenSim-" + OpenSim_Main.cfg.RegionHandle.ToString() + " # "); | ||
180 | tempstrarray = tempstr.Split(' '); | ||
181 | string cmd=tempstrarray[0]; | ||
182 | Array.Reverse(tempstrarray); | ||
183 | Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1); | ||
184 | Array.Reverse(tempstrarray); | ||
185 | string[] cmdparams=(string[])tempstrarray; | ||
186 | RunCmd(cmd,cmdparams); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | } | ||