public bool isCachedImage(LLUUID ImageID) { if (ImageID == null) { throw new Exception("Don't go calling isCachedImage() with a null..."); } switch (CacheType) { case CacheTypes.Memory: return(CacheTable.ContainsKey(ImageID)); case CacheTypes.Disk: if (CachedDiskIndex.Contains(ImageID)) { return(true); } else { String filepath = Path.Combine(CacheDirectory, ImageID.ToStringHyphenated()); if (File.Exists(filepath)) { CachedDiskIndex.Add(ImageID); return(true); } else { return(false); } } default: return(false); } }
static void Main(string[] args) { SecondLife client = new SecondLife(); if (args.Length < 4) { Console.WriteLine("Usage: Key2Name [loginfirstname] [loginlastname] [password] [key]"); return; } Console.WriteLine("Attempting to connect and login to Second Life."); // Setup Login to Second Life Dictionary <string, object> loginParams = client.Network.DefaultLoginValues(args[0], args[1], args[2], "00:00:00:00:00:00", "last", "Win", "0", "key2name", "*****@*****.**"); Dictionary <string, object> loginReply = new Dictionary <string, object>(); if (!client.Network.Login(loginParams)) { // Login failed Console.WriteLine("Error logging in: " + client.Network.LoginError); return; } AvatarTracker avatarTracker = new AvatarTracker(client); LLUUID lookup = new LLUUID(args[3]); Console.WriteLine("Looking up name for " + lookup.ToStringHyphenated()); string name = avatarTracker.GetAvatarName(lookup); Console.WriteLine("Name: " + name + ". Press enter to logout."); Console.ReadLine(); client.Network.Logout(); }
private byte[] CachedImage(LLUUID ImageID) { switch (CacheType) { case CacheTypes.Memory: if (CacheTable.ContainsKey(ImageID)) { return(CacheTable[ImageID]); } else { return(null); } case CacheTypes.Disk: String filepath = Path.Combine(CacheDirectory, ImageID.ToStringHyphenated()); if (File.Exists(filepath)) { return(File.ReadAllBytes(filepath)); } else { return(null); } default: return(null); } }
public bool UpdateItemAsset(LLUUID itemID, AssetBase asset) { if (this.InventoryItems.ContainsKey(itemID)) { InventoryItem Item = this.InventoryItems[itemID]; Item.AssetID = asset.FullID; Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated() + " so it now is set to asset " + asset.FullID.ToStringHyphenated()); //TODO need to update the rest of the info } return(true); }
private string grabAsset(LLUUID AssetID) { AssetRequestDownload request = base.iManager.AssetManager.RequestInventoryAsset(this); if (request.Wait(libsecondlife.AssetSystem.AssetManager.DefaultTimeout) != AssetRequestDownload.RequestStatus.Success) { throw new Exception("Asset (" + AssetID.ToStringHyphenated() + ") unavailable (" + request.StatusMsg + ") for " + this.Name); } _Asset = new AssetLandmark(AssetID, request.GetAssetData()); return(((AssetLandmark)Asset).Body); }
/// <summary> /// Requests an image from SecondLife and blocks until it's received. /// </summary> /// <param name="ImageID">The Image's AssetID</param> public byte[] RequestImage(LLUUID ImageID) { byte[] imgData = CachedImage(ImageID); if (imgData != null) { return(imgData); } TransferRequest tr; lock (htDownloadRequests) { if (htDownloadRequests.ContainsKey(ImageID) == false) { tr = new TransferRequest(); tr.Size = int.MaxValue; // Number of bytes expected tr.Received = 0; // Number of bytes received tr.TimeOfLastPacket = Helpers.GetUnixTime(); // last time we recevied a packet for this request htDownloadRequests[ImageID] = tr; Packet packet = ImagePacketHelper.RequestImage(ImageID); slClient.Network.SendPacket(packet); } else { tr = htDownloadRequests[ImageID]; } } // Wait for transfer to complete. while (!tr.Completed.WaitOne(10000, false)) //If it times out, then check, otherwise loop again until WaitOne returns true { slClient.Log("Warning long running texture download: " + ImageID.ToStringHyphenated(), Helpers.LogLevel.Warning); Console.WriteLine("Downloaded : " + tr.Received); if ((Helpers.GetUnixTime() - tr.TimeOfLastPacket) > 10) { tr.Status = false; tr.StatusMsg = "Timeout while downloading image."; slClient.Log(tr.StatusMsg, Helpers.LogLevel.Error); tr.Completed.Set(); } } if (tr.Status == true) { return(tr.AssetData); } else { throw new Exception("RequestImage: " + tr.StatusMsg); } }
public bool UpdateItemDetails(LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet) { Console.WriteLine("updating inventory item details"); if (this.InventoryItems.ContainsKey(itemID)) { Console.WriteLine("changing name to " + Util.FieldToString(packet.Name)); InventoryItem Item = this.InventoryItems[itemID]; Item.Name = Util.FieldToString(packet.Name); Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated()); //TODO need to update the rest of the info } return(true); }
private void setAsset() { string body = "Landmark version " + _Version.ToString() + "\n"; body += "region_id " + _Region.ToStringHyphenated() + "\n"; body += "local_pos " + _Pos.X.ToString() + " " + _Pos.Y.ToString() + " " + _Pos.Z.ToString(); // Assume this is a string, add 1 for the null terminator byte[] stringBytes = System.Text.Encoding.UTF8.GetBytes((string)body); byte[] assetData = new byte[stringBytes.Length + 1]; Buffer.BlockCopy(stringBytes, 0, assetData, 0, stringBytes.Length); SetAssetData(assetData); }
private void CacheImage(LLUUID ImageID, byte[] ImageData) { switch (CacheType) { case CacheTypes.Memory: CacheTable[ImageID] = ImageData; break; case CacheTypes.Disk: String filepath = Path.Combine(CacheDirectory, ImageID.ToStringHyphenated()); File.WriteAllBytes(filepath, ImageData); CachedDiskIndex.Add(ImageID); break; default: break; } }
public override string Execute(string[] args, LLUUID fromAgentID) { if (args.Length < 3) { return("Usage: im [firstname] [lastname] [message]"); } ToAvatarName = args[0] + " " + args[1]; // Build the message string message = String.Empty; for (int ct = 2; ct < args.Length; ct++) { message += args[ct] + " "; } message = message.TrimEnd(); if (message.Length > 1023) { message = message.Remove(1023); } if (!Name2Key.ContainsKey(ToAvatarName.ToLower())) { // Send the Query Client.Avatars.RequestAvatarNameSearch(ToAvatarName, LLUUID.Random()); NameSearchEvent.WaitOne(6000, false); } if (Name2Key.ContainsKey(ToAvatarName.ToLower())) { LLUUID id = Name2Key[ToAvatarName.ToLower()]; Client.Self.InstantMessage(id, message, id); return("Instant Messaged " + id.ToStringHyphenated() + " with message: " + message); } else { return("Name lookup for " + ToAvatarName + " failed"); } }
public override string Execute(string[] args, LLUUID fromAgentID) { if (args.Length != 1) { return(Description); } LLUUID targetID; ReceivedProperties = false; ReceivedInterests = false; try { targetID = new LLUUID(args[0]); } catch (Exception) { return(Description); } Client.Avatars.RequestAvatarProperties(targetID); ReceivedProfileEvent.Reset(); ReceivedProfileEvent.WaitOne(5000, false); if (!ReceivedInterests || !ReceivedProperties) { return("Failed to retrieve a complete profile for that UUID"); } Client.Self.ProfileInterests = Interests; Client.Self.ProfileProperties = Properties; Client.Self.SetAvatarInformation(); return("Synchronized our profile to the profile of " + targetID.ToStringHyphenated()); }
private void NewImageRetrievedCallBack(LLUUID ImageID, byte[] data, bool wasCached, string statusMsg) { if (wasCached) { Console.WriteLine("Cache ( " + data.Length + "): " + ImageID); } else { if (data == null) { Console.WriteLine("Image Data is null (" + statusMsg + "): " + ImageID); } else { Console.WriteLine("Finished ( " + data.Length + "): " + ImageID); String filename = Path.Combine(OutputDirectory, ImageID.ToStringHyphenated()) + ".tif"; TiffJob tj = new TiffJob(filename, data); Thread t = new Thread(tj.RunMe); t.Start(); } } }
// ProxyLogin: proxy a login request private void ProxyLogin(StreamReader reader, StreamWriter writer) { lock (this) { string line; int contentLength = 0; // read HTTP header do { // read one line of the header line = reader.ReadLine(); // check for premature EOF if (line == null) { throw new Exception("EOF in client HTTP header"); } // look for Content-Length Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line); if (match.Success) { contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString()); } } while (line != ""); // read the HTTP body into a buffer char[] content = new char[contentLength]; reader.Read(content, 0, contentLength); XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content)); if (request.MethodName == "login_to_simulator") { Hashtable requestData = (Hashtable)request.Params[0]; string first; string last; string passwd; LLUUID Agent; LLUUID Session; //get login name if (requestData.Contains("first")) { first = (string)requestData["first"]; } else { first = "test"; } if (requestData.Contains("last")) { last = (string)requestData["last"]; } else { last = "User" + NumClients.ToString(); } if (requestData.Contains("passwd")) { passwd = (string)requestData["passwd"]; } else { passwd = "notfound"; } if (!Authenticate(first, last, passwd)) { // Fail miserably writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); writer.WriteLine(); return; } NumClients++; //create a agent and session LLUUID Agent = GetAgentId(first, last); int SessionRand = this.RandomClass.Next(1, 999); Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797"); XmlRpcResponse response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); Hashtable responseData = (Hashtable)response.Value; responseData["sim_port"] = Globals.Instance.SimPort; responseData["sim_ip"] = Globals.Instance.SimIPAddress; responseData["agent_id"] = Agent.ToStringHyphenated(); responseData["session_id"] = Session.ToStringHyphenated(); ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"]; Hashtable Inventory1 = (Hashtable)InventoryList[0]; Hashtable Inventory2 = (Hashtable)InventoryList[1]; LLUUID BaseFolderID = LLUUID.Random(); LLUUID InventoryFolderID = LLUUID.Random(); Inventory2["name"] = "Base"; Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated(); Inventory2["type_default"] = 6; Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated(); ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"]; Hashtable Inventoryroot = (Hashtable)InventoryRoot[0]; Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated(); CustomiseLoginResponse(responseData, first, last); this._login = new Logon(); //copy data to login object _login.First = first; _login.Last = last; _login.Agent = Agent; _login.Session = Session; _login.BaseFolder = BaseFolderID; _login.InventoryFolder = InventoryFolderID; lock (Globals.Instance.IncomingLogins) { Globals.Instance.IncomingLogins.Add(_login); } // forward the XML-RPC response to the client writer.WriteLine("HTTP/1.0 200 OK"); writer.WriteLine("Content-type: text/xml"); writer.WriteLine(); XmlTextWriter responseWriter = new XmlTextWriter(writer); XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response); responseWriter.Close(); } else { writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); writer.WriteLine(); } } }
public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) { Console.WriteLine("login attempt"); Hashtable requestData = (Hashtable)request.Params[0]; string first; string last; string passwd; LLUUID Agent; LLUUID Session; LoginResponse loginResponse = new LoginResponse(regionX, regionY); //get login name if (requestData.Contains("first")) { first = (string)requestData["first"]; } else { first = "test"; } if (requestData.Contains("last")) { last = (string)requestData["last"]; } else { last = "User" + NumClients.ToString(); } if (requestData.Contains("passwd")) { passwd = (string)requestData["passwd"]; } else { passwd = "notfound"; } if (!Authenticate(first, last, passwd)) { return(loginResponse.LoginFailedResponse()); } NumClients++; // Create a agent and session LLUUID Agent = GetAgentId(first, last); int SessionRand = Util.RandomClass.Next(1, 999); Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797"); LLUUID secureSess = LLUUID.Random(); loginResponse.SimPort = m_simPort.ToString(); loginResponse.SimAddress = m_simAddr.ToString(); loginResponse.AgentID = Agent.ToStringHyphenated(); loginResponse.SessionID = Session.ToStringHyphenated(); loginResponse.SecureSessionID = secureSess.ToStringHyphenated(); loginResponse.CircuitCode = (Int32)(Util.RandomClass.Next()); XmlRpcResponse response = loginResponse.ToXmlRpcResponse(); Hashtable responseData = (Hashtable)response.Value; // inventory ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"]; Hashtable Inventory1 = (Hashtable)InventoryList[0]; Hashtable Inventory2 = (Hashtable)InventoryList[1]; LLUUID BaseFolderID = LLUUID.Random(); LLUUID InventoryFolderID = LLUUID.Random(); Inventory2["name"] = "Textures"; Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated(); Inventory2["type_default"] = 0; Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated(); ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"]; Hashtable Inventoryroot = (Hashtable)InventoryRoot[0]; Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated(); CustomiseLoginResponse(responseData, first, last); Login _login = new Login(); //copy data to login object _login.First = first; _login.Last = last; _login.Agent = Agent; _login.Session = Session; _login.SecureSession = secureSess; _login.BaseFolder = BaseFolderID; _login.InventoryFolder = InventoryFolderID; //working on local computer if so lets add to the gridserver's list of sessions? if (m_gridServer.GetName() == "Local") { ((LocalGridBase)m_gridServer).AddNewSession(_login); } return(response); }
public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) { XmlRpcResponse response = new XmlRpcResponse(); Hashtable requestData = (Hashtable)request.Params[0]; bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd")); bool GoodLogin = false; string firstname = ""; string lastname = ""; string passwd = ""; if (GoodXML) { firstname = (string)requestData["first"]; lastname = (string)requestData["last"]; passwd = (string)requestData["passwd"]; GoodLogin = AuthenticateUser(firstname, lastname, passwd); } if (!(GoodXML && GoodLogin)) { response = CreateErrorConnectingToGridResponse(); } else { UserProfile TheUser = GetProfileByName(firstname, lastname); //we need to sort out how sessions are logged out , currently the sim tells the gridserver //but if as this suggests the userserver handles it then please have the sim telling the userserver instead //as it really makes things messy for sandbox mode //if (!((TheUser.CurrentSessionID == null) && (TheUser.CurrentSecureSessionID == null))) // { // response = CreateAlreadyLoggedInResponse(); // } //else //{ try { Hashtable responseData = new Hashtable(); LLUUID AgentID = TheUser.UUID; TheUser.InitSessionData(); //for loading data from a grid server, make any changes in CustomiseResponse() (or create a sub class of this and override that method) //SimProfile SimInfo = new SimProfile(); //SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey); Hashtable GlobalT = new Hashtable(); GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271"; GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; ArrayList GlobalTextures = new ArrayList(); GlobalTextures.Add(GlobalT); Hashtable LoginFlagsHash = new Hashtable(); LoginFlagsHash["daylight_savings"] = "N"; LoginFlagsHash["stipend_since_login"] = "******"; LoginFlagsHash["gendered"] = "Y"; LoginFlagsHash["ever_logged_in"] = "Y"; ArrayList LoginFlags = new ArrayList(); LoginFlags.Add(LoginFlagsHash); Hashtable uiconfig = new Hashtable(); uiconfig["allow_first_life"] = "Y"; ArrayList ui_config = new ArrayList(); ui_config.Add(uiconfig); Hashtable ClassifiedCategoriesHash = new Hashtable(); ClassifiedCategoriesHash["category_name"] = "bla bla"; ClassifiedCategoriesHash["category_id"] = (Int32)1; ArrayList ClassifiedCategories = new ArrayList(); ClassifiedCategories.Add(ClassifiedCategoriesHash); ArrayList AgentInventory = new ArrayList(); Console.WriteLine("adding inventory to response"); Hashtable TempHash; foreach (InventoryFolder InvFolder in TheUser.Inventory.InventoryFolders.Values) { TempHash = new Hashtable(); Console.WriteLine("adding folder " + InvFolder.FolderName + ", ID: " + InvFolder.FolderID.ToStringHyphenated() + " with parent: " + InvFolder.ParentID.ToStringHyphenated()); TempHash["name"] = InvFolder.FolderName; TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated(); TempHash["version"] = (Int32)InvFolder.Version; TempHash["type_default"] = (Int32)InvFolder.DefaultType; TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated(); AgentInventory.Add(TempHash); } Hashtable InventoryRootHash = new Hashtable(); InventoryRootHash["folder_id"] = TheUser.Inventory.InventoryRoot.FolderID.ToStringHyphenated(); ArrayList InventoryRoot = new ArrayList(); InventoryRoot.Add(InventoryRootHash); Hashtable InitialOutfitHash = new Hashtable(); InitialOutfitHash["folder_name"] = "Nightclub Female"; InitialOutfitHash["gender"] = "female"; ArrayList InitialOutfit = new ArrayList(); InitialOutfit.Add(InitialOutfitHash); uint circode = (uint)(Util.RandomClass.Next()); //TheUser.AddSimCircuit(circode, SimInfo.UUID); responseData["last_name"] = TheUser.lastname; responseData["ui-config"] = ui_config; responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString(); responseData["login-flags"] = LoginFlags; responseData["global-textures"] = GlobalTextures; responseData["classified_categories"] = ClassifiedCategories; responseData["event_categories"] = new ArrayList(); responseData["inventory-skeleton"] = AgentInventory; responseData["inventory-skel-lib"] = new ArrayList(); responseData["inventory-root"] = InventoryRoot; responseData["event_notifications"] = new ArrayList(); responseData["gestures"] = new ArrayList(); responseData["inventory-lib-owner"] = new ArrayList(); responseData["initial-outfit"] = InitialOutfit; responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; responseData["start_location"] = "last"; responseData["home"] = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + TheUser.homepos.X.ToString() + ",r" + TheUser.homepos.Y.ToString() + ",r" + TheUser.homepos.Z.ToString() + "], 'look_at':[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]}"; responseData["message"] = DefaultStartupMsg; responseData["first_name"] = TheUser.firstname; responseData["circuit_code"] = (Int32)circode; responseData["sim_port"] = 9000; //(Int32)SimInfo.sim_port; responseData["secure_session_id"] = TheUser.CurrentSecureSessionID.ToStringHyphenated(); responseData["look_at"] = "\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n"; responseData["agent_id"] = AgentID.ToStringHyphenated(); responseData["region_y"] = (Int32)996 * 256; // (Int32)SimInfo.RegionLocY * 256; responseData["region_x"] = (Int32)997 * 256; //SimInfo.RegionLocX * 256; responseData["seed_capability"] = ""; responseData["agent_access"] = "M"; responseData["session_id"] = TheUser.CurrentSessionID.ToStringHyphenated(); responseData["login"] = "******"; this.CustomiseResponse(ref responseData, TheUser); response.Value = responseData; // TheUser.SendDataToSim(SimInfo); return(response); } catch (Exception E) { Console.WriteLine(E.ToString()); } //} } return(response); }