Exemple #1
0
        private void SeedRequestCompleteHandler(CapsClient client, LLSD result, Exception error)
        {
            if (result != null && result.Type == LLSDType.Map)
            {
                LLSDMap respTable = (LLSDMap)result;

                StringBuilder capsList = new StringBuilder();

                foreach (string cap in respTable.Keys)
                {
                    capsList.Append(cap);
                    capsList.Append(' ');

                    _Caps[cap] = respTable[cap].AsUri();
                }

                Logger.DebugLog("Got capabilities: " + capsList.ToString(), Simulator.Client);

                if (_Caps.ContainsKey("EventQueueGet"))
                {
                    Logger.DebugLog("Starting event queue for " + Simulator.ToString(), Simulator.Client);

                    _EventQueueCap              = new EventQueueClient(_Caps["EventQueueGet"]);
                    _EventQueueCap.OnConnected += new EventQueueClient.ConnectedCallback(EventQueueConnectedHandler);
                    _EventQueueCap.OnEvent     += new EventQueueClient.EventCallback(EventQueueEventHandler);
                    _EventQueueCap.Start();
                }
            }
            else
            {
                // The initial CAPS connection failed, try again
                MakeSeedRequest();
            }
        }
Exemple #2
0
        private void RegionHandshakeHandler(Packet packet, Simulator simulator)
        {
            RegionHandshakePacket handshake = (RegionHandshakePacket)packet;

            simulator.ID = handshake.RegionInfo.CacheID;

            simulator.IsEstateManager      = handshake.RegionInfo.IsEstateManager;
            simulator.Name                 = Helpers.FieldToUTF8String(handshake.RegionInfo.SimName);
            simulator.SimOwner             = handshake.RegionInfo.SimOwner;
            simulator.TerrainBase0         = handshake.RegionInfo.TerrainBase0;
            simulator.TerrainBase1         = handshake.RegionInfo.TerrainBase1;
            simulator.TerrainBase2         = handshake.RegionInfo.TerrainBase2;
            simulator.TerrainBase3         = handshake.RegionInfo.TerrainBase3;
            simulator.TerrainDetail0       = handshake.RegionInfo.TerrainDetail0;
            simulator.TerrainDetail1       = handshake.RegionInfo.TerrainDetail1;
            simulator.TerrainDetail2       = handshake.RegionInfo.TerrainDetail2;
            simulator.TerrainDetail3       = handshake.RegionInfo.TerrainDetail3;
            simulator.TerrainHeightRange00 = handshake.RegionInfo.TerrainHeightRange00;
            simulator.TerrainHeightRange01 = handshake.RegionInfo.TerrainHeightRange01;
            simulator.TerrainHeightRange10 = handshake.RegionInfo.TerrainHeightRange10;
            simulator.TerrainHeightRange11 = handshake.RegionInfo.TerrainHeightRange11;
            simulator.TerrainStartHeight00 = handshake.RegionInfo.TerrainStartHeight00;
            simulator.TerrainStartHeight01 = handshake.RegionInfo.TerrainStartHeight01;
            simulator.TerrainStartHeight10 = handshake.RegionInfo.TerrainStartHeight10;
            simulator.TerrainStartHeight11 = handshake.RegionInfo.TerrainStartHeight11;
            simulator.WaterHeight          = handshake.RegionInfo.WaterHeight;
            simulator.Flags                = (Simulator.RegionFlags)handshake.RegionInfo.RegionFlags;
            simulator.BillableFactor       = handshake.RegionInfo.BillableFactor;
            simulator.Access               = (Simulator.SimAccess)handshake.RegionInfo.SimAccess;

            Client.Log("Received a region handshake for " + simulator.ToString(), Helpers.LogLevel.Info);

            // Send a RegionHandshakeReply
            RegionHandshakeReplyPacket reply = new RegionHandshakeReplyPacket();

            reply.AgentData.AgentID   = Client.Self.AgentID;
            reply.AgentData.SessionID = Client.Self.SessionID;
            reply.RegionInfo.Flags    = 0;
            SendPacket(reply, simulator);

            // We're officially connected to this sim
            simulator.connected = true;
            simulator.ConnectedEvent.Set();
        }
Exemple #3
0
        private void ParcelOverlayHandler(Packet packet, Simulator simulator)
        {
            ParcelOverlayPacket overlay = (ParcelOverlayPacket)packet;

            if (overlay.ParcelData.SequenceID >= 0 && overlay.ParcelData.SequenceID <= 3)
            {
                Buffer.BlockCopy(overlay.ParcelData.Data, 0, simulator.ParcelOverlay,
                                 overlay.ParcelData.SequenceID * 1024, 1024);
                simulator.ParcelOverlaysReceived++;

                if (simulator.ParcelOverlaysReceived > 3)
                {
                    // TODO: ParcelOverlaysReceived should become internal, and reset to zero every
                    // time it hits four. Also need a callback here
                }
            }
            else
            {
                Client.Log("Parcel overlay with sequence ID of " + overlay.ParcelData.SequenceID +
                           " received from " + simulator.ToString(), Helpers.LogLevel.Warning);
            }
        }
 private void Network_OnEventQueueRunning(Simulator simulator)
 {
     Logger.DebugLog("Event queue is running for " + simulator.ToString() + ", enabling uploads", Client);
     EnableUpload();
 }
