From 76ba7cb94215e88ebdb4aeb79799800f747fe9bd Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 27 Nov 2023 03:41:48 -0500 Subject: [PATCH 1/9] feat: Custom prefixes and basic help command --- config.json | 6 ++++++ config/config.go | 1 + server/channelserver/handlers_cast_binary.go | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index da75463ee..5a6e09216 100644 --- a/config.json +++ b/config.json @@ -14,6 +14,7 @@ "ClientMode": "ZZ", "QuestCacheExpiry": 300, "ProxyPort": 0, + "CommandPrefix": "!", "DevMode": true, "DevModeOptions": { "AutoCreateAccount": true, @@ -78,6 +79,11 @@ "RealtimeChannelID": "" }, "Commands": [ + { + "Name": "Help", + "Enabled": true, + "Prefix": "help" + }, { "Name": "Rights", "Enabled": false, diff --git a/config/config.go b/config/config.go index 31fedd246..5a50a511b 100644 --- a/config/config.go +++ b/config/config.go @@ -81,6 +81,7 @@ type Config struct { RealClientMode Mode QuestCacheExpiry int // Number of seconds to keep quest data cached ProxyPort uint16 // Forces the game to connect to a channel server proxy + CommandPrefix string // The prefix for commands DevMode bool DevModeOptions DevModeOptions diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index dbfafc68c..806c50749 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -318,6 +318,12 @@ func parseChatCommand(s *Session, command string) { } else { sendDisabledCommandMessage(s, commands["Teleport"]) } + case commands["Help"].Prefix: + if commands["Help"].Enabled { + sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandTeleportSuccess"], x, y)) + } else { + sendDisabledCommandMessage(s, commands["Help"]) + } } } @@ -391,7 +397,7 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) { bf.SetLE() chatMessage := &binpacket.MsgBinChat{} chatMessage.Parse(bf) - if strings.HasPrefix(chatMessage.Message, "!") { + if strings.HasPrefix(chatMessage.Message, s.server.erupeConfig.CommandPrefix) { parseChatCommand(s, chatMessage.Message) return } From ce773a6c569f464932d3c7c94b37183ed987726d Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 27 Nov 2023 04:05:15 -0500 Subject: [PATCH 2/9] feat: Finish help command and add description to commands. --- config.json | 8 ++++++++ config/config.go | 7 ++++--- server/channelserver/handlers_cast_binary.go | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index 5a6e09216..e18506f3a 100644 --- a/config.json +++ b/config.json @@ -82,35 +82,43 @@ { "Name": "Help", "Enabled": true, + "Description": "Show all of the commands", "Prefix": "help" }, { "Name": "Rights", "Enabled": false, + "Description": "Directly alter user's applied courses.", "Prefix": "rights" }, { "Name": "Raviente", "Enabled": true, + "Description": "Start or view an ongoing raviante raid.", "Prefix": "ravi" }, { "Name": "Teleport", "Enabled": false, + "Description": "Teleport to a specified stage.", "Prefix": "tele" }, { "Name": "Reload", "Enabled": true, + "Description": "Reload all user sessions (Forces log out)", "Prefix": "reload" }, { "Name": "KeyQuest", "Enabled": false, + "Description": "Allow the overriding of necessary key quests.", "Prefix": "kqf" }, { "Name": "Course", "Enabled": true, + "Description": "Apply/remove user courses based on the name.", "Prefix": "course" }, { "Name": "PSN", "Enabled": true, + "Description": "Link a PSN account to your Erupe account.", "Prefix": "psn" } ], diff --git a/config/config.go b/config/config.go index 5a50a511b..12cb00316 100644 --- a/config/config.go +++ b/config/config.go @@ -169,9 +169,10 @@ type Discord struct { // Command is a channelserver chat command type Command struct { - Name string - Enabled bool - Prefix string + Name string + Enabled bool + Description string + Prefix string } // Course represents a course within MHF diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index 806c50749..e74728906 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -10,6 +10,7 @@ import ( "erupe-ce/network/binpacket" "erupe-ce/network/mhfpacket" "fmt" + "golang.org/x/exp/maps" "golang.org/x/exp/slices" "math" "strconv" @@ -320,7 +321,9 @@ func parseChatCommand(s *Session, command string) { } case commands["Help"].Prefix: if commands["Help"].Enabled { - sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandTeleportSuccess"], x, y)) + for _, command := range maps.Values(commands) { + sendServerChatMessage(s, fmt.Sprintf("%s: %s", command.Name, command.Description)) + } } else { sendDisabledCommandMessage(s, commands["Help"]) } From 23bc66eda508c4fe20538b8672527c4e8e88bfa6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 27 Nov 2023 04:07:44 -0500 Subject: [PATCH 3/9] fix: Consider prefix length when slicing. --- server/channelserver/handlers_cast_binary.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index e74728906..990dfb1ce 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -85,7 +85,7 @@ func sendServerChatMessage(s *Session, message string) { } func parseChatCommand(s *Session, command string) { - args := strings.Split(command[1:], " ") + args := strings.Split(command[len(s.server.erupeConfig.CommandPrefix):], " ") switch args[0] { case commands["PSN"].Prefix: if commands["PSN"].Enabled { From 88652e1dc0c7e44b300767831dd421c836940d65 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 27 Nov 2023 15:32:52 -0500 Subject: [PATCH 4/9] chore: Change command name to show the prefix instead. --- server/channelserver/handlers_cast_binary.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index ef9ee8798..10ac2fa7c 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -326,7 +326,7 @@ func parseChatCommand(s *Session, command string) { case commands["Help"].Prefix: if commands["Help"].Enabled { for _, command := range maps.Values(commands) { - sendServerChatMessage(s, fmt.Sprintf("%s: %s", command.Name, command.Description)) + sendServerChatMessage(s, fmt.Sprintf("!%s: %s", command.Prefix, command.Description)) } } else { sendDisabledCommandMessage(s, commands["Help"]) From de5c3addd19b3a4f6af89cd28b08b241200fdeee Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 27 Nov 2023 15:34:28 -0500 Subject: [PATCH 5/9] fix: Show config prefix instead of just ! --- server/channelserver/handlers_cast_binary.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index 10ac2fa7c..816ee3307 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -326,7 +326,7 @@ func parseChatCommand(s *Session, command string) { case commands["Help"].Prefix: if commands["Help"].Enabled { for _, command := range maps.Values(commands) { - sendServerChatMessage(s, fmt.Sprintf("!%s: %s", command.Prefix, command.Description)) + sendServerChatMessage(s, fmt.Sprintf("%s%s: %s", s.server.erupeConfig.CommandPrefix, command.Prefix, command.Description)) } } else { sendDisabledCommandMessage(s, commands["Help"]) From 7b7b2874c5d58ba3c6eccdb9aba7d258146fb548 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 27 Nov 2023 16:14:32 -0500 Subject: [PATCH 6/9] fix: Fixed description for reload command. --- config.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index e18506f3a..e30514bb6 100644 --- a/config.json +++ b/config.json @@ -84,8 +84,7 @@ "Enabled": true, "Description": "Show all of the commands", "Prefix": "help" - }, - { + }, { "Name": "Rights", "Enabled": false, "Description": "Directly alter user's applied courses.", @@ -103,7 +102,7 @@ }, { "Name": "Reload", "Enabled": true, - "Description": "Reload all user sessions (Forces log out)", + "Description": "Delete and recreate all players within the session.", "Prefix": "reload" }, { "Name": "KeyQuest", From 8d02c9f9071e0fa50889373e048158e3d649869d Mon Sep 17 00:00:00 2001 From: wish Date: Tue, 28 Nov 2023 23:40:47 +1100 Subject: [PATCH 7/9] remove unnecessary dependency change --- server/channelserver/handlers_cast_binary.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index 816ee3307..4d3fc639a 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -10,7 +10,6 @@ import ( "erupe-ce/network/binpacket" "erupe-ce/network/mhfpacket" "fmt" - "golang.org/x/exp/maps" "golang.org/x/exp/slices" "math" "strconv" @@ -325,7 +324,7 @@ func parseChatCommand(s *Session, command string) { } case commands["Help"].Prefix: if commands["Help"].Enabled { - for _, command := range maps.Values(commands) { + for _, command := range commands { sendServerChatMessage(s, fmt.Sprintf("%s%s: %s", s.server.erupeConfig.CommandPrefix, command.Prefix, command.Description)) } } else { From 1cd60eb5aee8ea8d7610ee9f327947a647d05600 Mon Sep 17 00:00:00 2001 From: wish Date: Tue, 28 Nov 2023 23:41:22 +1100 Subject: [PATCH 8/9] hide disabled commands --- server/channelserver/handlers_cast_binary.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index 4d3fc639a..71a8a6f07 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -325,7 +325,9 @@ func parseChatCommand(s *Session, command string) { case commands["Help"].Prefix: if commands["Help"].Enabled { for _, command := range commands { - sendServerChatMessage(s, fmt.Sprintf("%s%s: %s", s.server.erupeConfig.CommandPrefix, command.Prefix, command.Description)) + if command.Enabled { + sendServerChatMessage(s, fmt.Sprintf("%s%s: %s", s.server.erupeConfig.CommandPrefix, command.Prefix, command.Description)) + } } } else { sendDisabledCommandMessage(s, commands["Help"]) From d7b400c812c3fd1781ce38fab35a0738520daeaf Mon Sep 17 00:00:00 2001 From: wish Date: Tue, 28 Nov 2023 23:41:54 +1100 Subject: [PATCH 9/9] revise command descriptions --- config.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config.json b/config.json index e30514bb6..688a9879b 100644 --- a/config.json +++ b/config.json @@ -82,42 +82,42 @@ { "Name": "Help", "Enabled": true, - "Description": "Show all of the commands", + "Description": "Show enabled chat commands", "Prefix": "help" }, { "Name": "Rights", "Enabled": false, - "Description": "Directly alter user's applied courses.", + "Description": "Overwrite the Rights value on your account", "Prefix": "rights" }, { "Name": "Raviente", "Enabled": true, - "Description": "Start or view an ongoing raviante raid.", + "Description": "Various Raviente siege commands", "Prefix": "ravi" }, { "Name": "Teleport", "Enabled": false, - "Description": "Teleport to a specified stage.", + "Description": "Teleport to specified coordinates", "Prefix": "tele" }, { "Name": "Reload", "Enabled": true, - "Description": "Delete and recreate all players within the session.", + "Description": "Reload all players in your Land", "Prefix": "reload" }, { "Name": "KeyQuest", "Enabled": false, - "Description": "Allow the overriding of necessary key quests.", + "Description": "Overwrite your HR Key Quest progress", "Prefix": "kqf" }, { "Name": "Course", "Enabled": true, - "Description": "Apply/remove user courses based on the name.", + "Description": "Toggle Courses on your account", "Prefix": "course" }, { "Name": "PSN", "Enabled": true, - "Description": "Link a PSN account to your Erupe account.", + "Description": "Link a PlayStation Network ID to your account", "Prefix": "psn" } ],