mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-24 00:00:18 +00:00
rename cnpeer package to cnet
This commit is contained in:
parent
e1804a1042
commit
c60017f78f
@ -1,4 +1,4 @@
|
||||
package cnpeer
|
||||
package cnet
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -10,14 +10,14 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"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
|
||||
}
|
||||
|
||||
@ -29,18 +29,18 @@ type Service struct {
|
||||
started chan struct{}
|
||||
stopped chan struct{}
|
||||
packetHandlers map[uint32]PacketHandler
|
||||
peers map[chan *cnpeer.PacketEvent]*cnpeer.CNPeer
|
||||
peers map[chan *cnet.PacketEvent]*cnet.CNPeer
|
||||
stateLock sync.Mutex
|
||||
|
||||
// OnDisconnect is called when a peer disconnects from the service.
|
||||
// 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)
|
||||
OnDisconnect func(peer *cnpeer.CNPeer)
|
||||
OnDisconnect func(peer *cnet.CNPeer)
|
||||
|
||||
// OnConnect is called when a peer connects to the service.
|
||||
// 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)
|
||||
OnConnect func(peer *cnpeer.CNPeer)
|
||||
OnConnect func(peer *cnet.CNPeer)
|
||||
}
|
||||
|
||||
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) {
|
||||
srvc.ctx = ctx
|
||||
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.stopped = make(chan struct{})
|
||||
}
|
||||
@ -81,8 +81,8 @@ func (srvc *Service) AddPacketHandler(pktID uint32, handler PacketHandler) {
|
||||
}
|
||||
|
||||
type newPeerConnection struct {
|
||||
peer *cnpeer.CNPeer
|
||||
channel chan *cnpeer.PacketEvent
|
||||
peer *cnet.CNPeer
|
||||
channel chan *cnet.PacketEvent
|
||||
}
|
||||
|
||||
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
|
||||
peer := cnpeer.NewCNPeer(srvc.ctx, conn)
|
||||
eRecv := make(chan *cnpeer.PacketEvent)
|
||||
peer := cnet.NewCNPeer(srvc.ctx, conn)
|
||||
eRecv := make(chan *cnet.PacketEvent)
|
||||
peerConnections <- newPeerConnection{channel: eRecv, peer: peer}
|
||||
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]
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (srvc *Service) removePeer(channel chan *cnpeer.PacketEvent) {
|
||||
func (srvc *Service) removePeer(channel chan *cnet.PacketEvent) {
|
||||
delete(srvc.peers, channel)
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ func (srvc *Service) Stopped() <-chan struct{} {
|
||||
// if f returns false, the iteration is stopped.
|
||||
// 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.
|
||||
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 {
|
||||
if !f(peer) {
|
||||
break
|
||||
@ -168,7 +168,7 @@ func (srvc *Service) Unlock() {
|
||||
|
||||
func (srvc *Service) stop() {
|
||||
// OnDisconnect handler might need to do something important
|
||||
srvc.RangePeers(func(peer *cnpeer.CNPeer) bool {
|
||||
srvc.RangePeers(func(peer *cnet.CNPeer) bool {
|
||||
peer.Kill()
|
||||
if srvc.OnDisconnect != nil {
|
||||
srvc.OnDisconnect(peer)
|
||||
@ -197,7 +197,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
|
||||
Chan: reflect.ValueOf(peerPipe),
|
||||
})
|
||||
|
||||
addPoll := func(channel chan *cnpeer.PacketEvent) {
|
||||
addPoll := func(channel chan *cnet.PacketEvent) {
|
||||
poll = append(poll, reflect.SelectCase{
|
||||
Dir: reflect.SelectRecv,
|
||||
Chan: reflect.ValueOf(channel),
|
||||
@ -222,7 +222,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
|
||||
addPoll(evnt.channel)
|
||||
srvc.connect(evnt.channel, evnt.peer)
|
||||
default: // peer event
|
||||
channel := poll[chosen].Chan.Interface().(chan *cnpeer.PacketEvent)
|
||||
channel := poll[chosen].Chan.Interface().(chan *cnet.PacketEvent)
|
||||
peer := srvc.getPeer(channel)
|
||||
if peer == nil {
|
||||
log.Printf("Unknown peer event: %v", value)
|
||||
@ -230,7 +230,7 @@ func (srvc *Service) handleEvents(peerPipe <-chan newPeerConnection) {
|
||||
continue
|
||||
}
|
||||
|
||||
evnt, ok := value.Interface().(*cnpeer.PacketEvent)
|
||||
evnt, ok := value.Interface().(*cnet.PacketEvent)
|
||||
if !recvOK || !ok || evnt == nil {
|
||||
// peer disconnected, remove it from our poll queue
|
||||
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 {
|
||||
// fmt.Printf("Handling packet %x\n", typeID)
|
||||
if err := hndlr(peer, pkt); err != nil {
|
||||
@ -264,7 +264,7 @@ func (srvc *Service) handlePacket(peer *cnpeer.CNPeer, typeID uint32, pkt protoc
|
||||
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)
|
||||
if srvc.OnDisconnect != nil {
|
||||
srvc.OnDisconnect(peer)
|
||||
@ -273,7 +273,7 @@ func (srvc *Service) disconnect(channel chan *cnpeer.PacketEvent, peer *cnpeer.C
|
||||
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)
|
||||
if srvc.OnConnect != nil {
|
||||
srvc.OnConnect(peer)
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
"github.com/CPunch/gopenfusion/internal/service"
|
||||
"github.com/matryer/is"
|
||||
@ -68,7 +68,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// our dummy packet handler
|
||||
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)
|
||||
wg.Done()
|
||||
return nil
|
||||
@ -76,12 +76,12 @@ func TestService(t *testing.T) {
|
||||
|
||||
// wait for all dummy peers to connect and disconnect
|
||||
wg.Add(maxDummyPeers)
|
||||
srvc.OnConnect = func(peer *cnpeer.CNPeer) {
|
||||
srvc.OnConnect = func(peer *cnet.CNPeer) {
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
wg.Add(maxDummyPeers)
|
||||
srvc.OnDisconnect = func(peer *cnpeer.CNPeer) {
|
||||
srvc.OnDisconnect = func(peer *cnet.CNPeer) {
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func TestService(t *testing.T) {
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", srvcPort))
|
||||
is.NoErr(err) // net.Dial error
|
||||
|
||||
peer := cnpeer.NewCNPeer(ctx, conn)
|
||||
peer := cnet.NewCNPeer(ctx, conn)
|
||||
go func() {
|
||||
defer peer.Kill()
|
||||
|
||||
@ -107,7 +107,7 @@ func TestService(t *testing.T) {
|
||||
}()
|
||||
|
||||
// we wait until Handler gracefully exits (peer was killed)
|
||||
peer.Handler(make(chan *cnpeer.PacketEvent))
|
||||
peer.Handler(make(chan *cnet.PacketEvent))
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/internal/db"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
@ -27,7 +27,7 @@ const (
|
||||
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{
|
||||
SzID: SzID,
|
||||
ICharCount: int8(len(data)),
|
||||
@ -63,7 +63,7 @@ func (server *LoginServer) AcceptLogin(peer *cnpeer.CNPeer, SzID string, IClient
|
||||
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
|
||||
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)])
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
pkt.Decode(&charPkt)
|
||||
|
||||
@ -203,7 +203,7 @@ func validateCharacterCreation(character *protocol.SP_CL2LS_REQ_CHAR_CREATE) boo
|
||||
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{
|
||||
IErrorCode: 2,
|
||||
}); err != nil {
|
||||
@ -213,7 +213,7 @@ func SendFail(peer *cnpeer.CNPeer) error {
|
||||
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
|
||||
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
|
||||
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
|
||||
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)
|
||||
}
|
||||
|
||||
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
|
||||
pkt.Decode(&charPkt)
|
||||
|
||||
|
@ -3,12 +3,12 @@ package shard
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
"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
|
||||
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
|
||||
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
|
||||
pkt.Decode(&chat)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "github.com/CPunch/gopenfusion/cnpeer"
|
||||
import "github.com/CPunch/gopenfusion/cnet"
|
||||
|
||||
type EntityKind int
|
||||
|
||||
@ -20,6 +20,6 @@ type Entity interface {
|
||||
SetPosition(x, y, z int)
|
||||
SetAngle(angle int)
|
||||
|
||||
DisappearFromViewOf(peer *cnpeer.CNPeer)
|
||||
EnterIntoViewOf(peer *cnpeer.CNPeer)
|
||||
DisappearFromViewOf(peer *cnet.CNPeer)
|
||||
EnterIntoViewOf(peer *cnet.CNPeer)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package entity
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
)
|
||||
|
||||
@ -63,13 +63,13 @@ func (npc *NPC) SetAngle(angle int) {
|
||||
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{
|
||||
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{
|
||||
NPCAppearanceData: npc.GetAppearanceData(),
|
||||
})
|
||||
|
@ -1,18 +1,18 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/internal/db"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
db.Player
|
||||
Peer *cnpeer.CNPeer
|
||||
Peer *cnet.CNPeer
|
||||
Chunk ChunkPosition
|
||||
}
|
||||
|
||||
func NewPlayer(peer *cnpeer.CNPeer, player *db.Player) *Player {
|
||||
func NewPlayer(peer *cnet.CNPeer, player *db.Player) *Player {
|
||||
return &Player{
|
||||
Player: *player,
|
||||
Peer: peer,
|
||||
@ -52,13 +52,13 @@ func (plr *Player) SetAngle(angle int) {
|
||||
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{
|
||||
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{
|
||||
PCAppearanceData: plr.GetAppearanceData(),
|
||||
})
|
||||
|
@ -4,14 +4,14 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
"github.com/CPunch/gopenfusion/internal/redis"
|
||||
"github.com/CPunch/gopenfusion/shard/entity"
|
||||
"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))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -26,7 +26,7 @@ func (server *ShardServer) attachPlayer(peer *cnpeer.CNPeer, meta redis.LoginMet
|
||||
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
|
||||
pkt.Decode(&enter)
|
||||
|
||||
@ -57,7 +57,7 @@ func (server *ShardServer) RequestEnter(peer *cnpeer.CNPeer, pkt protocol.Packet
|
||||
// setup peer
|
||||
peer.E_key = protocol.CreateNewKey(resp.UiSvrTime, uint64(resp.IID+1), uint64(resp.PCLoadData2CL.IFusionMatter+1))
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
pkt.Decode(&loadComplete)
|
||||
|
||||
|
@ -3,7 +3,7 @@ package shard
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
"github.com/CPunch/gopenfusion/shard/entity"
|
||||
"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))
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
pkt.Decode(&jump)
|
||||
|
||||
|
@ -3,7 +3,7 @@ package shard
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/CPunch/gopenfusion/cnpeer"
|
||||
"github.com/CPunch/gopenfusion/cnet"
|
||||
"github.com/CPunch/gopenfusion/config"
|
||||
"github.com/CPunch/gopenfusion/internal/db"
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"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 {
|
||||
service *service.Service
|
||||
@ -56,7 +56,7 @@ func (server *ShardServer) Start() {
|
||||
server.service.Start()
|
||||
}
|
||||
|
||||
func (server *ShardServer) onDisconnect(peer *cnpeer.CNPeer) {
|
||||
func (server *ShardServer) onDisconnect(peer *cnet.CNPeer) {
|
||||
// remove from chunks
|
||||
plr, ok := peer.UserData().(*entity.Player)
|
||||
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) {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user