rename cnpeer package to cnet

This commit is contained in:
CPunch 2023-12-01 17:11:41 -06:00
parent e1804a1042
commit c60017f78f
11 changed files with 67 additions and 67 deletions

View File

@ -1,4 +1,4 @@
package cnpeer package cnet
import ( import (
"bytes" "bytes"

View File

@ -10,14 +10,14 @@ import (
"strconv" "strconv"
"sync" "sync"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/config" "github.com/CPunch/gopenfusion/config"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
) )
type PacketHandler func(peer *cnpeer.CNPeer, pkt protocol.Packet) error type PacketHandler func(peer *cnet.CNPeer, pkt protocol.Packet) error
func StubbedPacket(_ *cnpeer.CNPeer, _ protocol.Packet) error { func StubbedPacket(_ *cnet.CNPeer, _ 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 *cnpeer.PacketEvent]*cnpeer.CNPeer peers map[chan *cnet.PacketEvent]*cnet.CNPeer
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 *cnpeer.CNPeer) OnDisconnect func(peer *cnet.CNPeer)
// 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 *cnpeer.CNPeer) OnConnect func(peer *cnet.CNPeer)
} }
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 *cnpeer.PacketEvent]*cnpeer.CNPeer) srvc.peers = make(map[chan *cnet.PacketEvent]*cnet.CNPeer)
srvc.started = make(chan struct{}) srvc.started = make(chan struct{})
srvc.stopped = make(chan struct{}) srvc.stopped = make(chan struct{})
} }
@ -81,8 +81,8 @@ func (srvc *Service) AddPacketHandler(pktID uint32, handler PacketHandler) {
} }
type newPeerConnection struct { type newPeerConnection struct {
peer *cnpeer.CNPeer peer *cnet.CNPeer
channel chan *cnpeer.PacketEvent channel chan *cnet.PacketEvent
} }
func (srvc *Service) Start() error { func (srvc *Service) Start() error {
@ -113,22 +113,22 @@ 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 := cnpeer.NewCNPeer(srvc.ctx, conn) peer := cnet.NewCNPeer(srvc.ctx, conn)
eRecv := make(chan *cnpeer.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 *cnpeer.PacketEvent) *cnpeer.CNPeer { func (srvc *Service) getPeer(channel chan *cnet.PacketEvent) *cnet.CNPeer {
return srvc.peers[channel] return srvc.peers[channel]
} }
func (srvc *Service) setPeer(channel chan *cnpeer.PacketEvent, peer *cnpeer.CNPeer) { func (srvc *Service) setPeer(channel chan *cnet.PacketEvent, peer *cnet.CNPeer) {
srvc.peers[channel] = peer srvc.peers[channel] = peer
} }
func (srvc *Service) removePeer(channel chan *cnpeer.PacketEvent) { func (srvc *Service) removePeer(channel chan *cnet.PacketEvent) {
delete(srvc.peers, channel) delete(srvc.peers, channel)
} }
@ -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 *cnpeer.CNPeer) bool) { func (srvc *Service) RangePeers(f func(peer *cnet.CNPeer) 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 *cnpeer.CNPeer) bool { srvc.RangePeers(func(peer *cnet.CNPeer) bool {
peer.Kill() peer.Kill()
if srvc.OnDisconnect != nil { if srvc.OnDisconnect != nil {
srvc.OnDisconnect(peer) srvc.OnDisconnect(peer)
@ -197,7 +197,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
Chan: reflect.ValueOf(peerPipe), Chan: reflect.ValueOf(peerPipe),
}) })
addPoll := func(channel chan *cnpeer.PacketEvent) { addPoll := func(channel chan *cnet.PacketEvent) {
poll = append(poll, reflect.SelectCase{ poll = append(poll, reflect.SelectCase{
Dir: reflect.SelectRecv, Dir: reflect.SelectRecv,
Chan: reflect.ValueOf(channel), Chan: reflect.ValueOf(channel),
@ -222,7 +222,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
addPoll(evnt.channel) addPoll(evnt.channel)
srvc.connect(evnt.channel, evnt.peer) srvc.connect(evnt.channel, evnt.peer)
default: // peer event default: // peer event
channel := poll[chosen].Chan.Interface().(chan *cnpeer.PacketEvent) channel := poll[chosen].Chan.Interface().(chan *cnet.PacketEvent)
peer := srvc.getPeer(channel) peer := srvc.getPeer(channel)
if peer == nil { if peer == nil {
log.Printf("Unknown peer event: %v", value) log.Printf("Unknown peer event: %v", value)
@ -230,7 +230,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
continue continue
} }
evnt, ok := value.Interface().(*cnpeer.PacketEvent) evnt, ok := value.Interface().(*cnet.PacketEvent)
if !recvOK || !ok || evnt == nil { if !recvOK || !ok || evnt == nil {
// peer disconnected, remove it from our poll queue // peer disconnected, remove it from our poll queue
removePoll(chosen) removePoll(chosen)
@ -251,7 +251,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
} }
} }
func (srvc *Service) handlePacket(peer *cnpeer.CNPeer, typeID uint32, pkt protocol.Packet) error { func (srvc *Service) handlePacket(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, typeID uint32, pkt protoc
return nil return nil
} }
func (srvc *Service) disconnect(channel chan *cnpeer.PacketEvent, peer *cnpeer.CNPeer) { func (srvc *Service) disconnect(channel chan *cnet.PacketEvent, peer *cnet.CNPeer) {
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 *cnpeer.PacketEvent, peer *cnpeer.C
srvc.removePeer(channel) srvc.removePeer(channel)
} }
func (srvc *Service) connect(channel chan *cnpeer.PacketEvent, peer *cnpeer.CNPeer) { func (srvc *Service) connect(channel chan *cnet.PacketEvent, peer *cnet.CNPeer) {
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

@ -10,7 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
"github.com/CPunch/gopenfusion/internal/service" "github.com/CPunch/gopenfusion/internal/service"
"github.com/matryer/is" "github.com/matryer/is"
@ -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 *cnpeer.CNPeer, pkt protocol.Packet) error { srvc.AddPacketHandler(0x1234, func(peer *cnet.CNPeer, 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 *cnpeer.CNPeer) { srvc.OnConnect = func(peer *cnet.CNPeer) {
wg.Done() wg.Done()
} }
wg.Add(maxDummyPeers) wg.Add(maxDummyPeers)
srvc.OnDisconnect = func(peer *cnpeer.CNPeer) { srvc.OnDisconnect = func(peer *cnet.CNPeer) {
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 := cnpeer.NewCNPeer(ctx, conn) peer := cnet.NewCNPeer(ctx, conn)
go func() { go func() {
defer peer.Kill() defer peer.Kill()
@ -107,7 +107,7 @@ func TestService(t *testing.T) {
}() }()
// we wait until Handler gracefully exits (peer was killed) // we wait until Handler gracefully exits (peer was killed)
peer.Handler(make(chan *cnpeer.PacketEvent)) peer.Handler(make(chan *cnet.PacketEvent))
wg.Done() wg.Done()
}() }()
} }

View File

@ -7,7 +7,7 @@ import (
"log" "log"
"math/rand" "math/rand"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/config" "github.com/CPunch/gopenfusion/config"
"github.com/CPunch/gopenfusion/internal/db" "github.com/CPunch/gopenfusion/internal/db"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
@ -27,7 +27,7 @@ const (
LOGIN_UPDATED_EUALA_REQUIRED = 9 LOGIN_UPDATED_EUALA_REQUIRED = 9
) )
func (server *LoginServer) AcceptLogin(peer *cnpeer.CNPeer, SzID string, IClientVerC int32, ISlotNum int8, data []protocol.SP_LS2CL_REP_CHAR_INFO) error { func (server *LoginServer) AcceptLogin(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, SzID string, IClient
return nil return nil
} }
func (server *LoginServer) Login(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) Login(peer *cnet.CNPeer, 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 *cnpeer.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 *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) CheckCharacterName(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.
}) })
} }
func (server *LoginServer) SaveCharacterName(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) SaveCharacterName(peer *cnet.CNPeer, 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 *cnpeer.CNPeer) error { func SendFail(peer *cnet.CNPeer) 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 *cnpeer.CNPeer) error {
return nil return nil
} }
func (server *LoginServer) CharacterCreate(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) CharacterCreate(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.Pac
}) })
} }
func (server *LoginServer) CharacterDelete(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) CharacterDelete(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.Pac
}) })
} }
func (server *LoginServer) ShardSelect(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) ShardSelect(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.Packet)
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 *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *LoginServer) FinishTutorial(peer *cnet.CNPeer, 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

@ -3,12 +3,12 @@ package shard
import ( import (
"fmt" "fmt"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
"github.com/CPunch/gopenfusion/shard/entity" "github.com/CPunch/gopenfusion/shard/entity"
) )
func (server *ShardServer) freeChat(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) freeChat(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.Packet) er
}) })
} }
func (server *ShardServer) menuChat(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) menuChat(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.Packet) er
}) })
} }
func (server *ShardServer) emoteChat(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) emoteChat(peer *cnet.CNPeer, 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

@ -1,6 +1,6 @@
package entity package entity
import "github.com/CPunch/gopenfusion/cnpeer" import "github.com/CPunch/gopenfusion/cnet"
type EntityKind int type EntityKind int
@ -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 *cnpeer.CNPeer) DisappearFromViewOf(peer *cnet.CNPeer)
EnterIntoViewOf(peer *cnpeer.CNPeer) EnterIntoViewOf(peer *cnet.CNPeer)
} }

