60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package server
|
|
|
|
import (
|
|
"game/common/model/user"
|
|
"game/common/proto/pb"
|
|
"game/common/rpc"
|
|
"game/common/utils"
|
|
"github.com/fox/fox/ipb"
|
|
"github.com/fox/fox/ksync"
|
|
"github.com/fox/fox/log"
|
|
"github.com/fox/fox/service"
|
|
)
|
|
|
|
// 匹配房间
|
|
func (s *MatchService) onMatchRoom(iMsg *ipb.InternalMsg, req *pb.ReqMatchRoom) {
|
|
ksync.GoSafe(func() {
|
|
// color game无需进入匹配队列
|
|
gameId := pb.ServiceTypeId(req.GameId)
|
|
switch gameId {
|
|
case pb.ServiceTypeId_STI_ColorGame:
|
|
node, err := s.bindService.FindServiceNode(iMsg.UserId, gameId)
|
|
if err != nil {
|
|
log.ErrorF("db service node error:%v", err)
|
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId,
|
|
int32(pb.MsgId_RspMatchRoomId), &pb.RspMatchRoom{Code: pb.ErrCode_SystemErr})
|
|
return
|
|
}
|
|
s.SendServiceMsg(service.TopicEx(node.Name), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_ReqMatchRoomId), req)
|
|
return
|
|
}
|
|
|
|
var us *user.GameUser
|
|
rsp := &pb.RspMatchRoom{}
|
|
us, rsp.Code = rpc.RpcGetGameUser(s.bindService, s, iMsg.UserId)
|
|
if rsp.Code != pb.ErrCode_OK {
|
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
|
return
|
|
}
|
|
vipLv, vipExp := utils.VipLevel(us.VipExp)
|
|
rsp.User = &pb.GameUser{
|
|
UserId: us.ID,
|
|
Nickname: us.Nickname,
|
|
Avatar: us.AvatarUrl,
|
|
AvatarFrame: us.AvatarFrame,
|
|
VipLevel: vipLv,
|
|
VipExp: vipExp,
|
|
Seat: 0,
|
|
Gold: us.Gold,
|
|
}
|
|
rsp.GameId = req.GameId
|
|
rsp.RoomType = req.RoomType
|
|
switch pb.ServiceTypeId(rsp.GameId) {
|
|
case pb.ServiceTypeId_STI_ColorGame:
|
|
rsp.ColorInfo = &pb.RspMatchRoom_ColorInfo{}
|
|
}
|
|
|
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
|
}, nil)
|
|
}
|