Added timeout
Added timeout for not authenticated players, as well as kick for wrong password.
This commit is contained in:
parent
9965e8d804
commit
16773c125a
|
@ -117,7 +117,7 @@ public class AuthCommand {
|
||||||
if(sender != null)
|
if(sender != null)
|
||||||
sender.sendMessage(configurationReloaded);
|
sender.sendMessage(configurationReloaded);
|
||||||
else
|
else
|
||||||
LOGGER.info(configurationReloaded);
|
LOGGER.info(SimpleAuth.config.lang.configurationReloaded);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import org.samo_lego.simpleauth.SimpleAuth;
|
import org.samo_lego.simpleauth.SimpleAuth;
|
||||||
import org.samo_lego.simpleauth.utils.AuthHelper;
|
import org.samo_lego.simpleauth.utils.AuthHelper;
|
||||||
|
|
||||||
|
@ -47,12 +46,11 @@ public class LoginCommand {
|
||||||
// Player no longer needs to be invisible and invulnerable
|
// Player no longer needs to be invisible and invulnerable
|
||||||
player.setInvulnerable(false);
|
player.setInvulnerable(false);
|
||||||
player.setInvisible(false);
|
player.setInvisible(false);
|
||||||
//player.setAir(AuthEventHandler.playerAir);
|
|
||||||
//player.getDataTracker().startTracking();
|
|
||||||
player.sendMessage(successfullyAuthenticated);
|
player.sendMessage(successfullyAuthenticated);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
player.sendMessage(wrongPassword);
|
player.networkHandler.disconnect(wrongPassword);
|
||||||
|
//player.sendMessage(wrongPassword);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,17 @@ import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.TypedActionResult;
|
import net.minecraft.util.TypedActionResult;
|
||||||
import org.samo_lego.simpleauth.SimpleAuth;
|
import org.samo_lego.simpleauth.SimpleAuth;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will take care of actions players try to do,
|
* This class will take care of actions players try to do,
|
||||||
* and cancels them if they aren't authenticated
|
* and cancel them if they aren't authenticated
|
||||||
*/
|
*/
|
||||||
public class AuthEventHandler {
|
public class AuthEventHandler {
|
||||||
private static TranslatableText notAuthenticated = new TranslatableText(SimpleAuth.config.lang.notAuthenticated);
|
private static TranslatableText notAuthenticated = new TranslatableText(SimpleAuth.config.lang.notAuthenticated);
|
||||||
|
private static TranslatableText timeExpired = new TranslatableText(SimpleAuth.config.lang.timeExpired);
|
||||||
|
private static int delay = SimpleAuth.config.main.delay;
|
||||||
|
|
||||||
// Player joining the server
|
// Player joining the server
|
||||||
public static void onPlayerJoin(ServerPlayerEntity player) {
|
public static void onPlayerJoin(ServerPlayerEntity player) {
|
||||||
|
@ -24,6 +29,14 @@ public class AuthEventHandler {
|
||||||
// Setting the player to be invisible to mobs and also invulnerable
|
// Setting the player to be invisible to mobs and also invulnerable
|
||||||
player.setInvulnerable(SimpleAuth.config.main.playerInvulnerable);
|
player.setInvulnerable(SimpleAuth.config.main.playerInvulnerable);
|
||||||
player.setInvisible(SimpleAuth.config.main.playerInvisible);
|
player.setInvisible(SimpleAuth.config.main.playerInvisible);
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(!SimpleAuth.isAuthenticated(player)) // Kicking player if not authenticated
|
||||||
|
player.networkHandler.disconnect(timeExpired);
|
||||||
|
}
|
||||||
|
}, delay * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Player leaving the server
|
// Player leaving the server
|
||||||
|
|
|
@ -37,8 +37,12 @@ public class AuthConfig {
|
||||||
public boolean allowItemUse = false;
|
public boolean allowItemUse = false;
|
||||||
public boolean allowEntityPunch = false;
|
public boolean allowEntityPunch = false;
|
||||||
public boolean allowEntityInteract = false;
|
public boolean allowEntityInteract = false;
|
||||||
|
// If player should be invulnerable before authentication
|
||||||
public boolean playerInvulnerable = true;
|
public boolean playerInvulnerable = true;
|
||||||
|
// If player should be invisible to mobs before authentication
|
||||||
public boolean playerInvisible = true;
|
public boolean playerInvisible = true;
|
||||||
|
// Time after which player will be kicked if not authenticated [s]
|
||||||
|
public int delay = 60;
|
||||||
}
|
}
|
||||||
public static class LangConfig {
|
public static class LangConfig {
|
||||||
public String enterPassword = "§6You need to enter your password!";
|
public String enterPassword = "§6You need to enter your password!";
|
||||||
|
@ -49,6 +53,7 @@ public class AuthConfig {
|
||||||
public String notAuthenticated = "§cYou are not authenticated!\n§6Try with /login or /register.";
|
public String notAuthenticated = "§cYou are not authenticated!\n§6Try with /login or /register.";
|
||||||
public String alreadyAuthenticated = "§4You are already authenticated.";
|
public String alreadyAuthenticated = "§4You are already authenticated.";
|
||||||
public String successfullyAuthenticated = "§aYou are now authenticated.";
|
public String successfullyAuthenticated = "§aYou are now authenticated.";
|
||||||
|
public String timeExpired = "§cTime for authentication has expired.";
|
||||||
public String alreadyRegistered = "§6This account name is already registered!";
|
public String alreadyRegistered = "§6This account name is already registered!";
|
||||||
public String registerSuccess = "§aYou are now authenticated.";
|
public String registerSuccess = "§aYou are now authenticated.";
|
||||||
public String userdataDeleted = "§aUserdata deleted.";
|
public String userdataDeleted = "§aUserdata deleted.";
|
||||||
|
|
Loading…
Reference in New Issue