Пример #1
0
 public void WriteString(string text, int limit)
 {
     try
     {
         if (text == null)
         {
             binaryWriter.Write((short)0);
         }
         else
         {
             binaryWriter.Write(ConvertidorTipos.StringToByteArray(text, limit));
         }
     }
     catch (Exception exeption)
     {
         throw exeption;
     }
 }
Пример #2
0
        public void loginUsuario()
        {
            byte opCode   = ReadByte();
            byte sizeCode = ReadByte();
            byte headCode = ReadByte();
            byte subCode  = ReadByte();

            byte[] codigo     = ReadBytes(10);
            byte[] contrasena = ReadBytes(6);
            byte   tipo       = ReadByte();

            byte[] TiempoActual = ReadBytes(10);
            byte[] CliVersion   = ReadBytes(3);

            string codigo_     = ConvertidorTipos.ByteArrayToString(codigo);
            string contrasena_ = ConvertidorTipos.ByteArrayToString(contrasena);

            TipoCliente tipo_ = TipoCliente.Espacio;

            switch (tipo)
            {
            case 0x00:
                tipo_ = TipoCliente.Usuario;
                break;

            case 0x01:
                tipo_ = TipoCliente.Espacio;
                break;
            }

            string TiempoActual_ = ConvertidorTipos.ByteArrayToString(TiempoActual);
            string CliVersion_   = ConvertidorTipos.ByteArrayToString(CliVersion);

            byte result = 0x00;

            Log.dBlack("Enviado para ingresar: ({0}){1}", cliente.Puerto.ToString(), codigo_);

            if (CliVersion_.Equals(Config.APP_VERSION))
            {
                Usuario usuario = Usuarios.Login(codigo_, contrasena_);

                if (usuario.USUid == 0)
                {
                    result = 0x02;
                }
                else
                {
                    if (usuario.USUonline == 1)
                    {
                        result = 0x03;
                    }
                    else
                    {
                        result = 0x01;

                        cliente.Tipo = TipoCliente.Usuario;

                        cliente.Usuario = usuario;

                        Usuarios.SetOnline(usuario.USUid, 1);

                        Log.dBlack("Login ({0}): ({1})", cliente.Ip, codigo_);
                    }
                }
            }
            else
            {
                result = 0x06;
            }

            //

            PacketWriter pw = new PacketWriter();

            pw.WriteByte((byte)0xC1);
            pw.WriteByte(sizeCode);
            pw.WriteByte(headCode);
            pw.WriteByte(subCode);
            pw.WriteByte(result);

            cliente.Send(pw.Compile());
        }