mihai-rotaru

MyFirstBot.cs

Apr 5th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Timers;
  6. using OpenMetaverse;
  7.  
  8. namespace MyFirstBot
  9. {
  10.     class MyFirstBot
  11.     {
  12.         static Timer _timer;
  13.         static int fiveseconds = 0;
  14.         public static GridClient Client = new GridClient();
  15.  
  16.         private static string first_name = "KellbossBot";
  17.         private static string last_name = "Resident";
  18.         private static string password = "**obscured**";
  19.  
  20.         static void Main(string[] args)
  21.         {
  22.             _timer = new Timer(5000);
  23.             _timer.Elapsed += new ElapsedEventHandler(_timer_elapsed);
  24.             _timer.Enabled = true;
  25.  
  26.             string startLocation = NetworkManager.StartLocation("Nogojiri", 178, 42, 54);
  27.             Client.Network.LoginProgress += new EventHandler<LoginProgressEventArgs>(Network_LoginProgress);
  28.             if (Client.Network.Login(first_name, last_name, password, "My First Bot", startLocation, "Your name"))
  29.             {
  30.                 Console.WriteLine("I logged into Second Life!");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("I couldn't log in, here is why: " + Client.Network.LoginMessage);
  35.                 Console.WriteLine("press enter to close...");
  36.                 Console.ReadLine();
  37.             }
  38.         }
  39.  
  40.         static void Network_LoginProgress(object sender, LoginProgressEventArgs e)
  41.         {
  42.             if (e.Status == LoginStatus.Success)
  43.             {
  44.                 Console.WriteLine("I'm connected to the simulator, going to greet everyone around me");
  45.                 Client.Self.Chat("Hello World!", 0, ChatType.Normal);
  46.             }
  47.         }
  48.  
  49.         static void _timer_elapsed(Object sender, ElapsedEventArgs e)
  50.         {
  51.             fiveseconds++;
  52.             if (fiveseconds == 20)
  53.             {
  54.                 Console.WriteLine("Now I am going to logout of SL.. Goodbye!");
  55.                 Client.Self.Chat("I'm logging out now!", 0, ChatType.Normal);
  56.                 Client.Network.Logout();
  57.                 Console.WriteLine("I am Loged out please press enter to close...");
  58.                 Console.ReadLine();
  59.             }
  60.             Console.WriteLine("Timer event fired; saying hello...");
  61.             Client.Self.Chat("Hello World! I'm a robot", 0, ChatType.Normal);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment