-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PacketHandlerCodec for entire login and config process
- Loading branch information
Showing
50 changed files
with
1,170 additions
and
796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/zenith/cache/data/config/ConfigurationCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.zenith.network; | ||
|
||
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundKeepAlivePacket; | ||
import com.zenith.network.server.ServerConnection; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.zenith.Shared.SCHEDULED_EXECUTOR_SERVICE; | ||
|
||
public class KeepAliveTask implements Runnable { | ||
private final ServerConnection session; | ||
|
||
public KeepAliveTask(ServerConnection session) { | ||
this.session = session; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (this.session.isConnected()) { | ||
session.setLastPingTime(System.currentTimeMillis()); | ||
session.setLastPingId((int) session.getLastPingTime()); | ||
this.session.sendAsync(new ClientboundKeepAlivePacket(session.getLastPingId())); | ||
SCHEDULED_EXECUTOR_SERVICE.schedule(this, 2L, TimeUnit.SECONDS); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.zenith.network; | ||
|
||
import com.github.steveice10.mc.auth.data.GameProfile; | ||
import com.github.steveice10.mc.auth.exception.request.RequestException; | ||
import com.github.steveice10.mc.auth.service.SessionService; | ||
import com.github.steveice10.mc.protocol.MinecraftConstants; | ||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginCompressionPacket; | ||
import com.zenith.network.server.ServerConnection; | ||
|
||
import javax.crypto.SecretKey; | ||
import java.util.UUID; | ||
|
||
public class UserAuthTask implements Runnable { | ||
private ServerConnection session; | ||
private SecretKey key; | ||
|
||
public UserAuthTask(ServerConnection session, SecretKey key) { | ||
this.key = key; | ||
this.session = session; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
GameProfile profile; | ||
if (this.key != null) { | ||
SessionService sessionService = this.session.getFlag(MinecraftConstants.SESSION_SERVICE_KEY, | ||
new SessionService()); | ||
try { | ||
profile = sessionService.getProfileByServer(session.getUsername(), | ||
sessionService.getServerId(session.getServerId(), | ||
session.getKeyPair().getPublic(), | ||
this.key)); | ||
} catch (RequestException e) { | ||
this.session.disconnect("Failed to make session service request.", e); | ||
return; | ||
} | ||
|
||
if (profile == null) { | ||
this.session.disconnect("Failed to verify username."); | ||
} | ||
} else { | ||
profile = new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + session.getUsername()).getBytes()), | ||
session.getUsername()); | ||
} | ||
|
||
this.session.setFlag(MinecraftConstants.PROFILE_KEY, profile); | ||
|
||
int threshold = session.getFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD, | ||
ServerConnection.DEFAULT_COMPRESSION_THRESHOLD); | ||
this.session.send(new ClientboundLoginCompressionPacket(threshold)); | ||
} | ||
} |
Oops, something went wrong.