aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/ServerConsole.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ServerConsole.cs195
1 files changed, 0 insertions, 195 deletions
diff --git a/src/ServerConsole.cs b/src/ServerConsole.cs
deleted file mode 100644
index 21a465d..0000000
--- a/src/ServerConsole.cs
+++ /dev/null
@@ -1,195 +0,0 @@
1/*
2Copyright (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
30using System;
31using System.Collections;
32using System.Collections.Generic;
33using System.Threading;
34using System.IO;
35using System.Net;
36using libsecondlife;
37using libsecondlife.Packets;
38
39namespace 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 "help":
148 this.WriteLine("show users - show info about connected users");
149 this.WriteLine("shutdown - disconnect all clients and shutdown");
150 break;
151
152 case "show":
153 ShowCommands(cmdparams[0]);
154 break;
155
156 case "shutdown":
157 OpenSim_Main.Shutdown();
158 break;
159 }
160 return null;
161 }
162
163 // Shows data about something
164 public void ShowCommands(string ShowWhat) {
165 switch(ShowWhat) {
166 case "uptime":
167 this.WriteLine("OpenSim has been running since " + OpenSim_Main.startuptime.ToString());
168 this.WriteLine("That is " + (DateTime.Now-OpenSim_Main.startuptime).ToString());
169 break;
170 case "users":
171 OpenSim.world.Avatar TempAv;
172 this.WriteLine(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}","Firstname", "Lastname","Agent ID", "Session ID", "Circuit", "IP"));
173 foreach (libsecondlife.LLUUID UUID in OpenSim_Main.local_world.Entities.Keys) {
174 TempAv=(OpenSim.world.Avatar)OpenSim_Main.local_world.Entities[UUID];
175 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()));
176 }
177 break;
178 }
179 }
180
181 // Displays a prompt to the user and then runs the command they entered
182 public void MainConsolePrompt() {
183 string[] tempstrarray;
184 string tempstr = this.CmdPrompt("OpenSim-" + OpenSim_Main.cfg.RegionHandle.ToString() + " # ");
185 tempstrarray = tempstr.Split(' ');
186 string cmd=tempstrarray[0];
187 Array.Reverse(tempstrarray);
188 Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1);
189 Array.Reverse(tempstrarray);
190 string[] cmdparams=(string[])tempstrarray;
191 RunCmd(cmd,cmdparams);
192 }
193 }
194
195}