mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-02-04 09:15:08 +01:00
lockable courses via config
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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,22 +323,26 @@ 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}) {
|
||||||
existingIndex := -1
|
if s.FindCourse(name).Value != 0 {
|
||||||
for i, course := range s.courses {
|
existingIndex := -1
|
||||||
for _, alias := range course.Aliases {
|
for i, course := range s.courses {
|
||||||
if strings.ToLower(name) == strings.ToLower(alias) {
|
for _, alias := range course.Aliases {
|
||||||
existingIndex = i
|
if strings.ToLower(name) == strings.ToLower(alias) {
|
||||||
|
existingIndex = i
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if existingIndex >= 0 {
|
||||||
if existingIndex >= 0 {
|
s.courses = append(s.courses[:existingIndex], s.courses[existingIndex+1:]...)
|
||||||
s.courses = append(s.courses[:existingIndex], s.courses[existingIndex+1:]...)
|
sendServerChatMessage(s, fmt.Sprintf(`%s Course disabled.`, course.Aliases[0]))
|
||||||
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 {
|
} else {
|
||||||
s.courses = append(s.courses, course)
|
sendServerChatMessage(s, fmt.Sprintf(`%s Course is locked.`, course.Aliases[0]))
|
||||||
sendServerChatMessage(s, fmt.Sprintf(`%s Course enabled.`, course.Aliases[0]))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -69,16 +67,12 @@ type Session struct {
|
|||||||
// NewSession creates a new Session type.
|
// NewSession creates a new Session type.
|
||||||
func NewSession(server *Server, conn net.Conn) *Session {
|
func NewSession(server *Server, conn net.Conn) *Session {
|
||||||
s := &Session{
|
s := &Session{
|
||||||
logger: server.logger.Named(conn.RemoteAddr().String()),
|
logger: server.logger.Named(conn.RemoteAddr().String()),
|
||||||
server: server,
|
server: server,
|
||||||
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{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user