mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-12 19:20:06 +00:00
CPunch
c0ba365cf5
- each CNPeer is given a unique chan *protocol.Event to pass events to the service.handleEvents() loop. this is now passed to CNPeer.Handler() as opposed to NewCNPeer(). - service has basically been rewritten. handleEvents() main loop uses reflect.SelectCase() now to handle all of the eRecv channels for each peer - new protocol Event type: EVENT_CLIENT_CONNECT - Added service_test.go; blackbox-styled testing like the others. TestService() starts a service and spins up a bunch of dummy peers and verifies that each packet sent causes the corresponding packet handler to be called.
53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package login
|
|
|
|
import (
|
|
"github.com/CPunch/gopenfusion/internal/db"
|
|
"github.com/CPunch/gopenfusion/internal/protocol"
|
|
"github.com/CPunch/gopenfusion/internal/redis"
|
|
"github.com/CPunch/gopenfusion/internal/service"
|
|
)
|
|
|
|
type LoginServer struct {
|
|
service *service.Service
|
|
dbHndlr *db.DBHandler
|
|
redisHndlr *redis.RedisHandler
|
|
}
|
|
|
|
func NewLoginServer(dbHndlr *db.DBHandler, redisHndlr *redis.RedisHandler, port int) (*LoginServer, error) {
|
|
srvc := service.NewService("LOGIN", port)
|
|
|
|
server := &LoginServer{
|
|
service: srvc,
|
|
dbHndlr: dbHndlr,
|
|
redisHndlr: redisHndlr,
|
|
}
|
|
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_LOGIN, server.Login)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_CHECK_CHAR_NAME, server.CheckCharacterName)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_SAVE_CHAR_NAME, server.SaveCharacterName)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_CHAR_CREATE, server.CharacterCreate)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_CHAR_SELECT, server.ShardSelect)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_CHAR_DELETE, server.CharacterDelete)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_SHARD_SELECT, service.StubbedPacket)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_SHARD_LIST_INFO, service.StubbedPacket)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_CHECK_NAME_LIST, service.StubbedPacket)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_SAVE_CHAR_TUTOR, server.FinishTutorial)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_PC_EXIT_DUPLICATE, service.StubbedPacket)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REP_LIVE_CHECK, service.StubbedPacket)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_CHANGE_CHAR_NAME, service.StubbedPacket)
|
|
srvc.AddPacketHandler(protocol.P_CL2LS_REQ_SERVER_SELECT, service.StubbedPacket)
|
|
|
|
srvc.OnConnect = func(peer *protocol.CNPeer) interface{} {
|
|
return nil
|
|
}
|
|
|
|
return server, nil
|
|
}
|
|
|
|
func (server *LoginServer) Start() error {
|
|
return server.service.Start()
|
|
}
|
|
|
|
func (server *LoginServer) Stop() {
|
|
server.service.Stop()
|
|
} |