aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.UserServer/Main.cs
diff options
context:
space:
mode:
authorlbsa712007-03-27 08:10:15 +0000
committerlbsa712007-03-27 08:10:15 +0000
commita4fc6b5fbba7fd9a7b147b11a0d1c3ded1834d54 (patch)
tree560961306b9d80636d8ec976c05fcb8b54304f33 /OpenGridServices.UserServer/Main.cs
parentHeightfield needs fixing, or i'll re-implement it (probably actually the coll... (diff)
downloadopensim-SC_OLD-a4fc6b5fbba7fd9a7b147b11a0d1c3ded1834d54.zip
opensim-SC_OLD-a4fc6b5fbba7fd9a7b147b11a0d1c3ded1834d54.tar.gz
opensim-SC_OLD-a4fc6b5fbba7fd9a7b147b11a0d1c3ded1834d54.tar.bz2
opensim-SC_OLD-a4fc6b5fbba7fd9a7b147b11a0d1c3ded1834d54.tar.xz
* Now there's one Console class, and instead the apps responds to cmd's and show's
* Removed Golden Future TCP/SimChat options * Moved Ode.NET.dll to bin and changed prebuild accordingly (due to Prebuild limitations) * Normalized some namespaces * Added FxCop project * Added (temp disabled) Servers project (for great justice)
Diffstat (limited to 'OpenGridServices.UserServer/Main.cs')
-rw-r--r--OpenGridServices.UserServer/Main.cs215
1 files changed, 53 insertions, 162 deletions
diff --git a/OpenGridServices.UserServer/Main.cs b/OpenGridServices.UserServer/Main.cs
index d27f34e..c12e9d4 100644
--- a/OpenGridServices.UserServer/Main.cs
+++ b/OpenGridServices.UserServer/Main.cs
@@ -33,16 +33,16 @@ using System.Collections.Generic;
33using System.IO; 33using System.IO;
34using System.Text; 34using System.Text;
35using libsecondlife; 35using libsecondlife;
36using ServerConsole;
37using OpenSim.Framework.User; 36using OpenSim.Framework.User;
38using OpenSim.Framework.Sims; 37using OpenSim.Framework.Sims;
39using OpenSim.Framework.Inventory; 38using OpenSim.Framework.Inventory;
39using OpenSim.Framework.Console;
40 40
41namespace OpenGridServices 41namespace OpenGridServices.UserServer
42{ 42{
43 /// <summary> 43 /// <summary>
44 /// </summary> 44 /// </summary>
45 public class OpenUser_Main 45 public class OpenUser_Main : conscmd_callback
46 { 46 {
47 47
48 public static OpenUser_Main userserver; 48 public static OpenUser_Main userserver;
@@ -57,32 +57,45 @@ namespace OpenGridServices
57 57
58 public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>(); 58 public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
59 59
60 ConsoleBase m_console;
61
60 [STAThread] 62 [STAThread]
61 public static void Main( string[] args ) 63 public static void Main( string[] args )
62 { 64 {
63 Console.WriteLine("Starting...\n"); 65 Console.WriteLine("Starting...\n");
64 ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local, "", 0, "opengrid-console.log", "OpenUser", new UserConsole());
65 66
66 userserver = new OpenUser_Main(); 67 userserver = new OpenUser_Main();
67 userserver.Startup(); 68 userserver.Startup();
68 69
69 ServerConsole.MainConsole.Instance.WriteLine("\nEnter help for a list of commands\n"); 70 userserver.Work();
70
71 while(true) {
72 ServerConsole.MainConsole.Instance.MainConsolePrompt();
73 }
74 } 71 }
72
73 private OpenUser_Main()
74 {
75 m_console = new ConsoleBase("opengrid-console.log", "OpenUser", this);
76 MainConsole.Instance = m_console;
77 }
75 78
79 private void Work()
80 {
81 m_console.WriteLine("\nEnter help for a list of commands\n");
82
83 while (true)
84 {
85 m_console.MainConsolePrompt();
86 }
87 }
88
76 public void Startup() { 89 public void Startup() {
77 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings"); 90 MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings");
78 91
79 this.GridURL=ServerConsole.MainConsole.Instance.CmdPrompt("Grid URL: "); 92 this.GridURL=MainConsole.Instance.CmdPrompt("Grid URL: ");
80 this.GridSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to grid: "); 93 this.GridSendKey=MainConsole.Instance.CmdPrompt("Key to send to grid: ");
81 this.GridRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from grid: "); 94 this.GridRecvKey=MainConsole.Instance.CmdPrompt("Key to expect from grid: ");
82 95
83 this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!"); 96 this.DefaultStartupMsg=MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!");
84 97
85 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager"); 98 MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager");
86 _profilemanager = new UserProfileManager(); 99 _profilemanager = new UserProfileManager();
87 _profilemanager.InitUserProfiles(); 100 _profilemanager.InitUserProfiles();
88 _profilemanager.SetKeys(GridSendKey, GridRecvKey, GridURL, DefaultStartupMsg); 101 _profilemanager.SetKeys(GridSendKey, GridRecvKey, GridURL, DefaultStartupMsg);
@@ -91,10 +104,10 @@ namespace OpenGridServices
91 string tempfirstname; 104 string tempfirstname;
92 string templastname; 105 string templastname;
93 string tempMD5Passwd; 106 string tempMD5Passwd;
94 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:"); 107 MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:");
95 tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: "); 108 tempfirstname=MainConsole.Instance.CmdPrompt("First name: ");
96 templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: "); 109 templastname=MainConsole.Instance.CmdPrompt("Last name: ");
97 tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: "); 110 tempMD5Passwd=MainConsole.Instance.PasswdPrompt("Password: ");
98 111
99 System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); 112 System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
100 byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd); 113 byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd);
@@ -111,149 +124,27 @@ namespace OpenGridServices
111 GridGod.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f); 124 GridGod.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f);
112 GridGod.homepos = new LLVector3(128f,128f,23f); 125 GridGod.homepos = new LLVector3(128f,128f,23f);
113 126
114 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); 127 MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
115 _httpd = new UserHTTPServer(); 128 _httpd = new UserHTTPServer();
116 }
117 }
118
119 public class MServerConsole : ConsoleBase
120 {
121
122 private ConsoleType ConsType;
123 StreamWriter Log;
124 public conscmd_callback cmdparser;
125 public string componentname;
126
127 // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!!
128 // constype - the type of console to use (see enum ConsoleType)
129 // sparam - depending on the console type:
130 // TCP - the IP to bind to (127.0.0.1 if blank)
131 // Local - param ignored
132 // and for the iparam:
133 // TCP - the port to bind to
134 // Local - param ignored
135 // LogFile - duh
136 // componentname - which component of the OGS system? (user, asset etc)
137 // cmdparser - a reference to a conscmd_callback object
138
139 public MServerConsole(ConsoleType constype, string sparam, int iparam, string LogFile, string componentname, conscmd_callback cmdparser) {
140 ConsType = constype;
141 this.componentname = componentname;
142 this.cmdparser = cmdparser;
143 switch(constype) {
144 case ConsoleType.Local:
145 Console.WriteLine("ServerConsole.cs - creating new local console");
146 Console.WriteLine("Logs will be saved to current directory in " + LogFile);
147 Log=File.AppendText(LogFile);
148 Log.WriteLine("========================================================================");
149 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString());
150 break;
151
152 case ConsoleType.TCP:
153 break;
154
155 default:
156 Console.WriteLine("ServerConsole.cs - what are you smoking? that isn't a valid console type!");
157 break;
158 }
159 }
160
161 public override void Close() {
162 Log.WriteLine("Shutdown at " + DateTime.Now.ToString());
163 Log.Close();
164 }
165
166 // 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
167 public override void WriteLine(string Line) {
168 Log.WriteLine(Line);
169 Console.WriteLine(Line);
170 return;
171 }
172
173 public override string ReadLine() {
174 string TempStr=Console.ReadLine();
175 Log.WriteLine(TempStr);
176 return TempStr;
177 }
178
179 public override int Read() {
180 int TempInt= Console.Read();
181 Log.Write((char)TempInt);
182 return TempInt;
183 }
184
185 public override void Write(string Line) {
186 Console.Write(Line);
187 Log.Write(Line);
188 return;
189 }
190
191
192 // Displays a prompt and waits for the user to enter a string, then returns that string
193 // Done with no echo and suitable for passwords
194 public override string PasswdPrompt(string prompt) {
195 // FIXME: Needs to be better abstracted
196 Log.WriteLine(prompt);
197 this.Write(prompt);
198 ConsoleColor oldfg=Console.ForegroundColor;
199 Console.ForegroundColor=Console.BackgroundColor;
200 string temp=Console.ReadLine();
201 Console.ForegroundColor=oldfg;
202 return temp;
203 }
204
205 // Displays a command prompt and waits for the user to enter a string, then returns that string
206 public override string CmdPrompt(string prompt) {
207 this.Write(prompt);
208 return this.ReadLine();
209 }
210
211 // Displays a command prompt and returns a default value if the user simply presses enter
212 public override string CmdPrompt(string prompt, string defaultresponse) {
213 string temp=CmdPrompt(prompt);
214 if(temp=="") {
215 return defaultresponse;
216 } else {
217 return temp;
218 }
219 }
220
221 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
222 public override string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) {
223 bool itisdone=false;
224 string temp=CmdPrompt(prompt,defaultresponse);
225 while(itisdone==false) {
226 if((temp==OptionA) || (temp==OptionB)) {
227 itisdone=true;
228 } else {
229 this.WriteLine("Valid options are " + OptionA + " or " + OptionB);
230 temp=CmdPrompt(prompt,defaultresponse);
231 }
232 }
233 return temp;
234 }
235
236 // Runs a command with a number of parameters
237 public override Object RunCmd(string Cmd, string[] cmdparams) {
238 cmdparser.RunCmd(Cmd, cmdparams);
239 return null;
240 }
241
242 // Shows data about something
243 public override void ShowCommands(string ShowWhat) {
244 cmdparser.Show(ShowWhat);
245 } 129 }
246 130
247 public override void MainConsolePrompt() { 131 public void RunCmd(string cmd, string[] cmdparams)
248 string[] tempstrarray; 132 {
249 string tempstr = this.CmdPrompt(this.componentname + "# "); 133 switch (cmd)
250 tempstrarray = tempstr.Split(' '); 134 {
251 string cmd=tempstrarray[0]; 135 case "help":
252 Array.Reverse(tempstrarray); 136 m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)");
253 Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1); 137 break;
254 Array.Reverse(tempstrarray); 138
255 string[] cmdparams=(string[])tempstrarray; 139 case "shutdown":
256 RunCmd(cmd,cmdparams); 140 m_console.Close();
257 } 141 Environment.Exit(0);
142 break;
143 }
144 }
145
146 public void Show(string ShowWhat)
147 {
148 }
258 } 149 }
259} 150}