Exemple #1
0
        static void Main(string[] args)
        {
            SecondLife client = new SecondLife();

            if (args.Length < 4)
            {
                Console.WriteLine("Usage: Key2Name [loginfirstname] [loginlastname] [password] [key]");
                return;
            }
            Console.WriteLine("Attempting to connect and login to Second Life.");

            // Setup Login to Second Life
            Dictionary <string, object> loginParams = client.Network.DefaultLoginValues(args[0],
                                                                                        args[1], args[2], "00:00:00:00:00:00", "last", "Win", "0", "key2name",
                                                                                        "*****@*****.**");
            Dictionary <string, object> loginReply = new Dictionary <string, object>();

            if (!client.Network.Login(loginParams))
            {
                // Login failed
                Console.WriteLine("Error logging in: " + client.Network.LoginError);
                return;
            }
            AvatarTracker avatarTracker = new AvatarTracker(client);
            LLUUID        lookup        = new LLUUID(args[3]);

            Console.WriteLine("Looking up name for " + lookup.ToStringHyphenated());
            string name = avatarTracker.GetAvatarName(lookup);

            Console.WriteLine("Name: " + name + ". Press enter to logout.");
            Console.ReadLine();
            client.Network.Logout();
        }
Exemple #2
0
        public void NameLookup()
        {
            AvatarTracker tracker = new AvatarTracker(Client);

            string name = tracker.GetAvatarName(LookupKey1);

            Assert.IsTrue(name == LookupName1, "AvatarTracker.GetAvatarName() returned " + name +
                          " instead of " + LookupName1);
        }
