Android Open Source - Minecraft-Query-Android Query Request






From Project

Back to project page Minecraft-Query-Android.

License

The source code is released under:

MIT License

If you think the Android project Minecraft-Query-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.metrafonic.nativeminecraftquery;
/*from  w  ww .  j  av  a2s. co  m*/
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class QueryRequest
{
  private ByteArrayOutputStream byteStream;
  private DataOutputStream dataStream;
  
  static byte[] MAGIC = {(byte) 0xFE, (byte) 0xFD};
  byte type;
  int sessionID;
  byte[] payload;
  
  public QueryRequest()
  {
    int size = 1460;
    byteStream = new ByteArrayOutputStream(size);
    dataStream = new DataOutputStream(byteStream);
  }
  public QueryRequest(byte type)
  {
    this.type = type;
    //TODO move static type variables to Request
  }
  
  //convert the data in this request to a byte array to send to the server
  byte[] toBytes()
  {
    byteStream.reset();
    
    try
    {
      dataStream.write(MAGIC);
      dataStream.write(type);
      dataStream.writeInt(sessionID);
      dataStream.write(payloadBytes());
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    
    return byteStream.toByteArray();
  }
  
  private byte[] payloadBytes()
  {
    if(type == MCQuery.HANDSHAKE)
    {
      return new byte[]{}; //return empty byte array
    }
    else //(type == MCQuery.STAT)
    {
      return payload;
    }
  }
  
  protected void setPayload(int load)
  {
    this.payload = ByteUtils.intToBytes(load);
  }
}




Java Source Code List

com.metrafonic.nativeminecraftquery.AppSettingsHelper.java
com.metrafonic.nativeminecraftquery.ByteUtils.java
com.metrafonic.nativeminecraftquery.MCQuery.java
com.metrafonic.nativeminecraftquery.MainActivity.java
com.metrafonic.nativeminecraftquery.QueryRequest.java
com.metrafonic.nativeminecraftquery.QueryResponse.java
com.metrafonic.nativeminecraftquery.playerListActivity.java