samba/server/hall/handler/msghandler.go

57 lines
1.8 KiB
Go
Raw Permalink Normal View History

2025-06-04 09:51:39 +08:00
package handler
import (
"github.com/rabbitmq/amqp091-go"
"samba/pkg/log"
"samba/pkg/servername"
"samba/pkg/service"
"samba/proto"
"samba/util/routingKey"
"samba/util/util"
)
var MsgHandler = map[string]MessageHandler{
proto.NtfUserOnlineId: onUserOnline,
proto.NtfUserOfflineId: onUserOffline,
proto.NtfNewServiceId: onUpdateService,
proto.ReqMatchClubRoomId: onMatchClubRoom,
proto.ReqCancelMatchClubRoomId: onCancelMatchClubRoom,
proto.ReqMatchRoomId: onMatchRoom,
proto.ReqCancelMatchRoomId: onCancelMatchRoom,
proto.ReqReconnectId: onUserReconnect,
proto.ReqLeaveRoomId: onLeaveRoom,
proto.ReqEnterRoomId: onEnterRoom,
proto.ReqDisbandRoomId: onDisbandRoom,
proto.NtfUpdateConfigId: onUpdateConfig,
proto.ReqQuickEnterClubRoomId: onQuickEnterClubRoom,
proto.ReqEnterClubRoomId: onEnterClubRoom,
proto.ReqUserDisbandRoomId: onUserDisbandRoom,
proto.ReqBankruptSubsidyId: onBankruptSubsidy,
proto.ReqPlayingNumId: onPlayingNum,
}
type MessageHandler func(d *amqp091.Delivery, data map[string]interface{})
func RegisterMsgHandler(s service.IService) bool {
for msgId := range MsgHandler {
if err := s.QueueBind(QueueName(), msgId, util.Direct(servername.Hall)); err != nil {
log.Error(err.Error())
return false
}
}
if err := s.QueueBind(QueueName(), routingKey.Hall, util.Direct(servername.Hall)); err != nil {
log.Error(err.Error())
return false
}
if err := s.QueueBind(QueueName(), routingKey.UserOnline, util.Topic(servername.User)); err != nil {
log.Error(err.Error())
return false
}
if err := s.QueueBind(QueueName(), routingKey.UserOffline, util.Topic(servername.User)); err != nil {
log.Error(err.Error())
return false
}
return true
}