package server

import (
	"game/common/proto/pb"
	"game/common/topicName"
	"github.com/fox/fox/log"
	"github.com/fox/fox/processor"
	"github.com/fox/fox/service"
)

func (s *ChatService) initProcessor() {
	s.processor.RegisterMessages(processor.RegisterMetas{
		pb.MsgId_ReqChatId: {pb.ReqChat{}, s.onChat},
	})
}

// 收到登陆成功消息，判断是否顶号
func (s *ChatService) onChat(uid int64, msg *pb.ReqChat) {
	switch msg.Type {
	case pb.ChatType_CT_Private:
		node, err := s.bindService.FindServiceNode(pb.ServiceTypeId_STI_Gate, msg.DstUser.UserId)
		if node == nil {
			log.ErrorF("user:%v find gate failed.err:%v", uid, err)
			return
		}
		s.SendServiceMsg(service.TopicEx(node.Name), msg.DstUser.UserId, int32(pb.MsgId_RspChatId), msg)
	default:
		s.SendServiceMsg(service.TopicEx(topicName.WorldMessage), uid, int32(pb.MsgId_RspChatId), msg)
	}
}
