170 likes | 297 Views
Libsecondlife: Bots. Hyungwook Park. LSL vs. libsecondlife. Linden Script Language (LSL) P rogramming language used by residents of Second Life Controls the behavior of in-world objects and allows objects to interact with the Second Life world
E N D
Libsecondlife: Bots Hyungwook Park
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 commandsthat will modify the state • Written in general purpose programming language (C#)
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
Communication Network Second Life Libsecondlife Function Second Life Server Second Life Server Function Visualization Visualization Client Daemon Client Client-server model Centralized network topology
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)
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
LibSecondLife • 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
LibSecondLife (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 LSLwill be one of possible solutions • Demos • http://www.youtube.com/watch?v=3TFGFtRizn0 • http://www.youtube.com/watch?v=VaUNX00Uqc0
LibSL: Getting Started (1) * 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. • 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
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.
How to create a basic libSL bot • http://www.libsecondlife.org/wiki/Use_libSL_to_login_to_the_SL_grid
LibSL: 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 libraries Define SecondLife client(s) Add your bot’s name Define a connected event Try to log in to the Grid When connected, send a message After your message, logout
LibSL: 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"))
LibSL: 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
LibSL: 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_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)
LibSL: Movement http://www.libsecondlife.org/docs/ • 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);
Second China Demo • Questions?