Examples of BNetInputStream


Examples of net.bnubot.util.BNetInputStream

  public BNCSWarden(BNCSConnection c, byte[] seed) throws IOException {
    this.c = c;

    BNLSConnection bnls = BNLSManager.getWardenConnection();
    int cookie_out = c.getConnectionSettings().botNum;
    BNetInputStream is = bnls.sendWarden0(
        cookie_out,
        c.getProductID().getDword(),
        seed);

    byte u = is.readByte();
    int cookie = is.readDWord();
    byte result = is.readByte();
    short dataLen = is.readWord();
    if(u != 0)
      throw new IOException("wrong useage");
    if(cookie != cookie_out)
      throw new IOException("wrong cookie");
    if(result != 0)
View Full Code Here

Examples of net.bnubot.util.BNetInputStream

  }

  public void processWardenPacket(byte[] payload, OutputStream os) throws IOException {
    BNLSConnection bnls = BNLSManager.getWardenConnection();
    int cookie_out = c.getConnectionSettings().botNum;
    BNetInputStream is = bnls.sendWarden1(cookie_out, payload);

    byte u = is.readByte();
    int cookie = is.readDWord();
    byte result = is.readByte();
    short dataLen = is.readWord();
    byte[] data = new byte[dataLen];
    is.read(data);

    if(u != 1)
      throw new IOException("wrong useage");
    if(cookie != cookie_out)
      throw new IOException("wrong cookie");
View Full Code Here

Examples of net.bnubot.util.BNetInputStream

    int port = getPort();
    InetAddress address = MirrorSelector.getClosestMirror(getServer(), port);
    dispatchRecieveInfo("Connecting to " + address + ":" + port + ".");
    socket = new Socket(address, port);
    socket.setKeepAlive(true);
    dtInputStream = new BNetInputStream(socket.getInputStream());
    dtOutputStream = new DataOutputStream(socket.getOutputStream());

    // Connected
    connect.updateProgress("Connected");
  }
View Full Code Here

Examples of net.bnubot.util.BNetInputStream

    while(isConnected() && !socket.isClosed() && !disposed) {
      if(dtInputStream.available() <= 0) {
        sleep(200);
      } else {
        DTPacketReader pr = new DTPacketReader(dtInputStream);
        BNetInputStream is = pr.getData();

        switch(pr.packetId) {
        case PKT_LOGON: {
          /* (BYTE)   Status
           *
           * Status codes:
           * 0x00 - (C) Passed
           * 0x01 - (A) Failed
           * 0x02 - (C) Account created
           * 0x03 - (A) Account online.
           * Other: Unknown (failure).
           */
          int status = is.readByte();
          switch(status) {
          case 0x00:
            dispatchRecieveInfo("Login accepted.");
            break;
          case 0x01:
View Full Code Here

Examples of net.bnubot.util.BNetInputStream

      if(dtInputStream.available() <= 0) {
        sleep(200);
      } else {
        DTPacketReader pr = new DTPacketReader(dtInputStream);
        BNetInputStream is = pr.getData();

        switch(pr.packetId) {
        case PKT_ENTERCHANNEL: {
          /* (CString)   Channel
           * (UInt32)  Flags
           * (CString)  MOTD
           *
           * Flags:
           * 0x01 : Registered
           * 0x02 : Silent
           * 0x04 : Admin
           */

          String channel = is.readNTString();
          int flags = is.readDWord();
          String motd = is.readNTString();

          dispatchJoinedChannel(channel, flags);
          dispatchRecieveInfo(motd);
          break;
        }

        case PKT_CHANNELUSERS: {
          /* (Byte)    User Count
           * (void)    User Data
           *
           * For each user...
           *   (CString)  Username
           *   (UInt32)  Flags
           *
           * User Flags:
           * 0x01 : Operator
           * 0x02 : Ignored
           * 0x04 : Admin
           * 0x08 : NetOp
           */
          int numUsers = is.readByte();
          for(int i = 0; i < numUsers; i++) {
            String username = is.readNTString();
            int flags = is.readDWord();

            dispatchChannelUser(findCreateBNUser(username, flags));
          }
          break;
        }

        case PKT_USERUPDATE: {
          /* (CString)  Username
           * (UInt32)  Flags
           */
          String username = is.readNTString();
          int flags = is.readDWord();

          dispatchChannelUser(findCreateBNUser(username, flags));
          break;
        }

        case PKT_CHANNELJOIN: {
          /* (CString)  Username
           * (UInt32)  Flags
           */
          String username = is.readNTString();
          int flags = is.readDWord();

          dispatchChannelJoin(findCreateBNUser(username, flags));
          break;
        }

        case PKT_CHANNELLEAVE: {
          /* (CString)  Username
           */
          String username = is.readNTString();

          dispatchChannelLeave(findCreateBNUser(username, null));
          break;
        }

        case PKT_CHANNELCHAT: {
          /* (Byte)    Chat Type
           * (CString)  From
           * (CString)  Message
           *
           * Chat Type values:
           * 0x00 : Normal
           * 0x01 : Self Talking
           * 0x02 : Whisper To
           * 0x03 : Whisper From
           * 0x04 : Emote
           * 0x05 : Self Emote
           */
          int chatType = is.readByte();
          String username = is.readNTString();
          ByteArray text = new ByteArray(is.readNTBytes());

          // Get a BNetUser object for the user
          BNetUser user = null;
          if(myUser.equals(username))
            user = myUser;
          else
            user = getCreateBNetUser(username, myUser);

          switch(chatType) {
          case 0x00: // Normal
          case 0x01: // Self talking
            dispatchRecieveChat(user, text);
            break;
          case 0x02: // Whisper to
            dispatchWhisperSent(user, text.toString());
            break;
          case 0x03: // Whisper from
            dispatchWhisperRecieved(user, text.toString());
            break;
          case 0x04: // Emote
          case 0x05: // Self Emote
            dispatchRecieveEmote(user, text.toString());
            break;
          default:
            Out.debugAlways(getClass(), "Unexpected chat type 0x" + Integer.toHexString(chatType) + " from " + username + ": " + text);
            break;
          }

          break;
        }

        case PKT_UNKNOWN_0x22: {
          int unknown = is.readDWord();
          String text = is.readNTString();
          switch(unknown) {
          case 0x00:
            dispatchRecieveInfo(text);
            break;
          case 0x01:
View Full Code Here

Examples of net.bnubot.util.BNetInputStream

  int packetLength;
  byte data[];

  public BNLSPacketReader(InputStream rawis) throws IOException {
    // Operates on a socket, which we don't want to close; suppress the warning
    @SuppressWarnings("resource")
    BNetInputStream is = new BNetInputStream(rawis);

    packetLength = is.readWord() & 0x0000FFFF;
    packetId = BNLSPacketId.values()[is.readByte() & 0x000000FF];
    assert(packetLength >= 3);

    data = new byte[packetLength-3];
    for(int i = 0; i < packetLength-3; i++)
      data[i] = is.readByte();

    if(GlobalSettings.packetLog) {
      String msg = "RECV " + packetId.name();
      if(Out.isDebug()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

Examples of net.bnubot.util.BNetInputStream

  public byte[] getData() {
    return data;
  }

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

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

Examples of net.bnubot.util.BNetInputStream

  }

  protected abstract void parse(BNetInputStream is) throws IOException;

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

Examples of net.bnubot.util.BNetInputStream

    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
Copyright © 2018 www.massapi.com. 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.