landwalker achieved!

- the shard's ip sent to the client via the login server is currently hardcoded in config/config.go
- no packets other than P_CL2FE_REQ_PC_ENTER and P_CL2FE_REQ_PC_LOADING_COMPLETE are supported via the shard server
This commit is contained in:
CPunch 2023-03-22 17:07:16 -05:00
parent 5b2a8b838e
commit bb29a988b3
5 changed files with 83 additions and 7 deletions

View File

@ -124,7 +124,7 @@ const (
) )
func (db *DBHandler) readPlayer(rows *sql.Rows) (*core.Player, error) { func (db *DBHandler) readPlayer(rows *sql.Rows) (*core.Player, error) {
plr := core.Player{} plr := core.Player{ActiveNanoSlotNum: -1}
if err := rows.Scan( if err := rows.Scan(
&plr.PlayerID, &plr.AccountID, &plr.Slot, &plr.PCStyle.SzFirstName, &plr.PCStyle.SzLastName, &plr.PlayerID, &plr.AccountID, &plr.Slot, &plr.PCStyle.SzFirstName, &plr.PCStyle.SzLastName,

View File

@ -34,3 +34,31 @@ type Player struct {
Fatigue int Fatigue int
CurrentMissionID int CurrentMissionID int
} }
func (plr *Player) ToPCLoadData2CL() protocol.SPCLoadData2CL {
return protocol.SPCLoadData2CL{
IUserLevel: int16(plr.AccountLevel),
PCStyle: plr.PCStyle,
PCStyle2: plr.PCStyle2,
IMentor: int16(plr.Mentor),
IMentorCount: 1,
IHP: int32(plr.HP),
IBatteryW: int32(plr.BatteryW),
IBatteryN: int32(plr.BatteryN),
ICandy: int32(plr.Taros),
IFusionMatter: int32(plr.FusionMatter),
ISpecialState: 0,
IMapNum: 0,
IX: int32(plr.X),
IY: int32(plr.Y),
IZ: int32(plr.Z),
IAngle: int32(plr.Angle),
AEquip: plr.Equip,
AInven: plr.Inven,
ANanoSlots: [3]int16{int16(plr.EquippedNanos[0]), int16(plr.EquippedNanos[1]), int16(plr.EquippedNanos[2])},
IActiveNanoSlotNum: int16(plr.ActiveNanoSlotNum),
IWarpLocationFlag: int32(plr.WarpLocationFlag),
IBuddyWarpTime: 60,
IFatigue: 50,
}
}

View File

@ -87,6 +87,10 @@ func (peer *CNPeer) Send(typeID uint32, data ...interface{}) error {
return nil return nil
} }
func (peer *CNPeer) SetActiveKey(whichKey int) {
peer.whichKey = whichKey
}
func (peer *CNPeer) Kill() { func (peer *CNPeer) Kill() {
if !peer.alive { if !peer.alive {
return return

View File

@ -1,8 +1,13 @@
package server package server
import "github.com/CPunch/gopenfusion/core/protocol" import (
"fmt"
"time"
func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Packet) (retErr error) { "github.com/CPunch/gopenfusion/core/protocol"
)
func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Packet) error {
var enter protocol.SP_CL2FE_REQ_PC_ENTER var enter protocol.SP_CL2FE_REQ_PC_ENTER
pkt.Decode(&enter) pkt.Decode(&enter)
@ -19,7 +24,31 @@ func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Pack
return err return err
} }
// TODO // attach player
_ = plr server.JoinPlayer(peer, plr)
return nil
resp := &protocol.SP_FE2CL_REP_PC_ENTER_SUCC{
IID: int32(plr.PlayerID),
PCLoadData2CL: plr.ToPCLoadData2CL(),
UiSvrTime: uint64(time.Now().Unix()),
}
// setup key
peer.E_key = protocol.CreateNewKey(resp.UiSvrTime, uint64(resp.IID+1), uint64(resp.PCLoadData2CL.IFusionMatter+1))
peer.FE_key = loginData.FEKey
peer.SetActiveKey(protocol.USE_FE)
return peer.Send(protocol.P_FE2CL_REP_PC_ENTER_SUCC, resp)
}
func (server *ShardServer) LoadingComplete(peer *protocol.CNPeer, pkt protocol.Packet) error {
var loadComplete protocol.SP_CL2FE_REQ_PC_LOADING_COMPLETE
pkt.Decode(&loadComplete)
plr := server.GetPlayer(peer)
if plr == nil {
return fmt.Errorf("peer has no player attached!")
}
return peer.Send(protocol.P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, protocol.SP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC{IPC_ID: int32(plr.PlayerID)})
} }

View File

@ -41,7 +41,8 @@ func NewShardServer(dbHndlr *db.DBHandler, port int) (*ShardServer, error) {
} }
server.packetHandlers = map[uint32]PacketHandler{ server.packetHandlers = map[uint32]PacketHandler{
protocol.P_CL2FE_REQ_PC_ENTER: server.RequestEnter, protocol.P_CL2FE_REQ_PC_ENTER: server.RequestEnter,
protocol.P_CL2FE_REQ_PC_LOADING_COMPLETE: server.LoadingComplete,
} }
return server, nil return server, nil
@ -89,6 +90,20 @@ func (server *ShardServer) Connect(peer *protocol.CNPeer) {
server.peers.Store(peer, nil) server.peers.Store(peer, nil)
} }
func (server *ShardServer) GetPlayer(peer *protocol.CNPeer) *core.Player {
val, ok := server.peers.Load(peer)
if !ok {
return nil
}
plr, ok := val.(*core.Player)
if !ok {
return nil
}
return plr
}
func (server *ShardServer) JoinPlayer(peer *protocol.CNPeer, player *core.Player) { func (server *ShardServer) JoinPlayer(peer *protocol.CNPeer, player *core.Player) {
server.peers.Store(peer, player) server.peers.Store(peer, player)
} }