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

View File

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

View File

@@ -7,6 +7,7 @@ import (
"erupe-ce/network/binpacket" "erupe-ce/network/binpacket"
"erupe-ce/network/mhfpacket" "erupe-ce/network/mhfpacket"
"fmt" "fmt"
"golang.org/x/exp/slices"
"math" "math"
"math/rand" "math/rand"
"strings" "strings"
@@ -322,7 +323,8 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
for _, course := range mhfpacket.Courses() { for _, course := range mhfpacket.Courses() {
for _, alias := range course.Aliases { for _, alias := range course.Aliases {
if strings.ToLower(name) == strings.ToLower(alias) { if strings.ToLower(name) == strings.ToLower(alias) {
if s.CourseExists(name) { if slices.Contains(s.server.erupeConfig.Courses, config.Course{Name: course.Aliases[0], Enabled: true}) {
if s.FindCourse(name).Value != 0 {
existingIndex := -1 existingIndex := -1
for i, course := range s.courses { for i, course := range s.courses {
for _, alias := range course.Aliases { for _, alias := range course.Aliases {
@@ -339,6 +341,9 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
s.courses = append(s.courses, course) s.courses = append(s.courses, course)
sendServerChatMessage(s, fmt.Sprintf(`%s Course enabled.`, course.Aliases[0])) sendServerChatMessage(s, fmt.Sprintf(`%s Course enabled.`, course.Aliases[0]))
} }
} else {
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/byteframe"
"erupe-ce/common/stringstack" "erupe-ce/common/stringstack"
"erupe-ce/common/stringsupport"
"erupe-ce/network" "erupe-ce/network"
"erupe-ce/network/clientctx" "erupe-ce/network/clientctx"
"erupe-ce/network/mhfpacket" "erupe-ce/network/mhfpacket"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/text/encoding/japanese"
) )
type packet struct { type packet struct {
@@ -74,11 +72,7 @@ func NewSession(server *Server, conn net.Conn) *Session {
rawConn: conn, rawConn: conn,
cryptConn: network.NewCryptConn(conn), cryptConn: network.NewCryptConn(conn),
sendPackets: make(chan packet, 20), sendPackets: make(chan packet, 20),
clientContext: &clientctx.ClientContext{ clientContext: &clientctx.ClientContext{},
StrConv: &stringsupport.StringConverter{
Encoding: japanese.ShiftJIS,
},
},
sessionStart: Time_Current_Adjusted().Unix(), sessionStart: Time_Current_Adjusted().Unix(),
stageMoveStack: stringstack.New(), 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 _, course := range s.courses {
for _, alias := range course.Aliases { for _, alias := range course.Aliases {
if strings.ToLower(name) == strings.ToLower(alias) { if strings.ToLower(name) == strings.ToLower(alias) {
return true return course
} }
} }
} }
return false return mhfpacket.Course{}
} }