private void Init(string[] args, ProxyConfig proxyConfig) { //bool externalPlugin = false; this.args = args; if (proxyConfig == null) { proxyConfig = new ProxyConfig("GridProxy", "Austin Jennings / Andrew Ortman", args, true); } proxy = new Proxy(proxyConfig); // add delegates for login proxy.AddLoginRequestDelegate(new XmlRpcRequestDelegate(LoginRequest)); proxy.AddLoginResponseDelegate(new XmlRpcResponseDelegate(LoginResponse)); // add a delegate for outgoing chat proxy.AddDelegate(PacketType.ChatFromViewer, Direction.Outgoing, new PacketDelegate(ChatFromViewerOut)); // handle command line arguments foreach (string arg in args) { if (arg == "--log-login") { logLogin = true; } else if (arg.Substring(0, 2) == "--") { int ipos = arg.IndexOf("="); if (ipos != -1) { string sw = arg.Substring(0, ipos); string val = arg.Substring(ipos + 1); Logger.Log("arg '" + sw + "' val '" + val + "'", Helpers.LogLevel.Debug); if (sw == "--load") { //externalPlugin = true; LoadPlugin(val); } } } } commandDelegates["/load"] = new CommandDelegate(CmdLoad); }
private void CmdLoad(string[] words) { if (words.Length != 2) { SayToUser("Usage: /load <plugin name>"); } else { try { LoadPlugin(words[1]); } catch (Exception e) { Logger.Log("LoadPlugin exception", Helpers.LogLevel.Error, e); } } }
public void LoadPlugin(string name) { Assembly assembly = Assembly.LoadFile(Path.GetFullPath(name)); foreach (Type t in assembly.GetTypes()) { try { if (t.IsSubclassOf(typeof(ProxyPlugin))) { ConstructorInfo info = t.GetConstructor(new Type[] { typeof(ProxyFrame) }); ProxyPlugin plugin = (ProxyPlugin)info.Invoke(new object[] { this }); plugin.Init(); } } catch (Exception e) { Logger.Log("LoadPlugin exception", Helpers.LogLevel.Error, e); } } }
protected void StartPoxy() { AppendLog("Starting proxy..." + Environment.NewLine); try { proxy = new ProxyManager(txtPort.Text, cbListen.ActiveText, cbLoginURL.ActiveText); proxy.Start(); btnLoadPlugin.Sensitive = true; ApplyProxyFilters(); } catch (Exception ex) { Logger.Log("Failed to start proxy: " + ex.Message, OpenMetaverse.Helpers.LogLevel.Error); try { proxy.Stop(); } catch { } btnStart.Label = "Start Proxy"; proxy = null; } }
/// <summary> /// Loads in inventory cache file into the inventory structure. Note only valid to call after login has been successful. /// </summary> /// <param name="filename">Name of the cache file to load</param> /// <returns>The number of inventory items sucessfully reconstructed into the inventory node tree</returns> public int RestoreFromDisk(string filename) { List <InventoryNode> nodes = new List <InventoryNode>(); int item_count = 0; try { if (!File.Exists(filename)) { return(-1); } using (Stream stream = File.Open(filename, FileMode.Open)) { BinaryFormatter bformatter = new BinaryFormatter(); while (stream.Position < stream.Length) { OpenMetaverse.InventoryNode node = (InventoryNode)bformatter.Deserialize(stream); nodes.Add(node); item_count++; } } } catch (Exception e) { Logger.Log("Error accessing inventory cache file :" + e.Message, Helpers.LogLevel.Error); return(-1); } Logger.Log("Read " + item_count.ToString() + " items from inventory cache file", Helpers.LogLevel.Info); item_count = 0; List <InventoryNode> del_nodes = new List <InventoryNode>(); //nodes that we have processed and will delete List <UUID> dirty_folders = new List <UUID>(); // Tainted folders that we will not restore items into // Because we could get child nodes before parents we must itterate around and only add nodes who have // a parent already in the list because we must update both child and parent to link together // But sometimes we have seen orphin nodes due to bad/incomplete data when caching so we have an emergency abort route int stuck = 0; while (nodes.Count != 0 && stuck < 5) { foreach (InventoryNode node in nodes) { InventoryNode pnode; if (node.ParentID == UUID.Zero) { //We don't need the root nodes "My Inventory" etc as they will already exist for the correct // user of this cache. del_nodes.Add(node); item_count--; } else if (Items.TryGetValue(node.Data.UUID, out pnode)) { //We already have this it must be a folder if (node.Data is InventoryFolder) { InventoryFolder cache_folder = (InventoryFolder)node.Data; InventoryFolder server_folder = (InventoryFolder)pnode.Data; if (cache_folder.Version != server_folder.Version) { Logger.DebugLog("Inventory Cache/Server version mismatch on " + node.Data.Name + " " + cache_folder.Version.ToString() + " vs " + server_folder.Version.ToString()); pnode.NeedsUpdate = true; dirty_folders.Add(node.Data.UUID); } else { pnode.NeedsUpdate = false; } del_nodes.Add(node); } } else if (Items.TryGetValue(node.ParentID, out pnode)) { if (node.Data != null) { // If node is folder, and it does not exist in skeleton, mark it as // dirty and don't process nodes that belong to it if (node.Data is InventoryFolder && !(Items.ContainsKey(node.Data.UUID))) { dirty_folders.Add(node.Data.UUID); } //Only add new items, this is most likely to be run at login time before any inventory //nodes other than the root are populated. Don't add non existing folders. if (!Items.ContainsKey(node.Data.UUID) && !dirty_folders.Contains(pnode.Data.UUID) && !(node.Data is InventoryFolder)) { Items.Add(node.Data.UUID, node); node.Parent = pnode; //Update this node with its parent pnode.Nodes.Add(node.Data.UUID, node); // Add to the parents child list item_count++; } } del_nodes.Add(node); } } if (del_nodes.Count == 0) { stuck++; } else { stuck = 0; } //Clean up processed nodes this loop around. foreach (InventoryNode node in del_nodes) { nodes.Remove(node); } del_nodes.Clear(); } Logger.Log("Reassembled " + item_count.ToString() + " items from inventory cache file", Helpers.LogLevel.Info); return(item_count); }
/// <summary>Process an incoming packet and raise the appropriate events</summary> /// <param name="sender">The sender</param> /// <param name="e">The EventArgs object containing the packet data</param> protected void MapItemReplyHandler(object sender, PacketReceivedEventArgs e) { if (m_GridItems != null) { MapItemReplyPacket reply = (MapItemReplyPacket)e.Packet; GridItemType type = (GridItemType)reply.RequestData.ItemType; List <MapItem> items = new List <MapItem>(); for (int i = 0; i < reply.Data.Length; i++) { string name = Utils.BytesToString(reply.Data[i].Name); switch (type) { case GridItemType.AgentLocations: MapAgentLocation location = new MapAgentLocation(); location.GlobalX = reply.Data[i].X; location.GlobalY = reply.Data[i].Y; location.Identifier = name; location.AvatarCount = reply.Data[i].Extra; items.Add(location); break; case GridItemType.Classified: //FIXME: Logger.Log("FIXME", Helpers.LogLevel.Error, Client); break; case GridItemType.LandForSale: MapLandForSale landsale = new MapLandForSale(); landsale.GlobalX = reply.Data[i].X; landsale.GlobalY = reply.Data[i].Y; landsale.ID = reply.Data[i].ID; landsale.Name = name; landsale.Size = reply.Data[i].Extra; landsale.Price = reply.Data[i].Extra2; items.Add(landsale); break; case GridItemType.MatureEvent: MapMatureEvent matureEvent = new MapMatureEvent(); matureEvent.GlobalX = reply.Data[i].X; matureEvent.GlobalY = reply.Data[i].Y; matureEvent.Description = name; matureEvent.Flags = (DirectoryManager.EventFlags)reply.Data[i].Extra2; items.Add(matureEvent); break; case GridItemType.PgEvent: MapPGEvent PGEvent = new MapPGEvent(); PGEvent.GlobalX = reply.Data[i].X; PGEvent.GlobalY = reply.Data[i].Y; PGEvent.Description = name; PGEvent.Flags = (DirectoryManager.EventFlags)reply.Data[i].Extra2; items.Add(PGEvent); break; case GridItemType.Popular: //FIXME: Logger.Log("FIXME", Helpers.LogLevel.Error, Client); break; case GridItemType.Telehub: MapTelehub teleHubItem = new MapTelehub(); teleHubItem.GlobalX = reply.Data[i].X; teleHubItem.GlobalY = reply.Data[i].Y; items.Add(teleHubItem); break; case GridItemType.AdultLandForSale: MapAdultLandForSale adultLandsale = new MapAdultLandForSale(); adultLandsale.GlobalX = reply.Data[i].X; adultLandsale.GlobalY = reply.Data[i].Y; adultLandsale.ID = reply.Data[i].ID; adultLandsale.Name = name; adultLandsale.Size = reply.Data[i].Extra; adultLandsale.Price = reply.Data[i].Extra2; items.Add(adultLandsale); break; case GridItemType.AdultEvent: MapAdultEvent adultEvent = new MapAdultEvent(); adultEvent.GlobalX = reply.Data[i].X; adultEvent.GlobalY = reply.Data[i].Y; adultEvent.Description = Utils.BytesToString(reply.Data[i].Name); adultEvent.Flags = (DirectoryManager.EventFlags)reply.Data[i].Extra2; items.Add(adultEvent); break; default: Logger.Log("Unknown map item type " + type, Helpers.LogLevel.Warning, Client); break; } } OnGridItems(new GridItemsEventArgs(type, items)); } }