2007-02-01 00:15:47 +00:00
/ *
2007-02-03 19:51:52 +00:00
Copyright ( c ) OpenSim project , http : //sim.opensecondlife.org/
2007-02-01 00:15:47 +00:00
* 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.Timers ;
using System.Collections.Generic ;
using libsecondlife ;
using libsecondlife.Packets ;
using System.Collections ;
using System.Text ;
using System.IO ;
using Axiom.MathLib ;
using log4net ;
2007-02-02 17:23:56 +00:00
namespace OpenSim
{
2007-02-01 00:15:47 +00:00
/// <summary>
/// Description of MainForm.
/// </summary>
2007-02-04 11:36:35 +00:00
public partial class Controller : ServerCallback
{
2007-02-01 00:15:47 +00:00
[STAThread]
2007-02-04 11:36:35 +00:00
public static void Main ( string [ ] args )
{
2007-02-01 00:15:47 +00:00
Controller c = new Controller ( ) ;
while ( true ) // fuckin' a
2007-02-04 11:36:35 +00:00
System . Threading . Thread . Sleep ( 1000 ) ;
2007-02-01 00:15:47 +00:00
}
2007-02-04 11:36:35 +00:00
private Server _server ;
private Logon _login ;
private AgentManager _agentManager ;
private PrimManager _primManager ;
private AssetManagement _assetManager ;
private GridManager _gridManager ;
private InventoryManager _inventoryManager ;
private LoginManager _loginManager ; //built in login server
2007-02-01 00:15:47 +00:00
private ulong time ; //ticks
private Timer timer1 = new Timer ( ) ;
2007-02-09 20:01:07 +00:00
private System . Text . Encoding _enc = System . Text . Encoding . ASCII ;
2007-02-01 00:15:47 +00:00
public Controller ( ) {
2007-02-04 11:36:35 +00:00
_login = new Logon ( ) ; // should create a list for these.
_server = new Server ( this ) ;
_agentManager = new AgentManager ( this . _server ) ;
_primManager = new PrimManager ( this . _server ) ;
_inventoryManager = new InventoryManager ( this . _server ) ;
_assetManager = new AssetManagement ( this . _server , _inventoryManager ) ;
_primManager . AgentManagement = _agentManager ;
_agentManager . Prim_Manager = _primManager ;
_agentManager . assetManager = _assetManager ;
_gridManager = new GridManager ( this . _server , _agentManager ) ;
2007-02-03 21:09:54 +00:00
2007-02-02 17:23:56 +00:00
if ( Globals . Instance . LoginSever )
{
Console . WriteLine ( "Starting login Server" ) ;
2007-02-04 11:36:35 +00:00
_loginManager = new LoginManager ( _login ) ; // startup
_loginManager . Startup ( ) ; // login server
2007-02-02 17:23:56 +00:00
}
2007-02-03 21:09:54 +00:00
2007-02-02 17:23:56 +00:00
timer1 . Enabled = true ;
2007-02-01 00:15:47 +00:00
timer1 . Interval = 200 ;
timer1 . Elapsed + = new ElapsedEventHandler ( this . Timer1Tick ) ;
}
2007-02-04 11:36:35 +00:00
public void MainCallback ( Packet pack , UserAgentInfo userInfo )
{
2007-02-03 19:51:52 +00:00
/ * if ( ( pack . Type ! = PacketType . StartPingCheck ) & & ( pack . Type ! = PacketType . AgentUpdate ) ) {
//Log packet?
2007-02-04 11:36:35 +00:00
//System.Console.WriteLine(pack.Type);
//this.richTextBox1.Text = this.richTextBox1.Text + "\n " + pack.Type;
2007-02-03 19:51:52 +00:00
} * /
//should replace with a switch
2007-02-01 00:15:47 +00:00
if ( pack . Type = = PacketType . AgentSetAppearance ) {
2007-02-04 11:36:35 +00:00
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . AgentAnimation )
{
AgentAnimationPacket AgentAni = ( AgentAnimationPacket ) pack ;
2007-02-13 20:27:14 +00:00
for ( int i = 0 ; i < AgentAni . AnimationList . Length ; i + + )
2007-02-12 01:38:21 +00:00
{
2007-02-13 20:27:14 +00:00
if ( AgentAni . AnimationList [ i ] . StartAnim )
{
_agentManager . UpdateAnim ( userInfo , AgentAni . AnimationList [ 0 ] . AnimID , 1 ) ;
}
2007-02-12 01:38:21 +00:00
}
2007-02-13 20:27:14 +00:00
2007-02-12 01:38:21 +00:00
}
else if ( pack . Type = = PacketType . FetchInventory )
{
FetchInventoryPacket FetchInventory = ( FetchInventoryPacket ) pack ;
_inventoryManager . FetchInventory ( userInfo , FetchInventory ) ;
}
else if ( pack . Type = = PacketType . FetchInventoryDescendents )
{
FetchInventoryDescendentsPacket Fetch = ( FetchInventoryDescendentsPacket ) pack ;
_inventoryManager . FetchInventoryDescendents ( userInfo , Fetch ) ;
}
else if ( pack . Type = = PacketType . MapBlockRequest )
{
MapBlockRequestPacket MapRequest = ( MapBlockRequestPacket ) pack ;
this . _gridManager . RequestMapBlock ( userInfo , MapRequest . PositionData . MinX , MapRequest . PositionData . MinY , MapRequest . PositionData . MaxX , MapRequest . PositionData . MaxY ) ;
}
else if ( pack . Type = = PacketType . UUIDNameRequest )
{
UUIDNameRequestPacket nameRequest = ( UUIDNameRequestPacket ) pack ;
UUIDNameReplyPacket nameReply = new UUIDNameReplyPacket ( ) ;
nameReply . UUIDNameBlock = new UUIDNameReplyPacket . UUIDNameBlockBlock [ nameRequest . UUIDNameBlock . Length ] ;
for ( int i = 0 ; i < nameRequest . UUIDNameBlock . Length ; i + + )
{
nameReply . UUIDNameBlock [ i ] = new UUIDNameReplyPacket . UUIDNameBlockBlock ( ) ;
nameReply . UUIDNameBlock [ i ] . ID = nameRequest . UUIDNameBlock [ i ] . ID ;
nameReply . UUIDNameBlock [ i ] . FirstName = _enc . GetBytes ( "harry \0" ) ; //for now send any name
nameReply . UUIDNameBlock [ i ] . LastName = _enc . GetBytes ( "tom \0" ) ; //in future need to look it up
}
_server . SendPacket ( nameReply , true , userInfo ) ;
}
else if ( pack . Type = = PacketType . CloseCircuit )
{
this . _agentManager . RemoveAgent ( userInfo ) ;
}
else if ( pack . Type = = PacketType . MapLayerRequest )
{
this . _gridManager . RequestMapLayer ( userInfo ) ;
}
else if ( ( pack . Type = = PacketType . TeleportRequest ) | | ( pack . Type = = PacketType . TeleportLocationRequest ) )
{
TeleportLocationRequestPacket Request = ( TeleportLocationRequestPacket ) pack ;
this . _gridManager . RequestTeleport ( userInfo , Request ) ;
}
else if ( pack . Type = = PacketType . TransferRequest )
{
2007-02-04 11:36:35 +00:00
TransferRequestPacket transfer = ( TransferRequestPacket ) pack ;
2007-02-12 01:38:21 +00:00
LLUUID id = new LLUUID ( transfer . TransferInfo . Params , 0 ) ;
_assetManager . AddAssetRequest ( userInfo , id , transfer ) ;
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else if ( ( pack . Type = = PacketType . StartPingCheck ) )
{
2007-02-01 00:15:47 +00:00
//reply to pingcheck
2007-02-04 11:36:35 +00:00
libsecondlife . Packets . StartPingCheckPacket startping = ( libsecondlife . Packets . StartPingCheckPacket ) pack ;
2007-02-01 00:15:47 +00:00
libsecondlife . Packets . CompletePingCheckPacket endping = new CompletePingCheckPacket ( ) ;
2007-02-04 11:36:35 +00:00
endping . PingID . PingID = startping . PingID . PingID ;
2007-02-12 01:38:21 +00:00
_server . SendPacket ( endping , true , userInfo ) ;
}
else if ( pack . Type = = PacketType . CompleteAgentMovement )
{
_agentManager . AgentJoin ( userInfo ) ;
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . RequestImage )
{
2007-02-04 11:36:35 +00:00
RequestImagePacket imageRequest = ( RequestImagePacket ) pack ;
2007-02-12 01:38:21 +00:00
for ( int i = 0 ; i < imageRequest . RequestImage . Length ; i + + )
2007-02-03 21:09:54 +00:00
{
2007-02-04 11:36:35 +00:00
this . _assetManager . AddTextureRequest ( userInfo , imageRequest . RequestImage [ i ] . Image ) ;
2007-02-01 00:15:47 +00:00
}
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . RegionHandshakeReply )
{
2007-02-01 00:15:47 +00:00
//recieved regionhandshake so can now start sending info
2007-02-12 01:38:21 +00:00
_agentManager . SendInitialData ( userInfo ) ;
}
else if ( pack . Type = = PacketType . ObjectAdd )
{
2007-02-01 00:15:47 +00:00
ObjectAddPacket ad = ( ObjectAddPacket ) pack ;
2007-02-12 01:38:21 +00:00
_primManager . CreatePrim ( userInfo , ad . ObjectData . RayEnd , ad ) ;
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . ObjectPosition )
{
2007-02-01 00:15:47 +00:00
//System.Console.WriteLine(pack.ToString());
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . MultipleObjectUpdate )
2007-02-04 11:36:35 +00:00
{
MultipleObjectUpdatePacket multipleupdate = ( MultipleObjectUpdatePacket ) pack ;
2007-02-01 00:15:47 +00:00
2007-02-12 01:38:21 +00:00
for ( int i = 0 ; i < multipleupdate . ObjectData . Length ; i + + )
2007-02-03 21:09:54 +00:00
{
2007-02-12 01:38:21 +00:00
if ( multipleupdate . ObjectData [ i ] . Type = = 9 ) //change position
{
libsecondlife . LLVector3 pos = new LLVector3 ( multipleupdate . ObjectData [ i ] . Data , 0 ) ;
_primManager . UpdatePrimPosition ( userInfo , pos , multipleupdate . ObjectData [ i ] . ObjectLocalID , false , libsecondlife . LLQuaternion . Identity ) ;
2007-02-01 00:15:47 +00:00
//should update stored position of the prim
}
2007-02-12 01:38:21 +00:00
else if ( multipleupdate . ObjectData [ i ] . Type = = 10 ) //rotation
2007-02-02 17:23:56 +00:00
{
2007-02-12 01:38:21 +00:00
libsecondlife . LLVector3 pos = new LLVector3 ( 100 , 100 , 22 ) ;
libsecondlife . LLQuaternion rot = new LLQuaternion ( multipleupdate . ObjectData [ i ] . Data , 0 , true ) ;
_primManager . UpdatePrimPosition ( userInfo , pos , multipleupdate . ObjectData [ i ] . ObjectLocalID , true , rot ) ;
2007-02-02 17:23:56 +00:00
}
2007-02-01 00:15:47 +00:00
}
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . AgentWearablesRequest )
2007-02-03 21:09:54 +00:00
{
2007-02-12 01:38:21 +00:00
_agentManager . SendIntialAvatarAppearance ( userInfo ) ;
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . AgentUpdate )
2007-02-03 19:51:52 +00:00
{
2007-02-12 01:38:21 +00:00
// System.Console.WriteLine("agent update");
2007-02-04 11:36:35 +00:00
AgentUpdatePacket agent = ( AgentUpdatePacket ) pack ;
2007-02-12 01:38:21 +00:00
uint mask = agent . AgentData . ControlFlags & ( 1 ) ;
AvatarData avatar = _agentManager . GetAgent ( userInfo . AgentID ) ;
2007-02-14 02:36:25 +00:00
avatar . CameraAtAxis = agent . AgentData . CameraAtAxis ;
avatar . CameraUpAxis = agent . AgentData . CameraUpAxis ;
avatar . CameraCenter = agent . AgentData . CameraCenter ;
avatar . far = agent . AgentData . Far ;
2007-02-12 01:38:21 +00:00
if ( avatar ! = null )
{
if ( avatar . Started )
2007-02-03 21:09:54 +00:00
{
2007-02-12 01:38:21 +00:00
if ( mask = = ( 1 ) )
2007-02-03 21:09:54 +00:00
{
2007-02-12 01:38:21 +00:00
if ( ! avatar . Walk )
2007-02-03 21:09:54 +00:00
{
2007-02-01 00:15:47 +00:00
//start walking
2007-02-12 01:38:21 +00:00
_agentManager . SendMoveCommand ( userInfo , false , avatar . Position . X , avatar . Position . Y , avatar . Position . Z , 0 , agent . AgentData . BodyRotation ) ;
2007-02-13 20:27:14 +00:00
_agentManager . UpdateAnim ( avatar . NetInfo , AgentManager . AnimsLLUUID [ "ANIM_AGENT_WALK" ] , 1 ) ;
2007-02-12 01:38:21 +00:00
Axiom . MathLib . Vector3 v3 = new Axiom . MathLib . Vector3 ( 1 , 0 , 0 ) ;
Axiom . MathLib . Quaternion q = new Axiom . MathLib . Quaternion ( agent . AgentData . BodyRotation . W , agent . AgentData . BodyRotation . X , agent . AgentData . BodyRotation . Y , agent . AgentData . BodyRotation . Z ) ;
2007-02-01 00:15:47 +00:00
Axiom . MathLib . Vector3 direc = q * v3 ;
direc . Normalize ( ) ;
2007-02-12 01:38:21 +00:00
direc = direc * ( ( 0.03f ) * 128f ) ;
2007-02-01 00:15:47 +00:00
2007-02-04 11:36:35 +00:00
avatar . Velocity . X = direc . x ;
avatar . Velocity . Y = direc . y ;
avatar . Velocity . Z = direc . z ;
avatar . Walk = true ;
2007-02-01 00:15:47 +00:00
}
}
2007-02-12 01:38:21 +00:00
else
2007-02-03 21:09:54 +00:00
{
2007-02-12 01:38:21 +00:00
if ( avatar . Walk )
2007-02-03 21:09:54 +00:00
{
2007-02-01 00:15:47 +00:00
//walking but key not pressed so need to stop
2007-02-12 01:38:21 +00:00
_agentManager . SendMoveCommand ( userInfo , true , avatar . Position . X , avatar . Position . Y , avatar . Position . Z , 0 , agent . AgentData . BodyRotation ) ;
2007-02-13 20:27:14 +00:00
_agentManager . UpdateAnim ( avatar . NetInfo , AgentManager . AnimsLLUUID [ "ANIM_AGENT_STAND" ] , 1 ) ;
2007-02-04 11:36:35 +00:00
avatar . Walk = false ;
avatar . Velocity . X = 0 ;
avatar . Velocity . Y = 0 ;
avatar . Velocity . Z = 0 ;
2007-02-01 00:15:47 +00:00
}
}
}
}
2007-02-04 11:36:35 +00:00
else
{
2007-02-12 01:38:21 +00:00
2007-02-04 11:36:35 +00:00
}
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else if ( pack . Type = = PacketType . ChatFromViewer )
2007-02-03 21:09:54 +00:00
{
2007-02-01 00:15:47 +00:00
ChatFromViewerPacket chat = ( ChatFromViewerPacket ) pack ;
System . Text . Encoding enc = System . Text . Encoding . ASCII ;
2007-02-12 01:38:21 +00:00
string myString = enc . GetString ( chat . ChatData . Message ) ;
if ( myString ! = "" )
{
string [ ] comp = new string [ 10 ] ;
2007-02-01 00:15:47 +00:00
string delimStr = " , " ;
char [ ] delimiter = delimStr . ToCharArray ( ) ;
string line ;
line = myString ;
2007-02-12 01:38:21 +00:00
comp = line . Split ( delimiter ) ;
if ( comp [ 0 ] = = "pos" )
2007-02-03 21:09:54 +00:00
{
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else if ( comp [ 0 ] = = "veloc" )
2007-02-03 21:09:54 +00:00
{
2007-02-01 00:15:47 +00:00
}
2007-02-12 01:38:21 +00:00
else
2007-02-03 21:09:54 +00:00
{
2007-02-12 01:38:21 +00:00
_agentManager . SendChatMessage ( userInfo , line ) ;
2007-02-01 00:15:47 +00:00
}
}
}
}
2007-02-04 11:36:35 +00:00
public void NewUserCallback ( UserAgentInfo userInfo )
2007-02-03 21:09:54 +00:00
{
2007-02-04 11:36:35 +00:00
Console . WriteLine ( "new user - {0} - has joined [session {1}]" , userInfo . AgentID . ToString ( ) , userInfo . SessionID . ToString ( ) + "curcuit used" + userInfo . circuitCode ) ;
2007-02-03 21:09:54 +00:00
string first , last ;
LLUUID Base , Inventory ;
2007-02-02 17:23:56 +00:00
lock ( _login )
{
2007-02-04 11:36:35 +00:00
first = _login . First ;
last = _login . Last ;
2007-02-03 19:51:52 +00:00
Base = _login . BaseFolder ;
2007-02-04 11:36:35 +00:00
Inventory = _login . InventoryFolder ;
2007-02-02 17:23:56 +00:00
//should get agentid and sessionid so they can be checked.
}
2007-02-04 11:36:35 +00:00
_agentManager . NewAgent ( userInfo , first , last , Base , Inventory ) ;
2007-02-02 17:23:56 +00:00
//now because of the lack of Global account management (User server etc)
//we need to reset the names back to default incase a teleport happens
//which will not have a Login name set, so they will use default names
lock ( _login )
{
2007-02-04 11:36:35 +00:00
_login . First = "Test" ;
_login . Last = "User" ;
2007-02-02 17:23:56 +00:00
}
2007-02-01 00:15:47 +00:00
}
2007-02-02 17:23:56 +00:00
public void ErrorCallback ( string text ) {
2007-02-01 00:15:47 +00:00
Console . WriteLine ( "error report: {0}" , text ) ;
}
void Timer1Tick ( object sender , System . EventArgs e ) {
this . time + + ;
2007-02-04 11:36:35 +00:00
_agentManager . UpdatePositions ( ) ;
this . _assetManager . DoWork ( time ) ;
2007-02-01 00:15:47 +00:00
}
}
2007-02-02 17:23:56 +00:00
public class Logon
{
2007-02-04 11:36:35 +00:00
public string First = "Test" ;
public string Last = "User" ;
2007-02-02 17:23:56 +00:00
public LLUUID Agent ;
public LLUUID Session ;
2007-02-03 19:51:52 +00:00
public LLUUID InventoryFolder ;
public LLUUID BaseFolder ;
2007-02-02 17:23:56 +00:00
public Logon ( )
{
}
}
}