From a41e0e918dfd5ef0eb1611e75cd83f46320f68f6 Mon Sep 17 00:00:00 2001 From: MW Date: Fri, 2 Mar 2007 18:10:45 +0000 Subject: [PATCH] A example of how the physics plugins might work --- Config.cs | 141 ++++++++++++ Main.cs | 142 ++++++++++++ OpenSimClient.cs | 408 ++++++++++++++++++++++++++++++++++ Second-server.csproj | 68 ++++++ Second-server.sln | 26 +++ physics/AssemblyInfo.cs | 31 +++ physics/PhysicsManager.cs | 162 ++++++++++++++ physics/PhysicsManager.csproj | 35 +++ physics/PhysicsManager.sln | 23 ++ 9 files changed, 1036 insertions(+) create mode 100644 Config.cs create mode 100644 Main.cs create mode 100644 OpenSimClient.cs create mode 100644 Second-server.csproj create mode 100644 Second-server.sln create mode 100644 physics/AssemblyInfo.cs create mode 100644 physics/PhysicsManager.cs create mode 100644 physics/PhysicsManager.csproj create mode 100644 physics/PhysicsManager.sln diff --git a/Config.cs b/Config.cs new file mode 100644 index 0000000000..aa29cd1c48 --- /dev/null +++ b/Config.cs @@ -0,0 +1,141 @@ +/* +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 Db4objects.Db4o; +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 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; + + private IObjectContainer db; + + + public void LoadDefaults() { + this.RegionName = "OpenSim test\0"; + this.RegionLocX = 997; + this.RegionLocY = 996; + this.RegionHandle = Helpers.UIntsToLong((RegionLocX*256), (RegionLocY*256)); + this.IPListenPort = 9000; + this.IPListenAddr = "4.78.190.75"; + this.AssetURL = "http://www.osgrid.org/ogs/assetserver/"; + this.AssetSendKey = "1234"; + this.GridURL = "http://www.osgrid.org/ogs/gridserver/"; + this.GridSendKey = "1234"; + } + + public void InitConfig() { + try { + db = Db4oFactory.OpenFile("opensim.yap"); + IObjectSet result = db.Get(typeof(SimConfig)); + if(result.Count==1) { + Console.WriteLine("Config.cs:InitConfig() - Found a SimConfig object in the local database, loading"); + foreach (SimConfig cfg in result) { + this.RegionName = cfg.RegionName; + this.RegionLocX = cfg.RegionLocX; + this.RegionLocY = cfg.RegionLocY; + this.RegionHandle = Helpers.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 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 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/Main.cs b/Main.cs new file mode 100644 index 0000000000..78eaf41a2a --- /dev/null +++ b/Main.cs @@ -0,0 +1,142 @@ +/* +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.Collections; +using System.Collections.Generic; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim.world; + +namespace OpenSim +{ + /// + /// Description of MainForm. + /// + public class OpenSim_Main + { + private static OpenSim_Main sim; + public static SimConfig cfg; + public static World local_world; + 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; + [STAThread] + public static void Main( string[] args ) + { + Console.WriteLine("OpenSim " + VersionInfo.Version + "\n"); + Console.WriteLine("Starting...\n"); + sim = new OpenSim_Main(); + sim.Startup(); + while(true) { + Thread.Sleep(1000); + } + } + + private OpenSim_Main() { + } + + private void Startup() { + // We check our local database first, then the grid for config options + Console.WriteLine("Main.cs:Startup() - Loading configuration"); + cfg = new SimConfig(); + 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 PhysicsManager(); + this.physManager.LoadPlugins(); + local_world.PhysScene = this.physManager.GetScene("PhysX"); //should be reading from the config file what physics engine to use + + Console.WriteLine("Main.cs:Startup() - Starting up messaging system"); + MainListener = new Thread(new ThreadStart(MainServerListener)); + MainListener.Start(); + + } + + 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..."); + while(true) { + Thread.Sleep(1000); + } + } + } +} diff --git a/OpenSimClient.cs b/OpenSimClient.cs new file mode 100644 index 0000000000..83d859941f --- /dev/null +++ b/OpenSimClient.cs @@ -0,0 +1,408 @@ +/* +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; + +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 BlockingQueue AssetRequests; + 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 AssetLoader() { + Console.WriteLine("OpenSimClient.cs:AssetLoader() - Starting new thread"); + TransferRequestPacket reqPacket = AssetRequests.Dequeue(); + Console.WriteLine("OpenSimClient.cs:AssetLoader() - Got a request, processing it"); + LLUUID AssetID = new LLUUID(reqPacket.TransferInfo.Params, 0); + WebRequest AssetLoad = WebRequest.Create(OpenSim_Main.cfg.AssetURL + "getasset/" + OpenSim_Main.cfg.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(); + + TransferInfoPacket Transfer = new TransferInfoPacket(); + Transfer.TransferInfo.ChannelType = 2; + Transfer.TransferInfo.Status = 0; + Transfer.TransferInfo.TargetType = 0; + Transfer.TransferInfo.Params = reqPacket.TransferInfo.Params; + Transfer.TransferInfo.Size = (int)AssetResponse.ContentLength; + Transfer.TransferInfo.TransferID = reqPacket.TransferInfo.TransferID; + + OutPacket(Transfer); + + TransferPacketPacket TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 0; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID=reqPacket.TransferInfo.TransferID; + + if(AssetResponse.ContentLength>1000) { + byte[] chunk = new byte[1000]; + Array.Copy(idata,chunk,1000); + TransferPacket.TransferData.Data = chunk; + TransferPacket.TransferData.Status = 0; + OutPacket(TransferPacket); + + TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = 1; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID = reqPacket.TransferInfo.TransferID; + byte[] chunk1 = new byte[(idata.Length-1000)]; + Array.Copy(idata, 1000, chunk1, 0, chunk1.Length); + TransferPacket.TransferData.Data = chunk1; + TransferPacket.TransferData.Status = 1; + OutPacket(TransferPacket); + } else { + TransferPacket.TransferData.Status = 1; + TransferPacket.TransferData.Data = idata; + OutPacket(TransferPacket); + } + AssetResponse.Close(); + } + + 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"); + // We put transfer requests into a big queue and then spawn a thread for each new one + TransferRequestPacket transfer = (TransferRequestPacket)Pack; + AssetRequests.Enqueue(transfer); + Thread AssetLoaderThread = new Thread(new ThreadStart(AssetLoader)); + AssetLoaderThread.Start(); + 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(); + AssetRequests = 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() { + Console.WriteLine("OpenSimClient.cs:AuthUser() - Authenticating new user request with grid"); + WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + cirpack.CircuitCode.ID.ToString() + "/" + cirpack.CircuitCode.Code.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 + Console.WriteLine("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString()); + this.AgentID=cirpack.CircuitCode.ID; + this.SessionID=cirpack.CircuitCode.SessionID; + this.CircuitCode=cirpack.CircuitCode.Code; + InitNewClient(); + ClientLoop(); + } else { // Invalid + Console.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString()); + ClientThread.Abort(); + } + } + } + +} diff --git a/Second-server.csproj b/Second-server.csproj new file mode 100644 index 0000000000..87f32044bb --- /dev/null +++ b/Second-server.csproj @@ -0,0 +1,68 @@ + + + Exe + OpenSim + OpenSim + Debug + AnyCPU + {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E} + OpenSim.OpenSim_Main + + + ..\bin\ + False + DEBUG;TRACE + True + Full + True + + + ..\bin\ + True + TRACE + False + None + False + + + + False + ..\bin\Axiom.MathLib.dll + + + + False + ..\bin\libsecondlife.dll + + + False + ..\bin\log4net.dll + + + + + + ..\..\..\..\physics\PhysicsManager\bin\Release\PhysicsManager.dll + False + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Second-server.sln b/Second-server.sln new file mode 100644 index 0000000000..86fc54c313 --- /dev/null +++ b/Second-server.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Second-server", "Second-server.csproj", "{132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}" +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 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/physics/AssemblyInfo.cs b/physics/AssemblyInfo.cs new file mode 100644 index 0000000000..57a8913d33 --- /dev/null +++ b/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/physics/PhysicsManager.cs b/physics/PhysicsManager.cs new file mode 100644 index 0000000000..9315e03497 --- /dev/null +++ b/physics/PhysicsManager.cs @@ -0,0 +1,162 @@ +/* +* 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 PhysicsManager +{ + /// + /// Description of MyClass. + /// + public class PhysicsManager + { + private Dictionary _plugins=new Dictionary(); + + public PhysicsManager() + { + + } + + public PhysicsScene GetPhysicsScene(string engineName) + { + if(_plugins.ContainsKey(engineName)) + { + return _plugins[engineName].GetScene(); + } + else + { + return null; + } + } + + public void LoadPlugins() + { + string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory ,"Physics"); + string[] pluginFiles = Directory.GetFiles(path, "*.Phy"); + + + 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/physics/PhysicsManager.sln b/physics/PhysicsManager.sln new file mode 100644 index 0000000000..565813fde9 --- /dev/null +++ b/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