Exemple #1
0
        /// <summary>Process an incoming packet and raise the appropriate events</summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The EventArgs object containing the packet data</param>
        protected void OnlineNotificationHandler(object sender, PacketReceivedEventArgs e)
        {
            Packet packet = e.Packet;

            if (packet.Type == PacketType.OnlineNotification)
            {
                OnlineNotificationPacket notification = ((OnlineNotificationPacket)packet);

                foreach (OnlineNotificationPacket.AgentBlockBlock block in notification.AgentBlock)
                {
                    FriendInfo friend;
                    lock (FriendList.Dictionary)
                    {
                        if (!FriendList.ContainsKey(block.AgentID))
                        {
                            friend = new FriendInfo(block.AgentID, FriendRights.CanSeeOnline,
                                                    FriendRights.CanSeeOnline);
                            FriendList.Add(block.AgentID, friend);
                        }
                        else
                        {
                            friend = FriendList[block.AgentID];
                        }
                    }

                    bool doNotify = !friend.IsOnline;
                    friend.IsOnline = true;

                    if (m_FriendOnline != null && doNotify)
                    {
                        OnFriendOnline(new FriendInfoEventArgs(friend));
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Handle notifications sent when a friends has come online.
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="simulator"></param>
        private void OnlineNotificationHandler(Packet packet, Simulator simulator)
        {
            if (packet.Type == PacketType.OnlineNotification)
            {
                OnlineNotificationPacket notification = ((OnlineNotificationPacket)packet);

                foreach (OnlineNotificationPacket.AgentBlockBlock block in notification.AgentBlock)
                {
                    FriendInfo friend;

                    lock (FriendList)
                    {
                        if (!FriendList.ContainsKey(block.AgentID))
                        {
                            friend = new FriendInfo(block.AgentID, FriendRights.CanSeeOnline,
                                                    FriendRights.CanSeeOnline);
                            FriendList.Add(block.AgentID, friend);
                        }
                        else
                        {
                            friend = FriendList[block.AgentID];
                        }
                    }

                    bool doNotify = !friend.IsOnline;
                    friend.IsOnline = true;

                    if (OnFriendOnline != null && doNotify)
                    {
                        try { OnFriendOnline(friend); }
                        catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                    }
                }
            }
        }
Exemple #3
0
        void CompleteAgentMovementHandler(Packet packet, Agent agent)
        {
            // Add this avatar as an object in the scene
            ObjectAddOrUpdate(this, agent.Avatar, agent.Avatar.Prim.OwnerID, 0, PrimFlags.None, UpdateFlags.FullUpdate);

            // Send a response back to the client
            AgentMovementCompletePacket complete = new AgentMovementCompletePacket();
            complete.AgentData.AgentID = agent.ID;
            complete.AgentData.SessionID = agent.SessionID;
            complete.Data.LookAt = Vector3.UnitZ; // TODO: Properly implement LookAt someday
            complete.Data.Position = agent.Avatar.Prim.Position;
            complete.Data.RegionHandle = regionHandle;
            complete.Data.Timestamp = Utils.DateTimeToUnixTime(DateTime.Now);
            complete.SimData.ChannelVersion = Utils.StringToBytes("Simian");

            udp.SendPacket(agent.ID, complete, PacketCategory.Transaction);

            //HACK: Notify everyone when someone logs on to the simulator
            OnlineNotificationPacket online = new OnlineNotificationPacket();
            online.AgentBlock = new OnlineNotificationPacket.AgentBlockBlock[1];
            online.AgentBlock[0] = new OnlineNotificationPacket.AgentBlockBlock();
            online.AgentBlock[0].AgentID = agent.ID;
            udp.BroadcastPacket(online, PacketCategory.State);
        }
        void ImprovedInstantMessageHandler(Packet packet, Agent agent)
        {
            ImprovedInstantMessagePacket im     = (ImprovedInstantMessagePacket)packet;
            InstantMessageDialog         dialog = (InstantMessageDialog)im.MessageBlock.Dialog;

            if (dialog == InstantMessageDialog.FriendshipOffered || dialog == InstantMessageDialog.FriendshipAccepted || dialog == InstantMessageDialog.FriendshipDeclined)
            {
                lock (server.Agents)
                {
                    foreach (Agent recipient in server.Agents.Values)
                    {
                        if (recipient.AgentID == im.MessageBlock.ToAgentID)
                        {
                            ImprovedInstantMessagePacket sendIM = new ImprovedInstantMessagePacket();
                            sendIM.MessageBlock.RegionID       = UUID.Random(); //FIXME
                            sendIM.MessageBlock.ParentEstateID = 1;
                            sendIM.MessageBlock.FromGroup      = false;
                            sendIM.MessageBlock.FromAgentName  = Utils.StringToBytes(agent.Avatar.Name);
                            sendIM.MessageBlock.ToAgentID      = im.MessageBlock.ToAgentID;
                            sendIM.MessageBlock.Dialog         = im.MessageBlock.Dialog;
                            sendIM.MessageBlock.Offline        = (byte)InstantMessageOnline.Online;
                            sendIM.MessageBlock.ID             = agent.AgentID;
                            sendIM.MessageBlock.Message        = im.MessageBlock.Message;
                            sendIM.MessageBlock.BinaryBucket   = new byte[0];
                            sendIM.MessageBlock.Timestamp      = 0;
                            sendIM.MessageBlock.Position       = agent.Avatar.Position;

                            sendIM.AgentData.AgentID = agent.AgentID;

                            server.UDP.SendPacket(recipient.AgentID, sendIM, PacketCategory.Transaction);

                            if (dialog == InstantMessageDialog.FriendshipAccepted)
                            {
                                bool receiverOnline = server.Agents.ContainsKey(agent.AgentID);
                                bool senderOnline   = server.Agents.ContainsKey(recipient.AgentID);

                                if (receiverOnline)
                                {
                                    if (senderOnline)
                                    {
                                        OnlineNotificationPacket notify = new OnlineNotificationPacket();
                                        notify.AgentBlock            = new OnlineNotificationPacket.AgentBlockBlock[0];
                                        notify.AgentBlock[0]         = new OnlineNotificationPacket.AgentBlockBlock();
                                        notify.AgentBlock[0].AgentID = agent.AgentID;
                                        server.UDP.SendPacket(recipient.AgentID, notify, PacketCategory.State);
                                    }
                                    else
                                    {
                                        OfflineNotificationPacket notify = new OfflineNotificationPacket();
                                        notify.AgentBlock            = new OfflineNotificationPacket.AgentBlockBlock[0];
                                        notify.AgentBlock[0]         = new OfflineNotificationPacket.AgentBlockBlock();
                                        notify.AgentBlock[0].AgentID = agent.AgentID;
                                        server.UDP.SendPacket(recipient.AgentID, notify, PacketCategory.State);
                                    }
                                }

                                if (senderOnline)
                                {
                                    if (receiverOnline)
                                    {
                                        OnlineNotificationPacket notify = new OnlineNotificationPacket();
                                        notify.AgentBlock            = new OnlineNotificationPacket.AgentBlockBlock[0];
                                        notify.AgentBlock[0]         = new OnlineNotificationPacket.AgentBlockBlock();
                                        notify.AgentBlock[0].AgentID = recipient.AgentID;
                                        server.UDP.SendPacket(agent.AgentID, notify, PacketCategory.State);
                                    }
                                    else
                                    {
                                        OfflineNotificationPacket notify = new OfflineNotificationPacket();
                                        notify.AgentBlock            = new OfflineNotificationPacket.AgentBlockBlock[0];
                                        notify.AgentBlock[0]         = new OfflineNotificationPacket.AgentBlockBlock();
                                        notify.AgentBlock[0].AgentID = recipient.AgentID;
                                        server.UDP.SendPacket(agent.AgentID, notify, PacketCategory.State);
                                    }
                                }
                            }

                            break;
                        }
                    }
                }
            }
        }
Exemple #5
0
        void CompleteAgentMovementHandler(Packet packet, Agent agent)
        {
            CompleteAgentMovementPacket request = (CompleteAgentMovementPacket)packet;

            // Create a representation for this agent
            Avatar avatar = new Avatar();

            avatar.ID                = agent.AgentID;
            avatar.LocalID           = (uint)Interlocked.Increment(ref currentLocalID);
            avatar.Position          = new Vector3(128f, 128f, 25f);
            avatar.Rotation          = Quaternion.Identity;
            avatar.Scale             = new Vector3(0.45f, 0.6f, 1.9f);
            avatar.PrimData.Material = Material.Flesh;
            avatar.PrimData.PCode    = PCode.Avatar;

            // Create a default outfit for the avatar
            Primitive.TextureEntry te = new Primitive.TextureEntry(new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97"));
            avatar.Textures = te;

            // Set the avatar name
            NameValue[] name = new NameValue[2];
            name[0] = new NameValue("FirstName", NameValue.ValueType.String, NameValue.ClassType.ReadWrite,
                                    NameValue.SendtoType.SimViewer, agent.FirstName);
            name[1] = new NameValue("LastName", NameValue.ValueType.String, NameValue.ClassType.ReadWrite,
                                    NameValue.SendtoType.SimViewer, agent.LastName);
            avatar.NameValues = name;

            // Link this avatar up with the corresponding agent
            agent.Avatar = avatar;

            // Give testers a provisionary balance of 1000L
            agent.Balance = 1000;

            // Add this avatar as an object in the scene
            if (ObjectAdd(this, agent, new SimulationObject(agent.Avatar, server), PrimFlags.None))
            {
                // Send a response back to the client
                AgentMovementCompletePacket complete = new AgentMovementCompletePacket();
                complete.AgentData.AgentID      = agent.AgentID;
                complete.AgentData.SessionID    = agent.SessionID;
                complete.Data.LookAt            = Vector3.UnitX;
                complete.Data.Position          = avatar.Position;
                complete.Data.RegionHandle      = server.RegionHandle;
                complete.Data.Timestamp         = Utils.DateTimeToUnixTime(DateTime.Now);
                complete.SimData.ChannelVersion = Utils.StringToBytes("Simian");

                server.UDP.SendPacket(agent.AgentID, complete, PacketCategory.Transaction);

                // Send updates and appearances for every avatar to this new avatar
                SynchronizeStateTo(agent);

                //HACK: Notify everyone when someone logs on to the simulator
                OnlineNotificationPacket online = new OnlineNotificationPacket();
                online.AgentBlock            = new OnlineNotificationPacket.AgentBlockBlock[1];
                online.AgentBlock[0]         = new OnlineNotificationPacket.AgentBlockBlock();
                online.AgentBlock[0].AgentID = agent.AgentID;
                server.UDP.BroadcastPacket(online, PacketCategory.State);
            }
            else
            {
                Logger.Log("Received a CompleteAgentMovement from an avatar already in the scene, " +
                           agent.FullName, Helpers.LogLevel.Warning);
            }
        }