Exemple #3
0
        private void RegisterCallbacks(User user)
        {
            SecondLife    client  = user.Client;
            Events        events  = user.Events;
            AvatarTracker avatars = user.Avatars;

            // SecondLife Event callbacks.
            // These are assigned to the aforementioned Event object.
            client.Self.OnScriptQuestion            += new AgentManager.ScriptQuestionCallback(events.Self_OnScriptQuestion);
            client.Self.OnScriptDialog              += new AgentManager.ScriptDialogCallback(events.Self_OnScriptDialog);
            client.Self.OnInstantMessage            += new AgentManager.InstantMessageCallback(events.Self_OnInstantMessage);
            client.Self.OnChat                      += new AgentManager.ChatCallback(events.Self_OnChat);
            client.Self.OnTeleport                  += new AgentManager.TeleportCallback(events.Self_OnTeleport);
            client.Self.OnBalanceUpdated            += new AgentManager.BalanceCallback(events.Self_OnBalanceUpdated);
            client.Self.OnMoneyBalanceReplyReceived += new AgentManager.MoneyBalanceReplyCallback(events.Self_OnMoneyBalanceReplyReceived);
            client.Self.OnGroupChatJoin             += new AgentManager.GroupChatJoined(events.Self_OnGroupChatJoin);
            client.Friends.OnFriendOnline           += new FriendsManager.FriendOnlineEvent(events.Friends_OnOnOffline);
            client.Friends.OnFriendOffline          += new FriendsManager.FriendOfflineEvent(events.Friends_OnOnOffline);
            client.Friends.OnFriendRights           += new FriendsManager.FriendRightsEvent(events.Friends_OnFriendRights);
            client.Friends.OnFriendshipOffered      += new FriendsManager.FriendshipOfferedEvent(events.Friends_OnFriendshipOffered);
            client.Friends.OnFriendFound            += new FriendsManager.FriendFoundEvent(events.Friends_OnFriendFound);
            client.Avatars.OnAvatarNames            += new AvatarManager.AvatarNamesCallback(events.Avatars_OnAvatarNames);
            client.Avatars.OnAvatarGroups           += new AvatarManager.AvatarGroupsCallback(events.Avatars_OnAvatarGroups);
            client.Avatars.OnAvatarInterests        += new AvatarManager.AvatarInterestsCallback(events.Avatars_OnAvatarInterests);
            client.Directory.OnDirPeopleReply       += new DirectoryManager.DirPeopleReplyCallback(events.Directory_OnDirPeopleReply);
            client.Directory.OnDirGroupsReply       += new DirectoryManager.DirGroupsReplyCallback(events.Directory_OnDirGroupsReply);
            client.Network.OnDisconnected           += new NetworkManager.DisconnectedCallback(events.Network_OnDisconnected);
            // We shouldn't really be using this... it forces us to immediately accept inventory.
            client.Inventory.OnObjectOffered    += new InventoryManager.ObjectOfferedCallback(events.Inventory_OnObjectOffered);
            client.Inventory.OnFolderUpdated    += new InventoryManager.FolderUpdatedCallback(events.Inventory_OnFolderUpdated);
            client.Inventory.OnItemReceived     += new InventoryManager.ItemReceivedCallback(events.Inventory_OnItemReceived);
            client.Inventory.OnTaskItemReceived += new InventoryManager.TaskItemReceivedCallback(events.Inventory_OnTaskItemReceived);
            client.Assets.OnImageReceived       += new AssetManager.ImageReceivedCallback(events.Assets_OnImageReceived);
            client.Assets.OnAssetReceived       += new AssetManager.AssetReceivedCallback(events.Assets_OnAssetReceived);
            client.Terrain.OnLandPatch          += new TerrainManager.LandPatchCallback(events.Terrain_OnLandPatch);
            client.Groups.OnGroupProfile        += new GroupManager.GroupProfileCallback(events.Groups_OnGroupProfile);
            client.Groups.OnGroupMembers        += new GroupManager.GroupMembersCallback(events.Groups_OnGroupMembers);
            client.Groups.OnGroupNames          += new GroupManager.GroupNamesCallback(events.Groups_OnGroupNames);
            client.Groups.OnCurrentGroups       += new GroupManager.CurrentGroupsCallback(events.Groups_OnCurrentGroups);
            client.Parcels.OnParcelProperties   += new libsecondlife.ParcelManager.ParcelPropertiesCallback(events.Parcels_OnParcelProperties);

            // AvatarTracker event callbacks.
            avatars.OnAvatarAdded   += new AvatarTracker.Added(events.AvatarTracker_OnAvatarAdded);
            avatars.OnAvatarRemoved += new AvatarTracker.Removed(events.AvatarTracker_OnAvatarRemoved);
            avatars.OnAvatarUpdated += new AvatarTracker.Updated(events.AvatarTracker_OnAvatarUpdated);

            client.Assets.OnAssetUploaded += new AssetManager.AssetUploadedCallback(events.Assets_OnAssetUploaded);

            // Packet callbacks
            // We register these because there's no LibSL function for doing it easily.
            client.Network.RegisterCallback(PacketType.AvatarPropertiesReply, new NetworkManager.PacketCallback(events.Avatars_OnAvatarProperties));
            // Manual map handler.
            client.Network.RegisterCallback(PacketType.MapBlockReply, new NetworkManager.PacketCallback(events.Packet_MapBlockReply));
            client.Network.RegisterCallback(PacketType.MapItemReply, new NetworkManager.PacketCallback(events.Packet_MapItemReply));
        }
