use of net.glowstone.net.ProxyData in project Glowstone by GlowstoneMC.
the class LoginStartHandler method handle.
@Override
public void handle(GlowSession session, LoginStartMessage message) {
String name = message.getUsername();
if (session.getServer().getOnlineMode()) {
// Get necessary information to create our request message
String sessionId = session.getSessionId();
//Convert to X509 format
byte[] publicKey = SecurityUtils.generateX509Key(session.getServer().getKeyPair().getPublic()).getEncoded();
byte[] verifyToken = SecurityUtils.generateVerifyToken();
// Set verify data on session for use in the response handler
session.setVerifyToken(verifyToken);
session.setVerifyUsername(name);
// Send created request message and wait for the response
session.send(new EncryptionKeyRequestMessage(sessionId, publicKey, verifyToken));
} else {
PlayerProfile profile;
ProxyData proxy = session.getProxyData();
if (proxy == null) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
profile = new PlayerProfile(name, uuid);
} else {
profile = proxy.getProfile();
if (profile == null) {
profile = proxy.getProfile(name);
}
}
AsyncPlayerPreLoginEvent event = EventFactory.onPlayerPreLogin(profile.getName(), session.getAddress(), profile.getUniqueId());
if (event.getLoginResult() != Result.ALLOWED) {
session.disconnect(event.getKickMessage(), true);
return;
}
PlayerProfile finalProfile = profile;
session.getServer().getScheduler().runTask(null, () -> session.setPlayer(finalProfile));
}
}
use of net.glowstone.net.ProxyData in project Glowstone by GlowstoneMC.
the class HandshakeHandler method handle.
@Override
public void handle(GlowSession session, HandshakeMessage message) {
ProtocolType protocol;
if (message.getState() == 1) {
protocol = ProtocolType.STATUS;
} else if (message.getState() == 2) {
protocol = ProtocolType.LOGIN;
} else {
session.disconnect("Invalid state");
return;
}
session.setVersion(message.getVersion());
session.setHostname(message.getAddress() + ":" + message.getPort());
// the client's UUID and (optionally) properties
if (session.getServer().getProxySupport()) {
try {
session.setProxyData(new ProxyData(session, message.getAddress()));
} catch (IllegalArgumentException ex) {
session.disconnect("Invalid proxy data provided.");
// protocol is still set here and below to prevent errors
// trying to decode packets after this one under the wrong
// protocol, even though client is kicked
session.setProtocol(protocol);
return;
} catch (Exception ex) {
GlowServer.logger.log(Level.SEVERE, "Error parsing proxy data for " + session, ex);
session.disconnect("Failed to parse proxy data.");
session.setProtocol(protocol);
return;
}
}
session.setProtocol(protocol);
if (protocol == ProtocolType.LOGIN) {
if (message.getVersion() < GlowServer.PROTOCOL_VERSION) {
session.disconnect("Outdated client! I'm running " + GlowServer.GAME_VERSION);
} else if (message.getVersion() > GlowServer.PROTOCOL_VERSION) {
session.disconnect("Outdated server! I'm running " + GlowServer.GAME_VERSION);
}
}
}
Aggregations