Skip to content

Commit 73bf798

Browse files
committed
🐛 fix: v1.2.4 - Fix whitelist and encoding issues, improve email config
1 parent d6ca4ae commit 73bf798

14 files changed

Lines changed: 92 additions & 39 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ smtp:
134134
password: your_email_password
135135
from: your_email@qq.com
136136
enable_ssl: true
137+
# Subject (title) of the verification code email
138+
email.subject: VerifyMC Verification Code
137139

138140
# ----------------------------------------
139141
# Sync Settings (for bukkit mode)

README_zh.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ smtp:
140140
password: your_email_password
141141
from: your_email@qq.com
142142
enable_ssl: true
143+
# 验证码邮件的主题(标题)
144+
email.subject: VerifyMC Verification Code
143145

144146
# ----------------------------------------
145147
# 同步设置 (用于 bukkit 模式)

plugin/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>team.kitemc</groupId>
55
<artifactId>verifymc</artifactId>
66
<name>VerifyMC</name>
7-
<version>1.2.3</version>
7+
<version>1.2.4</version>
88
<description>Web-based MC whitelist authentication plugin</description>
99
<build>
1010
<resources>

plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>team.kitemc</groupId>
55
<artifactId>verifymc</artifactId>
6-
<version>1.2.3</version>
6+
<version>1.2.4</version>
77
<packaging>jar</packaging>
88
<name>VerifyMC</name>
99
<description>Web-based MC whitelist authentication plugin</description>

plugin/src/main/java/team/kitemc/verifymc/VerifyMC.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,12 @@ public void onEnable() {
178178
}
179179
boolean autoSync = getConfig().getBoolean("auto_sync_whitelist", true);
180180
boolean autoCleanup = getConfig().getBoolean("auto_cleanup_whitelist", true);
181-
if ("bukkit".equalsIgnoreCase(whitelistMode) && autoSync) {
181+
// Keep Bukkit whitelist in sync no matter which whitelist mode is chosen
182+
if (autoSync) {
182183
syncWhitelistToServer();
183-
} else if (!"bukkit".equalsIgnoreCase(whitelistMode) && autoCleanup) {
184+
}
185+
// Clean up unexpected whitelist entries (without removing approved users)
186+
if (autoCleanup) {
184187
cleanupServerWhitelist();
185188
}
186189
// Always register event listener for player login interception
@@ -550,6 +553,8 @@ public void onPlayerLogin(PlayerLoginEvent event) {
550553
event.disallow(Result.KICK_WHITELIST, msg);
551554
debugLog("Blocked unregistered player: " + player.getName() + " from IP: " + ip);
552555
} else {
556+
// Ensure approved users are explicitly allowed even if vanilla whitelist rejected them earlier
557+
event.setResult(Result.ALLOWED);
553558
debugLog("Allowed registered player: " + player.getName() + " (Status: approved)");
554559
}
555560
}
@@ -678,8 +683,11 @@ private void syncWhitelistToServer() {
678683
private void cleanupServerWhitelist() {
679684
for (org.bukkit.OfflinePlayer p : Bukkit.getWhitelistedPlayers()) {
680685
Map<String, Object> user = userDao.getUserByUsername(p.getName());
681-
if (user != null && "approved".equals(user.get("status"))) {
686+
if (user == null || !"approved".equals(user.get("status"))) {
682687
p.setWhitelisted(false);
688+
} else {
689+
// Ensure approved users stay whitelisted
690+
p.setWhitelisted(true);
683691
}
684692
}
685693
}

plugin/src/main/java/team/kitemc/verifymc/web/WebServer.java

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Base64;
2727
import java.util.Arrays;
2828
import java.util.HashMap;
29+
import java.nio.charset.StandardCharsets;
2930

3031
public class WebServer {
3132
private HttpServer server;
@@ -229,9 +230,10 @@ public void start() throws IOException {
229230
server.createContext("/api/ping", exchange -> {
230231
String resp = "{\"msg\":\"pong\"}";
231232
exchange.getResponseHeaders().add("Content-Type", "application/json; charset=utf-8");
232-
exchange.sendResponseHeaders(200, resp.getBytes().length);
233+
byte[] data = resp.getBytes(StandardCharsets.UTF_8);
234+
exchange.sendResponseHeaders(200, data.length);
233235
OutputStream os = exchange.getResponseBody();
234-
os.write(resp.getBytes());
236+
os.write(data);
235237
os.close();
236238
});
237239

@@ -330,7 +332,7 @@ public void start() throws IOException {
330332
return;
331333
}
332334

333-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
335+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
334336
String email = req.optString("email", "").trim().toLowerCase();
335337
String language = req.optString("language", "en");
336338

@@ -381,7 +383,9 @@ public void start() throws IOException {
381383
String code = codeService.generateCode(email);
382384
debugLog("Generated verification code for email: " + email + ", code: " + code);
383385

384-
boolean sent = mailService.sendCode(email, getMsg("email.subject", language), code);
386+
// Get email subject from config.yml, fallback to default if not set
387+
String emailSubject = plugin.getConfig().getString("email_subject", "VerifyMC Verification Code");
388+
boolean sent = mailService.sendCode(email, emailSubject, code);
385389
JSONObject resp = new JSONObject();
386390
resp.put("success", sent);
387391
resp.put("msg", sent ? getMsg("email.sent", language) : getMsg("email.failed", language));
@@ -399,7 +403,7 @@ public void start() throws IOException {
399403
server.createContext("/api/register", exchange -> {
400404
debugLog("/api/register called");
401405
if (!"POST".equals(exchange.getRequestMethod())) { exchange.sendResponseHeaders(405, 0); exchange.close(); return; }
402-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
406+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
403407
String email = req.optString("email", "").trim().toLowerCase();
404408
String code = req.optString("code");
405409
String uuid = req.optString("uuid");
@@ -557,7 +561,7 @@ public void start() throws IOException {
557561
exchange.close();
558562
return;
559563
}
560-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
564+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
561565
String password = req.optString("password");
562566
String language = req.optString("language", "en");
563567

@@ -649,7 +653,7 @@ public void start() throws IOException {
649653
return;
650654
}
651655

652-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
656+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
653657
String uuid = req.optString("uuid");
654658
String action = req.optString("action");
655659
String language = req.optString("language", "en");
@@ -868,7 +872,7 @@ public void start() throws IOException {
868872
return;
869873
}
870874

871-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
875+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
872876
String uuid = req.optString("uuid");
873877
String language = req.optString("language", "en");
874878

@@ -936,7 +940,7 @@ public void start() throws IOException {
936940
return;
937941
}
938942

939-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
943+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
940944
String uuid = req.optString("uuid");
941945
String language = req.optString("language", "en");
942946

@@ -999,7 +1003,7 @@ public void start() throws IOException {
9991003
return;
10001004
}
10011005

1002-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
1006+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
10031007
String uuid = req.optString("uuid");
10041008
String language = req.optString("language", "en");
10051009

@@ -1062,7 +1066,7 @@ public void start() throws IOException {
10621066
return;
10631067
}
10641068

1065-
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes()));
1069+
JSONObject req = new JSONObject(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
10661070
String uuid = req.optString("uuid");
10671071
String username = req.optString("username");
10681072
String newPassword = req.optString("newPassword");
@@ -1287,8 +1291,38 @@ public void handle(HttpExchange exchange) throws IOException {
12871291
return;
12881292
}
12891293
String mime = Files.probeContentType(file);
1290-
if (mime == null) mime = "application/octet-stream";
1291-
exchange.getResponseHeaders().add("Content-Type", mime);
1294+
if (mime == null) {
1295+
// Try to determine MIME type from file extension
1296+
String fileName = file.getFileName().toString().toLowerCase();
1297+
if (fileName.endsWith(".html") || fileName.endsWith(".htm")) {
1298+
mime = "text/html";
1299+
} else if (fileName.endsWith(".css")) {
1300+
mime = "text/css";
1301+
} else if (fileName.endsWith(".js")) {
1302+
mime = "application/javascript";
1303+
} else if (fileName.endsWith(".json")) {
1304+
mime = "application/json";
1305+
} else if (fileName.endsWith(".svg")) {
1306+
mime = "image/svg+xml";
1307+
} else if (fileName.endsWith(".xml")) {
1308+
mime = "text/xml";
1309+
} else {
1310+
mime = "application/octet-stream";
1311+
}
1312+
}
1313+
1314+
// Add charset=utf-8 for text-based content types
1315+
String contentType = mime;
1316+
if (mime.startsWith("text/") ||
1317+
mime.equals("application/javascript") ||
1318+
mime.equals("application/json") ||
1319+
mime.equals("application/xml") ||
1320+
mime.equals("text/xml") ||
1321+
mime.equals("image/svg+xml")) {
1322+
contentType = mime + "; charset=utf-8";
1323+
}
1324+
1325+
exchange.getResponseHeaders().add("Content-Type", contentType);
12921326
byte[] data = Files.readAllBytes(file);
12931327
exchange.sendResponseHeaders(200, data.length);
12941328
OutputStream os = exchange.getResponseBody();
@@ -1312,7 +1346,7 @@ public void handle(HttpExchange exchange) throws IOException {
13121346

13131347
private void sendJson(HttpExchange exchange, JSONObject resp) throws IOException {
13141348
JSONObject withCopy = withCopyright(resp);
1315-
byte[] data = withCopy.toString().getBytes();
1349+
byte[] data = withCopy.toString().getBytes(StandardCharsets.UTF_8);
13161350
exchange.getResponseHeaders().add("Content-Type", "application/json; charset=utf-8");
13171351
exchange.sendResponseHeaders(200, data.length);
13181352
exchange.getResponseBody().write(data);

plugin/src/main/resources/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ smtp:
2626
password: your_email_password
2727
from: your_email@qq.com
2828
enable_ssl: true
29+
email.subject: VerifyMC Verification Code
2930
whitelist_json_sync: true
3031
auto_sync_whitelist: true
3132
auto_cleanup_whitelist: true

plugin/src/main/resources/config_help_en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ smtp:
6969
password: your_email_password
7070
from: your_email@qq.com
7171
enable_ssl: true
72+
# Subject (title) of the verification code email
73+
email_subject: VerifyMC Verification Code
7274

7375
# ----------------------------------------
7476
# Sync Settings (for bukkit mode)

plugin/src/main/resources/config_help_zh.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ smtp:
6969
password: your_email_password
7070
from: your_email@qq.com
7171
enable_ssl: true
72+
# 验证码邮件的主题(标题)
73+
email_subject: VerifyMC Verification Code
7274

7375
# ----------------------------------------
7476
# 同步设置 (用于 bukkit 模式)

plugin/src/main/resources/i18n/messages_en.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ admin.login_success=Admin login successful, redirecting...
3232
admin.load_failed=Load failed, please try again
3333

3434
# Email related
35-
email.subject=VerifyMC Verification Code
3635
email.sent=Verification code sent, please check your inbox
3736
email.failed=Failed to send verification code, please try again
3837
email.invalid_format=Invalid email format

0 commit comments

Comments
 (0)