根据框架调整
This commit is contained in:
parent
89557ad9e4
commit
4bda8b1825
@ -1,38 +0,0 @@
|
||||
package model
|
||||
|
||||
// 该类将玩家与网关绑定以及保存token这些事情混在一起了,绑定关系由userBindService提供。token这些由login服提供
|
||||
|
||||
//type UserGate struct {
|
||||
// GateName string `json:"gate_name"`
|
||||
// Token string `json:"token"`
|
||||
// OnlineTime utils.Time `json:"online"`
|
||||
// rdb *redis.Client
|
||||
//}
|
||||
//
|
||||
//func NewUserGate() *UserGate {
|
||||
// return &UserGate{rdb: UserRedis}
|
||||
//}
|
||||
//
|
||||
//func (u *UserGate) key(userId int64, gateId string) string {
|
||||
// return fmt.Sprintf("gateway:%v:%v", gateId, userId)
|
||||
//}
|
||||
//
|
||||
//func (u *UserGate) Set(userId int64, gateId string, token string) {
|
||||
// u.GateName = gateId
|
||||
// u.Token = token
|
||||
// u.OnlineTime = utils.Time(time.Now())
|
||||
// u.rdb.Set(context.Background(), u.key(userId, gateId), utils.Marshal(u), time.Hour*24)
|
||||
//}
|
||||
//
|
||||
//func (u *UserGate) Get(userId int64, gateId string) (*UserGate, error) {
|
||||
// s, err := u.rdb.Get(context.Background(), u.key(userId, gateId)).Result()
|
||||
// if err != nil {
|
||||
// return u, err
|
||||
// }
|
||||
// err = json.Unmarshal([]byte(s), u)
|
||||
// return u, err
|
||||
//}
|
||||
//
|
||||
//func (u *UserGate) Del(userId int64, gateId string) {
|
||||
// _, _ = u.rdb.Del(context.Background(), u.key(userId, gateId)).Result()
|
||||
//}
|
@ -1,22 +0,0 @@
|
||||
package model
|
||||
|
||||
//const (
|
||||
// userId = 1111
|
||||
// gateId = "gate-1"
|
||||
// token = "token"
|
||||
//)
|
||||
//
|
||||
//func TestUserGate(t *testing.T) {
|
||||
// UserRedis, err = db.InitRedis(testHelper.RedisPassword, testHelper.Host, testHelper.RedisPort, 0)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// var ug *UserGate
|
||||
// ug, err = NewUserGate().Get(userId, gateId)
|
||||
// if err != nil {
|
||||
// t.Log(err)
|
||||
// ug.Set(userId, gateId, token)
|
||||
// ug, _ = NewUserGate().Get(userId, gateId)
|
||||
// }
|
||||
// t.Logf("user_gate:%v", utils.Marshal(ug))
|
||||
//}
|
@ -151,15 +151,15 @@ func (s *GateService) OnMessage(data []byte) error {
|
||||
/*
|
||||
查找topic,根据serviceTypeId以及玩家id查找玩家过往访问该服务的节点,优先使用原节点
|
||||
*/
|
||||
func (s *GateService) findTopic(userId int64, serviceTypeId pb.ServiceTypeId) string {
|
||||
func (s *GateService) findTopic(userId int64, serviceTypeId pb.ServiceTypeId) (topic, sName string) {
|
||||
if userId != 0 {
|
||||
if sName, err := s.bindService.FindServiceName(userId, serviceTypeId); err == nil {
|
||||
return service.TopicEx(sName)
|
||||
return service.TopicEx(sName), sName
|
||||
} else {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return "", sName
|
||||
}
|
||||
|
||||
// 运行在conn的read协程里。将消息转发给内部服务
|
||||
@ -173,7 +173,7 @@ func (s *GateService) WsOnMessage(conn ws.IConn, data []byte) {
|
||||
if msg.ServiceName != "" {
|
||||
topic = service.TopicEx(msg.ServiceName)
|
||||
} else {
|
||||
topic = s.findTopic(conn.UserId(), msg.ServiceTid)
|
||||
topic, msg.ServiceName = s.findTopic(conn.UserId(), msg.ServiceTid)
|
||||
}
|
||||
if topic != "" {
|
||||
s.SendServiceData(topic, conn, msg.MsgId, msg.Data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user