17
Libsecondlife: Bots Hyungwook Park

Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL) Programming language used by residents of Second Life Controls

Embed Size (px)

Citation preview

Page 1: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

Libsecondlife: Bots

Hyungwook Park

Page 2: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LSL vs. libsecondlife

Linden Script Language (LSL) Programming language used by residents of Second Life

Controls the behavior of in-world objects and allows objects to interact with

the Second Life world

State-event driven scripting language, in the sense of a finite state machine

Libsecondlife (LibSL) A software library to communicate with the servers that control the virtual

world of Second Life Function by manipulating avatars

Reverse engineering of SL network protocol

Used both to query the state of the world and to send uploads and commands

that will modify the state

Written in general purpose programming language (C#)

Page 3: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

Bots in Second Life

What is the difference between Avatar and Bot?http://www.youtube.com/watch?v=bcemyUuzCds&eurl=

Two types of bot LSL based (prims)

Come in many shapes and sizes

Primarily server side code

LibSL based (avatars)

Function by manipulating avatars

Mixed computation from client and server

Network delay becomes an issue

Page 4: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

Communication Network

Second LifeServer

Client

Second LifeServer

ClientDaemon

Centralized network topology Client-server model

Second Life Libsecondlife

Function

FunctionVisualization

Visualization

Page 5: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LSL Bot

Prims with (motion) control Control is defined through LSL Integrated sensing (LSL sensors) Can interface with remote resources

http://www.youtube.com/watch?v=824TFPerXsQ

Tour Guide (Aesthetica)

Page 6: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LSL Bots: LSL Limitations

Language limitations Emphasis on states and events No native arrays, only sequential list can be used Limited length for script (16KB)

make it difficult to develop large, complex applications

Control limitations Embedded in a prim, not in avatars Cannot log into the world more than one avatar Avatar cannot have the script, thus the prim has to be attached into the

avatar

Page 7: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSecondLifeLibSecondLife

Potential for complete avatar simulation Reverse engineering of SL network protocol

Based on C# All C# features are available

Much more flexible programming environment

Avatar control

Client-server interface

Page 8: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSecondLifeLibSecondLife (continue) (continue)

Disadvantages

Network traffic is subject to missed packets and limited by client

performance

Not robust (Beta version v0.3.2) and lack of documentation

Combination with LSL will be one of possible solutions

Demos

http://www.youtube.com/watch?v=3TFGFtRizn0

http://www.youtube.com/watch?v=VaUNX00Uqc0

Page 9: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSL: Getting Started (1)

Prerequisites (For Windows) C# compiler

Visual Studio .NET 2005 (Windows) Visual Studio Express .NET (Windows, free)

Source code via SubVersion (SVN)* svn://openmetaverse.org/libsl/trunk

For more help: http://www.libsecondlife.org/wiki/Main_Page http://www.libsecondlife.org/wiki/Getting_Started

* Subversion (SVN) is a version control system. It is used to maintain current and historical versions of files such as source code, web pages, and documentation.

Page 10: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSL: Getting Started (2)

Instructions

Create a folder named dev in C:\

In the dev folder, create a folder named libsecondlife.

Right click the libsecondlife folder, select SVN Checkout…

In the field for "URL of Repository", put

svn://opensecondlife.org/libsl/trunk

Files should start getting downloaded.

Page 11: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

How to create a basic libSL bot

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

Page 12: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSL: LibSL: Sample code (1)Sample code (1)using System; using System.Collections.Generic; using System.Text; using libsecondlife;  

namespace MyFirstBot { class MyFirstBot { public static SecondLife client = new SecondLife();   private static string first_name = "First"; private static string last_name = "Last"; private static string password = "password";  

public static void Main() { client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected); 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); }  

static void Network_OnConnected(object sender) { Console.WriteLine("I'm connected to the simulator"); client.Self.Chat("Hello World!", 0, ChatType.Normal); Console.WriteLine("Now I am going to logout of SL.. Goodbye!"); client.Network.Logout(); } }}  

Include libsecondlife librariesInclude libsecondlife libraries

Define SecondLife client(s)Define SecondLife client(s)

Add your bot’s nameAdd your bot’s name

Define a connected eventDefine a connected event

Try to log in to the GridTry to log in to the Grid

When connected, send a messageWhen connected, send a message

After your message, logoutAfter your message, logout

Page 13: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSL: LibSL: Sample code (2)Sample code (2)using System; using System.Collections.Generic; using System.Text; using libsecondlife;  

namespace MyFirstBot { class MyFirstBot { public static SecondLife client = new SecondLife();   private static string first_name = "First"; private static string last_name = "Last"; private static string password = "password";  

public static void Main() { client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected); 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); }  

static void Network_OnConnected(object sender) { Console.WriteLine("I'm connected to the simulator"); client.Self.Chat("Hello World!", 0, ChatType.Normal); Console.WriteLine("Now I am going to logout of SL.. Goodbye!"); client.Network.Logout(); } }}  

string startLocation = NetworkManager.StartLocation("Second China", 179,165,31);if (client.Network.Login(first_name, last_name, password, "My First Bot", startLocation, "Your name"))string startLocation = NetworkManager.StartLocation("Second China", 179,165,31);if (client.Network.Login(first_name, last_name, password, "My First Bot", startLocation, "Your name"))

Page 14: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSL: FrameworkLibSL: Framework

Most actions are defined within callbacks (events) Network events

OnConnected / OnDisconnected OnCurrentSimChanged

Client (Avatar) events OnInstantMessage OnChat OnTeleport

Object events OnNewAvatar / OnNewPrim OnObjectUpdated / OnObjectKilled

Page 15: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSL: LibSL: CommunicationCommunication

Send an instant message

client.Self.InstantMessage(target, "Hello, World!");

Say something

client.Self.Chat("Hey There World", 0, ChatType.Normal);

Respond to instant message client.Self.OnInstantMessage += new

AgentManager.InstantMessageCallback(Self_OnInstantMessage);  

static void Self_OnInstantMessage(InstantMessage im, Simulator sim)

Respond to chat client.Self.OnChat += new AgentManager.ChatCallback(Self_OnChat);

static void Self_OnChat(string message, ChatAudibleLevel audible, ChatType

type, ChatSourceType sourceType, string fromName, LLUUID id,

LLUUID ownerid, LLVector3 position)

Page 16: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

LibSL: LibSL: MovementMovement

Teleport client.Self.Teleport(“Second China", new LLVector3(128.0f, 128.0f, 50.0f));

client.Self.Teleport(new LLUUID("The-key-of-a-landmark"));

client.Self.OnTeleport += new AgentManager.TeleportCallback(Self_OnTeleport);  

static void Self_OnTeleport(string message, AgentManager.TeleportStatus

status, AgentManager.TeleportFlags flags)

LookAt(LLVector3 location)

Walk client.Self.AutopilotLocal(128, 128, 30);

Animation client.Self.AnimationStart(“UUID of animation”, true);

System.Threading.Thread.Sleep(5000);

client.Self.AnimationStop(“UUID of animation”, true);

http://www.libsecondlife.org/docs/

Page 17: Libsecondlife: Bots Hyungwook Park. LSL vs. libsecondlife Linden Script Language (LSL)  Programming language used by residents of Second Life  Controls

Second China Demo

Questions?