修改bug
This commit is contained in:
parent
b596e502ee
commit
e7cb90ed63
@ -159,7 +159,7 @@ func (r *BaseRoom[Seat]) SendMsg(user IPlayer, msgId pb.MsgId, msg proto.Message
|
||||
user.Robot().OnMessage(msgId, msg)
|
||||
} else {
|
||||
iMsg := ipb.MakeMsgEx(r.srv.Name(), 0, user.Id(), int32(msgId), msg)
|
||||
_ = r.srv.Send(user.GateTopicName(), iMsg)
|
||||
_ = r.srv.SendByTopic(user.GateTopicName(), iMsg)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ func (r *HundredRoom) SendMsg(user IPlayer, msgId pb.MsgId, msg proto.Message) {
|
||||
user.Robot().OnMessage(msgId, msg)
|
||||
} else {
|
||||
iMsg := ipb.MakeMsgEx(r.room.srv.Name(), 0, user.Id(), int32(msgId), msg)
|
||||
_ = r.room.srv.Send(user.GateTopicName(), iMsg)
|
||||
_ = r.room.srv.SendByTopic(user.GateTopicName(), iMsg)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,18 @@ package gameService
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/config"
|
||||
"game/common/constant"
|
||||
"game/common/proto/pb"
|
||||
"game/common/userBindService"
|
||||
"game/server/colorgame/model"
|
||||
"game/common/utils"
|
||||
"github.com/fox/fox/db"
|
||||
"github.com/fox/fox/etcd"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/fox/fox/processor"
|
||||
"github.com/fox/fox/service"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"time"
|
||||
)
|
||||
@ -20,7 +24,7 @@ type GameService struct {
|
||||
bindService *userBindService.UserBindService
|
||||
}
|
||||
|
||||
func NewGameService(param *service.InitNatsServiceParams) *GameService {
|
||||
func NewGameService(param *service.InitNatsServiceParams, cfgRedis *config.Redis) *GameService {
|
||||
var err error
|
||||
s := new(GameService)
|
||||
s.NatsService, err = service.NewNatsService(param)
|
||||
@ -28,7 +32,14 @@ func NewGameService(param *service.InitNatsServiceParams) *GameService {
|
||||
log.Fatal(err.Error())
|
||||
return nil
|
||||
}
|
||||
s.bindService = userBindService.NewUserBindService(model.UserBindServiceRedis, s.ServiceEtcd())
|
||||
var userBindServiceRedis *redis.Client
|
||||
userBindServiceRedis, err = db.InitRedis(cfgRedis.Password, cfgRedis.Host, cfgRedis.Port, constant.Redis3UserBindService)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return nil
|
||||
}
|
||||
utils.AutoSetRedisPool(userBindServiceRedis)
|
||||
s.bindService = userBindService.NewUserBindService(userBindServiceRedis, s.ServiceEtcd())
|
||||
s.processor = processor.NewProcessor()
|
||||
return s
|
||||
}
|
||||
@ -65,9 +76,13 @@ func (s *GameService) SendServiceMsg(sid pb.ServiceTypeId, userId int64, msgId i
|
||||
return
|
||||
}
|
||||
topic := service.TopicEx(node.Name)
|
||||
s.SendServiceMsgByTopic(topic, 0, userId, msgId, msg)
|
||||
}
|
||||
|
||||
func (s *GameService) SendServiceMsgByTopic(topic string, connId uint32, userId int64, msgId int32, msg proto.Message) {
|
||||
log.DebugF("send to:%v msg id:%v, msg:%v", topic, pb.MsgId(msgId), msg.String())
|
||||
data, _ := proto.Marshal(msg)
|
||||
s.SendServiceData(topic, 0, userId, msgId, data)
|
||||
s.SendServiceData(topic, connId, userId, msgId, data)
|
||||
}
|
||||
|
||||
// 向内部服务发送消息
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
UserBindServiceRedis *redis.Client
|
||||
//UserBindServiceRedis *redis.Client
|
||||
UserRedis *redis.Client
|
||||
)
|
||||
|
||||
@ -18,12 +18,12 @@ func InitRedis() {
|
||||
log.Debug("init redis")
|
||||
var err error
|
||||
cfg := &config.Cfg.Redis
|
||||
UserBindServiceRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis3UserBindService)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return
|
||||
}
|
||||
utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
//UserBindServiceRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis3UserBindService)
|
||||
//if err != nil {
|
||||
// log.Fatal(err.Error())
|
||||
// return
|
||||
//}
|
||||
//utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
|
||||
UserRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis1User)
|
||||
if err != nil {
|
||||
|
@ -58,7 +58,7 @@ func newColorService(serviceId int) service.IService {
|
||||
OnFunc: s,
|
||||
TypeId: int(pb.ServiceTypeId_STI_ColorGame),
|
||||
Version: config.Cfg.BuildDate,
|
||||
})
|
||||
}, &config.Cfg.Redis)
|
||||
s.initProcessor()
|
||||
|
||||
s.playerMgr = baseroom.NewPlayerMgr(nil)
|
||||
|
@ -1,22 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"game/common/constant"
|
||||
"game/common/utils"
|
||||
"game/server/gate/config"
|
||||
"github.com/fox/fox/db"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
var UserBindServiceRedis *redis.Client
|
||||
var err error
|
||||
//var UserBindServiceRedis *redis.Client
|
||||
//var err error
|
||||
|
||||
func InitRedis() {
|
||||
UserBindServiceRedis, err = db.InitRedis(config.Cfg.Redis.Password, config.Cfg.Redis.Host, config.Cfg.Redis.Port, constant.Redis3UserBindService)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return
|
||||
}
|
||||
utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
//UserBindServiceRedis, err = db.InitRedis(config.Cfg.Redis.Password, config.Cfg.Redis.Host, config.Cfg.Redis.Port, constant.Redis3UserBindService)
|
||||
//if err != nil {
|
||||
// log.Fatal(err.Error())
|
||||
// return
|
||||
//}
|
||||
//utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ func (s *GateService) onUserLogin(iMsg *ipb.InternalMsg, conn ws.IConn, msg *pb.
|
||||
if sName != "" && sName != s.Name() {
|
||||
s.SendServiceMsg(service.TopicEx(sName), conn, int32(pb.MsgId_RspUserLogoutId), &pb.RspUserLogout{Code: pb.ErrCode_LoginDiffLoc})
|
||||
}
|
||||
s.BindService().SaveUserService(msg.UserId, pb.ServiceTypeId_STI_Gate, s.Name())
|
||||
// 广播玩家上线
|
||||
s.SendServiceMsg(topicName.UserOnline, conn, int32(pb.MsgId_NtfUserOnlineId), &pb.NtfUserOnline{UserId: msg.UserId})
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func newGateService(serviceId int) *GateService {
|
||||
OnFunc: s,
|
||||
TypeId: int(pb.ServiceTypeId_STI_Gate),
|
||||
Version: config.Cfg.BuildDate,
|
||||
})
|
||||
}, &config.Cfg.Redis)
|
||||
|
||||
addressPos := serviceId - config.Command.ServiceId
|
||||
if len(config.GateCfg.Address) <= addressPos {
|
||||
|
@ -1,20 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"game/common/constant"
|
||||
"game/server/lobby/config"
|
||||
"github.com/fox/fox/db"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/go-redis/redis/v8"
|
||||
var (
|
||||
// UserRedis *redis.Client
|
||||
// UserDB *gorm.DB
|
||||
// LogDB *gorm.DB
|
||||
)
|
||||
|
||||
var UserRedis *redis.Client
|
||||
var err error
|
||||
//var err error
|
||||
|
||||
func InitRedis() {
|
||||
UserRedis, err = db.InitRedis(config.Cfg.Redis.Password, config.Cfg.Redis.Host, config.Cfg.Redis.Port, constant.Redis1User)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return
|
||||
}
|
||||
//UserRedis, err = db.InitRedis(config.Cfg.Redis.Password, config.Cfg.Redis.Host, config.Cfg.Redis.Port, constant.Redis1User)
|
||||
//if err != nil {
|
||||
// log.Fatal(err.Error())
|
||||
// return
|
||||
//}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func newLobbyService(serviceId int) *LobbyService {
|
||||
OnFunc: s,
|
||||
TypeId: int(pb.ServiceTypeId_STI_Lobby),
|
||||
Version: config.Cfg.BuildDate,
|
||||
})
|
||||
}, &config.Cfg.Redis)
|
||||
|
||||
s.initProcessor()
|
||||
s.OnInit()
|
||||
|
@ -1,30 +1,25 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"game/common/constant"
|
||||
"game/common/utils"
|
||||
"game/server/login/config"
|
||||
"github.com/fox/fox/db"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
var (
|
||||
UserBindServiceRedis *redis.Client
|
||||
// UserBindServiceRedis *redis.Client
|
||||
// UserDB *gorm.DB
|
||||
// LogDB *gorm.DB
|
||||
)
|
||||
|
||||
func InitRedis() {
|
||||
log.Debug("init redis")
|
||||
var err error
|
||||
cfg := &config.Cfg.Redis
|
||||
UserBindServiceRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis3UserBindService)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return
|
||||
}
|
||||
utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
//var err error
|
||||
//cfg := &config.Cfg.Redis
|
||||
//UserBindServiceRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis3UserBindService)
|
||||
//if err != nil {
|
||||
// log.Fatal(err.Error())
|
||||
// return
|
||||
//}
|
||||
//utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"github.com/fox/fox/processor"
|
||||
"github.com/fox/fox/service"
|
||||
"github.com/fox/fox/xrand"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -153,9 +152,7 @@ func (s *LoginService) onLoginOrRegister(iMsg *ipb.InternalMsg, req *pb.ReqUserL
|
||||
}
|
||||
}
|
||||
topic := service.TopicEx(iMsg.ServiceName)
|
||||
log.DebugF("send to:%v msg id:%v, msg:%v", topic, pb.MsgId_RspUserLoginId, rsp.String())
|
||||
data, _ := proto.Marshal(rsp)
|
||||
s.SendServiceData(topic, iMsg.ConnId, userId, int32(pb.MsgId_RspUserLoginId), data)
|
||||
s.SendServiceMsgByTopic(topic, iMsg.ConnId, userId, int32(pb.MsgId_RspUserLoginId), rsp)
|
||||
|
||||
if account != nil && account.ID > 0 {
|
||||
loginLog := &user.UserLoginLog{
|
||||
|
@ -52,7 +52,7 @@ func newLoginService(serviceId int) *LoginService {
|
||||
OnFunc: s,
|
||||
TypeId: int(pb.ServiceTypeId_STI_Login),
|
||||
Version: config.Cfg.BuildDate,
|
||||
})
|
||||
}, &config.Cfg.Redis)
|
||||
|
||||
s.initProcessor()
|
||||
s.OnInit()
|
||||
|
@ -1,38 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"game/common/constant"
|
||||
"game/common/utils"
|
||||
"game/server/match/config"
|
||||
"github.com/fox/fox/db"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
var (
|
||||
UserBindServiceRedis *redis.Client
|
||||
ConfigRedis *redis.Client
|
||||
// UserBindServiceRedis *redis.Client
|
||||
// ConfigRedis *redis.Client
|
||||
// UserDB *gorm.DB
|
||||
// LogDB *gorm.DB
|
||||
)
|
||||
|
||||
func InitRedis() {
|
||||
log.Debug("init redis")
|
||||
var err error
|
||||
cfg := &config.Cfg.Redis
|
||||
UserBindServiceRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis3UserBindService)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return
|
||||
}
|
||||
utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
//var err error
|
||||
//cfg := &config.Cfg.Redis
|
||||
//UserBindServiceRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis3UserBindService)
|
||||
//if err != nil {
|
||||
// log.Fatal(err.Error())
|
||||
// return
|
||||
//}
|
||||
//utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
|
||||
ConfigRedis, err = db.InitRedis(cfg.Password, cfg.Host, cfg.Port, constant.Redis0Config)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return
|
||||
}
|
||||
utils.AutoSetRedisPool(UserBindServiceRedis)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -18,25 +18,23 @@ func (s *MatchService) onMatchRoom(iMsg *ipb.InternalMsg, req *pb.ReqMatchRoom)
|
||||
gameId := req.GameId
|
||||
switch gameId {
|
||||
case pb.ServiceTypeId_STI_ColorGame:
|
||||
node, err := s.bindService.FindServiceNode(gameId, iMsg.UserId)
|
||||
node, err := s.BindService().FindServiceNode(gameId, iMsg.UserId)
|
||||
if err != nil {
|
||||
log.ErrorF("db service node error:%v", err)
|
||||
s.SendServiceMsg(iMsg.ServiceName, service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId,
|
||||
int32(pb.MsgId_RspMatchRoomId), &pb.RspMatchRoom{Code: pb.ErrCode_SystemErr})
|
||||
s.SendServiceMsg(pb.ServiceTypeId_STI_Gate, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), &pb.RspMatchRoom{Code: pb.ErrCode_SystemErr})
|
||||
return
|
||||
}
|
||||
s.SendServiceMsg(iMsg.ServiceName, service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId,
|
||||
int32(pb.MsgId_RspMatchRoomId), &pb.RspMatchRoom{})
|
||||
s.SendServiceMsg(iMsg.ServiceName, service.TopicEx(node.Name), iMsg.ConnId, iMsg.UserId,
|
||||
s.SendServiceMsg(pb.ServiceTypeId_STI_Gate, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), &pb.RspMatchRoom{})
|
||||
s.SendServiceMsgByTopic(service.TopicEx(node.Name), iMsg.ConnId, iMsg.UserId,
|
||||
int32(pb.MsgId_ReqEnterRoomId), &pb.ReqEnterRoom{})
|
||||
return
|
||||
}
|
||||
|
||||
var us *user.GameUser
|
||||
rsp := &pb.RspMatchRoom{}
|
||||
us, rsp.Code = rpc.RpcGetGameUser(s.bindService, s, iMsg.UserId)
|
||||
us, rsp.Code = rpc.RpcGetGameUser(s, iMsg.UserId)
|
||||
if rsp.Code != pb.ErrCode_OK {
|
||||
s.SendServiceMsg(iMsg.ServiceName, service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
||||
s.SendServiceMsg(pb.ServiceTypeId_STI_Gate, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
||||
return
|
||||
}
|
||||
vipLv, vipExp := utils.VipLevel(us.VipExp)
|
||||
@ -57,6 +55,6 @@ func (s *MatchService) onMatchRoom(iMsg *ipb.InternalMsg, req *pb.ReqMatchRoom)
|
||||
rsp.ColorInfo = &pb.RspMatchRoom_ColorInfo{}
|
||||
}
|
||||
|
||||
s.SendServiceMsg(iMsg.ServiceName, service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
||||
s.SendServiceMsg(pb.ServiceTypeId_STI_Gate, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
||||
}, nil)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ const (
|
||||
)
|
||||
|
||||
func (s *MatchService) initProcessor() {
|
||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
||||
s.Processor().RegisterMessages(processor.RegisterMetas{
|
||||
pb.MsgId_ReqMatchRoomId: {pb.ReqMatchRoom{}, s.onMatchRoom},
|
||||
})
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func newService(serviceId int) *MatchService {
|
||||
OnFunc: s,
|
||||
TypeId: int(pb.ServiceTypeId_STI_Match),
|
||||
Version: config.Cfg.BuildDate,
|
||||
})
|
||||
}, &config.Cfg.Redis)
|
||||
|
||||
s.initProcessor()
|
||||
s.OnInit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user