Package net.bnubot.util

Examples of net.bnubot.util.BNetInputStream


        throw new Exception("Assertion failed: ((MCPChunk1.length != 4) || (MCPChunk2.length != 12))");

      Out.info(MCPConnection.class, "Connecting to MCP server " + server + ":" + port);

      s = new Socket(server, port);
      dis = new BNetInputStream(s.getInputStream());
      dos = new DataOutputStream(s.getOutputStream());

      connected = true;

      //MCP
      dos.writeByte(1);

      try (MCPPacket p = new MCPPacket(MCPPacketID.MCP_STARTUP)) {
        for(int i = 0; i < 4; i++)
          p.writeDWord(MCPChunk1[i]);
        for(int i = 0; i < 12; i++)
          p.writeDWord(MCPChunk2[i]);
        p.writeNTString(uniqueName);
        p.sendPacket(dos);
      }

      while(!s.isClosed() && connected) {
        if(dis.available() > 0) {
          MCPPacketReader pr = new MCPPacketReader(dis);
          BNetInputStream is = pr.getData();
          switch(pr.packetId) {
          case MCP_STARTUP: {
            /* (DWORD)     Result
             *
             * 0x00: Success
             * 0x02, 0x0A-0x0D: Realm Unavailable: No Battle.net connection detected.
             * 0x7E: CDKey banned from realm play.
             * 0x7F: Temporary IP ban "Your connection has been
             *  temporarily restricted from this realm. Please
             *  try to log in at another time"
             */
            int result = is.readDWord();
            switch(result) {
            case 0:
              recieveRealmInfo("Realm logon success");

              try (MCPPacket p = new MCPPacket(MCPPacketID.MCP_CHARLIST2)) {
                p.writeDWord(8)//Nubmer of chars to list
                p.sendPacket(dos);
              }
              break;
            case 0x02:
            case 0x0A:
            case 0x0B:
            case 0x0C:
            case 0x0D:
              recieveRealmError("Realm server did not detect a Battle.net connection");
              setConnected(false);
              break;
            case 0x7E:
              recieveRealmError("Your CD-Key is banned from realm play");
              setConnected(false);
              break;
            case 0x7F:
              recieveRealmError("You are temporarily banned from the realm");
              setConnected(false);
              break;
            }
            break;
          }

          case MCP_CHARLIST2: {
            /* (WORD)     Number of characters requested
             * (DWORD)     Number of characters that exist on this account
             * (WORD)     Number of characters returned
             *
             * For each character:
             * (DWORD)     Seconds since January 1 00:00:00 UTC 1970
             * (STRING)    Name
             * (WORD)     Flags
             * (STRING)    Character statstring
             */
            is.readWord();
            is.readDWord();
            int numChars = is.readWord();

            List<MCPCharacter> chars = new ArrayList<MCPCharacter>(numChars);

            for(int i = 0; i < numChars; i++) {
              final long time = (1000L * is.readDWord()) - System.currentTimeMillis();
              final String name = is.readNTString();

              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              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);

              if(Out.isDebug(getClass()))
                Out.debugAlways(getClass(), c.toString());

              chars.add(c);
            }

            recieveCharacterList(chars);
            break;
          }

          case MCP_CHARLOGON: {
            /* (DWORD) Result
             *
             * 0x00: Success
             * 0x46: Player not found
             * 0x7A: Logon failed
             * 0x7B: Character expired
             */
            int result = is.readDWord();
            switch(result) {
            case 0x00:
              recieveRealmInfo("Character logon success");
              break;
            case 0x46:
View Full Code Here


  }

  protected abstract void parse(BNetInputStream is) throws IOException;

  public BNetInputStream getData() {
    return new BNetInputStream(new ByteArrayInputStream(data));
  }
View Full Code Here

    this.fileName = fileName;

    // Make sure mark support is available
    if(!is0.markSupported())
      is0 = new BufferedInputStream(is0);
    is = new BNetInputStream(is0);
    is.mark(Integer.MAX_VALUE);

    // Search for the MPQ header
    final int offset_mpq = findHeader();

    // Jump to the beginning of the archive
    is.reset();
    is.skip(offset_mpq);

    // 32-byte header
    is.skip(4); //int file_format = is.readDWord();
    is.skip(4); //int header_size = is.readDWord();
    int archive_size = is.readDWord();
    is.skip(2); //short format_version = is.readWord();
    is.skip(2); //short block_size = is.readWord();
    final int offset_htbl = is.readDWord();
    final int offset_btbl = is.readDWord();
    final int count_htbl = is.readDWord() << 2;
    final int num_files = is.readDWord();
    final int count_btbl = num_files << 2;

    // Jump to the beginning of the archive
    is.reset();
    is.skip(offset_mpq);

    // Read the entire archive
    byte[] data = new byte[archive_size];
    is.readFully(data);

    // Rebuild the InputStream with just the archive data
    is = new BNetInputStream(new ByteArrayInputStream(data));
    is.mark(archive_size);

    // Jump to the hash table
    is.reset();
    is.skip(offset_htbl);
View Full Code Here

TOP

Related Classes of net.bnubot.util.BNetInputStream

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.