コード例 #1
0
 public RegionHandshakeData(RegionHandshake msg)
 {
     RegionFlags          = msg.RegionFlags;
     SimAccess            = msg.SimAccess;
     SimName              = msg.SimName;
     IsEstateManager      = msg.IsEstateManager;
     WaterHeight          = msg.WaterHeight;
     BillableFactor       = msg.BillableFactor;
     CacheID              = msg.CacheID;
     TerrainBase0         = msg.TerrainBase0;
     TerrainBase1         = msg.TerrainBase1;
     TerrainBase2         = msg.TerrainBase2;
     TerrainBase3         = msg.TerrainBase3;
     TerrainDetail0       = msg.TerrainDetail0;
     TerrainDetail1       = msg.TerrainDetail1;
     TerrainDetail2       = msg.TerrainDetail2;
     TerrainDetail3       = msg.TerrainDetail3;
     TerrainHeightRange00 = msg.TerrainHeightRange00;
     TerrainHeightRange01 = msg.TerrainHeightRange01;
     TerrainHeightRange10 = msg.TerrainHeightRange10;
     TerrainHeightRange11 = msg.TerrainHeightRange11;
     TerrainStartHeight00 = msg.TerrainStartHeight00;
     TerrainStartHeight01 = msg.TerrainStartHeight01;
     TerrainStartHeight10 = msg.TerrainStartHeight10;
     TerrainStartHeight11 = msg.TerrainStartHeight11;
     RegionID             = msg.RegionID;
     CPUClassID           = msg.CPUClassID;
     CPURatio             = msg.CPURatio;
     ColoName             = msg.ColoName;
     ProductSKU           = msg.ProductSKU;
     ProductName          = msg.ProductName;
     RegionExtData        = msg.RegionExtData;
 }
