Merge remote-tracking branch 'origin/main' into fix/chat-commands-args

# Conflicts:
#	server/channelserver/handlers_cast_binary.go
This commit is contained in:
wish
2023-08-29 22:41:59 +10:00
48 changed files with 3597 additions and 687 deletions

View File

@@ -111,7 +111,12 @@ func handleMsgSysTerminalLog(s *Session, p mhfpacket.MHFPacket) {
s.server.logger.Info("SysTerminalLog",
zap.Uint8("Type1", pkt.Entries[i].Type1),
zap.Uint8("Type2", pkt.Entries[i].Type2),
zap.Int16s("Data", pkt.Entries[i].Data))
zap.Int16("Unk0", pkt.Entries[i].Unk0),
zap.Int32("Unk1", pkt.Entries[i].Unk1),
zap.Int32("Unk2", pkt.Entries[i].Unk2),
zap.Int32("Unk3", pkt.Entries[i].Unk3),
zap.Int32s("Unk4", pkt.Entries[i].Unk4),
)
}
resp := byteframe.NewByteFrame()
resp.WriteUint32(pkt.LogID + 1) // LogID to use for requests after this.
@@ -177,6 +182,7 @@ func logoutPlayer(s *Session) {
delete(s.server.sessions, s.rawConn)
}
s.rawConn.Close()
delete(s.server.objectIDs, s)
s.server.Unlock()
for _, stage := range s.server.stages {
@@ -266,13 +272,12 @@ func handleMsgSysPing(s *Session, p mhfpacket.MHFPacket) {
}
func handleMsgSysTime(s *Session, p mhfpacket.MHFPacket) {
//pkt := p.(*mhfpacket.MsgSysTime)
resp := &mhfpacket.MsgSysTime{
GetRemoteTime: false,
Timestamp: uint32(TimeAdjusted().Unix()), // JP timezone
}
s.QueueSendMHF(resp)
s.notifyRavi()
}
func handleMsgSysIssueLogkey(s *Session, p mhfpacket.MHFPacket) {
@@ -1691,7 +1696,14 @@ func handleMsgMhfGetEarthValue(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfDebugPostValue(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfGetRandFromTable(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfGetRandFromTable(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetRandFromTable)
bf := byteframe.NewByteFrame()
for i := uint16(0); i < pkt.Results; i++ {
bf.WriteUint32(0)
}
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}
func handleMsgMhfGetSenyuDailyCount(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetSenyuDailyCount)
@@ -1847,61 +1859,49 @@ func handleMsgMhfGetDailyMissionPersonal(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfSetDailyMissionPersonal(s *Session, p mhfpacket.MHFPacket) {}
func equipSkinHistSize() int {
size := 3200
if _config.ErupeConfig.RealClientMode <= _config.Z2 {
size = 2560
}
if _config.ErupeConfig.RealClientMode <= _config.Z1 {
size = 1280
}
return size
}
func handleMsgMhfGetEquipSkinHist(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetEquipSkinHist)
// Transmog / reskin system, bitmask of 3200 bytes length
// presumably divided by 5 sections for 5120 armour IDs covered
// +10,000 for actual ID to be unlocked by each bit
// Returning 3200 bytes of FF just unlocks everything for now
size := equipSkinHistSize()
var data []byte
err := s.server.db.QueryRow("SELECT COALESCE(skin_hist::bytea, $2::bytea) FROM characters WHERE id = $1", s.charID, make([]byte, 0xC80)).Scan(&data)
err := s.server.db.QueryRow("SELECT COALESCE(skin_hist::bytea, $2::bytea) FROM characters WHERE id = $1", s.charID, make([]byte, size)).Scan(&data)
if err != nil {
s.logger.Error("Failed to load skin_hist", zap.Error(err))
data = make([]byte, 3200)
data = make([]byte, size)
}
doAckBufSucceed(s, pkt.AckHandle, data)
}
func handleMsgMhfUpdateEquipSkinHist(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfUpdateEquipSkinHist)
// sends a raw armour ID back that needs to be mapped into the persistent bitmask above (-10,000)
size := equipSkinHistSize()
var data []byte
err := s.server.db.QueryRow("SELECT COALESCE(skin_hist, $2) FROM characters WHERE id = $1", s.charID, make([]byte, 0xC80)).Scan(&data)
err := s.server.db.QueryRow("SELECT COALESCE(skin_hist, $2) FROM characters WHERE id = $1", s.charID, make([]byte, size)).Scan(&data)
if err != nil {
s.logger.Error("Failed to save skin_hist", zap.Error(err))
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
s.logger.Error("Failed to get skin_hist", zap.Error(err))
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
return
}
var bit int
var startByte int
switch pkt.MogType {
case 0: // legs
bit = int(pkt.ArmourID) - 10000
startByte = 0
case 1:
bit = int(pkt.ArmourID) - 10000
startByte = 640
case 2:
bit = int(pkt.ArmourID) - 10000
startByte = 1280
case 3:
bit = int(pkt.ArmourID) - 10000
startByte = 1920
case 4:
bit = int(pkt.ArmourID) - 10000
startByte = 2560
}
bit := int(pkt.ArmourID) - 10000
startByte := (size / 5) * int(pkt.MogType)
// psql set_bit could also work but I couldn't get it working
byteInd := (bit / 8)
byteInd := bit / 8
bitInByte := bit % 8
data[startByte+byteInd] |= bits.Reverse8((1 << uint(bitInByte)))
data[startByte+byteInd] |= bits.Reverse8(1 << uint(bitInByte))
dumpSaveData(s, data, "skinhist")
_, err = s.server.db.Exec("UPDATE characters SET skin_hist=$1 WHERE id=$2", data, s.charID)
if err != nil {
panic(err)
}
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
s.server.db.Exec("UPDATE characters SET skin_hist=$1 WHERE id=$2", data, s.charID)
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}
func handleMsgMhfGetUdShopCoin(s *Session, p mhfpacket.MHFPacket) {
@@ -1945,20 +1945,45 @@ func handleMsgMhfGetLobbyCrowd(s *Session, p mhfpacket.MHFPacket) {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 0x320))
}
type TrendWeapon struct {
WeaponType uint8
WeaponID uint16
}
func handleMsgMhfGetTrendWeapon(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetTrendWeapon)
// TODO (Fist): Work out actual format limitations, seems to be final upgrade
// for weapons and it traverses its upgrade tree to recommend base as final
// 423C correlates with most popular magnet spike in use on JP
// 2A 00 3C 44 00 3C 76 00 3F EA 01 0F 20 01 0F 50 01 0F F8 02 3C 7E 02 3D
// F3 02 40 2A 03 3D 65 03 3F 2A 03 40 36 04 3D 59 04 41 E7 04 43 3E 05 0A
// ED 05 0F 4C 05 0F F2 06 3A FE 06 41 E8 06 41 FA 07 3B 02 07 3F ED 07 40
// 24 08 3D 37 08 3F 66 08 41 EC 09 3D 38 09 3F 8A 09 41 EE 0A 0E 78 0A 0F
// AA 0A 0F F9 0B 3E 2E 0B 41 EF 0B 42 FB 0C 41 F0 0C 43 3F 0C 43 EE 0D 41 F1 0D 42 10 0D 42 3C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 0xA9))
trendWeapons := [14][3]TrendWeapon{}
for i := uint8(0); i < 14; i++ {
rows, err := s.server.db.Query(`SELECT weapon_id FROM trend_weapons WHERE weapon_type=$1 ORDER BY count DESC LIMIT 3`, i)
if err != nil {
continue
}
j := 0
for rows.Next() {
trendWeapons[i][j].WeaponType = i
rows.Scan(&trendWeapons[i][j].WeaponID)
j++
}
}
x := uint8(0)
bf := byteframe.NewByteFrame()
bf.WriteUint8(0)
for _, weaponType := range trendWeapons {
for _, weapon := range weaponType {
bf.WriteUint8(weapon.WeaponType)
bf.WriteUint16(weapon.WeaponID)
x++
}
}
bf.Seek(0, 0)
bf.WriteUint8(x)
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}
func handleMsgMhfUpdateUseTrendWeaponLog(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfUpdateUseTrendWeaponLog)
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
s.server.db.Exec(`INSERT INTO trend_weapons (weapon_id, weapon_type, count) VALUES ($1, $2, 1) ON CONFLICT (weapon_id) DO
UPDATE SET count = trend_weapons.count+1`, pkt.WeaponID, pkt.WeaponType)
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}

