/*
         ____  __.  _________            .__        __   
        |    |/ _| /   _____/ ___________|__|______/  |_ 
        |      <   \_____  \_/ ___\_  __ \  \____ \   __\
        |    |  \  /        \  \___|  | \/  |  |_> >  |  
        |____|__ \/_______  /\___  >__|  |__|   __/|__|  
                \/        \/     \/         |__|          
        
        Briefkasten Parser
        © The Don of NYC - 2012
 */

using KNLib;
using System;
using System.Windows.Forms;

namespace Briefkasten_Parser
{
    class Program
    {
        static void Main()
        {
            Application.EnableVisualStyles();
            Console.Title = "Briefkasten Parser";

            KSClient KSC = new KSClient(new Applet("applet.jar"));
            KSC.OnTokenReceived += new KSClient.ReceivedHandler(KSC_OnTokenReceived);
            KSC.Connect(ChatSystem.DE);

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("<ENTER> Knuddes Login");
            Console.ReadLine();

            KSC.Login("", "", "");
        }

        static void KSC_OnTokenReceived(KSClient KSC, String packet)
        {
            String[] token = packet.Split('\0');

            switch (token[0])
            {
                case "u":

                    Console.WriteLine("Erfoglreich eingeloggt.");
                    break;

                case "r":

                    if (token[4].Contains("hat dir gerade"))
                        KSC.SendMessage("/m +");

                    break;

                case "k":

                    if (token[1].Contains("Briefkasten"))
                        new MailBox(token[20]).Show();

                    break;
            }
        }
    }
}
