mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-02-06 10:06:53 +01:00
initial course command
This commit is contained in:
14
config.json
14
config.json
@@ -55,8 +55,22 @@
|
|||||||
"Name": "KeyQuest",
|
"Name": "KeyQuest",
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
"Prefix": "!kqf"
|
"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": {
|
"Database": {
|
||||||
"Host": "localhost",
|
"Host": "localhost",
|
||||||
"Port": 5432,
|
"Port": 5432,
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ type Command struct {
|
|||||||
Prefix string
|
Prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Courses is an array of enabled courses
|
||||||
|
type Courses struct {
|
||||||
|
Name string
|
||||||
|
Enabled bool
|
||||||
|
}
|
||||||
|
|
||||||
// Database holds the postgres database config.
|
// Database holds the postgres database config.
|
||||||
type Database struct {
|
type Database struct {
|
||||||
Host string
|
Host string
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type ClientRight struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Course struct {
|
type Course struct {
|
||||||
Name string
|
Aliases []string
|
||||||
ID uint16
|
ID uint16
|
||||||
Value uint32
|
Value uint32
|
||||||
}
|
}
|
||||||
@@ -74,24 +74,28 @@ func (m *MsgSysUpdateRight) Build(bf *byteframe.ByteFrame, ctx *clientctx.Client
|
|||||||
return nil
|
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
|
// GetCourseStruct returns a slice of Course(s) from a rights integer
|
||||||
func GetCourseStruct(rights uint32) []Course {
|
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
|
var resp []Course
|
||||||
for _, course := range courses {
|
for _, course := range Courses() {
|
||||||
if rights-course.Value < 0x80000000 {
|
if rights-course.Value < 0x80000000 {
|
||||||
resp = append(resp, course)
|
resp = append(resp, course)
|
||||||
rights -= course.Value
|
rights -= course.Value
|
||||||
|
|||||||
@@ -75,13 +75,11 @@ func doAckSimpleFail(s *Session, ackHandle uint32, data []byte) {
|
|||||||
func updateRights(s *Session) {
|
func updateRights(s *Session) {
|
||||||
rightsInt := uint32(0x0E)
|
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)
|
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)
|
||||||
|
s.courses = mhfpacket.GetCourseStruct(rightsInt)
|
||||||
courses := mhfpacket.GetCourseStruct(rightsInt)
|
|
||||||
rights := []mhfpacket.ClientRight{{1, 0, 0}}
|
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})
|
rights = append(rights, mhfpacket.ClientRight{ID: course.ID, Timestamp: 0x70DB59F0})
|
||||||
}
|
}
|
||||||
|
|
||||||
update := &mhfpacket.MsgSysUpdateRight{
|
update := &mhfpacket.MsgSysUpdateRight{
|
||||||
ClientRespAckHandle: 0,
|
ClientRespAckHandle: 0,
|
||||||
Bitfield: rightsInt,
|
Bitfield: rightsInt,
|
||||||
|
|||||||
@@ -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 strings.HasPrefix(chatMessage.Message, commands["Raviente"].Prefix) {
|
||||||
if commands["Raviente"].Enabled {
|
if commands["Raviente"].Enabled {
|
||||||
if getRaviSemaphore(s) != "" {
|
if getRaviSemaphore(s) != "" {
|
||||||
|
|||||||
@@ -272,9 +272,11 @@ func (s *Session) logMessage(opcode uint16, data []byte, sender string, recipien
|
|||||||
|
|
||||||
func (s *Session) CourseExists(name string) bool {
|
func (s *Session) CourseExists(name string) bool {
|
||||||
for _, course := range s.courses {
|
for _, course := range s.courses {
|
||||||
if strings.ToLower(name) == strings.ToLower(course.Name) {
|
for _, alias := range course.Aliases {
|
||||||
|
if strings.ToLower(name) == strings.ToLower(alias) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user