View File

@@ -4,6 +4,7 @@ import (
"erupe-ce/common/byteframe"
ps "erupe-ce/common/pascalstring"
"erupe-ce/common/stringsupport"
_config "erupe-ce/config"
"erupe-ce/network/mhfpacket"
"time"
)
@@ -67,8 +68,10 @@ func handleMsgMhfEnumerateCampaign(s *Session, p mhfpacket.MHFPacket) {
bf.WriteInt16(event.MaxHR)
bf.WriteInt16(event.MinSR)
bf.WriteInt16(event.MaxSR)
bf.WriteInt16(event.MinGR)
bf.WriteInt16(event.MaxGR)
if _config.ErupeConfig.RealClientMode >= _config.G3 {
bf.WriteInt16(event.MinGR)
bf.WriteInt16(event.MaxGR)
}
bf.WriteUint16(event.Unk1)
bf.WriteUint8(event.Unk2)
bf.WriteUint8(event.Unk3)

View File

@@ -88,9 +88,15 @@ func parseChatCommand(s *Session, command string) {
case commands["PSN"].Prefix:
if commands["PSN"].Enabled {
if len(args) > 1 {
_, err := s.server.db.Exec(`UPDATE users u SET psn_id=$1 WHERE u.id=(SELECT c.user_id FROM characters c WHERE c.id=$2)`, args[1], s.charID)
if err == nil {
sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandPSNSuccess"], args[1]))
var exists int
s.server.db.QueryRow(`SELECT count(*) FROM users WHERE psn_id = $1`, id).Scan(&exists)
if exists == 0 {
_, err := s.server.db.Exec(`UPDATE users u SET psn_id=$1 WHERE u.id=(SELECT c.user_id FROM characters c WHERE c.id=$2)`, args[1], s.charID)
if err == nil {
sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandPSNSuccess"], args[1]))
}
} else {
sendServerChatMessage(s, s.server.dict["commandPSNExists"])
}
} else {
sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandPSNError"], commands["PSN"].Prefix))

View File

@@ -239,19 +239,19 @@ func dumpSaveData(s *Session, data []byte, suffix string) {
_, err := os.Stat(dir)
if err != nil {
if os.IsNotExist(err) {
err = os.Mkdir(dir, os.ModePerm)
err = os.MkdirAll(dir, os.ModePerm)
if err != nil {
s.logger.Warn("Error dumping savedata, could not create folder")
s.logger.Error("Error dumping savedata, could not create folder")
return
}
} else {
s.logger.Warn("Error dumping savedata")
s.logger.Error("Error dumping savedata")
return
}
}
err = os.WriteFile(path, data, 0644)
if err != nil {
s.logger.Warn("Error dumping savedata, could not write file", zap.Error(err))
s.logger.Error("Error dumping savedata, could not write file", zap.Error(err))
}
}
}

View File

@@ -4,6 +4,7 @@ import (
"erupe-ce/common/byteframe"
ps "erupe-ce/common/pascalstring"
"erupe-ce/network/mhfpacket"
"go.uber.org/zap"
)

View File

@@ -49,14 +49,14 @@ func handleMsgMhfReleaseEvent(s *Session, p mhfpacket.MHFPacket) {
}
type Event struct {
Unk0 uint16
Unk1 uint16
Unk2 uint16
Unk3 uint16
Unk4 uint16
Unk5 uint32
Unk6 uint32
Unk7 []uint16
EventType uint16
Unk1 uint16
Unk2 uint16
Unk3 uint16
Unk4 uint16
Unk5 uint32
Unk6 uint32
QuestFileIDs []uint16
}
func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) {
@@ -67,17 +67,17 @@ func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) {
bf.WriteUint8(uint8(len(events)))
for _, event := range events {
bf.WriteUint16(event.Unk0)
bf.WriteUint16(event.EventType)
bf.WriteUint16(event.Unk1)
bf.WriteUint16(event.Unk2)
bf.WriteUint16(event.Unk3)
bf.WriteUint16(event.Unk4)
bf.WriteUint32(event.Unk5)
bf.WriteUint32(event.Unk6)
if event.Unk0 == 2 {
bf.WriteUint8(uint8(len(event.Unk7)))
for _, u := range event.Unk7 {
bf.WriteUint16(u)
if event.EventType == 2 {
bf.WriteUint8(uint8(len(event.QuestFileIDs)))
for _, qf := range event.QuestFileIDs {
bf.WriteUint16(qf)
}
}
}
@@ -123,24 +123,24 @@ func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) {
}
func generateFeatureWeapons(count int) activeFeature {
max := 14
_max := 14
if _config.ErupeConfig.RealClientMode < _config.ZZ {
max = 13
_max = 13
}
if _config.ErupeConfig.RealClientMode < _config.G10 {
max = 12
_max = 12
}
if _config.ErupeConfig.RealClientMode < _config.GG {
max = 11
_max = 11
}
if count > max {
count = max
if count > _max {
count = _max
}
nums := make([]int, 0)
var result int
for len(nums) < count {
rng := token.RNG()
num := rng.Intn(max)
num := rng.Intn(_max)
exist := false
for _, v := range nums {
if v == num {

View File

@@ -4,6 +4,7 @@ import (
"erupe-ce/common/byteframe"
ps "erupe-ce/common/pascalstring"
"erupe-ce/common/token"
_config "erupe-ce/config"
"erupe-ce/network/mhfpacket"
"sort"
"time"
@@ -265,7 +266,14 @@ func handleMsgMhfInfoFesta(s *Session, p mhfpacket.MHFPacket) {
bf.WriteUint8(reward.Unk7)
}
bf.WriteUint32(s.server.erupeConfig.GameplayOptions.MaximumFP)
if _config.ErupeConfig.RealClientMode <= _config.G61 {
if s.server.erupeConfig.GameplayOptions.MaximumFP > 0xFFFF {
s.server.erupeConfig.GameplayOptions.MaximumFP = 0xFFFF
}
bf.WriteUint16(uint16(s.server.erupeConfig.GameplayOptions.MaximumFP))
} else {
bf.WriteUint32(s.server.erupeConfig.GameplayOptions.MaximumFP)
}
bf.WriteUint16(500)
categoryWinners := uint16(0) // NYI

View File

@@ -10,25 +10,9 @@ import (
func handleMsgSysCreateObject(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgSysCreateObject)
// Prevent reusing an object index
var nextID uint32
for {
exists := false
nextID = s.stage.NextObjectID()
for _, object := range s.stage.objects {
if object.id == nextID {
exists = true
break
}
}
if exists == false {
break
}
}
s.stage.Lock()
newObj := &Object{
id: nextID,
id: s.NextObjectID(),
ownerCharID: s.charID,
x: pkt.X,
y: pkt.Y,

View File

@@ -1,14 +1,19 @@
package channelserver
import (
"database/sql"
"erupe-ce/common/byteframe"
"erupe-ce/common/decryption"
ps "erupe-ce/common/pascalstring"
_config "erupe-ce/config"
"erupe-ce/network/mhfpacket"
"fmt"
"go.uber.org/zap"
"io"
"os"
"path/filepath"
"time"
"go.uber.org/zap"
)
func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
@@ -35,29 +40,47 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
}
doAckBufSucceed(s, pkt.AckHandle, data)
} else {
if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, "quest_override.bin")); err == nil {
data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, "quest_override.bin"))
if err != nil {
panic(err)
}
doAckBufSucceed(s, pkt.AckHandle, data)
} else {
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
s.logger.Debug(
"Quest",
zap.String("Filename", pkt.Filename),
)
}
// Get quest file.
data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename)))
if err != nil {
s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename))
// This will crash the game.
doAckBufSucceed(s, pkt.AckHandle, data)
return
}
doAckBufSucceed(s, pkt.AckHandle, data)
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
s.logger.Debug(
"Quest",
zap.String("Filename", pkt.Filename),
)
}
if s.server.erupeConfig.GameplayOptions.SeasonOverride {
pkt.Filename = seasonConversion(s, pkt.Filename)
}
data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename)))
if err != nil {
s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename))
// This will crash the game.
doAckBufSucceed(s, pkt.AckHandle, data)
return
}
doAckBufSucceed(s, pkt.AckHandle, data)
}
}
func questSuffix(s *Session) string {
// Determine the letter to append for day / night
var timeSet string
if TimeGameAbsolute() > 2880 {
timeSet = "d"
} else {
timeSet = "n"
}
return fmt.Sprintf("%s%d", timeSet, s.server.Season())
}
func seasonConversion(s *Session, questFile string) string {
filename := fmt.Sprintf("%s%s", questFile[:5], questSuffix(s))
// Return original file if file doesn't exist
if _, err := os.Stat(filename); err == nil {
return filename
} else {
return questFile
}
}
@@ -79,34 +102,125 @@ func handleMsgMhfSaveFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
}
func loadQuestFile(s *Session, questId int) []byte {
file, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%05dd0.bin", questId)))
if err != nil {
return nil
}
decrypted := decryption.UnpackSimple(file)
fileBytes := byteframe.NewByteFrameFromBytes(decrypted)
fileBytes.SetLE()
fileBytes.Seek(int64(fileBytes.ReadUint32()), 0)
// The 320 bytes directly following the data pointer must go directly into the event's body, after the header and before the string pointers.
questBody := byteframe.NewByteFrameFromBytes(fileBytes.ReadBytes(320))
questBody.SetLE()
// Find the master quest string pointer
questBody.Seek(40, 0)
fileBytes.Seek(int64(questBody.ReadUint32()), 0)
questBody.Seek(40, 0)
// Overwrite it
questBody.WriteUint32(320)
questBody.Seek(0, 2)
// Rewrite the quest strings and their pointers
var tempString []byte
newStrings := byteframe.NewByteFrame()
tempPointer := 352
for i := 0; i < 8; i++ {
questBody.WriteUint32(uint32(tempPointer))
temp := int64(fileBytes.Index())
fileBytes.Seek(int64(fileBytes.ReadUint32()), 0)
tempString = fileBytes.ReadNullTerminatedBytes()
fileBytes.Seek(temp+4, 0)
tempPointer += len(tempString) + 1
newStrings.WriteNullTerminatedBytes(tempString)
}
questBody.WriteBytes(newStrings.Data())
return questBody.Data()
}
func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
var id, mark uint32
var questId int
var maxPlayers, questType uint8
rows.Scan(&id, &maxPlayers, &questType, &questId, &mark)
data := loadQuestFile(s, questId)
if data == nil {
return nil, fmt.Errorf("failed to load quest file")
}
bf := byteframe.NewByteFrame()
bf.WriteUint32(id)
bf.WriteUint32(0)
bf.WriteUint8(0) // Indexer
switch questType {
case 16:
bf.WriteUint8(s.server.erupeConfig.GameplayOptions.RegularRavienteMaxPlayers)
case 22:
bf.WriteUint8(s.server.erupeConfig.GameplayOptions.ViolentRavienteMaxPlayers)
case 40:
bf.WriteUint8(s.server.erupeConfig.GameplayOptions.BerserkRavienteMaxPlayers)
case 50:
bf.WriteUint8(s.server.erupeConfig.GameplayOptions.ExtremeRavienteMaxPlayers)
case 51:
bf.WriteUint8(s.server.erupeConfig.GameplayOptions.SmallBerserkRavienteMaxPlayers)
default:
bf.WriteUint8(maxPlayers)
}
bf.WriteUint8(questType)
if questType == 9 {
bf.WriteBool(false)
} else {
bf.WriteBool(true)
}
bf.WriteUint16(0)
if _config.ErupeConfig.RealClientMode >= _config.G1 {
bf.WriteUint32(mark)
}
bf.WriteUint16(0)
bf.WriteUint16(uint16(len(data)))
bf.WriteBytes(data)
ps.Uint8(bf, "", true) // What is this string for?
return bf.Data(), nil
}
func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateQuest)
var totalCount, returnedCount uint16
bf := byteframe.NewByteFrame()
bf.WriteUint16(0)
filepath.Walk(fmt.Sprintf("%s/events/", s.server.erupeConfig.BinPath), func(path string, info os.FileInfo, err error) error {
rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark FROM event_quests ORDER BY quest_id")
for rows.Next() {
data, err := makeEventQuest(s, rows)
if err != nil {
return err
} else if info.IsDir() {
return nil
}
data, err := os.ReadFile(path)
if err != nil {
return err
continue
} else {
if len(data) > 850 || len(data) < 400 {
return nil // Could be more or less strict with size limits
if len(data) > 896 || len(data) < 352 {
continue
} else {
totalCount++
if totalCount > pkt.Offset && len(bf.Data()) < 60000 {
returnedCount++
bf.WriteBytes(data)
return nil
if _config.ErupeConfig.RealClientMode == _config.F5 {
if totalCount > pkt.Offset && len(bf.Data()) < 21550 {
returnedCount++
bf.WriteBytes(data)
continue
}
} else {
if totalCount > pkt.Offset && len(bf.Data()) < 60000 {
returnedCount++
bf.WriteBytes(data)
continue
}
}
}
}
return nil
})
}
type tuneValue struct {
ID uint16
@@ -518,6 +632,27 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
offset := uint16(time.Now().Unix())
bf.WriteUint16(offset)
if _config.ErupeConfig.RealClientMode <= _config.F5 {
tuneValues = tuneValues[:256]
} else if _config.ErupeConfig.RealClientMode <= _config.G3 {
tuneValues = tuneValues[:283]
} else if _config.ErupeConfig.RealClientMode <= _config.GG {
tuneValues = tuneValues[:315]
} else if _config.ErupeConfig.RealClientMode <= _config.G61 {
tuneValues = tuneValues[:332]
} else if _config.ErupeConfig.RealClientMode <= _config.G7 {
tuneValues = tuneValues[:339]
} else if _config.ErupeConfig.RealClientMode <= _config.G81 {
tuneValues = tuneValues[:396]
} else if _config.ErupeConfig.RealClientMode <= _config.G91 {
tuneValues = tuneValues[:694]
} else if _config.ErupeConfig.RealClientMode <= _config.G101 {
tuneValues = tuneValues[:704]
} else if _config.ErupeConfig.RealClientMode <= _config.Z2 {
tuneValues = tuneValues[:750]
}
bf.WriteUint16(uint16(len(tuneValues)))
for i := range tuneValues {
bf.WriteUint16(tuneValues[i].ID ^ offset)
@@ -537,7 +672,8 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
{false, 10000},
}
bf.WriteUint16(uint16(len(vsQuestItems)))
bf.WriteUint32(uint32(len(vsQuestBets)))
bf.WriteUint16(0) // Unk array of uint16s
bf.WriteUint16(uint16(len(vsQuestBets)))
bf.WriteUint16(0) // Unk
for i := range vsQuestItems {
@@ -554,6 +690,7 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
bf.WriteUint16(pkt.Offset)
bf.Seek(0, io.SeekStart)
bf.WriteUint16(returnedCount)
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}

View File

@@ -196,7 +196,9 @@ func handleMsgSysOperateRegister(s *Session, p mhfpacket.MHFPacket) {
resp.WriteUint8(0)
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
}
s.notifyRavi()
if s.server.erupeConfig.GameplayOptions.LowLatencyRaviente {
s.notifyRavi()
}
s.server.raviente.Unlock()
}
@@ -241,6 +243,10 @@ func handleMsgSysLoadRegister(s *Session, p mhfpacket.MHFPacket) {
}
func (s *Session) notifyRavi() {
sema := getRaviSemaphore(s.server)
if sema == nil {
return
}
var temp mhfpacket.MHFPacket
raviNotif := byteframe.NewByteFrame()
temp = &mhfpacket.MsgSysNotifyRegister{RegisterID: 4}
@@ -253,11 +259,16 @@ func (s *Session) notifyRavi() {
raviNotif.WriteUint16(uint16(temp.Opcode()))
temp.Build(raviNotif, s.clientContext)
raviNotif.WriteUint16(0x0010) // End it.
sema := getRaviSemaphore(s.server)
if sema != nil {
if s.server.erupeConfig.GameplayOptions.LowLatencyRaviente {
for session := range sema.clients {
session.QueueSend(raviNotif.Data())
}
} else {
for session := range sema.clients {
if session.charID == s.charID {
session.QueueSend(raviNotif.Data())
}
}
}
}

View File

@@ -85,13 +85,13 @@ func handleMsgSysCreateAcquireSemaphore(s *Session, p mhfpacket.MHFPacket) {
if !exists {
s.server.semaphoreLock.Lock()
if strings.HasPrefix(SemaphoreID, "hs_l0u3B5") {
suffix, _ := strconv.ParseUint(pkt.SemaphoreID[len(pkt.SemaphoreID)-1:], 10, 32)
suffix, _ := strconv.Atoi(pkt.SemaphoreID[len(pkt.SemaphoreID)-1:])
s.server.semaphore[SemaphoreID] = &Semaphore{
id_semaphore: pkt.SemaphoreID,
id: uint32(suffix + 1),
clients: make(map[*Session]uint32),
reservedClientSlots: make(map[uint32]interface{}),
maxPlayers: 32,
maxPlayers: 127,
}
} else {
s.server.semaphore[SemaphoreID] = NewSemaphore(s.server, SemaphoreID, 1)

View File

@@ -3,6 +3,7 @@ package channelserver
import (
"erupe-ce/common/byteframe"
ps "erupe-ce/common/pascalstring"
_config "erupe-ce/config"
"erupe-ce/network/mhfpacket"
"math/rand"
)
@@ -40,13 +41,14 @@ type GachaEntry struct {
EntryType uint8 `db:"entry_type"`
ID uint32 `db:"id"`
ItemType uint8 `db:"item_type"`
ItemNumber uint16 `db:"item_number"`
ItemNumber uint32 `db:"item_number"`
ItemQuantity uint16 `db:"item_quantity"`
Weight float64 `db:"weight"`
Rarity uint8 `db:"rarity"`
Rolls uint8 `db:"rolls"`
FrontierPoints uint16 `db:"frontier_points"`
DailyLimit uint8 `db:"daily_limit"`
Name string `db:"name"`
}
type GachaItem struct {
@@ -108,6 +110,12 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
// 8: special item
switch pkt.ShopType {
case 1: // Running gachas
// Fundamentally, gacha works completely differently, just hide it for now.
if _config.ErupeConfig.RealClientMode <= _config.G7 {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
return
}
var count uint16
shopEntries, err := s.server.db.Queryx("SELECT id, min_gr, min_hr, name, url_banner, url_feature, url_thumbnail, wide, recommended, gacha_type, hidden FROM gacha_shop")
if err != nil {
@@ -151,7 +159,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
bf.WriteUint32(pkt.ShopID)
var gachaType int
s.server.db.QueryRow(`SELECT gacha_type FROM gacha_shop WHERE id = $1`, pkt.ShopID).Scan(&gachaType)
entries, err := s.server.db.Queryx(`SELECT entry_type, id, item_type, item_number, item_quantity, weight, rarity, rolls, daily_limit, frontier_points FROM gacha_entries WHERE gacha_id = $1 ORDER BY weight DESC`, pkt.ShopID)
entries, err := s.server.db.Queryx(`SELECT entry_type, id, item_type, item_number, item_quantity, weight, rarity, rolls, daily_limit, frontier_points, name FROM gacha_entries WHERE gacha_id = $1 ORDER BY weight DESC`, pkt.ShopID)
if err != nil {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
return
@@ -168,8 +176,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
bf.WriteUint8(gachaEntry.EntryType)
bf.WriteUint32(gachaEntry.ID)
bf.WriteUint8(gachaEntry.ItemType)
bf.WriteUint16(0)
bf.WriteUint16(gachaEntry.ItemNumber)
bf.WriteUint32(gachaEntry.ItemNumber)
bf.WriteUint16(gachaEntry.ItemQuantity)
if gachaType >= 4 { // If box
bf.WriteUint16(1)
@@ -197,7 +204,11 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
bf.WriteUint16(gachaEntry.FrontierPoints)
bf.WriteUint8(gachaEntry.DailyLimit)
bf.WriteUint8(0)
if gachaEntry.EntryType < 10 {
ps.Uint8(bf, gachaEntry.Name, true)
} else {
bf.WriteUint8(0)
}
bf.WriteBytes(temp.Data())
}
bf.Seek(4, 0)

View File

@@ -47,6 +47,7 @@ type Server struct {
acceptConns chan net.Conn
deleteConns chan net.Conn
sessions map[net.Conn]*Session
objectIDs map[*Session]uint16
listener net.Listener // Listener that is created when Server.Start is called.
isShuttingDown bool
@@ -152,6 +153,7 @@ func NewServer(config *Config) *Server {
acceptConns: make(chan net.Conn),
deleteConns: make(chan net.Conn),
sessions: make(map[net.Conn]*Session),
objectIDs: make(map[*Session]uint16),
stages: make(map[string]*Stage),
userBinaryParts: make(map[userBinaryPartID][]byte),
semaphore: make(map[string]*Semaphore),
@@ -405,3 +407,8 @@ func (s *Server) NextSemaphoreID() uint32 {
}
return s.semaphoreIndex
}
func (s *Server) Season() uint8 {
sid := int64(((s.ID & 0xFF00) - 4096) / 256)
return uint8(((TimeAdjusted().Unix() / 86400) + sid) % 3)
}

View File

@@ -22,6 +22,7 @@ func getLangStrings(s *Server) map[string]string {
strings["commandTeleportSuccess"] = "%d %dにテレポート"
strings["commandPSNError"] = "PSN連携コマンドエラー %s <psn id>"
strings["commandPSNSuccess"] = "PSN「%s」が連携されています"
strings["commandPSNExists"] = "PSNは既存のユーザに接続されています"
strings["commandRaviNoCommand"] = "ラヴィコマンドが指定されていません"
strings["commandRaviStartSuccess"] = "大討伐を開始します"
@@ -72,6 +73,7 @@ func getLangStrings(s *Server) map[string]string {
strings["commandTeleportSuccess"] = "Teleporting to %d %d"
strings["commandPSNError"] = "Error in command. Format: %s <psn id>"
strings["commandPSNSuccess"] = "Connected PSN ID: %s"
strings["commandPSNExists"] = "PSN ID is connected to another account!"
strings["commandRaviNoCommand"] = "No Raviente command specified!"
strings["commandRaviStartSuccess"] = "The Great Slaying will begin in a moment"

View File

@@ -34,6 +34,7 @@ type Session struct {
clientContext *clientctx.ClientContext
lastPacket time.Time
objectIndex uint16
userEnteredStage bool // If the user has entered a stage before
stageID string
stage *Stage
@@ -78,6 +79,7 @@ func NewSession(server *Server, conn net.Conn) *Session {
sessionStart: TimeAdjusted().Unix(),
stageMoveStack: stringstack.New(),
}
s.SetObjectID()
return s
}
@@ -268,3 +270,29 @@ 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) SetObjectID() {
for i := uint16(1); i < 127; i++ {
exists := false
for _, j := range s.server.objectIDs {
if i == j {
exists = true
break
}
}
if !exists {
s.server.objectIDs[s] = i
return
}
}
s.server.objectIDs[s] = 0
}
func (s *Session) NextObjectID() uint32 {
bf := byteframe.NewByteFrame()
bf.WriteUint16(s.server.objectIDs[s])
s.objectIndex++
bf.WriteUint16(s.objectIndex)
bf.Seek(0, 0)
return bf.ReadUint32()
}

View File

@@ -30,7 +30,7 @@ type Stage struct {
// Objects
objects map[uint32]*Object
objectIndex uint16
objectIndex uint8
// Map of session -> charID.
// These are clients that are CURRENTLY in the stage
@@ -56,6 +56,7 @@ func NewStage(ID string) *Stage {
clients: make(map[*Session]uint32),
reservedClientSlots: make(map[uint32]bool),
objects: make(map[uint32]*Object),
objectIndex: 0,
rawBinaryData: make(map[stageBinaryKey][]byte),
maxPlayers: 4,
}
@@ -94,12 +95,3 @@ func (s *Stage) isCharInQuestByID(charID uint32) bool {
func (s *Stage) isQuest() bool {
return len(s.reservedClientSlots) > 0
}
func (s *Stage) NextObjectID() uint32 {
s.objectIndex++
bf := byteframe.NewByteFrame()
bf.WriteUint16(127)
bf.WriteUint16(s.objectIndex)
bf.Seek(0, 0)
return bf.ReadUint32()
}

View File

@@ -23,3 +23,7 @@ func TimeWeekStart() time.Time {
func TimeWeekNext() time.Time {
return TimeWeekStart().Add(time.Hour * 24 * 7)
}
func TimeGameAbsolute() uint32 {
return uint32((TimeAdjusted().Unix() - 2160) % 5760)
}

View File

@@ -1,87 +0,0 @@
package timeserver
import (
"time"
)
var DoOnce_midnight = false
var DoOnce_t2 = false
var DoOnce_t = false
var Fix_midnight = time.Time{}
var Fix_t2 = time.Time{}
var Fix_t = time.Time{}
var Pfixtimer time.Duration
var Pnewtime = 0
var yearsFixed = -7
func PFadd_time() time.Duration {
Pnewtime = Pnewtime + 24
Pfixtimer = time.Duration(Pnewtime)
return Pfixtimer
}
func Time_static() time.Time {
if !DoOnce_t {
DoOnce_t = true
// Force to 201x
tFix1 := time.Now()
tFix2 := tFix1.AddDate(yearsFixed, 0, 0)
Fix_t = tFix2.In(time.FixedZone("UTC+1", 1*60*60))
}
return Fix_t
}
func Tstatic_midnight() time.Time {
if !DoOnce_midnight {
DoOnce_midnight = true
// Force to 201x
tFix1 := time.Now()
tFix2 := tFix1.AddDate(yearsFixed, 0, 0)
var tFix = tFix2.In(time.FixedZone("UTC+1", 1*60*60))
yearFix, monthFix, dayFix := tFix2.Date()
Fix_midnight = time.Date(yearFix, monthFix, dayFix, 0, 0, 0, 0, tFix.Location()).Add(time.Hour)
}
return Fix_midnight
}
func Time_midnight() time.Time {
// Force to 201x
t1 := time.Now()
t2 := t1.AddDate(yearsFixed, 0, 0)
var t = t2.In(time.FixedZone("UTC+1", 1*60*60))
year, month, day := t2.Date()
midnight := time.Date(year, month, day, 0, 0, 0, 0, t.Location()).Add(time.Hour)
return midnight
}
func TimeCurrent() time.Time {
// Force to 201x
t1 := time.Now()
t2 := t1.AddDate(yearsFixed, 0, 0)
var t = t2.In(time.FixedZone("UTC+1", 1*60*60))
return t
}
func Time_Current_Week_uint8() uint8 {
beginningOfTheMonth := time.Date(TimeCurrent().Year(), TimeCurrent().Month(), 1, 1, 1, 1, 1, time.UTC)
_, thisWeek := TimeCurrent().ISOWeek()
_, beginningWeek := beginningOfTheMonth.ISOWeek()
return uint8(1 + thisWeek - beginningWeek)
}
func Time_Current_Week_uint32() uint32 {
beginningOfTheMonth := time.Date(TimeCurrent().Year(), TimeCurrent().Month(), 1, 1, 1, 1, 1, time.UTC)
_, thisWeek := TimeCurrent().ISOWeek()
_, beginningWeek := beginningOfTheMonth.ISOWeek()
result := 1 + thisWeek - beginningWeek
return uint32(result)
}
func Detect_Day() bool {
switch time.Now().Weekday() {
case time.Wednesday:
return true
}
return false
}