mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Fix user verification.
This commit is contained in:
parent
aff6600deb
commit
6cc87bcbdb
1 changed files with 27 additions and 26 deletions
|
@ -1,8 +1,8 @@
|
||||||
package org.spacehq.mc.protocol;
|
package org.spacehq.mc.protocol;
|
||||||
|
|
||||||
import org.spacehq.mc.auth.data.GameProfile;
|
import org.spacehq.mc.auth.data.GameProfile;
|
||||||
|
import org.spacehq.mc.auth.exception.request.RequestException;
|
||||||
import org.spacehq.mc.auth.service.SessionService;
|
import org.spacehq.mc.auth.service.SessionService;
|
||||||
import org.spacehq.mc.auth.exception.request.ServiceUnavailableException;
|
|
||||||
import org.spacehq.mc.protocol.data.SubProtocol;
|
import org.spacehq.mc.protocol.data.SubProtocol;
|
||||||
import org.spacehq.mc.protocol.data.status.ServerStatusInfo;
|
import org.spacehq.mc.protocol.data.status.ServerStatusInfo;
|
||||||
import org.spacehq.mc.protocol.data.status.handler.ServerInfoBuilder;
|
import org.spacehq.mc.protocol.data.status.handler.ServerInfoBuilder;
|
||||||
|
@ -120,6 +120,7 @@ public class ServerListener extends SessionAdapter {
|
||||||
ServerInfoBuilder builder = event.getSession().getFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY);
|
ServerInfoBuilder builder = event.getSession().getFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY);
|
||||||
if(builder == null) {
|
if(builder == null) {
|
||||||
event.getSession().disconnect("No server info builder set.");
|
event.getSession().disconnect("No server info builder set.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerStatusInfo info = builder.buildInfo(event.getSession());
|
ServerStatusInfo info = builder.buildInfo(event.getSession());
|
||||||
|
@ -161,34 +162,34 @@ public class ServerListener extends SessionAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MinecraftProtocol protocol = (MinecraftProtocol) this.session.getPacketProtocol();
|
Proxy proxy = this.session.<Proxy>getFlag(MinecraftConstants.AUTH_PROXY_KEY);
|
||||||
|
if(proxy == null) {
|
||||||
|
proxy = Proxy.NO_PROXY;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameProfile profile = null;
|
||||||
try {
|
try {
|
||||||
Proxy proxy = this.session.<Proxy>getFlag(MinecraftConstants.AUTH_PROXY_KEY);
|
profile = new SessionService(proxy).getProfileByServer(username, new BigInteger(CryptUtil.getServerIdHash(serverId, pair.getPublic(), this.key)).toString(16));
|
||||||
if(proxy == null) {
|
} catch(RequestException e) {
|
||||||
proxy = Proxy.NO_PROXY;
|
this.session.disconnect("Failed to make session service request.", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(profile != null) {
|
||||||
|
int threshold = this.session.getFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD);
|
||||||
|
this.session.send(new LoginSetCompressionPacket(threshold));
|
||||||
|
this.session.setCompressionThreshold(threshold);
|
||||||
|
this.session.send(new LoginSuccessPacket(profile));
|
||||||
|
this.session.setFlag(MinecraftConstants.PROFILE_KEY, profile);
|
||||||
|
((MinecraftProtocol) this.session.getPacketProtocol()).setSubProtocol(SubProtocol.GAME, false, this.session);
|
||||||
|
ServerLoginHandler handler = this.session.getFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY);
|
||||||
|
if(handler != null) {
|
||||||
|
handler.loggedIn(this.session);
|
||||||
}
|
}
|
||||||
|
|
||||||
String serverHash = new BigInteger(CryptUtil.getServerIdHash(serverId, pair.getPublic(), this.key)).toString(16);
|
new Thread(new KeepAlive(this.session)).start();
|
||||||
SessionService service = new SessionService(proxy);
|
} else {
|
||||||
GameProfile profile = service.getProfileByServer(username, serverHash);
|
this.session.disconnect("Failed to verify username.");
|
||||||
if(profile != null) {
|
|
||||||
int threshold = this.session.getFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD);
|
|
||||||
this.session.send(new LoginSetCompressionPacket(threshold));
|
|
||||||
this.session.setCompressionThreshold(threshold);
|
|
||||||
this.session.send(new LoginSuccessPacket(profile));
|
|
||||||
this.session.setFlag(MinecraftConstants.PROFILE_KEY, profile);
|
|
||||||
protocol.setSubProtocol(SubProtocol.GAME, false, this.session);
|
|
||||||
ServerLoginHandler handler = this.session.getFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY);
|
|
||||||
if(handler != null) {
|
|
||||||
handler.loggedIn(this.session);
|
|
||||||
}
|
|
||||||
|
|
||||||
new Thread(new KeepAlive(this.session)).start();
|
|
||||||
} else {
|
|
||||||
this.session.disconnect("Failed to verify username!");
|
|
||||||
}
|
|
||||||
} catch(ServiceUnavailableException e) {
|
|
||||||
this.session.disconnect("Authentication servers are down. Please try again later, sorry!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue