Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
new login method, and release 0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DefinitlyEvil committed Dec 26, 2017
1 parent 4bd478d commit ceab389
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>proxy</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<name>DragonProxy</name>
<groupId>org.dragonet.proxy</groupId>

Expand Down
Binary file added screenshots/form-login.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions src/main/java/org/dragonet/proxy/configuration/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ public class Lang extends PropertiesConfig {
public static final String ERROR_CLS_UNREACHABLE = "error_cls_unreachable";
public static final String ERROR_CLS_ERROR = "error_cls_error";
public static final String ERROR_CLS_LOGIN = "error_cls_login";
public static final String MESSAGE_ONLINE_NOTICE = "message_online_notice";
public static final String MESSAGE_ONLINE_EMAIL = "message_online_email";
//public static final String MESSAGE_ONLINE_NOTICE = "message_online_notice";
//public static final String MESSAGE_ONLINE_EMAIL = "message_online_email";
public static final String MESSAGE_LOGIN_PROMPT = "message_login_prompt";
public static final String MESSAGE_LOGIN_PROGRESS = "message_login_progress";
public static final String FORM_LOGIN_TITLE = "form_login_title";
public static final String FORM_LOGIN_DESC = "form_login_desc";
public static final String FORM_LOGIN_PROMPT = "form_login_prompt";
public static final String FORM_LOGIN_USERNAME = "form_login_username";
public static final String FORM_LOGIN_PASSWORD = "form_login_password";
public static final String MESSAGE_ONLINE_ERROR = "message_online_error";
public static final String MESSAGE_ONLINE_PASSWORD = "message_online_password";
public static final String MESSAGE_ONLINE_LOGGIN_IN = "message_online_logging_in";
public static final String MESSAGE_ONLINE_LOGGING_IN = "message_online_logging_in";
public static final String MESSAGE_ONLINE_LOGIN_SUCCESS = "message_online_login_success";
public static final String MESSAGE_ONLINE_LOGIN_SUCCESS_CONSOLE = "message_online_login_success_console";
public static final String MESSAGE_TELEPORT_TO_SPAWN = "message_teleport_to_spawn";
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/dragonet/proxy/gui/InputComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.dragonet.proxy.gui;

import org.json.JSONObject;

/**
* Created on 2017/12/26.
*/
public class InputComponent extends BaseModalFormComponent {

private String text;

private String defaultValue;

private String placeholder;

public InputComponent(String text) {
super("input");
this.text = text;
}

public InputComponent setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
return this;
}

public InputComponent setPlaceholder(String placeholder) {
this.placeholder = placeholder;
return this;
}

@Override
public void serializeData(JSONObject out) {
out.put("text", text);
if(defaultValue != null) out.put("default", defaultValue);
if(placeholder != null) out.put("placeholder", placeholder);
}
}
3 changes: 0 additions & 3 deletions src/main/java/org/dragonet/proxy/network/CacheKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public final class CacheKey {
public static final String AUTHENTICATION_STATE = "auth_state";
public static final String WINDOW_OPENED_ID = "window_opened_id";

// Strings
public static final String AUTHENTICATION_EMAIL = "auth_mail";

// Positions
public static final String BLOCK_BREAKING_POSITION = "block_breaking_position";
public static final String WINDOW_BLOCK_POSITION = "window_block_position";
Expand Down
42 changes: 34 additions & 8 deletions src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import java.util.Deque;

import com.github.steveice10.packetlib.packet.Packet;
import org.dragonet.proxy.configuration.Lang;
import org.dragonet.proxy.gui.CustomFormComponent;
import org.dragonet.proxy.gui.InputComponent;
import org.dragonet.proxy.gui.LabelComponent;
import org.dragonet.proxy.protocol.PEPacket;
import org.dragonet.proxy.protocol.Protocol;
import org.dragonet.proxy.protocol.ProtocolInfo;
import org.dragonet.proxy.protocol.packets.ChunkRadiusUpdatedPacket;
import org.dragonet.proxy.protocol.packets.LoginPacket;
import org.dragonet.proxy.protocol.packets.RequestChunkRadiusPacket;
import org.dragonet.proxy.protocol.packets.*;
import org.json.JSONArray;

public class PEPacketProcessor implements Runnable {

Expand Down Expand Up @@ -70,6 +73,8 @@ public void handlePacket(PEPacket packet) {
return;
}

System.out.println(" <<PE " + org.dragonet.proxy.utilities.DebugTools.matchConstant((byte)(packet.pid() & 0xFF), ProtocolInfo.class));

// System.out.println("RECEIVED PACKET=" + packet.getClass().getSimpleName());
/*
* try{ FileOutputStream fos = new FileOutputStream("cap_" +
Expand All @@ -80,6 +85,32 @@ public void handlePacket(PEPacket packet) {
case ProtocolInfo.LOGIN_PACKET:
client.onLogin((LoginPacket) packet);
break;
case ProtocolInfo.MOVE_PLAYER_PACKET:
if(client.getDataCache().containsKey(CacheKey.AUTHENTICATION_STATE) &&
client.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("online_login_wait")) {
// client.getDataCache().put(CacheKey.AUTHENTICATION_STATE, "online_login");
ModalFormRequestPacket packetForm = new ModalFormRequestPacket();
CustomFormComponent form = new CustomFormComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_TITLE));
form.addComponent(new LabelComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_DESC)));
form.addComponent(new LabelComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_PROMPT)));
form.addComponent(new InputComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_USERNAME)).setPlaceholder("[email protected]"));
form.addComponent(new InputComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_PASSWORD)).setPlaceholder("123456"));
packetForm.formId = 1;
packetForm.formData = form.serializeToJson().toString();
client.sendPacket(packetForm);
break;
}
case ProtocolInfo.MODAL_FORM_RESPONSE_PACKET:
if(client.getDataCache().containsKey(CacheKey.AUTHENTICATION_STATE) &&
client.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("online_login_wait")) {
client.sendChat(client.getProxy().getLang().get(Lang.MESSAGE_LOGIN_PROGRESS));

ModalFormResponsePacket formResponse = (ModalFormResponsePacket) packet;
JSONArray array = new JSONArray(formResponse.formData);
client.authenticate(array.get(2).toString(), array.get(3).toString());
client.getDataCache().remove(CacheKey.AUTHENTICATION_STATE);
break;
}
case ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET:
if (client.isLoggedIn()) {
return;
Expand All @@ -89,11 +120,6 @@ public void handlePacket(PEPacket packet) {
case ProtocolInfo.REQUEST_CHUNK_RADIUS_PACKET:
client.sendPacket(new ChunkRadiusUpdatedPacket(((RequestChunkRadiusPacket) packet).radius));
break;
case ProtocolInfo.TEXT_PACKET: // Text (check CLS Login)
if (client.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) {
PacketTranslatorRegister.translateToPC(client, packet);
break;
}
default:
if (client.getDownstream() == null) {
break;
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/dragonet/proxy/network/UpstreamSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,10 @@ public void onDisconnect(String reason) {
packetProcessorScheule.cancel(true);
}

public void authenticate(String password) {
public void authenticate(String email, String password) {
proxy.getGeneralThreadPool().execute(() -> {
try {
protocol = new MinecraftProtocol((String) dataCache.get(CacheKey.AUTHENTICATION_EMAIL), password,
false);
protocol = new MinecraftProtocol(email, password, false);
} catch (RequestException ex) {
if (ex.getMessage().toLowerCase().contains("invalid")) {
sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD));
Expand Down Expand Up @@ -347,14 +346,13 @@ public void postLogin() {
sendPacket(new FullChunkDataPacket(-1, 0, data.getBuffer()));
sendPacket(new FullChunkDataPacket(-1, -1, data.getBuffer()));

dataCache.put(CacheKey.AUTHENTICATION_STATE, "online_login_wait");

PlayStatusPacket pkStat = new PlayStatusPacket();
pkStat.status = PlayStatusPacket.PLAYER_SPAWN;
sendPacket(pkStat, true);

dataCache.put(CacheKey.AUTHENTICATION_STATE, "email");

sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_NOTICE, username));
sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_EMAIL));
sendChat(proxy.getLang().get(Lang.MESSAGE_LOGIN_PROMPT));
} else if (proxy.getAuthMode().equals("cls")) {
// CLS LOGIN!
if ((username.length() < 6 + 1 + 1) || (!username.contains("_"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@

import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
import com.github.steveice10.packetlib.packet.Packet;
import org.dragonet.proxy.configuration.Lang;
import org.dragonet.proxy.network.CacheKey;
import org.dragonet.proxy.network.UpstreamSession;
import org.dragonet.proxy.network.translator.IPEPacketTranslator;
import org.dragonet.proxy.protocol.packets.TextPacket;
import org.dragonet.proxy.utilities.PatternChecker;

public class PEChatPacketTranslator implements IPEPacketTranslator<TextPacket> {

public Packet[] translate(UpstreamSession session, TextPacket packet) {
if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) {
/*if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) {
if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("email")) {
if (!PatternChecker.matchEmail(packet.message.trim())) {
session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR));
Expand All @@ -40,12 +37,12 @@ public Packet[] translate(UpstreamSession session, TextPacket packet) {
session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR));
return null;
}
session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGGIN_IN));
session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGGING_IN));
session.getDataCache().remove(CacheKey.AUTHENTICATION_STATE);
session.authenticate(packet.message); // We NEVER cache password for better security.
}
return null;
}
}*/

ClientChatPacket pk = new ClientChatPacket(packet.message);
return new Packet[]{pk};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
public class ModalFormResponsePacket extends PEPacket {

private int formId;
private String formData;
public int formId;
public String formData;

@Override
public int pid() {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/dragonet/proxy/utilities/DebugTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,22 @@ public static String getAllFields(Object obj) {
}
return data;
}

public static String matchConstant(Object obj, Class target) {
if(obj == null) return "NULL";
try {
for (Field f : target.getDeclaredFields()) {
if ((f.getModifiers() & Modifier.STATIC) > 0) {
if (obj == f.get(null)) {
return f.getName();
}
}
}
}catch (Exception e){
e.printStackTrace();
System.out.println("DebugTools.matchConstant() ERROR! ");
return "ERROR(" + obj.toString() + ")";
}
return "NOT_FOUND(" + obj.toString() + ")";
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/dragonet/proxy/utilities/Versioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class Versioning {

public static final String RELEASE_VERSION = "0.3.2";
public static final String RELEASE_VERSION = "0.3.3";
public static final String MINECRAFT_PC_VERSION = "1.12.2";
// public static final int MINECRAFT_PC_PROTOCOL = 47;
// This is STRICT to MCPE binary's definition, DO NOT CHANGE
Expand Down
13 changes: 10 additions & 3 deletions src/main/resources/en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ init_creating_thread_pool=Creating thread pool(Size:%s)...
init_binding=Binding on %s:%s ...
init_done=The proxy has started!
command_not_found=\u00a7cCommand not found!
message_client_connected=Player %s[%s] connected!
message_online_notice=\u00b7------------------------\n\u00b7* Minecraft Login *\n\u00b7Powered by DragonProxy! \n\u00b7http://dragonet.org/proxy\n\u00b7\n\u00b7Logging in as [%s]. \n\u00b7------------------------
message_online_email=\u00b7Please enter your Minecraft PC/Mac account e-mail address in chat:
message_client_connected=Player %s[%s] connected!
message_login_prompt=\u00a7e==== \u00a7bLogin to \u00a74Minecraft \u00a7e====\n\
\u00a7fpowered by DragonProxy\n\
\u00a7aMove a bit to login!
message_login_progress=\u00a76authenticating...
form_login_title=\u00a71\u00a7lLogin to \u00a74\u00a7lMinecraft \u00a71\u00a7lAccount
form_login_desc=DragonProxy is a software to allow Bedrock players joining Minecraft: Java Edition servers.
form_login_prompt=\u00a7aYou are logging in to Minecraft: Java Edition account
form_login_username=\u00a7bUsername:
form_login_password=\u00a7bPassword:
message_online_error=\u00a7cYour details were wrong. Please rejoin.
message_online_password=\u00b7Please enter password:
message_online_logging_in=\u00b7Logging in via Mojang AB, please wait...
Expand Down

0 comments on commit ceab389

Please sign in to comment.