Skip to content

Commit

Permalink
Account linking part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 authored and Tim203 committed Apr 28, 2020
1 parent 2904612 commit 44384fa
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@ description: ${project.description}
version: ${project.version}
author: ${project.organization.name}
website: ${project.url}
main: org.geysermc.floodgate.BukkitPlugin
main: org.geysermc.floodgate.BukkitPlugin
commands:
linkaccount:
description: Link your Java and Bedrock accounts
usage: /linkaccount [code]
permission: floodgate.linkaccount
permission-message: You don't have the floodgate.linkaccount permission.
unlinkaccount:
description: Unlink your Java account from your Bedrock account
usage: /unlinkaccount
permission: floodgate.unlinkaccount
permission-message: You don't have the floodgate.unlinkaccount permission.
permissions:
floodgate.linkaccount:
description: Allows players to link their Bedrock and Java accounts
default: true
floodgate.unlinkaccount:
description: Allows players to unlink their Bedrock and Java accounts
default: true
6 changes: 6 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<version>2.9.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.30.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
13 changes: 13 additions & 0 deletions common/src/main/java/org/geysermc/floodgate/FloodgateConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class FloodgateConfig {
@JsonProperty(value = "disconnect")
private DisconnectMessages messages;

@JsonProperty(value = "player-link")
private PlayerLinkConfig playerLink;

@JsonProperty
private boolean debug;

Expand All @@ -40,6 +43,16 @@ public static class DisconnectMessages {
private String invalidArgumentsLength;
}

@Getter
public static class PlayerLinkConfig {
@JsonProperty("enable")
private boolean enabled;
@JsonProperty("allow-linking")
private boolean allowLinking;
@JsonProperty("link-code-timeout")
private long linkCodeTimeout;
}

public static FloodgateConfig load(Logger logger, Path configPath) {
return load(logger, configPath, FloodgateConfig.class);
}
Expand Down
48 changes: 48 additions & 0 deletions common/src/main/java/org/geysermc/floodgate/LinkRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.geysermc.floodgate;

import lombok.Getter;

import java.time.Instant;
import java.util.UUID;

@Getter
public class LinkRequest {
/**
* The Java username of the linked player
*/
private String javaUsername;
/**
* The Java UUID of the linked player
*/
private UUID javaUniqueId;
/**
* The link code
*/
private String linkCode;
/**
* The username of player being linked
*/
private String bedrockUsername;
/**
* The time when the link was requested
*/
private long unixTime;

LinkRequest(String username, UUID uuid, String code, String beUsername) {
javaUniqueId = uuid;
javaUsername = username;
linkCode = code;
bedrockUsername = beUsername;
unixTime = Instant.now().getEpochSecond();
}

public boolean isExpired() {
long timePassed = Instant.now().getEpochSecond() - unixTime;
return timePassed > PlayerLink.getVerifyLinkTimeout();
}

public boolean checkGamerTag(FloodgatePlayer player) {
// Accept the request whether the prefix was used or not
return bedrockUsername.equals(player.getUsername()) || bedrockUsername.equals(player.getJavaUsername());
}
}
25 changes: 25 additions & 0 deletions common/src/main/java/org/geysermc/floodgate/LinkedPlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.geysermc.floodgate;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.UUID;

@AllArgsConstructor(access = AccessLevel.PACKAGE)
@Getter @Setter
public class LinkedPlayer {
/**
* The Java username of the linked player
*/
public String javaUsername;
/**
* The Java UUID of the linked player
*/
public UUID javaUniqueId;
/**
* The UUID of the Bedrock player
*/
public UUID bedrockId;
}
16 changes: 16 additions & 0 deletions common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,19 @@ disconnect:
# The disconnect message Geyser users should get when connecting
# to the server with the correct key but not with the correct data format
invalid-arguments-length: Expected {0} arguments, got {1}. Is Geyser up-to-date?

# Configuration for player linking
player-link:
# Whether to enable the linking system. Turning this off will prevent
# players from using the linking feature even if they are already linked.
enable: false
# The type of storage system you want to use
# Currently implemented: SQLite
type: sqlite
# Whether to allow the use of /linkaccount and /unlinkaccount
# You can also use allow specific people to use the commands using the
# permissions floodgate.linkaccount and floodgate.unlinkaccount.
# This is only for linking, already connected people will stay connected
allow-linking: true
# The amount of time until a link code expires in seconds
link-code-timeout: 300

0 comments on commit 44384fa

Please sign in to comment.