Skip to content

Commit

Permalink
Update Smoothness PR for Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Jul 21, 2020
1 parent ae01988 commit b37c77b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.geysermc.connector.event.events.network.SessionDisconnectEvent;
import org.geysermc.connector.event.events.packet.DownstreamPacketReceiveEvent;
import org.geysermc.connector.event.events.packet.DownstreamPacketSendEvent;
import org.geysermc.connector.event.events.packet.UpstreamPacketReceiveEvent;
import org.geysermc.connector.event.events.packet.UpstreamPacketSendEvent;
import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.remote.RemoteServer;
Expand Down Expand Up @@ -249,6 +250,10 @@ public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServ
public void connect(RemoteServer remoteServer) {
this.remoteServer = remoteServer;

if (EventManager.getInstance().triggerEvent(new GeyserLoginEvent(this)).isCancelled()) {
return;
}

if (connector.getAuthType() != AuthType.ONLINE) {
if (connector.getAuthType() == AuthType.OFFLINE) {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.offline"));
Expand Down Expand Up @@ -288,6 +293,10 @@ public void start() {
}

public void initialize() {
if (getUpstream().isInitialized()) {
return;
}

startGame();

BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
Expand All @@ -309,29 +318,17 @@ public void initialize() {
}
}

public void login() {
if (EventManager.getInstance().triggerEvent(new GeyserLoginEvent(this)).isCancelled()) {
return;
}

if (connector.getAuthType() != AuthType.ONLINE) {
if (connector.getAuthType() == AuthType.OFFLINE) {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.offline"));
} else {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.floodgate"));
}
authenticate(authData.getName());
}
}

public void authenticate(String username) {
authenticate(username, "");
}

public void authenticate(String username, String password) {
if (EventManager.getInstance().triggerEvent(new GeyserAuthenticationEvent(this, username, password)).isCancelled()) {
EventManager.TriggerResult<GeyserAuthenticationEvent> result = EventManager.getInstance().triggerEvent(new GeyserAuthenticationEvent(this, username, password));
if (result.isCancelled()) {
return;
}
final String user = result.getEvent().getUsername();
final String pass = result.getEvent().getPassword();

if (loggedIn) {
connector.getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.auth.already_loggedin", username));
Expand All @@ -342,10 +339,10 @@ public void authenticate(String username, String password) {
// new thread so clients don't timeout
new Thread(() -> {
try {
if (password != null && !password.isEmpty()) {
protocol = new MinecraftProtocol(username.replace(" ","_"), password);
if (pass != null && !pass.isEmpty()) {
protocol = new MinecraftProtocol(user.replace(" ","_"), pass);
} else {
protocol = new MinecraftProtocol(username.replace(" ","_"));
protocol = new MinecraftProtocol(user.replace(" ","_"));
}

boolean floodgate = connector.getAuthType() == AuthType.FLOODGATE;
Expand Down Expand Up @@ -551,6 +548,18 @@ public boolean isConsole() {
}

public void sendForm(FormWindow window, int id) {
if (!getUpstream().isInitialized()) {
initialize();
start();
EventManager.getInstance().on(UpstreamPacketReceiveEvent.class, (h, e) -> {
h.unregister();
windowCache.showWindow(window, id);
})
.filter(SetLocalPlayerAsInitializedPacket.class)
.build();
return;
}

windowCache.showWindow(window, id);
}

Expand All @@ -569,6 +578,18 @@ public InetSocketAddress getSocketAddress() {
}

public void sendForm(FormWindow window) {
if (!getUpstream().isInitialized()) {
initialize();
start();
EventManager.getInstance().on(UpstreamPacketReceiveEvent.class, (h,e) -> {
h.unregister();
windowCache.showWindow(window);
})
.filter(SetLocalPlayerAsInitializedPacket.class)
.build();
return;
}

windowCache.showWindow(window);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,7 @@ public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession se
}

if (entity.isPlayerList()) {
PlayerListPacket.Entry entry = SkinUtils.buildCachedEntry(entity.getProfile(), entity.getGeyserId());
if (entity == session.getPlayerEntity()) {
// Copy the entry with our identity instead.
PlayerListPacket.Entry copy = new PlayerListPacket.Entry(session.getAuthData().getUUID());
copy.setName(entry.getName());
copy.setEntityId(entry.getEntityId());
copy.setSkin(entry.getSkin());
copy.setXuid(entry.getXuid());
copy.setPlatformChatId(entry.getPlatformChatId());
copy.setTeacher(entry.isTeacher());
entry = copy;
}
playerListPacket.getEntries().add(entry);
playerListPacket.getEntries().add(SkinUtils.buildCachedEntry(session, entity));
}
}

Expand Down

0 comments on commit b37c77b

Please sign in to comment.