cs590vc – tutorial 6 client-side connection through external application

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

Upload: gwendoline-garrett

Post on 04-Jan-2016

235 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CS590VC – Tutorial 6 Client-side connection through external application

CS590VC – Tutorial 6

Client-side connection through external application

Page 2: 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

Page 3: CS590VC – Tutorial 6 Client-side connection through external application

Brief Technicalities

• libsecondlife runs in a .Net virtual machine.

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

• We will be using Windows platform.

Page 4: CS590VC – Tutorial 6 Client-side connection through external application

How to use libsecondlife in Visual Studio

Page 5: CS590VC – Tutorial 6 Client-side connection through external application

Step 1: Create new project

Page 6: CS590VC – Tutorial 6 Client-side connection through external application

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

Page 7: CS590VC – Tutorial 6 Client-side connection through external application

You write the code now

Page 8: CS590VC – Tutorial 6 Client-side connection through external application

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";

Page 9: CS590VC – Tutorial 6 Client-side connection through external application

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();• }• }

• }

Page 10: CS590VC – Tutorial 6 Client-side connection through external application

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();• }• }• }

Page 11: CS590VC – Tutorial 6 Client-side connection through external application

Step 4: Click “Solution Explorer” Solution explorer

Right click on “References” -> Add References

Page 12: CS590VC – Tutorial 6 Client-side connection through external application

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

Select “OpenMetaverse.dll.dll”

Page 13: CS590VC – Tutorial 6 Client-side connection through external application

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

Select “OpenMetaverseTypes.dll”

Page 14: CS590VC – Tutorial 6 Client-side connection through external application

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

Select “OpenMetaverse.StructuredData.dll

Page 15: CS590VC – Tutorial 6 Client-side connection through external application

Step 6: Compilation

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

Page 16: CS590VC – Tutorial 6 Client-side connection through external application

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.]

Page 17: CS590VC – Tutorial 6 Client-side connection through external application

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.

Page 18: CS590VC – Tutorial 6 Client-side connection through external application

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

Page 19: CS590VC – Tutorial 6 Client-side connection through external application

References

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

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

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