mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-17 06:44:35 +01:00
Improve command system
This commit is contained in:
@@ -233,7 +233,8 @@ public class Nebula {
|
|||||||
String input;
|
String input;
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
|
||||||
while ((input = br.readLine()) != null) {
|
while ((input = br.readLine()) != null) {
|
||||||
Nebula.getCommandManager().invoke(null, input);
|
var result = Nebula.getCommandManager().invoke(null, input);
|
||||||
|
Nebula.getLogger().info(result.getMessage());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Nebula.getLogger().error("Console error:", e);
|
Nebula.getLogger().error("Console error:", e);
|
||||||
|
|||||||
@@ -113,18 +113,6 @@ public class CommandArgs {
|
|||||||
return this.list.get(index);
|
return this.list.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a message to the command sender
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
public void sendMessage(String message) {
|
|
||||||
if (sender != null) {
|
|
||||||
sender.sendMessage(message);
|
|
||||||
} else {
|
|
||||||
Nebula.getLogger().info(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasFlag(String flag) {
|
public boolean hasFlag(String flag) {
|
||||||
if (this.flags == null) return false;
|
if (this.flags == null) return false;
|
||||||
return this.flags.contains(flag);
|
return this.flags.contains(flag);
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ public interface CommandHandler {
|
|||||||
return getData().label();
|
return getData().label();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(CommandArgs args);
|
public String execute(CommandArgs args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public class CommandManager {
|
|||||||
return sender.getAccount().hasPermission("target." + command.permission());
|
return sender.getAccount().hasPermission("target." + command.permission());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invoke(Player sender, String message) {
|
public CommandResult invoke(Player sender, String message) {
|
||||||
// Parse message into arguments
|
// Parse message into arguments
|
||||||
List<String> args = Arrays.stream(message.split(" ")).collect(Collectors.toCollection(ArrayList::new));
|
List<String> args = Arrays.stream(message.split(" ")).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
|
||||||
@@ -123,6 +123,9 @@ public class CommandManager {
|
|||||||
// Get command handler
|
// Get command handler
|
||||||
CommandHandler handler = this.commands.get(label);
|
CommandHandler handler = this.commands.get(label);
|
||||||
|
|
||||||
|
// Create result object
|
||||||
|
var result = CommandResult.builder();
|
||||||
|
|
||||||
// Execute command
|
// Execute command
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
// Get command annotation data
|
// Get command annotation data
|
||||||
@@ -131,8 +134,8 @@ public class CommandManager {
|
|||||||
// Check if sender has permission to run the command.
|
// Check if sender has permission to run the command.
|
||||||
if (sender != null && !this.checkPermission(sender, command)) {
|
if (sender != null && !this.checkPermission(sender, command)) {
|
||||||
// We have a double null check here just in case
|
// We have a double null check here just in case
|
||||||
sender.sendMessage("You do not have permission to use this command.");
|
result.message("Error - You do not have permission to use this command");
|
||||||
return;
|
return result.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build command arguments
|
// Build command arguments
|
||||||
@@ -140,14 +143,14 @@ public class CommandManager {
|
|||||||
|
|
||||||
// Check targeted permission
|
// Check targeted permission
|
||||||
if (sender != cmdArgs.getTarget() && !this.checkTargetPermission(sender, command)) {
|
if (sender != cmdArgs.getTarget() && !this.checkTargetPermission(sender, command)) {
|
||||||
cmdArgs.sendMessage("You do not have permission to use this command on another player.");
|
result.message("Error - You do not have permission to use this command on another player");
|
||||||
return;
|
return result.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure our command has a target
|
// Make sure our command has a target
|
||||||
if (command.requireTarget() && cmdArgs.getTarget() == null) {
|
if (command.requireTarget() && cmdArgs.getTarget() == null) {
|
||||||
cmdArgs.sendMessage("Error: Targeted player not found or offline");
|
result.message("Error - Targeted player not found or offline");
|
||||||
return;
|
return result.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
@@ -156,13 +159,20 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run command
|
// Run command
|
||||||
handler.execute(cmdArgs);
|
String commandMessage = handler.execute(cmdArgs);
|
||||||
} else {
|
|
||||||
if (sender != null) {
|
// Parse out last newline
|
||||||
sender.sendMessage("Invalid Command!");
|
if (commandMessage.endsWith("\n")) {
|
||||||
} else {
|
commandMessage = commandMessage.substring(0, commandMessage.length() - 1);
|
||||||
Nebula.getLogger().info("Invalid Command!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set result data
|
||||||
|
result.command(handler);
|
||||||
|
result.message(commandMessage);
|
||||||
|
} else {
|
||||||
|
result.message("Invalid Command!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/main/java/emu/nebula/command/CommandResult.java
Normal file
19
src/main/java/emu/nebula/command/CommandResult.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package emu.nebula.command;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
public class CommandResult {
|
||||||
|
private CommandHandler command;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public boolean isCommandTypeOf(Class<? extends CommandHandler> handler) {
|
||||||
|
if (command == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return command.getClass().equals(handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,10 +10,9 @@ import emu.nebula.util.Utils;
|
|||||||
public class AccountCommand implements CommandHandler {
|
public class AccountCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
args.sendMessage("Invalid amount of args");
|
return "Invalid amount of args";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String command = args.get(0).toLowerCase();
|
String command = args.get(0).toLowerCase();
|
||||||
@@ -29,19 +28,22 @@ public class AccountCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (AccountHelper.createAccount(username, null, reservedUid) != null) {
|
if (AccountHelper.createAccount(username, null, reservedUid) != null) {
|
||||||
args.sendMessage("Account created");
|
return "Account created";
|
||||||
} else {
|
} else {
|
||||||
args.sendMessage("Account already exists");
|
return "Account already exists";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "delete" -> {
|
case "delete" -> {
|
||||||
if (AccountHelper.deleteAccount(username)) {
|
if (AccountHelper.deleteAccount(username)) {
|
||||||
args.sendMessage("Account deleted");
|
return "Account deleted";
|
||||||
} else {
|
} else {
|
||||||
args.sendMessage("Account doesnt exist");
|
return "Account doesnt exist";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
return "Account sub command not found";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import emu.nebula.command.CommandHandler;
|
|||||||
public class CharacterCommand implements CommandHandler {
|
public class CharacterCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
// Init
|
// Init
|
||||||
var player = args.getTarget();
|
var player = args.getTarget();
|
||||||
var characters = new HashSet<GameCharacter>();
|
var characters = new HashSet<GameCharacter>();
|
||||||
@@ -51,8 +51,7 @@ public class CharacterCommand implements CommandHandler {
|
|||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (characters.isEmpty()) {
|
if (characters.isEmpty()) {
|
||||||
args.sendMessage("Error: No characters selected");
|
return "Error: No characters selected";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of modified characters that we send to the client for updates
|
// List of modified characters that we send to the client for updates
|
||||||
@@ -73,8 +72,7 @@ public class CharacterCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (modified.isEmpty()) {
|
if (modified.isEmpty()) {
|
||||||
args.sendMessage("No changes applied");
|
return "No changes applied";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode and send
|
// Encode and send
|
||||||
@@ -85,6 +83,6 @@ public class CharacterCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.addNextPackage(NetMsgId.chars_final_notify, proto);
|
player.addNextPackage(NetMsgId.chars_final_notify, proto);
|
||||||
args.sendMessage("Updated " + modified.size() + " character(s)");
|
return "Updated " + modified.size() + " character(s)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import java.util.HashSet;
|
|||||||
public class CleanCommand implements CommandHandler {
|
public class CleanCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
var player = args.getTarget();
|
var player = args.getTarget();
|
||||||
var inv = player.getInventory();
|
var inv = player.getInventory();
|
||||||
|
|
||||||
@@ -77,8 +77,8 @@ public class CleanCommand implements CommandHandler {
|
|||||||
} else {
|
} else {
|
||||||
for (int id : ids) {
|
for (int id : ids) {
|
||||||
ItemDef data = GameData.getItemDataTable().get(id);
|
ItemDef data = GameData.getItemDataTable().get(id);
|
||||||
|
if (data == null) continue;
|
||||||
|
|
||||||
if (data != null) {
|
|
||||||
ItemType type = data.getItemType();
|
ItemType type = data.getItemType();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -111,9 +111,6 @@ public class CleanCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
args.sendMessage("Error: Invalid item id " + id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,11 +119,11 @@ public class CleanCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (change.isEmpty()) {
|
if (change.isEmpty()) {
|
||||||
args.sendMessage("No items/resources removed");
|
return "No items/resources removed";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.addNextPackage(NetMsgId.items_change_notify, change.toProto());
|
player.addNextPackage(NetMsgId.items_change_notify, change.toProto());
|
||||||
args.sendMessage("Inventory cleaned");
|
|
||||||
|
return "Inventory cleaned";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import emu.nebula.command.CommandHandler;
|
|||||||
public class DiscCommand implements CommandHandler {
|
public class DiscCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
// Init
|
// Init
|
||||||
var player = args.getTarget();
|
var player = args.getTarget();
|
||||||
var discs = new HashSet<GameDisc>();
|
var discs = new HashSet<GameDisc>();
|
||||||
@@ -50,7 +50,7 @@ public class DiscCommand implements CommandHandler {
|
|||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (discs.isEmpty()) {
|
if (discs.isEmpty()) {
|
||||||
return;
|
return "No discs selected";
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of modified characters that we send to the client for updates
|
// List of modified characters that we send to the client for updates
|
||||||
@@ -71,12 +71,15 @@ public class DiscCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (modified.isEmpty()) {
|
if (modified.isEmpty()) {
|
||||||
return;
|
return "No discs changed";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode and send
|
// Encode and send
|
||||||
for (var disc : modified) {
|
for (var disc : modified) {
|
||||||
player.addNextPackage(NetMsgId.disc_reset_notify, disc.toProto());
|
player.addNextPackage(NetMsgId.disc_reset_notify, disc.toProto());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return message
|
||||||
|
return "Changed " + modified.size() + " discs";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,15 +31,14 @@ public class GiveAllCommand implements CommandHandler {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
Player target = args.getTarget();
|
Player target = args.getTarget();
|
||||||
String type = args.get(0).toLowerCase();
|
String type = args.get(0).toLowerCase();
|
||||||
|
|
||||||
|
|
||||||
var change = new PlayerChangeInfo();
|
var change = new PlayerChangeInfo();
|
||||||
|
var message = new StringBuilder();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
default -> args.sendMessage("Error: Invalid type");
|
|
||||||
case "m", "materials", "mats" -> {
|
case "m", "materials", "mats" -> {
|
||||||
// Create items map
|
// Create items map
|
||||||
var items = new ItemParamMap();
|
var items = new ItemParamMap();
|
||||||
@@ -66,7 +65,7 @@ public class GiveAllCommand implements CommandHandler {
|
|||||||
target.getInventory().addItems(items, change);
|
target.getInventory().addItems(items, change);
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
args.sendMessage("Giving " + target.getName() + " " + items.size() + " items");
|
message.append("Giving " + target.getName() + " " + items.size() + " items.\n");
|
||||||
}
|
}
|
||||||
case "d", "discs" -> {
|
case "d", "discs" -> {
|
||||||
// Get all discs
|
// Get all discs
|
||||||
@@ -92,7 +91,7 @@ public class GiveAllCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
args.sendMessage("Giving " + target.getName() + " all discs");
|
message.append("Giving " + target.getName() + " all discs.\n");
|
||||||
}
|
}
|
||||||
case "c", "characters", "trekkers", "t" -> {
|
case "c", "characters", "trekkers", "t" -> {
|
||||||
// Get all characters
|
// Get all characters
|
||||||
@@ -118,16 +117,22 @@ public class GiveAllCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
args.sendMessage("Giving " + target.getName() + " all characters");
|
message.append("Giving " + target.getName() + " all characters.\n");
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
// Ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (change.isEmpty()) {
|
if (change.isEmpty()) {
|
||||||
return;
|
return "No items given to the player";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode and send
|
// Encode and send
|
||||||
target.addNextPackage(NetMsgId.items_change_notify, change.toProto());
|
target.addNextPackage(NetMsgId.items_change_notify, change.toProto());
|
||||||
|
|
||||||
|
// Complete
|
||||||
|
return message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import emu.nebula.command.CommandHandler;
|
|||||||
public class GiveCommand implements CommandHandler {
|
public class GiveCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
// Setup mail
|
// Setup mail
|
||||||
var mail = new GameMail("System", "Give Command Result", "");
|
var mail = new GameMail("System", "Give Command Result", "");
|
||||||
|
|
||||||
@@ -31,18 +31,17 @@ public class GiveCommand implements CommandHandler {
|
|||||||
|
|
||||||
var itemData = GameData.getItemDataTable().get(itemId);
|
var itemData = GameData.getItemDataTable().get(itemId);
|
||||||
if (itemData == null) {
|
if (itemData == null) {
|
||||||
args.sendMessage("Item \"" + arg + "\" does not exist!");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add
|
// Add
|
||||||
mail.addAttachment(itemId, amount);
|
mail.addAttachment(itemId, amount);
|
||||||
|
|
||||||
// Log
|
|
||||||
args.sendMessage("Giving " + args.getTarget().getName() + " " + amount + " of " + itemId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add mail
|
// Add mail
|
||||||
args.getTarget().getMailbox().sendMail(mail);
|
args.getTarget().getMailbox().sendMail(mail);
|
||||||
|
|
||||||
|
//
|
||||||
|
return "Give command success, check your mail";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import emu.nebula.command.CommandHandler;
|
|||||||
public class HelpCommand implements CommandHandler {
|
public class HelpCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
args.sendMessage("Displaying list of commands:");
|
var message = new StringBuilder();
|
||||||
|
|
||||||
|
message.append("Displaying list of commands:\n");
|
||||||
|
|
||||||
// Sort command names
|
// Sort command names
|
||||||
var labels = Nebula.getCommandManager().getLabels().keySet().stream().sorted().toList();
|
var labels = Nebula.getCommandManager().getLabels().keySet().stream().sorted().toList();
|
||||||
@@ -21,9 +23,11 @@ public class HelpCommand implements CommandHandler {
|
|||||||
|
|
||||||
// Only send command description if the sender has permission to use the command
|
// Only send command description if the sender has permission to use the command
|
||||||
if (Nebula.getCommandManager().checkPermission(args.getSender(), command)) {
|
if (Nebula.getCommandManager().checkPermission(args.getSender(), command)) {
|
||||||
args.sendMessage(command.desc());
|
message.append(command.desc());
|
||||||
}
|
message.append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,41 +17,36 @@ import emu.nebula.util.Utils;
|
|||||||
desc = "/mail \"subject\" \"body\" [itemId xQty | itemId:qty ...]. Sends the targeted player a system mail."
|
desc = "/mail \"subject\" \"body\" [itemId xQty | itemId:qty ...]. Sends the targeted player a system mail."
|
||||||
)
|
)
|
||||||
public class MailCommand implements CommandHandler {
|
public class MailCommand implements CommandHandler {
|
||||||
|
private static final String USAGE_TEXT = "Usage: /mail \"subject\" \"body\" [itemId xQty | itemId:qty ...]";
|
||||||
private static final Pattern QUOTED_TEXT = Pattern.compile("\"([^\"]*)\"");
|
private static final Pattern QUOTED_TEXT = Pattern.compile("\"([^\"]*)\"");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
var target = args.getTarget();
|
var target = args.getTarget();
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
args.sendMessage("Error: Targeted player not found or offline");
|
return "Error - Targeted player not found or offline";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String rawInput = args.getRaw() == null ? "" : args.getRaw().trim();
|
String rawInput = args.getRaw() == null ? "" : args.getRaw().trim();
|
||||||
if (rawInput.isEmpty()) {
|
if (rawInput.isEmpty()) {
|
||||||
sendUsage(args);
|
return USAGE_TEXT;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher matcher = QUOTED_TEXT.matcher(rawInput);
|
Matcher matcher = QUOTED_TEXT.matcher(rawInput);
|
||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
sendUsage(args);
|
return USAGE_TEXT;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String subject = matcher.group(1).trim();
|
String subject = matcher.group(1).trim();
|
||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
args.sendMessage("Mail body must be wrapped in quotes after the subject.");
|
return "Mail body must be wrapped in quotes after the subject.";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String body = matcher.group(1).trim();
|
String body = matcher.group(1).trim();
|
||||||
int attachmentStartIndex = matcher.end();
|
int attachmentStartIndex = matcher.end();
|
||||||
|
|
||||||
if (subject.isEmpty()) {
|
if (subject.isEmpty()) {
|
||||||
args.sendMessage("Mail subject cannot be empty.");
|
return "Mail subject cannot be empty.";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.isEmpty()) {
|
if (body.isEmpty()) {
|
||||||
@@ -68,7 +63,7 @@ public class MailCommand implements CommandHandler {
|
|||||||
parseAttachments(attachmentSection, mail, args);
|
parseAttachments(attachmentSection, mail, args);
|
||||||
|
|
||||||
target.getMailbox().sendMail(mail);
|
target.getMailbox().sendMail(mail);
|
||||||
args.sendMessage("Mail sent to " + target.getName() + " with subject \"" + subject + "\".");
|
return "Mail sent to " + target.getName() + " with subject \"" + subject + "\".";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseAttachments(String attachmentSection, GameMail mail, CommandArgs args) {
|
private void parseAttachments(String attachmentSection, GameMail mail, CommandArgs args) {
|
||||||
@@ -93,7 +88,7 @@ public class MailCommand implements CommandHandler {
|
|||||||
|
|
||||||
if (token.startsWith("x") && token.length() > 1) {
|
if (token.startsWith("x") && token.length() > 1) {
|
||||||
if (pendingItemId == null) {
|
if (pendingItemId == null) {
|
||||||
args.sendMessage("Quantity token '" + token + "' must follow an item id.");
|
//args.sendMessage("Quantity token '" + token + "' must follow an item id.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +105,7 @@ public class MailCommand implements CommandHandler {
|
|||||||
|
|
||||||
int itemId = Utils.parseSafeInt(token);
|
int itemId = Utils.parseSafeInt(token);
|
||||||
if (itemId <= 0) {
|
if (itemId <= 0) {
|
||||||
args.sendMessage("Invalid item id '" + token + "'.");
|
//args.sendMessage("Invalid item id '" + token + "'.");
|
||||||
pendingItemId = null;
|
pendingItemId = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -119,7 +114,7 @@ public class MailCommand implements CommandHandler {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
args.sendMessage("Ignoring attachment token '" + token + "'.");
|
//args.sendMessage("Ignoring attachment token '" + token + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pendingItemId != null) {
|
if (pendingItemId != null) {
|
||||||
@@ -129,7 +124,7 @@ public class MailCommand implements CommandHandler {
|
|||||||
|
|
||||||
private void addAttachment(GameMail mail, CommandArgs args, int itemId, int quantity) {
|
private void addAttachment(GameMail mail, CommandArgs args, int itemId, int quantity) {
|
||||||
if (itemId <= 0) {
|
if (itemId <= 0) {
|
||||||
args.sendMessage("Item id must be positive.");
|
//args.sendMessage("Item id must be positive.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,8 +140,4 @@ public class MailCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
return !token.isEmpty();
|
return !token.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendUsage(CommandArgs args) {
|
|
||||||
args.sendMessage("Usage: /mail \"subject\" \"body\" [itemId xQty | itemId:qty ...]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,17 @@ import emu.nebula.command.CommandHandler;
|
|||||||
public class ReloadCommand implements CommandHandler {
|
public class ReloadCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
|
// Reload config first
|
||||||
Nebula.loadConfig();
|
Nebula.loadConfig();
|
||||||
|
|
||||||
|
// Reload patch list if the server is running
|
||||||
if (Nebula.getHttpServer() != null) {
|
if (Nebula.getHttpServer() != null) {
|
||||||
Nebula.getHttpServer().loadPatchList();
|
Nebula.getHttpServer().loadPatchList();
|
||||||
}
|
}
|
||||||
|
|
||||||
args.sendMessage("Reloaded the server config");
|
// Result message
|
||||||
|
return "Reloaded the server config";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,17 +9,11 @@ import java.util.Random;
|
|||||||
|
|
||||||
@Command(label = "remote", permission = "player.remote", requireTarget = true, desc = "/remote. Send remote to web remote")
|
@Command(label = "remote", permission = "player.remote", requireTarget = true, desc = "/remote. Send remote to web remote")
|
||||||
public class RemoteKeyCommand implements CommandHandler {
|
public class RemoteKeyCommand implements CommandHandler {
|
||||||
|
private final String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
private static String lastMessage;
|
|
||||||
|
|
||||||
public static String getLastMessage() {
|
|
||||||
return lastMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandArgs args) {
|
public String execute(CommandArgs args) {
|
||||||
if (Nebula.getConfig().getRemoteCommand().useRemoteServices) {
|
if (Nebula.getConfig().getRemoteCommand().useRemoteServices) {
|
||||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
||||||
@@ -27,18 +21,12 @@ public class RemoteKeyCommand implements CommandHandler {
|
|||||||
int index = random.nextInt(characters.length());
|
int index = random.nextInt(characters.length());
|
||||||
sb.append(characters.charAt(index));
|
sb.append(characters.charAt(index));
|
||||||
}
|
}
|
||||||
args.getTarget().setPlayerRemoteToken(sb.toString());
|
|
||||||
args.getTarget().save();
|
|
||||||
String textsend = "Key Generated: " + sb.toString();
|
|
||||||
lastMessage = textsend;
|
|
||||||
args.sendMessage(textsend);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String textsend = "RemoteCommand Disabled on Server";
|
|
||||||
args.getTarget().setPlayerRemoteToken(null);
|
|
||||||
args.getTarget().save();
|
|
||||||
lastMessage = textsend;
|
|
||||||
args.sendMessage(textsend);
|
|
||||||
|
|
||||||
|
args.getTarget().setRemoteToken(sb.toString());
|
||||||
|
return "Key Generated: " + sb.toString();
|
||||||
|
} else {
|
||||||
|
args.getTarget().setRemoteToken(null);
|
||||||
|
return "Remote Command Disabled on Server";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package emu.nebula.game.player;
|
|||||||
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.AlsoLoad;
|
||||||
import dev.morphia.annotations.Entity;
|
import dev.morphia.annotations.Entity;
|
||||||
import dev.morphia.annotations.Id;
|
import dev.morphia.annotations.Id;
|
||||||
import dev.morphia.annotations.Indexed;
|
import dev.morphia.annotations.Indexed;
|
||||||
@@ -46,7 +47,6 @@ import emu.nebula.proto.Public.WorldClassRewardState;
|
|||||||
import emu.nebula.proto.Public.Title;
|
import emu.nebula.proto.Public.Title;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import us.hebi.quickbuf.ProtoMessage;
|
import us.hebi.quickbuf.ProtoMessage;
|
||||||
import us.hebi.quickbuf.RepeatedInt;
|
import us.hebi.quickbuf.RepeatedInt;
|
||||||
|
|
||||||
@@ -59,6 +59,10 @@ public class Player implements GameDatabaseObject {
|
|||||||
private transient Account account;
|
private transient Account account;
|
||||||
private transient GameSession session;
|
private transient GameSession session;
|
||||||
|
|
||||||
|
@Indexed
|
||||||
|
@AlsoLoad("playerRemoteToken")
|
||||||
|
private String remoteToken;
|
||||||
|
|
||||||
// Details
|
// Details
|
||||||
private String name;
|
private String name;
|
||||||
private String signature;
|
private String signature;
|
||||||
@@ -90,7 +94,6 @@ public class Player implements GameDatabaseObject {
|
|||||||
private final transient InfinityTowerManager infinityTowerManager;
|
private final transient InfinityTowerManager infinityTowerManager;
|
||||||
private final transient VampireSurvivorManager vampireSurvivorManager;
|
private final transient VampireSurvivorManager vampireSurvivorManager;
|
||||||
private final transient ScoreBossManager scoreBossManager;
|
private final transient ScoreBossManager scoreBossManager;
|
||||||
@Indexed @Setter @Getter private String playerRemoteToken;
|
|
||||||
|
|
||||||
// Referenced data
|
// Referenced data
|
||||||
private transient Inventory inventory;
|
private transient Inventory inventory;
|
||||||
@@ -147,7 +150,6 @@ public class Player implements GameDatabaseObject {
|
|||||||
this.honor = new int[3];
|
this.honor = new int[3];
|
||||||
this.showChars = new int[3];
|
this.showChars = new int[3];
|
||||||
this.boards = new int[] {410301};
|
this.boards = new int[] {410301};
|
||||||
this.playerRemoteToken = null;
|
|
||||||
|
|
||||||
this.level = 1;
|
this.level = 1;
|
||||||
this.energy = 240;
|
this.energy = 240;
|
||||||
@@ -200,6 +202,25 @@ public class Player implements GameDatabaseObject {
|
|||||||
return this.session != null;
|
return this.session != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRemoteToken(String token) {
|
||||||
|
// Skip if tokens are the same
|
||||||
|
if (this.remoteToken == null) {
|
||||||
|
if (token == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (this.remoteToken != null) {
|
||||||
|
if (this.remoteToken.equals(token)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set remote token
|
||||||
|
this.remoteToken = token;
|
||||||
|
|
||||||
|
// Update in database
|
||||||
|
Nebula.getGameDatabase().update(this, this.getUid(), "remoteToken", this.remoteToken);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getGender() {
|
public boolean getGender() {
|
||||||
return this.gender;
|
return this.gender;
|
||||||
}
|
}
|
||||||
@@ -553,12 +574,6 @@ public class Player implements GameDatabaseObject {
|
|||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
public void sendMessage(String string) {
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dailies
|
// Dailies
|
||||||
|
|
||||||
public void checkResetDailies() {
|
public void checkResetDailies() {
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ public class GameSession {
|
|||||||
var player = this.player;
|
var player = this.player;
|
||||||
this.player = null;
|
this.player = null;
|
||||||
|
|
||||||
// Clear remote token
|
|
||||||
player.setPlayerRemoteToken(null);
|
|
||||||
player.save();
|
|
||||||
|
|
||||||
// Remove session from player
|
// Remove session from player
|
||||||
player.removeSession();
|
player.removeSession();
|
||||||
|
|
||||||
|
|||||||
@@ -23,27 +23,11 @@ public class HandlerPlayerSignatureEdit extends NetHandler {
|
|||||||
|
|
||||||
// Check if we need to handle a command
|
// Check if we need to handle a command
|
||||||
if (signature.charAt(0) == '!' || signature.charAt(0) == '/') {
|
if (signature.charAt(0) == '!' || signature.charAt(0) == '/') {
|
||||||
String commandLabel = signature.toLowerCase().trim();
|
var result = Nebula.getCommandManager().invoke(session.getPlayer(), signature);
|
||||||
if (commandLabel.startsWith("!") || commandLabel.startsWith("/")) {
|
|
||||||
commandLabel = commandLabel.substring(1).split(" ")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
Nebula.getCommandManager().invoke(session.getPlayer(), signature);
|
|
||||||
|
|
||||||
// If this is the remote command, return the message
|
|
||||||
if ("remote".equals(commandLabel)) {
|
|
||||||
String remoteMessage = emu.nebula.command.commands.RemoteKeyCommand.getLastMessage();
|
|
||||||
if (remoteMessage != null) {
|
|
||||||
return session.encodeMsg(
|
|
||||||
NetMsgId.player_signature_edit_failed_ack,
|
|
||||||
Error.newInstance().setCode(119902).addArguments("\n" + remoteMessage)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return session.encodeMsg(
|
return session.encodeMsg(
|
||||||
NetMsgId.player_signature_edit_failed_ack,
|
NetMsgId.player_signature_edit_failed_ack,
|
||||||
Error.newInstance().setCode(119902).addArguments("\nCommand Success")
|
Error.newInstance().setCode(119902).addArguments("\nCommand Result: " + result.getMessage())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class RemoteHandler implements Handler {
|
|||||||
if (cachedUid != null) {
|
if (cachedUid != null) {
|
||||||
player = Nebula.getGameContext().getPlayerModule().getPlayer(cachedUid);
|
player = Nebula.getGameContext().getPlayerModule().getPlayer(cachedUid);
|
||||||
// Verify token matches (in case player changed token or cache is stale)
|
// Verify token matches (in case player changed token or cache is stale)
|
||||||
if (player != null && !token.equals(player.getPlayerRemoteToken())) {
|
if (player != null && !token.equals(player.getRemoteToken())) {
|
||||||
player = null;
|
player = null;
|
||||||
tokenCache.remove(token);
|
tokenCache.remove(token);
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ public class RemoteHandler implements Handler {
|
|||||||
|
|
||||||
// 2. Fallback to DB if not in cache or cache invalid
|
// 2. Fallback to DB if not in cache or cache invalid
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
player = Nebula.getGameDatabase().getObjectByField(Player.class, "playerRemoteToken", token);
|
player = Nebula.getGameDatabase().getObjectByField(Player.class, "remoteToken", token);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
tokenCache.put(token, player.getUid());
|
tokenCache.put(token, player.getUid());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user