From b73f85ef4a346b46d16759c7ca8ec163cd523f2e Mon Sep 17 00:00:00 2001 From: wish Date: Tue, 20 Feb 2024 00:33:38 +1100 Subject: [PATCH] add Quest timer toggle Chat Command --- config.json | 5 ++++ schemas/patch-schema/timer-toggle.sql | 5 ++++ server/channelserver/handlers_cast_binary.go | 25 ++++++++++++++++---- server/channelserver/sys_language.go | 10 ++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 schemas/patch-schema/timer-toggle.sql diff --git a/config.json b/config.json index c8705a661..48e166824 100644 --- a/config.json +++ b/config.json @@ -157,6 +157,11 @@ "Enabled": false, "Description": "Ban/Temp Ban a user", "Prefix": "ban" + }, { + "Name": "Timer", + "Enabled": true, + "Description": "Toggle the Quest timer", + "Prefix": "timer" } ], "Courses": [ diff --git a/schemas/patch-schema/timer-toggle.sql b/schemas/patch-schema/timer-toggle.sql new file mode 100644 index 000000000..c2bff008f --- /dev/null +++ b/schemas/patch-schema/timer-toggle.sql @@ -0,0 +1,5 @@ +BEGIN; + +ALTER TABLE users ADD COLUMN IF NOT EXISTS timer bool; + +END; \ No newline at end of file diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index c219e8a42..67e6e3a3a 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -144,6 +144,19 @@ func parseChatCommand(s *Session, command string) { } else { sendServerChatMessage(s, s.server.i18n.commands.noOp) } + case commands["Timer"].Prefix: + if commands["Timer"].Enabled || s.isOp() { + var state bool + s.server.db.QueryRow(`SELECT COALESCE(timer, false) FROM users u WHERE u.id=(SELECT c.user_id FROM characters c WHERE c.id=$1)`, s.charID).Scan(&state) + s.server.db.Exec(`UPDATE users u SET timer=$1 WHERE u.id=(SELECT c.user_id FROM characters c WHERE c.id=$2)`, !state, s.charID) + if state { + sendServerChatMessage(s, s.server.i18n.commands.timer.disabled) + } else { + sendServerChatMessage(s, s.server.i18n.commands.timer.enabled) + } + } else { + sendDisabledCommandMessage(s, commands["Timer"]) + } case commands["PSN"].Prefix: if commands["PSN"].Enabled || s.isOp() { if len(args) > 1 { @@ -413,10 +426,14 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) { if pkt.BroadcastType == 0x03 && pkt.MessageType == 0x03 && len(pkt.RawDataPayload) == 0x10 { if tmp.ReadUint16() == 0x0002 && tmp.ReadUint8() == 0x18 { - _ = tmp.ReadBytes(9) - tmp.SetLE() - frame := tmp.ReadUint32() - sendServerChatMessage(s, fmt.Sprintf("TIME : %d'%d.%03d (%dframe)", frame/30/60, frame/30%60, int(math.Round(float64(frame%30*100)/3)), frame)) + var timer bool + s.server.db.QueryRow(`SELECT COALESCE(timer, false) FROM users u WHERE u.id=(SELECT c.user_id FROM characters c WHERE c.id=$1)`, s.charID).Scan(&timer) + if timer { + _ = tmp.ReadBytes(9) + tmp.SetLE() + frame := tmp.ReadUint32() + sendServerChatMessage(s, fmt.Sprintf(s.server.i18n.timer, frame/30/60/60, frame/30/60, frame/30%60, int(math.Round(float64(frame%30*100)/3)), frame)) + } } } diff --git a/server/channelserver/sys_language.go b/server/channelserver/sys_language.go index eae96dc85..aae8706bb 100644 --- a/server/channelserver/sys_language.go +++ b/server/channelserver/sys_language.go @@ -5,6 +5,7 @@ type i18n struct { cafe struct { reset string } + timer string commands struct { noOp string disabled string @@ -46,6 +47,10 @@ type i18n struct { error string length string } + timer struct { + enabled string + disabled string + } ravi struct { noCommand string start struct { @@ -102,6 +107,7 @@ func getLangStrings(s *Server) i18n { case "jp": i.language = "日本語" i.cafe.reset = "%d/%dにリセット" + i.timer = "タイマー:%02d'%02d\"%02d.%03d (%df)" i.commands.noOp = "You don't have permission to use this command" i.commands.disabled = "%sのコマンドは無効です" @@ -164,6 +170,7 @@ func getLangStrings(s *Server) i18n { default: i.language = "English" i.cafe.reset = "Resets on %d/%d" + i.timer = "Time: %02d:%02d:%02d.%03d (%df)" i.commands.noOp = "You don't have permission to use this command" i.commands.disabled = "%s command is disabled" @@ -192,6 +199,9 @@ func getLangStrings(s *Server) i18n { i.commands.ban.error = "Error in command. Format: %s [length]" i.commands.ban.length = " until %s" + i.commands.timer.enabled = "Quest timer enabled" + i.commands.timer.disabled = "Quest timer disabled" + i.commands.ravi.noCommand = "No Raviente command specified!" i.commands.ravi.start.success = "The Great Slaying will begin in a moment" i.commands.ravi.start.error = "The Great Slaying has already begun!"