diff --git a/core/db/players.go b/core/db/players.go index 7d81ce1..0f41d70 100644 --- a/core/db/players.go +++ b/core/db/players.go @@ -124,7 +124,7 @@ const ( ) func (db *DBHandler) readPlayer(rows *sql.Rows) (*core.Player, error) { - plr := core.Player{} + plr := core.Player{ActiveNanoSlotNum: -1} if err := rows.Scan( &plr.PlayerID, &plr.AccountID, &plr.Slot, &plr.PCStyle.SzFirstName, &plr.PCStyle.SzLastName, diff --git a/core/player.go b/core/player.go index a4375f6..3c3b4e1 100644 --- a/core/player.go +++ b/core/player.go @@ -34,3 +34,31 @@ type Player struct { Fatigue 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, + } +} diff --git a/core/protocol/cnpeer.go b/core/protocol/cnpeer.go index b77e563..c3afb7d 100644 --- a/core/protocol/cnpeer.go +++ b/core/protocol/cnpeer.go @@ -87,6 +87,10 @@ func (peer *CNPeer) Send(typeID uint32, data ...interface{}) error { return nil } +func (peer *CNPeer) SetActiveKey(whichKey int) { + peer.whichKey = whichKey +} + func (peer *CNPeer) Kill() { if !peer.alive { return diff --git a/server/join.go b/server/join.go index b66c10d..6d3551c 100644 --- a/server/join.go +++ b/server/join.go @@ -1,8 +1,13 @@ 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 pkt.Decode(&enter) @@ -19,7 +24,31 @@ func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Pack return err } - // TODO - _ = plr - return nil + // attach player + server.JoinPlayer(peer, plr) + + 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)}) } diff --git a/server/shardServer.go b/server/shardServer.go index 0c34a00..4e93621 100644 --- a/server/shardServer.go +++ b/server/shardServer.go @@ -41,7 +41,8 @@ func NewShardServer(dbHndlr *db.DBHandler, port int) (*ShardServer, error) { } 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 @@ -89,6 +90,20 @@ func (server *ShardServer) Connect(peer *protocol.CNPeer) { 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) { server.peers.Store(peer, player) }