Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions packages/core/src/handlers/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import { NetworkHandler } from "../network";
import { ClientSystemInfo, Player } from "../entity";
import { PlayerProperties } from "../types";
import { PlayerJoinSignal } from "../events";

Check warning on line 20 in packages/core/src/handlers/login.ts

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import { AuthenticationType } from "@serenityjs/protocol/src/types/authentication-type";

Check warning on line 21 in packages/core/src/handlers/login.ts

View workflow job for this annotation

GitHub Actions / Lint

`@serenityjs/protocol/src/types/authentication-type` import should occur before import of `../network`

class LoginHandler extends NetworkHandler {
public static readonly packet = Packet.Login;
Expand All @@ -28,7 +29,23 @@
// Decode the tokens given by the client.
// This contains the client data, identity data, and public key.
// Along with the players XUID, display name, and uuid.
const { clientData, identityData } = LoginHandler.decode(packet.tokens);
const { clientData, identityData, authenticationType } = LoginHandler.decode(packet.tokens);

// Check if the authentication type is valid.
// The LoginPacket passes one of three authentication types:
// 0 - Standard, the player is using their own token to connect.
// 1 - The connection is coming from a guest split screen session using the host's token.
// 2 - The connection is not authenticated.
// By default, we do not want to allow guest or unauthenticated connections to the server.

if (authenticationType !== AuthenticationType.Full && !this.serenity.properties.allowUnsignedConnections) {
// Disconnect the player.
return this.network.disconnectConnection(
connection,
"Failed to authenticate. Make sure you are connected to Xbox Live before joining the server.",
DisconnectReason.NotAuthenticated
);
}

// Get the clients xuid and username.
const xuid = identityData.XUID;
Expand Down Expand Up @@ -165,7 +182,7 @@
const clientData: ClientData = this.decoder(tokens.client);

// Parse the identity data from the tokens
const identity: { Certificate: string } = JSON.parse(tokens.identity);
const identity: { AuthenticationType: number, Certificate: string } = JSON.parse(tokens.identity);

// Get the identity chain from the identity data
const chains: Array<string> = JSON.parse(identity.Certificate).chain;
Expand All @@ -187,7 +204,8 @@
return {
clientData,
identityData,
publicKey
publicKey,
authenticationType: identity.AuthenticationType
};
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/serenity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const DefaultSerenityProperties: SerenityProperties = {
movementValidation: true,
movementHorizontalThreshold: 0.4,
movementVerticalThreshold: 0.6,
allowUnsignedConnections: false,
shutdownMessage: "Server is shutting down.",
ticksPerSecond: 20,
debugLogging: false
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/serenity-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SerenityProperties {
movementValidation: boolean;
movementHorizontalThreshold: number;
movementVerticalThreshold: number;
allowUnsignedConnections: boolean;
shutdownMessage: string;
ticksPerSecond: number;
debugLogging: boolean;
Expand Down
7 changes: 7 additions & 0 deletions packages/protocol/src/types/authentication-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum AuthenticationType {
Full = 0, // The player's own token
Guest = 1, // Split screen sessions, the player is using the host's token
SelfSigned = 2 // Not authenticated
}

export { AuthenticationType }

Check warning on line 7 in packages/protocol/src/types/authentication-type.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `;⏎`
3 changes: 3 additions & 0 deletions packages/protocol/src/types/login-data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AuthenticationType } from "./authentication-type";

interface ClientData {
AnimatedImageData: Array<AnimatedImageData>;
ArmSize: string;
Expand Down Expand Up @@ -78,6 +80,7 @@
clientData: ClientData;
identityData: IdentityData;
publicKey: string;
authenticationType: AuthenticationType

Check warning on line 83 in packages/protocol/src/types/login-data.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `;`
}

export type { LoginTokenData, IdentityData, ClientData };
Loading