Exemple #5
0
        private void RegionHandshakeHandler(Packet packet, Simulator simulator)
        {
            RegionHandshakePacket handshake = (RegionHandshakePacket)packet;

            simulator.ID = handshake.RegionInfo.CacheID;

            simulator.IsEstateManager = handshake.RegionInfo.IsEstateManager;
            simulator.Name = Helpers.FieldToUTF8String(handshake.RegionInfo.SimName);
            simulator.SimOwner = handshake.RegionInfo.SimOwner;
            simulator.TerrainBase0 = handshake.RegionInfo.TerrainBase0;
            simulator.TerrainBase1 = handshake.RegionInfo.TerrainBase1;
            simulator.TerrainBase2 = handshake.RegionInfo.TerrainBase2;
            simulator.TerrainBase3 = handshake.RegionInfo.TerrainBase3;
            simulator.TerrainDetail0 = handshake.RegionInfo.TerrainDetail0;
            simulator.TerrainDetail1 = handshake.RegionInfo.TerrainDetail1;
            simulator.TerrainDetail2 = handshake.RegionInfo.TerrainDetail2;
            simulator.TerrainDetail3 = handshake.RegionInfo.TerrainDetail3;
            simulator.TerrainHeightRange00 = handshake.RegionInfo.TerrainHeightRange00;
            simulator.TerrainHeightRange01 = handshake.RegionInfo.TerrainHeightRange01;
            simulator.TerrainHeightRange10 = handshake.RegionInfo.TerrainHeightRange10;
            simulator.TerrainHeightRange11 = handshake.RegionInfo.TerrainHeightRange11;
            simulator.TerrainStartHeight00 = handshake.RegionInfo.TerrainStartHeight00;
            simulator.TerrainStartHeight01 = handshake.RegionInfo.TerrainStartHeight01;
            simulator.TerrainStartHeight10 = handshake.RegionInfo.TerrainStartHeight10;
            simulator.TerrainStartHeight11 = handshake.RegionInfo.TerrainStartHeight11;
            simulator.WaterHeight = handshake.RegionInfo.WaterHeight;
            simulator.Flags = (Simulator.RegionFlags)handshake.RegionInfo.RegionFlags;
            simulator.BillableFactor = handshake.RegionInfo.BillableFactor;
            simulator.Access = (Simulator.SimAccess)handshake.RegionInfo.SimAccess;

            Client.Log("Received a region handshake for " + simulator.ToString(), Helpers.LogLevel.Info);

            // Send a RegionHandshakeReply
            RegionHandshakeReplyPacket reply = new RegionHandshakeReplyPacket();
            reply.AgentData.AgentID = Client.Self.AgentID;
            reply.AgentData.SessionID = Client.Self.SessionID;
            reply.RegionInfo.Flags = 0;
            SendPacket(reply, simulator);

            // We're officially connected to this sim
            simulator.connected = true;
            simulator.ConnectedEvent.Set();
        }
Exemple #6
0
        private void ParcelOverlayHandler(Packet packet, Simulator simulator)
        {
            ParcelOverlayPacket overlay = (ParcelOverlayPacket)packet;

            if (overlay.ParcelData.SequenceID >= 0 && overlay.ParcelData.SequenceID <= 3)
            {
                Buffer.BlockCopy(overlay.ParcelData.Data, 0, simulator.ParcelOverlay, 
                    overlay.ParcelData.SequenceID * 1024, 1024);
                simulator.ParcelOverlaysReceived++;

                if (simulator.ParcelOverlaysReceived > 3)
                {
                    // TODO: ParcelOverlaysReceived should become internal, and reset to zero every 
                    // time it hits four. Also need a callback here
                }
            }
            else
            {
                Client.Log("Parcel overlay with sequence ID of " + overlay.ParcelData.SequenceID +
                    " received from " + simulator.ToString(), Helpers.LogLevel.Warning);
            }
        }
