Package net.bnubot.util

Examples of net.bnubot.util.ByteArray


   */
  private void sendBotNetChat(int command, boolean emote, int target, String message) throws Exception {
    if(message.length() > 496)
      throw new IllegalStateException("Chat length too long");

    byte[] crypt = GenericCrypto.encode(new ByteArray(message), master.enabledCryptos).getBytes();

    BotNetPacket p = new BotNetPacket(this, BotNetPacketId.PACKET_BOTNETCHAT);
    p.writeDWord(command);
    p.writeDWord(emote ? 1 : 0);
    p.writeDWord(target);
View Full Code Here


        dataOut[pos++] = b;
      else
        dataOut[pos++] = nonSpecial[--nsPos];
    }

    return new ByteArray(dataOut);
  }
View Full Code Here

    for(int i = 0; i < lenbyte; i++) {
      int oper = data.byteAt(pos++) - 100;
      int a = data.byteAt(pos++) - 63;
      out[i] = (byte)(a ^ oper);
    }
    return new ByteArray(out);
  }
View Full Code Here

    }

    while(pos < out.length)
      out[pos++] = (byte)(180 * Math.random() + 60);

    return new ByteArray(out);
  }
View Full Code Here

        b -= 0x7D;

      // Write the new byte
      out[i] = (byte)b;
    }
    return new ByteArray(out);
  }
View Full Code Here

        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;
      }
View Full Code Here

          String theRest = cmd.substring(i + 1);
          cmd = cmd.substring(0, i);

          if (isTargetedCommand(cmd)) {
            if (theRest.charAt(0) != '*')
              data = new ByteArray('/' + cmd + " *" + theRest);
          }

        }
      }
      break;
View Full Code Here

        if(!con.canSendChat()) {
          lastCon--;
          break;
        }

        ByteArray text;
        synchronized(queue) {
          text = queue.remove(0).text;
        }

        if(con.isOp() || !requiresOps(text.toString())) {
          // Write the text out
          con.sendChatCommand(text);
          continue;
        }
View Full Code Here

           * 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;
          }
View Full Code Here

* @author scotta
*/
public class Base64Test extends TestCase {

  public void testEncode() {
    assertEquals(Base64.encode(new ByteArray("asdf")), "YXNkZg==");
  }
View Full Code Here

TOP

Related Classes of net.bnubot.util.ByteArray

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.