What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

@addiktion Growl Notifications with Trinity

My420Time

New Member
Joined
Nov 21, 2012
Messages
29
Reaction score
0
Ok, so here is the code you requested. Converted it with just notepad before so couldn't check it but compiles without issue now. According to Sending Growl Notifications From CSharp*|*Michael E. Chancey Jr. it should work. You will need to modify SendNotification in NotificationManager.cs. Also you will need to obviously fill in the ip/port/password.

NotificationManager.cs Line 39
Code:
public static void SendNotification(ProwlNotification notification)
        {
            if (GilesTrinity.Settings.Notification.IPhoneEnabled && !string.IsNullOrWhiteSpace(GilesTrinity.Settings.Notification.IPhoneKey))
            {
                

                var newNotification =
                        new ProwlNotification
                        {
                            Description = notification.Description,
                            Event = notification.Event,
                            Priority = notification.Priority
                        };
                try
                {
                    PostNotification(newNotification);
                }
                catch
                {
                }
            }
            if (GilesTrinity.Settings.Notification.AndroidEnabled && !string.IsNullOrWhiteSpace(GilesTrinity.Settings.Notification.AndroidKey))
            {
                var newNotification =
                        new ProwlNotification
                        {
                            Description = notification.Description,
                            Event = notification.Event,
                            Priority = notification.Priority
                        };
                try
                {
                    PostNotification(newNotification, true);
                }
                catch
                {
                }
            }

            bool UseGrowl = true;

            if (UseGrowl)
            {
                try
                {
                    //Growl
                    string ServerIP = "12.34.56.78";
                    int ServerPort = 9887;
                    string ServerPassword = "SuperSecretPasswordDontTellAnyone";
                    GrowlSend.GrowlSend(ServerIP, ServerPort, ServerPassword, notification.Event, notification.Description);
                    //Growl
                }
                catch
                {
                }
            } 
        }

GrowlNotification.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Security.Cryptography;

namespace GilesTrinity.Notifications
{
    public class GrowlSend
    {
        public static void GrowlSend(string UserServer, int UserServerPort, string UserServerPassword, string NotificationTitle, string NotificationDescription)
        {
            string[] NotificationTypes = { "Notify Type 1", "Notify Type 2" };
            Growl tmpNotify = new Growl("Trinity Growl Notify", UserServer, UserServerPort, UserServerPassword);
            tmpNotify.RegisterApplication((from a in NotificationTypes select new GrowlNotification() { Name = a, EnabledByDefault = true }).ToArray());
            tmpNotify.SendNotification(NotificationTypes[0], NotificationTitle, NotificationDescription, GrowlNotificationPriority.Normal, false);
        }
    }

    public class Growl
    {
        private System.Net.Sockets.UdpClient mClient = new UdpClient();
        public string ApplicationName { get; set; }
        public string GrowlServer { get; set; }
        public int GrowlPort { get; set; }
        public string GrowlPassword { get; set; }

        public Growl(string ApplicationName, string Server, int Port, string Password)
        {
            this.ApplicationName = ApplicationName;
            this.GrowlServer = Server;
            this.GrowlPort = Port;
            this.GrowlPassword = Password;
        }

        public void RegisterApplication(GrowlNotification[] Notifications)
        {
            List<byte> tmpPacket = new List<byte>();

            //SETUP THE PACKET VERSION ACCORDING TO GROWL STD 
            tmpPacket.Add((byte)1);         //1 GROWL_PROTOCOL_VERSION
            tmpPacket.Add((byte)0);         //0 GROWL_TYPE_REGISTRATION

            //APPLICATION NAME LENGTH AS UNSIGNED INTEGER
            //BITCONVERTER REVERSES THE ARRAY FOR SOME REASON SO WE SWITCH IT BACK WITH REVERSE
            tmpPacket.AddRange(BitConverter.GetBytes((UInt16)ApplicationName.Length).Reverse());

            //NUMBER OF NOTIFICATIONS THIS APPLICATION SUPPORTS
            tmpPacket.Add((byte)Notifications.Length);

            //NUMBER OF NOTIFICATIONS WHICH ARE ENABLED BY DEFAULT
            tmpPacket.Add((byte)(from a in Notifications where a.EnabledByDefault == true select a).Count());

            //APPLICATION NAME WHICH NEEDS TO BE INSERTED
            tmpPacket.AddRange(System.Text.UTF8Encoding.UTF8.GetBytes(ApplicationName));

            //ADD EACH NOTIFIACITON TO THE LIST
            foreach (GrowlNotification tmpNotification in Notifications)
            {
                tmpPacket.AddRange(BitConverter.GetBytes((UInt16)tmpNotification.Name.Length).Reverse());
                tmpPacket.AddRange(UTF8Encoding.UTF8.GetBytes(tmpNotification.Name));
            }

            //ADD EACH OF THE ENABLED NOTIFIACTIONS TO THE LIST
            for (int i = 0; i < Notifications.Length; i++)
            {
                if (Notifications[i].EnabledByDefault)
                    tmpPacket.Add((byte)i);
            }

            //COMPUTE THE HASH FOR THIS PACKET WHICH = HASH OF PACKET+PASSWORD
            tmpPacket.AddRange(ComputeHash(tmpPacket.ToArray(), GrowlPassword));

            //SEND THE PACKET TO THE CLIENT SYSTEM
            mClient.Send(tmpPacket.ToArray(), tmpPacket.Count, new IPEndPoint(Dns.GetHostAddresses(GrowlServer).FirstOrDefault(), GrowlPort));
        }

