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

Add multilingual support

Add multilingual support
parent 86e6eef4
......@@ -25,11 +25,11 @@ public final class KillCharacterCommand implements CommandHandler {
try {
target = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
CommandHandler.sendMessage(null, "Invalid player id.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
CommandHandler.sendMessage(null, "Usage: /killcharacter [playerId]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().KillCharacter_usage);
return;
}
} else {
......@@ -40,7 +40,7 @@ public final class KillCharacterCommand implements CommandHandler {
target = sender.getUid();
}
} catch (NumberFormatException e) {
CommandHandler.sendMessage(sender, "Invalid player id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
......@@ -50,7 +50,7 @@ public final class KillCharacterCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return;
}
......@@ -63,6 +63,6 @@ public final class KillCharacterCommand implements CommandHandler {
targetPlayer.getScene().removeEntity(entity);
entity.onDeath(0);
CommandHandler.sendMessage(sender, "Killed " + targetPlayer.getNickname() + " current character.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().KillCharacter_kill_current_character, targetPlayer.getNickname()));
}
}
......@@ -21,7 +21,7 @@ public final class ListCommand implements CommandHandler {
needUID = args.get(0).equals("uid");
}
CommandHandler.sendMessage(sender, String.format("There are %s player(s) online:", playersMap.size()));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().List_message, playersMap.size()));
if (playersMap.size() != 0) {
StringBuilder playerSet = new StringBuilder();
......
......@@ -15,7 +15,7 @@ public final class PermissionCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 3) {
CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
return;
}
......@@ -25,23 +25,23 @@ public final class PermissionCommand implements CommandHandler {
Account account = Grasscutter.getGameServer().getAccountByName(username);
if (account == null) {
CommandHandler.sendMessage(sender, "Account not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Account_not_find);
return;
}
switch (action) {
default:
CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
break;
case "add":
if (account.addPermission(permission)) {
CommandHandler.sendMessage(sender, "Permission added.");
} else CommandHandler.sendMessage(sender, "They already have this permission!");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_add);
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_have_permission);
break;
case "remove":
if (account.removePermission(permission)) {
CommandHandler.sendMessage(sender, "Permission removed.");
} else CommandHandler.sendMessage(sender, "They don't have this permission!");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_remove);
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_not_have_permission);
break;
}
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
......@@ -13,11 +14,11 @@ public final class PositionCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f\nScene id: %d",
sender.dropMessage(String.format(Grasscutter.getLanguage().Position_message,
sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ(), sender.getSceneId()));
}
}
......@@ -13,12 +13,13 @@ public final class ReloadCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
CommandHandler.sendMessage(sender, "Reloading config.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_start);
Grasscutter.loadConfig();
Grasscutter.loadLanguage();
Grasscutter.getGameServer().getGachaManager().load();
Grasscutter.getGameServer().getDropManager().load();
Grasscutter.getGameServer().getShopManager().load();
Grasscutter.getDispatchServer().loadQueries();
CommandHandler.sendMessage(sender, "Reload complete.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_done);
}
}
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.avatar.Avatar;
......@@ -16,13 +17,13 @@ public final class ResetConstCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
sender.getAvatars().forEach(this::resetConstellation);
sender.dropMessage("Reset all avatars' constellations.");
sender.dropMessage(Grasscutter.getLanguage().ResetConst_reset_all);
} else {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
if (entity == null) {
......@@ -32,7 +33,7 @@ public final class ResetConstCommand implements CommandHandler {
Avatar avatar = entity.getAvatar();
this.resetConstellation(avatar);
sender.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes.");
sender.dropMessage(String.format(Grasscutter.getLanguage().ResetConst_reset_all_done, avatar.getAvatarData().getName()));
}
}
......
......@@ -13,19 +13,19 @@ public final class ResetShopLimitCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 1) {
CommandHandler.sendMessage(sender,"Usage: /resetshop <player id>");
CommandHandler.sendMessage(sender,Grasscutter.getLanguage().ResetShopLimit_usage);
return;
}
int target = Integer.parseInt(args.get(0));
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
targetPlayer.getShopLimit().forEach(x -> x.setNextRefreshTime(0));
targetPlayer.save();
CommandHandler.sendMessage(sender, "Success");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Success);
}
}
......@@ -45,16 +45,16 @@ public final class SendMailCommand implements CommandHandler {
if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) {
mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail());
} else {
CommandHandler.sendMessage(sender, "The user with an id of '" + args.get(0) + "' does not exist");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_user_not_exist, args.get(0)));
return;
}
}
}
mailBeingConstructed.put(senderId, mailBuilder);
CommandHandler.sendMessage(sender, "Starting composition of message.\nPlease use `/sendmail <title>` to continue.\nYou can use `/sendmail stop` at any time");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_start_composition);
}
case 2 -> CommandHandler.sendMessage(sender, "Mail templates coming soon implemented...");
default -> CommandHandler.sendMessage(sender, "Invalid arguments.\nUsage `/sendmail <userId|all|help> [templateId]`");
case 2 -> CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_templates);
default -> CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_invalid_arguments);
}
} else {
MailBuilder mailBuilder = mailBeingConstructed.get(senderId);
......@@ -63,28 +63,28 @@ public final class SendMailCommand implements CommandHandler {
switch (args.get(0).toLowerCase()) {
case "stop" -> {
mailBeingConstructed.remove(senderId);
CommandHandler.sendMessage(sender, "Message sending cancelled");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_cancel);
return;
}
case "finish" -> {
if (mailBuilder.constructionStage == 3) {
if (!mailBuilder.sendToAll) {
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_send_done, mailBuilder.recipient));
} else {
for (Player player : DatabaseHelper.getAllPlayers()) {
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail);
}
CommandHandler.sendMessage(sender, "Message sent to all users!");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_all_done);
}
mailBeingConstructed.remove(senderId);
} else {
CommandHandler.sendMessage(sender, "Message composition not at final stage.\nPlease use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage) + "` or `/sendmail stop` to cancel");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_not_composition_end, getConstructionArgs(mailBuilder.constructionStage)));
}
return;
}
case "help" -> {
CommandHandler.sendMessage(sender, "Please use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage) + "`");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_Please_use, getConstructionArgs(mailBuilder.constructionStage)));
return;
}
default -> {
......@@ -92,19 +92,19 @@ public final class SendMailCommand implements CommandHandler {
case 0 -> {
String title = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.title = title;
CommandHandler.sendMessage(sender, "Message title set as '" + title + "'.\nUse '/sendmail <content>' to continue.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_set_title, title));
mailBuilder.constructionStage++;
}
case 1 -> {
String contents = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.content = contents;
CommandHandler.sendMessage(sender, "Message contents set as '" + contents + "'.\nUse '/sendmail <sender>' to continue.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_set_contents, contents));
mailBuilder.constructionStage++;
}
case 2 -> {
String msgSender = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.sender = msgSender;
CommandHandler.sendMessage(sender, "Message sender set as '" + msgSender + "'.\nUse '/sendmail <itemId|itemName|finish> [amount] [level]' to continue.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_set_message_sender, msgSender));
mailBuilder.constructionStage++;
}
case 3 -> {
......@@ -112,7 +112,7 @@ public final class SendMailCommand implements CommandHandler {
int item, lvl, amount = 1;
switch (args.size()) {
default -> { // *No args*
CommandHandler.sendMessage(sender, "Usage: give [player] <itemId|itemName> [amount]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_usage);
return;
}
case 1 -> { // <itemId|itemName>
......@@ -121,7 +121,7 @@ public final class SendMailCommand implements CommandHandler {
lvl = 1;
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return;
}
}
......@@ -138,19 +138,19 @@ public final class SendMailCommand implements CommandHandler {
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item or player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_or_player_id);
return;
}
}
}
mailBuilder.mail.itemList.add(new Mail.MailItem(item, amount, lvl));
CommandHandler.sendMessage(sender, String.format("Attached %s of %s (level %s) to the message.\nContinue adding more items or use `/sendmail finish` to send the message.", amount, item, lvl));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_send, amount, item, lvl));
}
}
}
}
} else {
CommandHandler.sendMessage(sender, "Invalid arguments \n Please use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_invalid_arguments_please_use, getConstructionArgs(mailBuilder.constructionStage)));
}
}
}
......@@ -158,21 +158,21 @@ public final class SendMailCommand implements CommandHandler {
private String getConstructionArgs(int stage) {
switch (stage) {
case 0 -> {
return "<title>";
return Grasscutter.getLanguage().SendMail_title;
}
case 1 -> {
return "<message>";
return Grasscutter.getLanguage().SendMail_message;
}
case 2 -> {
return "<sender>";
return Grasscutter.getLanguage().SendMail_sender;
}
case 3 -> {
return "<itemId|itemName|finish> [amount] [level]";
return Grasscutter.getLanguage().SendMail_arguments;
}
default -> {
Thread.dumpStack();
return "ERROR: invalid construction stage " + stage + ". Check console for stacktrace.";
return String.format(Grasscutter.getLanguage().SendMail_error, stage);
}
}
}
......
......@@ -14,7 +14,7 @@ public final class SendMessageCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: sendmessage <player> <message>");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage);
return;
}
......@@ -24,14 +24,14 @@ public final class SendMessageCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
CommandHandler.sendMessage(targetPlayer, message);
CommandHandler.sendMessage(sender, "Message sent.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SenaMessage_message_sent);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package emu.grasscutter.command.commands;
import java.util.List;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
......@@ -17,19 +18,19 @@ public final class SetFetterLevelCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: setfetterlevel <level>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_usage);
return;
}
try {
int fetterLevel = Integer.parseInt(args.get(0));
if (fetterLevel < 0 || fetterLevel > 10) {
CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_level_must_between_0_and_10);
return;
}
Avatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar();
......@@ -41,9 +42,9 @@ public final class SetFetterLevelCommand implements CommandHandler {
avatar.save();
sender.sendPacket(new PacketAvatarFetterDataNotify(avatar));
CommandHandler.sendMessage(sender, "Fetter level set to " + fetterLevel);
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetFetterLevel_fetter_set_level, fetterLevel));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid fetter level.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_invalid_fetter_level);
}
}
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.entity.EntityAvatar;
......@@ -16,20 +17,20 @@ public final class SetStatsCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 2){
CommandHandler.sendMessage(sender, "Usage: setstats|stats <stat> <value>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_usage);
return;
}
String stat = args.get(0);
switch (stat) {
default:
CommandHandler.sendMessage(sender, "Usage: /setstats|stats <hp | mhp | def | atk | em | er | crate | cdmg> <value> for basic stats");
CommandHandler.sendMessage(sender, "Usage: /stats <epyro | ecryo | ehydro | egeo | edend | eelec | ephys> <amount> for elemental bonus");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_setstats_help_message);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_stats_help_message);
return;
case "mhp":
try {
......@@ -37,9 +38,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_MAX_HP, health);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_MAX_HP));
CommandHandler.sendMessage(sender, "MAX HP set to " + health + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_max_hp, health));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Max HP value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_max_hp_error);
return;
}
break;
......@@ -49,9 +50,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
CommandHandler.sendMessage(sender, "HP set to " + health + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_hp, health));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid HP value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_hp_error);
return;
}
break;
......@@ -61,9 +62,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, def);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE));
CommandHandler.sendMessage(sender, "DEF set to " + def + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_def, def));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid DEF value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_def_error);
return;
}
break;
......@@ -73,9 +74,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, atk);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_ATTACK));
CommandHandler.sendMessage(sender, "ATK set to " + atk + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_atk, atk));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ATK value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_atk_error);
return;
}
break;
......@@ -85,9 +86,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_ELEMENT_MASTERY, em);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEMENT_MASTERY));
CommandHandler.sendMessage(sender, "Elemental Mastery set to " + em + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_em, em));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid EM value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_em_error);
return;
}
break;
......@@ -99,9 +100,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, erecharge);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY));
float iger = erecharge * 100;
CommandHandler.sendMessage(sender, "Energy recharge set to " + iger + "%.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_er, iger));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ER value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_er_error);
return;
}
break;
......@@ -113,9 +114,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL, crate);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL));
float igcrate = crate * 100;
CommandHandler.sendMessage(sender, "Crit Rate set to " + igcrate + "%.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_cr, igcrate));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Crit Rate value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_cr_error);
return;
}
break;
......@@ -127,9 +128,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL_HURT, cdamage);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL_HURT));
float igcdmg = cdamage * 100;
CommandHandler.sendMessage(sender, "Crit DMG set to " + igcdmg + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_cd, igcdmg));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Crit DMG value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_cd_error);
return;
}
break;
......@@ -141,9 +142,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_FIRE_ADD_HURT, pyro);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_FIRE_ADD_HURT));
float igpyro = pyro * 100;
CommandHandler.sendMessage(sender, "Pyro DMG Bonus set to " + igpyro + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_pdb, igpyro));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Pyro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_pdb_error);
return;
}
break;
......@@ -155,9 +156,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_ICE_ADD_HURT, cryo);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ICE_ADD_HURT));
float igcyro = cryo * 100;
CommandHandler.sendMessage(sender, "Cyro DMG Bonus set to " + igcyro + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_cdb, igcyro));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Cryo DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_cdb_error);
return;
}
break;
......@@ -169,9 +170,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_WATER_ADD_HURT, hydro);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_WATER_ADD_HURT));
float ighydro = hydro * 100;
CommandHandler.sendMessage(sender, "Hydro DMG Bonus set to " + ighydro + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_hdb, ighydro));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Hydro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_hdb_error);
return;
}
break;
......@@ -183,9 +184,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_WIND_ADD_HURT, anemo);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_WIND_ADD_HURT));
float iganemo = anemo * 100;
CommandHandler.sendMessage(sender, "Anemo DMG Bonus set to " + iganemo + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_adb, iganemo));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Anemo DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_adb_error);
return;
}
break;
......@@ -197,9 +198,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_ROCK_ADD_HURT, geo);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ROCK_ADD_HURT));
float iggeo = geo * 100;
CommandHandler.sendMessage(sender, "Geo DMG Bonus set to " + iggeo + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_gdb, iggeo));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Geo DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_gdb_error);
return;
}
break;
......@@ -212,9 +213,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_ELEC_ADD_HURT, elec);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEC_ADD_HURT));
float igelec = elec * 100;
CommandHandler.sendMessage(sender, "Electro DMG Bonus set to " + igelec + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_edb, igelec));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Electro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_edb_error);
return;
}
break;
......@@ -226,9 +227,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT, phys);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT));
float igphys = phys * 100;
CommandHandler.sendMessage(sender, "Physical DMG Bonus set to " + igphys + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_physdb, igphys));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Physical DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_physdb_error);
return;
}
break;
......@@ -240,9 +241,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_GRASS_ADD_HURT, dend);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_GRASS_ADD_HURT));
float igdend = dend * 100;
CommandHandler.sendMessage(sender, "Dendro DMG Bonus set to " + igdend + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_ddb, igdend));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Dendro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_ddb_error);
return;
}
break;
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
......@@ -14,19 +15,19 @@ public final class SetWorldLevelCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; // TODO: set player's world level from console or other players
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: setworldlevel <level>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_usage);
return;
}
try {
int level = Integer.parseInt(args.get(0));
if (level > 8 || level < 0) {
sender.dropMessage("World level must be between 0-8");
sender.dropMessage(Grasscutter.getLanguage().SetWorldLevel_world_level_must_between_0_and_8);
return;
}
......@@ -34,9 +35,9 @@ public final class SetWorldLevelCommand implements CommandHandler {
sender.getWorld().setWorldLevel(level);
sender.setWorldLevel(level);
sender.dropMessage("World level set to " + level + ".");
sender.dropMessage(String.format(Grasscutter.getLanguage().SetWorldLevel_set_world_level, level));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid world level.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SetWorldLevel_invalid_world_level);
}
}
}
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
......@@ -25,12 +26,12 @@ public final class SpawnCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: spawn <entityId> [amount] [level(monster only)]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_usage);
return;
}
......@@ -43,7 +44,7 @@ public final class SpawnCommand implements CommandHandler {
GadgetData gadgetData = GameData.getGadgetDataMap().get(id);
ItemData itemData = GameData.getItemDataMap().get(id);
if (monsterData == null && gadgetData == null && itemData == null) {
CommandHandler.sendMessage(sender, "Invalid entity id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
return;
}
......@@ -78,9 +79,9 @@ public final class SpawnCommand implements CommandHandler {
sender.getScene().addEntity(entity);
}
CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, id));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Spawn_message, amount, id));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid entity ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
}
}
......
......@@ -13,9 +13,9 @@ public final class StopCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
CommandHandler.sendMessage(null, "Server shutting down...");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Stop_message);
for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, "Server shutting down...");
CommandHandler.sendMessage(p, Grasscutter.getLanguage().Stop_message);
}
System.exit(1);
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.def.AvatarSkillDepotData;
......@@ -18,23 +19,23 @@ public final class TalentCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1){
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return;
}
String cmdSwitch = args.get(0);
switch (cmdSwitch) {
default:
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return;
case "set":
try {
......@@ -49,12 +50,12 @@ public final class TalentCommand implements CommandHandler {
int currentLevelE = avatar.getSkillLevelMap().get(skillIdE);
int currentLevelQ = avatar.getSkillLevelMap().get(skillIdQ);
if (args.size() < 2){
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return;
}
if (nextLevel >= 16){
CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
return;
}
if (skillId == skillIdNorAtk){
......@@ -65,7 +66,7 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
CommandHandler.sendMessage(sender, "Set talent Normal ATK to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_atk, nextLevel));
}
if (skillId == skillIdE){
// Upgrade skill
......@@ -75,7 +76,7 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel));
CommandHandler.sendMessage(sender, "Set talent E to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_e, nextLevel));
}
if (skillId == skillIdQ){
// Upgrade skill
......@@ -85,11 +86,11 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel));
CommandHandler.sendMessage(sender, "Set talent Q to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_q, nextLevel));
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid skill ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_skill_id);
return;
}
......@@ -114,11 +115,11 @@ public final class TalentCommand implements CommandHandler {
int nextLevel = Integer.parseInt(args.get(1));
int currentLevel = avatar.getSkillLevelMap().get(skillId);
if (args.size() < 1){
CommandHandler.sendMessage(sender, "To set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
return;
}
if (nextLevel >= 16){
CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
return;
}
// Upgrade skill
......@@ -127,9 +128,9 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel));
CommandHandler.sendMessage(sender, "Set this talent to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_this, nextLevel));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid talent level.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level);
return;
}
break;
......@@ -140,9 +141,9 @@ public final class TalentCommand implements CommandHandler {
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
CommandHandler.sendMessage(sender, "Normal Attack ID " + skillIdNorAtk + ".");
CommandHandler.sendMessage(sender, "E skill ID " + skillIdE + ".");
CommandHandler.sendMessage(sender, "Q skill ID " + skillIdQ + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_normal_attack_id, skillIdNorAtk));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_e_skill_id, skillIdE));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_q_skill_id, skillIdQ));
break;
}
}
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
......@@ -13,12 +14,12 @@ public final class TeleportAllCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (!sender.getWorld().isMultiplayer()) {
CommandHandler.sendMessage(sender, "You only can use this command in MP mode.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().TeleportAll_message);
return;
}
......
......@@ -16,20 +16,20 @@ public final class TeleportCommand implements CommandHandler {
public void execute(Player sender, List<String> args) {
int target;
if (args.size() < (sender == null ? 4 : 3)) {
CommandHandler.sendMessage(sender, sender == null ? "Usage: /tp @<player id> <x> <y> <z> [scene id]" :
"Usage: /tp [@<player id>] <x> <y> <z> [scene id]");
CommandHandler.sendMessage(sender, sender == null ? Grasscutter.getLanguage().Teleport_usage_server :
Grasscutter.getLanguage().Teleport_usage);
return;
}
if (args.get(0).startsWith("@")) {
try {
target = Integer.parseInt(args.get(0).substring(1));
} catch (NumberFormatException e) {
CommandHandler.sendMessage(sender, "Invalid player id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
if (sender == null) {
CommandHandler.sendMessage(null, "You must specify a player id.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Teleport_specify_player_id);
return;
}
target = sender.getUid();
......@@ -37,7 +37,7 @@ public final class TeleportCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return;
}
args = args.subList(args.get(0).startsWith("@") ? 1 : 0, args.size());
......@@ -80,12 +80,12 @@ public final class TeleportCommand implements CommandHandler {
Position target_pos = new Position(x, y, z);
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos);
if (!result) {
CommandHandler.sendMessage(sender, "Invalid position.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
} else {
CommandHandler.sendMessage(sender, "Teleported " + targetPlayer.getNickname() + " to " + x + "," + y + "," + z + " in scene " + sceneId);
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Teleport_message, targetPlayer.getNickname(), x, y, z, sceneId));
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid position.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
}
}
}
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
......@@ -15,12 +16,12 @@ public final class WeatherCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: weather <weatherId> [climateId]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_usage);
return;
}
......@@ -33,9 +34,9 @@ public final class WeatherCommand implements CommandHandler {
sender.getScene().setWeather(weatherId);
sender.getScene().setClimate(climate);
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
CommandHandler.sendMessage(sender, "Changed weather to " + weatherId + " with climate " + climateId);
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Weather_message, weatherId, climateId));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
}
}
}
......@@ -32,7 +32,7 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler {
public void handle(Request req, Response res) throws IOException {
// 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())) {
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s %s request: %s", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : ""));
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_request, req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : ""));
}
res.send(response);
}
......
......@@ -211,21 +211,21 @@ public final class DispatchServer {
sslContextFactory.setKeyStorePassword(Grasscutter.getConfig().getDispatchOptions().KeystorePassword);
} catch (Exception e) {
e.printStackTrace();
Grasscutter.getLogger().warn("[Dispatch] Unable to load keystore. Trying default keystore password...");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Not_load_keystore);
try {
sslContextFactory.setKeyStorePath(keystoreFile.getPath());
sslContextFactory.setKeyStorePassword("123456");
Grasscutter.getLogger().warn("[Dispatch] The default keystore password was loaded successfully. Please consider setting the password to 123456 in config.json.");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Use_default_keystore);
} catch (Exception e2) {
Grasscutter.getLogger().warn("[Dispatch] Error while loading keystore!");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Load_keystore_error);
e2.printStackTrace();
}
}
serverConnector = new ServerConnector(server, sslContextFactory);
} else {
Grasscutter.getLogger().warn("[Dispatch] No SSL cert found! Falling back to HTTP server.");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Not_find_ssl_cert);
Grasscutter.getConfig().getDispatchOptions().UseSSL = false;
serverConnector = new ServerConnector(server);
......@@ -245,11 +245,11 @@ public final class DispatchServer {
}
});
httpServer.get("/", (req, res) -> res.send("Welcome to Grasscutter"));
httpServer.get("/", (req, res) -> res.send(Grasscutter.getLanguage().Welcome));
httpServer.raw().error(404, ctx -> {
if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING) {
Grasscutter.getLogger().info(String.format("[Dispatch] Potential unhandled %s request: %s", ctx.method(), ctx.url()));
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Potential_unhandled_request, ctx.method(), ctx.url()));
}
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.
......@@ -327,7 +327,7 @@ public final class DispatchServer {
return;
}
LoginResultJson responseData = new LoginResultJson();
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s is trying to log in via token", req.ip()));
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login_token, req.ip()));
// Login
Account account = DatabaseHelper.getAccountById(requestData.uid);
......@@ -335,17 +335,17 @@ public final class DispatchServer {
// Test
if (account == null || !account.getSessionKey().equals(requestData.token)) {
responseData.retcode = -111;
responseData.message = "Game account cache information error";
responseData.message = Grasscutter.getLanguage().Game_account_cache_error;
Grasscutter.getLogger()
.info(String.format("[Dispatch] Client %s failed to log in via token", req.ip()));
.info(String.format(Grasscutter.getLanguage().Client_token_login_failed, req.ip()));
} else {
responseData.message = "OK";
responseData.data.account.uid = requestData.uid;
responseData.data.account.token = requestData.token;
responseData.data.account.email = account.getEmail();
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s logged in via token as %s",
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login_in_token,
req.ip(), responseData.data.account.uid));
}
......@@ -376,10 +376,10 @@ public final class DispatchServer {
// Test
if (account == null || !account.getSessionKey().equals(loginData.token)) {
responseData.retcode = -201;
responseData.message = "Wrong session key.";
responseData.message = Grasscutter.getLanguage().Wrong_session_key;
Grasscutter.getLogger().info(
String.format("[Dispatch] Client %s failed to exchange combo token", req.ip()));
String.format(Grasscutter.getLanguage().Client_failed_exchange_combo_token, req.ip()));
} else {
responseData.message = "OK";
responseData.data.open_id = loginData.uid;
......@@ -387,7 +387,7 @@ public final class DispatchServer {
responseData.data.combo_token = account.generateLoginToken();
Grasscutter.getLogger().info(
String.format("[Dispatch] Client %s succeed to exchange combo token", req.ip()));
String.format(Grasscutter.getLanguage().Client_exchange_combo_token, req.ip()));
}
res.send(responseData);
......@@ -453,7 +453,7 @@ public final class DispatchServer {
httpServer.get("/gcstatic/*", new StaticFileHandler());
httpServer.listen(Grasscutter.getConfig().getDispatchOptions().Port);
Grasscutter.getLogger().info("[Dispatch] Dispatch server started on port " + httpServer.raw().port());
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Dispatch_start_server_port, httpServer.raw().port()));
}
private Map<String, String> parseQueryString(String qs) {
......
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