Commit b8f52999 authored by 方块君's avatar 方块君 Committed by Melledy
Browse files

Optimize multilingualism (using variables)

Optimize multilingualism (using variables)
parent 8733812e
...@@ -66,7 +66,7 @@ public final class TalentCommand implements CommandHandler { ...@@ -66,7 +66,7 @@ public final class TalentCommand implements CommandHandler {
// Packet // Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel)); sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel)); sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_atk, nextLevel)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_atk.replace("{level}", Integer.toString(nextLevel)));
} }
if (skillId == skillIdE){ if (skillId == skillIdE){
// Upgrade skill // Upgrade skill
...@@ -76,7 +76,7 @@ public final class TalentCommand implements CommandHandler { ...@@ -76,7 +76,7 @@ public final class TalentCommand implements CommandHandler {
// Packet // Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel)); sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel)); sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_e, nextLevel)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_e.replace("{level}", Integer.toString(nextLevel)));
} }
if (skillId == skillIdQ){ if (skillId == skillIdQ){
// Upgrade skill // Upgrade skill
...@@ -86,7 +86,7 @@ public final class TalentCommand implements CommandHandler { ...@@ -86,7 +86,7 @@ public final class TalentCommand implements CommandHandler {
// Packet // Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel)); sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel)); sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_q, nextLevel)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_q.replace("{level}", Integer.toString(nextLevel)));
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
...@@ -128,7 +128,7 @@ public final class TalentCommand implements CommandHandler { ...@@ -128,7 +128,7 @@ public final class TalentCommand implements CommandHandler {
// Packet // Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel)); sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel)); sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_this, nextLevel)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_this.replace("{level}", Integer.toString(nextLevel)));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level);
return; return;
...@@ -140,10 +140,10 @@ public final class TalentCommand implements CommandHandler { ...@@ -140,10 +140,10 @@ public final class TalentCommand implements CommandHandler {
int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_normal_attack_id, skillIdNorAtk)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_normal_attack_id.replace("{id}", Integer.toString(skillIdNorAtk)));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_e_skill_id, skillIdE)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_e_skill_id.replace("{id}", Integer.toString(skillIdE)));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_q_skill_id, skillIdQ)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_q_skill_id.replace("{id}", Integer.toString(skillIdQ)));
break; break;
} }
} }
......
...@@ -82,7 +82,7 @@ public final class TeleportCommand implements CommandHandler { ...@@ -82,7 +82,7 @@ public final class TeleportCommand implements CommandHandler {
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
} else { } else {
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Teleport_message, targetPlayer.getNickname(), x, y, z, sceneId)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_message.replace("{name}", targetPlayer.getNickname()).replace("{x}", Float.toString(x)).replace("{y}", Float.toString(y)).replace("{z}", Float.toString(z)).replace("{id}", Integer.toString(sceneId)));
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
......
...@@ -34,7 +34,7 @@ public final class WeatherCommand implements CommandHandler { ...@@ -34,7 +34,7 @@ public final class WeatherCommand implements CommandHandler {
sender.getScene().setWeather(weatherId); sender.getScene().setWeather(weatherId);
sender.getScene().setClimate(climate); sender.getScene().setClimate(climate);
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender)); sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Weather_message, weatherId, climateId)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_message.replace("{weatherId}", Integer.toString(weatherId)).replace("{climateId}", Integer.toString(climateId)));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
} }
......
...@@ -32,7 +32,7 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler { ...@@ -32,7 +32,7 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler {
public void handle(Request req, Response res) throws IOException { public void handle(Request req, Response res) throws IOException {
// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled // Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) { if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) {
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_request, req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : "")); Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_request.replace("{ip}", req.ip()).replace("{method}", req.method()).replace("{url}", req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : ""));
} }
res.send(response); res.send(response);
} }
......
...@@ -249,7 +249,7 @@ public final class DispatchServer { ...@@ -249,7 +249,7 @@ public final class DispatchServer {
httpServer.raw().error(404, ctx -> { httpServer.raw().error(404, ctx -> {
if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING) { if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING) {
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Potential_unhandled_request, ctx.method(), ctx.url())); Grasscutter.getLogger().info(Grasscutter.getLanguage().Potential_unhandled_request.replace("{method}", ctx.method()).replace("{url}", ctx.url()));
} }
ctx.contentType("text/html"); ctx.contentType("text/html");
ctx.result("<!doctype html><html lang=\"en\"><body><img src=\"https://http.cat/404\" /></body></html>"); // I'm like 70% sure this won't break anything. ctx.result("<!doctype html><html lang=\"en\"><body><img src=\"https://http.cat/404\" /></body></html>"); // I'm like 70% sure this won't break anything.
...@@ -307,7 +307,7 @@ public final class DispatchServer { ...@@ -307,7 +307,7 @@ public final class DispatchServer {
if (requestData == null) { if (requestData == null) {
return; return;
} }
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s is trying to log in", req.ip())); Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_try_login.replace("{ip}", req.ip()));
res.send(this.getAuthHandler().handleGameLogin(req, requestData)); res.send(this.getAuthHandler().handleGameLogin(req, requestData));
}); });
...@@ -327,7 +327,7 @@ public final class DispatchServer { ...@@ -327,7 +327,7 @@ public final class DispatchServer {
return; return;
} }
LoginResultJson responseData = new LoginResultJson(); LoginResultJson responseData = new LoginResultJson();
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login_token, req.ip())); Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_login_token.replace("{ip}", req.ip()));
// Login // Login
Account account = DatabaseHelper.getAccountById(requestData.uid); Account account = DatabaseHelper.getAccountById(requestData.uid);
...@@ -337,16 +337,14 @@ public final class DispatchServer { ...@@ -337,16 +337,14 @@ public final class DispatchServer {
responseData.retcode = -111; responseData.retcode = -111;
responseData.message = Grasscutter.getLanguage().Game_account_cache_error; responseData.message = Grasscutter.getLanguage().Game_account_cache_error;
Grasscutter.getLogger() Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_token_login_failed.replace("{ip}", req.ip()));
.info(String.format(Grasscutter.getLanguage().Client_token_login_failed, req.ip()));
} else { } else {
responseData.message = "OK"; responseData.message = "OK";
responseData.data.account.uid = requestData.uid; responseData.data.account.uid = requestData.uid;
responseData.data.account.token = requestData.token; responseData.data.account.token = requestData.token;
responseData.data.account.email = account.getEmail(); responseData.data.account.email = account.getEmail();
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login_in_token, Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_login_in_token.replace("{ip}", req.ip()).replace("{uid}", responseData.data.account.uid));
req.ip(), responseData.data.account.uid));
} }
res.send(responseData); res.send(responseData);
...@@ -378,16 +376,14 @@ public final class DispatchServer { ...@@ -378,16 +376,14 @@ public final class DispatchServer {
responseData.retcode = -201; responseData.retcode = -201;
responseData.message = Grasscutter.getLanguage().Wrong_session_key; responseData.message = Grasscutter.getLanguage().Wrong_session_key;
Grasscutter.getLogger().info( Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_failed_exchange_combo_token.replace("{ip}", req.ip()));
String.format(Grasscutter.getLanguage().Client_failed_exchange_combo_token, req.ip()));
} else { } else {
responseData.message = "OK"; responseData.message = "OK";
responseData.data.open_id = loginData.uid; responseData.data.open_id = loginData.uid;
responseData.data.combo_id = "157795300"; responseData.data.combo_id = "157795300";
responseData.data.combo_token = account.generateLoginToken(); responseData.data.combo_token = account.generateLoginToken();
Grasscutter.getLogger().info( Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_exchange_combo_token.replace("{ip}", req.ip()));
String.format(Grasscutter.getLanguage().Client_exchange_combo_token, req.ip()));
} }
res.send(responseData); res.send(responseData);
...@@ -453,7 +449,7 @@ public final class DispatchServer { ...@@ -453,7 +449,7 @@ public final class DispatchServer {
httpServer.get("/gcstatic/*", new StaticFileHandler()); httpServer.get("/gcstatic/*", new StaticFileHandler());
httpServer.listen(Grasscutter.getConfig().getDispatchOptions().Port); httpServer.listen(Grasscutter.getConfig().getDispatchOptions().Port);
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Dispatch_start_server_port, httpServer.raw().port())); Grasscutter.getLogger().info(Grasscutter.getLanguage().Dispatch_start_server_port.replace("{port}", Integer.toString(httpServer.raw().port())));
} }
private Map<String, String> parseQueryString(String qs) { private Map<String, String> parseQueryString(String qs) {
......
...@@ -51,15 +51,12 @@ public class DefaultAuthenticationHandler implements AuthenticationHandler { ...@@ -51,15 +51,12 @@ public class DefaultAuthenticationHandler implements AuthenticationHandler {
responseData.data.account.token = account.generateSessionKey(); responseData.data.account.token = account.generateSessionKey();
responseData.data.account.email = account.getEmail(); responseData.data.account.email = account.getEmail();
Grasscutter.getLogger() Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_failed_login_account_create.replace("{ip}", req.ip()).replace("{uid}", responseData.data.account.uid));
.info(String.format(Grasscutter.getLanguage().Client_failed_login_account_create,
req.ip(), responseData.data.account.uid));
} else { } else {
responseData.retcode = -201; responseData.retcode = -201;
responseData.message = Grasscutter.getLanguage().Username_not_found_create_failed; responseData.message = Grasscutter.getLanguage().Username_not_found_create_failed;
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_failed_login_account_create_failed Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_failed_login_account_no_found.replace("{ip}", req.ip()));
, req.ip()));
} }
} else { } else {
responseData.retcode = -201; responseData.retcode = -201;
...@@ -75,8 +72,7 @@ public class DefaultAuthenticationHandler implements AuthenticationHandler { ...@@ -75,8 +72,7 @@ public class DefaultAuthenticationHandler implements AuthenticationHandler {
responseData.data.account.token = account.generateSessionKey(); responseData.data.account.token = account.generateSessionKey();
responseData.data.account.email = account.getEmail(); responseData.data.account.email = account.getEmail();
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login, req.ip(), Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_login.replace("{ip}", req.ip()).replace("{uid}", responseData.data.account.uid));
responseData.data.account.uid));
} }
return responseData; return responseData;
......
...@@ -208,7 +208,7 @@ public final class GameServer extends KcpServer { ...@@ -208,7 +208,7 @@ public final class GameServer extends KcpServer {
@Override @Override
public void onStartFinish() { public void onStartFinish() {
Grasscutter.getLogger().info(Grasscutter.getLanguage().Grasscutter_is_free); Grasscutter.getLogger().info(Grasscutter.getLanguage().Grasscutter_is_free);
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Game_start_port, address.getPort())); Grasscutter.getLogger().info(Grasscutter.getLanguage().Game_start_port.replace("{port}", Integer.toString(address.getPort())));
ServerStartEvent event = new ServerStartEvent(ServerEvent.Type.GAME, OffsetDateTime.now()); event.call(); ServerStartEvent event = new ServerStartEvent(ServerEvent.Type.GAME, OffsetDateTime.now()); event.call();
} }
......
...@@ -113,12 +113,12 @@ public class GameSession extends KcpChannel { ...@@ -113,12 +113,12 @@ public class GameSession extends KcpChannel {
@Override @Override
protected void onConnect() { protected void onConnect() {
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_connect, getAddress().getHostString().toLowerCase())); Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_connect.replace("{address}", getAddress().getHostString().toLowerCase()));
} }
@Override @Override
protected synchronized void onDisconnect() { // Synchronize so we dont add character at the same time protected synchronized void onDisconnect() { // Synchronize so we dont add character at the same time
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_disconnect, getAddress().getHostString().toLowerCase())); Grasscutter.getLogger().info(Grasscutter.getLanguage().Client_disconnect.replace("{address}", getAddress().getHostString().toLowerCase()));
// Set state so no more packets can be handled // Set state so no more packets can be handled
this.setState(SessionState.INACTIVE); this.setState(SessionState.INACTIVE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment