renamed cnet.CNPeer -> cnet.Peer

This commit is contained in:
CPunch 2023-12-01 19:15:00 -06:00
parent c60017f78f
commit af867ccff2
11 changed files with 58 additions and 58 deletions

View File

@ -23,8 +23,8 @@ type PacketEvent struct {
PktID uint32 PktID uint32
} }
// CNPeer is a simple wrapper for net.Conn connections to send/recv packets over the Fusionfall packet protocol. // Peer is a simple wrapper for net.Conn connections to send/recv packets over the Fusionfall packet protocol.
type CNPeer struct { type Peer struct {
uData interface{} uData interface{}
conn net.Conn conn net.Conn
ctx context.Context ctx context.Context
@ -38,8 +38,8 @@ type CNPeer struct {
FE_key []byte FE_key []byte
} }
func NewCNPeer(ctx context.Context, conn net.Conn) *CNPeer { func NewPeer(ctx context.Context, conn net.Conn) *Peer {
p := &CNPeer{ p := &Peer{
conn: conn, conn: conn,
ctx: ctx, ctx: ctx,
whichKey: USE_E, whichKey: USE_E,
@ -52,15 +52,15 @@ func NewCNPeer(ctx context.Context, conn net.Conn) *CNPeer {
return p return p
} }
func (peer *CNPeer) SetUserData(uData interface{}) { func (peer *Peer) SetUserData(uData interface{}) {
peer.uData = uData peer.uData = uData
} }
func (peer *CNPeer) UserData() interface{} { func (peer *Peer) UserData() interface{} {
return peer.uData return peer.uData
} }
func (peer *CNPeer) Send(typeID uint32, data ...interface{}) error { func (peer *Peer) Send(typeID uint32, data ...interface{}) error {
// grab buffer from pool // grab buffer from pool
buf := protocol.GetBuffer() buf := protocol.GetBuffer()
defer protocol.PutBuffer(buf) defer protocol.PutBuffer(buf)
@ -104,11 +104,11 @@ func (peer *CNPeer) Send(typeID uint32, data ...interface{}) error {
return nil return nil
} }
func (peer *CNPeer) SetActiveKey(whichKey int) { func (peer *Peer) SetActiveKey(whichKey int) {
peer.whichKey = whichKey peer.whichKey = whichKey
} }
func (peer *CNPeer) Kill() { func (peer *Peer) Kill() {
// de-bounce: only kill if alive // de-bounce: only kill if alive
if !peer.alive.CompareAndSwap(true, false) { if !peer.alive.CompareAndSwap(true, false) {
return return
@ -118,7 +118,7 @@ func (peer *CNPeer) Kill() {
} }
// meant to be invoked as a goroutine // meant to be invoked as a goroutine
func (peer *CNPeer) Handler(eRecv chan<- *PacketEvent) error { func (peer *Peer) Handler(eRecv chan<- *PacketEvent) error {
defer func() { defer func() {
close(eRecv) close(eRecv)
peer.Kill() peer.Kill()

View File

@ -15,9 +15,9 @@ import (
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
) )
type PacketHandler func(peer *cnet.CNPeer, pkt protocol.Packet) error type PacketHandler func(peer *cnet.Peer, pkt protocol.Packet) error
func StubbedPacket(_ *cnet.CNPeer, _ protocol.Packet) error { func StubbedPacket(_ *cnet.Peer, _ protocol.Packet) error {
return nil return nil
} }
@ -29,18 +29,18 @@ type Service struct {
started chan struct{} started chan struct{}
stopped chan struct{} stopped chan struct{}
packetHandlers map[uint32]PacketHandler packetHandlers map[uint32]PacketHandler
peers map[chan *cnet.PacketEvent]*cnet.CNPeer peers map[chan *cnet.PacketEvent]*cnet.Peer
stateLock sync.Mutex stateLock sync.Mutex
// OnDisconnect is called when a peer disconnects from the service. // OnDisconnect is called when a peer disconnects from the service.
// uData is the stored value of the key/value pair in the peer map. // uData is the stored value of the key/value pair in the peer map.
// It may not be set while the service is running. (eg. srvc.Start() has been called) // It may not be set while the service is running. (eg. srvc.Start() has been called)
OnDisconnect func(peer *cnet.CNPeer) OnDisconnect func(peer *cnet.Peer)
// OnConnect is called when a peer connects to the service. // OnConnect is called when a peer connects to the service.
// return value is used as the value in the peer map. // return value is used as the value in the peer map.
// It may not be set while the service is running. (eg. srvc.Start() has been called) // It may not be set while the service is running. (eg. srvc.Start() has been called)
OnConnect func(peer *cnet.CNPeer) OnConnect func(peer *cnet.Peer)
} }
func RandomPort() (int, error) { func RandomPort() (int, error) {
@ -70,7 +70,7 @@ func NewService(ctx context.Context, name string, port int) *Service {
func (srvc *Service) Reset(ctx context.Context) { func (srvc *Service) Reset(ctx context.Context) {
srvc.ctx = ctx srvc.ctx = ctx
srvc.packetHandlers = make(map[uint32]PacketHandler) srvc.packetHandlers = make(map[uint32]PacketHandler)
srvc.peers = make(map[chan *cnet.PacketEvent]*cnet.CNPeer) srvc.peers = make(map[chan *cnet.PacketEvent]*cnet.Peer)
srvc.started = make(chan struct{}) srvc.started = make(chan struct{})
srvc.stopped = make(chan struct{}) srvc.stopped = make(chan struct{})
} }
@ -81,7 +81,7 @@ func (srvc *Service) AddPacketHandler(pktID uint32, handler PacketHandler) {
} }
type newPeerConnection struct { type newPeerConnection struct {
peer *cnet.CNPeer peer *cnet.Peer
channel chan *cnet.PacketEvent channel chan *cnet.PacketEvent
} }
@ -113,18 +113,18 @@ func (srvc *Service) Start() error {
} }
// create a new peer and pass it to the event loop // create a new peer and pass it to the event loop
peer := cnet.NewCNPeer(srvc.ctx, conn) peer := cnet.NewPeer(srvc.ctx, conn)
eRecv := make(chan *cnet.PacketEvent) eRecv := make(chan *cnet.PacketEvent)
peerConnections <- newPeerConnection{channel: eRecv, peer: peer} peerConnections <- newPeerConnection{channel: eRecv, peer: peer}
go peer.Handler(eRecv) go peer.Handler(eRecv)
} }
} }
func (srvc *Service) getPeer(channel chan *cnet.PacketEvent) *cnet.CNPeer { func (srvc *Service) getPeer(channel chan *cnet.PacketEvent) *cnet.Peer {
return srvc.peers[channel] return srvc.peers[channel]
} }
func (srvc *Service) setPeer(channel chan *cnet.PacketEvent, peer *cnet.CNPeer) { func (srvc *Service) setPeer(channel chan *cnet.PacketEvent, peer *cnet.Peer) {
srvc.peers[channel] = peer srvc.peers[channel] = peer
} }
@ -148,7 +148,7 @@ func (srvc *Service) Stopped() <-chan struct{} {
// if f returns false, the iteration is stopped. // if f returns false, the iteration is stopped.
// NOTE: the peer map is not locked while iterating, if you're calling this // NOTE: the peer map is not locked while iterating, if you're calling this
// outside of the service's event loop, you'll need to lock the peer map yourself. // outside of the service's event loop, you'll need to lock the peer map yourself.
func (srvc *Service) RangePeers(f func(peer *cnet.CNPeer) bool) { func (srvc *Service) RangePeers(f func(peer *cnet.Peer) bool) {
for _, peer := range srvc.peers { for _, peer := range srvc.peers {
if !f(peer) { if !f(peer) {
break break
@ -168,7 +168,7 @@ func (srvc *Service) Unlock() {
func (srvc *Service) stop() { func (srvc *Service) stop() {
// OnDisconnect handler might need to do something important // OnDisconnect handler might need to do something important
srvc.RangePeers(func(peer *cnet.CNPeer) bool { srvc.RangePeers(func(peer *cnet.Peer) bool {
peer.Kill() peer.Kill()
if srvc.OnDisconnect != nil { if srvc.OnDisconnect != nil {
srvc.OnDisconnect(peer) srvc.OnDisconnect(peer)
@ -251,7 +251,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
} }
} }
func (srvc *Service) handlePacket(peer *cnet.CNPeer, typeID uint32, pkt protocol.Packet) error { func (srvc *Service) handlePacket(peer *cnet.Peer, typeID uint32, pkt protocol.Packet) error {
if hndlr, ok := srvc.packetHandlers[typeID]; ok { if hndlr, ok := srvc.packetHandlers[typeID]; ok {
// fmt.Printf("Handling packet %x\n", typeID) // fmt.Printf("Handling packet %x\n", typeID)
if err := hndlr(peer, pkt); err != nil { if err := hndlr(peer, pkt); err != nil {
@ -264,7 +264,7 @@ func (srvc *Service) handlePacket(peer *cnet.CNPeer, typeID uint32, pkt protocol
return nil return nil
} }
func (srvc *Service) disconnect(channel chan *cnet.PacketEvent, peer *cnet.CNPeer) { func (srvc *Service) disconnect(channel chan *cnet.PacketEvent, peer *cnet.Peer) {
log.Printf("Peer %p disconnected from %s\n", peer, srvc.Name) log.Printf("Peer %p disconnected from %s\n", peer, srvc.Name)
if srvc.OnDisconnect != nil { if srvc.OnDisconnect != nil {
srvc.OnDisconnect(peer) srvc.OnDisconnect(peer)
@ -273,7 +273,7 @@ func (srvc *Service) disconnect(channel chan *cnet.PacketEvent, peer *cnet.CNPee
srvc.removePeer(channel) srvc.removePeer(channel)
} }
func (srvc *Service) connect(channel chan *cnet.PacketEvent, peer *cnet.CNPeer) { func (srvc *Service) connect(channel chan *cnet.PacketEvent, peer *cnet.Peer) {
log.Printf("New peer %p connected to %s\n", peer, srvc.Name) log.Printf("New peer %p connected to %s\n", peer, srvc.Name)
if srvc.OnConnect != nil { if srvc.OnConnect != nil {
srvc.OnConnect(peer) srvc.OnConnect(peer)

View File

@ -68,7 +68,7 @@ func TestService(t *testing.T) {
// our dummy packet handler // our dummy packet handler
wg.Add(maxDummyPeers) wg.Add(maxDummyPeers)
srvc.AddPacketHandler(0x1234, func(peer *cnet.CNPeer, pkt protocol.Packet) error { srvc.AddPacketHandler(0x1234, func(peer *cnet.Peer, pkt protocol.Packet) error {
log.Printf("Received packet %#v", pkt) log.Printf("Received packet %#v", pkt)
wg.Done() wg.Done()
return nil return nil
@ -76,12 +76,12 @@ func TestService(t *testing.T) {
// wait for all dummy peers to connect and disconnect // wait for all dummy peers to connect and disconnect
wg.Add(maxDummyPeers) wg.Add(maxDummyPeers)
srvc.OnConnect = func(peer *cnet.CNPeer) { srvc.OnConnect = func(peer *cnet.Peer) {
wg.Done() wg.Done()
} }
wg.Add(maxDummyPeers) wg.Add(maxDummyPeers)
srvc.OnDisconnect = func(peer *cnet.CNPeer) { srvc.OnDisconnect = func(peer *cnet.Peer) {
wg.Done() wg.Done()
} }
@ -96,7 +96,7 @@ func TestService(t *testing.T) {
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", srvcPort)) conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", srvcPort))
is.NoErr(err) // net.Dial error is.NoErr(err) // net.Dial error
peer := cnet.NewCNPeer(ctx, conn) peer := cnet.NewPeer(ctx, conn)
go func() { go func() {
defer peer.Kill() defer peer.Kill()

View File

@ -27,7 +27,7 @@ const (
LOGIN_UPDATED_EUALA_REQUIRED = 9 LOGIN_UPDATED_EUALA_REQUIRED = 9
) )
func (server *LoginServer) AcceptLogin(peer *cnet.CNPeer, SzID string, IClientVerC int32, ISlotNum int8, data []protocol.SP_LS2CL_REP_CHAR_INFO) error { func (server *LoginServer) AcceptLogin(peer *cnet.Peer, SzID string, IClientVerC int32, ISlotNum int8, data []protocol.SP_LS2CL_REP_CHAR_INFO) error {
resp := protocol.SP_LS2CL_REP_LOGIN_SUCC{ resp := protocol.SP_LS2CL_REP_LOGIN_SUCC{
SzID: SzID, SzID: SzID,
ICharCount: int8(len(data)), ICharCount: int8(len(data)),
@ -63,7 +63,7 @@ func (server *LoginServer) AcceptLogin(peer *cnet.CNPeer, SzID string, IClientVe
return nil return nil
} }
func (server *LoginServer) Login(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) Login(peer *cnet.Peer, pkt protocol.Packet) error {
var loginPkt protocol.SP_CL2LS_REQ_LOGIN var loginPkt protocol.SP_CL2LS_REQ_LOGIN
pkt.Decode(&loginPkt) pkt.Decode(&loginPkt)
@ -139,7 +139,7 @@ func (server *LoginServer) Login(peer *cnet.CNPeer, pkt protocol.Packet) error {
return server.AcceptLogin(peer, loginPkt.SzID, loginPkt.IClientVerC, 1, charInfo[:len(plrs)]) return server.AcceptLogin(peer, loginPkt.SzID, loginPkt.IClientVerC, 1, charInfo[:len(plrs)])
} }
func (server *LoginServer) CheckCharacterName(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) CheckCharacterName(peer *cnet.Peer, pkt protocol.Packet) error {
var charPkt protocol.SP_CL2LS_REQ_CHECK_CHAR_NAME var charPkt protocol.SP_CL2LS_REQ_CHECK_CHAR_NAME
pkt.Decode(&charPkt) pkt.Decode(&charPkt)
@ -150,7 +150,7 @@ func (server *LoginServer) CheckCharacterName(peer *cnet.CNPeer, pkt protocol.Pa
}) })
} }
func (server *LoginServer) SaveCharacterName(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) SaveCharacterName(peer *cnet.Peer, pkt protocol.Packet) error {
var charPkt protocol.SP_CL2LS_REQ_SAVE_CHAR_NAME var charPkt protocol.SP_CL2LS_REQ_SAVE_CHAR_NAME
pkt.Decode(&charPkt) pkt.Decode(&charPkt)
@ -203,7 +203,7 @@ func validateCharacterCreation(character *protocol.SP_CL2LS_REQ_CHAR_CREATE) boo
return true return true
} }
func SendFail(peer *cnet.CNPeer) error { func SendFail(peer *cnet.Peer) error {
if err := peer.Send(protocol.P_LS2CL_REP_SHARD_SELECT_FAIL, protocol.SP_LS2CL_REP_SHARD_SELECT_FAIL{ if err := peer.Send(protocol.P_LS2CL_REP_SHARD_SELECT_FAIL, protocol.SP_LS2CL_REP_SHARD_SELECT_FAIL{
IErrorCode: 2, IErrorCode: 2,
}); err != nil { }); err != nil {
@ -213,7 +213,7 @@ func SendFail(peer *cnet.CNPeer) error {
return nil return nil
} }
func (server *LoginServer) CharacterCreate(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) CharacterCreate(peer *cnet.Peer, pkt protocol.Packet) error {
var charPkt protocol.SP_CL2LS_REQ_CHAR_CREATE var charPkt protocol.SP_CL2LS_REQ_CHAR_CREATE
pkt.Decode(&charPkt) pkt.Decode(&charPkt)
@ -246,7 +246,7 @@ func (server *LoginServer) CharacterCreate(peer *cnet.CNPeer, pkt protocol.Packe
}) })
} }
func (server *LoginServer) CharacterDelete(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) CharacterDelete(peer *cnet.Peer, pkt protocol.Packet) error {
var charPkt protocol.SP_CL2LS_REQ_CHAR_DELETE var charPkt protocol.SP_CL2LS_REQ_CHAR_DELETE
pkt.Decode(&charPkt) pkt.Decode(&charPkt)
@ -265,7 +265,7 @@ func (server *LoginServer) CharacterDelete(peer *cnet.CNPeer, pkt protocol.Packe
}) })
} }
func (server *LoginServer) ShardSelect(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) ShardSelect(peer *cnet.Peer, pkt protocol.Packet) error {
var selection protocol.SP_CL2LS_REQ_CHAR_SELECT var selection protocol.SP_CL2LS_REQ_CHAR_SELECT
pkt.Decode(&selection) pkt.Decode(&selection)
@ -321,7 +321,7 @@ func (server *LoginServer) ShardSelect(peer *cnet.CNPeer, pkt protocol.Packet) e
return peer.Send(protocol.P_LS2CL_REP_SHARD_SELECT_SUCC, resp) return peer.Send(protocol.P_LS2CL_REP_SHARD_SELECT_SUCC, resp)
} }
func (server *LoginServer) FinishTutorial(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) FinishTutorial(peer *cnet.Peer, pkt protocol.Packet) error {
var charPkt protocol.SP_CL2LS_REQ_SAVE_CHAR_TUTOR var charPkt protocol.SP_CL2LS_REQ_SAVE_CHAR_TUTOR
pkt.Decode(&charPkt) pkt.Decode(&charPkt)

View File

@ -8,7 +8,7 @@ import (
"github.com/CPunch/gopenfusion/shard/entity" "github.com/CPunch/gopenfusion/shard/entity"
) )
func (server *ShardServer) freeChat(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) freeChat(peer *cnet.Peer, pkt protocol.Packet) error {
var chat protocol.SP_CL2FE_REQ_SEND_FREECHAT_MESSAGE var chat protocol.SP_CL2FE_REQ_SEND_FREECHAT_MESSAGE
pkt.Decode(&chat) pkt.Decode(&chat)
@ -25,7 +25,7 @@ func (server *ShardServer) freeChat(peer *cnet.CNPeer, pkt protocol.Packet) erro
}) })
} }
func (server *ShardServer) menuChat(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) menuChat(peer *cnet.Peer, pkt protocol.Packet) error {
var chat protocol.SP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE var chat protocol.SP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE
pkt.Decode(&chat) pkt.Decode(&chat)
@ -42,7 +42,7 @@ func (server *ShardServer) menuChat(peer *cnet.CNPeer, pkt protocol.Packet) erro
}) })
} }
func (server *ShardServer) emoteChat(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) emoteChat(peer *cnet.Peer, pkt protocol.Packet) error {
var chat protocol.SP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT var chat protocol.SP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT
pkt.Decode(&chat) pkt.Decode(&chat)

View File

@ -20,6 +20,6 @@ type Entity interface {
SetPosition(x, y, z int) SetPosition(x, y, z int)
SetAngle(angle int) SetAngle(angle int)
DisappearFromViewOf(peer *cnet.CNPeer) DisappearFromViewOf(peer *cnet.Peer)
EnterIntoViewOf(peer *cnet.CNPeer) EnterIntoViewOf(peer *cnet.Peer)
} }

View File

@ -63,13 +63,13 @@ func (npc *NPC) SetAngle(angle int) {
npc.Angle = angle npc.Angle = angle
} }
func (npc *NPC) DisappearFromViewOf(peer *cnet.CNPeer) { func (npc *NPC) DisappearFromViewOf(peer *cnet.Peer) {
peer.Send(protocol.P_FE2CL_NPC_EXIT, protocol.SP_FE2CL_NPC_EXIT{ peer.Send(protocol.P_FE2CL_NPC_EXIT, protocol.SP_FE2CL_NPC_EXIT{
INPC_ID: int32(npc.ID), INPC_ID: int32(npc.ID),
}) })
} }
func (npc *NPC) EnterIntoViewOf(peer *cnet.CNPeer) { func (npc *NPC) EnterIntoViewOf(peer *cnet.Peer) {
peer.Send(protocol.P_FE2CL_NPC_NEW, protocol.SP_FE2CL_NPC_NEW{ peer.Send(protocol.P_FE2CL_NPC_NEW, protocol.SP_FE2CL_NPC_NEW{
NPCAppearanceData: npc.GetAppearanceData(), NPCAppearanceData: npc.GetAppearanceData(),
}) })

View File

@ -8,11 +8,11 @@ import (
type Player struct { type Player struct {
db.Player db.Player
Peer *cnet.CNPeer Peer *cnet.Peer
Chunk ChunkPosition Chunk ChunkPosition
} }
func NewPlayer(peer *cnet.CNPeer, player *db.Player) *Player { func NewPlayer(peer *cnet.Peer, player *db.Player) *Player {
return &Player{ return &Player{
Player: *player, Player: *player,
Peer: peer, Peer: peer,
@ -52,13 +52,13 @@ func (plr *Player) SetAngle(angle int) {
plr.Angle = angle plr.Angle = angle
} }
func (plr *Player) DisappearFromViewOf(peer *cnet.CNPeer) { func (plr *Player) DisappearFromViewOf(peer *cnet.Peer) {
peer.Send(protocol.P_FE2CL_PC_EXIT, protocol.SP_FE2CL_PC_EXIT{ peer.Send(protocol.P_FE2CL_PC_EXIT, protocol.SP_FE2CL_PC_EXIT{
IID: int32(plr.PlayerID), IID: int32(plr.PlayerID),
}) })
} }
func (plr *Player) EnterIntoViewOf(peer *cnet.CNPeer) { func (plr *Player) EnterIntoViewOf(peer *cnet.Peer) {
peer.Send(protocol.P_FE2CL_PC_NEW, protocol.SP_FE2CL_PC_NEW{ peer.Send(protocol.P_FE2CL_PC_NEW, protocol.SP_FE2CL_PC_NEW{
PCAppearanceData: plr.GetAppearanceData(), PCAppearanceData: plr.GetAppearanceData(),
}) })

View File

@ -11,7 +11,7 @@ import (
"github.com/CPunch/gopenfusion/util" "github.com/CPunch/gopenfusion/util"
) )
func (server *ShardServer) attachPlayer(peer *cnet.CNPeer, meta redis.LoginMetadata) (*entity.Player, error) { func (server *ShardServer) attachPlayer(peer *cnet.Peer, meta redis.LoginMetadata) (*entity.Player, error) {
dbPlr, err := server.dbHndlr.GetPlayer(int(meta.PlayerID)) dbPlr, err := server.dbHndlr.GetPlayer(int(meta.PlayerID))
if err != nil { if err != nil {
return nil, err return nil, err
@ -26,7 +26,7 @@ func (server *ShardServer) attachPlayer(peer *cnet.CNPeer, meta redis.LoginMetad
return plr, nil return plr, nil
} }
func (server *ShardServer) RequestEnter(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) RequestEnter(peer *cnet.Peer, 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)
@ -67,7 +67,7 @@ func (server *ShardServer) RequestEnter(peer *cnet.CNPeer, pkt protocol.Packet)
return nil return nil
} }
func (server *ShardServer) LoadingComplete(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) LoadingComplete(peer *cnet.Peer, pkt protocol.Packet) error {
var loadComplete protocol.SP_CL2FE_REQ_PC_LOADING_COMPLETE var loadComplete protocol.SP_CL2FE_REQ_PC_LOADING_COMPLETE
pkt.Decode(&loadComplete) pkt.Decode(&loadComplete)

View File

@ -17,7 +17,7 @@ func (server *ShardServer) updatePlayerPosition(plr *entity.Player, X, Y, Z, Ang
server.updateEntityChunk(plr, plr.GetChunkPos(), entity.MakeChunkPosition(X, Y)) server.updateEntityChunk(plr, plr.GetChunkPos(), entity.MakeChunkPosition(X, Y))
} }
func (server *ShardServer) playerMove(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) playerMove(peer *cnet.Peer, pkt protocol.Packet) error {
var move protocol.SP_CL2FE_REQ_PC_MOVE var move protocol.SP_CL2FE_REQ_PC_MOVE
pkt.Decode(&move) pkt.Decode(&move)
@ -45,7 +45,7 @@ func (server *ShardServer) playerMove(peer *cnet.CNPeer, pkt protocol.Packet) er
}) })
} }
func (server *ShardServer) playerStop(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) playerStop(peer *cnet.Peer, pkt protocol.Packet) error {
var stop protocol.SP_CL2FE_REQ_PC_STOP var stop protocol.SP_CL2FE_REQ_PC_STOP
pkt.Decode(&stop) pkt.Decode(&stop)
@ -67,7 +67,7 @@ func (server *ShardServer) playerStop(peer *cnet.CNPeer, pkt protocol.Packet) er
}) })
} }
func (server *ShardServer) playerJump(peer *cnet.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) playerJump(peer *cnet.Peer, pkt protocol.Packet) error {
var jump protocol.SP_CL2FE_REQ_PC_JUMP var jump protocol.SP_CL2FE_REQ_PC_JUMP
pkt.Decode(&jump) pkt.Decode(&jump)

View File

@ -12,7 +12,7 @@ import (
"github.com/CPunch/gopenfusion/shard/entity" "github.com/CPunch/gopenfusion/shard/entity"
) )
type PacketHandler func(peer *cnet.CNPeer, pkt protocol.Packet) error type PacketHandler func(peer *cnet.Peer, pkt protocol.Packet) error
type ShardServer struct { type ShardServer struct {
service *service.Service service *service.Service
@ -56,7 +56,7 @@ func (server *ShardServer) Start() {
server.service.Start() server.service.Start()
} }
func (server *ShardServer) onDisconnect(peer *cnet.CNPeer) { func (server *ShardServer) onDisconnect(peer *cnet.Peer) {
// remove from chunks // remove from chunks
plr, ok := peer.UserData().(*entity.Player) plr, ok := peer.UserData().(*entity.Player)
if ok && plr != nil { if ok && plr != nil {
@ -64,6 +64,6 @@ func (server *ShardServer) onDisconnect(peer *cnet.CNPeer) {
} }
} }
func (server *ShardServer) onConnect(peer *cnet.CNPeer) { func (server *ShardServer) onConnect(peer *cnet.Peer) {
} }