2023-03-27 22:02:13 +00:00
|
|
|
package shard
|
2023-03-17 21:27:47 +00:00
|
|
|
|
2023-03-22 22:07:16 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2023-03-17 21:27:47 +00:00
|
|
|
|
2023-03-27 02:08:13 +00:00
|
|
|
"github.com/CPunch/gopenfusion/core"
|
2023-03-22 22:07:16 +00:00
|
|
|
"github.com/CPunch/gopenfusion/core/protocol"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Packet) error {
|
2023-03-18 21:40:20 +00:00
|
|
|
var enter protocol.SP_CL2FE_REQ_PC_ENTER
|
|
|
|
pkt.Decode(&enter)
|
|
|
|
|
2023-03-22 05:30:58 +00:00
|
|
|
loginData, err := server.CheckLogin(enter.IEnterSerialKey)
|
|
|
|
if err != nil {
|
|
|
|
// the error codes for P_FE2CL_REP_PC_ENTER_FAIL aren't referenced in the client :(
|
|
|
|
peer.Send(protocol.P_FE2CL_REP_PC_ENTER_FAIL, protocol.SP_FE2CL_REP_PC_ENTER_FAIL{})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-22 22:07:16 +00:00
|
|
|
// attach player
|
2023-03-27 02:08:13 +00:00
|
|
|
var resp *protocol.SP_FE2CL_REP_PC_ENTER_SUCC
|
|
|
|
if err := server.UpdatePlayer(peer, func(old *core.Player) (*core.Player, error) {
|
|
|
|
if old != nil { // resending a shard enter packet?
|
|
|
|
return nil, fmt.Errorf("resent enter packet!")
|
|
|
|
}
|
2023-03-22 22:07:16 +00:00
|
|
|
|
2023-03-27 02:08:13 +00:00
|
|
|
plr, err := server.dbHndlr.GetPlayer(int(loginData.PlayerID))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp = &protocol.SP_FE2CL_REP_PC_ENTER_SUCC{
|
|
|
|
IID: int32(plr.PlayerID),
|
|
|
|
PCLoadData2CL: plr.ToPCLoadData2CL(),
|
|
|
|
UiSvrTime: uint64(time.Now().Unix()),
|
|
|
|
}
|
|
|
|
|
|
|
|
return plr, nil
|
|
|
|
}); err != nil {
|
|
|
|
peer.Send(protocol.P_FE2CL_REP_PC_ENTER_FAIL, protocol.SP_FE2CL_REP_PC_ENTER_FAIL{})
|
|
|
|
return err
|
2023-03-22 22:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
2023-03-27 02:08:13 +00:00
|
|
|
plr := server.LoadPlayer(peer)
|
2023-03-22 22:07:16 +00:00
|
|
|
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)})
|
2023-03-17 21:27:47 +00:00
|
|
|
}
|