aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/OpenSimConsole.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/OpenSimConsole.cs')
-rw-r--r--src/OpenSimConsole.cs194
1 files changed, 194 insertions, 0 deletions
diff --git a/src/OpenSimConsole.cs b/src/OpenSimConsole.cs
new file mode 100644
index 0000000..7d8563f
--- /dev/null
+++ b/src/OpenSimConsole.cs
@@ -0,0 +1,194 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Threading;
32using System.IO;
33using System.Net;
34using libsecondlife;
35using libsecondlife.Packets;
36using ServerConsole;
37
38namespace OpenSim
39{
40 /// <summary>
41 /// Description of ServerConsole.
42 /// </summary>
43 public class MServerConsole : ConsoleBase
44 {
45
46 private ConsoleType ConsType;
47 StreamWriter Log;
48
49
50 // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!!
51 // constype - the type of console to use (see enum ConsoleType)
52 // sparam - depending on the console type:
53 // TCP - the IP to bind to (127.0.0.1 if blank)
54 // Local - param ignored
55 // SimChat - the AgentID of this sim's admin
56 // and for the iparam:
57 // TCP - the port to bind to
58 // Local - param ignored
59 // SimChat - the chat channel to accept commands from
60 public MServerConsole(ConsoleType constype, string sparam, int iparam) {
61 ConsType = constype;
62 switch(constype) {
63 case ConsoleType.Local:
64 Console.WriteLine("ServerConsole.cs - creating new local console");
65 Console.WriteLine("Logs will be saved to current directory in opensim-console.log");
66 Log=File.AppendText("opensim-console.log");
67 Log.WriteLine("========================================================================");
68 //Log.WriteLine("OpenSim " + VersionInfo.Version + " Started at " + DateTime.Now.ToString());
69 break;
70 case ConsoleType.TCP:
71 break;
72 case ConsoleType.SimChat:
73 break;
74
75 default:
76 Console.WriteLine("ServerConsole.cs - what are you smoking? that isn't a valid console type!");
77 break;
78 }
79 }
80
81 public override void Close() {
82 Log.WriteLine("OpenSim shutdown at " + DateTime.Now.ToString());
83 Log.Close();
84 }
85
86 // 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
87 public override void WriteLine(string Line) {
88 Log.WriteLine(Line);
89 Console.WriteLine(Line);
90 return;
91 }
92
93 public override string ReadLine() {
94 string TempStr=Console.ReadLine();
95 Log.WriteLine(TempStr);
96 return TempStr;
97 }
98
99 public override int Read() {
100 int TempInt= Console.Read();
101 Log.Write((char)TempInt);
102 return TempInt;
103 }
104
105 public override void Write(string Line) {
106 Console.Write(Line);
107 Log.Write(Line);
108 return;
109 }
110
111 // Displays a command prompt and waits for the user to enter a string, then returns that string
112 public override string CmdPrompt(string prompt) {
113 this.Write(prompt);
114 return this.ReadLine();
115 }
116
117 // Displays a command prompt and returns a default value if the user simply presses enter
118 public override string CmdPrompt(string prompt, string defaultresponse) {
119 string temp=CmdPrompt(prompt);
120 if(temp=="") {
121 return defaultresponse;
122 } else {
123 return temp;
124 }
125 }
126
127 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
128 public override string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) {
129 bool itisdone=false;
130 string temp=CmdPrompt(prompt,defaultresponse);
131 while(itisdone==false) {
132 if((temp==OptionA) || (temp==OptionB)) {
133 itisdone=true;
134 } else {
135 this.WriteLine("Valid options are " + OptionA + " or " + OptionB);
136 temp=CmdPrompt(prompt,defaultresponse);
137 }
138 }
139 return temp;
140 }
141
142 // Runs a command with a number of parameters
143 public override Object RunCmd(string Cmd, string[] cmdparams) {
144 switch(Cmd) {
145 case "help":
146 this.WriteLine("show users - show info about connected users");
147 this.WriteLine("shutdown - disconnect all clients and shutdown");
148 break;
149
150 case "show":
151 ShowCommands(cmdparams[0]);
152 break;
153
154 case "shutdown":
155 OpenSim_Main.Shutdown();
156 break;
157 }
158 return null;
159 }
160
161 // Shows data about something
162 public override void ShowCommands(string ShowWhat) {
163 switch(ShowWhat) {
164 case "uptime":
165 this.WriteLine("OpenSim has been running since " + OpenSim_Main.sim.startuptime.ToString());
166 this.WriteLine("That is " + (DateTime.Now-OpenSim_Main.sim.startuptime).ToString());
167 break;
168 case "users":
169 OpenSim.world.Avatar TempAv;
170 this.WriteLine(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}","Firstname", "Lastname","Agent ID", "Session ID", "Circuit", "IP"));
171 foreach (libsecondlife.LLUUID UUID in OpenSim_Main.local_world.Entities.Keys) {
172 TempAv=(OpenSim.world.Avatar)OpenSim_Main.local_world.Entities[UUID];
173 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()));
174 }
175 break;
176 }
177 }
178
179 // Displays a prompt to the user and then runs the command they entered
180 public override void MainConsolePrompt() {
181 string[] tempstrarray;
182 string tempstr = this.CmdPrompt("OpenSim-" + OpenSim_Main.cfg.RegionHandle.ToString() + " # ");
183 tempstrarray = tempstr.Split(' ');
184 string cmd=tempstrarray[0];
185 Array.Reverse(tempstrarray);
186 Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1);
187 Array.Reverse(tempstrarray);
188 string[] cmdparams=(string[])tempstrarray;
189 RunCmd(cmd,cmdparams);
190 }
191 }
192}
193
194