CS590VC – Tutorial 6 Client-side connection through external application.

Post on 04-Jan-2016

217 views 1 download

transcript

CS590VC – Tutorial 6

Client-side connection through external application

LibSecondLife Project• An effort directed at understanding how Second

Life works from a technical perspective.• Extending and integrating with the rest of the

web.• Understanding how the official Second Life client

operates• Understanding how it communicates with the

Second Life simulator servers• Development of independent third party clients

and tools

Brief Technicalities

• libsecondlife runs in a .Net virtual machine.

• libsecondlife is written in C# using Microsoft .NET.

• We will be using Windows platform.

How to use libsecondlife in Visual Studio

Step 1: Create new project

Step 2: Select “Console Application” under Visual C# -> Windows

You write the code now

Step 3: Copy the given code in the editor

• using System;• using System.Collections.Generic;• using System.Linq;• using System.Text;

• using OpenMetaverse;

• namespace ConsoleApplication3• {• class Program• {• public static GridClient Client = new GridClient();

• private static string first_name = "First";• private static string last_name = "Last";• private static string password = "password";

Code contd..• static void Main(string[] args)• {• Client.Network.LoginProgress += new

EventHandler<LoginProgressEventArgs>(Network_LoginProgress);• if (Client.Network.Login(first_name, last_name, password, "My First Bot", "Your name"))• {• Console.WriteLine("I logged into Second Life!");• }• else• {• Console.WriteLine("I couldn't log in, here is why: " + Client.Network.LoginMessage);• Console.WriteLine("press enter to close...");• Console.ReadLine();• }• }

• }

Code contd..• static void Network_LoginProgress(object sender, LoginProgressEventArgs e)• {• if (e.Status == LoginStatus.Success)• {• Console.WriteLine("I'm connected to the simulator, going to greet everyone around

me");• Client.Self.Chat("Hello World!", 0, ChatType.Normal);• Console.WriteLine("Now I am going to logout of SL.. Goodbye!");• Client.Network.Logout();• Console.WriteLine("I am Loged out please press enter to close...");• Console.ReadLine();• }• }• }

Step 4: Click “Solution Explorer” Solution explorer

Right click on “References” -> Add References

Step 5: Select “Browse” -> select “bin” of the “libsecondlife-0_4_1_1-binary” folder

Select “OpenMetaverse.dll.dll”

Select “Browse” -> select “bin” of the “libsecondlife-0_4_1_1-binary” folder

Select “OpenMetaverseTypes.dll”

Select “Browse” -> select “bin” of the “libsecondlife-0_4_1_1-binary” folder

Select “OpenMetaverse.StructuredData.dll

Step 6: Compilation

“OpenMetaverseTypes.dll”OpenMetaverseTypes.dllOpenMetaverse.StructuredData.dll addedBuild successful

Code Explanation 1:

• using OpenMetaverse;

This tells the compiler to include the contents of the OpenMetaverse library when compiling this file, put this at the top of all files using any of the libsecondlife classes.

• public static GridClient Client = new GridClient();

This line is probably the most important line in any libsecondlife application. It contains all of the functions that are required for your bot to communicate with the Second Life grid.

[Usually this variable is named "client," but you can call it whatever you want.]

Code Explanation 2:• Client.Network.LoginProgress += new

EventHandler<LoginProgressEventArgs>(Network_LoginProgress);

The LoginProgressis an Event (found under the Network class in your SecondLife variable). Basically, whenever your bot connects to a simulator (server side) and marks its presence there, it will fire the Network_LoginProgress method (Event Handler).

[This event handler has to be coded according to your application. Defines what the bot should do when it logs in]

• if (client.Network.Login(first_name, last_name, password, "My First Bot", "Your name"))

The bot logs in with the login information.

How to run the bot

Go to the Debug menu at the top of Visual Studio and click "Start Debugging"

If everything went according to plan, you should see a windows console pop up

References

• http://www.libsecondlife.org/wiki/

• http://www.libsecondlife.org/builds/ - for installation

[build ver.: libsecondlife-0_4_1_1-binary.zip]