Exemplo n.º 1
0
        public void EjecutarMensaje(PaqueteCliente mensaje, ServidorMonopolio.Modelo.Jugador jugador, ServidorMonopolio.Modelo.Juego juego, ServidorMonopolio.ServerForm VentanaServidor)
        {
            IMensajeCliente IMensaje = Verificar_Mensaje(mensaje, VentanaServidor);

            if (IMensaje == null)
            {
                return;
            }

            IMensaje.Ejecutar(mensaje, jugador, juego, VentanaServidor);
        }
Exemplo n.º 2
0
        private void RecibiendoMensajeCliente(IAsyncResult AsyncResult)
        {
            int     nCountReadBytes = 0;
            string  mensaje_lectura = "";
            Jugador _jugador        = null;

            lock (_juego.JugadoresConectados)
            {
                try
                {
                    _jugador = _juego.JugadoresConectados.Find(x => x.Cliente == (TcpClient)AsyncResult.AsyncState);

                    if (_jugador == null)
                    {
                        return;
                    }

                    nCountReadBytes = _jugador.Cliente.GetStream().EndRead(AsyncResult);

                    mensaje_lectura = Encoding.ASCII.GetString(_jugador.Lectura, 0, nCountReadBytes).Trim();

                    _paquete = new PaqueteCliente(mensaje_lectura.Split(';'));

                    _mensajeManager.EjecutarMensaje(_paquete, _jugador, _juego, _form);
                }
                catch (IndexOutOfRangeException)
                {
                    _form.Imprimir_Log("Error al decodificar el mensaje: " + mensaje_lectura);
                }
                catch (System.IO.IOException)
                {
                    _form.Imprimir_Log("ATENCION: El jugador: " + _jugador.Usuario + " se ha desconectado.");
                    RemoverJugador(_jugador);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error General", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (_jugador != null)
                    {
                        if (_jugador.Cliente.Connected)
                        {
                            _jugador.Lectura = new byte[512];
                            _jugador.Cliente.Client.BeginReceive(_jugador.Lectura, 0, _jugador.Lectura.Length, 0, new AsyncCallback(RecibiendoMensajeCliente), _jugador.Cliente);
                            //_jugador.Cliente.GetStream().BeginRead(_jugador.Lectura, 0, _jugador.Lectura.Length, RecibiendoMensajeCliente, _jugador.Cliente);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private IMensajeCliente Verificar_Mensaje(PaqueteCliente Split, ServidorMonopolio.ServerForm VentanaServidor)
        {
            int             Codigo_Entrada = -1;
            IMensajeCliente IMensaje       = null;

            try
            {
                Codigo_Entrada = Split.PopInt();

                if (!_mensajesCliente.TryGetValue(Codigo_Entrada, out IMensaje))
                {
                    VentanaServidor.Imprimir_Log("Codigo de entrada desconocido: " + Codigo_Entrada);
                    return(null);
                }

                return(IMensaje);
            }
            catch (Exception)
            {
                VentanaServidor.Imprimir_Log("Error al convertir el código de entrada: " + Split.GetITem(0));
                return(null);
            }
        }