From 740a21330e1a6816bd9aca7ac3501b84f75f5024 Mon Sep 17 00:00:00 2001 From: MW Date: Thu, 15 Mar 2007 18:10:57 +0000 Subject: [PATCH] Clean up a bit and added missing files --- src/Assets/AssetCache.cs | 945 +++++++------- src/Assets/InventoryManager.cs | 524 ++++---- src/CAPS/SimHttp.cs | 175 +++ src/Config.cs | 70 +- src/Config/SimConfig/SimConfig.csproj | 4 +- src/GridInterfaces/IAssetServer.cs | 92 +- src/GridInterfaces/IGridServer.cs | 149 ++- src/GridInterfaces/ILocalStorage.cs | 92 +- src/GridServers/LoginServer.cs | 30 +- .../LocalGridServers/LocalGrid.cs | 25 +- src/Main.cs | 587 ++++----- src/OpenSimClient.cs | 1083 +++++++++-------- src/OpenSimConsole.cs | 45 +- .../RemoteGridServers/RemoteGrid.cs | 436 +++---- src/Second-server.csproj | 21 +- .../ServerConsole/ServerConsole.cs | 87 ++ .../ServerConsole/ServerConsole.csproj | 35 + src/Util.cs | 101 ++ src/VersionInfo.cs | 37 + src/opensim.sln | 74 ++ src/physics/PhysicsActor.cs | 161 +++ src/physics/PhysicsManager.cs | 92 +- src/physics/PhysicsManager.csproj | 4 + src/physics/PhysicsScene.cs | 98 ++ src/physics/PhysicsVector.cs | 54 + src/physics/plugins/BasicPhysicsplugin.csproj | 59 + 26 files changed, 3033 insertions(+), 2047 deletions(-) create mode 100644 src/CAPS/SimHttp.cs create mode 100644 src/ServerConsole/ServerConsole/ServerConsole.cs create mode 100644 src/ServerConsole/ServerConsole/ServerConsole.csproj create mode 100644 src/Util.cs create mode 100644 src/VersionInfo.cs create mode 100644 src/opensim.sln create mode 100644 src/physics/PhysicsActor.cs create mode 100644 src/physics/PhysicsScene.cs create mode 100644 src/physics/PhysicsVector.cs create mode 100644 src/physics/plugins/BasicPhysicsplugin.csproj diff --git a/src/Assets/AssetCache.cs b/src/Assets/AssetCache.cs index c5f31e0c6d..cf77f89715 100644 --- a/src/Assets/AssetCache.cs +++ b/src/Assets/AssetCache.cs @@ -35,419 +35,420 @@ using OpenSim.GridServers; namespace OpenSim.Assets { - /// - /// Manages local cache of assets and their sending to viewers. - /// - public class AssetCache : IAssetReceiver - { - public Dictionary Assets; - public Dictionary Textures; - - public List AssetRequests = new List(); //assets ready to be sent to viewers - public List TextureRequests = new List(); //textures ready to be sent - - public Dictionary RequestedAssets = new Dictionary(); //Assets requested from the asset server - public Dictionary RequestedTextures = new Dictionary(); //Textures requested from the asset server - - private Dictionary IncomingAssets; - - private IAssetServer _assetServer; - private Thread _assetCacheThread; - private LLUUID[] textureList = new LLUUID[2]; - - /// - /// - /// - public AssetCache( IAssetServer assetServer) - { - Console.WriteLine("Creating Asset cache"); - _assetServer = assetServer; - _assetServer.SetReceiver(this); - Assets = new Dictionary (); - Textures = new Dictionary (); - IncomingAssets = new Dictionary(); - this._assetCacheThread = new Thread( new ThreadStart(RunAssetManager)); - this._assetCacheThread.IsBackground = true; - this._assetCacheThread.Start(); - - } - - /// - /// - /// - public void RunAssetManager() - { - while(true) - { - try{ - this.ProcessAssetQueue(); - this.ProcessTextureQueue(); - Thread.Sleep(100); - } - catch(Exception e) - { - Console.WriteLine(e.Message); - } - } - } - - public void LoadDefaultTextureSet() - { - //hack: so we can give each user a set of textures - textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001"); - textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002"); - for(int i = 0; i< textureList.Length; i++) - { - this._assetServer.RequestAsset(textureList[i], true); - } - - } - - public AssetBase[] CreateNewInventorySet(LLUUID agentID) - { - AssetBase[] inventorySet = new AssetBase[this.textureList.Length]; - for(int i = 0; i< textureList.Length; i++) - { - if(this.Textures.ContainsKey(textureList[i])) - { - inventorySet[i] = this.CloneImage(agentID, this.Textures[textureList[i]]); - TextureImage image = new TextureImage(inventorySet[i]); - this.Textures.Add(image.FullID, image); - } - } - return inventorySet; - } - - /// - /// - /// - private void ProcessTextureQueue() - { - if(this.TextureRequests.Count == 0) - { - //no requests waiting - return; - } - int num; - - if(this.TextureRequests.Count < 5) - { - //lower than 5 so do all of them - num = this.TextureRequests.Count; - } - else - { - num=5; - } - AssetRequest req; - for(int i = 0; i < num; i++) - { - req=(AssetRequest)this.TextureRequests[i]; - - if(req.PacketCounter == 0) - { - //first time for this request so send imagedata packet - if(req.NumPackets == 1) - { - //only one packet so send whole file - ImageDataPacket im = new ImageDataPacket(); - im.ImageID.Packets = 1; - im.ImageID.ID = req.ImageInfo.FullID; - im.ImageID.Size = (uint)req.ImageInfo.Data.Length; - im.ImageData.Data = req.ImageInfo.Data; - im.ImageID.Codec = 2; - req.RequestUser.OutPacket(im); - req.PacketCounter++; - //req.ImageInfo.l= time; - //System.Console.WriteLine("sent texture: "+req.image_info.FullID); - } - else - { - //more than one packet so split file up - ImageDataPacket im = new ImageDataPacket(); - im.ImageID.Packets = (ushort)req.NumPackets; - im.ImageID.ID = req.ImageInfo.FullID; - im.ImageID.Size = (uint)req.ImageInfo.Data.Length; - im.ImageData.Data = new byte[600]; - Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600); - im.ImageID.Codec = 2; - req.RequestUser.OutPacket(im); - req.PacketCounter++; - //req.ImageInfo.last_used = time; - //System.Console.WriteLine("sent first packet of texture: - } - } - else - { - //send imagepacket - //more than one packet so split file up - ImagePacketPacket im = new ImagePacketPacket(); - im.ImageID.Packet = (ushort)req.PacketCounter; - im.ImageID.ID = req.ImageInfo.FullID; - int size = req.ImageInfo.Data.Length - 600 - 1000*(req.PacketCounter - 1); - if(size > 1000) size = 1000; - im.ImageData.Data = new byte[size]; - Array.Copy(req.ImageInfo.Data, 600 + 1000*(req.PacketCounter - 1), im.ImageData.Data, 0, size); - req.RequestUser.OutPacket(im); - req.PacketCounter++; - //req.ImageInfo.last_used = time; - //System.Console.WriteLine("sent a packet of texture: "+req.image_info.FullID); - } - } - - //remove requests that have been completed - int count = 0; - for(int i = 0; i < num; i++) - { - req=(AssetRequest)this.TextureRequests[count]; - if(req.PacketCounter == req.NumPackets) - { - this.TextureRequests.Remove(req); - } - else - { - count++; - } - } - - } - public void AssetReceived(AssetBase asset, bool IsTexture) - { - - if(asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server - { - //check if it is a texture or not - //then add to the correct cache list - //then check for waiting requests for this asset/texture (in the Requested lists) - //and move those requests into the Requests list. - if(IsTexture) - { - TextureImage image = new TextureImage(asset); - this.Textures.Add(image.FullID, image); - if(this.RequestedTextures.ContainsKey(image.FullID)) - { - AssetRequest req = this.RequestedTextures[image.FullID]; - req.ImageInfo = image; - this.RequestedTextures.Remove(image.FullID); - this.TextureRequests.Add(req); - } - } - else - { - AssetInfo assetInf = new AssetInfo(asset); - this.Assets.Add(assetInf.FullID, assetInf); - if(this.RequestedAssets.ContainsKey(assetInf.FullID)) - { - AssetRequest req = this.RequestedAssets[assetInf.FullID]; - req.AssetInf = assetInf; - this.RequestedAssets.Remove(assetInf.FullID); - this.AssetRequests.Add(req); - } - } - } - } - - public void AssetNotFound(AssetBase asset) - { - //the asset server had no knowledge of requested asset - - } - - #region Assets - /// - /// - /// - /// - /// - public void AddAssetRequest(OpenSimClient userInfo, TransferRequestPacket transferRequest) - { - LLUUID requestID = new LLUUID(transferRequest.TransferInfo.Params, 0); - //check to see if asset is in local cache, if not we need to request it from asset server. - if(!this.Assets.ContainsKey(requestID)) - { - //not found asset - // so request from asset server - AssetRequest request = new AssetRequest(); - request.RequestUser = userInfo; - request.RequestAssetID = requestID; - request.TransferRequestID = transferRequest.TransferInfo.TransferID; - this.RequestedAssets.Add(requestID,request); - this._assetServer.RequestAsset(requestID, false); - return; - } - //it is in our cache - AssetInfo asset = this.Assets[requestID]; - - //work out how many packets it should be sent in - // and add to the AssetRequests list - AssetRequest req = new AssetRequest(); - req.RequestUser = userInfo; - req.RequestAssetID = requestID; - req.TransferRequestID = transferRequest.TransferInfo.TransferID; - req.AssetInf = asset; - - if(asset.Data.LongLength>600) - { - //over 600 bytes so split up file - req.NumPackets = 1 + (int)(asset.Data.Length-600+999)/1000; - } - else - { - req.NumPackets = 1; - } - - this.AssetRequests.Add(req); - } - - /// - /// - /// - private void ProcessAssetQueue() - { - if(this.AssetRequests.Count == 0) - { - //no requests waiting - return; - } - int num; - - if(this.AssetRequests.Count < 5) - { - //lower than 5 so do all of them - num = this.AssetRequests.Count; - } - else - { - num=5; - } - AssetRequest req; - for(int i = 0; i < num; i++) - { - req=(AssetRequest)this.AssetRequests[i]; - - TransferInfoPacket Transfer = new TransferInfoPacket(); - Transfer.TransferInfo.ChannelType = 2; - Transfer.TransferInfo.Status = 0; - Transfer.TransferInfo.TargetType = 0; - Transfer.TransferInfo.Params = req.RequestAssetID.GetBytes(); - Transfer.TransferInfo.Size = (int)req.AssetInf.Data.Length; - Transfer.TransferInfo.TransferID = req.TransferRequestID; - req.RequestUser.OutPacket(Transfer); - - if(req.NumPackets == 1) - { - TransferPacketPacket TransferPacket = new TransferPacketPacket(); - TransferPacket.TransferData.Packet = 0; - TransferPacket.TransferData.ChannelType = 2; - TransferPacket.TransferData.TransferID=req.TransferRequestID; - TransferPacket.TransferData.Data = req.AssetInf.Data; - TransferPacket.TransferData.Status = 1; - req.RequestUser.OutPacket(TransferPacket); - } - else - { - //more than one packet so split file up , for now it can't be bigger than 2000 bytes - TransferPacketPacket TransferPacket = new TransferPacketPacket(); - TransferPacket.TransferData.Packet = 0; - TransferPacket.TransferData.ChannelType = 2; - TransferPacket.TransferData.TransferID=req.TransferRequestID; - byte[] chunk = new byte[1000]; - Array.Copy(req.AssetInf.Data,chunk,1000); - TransferPacket.TransferData.Data = chunk; - TransferPacket.TransferData.Status = 0; - req.RequestUser.OutPacket(TransferPacket); - - TransferPacket = new TransferPacketPacket(); - TransferPacket.TransferData.Packet = 1; - TransferPacket.TransferData.ChannelType = 2; - TransferPacket.TransferData.TransferID = req.TransferRequestID; - byte[] chunk1 = new byte[(req.AssetInf.Data.Length-1000)]; - Array.Copy(req.AssetInf.Data, 1000, chunk1, 0, chunk1.Length); - TransferPacket.TransferData.Data = chunk1; - TransferPacket.TransferData.Status = 1; - req.RequestUser.OutPacket(TransferPacket); - } - - } - - //remove requests that have been completed - for(int i = 0; i < num; i++) - { - this.AssetRequests.RemoveAt(0); - } - - } - - public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset) - { - AssetInfo newAsset = new AssetInfo(); - newAsset.Data = new byte[sourceAsset.Data.Length]; - Array.Copy(sourceAsset.Data, newAsset.Data, sourceAsset.Data.Length); - newAsset.FullID = LLUUID.Random(); - newAsset.Type = sourceAsset.Type; - newAsset.InvType = sourceAsset.InvType; - return(newAsset); - } - #endregion - - #region Textures - /// - /// - /// - /// - /// - public void AddTextureRequest(OpenSimClient userInfo, LLUUID imageID) - { - //check to see if texture is in local cache, if not request from asset server - if(!this.Textures.ContainsKey(imageID)) - { - if(!this.RequestedTextures.ContainsKey(imageID)) - { - //not is cache so request from asset server - AssetRequest request = new AssetRequest(); - request.RequestUser = userInfo; - request.RequestAssetID = imageID; - request.IsTextureRequest = true; - this.RequestedTextures.Add(imageID, request); - this._assetServer.RequestAsset(imageID, true); - } - return; - } - - TextureImage imag = this.Textures[imageID]; - AssetRequest req = new AssetRequest(); - req.RequestUser = userInfo; - req.RequestAssetID = imageID; - req.IsTextureRequest = true; - req.ImageInfo = imag; - - if(imag.Data.LongLength>600) - { - //over 600 bytes so split up file - req.NumPackets = 1 + (int)(imag.Data.Length-600+999)/1000; - } - else - { - req.NumPackets = 1; - } - - this.TextureRequests.Add(req); - } - - public TextureImage CloneImage(LLUUID newOwner, TextureImage source) - { - TextureImage newImage = new TextureImage(); - newImage.Data = new byte[source.Data.Length]; - Array.Copy(source.Data,newImage.Data,source.Data.Length); - //newImage.filename = source.filename; - newImage.FullID = LLUUID.Random(); - newImage.Name = source.Name; - return(newImage); - } - #endregion - - #region viewer asset uploading - /* public AssetBase UploadPacket(AssetUploadRequestPacket pack) + /// + /// Manages local cache of assets and their sending to viewers. + /// + public class AssetCache : IAssetReceiver + { + public Dictionary Assets; + public Dictionary Textures; + + public List AssetRequests = new List(); //assets ready to be sent to viewers + public List TextureRequests = new List(); //textures ready to be sent + + public Dictionary RequestedAssets = new Dictionary(); //Assets requested from the asset server + public Dictionary RequestedTextures = new Dictionary(); //Textures requested from the asset server + + private Dictionary IncomingAssets; + + private IAssetServer _assetServer; + private Thread _assetCacheThread; + private LLUUID[] textureList = new LLUUID[2]; + + /// + /// + /// + public AssetCache(IAssetServer assetServer) + { + Console.WriteLine("Creating Asset cache"); + _assetServer = assetServer; + _assetServer.SetReceiver(this); + Assets = new Dictionary(); + Textures = new Dictionary(); + IncomingAssets = new Dictionary(); + this._assetCacheThread = new Thread(new ThreadStart(RunAssetManager)); + this._assetCacheThread.IsBackground = true; + this._assetCacheThread.Start(); + + } + + /// + /// + /// + public void RunAssetManager() + { + while (true) + { + try + { + this.ProcessAssetQueue(); + this.ProcessTextureQueue(); + Thread.Sleep(100); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + } + + public void LoadDefaultTextureSet() + { + //hack: so we can give each user a set of textures + textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001"); + textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002"); + for (int i = 0; i < textureList.Length; i++) + { + this._assetServer.RequestAsset(textureList[i], true); + } + + } + + public AssetBase[] CreateNewInventorySet(LLUUID agentID) + { + AssetBase[] inventorySet = new AssetBase[this.textureList.Length]; + for (int i = 0; i < textureList.Length; i++) + { + if (this.Textures.ContainsKey(textureList[i])) + { + inventorySet[i] = this.CloneImage(agentID, this.Textures[textureList[i]]); + TextureImage image = new TextureImage(inventorySet[i]); + this.Textures.Add(image.FullID, image); + } + } + return inventorySet; + } + + /// + /// + /// + private void ProcessTextureQueue() + { + if (this.TextureRequests.Count == 0) + { + //no requests waiting + return; + } + int num; + + if (this.TextureRequests.Count < 5) + { + //lower than 5 so do all of them + num = this.TextureRequests.Count; + } + else + { + num = 5; + } + AssetRequest req; + for (int i = 0; i < num; i++) + { + req = (AssetRequest)this.TextureRequests[i]; + + if (req.PacketCounter == 0) + { + //first time for this request so send imagedata packet + if (req.NumPackets == 1) + { + //only one packet so send whole file + ImageDataPacket im = new ImageDataPacket(); + im.ImageID.Packets = 1; + im.ImageID.ID = req.ImageInfo.FullID; + im.ImageID.Size = (uint)req.ImageInfo.Data.Length; + im.ImageData.Data = req.ImageInfo.Data; + im.ImageID.Codec = 2; + req.RequestUser.OutPacket(im); + req.PacketCounter++; + //req.ImageInfo.l= time; + //System.Console.WriteLine("sent texture: "+req.image_info.FullID); + } + else + { + //more than one packet so split file up + ImageDataPacket im = new ImageDataPacket(); + im.ImageID.Packets = (ushort)req.NumPackets; + im.ImageID.ID = req.ImageInfo.FullID; + im.ImageID.Size = (uint)req.ImageInfo.Data.Length; + im.ImageData.Data = new byte[600]; + Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600); + im.ImageID.Codec = 2; + req.RequestUser.OutPacket(im); + req.PacketCounter++; + //req.ImageInfo.last_used = time; + //System.Console.WriteLine("sent first packet of texture: + } + } + else + { + //send imagepacket + //more than one packet so split file up + ImagePacketPacket im = new ImagePacketPacket(); + im.ImageID.Packet = (ushort)req.PacketCounter; + im.ImageID.ID = req.ImageInfo.FullID; + int size = req.ImageInfo.Data.Length - 600 - 1000 * (req.PacketCounter - 1); + if (size > 1000) size = 1000; + im.ImageData.Data = new byte[size]; + Array.Copy(req.ImageInfo.Data, 600 + 1000 * (req.PacketCounter - 1), im.ImageData.Data, 0, size); + req.RequestUser.OutPacket(im); + req.PacketCounter++; + //req.ImageInfo.last_used = time; + //System.Console.WriteLine("sent a packet of texture: "+req.image_info.FullID); + } + } + + //remove requests that have been completed + int count = 0; + for (int i = 0; i < num; i++) + { + req = (AssetRequest)this.TextureRequests[count]; + if (req.PacketCounter == req.NumPackets) + { + this.TextureRequests.Remove(req); + } + else + { + count++; + } + } + + } + public void AssetReceived(AssetBase asset, bool IsTexture) + { + + if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server + { + //check if it is a texture or not + //then add to the correct cache list + //then check for waiting requests for this asset/texture (in the Requested lists) + //and move those requests into the Requests list. + if (IsTexture) + { + TextureImage image = new TextureImage(asset); + this.Textures.Add(image.FullID, image); + if (this.RequestedTextures.ContainsKey(image.FullID)) + { + AssetRequest req = this.RequestedTextures[image.FullID]; + req.ImageInfo = image; + this.RequestedTextures.Remove(image.FullID); + this.TextureRequests.Add(req); + } + } + else + { + AssetInfo assetInf = new AssetInfo(asset); + this.Assets.Add(assetInf.FullID, assetInf); + if (this.RequestedAssets.ContainsKey(assetInf.FullID)) + { + AssetRequest req = this.RequestedAssets[assetInf.FullID]; + req.AssetInf = assetInf; + this.RequestedAssets.Remove(assetInf.FullID); + this.AssetRequests.Add(req); + } + } + } + } + + public void AssetNotFound(AssetBase asset) + { + //the asset server had no knowledge of requested asset + + } + + #region Assets + /// + /// + /// + /// + /// + public void AddAssetRequest(OpenSimClient userInfo, TransferRequestPacket transferRequest) + { + LLUUID requestID = new LLUUID(transferRequest.TransferInfo.Params, 0); + //check to see if asset is in local cache, if not we need to request it from asset server. + if (!this.Assets.ContainsKey(requestID)) + { + //not found asset + // so request from asset server + AssetRequest request = new AssetRequest(); + request.RequestUser = userInfo; + request.RequestAssetID = requestID; + request.TransferRequestID = transferRequest.TransferInfo.TransferID; + this.RequestedAssets.Add(requestID, request); + this._assetServer.RequestAsset(requestID, false); + return; + } + //it is in our cache + AssetInfo asset = this.Assets[requestID]; + + //work out how many packets it should be sent in + // and add to the AssetRequests list + AssetRequest req = new AssetRequest(); + req.RequestUser = userInfo; + req.RequestAssetID = requestID; + req.TransferRequestID = transferRequest.TransferInfo.TransferID; + req.AssetInf = asset; + + if (asset.Data.LongLength > 600) + { + //over 600 bytes so split up file + req.NumPackets = 1 + (int)(asset.Data.Length - 600 + 999) / 1000; + } + else + { + req.NumPackets = 1; + } + + this.AssetRequests.Add(req); + } + + /// + /// + /// + private void ProcessAssetQueue() + { + if (this.AssetRequests.Count == 0) + { + //no requests waiting + return; + } + int num; + + if (this.AssetRequests.Count < 5) + { + //lower than 5 so do all of them + num = this.AssetRequests.Count; + } + else + { + num = 5; + } + AssetRequest req; + for (int i = 0; i < num; i++) + { + req = (AssetRequest)this.AssetRequests[i]; + + TransferInfoPacket Transfer = new TransferInfoPacket(); + Transfer.TransferInfo.ChannelType = 2; + Transfer.TransferInfo.Status = 0; + Transfer.TransferInfo.TargetType = 0; + Transfer.TransferInfo.Params = req.RequestAssetID.GetBytes(); + Transfer.TransferInfo.Size = (int)req.AssetInf.Data.Length; + Transfer.TransferInfo.TransferID = req.TransferRequestID; + req.RequestUser.OutPacket(Transfer); + + if (req.NumPackets == 1) + { + TransferPacketPacket TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 0; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID = req.TransferRequestID; + TransferPacket.TransferData.Data = req.AssetInf.Data; + TransferPacket.TransferData.Status = 1; + req.RequestUser.OutPacket(TransferPacket); + } + else + { + //more than one packet so split file up , for now it can't be bigger than 2000 bytes + TransferPacketPacket TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 0; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID = req.TransferRequestID; + byte[] chunk = new byte[1000]; + Array.Copy(req.AssetInf.Data, chunk, 1000); + TransferPacket.TransferData.Data = chunk; + TransferPacket.TransferData.Status = 0; + req.RequestUser.OutPacket(TransferPacket); + + TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 1; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID = req.TransferRequestID; + byte[] chunk1 = new byte[(req.AssetInf.Data.Length - 1000)]; + Array.Copy(req.AssetInf.Data, 1000, chunk1, 0, chunk1.Length); + TransferPacket.TransferData.Data = chunk1; + TransferPacket.TransferData.Status = 1; + req.RequestUser.OutPacket(TransferPacket); + } + + } + + //remove requests that have been completed + for (int i = 0; i < num; i++) + { + this.AssetRequests.RemoveAt(0); + } + + } + + public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset) + { + AssetInfo newAsset = new AssetInfo(); + newAsset.Data = new byte[sourceAsset.Data.Length]; + Array.Copy(sourceAsset.Data, newAsset.Data, sourceAsset.Data.Length); + newAsset.FullID = LLUUID.Random(); + newAsset.Type = sourceAsset.Type; + newAsset.InvType = sourceAsset.InvType; + return (newAsset); + } + #endregion + + #region Textures + /// + /// + /// + /// + /// + public void AddTextureRequest(OpenSimClient userInfo, LLUUID imageID) + { + //check to see if texture is in local cache, if not request from asset server + if (!this.Textures.ContainsKey(imageID)) + { + if (!this.RequestedTextures.ContainsKey(imageID)) + { + //not is cache so request from asset server + AssetRequest request = new AssetRequest(); + request.RequestUser = userInfo; + request.RequestAssetID = imageID; + request.IsTextureRequest = true; + this.RequestedTextures.Add(imageID, request); + this._assetServer.RequestAsset(imageID, true); + } + return; + } + + TextureImage imag = this.Textures[imageID]; + AssetRequest req = new AssetRequest(); + req.RequestUser = userInfo; + req.RequestAssetID = imageID; + req.IsTextureRequest = true; + req.ImageInfo = imag; + + if (imag.Data.LongLength > 600) + { + //over 600 bytes so split up file + req.NumPackets = 1 + (int)(imag.Data.Length - 600 + 999) / 1000; + } + else + { + req.NumPackets = 1; + } + + this.TextureRequests.Add(req); + } + + public TextureImage CloneImage(LLUUID newOwner, TextureImage source) + { + TextureImage newImage = new TextureImage(); + newImage.Data = new byte[source.Data.Length]; + Array.Copy(source.Data, newImage.Data, source.Data.Length); + //newImage.filename = source.filename; + newImage.FullID = LLUUID.Random(); + newImage.Name = source.Name; + return (newImage); + } + #endregion + + #region viewer asset uploading + /* public AssetBase UploadPacket(AssetUploadRequestPacket pack) { AssetBase asset = null; if(this.IncomingAssets.ContainsKey(pack.AssetBlock.TransactionID)) @@ -491,65 +492,65 @@ namespace OpenSim.Assets } return asset; }*/ - - #endregion - - } - public class AssetRequest - { - public OpenSimClient RequestUser; - public LLUUID RequestAssetID; - public AssetInfo AssetInf; - public TextureImage ImageInfo; - public LLUUID TransferRequestID; - public long DataPointer = 0; - public int NumPackets = 0; - public int PacketCounter = 0; - public bool IsTextureRequest; - //public bool AssetInCache; - //public int TimeRequested; - - public AssetRequest() - { - - } - } - - public class AssetInfo : AssetBase - { - public AssetInfo() - { - - } - - public AssetInfo(AssetBase aBase) - { - Data= aBase.Data; - FullID = aBase.FullID; - Type = aBase.Type; - InvType = aBase.InvType; - Name= aBase.Name; - Description = aBase.Description; - } - } - - public class TextureImage : AssetBase - { - public TextureImage() - { - - } - - public TextureImage(AssetBase aBase) - { - Data= aBase.Data; - FullID = aBase.FullID; - Type = aBase.Type; - InvType = aBase.InvType; - Name= aBase.Name; - Description = aBase.Description; - } - } + #endregion + + } + + public class AssetRequest + { + public OpenSimClient RequestUser; + public LLUUID RequestAssetID; + public AssetInfo AssetInf; + public TextureImage ImageInfo; + public LLUUID TransferRequestID; + public long DataPointer = 0; + public int NumPackets = 0; + public int PacketCounter = 0; + public bool IsTextureRequest; + //public bool AssetInCache; + //public int TimeRequested; + + public AssetRequest() + { + + } + } + + public class AssetInfo : AssetBase + { + public AssetInfo() + { + + } + + public AssetInfo(AssetBase aBase) + { + Data = aBase.Data; + FullID = aBase.FullID; + Type = aBase.Type; + InvType = aBase.InvType; + Name = aBase.Name; + Description = aBase.Description; + } + } + + public class TextureImage : AssetBase + { + public TextureImage() + { + + } + + public TextureImage(AssetBase aBase) + { + Data = aBase.Data; + FullID = aBase.FullID; + Type = aBase.Type; + InvType = aBase.InvType; + Name = aBase.Name; + Description = aBase.Description; + } + } } diff --git a/src/Assets/InventoryManager.cs b/src/Assets/InventoryManager.cs index 275ca4c4ac..fa88d95830 100644 --- a/src/Assets/InventoryManager.cs +++ b/src/Assets/InventoryManager.cs @@ -34,266 +34,266 @@ using OpenSim.GridServers; namespace OpenSim.Assets { - /// - /// Description of InventoryManager. - /// - public class InventoryManager - { - private Dictionary _agentsInventory; - private List _serverRequests; //list of requests made to user server. - private System.Text.Encoding _enc = System.Text.Encoding.ASCII; - private const uint FULL_MASK_PERMISSIONS = 2147483647; - - public InventoryManager() - { - _agentsInventory = new Dictionary(); - _serverRequests = new List(); - } - - public void AddNewAgentsInventory(AgentInventory agentInventory) - { - this._agentsInventory.Add(agentInventory.AgentID, agentInventory); - } - - public void ClientLeaving(LLUUID clientID) - { - if(this._agentsInventory.ContainsKey(clientID)) - { - this._agentsInventory.Remove(clientID); - } - - } - public bool CreateNewInventoryFolder(OpenSimClient remoteClient, LLUUID folderID) - { - bool res = false; - if(folderID != LLUUID.Zero) //don't create a folder with a zero id - { - if(this._agentsInventory.ContainsKey(remoteClient.AgentID)) - { - res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID); - } - } - return res; - } - - public LLUUID AddNewInventoryItem(OpenSimClient remoteClient, LLUUID folderID, AssetBase asset) - { - LLUUID newItem = null; - if(this._agentsInventory.ContainsKey(remoteClient.AgentID)) - { - newItem = this._agentsInventory[remoteClient.AgentID].AddToInventory(folderID, asset); - } - - return newItem; - } - - public void FetchInventoryDescendents(OpenSimClient userInfo, FetchInventoryDescendentsPacket FetchDescend) - { - if(this._agentsInventory.ContainsKey(userInfo.AgentID)) - { - AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID]; - if(FetchDescend.InventoryData.FetchItems) - { - if(agentInventory.Folders.ContainsKey(FetchDescend.InventoryData.FolderID)) - { - InventoryFolder Folder = agentInventory.Folders[FetchDescend.InventoryData.FolderID]; - InventoryDescendentsPacket Descend = new InventoryDescendentsPacket(); - Descend.AgentData.AgentID = userInfo.AgentID; - Descend.AgentData.OwnerID = Folder.OwnerID; - Descend.AgentData.FolderID = FetchDescend.InventoryData.FolderID; - Descend.AgentData.Descendents = Folder.Items.Count; - Descend.AgentData.Version = Folder.Items.Count; - - - Descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[Folder.Items.Count]; - for(int i = 0; i < Folder.Items.Count ; i++) - { - - InventoryItem Item=Folder.Items[i]; - Descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock(); - Descend.ItemData[i].ItemID = Item.ItemID; - Descend.ItemData[i].AssetID = Item.AssetID; - Descend.ItemData[i].CreatorID = Item.CreatorID; - Descend.ItemData[i].BaseMask = FULL_MASK_PERMISSIONS; - Descend.ItemData[i].CreationDate = 1000; - Descend.ItemData[i].Description = _enc.GetBytes(Item.Description+"\0"); - Descend.ItemData[i].EveryoneMask = FULL_MASK_PERMISSIONS; - Descend.ItemData[i].Flags = 1; - Descend.ItemData[i].FolderID = Item.FolderID; - Descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000"); - Descend.ItemData[i].GroupMask = FULL_MASK_PERMISSIONS; - Descend.ItemData[i].InvType = Item.InvType; - Descend.ItemData[i].Name = _enc.GetBytes(Item.Name+"\0"); - Descend.ItemData[i].NextOwnerMask = FULL_MASK_PERMISSIONS; - Descend.ItemData[i].OwnerID = Item.OwnerID; - Descend.ItemData[i].OwnerMask = FULL_MASK_PERMISSIONS; - Descend.ItemData[i].SalePrice = 100; - Descend.ItemData[i].SaleType = 0; - Descend.ItemData[i].Type = Item.Type; - Descend.ItemData[i].CRC=libsecondlife.Helpers.InventoryCRC(1000, 0, Descend.ItemData[i].InvType, Descend.ItemData[i].Type, Descend.ItemData[i].AssetID, Descend.ItemData[i].GroupID, 100, Descend.ItemData[i].OwnerID, Descend.ItemData[i].CreatorID, Descend.ItemData[i].ItemID, Descend.ItemData[i].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS); - } - userInfo.OutPacket(Descend); - - } - } - else - { - Console.WriteLine("fetch subfolders"); - } - } - } - - public void FetchInventory(OpenSimClient userInfo, FetchInventoryPacket FetchItems) - { - if(this._agentsInventory.ContainsKey(userInfo.AgentID)) - { - AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID]; - - for(int i = 0; i < FetchItems.InventoryData.Length; i++) - { - if(agentInventory.Items.ContainsKey(FetchItems.InventoryData[i].ItemID)) - { - InventoryItem Item = agentInventory.Items[FetchItems.InventoryData[i].ItemID]; - FetchInventoryReplyPacket InventoryReply = new FetchInventoryReplyPacket(); - InventoryReply.AgentData.AgentID = userInfo.AgentID; - InventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1]; - InventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock(); - InventoryReply.InventoryData[0].ItemID = Item.ItemID; - InventoryReply.InventoryData[0].AssetID = Item.AssetID; - InventoryReply.InventoryData[0].CreatorID = Item.CreatorID; - InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS; - InventoryReply.InventoryData[0].CreationDate = 1000; - InventoryReply.InventoryData[0].Description = _enc.GetBytes( Item.Description+"\0"); - InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS; - InventoryReply.InventoryData[0].Flags = 1; - InventoryReply.InventoryData[0].FolderID = Item.FolderID; - InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000"); - InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS; - InventoryReply.InventoryData[0].InvType = Item.InvType; - InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name+"\0"); - InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS; - InventoryReply.InventoryData[0].OwnerID = Item.OwnerID; - InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS; - InventoryReply.InventoryData[0].SalePrice = 100; - InventoryReply.InventoryData[0].SaleType = 0; - InventoryReply.InventoryData[0].Type = Item.Type; - InventoryReply.InventoryData[0].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType, InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID, InventoryReply.InventoryData[0].GroupID, 100, InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID, InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS); - userInfo.OutPacket(InventoryReply); - } - } - } - } - } - - public class AgentInventory - { - //Holds the local copy of Inventory info for a agent - public Dictionary Folders; - public Dictionary Items; - public int LastCached; //time this was last stored/compared to user server - public LLUUID AgentID; - public AvatarWearable[] Wearables; - - public AgentInventory() - { - Folders = new Dictionary(); - Items = new Dictionary(); - Wearables = new AvatarWearable[2]; - for(int i = 0; i < 2; i++) - { - Wearables[i] = new AvatarWearable(); - } - } - - public bool CreateNewFolder(LLUUID folderID) - { - InventoryFolder Folder = new InventoryFolder(); - Folder.FolderID = folderID; - Folder.OwnerID = this.AgentID; - this.Folders.Add(Folder.FolderID, Folder); - - return(true); - } - - public LLUUID AddToInventory( LLUUID folderID, AssetBase asset) - { - if(this.Folders.ContainsKey(folderID)) - { - LLUUID NewItemID = LLUUID.Random(); - - InventoryItem Item = new InventoryItem(); - Item.FolderID = folderID; - Item.OwnerID = AgentID; - Item.AssetID = asset.FullID; - Item.ItemID = NewItemID; - Item.Type = asset.Type; - Item.Name = asset.Name; - Item.Description = asset.Description; - Item.InvType = asset.InvType; - this.Items.Add(Item.ItemID, Item); - InventoryFolder Folder = Folders[Item.FolderID]; - Folder.Items.Add(Item); - return(Item.ItemID); - } - else - { - return(null); - } - } - } - - public class InventoryFolder - { - public List Items; - //public List Subfolders; - public LLUUID FolderID; - public LLUUID OwnerID; - public LLUUID ParentID; - public string Name; - public byte Type; - - public InventoryFolder() - { - Items = new List(); - //Subfolders = new List(); - } - - } - - public class InventoryItem - { - public LLUUID FolderID; - public LLUUID OwnerID; - public LLUUID ItemID; - public LLUUID AssetID; - public LLUUID CreatorID; - public sbyte InvType; - public sbyte Type; - public string Name; - public string Description; - - public InventoryItem() - { - this.CreatorID = LLUUID.Zero; - } - } - - public class UserServerRequest - { - public UserServerRequest() - { - - } - } - - public class AvatarWearable - { - public LLUUID AssetID = new LLUUID("00000000-0000-0000-0000-000000000000"); - public LLUUID ItemID = new LLUUID("00000000-0000-0000-0000-000000000000"); - - public AvatarWearable() - { - - } - } + /// + /// Description of InventoryManager. + /// + public class InventoryManager + { + private Dictionary _agentsInventory; + private List _serverRequests; //list of requests made to user server. + private System.Text.Encoding _enc = System.Text.Encoding.ASCII; + private const uint FULL_MASK_PERMISSIONS = 2147483647; + + public InventoryManager() + { + _agentsInventory = new Dictionary(); + _serverRequests = new List(); + } + + public void AddNewAgentsInventory(AgentInventory agentInventory) + { + this._agentsInventory.Add(agentInventory.AgentID, agentInventory); + } + + public void ClientLeaving(LLUUID clientID) + { + if (this._agentsInventory.ContainsKey(clientID)) + { + this._agentsInventory.Remove(clientID); + } + + } + public bool CreateNewInventoryFolder(OpenSimClient remoteClient, LLUUID folderID) + { + bool res = false; + if (folderID != LLUUID.Zero) //don't create a folder with a zero id + { + if (this._agentsInventory.ContainsKey(remoteClient.AgentID)) + { + res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID); + } + } + return res; + } + + public LLUUID AddNewInventoryItem(OpenSimClient remoteClient, LLUUID folderID, AssetBase asset) + { + LLUUID newItem = null; + if (this._agentsInventory.ContainsKey(remoteClient.AgentID)) + { + newItem = this._agentsInventory[remoteClient.AgentID].AddToInventory(folderID, asset); + } + + return newItem; + } + + public void FetchInventoryDescendents(OpenSimClient userInfo, FetchInventoryDescendentsPacket FetchDescend) + { + if (this._agentsInventory.ContainsKey(userInfo.AgentID)) + { + AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID]; + if (FetchDescend.InventoryData.FetchItems) + { + if (agentInventory.Folders.ContainsKey(FetchDescend.InventoryData.FolderID)) + { + InventoryFolder Folder = agentInventory.Folders[FetchDescend.InventoryData.FolderID]; + InventoryDescendentsPacket Descend = new InventoryDescendentsPacket(); + Descend.AgentData.AgentID = userInfo.AgentID; + Descend.AgentData.OwnerID = Folder.OwnerID; + Descend.AgentData.FolderID = FetchDescend.InventoryData.FolderID; + Descend.AgentData.Descendents = Folder.Items.Count; + Descend.AgentData.Version = Folder.Items.Count; + + + Descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[Folder.Items.Count]; + for (int i = 0; i < Folder.Items.Count; i++) + { + + InventoryItem Item = Folder.Items[i]; + Descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock(); + Descend.ItemData[i].ItemID = Item.ItemID; + Descend.ItemData[i].AssetID = Item.AssetID; + Descend.ItemData[i].CreatorID = Item.CreatorID; + Descend.ItemData[i].BaseMask = FULL_MASK_PERMISSIONS; + Descend.ItemData[i].CreationDate = 1000; + Descend.ItemData[i].Description = _enc.GetBytes(Item.Description + "\0"); + Descend.ItemData[i].EveryoneMask = FULL_MASK_PERMISSIONS; + Descend.ItemData[i].Flags = 1; + Descend.ItemData[i].FolderID = Item.FolderID; + Descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000"); + Descend.ItemData[i].GroupMask = FULL_MASK_PERMISSIONS; + Descend.ItemData[i].InvType = Item.InvType; + Descend.ItemData[i].Name = _enc.GetBytes(Item.Name + "\0"); + Descend.ItemData[i].NextOwnerMask = FULL_MASK_PERMISSIONS; + Descend.ItemData[i].OwnerID = Item.OwnerID; + Descend.ItemData[i].OwnerMask = FULL_MASK_PERMISSIONS; + Descend.ItemData[i].SalePrice = 100; + Descend.ItemData[i].SaleType = 0; + Descend.ItemData[i].Type = Item.Type; + Descend.ItemData[i].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, Descend.ItemData[i].InvType, Descend.ItemData[i].Type, Descend.ItemData[i].AssetID, Descend.ItemData[i].GroupID, 100, Descend.ItemData[i].OwnerID, Descend.ItemData[i].CreatorID, Descend.ItemData[i].ItemID, Descend.ItemData[i].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS); + } + userInfo.OutPacket(Descend); + + } + } + else + { + Console.WriteLine("fetch subfolders"); + } + } + } + + public void FetchInventory(OpenSimClient userInfo, FetchInventoryPacket FetchItems) + { + if (this._agentsInventory.ContainsKey(userInfo.AgentID)) + { + AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID]; + + for (int i = 0; i < FetchItems.InventoryData.Length; i++) + { + if (agentInventory.Items.ContainsKey(FetchItems.InventoryData[i].ItemID)) + { + InventoryItem Item = agentInventory.Items[FetchItems.InventoryData[i].ItemID]; + FetchInventoryReplyPacket InventoryReply = new FetchInventoryReplyPacket(); + InventoryReply.AgentData.AgentID = userInfo.AgentID; + InventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1]; + InventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock(); + InventoryReply.InventoryData[0].ItemID = Item.ItemID; + InventoryReply.InventoryData[0].AssetID = Item.AssetID; + InventoryReply.InventoryData[0].CreatorID = Item.CreatorID; + InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS; + InventoryReply.InventoryData[0].CreationDate = 1000; + InventoryReply.InventoryData[0].Description = _enc.GetBytes(Item.Description + "\0"); + InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS; + InventoryReply.InventoryData[0].Flags = 1; + InventoryReply.InventoryData[0].FolderID = Item.FolderID; + InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000"); + InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS; + InventoryReply.InventoryData[0].InvType = Item.InvType; + InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name + "\0"); + InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS; + InventoryReply.InventoryData[0].OwnerID = Item.OwnerID; + InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS; + InventoryReply.InventoryData[0].SalePrice = 100; + InventoryReply.InventoryData[0].SaleType = 0; + InventoryReply.InventoryData[0].Type = Item.Type; + InventoryReply.InventoryData[0].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType, InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID, InventoryReply.InventoryData[0].GroupID, 100, InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID, InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS); + userInfo.OutPacket(InventoryReply); + } + } + } + } + } + + public class AgentInventory + { + //Holds the local copy of Inventory info for a agent + public Dictionary Folders; + public Dictionary Items; + public int LastCached; //time this was last stored/compared to user server + public LLUUID AgentID; + public AvatarWearable[] Wearables; + + public AgentInventory() + { + Folders = new Dictionary(); + Items = new Dictionary(); + Wearables = new AvatarWearable[2]; + for (int i = 0; i < 2; i++) + { + Wearables[i] = new AvatarWearable(); + } + } + + public bool CreateNewFolder(LLUUID folderID) + { + InventoryFolder Folder = new InventoryFolder(); + Folder.FolderID = folderID; + Folder.OwnerID = this.AgentID; + this.Folders.Add(Folder.FolderID, Folder); + + return (true); + } + + public LLUUID AddToInventory(LLUUID folderID, AssetBase asset) + { + if (this.Folders.ContainsKey(folderID)) + { + LLUUID NewItemID = LLUUID.Random(); + + InventoryItem Item = new InventoryItem(); + Item.FolderID = folderID; + Item.OwnerID = AgentID; + Item.AssetID = asset.FullID; + Item.ItemID = NewItemID; + Item.Type = asset.Type; + Item.Name = asset.Name; + Item.Description = asset.Description; + Item.InvType = asset.InvType; + this.Items.Add(Item.ItemID, Item); + InventoryFolder Folder = Folders[Item.FolderID]; + Folder.Items.Add(Item); + return (Item.ItemID); + } + else + { + return (null); + } + } + } + + public class InventoryFolder + { + public List Items; + //public List Subfolders; + public LLUUID FolderID; + public LLUUID OwnerID; + public LLUUID ParentID; + public string Name; + public byte Type; + + public InventoryFolder() + { + Items = new List(); + //Subfolders = new List(); + } + + } + + public class InventoryItem + { + public LLUUID FolderID; + public LLUUID OwnerID; + public LLUUID ItemID; + public LLUUID AssetID; + public LLUUID CreatorID; + public sbyte InvType; + public sbyte Type; + public string Name; + public string Description; + + public InventoryItem() + { + this.CreatorID = LLUUID.Zero; + } + } + + public class UserServerRequest + { + public UserServerRequest() + { + + } + } + + public class AvatarWearable + { + public LLUUID AssetID = new LLUUID("00000000-0000-0000-0000-000000000000"); + public LLUUID ItemID = new LLUUID("00000000-0000-0000-0000-000000000000"); + + public AvatarWearable() + { + + } + } } diff --git a/src/CAPS/SimHttp.cs b/src/CAPS/SimHttp.cs new file mode 100644 index 0000000000..063475897b --- /dev/null +++ b/src/CAPS/SimHttp.cs @@ -0,0 +1,175 @@ +/* +Copyright (c) OpenSimCAPS 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 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 ``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 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; +using OpenSim.GridServers; + +namespace OpenSim +{ + // Dummy HTTP server, does nothing useful for now + + public class SimCAPSHTTPServer + { + public Thread HTTPD; + public HttpListener Listener; + + public SimCAPSHTTPServer() + { + ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server"); + HTTPD = new Thread(new ThreadStart(StartHTTP)); + HTTPD.Start(); + } + + public void StartHTTP() + { + try + { + ServerConsole.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK"); + Listener = new HttpListener(); + + Listener.Prefixes.Add("http://+:" + OpenSim_Main.cfg.IPListenPort + "/"); + Listener.Start(); + + HttpListenerContext context; + while (true) + { + context = Listener.GetContext(); + ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context); + } + } + catch (Exception e) + { + ServerConsole.MainConsole.Instance.WriteLine(e.Message); + } + } + + static string ParseXMLRPC(string requestBody) + { + try + { + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); + + Hashtable requestData = (Hashtable)request.Params[0]; + switch (request.MethodName) + { + case "expect_user": + GridServers.agentcircuitdata agent_data = new GridServers.agentcircuitdata(); + agent_data.SessionID = new LLUUID((string)requestData["session_id"]); + agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]); + agent_data.firstname = (string)requestData["firstname"]; + agent_data.lastname = (string)requestData["lastname"]; + agent_data.AgentID = new LLUUID((string)requestData["agent_id"]); + agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]); + if (OpenSim_Main.gridServers.GridServer.GetName() == "Remote") + { + ((RemoteGridBase)OpenSim_Main.gridServers.GridServer).agentcircuits.Add((uint)agent_data.circuitcode, agent_data); + } + return ""; + break; + } + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + return ""; + } + + static string ParseREST(string requestBody, string requestURL) + { + return ""; + } + + static string ParseLLSDXML(string requestBody) + { + // dummy function for now - IMPLEMENT ME! + 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 = System.Text.Encoding.UTF8; + 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 "application/xml": + // probably LLSD we hope, otherwise it should be ignored by the parser + responseString = ParseLLSDXML(requestBody); + response.AddHeader("Content-type", "application/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.UTF8.GetBytes(responseString); + System.IO.Stream output = response.OutputStream; + response.SendChunked = false; + response.ContentLength64 = buffer.Length; + output.Write(buffer, 0, buffer.Length); + output.Close(); + } + } + + +} diff --git a/src/Config.cs b/src/Config.cs index c7cd3cd4a2..d36388b412 100644 --- a/src/Config.cs +++ b/src/Config.cs @@ -35,40 +35,40 @@ using OpenSim.world; namespace OpenSim { - /// - /// This class handles connection to the underlying database used for configuration of the region. - /// Region content is also stored by this class. The main entry point is InitConfig() which attempts to locate - /// opensim.yap in the current working directory. If opensim.yap can not be found, default settings are loaded from - /// what is hardcoded here and then saved into opensim.yap for future startups. - /// - - - public abstract class SimConfig - { - public string RegionName; - - public uint RegionLocX; - public uint RegionLocY; - public ulong RegionHandle; - - public int IPListenPort; - public string IPListenAddr; - + /// + /// This class handles connection to the underlying database used for configuration of the region. + /// Region content is also stored by this class. The main entry point is InitConfig() which attempts to locate + /// opensim.yap in the current working directory. If opensim.yap can not be found, default settings are loaded from + /// what is hardcoded here and then saved into opensim.yap for future startups. + /// + + + public abstract class SimConfig + { + public string RegionName; + + public uint RegionLocX; + public uint RegionLocY; + public ulong RegionHandle; + + public int IPListenPort; + public string IPListenAddr; + public string AssetURL; - public string AssetSendKey; - - public string GridURL; - public string GridSendKey; - - public abstract void InitConfig(); - public abstract void LoadFromGrid(); - public abstract World LoadWorld(); - public abstract void SaveMap(); - - } - - public interface ISimConfig - { - SimConfig GetConfigObject(); - } + public string AssetSendKey; + + public string GridURL; + public string GridSendKey; + + public abstract void InitConfig(); + public abstract void LoadFromGrid(); + public abstract World LoadWorld(); + public abstract void SaveMap(); + + } + + public interface ISimConfig + { + SimConfig GetConfigObject(); + } } diff --git a/src/Config/SimConfig/SimConfig.csproj b/src/Config/SimConfig/SimConfig.csproj index 3131405970..98e86f1f05 100644 --- a/src/Config/SimConfig/SimConfig.csproj +++ b/src/Config/SimConfig/SimConfig.csproj @@ -8,7 +8,7 @@ {B063760D-DB8D-4F64-B6FE-335FAD1E650A} - bin\Debug\ + ..\..\..\bin\ False DEBUG;TRACE True @@ -16,7 +16,7 @@ True - bin\Release\ + ..\..\..\bin\ True TRACE False diff --git a/src/GridInterfaces/IAssetServer.cs b/src/GridInterfaces/IAssetServer.cs index 8cd18919aa..9ec83bf2be 100644 --- a/src/GridInterfaces/IAssetServer.cs +++ b/src/GridInterfaces/IAssetServer.cs @@ -34,50 +34,50 @@ using libsecondlife; namespace OpenSim.GridServers { - /// - /// Description of IAssetServer. - /// - - public interface IAssetServer - { - void SetReceiver(IAssetReceiver receiver); - void RequestAsset(LLUUID assetID, bool isTexture); - void UpdateAsset(AssetBase asset); - void UploadNewAsset(AssetBase asset); - void SetServerInfo(string ServerUrl, string ServerKey); - void Close(); - } - - // could change to delegate? - public interface IAssetReceiver - { - void AssetReceived(AssetBase asset, bool IsTexture); - void AssetNotFound(AssetBase asset); - } - - public struct ARequest - { - public LLUUID AssetID; - public bool IsTexture; - } - - public class AssetBase - { - public byte[] Data; - public LLUUID FullID; - public sbyte Type; - public sbyte InvType; - public string Name; - public string Description; - - public AssetBase() - { - - } - } - - public interface IAssetPlugin - { - IAssetServer GetAssetServer(); - } + /// + /// Description of IAssetServer. + /// + + public interface IAssetServer + { + void SetReceiver(IAssetReceiver receiver); + void RequestAsset(LLUUID assetID, bool isTexture); + void UpdateAsset(AssetBase asset); + void UploadNewAsset(AssetBase asset); + void SetServerInfo(string ServerUrl, string ServerKey); + void Close(); + } + + // could change to delegate? + public interface IAssetReceiver + { + void AssetReceived(AssetBase asset, bool IsTexture); + void AssetNotFound(AssetBase asset); + } + + public struct ARequest + { + public LLUUID AssetID; + public bool IsTexture; + } + + public class AssetBase + { + public byte[] Data; + public LLUUID FullID; + public sbyte Type; + public sbyte InvType; + public string Name; + public string Description; + + public AssetBase() + { + + } + } + + public interface IAssetPlugin + { + IAssetServer GetAssetServer(); + } } diff --git a/src/GridInterfaces/IGridServer.cs b/src/GridInterfaces/IGridServer.cs index 6f4ab110bd..983912dada 100644 --- a/src/GridInterfaces/IGridServer.cs +++ b/src/GridInterfaces/IGridServer.cs @@ -32,64 +32,105 @@ using System.Net; using System.Net.Sockets; using System.IO; using libsecondlife; +using OpenSim; namespace OpenSim.GridServers { - /// - /// Handles connection to Grid Servers. - /// also Sim to Sim connections? - /// - - - - - public interface IGridServer - { - bool RequestConnection(); - UUIDBlock RequestUUIDBlock(); - void RequestNeighbours(); //should return a array of neighbouring regions - AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); - bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); - void SetServerInfo(string ServerUrl, string ServerKey); - void Close(); - void AddNewSession(Login session); // only used by local version of grid server - // and didn't use to be part of this interface until we put this in a dll - } - - public struct UUIDBlock - { - public LLUUID BlockStart; - public LLUUID BlockEnd; - } - - public class AuthenticateResponse - { - public bool Authorised; - public Login LoginInfo; - - public AuthenticateResponse() - { - - } - - } - - public class Login + /// + /// Handles connection to Grid Servers. + /// also Sim to Sim connections? + /// + + public interface IGridServer { - public string First = "Test"; - public string Last = "User"; - public LLUUID Agent; - public LLUUID Session; - public LLUUID InventoryFolder; - public LLUUID BaseFolder; - public Login() - { - - } + UUIDBlock RequestUUIDBlock(); + void RequestNeighbours(); //should return a array of neighbouring regions + AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); + bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); + string GetName(); + bool RequestConnection(); + void SetServerInfo(string ServerUrl, string ServerKey); + void Close(); } - public interface IGridPlugin - { - IGridServer GetGridServer(); - } + public abstract class RemoteGridBase : IGridServer + { + public abstract Dictionary agentcircuits + { + get; + set; + } + + public abstract UUIDBlock RequestUUIDBlock(); + public abstract void RequestNeighbours(); + public abstract AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); + public abstract bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); + public abstract string GetName(); + public abstract bool RequestConnection(); + public abstract void SetServerInfo(string ServerUrl, string ServerKey); + public abstract void Close(); + } + + public abstract class LocalGridBase : IGridServer + { + public abstract UUIDBlock RequestUUIDBlock(); + public abstract void RequestNeighbours(); + public abstract AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); + public abstract bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); + public abstract string GetName(); + public abstract bool RequestConnection(); + public abstract void SetServerInfo(string ServerUrl, string ServerKey); + public abstract void AddNewSession(Login session); + public abstract void Close(); + } + + public struct UUIDBlock + { + public LLUUID BlockStart; + public LLUUID BlockEnd; + } + + public class AuthenticateResponse + { + public bool Authorised; + public Login LoginInfo; + + public AuthenticateResponse() + { + + } + + } + + public class Login + { + public string First = "Test"; + public string Last = "User"; + public LLUUID Agent; + public LLUUID Session; + public LLUUID InventoryFolder; + public LLUUID BaseFolder; + public Login() + { + + } + } + + public interface IGridPlugin + { + IGridServer GetGridServer(); + } + + public class agentcircuitdata + { + public agentcircuitdata() { } + public LLUUID AgentID; + public LLUUID SessionID; + public LLUUID SecureSessionID; + public string firstname; + public string lastname; + public uint circuitcode; + } + + } diff --git a/src/GridInterfaces/ILocalStorage.cs b/src/GridInterfaces/ILocalStorage.cs index 6b7ded69e8..1475c0356b 100644 --- a/src/GridInterfaces/ILocalStorage.cs +++ b/src/GridInterfaces/ILocalStorage.cs @@ -30,57 +30,57 @@ using libsecondlife; namespace GridInterfaces { - /// - /// ILocalStorage. Really hacked together right now needs cleaning up - /// - public interface ILocalStorage - { - void StorePrim(PrimData prim); - void RemovePrim(LLUUID primID); - void LoadPrimitives(ILocalStorageReceiver receiver); - void ShutDown(); - } - - public interface ILocalStorageReceiver - { - void PrimFromStorage(PrimData prim); - } - - - public class PrimData - { - public LLUUID OwnerID; - public byte PCode; - public byte PathBegin; - public byte PathEnd; - public byte PathScaleX; - public byte PathScaleY; - public byte PathShearX; - public byte PathShearY; - public sbyte PathSkew; - public byte ProfileBegin; - public byte ProfileEnd; - public LLVector3 Scale; - public byte PathCurve; - public byte ProfileCurve; - public uint ParentID=0; - public byte ProfileHollow; - public sbyte PathRadiusOffset; + /// + /// ILocalStorage. Really hacked together right now needs cleaning up + /// + public interface ILocalStorage + { + void StorePrim(PrimData prim); + void RemovePrim(LLUUID primID); + void LoadPrimitives(ILocalStorageReceiver receiver); + void ShutDown(); + } + + public interface ILocalStorageReceiver + { + void PrimFromStorage(PrimData prim); + } + + + public class PrimData + { + public LLUUID OwnerID; + public byte PCode; + public byte PathBegin; + public byte PathEnd; + public byte PathScaleX; + public byte PathScaleY; + public byte PathShearX; + public byte PathShearY; + public sbyte PathSkew; + public byte ProfileBegin; + public byte ProfileEnd; + public LLVector3 Scale; + public byte PathCurve; + public byte ProfileCurve; + public uint ParentID = 0; + public byte ProfileHollow; + public sbyte PathRadiusOffset; public byte PathRevolutions; public sbyte PathTaperX; public sbyte PathTaperY; public sbyte PathTwist; public sbyte PathTwistBegin; - + //following only used during prim storage public LLVector3 Position; - public LLQuaternion Rotation; - public uint LocalID; - public LLUUID FullID; - - public PrimData() - { - - } - } + public LLQuaternion Rotation; + public uint LocalID; + public LLUUID FullID; + + public PrimData() + { + + } + } } diff --git a/src/GridServers/LoginServer.cs b/src/GridServers/LoginServer.cs index bd6bddf4f9..f63e077bcf 100644 --- a/src/GridServers/LoginServer.cs +++ b/src/GridServers/LoginServer.cs @@ -140,7 +140,6 @@ namespace OpenSim.GridServers // ProxyLogin: proxy a login request private void LoginRequest(StreamReader reader, StreamWriter writer) { - Console.WriteLine("LoginServer - new Login attempt"); lock(this) { string line; @@ -217,6 +216,21 @@ namespace OpenSim.GridServers int SessionRand = this.RandomClass.Next(1,999); Session = new LLUUID("aaaabbbb-0200-"+SessionRand.ToString("0000")+"-8664-58f53e442797"); + //create some login info + Hashtable LoginFlagsHash = new Hashtable(); + LoginFlagsHash["daylight_savings"]="N"; + LoginFlagsHash["stipend_since_login"]="N"; + LoginFlagsHash["gendered"]="Y"; + LoginFlagsHash["ever_logged_in"]="Y"; + ArrayList LoginFlags=new ArrayList(); + LoginFlags.Add(LoginFlagsHash); + + Hashtable GlobalT = new Hashtable(); + GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271"; + GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; + GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; + ArrayList GlobalTextures = new ArrayList(); + GlobalTextures.Add(GlobalT); XmlRpcResponse response =(XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); Hashtable responseData = (Hashtable)response.Value; @@ -225,6 +239,11 @@ namespace OpenSim.GridServers responseData["sim_ip"] = OpenSim_Main.cfg.IPListenAddr; responseData["agent_id"] = Agent.ToStringHyphenated(); responseData["session_id"] = Session.ToStringHyphenated(); + responseData["seconds_since_epoch"]=(Int32)(DateTime.UtcNow - new DateTime(1970,1,1)).TotalSeconds; + responseData["login-flags"]=LoginFlags; + responseData["global-textures"]=GlobalTextures; + + //inventory ArrayList InventoryList = (ArrayList) responseData["inventory-skeleton"]; Hashtable Inventory1 = (Hashtable)InventoryList[0]; Hashtable Inventory2 = (Hashtable)InventoryList[1]; @@ -232,7 +251,7 @@ namespace OpenSim.GridServers LLUUID InventoryFolderID = LLUUID.Random(); Inventory2["name"] = "Base"; Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated(); - Inventory2["type_default"] =0; + Inventory2["type_default"] =6; Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated(); ArrayList InventoryRoot = (ArrayList) responseData["inventory-root"]; @@ -250,8 +269,11 @@ namespace OpenSim.GridServers _login.BaseFolder = BaseFolderID; _login.InventoryFolder = InventoryFolderID; - //working on local computer so lets add to the gridserver's list of sessions - this._gridServer.AddNewSession(_login); + //working on local computer if so lets add to the gridserver's list of sessions? + if(OpenSim_Main.gridServers.GridServer.GetName() == "Local") + { + ((LocalGridBase)this._gridServer).AddNewSession(_login); + } // forward the XML-RPC response to the client writer.WriteLine("HTTP/1.0 200 OK"); diff --git a/src/LocalServers/LocalGridServers/LocalGrid.cs b/src/LocalServers/LocalGridServers/LocalGrid.cs index 3106d25977..936104ec3a 100644 --- a/src/LocalServers/LocalGridServers/LocalGrid.cs +++ b/src/LocalServers/LocalGridServers/LocalGrid.cs @@ -240,7 +240,7 @@ namespace LocalGridServers } } - public class LocalGridServer :IGridServer + public class LocalGridServer : LocalGridBase { public List Sessions = new List(); @@ -250,11 +250,17 @@ namespace LocalGridServers ServerConsole.MainConsole.Instance.WriteLine("Local Grid Server class created"); } - public bool RequestConnection() + public override bool RequestConnection() { return true; } - public AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) + + public override string GetName() + { + return "Local"; + } + + public override AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) { //we are running local AuthenticateResponse user = new AuthenticateResponse(); @@ -274,36 +280,37 @@ namespace LocalGridServers return(user); } - public bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) + public override bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) { return(true); } - public UUIDBlock RequestUUIDBlock() + public override UUIDBlock RequestUUIDBlock() { UUIDBlock uuidBlock = new UUIDBlock(); return(uuidBlock); } - public void RequestNeighbours() + public override void RequestNeighbours() { return; } - public void SetServerInfo(string ServerUrl, string ServerKey) + public override void SetServerInfo(string ServerUrl, string ServerKey) { } - public void Close() + public override void Close() { } + /// /// used by the local login server to inform us of new sessions /// /// - public void AddNewSession(Login session) + public override void AddNewSession(Login session) { lock(this.Sessions) { diff --git a/src/Main.cs b/src/Main.cs index fff3dbb347..45a4782b41 100644 --- a/src/Main.cs +++ b/src/Main.cs @@ -47,295 +47,316 @@ using PhysicsSystem; namespace OpenSim { - /// - /// Description of MainForm. - /// - public class OpenSim_Main - { - public static OpenSim_Main sim; - public static SimConfig cfg; - public static World local_world; - public static Grid gridServers; - - public static Socket Server; - private static IPEndPoint ServerIncoming; - private static byte[] RecvBuffer = new byte[4096]; - private byte[] ZeroBuffer = new byte[8192]; - private static IPEndPoint ipeSender; - private static EndPoint epSender; - private static AsyncCallback ReceivedData; + /// + /// Description of MainForm. + /// + public class OpenSim_Main + { + public static OpenSim_Main sim; + public static SimConfig cfg; + public static World local_world; + public static Grid gridServers; - public AssetCache assetCache; - public InventoryManager inventoryManager; - public DateTime startuptime; - public Dictionary ClientThreads = new Dictionary(); - private PhysicsManager physManager; - private System.Timers.Timer timer1 = new System.Timers.Timer(); - private string ConfigDll = "SimConfig.dll"; - private string _physicsEngine = "PhysX"; - public bool sandbox = false; - public bool loginserver = false; - - [STAThread] - public static void Main( string[] args ) - { - Console.WriteLine("OpenSim " + VersionInfo.Version + "\n"); - Console.WriteLine("Starting...\n"); - ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local,"",0); - - sim = new OpenSim_Main(); - - for (int i = 0; i < args.Length; i++) - { - if(args[i] == "-sandbox") - { - sim.sandbox = true; - } - if(args[i] == "-loginserver") - { - sim.loginserver = true; - } - if(args[i] == "-realphysx") - { - sim._physicsEngine = "RealPhysX"; - OpenSim.world.Avatar.PhysicsEngineFlying = true; - } - } - - //sim.SetUpAssetDatabase(); - OpenSim_Main.gridServers = new Grid(); - if(sim.sandbox) - { - OpenSim_Main.gridServers.AssetDll = "LocalGridServers.dll"; - OpenSim_Main.gridServers.GridDll = "LocalGridServers.dll"; - OpenSim_Main.gridServers.LoadPlugins(); - ServerConsole.MainConsole.Instance.WriteLine("Starting in Sandbox mode"); - } - else - { - OpenSim_Main.gridServers.AssetDll = "RemoteGridServers.dll"; - OpenSim_Main.gridServers.GridDll = "RemoteGridServers.dll"; - OpenSim_Main.gridServers.LoadPlugins(); - ServerConsole.MainConsole.Instance.WriteLine("Starting in Grid mode"); - } - - if(sim.loginserver && sim.sandbox) - { - LoginServer loginServer = new LoginServer(OpenSim_Main.gridServers.GridServer); - loginServer.Startup(); - } - - sim.assetCache = new AssetCache(OpenSim_Main.gridServers.AssetServer); - sim.inventoryManager = new InventoryManager(); - - sim.Startup(); - - while(true) { - ServerConsole.MainConsole.Instance.MainConsolePrompt(); - } - } + public SimCAPSHTTPServer http_server; + public Socket Server; + private IPEndPoint ServerIncoming; + private byte[] RecvBuffer = new byte[4096]; + private byte[] ZeroBuffer = new byte[8192]; + private IPEndPoint ipeSender; + private EndPoint epSender; + private AsyncCallback ReceivedData; - private OpenSim_Main() { - } - - private void Startup() { - startuptime=DateTime.Now; - - // We check our local database first, then the grid for config options - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration"); - cfg = this.LoadConfigDll(this.ConfigDll); - cfg.InitConfig(); - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Contacting gridserver"); - cfg.LoadFromGrid(); + public AssetCache assetCache; + public InventoryManager inventoryManager; + public DateTime startuptime; + public Dictionary ClientThreads = new Dictionary(); + private PhysicsManager physManager; + private System.Timers.Timer timer1 = new System.Timers.Timer(); + private string ConfigDll = "SimConfig.dll"; + private string _physicsEngine = "PhysX"; + public bool sandbox = false; + public bool loginserver = false; - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - We are " + cfg.RegionName + " at " + cfg.RegionLocX.ToString() + "," + cfg.RegionLocY.ToString()); - ServerConsole.MainConsole.Instance.WriteLine("Initialising world"); - local_world = cfg.LoadWorld(); - - this.physManager = new PhysicsSystem.PhysicsManager(); - this.physManager.LoadPlugins(); - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting up messaging system"); - local_world.PhysScene = this.physManager.GetPhysicsScene(this._physicsEngine); //should be reading from the config file what physics engine to use - local_world.PhysScene.SetTerrain(local_world.LandMap); - - OpenSim_Main.gridServers.AssetServer.SetServerInfo(OpenSim_Main.cfg.AssetURL, OpenSim_Main.cfg.AssetSendKey); - OpenSim_Main.gridServers.GridServer.SetServerInfo(OpenSim_Main.cfg.GridURL, OpenSim_Main.cfg.GridSendKey); - - local_world.LoadStorageDLL("Db4LocalStorage.dll"); //all these dll names shouldn't be hard coded. - local_world.LoadPrimsFromStorage(); - - this.assetCache.LoadDefaultTextureSet(); - MainServerListener(); - - timer1.Enabled = true; - timer1.Interval = 100; - timer1.Elapsed +=new ElapsedEventHandler( this.Timer1Tick ); - + [STAThread] + public static void Main(string[] args) + { + Console.WriteLine("OpenSim " + VersionInfo.Version + "\n"); + Console.WriteLine("Starting...\n"); + ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local, "", 0); - } - - private SimConfig LoadConfigDll(string dllName) - { - Assembly pluginAssembly = Assembly.LoadFrom(dllName); - SimConfig config = null; - - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (pluginType.IsPublic) - { - if (!pluginType.IsAbstract) - { - Type typeInterface = pluginType.GetInterface("ISimConfig", true); - - if (typeInterface != null) - { - ISimConfig plug = (ISimConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - config = plug.GetConfigObject(); - break; - } - - typeInterface = null; - } - } - } - pluginAssembly = null; - return config; - } + sim = new OpenSim_Main(); - private void OnReceivedData(IAsyncResult result) { - ipeSender = new IPEndPoint(IPAddress.Any, 0); - epSender = (EndPoint)ipeSender; - Packet packet = null; - int numBytes = Server.EndReceiveFrom(result, ref epSender); - int packetEnd = numBytes - 1; - packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); - - // This is either a new client or a packet to send to an old one - if(ClientThreads.ContainsKey(epSender)) { - ClientThreads[epSender].InPacket(packet); - } else if( packet.Type == PacketType.UseCircuitCode ) { // new client - OpenSimClient newuser = new OpenSimClient(epSender,(UseCircuitCodePacket)packet); - ClientThreads.Add(epSender, newuser); - } else { // invalid client - Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); - } - Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); - } + sim.sandbox = false; + sim.loginserver = false; + sim._physicsEngine = "PhysX"; - private void MainServerListener() { - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - New thread started"); - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + cfg.IPListenAddr + ":" + cfg.IPListenPort); + for (int i = 0; i < args.Length; i++) + { + if (args[i] == "-sandbox") + { + sim.sandbox = true; + } - ServerIncoming = new IPEndPoint(IPAddress.Any, cfg.IPListenPort); - Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); - Server.Bind(ServerIncoming); - - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen"); + if (args[i] == "-loginserver") + { + sim.loginserver = true; + } + if (args[i] == "-realphysx") + { + sim._physicsEngine = "RealPhysX"; + OpenSim.world.Avatar.PhysicsEngineFlying = true; + } + } - ipeSender = new IPEndPoint(IPAddress.Any, 0); - epSender = (EndPoint) ipeSender; - ReceivedData = new AsyncCallback(this.OnReceivedData); - Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); - - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Listening..."); - - } - - public static void Shutdown() { - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing all threads"); - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing listener thread"); - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing clients"); - // IMPLEMENT THIS - ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing console and terminating"); - OpenSim_Main.local_world.Close(); - OpenSim_Main.gridServers.Close(); - ServerConsole.MainConsole.Instance.Close(); - Environment.Exit(0); - } - - void Timer1Tick( object sender, System.EventArgs e ) - { - - local_world.Update(); - } - } - - public class Grid - { - public IAssetServer AssetServer; - public IGridServer GridServer; - public string AssetDll = ""; - public string GridDll = ""; - - public Grid() - { - } - - public void LoadPlugins() - { - this.AssetServer = this.LoadAssetDll(this.AssetDll); - this.GridServer = this.LoadGridDll(this.GridDll); - } - - public void Close() - { - this.AssetServer.Close(); - this.GridServer.Close(); - } - private IAssetServer LoadAssetDll(string dllName) - { - Assembly pluginAssembly = Assembly.LoadFrom(dllName); - IAssetServer server = null; - - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (pluginType.IsPublic) - { - if (!pluginType.IsAbstract) - { - Type typeInterface = pluginType.GetInterface("IAssetPlugin", true); - - if (typeInterface != null) - { - IAssetPlugin plug = (IAssetPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - server = plug.GetAssetServer(); - break; - } - - typeInterface = null; - } - } - } - pluginAssembly = null; - return server; - } - - private IGridServer LoadGridDll(string dllName) - { - Assembly pluginAssembly = Assembly.LoadFrom(dllName); - IGridServer server = null; - - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (pluginType.IsPublic) - { - if (!pluginType.IsAbstract) - { - Type typeInterface = pluginType.GetInterface("IGridPlugin", true); - - if (typeInterface != null) - { - IGridPlugin plug = (IGridPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - server = plug.GetGridServer(); - break; - } - - typeInterface = null; - } - } - } - pluginAssembly = null; - return server; - } - } + OpenSim_Main.gridServers = new Grid(); + if (sim.sandbox) + { + OpenSim_Main.gridServers.AssetDll = "LocalGridServers.dll"; + OpenSim_Main.gridServers.GridDll = "LocalGridServers.dll"; + OpenSim_Main.gridServers.LoadPlugins(); + ServerConsole.MainConsole.Instance.WriteLine("Starting in Sandbox mode"); + } + else + { + OpenSim_Main.gridServers.AssetDll = "RemoteGridServers.dll"; + OpenSim_Main.gridServers.GridDll = "RemoteGridServers.dll"; + OpenSim_Main.gridServers.LoadPlugins(); + ServerConsole.MainConsole.Instance.WriteLine("Starting in Grid mode"); + } + + if (sim.loginserver && sim.sandbox) + { + LoginServer loginServer = new LoginServer(OpenSim_Main.gridServers.GridServer); + loginServer.Startup(); + } + sim.assetCache = new AssetCache(OpenSim_Main.gridServers.AssetServer); + sim.inventoryManager = new InventoryManager(); + + sim.Startup(); + + while (true) + { + ServerConsole.MainConsole.Instance.MainConsolePrompt(); + } + } + + private OpenSim_Main() + { + } + + private void Startup() + { + startuptime = DateTime.Now; + + // We check our local database first, then the grid for config options + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration"); + cfg = this.LoadConfigDll(this.ConfigDll); + cfg.InitConfig(); + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Contacting gridserver"); + cfg.LoadFromGrid(); + + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - We are " + cfg.RegionName + " at " + cfg.RegionLocX.ToString() + "," + cfg.RegionLocY.ToString()); + ServerConsole.MainConsole.Instance.WriteLine("Initialising world"); + local_world = cfg.LoadWorld(); + + this.physManager = new PhysicsSystem.PhysicsManager(); + this.physManager.LoadPlugins(); + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting up messaging system"); + local_world.PhysScene = this.physManager.GetPhysicsScene(this._physicsEngine); //should be reading from the config file what physics engine to use + local_world.PhysScene.SetTerrain(local_world.LandMap); + + OpenSim_Main.gridServers.AssetServer.SetServerInfo(OpenSim_Main.cfg.AssetURL, OpenSim_Main.cfg.AssetSendKey); + OpenSim_Main.gridServers.GridServer.SetServerInfo(OpenSim_Main.cfg.GridURL, OpenSim_Main.cfg.GridSendKey); + + local_world.LoadStorageDLL("Db4LocalStorage.dll"); //all these dll names shouldn't be hard coded. + local_world.LoadPrimsFromStorage(); + + if (this.sandbox) + { + this.assetCache.LoadDefaultTextureSet(); + } + + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting CAPS HTTP server"); + http_server = new SimCAPSHTTPServer(); + + timer1.Enabled = true; + timer1.Interval = 100; + timer1.Elapsed += new ElapsedEventHandler(this.Timer1Tick); + + MainServerListener(); + + } + + private SimConfig LoadConfigDll(string dllName) + { + Assembly pluginAssembly = Assembly.LoadFrom(dllName); + SimConfig config = null; + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("ISimConfig", true); + + if (typeInterface != null) + { + ISimConfig plug = (ISimConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + config = plug.GetConfigObject(); + break; + } + + typeInterface = null; + } + } + } + pluginAssembly = null; + return config; + } + + private void OnReceivedData(IAsyncResult result) + { + ipeSender = new IPEndPoint(IPAddress.Any, 0); + epSender = (EndPoint)ipeSender; + Packet packet = null; + int numBytes = Server.EndReceiveFrom(result, ref epSender); + int packetEnd = numBytes - 1; + packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); + + // This is either a new client or a packet to send to an old one + if (ClientThreads.ContainsKey(epSender)) + { + ClientThreads[epSender].InPacket(packet); + } + else if (packet.Type == PacketType.UseCircuitCode) + { // new client + OpenSimClient newuser = new OpenSimClient(epSender, (UseCircuitCodePacket)packet); + ClientThreads.Add(epSender, newuser); + } + else + { // invalid client + Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); + } + Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); + } + + private void MainServerListener() + { + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - New thread started"); + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + cfg.IPListenAddr + ":" + cfg.IPListenPort); + + ServerIncoming = new IPEndPoint(IPAddress.Any, cfg.IPListenPort); + Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + Server.Bind(ServerIncoming); + + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen"); + + ipeSender = new IPEndPoint(IPAddress.Any, 0); + epSender = (EndPoint)ipeSender; + ReceivedData = new AsyncCallback(this.OnReceivedData); + Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); + + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Listening..."); + + } + + public static void Shutdown() + { + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing all threads"); + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing listener thread"); + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing clients"); + // IMPLEMENT THIS + ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing console and terminating"); + OpenSim_Main.local_world.Close(); + OpenSim_Main.gridServers.Close(); + ServerConsole.MainConsole.Instance.Close(); + Environment.Exit(0); + } + + void Timer1Tick(object sender, System.EventArgs e) + { + + local_world.Update(); + } + } + + public class Grid + { + public IAssetServer AssetServer; + public IGridServer GridServer; + public string AssetDll = ""; + public string GridDll = ""; + + public Grid() + { + } + + public void LoadPlugins() + { + this.AssetServer = this.LoadAssetDll(this.AssetDll); + this.GridServer = this.LoadGridDll(this.GridDll); + } + public void Close() + { + this.AssetServer.Close(); + this.GridServer.Close(); + } + + private IAssetServer LoadAssetDll(string dllName) + { + Assembly pluginAssembly = Assembly.LoadFrom(dllName); + IAssetServer server = null; + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("IAssetPlugin", true); + + if (typeInterface != null) + { + IAssetPlugin plug = (IAssetPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + server = plug.GetAssetServer(); + break; + } + + typeInterface = null; + } + } + } + pluginAssembly = null; + return server; + } + + private IGridServer LoadGridDll(string dllName) + { + Assembly pluginAssembly = Assembly.LoadFrom(dllName); + IGridServer server = null; + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("IGridPlugin", true); + + if (typeInterface != null) + { + IGridPlugin plug = (IGridPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + server = plug.GetGridServer(); + break; + } + + typeInterface = null; + } + } + } + pluginAssembly = null; + return server; + } + } } diff --git a/src/OpenSimClient.cs b/src/OpenSimClient.cs index c6171abd22..cc8371d1ed 100644 --- a/src/OpenSimClient.cs +++ b/src/OpenSimClient.cs @@ -40,555 +40,594 @@ using OpenSim.Assets; namespace OpenSim { - /// - /// Handles new client connections - /// Constructor takes a single Packet and authenticates everything - /// - public class OpenSimClient { - - public LLUUID AgentID; - public LLUUID SessionID; - public uint CircuitCode; - public world.Avatar ClientAvatar; - private UseCircuitCodePacket cirpack; - private Thread ClientThread; - public EndPoint userEP; - private BlockingQueue PacketQueue; - private Dictionary PendingAcks = new Dictionary(); - private Dictionary NeedAck = new Dictionary(); - private Dictionary UploadedAssets = new Dictionary(); - private System.Timers.Timer AckTimer; - private uint Sequence = 0; - private object SequenceLock = new object(); - private const int MAX_APPENDED_ACKS = 10; - private const int RESEND_TIMEOUT = 4000; - private const int MAX_SEQUENCE = 0xFFFFFF; - private LLUUID newAssetFolder = LLUUID.Zero; - private bool debug = false; - - public void ack_pack(Packet Pack) { - //libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket(); - //ack_it.Packets = new PacketAckPacket.PacketsBlock[1]; - //ack_it.Packets[0] = new PacketAckPacket.PacketsBlock(); - //ack_it.Packets[0].ID = Pack.Header.ID; - //ack_it.Header.Reliable = false; + /// + /// Handles new client connections + /// Constructor takes a single Packet and authenticates everything + /// + public class OpenSimClient + { - //OutPacket(ack_it); - - if (Pack.Header.Reliable) { - lock (PendingAcks) { - uint sequence = (uint)Pack.Header.Sequence; - if (!PendingAcks.ContainsKey(sequence)) { PendingAcks[sequence] = sequence; } - } - } - } - - public void ProcessInPacket(Packet Pack) { - ack_pack(Pack); - if(debug) - { - if(Pack.Type != PacketType.AgentUpdate) - { - Console.WriteLine(Pack.Type.ToString()); - } - } - switch(Pack.Type) { - case PacketType.CompleteAgentMovement: - ClientAvatar.CompleteMovement(OpenSim_Main.local_world); - ClientAvatar.SendInitialPosition(); - break; - case PacketType.RegionHandshakeReply: - OpenSim_Main.local_world.SendLayerData(this); - break; - case PacketType.AgentWearablesRequest: - ClientAvatar.SendInitialAppearance(); - foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) { - if(client.AgentID != this.AgentID) - { - ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket(); - this.OutPacket(objupdate); - client.ClientAvatar.SendAppearanceToOtherAgent(this); - } - } - OpenSim_Main.local_world.GetInitialPrims(this); - break; - case PacketType.ObjectAdd: - OpenSim_Main.local_world.AddNewPrim((ObjectAddPacket)Pack, this); - break; - case PacketType.ObjectLink: - ServerConsole.MainConsole.Instance.WriteLine(Pack.ToString()); - break; - case PacketType.ObjectScale: - ServerConsole.MainConsole.Instance.WriteLine(Pack.ToString()); - break; - case PacketType.ObjectShape: - ObjectShapePacket shape = (ObjectShapePacket)Pack; - for(int i =0; i PacketQueue; + private Dictionary PendingAcks = new Dictionary(); + private Dictionary NeedAck = new Dictionary(); + private Dictionary UploadedAssets = new Dictionary(); + private System.Timers.Timer AckTimer; + private uint Sequence = 0; + private object SequenceLock = new object(); + private const int MAX_APPENDED_ACKS = 10; + private const int RESEND_TIMEOUT = 4000; + private const int MAX_SEQUENCE = 0xFFFFFF; + private LLUUID newAssetFolder = LLUUID.Zero; + private bool debug = false; - for( int i = 0; i < multipleupdate.ObjectData.Length; i++ ) - { - if( multipleupdate.ObjectData[ i ].Type == 9 ) //change position - { - libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[ i ].Data, 0 ); - foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) - { - if(ent.localid == multipleupdate.ObjectData[ i ].ObjectLocalID) - { - ((OpenSim.world.Primitive)ent).UpdatePosition( pos); - - } - } - - //should update stored position of the prim - } - else if(multipleupdate.ObjectData[i].Type == 10 )//rotation - { - libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true); - foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) - { - if(ent.localid == multipleupdate.ObjectData[ i ].ObjectLocalID) - { - ent.rotation = new Axiom.MathLib.Quaternion(rot.W, rot.X, rot.Y, rot.W); - ((OpenSim.world.Primitive)ent).UpdateFlag = true; - } - } - } - else if(multipleupdate.ObjectData[i].Type == 13 )//scale - { - - libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[ i ].Data, 12 ); - foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) - { - if(ent.localid == multipleupdate.ObjectData[ i ].ObjectLocalID) - { - ((OpenSim.world.Primitive)ent).Scale = scale; - } - } - } - } - break; - case PacketType.RequestImage: - RequestImagePacket imageRequest = (RequestImagePacket) Pack; - for( int i = 0; i < imageRequest.RequestImage.Length; i++ ) - { - OpenSim_Main.sim.assetCache.AddTextureRequest(this, imageRequest.RequestImage[i].Image); - } - break; - case PacketType.TransferRequest: - //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request"); - TransferRequestPacket transfer = (TransferRequestPacket)Pack; - OpenSim_Main.sim.assetCache.AddAssetRequest(this, transfer); - break; - case PacketType.AgentUpdate: - ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack); - break; - case PacketType.LogoutRequest: - ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got a logout request"); - //tell all clients to kill our object - KillObjectPacket kill = new KillObjectPacket(); - kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; - kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); - kill.ObjectData[0].ID = this.ClientAvatar.localid; - foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) { - client.OutPacket(kill); - } - OpenSim_Main.gridServers.GridServer.LogoutSession(this.SessionID, this.AgentID, this.CircuitCode); - lock(OpenSim_Main.local_world.Entities) { - OpenSim_Main.local_world.Entities.Remove(this.AgentID); - } - //need to do other cleaning up here too - OpenSim_Main.sim.ClientThreads.Remove(this.userEP); - this.ClientThread.Abort(); - break; - case PacketType.ChatFromViewer: - ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack; - if(Helpers.FieldToString(inchatpack.ChatData.Message)=="") break; + public void ack_pack(Packet Pack) + { + //libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket(); + //ack_it.Packets = new PacketAckPacket.PacketsBlock[1]; + //ack_it.Packets[0] = new PacketAckPacket.PacketsBlock(); + //ack_it.Packets[0].ID = Pack.Header.ID; + //ack_it.Header.Reliable = false; - System.Text.Encoding _enc = System.Text.Encoding.ASCII; - libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); - reply.ChatData.Audible = 1; - reply.ChatData.Message = inchatpack.ChatData.Message; - reply.ChatData.ChatType = 1; - reply.ChatData.SourceType = 1; - reply.ChatData.Position = this.ClientAvatar.position; - reply.ChatData.FromName = _enc.GetBytes(this.ClientAvatar.firstname + " " + this.ClientAvatar.lastname + "\0"); - reply.ChatData.OwnerID = this.AgentID; - reply.ChatData.SourceID = this.AgentID; - foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) { - client.OutPacket(reply); - } - break; - case PacketType.ObjectImage: - ObjectImagePacket imagePack =(ObjectImagePacket) Pack; - for(int i = 0 ; i < imagePack.ObjectData.Length; i++) - { - foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) - { - if(ent.localid == imagePack.ObjectData[i].ObjectLocalID) - { - ((OpenSim.world.Primitive)ent).UpdateTexture(imagePack.ObjectData[i].TextureEntry); - } - } - } - break; - case PacketType.ObjectFlagUpdate: - ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket) Pack; - foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) - { - if(ent.localid == flags.AgentData.ObjectLocalID) - { - ((OpenSim.world.Primitive)ent).UpdateObjectFlags(flags); - } - } + //OutPacket(ack_it); + + if (Pack.Header.Reliable) + { + lock (PendingAcks) + { + uint sequence = (uint)Pack.Header.Sequence; + if (!PendingAcks.ContainsKey(sequence)) { PendingAcks[sequence] = sequence; } + } + } + } + + public void ProcessInPacket(Packet Pack) + { + ack_pack(Pack); + if (debug) + { + if (Pack.Type != PacketType.AgentUpdate) + { + Console.WriteLine(Pack.Type.ToString()); + } + } + switch (Pack.Type) + { + case PacketType.CompleteAgentMovement: + ClientAvatar.CompleteMovement(OpenSim_Main.local_world); + ClientAvatar.SendInitialPosition(); + break; + case PacketType.RegionHandshakeReply: + OpenSim_Main.local_world.SendLayerData(this); + break; + case PacketType.AgentWearablesRequest: + ClientAvatar.SendInitialAppearance(); + foreach (OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) + { + if (client.AgentID != this.AgentID) + { + ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket(); + this.OutPacket(objupdate); + client.ClientAvatar.SendAppearanceToOtherAgent(this); + } + } + OpenSim_Main.local_world.GetInitialPrims(this); + break; + case PacketType.ObjectAdd: + OpenSim_Main.local_world.AddNewPrim((ObjectAddPacket)Pack, this); + break; + case PacketType.ObjectLink: + ServerConsole.MainConsole.Instance.WriteLine(Pack.ToString()); + break; + case PacketType.ObjectScale: + ServerConsole.MainConsole.Instance.WriteLine(Pack.ToString()); + break; + case PacketType.ObjectShape: + ObjectShapePacket shape = (ObjectShapePacket)Pack; + for (int i = 0; i < shape.ObjectData.Length; i++) + { + foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) + { + if (ent.localid == shape.ObjectData[i].ObjectLocalID) + { + ((OpenSim.world.Primitive)ent).UpdateShape(shape.ObjectData[i]); + } + } + } + break; + case PacketType.MultipleObjectUpdate: + MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)Pack; + + for (int i = 0; i < multipleupdate.ObjectData.Length; i++) + { + if (multipleupdate.ObjectData[i].Type == 9) //change position + { + libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); + foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) + { + if (ent.localid == multipleupdate.ObjectData[i].ObjectLocalID) + { + ((OpenSim.world.Primitive)ent).UpdatePosition(pos); + + } + } + + //should update stored position of the prim + } + else if (multipleupdate.ObjectData[i].Type == 10)//rotation + { + libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true); + foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) + { + if (ent.localid == multipleupdate.ObjectData[i].ObjectLocalID) + { + ent.rotation = new Axiom.MathLib.Quaternion(rot.W, rot.X, rot.Y, rot.W); + ((OpenSim.world.Primitive)ent).UpdateFlag = true; + } + } + } + else if (multipleupdate.ObjectData[i].Type == 13)//scale + { + + libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12); + foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) + { + if (ent.localid == multipleupdate.ObjectData[i].ObjectLocalID) + { + ((OpenSim.world.Primitive)ent).Scale = scale; + } + } + } + } + break; + case PacketType.RequestImage: + RequestImagePacket imageRequest = (RequestImagePacket)Pack; + for (int i = 0; i < imageRequest.RequestImage.Length; i++) + { + OpenSim_Main.sim.assetCache.AddTextureRequest(this, imageRequest.RequestImage[i].Image); + } + break; + case PacketType.TransferRequest: + //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request"); + TransferRequestPacket transfer = (TransferRequestPacket)Pack; + OpenSim_Main.sim.assetCache.AddAssetRequest(this, transfer); + break; + case PacketType.AgentUpdate: + ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack); + break; + case PacketType.LogoutRequest: + ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got a logout request"); + //send reply to let the client logout + LogoutReplyPacket logReply = new LogoutReplyPacket(); + logReply.AgentData.AgentID = this.AgentID; + logReply.AgentData.SessionID = this.SessionID; + logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1]; + logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock(); + logReply.InventoryData[0].ItemID = LLUUID.Zero; + OutPacket(logReply); + //tell all clients to kill our object + KillObjectPacket kill = new KillObjectPacket(); + kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; + kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); + kill.ObjectData[0].ID = this.ClientAvatar.localid; + foreach (OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) + { + client.OutPacket(kill); + } + OpenSim_Main.gridServers.GridServer.LogoutSession(this.SessionID, this.AgentID, this.CircuitCode); + lock (OpenSim_Main.local_world.Entities) + { + OpenSim_Main.local_world.Entities.Remove(this.AgentID); + } + //need to do other cleaning up here too + OpenSim_Main.sim.ClientThreads.Remove(this.userEP); + this.ClientThread.Abort(); + break; + case PacketType.ChatFromViewer: + ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack; + if (Helpers.FieldToString(inchatpack.ChatData.Message) == "") break; + + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); + reply.ChatData.Audible = 1; + reply.ChatData.Message = inchatpack.ChatData.Message; + reply.ChatData.ChatType = 1; + reply.ChatData.SourceType = 1; + reply.ChatData.Position = this.ClientAvatar.position; + reply.ChatData.FromName = _enc.GetBytes(this.ClientAvatar.firstname + " " + this.ClientAvatar.lastname + "\0"); + reply.ChatData.OwnerID = this.AgentID; + reply.ChatData.SourceID = this.AgentID; + foreach (OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) + { + client.OutPacket(reply); + } + break; + case PacketType.ObjectImage: + ObjectImagePacket imagePack = (ObjectImagePacket)Pack; + for (int i = 0; i < imagePack.ObjectData.Length; i++) + { + foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) + { + if (ent.localid == imagePack.ObjectData[i].ObjectLocalID) + { + ((OpenSim.world.Primitive)ent).UpdateTexture(imagePack.ObjectData[i].TextureEntry); + } + } + } + break; + case PacketType.ObjectFlagUpdate: + ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack; + foreach (Entity ent in OpenSim_Main.local_world.Entities.Values) + { + if (ent.localid == flags.AgentData.ObjectLocalID) + { + ((OpenSim.world.Primitive)ent).UpdateObjectFlags(flags); + } + } + + break; + case PacketType.AssetUploadRequest: + //AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack; + //Console.WriteLine("upload request "+ request.AssetBlock.TransactionID); + //AssetBase newAsset = OpenSim_Main.sim.assetCache.UploadPacket(request); + //Console.WriteLine(request.ToString()); + + /*if(newAsset != null) + { + if(!this.UploadedAssets.ContainsKey(newAsset.FullID)) + { + this.UploadedAssets.Add(newAsset.FullID, newAsset); + } + }*/ + /*AssetUploadCompletePacket response = new AssetUploadCompletePacket(); + response.AssetBlock.Type =request.AssetBlock.Type; + response.AssetBlock.Success = false; + response.AssetBlock.UUID = request.AssetBlock.TransactionID; - break; - case PacketType.AssetUploadRequest: - //AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack; - //Console.WriteLine("upload request "+ request.AssetBlock.TransactionID); - //AssetBase newAsset = OpenSim_Main.sim.assetCache.UploadPacket(request); - //Console.WriteLine(request.ToString()); - - /*if(newAsset != null) - { - if(!this.UploadedAssets.ContainsKey(newAsset.FullID)) - { - this.UploadedAssets.Add(newAsset.FullID, newAsset); - } - }*/ - /*AssetUploadCompletePacket response = new AssetUploadCompletePacket(); - response.AssetBlock.Type =request.AssetBlock.Type; - response.AssetBlock.Success = false; - response.AssetBlock.UUID = request.AssetBlock.TransactionID; - - this.OutPacket(response);*/ - break; - case PacketType.AssetUploadComplete: - //AssetUploadCompletePacket complete = (AssetUploadCompletePacket)Pack; - //Console.WriteLine("upload complete "+ complete.AssetBlock.UUID); - - /*AssetBase completedAsset = OpenSim_Main.sim.assetCache.TransactionComplete(complete.AssetBlock.UUID); - if(completedAsset != null) - { - if(!this.UploadedAssets.ContainsKey(completedAsset.FullID)) - { - this.UploadedAssets.Remove(completedAsset.FullID); - if(this.newAssetFolder != LLUUID.Zero) - { - OpenSim_Main.sim.inventoryManager.AddNewInventoryItem(this, this.newAssetFolder, completedAsset); - } - } - } */ - break; - case PacketType.CreateInventoryFolder: - Console.WriteLine(Pack.ToString()); - break; - case PacketType.CreateInventoryItem: - Console.WriteLine(Pack.ToString()); - break; - case PacketType.FetchInventory: - Console.WriteLine("fetch item packet"); - FetchInventoryPacket FetchInventory = (FetchInventoryPacket)Pack; - OpenSim_Main.sim.inventoryManager.FetchInventory(this, FetchInventory); - break; - case PacketType.FetchInventoryDescendents: - FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack; - OpenSim_Main.sim.inventoryManager.FetchInventoryDescendents(this, Fetch); - break; - } - } + this.OutPacket(response);*/ + break; + case PacketType.AssetUploadComplete: + //AssetUploadCompletePacket complete = (AssetUploadCompletePacket)Pack; + //Console.WriteLine("upload complete "+ complete.AssetBlock.UUID); - private void ResendUnacked() - { - int now = Environment.TickCount; + /*AssetBase completedAsset = OpenSim_Main.sim.assetCache.TransactionComplete(complete.AssetBlock.UUID); + if(completedAsset != null) + { + if(!this.UploadedAssets.ContainsKey(completedAsset.FullID)) + { + this.UploadedAssets.Remove(completedAsset.FullID); + if(this.newAssetFolder != LLUUID.Zero) + { + OpenSim_Main.sim.inventoryManager.AddNewInventoryItem(this, this.newAssetFolder, completedAsset); + } + } + } */ + break; + case PacketType.CreateInventoryFolder: + Console.WriteLine(Pack.ToString()); + break; + case PacketType.CreateInventoryItem: + Console.WriteLine(Pack.ToString()); + break; + case PacketType.FetchInventory: + Console.WriteLine("fetch item packet"); + FetchInventoryPacket FetchInventory = (FetchInventoryPacket)Pack; + OpenSim_Main.sim.inventoryManager.FetchInventory(this, FetchInventory); + break; + case PacketType.FetchInventoryDescendents: + FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack; + OpenSim_Main.sim.inventoryManager.FetchInventoryDescendents(this, Fetch); + break; + } + } - lock (NeedAck) - { - foreach (Packet packet in NeedAck.Values) - { - if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent)) - { - ServerConsole.MainConsole.Instance.WriteLine("Resending " + packet.Type.ToString() + " packet, " + - (now - packet.TickCount) + "ms have passed"); + private void ResendUnacked() + { + int now = Environment.TickCount; - packet.Header.Resent = true; - OutPacket(packet); - } - } - } - } + lock (NeedAck) + { + foreach (Packet packet in NeedAck.Values) + { + if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent)) + { + ServerConsole.MainConsole.Instance.WriteLine("Resending " + packet.Type.ToString() + " packet, " + + (now - packet.TickCount) + "ms have passed"); - private void SendAcks() - { - lock (PendingAcks) - { - if (PendingAcks.Count > 0) - { - if (PendingAcks.Count > 250) - { - // FIXME: Handle the odd case where we have too many pending ACKs queued up - ServerConsole.MainConsole.Instance.WriteLine("Too many ACKs queued up!"); - return; - } - - ServerConsole.MainConsole.Instance.WriteLine("Sending PacketAck"); - + packet.Header.Resent = true; + OutPacket(packet); + } + } + } + } - int i = 0; - PacketAckPacket acks = new PacketAckPacket(); - acks.Packets = new PacketAckPacket.PacketsBlock[PendingAcks.Count]; + private void SendAcks() + { + lock (PendingAcks) + { + if (PendingAcks.Count > 0) + { + if (PendingAcks.Count > 250) + { + // FIXME: Handle the odd case where we have too many pending ACKs queued up + ServerConsole.MainConsole.Instance.WriteLine("Too many ACKs queued up!"); + return; + } - foreach (uint ack in PendingAcks.Values) - { - acks.Packets[i] = new PacketAckPacket.PacketsBlock(); - acks.Packets[i].ID = ack; - i++; - } + ServerConsole.MainConsole.Instance.WriteLine("Sending PacketAck"); - acks.Header.Reliable = false; - OutPacket(acks); - PendingAcks.Clear(); - } - } - } + int i = 0; + PacketAckPacket acks = new PacketAckPacket(); + acks.Packets = new PacketAckPacket.PacketsBlock[PendingAcks.Count]; - private void AckTimer_Elapsed(object sender, ElapsedEventArgs ea) - { - SendAcks(); - ResendUnacked(); - } + foreach (uint ack in PendingAcks.Values) + { + acks.Packets[i] = new PacketAckPacket.PacketsBlock(); + acks.Packets[i].ID = ack; + i++; + } - public void ProcessOutPacket(Packet Pack) { - - // Keep track of when this packet was sent out - Pack.TickCount = Environment.TickCount; + acks.Header.Reliable = false; + OutPacket(acks); - if (!Pack.Header.Resent) - { - // Set the sequence number - lock (SequenceLock) - { - if (Sequence >= MAX_SEQUENCE) - Sequence = 1; - else - Sequence++; - Pack.Header.Sequence = Sequence; - } + PendingAcks.Clear(); + } + } + } - if (Pack.Header.Reliable) //DIRTY HACK - { - lock (NeedAck) - { - if (!NeedAck.ContainsKey(Pack.Header.Sequence)) - { - NeedAck.Add(Pack.Header.Sequence, Pack); - } - else - { - // Client.Log("Attempted to add a duplicate sequence number (" + - // packet.Header.Sequence + ") to the NeedAck dictionary for packet type " + - // packet.Type.ToString(), Helpers.LogLevel.Warning); - } - } + private void AckTimer_Elapsed(object sender, ElapsedEventArgs ea) + { + SendAcks(); + ResendUnacked(); + } - // Don't append ACKs to resent packets, in case that's what was causing the - // delivery to fail - if (!Pack.Header.Resent) - { - // Append any ACKs that need to be sent out to this packet - lock (PendingAcks) - { - if (PendingAcks.Count > 0 && PendingAcks.Count < MAX_APPENDED_ACKS && - Pack.Type != PacketType.PacketAck && - Pack.Type != PacketType.LogoutRequest) - { - Pack.Header.AckList = new uint[PendingAcks.Count]; - int i = 0; - - foreach (uint ack in PendingAcks.Values) - { - Pack.Header.AckList[i] = ack; - i++; - } + public void ProcessOutPacket(Packet Pack) + { - PendingAcks.Clear(); - Pack.Header.AppendedAcks = true; - } - } - } - } - } + // Keep track of when this packet was sent out + Pack.TickCount = Environment.TickCount; - //ServerConsole.MainConsole.Instance.WriteLine("OUT: \n" + Pack.ToString()); + if (!Pack.Header.Resent) + { + // Set the sequence number + lock (SequenceLock) + { + if (Sequence >= MAX_SEQUENCE) + Sequence = 1; + else + Sequence++; + Pack.Header.Sequence = Sequence; + } - byte[] ZeroOutBuffer = new byte[4096]; - byte[] sendbuffer; - sendbuffer = Pack.ToBytes(); + if (Pack.Header.Reliable) //DIRTY HACK + { + lock (NeedAck) + { + if (!NeedAck.ContainsKey(Pack.Header.Sequence)) + { + NeedAck.Add(Pack.Header.Sequence, Pack); + } + else + { + // Client.Log("Attempted to add a duplicate sequence number (" + + // packet.Header.Sequence + ") to the NeedAck dictionary for packet type " + + // packet.Type.ToString(), Helpers.LogLevel.Warning); + } + } - try { - if (Pack.Header.Zerocoded) { - int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); - OpenSim_Main.Server.SendTo(ZeroOutBuffer, packetsize, SocketFlags.None,userEP); - } else { - OpenSim_Main.Server.SendTo(sendbuffer, sendbuffer.Length, SocketFlags.None,userEP); - } - } catch (Exception) { - ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread"); - ClientThread.Abort(); - } - - } + // Don't append ACKs to resent packets, in case that's what was causing the + // delivery to fail + if (!Pack.Header.Resent) + { + // Append any ACKs that need to be sent out to this packet + lock (PendingAcks) + { + if (PendingAcks.Count > 0 && PendingAcks.Count < MAX_APPENDED_ACKS && + Pack.Type != PacketType.PacketAck && + Pack.Type != PacketType.LogoutRequest) + { + Pack.Header.AckList = new uint[PendingAcks.Count]; + int i = 0; - public void InPacket(Packet NewPack) { - // Handle appended ACKs - if (NewPack.Header.AppendedAcks) - { - lock (NeedAck) - { - foreach (uint ack in NewPack.Header.AckList) - { - NeedAck.Remove(ack); - } - } - } + foreach (uint ack in PendingAcks.Values) + { + Pack.Header.AckList[i] = ack; + i++; + } - // Handle PacketAck packets - if (NewPack.Type == PacketType.PacketAck) - { - PacketAckPacket ackPacket = (PacketAckPacket)NewPack; + PendingAcks.Clear(); + Pack.Header.AppendedAcks = true; + } + } + } + } + } - lock (NeedAck) - { - foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets) - { - NeedAck.Remove(block.ID); - } - } - } else if( ( NewPack.Type == PacketType.StartPingCheck ) ) { - //reply to pingcheck - libsecondlife.Packets.StartPingCheckPacket startPing = (libsecondlife.Packets.StartPingCheckPacket)NewPack; - libsecondlife.Packets.CompletePingCheckPacket endPing = new CompletePingCheckPacket(); - endPing.PingID.PingID = startPing.PingID.PingID; - OutPacket(endPing); - } - else - { - QueItem item = new QueItem(); - item.Packet = NewPack; - item.Incoming = true; - this.PacketQueue.Enqueue(item); - } - - } + //ServerConsole.MainConsole.Instance.WriteLine("OUT: \n" + Pack.ToString()); - public void OutPacket(Packet NewPack) { - QueItem item = new QueItem(); - item.Packet = NewPack; - item.Incoming = false; - this.PacketQueue.Enqueue(item); - } + byte[] ZeroOutBuffer = new byte[4096]; + byte[] sendbuffer; + sendbuffer = Pack.ToBytes(); - public OpenSimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack) { - ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request"); - cirpack = initialcirpack; - userEP = remoteEP; - PacketQueue = new BlockingQueue(); - AckTimer = new System.Timers.Timer(500); - AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); - AckTimer.Start(); + try + { + if (Pack.Header.Zerocoded) + { + int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); + OpenSim_Main.sim.Server.SendTo(ZeroOutBuffer, packetsize, SocketFlags.None, userEP); + } + else + { + OpenSim_Main.sim.Server.SendTo(sendbuffer, sendbuffer.Length, SocketFlags.None, userEP); + } + } + catch (Exception) + { + ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread"); + ClientThread.Abort(); + } - ClientThread = new Thread(new ThreadStart(AuthUser)); - ClientThread.IsBackground = true; - ClientThread.Start(); - } - - private void ClientLoop() { - ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:ClientLoop() - Entered loop"); - while(true) { - QueItem nextPacket = PacketQueue.Dequeue(); - if(nextPacket.Incoming) - { - //is a incoming packet - ProcessInPacket(nextPacket.Packet); - } - else - { - //is a out going packet - ProcessOutPacket(nextPacket.Packet); - } - } - } + } - private void InitNewClient() { - ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:InitNewClient() - Adding viewer agent to world"); - OpenSim_Main.local_world.AddViewerAgent(this); - world.Entity tempent=OpenSim_Main.local_world.Entities[this.AgentID]; - this.ClientAvatar=(world.Avatar)tempent; - } - - private void AuthUser() - { - AuthenticateResponse sessionInfo = OpenSim_Main.gridServers.GridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code); - if(!sessionInfo.Authorised) - { - //session/circuit not authorised - ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString()); - ClientThread.Abort(); - } - else - { - ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString()); - //session is authorised - this.AgentID=cirpack.CircuitCode.ID; - this.SessionID=cirpack.CircuitCode.SessionID; - this.CircuitCode=cirpack.CircuitCode.Code; - InitNewClient(); - this.ClientAvatar.firstname = sessionInfo.LoginInfo.First; - this.ClientAvatar.lastname = sessionInfo.LoginInfo.Last; - if(sessionInfo.LoginInfo.InventoryFolder != null) - { - this.CreateInventory(sessionInfo.LoginInfo.InventoryFolder); - if(sessionInfo.LoginInfo.BaseFolder != null) - { - OpenSim_Main.sim.inventoryManager.CreateNewInventoryFolder(this, sessionInfo.LoginInfo.BaseFolder); - this.newAssetFolder = sessionInfo.LoginInfo.BaseFolder; - AssetBase[] inventorySet = OpenSim_Main.sim.assetCache.CreateNewInventorySet(this.AgentID); - if(inventorySet != null) - { - for( int i = 0; i < inventorySet.Length; i++) - { - if(inventorySet[i] != null) - { - Console.WriteLine(Helpers.FieldToString(inventorySet[i].Data)); - OpenSim_Main.sim.inventoryManager.AddNewInventoryItem(this, sessionInfo.LoginInfo.BaseFolder, inventorySet[i]); - } - } - } - } - } - ClientLoop(); - } - } - - private void CreateInventory(LLUUID baseFolder) - { - AgentInventory inventory = new AgentInventory(); - inventory.AgentID = this.AgentID; - OpenSim_Main.sim.inventoryManager.AddNewAgentsInventory(inventory); - OpenSim_Main.sim.inventoryManager.CreateNewInventoryFolder(this, baseFolder); - } - } + public void InPacket(Packet NewPack) + { + // Handle appended ACKs + if (NewPack.Header.AppendedAcks) + { + lock (NeedAck) + { + foreach (uint ack in NewPack.Header.AckList) + { + NeedAck.Remove(ack); + } + } + } + + // Handle PacketAck packets + if (NewPack.Type == PacketType.PacketAck) + { + PacketAckPacket ackPacket = (PacketAckPacket)NewPack; + + lock (NeedAck) + { + foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets) + { + NeedAck.Remove(block.ID); + } + } + } + else if ((NewPack.Type == PacketType.StartPingCheck)) + { + //reply to pingcheck + libsecondlife.Packets.StartPingCheckPacket startPing = (libsecondlife.Packets.StartPingCheckPacket)NewPack; + libsecondlife.Packets.CompletePingCheckPacket endPing = new CompletePingCheckPacket(); + endPing.PingID.PingID = startPing.PingID.PingID; + OutPacket(endPing); + } + else + { + QueItem item = new QueItem(); + item.Packet = NewPack; + item.Incoming = true; + this.PacketQueue.Enqueue(item); + } + + } + + public void OutPacket(Packet NewPack) + { + QueItem item = new QueItem(); + item.Packet = NewPack; + item.Incoming = false; + this.PacketQueue.Enqueue(item); + } + + public OpenSimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack) + { + ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request"); + cirpack = initialcirpack; + userEP = remoteEP; + PacketQueue = new BlockingQueue(); + AckTimer = new System.Timers.Timer(500); + AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); + AckTimer.Start(); + + ClientThread = new Thread(new ThreadStart(AuthUser)); + ClientThread.IsBackground = true; + ClientThread.Start(); + } + + private void ClientLoop() + { + ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:ClientLoop() - Entered loop"); + while (true) + { + QueItem nextPacket = PacketQueue.Dequeue(); + if (nextPacket.Incoming) + { + //is a incoming packet + ProcessInPacket(nextPacket.Packet); + } + else + { + //is a out going packet + ProcessOutPacket(nextPacket.Packet); + } + } + } + + private void InitNewClient() + { + ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:InitNewClient() - Adding viewer agent to world"); + OpenSim_Main.local_world.AddViewerAgent(this); + world.Entity tempent = OpenSim_Main.local_world.Entities[this.AgentID]; + this.ClientAvatar = (world.Avatar)tempent; + } + + private void AuthUser() + { + AuthenticateResponse sessionInfo = OpenSim_Main.gridServers.GridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code); + if (!sessionInfo.Authorised) + { + //session/circuit not authorised + ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString()); + ClientThread.Abort(); + } + else + { + ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString()); + //session is authorised + this.AgentID = cirpack.CircuitCode.ID; + this.SessionID = cirpack.CircuitCode.SessionID; + this.CircuitCode = cirpack.CircuitCode.Code; + InitNewClient(); + this.ClientAvatar.firstname = sessionInfo.LoginInfo.First; + this.ClientAvatar.lastname = sessionInfo.LoginInfo.Last; + + // Create Inventory, currently only works for sandbox mode + if (OpenSim_Main.sim.sandbox) + { + if (sessionInfo.LoginInfo.InventoryFolder != null) + { + this.CreateInventory(sessionInfo.LoginInfo.InventoryFolder); + if (sessionInfo.LoginInfo.BaseFolder != null) + { + OpenSim_Main.sim.inventoryManager.CreateNewInventoryFolder(this, sessionInfo.LoginInfo.BaseFolder); + this.newAssetFolder = sessionInfo.LoginInfo.BaseFolder; + AssetBase[] inventorySet = OpenSim_Main.sim.assetCache.CreateNewInventorySet(this.AgentID); + if (inventorySet != null) + { + for (int i = 0; i < inventorySet.Length; i++) + { + if (inventorySet[i] != null) + { + Console.WriteLine(Helpers.FieldToString(inventorySet[i].Data)); + OpenSim_Main.sim.inventoryManager.AddNewInventoryItem(this, sessionInfo.LoginInfo.BaseFolder, inventorySet[i]); + } + } + } + } + } + } + + ClientLoop(); + } + } + + private void CreateInventory(LLUUID baseFolder) + { + AgentInventory inventory = new AgentInventory(); + inventory.AgentID = this.AgentID; + OpenSim_Main.sim.inventoryManager.AddNewAgentsInventory(inventory); + OpenSim_Main.sim.inventoryManager.CreateNewInventoryFolder(this, baseFolder); + } + } } diff --git a/src/OpenSimConsole.cs b/src/OpenSimConsole.cs index 11bc648727..cf8b648330 100644 --- a/src/OpenSimConsole.cs +++ b/src/OpenSimConsole.cs @@ -61,6 +61,7 @@ namespace OpenSim ConsType = constype; switch(constype) { case ConsoleType.Local: + Console.WriteLine("ServerConsole.cs - creating new local console"); Console.WriteLine("Logs will be saved to current directory in opensim-console.log"); Log=File.AppendText("opensim-console.log"); @@ -75,22 +76,30 @@ namespace OpenSim default: Console.WriteLine("ServerConsole.cs - what are you smoking? that isn't a valid console type!"); break; - } + } } public override void Close() { Log.WriteLine("OpenSim shutdown at " + DateTime.Now.ToString()); Log.Close(); } - - // You know what ReadLine() and WriteLine() do, right? And Read() and Write()? Right, you do actually know C#, right? Are you actually a programmer? Do you know english? Do you find my sense of humour in comments irritating? Good, glad you're still here - public override void WriteLine(string Line) { - Log.WriteLine(Line); - Console.WriteLine(Line); - return; - } - - public override string ReadLine() { + + public override void Write(string format, params object[] args) + { + Log.Write(format, args); + Console.Write(format, args); + return; + } + + public override void WriteLine(string format, params object[] args) + { + Log.WriteLine(format, args); + Console.WriteLine(format, args); + return; + } + + public override string ReadLine() + { string TempStr=Console.ReadLine(); Log.WriteLine(TempStr); return TempStr; @@ -102,12 +111,6 @@ namespace OpenSim return TempInt; } - public override void Write(string Line) { - Console.Write(Line); - Log.Write(Line); - return; - } - // Displays a command prompt and waits for the user to enter a string, then returns that string public override string CmdPrompt(string prompt) { this.Write(prompt); @@ -172,7 +175,7 @@ namespace OpenSim break; case "users": OpenSim.world.Avatar TempAv; - this.WriteLine(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}","Firstname", "Lastname","Agent ID", "Session ID", "Circuit", "IP")); + this.WriteLine(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}","Firstname", "Lastname","Agent ID", "Session ID", "Circuit", "IP")); foreach (libsecondlife.LLUUID UUID in OpenSim_Main.local_world.Entities.Keys) { if(OpenSim_Main.local_world.Entities[UUID].ToString()== "OpenSim.world.Avatar") { @@ -196,7 +199,13 @@ namespace OpenSim string[] cmdparams=(string[])tempstrarray; RunCmd(cmd,cmdparams); } - } + + + public override void SetStatus(string status) + { + Console.Write( status + "\r" ); + } + } } diff --git a/src/RemoteServers/RemoteGridServers/RemoteGrid.cs b/src/RemoteServers/RemoteGridServers/RemoteGrid.cs index 5d2d6e7b35..a537c39bfa 100644 --- a/src/RemoteServers/RemoteGridServers/RemoteGrid.cs +++ b/src/RemoteServers/RemoteGridServers/RemoteGrid.cs @@ -35,216 +35,234 @@ using OpenSim.GridServers; namespace RemoteGridServers { - /// - /// - /// - /// - - public class RemoteGridPlugin : IGridPlugin - { - public RemoteGridPlugin() - { - - } - - public IGridServer GetGridServer() - { - return(new RemoteGridServer()); - } - } - - public class RemoteAssetPlugin : IAssetPlugin - { - public RemoteAssetPlugin() - { - - } - - public IAssetServer GetAssetServer() - { - return(new RemoteAssetServer()); - } - } - public class RemoteGridServer :IGridServer - { - private string GridServerUrl; - private string GridSendKey; - - public RemoteGridServer() - { - ServerConsole.MainConsole.Instance.WriteLine("Remote Grid Server class created"); - } - - public bool RequestConnection() - { - return true; - } - public AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) - { - AuthenticateResponse user = new AuthenticateResponse(); - - WebRequest CheckSession = WebRequest.Create(GridServerUrl + "/usersessions/" + GridSendKey + "/" + agentID.ToString() + "/" + circuitCode.ToString() + "/exists"); - WebResponse GridResponse = CheckSession.GetResponse(); - StreamReader sr = new StreamReader(GridResponse.GetResponseStream()); - String grTest = sr.ReadLine(); - sr.Close(); - GridResponse.Close(); - if(String.IsNullOrEmpty(grTest) || grTest.Equals("1")) - { - // YAY! Valid login - user.Authorised = true; - user.LoginInfo = new Login(); - user.LoginInfo.Agent = agentID; - user.LoginInfo.Session = sessionID; - user.LoginInfo.First = ""; - user.LoginInfo.Last = ""; - - } - else - { - // Invalid - user.Authorised = false; - } - - return(user); - } - - public bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) - { - WebRequest DeleteSession = WebRequest.Create(GridServerUrl + "/usersessions/" + GridSendKey + "/" + agentID.ToString() + "/" + circuitCode.ToString() + "/delete"); - WebResponse GridResponse = DeleteSession.GetResponse(); - StreamReader sr = new StreamReader(GridResponse.GetResponseStream()); - String grTest = sr.ReadLine(); - sr.Close(); - GridResponse.Close(); - ServerConsole.MainConsole.Instance.WriteLine("DEBUG: " + grTest); - return(true); - } - - public UUIDBlock RequestUUIDBlock() - { - UUIDBlock uuidBlock = new UUIDBlock(); - return(uuidBlock); - } - - public void RequestNeighbours() - { - return; - } - - public void SetServerInfo(string ServerUrl, string ServerKey) - { - this.GridServerUrl = ServerUrl; - this.GridSendKey = ServerKey; - } - - public void Close() - { - - } - - public void AddNewSession(Login session) - { - - } - } - - - public class RemoteAssetServer : IAssetServer - { - private IAssetReceiver _receiver; - private BlockingQueue _assetRequests; - private Thread _remoteAssetServerThread; - private string AssetServerUrl; - private string AssetSendKey; - - public RemoteAssetServer() - { - this._assetRequests = new BlockingQueue(); - this._remoteAssetServerThread = new Thread(new ThreadStart(RunRequests)); - this._remoteAssetServerThread.IsBackground = true; - this._remoteAssetServerThread.Start(); - ServerConsole.MainConsole.Instance.WriteLine("Remote Asset Server class created"); - } - - public void SetReceiver(IAssetReceiver receiver) - { - this._receiver = receiver; - } - - public void RequestAsset(LLUUID assetID, bool isTexture) - { - ARequest req = new ARequest(); - req.AssetID = assetID; - req.IsTexture = isTexture; - this._assetRequests.Enqueue(req); - } - - public void UpdateAsset(AssetBase asset) - { - - } - - public void UploadNewAsset(AssetBase asset) - { - - } - - public void SetServerInfo(string ServerUrl, string ServerKey) - { - this.AssetServerUrl = ServerUrl; - this.AssetSendKey = ServerKey; - } - - public void Close() - { - - } - private void RunRequests() - { - while(true) - { - //we need to add support for the asset server not knowing about a requested asset - ARequest req = this._assetRequests.Dequeue(); - LLUUID assetID = req.AssetID; - ServerConsole.MainConsole.Instance.WriteLine(" RemoteAssetServer- Got a AssetServer request, processing it"); - WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "getasset/" + AssetSendKey + "/" + assetID + "/data"); - WebResponse AssetResponse = AssetLoad.GetResponse(); - byte[] idata = new byte[(int)AssetResponse.ContentLength]; - BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream()); - idata = br.ReadBytes((int)AssetResponse.ContentLength); - br.Close(); - - AssetBase asset = new AssetBase(); - asset.FullID = assetID; - asset.Data = idata; - _receiver.AssetReceived(asset, req.IsTexture ); - } - } - } - - 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 class RemoteGridPlugin : IGridPlugin + { + public RemoteGridPlugin() + { - public T Dequeue() - { - lock(_queueSync) - { - if( _queue.Count < 1) - Monitor.Wait(_queueSync); + } - return _queue.Dequeue(); - } - } - } + public IGridServer GetGridServer() + { + return (new RemoteGridServer()); + } + } + + public class RemoteAssetPlugin : IAssetPlugin + { + public RemoteAssetPlugin() + { + + } + + public IAssetServer GetAssetServer() + { + return (new RemoteAssetServer()); + } + } + public class RemoteGridServer : RemoteGridBase + { + private string GridServerUrl; + private string GridSendKey; + private Dictionary AgentCircuits = new Dictionary(); + + public override Dictionary agentcircuits + { + get { return AgentCircuits; } + set { AgentCircuits = value; } + } + + public RemoteGridServer() + { + ServerConsole.MainConsole.Instance.WriteLine("Remote Grid Server class created"); + } + + public override bool RequestConnection() + { + return true; + } + + public override AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitcode) + { + agentcircuitdata validcircuit = null; + if (this.AgentCircuits.ContainsKey(circuitcode)) + { + validcircuit = this.AgentCircuits[circuitcode]; + } + AuthenticateResponse user = new AuthenticateResponse(); + if (validcircuit == null) + { + //don't have this circuit code in our list + user.Authorised = false; + return (user); + } + + if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID)) + { + // YAY! Valid login + user.Authorised = true; + user.LoginInfo = new Login(); + user.LoginInfo.Agent = agentID; + user.LoginInfo.Session = sessionID; + user.LoginInfo.First = validcircuit.firstname; + user.LoginInfo.Last = validcircuit.lastname; + } + else + { + // Invalid + user.Authorised = false; + } + + return (user); + } + + public override bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) + { + WebRequest DeleteSession = WebRequest.Create(GridServerUrl + "/usersessions/" + sessionID.ToString()); + DeleteSession.Method = "DELETE"; + DeleteSession.ContentType = "text/plaintext"; + DeleteSession.ContentLength = 0; + + StreamWriter stOut = new StreamWriter(DeleteSession.GetRequestStream(), System.Text.Encoding.ASCII); + stOut.Write(""); + stOut.Close(); + + StreamReader stIn = new StreamReader(DeleteSession.GetResponse().GetResponseStream()); + string GridResponse = stIn.ReadToEnd(); + stIn.Close(); + return (true); + } + + public override UUIDBlock RequestUUIDBlock() + { + UUIDBlock uuidBlock = new UUIDBlock(); + return (uuidBlock); + } + + public override void RequestNeighbours() + { + return; + } + + public override void SetServerInfo(string ServerUrl, string ServerKey) + { + this.GridServerUrl = ServerUrl; + this.GridSendKey = ServerKey; + } + + public override string GetName() + { + return "Remote"; + } + + public override void Close() + { + + } + } + + public class RemoteAssetServer : IAssetServer + { + private IAssetReceiver _receiver; + private BlockingQueue _assetRequests; + private Thread _remoteAssetServerThread; + private string AssetServerUrl; + private string AssetSendKey; + + public RemoteAssetServer() + { + this._assetRequests = new BlockingQueue(); + this._remoteAssetServerThread = new Thread(new ThreadStart(RunRequests)); + this._remoteAssetServerThread.IsBackground = true; + this._remoteAssetServerThread.Start(); + ServerConsole.MainConsole.Instance.WriteLine("Remote Asset Server class created"); + } + + public void SetReceiver(IAssetReceiver receiver) + { + this._receiver = receiver; + } + + public void RequestAsset(LLUUID assetID, bool isTexture) + { + ARequest req = new ARequest(); + req.AssetID = assetID; + req.IsTexture = isTexture; + this._assetRequests.Enqueue(req); + } + + public void UpdateAsset(AssetBase asset) + { + + } + + public void UploadNewAsset(AssetBase asset) + { + + } + + public void SetServerInfo(string ServerUrl, string ServerKey) + { + this.AssetServerUrl = ServerUrl; + this.AssetSendKey = ServerKey; + } + + private void RunRequests() + { + while (true) + { + //we need to add support for the asset server not knowing about a requested asset + ARequest req = this._assetRequests.Dequeue(); + LLUUID assetID = req.AssetID; + ServerConsole.MainConsole.Instance.WriteLine(" RemoteAssetServer- Got a AssetServer request, processing it"); + WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "getasset/" + AssetSendKey + "/" + assetID + "/data"); + WebResponse AssetResponse = AssetLoad.GetResponse(); + byte[] idata = new byte[(int)AssetResponse.ContentLength]; + BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream()); + idata = br.ReadBytes((int)AssetResponse.ContentLength); + br.Close(); + + AssetBase asset = new AssetBase(); + asset.FullID = assetID; + asset.Data = idata; + _receiver.AssetReceived(asset, req.IsTexture); + } + } + + public void Close() + { + + } + } + + public class BlockingQueue + { + private Queue _queue = new Queue(); + 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(); + } + } + } } diff --git a/src/Second-server.csproj b/src/Second-server.csproj index 8b5982d144..380b2674b6 100644 --- a/src/Second-server.csproj +++ b/src/Second-server.csproj @@ -35,6 +35,9 @@ AnyCPU 4096 + + ..\bin\ + @@ -53,6 +56,7 @@ + @@ -71,19 +75,30 @@ - + + - - {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9} GridInterfaces + + {D7F0395B-FADC-4936-80A0-D95AACE92F62} + LocalGridServers + + + {74784F23-B0FD-484C-82C1-96C0215733DC} + Db4LocalStorage + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B} PhysicsManager + + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5} + RemoteGridServers + {C9A6026D-8E0C-4FE4-8691-FB2A566AA245} ServerConsole diff --git a/src/ServerConsole/ServerConsole/ServerConsole.cs b/src/ServerConsole/ServerConsole/ServerConsole.cs new file mode 100644 index 0000000000..27d97e5f0e --- /dev/null +++ b/src/ServerConsole/ServerConsole/ServerConsole.cs @@ -0,0 +1,87 @@ +/* +* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ +* +* 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 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 ``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 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; + +namespace ServerConsole +{ + public class MainConsole { + + private static ConsoleBase instance; + + public static ConsoleBase Instance + { + get + { + return instance; + } + set + { + instance = value; + } + } + } + + public abstract class ConsoleBase + { + + public enum ConsoleType { + Local, // Use stdio + TCP, // Use TCP/telnet + SimChat // Use in-world chat (for gods) + } + + public abstract void Close(); + + public abstract void Write(string format, params object[] args); + + public abstract void WriteLine(string format, params object[] args); + + public abstract string ReadLine(); + + public abstract int Read() ; + + // Displays a command prompt and waits for the user to enter a string, then returns that string + public abstract string CmdPrompt(string prompt) ; + + // Displays a command prompt and returns a default value if the user simply presses enter + public abstract string CmdPrompt(string prompt, string defaultresponse); + + // Displays a command prompt and returns a default value, user may only enter 1 of 2 options + public abstract string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) ; + + // Runs a command with a number of parameters + public abstract Object RunCmd(string Cmd, string[] cmdparams) ; + + // Shows data about something + public abstract void ShowCommands(string ShowWhat) ; + + // Displays a prompt to the user and then runs the command they entered + public abstract void MainConsolePrompt() ; + + public abstract void SetStatus( string status ); + } +} diff --git a/src/ServerConsole/ServerConsole/ServerConsole.csproj b/src/ServerConsole/ServerConsole/ServerConsole.csproj new file mode 100644 index 0000000000..3d85860169 --- /dev/null +++ b/src/ServerConsole/ServerConsole/ServerConsole.csproj @@ -0,0 +1,35 @@ + + + Library + ServerConsole + ServerConsole + Debug + AnyCPU + {C9A6026D-8E0C-4FE4-8691-FB2A566AA245} + + + bin\Debug\ + False + DEBUG;TRACE + True + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + + + + + + \ No newline at end of file diff --git a/src/Util.cs b/src/Util.cs new file mode 100644 index 0000000000..1df82ce8a7 --- /dev/null +++ b/src/Util.cs @@ -0,0 +1,101 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + +* Copyright (c) , +* 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 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 ``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 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 OpenSim +{ + /// + /// + /// + 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; + } + + /* this is in IGridServer.cs, so there should be no reason for it to be here as well + public class agentcircuitdata + { + public agentcircuitdata() { } + public LLUUID AgentID; + public LLUUID SessionID; + public LLUUID SecureSessionID; + public string firstname; + public string lastname; + public uint circuitcode; + } + */ + + public class BlockingQueue + { + private Queue _queue = new Queue(); + 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(); + } + } + } +} diff --git a/src/VersionInfo.cs b/src/VersionInfo.cs new file mode 100644 index 0000000000..39767df665 --- /dev/null +++ b/src/VersionInfo.cs @@ -0,0 +1,37 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ +* +* 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 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 ``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 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; + +namespace OpenSim +{ + /// + /// + public class VersionInfo + { + public static string Version = "0.1, Build 1173843165, Revision 193:206M"; + } +} diff --git a/src/opensim.sln b/src/opensim.sln new file mode 100644 index 0000000000..3f86420a16 --- /dev/null +++ b/src/opensim.sln @@ -0,0 +1,74 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C# Express 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Second-server", "Second-server.csproj", "{132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GridInterfaces", "GridInterfaces\GridInterfaces.csproj", "{5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysicsManager", "physics\PhysicsManager.csproj", "{3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerConsole", "ServerConsole\ServerConsole\ServerConsole.csproj", "{C9A6026D-8E0C-4FE4-8691-FB2A566AA245}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalGridServers", "LocalServers\LocalGridServers\LocalGridServers.csproj", "{D7F0395B-FADC-4936-80A0-D95AACE92F62}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteGridServers", "RemoteServers\RemoteGridServers\RemoteGridServers.csproj", "{CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimConfig", "Config\SimConfig\SimConfig.csproj", "{B063760D-DB8D-4F64-B6FE-335FAD1E650A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Db4LocalStorage", "LocalStorage\Db4LocalStorage\Db4LocalStorage.csproj", "{74784F23-B0FD-484C-82C1-96C0215733DC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicPhysicsplugin", "physics\plugins\BasicPhysicsplugin.csproj", "{52BCCE7B-69EA-4AC3-9DBC-D571B96C2EA1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RealPhysXplugin", "physics\RealPhysX\RealPhysXplugin\RealPhysXplugin.csproj", "{56C1D214-F389-4228-921A-0A3A0712C159}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|Any CPU.Build.0 = Release|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|Any CPU.Build.0 = Release|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|Any CPU.Build.0 = Release|Any CPU + {C9A6026D-8E0C-4FE4-8691-FB2A566AA245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9A6026D-8E0C-4FE4-8691-FB2A566AA245}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9A6026D-8E0C-4FE4-8691-FB2A566AA245}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9A6026D-8E0C-4FE4-8691-FB2A566AA245}.Release|Any CPU.Build.0 = Release|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Release|Any CPU.Build.0 = Release|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Release|Any CPU.Build.0 = Release|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Release|Any CPU.Build.0 = Release|Any CPU + {74784F23-B0FD-484C-82C1-96C0215733DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74784F23-B0FD-484C-82C1-96C0215733DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74784F23-B0FD-484C-82C1-96C0215733DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74784F23-B0FD-484C-82C1-96C0215733DC}.Release|Any CPU.Build.0 = Release|Any CPU + {52BCCE7B-69EA-4AC3-9DBC-D571B96C2EA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52BCCE7B-69EA-4AC3-9DBC-D571B96C2EA1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52BCCE7B-69EA-4AC3-9DBC-D571B96C2EA1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52BCCE7B-69EA-4AC3-9DBC-D571B96C2EA1}.Release|Any CPU.Build.0 = Release|Any CPU + {56C1D214-F389-4228-921A-0A3A0712C159}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {56C1D214-F389-4228-921A-0A3A0712C159}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56C1D214-F389-4228-921A-0A3A0712C159}.Release|Any CPU.ActiveCfg = Release|Any CPU + {56C1D214-F389-4228-921A-0A3A0712C159}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/physics/PhysicsActor.cs b/src/physics/PhysicsActor.cs new file mode 100644 index 0000000000..54775222b5 --- /dev/null +++ b/src/physics/PhysicsActor.cs @@ -0,0 +1,161 @@ +/* +* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ +* +* 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 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 ``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 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.Text; + +namespace PhysicsSystem +{ + public abstract class PhysicsActor + { + public static PhysicsActor Null + { + get + { + return new NullPhysicsActor(); + } + } + + public abstract PhysicsVector Position + { + get; + set; + } + + public abstract PhysicsVector Velocity + { + get; + set; + } + + public abstract PhysicsVector Acceleration + { + get; + } + + public abstract Axiom.MathLib.Quaternion Orientation + { + get; + set; + } + + public abstract bool Flying + { + get; + set; + } + + public abstract bool Kinematic + { + get; + set; + } + + public abstract void AddForce(PhysicsVector force); + + public abstract void SetMomentum(PhysicsVector momentum); + } + + public class NullPhysicsActor : PhysicsActor + { + public override PhysicsVector Position + { + get + { + return PhysicsVector.Zero; + } + set + { + return; + } + } + + public override PhysicsVector Velocity + { + get + { + return PhysicsVector.Zero; + } + set + { + return; + } + } + + public override Axiom.MathLib.Quaternion Orientation + { + get + { + return Axiom.MathLib.Quaternion.Identity; + } + set + { + + } + } + + public override PhysicsVector Acceleration + { + get { return PhysicsVector.Zero; } + } + + public override bool Flying + { + get + { + return false; + } + set + { + return; + } + } + + public override bool Kinematic + { + get + { + return true; + } + set + { + return; + } + } + + public override void AddForce(PhysicsVector force) + { + return; + } + + public override void SetMomentum(PhysicsVector momentum) + { + return; + } + } +} diff --git a/src/physics/PhysicsManager.cs b/src/physics/PhysicsManager.cs index 7f2db18292..929a0f9484 100644 --- a/src/physics/PhysicsManager.cs +++ b/src/physics/PhysicsManager.cs @@ -47,15 +47,21 @@ namespace PhysicsSystem public PhysicsScene GetPhysicsScene(string engineName) { + if (String.IsNullOrEmpty(engineName)) + { + return new NullPhysicsScene(); + } + if(_plugins.ContainsKey(engineName)) { ServerConsole.MainConsole.Instance.WriteLine("creating "+engineName); return _plugins[engineName].GetScene(); } else - { - ServerConsole.MainConsole.Instance.WriteLine("couldn't find physicsEngine: "+ engineName); - return null; + { + string error = String.Format("couldn't find physicsEngine: {0}", engineName); + ServerConsole.MainConsole.Instance.WriteLine(error); + throw new ArgumentException(error); } } @@ -99,6 +105,7 @@ namespace PhysicsSystem pluginAssembly = null; } } + public interface IPhysicsPlugin { bool Init(); @@ -106,83 +113,4 @@ namespace PhysicsSystem string GetName(); void Dispose(); } - - public abstract class PhysicsScene - { - public abstract PhysicsActor AddAvatar(PhysicsVector position); - - public abstract PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size); - - public abstract void Simulate(float timeStep); - - public abstract void GetResults(); - - public abstract void SetTerrain(float[] heightMap); - - public abstract bool IsThreaded - { - get; - } - } - - public abstract class PhysicsActor - { - public abstract PhysicsVector Position - { - get; - set; - } - - public abstract PhysicsVector Velocity - { - get; - set; - } - - public abstract PhysicsVector Acceleration - { - get; - } - - public abstract Axiom.MathLib.Quaternion Orientation - { - get; - set; - } - - public abstract bool Flying - { - get; - set; - } - - public abstract bool Kinematic - { - get; - set; - } - - public abstract void AddForce(PhysicsVector force); - - public abstract void SetMomentum(PhysicsVector momentum); - } - - public class PhysicsVector - { - public float X; - public float Y; - public float Z; - - public PhysicsVector() - { - - } - - public PhysicsVector(float x, float y, float z) - { - X = x; - Y = y; - Z = z; - } - } } diff --git a/src/physics/PhysicsManager.csproj b/src/physics/PhysicsManager.csproj index 18ceeb8336..16f6445665 100644 --- a/src/physics/PhysicsManager.csproj +++ b/src/physics/PhysicsManager.csproj @@ -25,6 +25,7 @@ + ..\..\bin\Axiom.MathLib.dll @@ -32,8 +33,11 @@ + + + diff --git a/src/physics/PhysicsScene.cs b/src/physics/PhysicsScene.cs new file mode 100644 index 0000000000..c8bc3330a8 --- /dev/null +++ b/src/physics/PhysicsScene.cs @@ -0,0 +1,98 @@ +/* +* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ +* +* 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 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 ``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 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.Text; + +namespace PhysicsSystem +{ + public abstract class PhysicsScene + { + public static PhysicsScene Null + { + get + { + return new NullPhysicsScene(); + } + } + + public abstract PhysicsActor AddAvatar(PhysicsVector position); + + public abstract PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size); + + public abstract void Simulate(float timeStep); + + public abstract void GetResults(); + + public abstract void SetTerrain(float[] heightMap); + + public abstract bool IsThreaded + { + get; + } + } + + public class NullPhysicsScene : PhysicsScene + { + private static int m_workIndicator; + + public override PhysicsActor AddAvatar(PhysicsVector position) + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : AddAvatar({0})", position); + return PhysicsActor.Null; + } + + public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : AddPrim({0},{1})", position, size); + return PhysicsActor.Null; + } + + public override void Simulate(float timeStep) + { + m_workIndicator = (m_workIndicator + 1) % 10; + + ServerConsole.MainConsole.Instance.SetStatus(m_workIndicator.ToString()); + } + + public override void GetResults() + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : GetResults()"); + } + + public override void SetTerrain(float[] heightMap) + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : SetTerrain({0} items)", heightMap.Length); + } + + public override bool IsThreaded + { + get { return false; } + } + } +} diff --git a/src/physics/PhysicsVector.cs b/src/physics/PhysicsVector.cs new file mode 100644 index 0000000000..5733897066 --- /dev/null +++ b/src/physics/PhysicsVector.cs @@ -0,0 +1,54 @@ +/* +* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ +* +* 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 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 ``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 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.Text; + +namespace PhysicsSystem +{ + public class PhysicsVector + { + public float X; + public float Y; + public float Z; + + public PhysicsVector() + { + + } + + public PhysicsVector(float x, float y, float z) + { + X = x; + Y = y; + Z = z; + } + + public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f); + } +} diff --git a/src/physics/plugins/BasicPhysicsplugin.csproj b/src/physics/plugins/BasicPhysicsplugin.csproj new file mode 100644 index 0000000000..f0b3c9a2b5 --- /dev/null +++ b/src/physics/plugins/BasicPhysicsplugin.csproj @@ -0,0 +1,59 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {52BCCE7B-69EA-4AC3-9DBC-D571B96C2EA1} + Library + Properties + BasicPhysicsplugin + BasicPhysicsplugin + + + true + full + false + ..\..\..\bin\Physics\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\bin\Physics\ + TRACE + prompt + 4 + + + + False + ..\..\..\bin\Axiom.MathLib.dll + False + + + + + + + + + + + + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B} + PhysicsManager + False + + + + + \ No newline at end of file