use of net.glowstone.entity.meta.profile.PlayerProfile in project Dragonet-Legacy by DragonetMC.
the class PENetworkClient method handlePacket.
public void handlePacket(PEPacket packet) {
//System.out.println("Received Packet: " + packet.getClass().getSimpleName());
switch(packet.pid()) {
case PEPacketIDs.LOGIN_PACKET:
LoginPacket packetLogin = (LoginPacket) packet;
this.username = packetLogin.username;
BaseTranslator translator = TranslatorProvider.getByPEProtocolID(packetLogin.protocol1, packetLogin.protocol2);
if (!(translator instanceof BaseTranslator)) {
LoginStatusPacket pkLoginStatus = new LoginStatusPacket();
pkLoginStatus.status = LoginStatusPacket.LOGIN_FAILED_CLIENT;
this.sendPacket(pkLoginStatus);
this.disconnect("Unsupported game version! ");
break;
}
session = new MCPESession(inf.getSesMan().getServer(), this, translator);
LoginStatusPacket pkLoginStatus = new LoginStatusPacket();
pkLoginStatus.status = LoginStatusPacket.LOGIN_SUCCESS;
this.sendPacket(pkLoginStatus);
inf.getSesMan().getServer().getLogger().info("Accepted connection by [" + this.username + "]. ");
Matcher matcher = DragonetSession.PATTERN_USERNAME.matcher(this.username);
if (!matcher.matches()) {
this.disconnect("Bad username! ");
break;
}
session.setPlayer(new PlayerProfile(this.username, UUID.nameUUIDFromBytes(("OfflinePlayer:" + this.username).getBytes(StandardCharsets.UTF_8))));
break;
case PEPacketIDs.BATCH_PACKET:
BatchPacket packetBatch = (BatchPacket) packet;
if (packetBatch.packets == null || packetBatch.packets.isEmpty()) {
break;
}
for (PEPacket pk : packetBatch.packets) {
this.handlePacket(pk);
}
break;
default:
if (session == null) {
disconnect("Network error! ");
return;
}
session.onPacketReceived(packet);
}
}
use of net.glowstone.entity.meta.profile.PlayerProfile in project Glowstone by GlowstoneMC.
the class GlowSkull method setOwner.
@Override
public boolean setOwner(String name) {
PlayerProfile owner = PlayerProfile.getProfile(name);
if (owner == null) {
return false;
}
this.owner = owner;
setSkullType(SkullType.PLAYER);
return true;
}
use of net.glowstone.entity.meta.profile.PlayerProfile 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.entity.meta.profile.PlayerProfile in project Glowstone by GlowstoneMC.
the class GlowMetaSkull method setOwner.
@Override
public boolean setOwner(String name) {
PlayerProfile owner = PlayerProfile.getProfile(name);
if (owner == null) {
return false;
}
this.owner = owner;
return true;
}
use of net.glowstone.entity.meta.profile.PlayerProfile in project Glowstone by GlowstoneMC.
the class GlowServer method getOfflinePlayer.
@Override
@Deprecated
public OfflinePlayer getOfflinePlayer(String name) {
Player onlinePlayer = getPlayerExact(name);
if (onlinePlayer != null) {
return onlinePlayer;
}
OfflinePlayer result = getPlayerExact(name);
if (result == null) {
//probably blocking (same player once per minute)
PlayerProfile profile = PlayerProfile.getProfile(name);
if (profile == null) {
result = getOfflinePlayer(new PlayerProfile(name, UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes())));
} else {
result = getOfflinePlayer(profile);
}
}
return result;
}
Aggregations