//Eva Library 2010/07/08 using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Reflection; using System.Xml; using OpenMetaverse; using OpenMetaverse.Packets; using OpenMetaverse.Utilities; namespace ParcelDownload { public class LoginDetails { public string FirstName; public string LastName; public string Password; public string StartLocation; public bool GroupCommands; public string MasterName; public UUID MasterKey; public string URI; } public class StartPosition { public string sim; public int x; public int y; public int z; public StartPosition() { this.sim = null; this.x = 0; this.y = 0; this.z = 0; } } public class ParcelDownload { static bool LoginSuccess = false; static bool ParcelSuccess = false; static AutoResetEvent LoginEvent = new AutoResetEvent(false); static AutoResetEvent ParcelsDownloaded = new AutoResetEvent(false); static void Main(string[] args) { StringBuilder sb = new StringBuilder(); if (args.Length < 3){ Console.WriteLine("Usage: login firstname lastname password [simname] [login server url]"); return; } GridClient client; client = new GridClient(); client.Network.LoginProgress += LoginHandler; client.Parcels.SimParcelsDownloaded +=ParcelHandler; //Settings.LOG_LEVEL = Helpers.LogLevel.Debug; Settings.LOG_LEVEL = Helpers.LogLevel.Info; client.Settings.LOG_RESENDS = false; client.Settings.STORE_LAND_PATCHES = true; client.Settings.ALWAYS_DECODE_OBJECTS = true; client.Settings.ALWAYS_REQUEST_OBJECTS = true; client.Settings.SEND_AGENT_UPDATES = true; client.Settings.USE_ASSET_CACHE = true; client.Settings.MULTIPLE_SIMS = false; client.Settings.LOG_ALL_CAPS_ERRORS = false; client.Throttle.Wind = 0; client.Throttle.Cloud = 0; client.Throttle.Land = 1000000; client.Throttle.Task = 1000000; LoginDetails account = new LoginDetails(); account.FirstName = args[0]; account.LastName = args[1]; account.Password = args[2]; if (args.Length > 3){ // If it looks like a full starting position was specified, parse it if (args[3].StartsWith("http")){ account.URI = args[3]; }else{ if (args[3].IndexOf('/') >= 0){ char sep = '/'; string[] startbits = args[3].Split(sep); try{ account.StartLocation = NetworkManager.StartLocation(startbits[0], Int32.Parse(startbits[1]), Int32.Parse(startbits[2]), Int32.Parse(startbits[3])); } catch (FormatException){ } } // Otherwise, use the center of the named region if (account.StartLocation == null){ account.StartLocation = NetworkManager.StartLocation(args[3], 128, 128, 40); } } } if (args.Length > 4){ if (args[4].StartsWith("http")){ account.URI = args[4]; } } Logger.Log("Using login URI " + account.URI, Helpers.LogLevel.Info); LoginParams loginParams = client.Network.DefaultLoginParams(account.FirstName, account.LastName, account.Password, "TestClient", "1.0.0"); if (!String.IsNullOrEmpty(account.StartLocation)) loginParams.Start = account.StartLocation; if (!String.IsNullOrEmpty(account.URI)) loginParams.URI = account.URI; Logger.Log("Login:..." + account.FirstName + " " + account.LastName, Helpers.LogLevel.Info); client.Network.BeginLogin(loginParams); int login_timeout = 30; if (LoginEvent.WaitOne(1000 * login_timeout, false)){ if (LoginSuccess){ Logger.Log("Login success: " + client.Network.LoginMessage, Helpers.LogLevel.Info); }else{ Logger.Log("Login failed: " + client.Network.LoginMessage, Helpers.LogLevel.Error); } }else{ Logger.Log("Login timed out", Helpers.LogLevel.Error); } Logger.Log("Parcel reuest:...", Helpers.LogLevel.Info); client.Parcels.RequestAllSimParcels(client.Network.CurrentSim); client.Network.CurrentSim.IsParcelMapFull(); //System.Threading.Thread.Sleep(15000); int loop = 0; while(ParcelSuccess != true){ loop++; System.Threading.Thread.Sleep(100); if(loop > 1000){ break; } } sb.AppendFormat("Downloaded {0} Parcels in {1} " + System.Environment.NewLine, client.Network.CurrentSim.Parcels.Count, client.Network.CurrentSim.Name); client.Network.CurrentSim.Parcels.ForEach(delegate(Parcel parcel){ sb.AppendFormat("Parcel[{0}]: Name: \"{1}\", Description: \"{2}\" Traffic: {3}" + System.Environment.NewLine, parcel.LocalID, parcel.Name, parcel.Desc, parcel.Dwell); }); sb.ToString(); Logger.Log(sb , Helpers.LogLevel.Info); Logger.Log("Logout:...", Helpers.LogLevel.Info); client.Network.Logout(); return; } static void LoginHandler(object sender, LoginProgressEventArgs e) { Logger.Log(String.Format("Login: {0} ({1})", e.Status, e.Message), Helpers.LogLevel.Info); switch (e.Status) { case LoginStatus.Failed: LoginEvent.Set(); break; case LoginStatus.Success: LoginSuccess = true; LoginEvent.Set(); break; } } static void ParcelHandler(object sender, SimParcelsDownloadedEventArgs e){ if(ParcelSuccess){ return; } Logger.Log("Parcel Downloaded." , Helpers.LogLevel.Info); ParcelSuccess = true; } } }