No, it doesn't work yet

Stripped out old PHP code
Imported Util.cs
Defined sim and user profiles
Implemented XML parser and start of login responder
Defined inventory types
Added setup for keys and misc data to user server and grid server
Added the user server
Fixed issue with threading in HTTP server
Moved both grid&user to seperate ports
Drank lots of red bull
Didn't sleep
ogs-cs
gareth 2007-03-10 08:30:29 +00:00
parent 0f1c45c8e8
commit 03db131a84
14 changed files with 742 additions and 436 deletions

87
common/src/Util.cs Normal file
View File

@ -0,0 +1,87 @@
/*
Copyright (c) OpenSim project, http://osgrid.org/
* Copyright (c) <year>, <copyright holder>
* 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.Collections.Generic;
using System.Threading;
using libsecondlife;
using libsecondlife.Packets;
namespace OpenGridServices
{
/// <summary>
/// </summary>
///
public class Util
{
public static ulong UIntsToLong(uint X, uint Y)
{
return Helpers.UIntsToLong(X,Y);
}
public Util()
{
}
}
public class QueItem {
public QueItem()
{
}
public Packet Packet;
public bool Incoming;
}
public class BlockingQueue< T > {
private Queue< T > _queue = new Queue< T >();
private object _queueSync = new object();
public void Enqueue(T value)
{
lock(_queueSync)
{
_queue.Enqueue(value);
Monitor.Pulse(_queueSync);
}
}
public T Dequeue()
{
lock(_queueSync)
{
if( _queue.Count < 1)
Monitor.Wait(_queueSync);
return _queue.Dequeue();
}
}
}
}

View File

@ -24,7 +24,7 @@
<target name="build" description="compiles the source code">
<loadfile file="../VERSION" property="svnver"/>
<asminfo output="AssemblyInfo.cs" language="CSharp">
<asminfo output="src/AssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
@ -50,10 +50,8 @@
<sources>
<include name="../common/src/VersionInfo.cs" />
<include name="../common/src/OGS-Console.cs" />
<include name="src/ConsoleCmds.cs" />
<include name="src/UserProfiles.cs" />
<include name="src/GridHttp.cs" />
<include name="src/Main.cs" />
<include name="../common/src/Util.cs" />
<include name="src/*.cs" />
</sources>
</csc>

View File

@ -1,14 +0,0 @@
<?
// All the grid server specific stuff lives here
// What we send to authenticate to the user/login server
$userserver_sendkey="1234";
// What we expect to get back from the user/login server
$userserver_recvkey="1234";
$sim_recvkey = "1234";
$sim_sendkey = "1234";
$grid_home = "/ogs/gridserver/";
?>

View File

@ -1,176 +0,0 @@
<?
error_reporting(E_ALL); // yes, we remember this from the login server, don't we boys and girls? don't kill innocent XML-RPC!
// these files are soooo common..... (to the grid)
include("../common/xmlrpc.inc.php");
include("../common/database.inc.php");
include("../common/grid_config.inc.php");
include("../common/util.inc.php");
include("gridserver_config.inc.php"); // grid server specific config stuff
function get_sim_info($args) {
global $dbhost,$dbuser,$dbpasswd,$dbname;
global $userserver_sendkey, $userserver_recvkey;
// First see who's talking to us, if key is invalid then send an invalid one back and nothing more
if($args['authkey']!=$userserver_recvkey) {
return Array(
'authkey' => 'I can play the bad key trick too you know',
'login' => 'false'
);
}
// if we get to here, the key is valid, give that login server what it wants!
$link = mysql_connect($dbhost,$dbuser,$dbpasswd)
OR die("Unable to connect to database");
mysql_select_db($dbname)
or die("Unable to select database");
$region_handle = $args['region_handle'];
$query = "SELECT * FROM region_profiles WHERE region_handle='$region_handle'";
$result = mysql_query($query);
return mysql_fetch_assoc($result);
}
function get_session_info($args) {
global $dbhost,$dbuser,$dbpasswd,$dbname;
global $sim_sendkey, $sim_recvkey;
// authkey, session-id, agent-id
// First see who's talking to us, if key is invalid then send an invalid one back and nothing more
if($args[0]!=$sim_recvkey) {
return Array(
'authkey' => "I can play the bad key trick too you know"
);
}
$link = mysql_connect($dbhost,$dbuser,$dbpasswd)
OR die("Unable to connect to database");
mysql_select_db($dbname)
or die("Unable to select database");
$session_id = $args[1];
$agent_id = $args[2];
$query = "SELECT * FROM sessions WHERE session_id = '$session_id' AND agent_id='$agent_id' AND session_active=1";
$result = mysql_query($query);
if(mysql_num_rows($result)>0) {
$info=mysql_fetch_assoc($result);
$circuit_code = $info['circuit_code'];
$secure_session_id=$info['secure_session_id'];
$query = "SELECT * FROM local_user_profiles WHERE userprofile_LLUUID='$agent_id'";
$result=mysql_query($query);
$userinfo=mysql_fetch_assoc($result);
$firstname=$userinfo['profile_firstname'];
$lastname=$userinfo['profile_lastname'];
$agent_id=$userinfo['userprofile_LLUUID'];
return Array(
'authkey' => $sim_sendkey,
'circuit_code' => $circuit_code,
'agent_id' => $agent_id,
'session_id' => $session_id,
'secure_session_id' => $secure_session_id,
'firstname' => $firstname,
'lastname' => $lastname
);
}
}
function check_loggedin($args) {
global $dbhost,$dbuser,$dbpasswd,$dbname;
global $userserver_sendkey, $userserver_recvkey;
// First see who's talking to us, if key is invalid then send an invalid one back and nothing more
if($args['authkey']!=$userserver_recvkey) {
return Array(
'authkey' => "I can play the bad key trick too you know"
);
}
// if we get to here, the key is valid, give that login server what it wants!
$link = mysql_connect($dbhost,$dbuser,$dbpasswd)
OR die("Unable to connect to database");
mysql_select_db($dbname)
or die("Unable to select database");
$userprofile_LLUUID = $args['userprofile_LLUUID'];
$query = "SELECT * FROM sessions WHERE agent_id='$userprofile_LLUUID' AND session_active=1";
$result = mysql_query($query);
if(mysql_num_rows($result)>1) {
return Array(
'authkey' => $userserver_sendkey,
'logged_in' => 1
);
} else {
return Array(
'authkey' => $userserver_sendkey,
'logged_in' => 0
);
}
}
function create_session($args) {
global $dbhost,$dbuser,$dbpasswd,$dbname;
global $userserver_sendkey, $userserver_recvkey;
// First see who's talking to us, if key is invalid then send an invalid one back and nothing more
if($args['authkey']!=$userserver_recvkey) {
return Array(
'authkey' => "I can play the bad key trick too you know"
);
}
// if we get to here, the key is valid, give that login server what it wants!
$link = mysql_connect($dbhost,$dbuser,$dbpasswd)
OR die("Unable to connect to database");
mysql_select_db($dbname)
or die("Unable to select database");
// yes, secure_sessionid should be different, i know...
$query = "SELECT value FROM Grid_settings WHERE setting='highest_LLUUID'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$highest_LLUUID = $row['value'];
$newsession_id=inc_lluuid($highest_LLUUID);
$secure_session_id=inc_lluuid($newsession_id);
$query="UPDATE Grid_settings SET value='$secure_session_id' WHERE setting='highest_LLUUID' LIMIT 1";
$result=mysql_query($query);
$userprofile_LLUUID=$args['userprofile_LLUUID'];
$current_location=$args['current_location'];
$remote_ip=$args['remote_ip'];
$query="INSERT INTO sessions(session_id,secure_session_id,agent_id,session_start,session_active,current_location,remote_ip) VALUES('$newsession_id','$secure_session_id','$userprofile_LLUUID',NOW(),1,'$current_location','$remote_ip')";
$result=mysql_query($query);
if(!isset($result)) {
die();
}
return Array(
'authkey' => $userserver_sendkey,
'session_id' => $newsession_id,
'secure_session_id' => $secure_session_id
);
}
$server=new IXR_Server(
Array(
'check_session_loggedin' => 'check_loggedin',
'create_session' => 'create_session',
'get_sim_info' => 'get_sim_info',
'get_session_info' => 'get_session_info'
)
);
?>

View File

@ -29,7 +29,9 @@ Copyright (c) OpenGrid project, http://osgrid.org/
using System;
using System.Text;
using Nwc.XmlRpc;
using System.Threading;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Collections;
@ -44,7 +46,7 @@ namespace OpenGridServices
public HttpListener Listener;
public GridHTTPServer() {
ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server");
ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server");
HTTPD = new Thread(new ThreadStart(StartHTTP));
HTTPD.Start();
}
@ -53,39 +55,77 @@ namespace OpenGridServices
ServerConsole.MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK");
Listener = new HttpListener();
Listener.Prefixes.Add("http://+:8080/gridserver/");
Listener.Prefixes.Add("http://+:8001/gridserver/");
Listener.Start();
HttpListenerContext context;
while(true) {
context = Listener.GetContext();
new Thread( new ThreadStart( new HttpWorker(context).Startup ) ).Start();
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
}
}
}
static string ParseXMLRPC(string requestBody) {
XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
Hashtable requestData = (Hashtable)request.Params[0];
switch(request.MethodName) {
case "get_simulator_info":
break;
}
public class HttpWorker {
public HttpListenerContext context;
public HttpWorker(HttpListenerContext context) {
this.context=context;
return "";
}
public string HandleRequest(HttpListenerRequest request) {
ServerConsole.MainConsole.Instance.WriteLine(request.Url.ToString());
static string ParseREST(string requestBody, string requestURL) {
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;
static void HandleRequest(Object stateinfo) {
HttpListenerContext context=(HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
response.KeepAlive=false;
response.SendChunked=false;
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = request.ContentEncoding;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
string requestBody = reader.ReadToEnd();
body.Close();
reader.Close();
string responseString="";
switch(request.ContentType) {
case "text/xml":
// must be XML-RPC, so pass to the XML-RPC parser
responseString=ParseXMLRPC(requestBody);
response.AddHeader("Content-type","text/xml");
break;
case null:
// must be REST or invalid crap, so pass to the REST parser
responseString=ParseREST(request.Url.OriginalString,requestBody);
break;
}
byte[] buffer = System.Text.Encoding.Unicode.GetBytes(responseString);
System.IO.Stream output = response.OutputStream;
response.SendChunked=false;
encoding = System.Text.Encoding.UTF8;
response.ContentEncoding = encoding;
response.ContentLength64=buffer.Length;
output.Write(buffer,0,buffer.Length);
output.Close();
output.Close();
}
}
}

View File

@ -43,12 +43,13 @@ namespace OpenGridServices
public string GridOwner;
public string DefaultStartupMsg;
public string DefaultAssetServer;
public string AssetSendKey;
public string AssetRecvKey;
public string DefaultUserServer;
public string UserSendKey;
public string UserRecvKey;
public GridHTTPServer _httpd;
public UserProfileManager _profilemanager;
public UserProfile GridGod;
public LLUUID HighestUUID;
[STAThread]
public static void Main( string[] args )
@ -70,40 +71,17 @@ namespace OpenGridServices
public void Startup() {
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings");
this.GridOwner=ServerConsole.MainConsole.Instance.CmdPrompt("Grid owner [OGS development team] :","OGS development team");
this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!");
this.DefaultAssetServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default asset server [no default] :");
this.DefaultUserServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default user server [no default] :");
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager");
_profilemanager = new UserProfileManager();
_profilemanager.InitUserProfiles();
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Setting up LLUUID management");
HighestUUID = LLUUID.Random();
string tempfirstname;
string templastname;
string tempMD5Passwd;
this.GridOwner=ServerConsole.MainConsole.Instance.CmdPrompt("Grid owner [OGS development team]: ","OGS development team");
this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!]: ","Welcome to OGS!");
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:");
tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: ");
templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: ");
tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: ");
this.DefaultAssetServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default asset server [no default]: ");
this.AssetSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to asset server: ");
this.AssetRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from asset server: ");
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
tempMD5Passwd = "$1$" + s.ToString();
GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd);
_profilemanager.SetGod(GridGod.UUID);
this.DefaultUserServer=ServerConsole.MainConsole.Instance.CmdPrompt("Default user server [no default]: ");
this.UserSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to user server: ");
this.UserRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from user server: ");
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
_httpd = new GridHTTPServer();
}

View File

@ -0,0 +1,109 @@
/*
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.Collections;
using System.Collections.Generic;
using libsecondlife;
using ServerConsole;
namespace OpenGridServices
{
/// <summary>
/// </summary>
public class SimProfileManager {
public Dictionary<LLUUID, SimProfile> SimProfiles = new Dictionary<LLUUID, SimProfile>();
public SimProfileManager() {
}
public void InitSimProfiles() {
// TODO: need to load from database
}
public SimProfile GetProfileByHandle(ulong reqhandle) {
foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) {
if(SimProfiles[UUID].regionhandle==reqhandle) return SimProfiles[UUID];
}
return null;
}
public SimProfile GetProfileByLLUUID(LLUUID ProfileLLUUID) {
return SimProfiles[ProfileLLUUID];
}
public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey) {
SimProfile TheSim=GetProfileByHandle(regionhandle);
if(TheSim != null)
if(TheSim.recvkey==simrecvkey) {
return true;
} else {
return false;
} else return false;
}
public SimProfile CreateNewProfile(string regionname, string caps_url, string sim_ip, uint sim_port, uint RegionLocX, uint RegionLocY, string sendkey, string recvkey) {
SimProfile newprofile = new SimProfile();
newprofile.regionname=regionname;
newprofile.sim_ip=sim_ip;
newprofile.sim_port=sim_port;
newprofile.RegionLocX=RegionLocX;
newprofile.RegionLocY=RegionLocY;
newprofile.sendkey=sendkey;
newprofile.recvkey=recvkey;
newprofile.regionhandle=Util.UIntsToLong((RegionLocX*256), (RegionLocY*256));
this.SimProfiles.Add(newprofile.UUID,newprofile);
return newprofile;
}
}
public class SimProfile {
public LLUUID UUID;
public ulong regionhandle;
public string regionname;
public string sim_ip;
public uint sim_port;
public string caps_url;
public uint RegionLocX;
public uint RegionLocY;
public string sendkey;
public string recvkey;
public SimProfile() {
}
}
}

View File

@ -1,170 +0,0 @@
<?
error_reporting(0); // Remember kids, PHP errors kill XML-RPC responses!
// include all the common stuff
include("../common/xmlrpc.inc.php");
include("../common/database.inc.php");
include("../common/grid_config.inc.php");
include("../common/util.inc.php");
include("login_config.inc.php"); // include login/user specific config stuff (authentication keys etc)
function login($args) {
global $dbhost,$dbuser,$dbpasswd,$dbname;
global $grid_owner, $gridserver_sendkey, $gridserver_recvkey, $gridserver_url;
if(get_magic_quotes_gpc()) {
$firstname=addslashes($args['first']);
$lastname=addslashes($args['last']);
$passwd=addslashes($args['passwd']);
} else {
$firstname=$args['first'];
$lastname=$args['last'];
$passwd=$args['passwd'];
}
$link = mysql_connect($dbhost,$dbuser,$dbpasswd)
OR die("Unable to connect to database");
mysql_select_db($dbname)
or die("Unable to select database");
$query = "SELECT userprofile_LLUUID, profile_firstname, profile_lastname, profile_passwdmd5, homesim_ip, homesim_port, homeasset_url, look_at, region_handle, position FROM local_user_profiles WHERE profile_firstname='".$firstname."' AND profile_lastname='".$lastname."' AND profile_passwdmd5='" .$passwd."'";
$profile_lookup_result=mysql_query($query);
if(mysql_num_rows($profile_lookup_result) >0) {
$profiledata = mysql_fetch_assoc($profile_lookup_result);
// if we get here, the username/password is valid, but still need to check there's not an already existing session
$client = new IXR_Client($gridserver_url);
if (!$client->query('check_session_loggedin', Array('userprofile_LLUUID' => $profiledata['userprofile_LLUUID'], 'authkey' => $gridserver_sendkey, 'server_type' => 'login'))) { // if this doesn't work, grid server is down - that's bad
return Array (
'reason' => 'key',
'message' => "Could not connect to grid server. Please try again later or contact the grid owner ". $grid_owner,
'login' => "false"
);
}
$response=$client->getResponse();
if($response['authkey'] != $gridserver_recvkey) { // if this doesn't match up, it's a fake grid server
return Array (
'reason' => 'key',
'message' => "Could not connect to grid server due to possible security issues. It is possible that the grid has been compromised. Please contact the grid owner " . $grid_owner . " and report this issue",
'login' => "false"
);
}
if($response['logged_in'] == 1) { // if the user is already logged in, tell them
return Array (
'reason' => 'presence',
'message' => "You appear to already be logged into this grid, if your client has recently crashed then please try again later",
'login' => "false"
);
}
// now we start a new session on the grid
$remote_ip=$_SERVER['REMOTE_ADDR'];
$region_handle=$profiledata['region_handle'];
$client->query('create_session',Array('userprofile_LLUUID' => $profiledata['userprofile_LLUUID'], 'authkey' => $gridserver_sendkey, 'remote_ip' => $remote_ip, 'current_location' => $region_handle));
$response = $client->getResponse();
$session_id = $response['session_id'];
$secure_session_id = $response['secure_session_id'];
// ask the grid server what the IP address and port of the sim we want to connect to is
$client->query('get_sim_info', Array('region_handle' => $region_handle, 'authkey' => $gridserver_sendkey) );
$siminfo = $client->getResponse();
// send the final response!
$position=$profiledata['position'];
$look_at=$profiledata['look_at'];
$LocX=intval($siminfo['GridLocX'])*256;
$LocY=intval($siminfo['GridLocY'])*256;
$home="{'region_handle':'$region_handle', 'position':'$position', 'look_at':'$look_at'}";
$globaltextures = new LLBlock(
Array(
'sun_texture_id' => "cce0f112-878f-4586-a2e2-a8f104bba271",
'cloud_texture_id' => "fc4b9f0b-d008-45c6-96a4-01dd947ac621",
'moon_texture_id' => "d07f6eed-b96a-47cd-b51d-400ad4a1c428"
));
$login_flags = new LLBlock(
Array(
'stipend_since_login' => "N",
'ever_logged_in' => "Y",
'gendered' => "Y",
'daylight_savings' => "N"
));
$ui_config = new LLBlock(
Array(
'allow_first_life' => "Y"
));
$inventory_skeleton = new LLBlock(Array(
Array(
'name' => 'My inventory',
'parent_id' => '00000000-0000-0000-0000-000000000000',
'version' => 4,
'type_default' => 8,
'folder_id' => 'f798e114-c10f-409b-a90d-a11577ff1de8'
),
Array(
'name' => 'Textures',
'parent_id' => 'f798e114-c10f-409b-a90d-a11577ff1de8',
'version' => 1,
'type_default' => 0,
'folder_id' => 'fc8b4059-30bb-43a8-a042-46f5b431ad82'
)));
$inventory_root = new LLBlock(
Array(
'folder_id' => "f798e114-c10f-409b-a90d-a11577ff1de8"
));
$initial_outfit = new LLBlock(
Array(
'folder_name' => "Nightclub Female",
'gender' => "female"
));
return Array (
'message' => "Welcome to OGS!",
'session_id' => format_lluuid($session_id),
'sim_port' => intval($siminfo['port']),
'agent_access' => "M",
'start_location' => "last",
'global-textures' => $globaltextures,
'seconds_since_epoch' => time(),
'first_name' => $profiledata['profile_firstname'],
'circuit_code' => 50633318,
'login_flags' => $login_flags,
'seed_capability' => '',
'home' => $home,
'secure_session_id' => format_lluuid($secure_session_id),
'last_name' => $profiledata['profile_lastname'],
'ui-config' => $ui_config,
'region_x' => $LocX,
'inventory_skeleton' => $inventory_skeleton,
'sim_ip' => $siminfo['ip_addr'],
'region_y' => $LocY,
'inventory-root' => $inventory_root,
'login' => "true",
'look_at' => $look_at,
'agent_id' => format_lluuid($profiledata['userprofile_LLUUID']),
'initial-outfit' => $initial_outfit
);
} else {
// this is the default invalid username/password error
return Array (
'reason' => 'key',
'message' => "You have entered an invalid name/password combination or are using an incompatible client. Please check with the grid owner " .$grid_owner . " if you are sure your login details are accurate.",
'login' => "false",
);
}
}
$server=new IXR_Server(array('login_to_simulator' => 'login'));
?>

View File

@ -1,11 +0,0 @@
<?
// All the user/login server specific stuff lives here
// What we send to authenticate to the grid server
$gridserver_sendkey="1234";
// What we expect to get back from the grid server
$gridserver_recvkey="1234";
$gridserver_url="http://www.osgrid.org/ogs/gridserver/index.php";
?>

63
userserver/default.build Normal file
View File

@ -0,0 +1,63 @@
<?xml version="1.0"?>
<project name="UserServer" default="build" basedir="./">
<property name="debug" value="true" overwrite="false" />
<target name="clean" description="remove all generated files">
<delete>
<fileset failonempty="false">
<include name="bin/*.dll" />
<include name="bin/*.exe" />
<include name="bin/*.mdb" />
</fileset>
</delete>
</target>
<target name="svnupdate" description="updates to latest SVN">
<exec program="svn">
<arg value="update" />
</exec>
</target>
<target name="upgrade" description="updates from SVN and then builds" depends="clean,svnupdate,build">
</target>
<target name="build" description="compiles the source code">
<loadfile file="../VERSION" property="svnver"/>
<asminfo output="src/AssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
<import namespace="System.Runtime.InteropServices" />
</imports>
<attributes>
<attribute type="ComVisibleAttribute" value="false" />
<attribute type="CLSCompliantAttribute" value="false" />
<attribute type="AssemblyVersionAttribute" value="${svnver}" />
<attribute type="AssemblyTitleAttribute" value="ogs-UserServer" />
<attribute type="AssemblyDescriptionAttribute" value="The core OGS User Server" />
<attribute type="AssemblyCopyrightAttribute" value="Copyright © OGS development team 2007"/>
</attributes>
</asminfo>
<csc target="exe" output="bin/UserServer.exe" debug="${debug}" verbose="true" warninglevel="4">
<references failonempty="true">
<include name="System" />
<include name="System.Xml" />
<include name="../common/bin/ServerConsole.dll" />
<include name="../common/bin/libsecondlife.dll" />
</references>
<sources>
<include name="../common/src/VersionInfo.cs" />
<include name="../common/src/OGS-Console.cs" />
<include name="src/*.cs" />
</sources>
</csc>
<copy todir="bin/">
<fileset basedir="../common/bin">
<include name="*.*" />
</fileset>
</copy>
</target>
</project>

View File

@ -0,0 +1,57 @@
/*
Copyright (c) OpenSim 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 ServerConsole;
namespace OpenGridServices
{
public class UserConsole : conscmd_callback {
public UserConsole() { }
public override void RunCmd(string cmd, string[] cmdparams) {
switch(cmd) {
case "help":
ServerConsole.MainConsole.Instance.WriteLine("shutdown - shutdown the user server (USE CAUTION!)"
);
break;
case "shutdown":
ServerConsole.MainConsole.Instance.Close();
Environment.Exit(0);
break;
}
}
public override void Show(string ShowWhat) {
}
}
}

112
userserver/src/Main.cs Normal file
View File

@ -0,0 +1,112 @@
/*
Copyright (c) OpenSim 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.Collections;
using System.Collections.Generic;
using System.Text;
using libsecondlife;
using ServerConsole;
namespace OpenGridServices
{
/// <summary>
/// </summary>
public class OpenUser_Main
{
public static OpenUser_Main userserver;
public UserHTTPServer _httpd;
public UserProfileManager _profilemanager;
public UserProfile GridGod;
public string DefaultStartupMsg;
public string GridURL;
public string GridSendKey;
public string GridRecvKey;
public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
[STAThread]
public static void Main( string[] args )
{
Console.WriteLine("OpenUser " + VersionInfo.Version + "\n");
Console.WriteLine("Starting...\n");
ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local, "", 0, "opengrid-console.log", "OpenUser", new UserConsole());
userserver = new OpenUser_Main();
userserver.Startup();
ServerConsole.MainConsole.Instance.WriteLine("\nEnter help for a list of commands\n");
while(true) {
ServerConsole.MainConsole.Instance.MainConsolePrompt();
}
}
public void Startup() {
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings");
this.GridURL=ServerConsole.MainConsole.Instance.CmdPrompt("Grid URL: ");
this.GridSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to grid: ");
this.GridRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from grid: ");
this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!");
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager");
_profilemanager = new UserProfileManager();
_profilemanager.InitUserProfiles();
string tempfirstname;
string templastname;
string tempMD5Passwd;
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:");
tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: ");
templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: ");
tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: ");
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
tempMD5Passwd = "$1$" + s.ToString();
GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd);
_profilemanager.SetGod(GridGod.UUID);
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
_httpd = new UserHTTPServer();
}
}
}

181
userserver/src/UserHttp.cs Normal file
View File

@ -0,0 +1,181 @@
/*
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 Nwc.XmlRpc;
using System.Threading;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using libsecondlife;
using ServerConsole;
namespace OpenGridServices
{
public class UserHTTPServer {
public Thread HTTPD;
public HttpListener Listener;
public UserHTTPServer() {
ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server");
HTTPD = new Thread(new ThreadStart(StartHTTP));
HTTPD.Start();
}
public void StartHTTP() {
ServerConsole.MainConsole.Instance.WriteLine("UserHttp.cs:StartHTTP() - Spawned main thread OK");
Listener = new HttpListener();
Listener.Prefixes.Add("http://+:8002/userserver/");
Listener.Start();
HttpListenerContext context;
while(true) {
context = Listener.GetContext();
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
}
}
static string ParseXMLRPC(string requestBody) {
XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
Hashtable requestData = (Hashtable)request.Params[0];
switch(request.MethodName) {
case "login_to_simulator":
bool GoodXML= (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
bool GoodLogin=false;
string firstname="";
string lastname="";
string passwd="";
if(GoodXML) {
firstname=(string)requestData["first"];
lastname=(string)requestData["last"];
passwd=(string)requestData["passwd"];
GoodLogin=OpenUser_Main.userserver._profilemanager.AuthenticateUser(firstname,lastname,passwd);
}
if(!(GoodXML && GoodLogin)) {
XmlRpcResponse LoginErrorResp = new XmlRpcResponse();
Hashtable ErrorRespData = new Hashtable();
ErrorRespData["reason"]="key";
ErrorRespData["message"]="Error connecting to grid. Please double check your login details and check with the grid owner if you are sure these are correct";
ErrorRespData["login"]="false";
LoginErrorResp.Value=ErrorRespData;
return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(LoginErrorResp)," encoding=\"utf-16\"","" ));
}
UserProfile TheUser=OpenUser_Main.userserver._profilemanager.GetProfileByName(firstname,lastname);
if(!((TheUser.CurrentSessionID==null) && (TheUser.CurrentSecureSessionID==null))) {
XmlRpcResponse PresenceErrorResp = new XmlRpcResponse();
Hashtable PresenceErrorRespData = new Hashtable();
PresenceErrorRespData["reason"]="presence";
PresenceErrorRespData["message"]="You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner";
PresenceErrorRespData["login"]="false";
PresenceErrorResp.Value=PresenceErrorRespData;
return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp)," encoding=\"utf-16\"","" ));
}
LLUUID AgentID = TheUser.UUID;
TheUser.InitSessionData();
XmlRpcResponse LoginGoodResp = new XmlRpcResponse();
Hashtable LoginGoodData = new Hashtable();
LoginGoodData["message"]=OpenUser_Main.userserver.DefaultStartupMsg;
LoginGoodData["session_id"]=TheUser.CurrentSessionID;
LoginGoodData["secure_sessionid"]=TheUser.CurrentSecureSessionID;
LoginGoodResp.Value=LoginGoodData;
return(XmlRpcResponseSerializer.Singleton.Serialize(LoginGoodResp));
break;
}
return "";
}
static string ParseREST(string requestBody, string requestURL) {
return "";
}
static void HandleRequest(Object stateinfo) {
HttpListenerContext context=(HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
response.KeepAlive=false;
response.SendChunked=false;
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = request.ContentEncoding;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
string requestBody = reader.ReadToEnd();
body.Close();
reader.Close();
string responseString="";
switch(request.ContentType) {
case "text/xml":
// must be XML-RPC, so pass to the XML-RPC parser
responseString=ParseXMLRPC(requestBody);
response.AddHeader("Content-type","text/xml");
break;
case null:
// must be REST or invalid crap, so pass to the REST parser
responseString=ParseREST(request.Url.OriginalString,requestBody);
break;
}
byte[] buffer = System.Text.Encoding.Unicode.GetBytes(responseString);
System.IO.Stream output = response.OutputStream;
response.SendChunked=false;
encoding = System.Text.Encoding.UTF8;
response.ContentEncoding = encoding;
response.ContentLength64=buffer.Length;
output.Write(buffer,0,buffer.Length);
output.Close();
}
}
}

View File

@ -40,7 +40,7 @@ namespace OpenGridServices
/// </summary>
public class UserProfileManager {
private Dictionary<LLUUID, UserProfile> UserProfiles = new Dictionary<LLUUID, UserProfile>();
public Dictionary<LLUUID, UserProfile> UserProfiles = new Dictionary<LLUUID, UserProfile>();
public UserProfileManager() {
}
@ -60,6 +60,17 @@ namespace OpenGridServices
return UserProfiles[ProfileLLUUID];
}
public bool AuthenticateUser(string firstname, string lastname, string passwd) {
UserProfile TheUser=GetProfileByName(firstname, lastname);
if(TheUser != null)
if(TheUser.MD5passwd==passwd) {
return true;
} else {
return false;
} else return false;
}
public void SetGod(LLUUID GodID) {
this.UserProfiles[GodID].IsGridGod=true;
}
@ -69,9 +80,8 @@ namespace OpenGridServices
newprofile.firstname=firstname;
newprofile.lastname=lastname;
newprofile.MD5passwd=MD5passwd;
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!
newprofile.UUID=LLUUID.Random();
this.UserProfiles.Add(newprofile.UUID,newprofile);
return newprofile;
}
@ -81,13 +91,55 @@ namespace OpenGridServices
public string firstname;
public string lastname;
public bool IsGridGod;
public uint homeregionhandle;
public LLVector3 homepos;
public LLVector3 homelookat;
public bool IsGridGod=false;
public bool IsLocal=true; // will be used in future for visitors from foreign grids
public string AssetURL;
public string MD5passwd;
public LLUUID CurrentSessionID;
public LLUUID CurrentSecureSessionID;
public LLUUID UUID;
public Dictionary<LLUUID, uint> Circuits = new Dictionary<LLUUID, uint>(); // tracks circuit codes
public Dictionary<LLUUID, InventoryFolder> InventoryFolders;
public Dictionary<LLUUID, InventoryItem> InventoryItems;
public UserProfile() {
Circuits = new Dictionary<LLUUID, uint>();
InventoryFolders = new Dictionary<LLUUID, InventoryFolder>();
InventoryItems = new Dictionary<LLUUID, InventoryItem>();
}
public void InitSessionData() {
CurrentSessionID=LLUUID.Random();
CurrentSecureSessionID=LLUUID.Random();
}
public void AddSimCircuit(uint circuit_code, LLUUID region_UUID) {
if(!this.Circuits.ContainsKey(region_UUID)) this.Circuits.Add(region_UUID, circuit_code);
}
}
public class InventoryFolder {
public LLUUID FolderID;
public LLUUID ParentID;
public string FolderName;
public ushort DefaultType;
public ushort Version;
}
public class InventoryItem { //TODO: Fixup this and add full permissions etc
public LLUUID FolderID;
public LLUUID OwnerID;
public LLUUID ItemID;
public LLUUID AssetID;
public LLUUID CreatorID = LLUUID.Zero;
public sbyte InvType;
public sbyte Type;
public string Name;
public string Description;
}
}