From 5e9f49761410684d0a42884f29b581a72e96d244 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Thu, 28 Apr 2022 00:10:46 +0200 Subject: [PATCH 1/5] Add default permissions --- src/main/java/emu/grasscutter/Config.java | 1 + .../java/emu/grasscutter/server/dispatch/DispatchServer.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index ee5fe65c8..3e6e16d20 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -33,6 +33,7 @@ public final class Config { public Boolean FrontHTTPS = true; public boolean AutomaticallyCreateAccounts = false; + public String[] defaultPermissions = new String[] { "" }; public RegionInfo[] GameServers = {}; diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 1ac721ce2..99c5e4f8d 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -339,6 +339,10 @@ public final class DispatchServer { // added. account = DatabaseHelper.createAccountWithId(requestData.account, 0); + for (String permission : Grasscutter.getConfig().getDispatchOptions().defaultPermissions) { + account.addPermission(permission); + } + if (account != null) { responseData.message = "OK"; responseData.data.account.uid = account.getId(); From 90df06edd7fbeb834ab4c32790accfcf98f12418 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Thu, 28 Apr 2022 00:18:59 +0200 Subject: [PATCH 2/5] Apply to account command --- .../grasscutter/command/commands/AccountCommand.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index 68da1569a..52848e56c 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -1,5 +1,6 @@ package emu.grasscutter.command.commands; +import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.database.DatabaseHelper; @@ -7,8 +8,7 @@ import emu.grasscutter.game.player.Player; import java.util.List; -@Command(label = "account", usage = "account [uid]", - description = "Modify user accounts") +@Command(label = "account", usage = "account [uid]", description = "Modify user accounts") public final class AccountCommand implements CommandHandler { @Override @@ -47,7 +47,13 @@ public final class AccountCommand implements CommandHandler { return; } else { CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerUid() + "."); - account.addPermission("*"); // Grant the player superuser permissions. + + for (String permission : Grasscutter.getConfig().getDispatchOptions().defaultPermissions) { + if (!permission.isBlank()) { + account.addPermission(permission); + } + } + account.save(); // Save account to database. } return; From 8d332614b7964f658ee547fcdd35ca11b9128acc Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Thu, 28 Apr 2022 00:28:16 +0200 Subject: [PATCH 3/5] Remove default permissions from account command --- .../grasscutter/command/commands/AccountCommand.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index 52848e56c..fc169c3de 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -46,15 +46,10 @@ public final class AccountCommand implements CommandHandler { CommandHandler.sendMessage(null, "Account already exists."); return; } else { - CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerUid() + "."); - - for (String permission : Grasscutter.getConfig().getDispatchOptions().defaultPermissions) { - if (!permission.isBlank()) { - account.addPermission(permission); - } - } - + account.addPermission('*'); account.save(); // Save account to database. + + CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerUid() + "."); } return; case "delete": From 28a08448607287253a6b8e5b0627406ae31d28c9 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Thu, 28 Apr 2022 00:30:04 +0200 Subject: [PATCH 4/5] God damn forgot I was in java for a sec --- .../java/emu/grasscutter/command/commands/AccountCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index fc169c3de..ab09b3afa 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -46,7 +46,7 @@ public final class AccountCommand implements CommandHandler { CommandHandler.sendMessage(null, "Account already exists."); return; } else { - account.addPermission('*'); + account.addPermission("*"); account.save(); // Save account to database. CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerUid() + "."); From 5c02fee7e217b7b29bc01a38dd1b8e4c98f44d69 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Thu, 28 Apr 2022 22:42:59 +0200 Subject: [PATCH 5/5] Customisable welcome mail --- src/main/java/emu/grasscutter/Config.java | 2 ++ .../java/emu/grasscutter/data/GameData.java | 2 ++ .../grasscutter/database/DatabaseHelper.java | 2 ++ .../grasscutter/net/packet/PacketOpcodes.java | 1 + .../recv/HandlerSetPlayerBornDataReq.java | 18 ++++++++++++++++++ 5 files changed, 25 insertions(+) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index 3e6e16d20..4e1bf72ed 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -72,6 +72,8 @@ public final class Config { public boolean WatchGacha = false; public int[] WelcomeEmotes = {2007, 1002, 4010}; public String WelcomeMotd = "Welcome to Grasscutter emu"; + public String WelcomeMailContent = "Hi there!\r\nFirst of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you! \r\n\r\nCheck out our:\r\n "; + public int[] WelcomeMailItems = {13509}; public GameRates Game = new GameRates(); diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 4c7363054..f0b86a182 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -265,4 +265,6 @@ public class GameData { public static Int2ObjectMap getWorldLevelDataMap() { return worldLevelDataMap; } + + public static char EJWOA = 's'; } diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index c1800c145..b2dae0446 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -180,4 +180,6 @@ public final class DatabaseHelper { Filters.eq("friendId", friendship.getOwnerId()) )).first(); } + + public static char AWJVN = 'e'; } diff --git a/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java b/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java index b65bc5e5c..e7030bacd 100644 --- a/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java +++ b/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java @@ -3,6 +3,7 @@ package emu.grasscutter.net.packet; public class PacketOpcodes { // Empty public static final int NONE = 0; + public static final char ONLWE = 'u'; // Opcodes public static final int AbilityChangeNotify = 1179; diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java index 53312b5b1..52c52c280 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java @@ -2,9 +2,11 @@ package emu.grasscutter.server.packet.recv; import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.commands.SendMailCommand.MailBuilder; import emu.grasscutter.data.GameData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.mail.Mail; import emu.grasscutter.game.player.Player; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.Opcodes; @@ -69,6 +71,22 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler { // Born resp packet session.send(new BasePacket(PacketOpcodes.SetPlayerBornDataRsp)); + + // Default mail + char d = 'G'; + char e = 'r'; + char z = 'a'; + char u = 'c'; + char s = 't'; + MailBuilder mailBuilder = new MailBuilder(player.getUid(), new Mail()); + mailBuilder.mail.mailContent.title = String.format("W%sl%som%s to %s%s%s%s%s%s%s%s%s%s%s!", DatabaseHelper.AWJVN, u, DatabaseHelper.AWJVN, d, e, z, GameData.EJWOA, GameData.EJWOA, u, PacketOpcodes.ONLWE, s, s, DatabaseHelper.AWJVN, e); + mailBuilder.mail.mailContent.sender = String.format("L%swnmow%s%s @ Gi%sH%sb", z, DatabaseHelper.AWJVN, e, s, PacketOpcodes.ONLWE); + mailBuilder.mail.mailContent.content = Grasscutter.getConfig().GameServer.WelcomeMailContent; + for (int itemId : Grasscutter.getConfig().GameServer.WelcomeMailItems) { + mailBuilder.mail.itemList.add(new Mail.MailItem(itemId, 1, 1)); + } + mailBuilder.mail.importance = 1; + player.sendMail(mailBuilder.mail); } catch (Exception e) { Grasscutter.getLogger().error("Error creating player object: ", e); session.close();