Package net.bnubot.util

Examples of net.bnubot.util.BNetOutputStream


  @Override
  protected void initializeConnection(Task connect) throws Exception {
    s = new Socket(getServer(), getPort());
    is = new BNetInputStream(s.getInputStream());
    os = new BNetOutputStream(s.getOutputStream());
    //Chat
    //os.writeByte(0x03);
    //os.writeByte(0x04);
  }
View Full Code Here


    Out.info(BNFTPConnection.class, "Downloading " + fileName + "...");
    try (
      Socket s = new Socket(cs.server, cs.port);
      BNetInputStream is = new BNetInputStream(s.getInputStream());
      BNetOutputStream os = new BNetOutputStream(s.getOutputStream());
    ) {
      //FTP
      os.writeByte(0x02);

      //File request
      os.writeWord(32 + fileName.length() + 1);
      os.writeWord(0x100);    // Protocol version
      os.writeDWord(PlatformIDs.PLATFORM_IX86)// Platform ID
      os.writeDWord(cs.product.getDword())// Product ID
      os.writeDWord(0);    // Banners ID
      os.writeDWord(0);    // Banners File Extension
      os.writeDWord(0);    // File position
      os.writeQWord(0);    // Filetime
      os.writeNTString(fileName);

      long startTime = System.currentTimeMillis();
      while(is.available() == 0) {
        if(s.isClosed() || (System.currentTimeMillis() - startTime) > 500)
          throw new Exception("BNFTP download failed");
View Full Code Here

              byte[] data = new byte[33];
              is.read(data);
              if(is.readByte() != 0)
                throw new Exception("invalid statstr format\n" + HexDump.hexDump(baos.toByteArray()));

              try (BNetOutputStream bos = new BNetOutputStream(baos)) {
                bos.write(("PX2D[Realm]," + name + ",").getBytes());
                bos.write(data);
                bos.writeByte(0);
              }
              final StatString statstr = new StatString(new BNetInputStream(new ByteArrayInputStream(baos.toByteArray())));

              MCPCharacter c = new MCPCharacter(time, name, statstr);
View Full Code Here

    if(GlobalSettings.packetLog) {
      String msg = "RECV " + packetId.name();
      if(Out.isDebug()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (BNetOutputStream os = new BNetOutputStream(baos)) {
          os.writeByte(packetId.ordinal());
          os.writeWord(packetLength);
          os.write(data);
        }
        msg += "\n" + HexDump.hexDump(baos.toByteArray());
      }
      Out.debugAlways(getClass(), msg);
    }
View Full Code Here

      icon.xSize = icon.getIcon().getIconWidth();
      icon.ySize = icon.getIcon().getIconHeight();
    }

    try (
      BNetOutputStream os = new BNetOutputStream(new FileOutputStream(f));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      BNetOutputStream headerStream = new BNetOutputStream(baos);
    ) {
      Out.debug(IconsDotBniReader.class, "Writing " + f.getName());

      headerStream.writeWord(1); // BNI version
      headerStream.writeWord(0); // Alignment Padding (unused)
      headerStream.writeDWord(icons.length); // numIcons
      headerStream.writeDWord(-1); // dataOffset

      for(BNetIcon icon : icons) {
        headerStream.writeDWord(icon.flags);
        headerStream.writeDWord(icon.xSize);
        headerStream.writeDWord(icon.ySize);

        //Write up to 32 products; stop if we see a null
        for(int product : icon.products) {
          if(product == 0)
            break;
          headerStream.writeDWord(product);
        }
        headerStream.writeDWord(0);
      }


      byte[] header = baos.toByteArray();
      os.writeDWord(header.length);
View Full Code Here

  public void sendPacket(OutputStream out) {
    byte data[] = ((ByteArrayOutputStream)this.out).toByteArray();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try (BNetOutputStream sckout = new BNetOutputStream(baos)) {
      sckout.writeWord(data.length + 3);
      sckout.writeByte(packetId.ordinal());
      sckout.write(data);
    } catch(IOException e) {
      Out.fatalException(e);
    }

    data = baos.toByteArray();
View Full Code Here

    if(GlobalSettings.packetLog) {
      String msg = "RECV " + packetId.name();
      if(Out.isDebug()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (BNetOutputStream os = new BNetOutputStream(baos)) {
          os.writeWord(packetLength);
          os.writeByte(packetId.ordinal());
          os.write(data);
        }
        msg += "\n" + HexDump.hexDump(baos.toByteArray());
      }
      Out.debugAlways(getClass(), msg);
    }
View Full Code Here

  }

  public void sendPacket(OutputStream out) throws IOException, SocketException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try (BNetOutputStream sckout = new BNetOutputStream(baos)) {
      byte raw_data[] = ((ByteArrayOutputStream)this.out).toByteArray();
      sckout.writeWord(raw_data.length + 3);
      sckout.writeByte(packetId.ordinal());
      sckout.write(raw_data);
    } catch(IOException e) {
      Out.fatalException(e);
    }

    byte data[] = baos.toByteArray();
View Full Code Here

    is.reset();
    is.skip(offset);

    try (
      ByteArrayOutputStream baos = new ByteArrayOutputStream(size_unpacked);
      BNetOutputStream os = new BNetOutputStream(baos);
    ) {
      if(f_single_unit) {
        byte[] data = new byte[size_packed];
        is.readFully(data);
        if(f_encrypted)
          MPQUtils.decrypt(data, crc_file-1);

        if(data.length==size_unpacked) {
          // The block is unpacked
        } else {
          // Block is packed
          if(f_compressed) {
            // Multiple compressions are possible
            data = MPQUtils.unpack(data, size_unpacked);
          } else {
            // Just DCLib
            data = Explode.explode(data, 0, data.length, size_unpacked);
          }
        }
        os.write(data);
      } else if(f_imploded | f_compressed) {
        final int block_size = 0x1000;

        int num_blocks = ((size_unpacked-1)/block_size)+2;
        int header[] = new int[num_blocks + (f_has_extra ? 1 : 0)];
        for(int i = 0; i < header.length; i++)
          header[i] = is.readDWord();
        if(f_encrypted)
          MPQUtils.decrypt(header, crc_file-1);

        for(int i = 0; i < num_blocks-1; i++) {
          int length_read=header[i+1]-header[i];
          byte[] data = new byte[length_read];
          is.readFully(data);
          if(f_encrypted)
            MPQUtils.decrypt(data, crc_file++);

          final int out_size;
          if(i==num_blocks-2) {
            if((size_unpacked & 0xFFF) == 0) {
              // The last block could be either [0] or [block_size]
              out_size = size_unpacked-(block_size*i);
            } else {
              out_size = (size_unpacked & 0xFFF);
            }
          } else {
            out_size = block_size;
          }

          if(length_read==out_size) {
            // The block is unpacked
          } else {
            // Block is packed
            if(f_compressed) {
              // Multiple compressions are possible
              data = MPQUtils.unpack(data, out_size);
            } else {
              // Just DCLib
              data = Explode.explode(data, 0, data.length, out_size);
            }
          }
          os.write(data);
        }
      } else {
        // File is not compressed
        int block_size = f_encrypted ? 0x1000 : 0x60000;
        for(int pos=0; pos<size_packed; pos += block_size) {
          int length_read = block_size;
          if(length_read + pos > size_packed)
            length_read = size_packed % block_size;

          byte[] data = new byte[length_read];
          is.readFully(data);
          if(f_encrypted)
            MPQUtils.decrypt(data, crc_file++);
          os.write(data);
        }
      }
      return new ByteArrayInputStream(baos.toByteArray());
    }
  }
View Full Code Here

TOP

Related Classes of net.bnubot.util.BNetOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.