Exemple #7
0
        /// <summary>
        /// Handler for teleport Requests
        /// </summary>
        /// <param name="packet">Incoming TeleportHandler packet</param>
        /// <param name="simulator">Simulator sending teleport information</param>
        private void TeleportHandler(Packet packet, Simulator simulator)
        {
            bool finished = false;
            TeleportFlags flags = TeleportFlags.Default;
            
            if (packet.Type == PacketType.TeleportStart)
            {
                TeleportStartPacket start = (TeleportStartPacket)packet;

                teleportMessage = "Teleport started";
                flags = (TeleportFlags)start.Info.TeleportFlags;
                teleportStat = TeleportStatus.Start;

                Client.DebugLog("TeleportStart received, Flags: " + flags.ToString());
            }
            else if (packet.Type == PacketType.TeleportProgress)
            {
                TeleportProgressPacket progress = (TeleportProgressPacket)packet;

                teleportMessage = Helpers.FieldToUTF8String(progress.Info.Message);
                flags = (TeleportFlags)progress.Info.TeleportFlags;
                teleportStat = TeleportStatus.Progress;

                Client.DebugLog("TeleportProgress received, Message: " + teleportMessage + ", Flags: " + flags.ToString());
            }
            else if (packet.Type == PacketType.TeleportFailed)
            {
                TeleportFailedPacket failed = (TeleportFailedPacket)packet;

                teleportMessage = Helpers.FieldToUTF8String(failed.Info.Reason);
                teleportStat = TeleportStatus.Failed;
                finished = true;

                Client.DebugLog("TeleportFailed received, Reason: " + teleportMessage);
            }
            else if (packet.Type == PacketType.TeleportFinish)
            {
                TeleportFinishPacket finish = (TeleportFinishPacket)packet;

                flags = (TeleportFlags)finish.Info.TeleportFlags;
                string seedcaps = Helpers.FieldToUTF8String(finish.Info.SeedCapability);
                finished = true;

                Client.DebugLog("TeleportFinish received, Flags: " + flags.ToString());

                // Connect to the new sim
                Simulator newSimulator = Client.Network.Connect(new IPAddress(finish.Info.SimIP),
                    finish.Info.SimPort, finish.Info.RegionHandle, true, seedcaps);

                if (newSimulator != null)
                {
                    teleportMessage = "Teleport finished";
                    teleportStat = TeleportStatus.Finished;

                    // Disconnect from the previous sim
                    Client.Network.DisconnectSim(simulator, true);

                    Client.Log("Moved to new sim " + newSimulator.ToString(), Helpers.LogLevel.Info);
                }
                else
                {
                    teleportMessage = "Failed to connect to the new sim after a teleport";
                    teleportStat = TeleportStatus.Failed;

                    // We're going to get disconnected now
                    Client.Log(teleportMessage, Helpers.LogLevel.Error);
                }
            }
            else if (packet.Type == PacketType.TeleportCancel)
            {
                //TeleportCancelPacket cancel = (TeleportCancelPacket)packet;

                teleportMessage = "Cancelled";
                teleportStat = TeleportStatus.Cancelled;
                finished = true;

                Client.DebugLog("TeleportCancel received from " + simulator.ToString());
            }
            else if (packet.Type == PacketType.TeleportLocal)
            {
                TeleportLocalPacket local = (TeleportLocalPacket)packet;

                teleportMessage = "Teleport finished";
                flags = (TeleportFlags)local.Info.TeleportFlags;
                teleportStat = TeleportStatus.Finished;
                relativePosition = local.Info.Position;
                Movement.Camera.LookDirection(local.Info.LookAt);
                // This field is apparently not used for anything
                //local.Info.LocationID;
                finished = true;

                Client.DebugLog("TeleportLocal received, Flags: " + flags.ToString());
            }

            if (OnTeleport != null)
            {
                try { OnTeleport(teleportMessage, teleportStat, flags); }
                catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }

            if (finished) teleportEvent.Set();
        }
