﻿using System;
using System.Collections.Generic;

using NetworkCommsDotNet;
using NetworkCommsDotNet.Connections;
using NetworkCommsDotNet.Connections.TCP;

namespace EzClientLib
{
    public static class Connectivity
    {
        private static Connection peer;
        public static Connection Peer
        {
            get
            {
                if (peer == null) {
                    throw new Exception("Connection peer not initialized! Did you called Connect() ?");
                }

                return peer;
            }

            set { peer = value; }
        }

        public static string ServerAddress
        { 
            get;
            set;
        }

        public static int ServerPort
        {
            get;
            set;
        }

        public static void Connect()
        {
            //MessageHandler.RegisterPacketHandlers();
            //ServerAddress = "127.0.0.1";
            //ServerPort = 6990;

            ConnectionInfo connectionInfo = new ConnectionInfo(ServerAddress, ServerPort);
            Peer = TCPConnection.GetConnection(connectionInfo);
        }

        public static void Connect(string serverAddress, int serverPort)
        {
            ServerAddress = serverAddress;
            ServerPort = serverPort;
            Connect();
        }
    }
}
