添加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() {
|
||||
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
|
||||
|
||||
type ClientService struct {
|
||||
client *ws.Client
|
||||
processor *processor.Processor
|
||||
userId int64
|
||||
client *ws.Client
|
||||
processor *processor.Processor
|
||||
userId int64
|
||||
username string
|
||||
password string
|
||||
lastServiceName string // 最近使用的服务的节点
|
||||
}
|
||||
|
||||
func Init() {
|
||||
@ -37,6 +40,8 @@ func newClientService(serviceId int) *ClientService {
|
||||
var err error
|
||||
s := new(ClientService)
|
||||
|
||||
s.username = fmt.Sprintf("test%04d", serviceId)
|
||||
s.password = "123456"
|
||||
size := len(config.Cfg.Special.Address)
|
||||
addr := config.Cfg.Special.Address[serviceId%size]
|
||||
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
|
||||
}
|
||||
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)))
|
||||
return nil
|
||||
@ -76,7 +81,7 @@ func (s *ClientService) OnMessage(data []byte) error {
|
||||
func (s *ClientService) SendData(serviceTypeId pb.ServiceTypeId, msgId int32, data []byte) {
|
||||
msg := &pb.ClientMsg{
|
||||
ServiceTid: serviceTypeId,
|
||||
ServiceName: "",
|
||||
ServiceName: s.lastServiceName,
|
||||
UserId: s.userId,
|
||||
MsgId: msgId,
|
||||
Data: data,
|
||||
|
Loading…
x
Reference in New Issue
Block a user