2007-04-02 15:48:01 +00:00
using System ;
using System.Collections.Generic ;
using System.Text ;
2007-04-11 09:29:06 +00:00
using System.Net ;
using System.Web ;
using System.IO ;
2007-04-02 15:48:01 +00:00
using OpenSim.Framework.Interfaces ;
using OpenSim.Framework.Utilities ;
2007-04-04 18:57:13 +00:00
using libsecondlife ;
2007-04-02 15:48:01 +00:00
namespace OpenSim
{
public class RegionInfo // could inherit from SimProfileBase
{
2007-04-04 19:55:31 +00:00
public LLUUID SimUUID ;
2007-04-02 15:48:01 +00:00
public string RegionName ;
public uint RegionLocX ;
public uint RegionLocY ;
public ulong RegionHandle ;
2007-04-25 18:12:06 +00:00
public ushort RegionWaterHeight = 20 ;
public bool RegionTerraform = true ;
2007-04-02 15:48:01 +00:00
public int IPListenPort ;
public string IPListenAddr ;
//following should be removed and the GenericConfig object passed around,
//so each class (AssetServer, GridServer etc) can access what config data they want
public string AssetURL = "" ;
public string AssetSendKey = "" ;
public string GridURL = "" ;
public string GridSendKey = "" ;
public string GridRecvKey = "" ;
public string UserURL = "" ;
public string UserSendKey = "" ;
public string UserRecvKey = "" ;
private bool isSandbox ;
2007-04-27 21:11:02 +00:00
public string DataStore ;
2007-04-02 15:48:01 +00:00
public RegionInfo ( )
{
2007-04-11 09:29:06 +00:00
}
public void SaveToGrid ( )
{
//we really want to keep any server connection code out of here and out of the code code
// and put it in the server connection classes (those inheriting from IGridServer etc)
string reqtext ;
2007-04-20 13:44:17 +00:00
reqtext = "<Root>" ;
2007-04-13 15:14:21 +00:00
reqtext + = "<authkey>" + this . GridSendKey + "</authkey>" ;
2007-04-11 09:29:06 +00:00
reqtext + = "<sim>" ;
reqtext + = "<uuid>" + this . SimUUID . ToString ( ) + "</uuid>" ;
reqtext + = "<regionname>" + this . RegionName + "</regionname>" ;
reqtext + = "<sim_ip>" + this . IPListenAddr + "</sim_ip>" ;
reqtext + = "<sim_port>" + this . IPListenPort . ToString ( ) + "</sim_port>" ;
reqtext + = "<region_locx>" + this . RegionLocX . ToString ( ) + "</region_locx>" ;
reqtext + = "<region_locy>" + this . RegionLocY . ToString ( ) + "</region_locy>" ;
reqtext + = "<estate_id>1</estate_id>" ;
reqtext + = "</sim>" ;
2007-04-20 13:44:17 +00:00
reqtext + = "</Root>" ;
2007-04-17 12:03:52 +00:00
2007-04-20 13:44:17 +00:00
byte [ ] reqdata = ( new System . Text . ASCIIEncoding ( ) ) . GetBytes ( reqtext ) ;
string newpath = "" ;
if ( this . GridURL . EndsWith ( "/" ) )
{
newpath = this . GridURL + "sims/" ;
}
else
{
newpath = this . GridURL + "/sims/" ;
}
2007-04-11 09:29:06 +00:00
2007-04-20 13:44:17 +00:00
WebRequest GridSaveReq = WebRequest . Create ( newpath + this . SimUUID . ToString ( ) ) ;
2007-04-11 09:29:06 +00:00
GridSaveReq . Method = "POST" ;
2007-04-12 18:34:17 +00:00
GridSaveReq . ContentType = "application/x-www-form-urlencoded" ;
GridSaveReq . ContentLength = reqdata . Length ;
2007-04-11 09:29:06 +00:00
2007-04-12 18:34:17 +00:00
Stream stOut = GridSaveReq . GetRequestStream ( ) ;
2007-04-20 13:44:17 +00:00
stOut . Write ( reqdata , 0 , reqdata . Length ) ;
2007-04-11 09:29:06 +00:00
stOut . Close ( ) ;
2007-04-17 12:03:52 +00:00
WebResponse gridresp = GridSaveReq . GetResponse ( ) ;
2007-04-20 13:44:17 +00:00
StreamReader stIn = new StreamReader ( gridresp . GetResponseStream ( ) , Encoding . ASCII ) ;
2007-04-11 09:29:06 +00:00
string GridResponse = stIn . ReadToEnd ( ) ;
stIn . Close ( ) ;
2007-04-20 13:44:17 +00:00
gridresp . Close ( ) ;
2007-04-11 09:29:06 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "RegionInfo.CS:SaveToGrid() - Grid said: " + GridResponse ) ;
}
2007-04-02 15:48:01 +00:00
public void InitConfig ( bool sandboxMode , IGenericConfig configData )
{
this . isSandbox = sandboxMode ;
try
{
2007-04-04 19:55:31 +00:00
// Sim UUID
string attri = "" ;
attri = configData . GetAttribute ( "SimUUID" ) ;
if ( attri = = "" )
{
this . SimUUID = LLUUID . Random ( ) ;
configData . SetAttribute ( "SimUUID" , this . SimUUID . ToString ( ) ) ;
}
else
{
this . SimUUID = new LLUUID ( attri ) ;
}
2007-04-04 18:57:13 +00:00
2007-04-02 15:48:01 +00:00
// Sim name
2007-04-04 19:55:31 +00:00
attri = "" ;
2007-04-02 15:48:01 +00:00
attri = configData . GetAttribute ( "SimName" ) ;
if ( attri = = "" )
{
2007-04-11 20:07:58 +00:00
this . RegionName = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "Name" , "OpenSim test" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "SimName" , this . RegionName ) ;
}
else
{
this . RegionName = attri ;
}
// Sim/Grid location X
attri = "" ;
attri = configData . GetAttribute ( "SimLocationX" ) ;
if ( attri = = "" )
{
2007-04-11 20:07:58 +00:00
string location = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "Grid Location X" , "997" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "SimLocationX" , location ) ;
2007-04-03 13:37:11 +00:00
this . RegionLocX = ( uint ) Convert . ToUInt32 ( location ) ;
2007-04-02 15:48:01 +00:00
}
else
{
2007-04-03 13:37:11 +00:00
this . RegionLocX = ( uint ) Convert . ToUInt32 ( attri ) ;
2007-04-02 15:48:01 +00:00
}
// Sim/Grid location Y
attri = "" ;
attri = configData . GetAttribute ( "SimLocationY" ) ;
if ( attri = = "" )
{
2007-04-11 20:07:58 +00:00
string location = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "Grid Location Y" , "996" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "SimLocationY" , location ) ;
2007-04-03 13:37:11 +00:00
this . RegionLocY = ( uint ) Convert . ToUInt32 ( location ) ;
2007-04-02 15:48:01 +00:00
}
else
{
2007-04-03 13:37:11 +00:00
this . RegionLocY = ( uint ) Convert . ToUInt32 ( attri ) ;
2007-04-02 15:48:01 +00:00
}
2007-04-27 21:11:02 +00:00
// Local storage datastore
attri = "" ;
attri = configData . GetAttribute ( "Datastore" ) ;
if ( attri = = "" )
{
string datastore = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "Filename for local storage" , "localworld.yap" ) ;
configData . SetAttribute ( "Datastore" , datastore ) ;
this . DataStore = datastore ;
}
2007-04-02 15:48:01 +00:00
//Sim Listen Port
attri = "" ;
attri = configData . GetAttribute ( "SimListenPort" ) ;
if ( attri = = "" )
{
2007-04-11 20:07:58 +00:00
string port = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "UDP port for client connections" , "9000" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "SimListenPort" , port ) ;
this . IPListenPort = Convert . ToInt32 ( port ) ;
}
else
{
this . IPListenPort = Convert . ToInt32 ( attri ) ;
}
//Sim Listen Address
attri = "" ;
attri = configData . GetAttribute ( "SimListenAddress" ) ;
if ( attri = = "" )
{
2007-04-11 20:07:58 +00:00
this . IPListenAddr = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "IP Address to listen on for client connections" , "127.0.0.1" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "SimListenAddress" , this . IPListenAddr ) ;
}
else
{
2007-04-04 19:55:31 +00:00
this . IPListenAddr = attri ;
2007-04-02 15:48:01 +00:00
}
if ( ! isSandbox )
{
//shouldn't be reading this data in here, it should be up to the classes implementing the server interfaces to read what they need from the config object
2007-04-11 08:51:39 +00:00
//Grid Server URL
2007-04-02 15:48:01 +00:00
attri = "" ;
attri = configData . GetAttribute ( "GridServerURL" ) ;
if ( attri = = "" )
{
2007-04-21 05:09:06 +00:00
this . GridURL = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "Grid server URL" , "http://127.0.0.1:8001/" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "GridServerURL" , this . GridURL ) ;
}
else
{
this . GridURL = attri ;
}
2007-04-11 09:29:06 +00:00
2007-04-02 15:48:01 +00:00
//Grid Send Key
attri = "" ;
attri = configData . GetAttribute ( "GridSendKey" ) ;
if ( attri = = "" )
{
2007-04-21 05:09:06 +00:00
this . GridSendKey = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "Key to send to grid server" , "null" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "GridSendKey" , this . GridSendKey ) ;
}
else
{
this . GridSendKey = attri ;
}
2007-04-11 09:29:06 +00:00
2007-04-02 15:48:01 +00:00
//Grid Receive Key
attri = "" ;
attri = configData . GetAttribute ( "GridRecvKey" ) ;
if ( attri = = "" )
{
2007-04-21 05:09:06 +00:00
this . GridRecvKey = OpenSim . Framework . Console . MainConsole . Instance . CmdPrompt ( "Key to expect from grid server" , "null" ) ;
2007-04-02 15:48:01 +00:00
configData . SetAttribute ( "GridRecvKey" , this . GridRecvKey ) ;
}
else
{
this . GridRecvKey = attri ;
2007-04-11 09:29:06 +00:00
}
2007-04-11 08:51:39 +00:00
2007-04-02 15:48:01 +00:00
}
this . RegionHandle = Util . UIntsToLong ( ( RegionLocX * 256 ) , ( RegionLocY * 256 ) ) ;
2007-04-11 09:29:06 +00:00
if ( ! this . isSandbox )
{
this . SaveToGrid ( ) ;
}
2007-04-02 15:48:01 +00:00
configData . Commit ( ) ;
}
catch ( Exception e )
{
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Config.cs:InitConfig() - Exception occured" ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( e . ToString ( ) ) ;
}
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Sim settings loaded:" ) ;
2007-04-04 18:57:13 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "UUID: " + this . SimUUID . ToStringHyphenated ( ) ) ;
2007-04-04 19:55:31 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Name: " + this . RegionName ) ;
2007-04-02 15:48:01 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Region Location: [" + this . RegionLocX . ToString ( ) + "," + this . RegionLocY + "]" ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Region Handle: " + this . RegionHandle . ToString ( ) ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Listening on IP: " + this . IPListenAddr + ":" + this . IPListenPort ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Sandbox Mode? " + isSandbox . ToString ( ) ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Asset URL: " + this . AssetURL ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Asset key: " + this . AssetSendKey ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Grid URL: " + this . GridURL ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "Grid key: " + this . GridSendKey ) ;
}
}
}