add Quest timer toggle Chat Command

This commit is contained in:
wish
2024-02-20 00:33:38 +11:00
parent 9cfbd92454
commit b73f85ef4a
4 changed files with 41 additions and 4 deletions

View File

@@ -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": [

View File

@@ -0,0 +1,5 @@
BEGIN;
ALTER TABLE users ADD COLUMN IF NOT EXISTS timer bool;
END;

View File

@@ -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))
}
}
}

View File

@@ -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 <id> [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!"