129 lines
3.9 KiB
Go
129 lines
3.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/rabbitmq/amqp091-go"
|
|
"samba/pkg/log"
|
|
"samba/proto"
|
|
"samba/util/model"
|
|
"samba/util/util"
|
|
)
|
|
|
|
func onMatchClubRoom(_ *amqp091.Delivery, msg map[string]interface{}) {
|
|
_, _, uid, data := ParseMsg(msg)
|
|
req, err := util.MapToStructT[proto.ReqMatchClubRoom](data)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
gs := GameServerMgr.FindByRoomType(req.RoomType, true)
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqMatchClubRoomId, req)
|
|
}
|
|
|
|
func onCancelMatchClubRoom(_ *amqp091.Delivery, msg map[string]interface{}) {
|
|
_, _, uid, data := ParseMsg(msg)
|
|
req, err := util.MapToStructT[proto.ReqCancelMatchClubRoom](data)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
gs := GameServerMgr.FindByRoomType(req.RoomType, true)
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqCancelMatchClubRoomId, req)
|
|
}
|
|
|
|
// 非俱乐部玩法
|
|
func onMatchRoom(_ *amqp091.Delivery, msg map[string]interface{}) {
|
|
_, _, uid, data := ParseMsg(msg)
|
|
req, err := util.MapToStructT[proto.ReqMatchRoom](data)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
gs := GameServerMgr.FindByRoomType(req.RoomType, false)
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqMatchRoomId, req)
|
|
}
|
|
|
|
func onCancelMatchRoom(_ *amqp091.Delivery, msg map[string]interface{}) {
|
|
_, _, uid, data := ParseMsg(msg)
|
|
req, err := util.MapToStructT[proto.ReqCancelMatchRoom](data)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
gs := GameServerMgr.FindByRoomType(req.RoomType, false)
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqCancelMatchRoomId, req)
|
|
}
|
|
|
|
// 俱乐部玩法快速进房间
|
|
func onQuickEnterClubRoom(_ *amqp091.Delivery, msg map[string]interface{}) {
|
|
_, _, uid, data := ParseMsg(msg)
|
|
req, err := util.MapToStructT[proto.ReqQuickEnterClubRoom](data)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
if playInfos, _ := model.NewClubPlayInfoOp().Load(req.ClubId); playInfos != nil {
|
|
for _, info := range playInfos {
|
|
if info.PlayType == req.PlayType {
|
|
if gs := GameServerMgr.FindByPlayType(info.PlayType, true); gs != nil {
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqQuickEnterClubRoomId, req)
|
|
return
|
|
} else {
|
|
log.Error(fmt.Sprintf("recv msg:%+v.but can not find game service", req))
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
SendMsgToGate(uid, proto.RspQuickEnterClubRoomId, proto.RspQuickEnterClubRoom{Code: proto.NotExistRoom})
|
|
return
|
|
}
|
|
|
|
// 俱乐部玩法进指定房间
|
|
func onEnterClubRoom(_ *amqp091.Delivery, msg map[string]interface{}) {
|
|
_, _, uid, data := ParseMsg(msg)
|
|
req, err := util.MapToStructT[proto.ReqEnterClubRoom](data)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
if req.RoomID != 0 {
|
|
gs := GameServerMgr.FindByRoomId(req.RoomID)
|
|
if gs != nil {
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqEnterClubRoomId, req)
|
|
return
|
|
}
|
|
} else {
|
|
if playInfos, _ := model.NewClubPlayInfoOp().Load(req.ClubId); playInfos != nil {
|
|
for _, info := range playInfos {
|
|
if info.ID == req.RoomType {
|
|
if gs := GameServerMgr.FindByPlayType(info.PlayType, true); gs != nil {
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqEnterClubRoomId, req)
|
|
return
|
|
} else {
|
|
log.Error(fmt.Sprintf("recv msg:%+v.but can not find game service", req))
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
SendMsgToGate(uid, proto.RspEnterClubRoomId, proto.RspEnterClubRoom{Code: proto.NotExistRoom})
|
|
}
|
|
|
|
// 解散房间
|
|
func onUserDisbandRoom(_ *amqp091.Delivery, msg map[string]interface{}) {
|
|
_, _, uid, data := ParseMsg(msg)
|
|
req, err := util.MapToStructT[proto.ReqUserDisbandRoom](data)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
gs := GameServerMgr.FindByRoomId(req.RoomId)
|
|
if gs != nil {
|
|
SendMsg(util.Direct(gs.Type), gs.RouterKey, "", uid, proto.ReqUserDisbandRoomId, req)
|
|
} else {
|
|
SendMsgToGate(uid, proto.RspUserDisbandRoomId, &proto.RspUserDisbandRoom{Code: proto.NotExistRoom})
|
|
}
|
|
}
|