View File

@ -3,7 +3,7 @@ package entity
import ( import (
"sync/atomic" "sync/atomic"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
) )
@ -63,13 +63,13 @@ func (npc *NPC) SetAngle(angle int) {
npc.Angle = angle npc.Angle = angle
} }
func (npc *NPC) DisappearFromViewOf(peer *cnpeer.CNPeer) { func (npc *NPC) DisappearFromViewOf(peer *cnet.CNPeer) {
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 *cnpeer.CNPeer) { func (npc *NPC) EnterIntoViewOf(peer *cnet.CNPeer) {
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

@ -1,18 +1,18 @@
package entity package entity
import ( import (
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/internal/db" "github.com/CPunch/gopenfusion/internal/db"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
) )
type Player struct { type Player struct {
db.Player db.Player
Peer *cnpeer.CNPeer Peer *cnet.CNPeer
Chunk ChunkPosition Chunk ChunkPosition
} }
func NewPlayer(peer *cnpeer.CNPeer, player *db.Player) *Player { func NewPlayer(peer *cnet.CNPeer, 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 *cnpeer.CNPeer) { func (plr *Player) DisappearFromViewOf(peer *cnet.CNPeer) {
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 *cnpeer.CNPeer) { func (plr *Player) EnterIntoViewOf(peer *cnet.CNPeer) {
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

@ -4,14 +4,14 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
"github.com/CPunch/gopenfusion/internal/redis" "github.com/CPunch/gopenfusion/internal/redis"
"github.com/CPunch/gopenfusion/shard/entity" "github.com/CPunch/gopenfusion/shard/entity"
"github.com/CPunch/gopenfusion/util" "github.com/CPunch/gopenfusion/util"
) )
func (server *ShardServer) attachPlayer(peer *cnpeer.CNPeer, meta redis.LoginMetadata) (*entity.Player, error) { func (server *ShardServer) attachPlayer(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, meta redis.LoginMet
return plr, nil return plr, nil
} }
func (server *ShardServer) RequestEnter(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) RequestEnter(peer *cnet.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)
@ -57,7 +57,7 @@ func (server *ShardServer) RequestEnter(peer *cnpeer.CNPeer, pkt protocol.Packet
// setup peer // setup peer
peer.E_key = protocol.CreateNewKey(resp.UiSvrTime, uint64(resp.IID+1), uint64(resp.PCLoadData2CL.IFusionMatter+1)) peer.E_key = protocol.CreateNewKey(resp.UiSvrTime, uint64(resp.IID+1), uint64(resp.PCLoadData2CL.IFusionMatter+1))
peer.FE_key = loginData.FEKey peer.FE_key = loginData.FEKey
peer.SetActiveKey(cnpeer.USE_FE) peer.SetActiveKey(cnet.USE_FE)
log.Printf("Player %d (AccountID %d) entered\n", resp.IID, loginData.AccountID) log.Printf("Player %d (AccountID %d) entered\n", resp.IID, loginData.AccountID)
if err := peer.Send(protocol.P_FE2CL_REP_PC_ENTER_SUCC, resp); err != nil { if err := peer.Send(protocol.P_FE2CL_REP_PC_ENTER_SUCC, resp); err != nil {
@ -67,7 +67,7 @@ func (server *ShardServer) RequestEnter(peer *cnpeer.CNPeer, pkt protocol.Packet
return nil return nil
} }
func (server *ShardServer) LoadingComplete(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) LoadingComplete(peer *cnet.CNPeer, 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

@ -3,7 +3,7 @@ package shard
import ( import (
"fmt" "fmt"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
"github.com/CPunch/gopenfusion/shard/entity" "github.com/CPunch/gopenfusion/shard/entity"
"github.com/CPunch/gopenfusion/util" "github.com/CPunch/gopenfusion/util"
@ -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 *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) playerMove(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.Packet)
}) })
} }
func (server *ShardServer) playerStop(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) playerStop(peer *cnet.CNPeer, 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 *cnpeer.CNPeer, pkt protocol.Packet)
}) })
} }
func (server *ShardServer) playerJump(peer *cnpeer.CNPeer, pkt protocol.Packet) error { func (server *ShardServer) playerJump(peer *cnet.CNPeer, 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

@ -3,7 +3,7 @@ package shard
import ( import (
"context" "context"
"github.com/CPunch/gopenfusion/cnpeer" "github.com/CPunch/gopenfusion/cnet"
"github.com/CPunch/gopenfusion/config" "github.com/CPunch/gopenfusion/config"
"github.com/CPunch/gopenfusion/internal/db" "github.com/CPunch/gopenfusion/internal/db"
"github.com/CPunch/gopenfusion/internal/protocol" "github.com/CPunch/gopenfusion/internal/protocol"
@ -12,7 +12,7 @@ import (
"github.com/CPunch/gopenfusion/shard/entity" "github.com/CPunch/gopenfusion/shard/entity"
) )
type PacketHandler func(peer *cnpeer.CNPeer, pkt protocol.Packet) error type PacketHandler func(peer *cnet.CNPeer, 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 *cnpeer.CNPeer) { func (server *ShardServer) onDisconnect(peer *cnet.CNPeer) {
// 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 *cnpeer.CNPeer) {
} }
} }
func (server *ShardServer) onConnect(peer *cnpeer.CNPeer) { func (server *ShardServer) onConnect(peer *cnet.CNPeer) {
} }