Skip to content
Permalink
Browse files

Use an explicit Marker parameter instead of treating nullness of auth…

…entications as magic
  • Loading branch information...
Brianetta committed Feb 20, 2018
1 parent 10dedf1 commit 0253f08c5d366cf04f7e00761b5fc70c1489dc04
@@ -106,10 +106,10 @@ public void loginEvent(PlayerLoggedInEvent event)
}

@Override
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications)
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications, Marker authresult)
{
// null authentications means "kick"
if (authentications != null) return;
// Don't kick players unless authresult was one of the DENIED_* values
if (authresult == Marker.ALLOWED) return;
server.addScheduledTask(() -> {
EntityPlayerMP p = server.getPlayerList().getPlayerByUUID(player.getUuid());
//noinspection ConstantConditions
@@ -96,10 +96,10 @@ public void loginEvent(PlayerLoggedInEvent event)
}

@Override
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications)
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications, Marker authresult)
{
// null authentications means "kick"
if (authentications != null) return;
// Don't kick players unless authresult was one of the DENIED_* values
if (authresult == Marker.ALLOWED) return;
server.addScheduledTask(() -> {
EntityPlayerMP p = server.getPlayerList().getPlayerByUUID(player.getUuid());
//noinspection ConstantConditions
@@ -103,10 +103,10 @@ public void loginEvent(PlayerLoggedInEvent event)
}

@Override
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications)
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications, Marker authresult)
{
// null authentications means "kick"
if (authentications != null) return;
// Don't kick players unless authresult was one of the DENIED_* values
if (authresult == Marker.ALLOWED) return;
server.addScheduledTask(() -> {
EntityPlayerMP p = server.getPlayerList().getPlayerByUUID(player.getUuid());
//noinspection ConstantConditions
@@ -144,10 +144,10 @@ public void tickEvent(TickEvent.ServerTickEvent event)
}

@Override
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications)
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications, Marker authresult)
{
// null authentications means "kick"
if (authentications != null) return;
// Don't kick players unless authresult was one of the DENIED_* values
if (authresult == Marker.ALLOWED) return;
// 1.7.10 doesn't have threading, so use server tick even to sync.
TO_KICK.put(player.getName(), msg);
}
@@ -44,13 +44,10 @@ public void sendMessage(String message, FormatCode formatCode)
}

@Override
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications)
protected void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications, Marker authresult)
{
if (authentications == null) {
// null authentications means "kick"
Bukkit.getScheduler().runTask(MCLink.this, () -> Bukkit.getPlayer(player.getUuid()).kickPlayer(msg));
} else {
// Authentication returned something, now schedule a synchronous Event for Bukkit plugins to handle
if (authresult == Marker.ALLOWED) {
// Authentication succeeded, now schedule a synchronous Event for Bukkit plugins to handle
new BukkitRunnable() {
@Override
public void run() {
@@ -63,6 +60,9 @@ public void run() {
}
}
}.runTask(MCLink.this);
} else {
// authresult was DENIED_*, kick the player
Bukkit.getScheduler().runTask(MCLink.this, () -> Bukkit.getPlayer(player.getUuid()).kickPlayer(msg));
}
}

@@ -41,7 +41,7 @@
private Status latestStatus;
private String branding;

protected abstract void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications);
protected abstract void authCompleteAsync(IPlayer player, String msg, UUID name, ImmutableCollection<Authentication> authentications, Marker authresult);

@Nullable
protected abstract String nameFromUUID(UUID uuid);
@@ -81,14 +81,13 @@ public void login(IPlayer player, boolean sendStatus)
case IN_PROGRESS:
break;
case DENIED_NO_AUTH:
// null authentications means "kick"
authCompleteAsync(player, config.getKickMessage(), player.getUuid(), null);
authCompleteAsync(player, config.getKickMessage(), player.getUuid(), null, Marker.DENIED_NO_AUTH);
return;
case DENIED_ERROR:
authCompleteAsync(player, config.getErrorMessage(), player.getUuid(), null);
authCompleteAsync(player, config.getErrorMessage(), player.getUuid(), null, Marker.DENIED_ERROR);
return;
case DENIED_CLOSED:
authCompleteAsync(player, config.getClosedMessage(), player.getUuid(), null);
authCompleteAsync(player, config.getClosedMessage(), player.getUuid(), null, Marker.DENIED_CLOSED);
return;
}
if (sendStatus && latestStatus != null && config.isShowStatus())
@@ -257,7 +256,7 @@ private void check(IPlayer player,boolean free)
{
UUID_STATUS_MAP.remove(player.getUuid()); // login event already past, so we don't need this anymore.
// null authentications means "kick"
authCompleteAsync(player, config.getKickMessage(), player.getUuid(), null);
authCompleteAsync(player, config.getKickMessage(), player.getUuid(), null, Marker.DENIED_NO_AUTH);
}
}
else
@@ -271,7 +270,7 @@ private void check(IPlayer player,boolean free)
}
logger.info("Player {0} was authorized by: {1}", player, auths);
// send the authentications to the mod in question
authCompleteAsync(player, null, player.getUuid(), auth);
authCompleteAsync(player, null, player.getUuid(), auth, Marker.ALLOWED);
if (UUID_STATUS_MAP.put(player.getUuid(), Marker.ALLOWED) == null) // was already removed by login
{
UUID_STATUS_MAP.remove(player.getUuid()); // login event already passed, so we don't need this anymore.
@@ -287,7 +286,7 @@ private void check(IPlayer player,boolean free)
{
UUID_STATUS_MAP.remove(player.getUuid()); // login event already past, so we don't need this anymore.
// null authentications means "kick"
authCompleteAsync(player, config.getErrorMessage(), player.getUuid(), null);
authCompleteAsync(player, config.getErrorMessage(), player.getUuid(), null, Marker.DENIED_ERROR);
}
}
}

0 comments on commit 0253f08

Please sign in to comment.
You can’t perform that action at this time.