lockable courses via config

This commit is contained in:
wish
2022-10-30 16:43:58 +11:00
parent 8afec7a7df
commit 676bb736bf
4 changed files with 30 additions and 30 deletions

View File

@@ -21,6 +21,7 @@ type Config struct {
DevModeOptions DevModeOptions
Discord Discord
Commands []Command
Courses []Course
Database Database
Launcher Launcher
Sign Sign
@@ -70,8 +71,8 @@ type Command struct {
Prefix string
}
// Courses is an array of enabled courses
type Courses struct {
// Course represents a course within MHF
type Course struct {
Name string
Enabled bool
}

View File

@@ -213,7 +213,7 @@ func logoutPlayer(s *Session) {
timePlayed += sessionTime
var rpGained int
if s.CourseExists("Netcafe") {
if s.FindCourse("Netcafe").Value != 0 {
rpGained = timePlayed / 900
timePlayed = timePlayed % 900
} else {

View File

@@ -7,6 +7,7 @@ import (
"erupe-ce/network/binpacket"
"erupe-ce/network/mhfpacket"
"fmt"
"golang.org/x/exp/slices"
"math"
"math/rand"
"strings"
@@ -322,22 +323,26 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
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 slices.Contains(s.server.erupeConfig.Courses, config.Course{Name: course.Aliases[0], Enabled: true}) {
if s.FindCourse(name).Value != 0 {
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]))
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 {
s.courses = append(s.courses, course)
sendServerChatMessage(s, fmt.Sprintf(`%s Course enabled.`, course.Aliases[0]))
sendServerChatMessage(s, fmt.Sprintf(`%s Course is locked.`, course.Aliases[0]))
}
}
}

View File

@@ -12,12 +12,10 @@ import (
"erupe-ce/common/byteframe"
"erupe-ce/common/stringstack"
"erupe-ce/common/stringsupport"
"erupe-ce/network"
"erupe-ce/network/clientctx"
"erupe-ce/network/mhfpacket"
"go.uber.org/zap"
"golang.org/x/text/encoding/japanese"
)
type packet struct {
@@ -69,16 +67,12 @@ type Session struct {
// NewSession creates a new Session type.
func NewSession(server *Server, conn net.Conn) *Session {
s := &Session{
logger: server.logger.Named(conn.RemoteAddr().String()),
server: server,
rawConn: conn,
cryptConn: network.NewCryptConn(conn),
sendPackets: make(chan packet, 20),
clientContext: &clientctx.ClientContext{
StrConv: &stringsupport.StringConverter{
Encoding: japanese.ShiftJIS,
},
},
logger: server.logger.Named(conn.RemoteAddr().String()),
server: server,
rawConn: conn,
cryptConn: network.NewCryptConn(conn),
sendPackets: make(chan packet, 20),
clientContext: &clientctx.ClientContext{},
sessionStart: Time_Current_Adjusted().Unix(),
stageMoveStack: stringstack.New(),
}
@@ -270,13 +264,13 @@ func (s *Session) logMessage(opcode uint16, data []byte, sender string, recipien
}
}
func (s *Session) CourseExists(name string) bool {
func (s *Session) FindCourse(name string) mhfpacket.Course {
for _, course := range s.courses {
for _, alias := range course.Aliases {
if strings.ToLower(name) == strings.ToLower(alias) {
return true
return course
}
}
}
return false
return mhfpacket.Course{}
}