initial rights v4 concept

This commit is contained in:
wish
2023-03-11 23:17:14 +11:00
parent 29cf7add11
commit bcb71536ec
7 changed files with 135 additions and 129 deletions

View File

@@ -3,50 +3,17 @@ package mhfpacket
import (
"errors"
"erupe-ce/common/byteframe"
"erupe-ce/common/mhfcourse"
ps "erupe-ce/common/pascalstring"
"erupe-ce/network"
"erupe-ce/network/clientctx"
"golang.org/x/exp/slices"
"math"
)
/*
00 58 // Opcode
00 00 00 00
00 00 00 4e
00 04 // Count
00 00 // Skipped(padding?)
00 01 00 00 00 00 00 00
00 02 00 00 5d fa 14 c0
00 03 00 00 5d fa 14 c0
00 06 00 00 5d e7 05 10
00 00 // Count of some buf up to 0x800 bytes following it.
00 10 // Trailer
*/
// ClientRight represents a right that the client has.
type ClientRight struct {
ID uint16
Unk0 uint16
Timestamp uint32
}
type Course struct {
Aliases []string
ID uint16
Value uint32
}
// MsgSysUpdateRight represents the MSG_SYS_UPDATE_RIGHT
type MsgSysUpdateRight struct {
ClientRespAckHandle uint32 // If non-0, requests the client to send back a MSG_SYS_ACK packet with this value.
Bitfield uint32
Rights []ClientRight
Rights []mhfcourse.Course
UnkSize uint16 // Count of some buf up to 0x800 bytes following it.
}
@@ -68,54 +35,13 @@ func (m *MsgSysUpdateRight) Build(bf *byteframe.ByteFrame, ctx *clientctx.Client
bf.WriteUint16(0)
for _, v := range m.Rights {
bf.WriteUint16(v.ID)
bf.WriteUint16(v.Unk0)
bf.WriteUint32(v.Timestamp)
bf.WriteUint16(0)
if v.Expiry.IsZero() {
bf.WriteUint32(0)
} else {
bf.WriteUint32(uint32(v.Expiry.Unix()))
}
}
ps.Uint16(bf, "", false) // update client login token / password in the game's launcherstate struct
return nil
}
func Courses() []Course {
var courses = []Course{
{Aliases: []string{"Trial", "TL"}, ID: 1},
{Aliases: []string{"HunterLife", "HL"}, ID: 2}, // BASIC
{Aliases: []string{"Extra", "ExtraA", "EX"}, ID: 3},
{Aliases: []string{"ExtraB"}, ID: 4},
{Aliases: []string{"Mobile"}, ID: 5},
{Aliases: []string{"Premium"}, ID: 6},
{Aliases: []string{"Pallone", "ExtraC"}, ID: 7},
{Aliases: []string{"Assist", "Legend", "Rasta"}, ID: 8}, // LEGEND
{Aliases: []string{"N"}, ID: 9},
{Aliases: []string{"Hiden", "Secret"}, ID: 10}, // SECRET
{Aliases: []string{"HunterSupport", "HunterAid", "Support", "Aid", "Royal"}, ID: 11}, // ROYAL
{Aliases: []string{"NBoost", "NetCafeBoost", "Boost"}, ID: 12},
// 13-19 = (unknown), 20 = DEBUG, 21 = COG_LINK_EXPIRED, 22 = 360_GOLD, 23 = PS3_TROP
{Aliases: []string{"COG"}, ID: 24},
// 25 = CAFE_SP, active with 26 but useless on it's own? Just use OFFICIAL and set bit
{Aliases: []string{"NetCafe", "Cafe", "OfficialCafe", "Official"}, ID: 26},
{Aliases: []string{"HLRenewing", "HLR", "HLRenewal", "HLRenew"}, ID: 27}, // CARD
{Aliases: []string{"EXRenewing", "EXR", "EXRenewal", "EXRenew"}, ID: 28}, // CARD_EX
{Aliases: []string{"Free"}, ID: 29},
// 30 = NETCAFE, what actually gives you any NetCafe gameplay benefits
}
for i := range courses {
courses[i].Value = uint32(math.Pow(2, float64(courses[i].ID)))
}
return courses
}
// GetCourseStruct returns a slice of Course(s) from a rights integer
func GetCourseStruct(rights uint32) []Course {
var resp []Course
s := Courses()
slices.SortStableFunc(s, func(i, j Course) bool {
return i.ID > j.ID
})
for _, course := range s {
if rights-course.Value < 0x80000000 {
resp = append(resp, course)
rights -= course.Value
}
}
return resp
}