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

Commit ceab389

Browse files
committed
new login method, and release 0.3.3
1 parent 4bd478d commit ceab389

File tree

12 files changed

+121
-34
lines changed

12 files changed

+121
-34
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<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">
22
<modelVersion>4.0.0</modelVersion>
33
<artifactId>proxy</artifactId>
4-
<version>0.3.2</version>
4+
<version>0.3.3</version>
55
<name>DragonProxy</name>
66
<groupId>org.dragonet.proxy</groupId>
77

screenshots/form-login.jpg

56.7 KB
Loading

src/main/java/org/dragonet/proxy/configuration/Lang.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ public class Lang extends PropertiesConfig {
2929
public static final String ERROR_CLS_UNREACHABLE = "error_cls_unreachable";
3030
public static final String ERROR_CLS_ERROR = "error_cls_error";
3131
public static final String ERROR_CLS_LOGIN = "error_cls_login";
32-
public static final String MESSAGE_ONLINE_NOTICE = "message_online_notice";
33-
public static final String MESSAGE_ONLINE_EMAIL = "message_online_email";
32+
//public static final String MESSAGE_ONLINE_NOTICE = "message_online_notice";
33+
//public static final String MESSAGE_ONLINE_EMAIL = "message_online_email";
34+
public static final String MESSAGE_LOGIN_PROMPT = "message_login_prompt";
35+
public static final String MESSAGE_LOGIN_PROGRESS = "message_login_progress";
36+
public static final String FORM_LOGIN_TITLE = "form_login_title";
37+
public static final String FORM_LOGIN_DESC = "form_login_desc";
38+
public static final String FORM_LOGIN_PROMPT = "form_login_prompt";
39+
public static final String FORM_LOGIN_USERNAME = "form_login_username";
40+
public static final String FORM_LOGIN_PASSWORD = "form_login_password";
3441
public static final String MESSAGE_ONLINE_ERROR = "message_online_error";
3542
public static final String MESSAGE_ONLINE_PASSWORD = "message_online_password";
36-
public static final String MESSAGE_ONLINE_LOGGIN_IN = "message_online_logging_in";
43+
public static final String MESSAGE_ONLINE_LOGGING_IN = "message_online_logging_in";
3744
public static final String MESSAGE_ONLINE_LOGIN_SUCCESS = "message_online_login_success";
3845
public static final String MESSAGE_ONLINE_LOGIN_SUCCESS_CONSOLE = "message_online_login_success_console";
3946
public static final String MESSAGE_TELEPORT_TO_SPAWN = "message_teleport_to_spawn";
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.dragonet.proxy.gui;
2+
3+
import org.json.JSONObject;
4+
5+
/**
6+
* Created on 2017/12/26.
7+
*/
8+
public class InputComponent extends BaseModalFormComponent {
9+
10+
private String text;
11+
12+
private String defaultValue;
13+
14+
private String placeholder;
15+
16+
public InputComponent(String text) {
17+
super("input");
18+
this.text = text;
19+
}
20+
21+
public InputComponent setDefaultValue(String defaultValue) {
22+
this.defaultValue = defaultValue;
23+
return this;
24+
}
25+
26+
public InputComponent setPlaceholder(String placeholder) {
27+
this.placeholder = placeholder;
28+
return this;
29+
}
30+
31+
@Override
32+
public void serializeData(JSONObject out) {
33+
out.put("text", text);
34+
if(defaultValue != null) out.put("default", defaultValue);
35+
if(placeholder != null) out.put("placeholder", placeholder);
36+
}
37+
}

src/main/java/org/dragonet/proxy/network/CacheKey.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public final class CacheKey {
2323
public static final String AUTHENTICATION_STATE = "auth_state";
2424
public static final String WINDOW_OPENED_ID = "window_opened_id";
2525

26-
// Strings
27-
public static final String AUTHENTICATION_EMAIL = "auth_mail";
28-
2926
// Positions
3027
public static final String BLOCK_BREAKING_POSITION = "block_breaking_position";
3128
public static final String WINDOW_BLOCK_POSITION = "window_block_position";

src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
import java.util.Deque;
1818

1919
import com.github.steveice10.packetlib.packet.Packet;
20+
import org.dragonet.proxy.configuration.Lang;
21+
import org.dragonet.proxy.gui.CustomFormComponent;
22+
import org.dragonet.proxy.gui.InputComponent;
23+
import org.dragonet.proxy.gui.LabelComponent;
2024
import org.dragonet.proxy.protocol.PEPacket;
2125
import org.dragonet.proxy.protocol.Protocol;
2226
import org.dragonet.proxy.protocol.ProtocolInfo;
23-
import org.dragonet.proxy.protocol.packets.ChunkRadiusUpdatedPacket;
24-
import org.dragonet.proxy.protocol.packets.LoginPacket;
25-
import org.dragonet.proxy.protocol.packets.RequestChunkRadiusPacket;
27+
import org.dragonet.proxy.protocol.packets.*;
28+
import org.json.JSONArray;
2629

2730
public class PEPacketProcessor implements Runnable {
2831

@@ -70,6 +73,8 @@ public void handlePacket(PEPacket packet) {
7073
return;
7174
}
7275

76+
System.out.println(" <<PE " + org.dragonet.proxy.utilities.DebugTools.matchConstant((byte)(packet.pid() & 0xFF), ProtocolInfo.class));
77+
7378
// System.out.println("RECEIVED PACKET=" + packet.getClass().getSimpleName());
7479
/*
7580
* try{ FileOutputStream fos = new FileOutputStream("cap_" +
@@ -80,6 +85,32 @@ public void handlePacket(PEPacket packet) {
8085
case ProtocolInfo.LOGIN_PACKET:
8186
client.onLogin((LoginPacket) packet);
8287
break;
88+
case ProtocolInfo.MOVE_PLAYER_PACKET:
89+
if(client.getDataCache().containsKey(CacheKey.AUTHENTICATION_STATE) &&
90+
client.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("online_login_wait")) {
91+
// client.getDataCache().put(CacheKey.AUTHENTICATION_STATE, "online_login");
92+
ModalFormRequestPacket packetForm = new ModalFormRequestPacket();
93+
CustomFormComponent form = new CustomFormComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_TITLE));
94+
form.addComponent(new LabelComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_DESC)));
95+
form.addComponent(new LabelComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_PROMPT)));
96+
form.addComponent(new InputComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_USERNAME)).setPlaceholder("[email protected]"));
97+
form.addComponent(new InputComponent(client.getProxy().getLang().get(Lang.FORM_LOGIN_PASSWORD)).setPlaceholder("123456"));
98+
packetForm.formId = 1;
99+
packetForm.formData = form.serializeToJson().toString();
100+
client.sendPacket(packetForm);
101+
break;
102+
}
103+
case ProtocolInfo.MODAL_FORM_RESPONSE_PACKET:
104+
if(client.getDataCache().containsKey(CacheKey.AUTHENTICATION_STATE) &&
105+
client.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("online_login_wait")) {
106+
client.sendChat(client.getProxy().getLang().get(Lang.MESSAGE_LOGIN_PROGRESS));
107+
108+
ModalFormResponsePacket formResponse = (ModalFormResponsePacket) packet;
109+
JSONArray array = new JSONArray(formResponse.formData);
110+
client.authenticate(array.get(2).toString(), array.get(3).toString());
111+
client.getDataCache().remove(CacheKey.AUTHENTICATION_STATE);
112+
break;
113+
}
83114
case ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET:
84115
if (client.isLoggedIn()) {
85116
return;
@@ -89,11 +120,6 @@ public void handlePacket(PEPacket packet) {
89120
case ProtocolInfo.REQUEST_CHUNK_RADIUS_PACKET:
90121
client.sendPacket(new ChunkRadiusUpdatedPacket(((RequestChunkRadiusPacket) packet).radius));
91122
break;
92-
case ProtocolInfo.TEXT_PACKET: // Text (check CLS Login)
93-
if (client.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) {
94-
PacketTranslatorRegister.translateToPC(client, packet);
95-
break;
96-
}
97123
default:
98124
if (client.getDownstream() == null) {
99125
break;

src/main/java/org/dragonet/proxy/network/UpstreamSession.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,10 @@ public void onDisconnect(String reason) {
249249
packetProcessorScheule.cancel(true);
250250
}
251251

252-
public void authenticate(String password) {
252+
public void authenticate(String email, String password) {
253253
proxy.getGeneralThreadPool().execute(() -> {
254254
try {
255-
protocol = new MinecraftProtocol((String) dataCache.get(CacheKey.AUTHENTICATION_EMAIL), password,
256-
false);
255+
protocol = new MinecraftProtocol(email, password, false);
257256
} catch (RequestException ex) {
258257
if (ex.getMessage().toLowerCase().contains("invalid")) {
259258
sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD));
@@ -347,14 +346,13 @@ public void postLogin() {
347346
sendPacket(new FullChunkDataPacket(-1, 0, data.getBuffer()));
348347
sendPacket(new FullChunkDataPacket(-1, -1, data.getBuffer()));
349348

349+
dataCache.put(CacheKey.AUTHENTICATION_STATE, "online_login_wait");
350+
350351
PlayStatusPacket pkStat = new PlayStatusPacket();
351352
pkStat.status = PlayStatusPacket.PLAYER_SPAWN;
352353
sendPacket(pkStat, true);
353354

354-
dataCache.put(CacheKey.AUTHENTICATION_STATE, "email");
355-
356-
sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_NOTICE, username));
357-
sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_EMAIL));
355+
sendChat(proxy.getLang().get(Lang.MESSAGE_LOGIN_PROMPT));
358356
} else if (proxy.getAuthMode().equals("cls")) {
359357
// CLS LOGIN!
360358
if ((username.length() < 6 + 1 + 1) || (!username.contains("_"))) {

src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414

1515
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
1616
import com.github.steveice10.packetlib.packet.Packet;
17-
import org.dragonet.proxy.configuration.Lang;
18-
import org.dragonet.proxy.network.CacheKey;
1917
import org.dragonet.proxy.network.UpstreamSession;
2018
import org.dragonet.proxy.network.translator.IPEPacketTranslator;
2119
import org.dragonet.proxy.protocol.packets.TextPacket;
22-
import org.dragonet.proxy.utilities.PatternChecker;
2320

2421
public class PEChatPacketTranslator implements IPEPacketTranslator<TextPacket> {
2522

2623
public Packet[] translate(UpstreamSession session, TextPacket packet) {
27-
if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) {
24+
/*if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) {
2825
if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("email")) {
2926
if (!PatternChecker.matchEmail(packet.message.trim())) {
3027
session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR));
@@ -40,12 +37,12 @@ public Packet[] translate(UpstreamSession session, TextPacket packet) {
4037
session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR));
4138
return null;
4239
}
43-
session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGGIN_IN));
40+
session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGGING_IN));
4441
session.getDataCache().remove(CacheKey.AUTHENTICATION_STATE);
4542
session.authenticate(packet.message); // We NEVER cache password for better security.
4643
}
4744
return null;
48-
}
45+
}*/
4946

5047
ClientChatPacket pk = new ClientChatPacket(packet.message);
5148
return new Packet[]{pk};

src/main/java/org/dragonet/proxy/protocol/packets/ModalFormResponsePacket.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99
public class ModalFormResponsePacket extends PEPacket {
1010

11-
private int formId;
12-
private String formData;
11+
public int formId;
12+
public String formData;
1313

1414
@Override
1515
public int pid() {

src/main/java/org/dragonet/proxy/utilities/DebugTools.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,22 @@ public static String getAllFields(Object obj) {
6060
}
6161
return data;
6262
}
63+
64+
public static String matchConstant(Object obj, Class target) {
65+
if(obj == null) return "NULL";
66+
try {
67+
for (Field f : target.getDeclaredFields()) {
68+
if ((f.getModifiers() & Modifier.STATIC) > 0) {
69+
if (obj == f.get(null)) {
70+
return f.getName();
71+
}
72+
}
73+
}
74+
}catch (Exception e){
75+
e.printStackTrace();
76+
System.out.println("DebugTools.matchConstant() ERROR! ");
77+
return "ERROR(" + obj.toString() + ")";
78+
}
79+
return "NOT_FOUND(" + obj.toString() + ")";
80+
}
6381
}

0 commit comments

Comments
 (0)