diff options
author | gareth | 2007-03-24 18:10:05 +0000 |
---|---|---|
committer | gareth | 2007-03-24 18:10:05 +0000 |
commit | d1fbe870afc5b89c7b1f8bf33d27e431f886ec07 (patch) | |
tree | 5c0dc4125f90ce2f8de79d84e25ce39524cba7d6 /OpenGridServices.UserServer/Main.cs | |
parent | Uncommented line (diff) | |
download | opensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.zip opensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.tar.gz opensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.tar.bz2 opensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.tar.xz |
Brought in the OGS user server into the main trunk (in a rather messy way)
Diffstat (limited to 'OpenGridServices.UserServer/Main.cs')
-rw-r--r-- | OpenGridServices.UserServer/Main.cs | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/OpenGridServices.UserServer/Main.cs b/OpenGridServices.UserServer/Main.cs new file mode 100644 index 0000000..d27f34e --- /dev/null +++ b/OpenGridServices.UserServer/Main.cs | |||
@@ -0,0 +1,259 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenSim project, http://osgrid.org/ | ||
3 | |||
4 | |||
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.IO; | ||
34 | using System.Text; | ||
35 | using libsecondlife; | ||
36 | using ServerConsole; | ||
37 | using OpenSim.Framework.User; | ||
38 | using OpenSim.Framework.Sims; | ||
39 | using OpenSim.Framework.Inventory; | ||
40 | |||
41 | namespace OpenGridServices | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// </summary> | ||
45 | public class OpenUser_Main | ||
46 | { | ||
47 | |||
48 | public static OpenUser_Main userserver; | ||
49 | |||
50 | public UserHTTPServer _httpd; | ||
51 | public UserProfileManager _profilemanager; | ||
52 | public UserProfile GridGod; | ||
53 | public string DefaultStartupMsg; | ||
54 | public string GridURL; | ||
55 | public string GridSendKey; | ||
56 | public string GridRecvKey; | ||
57 | |||
58 | public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>(); | ||
59 | |||
60 | [STAThread] | ||
61 | public static void Main( string[] args ) | ||
62 | { | ||
63 | Console.WriteLine("Starting...\n"); | ||
64 | ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local, "", 0, "opengrid-console.log", "OpenUser", new UserConsole()); | ||
65 | |||
66 | userserver = new OpenUser_Main(); | ||
67 | userserver.Startup(); | ||
68 | |||
69 | ServerConsole.MainConsole.Instance.WriteLine("\nEnter help for a list of commands\n"); | ||
70 | |||
71 | while(true) { | ||
72 | ServerConsole.MainConsole.Instance.MainConsolePrompt(); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | public void Startup() { | ||
77 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings"); | ||
78 | |||
79 | this.GridURL=ServerConsole.MainConsole.Instance.CmdPrompt("Grid URL: "); | ||
80 | this.GridSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to grid: "); | ||
81 | this.GridRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from grid: "); | ||
82 | |||
83 | this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!"); | ||
84 | |||
85 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager"); | ||
86 | _profilemanager = new UserProfileManager(); | ||
87 | _profilemanager.InitUserProfiles(); | ||
88 | _profilemanager.SetKeys(GridSendKey, GridRecvKey, GridURL, DefaultStartupMsg); | ||
89 | |||
90 | |||
91 | string tempfirstname; | ||
92 | string templastname; | ||
93 | string tempMD5Passwd; | ||
94 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:"); | ||
95 | tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: "); | ||
96 | templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: "); | ||
97 | tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: "); | ||
98 | |||
99 | System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); | ||
100 | byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd); | ||
101 | bs = x.ComputeHash(bs); | ||
102 | System.Text.StringBuilder s = new System.Text.StringBuilder(); | ||
103 | foreach (byte b in bs) | ||
104 | { | ||
105 | s.Append(b.ToString("x2").ToLower()); | ||
106 | } | ||
107 | tempMD5Passwd = "$1$" + s.ToString(); | ||
108 | |||
109 | GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd); | ||
110 | _profilemanager.SetGod(GridGod.UUID); | ||
111 | GridGod.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f); | ||
112 | GridGod.homepos = new LLVector3(128f,128f,23f); | ||
113 | |||
114 | ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); | ||
115 | _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 | } | ||
246 | |||
247 | public override void MainConsolePrompt() { | ||
248 | string[] tempstrarray; | ||
249 | string tempstr = this.CmdPrompt(this.componentname + "# "); | ||
250 | tempstrarray = tempstr.Split(' '); | ||
251 | string cmd=tempstrarray[0]; | ||
252 | Array.Reverse(tempstrarray); | ||
253 | Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1); | ||
254 | Array.Reverse(tempstrarray); | ||
255 | string[] cmdparams=(string[])tempstrarray; | ||
256 | RunCmd(cmd,cmdparams); | ||
257 | } | ||
258 | } | ||
259 | } | ||