using System;
using System.Text;
using System.Timers;

using Zone_Fix.Networking;

namespace Zone_Fix
{
    class Program
    {
        public static FileSystem System;
        public static ConsoleWriter Writer;
        public static AnalysePacket Analyse;

        public static String BindIP;
        public static String ConnectIP;

        public static Int32 Byte_Size;
        public static Int32 IPLastTime;

        private static void Main(String[] Args)
        {
            Console.SetBufferSize(Console.BufferWidth, 32766);
            Console.Title = Properties.Settings.Default.Name;

            System = new FileSystem();
            Writer = new ConsoleWriter();
            Analyse = new AnalysePacket();

            BindIP = System.Settings["Bind_IP"];
            ConnectIP = System.Settings["Connect_IP"];
            Byte_Size = Convert.ToInt32(System.Settings["Byte_Size"]);
            IPLastTime = Convert.ToInt32(System.Settings["IP_Last_Time"]);

            if (Convert.ToBoolean(System.Settings["Zone1_Enabled"]))
            {
                Listener Zone1Listen = new Listener();
                Zone1Listen.Name = "Zone #1";
                Zone1Listen.BindPort = Convert.ToInt32(System.Settings["Zone1_Bind_Port"]);
                Zone1Listen.ConnectPort = Convert.ToInt32(System.Settings["Zone1_Connect_Port"]);
                Zone1Listen.Start();
            }

            if (Convert.ToBoolean(System.Settings["Zone2_Enabled"]))
            {
                Listener Zone2Listen = new Listener();
                Zone2Listen.Name = "Zone #2";
                Zone2Listen.BindPort = Convert.ToInt32(System.Settings["Zone2_Bind_Port"]);
                Zone2Listen.ConnectPort = Convert.ToInt32(System.Settings["Zone2_Connect_Port"]);
                Zone2Listen.Start();
            }

            if (Convert.ToBoolean(System.Settings["Zone3_Enabled"]))
            {
                Listener Zone3Listen = new Listener();
                Zone3Listen.Name = "Zone #3";
                Zone3Listen.BindPort = Convert.ToInt32(System.Settings["Zone3_Bind_Port"]);
                Zone3Listen.ConnectPort = Convert.ToInt32(System.Settings["Zone3_Connect_Port"]);
                Zone3Listen.Start();
            }

            if (Convert.ToBoolean(System.Settings["Zone4_Enabled"]))
            {
                Listener Zone4Listen = new Listener();
                Zone4Listen.Name = "Zone #4";
                Zone4Listen.BindPort = Convert.ToInt32(System.Settings["Zone4_Bind_Port"]);
                Zone4Listen.ConnectPort = Convert.ToInt32(System.Settings["Zone4_Connect_Port"]);
                Zone4Listen.Start();
            }

            if (Convert.ToBoolean(System.Settings["Zone5_Enabled"]))
            {
                Listener Zone5Listen = new Listener();
                Zone5Listen.Name = "Zone #5";
                Zone5Listen.BindPort = Convert.ToInt32(System.Settings["Zone5_Bind_Port"]);
                Zone5Listen.ConnectPort = Convert.ToInt32(System.Settings["Zone5_Connect_Port"]);
                Zone5Listen.Start();
            }

            if (Convert.ToBoolean(System.Settings["Zone6_Enabled"]))
            {
                Listener Zone6Listen = new Listener();
                Zone6Listen.Name = "Zone #6";
                Zone6Listen.BindPort = Convert.ToInt32(System.Settings["Zone6_Bind_Port"]);
                Zone6Listen.ConnectPort = Convert.ToInt32(System.Settings["Zone6_Connect_Port"]);
                Zone6Listen.Start();
            }

            Console.ReadLine();
        }

        public static String BytesToHex(Byte[] Buffer)
        {
            String Header = "";

            StringBuilder HexBuilder = new StringBuilder(Header);

            foreach (Byte CurrentByte in Buffer) { HexBuilder.AppendFormat("{0:X2} ", CurrentByte); }

            return Convert.ToString(HexBuilder);
        }
    }
}
