use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.
the class DPAddonBukkit method detectedBedrockPlayer.
public void detectedBedrockPlayer(Player player) {
getLogger().info("Detected bedrock player: " + player.getName() + " " + player.getUniqueId().toString());
bedrockPlayers.add(player.getUniqueId());
BedrockPlayer.createForPlayer(player);
// enable packet foward
BinaryStream bis = new BinaryStream();
bis.putString("PacketForward");
bis.putBoolean(true);
player.sendPluginMessage(this, "DragonProxy", bis.getBuffer());
}
use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.
the class Protocol method decode.
public static PEPacket[] decode(byte[] data) throws Exception {
if (data == null || data.length < 1)
return null;
byte[] inflated;
try {
inflated = Zlib.inflate(Arrays.copyOfRange(data, 1, data.length));
} catch (IOException e) {
e.printStackTrace();
return null;
}
ArrayList<PEPacket> packets = new ArrayList<>(2);
BinaryStream stream = new BinaryStream(inflated);
while (stream.offset < inflated.length) {
byte[] buffer = stream.get((int) stream.getUnsignedVarInt());
PEPacket decoded = decodeSingle(buffer);
if (decoded != null)
packets.add(decoded);
else
System.out.println("decode fail");
}
return packets.size() > 0 ? packets.toArray(new PEPacket[0]) : null;
}
use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.
the class BedrockPlayer method sendForm.
// NOT SUPPORTED YET
/* public void setPacketSubscription(Class<? extends PEPacket> clazz, boolean sub) {
if(clazz.equals(PEPacket.class)) throw new IllegalArgumentException();
BinaryStream bis = new BinaryStream();
bis.putString("PacketSubscription");
bis.putString(clazz.getSimpleName());
bis.putBoolean(sub);
player.sendPluginMessage(DPAddonBukkit.getInstance(), "DragonProxy", bis.getBuffer());
} */
public void sendForm(int formId, ModalFormComponent form) {
String formData = form.serializeToJson().toString();
ModalFormRequestPacket request = new ModalFormRequestPacket();
request.formId = formId;
request.formData = formData;
request.encode();
BinaryStream bis = new BinaryStream();
bis.putString("SendPacket");
bis.putByteArray(request.getBuffer());
player.sendPluginMessage(DPAddonBukkit.getInstance(), "DragonProxy", bis.getBuffer());
}
use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.
the class DPPluginMessageListener method onPluginMessageReceived.
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] data) {
// not likely to happen but...
if (!channel.equals("DragonProxy"))
return;
BinaryStream bis = new BinaryStream(data);
String command = bis.getString();
if (command.equals("Notification")) {
plugin.detectedBedrockPlayer(player);
} else if (command.equals("PacketForward")) {
processPacketForward(player, bis.getByteArray());
}
}
use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.
the class PEPacketProcessor method handlePacket.
// this method should be in UpstreamSession
public void handlePacket(PEPacket packet) {
if (packet == null)
return;
if (!client.getProxy().getConfig().disable_packet_events) {
PacketfromPlayerEvent packetEvent = new PacketfromPlayerEvent(client, packet);
client.getProxy().getEventManager().callEvent(packetEvent);
if (packetEvent.isCancelled()) {
return;
}
}
// Wait for player logginig in
if ("online_login_wait".equals(this.client.getDataCache().get(CacheKey.AUTHENTICATION_STATE))) {
if (packet.pid() == ProtocolInfo.MOVE_PLAYER_PACKET) {
InputComponent username = new InputComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_USERNAME)).setPlaceholder("steve@example.com");
InputComponent password = new InputComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_PASSWORD)).setPlaceholder("123456");
if (this.client.getProxy().getConfig().auto_login) {
username.setDefaultValue(this.client.getProxy().getConfig().online_username);
password.setDefaultValue(this.client.getProxy().getConfig().online_password);
}
// client.getDataCache().put(CacheKey.AUTHENTICATION_STATE, "online_login");
ModalFormRequestPacket packetForm = new ModalFormRequestPacket();
CustomFormComponent form = new CustomFormComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_TITLE));
form.addComponent(new LabelComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_DESC)));
form.addComponent(new LabelComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_PROMPT)));
form.addComponent(username);
form.addComponent(password);
packetForm.formId = 1;
packetForm.formData = form.serializeToJson().toString();
this.client.sendPacket(packetForm, true);
return;
}
if (packet.pid() == ProtocolInfo.MODAL_FORM_RESPONSE_PACKET) {
try {
this.client.sendChat(this.client.getProxy().getLang().get(Lang.MESSAGE_LOGIN_PROGRESS));
ModalFormResponsePacket formResponse = (ModalFormResponsePacket) packet;
JsonArray array = JsonUtil.parseArray(formResponse.formData);
this.client.getDataCache().remove(CacheKey.AUTHENTICATION_STATE);
this.client.authenticate(array.get(2).getAsString(), array.get(3).getAsString(), authProxy);
} catch (Exception ex) {
this.client.sendChat(this.client.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD));
}
return;
}
}
switch(packet.pid()) {
case ProtocolInfo.BATCH_PACKET:
DragonProxy.getInstance().getLogger().debug("Received batch packet from client !");
break;
case ProtocolInfo.LOGIN_PACKET:
this.client.onLogin((LoginPacket) packet);
break;
case ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET:
if (!this.client.isLoggedIn())
this.client.postLogin();
break;
default:
if (this.client.getDownstream() == null || !this.client.getDownstream().isConnected())
break;
if (enableForward.get() && FORWARDED_PACKETS.contains(packet.getClass())) {
BinaryStream bis = new BinaryStream();
bis.putString("PacketForward");
bis.putByteArray(packet.getBuffer());
ClientPluginMessagePacket msg = new ClientPluginMessagePacket("DragonProxy", bis.getBuffer());
client.getDownstream().send(msg);
} else // IMPORTANT Do not send packet until client is connected !
if (client.isSpawned()) {
Packet[] translated = PacketTranslatorRegister.translateToPC(this.client, packet);
if (translated == null || translated.length == 0)
break;
client.getDownstream().send(translated);
}
break;
}
}
Aggregations