Exemple #8
0
        private void DisconnectTimer_Elapsed(object obj)
        {
            if (!connected || CurrentSim == null)
            {
                if (DisconnectTimer != null)
                {
                    DisconnectTimer.Dispose();
                }
                connected = false;
            }
            else if (CurrentSim.DisconnectCandidate)
            {
                // The currently occupied simulator hasn't sent us any traffic in a while, shutdown
                Client.Log("Network timeout for the current simulator (" +
                           CurrentSim.ToString() + "), logging out", Helpers.LogLevel.Warning);

                if (DisconnectTimer != null)
                {
                    DisconnectTimer.Dispose();
                }
                connected = false;

                // Shutdown the network layer
                Shutdown(DisconnectType.NetworkTimeout);
            }
            else
            {
                #region Check for timed out simulators

                // Figure out which sims need to be disconnected, then fire
                // all of the events to avoid calling DisconnectSim() inside
                // the Simulators lock
                List <Simulator> disconnectedSims = null;

                // Check all of the connected sims for disconnects
                lock (Simulators)
                {
                    for (int i = 0; i < Simulators.Count; i++)
                    {
                        if (Simulators[i].DisconnectCandidate)
                        {
                            // Avoid initializing a new List<> every time the timer
                            // fires with this piece of code
                            if (disconnectedSims == null)
                            {
                                disconnectedSims = new List <Simulator>();
                            }

                            disconnectedSims.Add(Simulators[i]);
                        }
                        else
                        {
                            Simulators[i].DisconnectCandidate = true;
                        }
                    }
                }

                // Actually disconnect each sim we detected as disconnected
                if (disconnectedSims != null)
                {
                    for (int i = 0; i < disconnectedSims.Count; i++)
                    {
                        if (disconnectedSims[i] != null)
                        {
                            // This sim hasn't received any network traffic since the
                            // timer last elapsed, consider it disconnected
                            Client.Log("Network timeout for simulator " + disconnectedSims[i].ToString() +
                                       ", disconnecting", Helpers.LogLevel.Warning);

                            DisconnectSim(disconnectedSims[i], true);
                        }
                    }
                }

                #endregion Check for timed out simulators
            }
        }
        /// <summary>
        /// Handler for teleport Requests
        /// </summary>
        /// <param name="packet">Incoming TeleportHandler packet</param>
        /// <param name="simulator">Simulator sending teleport information</param>
        private void TeleportHandler(Packet packet, Simulator simulator)
        {
            if (packet.Type == PacketType.TeleportStart)
            {
                Client.DebugLog("TeleportStart received from " + simulator.ToString());

                teleportMessage = "Teleport started";
                TeleportStat = TeleportStatus.Start;

                if (OnBeginTeleport != null)
                {
                    OnBeginTeleport(Client.Network.CurrentSim, teleportMessage, TeleportStat);
                }
            }
            else if (packet.Type == PacketType.TeleportProgress)
            {
                Client.DebugLog("TeleportProgress received from " + simulator.ToString());

                teleportMessage = Helpers.FieldToString(((TeleportProgressPacket)packet).Info.Message);
                TeleportStat = TeleportStatus.Progress;

                if (OnBeginTeleport != null)
                {
                    OnBeginTeleport(Client.Network.CurrentSim, teleportMessage, TeleportStat);
                }
            }
            else if (packet.Type == PacketType.TeleportFailed)
            {
                Client.DebugLog("TeleportFailed received from " + simulator.ToString());

                teleportMessage = Helpers.FieldToString(((TeleportFailedPacket)packet).Info.Reason);
                TeleportStat = TeleportStatus.Failed;

                if (OnBeginTeleport != null)
                {
                    OnBeginTeleport(Client.Network.CurrentSim, teleportMessage, TeleportStat);
                }

                OnBeginTeleport = null;
            }
            else if (packet.Type == PacketType.TeleportFinish)
            {
                Client.DebugLog("TeleportFinish received from " + simulator.ToString());

                TeleportFinishPacket finish = (TeleportFinishPacket)packet;
                Simulator previousSim = Client.Network.CurrentSim;

                // Connect to the new sim
            String seedcaps = Encoding.UTF8.GetString(finish.Info.SeedCapability).Replace("\x00","");
                Simulator sim = Client.Network.Connect(new IPAddress((long)finish.Info.SimIP), finish.Info.SimPort,
                    simulator.CircuitCode, true, seedcaps);

                if (sim != null)
                {
                    teleportMessage = "Teleport finished";
                    TeleportStat = TeleportStatus.Finished;

                    // Move the avatar in to the new sim
                    CompleteAgentMovementPacket move = new CompleteAgentMovementPacket();
                    move.AgentData.AgentID = Client.Network.AgentID;
                    move.AgentData.SessionID = Client.Network.SessionID;
                    move.AgentData.CircuitCode = simulator.CircuitCode;
                    Client.Network.SendPacket(move, sim);

                    // Disconnect from the previous sim
                    Client.Network.DisconnectSim(previousSim);

                    Client.Log("Moved to new sim " + sim.ToString(), Helpers.LogLevel.Info);

                    if (OnBeginTeleport != null)
                    {
                        OnBeginTeleport(sim, teleportMessage, TeleportStat);
                    }
                    else
                    {
                        // Sleep a little while so we can collect parcel information
                        // NOTE: This doesn't belong in libsecondlife
                        // System.Threading.Thread.Sleep(1000);
                    }
                }
                else
                {
                    teleportMessage = "Failed to connect to the new sim after a teleport";
                    TeleportStat = TeleportStatus.Failed;

                    // FIXME: Set the previous CurrentSim to the current simulator again

                    Client.Log(teleportMessage, Helpers.LogLevel.Warning);

                    if (OnBeginTeleport != null)
                    {
                        OnBeginTeleport(Client.Network.CurrentSim, teleportMessage, TeleportStat);
                    }
                }

                OnBeginTeleport = null;
            }
        }