Skip to content

Commit ed0db89

Browse files
committed
feat: Implement initial rAuth plugin with core structure, configuration, localization, and database integration.
1 parent c0a8ced commit ed0db89

8 files changed

Lines changed: 74 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* **🎨 Modern Aesthetics**: Built with `MiniMessage` for clear, beautiful, and gradient-text support.
1212
* **🌍 Localization**: Full multi-language support (English & Turkish included out-of-the-box).
1313
* **⏱️ Login Timeout**: Configurable countdown timer (Title, Subtitle, Sound) to kick idle unauthenticated players.
14+
* **🌐 Proxy Support**: Seamless integration with Velocity and BungeeCord to send players to a lobby after login.
1415
* **💾 Database Support**: Flexible storage options (SQLite for simple setups, MySQL for networks).
1516
* **🔄 Session Management**: Remembers players for a configurable time, preventing repetitive logins.
1617
* **🛡️ Security**: IP limit checks, secure password hashing, and input validation.
@@ -45,6 +46,10 @@ security:
4546
min-password-length: 6
4647
login-timeout: 60 # Seconds before kick
4748
session-timeout: 30 # Minutes to remember login
49+
50+
bungeecord:
51+
enabled: false
52+
server: "lobby"
4853
```
4954
5055
---

src/main/java/com/raikou/rauth/RAuth.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void onEnable() {
5555
// Register Listeners
5656
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
5757

58+
// Register BungeeCord Channel
59+
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
60+
5861
getLogger().info("rAuth has been enabled!");
5962
}
6063

src/main/java/com/raikou/rauth/config/ConfigManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ public int getMaxPasswordLength() {
3232
public int getLoginTimeout() {
3333
return plugin.getConfig().getInt("security.login-timeout", 60);
3434
}
35+
36+
public boolean isBungeeEnabled() {
37+
return plugin.getConfig().getBoolean("bungeecord.enabled", false);
38+
}
39+
40+
public String getBungeeServer() {
41+
return plugin.getConfig().getString("bungeecord.server", "lobby");
42+
}
3543
}

src/main/java/com/raikou/rauth/database/DatabaseManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,18 @@ public int getRegistrationCount(String ip) {
143143
}
144144
return 0;
145145
}
146+
147+
public String getLastIp(UUID uuid) {
148+
try (Connection conn = dataSource.getConnection();
149+
PreparedStatement ps = conn.prepareStatement("SELECT last_ip FROM rauth_users WHERE uuid = ?")) {
150+
ps.setString(1, uuid.toString());
151+
ResultSet rs = ps.executeQuery();
152+
if (rs.next()) {
153+
return rs.getString("last_ip");
154+
}
155+
} catch (SQLException e) {
156+
e.printStackTrace();
157+
}
158+
return null;
159+
}
146160
}

src/main/java/com/raikou/rauth/manager/AuthManager.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ public void handleJoin(Player player) {
3131
// Check session
3232
if (sessionManager.hasSession(player.getUniqueId())) {
3333
String lastIp = player.getAddress().getAddress().getHostAddress();
34-
// We should verification against DB last IP if we want strict IP sessions,
35-
// but for now simple time-based session + re-login logic.
36-
// NOTE: Real implementation might verify IP from DB.
37-
38-
loggedInPlayers.add(player.getUniqueId());
39-
plugin.getTimeoutManager().stopTimer(player);
40-
player.sendMessage(plugin.getLanguageManager().getMessage("login-success"));
34+
String dbLastIp = plugin.getDatabaseManager().getLastIp(player.getUniqueId());
35+
36+
if (dbLastIp != null && dbLastIp.equals(lastIp)) {
37+
loggedInPlayers.add(player.getUniqueId());
38+
plugin.getTimeoutManager().stopTimer(player);
39+
player.sendMessage(plugin.getLanguageManager().getMessage("login-success"));
40+
41+
sendToBungeeServer(player);
42+
} else {
43+
// Session invalid due to IP change
44+
sessionManager.endSession(player.getUniqueId());
45+
player.sendMessage(plugin.getLanguageManager().getMessage("join-login"));
46+
}
4147
} else {
4248
player.sendMessage(plugin.getLanguageManager().getMessage("join-login"));
4349
}
@@ -79,6 +85,7 @@ public void register(Player player, String password) {
7985
plugin.getTimeoutManager().stopTimer(player);
8086

8187
player.sendMessage(plugin.getLanguageManager().getMessage("register-success"));
88+
sendToBungeeServer(player);
8289
}
8390

8491
public void login(Player player, String password) {
@@ -104,6 +111,7 @@ public void login(Player player, String password) {
104111
player.getAddress().getAddress().getHostAddress());
105112

106113
player.sendMessage(plugin.getLanguageManager().getMessage("login-success"));
114+
sendToBungeeServer(player);
107115
} else {
108116
player.sendMessage(plugin.getLanguageManager().getMessage("login-failed"));
109117
}
@@ -135,4 +143,24 @@ public void changePassword(Player player, String oldPassword, String newPassword
135143
player.sendMessage(plugin.getLanguageManager().getMessage("password-mismatch"));
136144
}
137145
}
146+
147+
private void sendToBungeeServer(Player player) {
148+
if (!plugin.getConfigManager().isBungeeEnabled())
149+
return;
150+
151+
String server = plugin.getConfigManager().getBungeeServer();
152+
player.sendMessage(plugin.getLanguageManager().getMessage("sending-to-server"));
153+
154+
// Wait a bit to ensure messages are sent
155+
Bukkit.getScheduler().runTaskLater(plugin, () -> {
156+
try {
157+
com.google.common.io.ByteArrayDataOutput out = com.google.common.io.ByteStreams.newDataOutput();
158+
out.writeUTF("Connect");
159+
out.writeUTF(server);
160+
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
161+
} catch (Exception e) {
162+
e.printStackTrace();
163+
}
164+
}, 10L);
165+
}
138166
}

src/main/resources/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ security:
2727
# Login timeout in seconds (0 to disable)
2828
login-timeout: 60
2929

30+
# BungeeCord / Velocity Support
31+
bungeecord:
32+
# Enable to send player to another server after login
33+
enabled: false
34+
# Target server name (must match proxy config)
35+
server: "lobby"
36+
3037
# Teleportation
3138
teleport:
3239
spawn-on-join: true

src/main/resources/messages_en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ messages:
2222
timeout-subtitle: "<gray>You will be kicked in <#FF5555><time> <gray>seconds!"
2323
timeout-chat: "<#FF5555>You will be kicked in <#FFFF55><time> <#FF5555>seconds!"
2424
logged-out: "<#55FF55>Logged out successfully. See you soon!"
25+
sending-to-server: "<#55FF55>Connecting to server..."
2526

2627
# Validation
2728
password-too-short: "<#FF5555>Password is too short. Minimum length is <#FFFF55><min><#FF5555>."

src/main/resources/messages_tr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ messages:
2222
timeout-subtitle: "<#FF5555><time> <gray>saniye içinde atılacaksınız!"
2323
timeout-chat: "<#FFFF55><time> <#FF5555>saniye içinde sunucudan atılacaksınız!"
2424
logged-out: "<#55FF55>Başarıyla çıkış yapıldı. Görüşmek üzere!"
25+
sending-to-server: "<#55FF55>Sunucuya bağlanılıyor..."
2526

2627
# Validation
2728
password-too-short: "<#FF5555>Şifre çok kısa. Minimum uzunluk: <#FFFF55><min><#FF5555>."

0 commit comments

Comments
 (0)