Title: Libsecondlife: Bots
1Libsecondlife Bots
2LSL 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)
3Bots in Second Life
- What is the difference between Avatar and Bot?
- http//www.youtube.com/watch?vbcemyUuzCdseurl
- 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
4Communication Network
Second Life
Libsecondlife
Function
Second Life Server
Second Life Server
Function
Visualization
Visualization
Client
Client
Daemon
Client-server model
Centralized network topology
5LSL Bot
- Prims with (motion) control
- Control is defined through LSL
- Integrated sensing (LSL sensors)
- Can interface with remote resources
- http//www.youtube.com/watch?v824TFPerXsQ
- Tour Guide (Aesthetica)
6LSL 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
7LibSecondLife
- 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
8LibSecondLife (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?v3TFGFtRizn0
- http//www.youtube.com/watch?vVaUNX00Uqc0
9LibSL 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.
10LibSL 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.
11How to create a basic libSL bot
- http//www.libsecondlife.org/wiki/Use_libSL_to_log
in_to_the_SL_grid
12LibSL 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_OnConnect
ed) 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 libraries
Define SecondLife client(s)
Add your bots name
Define a connected event
Try to log in to the Grid
When connected, send a message
After your message, logout
13LibSL 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_OnConnect
ed) 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.StartLocatio
n("Second China", 179,165,31) if
(client.Network.Login(first_name, last_name,
password, "My First Bot", startLocation, "Your
name"))
14LibSL 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
15LibSL Communication
- 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_OnInstant
Message) - static void Self_OnInstantMessage(InstantMessage
im, Simulator sim) - Respond to chat
- client.Self.OnChat new AgentManager.ChatCallbac
k(Self_OnChat) - static void Self_OnChat(string message,
ChatAudibleLevel audible, ChatType type,
ChatSourceType sourceType, string fromName,
LLUUID id, LLUUID ownerid, LLVector3 position)
16LibSL Movement
- Teleport
- client.Self.Teleport(Second China", new
LLVector3(128.0f, 128.0f, 50.0f)) - client.Self.Teleport(new LLUUID("The-key-of-a-land
mark")) - client.Self.OnTeleport new AgentManager.Telepor
tCallback(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/
17Second China Demo