From 7daa3955bc3a1918e40962851f9e8d38597a245e Mon Sep 17 00:00:00 2001 From: gareth Date: Thu, 22 Mar 2007 10:11:15 +0000 Subject: brought zircon branch into trunk --- OpenSim.RegionServer/Assets/AssetCache.cs | 589 +++++++++++++++++++ OpenSim.RegionServer/Assets/InventoryCache.cs | 199 +++++++ OpenSim.RegionServer/CAPS/SimHttp.cs | 175 ++++++ OpenSim.RegionServer/Grid.cs | 89 +++ OpenSim.RegionServer/OpenSim.RegionServer.csproj | 169 ++++++ .../OpenSim.RegionServer.exe.build | 67 +++ OpenSim.RegionServer/OpenSimApplication.cs | 16 + OpenSim.RegionServer/OpenSimMain.cs | 320 +++++++++++ OpenSim.RegionServer/OpenSimRoot.cs | 63 +++ OpenSim.RegionServer/QueItem.cs | 18 + OpenSim.RegionServer/SimClient.cs | 621 +++++++++++++++++++++ OpenSim.RegionServer/SimConsole.cs | 211 +++++++ .../UserServer/LocalUserProfileManager.cs | 76 +++ OpenSim.RegionServer/UserServer/LoginServer.cs | 414 ++++++++++++++ OpenSim.RegionServer/VersionInfo.cs | 37 ++ OpenSim.RegionServer/types/Mesh.cs | 28 + OpenSim.RegionServer/types/Triangle.cs | 28 + OpenSim.RegionServer/world/Avatar.cs | 501 +++++++++++++++++ OpenSim.RegionServer/world/Entity.cs | 67 +++ OpenSim.RegionServer/world/Primitive.cs | 485 ++++++++++++++++ OpenSim.RegionServer/world/ScriptEngine.cs | 18 + OpenSim.RegionServer/world/SurfacePatch.cs | 22 + OpenSim.RegionServer/world/World.cs | 213 +++++++ OpenSim.RegionServer/world/scripting/IScript.cs | 16 + 24 files changed, 4442 insertions(+) create mode 100644 OpenSim.RegionServer/Assets/AssetCache.cs create mode 100644 OpenSim.RegionServer/Assets/InventoryCache.cs create mode 100644 OpenSim.RegionServer/CAPS/SimHttp.cs create mode 100644 OpenSim.RegionServer/Grid.cs create mode 100644 OpenSim.RegionServer/OpenSim.RegionServer.csproj create mode 100644 OpenSim.RegionServer/OpenSim.RegionServer.exe.build create mode 100644 OpenSim.RegionServer/OpenSimApplication.cs create mode 100644 OpenSim.RegionServer/OpenSimMain.cs create mode 100644 OpenSim.RegionServer/OpenSimRoot.cs create mode 100644 OpenSim.RegionServer/QueItem.cs create mode 100644 OpenSim.RegionServer/SimClient.cs create mode 100644 OpenSim.RegionServer/SimConsole.cs create mode 100644 OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs create mode 100644 OpenSim.RegionServer/UserServer/LoginServer.cs create mode 100644 OpenSim.RegionServer/VersionInfo.cs create mode 100644 OpenSim.RegionServer/types/Mesh.cs create mode 100644 OpenSim.RegionServer/types/Triangle.cs create mode 100644 OpenSim.RegionServer/world/Avatar.cs create mode 100644 OpenSim.RegionServer/world/Entity.cs create mode 100644 OpenSim.RegionServer/world/Primitive.cs create mode 100644 OpenSim.RegionServer/world/ScriptEngine.cs create mode 100644 OpenSim.RegionServer/world/SurfacePatch.cs create mode 100644 OpenSim.RegionServer/world/World.cs create mode 100644 OpenSim.RegionServer/world/scripting/IScript.cs (limited to 'OpenSim.RegionServer') diff --git a/OpenSim.RegionServer/Assets/AssetCache.cs b/OpenSim.RegionServer/Assets/AssetCache.cs new file mode 100644 index 0000000..f7f2e10 --- /dev/null +++ b/OpenSim.RegionServer/Assets/AssetCache.cs @@ -0,0 +1,589 @@ +/* +* 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.Threading; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Assets; +using OpenSim.Framework.Utilities; + +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 + { + //Console.WriteLine("Asset cache loop"); + this.ProcessAssetQueue(); + this.ProcessTextureQueue(); + Thread.Sleep(500); + } + 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); + this._assetServer.UploadNewAsset(image); //save the asset to the asset server + } + } + 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; + Console.WriteLine("processing texture requests ( " + num + " )"); + for (int i = 0; i < num; i++) + { + req = (AssetRequest)this.TextureRequests[i]; + if (req.PacketCounter != req.NumPackets) + { + // if (req.ImageInfo.FullID == new LLUUID("00000000-0000-0000-5005-000000000005")) + Console.WriteLine("sending base texture ( " + req.ImageInfo.FullID + " ) in " + req.NumPackets + "number of packets"); + + 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++) + { + if (this.TextureRequests.Count > count) + { + req = (AssetRequest)this.TextureRequests[count]; + if (req.PacketCounter == req.NumPackets) + { + this.TextureRequests.Remove(req); + } + else + { + count++; + } + } + } + + } + public void AssetReceived(AssetBase asset, bool IsTexture) + { + Console.WriteLine("received asset from asset server ( " + asset.FullID + " )"); + 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; + if (image.Data.LongLength > 600) + { + //over 600 bytes so split up file + req.NumPackets = 1 + (int)(image.Data.Length - 600 + 999) / 1000; + } + else + { + req.NumPackets = 1; + } + 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; + if (assetInf.Data.LongLength > 600) + { + //over 600 bytes so split up file + req.NumPackets = 1 + (int)(assetInf.Data.Length - 600 + 999) / 1000; + } + else + { + req.NumPackets = 1; + } + 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(SimClient 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 + if (!this.RequestedAssets.ContainsKey(requestID)) + { + 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(SimClient userInfo, LLUUID imageID) + { + if (imageID == new LLUUID("00000000-0000-0000-5005-000000000005")) + Console.WriteLine("request base prim texture "); + + //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, LLUUID assetID) + { + + AssetBase asset = null; + if (pack.AssetBlock.Type == 0) + { + if (pack.AssetBlock.AssetData.Length > 0) + { + //first packet for transaction + asset = new AssetBase(); + asset.FullID = assetID; + asset.Type = pack.AssetBlock.Type; + asset.InvType = asset.Type; + asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000"); + asset.Data = pack.AssetBlock.AssetData; + this._assetServer.UploadNewAsset(asset); + TextureImage image = new TextureImage(asset); + this.Textures.Add(image.FullID, image); + } + } + + return asset; + } + + /* + public AssetBase TransactionComplete(LLUUID transactionID) + { + AssetBase asset = null; + if(this.IncomingAssets.ContainsKey(transactionID)) + { + // not the first packet of this transaction + asset = this.IncomingAssets[transactionID]; + if(asset.Type == 0) + { + TextureImage image = new TextureImage(asset); + this.Textures.Add(image.FullID, image); + } + } + return asset; + }*/ + + #endregion + + } + + public class AssetRequest + { + public SimClient 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/OpenSim.RegionServer/Assets/InventoryCache.cs b/OpenSim.RegionServer/Assets/InventoryCache.cs new file mode 100644 index 0000000..0788db2 --- /dev/null +++ b/OpenSim.RegionServer/Assets/InventoryCache.cs @@ -0,0 +1,199 @@ +/* +* 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 libsecondlife; +using OpenSim; +using libsecondlife.Packets; +//using OpenSim.GridServers; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.Assets; + +namespace OpenSim.Assets +{ + /// + /// Description of InventoryManager. + /// + public class InventoryCache + { + 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 InventoryCache() + { + _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(SimClient 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(SimClient remoteClient, LLUUID folderID, OpenSim.Framework.Assets.AssetBase asset) + { + LLUUID newItem = null; + if (this._agentsInventory.ContainsKey(remoteClient.AgentID)) + { + newItem = this._agentsInventory[remoteClient.AgentID].AddToInventory(folderID, asset); + } + + return newItem; + } + + public void FetchInventoryDescendents(SimClient userInfo, FetchInventoryDescendentsPacket FetchDescend) + { + if (this._agentsInventory.ContainsKey(userInfo.AgentID)) + { + AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID]; + if (FetchDescend.InventoryData.FetchItems) + { + if (agentInventory.InventoryFolders.ContainsKey(FetchDescend.InventoryData.FolderID)) + { + InventoryFolder Folder = agentInventory.InventoryFolders[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(SimClient 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.InventoryItems.ContainsKey(FetchItems.InventoryData[i].ItemID)) + { + InventoryItem Item = agentInventory.InventoryItems[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 UserServerRequest + { + public UserServerRequest() + { + + } + } +} diff --git a/OpenSim.RegionServer/CAPS/SimHttp.cs b/OpenSim.RegionServer/CAPS/SimHttp.cs new file mode 100644 index 0000000..f5a8705 --- /dev/null +++ b/OpenSim.RegionServer/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 OpenSim.Framework.Console; +using OpenSim.Framework.Interfaces; + +namespace OpenSim.CAPS +{ + // Dummy HTTP server, does nothing useful for now + + public class SimCAPSHTTPServer + { + public Thread HTTPD; + public HttpListener Listener; + + public SimCAPSHTTPServer() + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server"); + HTTPD = new Thread(new ThreadStart(StartHTTP)); + HTTPD.Start(); + } + + public void StartHTTP() + { + try + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK"); + Listener = new HttpListener(); + + Listener.Prefixes.Add("http://+:" + OpenSimRoot.Instance.Cfg.IPListenPort + "/"); + Listener.Start(); + + HttpListenerContext context; + while (true) + { + context = Listener.GetContext(); + ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context); + } + } + catch (Exception e) + { + OpenSim.Framework.Console.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": + AgentCircuitData agent_data = new 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 (OpenSimRoot.Instance.GridServers.GridServer.GetName() == "Remote") + { + ((RemoteGridBase)OpenSimRoot.Instance.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/OpenSim.RegionServer/Grid.cs b/OpenSim.RegionServer/Grid.cs new file mode 100644 index 0000000..b0df6a8 --- /dev/null +++ b/OpenSim.RegionServer/Grid.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Reflection; +using OpenSim.Framework.Interfaces; +using OpenSim.UserServer; + +namespace OpenSim +{ + public class Grid + { + public IAssetServer AssetServer; + public IGridServer GridServer; + public string AssetDll = ""; + public string GridDll = ""; + + public Grid() + { + } + + public virtual void Initialise() + { + //load the dlls + this.AssetServer = this.LoadAssetDll(this.AssetDll); + this.GridServer = this.LoadGridDll(this.GridDll); + } + public virtual 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/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj new file mode 100644 index 0000000..ebf2f87 --- /dev/null +++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj @@ -0,0 +1,169 @@ + + + Local + 8.0.50727 + 2.0 + {B48F0D82-2DE5-42B0-9F1D-0F4353FA243A} + Debug + AnyCPU + + + + OpenSim.RegionServer + JScript + Grid + IE50 + false + Exe + + OpenSim.RegionServer + OpenSim.RegionServer + + + + + False + 285212672 + False + + + TRACE;DEBUG + + True + 4096 + False + ..\bin\ + False + False + False + 4 + + + + False + 285212672 + False + + + TRACE + + False + 4096 + True + ..\bin\ + False + False + False + 4 + + + + + \System.dll + + + \System.Xml.dll.dll + + + \libsecondlife.dll.dll + + + \Axiom.MathLib.dll.dll + + + \Db4objects.Db4o.dll.dll + + + + + OpenSim.Framework.Console + {C8405E1A-EC19-48B6-9C8C-CA03624B9916} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + OpenSim.Physics.Manager + {58360A80-9333-4E0F-8F83-3CF937E51633} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + OpenSim.Framework + {1D2865A9-CF8E-45F7-B96D-91ED128A32CF} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.exe.build b/OpenSim.RegionServer/OpenSim.RegionServer.exe.build new file mode 100644 index 0000000..c65f751 --- /dev/null +++ b/OpenSim.RegionServer/OpenSim.RegionServer.exe.build @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenSim.RegionServer/OpenSimApplication.cs b/OpenSim.RegionServer/OpenSimApplication.cs new file mode 100644 index 0000000..abfdf45 --- /dev/null +++ b/OpenSim.RegionServer/OpenSimApplication.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; + +namespace OpenSim +{ + public abstract class OpenSimApplication + { + public abstract void StartUp(); + public abstract void Shutdown(); + public abstract void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode);// EndPoint packetSender); + public abstract void RemoveClientCircuit(uint circuitcode); + } +} diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs new file mode 100644 index 0000000..b2bc0b3 --- /dev/null +++ b/OpenSim.RegionServer/OpenSimMain.cs @@ -0,0 +1,320 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the 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 System.IO; +using System.Threading; +using System.Net; +using System.Net.Sockets; +using System.Timers; +using System.Reflection; +using System.Collections; +using System.Collections.Generic; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim.world; +using OpenSim.Framework.Interfaces; +using OpenSim.UserServer; +using OpenSim.Assets; +using OpenSim.CAPS; +using OpenSim.Framework.Console; +using OpenSim.Physics.Manager; + +namespace OpenSim +{ + /// + /// + /// + public class OpenSimMain : OpenSimApplication + { + private Dictionary clientCircuits = new Dictionary(); + private PhysicsManager physManager; + + 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 System.Timers.Timer timer1 = new System.Timers.Timer(); + private string ConfigDll = "OpenSim.Config.SimConfigDb4o.dll"; + private string _physicsEngine = "basicphysics"; + 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"); + OpenSim.Framework.Console.MainConsole.Instance = new SimConsole(OpenSim.Framework.Console.ConsoleBase.ConsoleType.Local, "", 0); + + //OpenSimRoot.instance = new OpenSimRoot(); + OpenSimMain sim = new OpenSimMain(); + OpenSimRoot.Instance.Application = sim; + + sim.sandbox = false; + sim.loginserver = false; + sim._physicsEngine = "basicphysics"; + + for (int i = 0; i < args.Length; i++) + { + if (args[i] == "-sandbox") + { + sim.sandbox = true; + OpenSimRoot.Instance.Sandbox = true; + } + + if (args[i] == "-loginserver") + { + sim.loginserver = true; + } + if (args[i] == "-realphysx") + { + sim._physicsEngine = "RealPhysX"; + OpenSim.world.Avatar.PhysicsEngineFlying = true; + } + } + + + OpenSimRoot.Instance.GridServers = new Grid(); + if (sim.sandbox) + { + OpenSimRoot.Instance.GridServers.AssetDll = "OpenSim.GridInterfaces.Local.dll"; + OpenSimRoot.Instance.GridServers.GridDll = "OpenSim.GridInterfaces.Local.dll"; + OpenSimRoot.Instance.GridServers.Initialise(); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting in Sandbox mode"); + } + else + { + OpenSimRoot.Instance.GridServers.AssetDll = "OpenSim.GridInterfaces.Remote.dll"; + OpenSimRoot.Instance.GridServers.GridDll = "OpenSim.GridInterfaces.Remote.dll"; + OpenSimRoot.Instance.GridServers.Initialise(); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting in Grid mode"); + } + + if (sim.loginserver && sim.sandbox) + { + LoginServer loginServer = new LoginServer(OpenSimRoot.Instance.GridServers.GridServer); + loginServer.Startup(); + } + + OpenSimRoot.Instance.StartUp(); + + while (true) + { + OpenSim.Framework.Console.MainConsole.Instance.MainConsolePrompt(); + } + } + + private OpenSimMain() + { + } + + public override void StartUp() + { + OpenSimRoot.Instance.startuptime = DateTime.Now; + + OpenSimRoot.Instance.AssetCache = new AssetCache(OpenSimRoot.Instance.GridServers.AssetServer); + OpenSimRoot.Instance.InventoryCache = new InventoryCache(); + + // We check our local database first, then the grid for config options + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration"); + OpenSimRoot.Instance.Cfg = this.LoadConfigDll(this.ConfigDll); + OpenSimRoot.Instance.Cfg.InitConfig(this.sandbox); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Contacting gridserver"); + OpenSimRoot.Instance.Cfg.LoadFromGrid(); + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - We are " + OpenSimRoot.Instance.Cfg.RegionName + " at " + OpenSimRoot.Instance.Cfg.RegionLocX.ToString() + "," + OpenSimRoot.Instance.Cfg.RegionLocY.ToString()); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Initialising world"); + OpenSimRoot.Instance.LocalWorld = new World(); + OpenSimRoot.Instance.LocalWorld.LandMap = OpenSimRoot.Instance.Cfg.LoadWorld(); + + this.physManager = new OpenSim.Physics.Manager.PhysicsManager(); + this.physManager.LoadPlugins(); + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting up messaging system"); + OpenSimRoot.Instance.LocalWorld.PhysScene = this.physManager.GetPhysicsScene(this._physicsEngine); //should be reading from the config file what physics engine to use + OpenSimRoot.Instance.LocalWorld.PhysScene.SetTerrain(OpenSimRoot.Instance.LocalWorld.LandMap); + + OpenSimRoot.Instance.GridServers.AssetServer.SetServerInfo(OpenSimRoot.Instance.Cfg.AssetURL, OpenSimRoot.Instance.Cfg.AssetSendKey); + OpenSimRoot.Instance.GridServers.GridServer.SetServerInfo(OpenSimRoot.Instance.Cfg.GridURL, OpenSimRoot.Instance.Cfg.GridSendKey, OpenSimRoot.Instance.Cfg.GridRecvKey); + + OpenSimRoot.Instance.LocalWorld.LoadStorageDLL("OpenSim.Storage.LocalStorageDb4o.dll"); //all these dll names shouldn't be hard coded. + OpenSimRoot.Instance.LocalWorld.LoadPrimsFromStorage(); + + if (this.sandbox) + { + OpenSimRoot.Instance.AssetCache.LoadDefaultTextureSet(); + } + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting CAPS HTTP server"); + OpenSimRoot.Instance.HttpServer = 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 (OpenSimRoot.Instance.ClientThreads.ContainsKey(epSender)) + + // do we already have a circuit for this endpoint + if(this.clientCircuits.ContainsKey(epSender)) + { + OpenSimRoot.Instance.ClientThreads[this.clientCircuits[epSender]].InPacket(packet); + } + else if (packet.Type == PacketType.UseCircuitCode) + { // new client + UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet; + this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); + SimClient newuser = new SimClient(epSender, useCircuit); + //OpenSimRoot.Instance.ClientThreads.Add(epSender, newuser); + OpenSimRoot.Instance.ClientThreads.Add(useCircuit.CircuitCode.Code, 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() + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - New thread started"); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + OpenSimRoot.Instance.Cfg.IPListenAddr + ":" + OpenSimRoot.Instance.Cfg.IPListenPort); + + ServerIncoming = new IPEndPoint(IPAddress.Any, OpenSimRoot.Instance.Cfg.IPListenPort); + Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + Server.Bind(ServerIncoming); + + OpenSim.Framework.Console.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); + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Listening..."); + + } + + public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode )//EndPoint packetSender) + { + // find the endpoint for this circuit + EndPoint sendto = null; + foreach(KeyValuePair p in this.clientCircuits) + { + if (p.Value == circuitcode) + { + sendto = p.Key; + break; + } + } + if (sendto != null) + { + //we found the endpoint so send the packet to it + this.Server.SendTo(buffer, size, flags, sendto); + } + } + + public override void RemoveClientCircuit(uint circuitcode) + { + foreach (KeyValuePair p in this.clientCircuits) + { + if (p.Value == circuitcode) + { + this.clientCircuits.Remove(p.Key); + break; + } + } + } + + public override void Shutdown() + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing all threads"); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing listener thread"); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing clients"); + // IMPLEMENT THIS + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing console and terminating"); + OpenSimRoot.Instance.LocalWorld.Close(); + OpenSimRoot.Instance.GridServers.Close(); + OpenSim.Framework.Console.MainConsole.Instance.Close(); + Environment.Exit(0); + } + + void Timer1Tick(object sender, System.EventArgs e) + { + OpenSimRoot.Instance.LocalWorld.Update(); + } + } + + +} diff --git a/OpenSim.RegionServer/OpenSimRoot.cs b/OpenSim.RegionServer/OpenSimRoot.cs new file mode 100644 index 0000000..3361e5d --- /dev/null +++ b/OpenSim.RegionServer/OpenSimRoot.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +//using System.Net.Sockets; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim.world; +using OpenSim.Framework.Interfaces; +using OpenSim.UserServer; +using OpenSim.Assets; +using OpenSim.CAPS; +using OpenSim.Framework.Console; +using OpenSim.Physics.Manager; + +namespace OpenSim +{ + public sealed class OpenSimRoot + { + private static OpenSimRoot instance = new OpenSimRoot(); + + public static OpenSimRoot Instance + { + get + { + return instance; + } + } + + private OpenSimRoot() + { + + } + + public World LocalWorld; + public Grid GridServers; + public SimConfig Cfg; + public SimCAPSHTTPServer HttpServer; + public AssetCache AssetCache; + public InventoryCache InventoryCache; + //public Dictionary ClientThreads = new Dictionary(); + public Dictionary ClientThreads = new Dictionary(); + public DateTime startuptime; + public OpenSimApplication Application; + public bool Sandbox = false; + + public void StartUp() + { + if (this.Application != null) + { + this.Application.StartUp(); + } + } + + public void Shutdown() + { + if (this.Application != null) + { + this.Application.Shutdown(); + } + } + } +} diff --git a/OpenSim.RegionServer/QueItem.cs b/OpenSim.RegionServer/QueItem.cs new file mode 100644 index 0000000..747e026 --- /dev/null +++ b/OpenSim.RegionServer/QueItem.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife.Packets; + +namespace OpenSim +{ + public class QueItem + { + public QueItem() + { + } + + public Packet Packet; + public bool Incoming; + } + +} diff --git a/OpenSim.RegionServer/SimClient.cs b/OpenSim.RegionServer/SimClient.cs new file mode 100644 index 0000000..210e0d9 --- /dev/null +++ b/OpenSim.RegionServer/SimClient.cs @@ -0,0 +1,621 @@ +/* +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; +using System.Collections; +using System.Collections.Generic; +using libsecondlife; +using libsecondlife.Packets; +using System.Net; +using System.Net.Sockets; +using System.IO; +using System.Threading; +using System.Timers; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Assets; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.Utilities; +using OpenSim.world; +using OpenSim.Assets; + +namespace OpenSim +{ + /// + /// Handles new client connections + /// Constructor takes a single Packet and authenticates everything + /// + public class SimClient + { + + public LLUUID AgentID; + public LLUUID SessionID; + public LLUUID SecureSessionID = LLUUID.Zero; + 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; + + private 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; + + //OutPacket(ack_it); + + if (Pack.Header.Reliable) + { + lock (PendingAcks) + { + uint sequence = (uint)Pack.Header.Sequence; + if (!PendingAcks.ContainsKey(sequence)) { PendingAcks[sequence] = sequence; } + } + } + } + + protected virtual 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(OpenSimRoot.Instance.LocalWorld); + ClientAvatar.SendInitialPosition(); + break; + case PacketType.RegionHandshakeReply: + OpenSimRoot.Instance.LocalWorld.SendLayerData(this); + break; + case PacketType.AgentWearablesRequest: + ClientAvatar.SendInitialAppearance(); + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + if (client.AgentID != this.AgentID) + { + ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket(); + this.OutPacket(objupdate); + client.ClientAvatar.SendAppearanceToOtherAgent(this); + } + } + OpenSimRoot.Instance.LocalWorld.GetInitialPrims(this); + break; + case PacketType.ObjectAdd: + OpenSimRoot.Instance.LocalWorld.AddNewPrim((ObjectAddPacket)Pack, this); + break; + case PacketType.ObjectLink: + OpenSim.Framework.Console.MainConsole.Instance.WriteLine(Pack.ToString()); + break; + case PacketType.ObjectScale: + OpenSim.Framework.Console.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 OpenSimRoot.Instance.LocalWorld.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 OpenSimRoot.Instance.LocalWorld.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 OpenSimRoot.Instance.LocalWorld.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 OpenSimRoot.Instance.LocalWorld.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++) + { + OpenSimRoot.Instance.AssetCache.AddTextureRequest(this, imageRequest.RequestImage[i].Image); + } + break; + case PacketType.TransferRequest: + //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request"); + TransferRequestPacket transfer = (TransferRequestPacket)Pack; + OpenSimRoot.Instance.AssetCache.AddAssetRequest(this, transfer); + break; + case PacketType.AgentUpdate: + ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack); + break; + case PacketType.LogoutRequest: + OpenSim.Framework.Console.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 (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + client.OutPacket(kill); + } + OpenSimRoot.Instance.GridServers.GridServer.LogoutSession(this.SessionID, this.AgentID, this.CircuitCode); + lock (OpenSimRoot.Instance.LocalWorld.Entities) + { + OpenSimRoot.Instance.LocalWorld.Entities.Remove(this.AgentID); + } + //need to do other cleaning up here too + OpenSimRoot.Instance.ClientThreads.Remove(this.CircuitCode); //this.userEP); + OpenSimRoot.Instance.Application.RemoveClientCircuit(this.CircuitCode); + 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 (SimClient client in OpenSimRoot.Instance.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 OpenSimRoot.Instance.LocalWorld.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 OpenSimRoot.Instance.LocalWorld.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 = OpenSimRoot.Instance.AssetCache.UploadPacket(request, LLUUID.Random()); + if (newAsset != null) + { + OpenSimRoot.Instance.InventoryCache.AddNewInventoryItem(this, this.newAssetFolder, newAsset); + } + Console.WriteLine(request.ToString()); + Console.WriteLine("combined uuid is " + request.AssetBlock.TransactionID.Combine(this.SecureSessionID).ToStringHyphenated()); + + AssetUploadCompletePacket response = new AssetUploadCompletePacket(); + response.AssetBlock.Type =request.AssetBlock.Type; + response.AssetBlock.Success = true; + response.AssetBlock.UUID = request.AssetBlock.TransactionID.Combine(this.SecureSessionID); + + this.OutPacket(response); + 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; + OpenSimRoot.Instance.InventoryCache.FetchInventory(this, FetchInventory); + break; + case PacketType.FetchInventoryDescendents: + FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack; + OpenSimRoot.Instance.InventoryCache.FetchInventoryDescendents(this, Fetch); + break; + } + } + + private void ResendUnacked() + { + int now = Environment.TickCount; + + lock (NeedAck) + { + foreach (Packet packet in NeedAck.Values) + { + if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent)) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Resending " + packet.Type.ToString() + " packet, " + + (now - packet.TickCount) + "ms have passed"); + + packet.Header.Resent = true; + OutPacket(packet); + } + } + } + } + + 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 + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Too many ACKs queued up!"); + return; + } + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Sending PacketAck"); + + + int i = 0; + PacketAckPacket acks = new PacketAckPacket(); + acks.Packets = new PacketAckPacket.PacketsBlock[PendingAcks.Count]; + + foreach (uint ack in PendingAcks.Values) + { + acks.Packets[i] = new PacketAckPacket.PacketsBlock(); + acks.Packets[i].ID = ack; + i++; + } + + acks.Header.Reliable = false; + OutPacket(acks); + + PendingAcks.Clear(); + } + } + } + + private void AckTimer_Elapsed(object sender, ElapsedEventArgs ea) + { + SendAcks(); + ResendUnacked(); + } + + protected virtual void ProcessOutPacket(Packet Pack) + { + + // Keep track of when this packet was sent out + Pack.TickCount = Environment.TickCount; + + if (!Pack.Header.Resent) + { + // Set the sequence number + lock (SequenceLock) + { + if (Sequence >= MAX_SEQUENCE) + Sequence = 1; + else + Sequence++; + Pack.Header.Sequence = Sequence; + } + + 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); + } + } + + // 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++; + } + + PendingAcks.Clear(); + Pack.Header.AppendedAcks = true; + } + } + } + } + } + + //ServerConsole.MainConsole.Instance.WriteLine("OUT: \n" + Pack.ToString()); + + byte[] ZeroOutBuffer = new byte[4096]; + byte[] sendbuffer; + sendbuffer = Pack.ToBytes(); + + try + { + if (Pack.Header.Zerocoded) + { + int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); + OpenSimRoot.Instance.Application.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, CircuitCode);//userEP); + } + else + { + OpenSimRoot.Instance.Application.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, CircuitCode); //userEP); + } + } + catch (Exception) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread"); + ClientThread.Abort(); + } + + } + + public virtual 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 virtual void OutPacket(Packet NewPack) + { + QueItem item = new QueItem(); + item.Packet = NewPack; + item.Incoming = false; + this.PacketQueue.Enqueue(item); + } + + public SimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack) + { + OpenSim.Framework.Console.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(); + } + + protected virtual void ClientLoop() + { + OpenSim.Framework.Console.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); + } + } + } + + protected virtual void InitNewClient() + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs:InitNewClient() - Adding viewer agent to world"); + OpenSimRoot.Instance.LocalWorld.AddViewerAgent(this); + world.Entity tempent = OpenSimRoot.Instance.LocalWorld.Entities[this.AgentID]; + this.ClientAvatar = (world.Avatar)tempent; + } + + protected virtual void AuthUser() + { + AuthenticateResponse sessionInfo = OpenSimRoot.Instance.GridServers.GridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code); + if (!sessionInfo.Authorised) + { + //session/circuit not authorised + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString()); + ClientThread.Abort(); + } + else + { + OpenSim.Framework.Console.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(); //shouldn't be called here as we might be a child agent and not want a full avatar + this.ClientAvatar.firstname = sessionInfo.LoginInfo.First; + this.ClientAvatar.lastname = sessionInfo.LoginInfo.Last; + if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero) + { + this.SecureSessionID = sessionInfo.LoginInfo.SecureSession; + } + + // Create Inventory, currently only works for sandbox mode + if (OpenSimRoot.Instance.Sandbox) + { + if (sessionInfo.LoginInfo.InventoryFolder != null) + { + this.CreateInventory(sessionInfo.LoginInfo.InventoryFolder); + if (sessionInfo.LoginInfo.BaseFolder != null) + { + OpenSimRoot.Instance.InventoryCache.CreateNewInventoryFolder(this, sessionInfo.LoginInfo.BaseFolder); + this.newAssetFolder = sessionInfo.LoginInfo.BaseFolder; + AssetBase[] inventorySet = OpenSimRoot.Instance.AssetCache.CreateNewInventorySet(this.AgentID); + if (inventorySet != null) + { + for (int i = 0; i < inventorySet.Length; i++) + { + if (inventorySet[i] != null) + { + OpenSimRoot.Instance.InventoryCache.AddNewInventoryItem(this, sessionInfo.LoginInfo.BaseFolder, inventorySet[i]); + } + } + } + } + } + } + + ClientLoop(); + } + } + + private void CreateInventory(LLUUID baseFolder) + { + AgentInventory inventory = new AgentInventory(); + inventory.AgentID = this.AgentID; + OpenSimRoot.Instance.InventoryCache.AddNewAgentsInventory(inventory); + OpenSimRoot.Instance.InventoryCache.CreateNewInventoryFolder(this, baseFolder); + } + } +} diff --git a/OpenSim.RegionServer/SimConsole.cs b/OpenSim.RegionServer/SimConsole.cs new file mode 100644 index 0000000..d6d5e44 --- /dev/null +++ b/OpenSim.RegionServer/SimConsole.cs @@ -0,0 +1,211 @@ +/* +* 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; +using System.Collections.Generic; +using System.Threading; +using System.IO; +using System.Net; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim.Framework.Console; + +namespace OpenSim +{ + /// + /// Description of ServerConsole. + /// + public class SimConsole : ConsoleBase + { + + private ConsoleType ConsType; + StreamWriter Log; + + + // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!! + // constype - the type of console to use (see enum ConsoleType) + // sparam - depending on the console type: + // TCP - the IP to bind to (127.0.0.1 if blank) + // Local - param ignored + // SimChat - the AgentID of this sim's admin + // and for the iparam: + // TCP - the port to bind to + // Local - param ignored + // SimChat - the chat channel to accept commands from + public SimConsole(ConsoleType constype, string sparam, int iparam) { + 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"); + Log.WriteLine("========================================================================"); + //Log.WriteLine("OpenSim " + VersionInfo.Version + " Started at " + DateTime.Now.ToString()); + break; + case ConsoleType.TCP: + break; + case ConsoleType.SimChat: + break; + + 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(); + } + + 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; + } + + public override int Read() { + int TempInt= Console.Read(); + Log.Write((char)TempInt); + return TempInt; + } + + // 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); + return this.ReadLine(); + } + + // Displays a command prompt and returns a default value if the user simply presses enter + public override string CmdPrompt(string prompt, string defaultresponse) { + string temp=CmdPrompt(prompt); + if(temp=="") { + return defaultresponse; + } else { + return temp; + } + } + + // Displays a command prompt and returns a default value, user may only enter 1 of 2 options + public override string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) { + bool itisdone=false; + string temp=CmdPrompt(prompt,defaultresponse); + while(itisdone==false) { + if((temp==OptionA) || (temp==OptionB)) { + itisdone=true; + } else { + this.WriteLine("Valid options are " + OptionA + " or " + OptionB); + temp=CmdPrompt(prompt,defaultresponse); + } + } + return temp; + } + + // Runs a command with a number of parameters + public override Object RunCmd(string Cmd, string[] cmdparams) { + switch(Cmd) { + case "help": + this.WriteLine("show users - show info about connected users"); + this.WriteLine("shutdown - disconnect all clients and shutdown"); + this.WriteLine("regenerate - regenerate the sim's terrain"); + break; + + case "show": + ShowCommands(cmdparams[0]); + break; + + case "regenerate": + OpenSimRoot.Instance.LocalWorld.RegenerateTerrain(); + break; + + case "shutdown": + OpenSimRoot.Instance.Shutdown(); + break; + } + return null; + } + + // Shows data about something + public override void ShowCommands(string ShowWhat) { + switch(ShowWhat) { + case "uptime": + this.WriteLine("OpenSim has been running since " + OpenSimRoot.Instance.startuptime.ToString()); + this.WriteLine("That is " + (DateTime.Now-OpenSimRoot.Instance.startuptime).ToString()); + 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")); + foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys) { + if(OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString()== "OpenSim.world.Avatar") + { + TempAv=(OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID]; + this.WriteLine(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}",TempAv.firstname, TempAv.lastname,UUID, TempAv.ControllingClient.SessionID, TempAv.ControllingClient.CircuitCode, TempAv.ControllingClient.userEP.ToString())); + } + } + break; + } + } + + // Displays a prompt to the user and then runs the command they entered + public override void MainConsolePrompt() { + string[] tempstrarray; + string tempstr = this.CmdPrompt("OpenSim-" + OpenSimRoot.Instance.Cfg.RegionHandle.ToString() + " # "); + tempstrarray = tempstr.Split(' '); + string cmd=tempstrarray[0]; + Array.Reverse(tempstrarray); + Array.Resize(ref tempstrarray,tempstrarray.Length-1); + Array.Reverse(tempstrarray); + string[] cmdparams=(string[])tempstrarray; + RunCmd(cmd,cmdparams); + } + + + public override void SetStatus(string status) + { + Console.Write( status + "\r" ); + } + } +} + + diff --git a/OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs b/OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs new file mode 100644 index 0000000..83e340b --- /dev/null +++ b/OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Text; +using OpenSim.Framework.User; +using OpenSim.Framework.Grid; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.Interfaces; +using libsecondlife; + +namespace OpenSim.UserServer +{ + class LocalUserProfileManager : UserProfileManager + { + private IGridServer _gridServer; + + public LocalUserProfileManager(IGridServer gridServer) + { + _gridServer = gridServer; + } + + public override void InitUserProfiles() + { + // TODO: need to load from database + } + + public override void CustomiseResponse(ref System.Collections.Hashtable response, UserProfile theUser) + { + uint circode = (uint)response["circuit_code"]; + theUser.AddSimCircuit(circode, LLUUID.Random()); + response["home"] = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + theUser.homepos.X.ToString() + ",r" + theUser.homepos.Y.ToString() + ",r" + theUser.homepos.Z.ToString() + "], 'look_at':[r" + theUser.homelookat.X.ToString() + ",r" + theUser.homelookat.Y.ToString() + ",r" + theUser.homelookat.Z.ToString() + "]}"; + response["sim_port"] = OpenSimRoot.Instance.Cfg.IPListenPort; + response["sim_ip"] = OpenSimRoot.Instance.Cfg.IPListenAddr; + response["region_y"] = (Int32)996 * 256; + response["region_x"] = (Int32)997* 256; + + string first; + string last; + if (response.Contains("first")) + { + first = (string)response["first"]; + } + else + { + first = "test"; + } + + if (response.Contains("last")) + { + last = (string)response["last"]; + } + else + { + last = "User"; + } + + ArrayList InventoryList = (ArrayList)response["inventory-skeleton"]; + Hashtable Inventory1 = (Hashtable)InventoryList[0]; + + Login _login = new Login(); + //copy data to login object + _login.First = first; + _login.Last = last; + _login.Agent = new LLUUID((string)response["agent_id"]) ; + _login.Session = new LLUUID((string)response["session_id"]); + _login.BaseFolder = null; + _login.InventoryFolder = new LLUUID((string)Inventory1["folder_id"]); + + //working on local computer if so lets add to the gridserver's list of sessions? + if (OpenSimRoot.Instance.GridServers.GridServer.GetName() == "Local") + { + ((LocalGridBase)this._gridServer).AddNewSession(_login); + } + } + } +} diff --git a/OpenSim.RegionServer/UserServer/LoginServer.cs b/OpenSim.RegionServer/UserServer/LoginServer.cs new file mode 100644 index 0000000..86b098a --- /dev/null +++ b/OpenSim.RegionServer/UserServer/LoginServer.cs @@ -0,0 +1,414 @@ +/* +* 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 Nwc.XmlRpc; +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Collections; +using System.Security.Cryptography; +using System.Xml; +using libsecondlife; +using OpenSim; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Grid; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.User; +using OpenSim.Framework.Utilities; + +namespace OpenSim.UserServer +{ + + /// + /// When running in local (default) mode , handles client logins. + /// + public class LoginServer : LoginService , IUserServer + { + private IGridServer _gridServer; + private ushort _loginPort = 8080; + public IPAddress clientAddress = IPAddress.Loopback; + public IPAddress remoteAddress = IPAddress.Any; + private Socket loginServer; + private int NumClients; + private string _defaultResponse; + private bool userAccounts = false; + private string _mpasswd; + private bool _needPasswd = false; + private LocalUserProfileManager userManager; + + public LoginServer(IGridServer gridServer) + { + _gridServer = gridServer; + } + + // InitializeLogin: initialize the login + private void InitializeLogin() + { + this._needPasswd = false; + //read in default response string + StreamReader SR; + string lines; + SR = File.OpenText("new-login.dat"); + + //lines=SR.ReadLine(); + + while (!SR.EndOfStream) + { + lines = SR.ReadLine(); + _defaultResponse += lines; + //lines = SR.ReadLine(); + } + SR.Close(); + this._mpasswd = EncodePassword("testpass"); + + userManager = new LocalUserProfileManager(this._gridServer); + userManager.InitUserProfiles(); + userManager.SetKeys("", "", "", "Welcome to OpenSim"); + + loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort)); + loginServer.Listen(1); + } + + public void Startup() + { + this.InitializeLogin(); + Thread runLoginProxy = new Thread(new ThreadStart(RunLogin)); + runLoginProxy.IsBackground = true; + runLoginProxy.Start(); + } + + private void RunLogin() + { + Console.WriteLine("Starting Login Server"); + try + { + for (; ; ) + { + Socket client = loginServer.Accept(); + IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint; + + + NetworkStream networkStream = new NetworkStream(client); + StreamReader networkReader = new StreamReader(networkStream); + StreamWriter networkWriter = new StreamWriter(networkStream); + + try + { + LoginRequest(networkReader, networkWriter); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + + networkWriter.Close(); + networkReader.Close(); + networkStream.Close(); + + client.Close(); + + // send any packets queued for injection + + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + } + } + + // ProxyLogin: proxy a login request + private void LoginRequest(StreamReader reader, StreamWriter writer) + { + lock (this) + { + string line; + int contentLength = 0; + // read HTTP header + do + { + // read one line of the header + line = reader.ReadLine(); + + // check for premature EOF + if (line == null) + throw new Exception("EOF in client HTTP header"); + + // look for Content-Length + Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line); + if (match.Success) + contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString()); + } while (line != ""); + + // read the HTTP body into a buffer + char[] content = new char[contentLength]; + reader.Read(content, 0, contentLength); + + if (this.userAccounts) + { + //ask the UserProfile Manager to process the request + string reply = this.userManager.ParseXMLRPC(new String(content)); + // forward the XML-RPC response to the client + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); + writer.WriteLine(reply); + } + else + { + //handle ourselves + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content)); + if (request.MethodName == "login_to_simulator") + { + this.ProcessXmlRequest(request, writer); + } + else + { + XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); + Hashtable PresenceErrorRespData = new Hashtable(); + PresenceErrorRespData["reason"] = "XmlRequest"; ; + PresenceErrorRespData["message"] = "Unknown Rpc request"; + PresenceErrorRespData["login"] = "false"; + PresenceErrorResp.Value = PresenceErrorRespData; + string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""); + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); + writer.WriteLine(reply); + } + } + } + } + + public bool ProcessXmlRequest(XmlRpcRequest request, StreamWriter writer) + { + Hashtable requestData = (Hashtable)request.Params[0]; + string first; + string last; + string passwd; + LLUUID Agent; + LLUUID Session; + + //get login name + if (requestData.Contains("first")) + { + first = (string)requestData["first"]; + } + else + { + first = "test"; + } + + if (requestData.Contains("last")) + { + last = (string)requestData["last"]; + } + else + { + last = "User" + NumClients.ToString(); + } + + if (requestData.Contains("passwd")) + { + passwd = (string)requestData["passwd"]; + } + else + { + passwd = "notfound"; + } + + if (!Authenticate(first, last, passwd)) + { + XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); + Hashtable PresenceErrorRespData = new Hashtable(); + PresenceErrorRespData["reason"] = "key"; ; + PresenceErrorRespData["message"] = "You have entered an invalid name/password combination. Check Caps/lock."; + PresenceErrorRespData["login"] = "false"; + PresenceErrorResp.Value = PresenceErrorRespData; + string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""); + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); + writer.WriteLine(reply); + return false; + } + + NumClients++; + + //create a agent and session LLUUID + Agent = GetAgentId(first, last); + int SessionRand = Util.RandomClass.Next(1, 999); + Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797"); + LLUUID secureSess = LLUUID.Random(); + //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; + + responseData["sim_port"] = OpenSimRoot.Instance.Cfg.IPListenPort; + responseData["sim_ip"] = OpenSimRoot.Instance.Cfg.IPListenAddr; + responseData["agent_id"] = Agent.ToStringHyphenated(); + responseData["session_id"] = Session.ToStringHyphenated(); + responseData["secure_session_id"]= secureSess.ToStringHyphenated(); + responseData["circuit_code"] = (Int32)(Util.RandomClass.Next()); + 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]; + LLUUID BaseFolderID = LLUUID.Random(); + LLUUID InventoryFolderID = LLUUID.Random(); + Inventory2["name"] = "Base"; + Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated(); + Inventory2["type_default"] = 0; + Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated(); + + ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"]; + Hashtable Inventoryroot = (Hashtable)InventoryRoot[0]; + Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated(); + + CustomiseLoginResponse(responseData, first, last); + + Login _login = new Login(); + //copy data to login object + _login.First = first; + _login.Last = last; + _login.Agent = Agent; + _login.Session = Session; + _login.SecureSession = secureSess; + _login.BaseFolder = BaseFolderID; + _login.InventoryFolder = InventoryFolderID; + + //working on local computer if so lets add to the gridserver's list of sessions? + if (OpenSimRoot.Instance.GridServers.GridServer.GetName() == "Local") + { + ((LocalGridBase)this._gridServer).AddNewSession(_login); + } + + // forward the XML-RPC response to the client + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); + + XmlTextWriter responseWriter = new XmlTextWriter(writer); + XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response); + responseWriter.Close(); + + return true; + } + + protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last) + { + } + + protected virtual LLUUID GetAgentId(string firstName, string lastName) + { + LLUUID Agent; + int AgentRand = Util.RandomClass.Next(1, 9999); + Agent = new LLUUID("99998888-0100-" + AgentRand.ToString("0000") + "-8ec1-0b1d5cd6aead"); + return Agent; + } + + protected virtual bool Authenticate(string first, string last, string passwd) + { + if (this._needPasswd) + { + //every user needs the password to login + string encodedPass = passwd.Remove(0, 3); //remove $1$ + if (encodedPass == this._mpasswd) + { + return true; + } + else + { + return false; + } + } + else + { + //do not need password to login + return true; + } + } + + private static string EncodePassword(string passwd) + { + Byte[] originalBytes; + Byte[] encodedBytes; + MD5 md5; + + md5 = new MD5CryptoServiceProvider(); + originalBytes = ASCIIEncoding.Default.GetBytes(passwd); + encodedBytes = md5.ComputeHash(originalBytes); + + return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower(); + } + + //IUserServer implementation + public AgentInventory RequestAgentsInventory(LLUUID agentID) + { + AgentInventory aInventory = null; + if (this.userAccounts) + { + aInventory = this.userManager.GetUsersInventory(agentID); + } + + return aInventory; + } + + public void SetServerInfo(string ServerUrl, string SendKey, string RecvKey) + { + + } + + } + + +} diff --git a/OpenSim.RegionServer/VersionInfo.cs b/OpenSim.RegionServer/VersionInfo.cs new file mode 100644 index 0000000..39767df --- /dev/null +++ b/OpenSim.RegionServer/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/OpenSim.RegionServer/types/Mesh.cs b/OpenSim.RegionServer/types/Mesh.cs new file mode 100644 index 0000000..3e00c91 --- /dev/null +++ b/OpenSim.RegionServer/types/Mesh.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.types +{ + // TODO: This will need some performance tuning no doubt. + public class Mesh + { + public List mesh; + + public Mesh() + { + mesh = new List(); + } + + public void AddTri(Triangle tri) + { + mesh.Add(tri); + } + + public static Mesh operator +(Mesh a, Mesh b) + { + a.mesh.AddRange(b.mesh); + return a; + } + } +} diff --git a/OpenSim.RegionServer/types/Triangle.cs b/OpenSim.RegionServer/types/Triangle.cs new file mode 100644 index 0000000..8dfea6e --- /dev/null +++ b/OpenSim.RegionServer/types/Triangle.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Axiom.MathLib; + +namespace OpenSim.types +{ + public class Triangle + { + Vector3 a; + Vector3 b; + Vector3 c; + + public Triangle() + { + a = new Vector3(); + b = new Vector3(); + c = new Vector3(); + } + + public Triangle(Vector3 A, Vector3 B, Vector3 C) + { + a = A; + b = B; + c = C; + } + } +} diff --git a/OpenSim.RegionServer/world/Avatar.cs b/OpenSim.RegionServer/world/Avatar.cs new file mode 100644 index 0000000..b4a3b82 --- /dev/null +++ b/OpenSim.RegionServer/world/Avatar.cs @@ -0,0 +1,501 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim.Physics.Manager; +using Axiom.MathLib; + +namespace OpenSim.world +{ + public class Avatar : Entity + { + public static bool PhysicsEngineFlying = false; + public string firstname; + public string lastname; + public SimClient ControllingClient; + private PhysicsActor _physActor; + private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate; + private bool updateflag = false; + private byte movementflag = 0; + private List forcesList = new List(); + private short _updateCount = 0; + private Axiom.MathLib.Quaternion bodyRot; + + public Avatar(SimClient TheClient) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs - Loading details from grid (DUMMY)"); + ControllingClient = TheClient; + localid = 8880000 + (OpenSimRoot.Instance.LocalWorld._localNumber++); + position = new LLVector3(100.0f, 100.0f, 30.0f); + position.Z = OpenSimRoot.Instance.LocalWorld.LandMap[(int)position.Y * 256 + (int)position.X] + 1; + } + + public PhysicsActor PhysActor + { + set + { + this._physActor = value; + } + } + + public override void addForces() + { + lock (this.forcesList) + { + if (this.forcesList.Count > 0) + { + for (int i = 0; i < this.forcesList.Count; i++) + { + NewForce force = this.forcesList[i]; + PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z); + this._physActor.Velocity = phyVector; + this.updateflag = true; + this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this + // but as we are setting the velocity (rather than using real forces) at the moment it is okay. + } + for (int i = 0; i < this.forcesList.Count; i++) + { + this.forcesList.RemoveAt(0); + } + } + } + } + + public override void update() + { + + if (this.updateflag) + { + //need to send movement info + //so create the improvedterseobjectupdate packet + //use CreateTerseBlock() + ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock(); + ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); + terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME + terse.RegionData.TimeDilation = 64096; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = terseBlock; + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + client.OutPacket(terse); + } + + updateflag = false; + //this._updateCount = 0; + } + else + { + //if((movementflag & 1) !=0) + //{ + _updateCount++; + if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (_updateCount > 0)) + { + //It has been a while since last update was sent so lets send one. + ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock(); + ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); + terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME + terse.RegionData.TimeDilation = 64096; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = terseBlock; + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + client.OutPacket(terse); + } + _updateCount = 0; + } + //} + } + } + + public static void SetupTemplate(string name) + { + int i = 0; + FileInfo fInfo = new FileInfo(name); + long numBytes = fInfo.Length; + FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); + BinaryReader br = new BinaryReader(fStream); + byte[] data1 = br.ReadBytes((int)numBytes); + br.Close(); + fStream.Close(); + + libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i); + + System.Text.Encoding enc = System.Text.Encoding.ASCII; + libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16); + pos.X = 100f; + objdata.ID = 8880000; + objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0"); + libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f); + //objdata.FullID=user.AgentID; + byte[] pb = pos.GetBytes(); + Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length); + + Avatar.AvatarTemplate = objdata; + } + + public void CompleteMovement(World RegionInfo) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet"); + AgentMovementCompletePacket mov = new AgentMovementCompletePacket(); + mov.AgentData.SessionID = this.ControllingClient.SessionID; + mov.AgentData.AgentID = this.ControllingClient.AgentID; + mov.Data.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; + // TODO - dynamicalise this stuff + mov.Data.Timestamp = 1172750370; + mov.Data.Position = new LLVector3(100f, 100f, 23f); + mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0); + + ControllingClient.OutPacket(mov); + } + + public void SendInitialPosition() + { + + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + //send a objectupdate packet with information about the clients avatar + ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); + objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; + objupdate.RegionData.TimeDilation = 64096; + objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; + + objupdate.ObjectData[0] = AvatarTemplate; + //give this avatar object a local id and assign the user a name + objupdate.ObjectData[0].ID = this.localid; + this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID; + objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); + + libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z); + + byte[] pb = pos2.GetBytes(); + + Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); + OpenSimRoot.Instance.LocalWorld._localNumber++; + + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + client.OutPacket(objupdate); + if (client.AgentID != ControllingClient.AgentID) + { + SendAppearanceToOtherAgent(client); + } + } + //this.ControllingClient.OutPacket(objupdate); + } + + public void SendInitialAppearance() + { + AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); + aw.AgentData.AgentID = this.ControllingClient.AgentID; + aw.AgentData.SerialNum = 0; + aw.AgentData.SessionID = ControllingClient.SessionID; + + aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; + AgentWearablesUpdatePacket.WearableDataBlock awb = new AgentWearablesUpdatePacket.WearableDataBlock(); + awb.WearableType = (byte)0; + awb.AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); + awb.ItemID = LLUUID.Random(); + aw.WearableData[0] = awb; + + for (int i = 1; i < 13; i++) + { + awb = new AgentWearablesUpdatePacket.WearableDataBlock(); + awb.WearableType = (byte)i; + awb.AssetID = new LLUUID("00000000-0000-0000-0000-000000000000"); + awb.ItemID = new LLUUID("00000000-0000-0000-0000-000000000000"); + aw.WearableData[i] = awb; + } + + ControllingClient.OutPacket(aw); + } + + public ObjectUpdatePacket CreateUpdatePacket() + { + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + //send a objectupdate packet with information about the clients avatar + ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); + objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; + objupdate.RegionData.TimeDilation = 64096; + objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; + + objupdate.ObjectData[0] = AvatarTemplate; + //give this avatar object a local id and assign the user a name + objupdate.ObjectData[0].ID = this.localid; + objupdate.ObjectData[0].FullID = ControllingClient.AgentID; + objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); + + libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z); + + byte[] pb = pos2.GetBytes(); + + Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); + return objupdate; + } + + public void SendAppearanceToOtherAgent(SimClient userInfo) + { + AvatarAppearancePacket avp = new AvatarAppearancePacket(); + + + avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218]; + //avp.ObjectData.TextureEntry=this.avatar_template.TextureEntry;// br.ReadBytes((int)numBytes); + + LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-0000-000000000005")); + avp.ObjectData.TextureEntry = ntex.ToBytes(); + + AvatarAppearancePacket.VisualParamBlock avblock = null; + for (int i = 0; i < 218; i++) + { + avblock = new AvatarAppearancePacket.VisualParamBlock(); + avblock.ParamValue = (byte)100; + avp.VisualParam[i] = avblock; + } + + avp.Sender.IsTrial = false; + avp.Sender.ID = ControllingClient.AgentID; + userInfo.OutPacket(avp); + + } + + public void HandleUpdate(AgentUpdatePacket pack) + { + if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_FLY) != 0) + { + this._physActor.Flying = true; + } + else + { + this._physActor.Flying = false; + } + if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_POS) != 0) + { + Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); + if (((movementflag & 1) == 0) || (q != this.bodyRot)) + { + //we should add a new force to the list + // but for now we will deal with velocities + NewForce newVelocity = new NewForce(); + Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0); + Axiom.MathLib.Vector3 direc = q * v3; + direc.Normalize(); + + //work out velocity for sim physics system + direc = direc * ((0.03f) * 128f); + if (this._physActor.Flying) + direc *= 2; + + newVelocity.X = direc.x; + newVelocity.Y = direc.y; + newVelocity.Z = direc.z; + this.forcesList.Add(newVelocity); + movementflag = 1; + this.bodyRot = q; + } + } + else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying)) + { + if (((movementflag & 2) == 0) && this._physActor.Flying) + { + //we should add a new force to the list + // but for now we will deal with velocities + NewForce newVelocity = new NewForce(); + Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1); + Axiom.MathLib.Vector3 direc = v3; + direc.Normalize(); + + //work out velocity for sim physics system + direc = direc * ((0.03f) * 128f * 2); + newVelocity.X = direc.x; + newVelocity.Y = direc.y; + newVelocity.Z = direc.z; + this.forcesList.Add(newVelocity); + movementflag = 2; + } + } + else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying)) + { + if (((movementflag & 4) == 0) && this._physActor.Flying) + { + //we should add a new force to the list + // but for now we will deal with velocities + NewForce newVelocity = new NewForce(); + Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1); + //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); + Axiom.MathLib.Vector3 direc = v3; + direc.Normalize(); + + //work out velocity for sim physics system + direc = direc * ((0.03f) * 128f * 2); + newVelocity.X = direc.x; + newVelocity.Y = direc.y; + newVelocity.Z = direc.z; + this.forcesList.Add(newVelocity); + movementflag = 4; + } + } + else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_NEG) != 0) + { + Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); + if (((movementflag & 8) == 0) || (q != this.bodyRot)) + { + //we should add a new force to the list + // but for now we will deal with velocities + NewForce newVelocity = new NewForce(); + Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0); + Axiom.MathLib.Vector3 direc = q * v3; + direc.Normalize(); + + //work out velocity for sim physics system + direc = direc * ((0.03f) * 128f); + if (this._physActor.Flying) + direc *= 2; + + newVelocity.X = direc.x; + newVelocity.Y = direc.y; + newVelocity.Z = direc.z; + this.forcesList.Add(newVelocity); + movementflag = 8; + this.bodyRot = q; + } + } + else + { + if ((movementflag) != 0) + { + NewForce newVelocity = new NewForce(); + newVelocity.X = 0; + newVelocity.Y = 0; + newVelocity.Z = 0; + this.forcesList.Add(newVelocity); + movementflag = 0; + } + } + } + + //should be moved somewhere else + public void SendRegionHandshake(World RegionInfo) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet"); + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + RegionHandshakePacket handshake = new RegionHandshakePacket(); + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details"); + handshake.RegionInfo.BillableFactor = 0; + handshake.RegionInfo.IsEstateManager = false; + handshake.RegionInfo.TerrainHeightRange00 = 60; + handshake.RegionInfo.TerrainHeightRange01 = 60; + handshake.RegionInfo.TerrainHeightRange10 = 60; + handshake.RegionInfo.TerrainHeightRange11 = 60; + handshake.RegionInfo.TerrainStartHeight00 = 10; + handshake.RegionInfo.TerrainStartHeight01 = 10; + handshake.RegionInfo.TerrainStartHeight10 = 10; + handshake.RegionInfo.TerrainStartHeight11 = 10; + handshake.RegionInfo.SimAccess = 13; + handshake.RegionInfo.WaterHeight = 20; + handshake.RegionInfo.RegionFlags = 72458694; + handshake.RegionInfo.SimName = _enc.GetBytes(OpenSimRoot.Instance.Cfg.RegionName + "\0"); + handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainBase0 = new LLUUID("b8d3965a-ad78-bf43-699b-bff8eca6c975"); + handshake.RegionInfo.TerrainBase1 = new LLUUID("abb783e6-3e93-26c0-248a-247666855da3"); + handshake.RegionInfo.TerrainBase2 = new LLUUID("179cdabd-398a-9b6b-1391-4dc333ba321f"); + handshake.RegionInfo.TerrainBase3 = new LLUUID("beb169c7-11ea-fff2-efe5-0f24dc881df2"); + handshake.RegionInfo.TerrainDetail0 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainDetail1 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainDetail2 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainDetail3 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37"); + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet"); + this.ControllingClient.OutPacket(handshake); + } + + public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() + { + byte[] bytes = new byte[60]; + int i = 0; + ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); + + dat.TextureEntry = AvatarTemplate.TextureEntry; + libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z); + + uint ID = this.localid; + + bytes[i++] = (byte)(ID % 256); + bytes[i++] = (byte)((ID >> 8) % 256); + bytes[i++] = (byte)((ID >> 16) % 256); + bytes[i++] = (byte)((ID >> 24) % 256); + bytes[i++] = 0; + bytes[i++] = 1; + i += 14; + bytes[i++] = 128; + bytes[i++] = 63; + + byte[] pb = pos2.GetBytes(); + Array.Copy(pb, 0, bytes, i, pb.Length); + i += 12; + ushort InternVelocityX; + ushort InternVelocityY; + ushort InternVelocityZ; + + Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z); + internDirec = internDirec / 128.0f; + internDirec.x += 1; + internDirec.y += 1; + internDirec.z += 1; + + InternVelocityX = (ushort)(32768 * internDirec.x); + InternVelocityY = (ushort)(32768 * internDirec.y); + InternVelocityZ = (ushort)(32768 * internDirec.z); + + ushort ac = 32767; + bytes[i++] = (byte)(InternVelocityX % 256); + bytes[i++] = (byte)((InternVelocityX >> 8) % 256); + bytes[i++] = (byte)(InternVelocityY % 256); + bytes[i++] = (byte)((InternVelocityY >> 8) % 256); + bytes[i++] = (byte)(InternVelocityZ % 256); + bytes[i++] = (byte)((InternVelocityZ >> 8) % 256); + + //accel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + //rot + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + //rotation vel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + dat.Data = bytes; + return (dat); + } + } + + public class NewForce + { + public float X; + public float Y; + public float Z; + + public NewForce() + { + + } + } +} diff --git a/OpenSim.RegionServer/world/Entity.cs b/OpenSim.RegionServer/world/Entity.cs new file mode 100644 index 0000000..780f3a0 --- /dev/null +++ b/OpenSim.RegionServer/world/Entity.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Axiom.MathLib; +using OpenSim.types; +using libsecondlife; + +namespace OpenSim.world +{ + public class Entity + { + public libsecondlife.LLUUID uuid; + public uint localid; + public LLVector3 position; + public LLVector3 velocity; + public Quaternion rotation; + protected string name; + protected List children; + + public Entity() + { + uuid = new libsecondlife.LLUUID(); + localid = 0; + position = new LLVector3(); + velocity = new LLVector3(); + rotation = new Quaternion(); + name = "(basic entity)"; + children = new List(); + } + public virtual void addForces() + { + foreach (Entity child in children) + { + child.addForces(); + } + } + public virtual void update() { + // Do any per-frame updates needed that are applicable to every type of entity + foreach (Entity child in children) + { + child.update(); + } + } + + public virtual string getName() + { + return name; + } + + public virtual Mesh getMesh() + { + Mesh mesh = new Mesh(); + + foreach (Entity child in children) + { + mesh += child.getMesh(); + } + + return mesh; + } + + public virtual void BackUp() + { + + } + } +} diff --git a/OpenSim.RegionServer/world/Primitive.cs b/OpenSim.RegionServer/world/Primitive.cs new file mode 100644 index 0000000..b190d81 --- /dev/null +++ b/OpenSim.RegionServer/world/Primitive.cs @@ -0,0 +1,485 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.types; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim.Framework.Interfaces; +using OpenSim.Physics.Manager; +using OpenSim.Framework.Assets; + +namespace OpenSim.world +{ + public class Primitive : Entity + { + protected float mesh_cutbegin; + protected float mesh_cutend; + protected PrimData primData; + protected bool newPrimFlag = false; + protected bool updateFlag = false; + protected bool dirtyFlag = false; + private ObjectUpdatePacket OurPacket; + private PhysicsActor _physActor; + private bool physicsEnabled = false; + private bool physicstest = false; //just added for testing + + public bool PhysicsEnabled + { + get + { + return physicsEnabled; + } + set + { + physicsEnabled = value; + } + } + public bool UpdateFlag + { + get + { + return updateFlag; + } + set + { + updateFlag = value; + } + } + public LLVector3 Scale + { + set + { + this.primData.Scale = value; + this.dirtyFlag = true; + } + get + { + return this.primData.Scale; + } + } + public PhysicsActor PhysActor + { + set + { + this._physActor = value; + } + } + + public Primitive() + { + mesh_cutbegin = 0.0f; + mesh_cutend = 1.0f; + } + + public override Mesh getMesh() + { + Mesh mesh = new Mesh(); + Triangle tri = new Triangle( + new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f), + new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f), + new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f)); + + mesh.AddTri(tri); + mesh += base.getMesh(); + + return mesh; + } + + public void UpdatePosition(LLVector3 pos) + { + this.position = pos; + if (this._physActor != null) // && this.physicsEnabled) + { + this._physActor.Position = new PhysicsVector(pos.X, pos.Y, pos.Z); + } + this.updateFlag = true; + } + + public override void update() + { + if (this.newPrimFlag) + { + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + client.OutPacket(OurPacket); + } + this.newPrimFlag = false; + } + else if (this.updateFlag) + { + ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); + terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME + terse.RegionData.TimeDilation = 64096; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = this.CreateImprovedBlock(); + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + client.OutPacket(terse); + } + this.updateFlag = false; + } + else if (this.dirtyFlag) + { + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + UpdateClient(client); + } + this.dirtyFlag = false; + } + else + { + if (this._physActor != null && this.physicsEnabled) + { + ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); + terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME + terse.RegionData.TimeDilation = 64096; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = this.CreateImprovedBlock(); + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + client.OutPacket(terse); + } + } + } + + if (this.physicstest) + { + LLVector3 pos = this.position; + pos.Z += 0.0001f; + this.UpdatePosition(pos); + this.physicstest = false; + } + } + + public void UpdateClient(SimClient RemoteClient) + { + + LLVector3 lPos; + if (this._physActor != null && this.physicsEnabled) + { + PhysicsVector pPos = this._physActor.Position; + lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); + } + else + { + lPos = this.position; + } + byte[] pb = lPos.GetBytes(); + Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length); + + // OurPacket should be update with the follwing in updateShape() rather than having to do it here + OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID; + OurPacket.ObjectData[0].PCode = this.primData.PCode; + OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin; + OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd; + OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX; + OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY; + OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX; + OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY; + OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew; + OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin; + OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd; + OurPacket.ObjectData[0].Scale = this.primData.Scale; + OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve; + OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve; + OurPacket.ObjectData[0].ParentID = 0; + OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow; + //finish off copying rest of shape data + OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset; + OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions; + OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX; + OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY; + OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist; + OurPacket.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin; + + RemoteClient.OutPacket(OurPacket); + } + + public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket) + { + this.primData.PathBegin = addPacket.PathBegin; + this.primData.PathEnd = addPacket.PathEnd; + this.primData.PathScaleX = addPacket.PathScaleX; + this.primData.PathScaleY = addPacket.PathScaleY; + this.primData.PathShearX = addPacket.PathShearX; + this.primData.PathShearY = addPacket.PathShearY; + this.primData.PathSkew = addPacket.PathSkew; + this.primData.ProfileBegin = addPacket.ProfileBegin; + this.primData.ProfileEnd = addPacket.ProfileEnd; + this.primData.PathCurve = addPacket.PathCurve; + this.primData.ProfileCurve = addPacket.ProfileCurve; + this.primData.ProfileHollow = addPacket.ProfileHollow; + this.primData.PathRadiusOffset = addPacket.PathRadiusOffset; + this.primData.PathRevolutions = addPacket.PathRevolutions; + this.primData.PathTaperX = addPacket.PathTaperX; + this.primData.PathTaperY = addPacket.PathTaperY; + this.primData.PathTwist = addPacket.PathTwist; + this.primData.PathTwistBegin = addPacket.PathTwistBegin; + this.dirtyFlag = true; + } + + public void UpdateTexture(byte[] tex) + { + this.primData.Texture = this.OurPacket.ObjectData[0].TextureEntry = tex; + this.dirtyFlag = true; + } + + public void UpdateObjectFlags(ObjectFlagUpdatePacket pack) + { + if (this._physActor != null) + { + if (this._physActor.Kinematic == pack.AgentData.UsePhysics) + { + this._physActor.Kinematic = !pack.AgentData.UsePhysics; //if Usephysics = true, then Kinematic should = false + } + this.physicsEnabled = pack.AgentData.UsePhysics; + if (this._physActor.Kinematic == false) + { + LLVector3 pos = this.position; + this.UpdatePosition(pos); + pos.Z += 0.000001f; + this.UpdatePosition(pos); + this.physicstest = true; + } + else + { + PhysicsVector vec = this._physActor.Position; + LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z); + this.position = pos; + this.updateFlag = true; + } + } + } + + public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID) + { + ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); + objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; + objupdate.RegionData.TimeDilation = 64096; + + objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; + PrimData PData = new PrimData(); + this.primData = PData; + objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock(); + objupdate.ObjectData[0].PSBlock = new byte[0]; + objupdate.ObjectData[0].ExtraParams = new byte[1]; + objupdate.ObjectData[0].MediaURL = new byte[0]; + objupdate.ObjectData[0].NameValue = new byte[0]; + objupdate.ObjectData[0].Text = new byte[0]; + objupdate.ObjectData[0].TextColor = new byte[4]; + objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0); + objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0); + objupdate.ObjectData[0].Material = 3; + objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456; + objupdate.ObjectData[0].TextureAnim = new byte[0]; + objupdate.ObjectData[0].Sound = LLUUID.Zero; + LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); + objupdate.ObjectData[0].TextureEntry = ntex.ToBytes(); + objupdate.ObjectData[0].State = 0; + objupdate.ObjectData[0].Data = new byte[0]; + PData.OwnerID = objupdate.ObjectData[0].OwnerID = agentID; + PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode; + PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin; + PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd; + PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX; + PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY; + PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX; + PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY; + PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew; + PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin; + PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd; + PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale; + PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve; + PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve; + PData.ParentID = objupdate.ObjectData[0].ParentID = 0; + PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow; + + PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset; + PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions; + PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX; + PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY; + PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist; + PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin; + + objupdate.ObjectData[0].ID = (uint)(localID); + objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000")); + objupdate.ObjectData[0].ObjectData = new byte[60]; + objupdate.ObjectData[0].ObjectData[46] = 128; + objupdate.ObjectData[0].ObjectData[47] = 63; + LLVector3 pos1 = addPacket.ObjectData.RayEnd; + //update position + byte[] pb = pos1.GetBytes(); + Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); + + this.newPrimFlag = true; + this.uuid = objupdate.ObjectData[0].FullID; + this.localid = objupdate.ObjectData[0].ID; + this.position = pos1; + this.OurPacket = objupdate; + } + + public void CreateFromStorage(PrimData store) + { + //need to clean this up as it shares a lot of code with CreateFromPacket() + ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); + objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; + objupdate.RegionData.TimeDilation = 64096; + objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; + + this.primData = store; + objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock(); + objupdate.ObjectData[0].PSBlock = new byte[0]; + objupdate.ObjectData[0].ExtraParams = new byte[1]; + objupdate.ObjectData[0].MediaURL = new byte[0]; + objupdate.ObjectData[0].NameValue = new byte[0]; + objupdate.ObjectData[0].Text = new byte[0]; + objupdate.ObjectData[0].TextColor = new byte[4]; + objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0); + objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0); + objupdate.ObjectData[0].Material = 3; + objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456; + objupdate.ObjectData[0].TextureAnim = new byte[0]; + objupdate.ObjectData[0].Sound = LLUUID.Zero; + + if (store.Texture == null) + { + LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); + objupdate.ObjectData[0].TextureEntry = ntex.ToBytes(); + } + else + { + objupdate.ObjectData[0].TextureEntry = store.Texture; + } + + objupdate.ObjectData[0].State = 0; + objupdate.ObjectData[0].Data = new byte[0]; + objupdate.ObjectData[0].OwnerID = this.primData.OwnerID; + objupdate.ObjectData[0].PCode = this.primData.PCode; + objupdate.ObjectData[0].PathBegin = this.primData.PathBegin; + objupdate.ObjectData[0].PathEnd = this.primData.PathEnd; + objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX; + objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY; + objupdate.ObjectData[0].PathShearX = this.primData.PathShearX; + objupdate.ObjectData[0].PathShearY = this.primData.PathShearY; + objupdate.ObjectData[0].PathSkew = this.primData.PathSkew; + objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin; + objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd; + objupdate.ObjectData[0].Scale = this.primData.Scale; + objupdate.ObjectData[0].PathCurve = this.primData.PathCurve; + objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve; + objupdate.ObjectData[0].ParentID = 0; + objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow; + //finish off copying rest of shape data + objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset; + objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions; + objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX; + objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY; + objupdate.ObjectData[0].PathTwist = this.primData.PathTwist; + objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin; + + objupdate.ObjectData[0].ID = (uint)store.LocalID; + objupdate.ObjectData[0].FullID = store.FullID; + + objupdate.ObjectData[0].ObjectData = new byte[60]; + objupdate.ObjectData[0].ObjectData[46] = 128; + objupdate.ObjectData[0].ObjectData[47] = 63; + LLVector3 pos1 = store.Position; + //update position + byte[] pb = pos1.GetBytes(); + Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); + + this.uuid = objupdate.ObjectData[0].FullID; + this.localid = objupdate.ObjectData[0].ID; + this.position = pos1; + this.OurPacket = objupdate; + + } + public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock() + { + uint ID = this.localid; + byte[] bytes = new byte[60]; + + int i = 0; + ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); + dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry; + + bytes[i++] = (byte)(ID % 256); + bytes[i++] = (byte)((ID >> 8) % 256); + bytes[i++] = (byte)((ID >> 16) % 256); + bytes[i++] = (byte)((ID >> 24) % 256); + bytes[i++] = 0; + bytes[i++] = 0; + + LLVector3 lPos; + Axiom.MathLib.Quaternion lRot; + if (this._physActor != null && this.physicsEnabled) + { + PhysicsVector pPos = this._physActor.Position; + lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); + lRot = this._physActor.Orientation; + } + else + { + lPos = this.position; + lRot = this.rotation; + } + byte[] pb = lPos.GetBytes(); + Array.Copy(pb, 0, bytes, i, pb.Length); + i += 12; + ushort ac = 32767; + + //vel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + //accel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + ushort rw, rx, ry, rz; + rw = (ushort)(32768 * (lRot.w + 1)); + rx = (ushort)(32768 * (lRot.x + 1)); + ry = (ushort)(32768 * (lRot.y + 1)); + rz = (ushort)(32768 * (lRot.z + 1)); + + //rot + bytes[i++] = (byte)(rx % 256); + bytes[i++] = (byte)((rx >> 8) % 256); + bytes[i++] = (byte)(ry % 256); + bytes[i++] = (byte)((ry >> 8) % 256); + bytes[i++] = (byte)(rz % 256); + bytes[i++] = (byte)((rz >> 8) % 256); + bytes[i++] = (byte)(rw % 256); + bytes[i++] = (byte)((rw >> 8) % 256); + + //rotation vel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + dat.Data = bytes; + return dat; + } + + public override void BackUp() + { + this.primData.FullID = this.uuid; + this.primData.LocalID = this.localid; + this.primData.Position = this.position; + this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w); + OpenSimRoot.Instance.LocalWorld.localStorage.StorePrim(this.primData); + } + } + +} diff --git a/OpenSim.RegionServer/world/ScriptEngine.cs b/OpenSim.RegionServer/world/ScriptEngine.cs new file mode 100644 index 0000000..f20a08e --- /dev/null +++ b/OpenSim.RegionServer/world/ScriptEngine.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.world +{ + public class ScriptEngine + { + public ScriptEngine(World env) + { + } + + public void LoadScript() + { + + } + } +} diff --git a/OpenSim.RegionServer/world/SurfacePatch.cs b/OpenSim.RegionServer/world/SurfacePatch.cs new file mode 100644 index 0000000..71e4116 --- /dev/null +++ b/OpenSim.RegionServer/world/SurfacePatch.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.world +{ + public class SurfacePatch + { + public float[] HeightMap; + + public SurfacePatch() { + HeightMap = new float[16*16]; + + int xinc; + int yinc; + for(xinc=0; xinc<16; xinc++) for(yinc=0; yinc<16; yinc++) { + HeightMap[xinc+(yinc*16)]=100.0f; + } + + } + } +} diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs new file mode 100644 index 0000000..ba99233 --- /dev/null +++ b/OpenSim.RegionServer/world/World.cs @@ -0,0 +1,213 @@ +using System; +using libsecondlife; +using libsecondlife.Packets; +using System.Collections.Generic; +using System.Text; +using System.Reflection; +using System.IO; +using OpenSim.Physics.Manager; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Assets; +using OpenSim.Framework.Terrain; + +namespace OpenSim.world +{ + public class World : ILocalStorageReceiver + { + public Dictionary Entities; + public float[] LandMap; + public ScriptEngine Scripts; + public uint _localNumber=0; + private PhysicsScene phyScene; + private float timeStep= 0.1f; + private libsecondlife.TerrainManager TerrainManager; + public ILocalStorage localStorage; + private Random Rand = new Random(); + private uint _primCount = 702000; + private int storageCount; + + public World() + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); + Entities = new Dictionary(); + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating LandMap"); + TerrainManager = new TerrainManager(new SecondLife()); + Avatar.SetupTemplate("avatar-template.dat"); + // ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance"); + // Initialise this only after the world has loaded + // Scripts = new ScriptEngine(this); + } + + public PhysicsScene PhysScene + { + set + { + this.phyScene = value; + } + get + { + return(this.phyScene); + } + } + + public void Update() + { + if(this.phyScene.IsThreaded) + { + this.phyScene.GetResults(); + + } + + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].addForces(); + } + + this.phyScene.Simulate(timeStep); + + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].update(); + } + + //backup world data + this.storageCount++; + if(storageCount> 1200) //set to how often you want to backup + { + this.Backup(); + storageCount =0; + } + } + + public bool LoadStorageDLL(string dllName) + { + Assembly pluginAssembly = Assembly.LoadFrom(dllName); + ILocalStorage store = null; + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("ILocalStorage", true); + + if (typeInterface != null) + { + ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + store = plug; + break; + } + + typeInterface = null; + } + } + } + pluginAssembly = null; + this.localStorage = store; + return(store == null); + } + + public void RegenerateTerrain() + { + HeightmapGenHills hills = new HeightmapGenHills(); + this.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false); + this.phyScene.SetTerrain(this.LandMap); + OpenSimRoot.Instance.Cfg.SaveMap(this.LandMap); + + foreach(SimClient client in OpenSimRoot.Instance.ClientThreads.Values) { + this.SendLayerData(client); + } + } + public void LoadPrimsFromStorage() + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives"); + this.localStorage.LoadPrimitives(this); + } + + public void PrimFromStorage(PrimData prim) + { + if(prim.LocalID >= this._primCount) + { + _primCount = prim.LocalID + 1; + } + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Reloading prim (localId "+ prim.LocalID+ " ) from storage"); + Primitive nPrim = new Primitive(); + nPrim.CreateFromStorage(prim); + this.Entities.Add(nPrim.uuid, nPrim); + } + + public void Close() + { + this.localStorage.ShutDown(); + } + + public void SendLayerData(SimClient RemoteClient) { + int[] patches = new int[4]; + + for (int y = 0; y < 16; y++) + { + for (int x = 0; x < 16; x = x + 4) + { + patches[0] = x + 0 + y * 16; + patches[1] = x + 1 + y * 16; + patches[2] = x + 2 + y * 16; + patches[3] = x + 3 + y * 16; + + Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches); + RemoteClient.OutPacket(layerpack); + } + } + } + + public void GetInitialPrims(SimClient RemoteClient) + { + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + if(Entities[UUID].ToString()== "OpenSim.world.Primitive") + { + ((OpenSim.world.Primitive)Entities[UUID]).UpdateClient(RemoteClient); + } + } + } + + public void AddViewerAgent(SimClient AgentClient) { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); + Avatar NewAvatar = new Avatar(AgentClient); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world"); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake "); + NewAvatar.SendRegionHandshake(this); + PhysicsVector pVec = new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z); + NewAvatar.PhysActor = this.phyScene.AddAvatar(pVec); + this.Entities.Add(AgentClient.AgentID, NewAvatar); + } + + public void AddNewPrim(ObjectAddPacket addPacket, SimClient AgentClient) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Creating new prim"); + Primitive prim = new Primitive(); + prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount); + PhysicsVector pVec = new PhysicsVector(prim.position.X, prim.position.Y, prim.position.Z); + PhysicsVector pSize = new PhysicsVector( 0.255f, 0.255f, 0.255f); + if(OpenSim.world.Avatar.PhysicsEngineFlying) + { + prim.PhysActor = this.phyScene.AddPrim(pVec, pSize ); + } + //prim.PhysicsEnabled = true; + this.Entities.Add(prim.uuid, prim); + this._primCount++; + } + + public bool Backup() { + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Backing up Primitives"); + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].BackUp(); + } + return true; + } + + } +} diff --git a/OpenSim.RegionServer/world/scripting/IScript.cs b/OpenSim.RegionServer/world/scripting/IScript.cs new file mode 100644 index 0000000..550594d --- /dev/null +++ b/OpenSim.RegionServer/world/scripting/IScript.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.world.scripting +{ + public interface IScriptHost { + bool Register(IScript iscript); + } + public interface IScript + { + string Name{get;set;} + IScriptHost Host{get;set;} + void Show(); + } +} -- cgit v1.1