コード例 #2
0
        private void UdpReceiveEndHandler(IAsyncResult ar)
        {
            Circuit circuit;
            var     pck = (UDPReceivePacket)ar.AsyncState;

            try
            {
                pck.DataLength = m_UdpSocket.EndReceiveFrom(ar, ref pck.RemoteEndPoint);
            }
            catch
            {
                return;
            }
            finally
            {
                if (m_InboundRunning)
                {
                    BeginUdpReceive();
                }
            }

            pck.TransferredAtTime = Environment.TickCount;
            pck.EnqueuedAtTime    = Environment.TickCount;

            /* we do not want to spend time on decoding packets that are unknown where they belong */
            if (!m_Circuits.TryGetValue(pck.RemoteEndPoint, out circuit) || circuit.ForceUseCircuitCode)
            {
                try
                {
                    /* check whether we got an UseCircuitCode */
                    var mType = pck.ReadMessageType();
                    if (MessageType.UseCircuitCode == mType)
                    {
                        var circuitcode = pck.ReadUInt32();
                        /* it is, so we have actually to look for the circuitcode and set up the remote endpoint here */
                        lock (m_UseCircuitCodeProcessingLock)
                        {
                            if (m_Circuits.TryGetValue(circuitcode, out circuit))
                            {
                                circuit.ForceUseCircuitCode = false;
                                var sessionID = pck.ReadUUID();
                                var agentID   = pck.ReadUUID();
                                var acircuit  = circuit as AgentCircuit;
                                if (acircuit != null)
                                {
                                    /* there it is check for SessionID and AgentID */
                                    if (!acircuit.SessionID.Equals(sessionID) ||
                                        !acircuit.AgentID.Equals(agentID) ||
                                        !VerifyEndpointAddress(acircuit, pck.RemoteEndPoint))
                                    {
                                        /* no match on SessionID or AgentID */
                                        m_Log.DebugFormat("Unmatched UseCircuitCode for AgentID {0} SessionID {1} CircuitCode {2} received", agentID, sessionID, circuitcode);
                                    }
                                    else
                                    {
                                        /* it matches, so we have to change the actual key */
                                        var endpoint = new IPEndPoint(0, 0);
                                        var ep       = endpoint.Create(pck.RemoteEndPoint.Serialize());
                                        m_Circuits.Remove(circuit.CircuitCode);
                                        m_Circuits.Add(ep, circuit.CircuitCode, circuit);
                                        circuit.RemoteEndPoint = ep;
                                        try
                                        {
                                            circuit.Start();

                                            var scene = Scene;
                                            RegionOptionFlags regionFlags = scene.RegionSettings.AsFlags;
                                            var rh = new RegionHandshake
                                            {
                                                RegionFlags          = regionFlags,
                                                SimAccess            = scene.Access,
                                                SimName              = scene.Name,
                                                SimOwner             = scene.Owner.ID,
                                                IsEstateManager      = scene.IsEstateManager(acircuit.Agent.Owner),
                                                WaterHeight          = scene.RegionSettings.WaterHeight,
                                                BillableFactor       = 1,
                                                TerrainStartHeight00 = scene.RegionSettings.Elevation1SW,
                                                TerrainStartHeight01 = scene.RegionSettings.Elevation2SW,
                                                TerrainStartHeight10 = scene.RegionSettings.Elevation1NW,
                                                TerrainStartHeight11 = scene.RegionSettings.Elevation2NW,
                                                TerrainHeightRange00 = scene.RegionSettings.Elevation1SE,
                                                TerrainHeightRange01 = scene.RegionSettings.Elevation2SE,
                                                TerrainHeightRange10 = scene.RegionSettings.Elevation1NE,
                                                TerrainHeightRange11 = scene.RegionSettings.Elevation2NE,
                                                TerrainBase0         = UUID.Zero,
                                                TerrainBase1         = UUID.Zero,
                                                TerrainBase2         = UUID.Zero,
                                                TerrainBase3         = UUID.Zero,
                                                TerrainDetail0       = scene.RegionSettings.TerrainTexture1,
                                                TerrainDetail1       = scene.RegionSettings.TerrainTexture2,
                                                TerrainDetail2       = scene.RegionSettings.TerrainTexture3,
                                                TerrainDetail3       = scene.RegionSettings.TerrainTexture4,
                                                RegionID             = scene.ID,
                                                CacheID              = UUID.Random,
                                                CPUClassID           = 9,
                                                CPURatio             = 1,
                                                ColoName             = string.Empty,
                                                ProductSKU           = VersionInfo.SimulatorVersion,
                                                ProductName          = scene.ProductName
                                            };
                                            rh.RegionExtData.Add(new RegionHandshake.RegionExtDataEntry
                                            {
                                                RegionFlagsExtended = (ulong)regionFlags,
                                                RegionProtocols     = RegionProtocolFlags.AgentAppearanceService
                                            });

                                            /* Immediate Ack */
                                            circuit.SendCircuitPacket(UDPPacket.PacketAckImmediate(pck.SequenceNumber));

                                            circuit.SendMessage(rh);
                                            return;
                                        }
                                        catch (Exception e)
                                        {
                                            m_Log.DebugFormat("UseCircuitCode Exception {0} {1}\n{2}", e.GetType().Name, e.Message, e.StackTrace);
                                            circuit.Stop();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                m_Log.DebugFormat("UseCircuitCode received for unknown circuit {0}", circuitcode);
                            }
                        }
                    }
                    else if (MessageType.NetTest == mType && (uint)m_NetTestSeqNumber == pck.SequenceNumber ||
                             pck.ReadUInt16() == (ushort)LocalPort)
                    {
                        OnNetTest?.Invoke(((IPEndPoint)pck.RemoteEndPoint).Address, LocalPort);
                        return;
                    }
#if DEBUG
                    if (mType != MessageType.StartPingCheck)
                    {
                        /* do not show that message for a StartPingCheck */
                        m_Log.DebugFormat("Unmatched endpoint address {0} for UDP server at port {1}", pck.RemoteEndPoint.ToString(), LocalPort);
                    }
#endif
                }
                catch
                {
                    /* no action required */
                }

                return;
            }

            /* here we spend time on decoding */
            if (pck.IsUndersized)
            {
                /* packet is undersized so we throw it away as well */
                return;
            }

            /* now we know that the packet is at least valid
             * We can pass it to the circuit handler.
             */

            /* we decode the ack numbers here, the code does not need to be implemented in the UDP Circuit Handler */
            List <UInt32> acknumbers = null;

            if (pck.HasAckFlag)
            {
                try
                {
                    acknumbers = pck.Acks;
                }
                catch
                {
                    /* packet is undersized so we throw it away as well */
                    return;
                }
            }

            try
            {
                circuit.PacketReceived(pck.RemoteEndPoint, pck, acknumbers);
            }
            catch (Exception e)
            {
                /* we catch all issues here */
                m_Log.ErrorFormat("Exception {0} => {1} at {2}", e.GetType().Name, e.ToString(), e.StackTrace);
            }
            /* return the buffer to the pool */
        }