Files
GaCy-GO/internal/gameserver/handlers_player.go
T

166 lines
5.3 KiB
Go

package gameserver
import (
"os"
"path/filepath"
"sort"
"strings"
goproto "gac-hkrpg-go/protocol/proto"
)
func init() {
// The three optional PlayerSettingInfo sub-messages are required by the
// Client requires these when processing _CmdGetBasicInfoScRsp.
handle("GetBasicInfo", func(s *Session, req *goproto.GetBasicInfoCsReq, rsp *goproto.GetBasicInfoScRsp) error {
rsp.Retcode = 0
rsp.Gender = 2
rsp.IsGenderSet = true
rsp.PlayerSettingInfo = &goproto.PlayerSettingInfo{
OJPAODIHAJE: &goproto.PNOLLIAKGDB{
BELKCBAGMFC: false,
JHJKCJKDHIB: 0,
MLPGDPGIFCJ: false,
},
ANKIDJJINEI: &goproto.LJFJOGEEGPJ{
MBIAIMKHNDB: false,
},
CMFCOOEEECB: &goproto.JPGACKPLGCD{
KALACJBAPOA: false,
FOKJIPGMKAN: false,
IBLGOCFBOCO: false,
},
}
return nil
})
handle("PlayerHeartBeat", func(s *Session, req *goproto.PlayerHeartBeatCsReq, rsp *goproto.PlayerHeartBeatScRsp) error {
rsp.ClientTimeMs = req.ClientTimeMs
rsp.ServerTimeMs = req.ClientTimeMs
var finalData []byte
finalData = append(finalData, heartbeatLua...)
if probe := s.takeBattleProbe(); len(probe) > 0 {
finalData = append(finalData, '\n')
finalData = append(finalData, probe...)
}
// Load all .lua files from scripts/ directory in deterministic order
if entries, err := os.ReadDir("scripts"); err == nil {
var luaFiles []string
for _, entry := range entries {
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".lua") {
luaFiles = append(luaFiles, entry.Name())
}
}
sort.Strings(luaFiles)
for _, name := range luaFiles {
if content, err := os.ReadFile(filepath.Join("scripts", name)); err == nil {
finalData = append(finalData, '\n')
finalData = append(finalData, content...)
}
}
} else if freecam, err := os.ReadFile("scripts/freecam.lua"); err == nil {
finalData = append(finalData, '\n')
finalData = append(finalData, freecam...)
}
rsp.DownloadData = &goproto.ClientDownloadData{
Version: goproto.ClientDownloadDataLuaVersion,
Time: int64(rsp.ServerTimeMs),
Data: finalData,
}
return nil
})
handle("PlayerLoginFinish", func(s *Session, req *goproto.PlayerLoginFinishCsReq, rsp *goproto.PlayerLoginFinishScRsp) error {
rsp.Retcode = 0
notify := &goproto.ContentPackageSyncDataScNotify{
Data: &goproto.ContentPackageData{},
}
for _, v := range contentPackageIDs {
notify.Data.ContentPackageList = append(notify.Data.ContentPackageList, &goproto.ContentPackageInfo{
Status: goproto.ContentPackageStatus_ContentPackageStatus_Finished,
ContentId: v,
})
}
return s.Send(notify)
})
handle("SyncClientResVersion", func(s *Session, req *goproto.SyncClientResVersionCsReq, rsp *goproto.SyncClientResVersionScRsp) error {
rsp.Retcode = 0
rsp.LJKMPIMKOMO = req.LJKMPIMKOMO
return nil
})
handle("GetPlayerBoardData", func(s *Session, req *goproto.GetPlayerBoardDataCsReq, rsp *goproto.GetPlayerBoardDataScRsp) error {
profile, err := loadProfileResources()
if err != nil {
return err
}
rsp.Retcode = 0
rsp.CurrentHeadIconId = profile.Icons[0]
rsp.CurrentPersonalCardId = profile.CurrentPersonalCard
rsp.HeadFrameInfo = profile.HeadFrame
rsp.NBIEJKLENOB = &goproto.DisplayAvatarVec{IsDisplay: true}
rsp.Signature = "Trailblazer"
// PearlSR 005d2c1 GetPlayerBoardDataScRsp: field 4 is personal
// cards, field 8 is head icons, and field 9 is assist avatar IDs.
rsp.JJDDEKIAOFC = profile.PersonalCards
for _, id := range profile.Icons {
rsp.KNINLDPFLMA = append(rsp.KNINLDPFLMA, &goproto.HeadIconData{Id: id})
}
if player := s.JSON(); player != nil {
for _, slot := range player.SortedLineupKeys() {
id := player.Lineups[slot]
if _, ok := player.Avatars[id]; !ok {
continue
}
rsp.KJAABDABLJJ = append(rsp.KJAABDABLJJ, id)
rsp.NBIEJKLENOB.DisplayAvatarList = append(rsp.NBIEJKLENOB.DisplayAvatarList,
&goproto.DisplayAvatarData{AvatarId: id, Pos: slot})
}
}
SceneDebugLog("GET_PLAYER_BOARD_DATA sent")
return nil
})
handle("GetPhoneData", func(s *Session, req *goproto.GetPhoneDataCsReq, rsp *goproto.GetPhoneDataScRsp) error {
profile, err := loadProfileResources()
if err != nil {
return err
}
rsp.Retcode = 0
rsp.CurPhoneTheme = profile.CurrentPhoneTheme
rsp.CurPhoneCase = profile.CurrentPhoneCase
rsp.CurChatBubble = profile.CurrentChatBubble
rsp.OwnedPhoneThemes = profile.PhoneThemes
rsp.OwnedPhoneCases = profile.PhoneCases
rsp.OwnedChatBubbles = profile.ChatBubbles
SceneDebugLog("GET_PHONE_DATA sent")
return nil
})
}
var contentPackageIDs = []uint32{
200001, 200002, 200003, 200004, 200005, 200006, 200007, 200008, 200009, 200010,
200011, 200012, 200013, 200014, 150017, 150015, 150021, 150018, 130011, 130012,
130013, 150025, 140006, 150026, 130014, 150034, 150029, 150035, 150041, 150039,
150045, 150057, 150042, 150067, 150064, 150063, 150024, 171002, 150068, 150070,
150071, 150073, 150074, 150075, 150076, 150077, 150078, 150079, 150132, 150134,
150135,
}
const heartbeatLua = `local function beta_text()
local gameObject = CS.UnityEngine.GameObject.Find("UIRoot/AboveDialog/BetaHintDialog(Clone)")
if gameObject then
local textComponent = gameObject:GetComponentInChildren(typeof(CS.RPG.Client.LocalizedText))
if textComponent then
textComponent.text = "<color=#FF2D00><b>GaC hkrpg GO server</b></color>"
end
end
end
beta_text()
`