Exemple #4
0
        private void RegisterCallbacks(User user)
        {
            GridClient    client  = user.Client;
            Events        events  = user.Events;
            AvatarTracker avatars = user.Avatars;

            // GridClient Event callbacks.
            // These are assigned to the aforementioned Event object.
            client.Self.ScriptQuestion          += new EventHandler <ScriptQuestionEventArgs>(events.Self_ScriptQuestion);
            client.Self.ScriptDialog            += new EventHandler <ScriptDialogEventArgs>(events.Self_ScriptDialog);
            client.Self.IM                      += new EventHandler <InstantMessageEventArgs>(events.Self_IM);
            client.Self.ChatFromSimulator       += new EventHandler <ChatEventArgs>(events.Self_ChatFromSimulator);
            client.Self.TeleportProgress        += new EventHandler <TeleportEventArgs>(events.Self_TeleportProgress);
            client.Self.MoneyBalance            += new EventHandler <BalanceEventArgs>(events.Self_MoneyBalance);
            client.Self.MoneyBalanceReply       += new EventHandler <MoneyBalanceReplyEventArgs>(events.Self_MoneyBalanceReply);
            client.Self.GroupChatJoined         += new EventHandler <GroupChatJoinedEventArgs>(events.Self_GroupChatJoined);
            client.Friends.FriendOnline         += new EventHandler <FriendInfoEventArgs>(events.Friends_FriendOnOffline);
            client.Friends.FriendOffline        += new EventHandler <FriendInfoEventArgs>(events.Friends_FriendOnOffline);
            client.Friends.FriendRightsUpdate   += new EventHandler <FriendInfoEventArgs>(events.Friends_FriendRightsUpdate);
            client.Friends.FriendshipOffered    += new EventHandler <FriendshipOfferedEventArgs>(events.Friends_FriendshipOffered);
            client.Friends.FriendFoundReply     += new EventHandler <FriendFoundReplyEventArgs>(events.Friends_FriendFoundReply);
            client.Avatars.UUIDNameReply        += new EventHandler <UUIDNameReplyEventArgs>(events.Avatars_UUIDNameReply);
            client.Avatars.AvatarGroupsReply    += new EventHandler <AvatarGroupsReplyEventArgs>(events.Avatars_AvatarGroupsReply);
            client.Avatars.AvatarInterestsReply += new EventHandler <AvatarInterestsReplyEventArgs>(events.Avatars_AvatarInterestsReply);
            client.Directory.DirPeopleReply     += new EventHandler <DirPeopleReplyEventArgs>(events.Directory_DirPeopleReply);
            client.Directory.DirGroupsReply     += new EventHandler <DirGroupsReplyEventArgs>(events.Directory_DirGroupsReply);
            client.Network.Disconnected         += new EventHandler <DisconnectedEventArgs>(events.Network_Disconnected);

            // We shouldn't really be using this... it forces us to immediately accept inventory.
            client.Inventory.InventoryObjectOffered += new EventHandler <InventoryObjectOfferedEventArgs>(events.Inventory_InventoryObjectOffered);
            client.Inventory.FolderUpdated          += new EventHandler <FolderUpdatedEventArgs>(events.Inventory_FolderUpdated);
            client.Inventory.ItemReceived           += new EventHandler <ItemReceivedEventArgs>(events.Inventory_ItemReceived);
            client.Inventory.TaskItemReceived       += new EventHandler <TaskItemReceivedEventArgs>(events.Inventory_TaskItemReceived);
            client.Terrain.LandPatchReceived        += new EventHandler <LandPatchReceivedEventArgs>(events.Terrain_LandPatchReceived);
            client.Groups.GroupProfile      += new EventHandler <GroupProfileEventArgs>(events.Groups_GroupProfile);
            client.Groups.GroupMembersReply += new EventHandler <GroupMembersReplyEventArgs>(events.Groups_GroupMembersReply);
            client.Groups.GroupNamesReply   += new EventHandler <GroupNamesEventArgs>(events.Groups_GroupNamesReply);
            client.Groups.CurrentGroups     += new EventHandler <CurrentGroupsEventArgs>(events.Groups_CurrentGroups);
            client.Parcels.ParcelProperties += new EventHandler <ParcelPropertiesEventArgs>(events.Parcels_ParcelProperties);

            // AvatarTracker event callbacks.
            avatars.OnAvatarAdded   += new AvatarTracker.Added(events.AvatarTracker_OnAvatarAdded);
            avatars.OnAvatarRemoved += new AvatarTracker.Removed(events.AvatarTracker_OnAvatarRemoved);
            avatars.OnAvatarUpdated += new AvatarTracker.Updated(events.AvatarTracker_OnAvatarUpdated);

            // Packet callbacks
            // We register these because there's no LibSL function for doing it easily.
            client.Network.RegisterCallback(PacketType.AvatarPropertiesReply, new EventHandler <PacketReceivedEventArgs>(events.Avatars_AvatarProperties));

            // Manual map handler.
            client.Network.RegisterCallback(PacketType.MapBlockReply, new EventHandler <PacketReceivedEventArgs>(events.Packet_MapBlockReply));
            client.Network.RegisterCallback(PacketType.MapItemReply, new EventHandler <PacketReceivedEventArgs>(events.Packet_MapItemReply));
        }
