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-02 17:23:56 +00:00
public partial class Controller : ServerCallback {
2007-02-01 00:15:47 +00:00
[STAThread]
public static void Main ( string [ ] args ) {
Controller c = new Controller ( ) ;
while ( true ) // fuckin' a
System . Threading . Thread . Sleep ( 1000 ) ;
}
public Server server ;
2007-02-02 17:23:56 +00:00
public Logon _login ;
private AgentManager Agent_Manager ;
private PrimManager Prim_Manager ;
2007-02-03 19:51:52 +00:00
// private TextureManager Texture_Manager;
private AssetManagement Asset_Manager ;
2007-02-02 17:23:56 +00:00
private GridManager Grid_Manager ;
2007-02-03 19:51:52 +00:00
private InventoryManager Inventory_Manager ;
2007-02-02 17:23:56 +00:00
private LoginManager Login_Manager ; //built in login server
2007-02-01 00:15:47 +00:00
private ulong time ; //ticks
private Timer timer1 = new Timer ( ) ;
public Controller ( ) {
2007-02-02 17:23:56 +00:00
_login = new Logon ( ) ; // should create a list for these.
2007-02-01 00:15:47 +00:00
server = new Server ( this ) ;
2007-02-02 17:23:56 +00:00
Agent_Manager = new AgentManager ( this . server ) ;
Prim_Manager = new PrimManager ( this . server ) ;
2007-02-03 19:51:52 +00:00
// Texture_Manager = new TextureManager( this.server );
Asset_Manager = new AssetManagement ( this . server ) ;
2007-02-02 17:23:56 +00:00
Prim_Manager . Agent_Manager = Agent_Manager ;
Agent_Manager . Prim_Manager = Prim_Manager ;
2007-02-03 19:51:52 +00:00
Agent_Manager . Asset_Manager = Asset_Manager ;
Inventory_Manager = new InventoryManager ( this . server ) ;
Asset_Manager . InventoryManager = Inventory_Manager ;
// Asset_Manager.TextureMan=Texture_Manager;
2007-02-02 17:23:56 +00:00
Grid_Manager = new GridManager ( this . server , Agent_Manager ) ;
if ( Globals . Instance . LoginSever )
{
Console . WriteLine ( "Starting login Server" ) ;
Login_Manager = new LoginManager ( _login ) ; // startup
Login_Manager . Startup ( ) ; // login server
}
timer1 . Enabled = true ;
2007-02-01 00:15:47 +00:00
timer1 . Interval = 200 ;
timer1 . Elapsed + = new ElapsedEventHandler ( this . Timer1Tick ) ;
}
2007-02-02 17:23:56 +00:00
public void MainCallback ( Packet pack , User_Agent_info User_info ) {
2007-02-03 19:51:52 +00:00
/ * if ( ( pack . Type ! = PacketType . StartPingCheck ) & & ( pack . Type ! = PacketType . AgentUpdate ) ) {
//Log packet?
// System.Console.WriteLine(pack.Type);
2007-02-01 00:15:47 +00:00
//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-03 19:51:52 +00:00
// System.Console.WriteLine(pack);
2007-02-01 00:15:47 +00:00
//this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type;
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . FetchInventory )
{
FetchInventoryPacket FetchInventory = ( FetchInventoryPacket ) pack ;
Inventory_Manager . FetchInventory ( User_info , FetchInventory ) ;
}
else if ( pack . Type = = PacketType . FetchInventoryDescendents )
{
FetchInventoryDescendentsPacket Fetch = ( FetchInventoryDescendentsPacket ) pack ;
Inventory_Manager . FetchInventoryDescendents ( User_info , Fetch ) ;
}
else if ( pack . Type = = PacketType . MapBlockRequest )
2007-02-02 17:23:56 +00:00
{
//int MinX, MinY, MaxX, MaxY;
MapBlockRequestPacket MapRequest = ( MapBlockRequestPacket ) pack ;
this . Grid_Manager . RequestMapBlock ( User_info , MapRequest . PositionData . MinX , MapRequest . PositionData . MinY , MapRequest . PositionData . MaxX , MapRequest . PositionData . MaxY ) ;
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . CloseCircuit )
2007-02-02 17:23:56 +00:00
{
this . Agent_Manager . RemoveAgent ( User_info ) ;
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . MapLayerRequest )
2007-02-02 17:23:56 +00:00
{
this . Grid_Manager . RequestMapLayer ( User_info ) ;
}
2007-02-03 19:51:52 +00:00
else if ( ( pack . Type = = PacketType . TeleportRequest ) | | ( pack . Type = = PacketType . TeleportLocationRequest ) )
2007-02-02 17:23:56 +00:00
{
TeleportLocationRequestPacket Request = ( TeleportLocationRequestPacket ) pack ;
this . Grid_Manager . RequestTeleport ( User_info , Request ) ;
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . TransferRequest ) {
2007-02-01 00:15:47 +00:00
TransferRequestPacket tran = ( TransferRequestPacket ) pack ;
LLUUID id = new LLUUID ( tran . TransferInfo . Params , 0 ) ;
2007-02-03 19:51:52 +00:00
// if( ( id == new LLUUID( "66c41e39-38f9-f75a-024e-585989bfab73" ) ) || ( id == new LLUUID( "e0ee49b5a4184df8d3c9a65361fe7f49" ) ) ) {
Asset_Manager . AddAssetRequest ( User_info , id , tran ) ;
// }
2007-02-01 00:15:47 +00:00
}
2007-02-03 19:51:52 +00:00
else if ( ( pack . Type = = PacketType . StartPingCheck ) ) {
2007-02-01 00:15:47 +00:00
//reply to pingcheck
libsecondlife . Packets . StartPingCheckPacket startp = ( libsecondlife . Packets . StartPingCheckPacket ) pack ;
libsecondlife . Packets . CompletePingCheckPacket endping = new CompletePingCheckPacket ( ) ;
endping . PingID . PingID = startp . PingID . PingID ;
server . SendPacket ( endping , true , User_info ) ;
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . CompleteAgentMovement ) {
2007-02-01 00:15:47 +00:00
// new client
2007-02-02 17:23:56 +00:00
Agent_Manager . AgentJoin ( User_info ) ;
2007-02-01 00:15:47 +00:00
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . RequestImage ) {
2007-02-01 00:15:47 +00:00
RequestImagePacket image_req = ( RequestImagePacket ) pack ;
for ( int i = 0 ; i < image_req . RequestImage . Length ; i + + ) {
2007-02-03 19:51:52 +00:00
this . Asset_Manager . AddTextureRequest ( User_info , image_req . RequestImage [ i ] . Image ) ;
2007-02-01 00:15:47 +00:00
}
}
2007-02-03 19:51:52 +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-02 17:23:56 +00:00
Agent_Manager . SendInitialData ( User_info ) ;
2007-02-01 00:15:47 +00:00
//this.setuptemplates("objectupate164.dat",User_info,false);
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . ObjectAdd ) {
2007-02-01 00:15:47 +00:00
ObjectAddPacket ad = ( ObjectAddPacket ) pack ;
2007-02-02 17:23:56 +00:00
Prim_Manager . CreatePrim ( User_info , ad . ObjectData . RayEnd , ad ) ;
2007-02-01 00:15:47 +00:00
//this.send_prim(User_info,ad.ObjectData.RayEnd, ad);
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . ObjectPosition ) {
2007-02-01 00:15:47 +00:00
//System.Console.WriteLine(pack.ToString());
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . MultipleObjectUpdate ) {
2007-02-01 00:15:47 +00:00
//System.Console.WriteLine(pack.ToString());
MultipleObjectUpdatePacket mupd = ( MultipleObjectUpdatePacket ) pack ;
for ( int i = 0 ; i < mupd . ObjectData . Length ; i + + ) {
if ( mupd . ObjectData [ i ] . Type = = 9 ) //change position
{
libsecondlife . LLVector3 pos = new LLVector3 ( mupd . ObjectData [ i ] . Data , 0 ) ;
2007-02-02 17:23:56 +00:00
// libsecondlife.LLQuaternion rot=new LLQuaternion(mupd.ObjectData[i].Data,12,true);
Prim_Manager . UpdatePrimPosition ( User_info , pos , mupd . ObjectData [ i ] . ObjectLocalID , false , libsecondlife . LLQuaternion . Identity ) ;
2007-02-01 00:15:47 +00:00
//should update stored position of the prim
}
2007-02-02 17:23:56 +00:00
else if ( mupd . ObjectData [ i ] . Type = = 10 )
{
//System.Console.WriteLine(mupd.ObjectData[ i ].Type);
//System.Console.WriteLine(mupd);
libsecondlife . LLVector3 pos = new LLVector3 ( 100 , 100 , 22 ) ;
libsecondlife . LLQuaternion rot = new LLQuaternion ( mupd . ObjectData [ i ] . Data , 0 , true ) ;
Prim_Manager . UpdatePrimPosition ( User_info , pos , mupd . ObjectData [ i ] . ObjectLocalID , true , rot ) ;
}
2007-02-01 00:15:47 +00:00
}
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . AgentWearablesRequest ) {
2007-02-02 17:23:56 +00:00
Agent_Manager . SendIntialAvatarAppearance ( User_info ) ;
2007-02-01 00:15:47 +00:00
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . AgentUpdate )
{
2007-02-01 00:15:47 +00:00
AgentUpdatePacket ag = ( AgentUpdatePacket ) pack ;
uint mask = ag . AgentData . ControlFlags & ( 1 ) ;
2007-02-02 17:23:56 +00:00
AvatarData m_av = Agent_Manager . GetAgent ( User_info . AgentID ) ;
2007-02-01 00:15:47 +00:00
if ( m_av ! = null ) {
2007-02-02 17:23:56 +00:00
if ( m_av . Started ) {
2007-02-01 00:15:47 +00:00
if ( mask = = ( 1 ) ) {
2007-02-02 17:23:56 +00:00
if ( ! m_av . Walk ) {
2007-02-01 00:15:47 +00:00
//start walking
2007-02-02 17:23:56 +00:00
Agent_Manager . SendMoveCommand ( User_info , false , m_av . Position . X , m_av . Position . Y , m_av . Position . Z , 0 , ag . AgentData . BodyRotation ) ;
2007-02-01 00:15:47 +00:00
Axiom . MathLib . Vector3 v3 = new Axiom . MathLib . Vector3 ( 1 , 0 , 0 ) ;
Axiom . MathLib . Quaternion q = new Axiom . MathLib . Quaternion ( ag . AgentData . BodyRotation . W , ag . AgentData . BodyRotation . X , ag . AgentData . BodyRotation . Y , ag . AgentData . BodyRotation . Z ) ;
Axiom . MathLib . Vector3 direc = q * v3 ;
direc . Normalize ( ) ;
direc = direc * ( ( 0.03f ) * 128f ) ;
2007-02-02 17:23:56 +00:00
m_av . Velocity . X = direc . x ;
m_av . Velocity . Y = direc . y ;
m_av . Velocity . Z = direc . z ;
m_av . Walk = true ;
2007-02-01 00:15:47 +00:00
}
}
else {
2007-02-02 17:23:56 +00:00
if ( m_av . Walk ) {
2007-02-01 00:15:47 +00:00
//walking but key not pressed so need to stop
2007-02-02 17:23:56 +00:00
Agent_Manager . SendMoveCommand ( User_info , true , m_av . Position . X , m_av . Position . Y , m_av . Position . Z , 0 , ag . AgentData . BodyRotation ) ;
m_av . Walk = false ;
m_av . Velocity . X = 0 ;
m_av . Velocity . Y = 0 ;
m_av . Velocity . Z = 0 ;
2007-02-01 00:15:47 +00:00
}
}
}
}
}
2007-02-03 19:51:52 +00:00
else if ( pack . Type = = PacketType . ChatFromViewer ) {
2007-02-01 00:15:47 +00:00
ChatFromViewerPacket chat = ( ChatFromViewerPacket ) pack ;
System . Text . Encoding enc = System . Text . Encoding . ASCII ;
string myString = enc . GetString ( chat . ChatData . Message ) ;
if ( myString ! = "" ) {
string [ ] comp = new string [ 10 ] ;
string delimStr = " , " ;
char [ ] delimiter = delimStr . ToCharArray ( ) ;
string line ;
line = myString ;
comp = line . Split ( delimiter ) ;
if ( comp [ 0 ] = = "pos" ) {
}
else if ( comp [ 0 ] = = "veloc" ) {
}
else {
2007-02-02 17:23:56 +00:00
Agent_Manager . SendChatMessage ( User_info , line ) ;
2007-02-01 00:15:47 +00:00
}
}
}
}
2007-02-02 17:23:56 +00:00
public void NewUserCallback ( User_Agent_info UserInfo ) {
Console . WriteLine ( "new user - {0} - has joined [session {1}]" , UserInfo . AgentID . ToString ( ) , UserInfo . SessionID . ToString ( ) + "curcuit used" + UserInfo . circuitCode ) ;
string first , last ;
2007-02-03 19:51:52 +00:00
LLUUID Base , Inventory ;
2007-02-02 17:23:56 +00:00
lock ( _login )
{
first = _login . first ;
last = _login . last ;
2007-02-03 19:51:52 +00:00
Base = _login . BaseFolder ;
Inventory = _login . InventoryFolder ;
2007-02-02 17:23:56 +00:00
//should get agentid and sessionid so they can be checked.
}
2007-02-03 19:51:52 +00:00
Agent_Manager . 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 )
{
_login . first = "Test" ;
_login . last = "User" ;
}
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-02 17:23:56 +00:00
Agent_Manager . UpdatePositions ( ) ;
2007-02-03 19:51:52 +00:00
this . Asset_Manager . DoWork ( time ) ;
2007-02-01 00:15:47 +00:00
}
}
2007-02-02 17:23:56 +00:00
public class Logon
{
public string first = "Test" ;
public string last = "User" ;
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 ( )
{
}
}
}