course enumeration concept

This commit is contained in:
wish
2022-10-30 11:44:22 +11:00
parent da1a48ee2c
commit bac4e70be4
3 changed files with 53 additions and 22 deletions

View File

@@ -6,7 +6,6 @@ import (
"erupe-ce/common/stringsupport"
"fmt"
"io"
"math"
"net"
"strings"
"time"
@@ -74,26 +73,18 @@ func doAckSimpleFail(s *Session, ackHandle uint32, data []byte) {
}
func updateRights(s *Session) {
s.rights = 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(&s.rights)
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)
rights := make([]mhfpacket.ClientRight, 0)
tempRights := s.rights
for i := 30; i > 0; i-- {
right := uint32(math.Pow(2, float64(i)))
if tempRights-right < 0x80000000 {
if i == 1 {
continue
}
rights = append(rights, mhfpacket.ClientRight{ID: uint16(i), Timestamp: 0x70DB59F0})
tempRights -= right
}
courses := mhfpacket.GetCourseStruct(rightsInt)
rights := []mhfpacket.ClientRight{{1, 0, 0}}
for _, course := range courses {
rights = append(rights, mhfpacket.ClientRight{ID: course.ID, Timestamp: 0x70DB59F0})
}
rights = append(rights, mhfpacket.ClientRight{ID: 1, Timestamp: 0})
update := &mhfpacket.MsgSysUpdateRight{
ClientRespAckHandle: 0,
Bitfield: s.rights,
Bitfield: rightsInt,
Rights: rights,
UnkSize: 0,
}
@@ -224,7 +215,7 @@ func logoutPlayer(s *Session) {
timePlayed += sessionTime
var rpGained int
if s.rights >= 0x40000000 { // N Course
if s.CourseExists("Netcafe") {
rpGained = timePlayed / 900
timePlayed = timePlayed % 900
} else {

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net"
"strings"
"sync"
"time"
@@ -43,7 +44,7 @@ type Session struct {
charID uint32
logKey []byte
sessionStart int64
rights uint32
courses []mhfpacket.Course
token string
kqf []byte
kqfOverride bool
@@ -268,3 +269,12 @@ func (s *Session) logMessage(opcode uint16, data []byte, sender string, recipien
fmt.Printf("Data [%d bytes]:\n(Too long!)\n\n", len(data))
}
}
func (s *Session) CourseExists(name string) bool {
for _, course := range s.courses {
if strings.ToLower(name) == strings.ToLower(course.Name) {
return true
}
}
return false
}