package server

import (
	"game/common/proto/pb"
	"github.com/fox/fox/etcd"
	"github.com/fox/fox/ipb"
	"github.com/fox/fox/processor"
	"github.com/fox/fox/service"
)

func (s *LobbyService) initProcessor() {
	s.processor.RegisterMessages(processor.RegisterMetas{
		pb.MsgId_NtfUserOnlineId: {pb.NtfUserOnline{}, s.onUserOnline},
	})
}

// 玩家上线，告诉玩家在哪个玩法中
func (s *LobbyService) onUserOnline(iMsg *ipb.InternalMsg, msg *pb.NtfUserOnline) {
	var nodes []*etcd.ServiceNode
	s.bindService.RangeUserAllServiceNode(msg.UserId, func(node *etcd.ServiceNode) bool {
		if node.TypeId != int(pb.ServiceTypeId_STI_Gate) {
			nodes = append(nodes, node)
		}
		return true
	})
	ntf := &pb.NtfUserInService{}
	for _, node := range nodes {
		ntf.ServiceNames = append(ntf.ServiceNames, node.Name)
	}
	s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.UserId, int32(pb.MsgId_NtfUserInServiceId), ntf)

}
