Example #1
0
        private static void setIP(string ip)
        {
            bool rightFormat = true;

            try
            {
                if (ip == "localhost")
                {
                    _serverIP = IPAddress.Parse("127.0.0.1");
                }
                else
                {
                    _serverIP = IPAddress.Parse(ip);
                }
            }
            catch {
                rightFormat = false;
            }
            if (rightFormat)
            {
                _correctFormat = true;
                Write.Ok("Format IP");
            }
            else
            {
                Write.Er("Format IP");
            }
        }
Example #2
0
        private static void ClientSetup()
        {
            if (_splash)
            {
                AsciiArt();
            }
            bool correctName = false;

            while (!correctName)
            {
                Console.Write("Wpisz swój nick: ");
                name = Console.ReadLine() + char.MinValue;
                if (String.IsNullOrEmpty(name) || name.Length > 24)
                {
                    Console.WriteLine("Nick nie może być pusty lub dłuższy niż 24 znaki.");
                }
                else
                {
                    if (name.Contains(" "))
                    {
                        Console.WriteLine("Nick nie może zawierać spacji.");
                    }
                    else
                    {
                        correctName = true;
                        name       += "<EOF>";
                    }
                }
            }
            while (!_correctFormat || !_correctMaster)
            {
                Console.Write("Pozostaw puste, lub wpisz IP serwera w formacie xxx.xxx.xxx.xxx\n>> ");
                string ip = Console.ReadLine();
                if (String.IsNullOrEmpty(ip))
                {
                    setIP("77.45.24.67");
                }
                else
                {
                    setIP(ip);
                }
                if (_correctFormat)
                {
                    bool correctMaster = true;
                    try
                    {
                        _socket.Connect(_serverIP, 1999);
                    }
                    catch
                    {
                        correctMaster = false;
                        Write.Er("Połączenie z serwerem");
                    }
                    if (correctMaster)
                    {
                        _correctMaster = true;
                    }
                }
            }
            if (_socket.Connected)
            {
                Write.Ok("Połączenie z serwerem");
            }
            _socket.Send(ASCIIEncoding.ASCII.GetBytes(name));
        }