Exemple #5
0
        // Someone wants connect.kat.
        public void OnFileRequested(HttpRequest request, IDirectory directory)
        {
            request.Response.ResponseContent = new MemoryStream();
            StreamWriter textWriter = new StreamWriter(request.Response.ResponseContent);
            try
            {
                // Grab various bits of data from the User object.
                // If we can't do that, complain.
                // While we're at it, decode the post data.
                User user;
                SecondLife client;
                StreamReader reader = new StreamReader(request.PostData);
                string qstring = reader.ReadToEnd();
                reader.Dispose();
                Dictionary<string, string> POST = AjaxLife.PostDecode(qstring);
                Guid key = new Guid(POST["session"]);
                // The session doesn't exist. Get upset.
                if (!this.users.ContainsKey(key))
                {
                    this.invalidSessionID(key, textWriter);
                    return;
                }
                lock (this.users)
                {
                    user = users[key];
                }
                user.LastRequest = DateTime.Now;
                client = user.GetClient();

                string first = "";
                string last = "";
                string pass = "";
                // Decrypt the incoming login data
                string decrypted = StringHelper.ASCIIBytesToString(AjaxLife.RSA.Decrypt(StringHelper.HexStringToBytes(POST["logindata"])));
                // Split it into its component parts.
                string[] data = decrypted.Split('\\');
                // Get upset if the challenge was incorrect.
                if (data[0] == null || data[0] != user.Challenge)
                {
                    throw new Exception("Invalid request.");
                }
                // Decode the login data.
                first = StringHelper.ASCIIBytesToString(StringHelper.FromBase64(data[1]));
                last = StringHelper.ASCIIBytesToString(StringHelper.FromBase64(data[2]));
                pass = data[3];
                user.Signature = data[4];
                // Check if they're banned first.
                if (AjaxLife.BannedUsers.IsBanned(first, last))
                {
                    textWriter.WriteLine("{success: false, message: \"You have been banned from AjaxLife by the administrator.\"}");
                    textWriter.Flush();
                    return;
                }
                LoginParams login = client.Network.DefaultLoginParams(first, last, pass, "AjaxLife", "Katharine Berry <*****@*****.**>");
                login.Platform = "web";
                login.Channel = "AjaxLife";
                login.MAC = AjaxLife.MAC_ADDRESS;
                login.id0 = AjaxLife.ID0;
                login.Start = (POST["location"] != "arbitrary") ? POST["location"] : NetworkManager.StartLocation(POST["sim"], 128, 128, 20);
                // Pick the correct loginuri.
                lock (AjaxLife.LOGIN_SERVERS) login.URI = AjaxLife.LOGIN_SERVERS[POST["grid"]];
                client.Settings.LOGIN_SERVER = login.URI;
                user.LindenGrid = POST["grid"].EndsWith("(Linden Lab)");
                Console.WriteLine(login.FirstName + " " + login.LastName + " is attempting to log into " + POST["grid"] + " (" + login.URI + ")");
                if (client.Network.Login(login))
                {
                    // Ensure that the challenge isn't matched by another request with the same SID.
                    // We don't do this until after successful login because otherwise a second attempt will always fail.
                    user.Challenge = null;
                    AvatarTracker avatars = new AvatarTracker(client);
                    Events events = new Events(user);
                    user.Events = events;
                    user.Avatars = avatars;
                    // Register event handlers
                    this.RegisterCallbacks(user);
                    // De-ruth.
                    client.Appearance.SetPreviousAppearance(false);
                    // Pythagoras says that 181.0193m is the optimal view distance to see the whole sim.
                    client.Self.Movement.Camera.Far = 181.0193f;

                    // This doesn't seem to work.
                    // client.Self.Movement.Camera.SetPositionOrientation(new LLVector3(128, 128, 0), 0, 0, 0);

                    // Everything's happy. Log the requested message list, if any.
                    if(POST.ContainsKey("events"))
                    {
                        user.ParseRequestedEvents(POST["events"]);
                    }

                    // If we got this far, it worked. Announce this.
                    textWriter.WriteLine("{\"success\": 1}");
                }
                else
                {
                    // Return whatever errors may have transpired.
                    textWriter.WriteLine("{success: false, message: " + AjaxLife.StringToJSON(client.Network.LoginMessage) + "}");
                }
            }
            catch (Exception exception)
            {
                request.Response.ContentType = "text/plain";
                textWriter.WriteLine(exception.Message);
            }
            textWriter.Flush();
        }
