Beispiel #1
0
        public App()
        {
            WanService.GetExternalIpAdress(out string ip);
            var tsk = WanService.CheckRouterCapabilities();

            if (ip == String.Empty)
            {
                ip = "not found";
            }
            InitializeComponent();
            UiChanger = this;
            SetText("Ip address is: " + IpAdress);
            SetText("Host name is: " + HostName);
            SetText("Free TCP port is: " + TcpPort);
            SetText("Checking router capabilities...");
            SetText("External IP is: " + ip);
            var success = tsk.Result;

            SetText(success ? "Your router configuration is correct" : "Your router configuration is incorrect");
            SetStartup();
            if (Properties.Settings.Default.run_at_startup)
            {
                ShowBallonTipOnStartUp("Lazy steam server is running.");
            }
            var tcpServer = new TcpServer(SetText1, TcpPort);

            tcpServer.Start();
            UdpServer.Start();
            SetText("Udp Started\nTcp Started");
            if (Properties.Settings.Default.unique_id == 0)
            {
                Properties.Settings.Default.unique_id = GenerateRandomId();
                Properties.Settings.Default.Save();
            }
        }
Beispiel #2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            Task.Run(() =>
            {
//                if (!WanService.GetExternalIpAdress(out string extIp))
//                {
//                    MessageBox.Show("Error when getting external IP!");
//                    //return;
//                }
//
//                if (!WanService.OpenNewPortForUpnp(out int extPort))
//                {
//                    MessageBox.Show("Error when opening new port for UnPnP!");
//                    //return;
//                }
//                MessageBox.Show(extIp + " port: " + extPort);

                WanService.DisplayallPorts();
            });
        }
        public void AcceptCallback(IAsyncResult ar)
        {
            Socket socket;

            try
            {
                socket = ServerSocket.EndAccept(ar);
                ServerSocket.BeginAccept(AcceptCallback, null);
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            ClientSockets.Add(socket);

            var com = ConnectionCodes.RecieveCom(RecieveToString(socket)); // FIRST STEP

            if (com != ConnectionCodes.CLIENT_BEGIN_SETUP)
            {
                return;
            }

            if (!CheckIfCodeIsValid(socket)) //SECOND STEP (RECIEVING security_code)
            {
                return;
            }

            var aesCrypt = new AesCypher();

            SendMessageFromString(ConnectionCodes.EncryptionKeyExchange(aesCrypt.AlgoKeyHexString), socket); //THIRD STEP SEND ENC CODE

            //FOURTH STEP GET CLIENT ID
            var recieveString = RecieveToString(socket);

            com = ConnectionCodes.RecieveCom(recieveString);
            if (com != ConnectionCodes.CLIENT_PORT_REQUEST)
            {
                return;
            }

            if (ConnectionCodes.ClientId(recieveString) == string.Empty)
            {
                return;
            }
            CyphersDictionary.Add(ConnectionCodes.ClientId(recieveString), aesCrypt); //ADD ID TO DICT

            var extIp   = string.Empty;
            var extPort = 0;

            if (!WanService.GetExternalIpAdress(out extIp))
            {
                MessageBox.Show("Error when getting external IP!");
                return;
            }

            if (!WanService.OpenNewPortForUpnp(out extPort))
            {
                MessageBox.Show("Error when opening new port for UnPnP!");
                return;
            }

            SendMessageFromString(ConnectionCodes.SetupPortResponse(extPort, extIp), socket);          //FIFTH STEP SEND EXTERNAL PORT AND IP DATA

            if (ConnectionCodes.RecieveCom(RecieveToString(socket)) != ConnectionCodes.CLIENT_CONFIRM) //SIXTH STEP CONFIRMATION
            {
                return;
            }
            SendMessageFromString(ConnectionCodes.SendCom(ConnectionCodes.SERVER_CONFIRM), socket);
        }