initial course command

This commit is contained in:
wish
2022-10-30 15:03:12 +11:00
parent bac4e70be4
commit 31bac7bd68
6 changed files with 85 additions and 24 deletions

View File

@@ -55,8 +55,22 @@
"Name": "KeyQuest",
"Enabled": false,
"Prefix": "!kqf"
}, {
"Name": "Course",
"Enabled": true,
"Prefix": "!course"
}
],
"Courses": [
{"Name": "HunterLife", "Enabled": true},
{"Name": "ExtraA", "Enabled": true},
{"Name": "Premium", "Enabled": true},
{"Name": "Assist", "Enabled": true},
{"Name": "Netcafe", "Enabled": true},
{"Name": "Hiden", "Enabled": true},
{"Name": "HunterSupport", "Enabled": true},
{"Name": "NetcafeBoost", "Enabled": true}
],
"Database": {
"Host": "localhost",
"Port": 5432,

View File

@@ -70,6 +70,12 @@ type Command struct {
Prefix string
}
// Courses is an array of enabled courses
type Courses struct {
Name string
Enabled bool
}
// Database holds the postgres database config.
type Database struct {
Host string

View File

@@ -36,9 +36,9 @@ type ClientRight struct {
}
type Course struct {
Name string
ID uint16
Value uint32
Aliases []string
ID uint16
Value uint32
}
// MsgSysUpdateRight represents the MSG_SYS_UPDATE_RIGHT
@@ -74,24 +74,28 @@ func (m *MsgSysUpdateRight) Build(bf *byteframe.ByteFrame, ctx *clientctx.Client
return nil
}
func Courses() []Course {
var courses = []Course{
{[]string{"Trial", "TL"}, 1, 0x00000002},
{[]string{"HunterLife", "HL"}, 2, 0x00000004},
{[]string{"ExtraA", "Extra", "EX"}, 3, 0x00000008},
{[]string{"ExtraB"}, 4, 0x00000010},
{[]string{"Mobile"}, 5, 0x00000020},
{[]string{"Premium"}, 6, 0x00000040},
{[]string{"Pallone"}, 7, 0x00000080},
{[]string{"Assist", "Legend", "Rasta"}, 8, 0x00000100}, // Legend
{[]string{"Netcafe", "N", "Cafe"}, 9, 0x00000200},
{[]string{"Hiden", "Secret"}, 10, 0x00000400}, // Secret
{[]string{"HunterSupport", "HunterAid", "Support", "Royal", "Aid"}, 11, 0x00000800}, // Royal
{[]string{"NetcafeBoost", "NBoost", "Boost"}, 12, 0x00001000},
}
return courses
}
// GetCourseStruct returns a slice of Course(s) from a rights integer
func GetCourseStruct(rights uint32) []Course {
var courses = []Course{
{"Trial", 1, 0x00000002},
{"HunterLife", 2, 0x00000004},
{"ExtraA", 3, 0x00000008},
{"ExtraB", 4, 0x00000010},
{"Mobile", 5, 0x00000020},
{"Premium", 6, 0x00000040},
{"Pallone", 7, 0x00000080},
{"Assist", 8, 0x00000100}, // Legend
{"Netcafe", 9, 0x00000200},
{"Hiden", 10, 0x00000400}, // Secret
{"HunterSupport", 11, 0x00000800}, // Royal
{"NetcafeBoost", 12, 0x00001000},
}
var resp []Course
for _, course := range courses {
for _, course := range Courses() {
if rights-course.Value < 0x80000000 {
resp = append(resp, course)
rights -= course.Value

View File

@@ -75,13 +75,11 @@ func doAckSimpleFail(s *Session, ackHandle uint32, data []byte) {
func updateRights(s *Session) {
rightsInt := uint32(0x0E)
s.server.db.QueryRow("SELECT rights FROM users u INNER JOIN characters c ON u.id = c.user_id WHERE c.id = $1", s.charID).Scan(&rightsInt)
courses := mhfpacket.GetCourseStruct(rightsInt)
s.courses = mhfpacket.GetCourseStruct(rightsInt)
rights := []mhfpacket.ClientRight{{1, 0, 0}}
for _, course := range courses {
for _, course := range s.courses {
rights = append(rights, mhfpacket.ClientRight{ID: course.ID, Timestamp: 0x70DB59F0})
}
update := &mhfpacket.MsgSysUpdateRight{
ClientRespAckHandle: 0,
Bitfield: rightsInt,

View File

@@ -311,6 +311,43 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
}
}
if strings.HasPrefix(chatMessage.Message, commands["Course"].Prefix) {
if commands["Course"].Enabled {
var name string
n, err := fmt.Sscanf(chatMessage.Message, "!course %s", &name)
if err != nil || n != 1 {
sendServerChatMessage(s, "Error in command. Format: !course <name>")
} else {
name = strings.ToLower(name)
for _, course := range mhfpacket.Courses() {
for _, alias := range course.Aliases {
if strings.ToLower(name) == strings.ToLower(alias) {
if s.CourseExists(name) {
existingIndex := -1
for i, course := range s.courses {
for _, alias := range course.Aliases {
if strings.ToLower(name) == strings.ToLower(alias) {
existingIndex = i
}
}
}
if existingIndex >= 0 {
s.courses = append(s.courses[:existingIndex], s.courses[existingIndex+1:]...)
sendServerChatMessage(s, fmt.Sprintf(`%s Course disabled.`, course.Aliases[0]))
}
} else {
s.courses = append(s.courses, course)
sendServerChatMessage(s, fmt.Sprintf(`%s Course enabled.`, course.Aliases[0]))
}
}
}
}
}
} else {
sendDisabledCommandMessage(s, commands["Course"])
}
}
if strings.HasPrefix(chatMessage.Message, commands["Raviente"].Prefix) {
if commands["Raviente"].Enabled {
if getRaviSemaphore(s) != "" {

View File

@@ -272,8 +272,10 @@ func (s *Session) logMessage(opcode uint16, data []byte, sender string, recipien
func (s *Session) CourseExists(name string) bool {
for _, course := range s.courses {
if strings.ToLower(name) == strings.ToLower(course.Name) {
return true
for _, alias := range course.Aliases {
if strings.ToLower(name) == strings.ToLower(alias) {
return true
}
}
}
return false