Merge pull request #104 from matthe815/feature/custom-prefix

feat: Custom prefixes and basic help command
This commit is contained in:
Matthew
2023-11-28 15:14:58 -08:00
committed by GitHub
3 changed files with 30 additions and 5 deletions

View File

@@ -14,6 +14,7 @@
"ClientMode": "ZZ", "ClientMode": "ZZ",
"QuestCacheExpiry": 300, "QuestCacheExpiry": 300,
"ProxyPort": 0, "ProxyPort": 0,
"CommandPrefix": "!",
"DevMode": true, "DevMode": true,
"DevModeOptions": { "DevModeOptions": {
"AutoCreateAccount": true, "AutoCreateAccount": true,
@@ -79,32 +80,44 @@
}, },
"Commands": [ "Commands": [
{ {
"Name": "Help",
"Enabled": true,
"Description": "Show enabled chat commands",
"Prefix": "help"
}, {
"Name": "Rights", "Name": "Rights",
"Enabled": false, "Enabled": false,
"Description": "Overwrite the Rights value on your account",
"Prefix": "rights" "Prefix": "rights"
}, { }, {
"Name": "Raviente", "Name": "Raviente",
"Enabled": true, "Enabled": true,
"Description": "Various Raviente siege commands",
"Prefix": "ravi" "Prefix": "ravi"
}, { }, {
"Name": "Teleport", "Name": "Teleport",
"Enabled": false, "Enabled": false,
"Description": "Teleport to specified coordinates",
"Prefix": "tele" "Prefix": "tele"
}, { }, {
"Name": "Reload", "Name": "Reload",
"Enabled": true, "Enabled": true,
"Description": "Reload all players in your Land",
"Prefix": "reload" "Prefix": "reload"
}, { }, {
"Name": "KeyQuest", "Name": "KeyQuest",
"Enabled": false, "Enabled": false,
"Description": "Overwrite your HR Key Quest progress",
"Prefix": "kqf" "Prefix": "kqf"
}, { }, {
"Name": "Course", "Name": "Course",
"Enabled": true, "Enabled": true,
"Description": "Toggle Courses on your account",
"Prefix": "course" "Prefix": "course"
}, { }, {
"Name": "PSN", "Name": "PSN",
"Enabled": true, "Enabled": true,
"Description": "Link a PlayStation Network ID to your account",
"Prefix": "psn" "Prefix": "psn"
} }
], ],

View File

@@ -81,6 +81,7 @@ type Config struct {
RealClientMode Mode RealClientMode Mode
QuestCacheExpiry int // Number of seconds to keep quest data cached QuestCacheExpiry int // Number of seconds to keep quest data cached
ProxyPort uint16 // Forces the game to connect to a channel server proxy ProxyPort uint16 // Forces the game to connect to a channel server proxy
CommandPrefix string // The prefix for commands
DevMode bool DevMode bool
DevModeOptions DevModeOptions DevModeOptions DevModeOptions
@@ -168,9 +169,10 @@ type Discord struct {
// Command is a channelserver chat command // Command is a channelserver chat command
type Command struct { type Command struct {
Name string Name string
Enabled bool Enabled bool
Prefix string Description string
Prefix string
} }
// Course represents a course within MHF // Course represents a course within MHF

View File

@@ -84,7 +84,7 @@ func sendServerChatMessage(s *Session, message string) {
} }
func parseChatCommand(s *Session, command string) { func parseChatCommand(s *Session, command string) {
args := strings.Split(command[1:], " ") args := strings.Split(command[len(s.server.erupeConfig.CommandPrefix):], " ")
switch args[0] { switch args[0] {
case commands["PSN"].Prefix: case commands["PSN"].Prefix:
if commands["PSN"].Enabled { if commands["PSN"].Enabled {
@@ -322,6 +322,16 @@ func parseChatCommand(s *Session, command string) {
} else { } else {
sendDisabledCommandMessage(s, commands["Teleport"]) sendDisabledCommandMessage(s, commands["Teleport"])
} }
case commands["Help"].Prefix:
if commands["Help"].Enabled {
for _, command := range commands {
if command.Enabled {
sendServerChatMessage(s, fmt.Sprintf("%s%s: %s", s.server.erupeConfig.CommandPrefix, command.Prefix, command.Description))
}
}
} else {
sendDisabledCommandMessage(s, commands["Help"])
}
} }
} }
@@ -395,7 +405,7 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
bf.SetLE() bf.SetLE()
chatMessage := &binpacket.MsgBinChat{} chatMessage := &binpacket.MsgBinChat{}
chatMessage.Parse(bf) chatMessage.Parse(bf)
if strings.HasPrefix(chatMessage.Message, "!") { if strings.HasPrefix(chatMessage.Message, s.server.erupeConfig.CommandPrefix) {
parseChatCommand(s, chatMessage.Message) parseChatCommand(s, chatMessage.Message)
return return
} }