commit 350f07e593fae4dfe40d671e1c372697f9831b1b Author: MW Date: Tue Mar 6 16:21:10 2007 +0000 Started to Convert to more of a plug-in system. SimConfig is now loaded from a Dll. GridServer and AssetServer classes are now loaded from Dlls. diff --git a/bin/avatar-template.dat b/bin/avatar-template.dat new file mode 100644 index 0000000000..c13c2c7ede Binary files /dev/null and b/bin/avatar-template.dat differ diff --git a/bin/new-login.dat b/bin/new-login.dat new file mode 100644 index 0000000000..3c911511aa --- /dev/null +++ b/bin/new-login.dat @@ -0,0 +1 @@ +messageWelcome to OpenSimsession_id99998888-8520-4f52-8ec1-0b1d5cd6aeadinventory-skel-libsim_port50000agent_accessMevent_notificationsstart_locationlastglobal-texturessun_texture_idcce0f112-878f-4586-a2e2-a8f104bba271cloud_texture_idfc4b9f0b-d008-45c6-96a4-01dd947ac621moon_texture_idd07f6eed-b96a-47cd-b51d-400ad4a1c428seconds_since_epoch1169908672first_name"Test"circuit_code50633318event_categorieslogin-flagsstipend_since_loginNever_logged_inYgenderedYdaylight_savingsNseed_capabilityhome{'region_handle':[r258560, r259840], 'position':[r41.6589, r100.8374, r22.5072], 'look_at':[r-0.57343, r-0.819255,r0]}secure_session_id71810f75-7437-49fb-8963-02b8fd1b95bflast_nameUserui-configallow_first_lifeYclassified_categoriescategory_nameShoppingcategory_id1category_nameLand Rentalcategory_id2category_nameProperty Rentalcategory_id3category_nameSpecial Attractioncategory_id4category_nameNew Productscategory_id5category_nameEmploymentcategory_id6category_nameWantedcategory_id7category_nameServicecategory_id8category_namePersonalcategory_id9region_x255232inventory-skeletonnameMy Inventoryparent_id00000000-0000-0000-0000-000000000000version4type_default8folder_idf798e114-c10f-409b-a90d-a11577ff1de8nameTexturesparent_idf798e114-c10f-409b-a90d-a11577ff1de8version1type_default0folder_idfc8b4059-30bb-43a8-a042-46f5b431ad82sim_ip127.0.0.1region_y254976gesturesinventory-lib-ownerinventory-rootfolder_idf798e114-c10f-409b-a90d-a11577ff1de8logintruelook_at[r0.99949799999999999756,r0.03166859999999999814,r0]agent_idaaaabbbb-8932-0271-8664-58f53e442797inventory-lib-rootinitial-outfitfolder_nameNightclub Femalegenderfemale \ No newline at end of file diff --git a/src/Assets/AssetCache.cs b/src/Assets/AssetCache.cs new file mode 100644 index 0000000000..3baebd601e --- /dev/null +++ b/src/Assets/AssetCache.cs @@ -0,0 +1,434 @@ +/* +* 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.GridServers; + +namespace OpenSim.Assets +{ + /// + /// Manages local cache of assets and their sending to viewers. + /// + public class AssetCache : IAssetReceiver + { + public Dictionary Assets; + public Dictionary Textures; + + public List AssetRequests = new List(); //assets ready to be sent to viewers + public List TextureRequests = new List(); //textures ready to be sent + + public Dictionary RequestedAssets = new Dictionary(); //Assets requested from the asset server + public Dictionary RequestedTextures = new Dictionary(); //Textures requested from the asset server + + private IAssetServer _assetServer; + private Thread _assetCacheThread; + + /// + /// + /// + public AssetCache( IAssetServer assetServer) + { + _assetServer = assetServer; + _assetServer.SetReceiver(this); + this._assetCacheThread = new Thread( new ThreadStart(RunAssetManager)); + this._assetCacheThread.IsBackground = true; + this._assetCacheThread.Start(); + } + + /// + /// + /// + private void RunAssetManager() + { + this.ProcessAssetQueue(); + this.ProcessTextureQueue(); + Thread.Sleep(100); + } + + /// + /// + /// + private void ProcessTextureQueue() + { + if(this.TextureRequests.Count == 0) + { + //no requests waiting + return; + } + int num; + + if(this.TextureRequests.Count < 5) + { + //lower than 5 so do all of them + num = this.TextureRequests.Count; + } + else + { + num=5; + } + AssetRequest req; + for(int i = 0; i < num; i++) + { + req=(AssetRequest)this.TextureRequests[i]; + + if(req.PacketCounter == 0) + { + //first time for this request so send imagedata packet + if(req.NumPackets == 1) + { + //only one packet so send whole file + ImageDataPacket im = new ImageDataPacket(); + im.ImageID.Packets = 1; + im.ImageID.ID = req.ImageInfo.FullID; + im.ImageID.Size = (uint)req.ImageInfo.Data.Length; + im.ImageData.Data = req.ImageInfo.Data; + im.ImageID.Codec = 2; + req.RequestUser.OutPacket(im); + req.PacketCounter++; + //req.ImageInfo.l= time; + //System.Console.WriteLine("sent texture: "+req.image_info.FullID); + } + else + { + //more than one packet so split file up + ImageDataPacket im = new ImageDataPacket(); + im.ImageID.Packets = (ushort)req.NumPackets; + im.ImageID.ID = req.ImageInfo.FullID; + im.ImageID.Size = (uint)req.ImageInfo.Data.Length; + im.ImageData.Data = new byte[600]; + Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600); + im.ImageID.Codec = 2; + req.RequestUser.OutPacket(im); + req.PacketCounter++; + //req.ImageInfo.last_used = time; + //System.Console.WriteLine("sent first packet of texture: + } + } + else + { + //send imagepacket + //more than one packet so split file up + ImagePacketPacket im = new ImagePacketPacket(); + im.ImageID.Packet = (ushort)req.PacketCounter; + im.ImageID.ID = req.ImageInfo.FullID; + int size = req.ImageInfo.Data.Length - 600 - 1000*(req.PacketCounter - 1); + if(size > 1000) size = 1000; + im.ImageData.Data = new byte[size]; + Array.Copy(req.ImageInfo.Data, 600 + 1000*(req.PacketCounter - 1), im.ImageData.Data, 0, size); + req.RequestUser.OutPacket(im); + req.PacketCounter++; + //req.ImageInfo.last_used = time; + //System.Console.WriteLine("sent a packet of texture: "+req.image_info.FullID); + } + } + + //remove requests that have been completed + int count = 0; + for(int i = 0; i < num; i++) + { + req=(AssetRequest)this.TextureRequests[count]; + if(req.PacketCounter == req.NumPackets) + { + this.TextureRequests.Remove(req); + } + else + { + count++; + } + } + + } + public void AssetReceived(AssetBase asset, bool IsTexture) + { + //check if it is a texture or not + //then add to the correct cache list + //then check for waiting requests for this asset/texture (in the Requested lists) + //and move those requests into the Requests list. + if(IsTexture) + { + TextureImage image = new TextureImage(asset); + this.Textures.Add(image.FullID, image); + if(this.RequestedTextures.ContainsKey(image.FullID)) + { + AssetRequest req = this.RequestedTextures[image.FullID]; + req.ImageInfo = image; + this.RequestedTextures.Remove(image.FullID); + this.TextureRequests.Add(req); + } + } + else + { + AssetInfo assetInf = new AssetInfo(asset); + this.Assets.Add(assetInf.FullID, assetInf); + if(this.RequestedAssets.ContainsKey(assetInf.FullID)) + { + AssetRequest req = this.RequestedAssets[assetInf.FullID]; + req.AssetInf = assetInf; + this.RequestedAssets.Remove(assetInf.FullID); + this.AssetRequests.Add(req); + } + } + } + + public void AssetNotFound(AssetBase asset) + { + //the asset server had no knowledge of requested asset + + } + + #region Assets + /// + /// + /// + /// + /// + public void AddAssetRequest(OpenSimClient userInfo, TransferRequestPacket transferRequest) + { + LLUUID requestID = new LLUUID(transferRequest.TransferInfo.Params, 0); + //check to see if asset is in local cache, if not we need to request it from asset server. + if(!this.Assets.ContainsKey(requestID)) + { + //not found asset + // so request from asset server + AssetRequest request = new AssetRequest(); + request.RequestUser = userInfo; + request.RequestAssetID = requestID; + request.TransferRequestID = transferRequest.TransferInfo.TransferID; + this.RequestedAssets.Add(requestID,request); + this._assetServer.RequestAsset(requestID, false); + return; + } + //it is in our cache + AssetInfo asset = this.Assets[requestID]; + + //work out how many packets it should be sent in + // and add to the AssetRequests list + AssetRequest req = new AssetRequest(); + req.RequestUser = userInfo; + req.RequestAssetID = requestID; + req.TransferRequestID = transferRequest.TransferInfo.TransferID; + req.AssetInf = asset; + + if(asset.Data.LongLength>600) + { + //over 600 bytes so split up file + req.NumPackets = 1 + (int)(asset.Data.Length-600+999)/1000; + } + else + { + req.NumPackets = 1; + } + + this.AssetRequests.Add(req); + } + + /// + /// + /// + private void ProcessAssetQueue() + { + if(this.AssetRequests.Count == 0) + { + //no requests waiting + return; + } + int num; + + if(this.AssetRequests.Count < 5) + { + //lower than 5 so do all of them + num = this.AssetRequests.Count; + } + else + { + num=5; + } + AssetRequest req; + for(int i = 0; i < num; i++) + { + req=(AssetRequest)this.AssetRequests[i]; + + TransferInfoPacket Transfer = new TransferInfoPacket(); + Transfer.TransferInfo.ChannelType = 2; + Transfer.TransferInfo.Status = 0; + Transfer.TransferInfo.TargetType = 0; + Transfer.TransferInfo.Params = req.RequestAssetID.GetBytes(); + Transfer.TransferInfo.Size = (int)req.AssetInf.Data.Length; + Transfer.TransferInfo.TransferID = req.TransferRequestID; + req.RequestUser.OutPacket(Transfer); + + if(req.NumPackets == 1) + { + TransferPacketPacket TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 0; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID=req.TransferRequestID; + TransferPacket.TransferData.Data = req.AssetInf.Data; + TransferPacket.TransferData.Status = 1; + req.RequestUser.OutPacket(TransferPacket); + } + else + { + //more than one packet so split file up , for now it can't be bigger than 2000 bytes + TransferPacketPacket TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 0; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID=req.TransferRequestID; + byte[] chunk = new byte[1000]; + Array.Copy(req.AssetInf.Data,chunk,1000); + TransferPacket.TransferData.Data = chunk; + TransferPacket.TransferData.Status = 0; + req.RequestUser.OutPacket(TransferPacket); + + TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 1; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID = req.TransferRequestID; + byte[] chunk1 = new byte[(req.AssetInf.Data.Length-1000)]; + Array.Copy(req.AssetInf.Data, 1000, chunk1, 0, chunk1.Length); + TransferPacket.TransferData.Data = chunk1; + TransferPacket.TransferData.Status = 1; + req.RequestUser.OutPacket(TransferPacket); + } + + } + + //remove requests that have been completed + for(int i = 0; i < num; i++) + { + this.AssetRequests.RemoveAt(0); + } + + } + + #endregion + + #region Textures + /// + /// + /// + /// + /// + public void AddTextureRequest(OpenSimClient userInfo, LLUUID imageID) + { + //check to see if texture is in local cache, if not request from asset server + if(!this.Textures.ContainsKey(imageID)) + { + //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); + } + #endregion + + } + + public class AssetRequest + { + public OpenSimClient RequestUser; + public LLUUID RequestAssetID; + public AssetInfo AssetInf; + public TextureImage ImageInfo; + public LLUUID TransferRequestID; + public long DataPointer = 0; + public int NumPackets = 0; + public int PacketCounter = 0; + public bool IsTextureRequest; + //public bool AssetInCache; + //public int TimeRequested; + + public AssetRequest() + { + + } + } + + public class AssetInfo : AssetBase + { + public AssetInfo() + { + + } + + public AssetInfo(AssetBase aBase) + { + Data= aBase.Data; + FullID = aBase.FullID; + Type = aBase.Type; + InvType = aBase.InvType; + Name= aBase.Name; + Description = aBase.Description; + } + } + + public class TextureImage : AssetBase + { + public TextureImage() + { + + } + + public TextureImage(AssetBase aBase) + { + Data= aBase.Data; + FullID = aBase.FullID; + Type = aBase.Type; + InvType = aBase.InvType; + Name= aBase.Name; + Description = aBase.Description; + } + } + +} diff --git a/src/Config.cs b/src/Config.cs new file mode 100644 index 0000000000..c42b80ecec --- /dev/null +++ b/src/Config.cs @@ -0,0 +1,72 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + +* Copyright (c) , +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.IO; +using libsecondlife; +using OpenSim.world; + +namespace OpenSim +{ + /// + /// This class handles connection to the underlying database used for configuration of the region. + /// Region content is also stored by this class. The main entry point is InitConfig() which attempts to locate + /// opensim.yap in the current working directory. If opensim.yap can not be found, default settings are loaded from + /// what is hardcoded here and then saved into opensim.yap for future startups. + /// + + + public abstract class SimConfig + { + public string RegionName; + + public uint RegionLocX; + public uint RegionLocY; + public ulong RegionHandle; + + public int IPListenPort; + public string IPListenAddr; + + public string AssetURL; + public string AssetSendKey; + + public string GridURL; + public string GridSendKey; + + public abstract void InitConfig(); + public abstract void LoadFromGrid(); + public abstract World LoadWorld(); + } + + public interface ISimConfig + { + SimConfig GetConfigObject(); + } +} diff --git a/src/Config/SimConfig/AssemblyInfo.cs b/src/Config/SimConfig/AssemblyInfo.cs new file mode 100644 index 0000000000..96c3e7383d --- /dev/null +++ b/src/Config/SimConfig/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("SimConfig")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SimConfig")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] diff --git a/src/Config/SimConfig/Db4SimConfig.cs b/src/Config/SimConfig/Db4SimConfig.cs new file mode 100644 index 0000000000..e46e8d593a --- /dev/null +++ b/src/Config/SimConfig/Db4SimConfig.cs @@ -0,0 +1,126 @@ +/* +* 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 OpenSim; +using OpenSim.world; +using Db4objects.Db4o; + +namespace Db40SimConfig +{ + public class Db40ConfigPlugin: ISimConfig + { + public SimConfig GetConfigObject() + { + Console.WriteLine("Loading Config dll"); + return ( new DbSimConfig()); + } + } + + public class DbSimConfig :SimConfig + { + + private IObjectContainer db; + + + public void LoadDefaults() { + this.RegionName = "OpenSim test\0"; + this.RegionLocX = 997; + this.RegionLocY = 996; + this.RegionHandle = Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); + this.IPListenPort = 9000; + this.IPListenAddr = "127.0.0.1"; + this.AssetURL = "http://www.osgrid.org/ogs/assetserver/"; + this.AssetSendKey = "1234"; + this.GridURL = "http://www.osgrid.org/ogs/gridserver/"; + this.GridSendKey = "1234"; + } + + public override void InitConfig() { + try { + db = Db4oFactory.OpenFile("opensim.yap"); + IObjectSet result = db.Get(typeof(DbSimConfig)); + if(result.Count==1) { + Console.WriteLine("Config.cs:InitConfig() - Found a SimConfig object in the local database, loading"); + foreach (DbSimConfig cfg in result) { + this.RegionName = cfg.RegionName; + this.RegionLocX = cfg.RegionLocX; + this.RegionLocY = cfg.RegionLocY; + this.RegionHandle = Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); + this.IPListenPort = cfg.IPListenPort; + this.IPListenAddr = cfg.IPListenAddr; + this.AssetURL = cfg.AssetURL; + this.AssetSendKey = cfg.AssetSendKey; + this.GridURL = cfg.GridURL; + this.GridSendKey = cfg.GridSendKey; + } + } else { + Console.WriteLine("Config.cs:InitConfig() - Could not find object in database, loading precompiled defaults"); + LoadDefaults(); + Console.WriteLine("Writing out default settings to local database"); + db.Set(this); + } + } catch(Exception e) { + db.Close(); + Console.WriteLine("Config.cs:InitConfig() - Exception occured"); + Console.WriteLine(e.ToString()); + } + } + + public override World LoadWorld() { + IObjectSet world_result = db.Get(typeof(OpenSim.world.World)); + if(world_result.Count==1) { + Console.WriteLine("Config.cs:LoadWorld() - Found an OpenSim.world.World object in local database, loading"); + return (World)world_result.Next(); + } else { + Console.WriteLine("Config.cs:LoadWorld() - Could not find the world or too many worlds! Constructing blank one"); + World blank = new World(); + Console.WriteLine("Config.cs:LoadWorld() - Saving initial world state to disk"); + db.Set(blank); + db.Commit(); + return blank; + } + } + + public override void LoadFromGrid() { + Console.WriteLine("Config.cs:LoadFromGrid() - dummy function, DOING ABSOLUTELY NOTHING AT ALL!!!"); + // TODO: Make this crap work + /* WebRequest GridLogin = WebRequest.Create(this.GridURL + "regions/" + this.RegionHandle.ToString() + "/login"); + WebResponse GridResponse = GridLogin.GetResponse(); + byte[] idata = new byte[(int)GridResponse.ContentLength]; + BinaryReader br = new BinaryReader(GridResponse.GetResponseStream()); + + br.Close(); + GridResponse.Close(); + */ + } + + public void Shutdown() { + db.Close(); + } + } +} diff --git a/src/Config/SimConfig/SimConfig.csproj b/src/Config/SimConfig/SimConfig.csproj new file mode 100644 index 0000000000..57f5979404 --- /dev/null +++ b/src/Config/SimConfig/SimConfig.csproj @@ -0,0 +1,43 @@ + + + Library + SimConfig + SimConfig + Debug + AnyCPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A} + + + bin\Debug\ + False + DEBUG;TRACE + True + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + ..\..\bin\OpenSim.exe + False + + + ..\..\bin\Db4objects.Db4o.dll + False + + + + + + + + \ No newline at end of file diff --git a/src/Config/SimConfig/SimConfig.sln b/src/Config/SimConfig/SimConfig.sln new file mode 100644 index 0000000000..944d6a8029 --- /dev/null +++ b/src/Config/SimConfig/SimConfig.sln @@ -0,0 +1,7 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# SharpDevelop 2.1.0.2017 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimConfig", "SimConfig.csproj", "{B063760D-DB8D-4F64-B6FE-335FAD1E650A}" +EndProject +Global +EndGlobal diff --git a/src/GridInterfaces/AssemblyInfo.cs b/src/GridInterfaces/AssemblyInfo.cs new file mode 100644 index 0000000000..89731a1f0d --- /dev/null +++ b/src/GridInterfaces/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("GridInterfaces")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GridInterfaces")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] diff --git a/src/GridInterfaces/GridInterfaces.csproj b/src/GridInterfaces/GridInterfaces.csproj new file mode 100644 index 0000000000..a1e56b6679 --- /dev/null +++ b/src/GridInterfaces/GridInterfaces.csproj @@ -0,0 +1,40 @@ + + + Library + GridInterfaces + GridInterfaces + Debug + AnyCPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9} + + + bin\Debug\ + False + DEBUG;TRACE + True + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + ..\..\Libsecond-dailys\libsl-03-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll + False + + + + + + + + + \ No newline at end of file diff --git a/src/GridInterfaces/GridInterfaces.sln b/src/GridInterfaces/GridInterfaces.sln new file mode 100644 index 0000000000..5ac2b6d5ad --- /dev/null +++ b/src/GridInterfaces/GridInterfaces.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# SharpDevelop 2.1.0.2017 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GridInterfaces", "GridInterfaces.csproj", "{5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|Any CPU.Build.0 = Release|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/GridInterfaces/IAssetServer.cs b/src/GridInterfaces/IAssetServer.cs new file mode 100644 index 0000000000..6050a6c679 --- /dev/null +++ b/src/GridInterfaces/IAssetServer.cs @@ -0,0 +1,82 @@ +/* +* 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.Net; +using System.Net.Sockets; +using System.IO; +using System.Threading; +using libsecondlife; + + +namespace OpenSim.GridServers +{ + /// + /// Description of IAssetServer. + /// + + public interface IAssetServer + { + void SetReceiver(IAssetReceiver receiver); + void RequestAsset(LLUUID assetID, bool isTexture); + void UpdateAsset(AssetBase asset); + void UploadNewAsset(AssetBase asset); + void SetServerInfo(string ServerUrl, string ServerKey); + } + + // could change to delegate? + public interface IAssetReceiver + { + void AssetReceived(AssetBase asset, bool IsTexture); + void AssetNotFound(AssetBase asset); + } + + public struct ARequest + { + public LLUUID AssetID; + public bool IsTexture; + } + + public class AssetBase + { + public byte[] Data; + public LLUUID FullID; + public sbyte Type; + public sbyte InvType; + public string Name; + public string Description; + + public AssetBase() + { + + } + } + + public interface IAssetPlugin + { + IAssetServer GetAssetServer(); + } +} diff --git a/src/GridInterfaces/IGridServer.cs b/src/GridInterfaces/IGridServer.cs new file mode 100644 index 0000000000..48f92896c1 --- /dev/null +++ b/src/GridInterfaces/IGridServer.cs @@ -0,0 +1,93 @@ +/* +* 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.Net; +using System.Net.Sockets; +using System.IO; +using libsecondlife; + +namespace OpenSim.GridServers +{ + /// + /// Handles connection to Grid Servers. + /// also Sim to Sim connections? + /// + + + + + public interface IGridServer + { + bool RequestConnection(); + UUIDBlock RequestUUIDBlock(); + void RequestNeighbours(); //should return a array of neighbouring regions + AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode); + void SetServerInfo(string ServerUrl, string ServerKey); + void AddNewSession(Login session); // only used by local version of grid server + // and didn't use to be part of this interface until we put this in a dll + } + + public struct UUIDBlock + { + public LLUUID BlockStart; + public LLUUID BlockEnd; + } + + public class AuthenticateResponse + { + public bool Authorised; + public Login LoginInfo; + + public AuthenticateResponse() + { + + } + + } + + public class Login + { + public string First = "Test"; + public string Last = "User"; + public LLUUID Agent; + public LLUUID Session; + public LLUUID InventoryFolder; + public LLUUID BaseFolder; + public Login() + { + + } + } + + public interface IGridPlugin + { + IGridServer GetGridServer(); + } +} diff --git a/src/GridServers/LoginServer.cs b/src/GridServers/LoginServer.cs new file mode 100644 index 0000000000..da982e77f5 --- /dev/null +++ b/src/GridServers/LoginServer.cs @@ -0,0 +1,322 @@ +/* +* 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; + +namespace OpenSim.GridServers +{ + + /// + /// When running in local (default) mode , handles client logins. + /// + public class LoginServer + { + public LoginServer(IGridServer gridServer) + { + _gridServer = gridServer; + } + private Login _login; + private IGridServer _gridServer; + private ushort _loginPort = 8080; + public IPAddress clientAddress = IPAddress.Loopback; + public IPAddress remoteAddress = IPAddress.Any; + private Socket loginServer; + private Random RandomClass = new Random(); + private int NumClients; + private string _defaultResponse; + + private string _mpasswd; + private bool _needPasswd=false; + + // InitializeLogin: initialize the login + private void InitializeLogin() { + loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort)); + loginServer.Listen(1); + + 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"); + } + + 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); + + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content)); + if(request.MethodName == "login_to_simulator") + { + 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)) + { + // Fail miserably + writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); + writer.WriteLine(); + return; + } + NumClients++; + + //create a agent and session LLUUID + Agent = GetAgentId( first, last ); + int SessionRand = this.RandomClass.Next(1,999); + Session = new LLUUID("aaaabbbb-0200-"+SessionRand.ToString("0000")+"-8664-58f53e442797"); + + + XmlRpcResponse response =(XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); + Hashtable responseData = (Hashtable)response.Value; + + responseData["sim_port"] = OpenSim_Main.cfg.IPListenPort; + responseData["sim_ip"] = OpenSim_Main.cfg.IPListenAddr; + responseData["agent_id"] = Agent.ToStringHyphenated(); + responseData["session_id"] = Session.ToStringHyphenated(); + 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"] =6; + 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 ); + + this._login = new Login(); + //copy data to login object + _login.First = first; + _login.Last = last; + _login.Agent = Agent; + _login.Session = Session; + _login.BaseFolder = BaseFolderID; + _login.InventoryFolder = InventoryFolderID; + + //working on local computer so lets add to the gridserver's list of sessions + 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(); + } + else + { + writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); + writer.WriteLine(); + } + } + } + + protected virtual void CustomiseLoginResponse( Hashtable responseData, string first, string last ) + { + } + + protected virtual LLUUID GetAgentId(string firstName, string lastName) + { + LLUUID Agent; + int AgentRand = this.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(); + } + + } + + +} diff --git a/src/LocalServers/LocalGridServers/AssemblyInfo.cs b/src/LocalServers/LocalGridServers/AssemblyInfo.cs new file mode 100644 index 0000000000..103b49a207 --- /dev/null +++ b/src/LocalServers/LocalGridServers/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("LocalGridServers")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("LocalGridServers")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] diff --git a/src/LocalServers/LocalGridServers/LocalGrid.cs b/src/LocalServers/LocalGridServers/LocalGrid.cs new file mode 100644 index 0000000000..2aab4560e4 --- /dev/null +++ b/src/LocalServers/LocalGridServers/LocalGrid.cs @@ -0,0 +1,200 @@ +/* +* 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 OpenSim.GridServers; +using libsecondlife; + +namespace LocalGridServers +{ + /// + /// + /// + /// + public class LocalGridPlugin : IGridPlugin + { + public LocalGridPlugin() + { + + } + + public IGridServer GetGridServer() + { + return(new LocalGridServer()); + } + } + + public class LocalAssetPlugin : IAssetPlugin + { + public LocalAssetPlugin() + { + + } + + public IAssetServer GetAssetServer() + { + return(new LocalAssetServer()); + } + } + + public class LocalAssetServer : IAssetServer + { + private IAssetReceiver _receiver; + private BlockingQueue _assetRequests; + + public LocalAssetServer() + { + this._assetRequests = new BlockingQueue(); + Console.WriteLine("Local Asset Server class created"); + } + + public void SetReceiver(IAssetReceiver receiver) + { + this._receiver = receiver; + } + + public void RequestAsset(LLUUID assetID, bool isTexture) + { + ARequest req = new ARequest(); + req.AssetID = assetID; + req.IsTexture = isTexture; + //this._assetRequests.Enqueue(req); + } + + public void UpdateAsset(AssetBase asset) + { + + } + + public void UploadNewAsset(AssetBase asset) + { + + } + + public void SetServerInfo(string ServerUrl, string ServerKey) + { + + } + + private void RunRequests() + { + while(true) + { + + } + } + } + + public class LocalGridServer :IGridServer + { + public List Sessions = new List(); + + public LocalGridServer() + { + Sessions = new List(); + Console.WriteLine("Local Grid Server class created"); + } + + public bool RequestConnection() + { + return true; + } + public AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) + { + //we are running local + AuthenticateResponse user = new AuthenticateResponse(); + + lock(this.Sessions) + { + + for(int i = 0; i < Sessions.Count; i++) + { + if((Sessions[i].Agent == agentID) && (Sessions[i].Session == sessionID)) + { + user.Authorised = true; + user.LoginInfo = Sessions[i]; + } + } + } + return(user); + } + + public UUIDBlock RequestUUIDBlock() + { + UUIDBlock uuidBlock = new UUIDBlock(); + return(uuidBlock); + } + + public void RequestNeighbours() + { + return; + } + + public void SetServerInfo(string ServerUrl, string ServerKey) + { + + } + /// + /// used by the local login server to inform us of new sessions + /// + /// + public void AddNewSession(Login session) + { + lock(this.Sessions) + { + this.Sessions.Add(session); + } + } + } + + public class BlockingQueue< T > { + private Queue< T > _queue = new Queue< T >(); + private object _queueSync = new object(); + + public void Enqueue(T value) + { + lock(_queueSync) + { + _queue.Enqueue(value); + Monitor.Pulse(_queueSync); + } + } + + public T Dequeue() + { + lock(_queueSync) + { + if( _queue.Count < 1) + Monitor.Wait(_queueSync); + + return _queue.Dequeue(); + } + } + } + +} diff --git a/src/LocalServers/LocalGridServers/LocalGridServers.csproj b/src/LocalServers/LocalGridServers/LocalGridServers.csproj new file mode 100644 index 0000000000..b7a49493f8 --- /dev/null +++ b/src/LocalServers/LocalGridServers/LocalGridServers.csproj @@ -0,0 +1,43 @@ + + + Library + LocalGridServers + LocalGridServers + Debug + AnyCPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62} + + + bin\Debug\ + False + DEBUG;TRACE + True + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + ..\..\..\GridInterfaces\GridInterfaces\bin\Debug\GridInterfaces.dll + False + + + ..\..\..\Libsecond-dailys\libsl-03-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll + False + + + + + + + + \ No newline at end of file diff --git a/src/LocalServers/LocalGridServers/LocalGridServers.sln b/src/LocalServers/LocalGridServers/LocalGridServers.sln new file mode 100644 index 0000000000..659e1d54fb --- /dev/null +++ b/src/LocalServers/LocalGridServers/LocalGridServers.sln @@ -0,0 +1,7 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# SharpDevelop 2.1.0.2017 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalGridServers", "LocalGridServers.csproj", "{D7F0395B-FADC-4936-80A0-D95AACE92F62}" +EndProject +Global +EndGlobal diff --git a/src/Main.cs b/src/Main.cs new file mode 100644 index 0000000000..4794fcfa8f --- /dev/null +++ b/src/Main.cs @@ -0,0 +1,299 @@ +/* +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.GridServers; +using OpenSim.Assets; +using PhysicsSystem; + +namespace OpenSim +{ + /// + /// Description of MainForm. + /// + public class OpenSim_Main + { + public static OpenSim_Main sim; + public static SimConfig cfg; + public static World local_world; + public static Grid gridServers; + public static AssetCache assetCache; + //private static Thread MainListener; + //private static Thread PingRespponder; + public static Socket Server; + private static IPEndPoint ServerIncoming; + private static byte[] RecvBuffer = new byte[4096]; + private byte[] ZeroBuffer = new byte[8192]; + private static IPEndPoint ipeSender; + private static EndPoint epSender; + private static AsyncCallback ReceivedData; + + public Dictionary ClientThreads = new Dictionary(); + private PhysicsManager physManager; + private System.Timers.Timer timer1 = new System.Timers.Timer(); + private string ConfigDll = "SimConfig.dll"; + + [STAThread] + public static void Main( string[] args ) + { + //Console.WriteLine("OpenSim " + VersionInfo.Version + "\n"); + Console.WriteLine("Starting...\n"); + sim = new OpenSim_Main(); + + bool sandbox = false; + bool loginserver = false; + for (int i = 0; i < args.Length; i++) + { + if(args[i] == "-sandbox") + { + sandbox = true; + } + if(args[i] == "-loginserver") + { + loginserver = true; + } + } + + OpenSim_Main.gridServers = new Grid(); + if(sandbox) + { + OpenSim_Main.gridServers.AssetDll = "LocalGridServers.dll"; + OpenSim_Main.gridServers.GridDll = "LocalGridServers.dll"; + OpenSim_Main.gridServers.LoadPlugins(); + Console.WriteLine("Starting in Sandbox mode"); + } + else + { + OpenSim_Main.gridServers.AssetDll = "RemoteGridServers.dll"; + OpenSim_Main.gridServers.GridDll = "RemoteGridServers.dll"; + OpenSim_Main.gridServers.LoadPlugins(); + Console.WriteLine("Starting in Grid mode"); + } + if(loginserver && sandbox) + { + LoginServer loginServer = new LoginServer(OpenSim_Main.gridServers.GridServer); + loginServer.Startup(); + } + assetCache = new AssetCache(OpenSim_Main.gridServers.AssetServer); + + sim.Startup(); + //while(true) { + Console.ReadLine(); + Thread.Sleep(1000); + //} + } + + private OpenSim_Main() { + } + + private void Startup() { + timer1.Enabled = true; + timer1.Interval = 100; + timer1.Elapsed +=new ElapsedEventHandler( this.Timer1Tick ); + + // We check our local database first, then the grid for config options + Console.WriteLine("Main.cs:Startup() - Loading configuration"); + cfg = this.LoadConfigDll(); + cfg.InitConfig(); + Console.WriteLine("Main.cs:Startup() - Contacting gridserver"); + cfg.LoadFromGrid(); + + Console.WriteLine("Main.cs:Startup() - We are " + cfg.RegionName + " at " + cfg.RegionLocX.ToString() + "," + cfg.RegionLocY.ToString()); + Console.WriteLine("Initialising world"); + local_world = cfg.LoadWorld(); + + this.physManager = new PhysicsSystem.PhysicsManager(); + this.physManager.LoadPlugins(); + Console.WriteLine("Main.cs:Startup() - Starting up messaging system"); + local_world.PhysScene = this.physManager.GetPhysicsScene("PhysX"); //should be reading from the config file what physics engine to use + + MainServerListener(); + + } + + private SimConfig LoadConfigDll() + { + Assembly pluginAssembly = Assembly.LoadFrom(this.ConfigDll); + 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); + Console.Error.WriteLine(packet.ToString()); + + // This is either a new client or a packet to send to an old one + if(ClientThreads.ContainsKey(epSender)) { + ClientThreads[epSender].InPacket(packet); + } else if( packet.Type == PacketType.UseCircuitCode ) { // new client + OpenSimClient newuser = new OpenSimClient(epSender,(UseCircuitCodePacket)packet); + ClientThreads.Add(epSender, newuser); + } else { // invalid client + Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); + } + Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); + } + + private void MainServerListener() { + Console.WriteLine("Main.cs:MainServerListener() - New thread started"); + Console.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + cfg.IPListenAddr + ":" + cfg.IPListenPort); + + ServerIncoming = new IPEndPoint(IPAddress.Any, cfg.IPListenPort); + Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + Server.Bind(ServerIncoming); + + Console.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); + + Console.WriteLine("Main.cs:MainServerListener() - Listening..."); + + } + + void Timer1Tick( object sender, System.EventArgs e ) + { + local_world.Update(); + } + } + + public class Grid + { + public IAssetServer AssetServer; + public IGridServer GridServer; + public string AssetDll = ""; + public string GridDll = ""; + + public Grid() + { + } + + public void LoadPlugins() + { + this.AssetServer =(IAssetServer) this.LoadAssetDll();//assets not implemented yet + this.GridServer =(IGridServer) this.LoadGridDll(); + } + + private IAssetServer LoadAssetDll() + { + Assembly pluginAssembly = Assembly.LoadFrom(this.AssetDll); + 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() + { + Assembly pluginAssembly = Assembly.LoadFrom(this.GridDll); + IGridServer server = null; + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("IGridPlugin", true); + + if (typeInterface != null) + { + IGridPlugin plug = (IGridPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + server = plug.GetGridServer(); + break; + } + + typeInterface = null; + } + } + } + pluginAssembly = null; + return server; + } + } +} diff --git a/src/OpenSimClient.cs b/src/OpenSimClient.cs new file mode 100644 index 0000000000..57189b0d5a --- /dev/null +++ b/src/OpenSimClient.cs @@ -0,0 +1,376 @@ +/* +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.GridServers; + +namespace OpenSim +{ + /// + /// Handles new client connections + /// Constructor takes a single Packet and authenticates everything + /// + public class OpenSimClient { + + public LLUUID AgentID; + public LLUUID SessionID; + public uint CircuitCode; + public world.Avatar ClientAvatar; + private UseCircuitCodePacket cirpack; + private Thread ClientThread; + private EndPoint userEP; + private BlockingQueue PacketQueue; + private Dictionary PendingAcks = new Dictionary(); + private Dictionary NeedAck = 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; + + public void ack_pack(Packet Pack) { + //libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket(); + //ack_it.Packets = new PacketAckPacket.PacketsBlock[1]; + //ack_it.Packets[0] = new PacketAckPacket.PacketsBlock(); + //ack_it.Packets[0].ID = Pack.Header.ID; + //ack_it.Header.Reliable = false; + + //OutPacket(ack_it); + + if (Pack.Header.Reliable) { + lock (PendingAcks) { + uint sequence = (uint)Pack.Header.Sequence; + if (!PendingAcks.ContainsKey(sequence)) { PendingAcks[sequence] = sequence; } + } + } + } + + public void ProcessInPacket(Packet Pack) { + ack_pack(Pack); + switch(Pack.Type) { + case PacketType.CompleteAgentMovement: + ClientAvatar.CompleteMovement(OpenSim_Main.local_world); + ClientAvatar.SendInitialPosition(); + break; + case PacketType.RegionHandshakeReply: + OpenSim_Main.local_world.SendLayerData(this); + break; + case PacketType.AgentWearablesRequest: + ClientAvatar.SendInitialAppearance(); + break; + case PacketType.TransferRequest: + //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request"); + TransferRequestPacket transfer = (TransferRequestPacket)Pack; + OpenSim_Main.assetCache.AddAssetRequest(this, transfer); + break; + case PacketType.AgentUpdate: + ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack); + break; + case PacketType.ChatFromViewer: + ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack; + if(Helpers.FieldToString(inchatpack.ChatData.Message)=="") break; + + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); + reply.ChatData.Audible = 1; + reply.ChatData.Message = inchatpack.ChatData.Message; + reply.ChatData.ChatType = 1; + reply.ChatData.SourceType = 1; + reply.ChatData.Position = this.ClientAvatar.position; + reply.ChatData.FromName = _enc.GetBytes(this.ClientAvatar.firstname + " " + this.ClientAvatar.lastname + "\0"); + reply.ChatData.OwnerID = this.AgentID; + reply.ChatData.SourceID = this.AgentID; + foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) { + client.OutPacket(reply); + } + break; + } + } + + private void ResendUnacked() + { + int now = Environment.TickCount; + + lock (NeedAck) + { + foreach (Packet packet in NeedAck.Values) + { + if (now - packet.TickCount > RESEND_TIMEOUT) + { + Console.WriteLine("Resending " + packet.Type.ToString() + " packet, " + + (now - packet.TickCount) + "ms have passed", Helpers.LogLevel.Info); + + 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 + Console.WriteLine("Too many ACKs queued up!", Helpers.LogLevel.Error); + return; + } + + Console.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(); + } + + public 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; + } + } + } + } + } + + Console.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); + OpenSim_Main.Server.SendTo(ZeroOutBuffer, packetsize, SocketFlags.None,userEP); + } else { + OpenSim_Main.Server.SendTo(sendbuffer, sendbuffer.Length, SocketFlags.None,userEP); + } + } catch (Exception) { + Console.WriteLine("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread"); + ClientThread.Abort(); + } + + } + + public void InPacket(Packet NewPack) { + // Handle appended ACKs + if (NewPack.Header.AppendedAcks) + { + lock (NeedAck) + { + foreach (uint ack in NewPack.Header.AckList) + { + NeedAck.Remove(ack); + } + } + } + + // Handle PacketAck packets + if (NewPack.Type == PacketType.PacketAck) + { + PacketAckPacket ackPacket = (PacketAckPacket)NewPack; + + lock (NeedAck) + { + foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets) + { + NeedAck.Remove(block.ID); + } + } + } else if( ( NewPack.Type == PacketType.StartPingCheck ) ) { + //reply to pingcheck + libsecondlife.Packets.StartPingCheckPacket startPing = (libsecondlife.Packets.StartPingCheckPacket)NewPack; + libsecondlife.Packets.CompletePingCheckPacket endPing = new CompletePingCheckPacket(); + endPing.PingID.PingID = startPing.PingID.PingID; + OutPacket(endPing); + } + else + { + QueItem item = new QueItem(); + item.Packet = NewPack; + item.Incoming = true; + this.PacketQueue.Enqueue(item); + } + + } + + public void OutPacket(Packet NewPack) { + QueItem item = new QueItem(); + item.Packet = NewPack; + item.Incoming = false; + this.PacketQueue.Enqueue(item); + } + + public OpenSimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack) { + Console.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request"); + cirpack = initialcirpack; + userEP = remoteEP; + PacketQueue = new BlockingQueue(); + AckTimer = new System.Timers.Timer(500); + AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); + AckTimer.Start(); + + ClientThread = new Thread(new ThreadStart(AuthUser)); + ClientThread.IsBackground = true; + ClientThread.Start(); + } + + private void ClientLoop() { + Console.WriteLine("OpenSimClient.cs:ClientLoop() - Entered loop"); + while(true) { + QueItem nextPacket = PacketQueue.Dequeue(); + if(nextPacket.Incoming) + { + //is a incoming packet + ProcessInPacket(nextPacket.Packet); + } + else + { + //is a out going packet + ProcessOutPacket(nextPacket.Packet); + } + } + } + + private void InitNewClient() { + Console.WriteLine("OpenSimClient.cs:InitNewClient() - Adding viewer agent to world"); + OpenSim_Main.local_world.AddViewerAgent(this); + world.Entity tempent=OpenSim_Main.local_world.Entities[this.AgentID]; + this.ClientAvatar=(world.Avatar)tempent; + } + + private void AuthUser() + { + AuthenticateResponse sessionInfo = OpenSim_Main.gridServers.GridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code); + if(!sessionInfo.Authorised) + { + //session/circuit not authorised + Console.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString()); + ClientThread.Abort(); + } + else + { + Console.WriteLine("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString()); + //session is authorised + this.AgentID=cirpack.CircuitCode.ID; + this.SessionID=cirpack.CircuitCode.SessionID; + this.CircuitCode=cirpack.CircuitCode.Code; + InitNewClient(); + this.ClientAvatar.firstname = sessionInfo.LoginInfo.First; + this.ClientAvatar.lastname = sessionInfo.LoginInfo.Last; + ClientLoop(); + } + } + } + +} diff --git a/src/RemoteServers/RemoteGridServers/AssemblyInfo.cs b/src/RemoteServers/RemoteGridServers/AssemblyInfo.cs new file mode 100644 index 0000000000..0fa7d6ea66 --- /dev/null +++ b/src/RemoteServers/RemoteGridServers/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("RemoteGridServers")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RemoteGridServers")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] diff --git a/src/RemoteServers/RemoteGridServers/RemoteGrid.cs b/src/RemoteServers/RemoteGridServers/RemoteGrid.cs new file mode 100644 index 0000000000..2279ba8b5f --- /dev/null +++ b/src/RemoteServers/RemoteGridServers/RemoteGrid.cs @@ -0,0 +1,229 @@ +/* +* 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 System.Net; +using System.Net.Sockets; +using System.IO; +using libsecondlife; +using OpenSim.GridServers; + +namespace RemoteGridServers +{ + /// + /// + /// + /// + + public class RemoteGridPlugin : IGridPlugin + { + public RemoteGridPlugin() + { + + } + + public IGridServer GetGridServer() + { + return(new RemoteGridServer()); + } + } + + public class RemoteAssetPlugin : IAssetPlugin + { + public RemoteAssetPlugin() + { + + } + + public IAssetServer GetAssetServer() + { + return(new RemoteAssetServer()); + } + } + public class RemoteGridServer :IGridServer + { + private string GridServerUrl; + private string GridSendKey; + + public RemoteGridServer() + { + Console.WriteLine("Remote Grid Server class created"); + } + + public bool RequestConnection() + { + return true; + } + public AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) + { + AuthenticateResponse user = new AuthenticateResponse(); + + WebRequest CheckSession = WebRequest.Create(GridServerUrl + "/usersessions/" + GridSendKey + "/" + agentID.ToString() + "/" + circuitCode.ToString() + "/exists"); + WebResponse GridResponse = CheckSession.GetResponse(); + StreamReader sr = new StreamReader(GridResponse.GetResponseStream()); + String grTest = sr.ReadLine(); + sr.Close(); + GridResponse.Close(); + if(String.IsNullOrEmpty(grTest) || grTest.Equals("1")) + { + // YAY! Valid login + user.Authorised = true; + user.LoginInfo = new Login(); + user.LoginInfo.Agent = agentID; + user.LoginInfo.Session = sessionID; + user.LoginInfo.First = ""; + user.LoginInfo.Last = ""; + + } + else + { + // Invalid + user.Authorised = false; + } + + return(user); + } + + public UUIDBlock RequestUUIDBlock() + { + UUIDBlock uuidBlock = new UUIDBlock(); + return(uuidBlock); + } + + public void RequestNeighbours() + { + return; + } + + public void SetServerInfo(string ServerUrl, string ServerKey) + { + this.GridServerUrl = ServerUrl; + this.GridSendKey = ServerKey; + } + + public void AddNewSession(Login session) + { + + } + } + + + public class RemoteAssetServer : IAssetServer + { + private IAssetReceiver _receiver; + private BlockingQueue _assetRequests; + private Thread _remoteAssetServerThread; + private string AssetServerUrl; + private string AssetSendKey; + + public RemoteAssetServer() + { + this._assetRequests = new BlockingQueue(); + this._remoteAssetServerThread = new Thread(new ThreadStart(RunRequests)); + this._remoteAssetServerThread.IsBackground = true; + this._remoteAssetServerThread.Start(); + Console.WriteLine("Remote Asset Server class created"); + } + + public void SetReceiver(IAssetReceiver receiver) + { + this._receiver = receiver; + } + + public void RequestAsset(LLUUID assetID, bool isTexture) + { + ARequest req = new ARequest(); + req.AssetID = assetID; + req.IsTexture = isTexture; + this._assetRequests.Enqueue(req); + } + + public void UpdateAsset(AssetBase asset) + { + + } + + public void UploadNewAsset(AssetBase asset) + { + + } + + public void SetServerInfo(string ServerUrl, string ServerKey) + { + this.AssetServerUrl = ServerUrl; + this.AssetSendKey = ServerKey; + } + + private void RunRequests() + { + while(true) + { + //we need to add support for the asset server not knowing about a requested asset + ARequest req = this._assetRequests.Dequeue(); + LLUUID assetID = req.AssetID; + Console.WriteLine(" RemoteAssetServer- Got a AssetServer request, processing it"); + WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "getasset/" + AssetSendKey + "/" + assetID + "/data"); + WebResponse AssetResponse = AssetLoad.GetResponse(); + byte[] idata = new byte[(int)AssetResponse.ContentLength]; + BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream()); + idata = br.ReadBytes((int)AssetResponse.ContentLength); + br.Close(); + + AssetBase asset = new AssetBase(); + asset.FullID = assetID; + asset.Data = idata; + _receiver.AssetReceived(asset, req.IsTexture ); + } + } + } + + public class BlockingQueue< T > { + private Queue< T > _queue = new Queue< T >(); + private object _queueSync = new object(); + + public void Enqueue(T value) + { + lock(_queueSync) + { + _queue.Enqueue(value); + Monitor.Pulse(_queueSync); + } + } + + public T Dequeue() + { + lock(_queueSync) + { + if( _queue.Count < 1) + Monitor.Wait(_queueSync); + + return _queue.Dequeue(); + } + } + } +} diff --git a/src/RemoteServers/RemoteGridServers/RemoteGridServers.csproj b/src/RemoteServers/RemoteGridServers/RemoteGridServers.csproj new file mode 100644 index 0000000000..cc314a8c35 --- /dev/null +++ b/src/RemoteServers/RemoteGridServers/RemoteGridServers.csproj @@ -0,0 +1,43 @@ + + + Library + RemoteGridServers + RemoteGridServers + Debug + AnyCPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5} + + + bin\Debug\ + False + DEBUG;TRACE + True + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + ..\..\..\Libsecond-dailys\libsl-03-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll + False + + + ..\..\..\GridInterfaces\GridInterfaces\bin\Debug\GridInterfaces.dll + False + + + + + + + + \ No newline at end of file diff --git a/src/RemoteServers/RemoteGridServers/RemoteGridServers.sln b/src/RemoteServers/RemoteGridServers/RemoteGridServers.sln new file mode 100644 index 0000000000..a990022246 --- /dev/null +++ b/src/RemoteServers/RemoteGridServers/RemoteGridServers.sln @@ -0,0 +1,7 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# SharpDevelop 2.1.0.2017 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteGridServers", "RemoteGridServers.csproj", "{CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}" +EndProject +Global +EndGlobal diff --git a/src/Second-server.csproj b/src/Second-server.csproj new file mode 100644 index 0000000000..a08160b5b7 --- /dev/null +++ b/src/Second-server.csproj @@ -0,0 +1,87 @@ + + + Exe + OpenSim + OpenSim + Debug + AnyCPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E} + OpenSim.OpenSim_Main + False + False + 4 + false + + + bin\ + False + DEBUG;TRACE + true + Full + True + + + ..\bin\ + True + TRACE + False + None + False + + + False + Auto + 4194304 + AnyCPU + 4096 + + + + + + + ..\physics\PhysicsManager\bin\Release\PhysicsManager.dll + False + + + ..\Version0_2_myserver\OpenSim\bin\Debug\log4net.dll + False + + + ..\Version0_2_myserver\OpenSim\bin\Debug\Axiom.MathLib.dll + False + + + ..\Version0_2_myserver\OpenSim\bin\Debug\libsecondlife.dll + False + + + ..\GridInterfaces\GridInterfaces\bin\Debug\GridInterfaces.dll + False + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Second-server.sln b/src/Second-server.sln new file mode 100644 index 0000000000..bb099e2bc4 --- /dev/null +++ b/src/Second-server.sln @@ -0,0 +1,86 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# SharpDevelop 2.1.0.2017 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Second-server", "Second-server.csproj", "{132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimConfig", "Config\SimConfig\SimConfig.csproj", "{B063760D-DB8D-4F64-B6FE-335FAD1E650A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalGridServers", "LocalServers\LocalGridServers\LocalGridServers.csproj", "{D7F0395B-FADC-4936-80A0-D95AACE92F62}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteGridServers", "RemoteServers\RemoteGridServers\RemoteGridServers.csproj", "{CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GridInterfaces", "GridInterfaces\GridInterfaces.csproj", "{5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysicsManager", "physics\PhysicsManager.csproj", "{3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysXplugin", "physics\plugins\PhysXplugin.csproj", "{ADB751AA-8426-4668-B1FA-43762126CEB3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|.NET 1.1 = Debug|.NET 1.1 + Debug|Any CPU = Debug|Any CPU + Release|.NET 1.1 = Release|.NET 1.1 + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|.NET 1.1.ActiveCfg = Debug|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|.NET 1.1.Build.0 = Debug|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|.NET 1.1.ActiveCfg = Release|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|.NET 1.1.Build.0 = Release|.NET 1.1 + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|Any CPU.Build.0 = Release|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Debug|.NET 1.1.Build.0 = Debug|.NET 1.1 + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Debug|.NET 1.1.ActiveCfg = Debug|.NET 1.1 + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Release|.NET 1.1.Build.0 = Release|.NET 1.1 + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Release|.NET 1.1.ActiveCfg = Release|.NET 1.1 + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Release|Any CPU.Build.0 = Release|Any CPU + {B063760D-DB8D-4F64-B6FE-335FAD1E650A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|.NET 1.1.Build.0 = Debug|.NET 1.1 + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|.NET 1.1.ActiveCfg = Debug|.NET 1.1 + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|.NET 1.1.Build.0 = Release|.NET 1.1 + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|.NET 1.1.ActiveCfg = Release|.NET 1.1 + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|Any CPU.Build.0 = Release|Any CPU + {5DA3174D-42F9-416D-9F0B-AF41FA2BE2F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Debug|.NET 1.1.Build.0 = Debug|.NET 1.1 + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Debug|.NET 1.1.ActiveCfg = Debug|.NET 1.1 + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Release|.NET 1.1.Build.0 = Release|.NET 1.1 + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Release|.NET 1.1.ActiveCfg = Release|.NET 1.1 + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Release|Any CPU.Build.0 = Release|Any CPU + {D7F0395B-FADC-4936-80A0-D95AACE92F62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Debug|.NET 1.1.Build.0 = Debug|.NET 1.1 + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Debug|.NET 1.1.ActiveCfg = Debug|.NET 1.1 + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Release|.NET 1.1.Build.0 = Release|.NET 1.1 + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Release|.NET 1.1.ActiveCfg = Release|.NET 1.1 + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Release|Any CPU.Build.0 = Release|Any CPU + {CF0E7E62-34F4-4AB2-BDBD-AFC63224A7E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|.NET 1.1.Build.0 = Debug|.NET 1.1 + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|.NET 1.1.ActiveCfg = Debug|.NET 1.1 + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|.NET 1.1.Build.0 = Release|.NET 1.1 + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|.NET 1.1.ActiveCfg = Release|.NET 1.1 + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|Any CPU.Build.0 = Release|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|.NET 1.1.Build.0 = Debug|.NET 1.1 + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|.NET 1.1.ActiveCfg = Debug|.NET 1.1 + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|.NET 1.1.Build.0 = Release|.NET 1.1 + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|.NET 1.1.ActiveCfg = Release|.NET 1.1 + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|Any CPU.Build.0 = Release|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Util.cs b/src/Util.cs new file mode 100644 index 0000000000..2474166e10 --- /dev/null +++ b/src/Util.cs @@ -0,0 +1,203 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + +* Copyright (c) , +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +using System; +using System.Collections.Generic; +using System.Threading; +using libsecondlife; +using libsecondlife.Packets; + +namespace OpenSim +{ + /// + /// + /// + public class Util + { + public static ulong UIntsToLong(uint X, uint Y) + { + return Helpers.UIntsToLong(X,Y); + } + public Util() + { + + } + } + + public class QueItem { + public QueItem() + { + } + + public Packet Packet; + public bool Incoming; + } + + + public class BlockingQueue< T > { + private Queue< T > _queue = new Queue< T >(); + private object _queueSync = new object(); + + public void Enqueue(T value) + { + lock(_queueSync) + { + _queue.Enqueue(value); + Monitor.Pulse(_queueSync); + } + } + + public T Dequeue() + { + lock(_queueSync) + { + if( _queue.Count < 1) + Monitor.Wait(_queueSync); + + return _queue.Dequeue(); + } + } + } + + public class VoipConnectionPacket : Packet + { + /// + // [XmlType("VoipConnection_Serverblock1")] + public class ServerBlock + { + public uint Test1; + public uint IP; + public ushort Port; + private byte[] userName; + public byte[] UserName + { + get { return userName; } + set + { + if (value == null) { userName = null; return; } + if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } + else { userName = new byte[value.Length]; Array.Copy(value, userName, value.Length); } + } + } + + //[XmlIgnore] + public int Length + { + get + { + int length = 4; + if (UserName != null) { length += 1 + UserName.Length; } + return length; + } + } + + public ServerBlock() { } + public ServerBlock(byte[] bytes, ref int i) + { + try + { + Test1 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(Test1 % 256); + bytes[i++] = (byte)((Test1 >> 8) % 256); + bytes[i++] = (byte)((Test1 >> 16) % 256); + bytes[i++] = (byte)((Test1 >> 24) % 256); + if(UserName == null) { Console.WriteLine("Warning: UserName is null, in " + this.GetType()); } + bytes[i++] = (byte)UserName.Length; + Array.Copy(UserName, 0, bytes, i, UserName.Length); + i += UserName.Length; + } + + public override string ToString() + { + string output = "-- ServerBlock1 --" + Environment.NewLine; + output += "Test1: " + Test1.ToString() + "" + Environment.NewLine; + output = output.Trim(); + return output; + } + } + + + private Header header; + public override Header Header { get { return header; } set { header = value; } } + public override PacketType Type { get { return PacketType.TestMessage; } } + public ServerBlock ServerBlock1; + + public VoipConnectionPacket() + { + Header = new LowHeader(); + Header.ID = 600; + Header.Reliable = true; + Header.Zerocoded = true; + ServerBlock1 = new ServerBlock(); + } + + public VoipConnectionPacket(byte[] bytes, ref int i) + { + int packetEnd = bytes.Length - 1; + Header = new LowHeader(bytes, ref i, ref packetEnd); + ServerBlock1 = new ServerBlock(bytes, ref i); + } + + public VoipConnectionPacket(Header head, byte[] bytes, ref int i) + { + Header = head; + ServerBlock1 = new ServerBlock(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += ServerBlock1.Length;; + if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } + byte[] bytes = new byte[length]; + int i = 0; + header.ToBytes(bytes, ref i); + ServerBlock1.ToBytes(bytes, ref i); + if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override string ToString() + { + string output = "--- VoipConnection ---" + Environment.NewLine; + output += ServerBlock1.ToString() + Environment.NewLine; + return output; + } + + } +} diff --git a/src/physics/AssemblyInfo.cs b/src/physics/AssemblyInfo.cs new file mode 100644 index 0000000000..57a8913d33 --- /dev/null +++ b/src/physics/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("PhysicsManager")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PhysicsManager")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] diff --git a/src/physics/PhysicsManager.cs b/src/physics/PhysicsManager.cs new file mode 100644 index 0000000000..90f6bf38bf --- /dev/null +++ b/src/physics/PhysicsManager.cs @@ -0,0 +1,167 @@ +/* +* 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.Collections; +using System.IO; +using System.Reflection; + +namespace PhysicsSystem +{ + /// + /// Description of MyClass. + /// + public class PhysicsManager + { + private Dictionary _plugins=new Dictionary(); + + public PhysicsManager() + { + + } + + public PhysicsScene GetPhysicsScene(string engineName) + { + if(_plugins.ContainsKey(engineName)) + { + Console.WriteLine("creating "+engineName); + return _plugins[engineName].GetScene(); + } + else + { + Console.WriteLine("couldn't find physicsEngine: "+ engineName); + return null; + } + } + + public void LoadPlugins() + { + string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory ,"Physics"); + string[] pluginFiles = Directory.GetFiles(path, "*.Dll"); + + + for(int i= 0; i + + Library + PhysicsManager + PhysicsManager + Debug + AnyCPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B} + + + bin\Debug\ + False + DEBUG;TRACE + True + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + + + + + + \ No newline at end of file diff --git a/src/physics/PhysicsManager.sln b/src/physics/PhysicsManager.sln new file mode 100644 index 0000000000..565813fde9 --- /dev/null +++ b/src/physics/PhysicsManager.sln @@ -0,0 +1,23 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# SharpDevelop 2.1.0.2017 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysicsManager", "PhysicsManager.csproj", "{3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysXplugin", "..\PhysXplugin\PhysXplugin\PhysXplugin.csproj", "{ADB751AA-8426-4668-B1FA-43762126CEB3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|Any CPU.Build.0 = Release|Any CPU + {3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|Any CPU.Build.0 = Release|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/physics/plugins/AssemblyInfo.cs b/src/physics/plugins/AssemblyInfo.cs new file mode 100644 index 0000000000..0c9c06c43d --- /dev/null +++ b/src/physics/plugins/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("PhysXplugin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PhysXplugin")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.*")] diff --git a/src/physics/plugins/PhysXplugin.cs b/src/physics/plugins/PhysXplugin.cs new file mode 100644 index 0000000000..6d6eca92de --- /dev/null +++ b/src/physics/plugins/PhysXplugin.cs @@ -0,0 +1,195 @@ +/* +* 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 PhysicsSystem; + +namespace PhysXplugin +{ + /// + /// Will be the PhysX plugin but for now will be a very basic physics engine + /// + public class PhysXPlugin : IPhysicsPlugin + { + private PhysXScene _mScene; + + public PhysXPlugin() + { + + } + + public bool Init() + { + return true; + } + + public PhysicsScene GetScene() + { + if(_mScene == null) + { + _mScene = new PhysXScene(); + } + return(_mScene); + } + + public string GetName() + { + return("PhysX"); + } + + public void Dispose() + { + + } + } + + public class PhysXScene :PhysicsScene + { + private List _actors = new List(); + + public PhysXScene() + { + + } + + public override PhysicsActor AddAvatar(PhysicsVector position) + { + PhysXActor act = new PhysXActor(); + act.Position = position; + _actors.Add(act); + return act; + } + + public override void Simulate(float timeStep) + { + foreach (PhysXActor actor in _actors) + { + actor.Position.X = actor.Position.X + actor.Velocity.X * timeStep; + actor.Position.Y = actor.Position.Y + actor.Velocity.Y * timeStep; + actor.Position.Z = actor.Position.Z + actor.Velocity.Z * timeStep; + if(actor.Position.X<0) + { + actor.Position.X = 0; + actor.Velocity.X = 0; + } + if(actor.Position.Y < 0) + { + actor.Position.Y = 0; + actor.Velocity.Y = 0; + } + if(actor.Position.X > 255) + { + actor.Position.X = 255; + actor.Velocity.X = 0; + } + if(actor.Position.Y > 255) + { + actor.Position.Y = 255; + actor.Velocity.X = 0; + } + } + } + + public override void GetResults() + { + + } + + public override bool IsThreaded + { + get + { + return(false); // for now we won't be multithreaded + } + } + + public override void SetTerrain(float[] heightMap) + { + + } + } + + public class PhysXActor : PhysicsActor + { + private PhysicsVector _position; + private PhysicsVector _velocity; + private PhysicsVector _acceleration; + + public PhysXActor() + { + + } + + public override PhysicsVector Position + { + get + { + return _position; + } + set + { + _position = value; + } + } + + public override PhysicsVector Velocity + { + get + { + return _velocity; + } + set + { + _velocity = value; + } + } + + public override PhysicsVector Acceleration + { + get + { + return _acceleration; + } + + } + public void SetAcceleration (PhysicsVector accel) + { + this._acceleration = accel; + } + + public override void AddForce(PhysicsVector force) + { + + } + + public override void SetMomentum(PhysicsVector momentum) + { + + } + } + +} diff --git a/src/physics/plugins/PhysXplugin.csproj b/src/physics/plugins/PhysXplugin.csproj new file mode 100644 index 0000000000..76272c8f76 --- /dev/null +++ b/src/physics/plugins/PhysXplugin.csproj @@ -0,0 +1,39 @@ + + + Library + PhysXplugin + PhysXplugin + Debug + AnyCPU + {ADB751AA-8426-4668-B1FA-43762126CEB3} + + + bin\Debug\ + False + DEBUG;TRACE + True + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + ..\..\PhysicsManager\bin\Release\PhysicsManager.dll + False + + + + + + + + \ No newline at end of file diff --git a/src/physics/plugins/PhysXplugin.sln b/src/physics/plugins/PhysXplugin.sln new file mode 100644 index 0000000000..06e73d162e --- /dev/null +++ b/src/physics/plugins/PhysXplugin.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# SharpDevelop 2.1.0.2017 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysXplugin", "PhysXplugin.csproj", "{ADB751AA-8426-4668-B1FA-43762126CEB3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|Any CPU.Build.0 = Release|Any CPU + {ADB751AA-8426-4668-B1FA-43762126CEB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/types/BitPack.cs b/src/types/BitPack.cs new file mode 100644 index 0000000000..1abbcf012e --- /dev/null +++ b/src/types/BitPack.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.types +{ + /* New Method + * + * 1. Get all the individual bytes and their bitlength, put them in a dictionary + * 2. Mash together when wanted. + * + * */ + public class Bits { + public byte[] data; + public int len; + } + + public class InverseBitPack + { + private List bits; + + public InverseBitPack() + { + bits = new List(); + } + } + + public class BitPack + { + private const int MAX_BITS = 8; + + private byte[] Data; + private int bytePos; + private int bitPos; + + public BitPack(byte[] data, int pos) // For libsl compatibility + { + Data = data; + bytePos = pos; + } + + public BitPack() // Encoding version + { + + } + + public void LoadData(byte[] data, int pos) { + Data = data; + bytePos = pos; + bitPos = 0; + } + + private void PackBitsArray(byte[] bits, int bitLen) + { + int offset = bitPos % MAX_BITS; + int i; + byte temp1; + byte temp2; + + for (i = 0; i < bits.Length; i++) + { + int Byte = bits[i]; + Byte <<= offset; + temp1 = (byte)(Byte & 0xFF); + temp2 = (byte)((Byte >> 8) & 0xFF); + + Data[Data.Length - 1] |= temp1; +// Data + + bitPos += bitLen; + } + } + + public float UnpackFloat() + { + byte[] output = UnpackBitsArray(32); + + if (!BitConverter.IsLittleEndian) Array.Reverse(output); + return BitConverter.ToSingle(output, 0); + } + + public int UnpackBits(int totalCount) + { + byte[] output = UnpackBitsArray(totalCount); + + if (!BitConverter.IsLittleEndian) Array.Reverse(output); + return BitConverter.ToInt32(output, 0); + } + + private byte[] UnpackBitsArray(int totalCount) + { + int count = 0; + byte[] output = new byte[4]; + int curBytePos = 0; + int curBitPos = 0; + + while (totalCount > 0) + { + if (totalCount > MAX_BITS) + { + count = MAX_BITS; + totalCount -= MAX_BITS; + } + else + { + count = totalCount; + totalCount = 0; + } + + while (count > 0) + { + // Shift the previous bits + output[curBytePos] <<= 1; + + // Grab one bit + if ((Data[bytePos] & (0x80 >> bitPos++)) != 0) + ++output[curBytePos]; + + --count; + ++curBitPos; + + if (bitPos >= MAX_BITS) + { + bitPos = 0; + ++bytePos; + } + if (curBitPos >= MAX_BITS) + { + curBitPos = 0; + ++curBytePos; + } + } + } + + return output; + } + } +} diff --git a/src/types/Mesh.cs b/src/types/Mesh.cs new file mode 100644 index 0000000000..3e00c9130b --- /dev/null +++ b/src/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/src/types/Triangle.cs b/src/types/Triangle.cs new file mode 100644 index 0000000000..8dfea6e762 --- /dev/null +++ b/src/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/src/world/Avatar.cs b/src/world/Avatar.cs new file mode 100644 index 0000000000..3b56b381b1 --- /dev/null +++ b/src/world/Avatar.cs @@ -0,0 +1,323 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using libsecondlife; +using libsecondlife.Packets; +using PhysicsSystem; +using Axiom.MathLib; + +namespace OpenSim.world +{ + public class Avatar : Entity + { + public string firstname; + public string lastname; + public OpenSimClient ControllingClient; + private PhysicsActor _physActor; + private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate; + private bool updateflag; + private bool walking; + private List forcesList = new List(); + + public Avatar(OpenSimClient TheClient) { + Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)"); + ControllingClient=TheClient; + SetupTemplate("avatar-template.dat"); + position = new LLVector3(100.0f,100.0f,30.0f); + } + + public PhysicsActor PhysActor + { + set + { + this._physActor = value; + } + } + public override void addFroces() + { + 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. + } + } + } + + 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 = OpenSim_Main.cfg.RegionHandle; // FIXME + terse.RegionData.TimeDilation = 0; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = terseBlock; + foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) { + client.OutPacket(terse); + } + + updateflag =false; + } + } + + private 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); + + AvatarTemplate = objdata; + + } + + public void CompleteMovement(World RegionInfo) { + Console.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 = OpenSim_Main.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); + + Console.WriteLine("Sending AgentMovementComplete packet"); + 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 = OpenSim_Main.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.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); + OpenSim_Main.local_world._localNumber++; + 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 void HandleUpdate(AgentUpdatePacket pack) { + if(((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_POS) !=0) { + if(!walking) + { + //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.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 = q * v3; + direc.Normalize(); + + //work out velocity for sim physics system + direc = direc * ((0.03f) * 128f); + newVelocity.X = direc.x; + newVelocity.Y = direc.y; + newVelocity.Z = direc.z; + this.forcesList.Add(newVelocity); + walking=true; + } + } + else + { + if(walking) + { + NewForce newVelocity = new NewForce(); + newVelocity.X = 0; + newVelocity.Y = 0; + newVelocity.Z = 0; + this.forcesList.Add(newVelocity); + walking = false; + } + } + } + + //should be moved somewhere else + public void SendRegionHandshake(World RegionInfo) { + Console.WriteLine("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet"); + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + RegionHandshakePacket handshake = new RegionHandshakePacket(); + + Console.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 = 5; + handshake.RegionInfo.RegionFlags = 72458694; + handshake.RegionInfo.SimName = _enc.GetBytes(OpenSim_Main.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"); + + Console.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/src/world/Entity.cs b/src/world/Entity.cs new file mode 100644 index 0000000000..1a4ced98d2 --- /dev/null +++ b/src/world/Entity.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Axiom.MathLib; +using OpenSim.types; +using libsecondlife; + +namespace OpenSim.world +{ + public class Entity + { + protected libsecondlife.LLUUID uuid; + protected uint localid; + public LLVector3 position; + public LLVector3 velocity; + public Quaternion rotation; + protected string name; + protected List children; + + public Entity() + { + uuid = new libsecondlife.LLUUID(); + localid = 8880000 + (OpenSim_Main.local_world._localNumber++); // FIXME - race condition! + position = new LLVector3(); + velocity = new LLVector3(); + rotation = new Quaternion(); + name = "(basic entity)"; + children = new List(); + } + public virtual void addFroces() + { + foreach (Entity child in children) + { + child.addFroces(); + } + } + 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; + } + } +} diff --git a/src/world/Primitive.cs b/src/world/Primitive.cs new file mode 100644 index 0000000000..143fa55a33 --- /dev/null +++ b/src/world/Primitive.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.types; + +namespace OpenSim.world +{ + public class Primitive : Entity + { + protected float mesh_cutbegin; + protected float mesh_cutend; + + 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; + } + } +} diff --git a/src/world/ScriptEngine.cs b/src/world/ScriptEngine.cs new file mode 100644 index 0000000000..f20a08ec1b --- /dev/null +++ b/src/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/src/world/SurfacePatch.cs b/src/world/SurfacePatch.cs new file mode 100644 index 0000000000..71e4116d11 --- /dev/null +++ b/src/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/src/world/TerrainDecoder.cs b/src/world/TerrainDecoder.cs new file mode 100644 index 0000000000..1a3482611f --- /dev/null +++ b/src/world/TerrainDecoder.cs @@ -0,0 +1,683 @@ +/* +* 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 libsecondlife.Packets; + +namespace OpenSim +{ + /// + /// Description of TerrainDecoder. + /// + public class TerrainDecode + { + + public enum LayerType : byte + { + Land = 0x4C, + Water = 0x57, + Wind = 0x37, + Cloud = 0x38 + } + + public struct GroupHeader + { + public int Stride; + public int PatchSize; + public LayerType Type; + } + + public struct PatchHeader + { + public float DCOffset; + public int Range; + public int QuantWBits; + public int PatchIDs; + public uint WordBits; + } + + public class Patch + { + public float[] Heightmap; + } + + + /// + /// + /// + /// + /// + /// + /// + /// + // public delegate void LandPatchCallback(Simulator simulator, int x, int y, int width, float[] data); + + + /// + /// + /// + //public event LandPatchCallback OnLandPatch; + + private Random RandomClass = new Random(); + + private const byte END_OF_PATCHES = 97; + private const int PATCHES_PER_EDGE = 16; + private const float OO_SQRT2 = 0.7071067811865475244008443621049f; + + //private SecondLife Client; + private Dictionary SimPatches = new Dictionary(); + private float[] DequantizeTable16 = new float[16 * 16]; + private float[] DequantizeTable32 = new float[32 * 32]; + private float[] ICosineTable16 = new float[16 * 16]; + private float[] ICosineTable32 = new float[32 * 32]; + private int[] DeCopyMatrix16 = new int[16 * 16]; + private int[] DeCopyMatrix32 = new int[32 * 32]; + + + /// + /// + /// + /// + public TerrainDecode() + { + + // Initialize the decompression tables + BuildDequantizeTable16(); + BuildDequantizeTable32(); + SetupICosines16(); + SetupICosines32(); + BuildDecopyMatrix16(); + BuildDecopyMatrix32(); + + } + + + private void BuildDequantizeTable16() + { + for (int j = 0; j < 16; j++) + { + for (int i = 0; i < 16; i++) + { + DequantizeTable16[j * 16 + i] = 1.0f + 2.0f * (float)(i + j); + } + } + } + + private void BuildDequantizeTable32() + { + for (int j = 0; j < 32; j++) + { + for (int i = 0; i < 32; i++) + { + DequantizeTable32[j * 32 + i] = 1.0f + 2.0f * (float)(i + j); + } + } + } + + private void SetupICosines16() + { + const float hposz = (float)Math.PI * 0.5f / 16.0f; + + for (int u = 0; u < 16; u++) + { + for (int n = 0; n < 16; n++) + { + ICosineTable16[u * 16 + n] = (float)Math.Cos((2.0f * (float)n + 1.0f) * (float)u * hposz); + } + } + } + + private void SetupICosines32() + { + const float hposz = (float)Math.PI * 0.5f / 32.0f; + + for (int u = 0; u < 32; u++) + { + for (int n = 0; n < 32; n++) + { + ICosineTable32[u * 32 + n] = (float)Math.Cos((2.0f * (float)n + 1.0f) * (float)u * hposz); + } + } + } + + private void BuildDecopyMatrix16() + { + bool diag = false; + bool right = true; + int i = 0; + int j = 0; + int count = 0; + + while (i < 16 && j < 16) + { + DeCopyMatrix16[j * 16 + i] = count++; + + if (!diag) + { + if (right) + { + if (i < 16 - 1) i++; + else j++; + + right = false; + diag = true; + } + else + { + if (j < 16 - 1) j++; + else i++; + + right = true; + diag = true; + } + } + else + { + if (right) + { + i++; + j--; + if (i == 16 - 1 || j == 0) diag = false; + } + else + { + i--; + j++; + if (j == 16 - 1 || i == 0) diag = false; + } + } + } + } + + private void BuildDecopyMatrix32() + { + bool diag = false; + bool right = true; + int i = 0; + int j = 0; + int count = 0; + + while (i < 32 && j < 32) + { + DeCopyMatrix32[j * 32 + i] = count++; + + if (!diag) + { + if (right) + { + if (i < 32 - 1) i++; + else j++; + + right = false; + diag = true; + } + else + { + if (j < 32 - 1) j++; + else i++; + + right = true; + diag = true; + } + } + else + { + if (right) + { + i++; + j--; + if (i == 32 - 1 || j == 0) diag = false; + } + else + { + i--; + j++; + if (j == 32 - 1 || i == 0) diag = false; + } + } + } + } + + private void EncodePatchHeader(BitPacker bitpack, PatchHeader header) + { + bitpack.PackBits(header.QuantWBits,8); + + if (header.QuantWBits == END_OF_PATCHES) + return; + + bitpack.PackFloat(header.DCOffset); + bitpack.PackBits(header.Range,16); + bitpack.PackBits(header.PatchIDs,10); + + } + + public void DCTLine16(float[] In, float[] Out, int line) + { + int N =16; + int lineSize = line * 16; + + for(int k = 0; k < N;k++) + { + float sum = 0.0f; + for(int n = 0; n < N; n++) + { + float num = (float)(Math.PI*k*(2.0f*n+1)/(2*N)); + float cosine = (float)Math.Cos(num); + float product = In[lineSize +n] * cosine; + sum += product; + } + + float alpha; + if(k == 0) + { + alpha = (float)(1.0f/Math.Sqrt(2)); + } + else + { + alpha = 1; + } + Out[lineSize + k] =(float)( sum * alpha ); + + } + } + public void DCTColumn16(float[] In, float[] Out, int Column) + { + int N =16; + int uSize; + + for(int k = 0; k < N; k++){ + float sum = 0.0f; + for(int n = 0; n < N; n++) + { + uSize = n * 16; + float num = (float)(Math.PI*k*(2.0f*n+1)/(2*N)); + float cosine = (float)Math.Cos(num); + float product = In[uSize + Column] * cosine; + sum += product; + } + + float alpha; + if(k == 0) + { + alpha = (float)(1.0f/Math.Sqrt(2)); + } + else + { + alpha = 1; + } + Out[16 * k + Column] = (float)( sum * alpha * (2.0f /N)); + + } + } + + private void EncodePatch(int[] patches, BitPacker bitpack, int size) + { + int lastnum =0; + for(int n = 0; n < size * size; n++) + { + if(patches[n]!=0) + lastnum=n; + } + for (int n = 0; n < lastnum+1; n++) + { + if(patches[n] != 0) + { + bitpack.PackBits(1,1); //value or EOB + bitpack.PackBits(1,1); //value + if(patches[n] > 0) + { + + bitpack.PackBits(0,1); // positive + bitpack.PackBits(patches[n],13); + + } + else + { + bitpack.PackBits(1,1); // negative + + int temp = patches[n] * -1; + bitpack.PackBits(temp,13); + + } + } + else + { + bitpack.PackBits(0,1); // no value + } + } + + bitpack.PackBits(1,1); //value or EOB + bitpack.PackBits(0,1); // EOB + } + + public int[] CompressPatch(float[] patches) + { + int size = 16; + float[] block = new float[size * size]; + int[] output = new int[size * size]; + int prequant = (139 >> 4) + 2; + int quantize = 1 << prequant; + float ooq = 1.0f / (float)quantize; + float mult = ooq * (float)1; + float addval = mult * (float)(1 << (prequant - 1)) + 20.4989f; + + if (size == 16) + { + for (int n = 0; n < 16 * 16; n++) + { + block[n] = (float)((patches[n] - addval)/ mult); + } + + float[] ftemp = new float[32 * 32]; + + for (int o = 0; o < 16; o++) + this.DCTColumn16(block, ftemp, o); + for (int o = 0; o < 16; o++) + this.DCTLine16(ftemp, block, o); + } + + for (int j = 0; j < block.Length; j++) + { + output[DeCopyMatrix16[j]] = (int)(block[j] / DequantizeTable16[j]); + } + + return output; + } + + public Packet CreateLayerPacket(float[] heightmap, int minX, int minY, int maxX, int maxY) + { + //int minX = 0, maxX = 2, minY = 0, maxY = 1; //these should be passed to this function + LayerDataPacket layer = new LayerDataPacket(); + byte[] Encoded = new byte[2048]; + layer.LayerID.Type = 76; + GroupHeader header = new GroupHeader(); + header.Stride = 264; + header.PatchSize = 16; + header.Type = LayerType.Land; + BitPacker newpack = new BitPacker(Encoded,0); + newpack.PackBits(header.Stride,16); + newpack.PackBits(header.PatchSize,8); + newpack.PackBits((int)header.Type,8); + + + float[] height; + for(int y = minY; y< maxY; y++) + { + for(int x = minX ; x < maxX ; x++) + { + height = new float[256]; + Array.Copy(heightmap, (4096 *y) +(x *256), height, 0, 256); + + this.CreatePatch(height, newpack, x, y); + } + } + + PatchHeader headers = new PatchHeader(); + headers.QuantWBits = END_OF_PATCHES; + this.EncodePatchHeader(newpack, headers); + + int lastused=0; + for(int i = 0; i < 2048 ; i++) + { + if(Encoded[i] !=0) + lastused = i; + } + + byte[] data = new byte[lastused+1]; + Array.Copy(Encoded, data, lastused+1); + layer.LayerData.Data =data; + + return(layer); + } + public void CreatePatch(float[] heightmap, BitPacker newpack, int x, int y) + { + PatchHeader header = new PatchHeader(); + header.DCOffset = 20.4989f; + header.QuantWBits = 139; + header.Range = 1; + header.PatchIDs = (y & 0x1F); + header.PatchIDs += x <<5 ; + + this.EncodePatchHeader(newpack, header); + + int[] newpatch = this.CompressPatch(heightmap); + this.EncodePatch(newpatch, newpack, 16); + + } + } + + //*************************************************** + public class BitPacker + { + private const int MAX_BITS = 8; + + private byte[] Data; + public int bytePos; + public int bitPos; + + /// + /// Default constructor, initialize the bit packer / bit unpacker + /// with a byte array and starting position + /// + /// Byte array to pack bits in to or unpack from + /// Starting position in the byte array + public BitPacker(byte[] data, int pos) + { + Data = data; + bytePos = pos; + } + + /// + /// Pack a floating point value in to the data + /// + /// Floating point value to pack + public void PackFloat(float data) + { + byte[] input = BitConverter.GetBytes(data); + PackBitArray(input, 32); + } + + /// + /// Pack part or all of an integer in to the data + /// + /// Integer containing the data to pack + /// Number of bits of the integer to pack + public void PackBits(int data, int totalCount) + { + byte[] input = BitConverter.GetBytes(data); + PackBitArray(input, totalCount); + } + + /// + /// Unpacking a floating point value from the data + /// + /// Unpacked floating point value + public float UnpackFloat() + { + byte[] output = UnpackBitsArray(32); + + if (!BitConverter.IsLittleEndian) Array.Reverse(output); + return BitConverter.ToSingle(output, 0); + } + + /// + /// Unpack a variable number of bits from the data in to integer format + /// + /// Number of bits to unpack + /// An integer containing the unpacked bits + /// This function is only useful up to 32 bits + public int UnpackBits(int totalCount) + { + byte[] output = UnpackBitsArray(totalCount); + + if (!BitConverter.IsLittleEndian) Array.Reverse(output); + return BitConverter.ToInt32(output, 0); + } + + private void PackBitArray(byte[] data, int totalCount) + { + int count = 0; + int curBytePos = 0; + int curBitPos = 0; + + while (totalCount > 0) + { + if (totalCount > (MAX_BITS )) + { + count = MAX_BITS ; + totalCount -= MAX_BITS ; + } + else + { + count = totalCount; + totalCount = 0; + } + + while (count > 0) + { + switch(count) + { + case 1: + if ((data[curBytePos] & (0x01)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + case 2: + if ((data[curBytePos] & (0x02)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + case 3: + if ((data[curBytePos] & (0x04)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + case 4: + if ((data[curBytePos] & (0x08)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + case 5: + if ((data[curBytePos] & (0x10)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + case 6: + if ((data[curBytePos] & (0x20)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + case 7: + if ((data[curBytePos] & (0x40)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + case 8: + if ((data[curBytePos] & (0x80)) != 0) + { + Data[bytePos] |= (byte)(0x80 >> bitPos); + } + break; + } + + bitPos++; + --count; + ++curBitPos; + + if (bitPos >= MAX_BITS) + { + bitPos = 0; + ++bytePos; + } + if (curBitPos >= MAX_BITS) + { + curBitPos = 0; + ++curBytePos; + } + } + } + } + + + private byte[] UnpackBitsArray(int totalCount) + { + int count = 0; + byte[] output = new byte[4]; + int curBytePos = 0; + int curBitPos = 0; + + while (totalCount > 0) + { + if (totalCount > MAX_BITS) + { + count = MAX_BITS; + totalCount -= MAX_BITS; + } + else + { + count = totalCount; + totalCount = 0; + } + + while (count > 0) + { + // Shift the previous bits + output[curBytePos] <<= 1; + + // Grab one bit + if ((Data[bytePos] & (0x80 >> bitPos++)) != 0) + ++output[curBytePos]; + + --count; + ++curBitPos; + + if (bitPos >= MAX_BITS) + { + bitPos = 0; + ++bytePos; + } + if (curBitPos >= MAX_BITS) + { + curBitPos = 0; + ++curBytePos; + } + } + } + + return output; + } + } +} diff --git a/src/world/World.cs b/src/world/World.cs new file mode 100644 index 0000000000..ebb7872b17 --- /dev/null +++ b/src/world/World.cs @@ -0,0 +1,93 @@ +using System; +using libsecondlife; +using libsecondlife.Packets; +using System.Collections.Generic; +using System.Text; +using PhysicsSystem; + +namespace OpenSim.world +{ + public class World + { + public Dictionary Entities; + public float[] LandMap; + public ScriptEngine Scripts; + public TerrainDecode terrainengine = new TerrainDecode(); + public uint _localNumber=0; + private PhysicsScene phyScene; + private float timeStep= 0.1f; + + private Random Rand = new Random(); + + public World() + { + Console.WriteLine("World.cs - creating new entitities instance"); + Entities = new Dictionary(); + + Console.WriteLine("World.cs - creating LandMap"); + terrainengine = new TerrainDecode(); + LandMap = new float[65536]; + for(int i =0; i < 65536; i++) { + LandMap[i] = 21.4989f; + } + + Console.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; + } + } + + public void Update() + { + if(this.phyScene.IsThreaded) + { + this.phyScene.GetResults(); + + } + + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].addFroces(); + } + + this.phyScene.Simulate(timeStep); + + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].update(); + } + } + + public void SendLayerData(OpenSimClient RemoteClient) { + for(int x=0; x<16; x=x+4) for(int y=0; y<16; y++){ + Packet layerpack=this.terrainengine.CreateLayerPacket(LandMap, x,y,x+4,y+1); + RemoteClient.OutPacket(layerpack); + } + } + + public void AddViewerAgent(OpenSimClient AgentClient) { + Console.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); + Avatar NewAvatar = new Avatar(AgentClient); + Console.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world"); + this.Entities.Add(AgentClient.AgentID, NewAvatar); + Console.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake "); + NewAvatar.SendRegionHandshake(this); + + NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z)); + //this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user + } + + public bool Backup() { + /* TODO: Save the current world entities state. */ + + return false; + } + } +} diff --git a/src/world/scripting/IScript.cs b/src/world/scripting/IScript.cs new file mode 100644 index 0000000000..550594d343 --- /dev/null +++ b/src/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(); + } +}