添加client测试端
This commit is contained in:
parent
3752feb4ef
commit
1e02964ec5
27
test/client/server/login.go
Normal file
27
test/client/server/login.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"game/common/proto/pb"
|
||||||
|
"github.com/fox/fox/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *ClientService) login() {
|
||||||
|
s.SendMsg(pb.ServiceTypeId_STI_Login, int32(pb.MsgId_C2SUserLoginId), &pb.C2SUserLogin{
|
||||||
|
Username: s.username,
|
||||||
|
Password: s.password,
|
||||||
|
Ip: "",
|
||||||
|
DeviceId: "",
|
||||||
|
Version: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 收到登陆成功消息,判断是否顶号
|
||||||
|
func (s *ClientService) onLogin(cMsg *pb.ClientMsg, msg *pb.S2CUserLogin) {
|
||||||
|
if msg.Code != pb.ErrCode_OK {
|
||||||
|
log.ErrorF("login error: %v", msg.Code)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_ = cMsg
|
||||||
|
s.userId = msg.UserId
|
||||||
|
log.DebugF("user:%v id:%v login success", s.username, msg.UserId)
|
||||||
|
}
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
func (s *ClientService) initProcessor() {
|
func (s *ClientService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.processor.RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_C2SChatId: {pb.C2SChat{}, s.onChat},
|
pb.MsgId_S2CUserLoginId: {pb.S2CUserLogin{}, s.onLogin},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,12 @@ import (
|
|||||||
var Clients []*ClientService
|
var Clients []*ClientService
|
||||||
|
|
||||||
type ClientService struct {
|
type ClientService struct {
|
||||||
client *ws.Client
|
client *ws.Client
|
||||||
processor *processor.Processor
|
processor *processor.Processor
|
||||||
userId int64
|
userId int64
|
||||||
|
username string
|
||||||
|
password string
|
||||||
|
lastServiceName string // 最近使用的服务的节点
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@ -37,6 +40,8 @@ func newClientService(serviceId int) *ClientService {
|
|||||||
var err error
|
var err error
|
||||||
s := new(ClientService)
|
s := new(ClientService)
|
||||||
|
|
||||||
|
s.username = fmt.Sprintf("test%04d", serviceId)
|
||||||
|
s.password = "123456"
|
||||||
size := len(config.Cfg.Special.Address)
|
size := len(config.Cfg.Special.Address)
|
||||||
addr := config.Cfg.Special.Address[serviceId%size]
|
addr := config.Cfg.Special.Address[serviceId%size]
|
||||||
if s.client, err = ws.NewClient(fmt.Sprintf("ws://%v", addr), s); err != nil {
|
if s.client, err = ws.NewClient(fmt.Sprintf("ws://%v", addr), s); err != nil {
|
||||||
@ -66,7 +71,7 @@ func (s *ClientService) OnMessage(data []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if req, err := s.processor.Unmarshal(cMsg.MsgId, cMsg.Data); err == nil {
|
if req, err := s.processor.Unmarshal(cMsg.MsgId, cMsg.Data); err == nil {
|
||||||
err = s.processor.Dispatch(cMsg.MsgId, cMsg.UserId, cMsg, req)
|
err = s.processor.Dispatch(cMsg.MsgId, cMsg, req)
|
||||||
}
|
}
|
||||||
//log.Debug(s.Log("on message:%v", string(cMsg)))
|
//log.Debug(s.Log("on message:%v", string(cMsg)))
|
||||||
return nil
|
return nil
|
||||||
@ -76,7 +81,7 @@ func (s *ClientService) OnMessage(data []byte) error {
|
|||||||
func (s *ClientService) SendData(serviceTypeId pb.ServiceTypeId, msgId int32, data []byte) {
|
func (s *ClientService) SendData(serviceTypeId pb.ServiceTypeId, msgId int32, data []byte) {
|
||||||
msg := &pb.ClientMsg{
|
msg := &pb.ClientMsg{
|
||||||
ServiceTid: serviceTypeId,
|
ServiceTid: serviceTypeId,
|
||||||
ServiceName: "",
|
ServiceName: s.lastServiceName,
|
||||||
UserId: s.userId,
|
UserId: s.userId,
|
||||||
MsgId: msgId,
|
MsgId: msgId,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user