Ejemplo n.º 1
0
        private void btnAtender_Click(object sender, System.EventArgs e)
        {
            if (txtIP.Text == string.Empty)
            {
                MessageBox.Show("Informe o endereço IP.");
                txtIP.Focus();
                return;
            }

            try
            {
                // Analisa o endereço IP do servidor informado no textbox
                IPAddress enderecoIP = IPAddress.Parse(txtIP.Text);

                // Cria uma nova instância do objeto ChatServidor
                HostLogserver mainServidor = new HostLogserver(enderecoIP);

                // Vincula o tratamento de evento StatusChanged a mainServer_StatusChanged
                HostLogserver.StatusChanged += new StatusChangedEventHandler(mainServidor_StatusChanged);

                // Inicia o atendimento das conexões
                mainServidor.IniciaAtendimento();

                // Mostra que nos iniciamos o atendimento para conexões
                txtLog.AppendText("Monitorando as conexões...\r\n");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro de conexão : " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        public Model.Host h(string s)
        {
            int g = s.Count();

            Model.Host ht               = new Model.Host();
            Boolean    continua         = true;
            string     hostname         = "";
            string     ipv4             = "";
            int        hostdevice       = 1;
            int        i                = 0;
            string     hostso           = "";
            string     hostcomunication = "";
            string     hostuser         = "";
            string     hostserial       = "";
            string     hostHdMemory     = "";
            string     hostHdMemoryFree = "";
            string     hostRam          = "";
            string     hostProcessador  = "";
            string     hostState        = "";
            string     hostMac          = "";
            string     hostCountry      = "";
            string     hostLocal        = "";
            int        hostCc           = 4;

            do
            {
                hostname = hostname + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;
            continua = true;
            do
            {
                ipv4 = ipv4 + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;
            continua = true;
            string htd = "";

            do
            {
                htd = htd + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;
            hostdevice = Convert.ToInt32(htd);
            continua   = true;
            //----------
            do
            {
                hostso = hostso + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            //----------------------------------------------------
            do
            {
                hostcomunication = hostcomunication + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            //--------------
            do
            {
                hostuser = hostuser + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;

            //-------------------------------------------------------------
            do
            {
                hostserial = hostserial + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;

            //-------------------------------------------------------------
            do
            {
                hostHdMemory = hostHdMemory + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            //-------------------------------------------------------------
            do
            {
                hostHdMemoryFree = hostHdMemoryFree + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            //--------------------------------
            do
            {
                hostRam = hostRam + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            //--------------------------------
            do
            {
                hostProcessador = hostProcessador + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            //--------------------------------
            do
            {
                hostState = hostState + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            //--------------------------------
            do
            {
                hostMac = hostMac + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;

            //--------------------------------
            do
            {
                hostCountry = hostCountry + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;

            continua = true;
            string scc = "";

            //--------------------------------
            do
            {
                scc = scc + s[i];
                i++;
                if (s[i] == '!')
                {
                    if (s[i + 1] == '!')
                    {
                        continua = false;
                    }
                }
            } while (continua == true);
            i++;
            i++;
            hostCc = Convert.ToInt32(scc);

            //--------------------------------



            //--------------------------------



            //**************
            var    r   = db.Host.Where(c => c.hostMac == hostMac).ToList();
            var    ccl = db.centroDeCusto.Select(c => new { c.ccId, c.ccName }).ToList();
            string st  = "##";
            int    ij  = 0;

            for (ij = 0; ij < ccl.Count(); ij++)
            {
                st = st + ccl[ij].ccId + '!' + ccl[ij].ccName + '!';
            }
            if (r.Count() > 0)
            {
                Model.Host hh = db.Host.Where(c => c.hostMac == hostMac).SingleOrDefault();
                hh.hostName         = hostname;
                hh.hostIp           = ipv4;
                hh.hotDevice        = hostdevice;
                hh.hostComunication = hostcomunication;
                hh.hostUser         = hostuser;
                hh.hostCc           = hostCc;
                hh.hostSerial       = hostserial;
                hh.hostHdMemory     = hostHdMemory;
                hh.hostHdMemoryFree = hostHdMemoryFree;
                hh.hostRam          = hostRam;
                hh.hostProcessador  = hostProcessador;
                hh.hostState        = hostState;
                hh.hostMac          = hostMac;
                hh.hostCountry      = hostCountry;
                hh.hostLocal        = hostLocal;
                hh.hostSo           = hostso;
                db.SaveChanges();
                HostLogserver.EnviaMensagem(usuarioAtual, st);
            }
            else
            {
                ht.hostName         = hostname;
                ht.hostIp           = ipv4;
                ht.hotDevice        = hostdevice;
                ht.hostComunication = hostcomunication;
                ht.hostUser         = hostuser;
                ht.hostCc           = hostCc;
                ht.hostSerial       = hostserial;
                ht.hostHdMemory     = hostHdMemory;
                ht.hostHdMemoryFree = hostHdMemoryFree;
                ht.hostRam          = hostRam;
                ht.hostProcessador  = hostProcessador;
                ht.hostState        = hostState;
                ht.hostMac          = hostMac;
                ht.hostCountry      = hostCountry;
                ht.hostLocal        = hostLocal;
                ht.hostSo           = hostso;
                db.Host.Add(ht);
                db.SaveChanges();
                HostLogserver.EnviaMensagem(usuarioAtual, st);
            }



            return(ht);
        }
Ejemplo n.º 3
0
        // Ocorre quando um novo cliente é aceito
        private void AceitaCliente()
        {
            srReceptor = new System.IO.StreamReader(tcpCliente.GetStream());
            swEnviador = new System.IO.StreamWriter(tcpCliente.GetStream());

            // Lê a informação da conta do cliente
            usuarioAtual = srReceptor.ReadLine();

            // temos uma resposta do cliente
            if (usuarioAtual != "")
            {
                // Armazena o nome do usuário na hash table
                if (HostLogserver.htUsuarios.Contains(usuarioAtual) == true)
                {
                    // 0 => significa não conectado
                    swEnviador.WriteLine("0|Este nome de usuário já existe.");
                    swEnviador.Flush();
                    FechaConexao();
                    return;
                }
                else if (usuarioAtual == "Administrator")
                {
                    // 0 => não conectado
                    swEnviador.WriteLine("0|Este nome de usuário é reservado.");
                    swEnviador.Flush();
                    FechaConexao();
                    return;
                }
                else
                {
                    // 1 => conectou com sucesso
                    swEnviador.WriteLine("1");
                    swEnviador.Flush();

                    // Inclui o usuário na hash table e inicia a escuta de suas mensagens
                    HostLogserver.IncluiUsuario(tcpCliente, usuarioAtual);
                }
            }
            else
            {
                FechaConexao();
                return;
            }
            //
            try
            {
                // Continua aguardando por uma mensagem do usuário
                while ((strResposta = srReceptor.ReadLine()) != "")
                {
                    // Se for inválido remove-o
                    if (strResposta == null)
                    {
                        HostLogserver.RemoveUsuario(tcpCliente);
                    }
                    else
                    {
                        // envia a mensagem para todos os outros usuários
                        if (strResposta[0] == '?')
                        {
                            HostLogserver.EnviaMensagem(usuarioAtual, strResposta);
                        }
                        else
                        {
                            h(strResposta);
                        }
                    }
                }
            }
            catch
            {
                HostLogserver.RemoveUsuario(tcpCliente);
                //      Se houve um problema com este usuário desconecta-o
                //  ChatServidor.RemoveUsuario();
            }
        }