Exemple #6
0
        // Someone wants connect.kat.
        public void OnFileRequested(HttpRequest request, IDirectory directory)
        {
            request.Response.ResponseContent = new MemoryStream();
            StreamWriter textWriter = new StreamWriter(request.Response.ResponseContent);

            try
            {
                // Grab various bits of data from the User object.
                // If we can't do that, complain.
                // While we're at it, decode the post data.
                User         user;
                SecondLife   client;
                StreamReader reader  = new StreamReader(request.PostData);
                string       qstring = reader.ReadToEnd();
                reader.Dispose();
                Dictionary <string, string> POST = AjaxLife.PostDecode(qstring);
                Guid key = new Guid(POST["session"]);
                // The session doesn't exist. Get upset.
                if (!this.users.ContainsKey(key))
                {
                    this.invalidSessionID(key, textWriter);
                    return;
                }
                lock (this.users)
                {
                    user = users[key];
                }
                user.LastRequest = DateTime.Now;
                client           = user.GetClient();

                string first = "";
                string last  = "";
                string pass  = "";
                // Decrypt the incoming login data
                string decrypted = StringHelper.ASCIIBytesToString(AjaxLife.RSA.Decrypt(StringHelper.HexStringToBytes(POST["logindata"])));
                // Split it into its component parts.
                string[] data = decrypted.Split('\\');
                // Get upset if the challenge was incorrect.
                if (data[0] == null || data[0] != user.Challenge)
                {
                    throw new Exception("Invalid request.");
                }
                // Decode the login data.
                first          = StringHelper.ASCIIBytesToString(StringHelper.FromBase64(data[1]));
                last           = StringHelper.ASCIIBytesToString(StringHelper.FromBase64(data[2]));
                pass           = data[3];
                user.Signature = data[4];
                // Check if they're banned first.
                if (AjaxLife.BannedUsers.IsBanned(first, last))
                {
                    textWriter.WriteLine("{success: false, message: \"You have been banned from AjaxLife by the administrator.\"}");
                    textWriter.Flush();
                    return;
                }
                LoginParams login = client.Network.DefaultLoginParams(first, last, pass, "AjaxLife", "Katharine Berry <*****@*****.**>");
                login.Platform = "web";
                login.Channel  = "AjaxLife";
                login.MAC      = AjaxLife.MAC_ADDRESS;
                login.id0      = AjaxLife.ID0;
                login.Start    = (POST["location"] != "arbitrary") ? POST["location"] : NetworkManager.StartLocation(POST["sim"], 128, 128, 20);
                // Pick the correct loginuri.
                lock (AjaxLife.LOGIN_SERVERS) login.URI = AjaxLife.LOGIN_SERVERS[POST["grid"]];
                client.Settings.LOGIN_SERVER = login.URI;
                user.LindenGrid = POST["grid"].EndsWith("(Linden Lab)");
                Console.WriteLine(login.FirstName + " " + login.LastName + " is attempting to log into " + POST["grid"] + " (" + login.URI + ")");
                if (client.Network.Login(login))
                {
                    // Ensure that the challenge isn't matched by another request with the same SID.
                    // We don't do this until after successful login because otherwise a second attempt will always fail.
                    user.Challenge = null;
                    AvatarTracker avatars = new AvatarTracker(client);
                    Events        events  = new Events(user);
                    user.Events  = events;
                    user.Avatars = avatars;
                    // Register event handlers
                    this.RegisterCallbacks(user);
                    // De-ruth.
                    client.Appearance.SetPreviousAppearance(false);
                    // Pythagoras says that 181.0193m is the optimal view distance to see the whole sim.
                    client.Self.Movement.Camera.Far = 181.0193f;

                    // This doesn't seem to work.
                    // client.Self.Movement.Camera.SetPositionOrientation(new LLVector3(128, 128, 0), 0, 0, 0);

                    // Everything's happy. Log the requested message list, if any.
                    if (POST.ContainsKey("events"))
                    {
                        user.ParseRequestedEvents(POST["events"]);
                    }

                    // If we got this far, it worked. Announce this.
                    textWriter.WriteLine("{\"success\": 1}");
                }
                else
                {
                    // Return whatever errors may have transpired.
                    textWriter.WriteLine("{success: false, message: " + AjaxLife.StringToJSON(client.Network.LoginMessage) + "}");
                }
            }
            catch (Exception exception)
            {
                request.Response.ContentType = "text/plain";
                textWriter.WriteLine(exception.Message);
            }
            textWriter.Flush();
        }