        public void SendNotification(string NotificationName, string Title, string Description, GrowlNotificationPriority Priority, bool Sticky)
        {
            List<byte> tmpPacket = new List<byte>();

            //SETUP THE PACKET VERSION ACCORDING TO GROWL STD 
            tmpPacket.Add((byte)1);         //1 GROWL_PROTOCOL_VERSION
            tmpPacket.Add((byte)1);         //1 GROWL_TYPE_NOTIFICATION

            //FLAGS ??
            Int16 tmpFlags = (Int16)((((int)Priority) & 7) * 2);

            if (Priority < 0)
                tmpFlags |= 8;
            if (Sticky)
                tmpFlags |= 256;

            tmpPacket.AddRange(BitConverter.GetBytes(tmpFlags).Reverse());

            //LENGTH OF THE NOTIFICATION NAME BEING SENT
            tmpPacket.AddRange(BitConverter.GetBytes((UInt16)NotificationName.Length).Reverse());

            //LENGTH OF THE TITLE BEING SENT
            tmpPacket.AddRange(BitConverter.GetBytes((UInt16)Title.Length).Reverse());

            //LENGTH OF THE DESCRIPTION
            tmpPacket.AddRange(BitConverter.GetBytes((UInt16)Description.Length).Reverse());

            //LENGTH OF THE APPLICATION NAME
            tmpPacket.AddRange(BitConverter.GetBytes((UInt16)ApplicationName.Length).Reverse());

            //NOTIFICATION NAME BEING SENT
            tmpPacket.AddRange(UTF8Encoding.UTF8.GetBytes(NotificationName));

            //TITLE BEING SENT
            tmpPacket.AddRange(UTF8Encoding.UTF8.GetBytes(Title));

            //DESCRIPTION BEING SENT
            tmpPacket.AddRange(UTF8Encoding.UTF8.GetBytes(Description));

            //APPLICATION NAME BEING SENT
            tmpPacket.AddRange(UTF8Encoding.UTF8.GetBytes(ApplicationName));

            //COMPUTE THE PACKET HASH WHICH = PACKET+PASSWORD
            tmpPacket.AddRange(ComputeHash(tmpPacket.ToArray(), GrowlPassword));

            //SEND THE PACKET
            mClient.Send(tmpPacket.ToArray(), tmpPacket.Count, new IPEndPoint(Dns.GetHostAddresses(GrowlServer).FirstOrDefault(), GrowlPort));
        }

        private IEnumerable<byte> ComputeHash(byte[] Packet, string Password)
        {
            List<byte> tmpHash = new List<byte>(Packet);
            tmpHash.AddRange(System.Text.UTF8Encoding.UTF8.GetBytes(Password));
            return MD5.Create().ComputeHash(tmpHash.ToArray());
        }
    }
}

GrowlNotificationPriority.cs
Code:
namespace GilesTrinity.Notifications
{
    public enum GrowlNotificationPriority
    {
        VeryLow = -2,
        Moderate = -1,
        Normal = 0,
        High = 1,
        Emergency = 2
    }

    public struct GrowlNotification
    {
        public string Name;
        public bool EnabledByDefault;
    }
}
 
Last edited:
Yeah Growl for Windows is actually Windows based so you could potentially test it out. They have guides and a sample app on how to implement it.

I mentioned it to rrrix but he's obviously too busy working on the core of Trinity right now with the recent changeovers. I'm not really a C# dev as I'm more of a Ruby kind of guy but it's cool you are throwing something together. It'd be a matter of cleaning it up and tying it into the existing item reporting system they are using now with their NotifyMyAndroid or Prowl.

One of the advantages that Growl has over the mobile variants is that it can forward stuff across the local network, so if you have all your bots on another machine, they can potentially alert you on your main Windows desktop.
Second advantage is well, its free. You can't beat free and I'm on my main computer that doesn't run bots anyhow, so its easy to get a simply notification on the screen I'm already staring at.
 
Last edited:
Here is a link to where they are managing the Notification System with Prowl and NotifyMyAndroid:

