Implemented crap webserver

ogs-cs
gareth 2007-03-08 18:44:15 +00:00
parent cfe3907cf4
commit 0f1c45c8e8
4 changed files with 107 additions and 2 deletions

View File

@ -52,6 +52,7 @@
<include name="../common/src/OGS-Console.cs" /> <include name="../common/src/OGS-Console.cs" />
<include name="src/ConsoleCmds.cs" /> <include name="src/ConsoleCmds.cs" />
<include name="src/UserProfiles.cs" /> <include name="src/UserProfiles.cs" />
<include name="src/GridHttp.cs" />
<include name="src/Main.cs" /> <include name="src/Main.cs" />
</sources> </sources>
</csc> </csc>

View File

@ -0,0 +1,91 @@
/*
Copyright (c) OpenGrid project, http://osgrid.org/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Text;
using System.Threading;
using System.Net;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using libsecondlife;
using ServerConsole;
namespace OpenGridServices
{
public class GridHTTPServer {
public Thread HTTPD;
public HttpListener Listener;
public GridHTTPServer() {
ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server");
HTTPD = new Thread(new ThreadStart(StartHTTP));
HTTPD.Start();
}
public void StartHTTP() {
ServerConsole.MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK");
Listener = new HttpListener();
Listener.Prefixes.Add("http://+:8080/gridserver/");
Listener.Start();
HttpListenerContext context;
while(true) {
context = Listener.GetContext();
new Thread( new ThreadStart( new HttpWorker(context).Startup ) ).Start();
}
}
}
public class HttpWorker {
public HttpListenerContext context;
public HttpWorker(HttpListenerContext context) {
this.context=context;
}
public string HandleRequest(HttpListenerRequest request) {
ServerConsole.MainConsole.Instance.WriteLine(request.Url.ToString());
return "";
}
public void Startup() {
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
string responseString=HandleRequest(request);
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
System.IO.Stream output = response.OutputStream;
output.Write(buffer,0,buffer.Length);
output.Close();
}
}
}

View File

@ -44,6 +44,8 @@ namespace OpenGridServices
public string DefaultStartupMsg; public string DefaultStartupMsg;
public string DefaultAssetServer; public string DefaultAssetServer;
public string DefaultUserServer; public string DefaultUserServer;
public GridHTTPServer _httpd;
public UserProfileManager _profilemanager; public UserProfileManager _profilemanager;
public UserProfile GridGod; public UserProfile GridGod;
public LLUUID HighestUUID; public LLUUID HighestUUID;
@ -100,6 +102,10 @@ namespace OpenGridServices
tempMD5Passwd = "$1$" + s.ToString(); tempMD5Passwd = "$1$" + s.ToString();
GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd); GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd);
_profilemanager.SetGod(GridGod.UUID);
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
_httpd = new GridHTTPServer();
} }
} }
} }

View File

@ -60,12 +60,17 @@ namespace OpenGridServices
return UserProfiles[ProfileLLUUID]; return UserProfiles[ProfileLLUUID];
} }
public void SetGod(LLUUID GodID) {
this.UserProfiles[GodID].IsGridGod=true;
}
public UserProfile CreateNewProfile(string firstname, string lastname, string MD5passwd) { public UserProfile CreateNewProfile(string firstname, string lastname, string MD5passwd) {
UserProfile newprofile = new UserProfile(); UserProfile newprofile = new UserProfile();
newprofile.firstname=firstname; newprofile.firstname=firstname;
newprofile.lastname=lastname; newprofile.lastname=lastname;
newprofile.MD5passwd=MD5passwd; newprofile.MD5passwd=MD5passwd;
UserProfiles.Add(OpenGrid_Main.thegrid.HighestUUID,newprofile); UserProfiles.Add(OpenGrid_Main.thegrid.HighestUUID,newprofile);
newprofile.UUID=OpenGrid_Main.thegrid.HighestUUID;
OpenGrid_Main.thegrid.HighestUUID=LLUUID.Random(); // FIXME: Increment, don't set random! OpenGrid_Main.thegrid.HighestUUID=LLUUID.Random(); // FIXME: Increment, don't set random!
return newprofile; return newprofile;
} }
@ -79,6 +84,8 @@ namespace OpenGridServices
public bool IsGridGod; public bool IsGridGod;
public string MD5passwd; public string MD5passwd;
public LLUUID UUID;
public UserProfile() { public UserProfile() {
} }