Examples of BNetInputStream


Examples of net.bnubot.core.BNetInputStream

        p.SendPacket(dos, true);
       
      while(!s.isClosed() && connected) {
        if(dis.available() > 0) {
          MCPPacketReader pr = new MCPPacketReader(dis, true);
          BNetInputStream is = pr.getData();
          switch(pr.packetId) {
          case MCPCommandIDs.MCP_STARTUP: {
            /* (DWORD)     Result
             *
             * 0x00: Success
             * 0x0C: No Battle.net connection detected
             * 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");
             
              p = new MCPPacket(MCPCommandIDs.MCP_CHARLIST2);
              p.writeDWord(8)//Nubmer of chars to list
              p.SendPacket(dos, true);
              break;
            case 0x0C:
              recieveRealmError("Realm server did not detect a Battle.net connection");
              setConnected(false);
              break;
            case 0x7F:
              recieveRealmError("You are temporarily banned from the realm");
              setConnected(false);
              break;
            }
            break;
          }
          case MCPCommandIDs.MCP_CHARLIST2: {
            recieveRealmError(HexDump.hexDump(pr.data));
            /* (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();
           
            long minTime = 0;
            String maxCharname = null;
           
            for(int i = 0; i < numChars; i++) {
              int secs = is.readDWord();
              String charname = is.readNTString();
              StatString statstr = new StatString("PX2D[Realm]," + charname + "," + is.readNTString());
             
              long time = new Date().getTime();
              time = (((long)secs) * 1000) - time;
             
              recieveRealmInfo(TimeFormatter.formatTime(time) + " - " + charname + " - " + statstr.toString());
View Full Code Here

Examples of net.bnubot.core.BNetInputStream

  int packetId;
  int packetLength;
  byte data[];
 
  public MCPPacketReader(InputStream rawis, boolean packetLog) throws IOException {
    BNetInputStream is = new BNetInputStream(rawis);
   
    packetLength = is.readWord() & 0x0000FFFF;
    packetId = is.readByte() & 0x000000FF;
    assert(packetLength >= 3);
   
    data = new byte[packetLength-3];
    for(int i = 0; i < packetLength-3; i++) {
      data[i] = is.readByte();
    }
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BNetOutputStream os = new BNetOutputStream(baos);
    os.writeByte(packetId);
View Full Code Here

Examples of net.bnubot.core.BNetInputStream

    if(packetLog)
      Out.info("MCPPacketReader", "RECV MCP\n" + HexDump.hexDump(baos.toByteArray()));
  }
 
  public BNetInputStream getData() {
    return new BNetInputStream(new ByteArrayInputStream(data));
  }
View Full Code Here

Examples of net.bnubot.core.BNetInputStream

  private static BNetIcon[] readIconsDotBni(File f) {
    try {
      //Out.info(this.getClass().getName(), "Reading " + f.getName());
     
      BNetInputStream is = new BNetInputStream(new FileInputStream(f));
      is.skip(4); //int headerSize = is.readDWord();
      int bniVersion = is.readWord();
      is.skip(2)// Alignment Padding (unused)
      int numIcons = is.readDWord();
      is.skip(4)//int dataOffset = is.readDWord();
     
      if(bniVersion != 1)
        throw new Exception("Unknown BNI version");
     
      //Out.info(this.getClass().getName(), "Reading " + numIcons + " icons in format " + bniVersion + " from offset " + dataOffset);

      //Image headers
      /*if(icons == null)
        icons = new BNetIcon[numIcons];
      else {
        BNetIcon[] newIcons = new BNetIcon[numIcons + icons.length];
        for(int i = numIcons; i < numIcons + icons.length; i++) {
          newIcons[i] = icons[i-numIcons];
        }
        icons = newIcons;
      }*/
      BNetIcon[] icons = new BNetIcon[numIcons];
     
      for(int i = 0; i < numIcons; i++) {
        BNetIcon icon = new BNetIcon();
        icon.flags = is.readDWord();
        icon.xSize = is.readDWord();
        icon.ySize = is.readDWord();
        if(icon.flags != 0)
          icon.sortIndex = i;
        else
          icon.sortIndex = numIcons;
        int numProducts;
        int products[] = new int[32];
       
        //Read in up to 32 products; stop if we see a null
        for(numProducts = 0; numProducts < 32; numProducts++) {
          products[numProducts] = is.readDWord();
          if(products[numProducts] == 0)
            break;
        }
       
        if(numProducts > 0) {
          icon.products = new int[numProducts];
          for(int j = 0; j < numProducts; j++)
            icon.products[j] = products[j];
        } else
          icon.products = null;
        icons[i] = icon;
        //Out.info(this.getClass().getName(), icon.toString());
      }
     
      //Image in targa format
      byte infoLength = is.readByte();
      is.skip(1);              // ColorMapType
      byte imageType = is.readByte();    // run-length true-color image types = 0x0A
      is.skip(5);              // ColorMapSpecification - color map data
      is.skip(2)//int xOrigin = is.readWord();
      is.skip(2)//int yOrigin = is.readWord();
      int width = is.readWord();
      int height = is.readWord();
      byte depth = is.readByte();      // 24 bit depth is good
      /*byte descriptor =*/ is.readByte()// bits 5 and 4 (00110000) specify the corner to start coloring pixels - 00=bl, 01=br, 10=tl, 11=tr
      is.skip(infoLength)//String info = is.readFixedLengthString(infoLength);
     
      if(imageType != 0x0A)
        throw new Exception("Unknown image type");
      if(depth != 24)
        throw new Exception("Unknown depth");
     
      //Pixel data
      int[] pixelData = new int[width*height];
      int currentPixel = 0;
     
      while(currentPixel < pixelData.length) {
        byte packetHeader = is.readByte()// if bit 7 (0x80) is set, run-length packet;
        int len = (packetHeader & 0x7F) + 1;
        if((packetHeader & 0x80) != 0) {
          //Run-length packet
          int blue = is.readByte() & 0xFF;
          int green = is.readByte() & 0xFF;
          int red = is.readByte() & 0xFF;
          int col = new Color(red, green, blue).getRGB();
          for(int i = 0; i < len; i++)
            pixelData[getRealPixelPosition(currentPixel++, height, width)] = col;
        } else {
          for(int i = 0; i < len; i++) {
            int blue = is.readByte() & 0xFF;
            int green = is.readByte() & 0xFF;
            int red = is.readByte() & 0xFF;
            int col = new Color(red, green, blue).getRGB();
            pixelData[getRealPixelPosition(currentPixel++, height, width)] = col;
          }
        }
      }
View Full Code Here

Examples of net.bnubot.core.BNetInputStream

  int packetId;
  int packetLength;
  byte data[];
 
  public BNCSPacketReader(InputStream rawis, boolean packetLog) throws IOException {
    BNetInputStream is = new BNetInputStream(rawis);
   
    byte magic;
    do {
      magic = is.readByte();
    } while(magic != (byte)0xFF);
   
    packetId = is.readByte() & 0x000000FF;
    packetLength = is.readWord() & 0x0000FFFF;
    assert(packetLength >= 4);
   
    data = new byte[packetLength-4];
    for(int i = 0; i < packetLength-4; i++) {
      data[i] = is.readByte();
    }
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BNetOutputStream os = new BNetOutputStream(baos);
    os.writeByte(0xFF);
View Full Code Here

Examples of net.bnubot.core.BNetInputStream

    if(packetLog)
      Out.info(this.getClass().getName(), "RECV\n" + HexDump.hexDump(baos.toByteArray()));
  }
 
  public BNetInputStream getData() {
    return new BNetInputStream(new ByteArrayInputStream(data));
  }
View Full Code Here

Examples of net.bnubot.core.BNetInputStream

        }
      }
     
      if(dis.available() > 0) {
        BNCSPacketReader pr = new BNCSPacketReader(dis, cs.packetLog);
        BNetInputStream is = pr.getData();
       
        switch(pr.packetId) {
        case BNCSCommandIDs.SID_EXTRAWORK:
        case BNCSCommandIDs.SID_REQUIREDWORK:
          break;
         
        case BNCSCommandIDs.SID_NULL: {
          lastNullPacket = timeNow;
          BNCSPacket p = new BNCSPacket(BNCSCommandIDs.SID_NULL);
          p.SendPacket(dos, cs.packetLog);
          break;
        }
       
        case BNCSCommandIDs.SID_PING: {
          BNCSPacket p = new BNCSPacket(BNCSCommandIDs.SID_PING);
          p.writeDWord(is.readDWord());
          p.SendPacket(dos, cs.packetLog);
          break;
        }
       
        case BNCSCommandIDs.SID_AUTH_INFO:
        case BNCSCommandIDs.SID_STARTVERSIONING: {
          if(pr.packetId == BNCSCommandIDs.SID_AUTH_INFO) {
            nlsRevision = is.readDWord();
            serverToken = is.readDWord();
            is.skip(4)//int udpValue = is.readDWord();
          }
          long MPQFileTime = is.readQWord();
          String MPQFileName = is.readNTString();
          String ValueStr = is.readNTString();
         
          recieveInfo("MPQ: " + MPQFileName);
       
          byte extraData[] = null;
          if(is.available() == 0x80) {
            extraData = new byte[0x80];
            is.read(extraData, 0, 0x80);
          }
          assert(is.available() == 0);
         
          // Hash the CD key
          byte keyHash[] = null;
          byte keyHash2[] = null;
          if(nlsRevision != -1) {
            keyHash = HashMain.hashKey(clientToken, serverToken, cs.cdkey).getBuffer();
            if(cs.product == ConnectionSettings.PRODUCT_LORDOFDESTRUCTION)
              keyHash2 = HashMain.hashKey(clientToken, serverToken, cs.cdkeyLOD).getBuffer();
            if(cs.product == ConnectionSettings.PRODUCT_THEFROZENTHRONE)
              keyHash2 = HashMain.hashKey(clientToken, serverToken, cs.cdkeyTFT).getBuffer();
          }
         
          // Hash the game files
            String files[] = HashMain.getFiles(cs.product, HashMain.PLATFORM_INTEL);

          int exeHash;
                  int exeVersion;
                  String exeInfo;
                 
                  try {
                    String tmp = MPQFileName;
                    tmp = tmp.substring(tmp.indexOf("IX86")+4);
                    while((tmp.charAt(0) < 0x30) || (tmp.charAt(0) > 0x39))
                      tmp = tmp.substring(1);
              tmp = tmp.substring(0,tmp.indexOf("."));
                      int mpqNum = Integer.parseInt(tmp);
                     
                      exeHash = CheckRevision.checkRevision(ValueStr, files, mpqNum);
              exeVersion = HashMain.getExeVer(cs.product);
            exeInfo = HashMain.getExeInfo(cs.product);
                  } catch(Exception e) {
                    recieveError("Local hashing failed. Trying BNLS server.");
                   
                    BNLSProtocol.OutPacketBuffer exeHashBuf;
                    if((cs.bnlsServer == null)
                    || (cs.bnlsServer.length() == 0)) {
                      exeHashBuf = CheckRevisionBNLS.checkRevision(ValueStr, cs.product, MPQFileName, MPQFileTime);
                    } else {
                      exeHashBuf = CheckRevisionBNLS.checkRevision(ValueStr, cs.product, MPQFileName, MPQFileTime, cs.bnlsServer);
                    }
              BNetInputStream exeStream = new BNetInputStream(new java.io.ByteArrayInputStream(exeHashBuf.getBuffer()));
              exeStream.skipBytes(3);
              int success = exeStream.readDWord();
              if(success != 1) {
                Out.error(this.getClass().getName(), HexDump.hexDump(exeHashBuf.getBuffer()));
                throw new Exception("BNLS failed to complete 0x1A sucessfully");
              }
              exeVersion = exeStream.readDWord();
              exeHash = exeStream.readDWord();
              exeInfo = exeStream.readNTString();
              exeStream.readDWord(); // cookie
              /*int exeVerbyte =*/ exeStream.readDWord();
              assert(exeStream.available() == 0);
                  }
                 
                  if((exeVersion == 0) || (exeHash == 0) || (exeInfo == null) || (exeInfo.length() == 0)) {
                    recieveError("Checkrevision failed!");
                    setConnected(false);
View Full Code Here

Examples of net.bnubot.util.BNetInputStream

        if(socket.isClosed()) break;
        // What is this?
        throw e;
      }

      BNetInputStream is = pr.getData();
      switch(pr.packetId) {
      case SID_NULL: {
        lastNullPacket = timeNow;
        BNCSPacket p = new BNCSPacket(this, BNCSPacketId.SID_NULL);
        p.sendPacket(bncsOutputStream);
        break;
      }

      case SID_PING: {
        BNCSPacket p = new BNCSPacket(this, BNCSPacketId.SID_PING);
        p.writeDWord(is.readDWord());
        p.sendPacket(bncsOutputStream);
        break;
      }

      case SID_NEWS_INFO: {
        int numEntries = is.readByte();
        // int lastLogon = is.readDWord();
        // int oldestNews = is.readDWord();
        // int newestNews = is.readDWord();;
        is.skip(12);

        for(int i = 0; i < numEntries; i++) {
          int timeStamp = is.readDWord();
          String news = is.readNTStringUTF8().trim();
          if(timeStamp == 0// MOTD
            dispatchRecieveServerInfo(news);
        }

        break;
      }

      case SID_GETCHANNELLIST: {
        recieveGetChannelList(is);
        break;
      }

      case SID_CHATEVENT: {
        BNCSChatEventId eid = BNCSChatEventId.values()[is.readDWord()];
        int flags = is.readDWord();
        int ping = is.readDWord();
        is.skip(12);
      // is.readDWord(); // IP Address (defunct)
      // is.readDWord(); // Account number (defunct)
      // is.readDWord(); // Registration authority (defunct)
        String username = is.readNTString();
        ByteArray data = null;
        StatString statstr = null;

        switch(eid) {
        case EID_SHOWUSER:
        case EID_JOIN:
          statstr = is.readStatString();
          break;
        case EID_USERFLAGS:
          // Sometimes USERFLAGS contains a statstring; sometimes
          // it doesn't
          statstr = is.readStatString();
          if(statstr.toString().length() == 0)
            statstr = null;
          break;
        default:
          data = new ByteArray(is.readNTBytes());
          break;
        }

        BNetUser user = null;
        switch(eid) {
        case EID_SHOWUSER:
        case EID_USERFLAGS:
        case EID_JOIN:
        case EID_LEAVE:
        case EID_TALK:
        case EID_EMOTE:
        case EID_WHISPERSENT:
        case EID_WHISPER:
          switch(productID) {
          case D2DV:
          case D2XP:
            int asterisk = username.indexOf('*');
            if(asterisk >= 0)
              username = username.substring(asterisk+1);
            break;
          }

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

          // Set the flags, ping, statstr
          user.setFlags(flags);
          user.setPing(ping);
          if(statstr != null)
            user.setStatString(statstr);
          break;
        }

        switch(eid) {
        case EID_SHOWUSER:
        case EID_USERFLAGS:
          dispatchChannelUser(user);
          break;
        case EID_JOIN:
          dispatchChannelJoin(user);
          break;
        case EID_LEAVE:
          dispatchChannelLeave(user);
          break;
        case EID_TALK:
          dispatchRecieveChat(user, data);
          break;
        case EID_BROADCAST:
          dispatchRecieveBroadcast(username, flags, data.toString());
          break;
        case EID_EMOTE:
          dispatchRecieveEmote(user, data.toString());
          break;
        case EID_INFO:
          dispatchRecieveServerInfo(data.toString());
          break;
        case EID_ERROR:
          dispatchRecieveServerError(data.toString());
          break;
        case EID_CHANNEL:
          // Don't clear the queue if we're connecting for the first time or rejoining
          String newChannel = data.toString();
          if((channelName != null) && !channelName.equals(newChannel))
            clearQueue();
          channelName = newChannel;
          dispatchJoinedChannel(newChannel, flags);
          dispatchTitleChanged();
          if(botnet != null)
            botnet.sendStatusUpdate();
          break;
        case EID_WHISPERSENT:
          dispatchWhisperSent(user, data.toString());
          break;
        case EID_WHISPER:
          dispatchWhisperRecieved(user, data.toString());
          break;
        case EID_CHANNELDOESNOTEXIST:
          dispatchRecieveError("Channel does not exist; creating");
          sendJoinChannel2(data.toString());
          break;
        case EID_CHANNELRESTRICTED:
          long timeSinceNormalJoin = timeNow - lastNormalJoin;
          if((lastNormalJoin != 0) && (timeSinceNormalJoin < 5000)) {
            dispatchRecieveError("Channel is restricted; forcing entry");
            sendJoinChannel2(data.toString());
          } else {
            dispatchRecieveError("Channel " + data.toString() + " is restricted");
          }
          break;
        case EID_CHANNELFULL:
          dispatchRecieveError("Channel " + data.toString() + " is full");
          break;
        default:
          dispatchRecieveError("Unknown SID_CHATEVENT " + eid + ": " + data.toString());
          break;
        }

        break;
      }

      case SID_MESSAGEBOX: {
        /* int style = */ is.readDWord();
        String text = is.readNTStringUTF8();
        String caption = is.readNTStringUTF8();

        dispatchRecieveInfo("<" + caption + "> " + text);
        break;
      }

      case SID_FLOODDETECTED: {
        dispatchRecieveError("You have been disconnected for flooding.");
        disconnect(ConnectionState.LONG_PAUSE_BEFORE_CONNECT);
        break;
      }

      /*
       * .----------.
       * |  Realms  |
       * '----------'
       */
      case SID_QUERYREALMS2: {
        /*
         * (DWORD) Unknown0
         * (DWORD) Number of Realms
         *
         * For each realm:
         * (DWORD) UnknownR0
         * (STRING) Realm Name
         * (STRING) Realm Description
         */
        is.readDWord();
        int numRealms = is.readDWord();
        String realms[] = new String[numRealms];
        for(int i = 0; i < numRealms; i++) {
          is.readDWord();
          realms[i] = is.readNTStringUTF8();
          is.readNTStringUTF8();
        }
        dispatchQueryRealms2(realms);
        break;
      }

      case SID_LOGONREALMEX: {
        /*
         * (DWORD) Cookie
         * (DWORD) Status
         * (DWORD[2]) MCP Chunk 1
         * (DWORD) IP
         * (DWORD) Port
         * (DWORD[12]) MCP Chunk 2
         * (STRING) BNCS unique name
         */
        if(pr.packetLength < 12)
          throw new Exception("pr.packetLength < 12");
        else if(pr.packetLength == 12) {
          /* int cookie = */ is.readDWord();
          int status = is.readDWord();
          switch(status) {
          case 0x80000001:
            dispatchRecieveError("Realm is unavailable.");
            break;
          case 0x80000002:
            dispatchRecieveError("Realm logon failed");
            break;
          default:
            throw new Exception("Unknown status code 0x" + Integer.toHexString(status));
          }
        } else {
          int MCPChunk1[] = new int[4];
          MCPChunk1[0] = is.readDWord();
          MCPChunk1[1] = is.readDWord();
          MCPChunk1[2] = is.readDWord();
          MCPChunk1[3] = is.readDWord();
          int ip = is.readDWord();
          int port = is.readDWord();
          port = ((port & 0xFF00) >> 8) | ((port & 0x00FF) << 8);
          int MCPChunk2[] = new int[12];
          MCPChunk2[0] = is.readDWord();
          MCPChunk2[1] = is.readDWord();
          MCPChunk2[2] = is.readDWord();
          MCPChunk2[3] = is.readDWord();
          MCPChunk2[4] = is.readDWord();
          MCPChunk2[5] = is.readDWord();
          MCPChunk2[6] = is.readDWord();
          MCPChunk2[7] = is.readDWord();
          MCPChunk2[8] = is.readDWord();
          MCPChunk2[9] = is.readDWord();
          MCPChunk2[10] = is.readDWord();
          MCPChunk2[11] = is.readDWord();
          String uniqueName = is.readNTString();
          dispatchLogonRealmEx(MCPChunk1, ip, port, MCPChunk2, uniqueName);
        }

        break;
      }

      /*
       * .-----------.
       * |  Profile  |
       * '-----------'
       */

      case SID_READUSERDATA: {
        /*
         * (DWORD) Number of accounts
         * (DWORD) Number of keys
         * (DWORD) Request ID
         * (STRING[]) Requested Key Values
         */
        int numAccounts = is.readDWord();
        int numKeys = is.readDWord();
        @SuppressWarnings("unchecked")
        List<Object> keys = (List<Object>)CookieUtility.destroyCookie(is.readDWord());

        if(numAccounts != 1)
          throw new IllegalStateException("SID_READUSERDATA with numAccounts != 1");

        UserProfile up = new UserProfile((String)keys.remove(0));
        dispatchRecieveInfo("Profile for " + up.getUser());
        for(int i = 0; i < numKeys; i++) {
          String key = (String)keys.get(i);
          String value = is.readNTStringUTF8();
          if((key == null) || (key.length() == 0))
            continue;
          value = prettyProfileValue(key, value);

          if(value.length() != 0) {
            dispatchRecieveInfo(key + " = " + value);
          } else if(
            key.equals(UserProfile.PROFILE_DESCRIPTION) ||
            key.equals(UserProfile.PROFILE_LOCATION) ||
            key.equals(UserProfile.PROFILE_SEX)) {
            // Always report these keys
          } else {
            continue;
          }
          up.put(key, value);
        }

        // FIXME this should be a dispatch
        if(PluginManager.getEnableGui())
          new ProfileEditor(up, this);
        break;
      }

      /*
       * .-----------.
       * |  Friends  |
       * '-----------'
       */

      case SID_FRIENDSLIST: {
        /*
         * (BYTE) Number of Entries
         *
         * For each member:
         * (STRING) Account
         * (BYTE) Status
         * (BYTE) Location
         * (DWORD) ProductID
         * (STRING) Location name
         */
        byte numEntries = is.readByte();
        FriendEntry[] entries = new FriendEntry[numEntries];

        for(int i = 0; i < numEntries; i++) {
          String uAccount = is.readNTString();
          byte uStatus = is.readByte();
          byte uLocation = is.readByte();
          int uProduct = is.readDWord();
          String uLocationName = is.readNTStringUTF8();

          entries[i] = new FriendEntry(uAccount, uStatus, uLocation, uProduct, uLocationName);
        }

        dispatchFriendsList(entries);
        break;
      }

      case SID_FRIENDSUPDATE: {
        /*
         * (BYTE) Entry number
         * (BYTE) Friend Location
         * (BYTE) Friend Status
         * (DWORD) ProductID
         * (STRING) Location
         */
        byte fEntry = is.readByte();
        byte fLocation = is.readByte();
        byte fStatus = is.readByte();
        int fProduct = is.readDWord();
        String fLocationName = is.readNTStringUTF8();

        dispatchFriendsUpdate(new FriendEntry(fEntry, fStatus, fLocation, fProduct, fLocationName));
        break;
      }

      case SID_FRIENDSADD: {
        /*
         * (STRING) Account
         * (BYTE) Friend Type
         * (BYTE) Friend Status
         * (DWORD) ProductID
         * (STRING) Location
         */
        String fAccount = is.readNTString();
        byte fLocation = is.readByte();
        byte fStatus = is.readByte();
        int fProduct = is.readDWord();
        String fLocationName = is.readNTStringUTF8();

        dispatchFriendsAdd(new FriendEntry(fAccount, fStatus, fLocation, fProduct, fLocationName));
        break;
      }

      case SID_FRIENDSREMOVE: {
        /*
         * (BYTE) Entry Number
         */
        byte entry = is.readByte();

        dispatchFriendsRemove(entry);
        break;
      }

      case SID_FRIENDSPOSITION: {
        /*
         * (BYTE) Old Position
         * (BYTE) New Position
         */
        byte oldPosition = is.readByte();
        byte newPosition = is.readByte();

        dispatchFriendsPosition(oldPosition, newPosition);
        break;
      }

      /*
       * .--------.
       * |  Clan  |
       * '--------'
       */

      case SID_CLANINFO: {
        recvClanInfo(is);
        break;
      }

      case SID_CLANFINDCANDIDATES: {
        Object cookie = CookieUtility.destroyCookie(is.readDWord());
        byte status = is.readByte();
        byte numCandidates = is.readByte();
        List<String> candidates = new ArrayList<String>(numCandidates);
        for(int i = 0 ; i < numCandidates; i++)
          candidates.add(is.readNTString());

        switch(status) {
        case 0x00:
          if(numCandidates < 9)
            dispatchRecieveError("Insufficient elegible W3 players (" + numCandidates + "/9).");
          else
            dispatchClanFindCandidates(cookie, candidates);
          break;
        case 0x01:
          dispatchRecieveError("Clan tag already taken");
          break;
        case 0x08:
          dispatchRecieveError("Already in a clan");
          break;
        case 0x0a:
          dispatchRecieveError("Invalid clan tag");
          break;
        default:
          dispatchRecieveError("Unknown response 0x" + Integer.toHexString(status));
          break;
        }
        break;
      }
      // SID_CLANINVITEMULTIPLE
      case SID_CLANCREATIONINVITATION: {
        int cookie = is.readDWord();
        int clanTag = is.readDWord();
        String clanName = is.readNTString();
        String inviter = is.readNTString();

        ClanCreationInvitationCookie c = new ClanCreationInvitationCookie(this, cookie, clanTag, clanName, inviter);
        dispatchClanCreationInvitation(c);
        break;
      }
      // SID_CLANDISBAND
      // SID_CLANMAKECHIEFTAIN

      // SID_CLANQUITNOTIFY
      case SID_CLANINVITATION: {
        Object cookie = CookieUtility.destroyCookie(is.readDWord());
        byte status = is.readByte();

        String result;
        switch(status) {
        case 0x00:
          result = "Invitation accepted";
          break;
        case 0x04:
          result = "Invitation declined";
          break;
        case 0x05:
          result = "Failed to invite user";
          break;
        case 0x09:
          result = "Clan is full";
          break;
        default:
          result = "Unknown response 0x" + Integer.toHexString(status);
          break;
        }

        if(cookie instanceof CommandResponseCookie)
          ((CommandResponseCookie)cookie).sendChat(result);
        else
          Out.info(getClass(), result);

        break;
      }

      // SID_CLANREMOVEMEMBER

      case SID_CLANINVITATIONRESPONSE: {
        /*
         * (DWORD) Cookie
         * (DWORD) Clan tag
         * (STRING) Clan name
         * (STRING) Inviter
         */
        int cookie = is.readDWord();
        int clanTag = is.readDWord();
        String clanName = is.readNTString();
        String inviter = is.readNTString();

        ClanInvitationCookie c = new ClanInvitationCookie(this, cookie, clanTag, clanName, inviter);
        dispatchClanInvitation(c);
        break;
      }

      case SID_CLANRANKCHANGE: {
        int cookie = is.readDWord();
        byte status = is.readByte();

        Object obj = CookieUtility.destroyCookie(cookie);
        String statusCode = null;
        switch(status) {
        case ClanStatusIDs.CLANSTATUS_SUCCESS:
          statusCode = "Successfully changed rank";
          break;
        case 0x01:
          statusCode = "Failed to change rank";
          break;
        case ClanStatusIDs.CLANSTATUS_TOO_SOON:
          statusCode = "Cannot change user'socket rank yet";
          break;
        case ClanStatusIDs.CLANSTATUS_NOT_AUTHORIZED:
          statusCode = "Not authorized to change user rank*";
          break;
        case 0x08:
          statusCode = "Not allowed to change user rank**";
          break;
        default:  statusCode = "Unknown ClanStatusID 0x" + Integer.toHexString(status);
        }

        dispatchRecieveInfo(statusCode + "\n" + obj.toString());
        // TODO: clanRankChange(obj, status)

        break;
      }

      case SID_CLANMOTD: {
        /*
         * (DWORD) Cookie
         * (DWORD) Unknown (0)
         * (STRING) MOTD
         */
        int cookieId = is.readDWord();
        is.readDWord();
        String text = is.readNTStringUTF8();

        Object cookie = CookieUtility.destroyCookie(cookieId);
        dispatchClanMOTD(cookie, text);
        break;
      }

      case SID_CLANMEMBERLIST: {
        /*
         * (DWORD) Cookie
         * (BYTE) Number of Members
         *
         * For each member:
         * (STRING) Username
         * (BYTE) Rank
         * (BYTE) Online Status
         * (STRING) Location
         */
        is.readDWord();
        byte numMembers = is.readByte();
        ClanMember[] members = new ClanMember[numMembers];

        for(int i = 0; i < numMembers; i++) {
          String uName = is.readNTString();
          byte uRank = is.readByte();
          byte uOnline = is.readByte();
          String uLocation = is.readNTStringUTF8();

          members[i] = new ClanMember(uName, uRank, uOnline, uLocation);
        }

        dispatchClanMemberList(members);
        break;
      }

      case SID_CLANMEMBERREMOVED: {
        /*
         * (STRING) Username
         */
        String username = is.readNTString();
        dispatchClanMemberRemoved(username);
        break;
      }

      case SID_CLANMEMBERSTATUSCHANGE: {
        /*
         * (STRING) Username
         * (BYTE) Rank
         * (BYTE) Status
         * (STRING) Location
         */
        String username = is.readNTString();
        byte rank = is.readByte();
        byte status = is.readByte();
        String location = is.readNTStringUTF8();

        dispatchClanMemberStatusChange(new ClanMember(username, rank, status, location));
        break;
      }

      case SID_CLANMEMBERRANKCHANGE: {
        /*
         * (BYTE) Old rank
         * (BYTE) New rank
         * (STRING) Clan member who changed your rank
         */
        byte oldRank = is.readByte();
        byte newRank = is.readByte();
        String user = is.readNTString();
        dispatchRecieveInfo("Rank changed from " + ClanRankIDs.ClanRank[oldRank] + " to " + ClanRankIDs.ClanRank[newRank] + " by " + user);
        dispatchClanMemberRankChange(oldRank, newRank, user);
        break;
      }

View Full Code Here

Examples of net.bnubot.util.BNetInputStream

  }*/

  @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

Examples of net.bnubot.util.BNetInputStream

    }

    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");
      }

      //Receive the file
      is.skip(2)//int headerLength = is.readWord();
      is.skip(2)//int unknown = is.readWord();
      int fileSize = is.readDWord();
      is.skip(4)//int bannersID = is.readDWord();
      is.skip(4)//int bannersFileExt = is.readDWord();
      Date fileTime = TimeFormatter.fileTime(is.readQWord());
      fileName = is.readNTString();

      //The rest is the data
      new File(path).mkdir();
      f = new File(path + fileName);
      FileOutputStream fw = new FileOutputStream(f);
      for(int i = 0; i < fileSize; i++) {
        int b = is.readByte();
        b = b & 0xFF;
        fw.write(b);
      }
      fw.close();
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.