https://www.assembla.com/code/unifi.../Sources/Notifications/NotificationManager.cs

Can anyone here with C# expertise clone the entire project and try implementing My420Time's code in a constructive fashion?

I thought I read somewhere that Growl indicated you don't have to have a server password, so you'd probably want to make that as an optional argument as well.
 
If some of you don't know what the hell we are talking about, Growl for Windows is a desktop notification system. You can tie various applications into it and it will alert you similar to NotifyMyAndroid or Prowl but for the Windows desktop instead.

Here's a link if you are interested in it: Growl for Windows
 
Gave you everything you needed. You should be able to go into NotificationManager.cs under SendNotification and add the GrowlSendMain call. Of course you will need to put you settings into the variables like in the examples at the top.
 
Gave you everything you needed. You should be able to go into NotificationManager.cs under SendNotification and add the GrowlSendMain call. Of course you will need to put you settings into the variables like in the examples at the top.

So you didn't actually need to use the connector and corelibrary dll files that come with the Growl SDK? Sweet. I'll give this a shot and see if it works.
 
Last edited:
On second thought, I don't have visual studio's installed... so I can't really compile it and test it out. Anyone else willing to give it a go?

Obviously the ideal solution would be for us to add in a couple more fields under the Mobile tab to make it easier for users.

A simple checkbox to "Enable Growl" and a field for port (which appears defaulted to 9887 like you listed) and password (which can be blank). With the IP I'm guessing it would just easier to detect the local LAN IP and store it automatically or at least pre-populate the IP field with the default LAN IP.

Then tie in the Notification.description into the message field.
 
Using your LAN IP of the desktop running DB would not work, you need to use the IP of the growl server. Also, you can test this just fine without Visual Studio. Just place the files in the correct folders in the trinity folder. After that you just need a small modification to NotificationManager.cs and your off to the races. Once it is verified working then it would be worth sticking it in the gui and what not. On another note Visual Studio Express is also free by the way just Google it.
 
Using your LAN IP of the desktop running DB would not work, you need to use the IP of the growl server. Also, you can test this just fine without Visual Studio. Just place the files in the correct folders in the trinity folder. After that you just need a small modification to NotificationManager.cs and your off to the races. Once it is verified working then it would be worth sticking it in the gui and what not. On another note Visual Studio Express is also free by the way just Google it.

Well it looked like to me that Growl was just piggy backing off of localhost. I'll see if I can find out what exactly the IP is on it.
 
Just firing it up with the above code and changing the above variables, DB throws this:

[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(4,9) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(6,10) : error CS1001: Identifier expected
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(6,12) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(7,50) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(8,84) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(9,59) : error CS1001: Identifier expected
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(18,10) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(18,53) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(19,12) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(20,12) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(21,12) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(22,12) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(24,12) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(32,12) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(32,60) : error CS1001: Identifier expected
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(32,62) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(34,36) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(63,32) : error CS1518: Expected class, delegate, enum, interface, or struct
[13:21:11.141 N] Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(65,9) : error CS1022: Type or namespace definition, or end-of-file expected

Going to double check that I pasted everything in correctly.
 
Last edited:
Will take a look at it sometime tomorrow. Just copied and pasted the growl code from that site didn't look over it much to check it.
 
Compiler Error: c:\DB\Plugins\GilesTrinity\Notifications\GrowlNotification.cs(13,28) : error CS0542: 'GrowlSend': member names cannot be the same as their enclosing type

Is the only error I'm getting now.
 
Is the only error I'm getting now.

I assumed it was angry because you used GrowlSend as the class name as well as the function definition within. I changed the function name to GrowlSender instead and now its no longer angry when I call GrowlSend.GrowlSender(...);

Will see now if it notifies my Growl when an item is found.
 
Last edited:
Just found a legendary and got no notification.

I've got my IP set as my default IP for my computer as I'm pretty sure Growl piggyback's off of localhost.

I also set the password as blank "" as growl does not require a password to receive notifications unless you specify one within the growl application; which I have not.
 
Last edited:
Going to attempt using port 23053 and see if that makes a difference. Supposedly that is the standard GNTP port.
 
Unfortunately I don't plan on install Visual Studio any time soon. I just don't have the storage space on my desktop's SSD right now. I'll keep experimenting in demonbuddy for now, but perhaps because that article was 2009, some things have changed since then.

How difficult would it be to simply drag in the two dll files included in the SDK kit and simply hook them into the NotificationManager.cs file? I'm not familiar with C# and how it references dll files inside a .cs file. The actual code at that point seems pretty simple based on the example guide they give.

Do you have time to test it 420 by downloading Growl for Windows and firing up a console app?

homepage: Growl for Windows
sdk link: http://www.growlforwindows.com/gfw/d.ashx?f=connectors/Growl_NET_Connector_SDK.zip
 
Last edited:
Back
Top