Esempio n. 1
0
        private void OnConnectCallback(IAsyncResult ar)
        {
            Socket sock = (Socket)ar.AsyncState;
            if (sock == null) return;

            IPEndPoint ep = null;
            try
            {
                sock.EndConnect(ar);
                ep = sock.RemoteEndPoint as IPEndPoint;

                _TCP = new ATCPConnector(sock, Uid64.CreateNewSync().Data, NetHelper.READ_BUFFER_BIG);
                _TCP.DisconnectEvent += OnDisconnectEventHandler;
                _TCP.ReceiveAction += OnReceveDataHandler;
                _TCP.ReceiveComAction += OnReceiveCommandHandler;
            }
            catch (SocketException ex){
                sock.Close();
                sock = null;
                NetLogger.Log(ex);
                return;
            }

            _isActive = true;
            if (ep != null) { NetLogger.Log("Connected to " + sock.RemoteEndPoint); }
            ConnectEvent?.Invoke(this, _TCP);
        }
Esempio n. 2
0
        private void NCAutorizeNewClient(IConnector connector, ArgComAutorize arg)
        {
            if (arg == null || connector == null)
            {
                return;
            }

            ATCPConnector atcpcon = connector as ATCPConnector;

            if (atcpcon == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(arg.Login) && arg.Password == "Password")
            {
                _autorizator.RemoveConnector(connector.UniqueID);

                ArgUniqueID argClientID = new ArgUniqueID(NComSendClientID.uniqueID);
                argClientID.UniqueID = Uid64.CreateNewSync().Data;
                TeamPainterTCPClient client = new TeamPainterTCPClient(atcpcon, argClientID.UniqueID, arg.Login);

                bool added = _worker.AddClient(client);
                if (!added)
                {
                    client.Disconnect(); return;
                }

                lvClients.Invoke((MethodInvoker) delegate
                {
                    ListViewItem lvi = lvClients.Items[client.Connector.UniqueID.ToString()];
                    if (lvi != null)
                    {
                        lvi.Name             = client.UniqueID.ToString();
                        lvi.SubItems[0].Text = client.UniqueID.ToString();
                        lvi.SubItems[1].Text = arg.Login;

                        lvi.BackColor = Color.WhiteSmoke;
                        lvi.ForeColor = Color.Black;

                        lvClients.Invalidate();
                    }
                });

                connector.SendCommand(argClientID);
            }
        }